Average Error: 2.0 → 2.0
Time: 8.1s
Precision: 64
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
\[\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right) + \left(a \cdot z\right) \cdot b\]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right) + \left(a \cdot z\right) \cdot b
double f(double x, double y, double z, double t, double a, double b) {
        double r658732 = x;
        double r658733 = y;
        double r658734 = z;
        double r658735 = r658733 * r658734;
        double r658736 = r658732 + r658735;
        double r658737 = t;
        double r658738 = a;
        double r658739 = r658737 * r658738;
        double r658740 = r658736 + r658739;
        double r658741 = r658738 * r658734;
        double r658742 = b;
        double r658743 = r658741 * r658742;
        double r658744 = r658740 + r658743;
        return r658744;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r658745 = a;
        double r658746 = t;
        double r658747 = z;
        double r658748 = y;
        double r658749 = x;
        double r658750 = fma(r658747, r658748, r658749);
        double r658751 = fma(r658745, r658746, r658750);
        double r658752 = r658745 * r658747;
        double r658753 = b;
        double r658754 = r658752 * r658753;
        double r658755 = r658751 + r658754;
        return r658755;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Target

Original2.0
Target0.4
Herbie2.0
\[\begin{array}{l} \mathbf{if}\;z \lt -11820553527347888000:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z \lt 4.75897431883642871 \cdot 10^{-122}:\\ \;\;\;\;\left(b \cdot z + t\right) \cdot a + \left(z \cdot y + x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \end{array}\]

Derivation

  1. Initial program 2.0

    \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
  2. Taylor expanded around inf 2.0

    \[\leadsto \color{blue}{\left(z \cdot y + \left(x + a \cdot t\right)\right)} + \left(a \cdot z\right) \cdot b\]
  3. Simplified2.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right)} + \left(a \cdot z\right) \cdot b\]
  4. Final simplification2.0

    \[\leadsto \mathsf{fma}\left(a, t, \mathsf{fma}\left(z, y, x\right)\right) + \left(a \cdot z\right) \cdot b\]

Reproduce

herbie shell --seed 2020045 +o rules:numerics
(FPCore (x y z t a b)
  :name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"
  :precision binary64

  :herbie-target
  (if (< z -11820553527347888000) (+ (* z (+ (* b a) y)) (+ x (* t a))) (if (< z 4.7589743188364287e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))

  (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))