Average Error: 34.3 → 10.3
Time: 17.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.006239684017339546564770304051967174461 \cdot 10^{118}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.892098135471955771557857083920836890719 \cdot 10^{-53}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{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.006239684017339546564770304051967174461 \cdot 10^{118}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r39771 = b;
        double r39772 = -r39771;
        double r39773 = r39771 * r39771;
        double r39774 = 4.0;
        double r39775 = a;
        double r39776 = r39774 * r39775;
        double r39777 = c;
        double r39778 = r39776 * r39777;
        double r39779 = r39773 - r39778;
        double r39780 = sqrt(r39779);
        double r39781 = r39772 + r39780;
        double r39782 = 2.0;
        double r39783 = r39782 * r39775;
        double r39784 = r39781 / r39783;
        return r39784;
}

double f(double a, double b, double c) {
        double r39785 = b;
        double r39786 = -1.0062396840173395e+118;
        bool r39787 = r39785 <= r39786;
        double r39788 = 1.0;
        double r39789 = c;
        double r39790 = r39789 / r39785;
        double r39791 = a;
        double r39792 = r39785 / r39791;
        double r39793 = r39790 - r39792;
        double r39794 = r39788 * r39793;
        double r39795 = 1.8920981354719558e-53;
        bool r39796 = r39785 <= r39795;
        double r39797 = r39785 * r39785;
        double r39798 = 4.0;
        double r39799 = r39798 * r39791;
        double r39800 = r39799 * r39789;
        double r39801 = r39797 - r39800;
        double r39802 = sqrt(r39801);
        double r39803 = r39802 - r39785;
        double r39804 = 2.0;
        double r39805 = r39804 * r39791;
        double r39806 = r39803 / r39805;
        double r39807 = -1.0;
        double r39808 = r39807 * r39790;
        double r39809 = r39796 ? r39806 : r39808;
        double r39810 = r39787 ? r39794 : r39809;
        return r39810;
}

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

Derivation

  1. Split input into 3 regimes
  2. if b < -1.0062396840173395e+118

    1. Initial program 52.3

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

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

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

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

    if -1.0062396840173395e+118 < b < 1.8920981354719558e-53

    1. Initial program 13.9

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

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

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

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

    if 1.8920981354719558e-53 < b

    1. Initial program 54.0

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

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

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

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

Reproduce

herbie shell --seed 2019306 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))