Average Error: 2.0 → 0.8
Time: 13.8s
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.029332914097035150003651381505816557895 \cdot 10^{146} \lor \neg \left(b \le 3.88479588022017558466900273665607578266 \cdot 10^{84}\right):\\ \;\;\;\;\left(a \cdot z\right) \cdot b + \left(\left(x + y \cdot z\right) + a \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t, a, \mathsf{fma}\left(z, \mathsf{fma}\left(a, b, y\right), 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.029332914097035150003651381505816557895 \cdot 10^{146} \lor \neg \left(b \le 3.88479588022017558466900273665607578266 \cdot 10^{84}\right):\\
\;\;\;\;\left(a \cdot z\right) \cdot b + \left(\left(x + y \cdot z\right) + a \cdot t\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r428355 = x;
        double r428356 = y;
        double r428357 = z;
        double r428358 = r428356 * r428357;
        double r428359 = r428355 + r428358;
        double r428360 = t;
        double r428361 = a;
        double r428362 = r428360 * r428361;
        double r428363 = r428359 + r428362;
        double r428364 = r428361 * r428357;
        double r428365 = b;
        double r428366 = r428364 * r428365;
        double r428367 = r428363 + r428366;
        return r428367;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r428368 = b;
        double r428369 = -1.0293329140970352e+146;
        bool r428370 = r428368 <= r428369;
        double r428371 = 3.8847958802201756e+84;
        bool r428372 = r428368 <= r428371;
        double r428373 = !r428372;
        bool r428374 = r428370 || r428373;
        double r428375 = a;
        double r428376 = z;
        double r428377 = r428375 * r428376;
        double r428378 = r428377 * r428368;
        double r428379 = x;
        double r428380 = y;
        double r428381 = r428380 * r428376;
        double r428382 = r428379 + r428381;
        double r428383 = t;
        double r428384 = r428375 * r428383;
        double r428385 = r428382 + r428384;
        double r428386 = r428378 + r428385;
        double r428387 = fma(r428375, r428368, r428380);
        double r428388 = fma(r428376, r428387, r428379);
        double r428389 = fma(r428383, r428375, r428388);
        double r428390 = r428374 ? r428386 : r428389;
        return r428390;
}

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.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 < -1.0293329140970352e+146 or 3.8847958802201756e+84 < b

    1. Initial program 0.9

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

    if -1.0293329140970352e+146 < b < 3.8847958802201756e+84

    1. Initial program 2.3

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

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

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

Reproduce

herbie shell --seed 2019179 +o rules:numerics
(FPCore (x y z t a b)
  :name "Graphics.Rasterific.CubicBezier:cachedBezierAt from Rasterific-0.6.1"

  :herbie-target
  (if (< z -1.1820553527347888e+19) (+ (* 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)))