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

\mathbf{elif}\;\left(t \cdot a + \left(z \cdot y + x\right)\right) + \left(a \cdot z\right) \cdot b \le 3.783205901186803298133700664037706613414 \cdot 10^{303}:\\
\;\;\;\;\left(t \cdot a + \left(z \cdot y + x\right)\right) + \left(a \cdot z\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r31906086 = x;
        double r31906087 = y;
        double r31906088 = z;
        double r31906089 = r31906087 * r31906088;
        double r31906090 = r31906086 + r31906089;
        double r31906091 = t;
        double r31906092 = a;
        double r31906093 = r31906091 * r31906092;
        double r31906094 = r31906090 + r31906093;
        double r31906095 = r31906092 * r31906088;
        double r31906096 = b;
        double r31906097 = r31906095 * r31906096;
        double r31906098 = r31906094 + r31906097;
        return r31906098;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r31906099 = t;
        double r31906100 = a;
        double r31906101 = r31906099 * r31906100;
        double r31906102 = z;
        double r31906103 = y;
        double r31906104 = r31906102 * r31906103;
        double r31906105 = x;
        double r31906106 = r31906104 + r31906105;
        double r31906107 = r31906101 + r31906106;
        double r31906108 = r31906100 * r31906102;
        double r31906109 = b;
        double r31906110 = r31906108 * r31906109;
        double r31906111 = r31906107 + r31906110;
        double r31906112 = -1.2241809761388828e+302;
        bool r31906113 = r31906111 <= r31906112;
        double r31906114 = fma(r31906100, r31906109, r31906103);
        double r31906115 = fma(r31906102, r31906114, r31906105);
        double r31906116 = fma(r31906099, r31906100, r31906115);
        double r31906117 = 3.783205901186803e+303;
        bool r31906118 = r31906111 <= r31906117;
        double r31906119 = r31906118 ? r31906111 : r31906116;
        double r31906120 = r31906113 ? r31906116 : r31906119;
        return r31906120;
}

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.3
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;z \lt -11820553527347888128:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z \lt 4.758974318836428710669076838657752600596 \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 (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)) < -1.2241809761388828e+302 or 3.783205901186803e+303 < (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b))

    1. Initial program 39.1

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

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

    if -1.2241809761388828e+302 < (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)) < 3.783205901186803e+303

    1. Initial program 0.2

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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