Average Error: 3.4 → 0.1
Time: 6.4s
Precision: binary64
Cost: 1480
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} t_0 := \left(1 - y\right) \cdot z\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+266}:\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+207}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot x\right) + x \cdot \left(1 - z\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (- 1.0 y) z)))
   (if (<= t_0 -2e+266)
     (* (* z x) (+ y -1.0))
     (if (<= t_0 2e+207)
       (* x (+ 1.0 (* z (+ y -1.0))))
       (+ (* y (* z x)) (* x (- 1.0 z)))))))
double code(double x, double y, double z) {
	return x * (1.0 - ((1.0 - y) * z));
}
double code(double x, double y, double z) {
	double t_0 = (1.0 - y) * z;
	double tmp;
	if (t_0 <= -2e+266) {
		tmp = (z * x) * (y + -1.0);
	} else if (t_0 <= 2e+207) {
		tmp = x * (1.0 + (z * (y + -1.0)));
	} else {
		tmp = (y * (z * x)) + (x * (1.0 - z));
	}
	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 - ((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) :: t_0
    real(8) :: tmp
    t_0 = (1.0d0 - y) * z
    if (t_0 <= (-2d+266)) then
        tmp = (z * x) * (y + (-1.0d0))
    else if (t_0 <= 2d+207) then
        tmp = x * (1.0d0 + (z * (y + (-1.0d0))))
    else
        tmp = (y * (z * x)) + (x * (1.0d0 - z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - ((1.0 - y) * z));
}
public static double code(double x, double y, double z) {
	double t_0 = (1.0 - y) * z;
	double tmp;
	if (t_0 <= -2e+266) {
		tmp = (z * x) * (y + -1.0);
	} else if (t_0 <= 2e+207) {
		tmp = x * (1.0 + (z * (y + -1.0)));
	} else {
		tmp = (y * (z * x)) + (x * (1.0 - z));
	}
	return tmp;
}
def code(x, y, z):
	return x * (1.0 - ((1.0 - y) * z))
def code(x, y, z):
	t_0 = (1.0 - y) * z
	tmp = 0
	if t_0 <= -2e+266:
		tmp = (z * x) * (y + -1.0)
	elif t_0 <= 2e+207:
		tmp = x * (1.0 + (z * (y + -1.0)))
	else:
		tmp = (y * (z * x)) + (x * (1.0 - z))
	return tmp
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z)))
end
function code(x, y, z)
	t_0 = Float64(Float64(1.0 - y) * z)
	tmp = 0.0
	if (t_0 <= -2e+266)
		tmp = Float64(Float64(z * x) * Float64(y + -1.0));
	elseif (t_0 <= 2e+207)
		tmp = Float64(x * Float64(1.0 + Float64(z * Float64(y + -1.0))));
	else
		tmp = Float64(Float64(y * Float64(z * x)) + Float64(x * Float64(1.0 - z)));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - ((1.0 - y) * z));
end
function tmp_2 = code(x, y, z)
	t_0 = (1.0 - y) * z;
	tmp = 0.0;
	if (t_0 <= -2e+266)
		tmp = (z * x) * (y + -1.0);
	elseif (t_0 <= 2e+207)
		tmp = x * (1.0 + (z * (y + -1.0)));
	else
		tmp = (y * (z * x)) + (x * (1.0 - z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+266], N[(N[(z * x), $MachinePrecision] * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+207], N[(x * N[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(z * x), $MachinePrecision]), $MachinePrecision] + N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot z\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+266}:\\
\;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+207}:\\
\;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.4
Target0.2
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) < -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{elif}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) < 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \end{array} \]

Derivation

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

    1. Initial program 34.1

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

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

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

      \[\leadsto \color{blue}{\left(1 - y\right) \cdot \left(z \cdot \left(-x\right)\right)} \]
      Proof

      [Start]0.2

      \[ -1 \cdot \left(z \cdot \left(\left(1 - y\right) \cdot x\right)\right) \]

      mul-1-neg [=>]0.2

      \[ \color{blue}{-z \cdot \left(\left(1 - y\right) \cdot x\right)} \]

      associate-*r* [=>]34.1

      \[ -\color{blue}{\left(z \cdot \left(1 - y\right)\right) \cdot x} \]

      *-commutative [<=]34.1

      \[ -\color{blue}{\left(\left(1 - y\right) \cdot z\right)} \cdot x \]

      distribute-rgt-neg-in [=>]34.1

      \[ \color{blue}{\left(\left(1 - y\right) \cdot z\right) \cdot \left(-x\right)} \]

      associate-*l* [=>]0.2

      \[ \color{blue}{\left(1 - y\right) \cdot \left(z \cdot \left(-x\right)\right)} \]
    5. Taylor expanded in y around 0 0.2

      \[\leadsto \color{blue}{y \cdot \left(z \cdot x\right) + -1 \cdot \left(z \cdot x\right)} \]
    6. Simplified0.2

      \[\leadsto \color{blue}{\left(z \cdot x\right) \cdot \left(y + -1\right)} \]
      Proof

      [Start]0.2

      \[ y \cdot \left(z \cdot x\right) + -1 \cdot \left(z \cdot x\right) \]

      distribute-rgt-out [=>]0.2

      \[ \color{blue}{\left(z \cdot x\right) \cdot \left(y + -1\right)} \]

    if -2.0000000000000001e266 < (*.f64 (-.f64 1 y) z) < 2.0000000000000001e207

    1. Initial program 0.1

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]

    if 2.0000000000000001e207 < (*.f64 (-.f64 1 y) z)

    1. Initial program 19.6

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Taylor expanded in y around 0 0.6

      \[\leadsto \color{blue}{y \cdot \left(z \cdot x\right) + \left(1 - z\right) \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Alternatives

Alternative 1
Error0.1
Cost1353
\[\begin{array}{l} t_0 := \left(1 - y\right) \cdot z\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+266} \lor \neg \left(t_0 \leq 2 \cdot 10^{+207}\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \end{array} \]
Alternative 2
Error21.0
Cost848
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := y \cdot \left(z \cdot x\right)\\ \mathbf{if}\;z \leq -7 \cdot 10^{+220}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7.6 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.6 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.55 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error9.1
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.22 \cdot 10^{-12} \lor \neg \left(z \leq 5.1 \cdot 10^{-12}\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot x\\ \end{array} \]
Alternative 4
Error1.0
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 5
Error11.6
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{+77}:\\ \;\;\;\;y \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;y \leq 3.05 \cdot 10^{+100}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot x\right)\\ \end{array} \]
Alternative 6
Error19.3
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error33.5
Cost64
\[x \]

Error

Reproduce

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

  :herbie-target
  (if (< (* x (- 1.0 (* (- 1.0 y) z))) -1.618195973607049e+50) (+ x (* (- 1.0 y) (* (- z) x))) (if (< (* x (- 1.0 (* (- 1.0 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1.0 y) (* (- z) x)))))

  (* x (- 1.0 (* (- 1.0 y) z))))