Average Error: 34.2 → 9.9
Time: 6.3s
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.4052299045085703 \cdot 10^{151}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.2529910715609764 \cdot 10^{-90}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{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 -1.4052299045085703 \cdot 10^{151}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r87692 = b;
        double r87693 = -r87692;
        double r87694 = r87692 * r87692;
        double r87695 = 4.0;
        double r87696 = a;
        double r87697 = r87695 * r87696;
        double r87698 = c;
        double r87699 = r87697 * r87698;
        double r87700 = r87694 - r87699;
        double r87701 = sqrt(r87700);
        double r87702 = r87693 + r87701;
        double r87703 = 2.0;
        double r87704 = r87703 * r87696;
        double r87705 = r87702 / r87704;
        return r87705;
}

double f(double a, double b, double c) {
        double r87706 = b;
        double r87707 = -1.4052299045085703e+151;
        bool r87708 = r87706 <= r87707;
        double r87709 = 1.0;
        double r87710 = c;
        double r87711 = r87710 / r87706;
        double r87712 = a;
        double r87713 = r87706 / r87712;
        double r87714 = r87711 - r87713;
        double r87715 = r87709 * r87714;
        double r87716 = 1.2529910715609764e-90;
        bool r87717 = r87706 <= r87716;
        double r87718 = r87706 * r87706;
        double r87719 = 4.0;
        double r87720 = r87719 * r87712;
        double r87721 = r87720 * r87710;
        double r87722 = r87718 - r87721;
        double r87723 = sqrt(r87722);
        double r87724 = -r87706;
        double r87725 = r87723 + r87724;
        double r87726 = 2.0;
        double r87727 = r87726 * r87712;
        double r87728 = r87725 / r87727;
        double r87729 = -1.0;
        double r87730 = r87729 * r87711;
        double r87731 = r87717 ? r87728 : r87730;
        double r87732 = r87708 ? r87715 : r87731;
        return r87732;
}

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.2
Target21.2
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.4052299045085703e+151

    1. Initial program 63.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.2

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

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

    if -1.4052299045085703e+151 < b < 1.2529910715609764e-90

    1. Initial program 12.2

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied +-commutative12.2

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

    if 1.2529910715609764e-90 < b

    1. Initial program 52.5

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

      \[\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 -1.4052299045085703 \cdot 10^{151}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.2529910715609764 \cdot 10^{-90}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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