Average Error: 3.7 → 0.3
Time: 12.3s
Precision: binary64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \leq -3.4347101080278726 \cdot 10^{+37}:\\ \;\;\;\;x + \left(y + -1\right) \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq 9.036544996947276 \cdot 10^{-119}:\\ \;\;\;\;x + \left(x \cdot \left(z \cdot y\right) - z \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq -3.4347101080278726 \cdot 10^{+37}:\\
\;\;\;\;x + \left(y + -1\right) \cdot \left(z \cdot x\right)\\

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

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

\end{array}
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -3.4347101080278726e+37)
   (+ x (* (+ y -1.0) (* z x)))
   (if (<= z 9.036544996947276e-119)
     (+ x (- (* x (* z y)) (* z x)))
     (+ x (* z (* x (+ y -1.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 tmp;
	if (z <= -3.4347101080278726e+37) {
		tmp = x + ((y + -1.0) * (z * x));
	} else if (z <= 9.036544996947276e-119) {
		tmp = x + ((x * (z * y)) - (z * x));
	} else {
		tmp = x + (z * (x * (y + -1.0)));
	}
	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.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 3 regimes
  2. if z < -3.43471010802787256e37

    1. Initial program 11.3

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

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

    if -3.43471010802787256e37 < z < 9.03654499694727634e-119

    1. Initial program 0.1

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

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

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

    if 9.03654499694727634e-119 < z

    1. Initial program 5.9

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

      \[\leadsto \color{blue}{x + \left(y + -1\right) \cdot \left(x \cdot z\right)}\]
    3. Using strategy rm
    4. Applied associate-*r*_binary64_174090.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.4347101080278726 \cdot 10^{+37}:\\ \;\;\;\;x + \left(y + -1\right) \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq 9.036544996947276 \cdot 10^{-119}:\\ \;\;\;\;x + \left(x \cdot \left(z \cdot y\right) - z \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \end{array}\]

Reproduce

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