Average Error: 34.6 → 9.8
Time: 4.9s
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.9358923729233266 \cdot 10^{149}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 9.39036747108992214 \cdot 10^{-69}:\\ \;\;\;\;0 - \frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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 -2.9358923729233266 \cdot 10^{149}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r92207 = b;
        double r92208 = -r92207;
        double r92209 = r92207 * r92207;
        double r92210 = 4.0;
        double r92211 = a;
        double r92212 = r92210 * r92211;
        double r92213 = c;
        double r92214 = r92212 * r92213;
        double r92215 = r92209 - r92214;
        double r92216 = sqrt(r92215);
        double r92217 = r92208 + r92216;
        double r92218 = 2.0;
        double r92219 = r92218 * r92211;
        double r92220 = r92217 / r92219;
        return r92220;
}

double f(double a, double b, double c) {
        double r92221 = b;
        double r92222 = -2.9358923729233266e+149;
        bool r92223 = r92221 <= r92222;
        double r92224 = 1.0;
        double r92225 = c;
        double r92226 = r92225 / r92221;
        double r92227 = a;
        double r92228 = r92221 / r92227;
        double r92229 = r92226 - r92228;
        double r92230 = r92224 * r92229;
        double r92231 = 9.390367471089922e-69;
        bool r92232 = r92221 <= r92231;
        double r92233 = 0.0;
        double r92234 = r92221 * r92221;
        double r92235 = 4.0;
        double r92236 = r92235 * r92227;
        double r92237 = r92236 * r92225;
        double r92238 = r92234 - r92237;
        double r92239 = sqrt(r92238);
        double r92240 = r92221 - r92239;
        double r92241 = 2.0;
        double r92242 = r92241 * r92227;
        double r92243 = r92240 / r92242;
        double r92244 = r92233 - r92243;
        double r92245 = -1.0;
        double r92246 = r92245 * r92226;
        double r92247 = r92232 ? r92244 : r92246;
        double r92248 = r92223 ? r92230 : r92247;
        return r92248;
}

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.6
Target21.2
Herbie9.8
\[\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 < -2.9358923729233266e+149

    1. Initial program 62.1

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

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

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

    if -2.9358923729233266e+149 < b < 9.390367471089922e-69

    1. Initial program 12.5

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

      \[\leadsto \frac{\color{blue}{\left(0 - b\right)} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    4. Applied associate-+l-12.5

      \[\leadsto \frac{\color{blue}{0 - \left(b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}\]
    5. Applied div-sub12.5

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

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

    if 9.390367471089922e-69 < b

    1. Initial program 53.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.9358923729233266 \cdot 10^{149}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 9.39036747108992214 \cdot 10^{-69}:\\ \;\;\;\;0 - \frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020018 +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)))