Average Error: 2.0 → 2.0
Time: 8.4s
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 r592652 = x;
        double r592653 = y;
        double r592654 = z;
        double r592655 = r592653 * r592654;
        double r592656 = r592652 + r592655;
        double r592657 = t;
        double r592658 = a;
        double r592659 = r592657 * r592658;
        double r592660 = r592656 + r592659;
        double r592661 = r592658 * r592654;
        double r592662 = b;
        double r592663 = r592661 * r592662;
        double r592664 = r592660 + r592663;
        return r592664;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r592665 = a;
        double r592666 = t;
        double r592667 = z;
        double r592668 = y;
        double r592669 = x;
        double r592670 = fma(r592667, r592668, r592669);
        double r592671 = fma(r592665, r592666, r592670);
        double r592672 = r592665 * r592667;
        double r592673 = b;
        double r592674 = r592672 * r592673;
        double r592675 = r592671 + r592674;
        return r592675;
}

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)))