Average Error: 34.3 → 6.5
Time: 6.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 -7.6038168240882645 \cdot 10^{144}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.2731438419880699 \cdot 10^{-203}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.1125387673008883 \cdot 10^{122}:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{2}{4}}}{\frac{1}{c}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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 -7.6038168240882645 \cdot 10^{144}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r284431 = b;
        double r284432 = -r284431;
        double r284433 = r284431 * r284431;
        double r284434 = 4.0;
        double r284435 = a;
        double r284436 = r284434 * r284435;
        double r284437 = c;
        double r284438 = r284436 * r284437;
        double r284439 = r284433 - r284438;
        double r284440 = sqrt(r284439);
        double r284441 = r284432 + r284440;
        double r284442 = 2.0;
        double r284443 = r284442 * r284435;
        double r284444 = r284441 / r284443;
        return r284444;
}

double f(double a, double b, double c) {
        double r284445 = b;
        double r284446 = -7.603816824088264e+144;
        bool r284447 = r284445 <= r284446;
        double r284448 = 1.0;
        double r284449 = c;
        double r284450 = r284449 / r284445;
        double r284451 = a;
        double r284452 = r284445 / r284451;
        double r284453 = r284450 - r284452;
        double r284454 = r284448 * r284453;
        double r284455 = -3.27314384198807e-203;
        bool r284456 = r284445 <= r284455;
        double r284457 = -r284445;
        double r284458 = r284445 * r284445;
        double r284459 = 4.0;
        double r284460 = r284459 * r284451;
        double r284461 = r284460 * r284449;
        double r284462 = r284458 - r284461;
        double r284463 = sqrt(r284462);
        double r284464 = sqrt(r284463);
        double r284465 = r284464 * r284464;
        double r284466 = r284457 + r284465;
        double r284467 = 2.0;
        double r284468 = r284467 * r284451;
        double r284469 = r284466 / r284468;
        double r284470 = 2.1125387673008883e+122;
        bool r284471 = r284445 <= r284470;
        double r284472 = 1.0;
        double r284473 = r284467 / r284459;
        double r284474 = r284472 / r284473;
        double r284475 = r284472 / r284449;
        double r284476 = r284474 / r284475;
        double r284477 = r284457 - r284463;
        double r284478 = r284476 / r284477;
        double r284479 = -1.0;
        double r284480 = r284479 * r284450;
        double r284481 = r284471 ? r284478 : r284480;
        double r284482 = r284456 ? r284469 : r284481;
        double r284483 = r284447 ? r284454 : r284482;
        return r284483;
}

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.3
Target21.2
Herbie6.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 4 regimes
  2. if b < -7.603816824088264e+144

    1. Initial program 61.2

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

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

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

    if -7.603816824088264e+144 < b < -3.27314384198807e-203

    1. Initial program 7.1

      \[\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-sqrt7.1

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

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

    if -3.27314384198807e-203 < b < 2.1125387673008883e+122

    1. Initial program 29.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 flip-+29.9

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

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num16.3

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied associate-/r*15.3

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

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

    if 2.1125387673008883e+122 < b

    1. Initial program 61.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.6038168240882645 \cdot 10^{144}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.2731438419880699 \cdot 10^{-203}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;b \le 2.1125387673008883 \cdot 10^{122}:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{2}{4}}}{\frac{1}{c}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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