Average Error: 34.6 → 10.5
Time: 21.8s
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.8920328608199634 \cdot 10^{82}:\\ \;\;\;\;\left(1 \cdot \frac{c}{b} - 0.5 \cdot \frac{b}{a}\right) - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} - \frac{b}{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.8920328608199634 \cdot 10^{82}:\\
\;\;\;\;\left(1 \cdot \frac{c}{b} - 0.5 \cdot \frac{b}{a}\right) - \frac{b}{2 \cdot a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r70333 = b;
        double r70334 = -r70333;
        double r70335 = r70333 * r70333;
        double r70336 = 4.0;
        double r70337 = a;
        double r70338 = r70336 * r70337;
        double r70339 = c;
        double r70340 = r70338 * r70339;
        double r70341 = r70335 - r70340;
        double r70342 = sqrt(r70341);
        double r70343 = r70334 + r70342;
        double r70344 = 2.0;
        double r70345 = r70344 * r70337;
        double r70346 = r70343 / r70345;
        return r70346;
}

double f(double a, double b, double c) {
        double r70347 = b;
        double r70348 = -2.8920328608199634e+82;
        bool r70349 = r70347 <= r70348;
        double r70350 = 1.0;
        double r70351 = c;
        double r70352 = r70351 / r70347;
        double r70353 = r70350 * r70352;
        double r70354 = 0.5;
        double r70355 = a;
        double r70356 = r70347 / r70355;
        double r70357 = r70354 * r70356;
        double r70358 = r70353 - r70357;
        double r70359 = 2.0;
        double r70360 = r70359 * r70355;
        double r70361 = r70347 / r70360;
        double r70362 = r70358 - r70361;
        double r70363 = 2.4581158795060287e-136;
        bool r70364 = r70347 <= r70363;
        double r70365 = 1.0;
        double r70366 = r70347 * r70347;
        double r70367 = 4.0;
        double r70368 = r70367 * r70355;
        double r70369 = r70368 * r70351;
        double r70370 = r70366 - r70369;
        double r70371 = sqrt(r70370);
        double r70372 = r70360 / r70371;
        double r70373 = r70365 / r70372;
        double r70374 = r70373 - r70361;
        double r70375 = -1.0;
        double r70376 = r70375 * r70352;
        double r70377 = r70364 ? r70374 : r70376;
        double r70378 = r70349 ? r70362 : r70377;
        return r70378;
}

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.6
Target21.3
Herbie10.5
\[\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.8920328608199634e+82

    1. Initial program 44.2

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

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

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

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

    if -2.8920328608199634e+82 < b < 2.4581158795060287e-136

    1. Initial program 11.7

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

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

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

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

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

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

    if 2.4581158795060287e-136 < b

    1. Initial program 50.8

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.8920328608199634 \cdot 10^{82}:\\ \;\;\;\;\left(1 \cdot \frac{c}{b} - 0.5 \cdot \frac{b}{a}\right) - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.45811587950602871 \cdot 10^{-136}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}} - \frac{b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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

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

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