Average Error: 3.4 → 0.3
Time: 21.4s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.3142458593744392 \cdot 10^{-53}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{elif}\;x \le 1.00697876248989277 \cdot 10^{-168}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, z \cdot \left(x \cdot \left(y - 1\right)\right) + \left(1 \cdot \left(x \cdot z\right)\right) \cdot 0\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}\;x \le -5.3142458593744392 \cdot 10^{-53}:\\
\;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\

\mathbf{elif}\;x \le 1.00697876248989277 \cdot 10^{-168}:\\
\;\;\;\;\mathsf{fma}\left(x, 1, z \cdot \left(x \cdot \left(y - 1\right)\right) + \left(1 \cdot \left(x \cdot z\right)\right) \cdot 0\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 r959405 = x;
        double r959406 = 1.0;
        double r959407 = y;
        double r959408 = r959406 - r959407;
        double r959409 = z;
        double r959410 = r959408 * r959409;
        double r959411 = r959406 - r959410;
        double r959412 = r959405 * r959411;
        return r959412;
}

double f(double x, double y, double z) {
        double r959413 = x;
        double r959414 = -5.314245859374439e-53;
        bool r959415 = r959413 <= r959414;
        double r959416 = 1.0;
        double r959417 = y;
        double r959418 = r959416 - r959417;
        double r959419 = z;
        double r959420 = r959418 * r959419;
        double r959421 = r959416 - r959420;
        double r959422 = r959413 * r959421;
        double r959423 = 1.0069787624898928e-168;
        bool r959424 = r959413 <= r959423;
        double r959425 = r959417 - r959416;
        double r959426 = r959413 * r959425;
        double r959427 = r959419 * r959426;
        double r959428 = r959413 * r959419;
        double r959429 = r959416 * r959428;
        double r959430 = 0.0;
        double r959431 = r959429 * r959430;
        double r959432 = r959427 + r959431;
        double r959433 = fma(r959413, r959416, r959432);
        double r959434 = r959428 * r959425;
        double r959435 = fma(r959413, r959416, r959434);
        double r959436 = r959424 ? r959433 : r959435;
        double r959437 = r959415 ? r959422 : r959436;
        return r959437;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.4
Target0.2
Herbie0.3
\[\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 3 regimes
  2. if x < -5.314245859374439e-53

    1. Initial program 0.4

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

    if -5.314245859374439e-53 < x < 1.0069787624898928e-168

    1. Initial program 6.7

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied add-cube-cbrt6.9

      \[\leadsto x \cdot \left(1 - \color{blue}{\left(\left(\sqrt[3]{1 - y} \cdot \sqrt[3]{1 - y}\right) \cdot \sqrt[3]{1 - y}\right)} \cdot z\right)\]
    4. Applied associate-*l*7.0

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

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

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

      \[\leadsto \mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - \color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}\right)\right)\]
    9. Applied add-sqr-sqrt34.3

      \[\leadsto \mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(\color{blue}{\sqrt{y} \cdot \sqrt{y}} - \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}\right)\right)\]
    10. Applied prod-diff34.3

      \[\leadsto \mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{y}, \sqrt{y}, -\sqrt[3]{1} \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)\right) + \mathsf{fma}\left(-\sqrt[3]{1}, \sqrt[3]{1} \cdot \sqrt[3]{1}, \sqrt[3]{1} \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)\right)\right)}\right)\]
    11. Applied distribute-lft-in34.3

      \[\leadsto \mathsf{fma}\left(x, 1, \color{blue}{\left(x \cdot z\right) \cdot \mathsf{fma}\left(\sqrt{y}, \sqrt{y}, -\sqrt[3]{1} \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt[3]{1}, \sqrt[3]{1} \cdot \sqrt[3]{1}, \sqrt[3]{1} \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)\right)}\right)\]
    12. Simplified0.1

      \[\leadsto \mathsf{fma}\left(x, 1, \color{blue}{z \cdot \left(x \cdot \left(y - 1\right)\right)} + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt[3]{1}, \sqrt[3]{1} \cdot \sqrt[3]{1}, \sqrt[3]{1} \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)\right)\right)\]
    13. Simplified0.1

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

    if 1.0069787624898928e-168 < x

    1. Initial program 1.9

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied add-cube-cbrt2.1

      \[\leadsto x \cdot \left(1 - \color{blue}{\left(\left(\sqrt[3]{1 - y} \cdot \sqrt[3]{1 - y}\right) \cdot \sqrt[3]{1 - y}\right)} \cdot z\right)\]
    4. Applied associate-*l*2.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.3142458593744392 \cdot 10^{-53}:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{elif}\;x \le 1.00697876248989277 \cdot 10^{-168}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, z \cdot \left(x \cdot \left(y - 1\right)\right) + \left(1 \cdot \left(x \cdot z\right)\right) \cdot 0\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 2020043 +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))))