Average Error: 3.3 → 3.3
Time: 1.1m
Precision: 64
\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\]
\[x \cdot \mathsf{fma}\left(z, y - 1, 1\right)\]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
x \cdot \mathsf{fma}\left(z, y - 1, 1\right)
double f(double x, double y, double z) {
        double r38010930 = x;
        double r38010931 = 1.0;
        double r38010932 = y;
        double r38010933 = r38010931 - r38010932;
        double r38010934 = z;
        double r38010935 = r38010933 * r38010934;
        double r38010936 = r38010931 - r38010935;
        double r38010937 = r38010930 * r38010936;
        return r38010937;
}

double f(double x, double y, double z) {
        double r38010938 = x;
        double r38010939 = z;
        double r38010940 = y;
        double r38010941 = 1.0;
        double r38010942 = r38010940 - r38010941;
        double r38010943 = fma(r38010939, r38010942, r38010941);
        double r38010944 = r38010938 * r38010943;
        return r38010944;
}

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 - \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.3

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

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

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

Reproduce

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