Average Error: 2.1 → 0.1
Time: 2.4s
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 r516270 = x;
        double r516271 = y;
        double r516272 = z;
        double r516273 = r516271 * r516272;
        double r516274 = r516270 + r516273;
        double r516275 = t;
        double r516276 = a;
        double r516277 = r516275 * r516276;
        double r516278 = r516274 + r516277;
        double r516279 = r516276 * r516272;
        double r516280 = b;
        double r516281 = r516279 * r516280;
        double r516282 = r516278 + r516281;
        return r516282;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r516283 = z;
        double r516284 = -3.298731175539478e+45;
        bool r516285 = r516283 <= r516284;
        double r516286 = 4.6837195722916015e-08;
        bool r516287 = r516283 <= r516286;
        double r516288 = !r516287;
        bool r516289 = r516285 || r516288;
        double r516290 = a;
        double r516291 = b;
        double r516292 = y;
        double r516293 = fma(r516290, r516291, r516292);
        double r516294 = t;
        double r516295 = x;
        double r516296 = fma(r516290, r516294, r516295);
        double r516297 = fma(r516293, r516283, r516296);
        double r516298 = fma(r516292, r516283, r516296);
        double r516299 = r516283 * r516291;
        double r516300 = r516290 * r516299;
        double r516301 = r516298 + r516300;
        double r516302 = r516289 ? r516297 : r516301;
        return r516302;
}

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)))