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 r618306 = x;
        double r618307 = y;
        double r618308 = z;
        double r618309 = r618307 * r618308;
        double r618310 = r618306 + r618309;
        double r618311 = t;
        double r618312 = a;
        double r618313 = r618311 * r618312;
        double r618314 = r618310 + r618313;
        double r618315 = r618312 * r618308;
        double r618316 = b;
        double r618317 = r618315 * r618316;
        double r618318 = r618314 + r618317;
        return r618318;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r618319 = b;
        double r618320 = -1.6253743712669907e+97;
        bool r618321 = r618319 <= r618320;
        double r618322 = 2.4152520560821147e+201;
        bool r618323 = r618319 <= r618322;
        double r618324 = !r618323;
        bool r618325 = r618321 || r618324;
        double r618326 = x;
        double r618327 = y;
        double r618328 = z;
        double r618329 = r618327 * r618328;
        double r618330 = r618326 + r618329;
        double r618331 = t;
        double r618332 = a;
        double r618333 = r618332 * r618328;
        double r618334 = r618333 * r618319;
        double r618335 = fma(r618331, r618332, r618334);
        double r618336 = r618330 + r618335;
        double r618337 = 1.0;
        double r618338 = fma(r618319, r618328, r618331);
        double r618339 = fma(r618328, r618327, r618326);
        double r618340 = fma(r618338, r618332, r618339);
        double r618341 = r618337 * r618340;
        double r618342 = r618325 ? r618336 : r618341;
        return r618342;
}

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)))