Average Error: 3.4 → 0.1
Time: 15.7s
Precision: 64
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.2944196778946482 \cdot 10^{-05}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot z, \left(x - x \cdot z\right) \cdot 1.0\right)\\ \mathbf{elif}\;z \le 7564588.652142659:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot z, \left(x - x \cdot z\right) \cdot 1.0\right)\\ \end{array}\]
x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -1.2944196778946482 \cdot 10^{-05}:\\
\;\;\;\;\mathsf{fma}\left(y, x \cdot z, \left(x - x \cdot z\right) \cdot 1.0\right)\\

\mathbf{elif}\;z \le 7564588.652142659:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r38073068 = x;
        double r38073069 = 1.0;
        double r38073070 = y;
        double r38073071 = r38073069 - r38073070;
        double r38073072 = z;
        double r38073073 = r38073071 * r38073072;
        double r38073074 = r38073069 - r38073073;
        double r38073075 = r38073068 * r38073074;
        return r38073075;
}

double f(double x, double y, double z) {
        double r38073076 = z;
        double r38073077 = -1.2944196778946482e-05;
        bool r38073078 = r38073076 <= r38073077;
        double r38073079 = y;
        double r38073080 = x;
        double r38073081 = r38073080 * r38073076;
        double r38073082 = r38073080 - r38073081;
        double r38073083 = 1.0;
        double r38073084 = r38073082 * r38073083;
        double r38073085 = fma(r38073079, r38073081, r38073084);
        double r38073086 = 7564588.652142659;
        bool r38073087 = r38073076 <= r38073086;
        double r38073088 = r38073079 - r38073083;
        double r38073089 = fma(r38073076, r38073088, r38073083);
        double r38073090 = r38073080 * r38073089;
        double r38073091 = r38073087 ? r38073090 : r38073085;
        double r38073092 = r38073078 ? r38073085 : r38073091;
        return r38073092;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.4
Target0.2
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{elif}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -1.2944196778946482e-05 or 7564588.652142659 < z

    1. Initial program 8.5

      \[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
    2. Simplified8.5

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt9.7

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}\right)} \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)\]
    5. Applied associate-*l*9.7

      \[\leadsto \color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \left(\sqrt[3]{x} \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)\right)}\]
    6. Taylor expanded around inf 8.5

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

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

    if -1.2944196778946482e-05 < z < 7564588.652142659

    1. Initial program 0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.2944196778946482 \cdot 10^{-05}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot z, \left(x - x \cdot z\right) \cdot 1.0\right)\\ \mathbf{elif}\;z \le 7564588.652142659:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot z, \left(x - x \cdot z\right) \cdot 1.0\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019158 +o rules:numerics
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"

  :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))))