Average Error: 3.7 → 0.2
Time: 3.7s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -8.468958278259224291912566289483962982914 \cdot 10^{66}:\\ \;\;\;\;x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - 1\right)\\ \mathbf{elif}\;z \le 19144349.1059049777686595916748046875:\\ \;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot \left(y - 1\right)\right) \cdot z\right) + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -8.468958278259224291912566289483962982914 \cdot 10^{66}:\\
\;\;\;\;x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - 1\right)\\

\mathbf{elif}\;z \le 19144349.1059049777686595916748046875:\\
\;\;\;\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r772168 = x;
        double r772169 = 1.0;
        double r772170 = y;
        double r772171 = r772169 - r772170;
        double r772172 = z;
        double r772173 = r772171 * r772172;
        double r772174 = r772169 - r772173;
        double r772175 = r772168 * r772174;
        return r772175;
}

double f(double x, double y, double z) {
        double r772176 = z;
        double r772177 = -8.468958278259224e+66;
        bool r772178 = r772176 <= r772177;
        double r772179 = x;
        double r772180 = 1.0;
        double r772181 = r772179 * r772180;
        double r772182 = r772179 * r772176;
        double r772183 = y;
        double r772184 = r772183 - r772180;
        double r772185 = r772182 * r772184;
        double r772186 = r772181 + r772185;
        double r772187 = 19144349.105904978;
        bool r772188 = r772176 <= r772187;
        double r772189 = r772180 - r772183;
        double r772190 = r772189 * r772176;
        double r772191 = r772180 - r772190;
        double r772192 = r772179 * r772191;
        double r772193 = r772179 * r772184;
        double r772194 = r772193 * r772176;
        double r772195 = fma(r772179, r772180, r772194);
        double r772196 = sqrt(r772180);
        double r772197 = -r772196;
        double r772198 = r772196 * r772196;
        double r772199 = fma(r772197, r772196, r772198);
        double r772200 = r772182 * r772199;
        double r772201 = r772195 + r772200;
        double r772202 = r772188 ? r772192 : r772201;
        double r772203 = r772178 ? r772186 : r772202;
        return r772203;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.7
Target0.2
Herbie0.2
\[\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 z < -8.468958278259224e+66

    1. Initial program 11.9

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

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

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

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

    if -8.468958278259224e+66 < z < 19144349.105904978

    1. Initial program 0.3

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

    if 19144349.105904978 < z

    1. Initial program 9.7

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
    2. Using strategy rm
    3. Applied sub-neg9.7

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

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

      \[\leadsto x \cdot 1 + \color{blue}{\left(x \cdot z\right) \cdot \left(y - 1\right)}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt0.1

      \[\leadsto x \cdot 1 + \left(x \cdot z\right) \cdot \left(y - \color{blue}{\sqrt{1} \cdot \sqrt{1}}\right)\]
    8. Applied add-cube-cbrt0.5

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 1, \mathsf{fma}\left(\sqrt[3]{y} \cdot \sqrt[3]{y}, \sqrt[3]{y}, -1 \cdot 1\right) \cdot \left(x \cdot z\right)\right)} + \left(x \cdot z\right) \cdot \mathsf{fma}\left(-\sqrt{1}, \sqrt{1}, \sqrt{1} \cdot \sqrt{1}\right)\]
    13. Using strategy rm
    14. Applied associate-*r*0.5

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

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

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

Reproduce

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