Average Error: 3.4 → 1.9
Time: 3.6s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le 35608010353305148:\\ \;\;\;\;\mathsf{fma}\left(y - 1, z, 1\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot z, y - 1, 1 \cdot x\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le 35608010353305148:\\
\;\;\;\;\mathsf{fma}\left(y - 1, z, 1\right) \cdot x\\

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

\end{array}
double f(double x, double y, double z) {
        double r754946 = x;
        double r754947 = 1.0;
        double r754948 = y;
        double r754949 = r754947 - r754948;
        double r754950 = z;
        double r754951 = r754949 * r754950;
        double r754952 = r754947 - r754951;
        double r754953 = r754946 * r754952;
        return r754953;
}

double f(double x, double y, double z) {
        double r754954 = z;
        double r754955 = 35608010353305148.0;
        bool r754956 = r754954 <= r754955;
        double r754957 = y;
        double r754958 = 1.0;
        double r754959 = r754957 - r754958;
        double r754960 = fma(r754959, r754954, r754958);
        double r754961 = x;
        double r754962 = r754960 * r754961;
        double r754963 = r754961 * r754954;
        double r754964 = r754958 * r754961;
        double r754965 = fma(r754963, r754959, r754964);
        double r754966 = r754956 ? r754962 : r754965;
        return r754966;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.4
Target0.2
Herbie1.9
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \lt -1.618195973607049 \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.8922376496639029 \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 < 35608010353305148.0

    1. Initial program 2.3

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

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

    if 35608010353305148.0 < z

    1. Initial program 8.5

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

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

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

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

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

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

Reproduce

herbie shell --seed 2020035 +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.618195973607049e+50) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x)))))

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