Average Error: 2.1 → 1.1
Time: 17.6s
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 -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\right):\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, \mathsf{fma}\left(\mathsf{fma}\left(z, b, t\right), a, 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 -6.010092830342159068026797631733328371903 \cdot 10^{91} \lor \neg \left(b \le 2.523072191078696760108259564699709727871 \cdot 10^{-269}\right):\\
\;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r549838 = x;
        double r549839 = y;
        double r549840 = z;
        double r549841 = r549839 * r549840;
        double r549842 = r549838 + r549841;
        double r549843 = t;
        double r549844 = a;
        double r549845 = r549843 * r549844;
        double r549846 = r549842 + r549845;
        double r549847 = r549844 * r549840;
        double r549848 = b;
        double r549849 = r549847 * r549848;
        double r549850 = r549846 + r549849;
        return r549850;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r549851 = b;
        double r549852 = -6.010092830342159e+91;
        bool r549853 = r549851 <= r549852;
        double r549854 = 2.5230721910786968e-269;
        bool r549855 = r549851 <= r549854;
        double r549856 = !r549855;
        bool r549857 = r549853 || r549856;
        double r549858 = x;
        double r549859 = y;
        double r549860 = z;
        double r549861 = r549859 * r549860;
        double r549862 = r549858 + r549861;
        double r549863 = t;
        double r549864 = a;
        double r549865 = r549863 * r549864;
        double r549866 = r549862 + r549865;
        double r549867 = r549864 * r549860;
        double r549868 = r549867 * r549851;
        double r549869 = r549866 + r549868;
        double r549870 = fma(r549860, r549851, r549863);
        double r549871 = fma(r549870, r549864, r549858);
        double r549872 = fma(r549860, r549859, r549871);
        double r549873 = r549857 ? r549869 : r549872;
        return r549873;
}

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.1
\[\begin{array}{l} \mathbf{if}\;z \lt -11820553527347888128:\\ \;\;\;\;z \cdot \left(b \cdot a + y\right) + \left(x + t \cdot a\right)\\ \mathbf{elif}\;z \lt 4.758974318836428710669076838657752600596 \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 < -6.010092830342159e+91 or 2.5230721910786968e-269 < b

    1. Initial program 1.5

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]

    if -6.010092830342159e+91 < b < 2.5230721910786968e-269

    1. Initial program 3.0

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

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

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

Reproduce

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