Average Error: 3.3 → 3.3
Time: 16.8s
Precision: 64
\[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
\[\mathsf{fma}\left(z, y - 1.0, 1.0\right) \cdot x\]
x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)
\mathsf{fma}\left(z, y - 1.0, 1.0\right) \cdot x
double f(double x, double y, double z) {
        double r26960548 = x;
        double r26960549 = 1.0;
        double r26960550 = y;
        double r26960551 = r26960549 - r26960550;
        double r26960552 = z;
        double r26960553 = r26960551 * r26960552;
        double r26960554 = r26960549 - r26960553;
        double r26960555 = r26960548 * r26960554;
        return r26960555;
}

double f(double x, double y, double z) {
        double r26960556 = z;
        double r26960557 = y;
        double r26960558 = 1.0;
        double r26960559 = r26960557 - r26960558;
        double r26960560 = fma(r26960556, r26960559, r26960558);
        double r26960561 = x;
        double r26960562 = r26960560 * r26960561;
        return r26960562;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original3.3
Target0.2
Herbie3.3
\[\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 3.3

    \[x \cdot \left(1.0 - \left(1.0 - y\right) \cdot z\right)\]
  2. Simplified3.3

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

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

Reproduce

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