Average Error: 34.1 → 10.0
Time: 16.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 -1.11981154530853106611761327467786604265 \cdot 10^{143}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 4.718890261991468628346768591871377778707 \cdot 10^{-106}:\\ \;\;\;\;\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.11981154530853106611761327467786604265 \cdot 10^{143}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 4.718890261991468628346768591871377778707 \cdot 10^{-106}:\\
\;\;\;\;\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 r168256 = b;
        double r168257 = -r168256;
        double r168258 = r168256 * r168256;
        double r168259 = 4.0;
        double r168260 = a;
        double r168261 = r168259 * r168260;
        double r168262 = c;
        double r168263 = r168261 * r168262;
        double r168264 = r168258 - r168263;
        double r168265 = sqrt(r168264);
        double r168266 = r168257 + r168265;
        double r168267 = 2.0;
        double r168268 = r168267 * r168260;
        double r168269 = r168266 / r168268;
        return r168269;
}

double f(double a, double b, double c) {
        double r168270 = b;
        double r168271 = -1.119811545308531e+143;
        bool r168272 = r168270 <= r168271;
        double r168273 = 1.0;
        double r168274 = c;
        double r168275 = r168274 / r168270;
        double r168276 = a;
        double r168277 = r168270 / r168276;
        double r168278 = r168275 - r168277;
        double r168279 = r168273 * r168278;
        double r168280 = 4.718890261991469e-106;
        bool r168281 = r168270 <= r168280;
        double r168282 = r168270 * r168270;
        double r168283 = 4.0;
        double r168284 = r168283 * r168276;
        double r168285 = r168284 * r168274;
        double r168286 = r168282 - r168285;
        double r168287 = sqrt(r168286);
        double r168288 = r168287 - r168270;
        double r168289 = 2.0;
        double r168290 = r168289 * r168276;
        double r168291 = r168288 / r168290;
        double r168292 = -1.0;
        double r168293 = r168292 * r168275;
        double r168294 = r168281 ? r168291 : r168293;
        double r168295 = r168272 ? r168279 : r168294;
        return r168295;
}

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.1
Target21.0
Herbie10.0
\[\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 < -1.119811545308531e+143

    1. Initial program 59.0

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

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

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity59.0

      \[\leadsto \color{blue}{\left(1 \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)\right)} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l*59.0

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

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

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

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

    if -1.119811545308531e+143 < b < 4.718890261991469e-106

    1. Initial program 11.1

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

      \[\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-inv11.2

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity11.2

      \[\leadsto \color{blue}{\left(1 \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right)\right)} \cdot \frac{1}{2 \cdot a}\]
    7. Applied associate-*l*11.2

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

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

    if 4.718890261991469e-106 < b

    1. Initial program 52.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.11981154530853106611761327467786604265 \cdot 10^{143}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 4.718890261991468628346768591871377778707 \cdot 10^{-106}:\\ \;\;\;\;\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 2019326 
(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)))