Average Error: 3.4 → 0.2
Time: 11.5s
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):\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \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):\\
\;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r633847 = x;
        double r633848 = 1.0;
        double r633849 = y;
        double r633850 = r633848 - r633849;
        double r633851 = z;
        double r633852 = r633850 * r633851;
        double r633853 = r633848 - r633852;
        double r633854 = r633847 * r633853;
        return r633854;
}

double f(double x, double y, double z) {
        double r633855 = z;
        double r633856 = -1.8056719246554763e-55;
        bool r633857 = r633855 <= r633856;
        double r633858 = 8.891798451741654e-79;
        bool r633859 = r633855 <= r633858;
        double r633860 = !r633859;
        bool r633861 = r633857 || r633860;
        double r633862 = x;
        double r633863 = 1.0;
        double r633864 = r633862 * r633855;
        double r633865 = y;
        double r633866 = r633865 - r633863;
        double r633867 = r633864 * r633866;
        double r633868 = fma(r633862, r633863, r633867);
        double r633869 = fma(r633855, r633866, r633863);
        double r633870 = r633869 * r633862;
        double r633871 = r633861 ? r633868 : r633870;
        return r633871;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

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. Simplified6.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y - 1, 1\right) \cdot x}\]
    3. 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)}\]
    4. Simplified0.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\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. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y - 1, 1\right) \cdot x}\]
  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):\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \end{array}\]

Reproduce

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