Average Error: 3.4 → 0.2
Time: 3.4s
Precision: binary64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8203134534163076 \cdot 10^{-14}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot x, y, x\right) - z \cdot x\\ \mathbf{elif}\;z \leq 4.6176097849876254 \cdot 10^{-54}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y, 1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, x \cdot y - 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 -2.8203134534163076e-14)
   (- (fma (* z x) y x) (* z x))
   (if (<= z 4.6176097849876254e-54)
     (* x (fma z y (- 1.0 z)))
     (fma z (- (* x y) 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 <= -2.8203134534163076e-14) {
		tmp = fma((z * x), y, x) - (z * x);
	} else if (z <= 4.6176097849876254e-54) {
		tmp = x * fma(z, y, (1.0 - z));
	} else {
		tmp = fma(z, ((x * y) - 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 <= -2.8203134534163076e-14)
		tmp = Float64(fma(Float64(z * x), y, x) - Float64(z * x));
	elseif (z <= 4.6176097849876254e-54)
		tmp = Float64(x * fma(z, y, Float64(1.0 - z)));
	else
		tmp = fma(z, Float64(Float64(x * y) - 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, -2.8203134534163076e-14], N[(N[(N[(z * x), $MachinePrecision] * y + x), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.6176097849876254e-54], N[(x * N[(z * y + N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision] + x), $MachinePrecision]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq -2.8203134534163076 \cdot 10^{-14}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot x, y, x\right) - z \cdot x\\

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

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.4
Target0.2
Herbie0.2
\[\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 < -2.8203134534163076e-14

    1. Initial program 8.1

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

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

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

    if -2.8203134534163076e-14 < z < 4.6176097849876254e-54

    1. Initial program 0.1

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

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

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

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

    if 4.6176097849876254e-54 < z

    1. Initial program 6.6

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

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

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

Reproduce

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