Average Error: 33.7 → 9.9
Time: 15.9s
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.97357776541463793 \cdot 10^{146}:\\ \;\;\;\;\left(1 \cdot \frac{c}{b} - 0.5 \cdot \frac{b}{a}\right) - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.84232518071997008 \cdot 10^{-85}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} - \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.97357776541463793 \cdot 10^{146}:\\
\;\;\;\;\left(1 \cdot \frac{c}{b} - 0.5 \cdot \frac{b}{a}\right) - \frac{b}{2 \cdot a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r60448 = b;
        double r60449 = -r60448;
        double r60450 = r60448 * r60448;
        double r60451 = 4.0;
        double r60452 = a;
        double r60453 = r60451 * r60452;
        double r60454 = c;
        double r60455 = r60453 * r60454;
        double r60456 = r60450 - r60455;
        double r60457 = sqrt(r60456);
        double r60458 = r60449 + r60457;
        double r60459 = 2.0;
        double r60460 = r60459 * r60452;
        double r60461 = r60458 / r60460;
        return r60461;
}

double f(double a, double b, double c) {
        double r60462 = b;
        double r60463 = -2.973577765414638e+146;
        bool r60464 = r60462 <= r60463;
        double r60465 = 1.0;
        double r60466 = c;
        double r60467 = r60466 / r60462;
        double r60468 = r60465 * r60467;
        double r60469 = 0.5;
        double r60470 = a;
        double r60471 = r60462 / r60470;
        double r60472 = r60469 * r60471;
        double r60473 = r60468 - r60472;
        double r60474 = 2.0;
        double r60475 = r60474 * r60470;
        double r60476 = r60462 / r60475;
        double r60477 = r60473 - r60476;
        double r60478 = 4.84232518071997e-85;
        bool r60479 = r60462 <= r60478;
        double r60480 = r60462 * r60462;
        double r60481 = 4.0;
        double r60482 = r60481 * r60470;
        double r60483 = r60482 * r60466;
        double r60484 = r60480 - r60483;
        double r60485 = sqrt(r60484);
        double r60486 = r60485 / r60475;
        double r60487 = r60486 - r60476;
        double r60488 = -1.0;
        double r60489 = r60488 * r60467;
        double r60490 = r60479 ? r60487 : r60489;
        double r60491 = r60464 ? r60477 : r60490;
        return r60491;
}

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.7
Target20.8
Herbie9.9
\[\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.973577765414638e+146

    1. Initial program 60.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified60.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-sub60.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. Taylor expanded around -inf 2.3

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

    if -2.973577765414638e+146 < b < 4.84232518071997e-85

    1. Initial program 11.5

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

      \[\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.5

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

    if 4.84232518071997e-85 < b

    1. Initial program 52.4

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

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

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

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

Reproduce

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