Average Error: 2.0 → 0.2
Time: 3.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}\;z \le -9.75990392429365618983427605077907163178 \cdot 10^{-9} \lor \neg \left(z \le 9.674444679566241783889887900241718617131 \cdot 10^{-89}\right):\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + {\left(a \cdot \left(z \cdot b\right)\right)}^{1}\\ \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 -9.75990392429365618983427605077907163178 \cdot 10^{-9} \lor \neg \left(z \le 9.674444679566241783889887900241718617131 \cdot 10^{-89}\right):\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(a, b, y\right), z, \mathsf{fma}\left(a, t, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(x + y \cdot z\right) + t \cdot a\right) + {\left(a \cdot \left(z \cdot b\right)\right)}^{1}\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r661836 = x;
        double r661837 = y;
        double r661838 = z;
        double r661839 = r661837 * r661838;
        double r661840 = r661836 + r661839;
        double r661841 = t;
        double r661842 = a;
        double r661843 = r661841 * r661842;
        double r661844 = r661840 + r661843;
        double r661845 = r661842 * r661838;
        double r661846 = b;
        double r661847 = r661845 * r661846;
        double r661848 = r661844 + r661847;
        return r661848;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r661849 = z;
        double r661850 = -9.759903924293656e-09;
        bool r661851 = r661849 <= r661850;
        double r661852 = 9.674444679566242e-89;
        bool r661853 = r661849 <= r661852;
        double r661854 = !r661853;
        bool r661855 = r661851 || r661854;
        double r661856 = a;
        double r661857 = b;
        double r661858 = y;
        double r661859 = fma(r661856, r661857, r661858);
        double r661860 = t;
        double r661861 = x;
        double r661862 = fma(r661856, r661860, r661861);
        double r661863 = fma(r661859, r661849, r661862);
        double r661864 = r661858 * r661849;
        double r661865 = r661861 + r661864;
        double r661866 = r661860 * r661856;
        double r661867 = r661865 + r661866;
        double r661868 = r661849 * r661857;
        double r661869 = r661856 * r661868;
        double r661870 = 1.0;
        double r661871 = pow(r661869, r661870);
        double r661872 = r661867 + r661871;
        double r661873 = r661855 ? r661863 : r661872;
        return r661873;
}

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.0
Target0.3
Herbie0.2
\[\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 z < -9.759903924293656e-09 or 9.674444679566242e-89 < z

    1. Initial program 3.7

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

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

    if -9.759903924293656e-09 < z < 9.674444679566242e-89

    1. Initial program 0.4

      \[\left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot b\]
    2. Using strategy rm
    3. Applied pow10.4

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot z\right) \cdot \color{blue}{{b}^{1}}\]
    4. Applied pow10.4

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(a \cdot \color{blue}{{z}^{1}}\right) \cdot {b}^{1}\]
    5. Applied pow10.4

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \left(\color{blue}{{a}^{1}} \cdot {z}^{1}\right) \cdot {b}^{1}\]
    6. Applied pow-prod-down0.4

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \color{blue}{{\left(a \cdot z\right)}^{1}} \cdot {b}^{1}\]
    7. Applied pow-prod-down0.4

      \[\leadsto \left(\left(x + y \cdot z\right) + t \cdot a\right) + \color{blue}{{\left(\left(a \cdot z\right) \cdot b\right)}^{1}}\]
    8. Simplified0.0

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

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

Reproduce

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