Average Error: 32.7 → 10.1
Time: 15.1s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.34601621878688 \cdot 10^{+118}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.3115303715225787 \cdot 10^{-131}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -2.34601621878688 \cdot 10^{+118}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\

\end{array}
double f(double a, double b, double c) {
        double r5029298 = b;
        double r5029299 = -r5029298;
        double r5029300 = r5029298 * r5029298;
        double r5029301 = 4.0;
        double r5029302 = a;
        double r5029303 = r5029301 * r5029302;
        double r5029304 = c;
        double r5029305 = r5029303 * r5029304;
        double r5029306 = r5029300 - r5029305;
        double r5029307 = sqrt(r5029306);
        double r5029308 = r5029299 + r5029307;
        double r5029309 = 2.0;
        double r5029310 = r5029309 * r5029302;
        double r5029311 = r5029308 / r5029310;
        return r5029311;
}

double f(double a, double b, double c) {
        double r5029312 = b;
        double r5029313 = -2.34601621878688e+118;
        bool r5029314 = r5029312 <= r5029313;
        double r5029315 = c;
        double r5029316 = r5029315 / r5029312;
        double r5029317 = a;
        double r5029318 = r5029312 / r5029317;
        double r5029319 = r5029316 - r5029318;
        double r5029320 = 1.3115303715225787e-131;
        bool r5029321 = r5029312 <= r5029320;
        double r5029322 = 1.0;
        double r5029323 = 2.0;
        double r5029324 = r5029317 * r5029323;
        double r5029325 = r5029322 / r5029324;
        double r5029326 = r5029312 * r5029312;
        double r5029327 = r5029315 * r5029317;
        double r5029328 = 4.0;
        double r5029329 = r5029327 * r5029328;
        double r5029330 = r5029326 - r5029329;
        double r5029331 = sqrt(r5029330);
        double r5029332 = r5029331 - r5029312;
        double r5029333 = r5029325 * r5029332;
        double r5029334 = -r5029316;
        double r5029335 = r5029321 ? r5029333 : r5029334;
        double r5029336 = r5029314 ? r5029319 : r5029335;
        return r5029336;
}

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

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

Derivation

  1. Split input into 3 regimes
  2. if b < -2.34601621878688e+118

    1. Initial program 48.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified48.8

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 3.1

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

    if -2.34601621878688e+118 < b < 1.3115303715225787e-131

    1. Initial program 10.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified10.7

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity10.7

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - \color{blue}{1 \cdot b}}{2 \cdot a}\]
    5. Applied *-un-lft-identity10.7

      \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}} - 1 \cdot b}{2 \cdot a}\]
    6. Applied distribute-lft-out--10.7

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}}\]
    8. Using strategy rm
    9. Applied associate-/r/10.8

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

    if 1.3115303715225787e-131 < b

    1. Initial program 50.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified50.3

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}}\]
    3. Taylor expanded around inf 11.7

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified11.7

      \[\leadsto \color{blue}{\frac{-c}{b}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.34601621878688 \cdot 10^{+118}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.3115303715225787 \cdot 10^{-131}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019134 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))