Average Error: 3.4 → 1.4
Time: 15.2s
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[\mathsf{fma}\left(x \cdot z, y - 1, 1 \cdot x\right)\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\mathsf{fma}\left(x \cdot z, y - 1, 1 \cdot x\right)
double f(double x, double y, double z) {
        double r32436562 = x;
        double r32436563 = 1.0;
        double r32436564 = y;
        double r32436565 = r32436563 - r32436564;
        double r32436566 = z;
        double r32436567 = r32436565 * r32436566;
        double r32436568 = r32436563 - r32436567;
        double r32436569 = r32436562 * r32436568;
        return r32436569;
}

double f(double x, double y, double z) {
        double r32436570 = x;
        double r32436571 = z;
        double r32436572 = r32436570 * r32436571;
        double r32436573 = y;
        double r32436574 = 1.0;
        double r32436575 = r32436573 - r32436574;
        double r32436576 = r32436574 * r32436570;
        double r32436577 = fma(r32436572, r32436575, r32436576);
        return r32436577;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.4
Target0.3
Herbie1.4
\[\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. Initial program 3.4

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, y - 1, 1\right) \cdot x}\]
  5. Taylor expanded around inf 3.4

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

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

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

Reproduce

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