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

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

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.5
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 x < -5.39888537937248265e48

    1. Initial program 0.1

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

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

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

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

    if -5.39888537937248265e48 < x < 75475486738441904

    1. Initial program 5.3

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

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

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

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

    if 75475486738441904 < x

    1. Initial program 0.1

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

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

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

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

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

Reproduce

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