Average Error: 34.5 → 10.3
Time: 16.7s
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 -63362873442066488610789523456:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 6.484072051994263737451444554171174935457 \cdot 10^{-107}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}{a \cdot 2}\\ \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 -63362873442066488610789523456:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r6238900 = b;
        double r6238901 = -r6238900;
        double r6238902 = r6238900 * r6238900;
        double r6238903 = 4.0;
        double r6238904 = a;
        double r6238905 = r6238903 * r6238904;
        double r6238906 = c;
        double r6238907 = r6238905 * r6238906;
        double r6238908 = r6238902 - r6238907;
        double r6238909 = sqrt(r6238908);
        double r6238910 = r6238901 + r6238909;
        double r6238911 = 2.0;
        double r6238912 = r6238911 * r6238904;
        double r6238913 = r6238910 / r6238912;
        return r6238913;
}

double f(double a, double b, double c) {
        double r6238914 = b;
        double r6238915 = -6.336287344206649e+28;
        bool r6238916 = r6238914 <= r6238915;
        double r6238917 = c;
        double r6238918 = r6238917 / r6238914;
        double r6238919 = a;
        double r6238920 = r6238914 / r6238919;
        double r6238921 = r6238918 - r6238920;
        double r6238922 = 1.0;
        double r6238923 = r6238921 * r6238922;
        double r6238924 = 6.484072051994264e-107;
        bool r6238925 = r6238914 <= r6238924;
        double r6238926 = r6238914 * r6238914;
        double r6238927 = 4.0;
        double r6238928 = r6238927 * r6238919;
        double r6238929 = r6238928 * r6238917;
        double r6238930 = r6238926 - r6238929;
        double r6238931 = sqrt(r6238930);
        double r6238932 = -r6238914;
        double r6238933 = r6238931 + r6238932;
        double r6238934 = 2.0;
        double r6238935 = r6238919 * r6238934;
        double r6238936 = r6238933 / r6238935;
        double r6238937 = -1.0;
        double r6238938 = r6238937 * r6238918;
        double r6238939 = r6238925 ? r6238936 : r6238938;
        double r6238940 = r6238916 ? r6238923 : r6238939;
        return r6238940;
}

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.5
Target21.0
Herbie10.3
\[\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 < -6.336287344206649e+28

    1. Initial program 34.8

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

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

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

    if -6.336287344206649e+28 < b < 6.484072051994264e-107

    1. Initial program 12.9

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

    if 6.484072051994264e-107 < 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.7

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

Reproduce

herbie shell --seed 2019192 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))