Average Error: 3.4 → 0.1
Time: 21.3s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.639188773065111173943924236271911560756 \cdot 10^{-29}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot x, y, 1 \cdot \left(x - z \cdot x\right)\right)\\ \mathbf{elif}\;z \le 5.566768969692308823890016512965200546653 \cdot 10^{-22}:\\ \;\;\;\;x \cdot \left(z \cdot y - 1 \cdot z\right) + 1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot x, y, 1 \cdot \left(x - z \cdot x\right)\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \le -1.639188773065111173943924236271911560756 \cdot 10^{-29}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot x, y, 1 \cdot \left(x - z \cdot x\right)\right)\\

\mathbf{elif}\;z \le 5.566768969692308823890016512965200546653 \cdot 10^{-22}:\\
\;\;\;\;x \cdot \left(z \cdot y - 1 \cdot z\right) + 1 \cdot x\\

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

\end{array}
double f(double x, double y, double z) {
        double r100259489 = x;
        double r100259490 = 1.0;
        double r100259491 = y;
        double r100259492 = r100259490 - r100259491;
        double r100259493 = z;
        double r100259494 = r100259492 * r100259493;
        double r100259495 = r100259490 - r100259494;
        double r100259496 = r100259489 * r100259495;
        return r100259496;
}

double f(double x, double y, double z) {
        double r100259497 = z;
        double r100259498 = -1.6391887730651112e-29;
        bool r100259499 = r100259497 <= r100259498;
        double r100259500 = x;
        double r100259501 = r100259497 * r100259500;
        double r100259502 = y;
        double r100259503 = 1.0;
        double r100259504 = r100259500 - r100259501;
        double r100259505 = r100259503 * r100259504;
        double r100259506 = fma(r100259501, r100259502, r100259505);
        double r100259507 = 5.566768969692309e-22;
        bool r100259508 = r100259497 <= r100259507;
        double r100259509 = r100259497 * r100259502;
        double r100259510 = r100259503 * r100259497;
        double r100259511 = r100259509 - r100259510;
        double r100259512 = r100259500 * r100259511;
        double r100259513 = r100259503 * r100259500;
        double r100259514 = r100259512 + r100259513;
        double r100259515 = r100259508 ? r100259514 : r100259506;
        double r100259516 = r100259499 ? r100259506 : r100259515;
        return r100259516;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.4
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 < -1.6391887730651112e-29 or 5.566768969692309e-22 < z

    1. Initial program 7.7

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

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

      \[\leadsto x \cdot \color{blue}{\left(\left(y - 1\right) \cdot z + 1\right)}\]
    5. Applied distribute-rgt-in7.7

      \[\leadsto \color{blue}{\left(\left(y - 1\right) \cdot z\right) \cdot x + 1 \cdot x}\]
    6. Taylor expanded around inf 7.7

      \[\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(z \cdot x, y, 1 \cdot \left(x - z \cdot x\right)\right)}\]

    if -1.6391887730651112e-29 < z < 5.566768969692309e-22

    1. Initial program 0.1

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

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

      \[\leadsto x \cdot \color{blue}{\left(\left(y - 1\right) \cdot z + 1\right)}\]
    5. Applied distribute-rgt-in0.0

      \[\leadsto \color{blue}{\left(\left(y - 1\right) \cdot z\right) \cdot x + 1 \cdot x}\]
    6. Taylor expanded around inf 0.0

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

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

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

Reproduce

herbie shell --seed 2019173 +o rules:numerics
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"

  :herbie-target
  (if (< (* x (- 1.0 (* (- 1.0 y) z))) -1.618195973607049e+50) (+ x (* (- 1.0 y) (* (- z) x))) (if (< (* x (- 1.0 (* (- 1.0 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1.0 y) (* (- z) x)))))

  (* x (- 1.0 (* (- 1.0 y) z))))