Average Error: 3.7 → 1.3
Time: 11.3s
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}\;y \cdot 9 \le -8.63828739859890366 \cdot 10^{64} \lor \neg \left(y \cdot 9 \le 4.26640526336584695 \cdot 10^{171}\right):\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot 27, b, \left(2 \cdot x - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right) + \left(\left(-t\right) \cdot \left(9 \cdot \left(z \cdot y\right)\right) + 9 \cdot \left(t \cdot \left(z \cdot y\right)\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}\;y \cdot 9 \le -8.63828739859890366 \cdot 10^{64} \lor \neg \left(y \cdot 9 \le 4.26640526336584695 \cdot 10^{171}\right):\\
\;\;\;\;\mathsf{fma}\left(a \cdot 27, b, x \cdot 2 - \left(y \cdot 9\right) \cdot \left(z \cdot t\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r663357 = x;
        double r663358 = 2.0;
        double r663359 = r663357 * r663358;
        double r663360 = y;
        double r663361 = 9.0;
        double r663362 = r663360 * r663361;
        double r663363 = z;
        double r663364 = r663362 * r663363;
        double r663365 = t;
        double r663366 = r663364 * r663365;
        double r663367 = r663359 - r663366;
        double r663368 = a;
        double r663369 = 27.0;
        double r663370 = r663368 * r663369;
        double r663371 = b;
        double r663372 = r663370 * r663371;
        double r663373 = r663367 + r663372;
        return r663373;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r663374 = y;
        double r663375 = 9.0;
        double r663376 = r663374 * r663375;
        double r663377 = -8.638287398598904e+64;
        bool r663378 = r663376 <= r663377;
        double r663379 = 4.266405263365847e+171;
        bool r663380 = r663376 <= r663379;
        double r663381 = !r663380;
        bool r663382 = r663378 || r663381;
        double r663383 = a;
        double r663384 = 27.0;
        double r663385 = r663383 * r663384;
        double r663386 = b;
        double r663387 = x;
        double r663388 = 2.0;
        double r663389 = r663387 * r663388;
        double r663390 = z;
        double r663391 = t;
        double r663392 = r663390 * r663391;
        double r663393 = r663376 * r663392;
        double r663394 = r663389 - r663393;
        double r663395 = fma(r663385, r663386, r663394);
        double r663396 = r663388 * r663387;
        double r663397 = r663390 * r663374;
        double r663398 = r663391 * r663397;
        double r663399 = r663375 * r663398;
        double r663400 = r663396 - r663399;
        double r663401 = -r663391;
        double r663402 = r663375 * r663397;
        double r663403 = r663401 * r663402;
        double r663404 = r663403 + r663399;
        double r663405 = r663400 + r663404;
        double r663406 = fma(r663385, r663386, r663405);
        double r663407 = r663382 ? r663395 : r663406;
        return r663407;
}

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
Herbie1.3
\[\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) < -8.638287398598904e+64 or 4.266405263365847e+171 < (* y 9.0)

    1. Initial program 10.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. Simplified10.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 associate-*l*1.0

      \[\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)\]

    if -8.638287398598904e+64 < (* y 9.0) < 4.266405263365847e+171

    1. Initial program 1.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. Simplified1.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 prod-diff1.4

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

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

      \[\leadsto \mathsf{fma}\left(a \cdot 27, b, \left(2 \cdot x - 9 \cdot \left(t \cdot \left(z \cdot y\right)\right)\right) + \color{blue}{\left(9 \cdot \left(z \cdot y\right)\right) \cdot \left(\left(-t\right) + t\right)}\right)\]
    7. Using strategy rm
    8. Applied distribute-lft-in1.4

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

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

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

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

Reproduce

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