Average Error: 34.1 → 9.0
Time: 22.0s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -3.408354642852288642375909774932644593067 \cdot 10^{-45}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(4 \cdot c\right)}{a \cdot 2}}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.823335453796603439248590818149160856749 \cdot 10^{131}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\mathbf{elif}\;b \le -3.408354642852288642375909774932644593067 \cdot 10^{-45}:\\
\;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(4 \cdot c\right)}{a \cdot 2}}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + \left(-b\right)}\\

\mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

\mathbf{elif}\;b \le 2.823335453796603439248590818149160856749 \cdot 10^{131}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r3935314 = b;
        double r3935315 = -r3935314;
        double r3935316 = r3935314 * r3935314;
        double r3935317 = 4.0;
        double r3935318 = a;
        double r3935319 = c;
        double r3935320 = r3935318 * r3935319;
        double r3935321 = r3935317 * r3935320;
        double r3935322 = r3935316 - r3935321;
        double r3935323 = sqrt(r3935322);
        double r3935324 = r3935315 - r3935323;
        double r3935325 = 2.0;
        double r3935326 = r3935325 * r3935318;
        double r3935327 = r3935324 / r3935326;
        return r3935327;
}

double f(double a, double b, double c) {
        double r3935328 = b;
        double r3935329 = -2.1229423973235387e+137;
        bool r3935330 = r3935328 <= r3935329;
        double r3935331 = -1.0;
        double r3935332 = c;
        double r3935333 = r3935332 / r3935328;
        double r3935334 = r3935331 * r3935333;
        double r3935335 = -3.4083546428522886e-45;
        bool r3935336 = r3935328 <= r3935335;
        double r3935337 = r3935328 * r3935328;
        double r3935338 = r3935337 - r3935337;
        double r3935339 = a;
        double r3935340 = 4.0;
        double r3935341 = r3935340 * r3935332;
        double r3935342 = r3935339 * r3935341;
        double r3935343 = r3935338 + r3935342;
        double r3935344 = 2.0;
        double r3935345 = r3935339 * r3935344;
        double r3935346 = r3935343 / r3935345;
        double r3935347 = r3935340 * r3935339;
        double r3935348 = r3935332 * r3935347;
        double r3935349 = r3935337 - r3935348;
        double r3935350 = sqrt(r3935349);
        double r3935351 = -r3935328;
        double r3935352 = r3935350 + r3935351;
        double r3935353 = r3935346 / r3935352;
        double r3935354 = -5.546621280225112e-56;
        bool r3935355 = r3935328 <= r3935354;
        double r3935356 = 2.8233354537966034e+131;
        bool r3935357 = r3935328 <= r3935356;
        double r3935358 = r3935351 - r3935350;
        double r3935359 = r3935358 / r3935345;
        double r3935360 = 1.0;
        double r3935361 = r3935328 / r3935339;
        double r3935362 = r3935333 - r3935361;
        double r3935363 = r3935360 * r3935362;
        double r3935364 = r3935357 ? r3935359 : r3935363;
        double r3935365 = r3935355 ? r3935334 : r3935364;
        double r3935366 = r3935336 ? r3935353 : r3935365;
        double r3935367 = r3935330 ? r3935334 : r3935366;
        return r3935367;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.1
Target21.1
Herbie9.0
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -2.1229423973235387e+137 or -3.4083546428522886e-45 < b < -5.546621280225112e-56

    1. Initial program 61.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 2.3

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]

    if -2.1229423973235387e+137 < b < -3.4083546428522886e-45

    1. Initial program 45.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*r*45.3

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{\left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv45.3

      \[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    6. Using strategy rm
    7. Applied flip--45.3

      \[\leadsto \color{blue}{\frac{\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} \cdot \frac{1}{2 \cdot a}\]
    8. Applied associate-*l/45.4

      \[\leadsto \color{blue}{\frac{\left(\left(-b\right) \cdot \left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    9. Simplified11.9

      \[\leadsto \frac{\color{blue}{\frac{\left(b \cdot b - b \cdot b\right) + \left(4 \cdot c\right) \cdot a}{a \cdot 2}}}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\]

    if -5.546621280225112e-56 < b < 2.8233354537966034e+131

    1. Initial program 12.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-*r*12.6

      \[\leadsto \frac{\left(-b\right) - \sqrt{b \cdot b - \color{blue}{\left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv12.8

      \[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    6. Using strategy rm
    7. Applied un-div-inv12.6

      \[\leadsto \color{blue}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\]

    if 2.8233354537966034e+131 < b

    1. Initial program 56.4

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 2.4

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified2.4

      \[\leadsto \color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.122942397323538653087473965252285768999 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -3.408354642852288642375909774932644593067 \cdot 10^{-45}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(4 \cdot c\right)}{a \cdot 2}}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -5.546621280225112292650318866994441138678 \cdot 10^{-56}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 2.823335453796603439248590818149160856749 \cdot 10^{131}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))