Average Error: 2.8 → 0.5
Time: 3.8s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.3306712281846513 \cdot 10^{-90}:\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{elif}\;z \le 4.26612945255824409 \cdot 10^{-114}:\\ \;\;\;\;\left(1 - \left(1 - y\right) \cdot z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, z \cdot \left(x \cdot \left(y - 1\right)\right)\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -2.3306712281846513 \cdot 10^{-90}:\\
\;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\

\mathbf{elif}\;z \le 4.26612945255824409 \cdot 10^{-114}:\\
\;\;\;\;\left(1 - \left(1 - y\right) \cdot z\right) \cdot x\\

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

\end{array}
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 temp;
	if ((z <= -2.3306712281846513e-90)) {
		temp = fma(1.0, x, ((x * z) * (y - 1.0)));
	} else {
		double temp_1;
		if ((z <= 4.266129452558244e-114)) {
			temp_1 = ((1.0 - ((1.0 - y) * z)) * x);
		} else {
			temp_1 = fma(1.0, x, (z * (x * (y - 1.0))));
		}
		temp = temp_1;
	}
	return temp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.8
Target0.2
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \lt -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) \lt 3.8922376496639029 \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.3306712281846513e-90

    1. Initial program 4.7

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Taylor expanded around inf 4.7

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

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

    if -2.3306712281846513e-90 < z < 4.266129452558244e-114

    1. Initial program 0.0

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied *-commutative0.0

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

    if 4.266129452558244e-114 < z

    1. Initial program 5.1

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Taylor expanded around inf 5.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)}\]
    4. Using strategy rm
    5. Applied *-commutative0.9

      \[\leadsto \mathsf{fma}\left(1, x, \color{blue}{\left(z \cdot x\right)} \cdot \left(y - 1\right)\right)\]
    6. Applied associate-*l*1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.3306712281846513 \cdot 10^{-90}:\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{elif}\;z \le 4.26612945255824409 \cdot 10^{-114}:\\ \;\;\;\;\left(1 - \left(1 - y\right) \cdot z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, z \cdot \left(x \cdot \left(y - 1\right)\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020066 +o rules:numerics
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
  :precision binary64

  :herbie-target
  (if (< (* x (- 1 (* (- 1 y) z))) -1.618195973607049e+50) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x)))))

  (* x (- 1 (* (- 1 y) z))))