Average Error: 2.0 → 1.0
Time: 3.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 -1.625374371266990680822013191263407453732 \cdot 10^{97} \lor \neg \left(b \le 2.415252056082114662102450908306260614324 \cdot 10^{201}\right):\\ \;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\mathsf{fma}\left(b, z, t\right), a, \mathsf{fma}\left(z, y, 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 -1.625374371266990680822013191263407453732 \cdot 10^{97} \lor \neg \left(b \le 2.415252056082114662102450908306260614324 \cdot 10^{201}\right):\\
\;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r611714 = x;
        double r611715 = y;
        double r611716 = z;
        double r611717 = r611715 * r611716;
        double r611718 = r611714 + r611717;
        double r611719 = t;
        double r611720 = a;
        double r611721 = r611719 * r611720;
        double r611722 = r611718 + r611721;
        double r611723 = r611720 * r611716;
        double r611724 = b;
        double r611725 = r611723 * r611724;
        double r611726 = r611722 + r611725;
        return r611726;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r611727 = b;
        double r611728 = -1.6253743712669907e+97;
        bool r611729 = r611727 <= r611728;
        double r611730 = 2.4152520560821147e+201;
        bool r611731 = r611727 <= r611730;
        double r611732 = !r611731;
        bool r611733 = r611729 || r611732;
        double r611734 = x;
        double r611735 = y;
        double r611736 = z;
        double r611737 = r611735 * r611736;
        double r611738 = r611734 + r611737;
        double r611739 = t;
        double r611740 = a;
        double r611741 = r611740 * r611736;
        double r611742 = r611741 * r611727;
        double r611743 = fma(r611739, r611740, r611742);
        double r611744 = r611738 + r611743;
        double r611745 = 1.0;
        double r611746 = fma(r611727, r611736, r611739);
        double r611747 = fma(r611736, r611735, r611734);
        double r611748 = fma(r611746, r611740, r611747);
        double r611749 = r611745 * r611748;
        double r611750 = r611733 ? r611744 : r611749;
        return r611750;
}

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.0
Target0.4
Herbie1.0
\[\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.6253743712669907e+97 or 2.4152520560821147e+201 < 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 + y \cdot z\right) + \left(t \cdot a + \left(a \cdot z\right) \cdot b\right)}\]
    4. Simplified0.8

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

    if -1.6253743712669907e+97 < b < 2.4152520560821147e+201

    1. Initial program 2.3

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

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

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

      \[\leadsto \left(x + y \cdot z\right) + \color{blue}{1 \cdot \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)}\]
    7. Applied *-un-lft-identity2.3

      \[\leadsto \color{blue}{1 \cdot \left(x + y \cdot z\right)} + 1 \cdot \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\]
    8. Applied distribute-lft-out2.3

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

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

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

Reproduce

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