Average Error: 3.7 → 0.3
Time: 3.6s
Precision: binary64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(y, z \cdot x, x\right) - z \cdot x\\ \mathbf{if}\;z \leq -8.795145312110055 \cdot 10^{+83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.599520831582608 \cdot 10^{-73}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(y, z, 1\right) - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, z \cdot x, x\right) - z \cdot x\\
\mathbf{if}\;z \leq -8.795145312110055 \cdot 10^{+83}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (fma y (* z x) x) (* z x))))
   (if (<= z -8.795145312110055e+83)
     t_0
     (if (<= z 1.599520831582608e-73) (* x (- (fma y z 1.0) z)) t_0))))
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 = fma(y, (z * x), x) - (z * x);
	double tmp;
	if (z <= -8.795145312110055e+83) {
		tmp = t_0;
	} else if (z <= 1.599520831582608e-73) {
		tmp = x * (fma(y, z, 1.0) - z);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.7
Target0.2
Herbie0.3
\[\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 2 regimes
  2. if z < -8.7951453121100549e83 or 1.5995208315826081e-73 < z

    1. Initial program 9.0

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

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

      \[\leadsto \color{blue}{\left(y \cdot \left(z \cdot x\right) + x\right) - z \cdot x} \]
    4. Applied fma-def_binary640.3

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

    if -8.7951453121100549e83 < z < 1.5995208315826081e-73

    1. Initial program 0.3

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

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

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

Reproduce

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