Average Error: 3.2 → 0.1
Time: 13.7s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -457939898.35897481441497802734375 \lor \neg \left(z \le 4.150175584430486936334444407897583336401 \cdot 10^{-41}\right):\\ \;\;\;\;\left(y - 1\right) \cdot \left(x \cdot z\right) + x \cdot 1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1, 1\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -457939898.35897481441497802734375 \lor \neg \left(z \le 4.150175584430486936334444407897583336401 \cdot 10^{-41}\right):\\
\;\;\;\;\left(y - 1\right) \cdot \left(x \cdot z\right) + x \cdot 1\\

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

\end{array}
double f(double x, double y, double z) {
        double r686965 = x;
        double r686966 = 1.0;
        double r686967 = y;
        double r686968 = r686966 - r686967;
        double r686969 = z;
        double r686970 = r686968 * r686969;
        double r686971 = r686966 - r686970;
        double r686972 = r686965 * r686971;
        return r686972;
}

double f(double x, double y, double z) {
        double r686973 = z;
        double r686974 = -457939898.3589748;
        bool r686975 = r686973 <= r686974;
        double r686976 = 4.150175584430487e-41;
        bool r686977 = r686973 <= r686976;
        double r686978 = !r686977;
        bool r686979 = r686975 || r686978;
        double r686980 = y;
        double r686981 = 1.0;
        double r686982 = r686980 - r686981;
        double r686983 = x;
        double r686984 = r686983 * r686973;
        double r686985 = r686982 * r686984;
        double r686986 = r686983 * r686981;
        double r686987 = r686985 + r686986;
        double r686988 = fma(r686973, r686982, r686981);
        double r686989 = r686983 * r686988;
        double r686990 = r686979 ? r686987 : r686989;
        return r686990;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.2
Target0.3
Herbie0.1
\[\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 < -457939898.3589748 or 4.150175584430487e-41 < z

    1. Initial program 7.3

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Simplified7.3

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

      \[\leadsto x \cdot \color{blue}{\left(z \cdot \left(y - 1\right) + 1\right)}\]
    5. Applied distribute-lft-in7.3

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

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

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

    if -457939898.3589748 < z < 4.150175584430487e-41

    1. Initial program 0.1

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

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

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

Reproduce

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