Average Error: 2.9 → 2.9
Time: 14.2s
Precision: 64
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[\mathsf{fma}\left(y - 1.0, z, 1.0\right) \cdot x\]
x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)
\mathsf{fma}\left(y - 1.0, z, 1.0\right) \cdot x
double f(double x, double y, double z) {
        double r36783470 = x;
        double r36783471 = 1.0;
        double r36783472 = y;
        double r36783473 = r36783471 - r36783472;
        double r36783474 = z;
        double r36783475 = r36783473 * r36783474;
        double r36783476 = r36783471 - r36783475;
        double r36783477 = r36783470 * r36783476;
        return r36783477;
}

double f(double x, double y, double z) {
        double r36783478 = y;
        double r36783479 = 1.0;
        double r36783480 = r36783478 - r36783479;
        double r36783481 = z;
        double r36783482 = fma(r36783480, r36783481, r36783479);
        double r36783483 = x;
        double r36783484 = r36783482 * r36783483;
        return r36783484;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original2.9
Target0.2
Herbie2.9
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{elif}\;x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right) \lt 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(1.0 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \end{array}\]

Derivation

  1. Initial program 2.9

    \[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
  2. Simplified2.9

    \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(z, y - 1.0, 1.0\right)}\]
  3. Taylor expanded around 0 2.9

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

    \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(y - 1.0, z, 1.0\right)}\]
  5. Final simplification2.9

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

Reproduce

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