Average Error: 34.3 → 9.0
Time: 5.2s
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.92241589842694968 \cdot 10^{111}:\\ \;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2 \cdot a}\\ \mathbf{elif}\;b \le -4.9276367402926466 \cdot 10^{-151}:\\ \;\;\;\;\frac{\left(\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.32579379880372662 \cdot 10^{154}:\\ \;\;\;\;\frac{\frac{1}{\frac{2}{4}} \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(\frac{2}{4} \cdot \frac{1}{c}\right) \cdot \left(2 \cdot \frac{a \cdot c}{b} - 2 \cdot 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 -2.92241589842694968 \cdot 10^{111}:\\
\;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2 \cdot a}\\

\mathbf{elif}\;b \le -4.9276367402926466 \cdot 10^{-151}:\\
\;\;\;\;\frac{\left(\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r149504 = b;
        double r149505 = -r149504;
        double r149506 = r149504 * r149504;
        double r149507 = 4.0;
        double r149508 = a;
        double r149509 = r149507 * r149508;
        double r149510 = c;
        double r149511 = r149509 * r149510;
        double r149512 = r149506 - r149511;
        double r149513 = sqrt(r149512);
        double r149514 = r149505 + r149513;
        double r149515 = 2.0;
        double r149516 = r149515 * r149508;
        double r149517 = r149514 / r149516;
        return r149517;
}

double f(double a, double b, double c) {
        double r149518 = b;
        double r149519 = -2.9224158984269497e+111;
        bool r149520 = r149518 <= r149519;
        double r149521 = 2.0;
        double r149522 = a;
        double r149523 = c;
        double r149524 = r149522 * r149523;
        double r149525 = r149524 / r149518;
        double r149526 = r149521 * r149525;
        double r149527 = 2.0;
        double r149528 = r149527 * r149518;
        double r149529 = r149526 - r149528;
        double r149530 = r149521 * r149522;
        double r149531 = r149529 / r149530;
        double r149532 = -4.9276367402926466e-151;
        bool r149533 = r149518 <= r149532;
        double r149534 = -r149518;
        double r149535 = r149518 * r149518;
        double r149536 = 4.0;
        double r149537 = r149536 * r149522;
        double r149538 = r149537 * r149523;
        double r149539 = r149535 - r149538;
        double r149540 = sqrt(r149539);
        double r149541 = r149534 + r149540;
        double r149542 = cbrt(r149541);
        double r149543 = r149542 * r149542;
        double r149544 = r149543 * r149542;
        double r149545 = r149544 / r149530;
        double r149546 = 1.3257937988037266e+154;
        bool r149547 = r149518 <= r149546;
        double r149548 = 1.0;
        double r149549 = r149521 / r149536;
        double r149550 = r149548 / r149549;
        double r149551 = r149550 * r149523;
        double r149552 = r149534 - r149540;
        double r149553 = r149551 / r149552;
        double r149554 = r149548 / r149523;
        double r149555 = r149549 * r149554;
        double r149556 = r149555 * r149529;
        double r149557 = r149548 / r149556;
        double r149558 = r149547 ? r149553 : r149557;
        double r149559 = r149533 ? r149545 : r149558;
        double r149560 = r149520 ? r149531 : r149559;
        return r149560;
}

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
Target20.8
Herbie9.0
\[\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 < -2.9224158984269497e+111

    1. Initial program 49.3

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]

    if -2.9224158984269497e+111 < b < -4.9276367402926466e-151

    1. Initial program 6.4

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

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

    if -4.9276367402926466e-151 < b < 1.3257937988037266e+154

    1. Initial program 30.4

      \[\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-+30.8

      \[\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. Simplified15.6

      \[\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 *-un-lft-identity15.6

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity15.6

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{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}\]
    9. Applied associate-/l*15.8

      \[\leadsto \color{blue}{\frac{\frac{1}{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}}}}}\]
    10. Simplified14.8

      \[\leadsto \frac{\frac{1}{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)}}\]
    11. Using strategy rm
    12. Applied times-frac14.8

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

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

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

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

    if 1.3257937988037266e+154 < b

    1. Initial program 64.0

      \[\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-+64.0

      \[\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. Simplified37.6

      \[\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 *-un-lft-identity37.6

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity37.6

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{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}\]
    9. Applied associate-/l*37.6

      \[\leadsto \color{blue}{\frac{\frac{1}{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}}}}}\]
    10. Simplified37.6

      \[\leadsto \frac{\frac{1}{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)}}\]
    11. Using strategy rm
    12. Applied times-frac37.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.92241589842694968 \cdot 10^{111}:\\ \;\;\;\;\frac{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}{2 \cdot a}\\ \mathbf{elif}\;b \le -4.9276367402926466 \cdot 10^{-151}:\\ \;\;\;\;\frac{\left(\sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) \cdot \sqrt[3]{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.32579379880372662 \cdot 10^{154}:\\ \;\;\;\;\frac{\frac{1}{\frac{2}{4}} \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(\frac{2}{4} \cdot \frac{1}{c}\right) \cdot \left(2 \cdot \frac{a \cdot c}{b} - 2 \cdot b\right)}\\ \end{array}\]

Reproduce

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