Average Error: 3.9 → 0.6
Time: 4.1s
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 -6.8994864051139462 \cdot 10^{137} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 4.2294488262356859 \cdot 10^{236}\right):\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - 9 \cdot \left(t \cdot \left(z \cdot y\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 -6.8994864051139462 \cdot 10^{137} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 4.2294488262356859 \cdot 10^{236}\right):\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r845782 = x;
        double r845783 = 2.0;
        double r845784 = r845782 * r845783;
        double r845785 = y;
        double r845786 = 9.0;
        double r845787 = r845785 * r845786;
        double r845788 = z;
        double r845789 = r845787 * r845788;
        double r845790 = t;
        double r845791 = r845789 * r845790;
        double r845792 = r845784 - r845791;
        double r845793 = a;
        double r845794 = 27.0;
        double r845795 = r845793 * r845794;
        double r845796 = b;
        double r845797 = r845795 * r845796;
        double r845798 = r845792 + r845797;
        return r845798;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r845799 = y;
        double r845800 = 9.0;
        double r845801 = r845799 * r845800;
        double r845802 = z;
        double r845803 = r845801 * r845802;
        double r845804 = -6.899486405113946e+137;
        bool r845805 = r845803 <= r845804;
        double r845806 = 4.229448826235686e+236;
        bool r845807 = r845803 <= r845806;
        double r845808 = !r845807;
        bool r845809 = r845805 || r845808;
        double r845810 = a;
        double r845811 = 27.0;
        double r845812 = b;
        double r845813 = r845811 * r845812;
        double r845814 = x;
        double r845815 = 2.0;
        double r845816 = r845814 * r845815;
        double r845817 = t;
        double r845818 = r845802 * r845817;
        double r845819 = r845800 * r845818;
        double r845820 = r845799 * r845819;
        double r845821 = r845816 - r845820;
        double r845822 = fma(r845810, r845813, r845821);
        double r845823 = r845810 * r845812;
        double r845824 = r845811 * r845823;
        double r845825 = r845802 * r845799;
        double r845826 = r845817 * r845825;
        double r845827 = r845800 * r845826;
        double r845828 = r845824 - r845827;
        double r845829 = fma(r845815, r845814, r845828);
        double r845830 = r845809 ? r845822 : r845829;
        return r845830;
}

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

Original3.9
Target2.9
Herbie0.6
\[\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 2 regimes
  2. if (* (* y 9.0) z) < -6.899486405113946e+137 or 4.229448826235686e+236 < (* (* y 9.0) z)

    1. Initial program 24.6

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

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

      \[\leadsto \mathsf{fma}\left(a, 27 \cdot 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*1.8

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

    if -6.899486405113946e+137 < (* (* y 9.0) z) < 4.229448826235686e+236

    1. Initial program 0.4

      \[\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, 27 \cdot b, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)}\]
    3. 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)}\]
    4. Simplified0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 9\right) \cdot z \le -6.8994864051139462 \cdot 10^{137} \lor \neg \left(\left(y \cdot 9\right) \cdot z \le 4.2294488262356859 \cdot 10^{236}\right):\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\ \end{array}\]

Reproduce

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