Average Error: 3.7 → 0.6
Time: 11.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 -4.010002446592372438474945913594818898356 \cdot 10^{58}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, 2 \cdot x\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{elif}\;t \le 6.480925815489128716088713250131903009787 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\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 -4.010002446592372438474945913594818898356 \cdot 10^{58}:\\
\;\;\;\;\mathsf{fma}\left(27, a \cdot b, 2 \cdot x\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\

\mathbf{elif}\;t \le 6.480925815489128716088713250131903009787 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\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 r848118 = x;
        double r848119 = 2.0;
        double r848120 = r848118 * r848119;
        double r848121 = y;
        double r848122 = 9.0;
        double r848123 = r848121 * r848122;
        double r848124 = z;
        double r848125 = r848123 * r848124;
        double r848126 = t;
        double r848127 = r848125 * r848126;
        double r848128 = r848120 - r848127;
        double r848129 = a;
        double r848130 = 27.0;
        double r848131 = r848129 * r848130;
        double r848132 = b;
        double r848133 = r848131 * r848132;
        double r848134 = r848128 + r848133;
        return r848134;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r848135 = t;
        double r848136 = -4.0100024465923724e+58;
        bool r848137 = r848135 <= r848136;
        double r848138 = 27.0;
        double r848139 = a;
        double r848140 = b;
        double r848141 = r848139 * r848140;
        double r848142 = 2.0;
        double r848143 = x;
        double r848144 = r848142 * r848143;
        double r848145 = fma(r848138, r848141, r848144);
        double r848146 = 9.0;
        double r848147 = z;
        double r848148 = y;
        double r848149 = r848147 * r848148;
        double r848150 = r848135 * r848149;
        double r848151 = r848146 * r848150;
        double r848152 = r848145 - r848151;
        double r848153 = 6.480925815489129e-06;
        bool r848154 = r848135 <= r848153;
        double r848155 = r848139 * r848138;
        double r848156 = r848143 * r848142;
        double r848157 = r848147 * r848135;
        double r848158 = r848146 * r848157;
        double r848159 = r848148 * r848158;
        double r848160 = r848156 - r848159;
        double r848161 = fma(r848155, r848140, r848160);
        double r848162 = r848138 * r848141;
        double r848163 = r848148 * r848146;
        double r848164 = r848163 * r848147;
        double r848165 = r848164 * r848135;
        double r848166 = r848156 - r848165;
        double r848167 = r848162 + r848166;
        double r848168 = r848154 ? r848161 : r848167;
        double r848169 = r848137 ? r848152 : r848168;
        return r848169;
}

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.6
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 3 regimes
  2. if t < -4.0100024465923724e+58

    1. Initial program 0.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. Simplified0.8

      \[\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 associate-*l*9.1

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

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

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \color{blue}{\left(\left(9 \cdot z\right) \cdot t\right)}\right)\]
    9. Taylor expanded around inf 0.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)}\]
    10. Simplified0.8

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

    if -4.0100024465923724e+58 < t < 6.480925815489129e-06

    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. Using strategy rm
    4. Applied associate-*l*0.6

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

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

    if 6.480925815489129e-06 < t

    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. Using strategy rm
    4. Applied fma-udef0.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \le -4.010002446592372438474945913594818898356 \cdot 10^{58}:\\ \;\;\;\;\mathsf{fma}\left(27, a \cdot b, 2 \cdot x\right) - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\\ \mathbf{elif}\;t \le 6.480925815489128716088713250131903009787 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - y \cdot \left(9 \cdot \left(z \cdot t\right)\right)\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 2019350 +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)))