Average Error: 2.3 → 1.5
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}\;a \le 7.58167121829787266 \cdot 10^{-69}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + \mathsf{fma}\left(z, y, \mathsf{fma}\left(b, z, t\right) \cdot a\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}\;a \le 7.58167121829787266 \cdot 10^{-69}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r727414 = x;
        double r727415 = y;
        double r727416 = z;
        double r727417 = r727415 * r727416;
        double r727418 = r727414 + r727417;
        double r727419 = t;
        double r727420 = a;
        double r727421 = r727419 * r727420;
        double r727422 = r727418 + r727421;
        double r727423 = r727420 * r727416;
        double r727424 = b;
        double r727425 = r727423 * r727424;
        double r727426 = r727422 + r727425;
        return r727426;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r727427 = a;
        double r727428 = 7.581671218297873e-69;
        bool r727429 = r727427 <= r727428;
        double r727430 = b;
        double r727431 = y;
        double r727432 = fma(r727427, r727430, r727431);
        double r727433 = z;
        double r727434 = t;
        double r727435 = x;
        double r727436 = fma(r727427, r727434, r727435);
        double r727437 = fma(r727432, r727433, r727436);
        double r727438 = fma(r727430, r727433, r727434);
        double r727439 = r727438 * r727427;
        double r727440 = fma(r727433, r727431, r727439);
        double r727441 = r727435 + r727440;
        double r727442 = r727429 ? r727437 : r727441;
        return r727442;
}

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.3
Target0.3
Herbie1.5
\[\begin{array}{l} \mathbf{if}\;z \lt -11820553527347888000:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z \lt 4.75897431883642871 \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 < 7.581671218297873e-69

    1. Initial program 1.6

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

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

    if 7.581671218297873e-69 < a

    1. Initial program 4.2

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

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

      \[\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 associate-+l+4.2

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

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

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

Reproduce

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