Average Error: 3.8 → 0.6
Time: 4.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 -1.442353657523720384679958711284619115705 \cdot 10^{-17} \lor \neg \left(t \le 1860873616316365328357708884770553856\right):\\ \;\;\;\;\mathsf{fma}\left(2, x, \left(27 \cdot a\right) \cdot b - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - \left(\left(9 \cdot t\right) \cdot z\right) \cdot y\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 -1.442353657523720384679958711284619115705 \cdot 10^{-17} \lor \neg \left(t \le 1860873616316365328357708884770553856\right):\\
\;\;\;\;\mathsf{fma}\left(2, x, \left(27 \cdot a\right) \cdot b - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r831799 = x;
        double r831800 = 2.0;
        double r831801 = r831799 * r831800;
        double r831802 = y;
        double r831803 = 9.0;
        double r831804 = r831802 * r831803;
        double r831805 = z;
        double r831806 = r831804 * r831805;
        double r831807 = t;
        double r831808 = r831806 * r831807;
        double r831809 = r831801 - r831808;
        double r831810 = a;
        double r831811 = 27.0;
        double r831812 = r831810 * r831811;
        double r831813 = b;
        double r831814 = r831812 * r831813;
        double r831815 = r831809 + r831814;
        return r831815;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r831816 = t;
        double r831817 = -1.4423536575237204e-17;
        bool r831818 = r831816 <= r831817;
        double r831819 = 1.8608736163163653e+36;
        bool r831820 = r831816 <= r831819;
        double r831821 = !r831820;
        bool r831822 = r831818 || r831821;
        double r831823 = 2.0;
        double r831824 = x;
        double r831825 = 27.0;
        double r831826 = a;
        double r831827 = r831825 * r831826;
        double r831828 = b;
        double r831829 = r831827 * r831828;
        double r831830 = 9.0;
        double r831831 = z;
        double r831832 = y;
        double r831833 = r831831 * r831832;
        double r831834 = r831816 * r831833;
        double r831835 = r831830 * r831834;
        double r831836 = r831829 - r831835;
        double r831837 = fma(r831823, r831824, r831836);
        double r831838 = r831826 * r831828;
        double r831839 = r831825 * r831838;
        double r831840 = r831830 * r831816;
        double r831841 = r831840 * r831831;
        double r831842 = r831841 * r831832;
        double r831843 = r831839 - r831842;
        double r831844 = fma(r831823, r831824, r831843);
        double r831845 = r831822 ? r831837 : r831844;
        return r831845;
}

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.8
Target2.8
Herbie0.6
\[\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 t < -1.4423536575237204e-17 or 1.8608736163163653e+36 < t

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

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

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

      \[\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)}\]
    5. Using strategy rm
    6. Applied associate-*r*0.6

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

    if -1.4423536575237204e-17 < t < 1.8608736163163653e+36

    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. Simplified6.0

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

      \[\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)}\]
    5. Using strategy rm
    6. Applied associate-*r*5.8

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

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

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

Reproduce

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