Average Error: 3.7 → 0.2
Time: 3.6s
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 r816803 = x;
        double r816804 = 1.0;
        double r816805 = y;
        double r816806 = r816804 - r816805;
        double r816807 = z;
        double r816808 = r816806 * r816807;
        double r816809 = r816804 - r816808;
        double r816810 = r816803 * r816809;
        return r816810;
}

double f(double x, double y, double z) {
        double r816811 = z;
        double r816812 = -8.468958278259224e+66;
        bool r816813 = r816811 <= r816812;
        double r816814 = x;
        double r816815 = 1.0;
        double r816816 = r816814 * r816815;
        double r816817 = r816814 * r816811;
        double r816818 = y;
        double r816819 = r816818 - r816815;
        double r816820 = r816817 * r816819;
        double r816821 = r816816 + r816820;
        double r816822 = 19144349.105904978;
        bool r816823 = r816811 <= r816822;
        double r816824 = r816815 - r816818;
        double r816825 = r816824 * r816811;
        double r816826 = r816815 - r816825;
        double r816827 = r816814 * r816826;
        double r816828 = r816814 * r816819;
        double r816829 = r816828 * r816811;
        double r816830 = fma(r816814, r816815, r816829);
        double r816831 = sqrt(r816815);
        double r816832 = -r816831;
        double r816833 = r816831 * r816831;
        double r816834 = fma(r816832, r816831, r816833);
        double r816835 = r816817 * r816834;
        double r816836 = r816830 + r816835;
        double r816837 = r816823 ? r816827 : r816836;
        double r816838 = r816813 ? r816821 : r816837;
        return r816838;
}

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))))