Average Error: 2.1 → 0.1
Time: 2.7s
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}\;z \le -3.298731175539478 \cdot 10^{45} \lor \neg \left(z \le 4.68371957229160155 \cdot 10^{-8}\right):\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, t, x\right)\right) + a \cdot \left(z \cdot b\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}\;z \le -3.298731175539478 \cdot 10^{45} \lor \neg \left(z \le 4.68371957229160155 \cdot 10^{-8}\right):\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r560082 = x;
        double r560083 = y;
        double r560084 = z;
        double r560085 = r560083 * r560084;
        double r560086 = r560082 + r560085;
        double r560087 = t;
        double r560088 = a;
        double r560089 = r560087 * r560088;
        double r560090 = r560086 + r560089;
        double r560091 = r560088 * r560084;
        double r560092 = b;
        double r560093 = r560091 * r560092;
        double r560094 = r560090 + r560093;
        return r560094;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r560095 = z;
        double r560096 = -3.298731175539478e+45;
        bool r560097 = r560095 <= r560096;
        double r560098 = 4.6837195722916015e-08;
        bool r560099 = r560095 <= r560098;
        double r560100 = !r560099;
        bool r560101 = r560097 || r560100;
        double r560102 = a;
        double r560103 = b;
        double r560104 = y;
        double r560105 = fma(r560102, r560103, r560104);
        double r560106 = t;
        double r560107 = x;
        double r560108 = fma(r560102, r560106, r560107);
        double r560109 = fma(r560105, r560095, r560108);
        double r560110 = fma(r560104, r560095, r560108);
        double r560111 = r560095 * r560103;
        double r560112 = r560102 * r560111;
        double r560113 = r560110 + r560112;
        double r560114 = r560101 ? r560109 : r560113;
        return r560114;
}

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
Herbie0.1
\[\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 z < -3.298731175539478e+45 or 4.6837195722916015e-08 < z

    1. Initial program 5.2

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

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

    if -3.298731175539478e+45 < z < 4.6837195722916015e-08

    1. Initial program 0.5

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
    2. Taylor expanded around inf 0.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, t, x\right)\right)} + \left(a \cdot z\right) \cdot b\]
    4. Using strategy rm
    5. Applied associate-*l*0.1

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

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

Reproduce

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