Average Error: 3.5 → 0.5
Time: 2.7s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.5086720243577012 \cdot 10^{74} \lor \neg \left(x \le 4.82713285845016858 \cdot 10^{-220}\right):\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \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}\;x \le -2.5086720243577012 \cdot 10^{74} \lor \neg \left(x \le 4.82713285845016858 \cdot 10^{-220}\right):\\
\;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\

\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 ((double) (x * ((double) (1.0 - ((double) (((double) (1.0 - y)) * z))))));
}
double code(double x, double y, double z) {
	double VAR;
	if (((x <= -2.508672024357701e+74) || !(x <= 4.8271328584501686e-220))) {
		VAR = ((double) fma(1.0, x, ((double) (((double) (x * z)) * ((double) (y - 1.0))))));
	} else {
		VAR = ((double) fma(1.0, x, ((double) (z * ((double) (x * ((double) (y - 1.0))))))));
	}
	return VAR;
}

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.3
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 2 regimes
  2. if x < -2.508672024357701e+74 or 4.8271328584501686e-220 < x

    1. Initial program 2.0

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Taylor expanded around inf 2.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.6

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

    if -2.508672024357701e+74 < x < 4.8271328584501686e-220

    1. Initial program 5.4

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

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

      \[\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 *-commutative2.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.5086720243577012 \cdot 10^{74} \lor \neg \left(x \le 4.82713285845016858 \cdot 10^{-220}\right):\\ \;\;\;\;\mathsf{fma}\left(1, x, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, z \cdot \left(x \cdot \left(y - 1\right)\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020113 +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))))