Average Error: 3.4 → 0.7
Time: 3.3s
Precision: binary64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} t_0 := 1 + z \cdot \left(y + -1\right)\\ \mathbf{if}\;t_0 \leq -1.98 \cdot 10^{+301}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(x, y, x\right), x\right)\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+62}:\\ \;\;\;\;\mathsf{fma}\left(x, y \cdot z - z, x\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \left(x - y \cdot x\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 (* z (+ y -1.0)))))
   (if (<= t_0 -1.98e+301)
     (fma z (fma x y x) x)
     (if (<= t_0 2e+62) (fma x (- (* y z) z) x) (- x (* z (- x (* y x))))))))
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 + (z * (y + -1.0));
	double tmp;
	if (t_0 <= -1.98e+301) {
		tmp = fma(z, fma(x, y, x), x);
	} else if (t_0 <= 2e+62) {
		tmp = fma(x, ((y * z) - z), x);
	} else {
		tmp = x - (z * (x - (y * x)));
	}
	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(1.0 + Float64(z * Float64(y + -1.0)))
	tmp = 0.0
	if (t_0 <= -1.98e+301)
		tmp = fma(z, fma(x, y, x), x);
	elseif (t_0 <= 2e+62)
		tmp = fma(x, Float64(Float64(y * z) - z), x);
	else
		tmp = Float64(x - Float64(z * Float64(x - Float64(y * x))));
	end
	return 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[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1.98e+301], N[(z * N[(x * y + x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 2e+62], N[(x * N[(N[(y * z), $MachinePrecision] - z), $MachinePrecision] + x), $MachinePrecision], N[(x - N[(z * N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
t_0 := 1 + z \cdot \left(y + -1\right)\\
\mathbf{if}\;t_0 \leq -1.98 \cdot 10^{+301}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(x, y, x\right), x\right)\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+62}:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot z - z, x\right)\\

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


\end{array}

Error

Target

Original3.4
Target0.2
Herbie0.7
\[\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 1 (*.f64 (-.f64 1 y) z)) < -1.98e301

    1. Initial program 57.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x \cdot y - x, x\right)} \]
    3. Applied egg-rr1.3

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(z, \mathsf{fma}\left(x, y, -x\right), x\right)}\right)}^{3}} \]
    4. Applied egg-rr4.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \mathsf{fma}\left(x, y, x\right), x\right)} \]

    if -1.98e301 < (-.f64 1 (*.f64 (-.f64 1 y) z)) < 2.00000000000000007e62

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x \cdot y - x, x\right)} \]
    3. Taylor expanded in z around 0 4.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y \cdot z - z, x\right)} \]

    if 2.00000000000000007e62 < (-.f64 1 (*.f64 (-.f64 1 y) z))

    1. Initial program 8.7

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Simplified2.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x \cdot y - x, x\right)} \]
    3. Taylor expanded in y around 0 2.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 + z \cdot \left(y + -1\right) \leq -1.98 \cdot 10^{+301}:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(x, y, x\right), x\right)\\ \mathbf{elif}\;1 + z \cdot \left(y + -1\right) \leq 2 \cdot 10^{+62}:\\ \;\;\;\;\mathsf{fma}\left(x, y \cdot z - z, x\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \left(x - y \cdot x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022190 
(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))))