Average Error: 7.9 → 5.1
Time: 10.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 -1.84154847940333438 \cdot 10^{268}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right) - 4.5 \cdot \frac{t \cdot z}{a}\\ \mathbf{elif}\;x \cdot y \le 5.0132949514285239 \cdot 10^{-62}:\\ \;\;\;\;\frac{1}{\frac{a}{\mathsf{fma}\left(z \cdot 9, \left(-t\right) + t, x \cdot y - 9 \cdot \left(t \cdot z\right)\right)} \cdot 2}\\ \mathbf{elif}\;x \cdot y \le 1.33984155606375487 \cdot 10^{175}:\\ \;\;\;\;0.5 \cdot \frac{x \cdot y}{a} - \left(t \cdot 4.5\right) \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right) - 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 -1.84154847940333438 \cdot 10^{268}:\\
\;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right) - 4.5 \cdot \frac{t \cdot z}{a}\\

\mathbf{elif}\;x \cdot y \le 5.0132949514285239 \cdot 10^{-62}:\\
\;\;\;\;\frac{1}{\frac{a}{\mathsf{fma}\left(z \cdot 9, \left(-t\right) + t, x \cdot y - 9 \cdot \left(t \cdot z\right)\right)} \cdot 2}\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r4212 = x;
        double r4213 = y;
        double r4214 = r4212 * r4213;
        double r4215 = z;
        double r4216 = 9.0;
        double r4217 = r4215 * r4216;
        double r4218 = t;
        double r4219 = r4217 * r4218;
        double r4220 = r4214 - r4219;
        double r4221 = a;
        double r4222 = 2.0;
        double r4223 = r4221 * r4222;
        double r4224 = r4220 / r4223;
        return r4224;
}

double f(double x, double y, double z, double t, double a) {
        double r4225 = x;
        double r4226 = y;
        double r4227 = r4225 * r4226;
        double r4228 = -1.8415484794033344e+268;
        bool r4229 = r4227 <= r4228;
        double r4230 = 0.5;
        double r4231 = a;
        double r4232 = r4226 / r4231;
        double r4233 = r4225 * r4232;
        double r4234 = r4230 * r4233;
        double r4235 = 4.5;
        double r4236 = t;
        double r4237 = z;
        double r4238 = r4236 * r4237;
        double r4239 = r4238 / r4231;
        double r4240 = r4235 * r4239;
        double r4241 = r4234 - r4240;
        double r4242 = 5.013294951428524e-62;
        bool r4243 = r4227 <= r4242;
        double r4244 = 1.0;
        double r4245 = 9.0;
        double r4246 = r4237 * r4245;
        double r4247 = -r4236;
        double r4248 = r4247 + r4236;
        double r4249 = r4245 * r4238;
        double r4250 = r4227 - r4249;
        double r4251 = fma(r4246, r4248, r4250);
        double r4252 = r4231 / r4251;
        double r4253 = 2.0;
        double r4254 = r4252 * r4253;
        double r4255 = r4244 / r4254;
        double r4256 = 1.3398415560637549e+175;
        bool r4257 = r4227 <= r4256;
        double r4258 = r4227 / r4231;
        double r4259 = r4230 * r4258;
        double r4260 = r4236 * r4235;
        double r4261 = r4237 / r4231;
        double r4262 = r4260 * r4261;
        double r4263 = r4259 - r4262;
        double r4264 = r4257 ? r4263 : r4241;
        double r4265 = r4243 ? r4255 : r4264;
        double r4266 = r4229 ? r4241 : r4265;
        return r4266;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original7.9
Target5.5
Herbie5.1
\[\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) < -1.8415484794033344e+268 or 1.3398415560637549e+175 < (* x y)

    1. Initial program 33.3

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

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

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

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

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

    if -1.8415484794033344e+268 < (* x y) < 5.013294951428524e-62

    1. Initial program 4.6

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

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

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

      \[\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 clear-num5.0

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

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

    if 5.013294951428524e-62 < (* x y) < 1.3398415560637549e+175

    1. Initial program 3.5

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}\]
    2. Taylor expanded around 0 3.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 *-un-lft-identity3.4

      \[\leadsto 0.5 \cdot \frac{x \cdot y}{a} - 4.5 \cdot \frac{t \cdot z}{\color{blue}{1 \cdot a}}\]
    5. Applied times-frac4.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*4.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. Simplified4.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \le -1.84154847940333438 \cdot 10^{268}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right) - 4.5 \cdot \frac{t \cdot z}{a}\\ \mathbf{elif}\;x \cdot y \le 5.0132949514285239 \cdot 10^{-62}:\\ \;\;\;\;\frac{1}{\frac{a}{\mathsf{fma}\left(z \cdot 9, \left(-t\right) + t, x \cdot y - 9 \cdot \left(t \cdot z\right)\right)} \cdot 2}\\ \mathbf{elif}\;x \cdot y \le 1.33984155606375487 \cdot 10^{175}:\\ \;\;\;\;0.5 \cdot \frac{x \cdot y}{a} - \left(t \cdot 4.5\right) \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right) - 4.5 \cdot \frac{t \cdot z}{a}\\ \end{array}\]

Reproduce

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