Average Error: 3.2 → 0.1
Time: 3.8s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -29706158508458240 \lor \neg \left(z \le 2.646668377626094194071257532149127333909 \cdot 10^{-8}\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 -29706158508458240 \lor \neg \left(z \le 2.646668377626094194071257532149127333909 \cdot 10^{-8}\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 r745284 = x;
        double r745285 = 1.0;
        double r745286 = y;
        double r745287 = r745285 - r745286;
        double r745288 = z;
        double r745289 = r745287 * r745288;
        double r745290 = r745285 - r745289;
        double r745291 = r745284 * r745290;
        return r745291;
}

double f(double x, double y, double z) {
        double r745292 = z;
        double r745293 = -2.970615850845824e+16;
        bool r745294 = r745292 <= r745293;
        double r745295 = 2.6466683776260942e-08;
        bool r745296 = r745292 <= r745295;
        double r745297 = !r745296;
        bool r745298 = r745294 || r745297;
        double r745299 = x;
        double r745300 = 1.0;
        double r745301 = r745299 * r745292;
        double r745302 = y;
        double r745303 = r745302 - r745300;
        double r745304 = r745301 * r745303;
        double r745305 = fma(r745299, r745300, r745304);
        double r745306 = fma(r745303, r745292, r745300);
        double r745307 = r745306 * r745299;
        double r745308 = r745298 ? r745305 : r745307;
        return r745308;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.2
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 2 regimes
  2. if z < -2.970615850845824e+16 or 2.6466683776260942e-08 < z

    1. Initial program 8.2

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

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

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

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

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

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

    if -2.970615850845824e+16 < z < 2.6466683776260942e-08

    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 -29706158508458240 \lor \neg \left(z \le 2.646668377626094194071257532149127333909 \cdot 10^{-8}\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 2019353 +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))))