Average Error: 3.7 → 0.1
Time: 15.5s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.171186142257821738930075961762293489096 \cdot 10^{-22}:\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \mathbf{elif}\;x \le 3.384200571349336964958405078165718304511 \cdot 10^{-78}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(-1, 1, 1\right), 1\right) + z \cdot \left(x \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x + \left(y - 1\right) \cdot \left(z \cdot x\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -4.171186142257821738930075961762293489096 \cdot 10^{-22}:\\
\;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\

\mathbf{elif}\;x \le 3.384200571349336964958405078165718304511 \cdot 10^{-78}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(-1, 1, 1\right), 1\right) + z \cdot \left(x \cdot \left(y - 1\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r34171105 = x;
        double r34171106 = 1.0;
        double r34171107 = y;
        double r34171108 = r34171106 - r34171107;
        double r34171109 = z;
        double r34171110 = r34171108 * r34171109;
        double r34171111 = r34171106 - r34171110;
        double r34171112 = r34171105 * r34171111;
        return r34171112;
}

double f(double x, double y, double z) {
        double r34171113 = x;
        double r34171114 = -4.1711861422578217e-22;
        bool r34171115 = r34171113 <= r34171114;
        double r34171116 = z;
        double r34171117 = y;
        double r34171118 = 1.0;
        double r34171119 = r34171117 - r34171118;
        double r34171120 = fma(r34171116, r34171119, r34171118);
        double r34171121 = r34171120 * r34171113;
        double r34171122 = 3.384200571349337e-78;
        bool r34171123 = r34171113 <= r34171122;
        double r34171124 = -1.0;
        double r34171125 = fma(r34171124, r34171118, r34171118);
        double r34171126 = fma(r34171116, r34171125, r34171118);
        double r34171127 = r34171113 * r34171126;
        double r34171128 = r34171113 * r34171119;
        double r34171129 = r34171116 * r34171128;
        double r34171130 = r34171127 + r34171129;
        double r34171131 = r34171118 * r34171113;
        double r34171132 = r34171116 * r34171113;
        double r34171133 = r34171119 * r34171132;
        double r34171134 = r34171131 + r34171133;
        double r34171135 = r34171123 ? r34171130 : r34171134;
        double r34171136 = r34171115 ? r34171121 : r34171135;
        return r34171136;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.7
Target0.2
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 3 regimes
  2. if x < -4.1711861422578217e-22

    1. Initial program 0.2

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

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

    if -4.1711861422578217e-22 < x < 3.384200571349337e-78

    1. Initial program 6.9

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

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

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

      \[\leadsto \color{blue}{x \cdot \left(z \cdot \left(y - 1\right)\right) + x \cdot 1}\]
    6. Using strategy rm
    7. Applied associate-*r*3.0

      \[\leadsto \color{blue}{\left(x \cdot z\right) \cdot \left(y - 1\right)} + x \cdot 1\]
    8. Using strategy rm
    9. Applied *-un-lft-identity3.0

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

      \[\leadsto \left(x \cdot z\right) \cdot \left(\color{blue}{\left(\sqrt[3]{y} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{y}} - 1 \cdot 1\right) + x \cdot 1\]
    11. Applied prod-diff3.4

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

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

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

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

      \[\leadsto \left(x \cdot z\right) \cdot \color{blue}{{\left(\mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -1 \cdot 1\right)\right)}^{1}} + x \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(-1, 1, 1\right), 1\right)\]
    17. Applied pow13.4

      \[\leadsto \left(x \cdot \color{blue}{{z}^{1}}\right) \cdot {\left(\mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -1 \cdot 1\right)\right)}^{1} + x \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(-1, 1, 1\right), 1\right)\]
    18. Applied pow13.4

      \[\leadsto \left(\color{blue}{{x}^{1}} \cdot {z}^{1}\right) \cdot {\left(\mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -1 \cdot 1\right)\right)}^{1} + x \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(-1, 1, 1\right), 1\right)\]
    19. Applied pow-prod-down3.4

      \[\leadsto \color{blue}{{\left(x \cdot z\right)}^{1}} \cdot {\left(\mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -1 \cdot 1\right)\right)}^{1} + x \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(-1, 1, 1\right), 1\right)\]
    20. Applied pow-prod-down3.4

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

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

    if 3.384200571349337e-78 < x

    1. Initial program 0.7

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

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

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

      \[\leadsto \color{blue}{x \cdot \left(z \cdot \left(y - 1\right)\right) + x \cdot 1}\]
    6. Using strategy rm
    7. Applied associate-*r*0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.171186142257821738930075961762293489096 \cdot 10^{-22}:\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \mathbf{elif}\;x \le 3.384200571349336964958405078165718304511 \cdot 10^{-78}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(-1, 1, 1\right), 1\right) + z \cdot \left(x \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x + \left(y - 1\right) \cdot \left(z \cdot x\right)\\ \end{array}\]

Reproduce

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