Average Error: 2.2 → 1.2
Time: 2.8s
Precision: 64
\[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.65029912159400242 \cdot 10^{34}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\\ \end{array}\]
\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b
\begin{array}{l}
\mathbf{if}\;z \le -2.65029912159400242 \cdot 10^{34}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r607952 = x;
        double r607953 = y;
        double r607954 = z;
        double r607955 = r607953 * r607954;
        double r607956 = r607952 + r607955;
        double r607957 = t;
        double r607958 = a;
        double r607959 = r607957 * r607958;
        double r607960 = r607956 + r607959;
        double r607961 = r607958 * r607954;
        double r607962 = b;
        double r607963 = r607961 * r607962;
        double r607964 = r607960 + r607963;
        return r607964;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r607965 = z;
        double r607966 = -2.6502991215940024e+34;
        bool r607967 = r607965 <= r607966;
        double r607968 = a;
        double r607969 = b;
        double r607970 = y;
        double r607971 = fma(r607968, r607969, r607970);
        double r607972 = t;
        double r607973 = x;
        double r607974 = fma(r607968, r607972, r607973);
        double r607975 = fma(r607971, r607965, r607974);
        double r607976 = r607970 * r607965;
        double r607977 = r607973 + r607976;
        double r607978 = r607968 * r607965;
        double r607979 = r607978 * r607969;
        double r607980 = fma(r607972, r607968, r607979);
        double r607981 = r607977 + r607980;
        double r607982 = r607967 ? r607975 : r607981;
        return r607982;
}

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.2
Target0.3
Herbie1.2
\[\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. Split input into 2 regimes
  2. if z < -2.6502991215940024e+34

    1. Initial program 6.6

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
    2. Simplified0.1

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

    if -2.6502991215940024e+34 < z

    1. Initial program 1.4

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
    2. Using strategy rm
    3. Applied associate-+l+1.4

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

      \[\leadsto \left(x + y \cdot z\right) + \color{blue}{\mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.65029912159400242 \cdot 10^{34}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\\ \end{array}\]

Reproduce

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