Average Error: 2.1 → 0.3
Time: 15.1s
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 -30523095539212807236544697370411008:\\ \;\;\;\;\left(a \cdot z\right) \cdot b + \left(x + \mathsf{fma}\left(z, y, t \cdot a\right)\right)\\ \mathbf{elif}\;b \le 1.270637704842553185240097539541791118405 \cdot 10^{-30}:\\ \;\;\;\;\mathsf{fma}\left(t, a, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot z\right) \cdot b + \left(x + \mathsf{fma}\left(z, y, t \cdot a\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 -30523095539212807236544697370411008:\\
\;\;\;\;\left(a \cdot z\right) \cdot b + \left(x + \mathsf{fma}\left(z, y, t \cdot a\right)\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r25664710 = x;
        double r25664711 = y;
        double r25664712 = z;
        double r25664713 = r25664711 * r25664712;
        double r25664714 = r25664710 + r25664713;
        double r25664715 = t;
        double r25664716 = a;
        double r25664717 = r25664715 * r25664716;
        double r25664718 = r25664714 + r25664717;
        double r25664719 = r25664716 * r25664712;
        double r25664720 = b;
        double r25664721 = r25664719 * r25664720;
        double r25664722 = r25664718 + r25664721;
        return r25664722;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r25664723 = b;
        double r25664724 = -3.0523095539212807e+34;
        bool r25664725 = r25664723 <= r25664724;
        double r25664726 = a;
        double r25664727 = z;
        double r25664728 = r25664726 * r25664727;
        double r25664729 = r25664728 * r25664723;
        double r25664730 = x;
        double r25664731 = y;
        double r25664732 = t;
        double r25664733 = r25664732 * r25664726;
        double r25664734 = fma(r25664727, r25664731, r25664733);
        double r25664735 = r25664730 + r25664734;
        double r25664736 = r25664729 + r25664735;
        double r25664737 = 1.2706377048425532e-30;
        bool r25664738 = r25664723 <= r25664737;
        double r25664739 = fma(r25664726, r25664723, r25664731);
        double r25664740 = fma(r25664727, r25664739, r25664730);
        double r25664741 = fma(r25664732, r25664726, r25664740);
        double r25664742 = r25664738 ? r25664741 : r25664736;
        double r25664743 = r25664725 ? r25664736 : r25664742;
        return r25664743;
}

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.5
Herbie0.3
\[\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 < -3.0523095539212807e+34 or 1.2706377048425532e-30 < b

    1. Initial program 0.6

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
    2. Using strategy rm
    3. Applied associate-+l+0.6

      \[\leadsto \color{blue}{\left(x + \left(y \cdot z + t \cdot a\right)\right)} + \left(a \cdot z\right) \cdot b\]
    4. Simplified0.6

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

    if -3.0523095539212807e+34 < b < 1.2706377048425532e-30

    1. Initial program 3.3

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

      \[\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 simplification0.3

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

Reproduce

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