Average Error: 33.2 → 10.6
Time: 27.6s
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 -3.5748480491313226 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.821014310434392 \cdot 10^{-21}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{\frac{a \cdot 2}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\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 -3.5748480491313226 \cdot 10^{+106}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r8120259 = b;
        double r8120260 = -r8120259;
        double r8120261 = r8120259 * r8120259;
        double r8120262 = 4.0;
        double r8120263 = a;
        double r8120264 = r8120262 * r8120263;
        double r8120265 = c;
        double r8120266 = r8120264 * r8120265;
        double r8120267 = r8120261 - r8120266;
        double r8120268 = sqrt(r8120267);
        double r8120269 = r8120260 + r8120268;
        double r8120270 = 2.0;
        double r8120271 = r8120270 * r8120263;
        double r8120272 = r8120269 / r8120271;
        return r8120272;
}

double f(double a, double b, double c) {
        double r8120273 = b;
        double r8120274 = -3.5748480491313226e+106;
        bool r8120275 = r8120273 <= r8120274;
        double r8120276 = c;
        double r8120277 = r8120276 / r8120273;
        double r8120278 = a;
        double r8120279 = r8120273 / r8120278;
        double r8120280 = r8120277 - r8120279;
        double r8120281 = 3.821014310434392e-21;
        bool r8120282 = r8120273 <= r8120281;
        double r8120283 = -r8120273;
        double r8120284 = r8120273 * r8120273;
        double r8120285 = 4.0;
        double r8120286 = r8120285 * r8120278;
        double r8120287 = r8120276 * r8120286;
        double r8120288 = r8120284 - r8120287;
        double r8120289 = sqrt(r8120288);
        double r8120290 = r8120283 + r8120289;
        double r8120291 = sqrt(r8120290);
        double r8120292 = 2.0;
        double r8120293 = r8120278 * r8120292;
        double r8120294 = r8120293 / r8120291;
        double r8120295 = r8120291 / r8120294;
        double r8120296 = -r8120277;
        double r8120297 = r8120282 ? r8120295 : r8120296;
        double r8120298 = r8120275 ? r8120280 : r8120297;
        return r8120298;
}

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

Original33.2
Target20.5
Herbie10.6
\[\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 < -3.5748480491313226e+106

    1. Initial program 46.5

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

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

    if -3.5748480491313226e+106 < b < 3.821014310434392e-21

    1. Initial program 14.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt15.2

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

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

    if 3.821014310434392e-21 < b

    1. Initial program 54.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified6.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.5748480491313226 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 3.821014310434392 \cdot 10^{-21}:\\ \;\;\;\;\frac{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{\frac{a \cdot 2}{\sqrt{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019149 
(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)))