Average Error: 3.8 → 0.2
Time: 16.0s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.600969880228342920976272849628587488737 \cdot 10^{-53} \lor \neg \left(x \le 3.769791437536624736866992851934661493425 \cdot 10^{-38}\right):\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x + \left(\left(-z \cdot \left(1 \cdot x\right)\right) + z \cdot \left(y \cdot x\right)\right)\\ \end{array}\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;x \le -2.600969880228342920976272849628587488737 \cdot 10^{-53} \lor \neg \left(x \le 3.769791437536624736866992851934661493425 \cdot 10^{-38}\right):\\
\;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\

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

\end{array}
double f(double x, double y, double z) {
        double r1205319 = x;
        double r1205320 = 1.0;
        double r1205321 = y;
        double r1205322 = r1205320 - r1205321;
        double r1205323 = z;
        double r1205324 = r1205322 * r1205323;
        double r1205325 = r1205320 - r1205324;
        double r1205326 = r1205319 * r1205325;
        return r1205326;
}

double f(double x, double y, double z) {
        double r1205327 = x;
        double r1205328 = -2.600969880228343e-53;
        bool r1205329 = r1205327 <= r1205328;
        double r1205330 = 3.7697914375366247e-38;
        bool r1205331 = r1205327 <= r1205330;
        double r1205332 = !r1205331;
        bool r1205333 = r1205329 || r1205332;
        double r1205334 = z;
        double r1205335 = y;
        double r1205336 = 1.0;
        double r1205337 = r1205335 - r1205336;
        double r1205338 = fma(r1205334, r1205337, r1205336);
        double r1205339 = r1205338 * r1205327;
        double r1205340 = r1205336 * r1205327;
        double r1205341 = r1205334 * r1205340;
        double r1205342 = -r1205341;
        double r1205343 = r1205335 * r1205327;
        double r1205344 = r1205334 * r1205343;
        double r1205345 = r1205342 + r1205344;
        double r1205346 = r1205340 + r1205345;
        double r1205347 = r1205333 ? r1205339 : r1205346;
        return r1205347;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.8
Target0.2
Herbie0.2
\[\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.600969880228343e-53 or 3.7697914375366247e-38 < x

    1. Initial program 0.3

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

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

    if -2.600969880228343e-53 < x < 3.7697914375366247e-38

    1. Initial program 6.9

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

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

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

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

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

      \[\leadsto \left(x \cdot z\right) \cdot \left(y - 1\right) + \color{blue}{1 \cdot x}\]
    8. Using strategy rm
    9. Applied sub-neg2.9

      \[\leadsto \left(x \cdot z\right) \cdot \color{blue}{\left(y + \left(-1\right)\right)} + 1 \cdot x\]
    10. Applied distribute-lft-in2.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.600969880228342920976272849628587488737 \cdot 10^{-53} \lor \neg \left(x \le 3.769791437536624736866992851934661493425 \cdot 10^{-38}\right):\\ \;\;\;\;\mathsf{fma}\left(z, y - 1, 1\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x + \left(\left(-z \cdot \left(1 \cdot x\right)\right) + z \cdot \left(y \cdot x\right)\right)\\ \end{array}\]

Reproduce

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