Average Error: 3.4 → 0.6
Time: 4.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 -3.382828072536658317614852819128042503843 \cdot 10^{-36}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \left(y \cdot \left(9 \cdot z\right)\right) \cdot t\right)\\ \mathbf{elif}\;t \le 431252594336352985594280195183564204015600:\\ \;\;\;\;\mathsf{fma}\left(2, x, 27 \cdot \left(a \cdot b\right) - 9 \cdot \left(\left(t \cdot z\right) \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, 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 -3.382828072536658317614852819128042503843 \cdot 10^{-36}:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, x \cdot 2 - \left(y \cdot \left(9 \cdot z\right)\right) \cdot t\right)\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, 27 \cdot b, 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 r866458 = x;
        double r866459 = 2.0;
        double r866460 = r866458 * r866459;
        double r866461 = y;
        double r866462 = 9.0;
        double r866463 = r866461 * r866462;
        double r866464 = z;
        double r866465 = r866463 * r866464;
        double r866466 = t;
        double r866467 = r866465 * r866466;
        double r866468 = r866460 - r866467;
        double r866469 = a;
        double r866470 = 27.0;
        double r866471 = r866469 * r866470;
        double r866472 = b;
        double r866473 = r866471 * r866472;
        double r866474 = r866468 + r866473;
        return r866474;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r866475 = t;
        double r866476 = -3.382828072536658e-36;
        bool r866477 = r866475 <= r866476;
        double r866478 = a;
        double r866479 = 27.0;
        double r866480 = b;
        double r866481 = r866479 * r866480;
        double r866482 = x;
        double r866483 = 2.0;
        double r866484 = r866482 * r866483;
        double r866485 = y;
        double r866486 = 9.0;
        double r866487 = z;
        double r866488 = r866486 * r866487;
        double r866489 = r866485 * r866488;
        double r866490 = r866489 * r866475;
        double r866491 = r866484 - r866490;
        double r866492 = fma(r866478, r866481, r866491);
        double r866493 = 4.31252594336353e+41;
        bool r866494 = r866475 <= r866493;
        double r866495 = r866478 * r866480;
        double r866496 = r866479 * r866495;
        double r866497 = r866475 * r866487;
        double r866498 = r866497 * r866485;
        double r866499 = r866486 * r866498;
        double r866500 = r866496 - r866499;
        double r866501 = fma(r866483, r866482, r866500);
        double r866502 = r866485 * r866486;
        double r866503 = r866502 * r866487;
        double r866504 = r866503 * r866475;
        double r866505 = r866484 - r866504;
        double r866506 = fma(r866478, r866481, r866505);
        double r866507 = r866494 ? r866501 : r866506;
        double r866508 = r866477 ? r866492 : r866507;
        return r866508;
}

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.4
Target2.3
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 < -3.382828072536658e-36

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

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

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

    if -3.382828072536658e-36 < t < 4.31252594336353e+41

    1. Initial program 5.2

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

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

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

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

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

    if 4.31252594336353e+41 < t

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

      \[\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. Recombined 3 regimes into one program.
  4. Final simplification0.6

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

Reproduce

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