Average Error: 3.4 → 2.0
Time: 7.0s
Precision: binary64
Cost: 708
\[ \begin{array}{c}[y, z] = \mathsf{sort}([y, z])\\ \end{array} \]
\[x \cdot \left(1 - y \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+148}:\\ \;\;\;\;x - \left(y \cdot z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (* y z) 2e+148) (- x (* (* y z) x)) (* y (* z (- x)))))
double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= 2e+148) {
		tmp = x - ((y * z) * x);
	} else {
		tmp = y * (z * -x);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * (1.0d0 - (y * z))
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y * z) <= 2d+148) then
        tmp = x - ((y * z) * x)
    else
        tmp = y * (z * -x)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
public static double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= 2e+148) {
		tmp = x - ((y * z) * x);
	} else {
		tmp = y * (z * -x);
	}
	return tmp;
}
def code(x, y, z):
	return x * (1.0 - (y * z))
def code(x, y, z):
	tmp = 0
	if (y * z) <= 2e+148:
		tmp = x - ((y * z) * x)
	else:
		tmp = y * (z * -x)
	return tmp
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(y * z)))
end
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * z) <= 2e+148)
		tmp = Float64(x - Float64(Float64(y * z) * x));
	else
		tmp = Float64(y * Float64(z * Float64(-x)));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - (y * z));
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y * z) <= 2e+148)
		tmp = x - ((y * z) * x);
	else
		tmp = y * (z * -x);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 2e+148], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
x \cdot \left(1 - y \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+148}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 y z) < 2.0000000000000001e148

    1. Initial program 2.0

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Applied egg-rr8.4

      \[\leadsto \color{blue}{\frac{\left(1 - {\left(y \cdot z\right)}^{2}\right) \cdot x}{1 + y \cdot z}} \]
    3. Applied egg-rr9.9

      \[\leadsto \frac{\left(1 - \color{blue}{\left(\left(y \cdot z\right) \cdot y\right) \cdot z}\right) \cdot x}{1 + y \cdot z} \]
    4. Taylor expanded in x around 0 21.3

      \[\leadsto \color{blue}{\frac{\left(1 - {y}^{2} \cdot {z}^{2}\right) \cdot x}{y \cdot z + 1}} \]
    5. Simplified7.8

      \[\leadsto \color{blue}{\left(1 - \left(y \cdot z\right) \cdot \left(y \cdot z\right)\right) \cdot \frac{x}{\mathsf{fma}\left(y, z, 1\right)}} \]
      Proof
      (*.f64 (-.f64 1 (*.f64 (*.f64 y z) (*.f64 y z))) (/.f64 x (fma.f64 y z 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 1 (Rewrite<= unswap-sqr_binary64 (*.f64 (*.f64 y y) (*.f64 z z)))) (/.f64 x (fma.f64 y z 1))): 67 points increase in error, 7 points decrease in error
      (*.f64 (-.f64 1 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 y 2)) (*.f64 z z))) (/.f64 x (fma.f64 y z 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 1 (*.f64 (pow.f64 y 2) (Rewrite<= unpow2_binary64 (pow.f64 z 2)))) (/.f64 x (fma.f64 y z 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 (-.f64 1 (*.f64 (pow.f64 y 2) (pow.f64 z 2))) (/.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y z) 1)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (-.f64 1 (*.f64 (pow.f64 y 2) (pow.f64 z 2))) x) (+.f64 (*.f64 y z) 1))): 5 points increase in error, 3 points decrease in error
    6. Taylor expanded in y around 0 5.1

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \left(z \cdot x\right)\right) + x} \]
    7. Simplified2.0

      \[\leadsto \color{blue}{x - x \cdot \left(y \cdot z\right)} \]
      Proof
      (-.f64 x (*.f64 x (*.f64 y z))): 0 points increase in error, 0 points decrease in error
      (-.f64 x (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 y z) x))): 0 points increase in error, 0 points decrease in error
      (-.f64 x (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 z x)))): 33 points increase in error, 18 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 x (neg.f64 (*.f64 y (*.f64 z x))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 y (*.f64 z x))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (*.f64 y (*.f64 z x))) x)): 0 points increase in error, 0 points decrease in error

    if 2.0000000000000001e148 < (*.f64 y z)

    1. Initial program 18.2

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Applied egg-rr62.0

      \[\leadsto \color{blue}{\frac{\left(1 - {\left(y \cdot z\right)}^{2}\right) \cdot x}{1 + y \cdot z}} \]
    3. Taylor expanded in y around inf 2.0

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \left(z \cdot x\right)\right)} \]
    4. Simplified2.0

      \[\leadsto \color{blue}{y \cdot \left(x \cdot \left(-z\right)\right)} \]
      Proof
      (*.f64 y (*.f64 x (neg.f64 z))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 x z)))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 z x)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y (*.f64 z x)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 y (*.f64 z x)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification2.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+148}:\\ \;\;\;\;x - \left(y \cdot z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error4.3
Cost1164
\[\begin{array}{l} t_0 := \left(y \cdot z\right) \cdot \left(-x\right)\\ \mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+148}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\ \end{array} \]
Alternative 2
Error16.5
Cost912
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{if}\;z \leq -1.1920259430034838 \cdot 10^{-57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+77}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+158}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+186}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error25.8
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022308 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
  :precision binary64
  (* x (- 1.0 (* y z))))