Average Error: 4.0 → 0.4
Time: 17.2s
Precision: 64
\[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \le -7.689109869801761566194329301151465841273 \cdot 10^{248}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9\right) \cdot z \le 1.977290462105873963555220939914994307216 \cdot 10^{268}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \end{array}\]
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\begin{array}{l}
\mathbf{if}\;\left(y \cdot 9\right) \cdot z \le -7.689109869801761566194329301151465841273 \cdot 10^{248}:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\

\mathbf{elif}\;\left(y \cdot 9\right) \cdot z \le 1.977290462105873963555220939914994307216 \cdot 10^{268}:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r422823 = x;
        double r422824 = 2.0;
        double r422825 = r422823 * r422824;
        double r422826 = y;
        double r422827 = 9.0;
        double r422828 = r422826 * r422827;
        double r422829 = z;
        double r422830 = r422828 * r422829;
        double r422831 = t;
        double r422832 = r422830 * r422831;
        double r422833 = r422825 - r422832;
        double r422834 = a;
        double r422835 = 27.0;
        double r422836 = r422834 * r422835;
        double r422837 = b;
        double r422838 = r422836 * r422837;
        double r422839 = r422833 + r422838;
        return r422839;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r422840 = y;
        double r422841 = 9.0;
        double r422842 = r422840 * r422841;
        double r422843 = z;
        double r422844 = r422842 * r422843;
        double r422845 = -7.689109869801762e+248;
        bool r422846 = r422844 <= r422845;
        double r422847 = 27.0;
        double r422848 = a;
        double r422849 = b;
        double r422850 = r422848 * r422849;
        double r422851 = x;
        double r422852 = 2.0;
        double r422853 = r422851 * r422852;
        double r422854 = t;
        double r422855 = r422843 * r422854;
        double r422856 = r422842 * r422855;
        double r422857 = r422853 - r422856;
        double r422858 = fma(r422847, r422850, r422857);
        double r422859 = 1.977290462105874e+268;
        bool r422860 = r422844 <= r422859;
        double r422861 = fma(r422847, r422850, r422853);
        double r422862 = r422843 * r422840;
        double r422863 = r422854 * r422862;
        double r422864 = r422841 * r422863;
        double r422865 = r422861 - r422864;
        double r422866 = r422848 * r422847;
        double r422867 = r422841 * r422855;
        double r422868 = r422840 * r422867;
        double r422869 = r422853 - r422868;
        double r422870 = fma(r422866, r422849, r422869);
        double r422871 = r422860 ? r422865 : r422870;
        double r422872 = r422846 ? r422858 : r422871;
        return r422872;
}

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

Original4.0
Target2.7
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;y \lt 7.590524218811188954625810696587370427881 \cdot 10^{-161}:\\ \;\;\;\;\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + a \cdot \left(27 \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - 9 \cdot \left(y \cdot \left(t \cdot z\right)\right)\right) + \left(a \cdot 27\right) \cdot b\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* (* y 9.0) z) < -7.689109869801762e+248

    1. Initial program 38.9

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    2. Simplified38.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. Using strategy rm
    4. Applied associate-*l*1.1

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \color{blue}{\left(y \cdot 9\right) \cdot \left(z \cdot t\right)}\right)\]
    5. Using strategy rm
    6. Applied fma-udef1.1

      \[\leadsto \color{blue}{\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)}\]
    7. Simplified1.1

      \[\leadsto \color{blue}{27 \cdot \left(a \cdot b\right)} + \left(x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\]
    8. Using strategy rm
    9. Applied fma-def1.1

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

    if -7.689109869801762e+248 < (* (* y 9.0) z) < 1.977290462105874e+268

    1. Initial program 0.5

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    2. Simplified0.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. Using strategy rm
    4. Applied associate-*l*3.9

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

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \color{blue}{y \cdot \left(9 \cdot \left(z \cdot t\right)\right)}\right)\]
    7. Taylor expanded around inf 0.4

      \[\leadsto \color{blue}{\left(2 \cdot x + 27 \cdot \left(a \cdot b\right)\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)}\]
    8. Simplified0.4

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

    if 1.977290462105874e+268 < (* (* y 9.0) z)

    1. Initial program 46.2

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b\]
    2. Simplified46.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. Using strategy rm
    4. Applied associate-*l*0.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \le -7.689109869801761566194329301151465841273 \cdot 10^{248}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9\right) \cdot z \le 1.977290462105873963555220939914994307216 \cdot 10^{268}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019322 +o rules:numerics
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, A"
  :precision binary64

  :herbie-target
  (if (< y 7.590524218811189e-161) (+ (- (* x 2) (* (* (* y 9) z) t)) (* a (* 27 b))) (+ (- (* x 2) (* 9 (* y (* t z)))) (* (* a 27) b)))

  (+ (- (* x 2) (* (* (* y 9) z) t)) (* (* a 27) b)))