Average Error: 34.0 → 9.9
Time: 12.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 -1.706986096130973982874965914706841162261 \cdot 10^{105}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.220579098145180702729203762831186311473 \cdot 10^{-72}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{1}{\frac{a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \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 -1.706986096130973982874965914706841162261 \cdot 10^{105}:\\
\;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\

\end{array}
double f(double a, double b, double c) {
        double r107321 = b;
        double r107322 = -r107321;
        double r107323 = r107321 * r107321;
        double r107324 = 4.0;
        double r107325 = a;
        double r107326 = r107324 * r107325;
        double r107327 = c;
        double r107328 = r107326 * r107327;
        double r107329 = r107323 - r107328;
        double r107330 = sqrt(r107329);
        double r107331 = r107322 + r107330;
        double r107332 = 2.0;
        double r107333 = r107332 * r107325;
        double r107334 = r107331 / r107333;
        return r107334;
}

double f(double a, double b, double c) {
        double r107335 = b;
        double r107336 = -1.706986096130974e+105;
        bool r107337 = r107335 <= r107336;
        double r107338 = 1.0;
        double r107339 = 2.0;
        double r107340 = r107338 / r107339;
        double r107341 = c;
        double r107342 = r107341 / r107335;
        double r107343 = r107339 * r107342;
        double r107344 = 2.0;
        double r107345 = a;
        double r107346 = r107335 / r107345;
        double r107347 = r107344 * r107346;
        double r107348 = r107343 - r107347;
        double r107349 = r107340 * r107348;
        double r107350 = 1.2205790981451807e-72;
        bool r107351 = r107335 <= r107350;
        double r107352 = r107335 * r107335;
        double r107353 = 4.0;
        double r107354 = r107353 * r107345;
        double r107355 = r107354 * r107341;
        double r107356 = r107352 - r107355;
        double r107357 = sqrt(r107356);
        double r107358 = r107357 - r107335;
        double r107359 = r107345 / r107358;
        double r107360 = r107338 / r107359;
        double r107361 = r107340 * r107360;
        double r107362 = -2.0;
        double r107363 = r107362 * r107342;
        double r107364 = r107340 * r107363;
        double r107365 = r107351 ? r107361 : r107364;
        double r107366 = r107337 ? r107349 : r107365;
        return r107366;
}

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.0
Target21.0
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 < -1.706986096130974e+105

    1. Initial program 48.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified48.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 *-un-lft-identity48.7

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

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

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

    if -1.706986096130974e+105 < b < 1.2205790981451807e-72

    1. Initial program 12.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified12.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 *-un-lft-identity12.7

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a}}\]
    6. Using strategy rm
    7. Applied clear-num12.8

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

    if 1.2205790981451807e-72 < b

    1. Initial program 53.4

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

      \[\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 *-un-lft-identity53.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.706986096130973982874965914706841162261 \cdot 10^{105}:\\ \;\;\;\;\frac{1}{2} \cdot \left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.220579098145180702729203762831186311473 \cdot 10^{-72}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{1}{\frac{a}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \left(-2 \cdot \frac{c}{b}\right)\\ \end{array}\]

Reproduce

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