Average Error: 1.9 → 0.5
Time: 15.2s
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.013766179399324678530116716049667748669 \cdot 10^{96}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{elif}\;b \le 1.495858250720639938141140012691115073428 \cdot 10^{-109}:\\ \;\;\;\;\mathsf{fma}\left(a, \mathsf{fma}\left(z, b, t\right), \mathsf{fma}\left(y, z, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \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.013766179399324678530116716049667748669 \cdot 10^{96}:\\
\;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r74794223 = x;
        double r74794224 = y;
        double r74794225 = z;
        double r74794226 = r74794224 * r74794225;
        double r74794227 = r74794223 + r74794226;
        double r74794228 = t;
        double r74794229 = a;
        double r74794230 = r74794228 * r74794229;
        double r74794231 = r74794227 + r74794230;
        double r74794232 = r74794229 * r74794225;
        double r74794233 = b;
        double r74794234 = r74794232 * r74794233;
        double r74794235 = r74794231 + r74794234;
        return r74794235;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r74794236 = b;
        double r74794237 = -1.0137661793993247e+96;
        bool r74794238 = r74794236 <= r74794237;
        double r74794239 = x;
        double r74794240 = y;
        double r74794241 = z;
        double r74794242 = r74794240 * r74794241;
        double r74794243 = r74794239 + r74794242;
        double r74794244 = t;
        double r74794245 = a;
        double r74794246 = r74794244 * r74794245;
        double r74794247 = r74794243 + r74794246;
        double r74794248 = r74794245 * r74794241;
        double r74794249 = r74794248 * r74794236;
        double r74794250 = r74794247 + r74794249;
        double r74794251 = 1.49585825072064e-109;
        bool r74794252 = r74794236 <= r74794251;
        double r74794253 = fma(r74794241, r74794236, r74794244);
        double r74794254 = fma(r74794240, r74794241, r74794239);
        double r74794255 = fma(r74794245, r74794253, r74794254);
        double r74794256 = r74794252 ? r74794255 : r74794250;
        double r74794257 = r74794238 ? r74794250 : r74794256;
        return r74794257;
}

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

Original1.9
Target0.4
Herbie0.5
\[\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 b < -1.0137661793993247e+96 or 1.49585825072064e-109 < b

    1. Initial program 0.8

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

    if -1.0137661793993247e+96 < b < 1.49585825072064e-109

    1. Initial program 2.9

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

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

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

Reproduce

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