Average Error: 1.9 → 0.8
Time: 12.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}\;b \le -2.184598399887742151607503598727674179515 \cdot 10^{173} \lor \neg \left(b \le 4.256811503202536895550421344867914511115 \cdot 10^{-102}\right):\\ \;\;\;\;\left(x + \mathsf{fma}\left(a, t, y \cdot z\right)\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\left(x + \mathsf{fma}\left(a, t, y \cdot z\right)\right) + a \cdot \left(z \cdot b\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 -2.184598399887742151607503598727674179515 \cdot 10^{173} \lor \neg \left(b \le 4.256811503202536895550421344867914511115 \cdot 10^{-102}\right):\\
\;\;\;\;\left(x + \mathsf{fma}\left(a, t, y \cdot z\right)\right) + \left(a \cdot z\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r472553 = x;
        double r472554 = y;
        double r472555 = z;
        double r472556 = r472554 * r472555;
        double r472557 = r472553 + r472556;
        double r472558 = t;
        double r472559 = a;
        double r472560 = r472558 * r472559;
        double r472561 = r472557 + r472560;
        double r472562 = r472559 * r472555;
        double r472563 = b;
        double r472564 = r472562 * r472563;
        double r472565 = r472561 + r472564;
        return r472565;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r472566 = b;
        double r472567 = -2.1845983998877422e+173;
        bool r472568 = r472566 <= r472567;
        double r472569 = 4.256811503202537e-102;
        bool r472570 = r472566 <= r472569;
        double r472571 = !r472570;
        bool r472572 = r472568 || r472571;
        double r472573 = x;
        double r472574 = a;
        double r472575 = t;
        double r472576 = y;
        double r472577 = z;
        double r472578 = r472576 * r472577;
        double r472579 = fma(r472574, r472575, r472578);
        double r472580 = r472573 + r472579;
        double r472581 = r472574 * r472577;
        double r472582 = r472581 * r472566;
        double r472583 = r472580 + r472582;
        double r472584 = r472577 * r472566;
        double r472585 = r472574 * r472584;
        double r472586 = r472580 + r472585;
        double r472587 = r472572 ? r472583 : r472586;
        return r472587;
}

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.3
Herbie0.8
\[\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 < -2.1845983998877422e+173 or 4.256811503202537e-102 < b

    1. Initial program 0.8

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

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

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

    if -2.1845983998877422e+173 < b < 4.256811503202537e-102

    1. Initial program 2.7

      \[\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+2.7

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

      \[\leadsto \left(x + \color{blue}{\mathsf{fma}\left(a, t, y \cdot z\right)}\right) + \left(a \cdot z\right) \cdot b\]
    5. Using strategy rm
    6. Applied associate-*l*0.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.184598399887742151607503598727674179515 \cdot 10^{173} \lor \neg \left(b \le 4.256811503202536895550421344867914511115 \cdot 10^{-102}\right):\\ \;\;\;\;\left(x + \mathsf{fma}\left(a, t, y \cdot z\right)\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\left(x + \mathsf{fma}\left(a, t, y \cdot z\right)\right) + a \cdot \left(z \cdot b\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019209 +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.75897431883642871e-122) (+ (* (+ (* b z) t) a) (+ (* z y) x)) (+ (* z (+ (* b a) y)) (+ x (* t a)))))

  (+ (+ (+ x (* y z)) (* t a)) (* (* a z) b)))