Average Error: 3.3 → 0.4
Time: 3.9s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.6801859900765786 \cdot 10^{35} \lor \neg \left(z \le 1.7138503459389252 \cdot 10^{-131}\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 -2.6801859900765786 \cdot 10^{35} \lor \neg \left(z \le 1.7138503459389252 \cdot 10^{-131}\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 r848367 = x;
        double r848368 = 1.0;
        double r848369 = y;
        double r848370 = r848368 - r848369;
        double r848371 = z;
        double r848372 = r848370 * r848371;
        double r848373 = r848368 - r848372;
        double r848374 = r848367 * r848373;
        return r848374;
}

double f(double x, double y, double z) {
        double r848375 = z;
        double r848376 = -2.6801859900765786e+35;
        bool r848377 = r848375 <= r848376;
        double r848378 = 1.7138503459389252e-131;
        bool r848379 = r848375 <= r848378;
        double r848380 = !r848379;
        bool r848381 = r848377 || r848380;
        double r848382 = x;
        double r848383 = 1.0;
        double r848384 = r848382 * r848375;
        double r848385 = y;
        double r848386 = r848385 - r848383;
        double r848387 = r848384 * r848386;
        double r848388 = fma(r848382, r848383, r848387);
        double r848389 = fma(r848386, r848375, r848383);
        double r848390 = r848389 * r848382;
        double r848391 = r848381 ? r848388 : r848390;
        return r848391;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.3
Target0.2
Herbie0.4
\[\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 < -2.6801859900765786e+35 or 1.7138503459389252e-131 < z

    1. Initial program 6.5

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

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

      \[\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*7.7

      \[\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 6.5

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

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

    if -2.6801859900765786e+35 < z < 1.7138503459389252e-131

    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.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.6801859900765786 \cdot 10^{35} \lor \neg \left(z \le 1.7138503459389252 \cdot 10^{-131}\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 2020056 +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))))