Average Error: 7.7 → 5.2
Time: 3.8s
Precision: 64
\[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot y \le -8.1516548360793441 \cdot 10^{300}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}} - 4.5 \cdot \frac{t \cdot z}{a}\\ \mathbf{elif}\;x \cdot y \le 3.69781325821701342 \cdot 10^{-255}:\\ \;\;\;\;0.5 \cdot \frac{x \cdot y}{a} - \left(t \cdot 4.5\right) \cdot \frac{z}{a}\\ \mathbf{elif}\;x \cdot y \le 6.2688458872086312 \cdot 10^{203}:\\ \;\;\;\;\frac{x \cdot y}{a \cdot 2} - \frac{z \cdot 9}{2} \cdot \frac{t - \left(\left(-t\right) + t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}} - 4.5 \cdot \frac{t \cdot z}{a}\\ \end{array}\]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
\mathbf{if}\;x \cdot y \le -8.1516548360793441 \cdot 10^{300}:\\
\;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}} - 4.5 \cdot \frac{t \cdot z}{a}\\

\mathbf{elif}\;x \cdot y \le 3.69781325821701342 \cdot 10^{-255}:\\
\;\;\;\;0.5 \cdot \frac{x \cdot y}{a} - \left(t \cdot 4.5\right) \cdot \frac{z}{a}\\

\mathbf{elif}\;x \cdot y \le 6.2688458872086312 \cdot 10^{203}:\\
\;\;\;\;\frac{x \cdot y}{a \cdot 2} - \frac{z \cdot 9}{2} \cdot \frac{t - \left(\left(-t\right) + t\right)}{a}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}} - 4.5 \cdot \frac{t \cdot z}{a}\\

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r735497 = x;
        double r735498 = y;
        double r735499 = r735497 * r735498;
        double r735500 = z;
        double r735501 = 9.0;
        double r735502 = r735500 * r735501;
        double r735503 = t;
        double r735504 = r735502 * r735503;
        double r735505 = r735499 - r735504;
        double r735506 = a;
        double r735507 = 2.0;
        double r735508 = r735506 * r735507;
        double r735509 = r735505 / r735508;
        return r735509;
}

double f(double x, double y, double z, double t, double a) {
        double r735510 = x;
        double r735511 = y;
        double r735512 = r735510 * r735511;
        double r735513 = -8.151654836079344e+300;
        bool r735514 = r735512 <= r735513;
        double r735515 = 0.5;
        double r735516 = a;
        double r735517 = r735516 / r735511;
        double r735518 = r735510 / r735517;
        double r735519 = r735515 * r735518;
        double r735520 = 4.5;
        double r735521 = t;
        double r735522 = z;
        double r735523 = r735521 * r735522;
        double r735524 = r735523 / r735516;
        double r735525 = r735520 * r735524;
        double r735526 = r735519 - r735525;
        double r735527 = 3.6978132582170134e-255;
        bool r735528 = r735512 <= r735527;
        double r735529 = r735512 / r735516;
        double r735530 = r735515 * r735529;
        double r735531 = r735521 * r735520;
        double r735532 = r735522 / r735516;
        double r735533 = r735531 * r735532;
        double r735534 = r735530 - r735533;
        double r735535 = 6.268845887208631e+203;
        bool r735536 = r735512 <= r735535;
        double r735537 = 2.0;
        double r735538 = r735516 * r735537;
        double r735539 = r735512 / r735538;
        double r735540 = 9.0;
        double r735541 = r735522 * r735540;
        double r735542 = r735541 / r735537;
        double r735543 = -r735521;
        double r735544 = r735543 + r735521;
        double r735545 = r735521 - r735544;
        double r735546 = r735545 / r735516;
        double r735547 = r735542 * r735546;
        double r735548 = r735539 - r735547;
        double r735549 = r735536 ? r735548 : r735526;
        double r735550 = r735528 ? r735534 : r735549;
        double r735551 = r735514 ? r735526 : r735550;
        return r735551;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.7
Target5.8
Herbie5.2
\[\begin{array}{l} \mathbf{if}\;a \lt -2.090464557976709 \cdot 10^{86}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot x}{a} - 4.5 \cdot \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;a \lt 2.14403070783397609 \cdot 10^{99}:\\ \;\;\;\;\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot \left(x \cdot 0.5\right) - \frac{t}{a} \cdot \left(z \cdot 4.5\right)\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* x y) < -8.151654836079344e+300 or 6.268845887208631e+203 < (* x y)

    1. Initial program 40.5

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
    2. Taylor expanded around 0 40.4

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{a} - 4.5 \cdot \frac{t \cdot z}{a}}\]
    3. Using strategy rm
    4. Applied associate-/l*7.4

      \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{a}{y}}} - 4.5 \cdot \frac{t \cdot z}{a}\]

    if -8.151654836079344e+300 < (* x y) < 3.6978132582170134e-255

    1. Initial program 4.1

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
    2. Taylor expanded around 0 4.0

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{a} - 4.5 \cdot \frac{t \cdot z}{a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity4.0

      \[\leadsto 0.5 \cdot \frac{x \cdot y}{a} - 4.5 \cdot \frac{t \cdot z}{\color{blue}{1 \cdot a}}\]
    5. Applied times-frac5.2

      \[\leadsto 0.5 \cdot \frac{x \cdot y}{a} - 4.5 \cdot \color{blue}{\left(\frac{t}{1} \cdot \frac{z}{a}\right)}\]
    6. Applied associate-*r*5.3

      \[\leadsto 0.5 \cdot \frac{x \cdot y}{a} - \color{blue}{\left(4.5 \cdot \frac{t}{1}\right) \cdot \frac{z}{a}}\]
    7. Simplified5.3

      \[\leadsto 0.5 \cdot \frac{x \cdot y}{a} - \color{blue}{\left(t \cdot 4.5\right)} \cdot \frac{z}{a}\]

    if 3.6978132582170134e-255 < (* x y) < 6.268845887208631e+203

    1. Initial program 3.9

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
    2. Using strategy rm
    3. Applied prod-diff3.9

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

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

      \[\leadsto \frac{\left(x \cdot y - 9 \cdot \left(t \cdot z\right)\right) + \color{blue}{\left(z \cdot 9\right) \cdot \left(\left(-t\right) + t\right)}}{a \cdot 2}\]
    6. Using strategy rm
    7. Applied associate-+l-3.9

      \[\leadsto \frac{\color{blue}{x \cdot y - \left(9 \cdot \left(t \cdot z\right) - \left(z \cdot 9\right) \cdot \left(\left(-t\right) + t\right)\right)}}{a \cdot 2}\]
    8. Applied div-sub3.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \le -8.1516548360793441 \cdot 10^{300}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}} - 4.5 \cdot \frac{t \cdot z}{a}\\ \mathbf{elif}\;x \cdot y \le 3.69781325821701342 \cdot 10^{-255}:\\ \;\;\;\;0.5 \cdot \frac{x \cdot y}{a} - \left(t \cdot 4.5\right) \cdot \frac{z}{a}\\ \mathbf{elif}\;x \cdot y \le 6.2688458872086312 \cdot 10^{203}:\\ \;\;\;\;\frac{x \cdot y}{a \cdot 2} - \frac{z \cdot 9}{2} \cdot \frac{t - \left(\left(-t\right) + t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{a}{y}} - 4.5 \cdot \frac{t \cdot z}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2020046 +o rules:numerics
(FPCore (x y z t a)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, I"
  :precision binary64

  :herbie-target
  (if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9 t))) (* a 2)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))

  (/ (- (* x y) (* (* z 9) t)) (* a 2)))