Average Error: 34.1 → 10.6
Time: 5.4s
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.2375225949334019 \cdot 10^{57}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 8.67970785211126629 \cdot 10^{-40}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \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.2375225949334019 \cdot 10^{57}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r195208 = b;
        double r195209 = -r195208;
        double r195210 = r195208 * r195208;
        double r195211 = 4.0;
        double r195212 = a;
        double r195213 = r195211 * r195212;
        double r195214 = c;
        double r195215 = r195213 * r195214;
        double r195216 = r195210 - r195215;
        double r195217 = sqrt(r195216);
        double r195218 = r195209 + r195217;
        double r195219 = 2.0;
        double r195220 = r195219 * r195212;
        double r195221 = r195218 / r195220;
        return r195221;
}

double f(double a, double b, double c) {
        double r195222 = b;
        double r195223 = -2.237522594933402e+57;
        bool r195224 = r195222 <= r195223;
        double r195225 = 1.0;
        double r195226 = c;
        double r195227 = r195226 / r195222;
        double r195228 = a;
        double r195229 = r195222 / r195228;
        double r195230 = r195227 - r195229;
        double r195231 = r195225 * r195230;
        double r195232 = 8.679707852111266e-40;
        bool r195233 = r195222 <= r195232;
        double r195234 = -r195222;
        double r195235 = r195222 * r195222;
        double r195236 = 4.0;
        double r195237 = r195236 * r195228;
        double r195238 = r195237 * r195226;
        double r195239 = r195235 - r195238;
        double r195240 = sqrt(r195239);
        double r195241 = r195234 + r195240;
        double r195242 = 2.0;
        double r195243 = r195242 * r195228;
        double r195244 = r195241 / r195243;
        double r195245 = -1.0;
        double r195246 = r195245 * r195227;
        double r195247 = r195233 ? r195244 : r195246;
        double r195248 = r195224 ? r195231 : r195247;
        return r195248;
}

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
Target20.9
Herbie10.6
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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.237522594933402e+57

    1. Initial program 38.1

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

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

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

    if -2.237522594933402e+57 < b < 8.679707852111266e-40

    1. Initial program 15.3

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

      \[\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}}\]
    4. Using strategy rm
    5. Applied un-div-inv15.3

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

    if 8.679707852111266e-40 < b

    1. Initial program 55.1

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

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

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

Reproduce

herbie shell --seed 2020025 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :herbie-target
  (if (< b 0.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)))