Average Error: 3.7 → 0.7
Time: 16.8s
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 -21855168504066649061551236802221703168:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(9 \cdot t\right) \cdot \left(z \cdot y\right)\right)\\ \mathbf{elif}\;t \le 47562004102643877624676352:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(\left(9 \cdot t\right) \cdot z\right) \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;27 \cdot \left(a \cdot b\right) + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\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 -21855168504066649061551236802221703168:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(9 \cdot t\right) \cdot \left(z \cdot y\right)\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r559113 = x;
        double r559114 = 2.0;
        double r559115 = r559113 * r559114;
        double r559116 = y;
        double r559117 = 9.0;
        double r559118 = r559116 * r559117;
        double r559119 = z;
        double r559120 = r559118 * r559119;
        double r559121 = t;
        double r559122 = r559120 * r559121;
        double r559123 = r559115 - r559122;
        double r559124 = a;
        double r559125 = 27.0;
        double r559126 = r559124 * r559125;
        double r559127 = b;
        double r559128 = r559126 * r559127;
        double r559129 = r559123 + r559128;
        return r559129;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r559130 = t;
        double r559131 = -2.185516850406665e+37;
        bool r559132 = r559130 <= r559131;
        double r559133 = a;
        double r559134 = 27.0;
        double r559135 = r559133 * r559134;
        double r559136 = b;
        double r559137 = x;
        double r559138 = 2.0;
        double r559139 = r559137 * r559138;
        double r559140 = 9.0;
        double r559141 = r559140 * r559130;
        double r559142 = z;
        double r559143 = y;
        double r559144 = r559142 * r559143;
        double r559145 = r559141 * r559144;
        double r559146 = r559139 - r559145;
        double r559147 = fma(r559135, r559136, r559146);
        double r559148 = 4.756200410264388e+25;
        bool r559149 = r559130 <= r559148;
        double r559150 = r559141 * r559142;
        double r559151 = r559150 * r559143;
        double r559152 = r559139 - r559151;
        double r559153 = fma(r559135, r559136, r559152);
        double r559154 = r559133 * r559136;
        double r559155 = r559134 * r559154;
        double r559156 = r559143 * r559140;
        double r559157 = r559156 * r559142;
        double r559158 = r559157 * r559130;
        double r559159 = r559139 - r559158;
        double r559160 = r559155 + r559159;
        double r559161 = r559149 ? r559153 : r559160;
        double r559162 = r559132 ? r559147 : r559161;
        return r559162;
}

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.9
Herbie0.7
\[\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 t < -2.185516850406665e+37

    1. Initial program 0.9

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

      \[\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, x \cdot 2 - \color{blue}{9 \cdot \left(t \cdot \left(z \cdot y\right)\right)}\right)\]
    4. Using strategy rm
    5. Applied associate-*r*1.1

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

    if -2.185516850406665e+37 < t < 4.756200410264388e+25

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

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

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

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

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

    if 4.756200410264388e+25 < 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.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. Using strategy rm
    4. Applied fma-udef0.7

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

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

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

Reproduce

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