Average Error: 2.1 → 1.4
Time: 4.3s
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.1872694963779026 \cdot 10^{90}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, t, x\right)\right) + a \cdot \left(z \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, t, x\right)\right) + \left(a \cdot z\right) \cdot b\\ \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.1872694963779026 \cdot 10^{90}:\\
\;\;\;\;\mathsf{fma}\left(y, z, \mathsf{fma}\left(a, t, x\right)\right) + a \cdot \left(z \cdot b\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r656664 = x;
        double r656665 = y;
        double r656666 = z;
        double r656667 = r656665 * r656666;
        double r656668 = r656664 + r656667;
        double r656669 = t;
        double r656670 = a;
        double r656671 = r656669 * r656670;
        double r656672 = r656668 + r656671;
        double r656673 = r656670 * r656666;
        double r656674 = b;
        double r656675 = r656673 * r656674;
        double r656676 = r656672 + r656675;
        return r656676;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r656677 = a;
        double r656678 = -7.187269496377903e+90;
        bool r656679 = r656677 <= r656678;
        double r656680 = y;
        double r656681 = z;
        double r656682 = t;
        double r656683 = x;
        double r656684 = fma(r656677, r656682, r656683);
        double r656685 = fma(r656680, r656681, r656684);
        double r656686 = b;
        double r656687 = r656681 * r656686;
        double r656688 = r656677 * r656687;
        double r656689 = r656685 + r656688;
        double r656690 = r656677 * r656681;
        double r656691 = r656690 * r656686;
        double r656692 = r656685 + r656691;
        double r656693 = r656679 ? r656689 : r656692;
        return r656693;
}

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
Herbie1.4
\[\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.187269496377903e+90

    1. Initial program 6.8

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

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

      \[\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)}\]

    if -7.187269496377903e+90 < a

    1. Initial program 1.5

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

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

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

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

Reproduce

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