Average Error: 34.2 → 10.4
Time: 11.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 -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{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 -4.12310353364421125 \cdot 10^{95}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r185263 = b;
        double r185264 = -r185263;
        double r185265 = r185263 * r185263;
        double r185266 = 4.0;
        double r185267 = a;
        double r185268 = r185266 * r185267;
        double r185269 = c;
        double r185270 = r185268 * r185269;
        double r185271 = r185265 - r185270;
        double r185272 = sqrt(r185271);
        double r185273 = r185264 + r185272;
        double r185274 = 2.0;
        double r185275 = r185274 * r185267;
        double r185276 = r185273 / r185275;
        return r185276;
}

double f(double a, double b, double c) {
        double r185277 = b;
        double r185278 = -4.123103533644211e+95;
        bool r185279 = r185277 <= r185278;
        double r185280 = 1.0;
        double r185281 = c;
        double r185282 = r185281 / r185277;
        double r185283 = a;
        double r185284 = r185277 / r185283;
        double r185285 = r185282 - r185284;
        double r185286 = r185280 * r185285;
        double r185287 = 3.446447862996811e-75;
        bool r185288 = r185277 <= r185287;
        double r185289 = 1.0;
        double r185290 = r185277 * r185277;
        double r185291 = 4.0;
        double r185292 = r185291 * r185283;
        double r185293 = r185292 * r185281;
        double r185294 = r185290 - r185293;
        double r185295 = sqrt(r185294);
        double r185296 = r185295 - r185277;
        double r185297 = 2.0;
        double r185298 = r185296 / r185297;
        double r185299 = r185283 / r185298;
        double r185300 = r185289 / r185299;
        double r185301 = -1.0;
        double r185302 = r185301 * r185282;
        double r185303 = r185288 ? r185300 : r185302;
        double r185304 = r185279 ? r185286 : r185303;
        return r185304;
}

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.1
Herbie10.4
\[\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 < -4.123103533644211e+95

    1. Initial program 47.3

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

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

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

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

    if -4.123103533644211e+95 < b < 3.446447862996811e-75

    1. Initial program 13.3

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2}}{a}}\]
    3. Using strategy rm
    4. Applied clear-num13.4

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

    if 3.446447862996811e-75 < 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. Simplified52.5

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

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

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

Reproduce

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