Average Error: 3.3 → 0.6
Time: 12.5s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.604483202204387970419560978992306305207 \cdot 10^{48}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot \left(y - 1\right), x, 1 \cdot x\right)\\ \mathbf{elif}\;x \le 3.089359645532634351223373452505685181748 \cdot 10^{-150}:\\ \;\;\;\;\left(x \cdot \left(y - 1\right)\right) \cdot z + 1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot \left(y - 1\right), x, 1 \cdot x\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -2.604483202204387970419560978992306305207 \cdot 10^{48}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \left(y - 1\right), x, 1 \cdot x\right)\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r34731321 = x;
        double r34731322 = 1.0;
        double r34731323 = y;
        double r34731324 = r34731322 - r34731323;
        double r34731325 = z;
        double r34731326 = r34731324 * r34731325;
        double r34731327 = r34731322 - r34731326;
        double r34731328 = r34731321 * r34731327;
        return r34731328;
}

double f(double x, double y, double z) {
        double r34731329 = x;
        double r34731330 = -2.604483202204388e+48;
        bool r34731331 = r34731329 <= r34731330;
        double r34731332 = z;
        double r34731333 = y;
        double r34731334 = 1.0;
        double r34731335 = r34731333 - r34731334;
        double r34731336 = r34731332 * r34731335;
        double r34731337 = r34731334 * r34731329;
        double r34731338 = fma(r34731336, r34731329, r34731337);
        double r34731339 = 3.0893596455326344e-150;
        bool r34731340 = r34731329 <= r34731339;
        double r34731341 = r34731329 * r34731335;
        double r34731342 = r34731341 * r34731332;
        double r34731343 = r34731342 + r34731337;
        double r34731344 = r34731340 ? r34731343 : r34731338;
        double r34731345 = r34731331 ? r34731338 : r34731344;
        return r34731345;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.3
Target0.3
Herbie0.6
\[\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 x < -2.604483202204388e+48 or 3.0893596455326344e-150 < x

    1. Initial program 1.0

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

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

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

      \[\leadsto \color{blue}{\left(z \cdot \left(y - 1\right)\right) \cdot x + 1 \cdot x}\]
    6. Using strategy rm
    7. Applied fma-def1.0

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

    if -2.604483202204388e+48 < x < 3.0893596455326344e-150

    1. Initial program 5.5

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

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

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

      \[\leadsto \color{blue}{\left(z \cdot \left(y - 1\right)\right) \cdot x + 1 \cdot x}\]
    6. Using strategy rm
    7. Applied associate-*l*0.3

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

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

Reproduce

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