Average Error: 3.7 → 1.1
Time: 19.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}\;\left(y \cdot 9\right) \cdot z \le -3.087876377269368779883663932063586038326 \cdot 10^{54}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \left(\left(b \cdot a\right) \cdot \sqrt{27}\right) \cdot \sqrt{27} - y \cdot \left(\left(z \cdot 9\right) \cdot t\right)\right)\\ \mathbf{elif}\;\left(y \cdot 9\right) \cdot z \le 1.498316341905703021605410093028330346329 \cdot 10^{157}:\\ \;\;\;\;\mathsf{fma}\left(x, 2, \left(b \cdot a\right) \cdot 27 - \left(\left(z \cdot y\right) \cdot t\right) \cdot 9\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot a, 27, x \cdot 2\right) - z \cdot \left(9 \cdot \left(y \cdot t\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 -3.087876377269368779883663932063586038326 \cdot 10^{54}:\\
\;\;\;\;\mathsf{fma}\left(x, 2, \left(\left(b \cdot a\right) \cdot \sqrt{27}\right) \cdot \sqrt{27} - y \cdot \left(\left(z \cdot 9\right) \cdot t\right)\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r33215670 = x;
        double r33215671 = 2.0;
        double r33215672 = r33215670 * r33215671;
        double r33215673 = y;
        double r33215674 = 9.0;
        double r33215675 = r33215673 * r33215674;
        double r33215676 = z;
        double r33215677 = r33215675 * r33215676;
        double r33215678 = t;
        double r33215679 = r33215677 * r33215678;
        double r33215680 = r33215672 - r33215679;
        double r33215681 = a;
        double r33215682 = 27.0;
        double r33215683 = r33215681 * r33215682;
        double r33215684 = b;
        double r33215685 = r33215683 * r33215684;
        double r33215686 = r33215680 + r33215685;
        return r33215686;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r33215687 = y;
        double r33215688 = 9.0;
        double r33215689 = r33215687 * r33215688;
        double r33215690 = z;
        double r33215691 = r33215689 * r33215690;
        double r33215692 = -3.087876377269369e+54;
        bool r33215693 = r33215691 <= r33215692;
        double r33215694 = x;
        double r33215695 = 2.0;
        double r33215696 = b;
        double r33215697 = a;
        double r33215698 = r33215696 * r33215697;
        double r33215699 = 27.0;
        double r33215700 = sqrt(r33215699);
        double r33215701 = r33215698 * r33215700;
        double r33215702 = r33215701 * r33215700;
        double r33215703 = r33215690 * r33215688;
        double r33215704 = t;
        double r33215705 = r33215703 * r33215704;
        double r33215706 = r33215687 * r33215705;
        double r33215707 = r33215702 - r33215706;
        double r33215708 = fma(r33215694, r33215695, r33215707);
        double r33215709 = 1.498316341905703e+157;
        bool r33215710 = r33215691 <= r33215709;
        double r33215711 = r33215698 * r33215699;
        double r33215712 = r33215690 * r33215687;
        double r33215713 = r33215712 * r33215704;
        double r33215714 = r33215713 * r33215688;
        double r33215715 = r33215711 - r33215714;
        double r33215716 = fma(r33215694, r33215695, r33215715);
        double r33215717 = r33215694 * r33215695;
        double r33215718 = fma(r33215698, r33215699, r33215717);
        double r33215719 = r33215687 * r33215704;
        double r33215720 = r33215688 * r33215719;
        double r33215721 = r33215690 * r33215720;
        double r33215722 = r33215718 - r33215721;
        double r33215723 = r33215710 ? r33215716 : r33215722;
        double r33215724 = r33215693 ? r33215708 : r33215723;
        return r33215724;
}

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.7
Target2.7
Herbie1.1
\[\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) < -3.087876377269369e+54

    1. Initial program 10.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. Simplified4.3

      \[\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 inf 10.2

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

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

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

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

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

    if -3.087876377269369e+54 < (* (* y 9.0) z) < 1.498316341905703e+157

    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. Simplified3.9

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

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

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

    if 1.498316341905703e+157 < (* (* y 9.0) z)

    1. Initial program 19.8

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

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

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

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

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

Reproduce

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