Average Error: 3.4 → 0.2
Time: 12.4s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.80567192465547634375199356200760357936 \cdot 10^{-55} \lor \neg \left(z \le 8.891798451741654150614573762157279387393 \cdot 10^{-79}\right):\\ \;\;\;\;\left(x \cdot z\right) \cdot y + 1 \cdot \left(x - x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z \cdot y\right) + 1 \cdot \left(x - x \cdot z\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -1.80567192465547634375199356200760357936 \cdot 10^{-55} \lor \neg \left(z \le 8.891798451741654150614573762157279387393 \cdot 10^{-79}\right):\\
\;\;\;\;\left(x \cdot z\right) \cdot y + 1 \cdot \left(x - x \cdot z\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r609443 = x;
        double r609444 = 1.0;
        double r609445 = y;
        double r609446 = r609444 - r609445;
        double r609447 = z;
        double r609448 = r609446 * r609447;
        double r609449 = r609444 - r609448;
        double r609450 = r609443 * r609449;
        return r609450;
}

double f(double x, double y, double z) {
        double r609451 = z;
        double r609452 = -1.8056719246554763e-55;
        bool r609453 = r609451 <= r609452;
        double r609454 = 8.891798451741654e-79;
        bool r609455 = r609451 <= r609454;
        double r609456 = !r609455;
        bool r609457 = r609453 || r609456;
        double r609458 = x;
        double r609459 = r609458 * r609451;
        double r609460 = y;
        double r609461 = r609459 * r609460;
        double r609462 = 1.0;
        double r609463 = r609458 - r609459;
        double r609464 = r609462 * r609463;
        double r609465 = r609461 + r609464;
        double r609466 = r609451 * r609460;
        double r609467 = r609458 * r609466;
        double r609468 = r609467 + r609464;
        double r609469 = r609457 ? r609465 : r609468;
        return r609469;
}

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.4
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \lt -1.618195973607048970493874632750554853795 \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.892237649663902900973248011051357504727 \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 < -1.8056719246554763e-55 or 8.891798451741654e-79 < z

    1. Initial program 6.7

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

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

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

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

    if -1.8056719246554763e-55 < z < 8.891798451741654e-79

    1. Initial program 0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.80567192465547634375199356200760357936 \cdot 10^{-55} \lor \neg \left(z \le 8.891798451741654150614573762157279387393 \cdot 10^{-79}\right):\\ \;\;\;\;\left(x \cdot z\right) \cdot y + 1 \cdot \left(x - x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z \cdot y\right) + 1 \cdot \left(x - x \cdot z\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019208 
(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.618195973607049e50) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 3.8922376496639029e134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x)))))

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