Average Error: 3.5 → 0.6
Time: 3.6s
Precision: binary64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+136}:\\ \;\;\;\;\mathsf{fma}\left(y + -1, z \cdot x, x\right)\\ \mathbf{elif}\;z \leq 3.4472072448506344 \cdot 10^{-29}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y + -1, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot x - x, x\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -1e+136)
   (fma (+ y -1.0) (* z x) x)
   (if (<= z 3.4472072448506344e-29)
     (* x (fma z (+ y -1.0) 1.0))
     (fma z (- (* y x) x) 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 tmp;
	if (z <= -1e+136) {
		tmp = fma((y + -1.0), (z * x), x);
	} else if (z <= 3.4472072448506344e-29) {
		tmp = x * fma(z, (y + -1.0), 1.0);
	} else {
		tmp = fma(z, ((y * x) - x), 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)
	tmp = 0.0
	if (z <= -1e+136)
		tmp = fma(Float64(y + -1.0), Float64(z * x), x);
	elseif (z <= 3.4472072448506344e-29)
		tmp = Float64(x * fma(z, Float64(y + -1.0), 1.0));
	else
		tmp = fma(z, Float64(Float64(y * x) - x), 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_] := If[LessEqual[z, -1e+136], N[(N[(y + -1.0), $MachinePrecision] * N[(z * x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 3.4472072448506344e-29], N[(x * N[(z * N[(y + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(z * N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision] + x), $MachinePrecision]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+136}:\\
\;\;\;\;\mathsf{fma}\left(y + -1, z \cdot x, x\right)\\

\mathbf{elif}\;z \leq 3.4472072448506344 \cdot 10^{-29}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, y + -1, 1\right)\\

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


\end{array}

Error

Target

Original3.5
Target0.3
Herbie0.6
\[\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 z < -1.00000000000000006e136

    1. Initial program 13.4

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

      \[\leadsto \color{blue}{z \cdot \left(\left(y - 1\right) \cdot x\right) + x} \]
    3. Applied egg-rr0.1

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

    if -1.00000000000000006e136 < z < 3.44720724485063437e-29

    1. Initial program 0.8

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

      \[\leadsto \color{blue}{z \cdot \left(\left(y - 1\right) \cdot x\right) + x} \]
    3. Applied egg-rr0.8

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

    if 3.44720724485063437e-29 < z

    1. Initial program 7.9

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

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

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

Reproduce

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