Average Error: 2.0 → 0.3
Time: 3.5s
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 -3.1039916340636497 \cdot 10^{-77} \lor \neg \left(b \le 427644347087821820\right):\\ \;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, 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 -3.1039916340636497 \cdot 10^{-77} \lor \neg \left(b \le 427644347087821820\right):\\
\;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, \left(a \cdot z\right) \cdot b\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r612594 = x;
        double r612595 = y;
        double r612596 = z;
        double r612597 = r612595 * r612596;
        double r612598 = r612594 + r612597;
        double r612599 = t;
        double r612600 = a;
        double r612601 = r612599 * r612600;
        double r612602 = r612598 + r612601;
        double r612603 = r612600 * r612596;
        double r612604 = b;
        double r612605 = r612603 * r612604;
        double r612606 = r612602 + r612605;
        return r612606;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r612607 = b;
        double r612608 = -3.1039916340636497e-77;
        bool r612609 = r612607 <= r612608;
        double r612610 = 4.276443470878218e+17;
        bool r612611 = r612607 <= r612610;
        double r612612 = !r612611;
        bool r612613 = r612609 || r612612;
        double r612614 = x;
        double r612615 = y;
        double r612616 = z;
        double r612617 = r612615 * r612616;
        double r612618 = r612614 + r612617;
        double r612619 = t;
        double r612620 = a;
        double r612621 = r612620 * r612616;
        double r612622 = r612621 * r612607;
        double r612623 = fma(r612619, r612620, r612622);
        double r612624 = r612618 + r612623;
        double r612625 = fma(r612620, r612607, r612615);
        double r612626 = fma(r612620, r612619, r612614);
        double r612627 = fma(r612625, r612616, r612626);
        double r612628 = r612613 ? r612624 : r612627;
        return r612628;
}

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
Herbie0.3
\[\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 b < -3.1039916340636497e-77 or 4.276443470878218e+17 < b

    1. Initial program 0.5

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

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

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

    if -3.1039916340636497e-77 < b < 4.276443470878218e+17

    1. Initial program 3.5

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

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

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

Reproduce

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