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

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

\end{array}
double f(double x, double y, double z) {
        double r33524096 = x;
        double r33524097 = 1.0;
        double r33524098 = y;
        double r33524099 = r33524097 - r33524098;
        double r33524100 = z;
        double r33524101 = r33524099 * r33524100;
        double r33524102 = r33524097 - r33524101;
        double r33524103 = r33524096 * r33524102;
        return r33524103;
}

double f(double x, double y, double z) {
        double r33524104 = y;
        double r33524105 = -1.77126585659422e+280;
        bool r33524106 = r33524104 <= r33524105;
        double r33524107 = x;
        double r33524108 = z;
        double r33524109 = 1.0;
        double r33524110 = r33524104 - r33524109;
        double r33524111 = fma(r33524108, r33524110, r33524109);
        double r33524112 = r33524107 * r33524111;
        double r33524113 = r33524107 * r33524108;
        double r33524114 = r33524113 * r33524110;
        double r33524115 = fma(r33524107, r33524109, r33524114);
        double r33524116 = r33524106 ? r33524112 : r33524115;
        return r33524116;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.8
Target0.2
Herbie1.7
\[\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 < -1.77126585659422e+280

    1. Initial program 16.0

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

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

    if -1.77126585659422e+280 < y

    1. Initial program 3.6

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

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

      \[\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. Using strategy rm
    6. Applied add-cube-cbrt4.9

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}\right)} \cdot \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)\]
    7. Applied associate-*l*4.9

      \[\leadsto \color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \left(\sqrt[3]{x} \cdot \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)\right)}\]
    8. Simplified4.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.771265856594219962128151511977091593235 \cdot 10^{280}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, y - 1, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\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))))