Average Error: 4.0 → 0.8
Time: 17.5s
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}\;t \le -2.1150978170932987 \cdot 10^{23}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, 2 \cdot x - \left(9 \cdot t\right) \cdot \left(z \cdot y\right)\right)\\ \mathbf{elif}\;t \le 6.18142103597057311 \cdot 10^{-49}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, 2 \cdot x - \left(\left(9 \cdot t\right) \cdot z\right) \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, 2 \cdot x\right) - 9 \cdot \left(t \cdot \left(z \cdot y\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}\;t \le -2.1150978170932987 \cdot 10^{23}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, 2 \cdot x - \left(9 \cdot t\right) \cdot \left(z \cdot y\right)\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r487222 = x;
        double r487223 = 2.0;
        double r487224 = r487222 * r487223;
        double r487225 = y;
        double r487226 = 9.0;
        double r487227 = r487225 * r487226;
        double r487228 = z;
        double r487229 = r487227 * r487228;
        double r487230 = t;
        double r487231 = r487229 * r487230;
        double r487232 = r487224 - r487231;
        double r487233 = a;
        double r487234 = 27.0;
        double r487235 = r487233 * r487234;
        double r487236 = b;
        double r487237 = r487235 * r487236;
        double r487238 = r487232 + r487237;
        return r487238;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r487239 = t;
        double r487240 = -2.1150978170932987e+23;
        bool r487241 = r487239 <= r487240;
        double r487242 = a;
        double r487243 = 27.0;
        double r487244 = r487242 * r487243;
        double r487245 = b;
        double r487246 = 2.0;
        double r487247 = x;
        double r487248 = r487246 * r487247;
        double r487249 = 9.0;
        double r487250 = r487249 * r487239;
        double r487251 = z;
        double r487252 = y;
        double r487253 = r487251 * r487252;
        double r487254 = r487250 * r487253;
        double r487255 = r487248 - r487254;
        double r487256 = fma(r487244, r487245, r487255);
        double r487257 = 6.181421035970573e-49;
        bool r487258 = r487239 <= r487257;
        double r487259 = r487250 * r487251;
        double r487260 = r487259 * r487252;
        double r487261 = r487248 - r487260;
        double r487262 = fma(r487244, r487245, r487261);
        double r487263 = r487242 * r487245;
        double r487264 = fma(r487243, r487263, r487248);
        double r487265 = r487239 * r487253;
        double r487266 = r487249 * r487265;
        double r487267 = r487264 - r487266;
        double r487268 = r487258 ? r487262 : r487267;
        double r487269 = r487241 ? r487256 : r487268;
        return r487269;
}

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.9
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;y \lt 7.590524218811189 \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 t < -2.1150978170932987e+23

    1. Initial program 0.7

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

      \[\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. Taylor expanded around inf 0.7

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

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

    if -2.1150978170932987e+23 < t < 6.181421035970573e-49

    1. Initial program 6.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. Simplified6.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. Taylor expanded around inf 6.4

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

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

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

    if 6.181421035970573e-49 < t

    1. Initial program 1.0

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

      \[\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. Taylor expanded around inf 0.9

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

      \[\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)}\]
    5. Simplified0.8

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

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

Reproduce

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

  :herbie-target
  (if (< y 7.590524218811189e-161) (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* a (* 27.0 b))) (+ (- (* x 2.0) (* 9.0 (* y (* t z)))) (* (* a 27.0) b)))

  (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))