Average Error: 2.3 → 0.3
Time: 3.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 -2.83689149784584297 \cdot 10^{-81} \lor \neg \left(z \le 5.0552842408320415 \cdot 10^{82}\right):\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + y \cdot z\right) + \mathsf{fma}\left(t, a, a \cdot \left(z \cdot b\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}\;z \le -2.83689149784584297 \cdot 10^{-81} \lor \neg \left(z \le 5.0552842408320415 \cdot 10^{82}\right):\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r733875 = x;
        double r733876 = y;
        double r733877 = z;
        double r733878 = r733876 * r733877;
        double r733879 = r733875 + r733878;
        double r733880 = t;
        double r733881 = a;
        double r733882 = r733880 * r733881;
        double r733883 = r733879 + r733882;
        double r733884 = r733881 * r733877;
        double r733885 = b;
        double r733886 = r733884 * r733885;
        double r733887 = r733883 + r733886;
        return r733887;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r733888 = z;
        double r733889 = -2.836891497845843e-81;
        bool r733890 = r733888 <= r733889;
        double r733891 = 5.0552842408320415e+82;
        bool r733892 = r733888 <= r733891;
        double r733893 = !r733892;
        bool r733894 = r733890 || r733893;
        double r733895 = a;
        double r733896 = b;
        double r733897 = y;
        double r733898 = fma(r733895, r733896, r733897);
        double r733899 = t;
        double r733900 = x;
        double r733901 = fma(r733895, r733899, r733900);
        double r733902 = fma(r733898, r733888, r733901);
        double r733903 = r733897 * r733888;
        double r733904 = r733900 + r733903;
        double r733905 = r733888 * r733896;
        double r733906 = r733895 * r733905;
        double r733907 = fma(r733899, r733895, r733906);
        double r733908 = r733904 + r733907;
        double r733909 = r733894 ? r733902 : r733908;
        return r733909;
}

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.3
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 z < -2.836891497845843e-81 or 5.0552842408320415e+82 < z

    1. Initial program 5.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(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)}\]

    if -2.836891497845843e-81 < z < 5.0552842408320415e+82

    1. Initial program 0.6

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

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

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

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

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

Reproduce

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