Average Error: 3.5 → 0.4
Time: 5.1s
Precision: binary64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;\left(1 - y\right) \cdot z \leq -6.7056208390435025 \cdot 10^{+137}:\\ \;\;\;\;x + \left(y \cdot \left(z \cdot x\right) - z \cdot x\right)\\ \mathbf{elif}\;\left(1 - y\right) \cdot z \leq 1.8141537630332114 \cdot 10^{+113}:\\ \;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot x - x\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;\left(1 - y\right) \cdot z \leq -6.7056208390435025 \cdot 10^{+137}:\\
\;\;\;\;x + \left(y \cdot \left(z \cdot x\right) - z \cdot x\right)\\

\mathbf{elif}\;\left(1 - y\right) \cdot z \leq 1.8141537630332114 \cdot 10^{+113}:\\
\;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(y \cdot 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 (<= (* (- 1.0 y) z) -6.7056208390435025e+137)
   (+ x (- (* y (* z x)) (* z x)))
   (if (<= (* (- 1.0 y) z) 1.8141537630332114e+113)
     (+ x (* x (* z (+ y -1.0))))
     (+ x (* z (- (* 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 (((1.0 - y) * z) <= -6.7056208390435025e+137) {
		tmp = x + ((y * (z * x)) - (z * x));
	} else if (((1.0 - y) * z) <= 1.8141537630332114e+113) {
		tmp = x + (x * (z * (y + -1.0)));
	} else {
		tmp = x + (z * ((y * x) - x));
	}
	return tmp;
}

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

Original3.5
Target0.2
Herbie0.4
\[\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 (*.f64 (-.f64 1 y) z) < -6.7056208390435025e137

    1. Initial program 12.3

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

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-\left(1 - y\right) \cdot z\right)\right)}\]
    4. Applied distribute-rgt-in_binary64_2321612.3

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

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

      \[\leadsto x + \color{blue}{x \cdot \left(z \cdot y - z\right)}\]
    7. Using strategy rm
    8. Applied sub-neg_binary64_2325912.3

      \[\leadsto x + x \cdot \color{blue}{\left(z \cdot y + \left(-z\right)\right)}\]
    9. Applied distribute-rgt-in_binary64_2321612.3

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

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

      \[\leadsto x + \left(x \cdot \left(z \cdot y\right) + \color{blue}{\left(-x \cdot z\right)}\right)\]
    12. Using strategy rm
    13. Applied associate-*r*_binary64_232061.0

      \[\leadsto x + \left(\color{blue}{\left(x \cdot z\right) \cdot y} + \left(-x \cdot z\right)\right)\]
    14. Using strategy rm
    15. Applied unsub-neg_binary64_232601.0

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

    if -6.7056208390435025e137 < (*.f64 (-.f64 1 y) z) < 1.81415376303321137e113

    1. Initial program 0.1

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

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

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

    if 1.81415376303321137e113 < (*.f64 (-.f64 1 y) z)

    1. Initial program 11.4

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied sub-neg_binary64_2325911.4

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

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

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

      \[\leadsto x + \color{blue}{x \cdot \left(z \cdot y - z\right)}\]
    7. Taylor expanded around 0 1.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(1 - y\right) \cdot z \leq -6.7056208390435025 \cdot 10^{+137}:\\ \;\;\;\;x + \left(y \cdot \left(z \cdot x\right) - z \cdot x\right)\\ \mathbf{elif}\;\left(1 - y\right) \cdot z \leq 1.8141537630332114 \cdot 10^{+113}:\\ \;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot x - x\right)\\ \end{array}\]

Reproduce

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