Average Error: 33.7 → 6.9
Time: 6.5s
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 -9.5975400610846271 \cdot 10^{115}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.06237398994986779 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.29571176074688 \cdot 10^{130}:\\ \;\;\;\;\frac{1}{\frac{0.5}{c} \cdot \left(-b\right) + \frac{0.5}{c} \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \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 -9.5975400610846271 \cdot 10^{115}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 3.29571176074688 \cdot 10^{130}:\\
\;\;\;\;\frac{1}{\frac{0.5}{c} \cdot \left(-b\right) + \frac{0.5}{c} \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\

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

\end{array}
double f(double a, double b, double c) {
        double r181662 = b;
        double r181663 = -r181662;
        double r181664 = r181662 * r181662;
        double r181665 = 4.0;
        double r181666 = a;
        double r181667 = r181665 * r181666;
        double r181668 = c;
        double r181669 = r181667 * r181668;
        double r181670 = r181664 - r181669;
        double r181671 = sqrt(r181670);
        double r181672 = r181663 + r181671;
        double r181673 = 2.0;
        double r181674 = r181673 * r181666;
        double r181675 = r181672 / r181674;
        return r181675;
}

double f(double a, double b, double c) {
        double r181676 = b;
        double r181677 = -9.597540061084627e+115;
        bool r181678 = r181676 <= r181677;
        double r181679 = 1.0;
        double r181680 = c;
        double r181681 = r181680 / r181676;
        double r181682 = a;
        double r181683 = r181676 / r181682;
        double r181684 = r181681 - r181683;
        double r181685 = r181679 * r181684;
        double r181686 = -1.0623739899498678e-305;
        bool r181687 = r181676 <= r181686;
        double r181688 = r181676 * r181676;
        double r181689 = 4.0;
        double r181690 = r181689 * r181682;
        double r181691 = r181690 * r181680;
        double r181692 = r181688 - r181691;
        double r181693 = sqrt(r181692);
        double r181694 = -r181676;
        double r181695 = r181693 + r181694;
        double r181696 = 2.0;
        double r181697 = r181696 * r181682;
        double r181698 = r181695 / r181697;
        double r181699 = 3.29571176074688e+130;
        bool r181700 = r181676 <= r181699;
        double r181701 = 1.0;
        double r181702 = 0.5;
        double r181703 = r181702 / r181680;
        double r181704 = r181703 * r181694;
        double r181705 = -r181693;
        double r181706 = r181703 * r181705;
        double r181707 = r181704 + r181706;
        double r181708 = r181701 / r181707;
        double r181709 = -1.0;
        double r181710 = r181709 * r181681;
        double r181711 = r181700 ? r181708 : r181710;
        double r181712 = r181687 ? r181698 : r181711;
        double r181713 = r181678 ? r181685 : r181712;
        return r181713;
}

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.9
Herbie6.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 4 regimes
  2. if b < -9.597540061084627e+115

    1. Initial program 48.7

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

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

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

    if -9.597540061084627e+115 < b < -1.0623739899498678e-305

    1. Initial program 8.7

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

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

    if -1.0623739899498678e-305 < b < 3.29571176074688e+130

    1. Initial program 34.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-+34.4

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

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

      \[\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. Simplified16.0

      \[\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. Taylor expanded around 0 9.6

      \[\leadsto \frac{1}{\color{blue}{\frac{0.5}{c}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    9. Using strategy rm
    10. Applied sub-neg9.6

      \[\leadsto \frac{1}{\frac{0.5}{c} \cdot \color{blue}{\left(\left(-b\right) + \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)\right)}}\]
    11. Applied distribute-lft-in9.6

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

    if 3.29571176074688e+130 < b

    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.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.5975400610846271 \cdot 10^{115}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -1.06237398994986779 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.29571176074688 \cdot 10^{130}:\\ \;\;\;\;\frac{1}{\frac{0.5}{c} \cdot \left(-b\right) + \frac{0.5}{c} \cdot \left(-\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020100 +o rules:numerics
(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)))