Average Error: 3.6 → 0.1
Time: 3.0s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -7.58275849651710822 \cdot 10^{-51} \lor \neg \left(z \le 2.6215325656918873 \cdot 10^{-23}\right):\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - 1, z, 1\right) \cdot x\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -7.58275849651710822 \cdot 10^{-51} \lor \neg \left(z \le 2.6215325656918873 \cdot 10^{-23}\right):\\
\;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r838778 = x;
        double r838779 = 1.0;
        double r838780 = y;
        double r838781 = r838779 - r838780;
        double r838782 = z;
        double r838783 = r838781 * r838782;
        double r838784 = r838779 - r838783;
        double r838785 = r838778 * r838784;
        return r838785;
}

double f(double x, double y, double z) {
        double r838786 = z;
        double r838787 = -7.582758496517108e-51;
        bool r838788 = r838786 <= r838787;
        double r838789 = 2.6215325656918873e-23;
        bool r838790 = r838786 <= r838789;
        double r838791 = !r838790;
        bool r838792 = r838788 || r838791;
        double r838793 = x;
        double r838794 = 1.0;
        double r838795 = r838793 * r838786;
        double r838796 = y;
        double r838797 = r838796 - r838794;
        double r838798 = r838795 * r838797;
        double r838799 = fma(r838793, r838794, r838798);
        double r838800 = fma(r838797, r838786, r838794);
        double r838801 = r838800 * r838793;
        double r838802 = r838792 ? r838799 : r838801;
        return r838802;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.6
Target0.2
Herbie0.1
\[\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 2 regimes
  2. if z < -7.582758496517108e-51 or 2.6215325656918873e-23 < z

    1. Initial program 7.7

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

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

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

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

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

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

    if -7.582758496517108e-51 < z < 2.6215325656918873e-23

    1. Initial program 0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -7.58275849651710822 \cdot 10^{-51} \lor \neg \left(z \le 2.6215325656918873 \cdot 10^{-23}\right):\\ \;\;\;\;\mathsf{fma}\left(x, 1, \left(x \cdot z\right) \cdot \left(y - 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - 1, z, 1\right) \cdot x\\ \end{array}\]

Reproduce

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