Average Error: 2.1 → 2.0
Time: 13.4s
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}\;y \le -4.266832387722162 \cdot 10^{-303}:\\ \;\;\;\;\left(z \cdot a\right) \cdot b + \left(\left(x + z \cdot y\right) + t \cdot a\right)\\ \mathbf{elif}\;y \le 2.4536070897035704 \cdot 10^{-54}:\\ \;\;\;\;\mathsf{fma}\left(t, a, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot a\right) \cdot b + \left(\left(x + z \cdot y\right) + t \cdot a\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}\;y \le -4.266832387722162 \cdot 10^{-303}:\\
\;\;\;\;\left(z \cdot a\right) \cdot b + \left(\left(x + z \cdot y\right) + t \cdot a\right)\\

\mathbf{elif}\;y \le 2.4536070897035704 \cdot 10^{-54}:\\
\;\;\;\;\mathsf{fma}\left(t, a, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), x\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r19682963 = x;
        double r19682964 = y;
        double r19682965 = z;
        double r19682966 = r19682964 * r19682965;
        double r19682967 = r19682963 + r19682966;
        double r19682968 = t;
        double r19682969 = a;
        double r19682970 = r19682968 * r19682969;
        double r19682971 = r19682967 + r19682970;
        double r19682972 = r19682969 * r19682965;
        double r19682973 = b;
        double r19682974 = r19682972 * r19682973;
        double r19682975 = r19682971 + r19682974;
        return r19682975;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r19682976 = y;
        double r19682977 = -4.266832387722162e-303;
        bool r19682978 = r19682976 <= r19682977;
        double r19682979 = z;
        double r19682980 = a;
        double r19682981 = r19682979 * r19682980;
        double r19682982 = b;
        double r19682983 = r19682981 * r19682982;
        double r19682984 = x;
        double r19682985 = r19682979 * r19682976;
        double r19682986 = r19682984 + r19682985;
        double r19682987 = t;
        double r19682988 = r19682987 * r19682980;
        double r19682989 = r19682986 + r19682988;
        double r19682990 = r19682983 + r19682989;
        double r19682991 = 2.4536070897035704e-54;
        bool r19682992 = r19682976 <= r19682991;
        double r19682993 = fma(r19682980, r19682982, r19682976);
        double r19682994 = fma(r19682979, r19682993, r19682984);
        double r19682995 = fma(r19682987, r19682980, r19682994);
        double r19682996 = r19682992 ? r19682995 : r19682990;
        double r19682997 = r19682978 ? r19682990 : r19682996;
        return r19682997;
}

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.1
Target0.4
Herbie2.0
\[\begin{array}{l} \mathbf{if}\;z \lt -1.1820553527347888 \cdot 10^{+19}:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z \lt 4.7589743188364287 \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 y < -4.266832387722162e-303 or 2.4536070897035704e-54 < y

    1. Initial program 1.8

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]

    if -4.266832387722162e-303 < y < 2.4536070897035704e-54

    1. Initial program 3.1

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

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

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

Reproduce

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

  :herbie-target
  (if (< z -1.1820553527347888e+19) (+ (* 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)))