Average Error: 2.2 → 0.6
Time: 16.3s
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}\;b \le -1.7457466297707951 \cdot 10^{-60} \lor \neg \left(b \le 4.9874819535691615 \cdot 10^{-140}\right):\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(\mathsf{fma}\left(z, b, t\right), a, x\right)\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}\;b \le -1.7457466297707951 \cdot 10^{-60} \lor \neg \left(b \le 4.9874819535691615 \cdot 10^{-140}\right):\\
\;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r473955 = x;
        double r473956 = y;
        double r473957 = z;
        double r473958 = r473956 * r473957;
        double r473959 = r473955 + r473958;
        double r473960 = t;
        double r473961 = a;
        double r473962 = r473960 * r473961;
        double r473963 = r473959 + r473962;
        double r473964 = r473961 * r473957;
        double r473965 = b;
        double r473966 = r473964 * r473965;
        double r473967 = r473963 + r473966;
        return r473967;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r473968 = b;
        double r473969 = -1.745746629770795e-60;
        bool r473970 = r473968 <= r473969;
        double r473971 = 4.987481953569162e-140;
        bool r473972 = r473968 <= r473971;
        double r473973 = !r473972;
        bool r473974 = r473970 || r473973;
        double r473975 = x;
        double r473976 = y;
        double r473977 = z;
        double r473978 = r473976 * r473977;
        double r473979 = r473975 + r473978;
        double r473980 = t;
        double r473981 = a;
        double r473982 = r473980 * r473981;
        double r473983 = r473979 + r473982;
        double r473984 = r473981 * r473977;
        double r473985 = r473984 * r473968;
        double r473986 = r473983 + r473985;
        double r473987 = fma(r473977, r473968, r473980);
        double r473988 = fma(r473987, r473981, r473975);
        double r473989 = fma(r473977, r473976, r473988);
        double r473990 = r473974 ? r473986 : r473989;
        return r473990;
}

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.4
Herbie0.6
\[\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 b < -1.745746629770795e-60 or 4.987481953569162e-140 < b

    1. Initial program 0.9

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

    if -1.745746629770795e-60 < b < 4.987481953569162e-140

    1. Initial program 4.3

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

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

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

Reproduce

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