Average Error: 2.1 → 1.2
Time: 16.3s
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}\;a \le -1.633099719810372038924919515496326271933 \cdot 10^{-76} \lor \neg \left(a \le 9.108876548869236631679254363644611836499 \cdot 10^{-243}\right):\\ \;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(\mathsf{fma}\left(z, b, t\right), a, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \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}\;a \le -1.633099719810372038924919515496326271933 \cdot 10^{-76} \lor \neg \left(a \le 9.108876548869236631679254363644611836499 \cdot 10^{-243}\right):\\
\;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(\mathsf{fma}\left(z, b, t\right), a, x\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r514378 = x;
        double r514379 = y;
        double r514380 = z;
        double r514381 = r514379 * r514380;
        double r514382 = r514378 + r514381;
        double r514383 = t;
        double r514384 = a;
        double r514385 = r514383 * r514384;
        double r514386 = r514382 + r514385;
        double r514387 = r514384 * r514380;
        double r514388 = b;
        double r514389 = r514387 * r514388;
        double r514390 = r514386 + r514389;
        return r514390;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r514391 = a;
        double r514392 = -1.633099719810372e-76;
        bool r514393 = r514391 <= r514392;
        double r514394 = 9.108876548869237e-243;
        bool r514395 = r514391 <= r514394;
        double r514396 = !r514395;
        bool r514397 = r514393 || r514396;
        double r514398 = z;
        double r514399 = y;
        double r514400 = b;
        double r514401 = t;
        double r514402 = fma(r514398, r514400, r514401);
        double r514403 = x;
        double r514404 = fma(r514402, r514391, r514403);
        double r514405 = fma(r514398, r514399, r514404);
        double r514406 = r514399 * r514398;
        double r514407 = r514403 + r514406;
        double r514408 = r514401 * r514391;
        double r514409 = r514407 + r514408;
        double r514410 = r514391 * r514398;
        double r514411 = r514410 * r514400;
        double r514412 = r514409 + r514411;
        double r514413 = r514397 ? r514405 : r514412;
        return r514413;
}

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.3
Herbie1.2
\[\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 a < -1.633099719810372e-76 or 9.108876548869237e-243 < a

    1. Initial program 2.8

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

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

    if -1.633099719810372e-76 < a < 9.108876548869237e-243

    1. Initial program 0.5

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.2

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

Reproduce

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