Average Error: 1.9 → 0.3
Time: 11.0s
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 -100018803714360295424 \lor \neg \left(b \le 2.471045423623236879623974249563003715746 \cdot 10^{-35}\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 -100018803714360295424 \lor \neg \left(b \le 2.471045423623236879623974249563003715746 \cdot 10^{-35}\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 r756697 = x;
        double r756698 = y;
        double r756699 = z;
        double r756700 = r756698 * r756699;
        double r756701 = r756697 + r756700;
        double r756702 = t;
        double r756703 = a;
        double r756704 = r756702 * r756703;
        double r756705 = r756701 + r756704;
        double r756706 = r756703 * r756699;
        double r756707 = b;
        double r756708 = r756706 * r756707;
        double r756709 = r756705 + r756708;
        return r756709;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r756710 = b;
        double r756711 = -1.000188037143603e+20;
        bool r756712 = r756710 <= r756711;
        double r756713 = 2.471045423623237e-35;
        bool r756714 = r756710 <= r756713;
        double r756715 = !r756714;
        bool r756716 = r756712 || r756715;
        double r756717 = x;
        double r756718 = y;
        double r756719 = z;
        double r756720 = r756718 * r756719;
        double r756721 = r756717 + r756720;
        double r756722 = t;
        double r756723 = a;
        double r756724 = r756722 * r756723;
        double r756725 = r756721 + r756724;
        double r756726 = r756723 * r756719;
        double r756727 = r756726 * r756710;
        double r756728 = r756725 + r756727;
        double r756729 = fma(r756719, r756710, r756722);
        double r756730 = fma(r756729, r756723, r756717);
        double r756731 = fma(r756719, r756718, r756730);
        double r756732 = r756716 ? r756728 : r756731;
        return r756732;
}

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.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 < -1.000188037143603e+20 or 2.471045423623237e-35 < b

    1. Initial program 0.6

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

    if -1.000188037143603e+20 < b < 2.471045423623237e-35

    1. Initial program 3.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -100018803714360295424 \lor \neg \left(b \le 2.471045423623236879623974249563003715746 \cdot 10^{-35}\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 2019351 +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)))