Average Error: 3.8 → 1.8
Time: 12.9s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.66140484112631331502718790303648000995 \cdot 10^{259}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot z, y - 1, x \cdot 1\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;y \le -2.66140484112631331502718790303648000995 \cdot 10^{259}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1, 1\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r30404862 = x;
        double r30404863 = 1.0;
        double r30404864 = y;
        double r30404865 = r30404863 - r30404864;
        double r30404866 = z;
        double r30404867 = r30404865 * r30404866;
        double r30404868 = r30404863 - r30404867;
        double r30404869 = r30404862 * r30404868;
        return r30404869;
}

double f(double x, double y, double z) {
        double r30404870 = y;
        double r30404871 = -2.6614048411263133e+259;
        bool r30404872 = r30404870 <= r30404871;
        double r30404873 = x;
        double r30404874 = z;
        double r30404875 = 1.0;
        double r30404876 = r30404870 - r30404875;
        double r30404877 = fma(r30404874, r30404876, r30404875);
        double r30404878 = r30404873 * r30404877;
        double r30404879 = r30404873 * r30404874;
        double r30404880 = r30404873 * r30404875;
        double r30404881 = fma(r30404879, r30404876, r30404880);
        double r30404882 = r30404872 ? r30404878 : r30404881;
        return r30404882;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.8
Target0.2
Herbie1.8
\[\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 y < -2.6614048411263133e+259

    1. Initial program 16.6

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

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

    if -2.6614048411263133e+259 < y

    1. Initial program 3.4

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.66140484112631331502718790303648000995 \cdot 10^{259}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot z, y - 1, x \cdot 1\right)\\ \end{array}\]

Reproduce

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