Average Error: 2.1 → 1.1
Time: 19.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 -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\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 -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\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 r392534 = x;
        double r392535 = y;
        double r392536 = z;
        double r392537 = r392535 * r392536;
        double r392538 = r392534 + r392537;
        double r392539 = t;
        double r392540 = a;
        double r392541 = r392539 * r392540;
        double r392542 = r392538 + r392541;
        double r392543 = r392540 * r392536;
        double r392544 = b;
        double r392545 = r392543 * r392544;
        double r392546 = r392542 + r392545;
        return r392546;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r392547 = b;
        double r392548 = -6.010092830342159e+91;
        bool r392549 = r392547 <= r392548;
        double r392550 = 2.5230721910786968e-269;
        bool r392551 = r392547 <= r392550;
        double r392552 = !r392551;
        bool r392553 = r392549 || r392552;
        double r392554 = x;
        double r392555 = y;
        double r392556 = z;
        double r392557 = r392555 * r392556;
        double r392558 = r392554 + r392557;
        double r392559 = t;
        double r392560 = a;
        double r392561 = r392559 * r392560;
        double r392562 = r392558 + r392561;
        double r392563 = r392560 * r392556;
        double r392564 = r392563 * r392547;
        double r392565 = r392562 + r392564;
        double r392566 = fma(r392556, r392547, r392559);
        double r392567 = fma(r392566, r392560, r392554);
        double r392568 = fma(r392556, r392555, r392567);
        double r392569 = r392553 ? r392565 : r392568;
        return r392569;
}

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
Herbie1.1
\[\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 < -6.010092830342159e+91 or 2.5230721910786968e-269 < b

    1. Initial program 1.5

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

    if -6.010092830342159e+91 < b < 2.5230721910786968e-269

    1. Initial program 3.0

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

      \[\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 simplification1.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\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 2019323 +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)))