Average Error: 4.0 → 1.3
Time: 29.6s
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}\;y \cdot 9 \le -2.434616547682554976717028694110922515392:\\ \;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\ \mathbf{elif}\;y \cdot 9 \le 1.511751713308080890358784734622859626508 \cdot 10^{-215}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, x \cdot 2\right) - z \cdot \left(\left(y \cdot 9\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\ \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}\;y \cdot 9 \le -2.434616547682554976717028694110922515392:\\
\;\;\;\;\mathsf{fma}\left(x, 2, a \cdot \left(27 \cdot b\right)\right) - \left(\left(t \cdot z\right) \cdot y\right) \cdot 9\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r27734219 = x;
        double r27734220 = 2.0;
        double r27734221 = r27734219 * r27734220;
        double r27734222 = y;
        double r27734223 = 9.0;
        double r27734224 = r27734222 * r27734223;
        double r27734225 = z;
        double r27734226 = r27734224 * r27734225;
        double r27734227 = t;
        double r27734228 = r27734226 * r27734227;
        double r27734229 = r27734221 - r27734228;
        double r27734230 = a;
        double r27734231 = 27.0;
        double r27734232 = r27734230 * r27734231;
        double r27734233 = b;
        double r27734234 = r27734232 * r27734233;
        double r27734235 = r27734229 + r27734234;
        return r27734235;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r27734236 = y;
        double r27734237 = 9.0;
        double r27734238 = r27734236 * r27734237;
        double r27734239 = -2.434616547682555;
        bool r27734240 = r27734238 <= r27734239;
        double r27734241 = x;
        double r27734242 = 2.0;
        double r27734243 = a;
        double r27734244 = 27.0;
        double r27734245 = b;
        double r27734246 = r27734244 * r27734245;
        double r27734247 = r27734243 * r27734246;
        double r27734248 = fma(r27734241, r27734242, r27734247);
        double r27734249 = t;
        double r27734250 = z;
        double r27734251 = r27734249 * r27734250;
        double r27734252 = r27734251 * r27734236;
        double r27734253 = r27734252 * r27734237;
        double r27734254 = r27734248 - r27734253;
        double r27734255 = 1.511751713308081e-215;
        bool r27734256 = r27734238 <= r27734255;
        double r27734257 = r27734243 * r27734245;
        double r27734258 = r27734241 * r27734242;
        double r27734259 = fma(r27734244, r27734257, r27734258);
        double r27734260 = r27734238 * r27734249;
        double r27734261 = r27734250 * r27734260;
        double r27734262 = r27734259 - r27734261;
        double r27734263 = r27734256 ? r27734262 : r27734254;
        double r27734264 = r27734240 ? r27734254 : r27734263;
        return r27734264;
}

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
Herbie1.3
\[\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 2 regimes
  2. if (* y 9.0) < -2.434616547682555 or 1.511751713308081e-215 < (* y 9.0)

    1. Initial program 6.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. Simplified5.4

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

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

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

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

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

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

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

    if -2.434616547682555 < (* y 9.0) < 1.511751713308081e-215

    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.5

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

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

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

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

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

Reproduce

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