Average Error: 33.4 → 10.0
Time: 17.8s
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.639043916588305 \cdot 10^{+143}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.046853365273247 \cdot 10^{-144}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right) \cdot \frac{\frac{1}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\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.639043916588305 \cdot 10^{+143}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r5842584 = b;
        double r5842585 = -r5842584;
        double r5842586 = r5842584 * r5842584;
        double r5842587 = 4.0;
        double r5842588 = a;
        double r5842589 = r5842587 * r5842588;
        double r5842590 = c;
        double r5842591 = r5842589 * r5842590;
        double r5842592 = r5842586 - r5842591;
        double r5842593 = sqrt(r5842592);
        double r5842594 = r5842585 + r5842593;
        double r5842595 = 2.0;
        double r5842596 = r5842595 * r5842588;
        double r5842597 = r5842594 / r5842596;
        return r5842597;
}

double f(double a, double b, double c) {
        double r5842598 = b;
        double r5842599 = -4.639043916588305e+143;
        bool r5842600 = r5842598 <= r5842599;
        double r5842601 = c;
        double r5842602 = r5842601 / r5842598;
        double r5842603 = a;
        double r5842604 = r5842598 / r5842603;
        double r5842605 = r5842602 - r5842604;
        double r5842606 = 5.046853365273247e-144;
        bool r5842607 = r5842598 <= r5842606;
        double r5842608 = r5842598 * r5842598;
        double r5842609 = r5842601 * r5842603;
        double r5842610 = 4.0;
        double r5842611 = r5842609 * r5842610;
        double r5842612 = r5842608 - r5842611;
        double r5842613 = sqrt(r5842612);
        double r5842614 = r5842613 - r5842598;
        double r5842615 = 0.5;
        double r5842616 = r5842615 / r5842603;
        double r5842617 = r5842614 * r5842616;
        double r5842618 = -r5842602;
        double r5842619 = r5842607 ? r5842617 : r5842618;
        double r5842620 = r5842600 ? r5842605 : r5842619;
        return r5842620;
}

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

Original33.4
Target19.8
Herbie10.0
\[\begin{array}{l} \mathbf{if}\;b \lt 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.639043916588305e+143

    1. Initial program 57.1

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

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

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

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]

    if -4.639043916588305e+143 < b < 5.046853365273247e-144

    1. Initial program 10.3

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

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

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

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

    if 5.046853365273247e-144 < b

    1. Initial program 49.8

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}}\]
    6. Using strategy rm
    7. Applied clear-num49.8

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    10. Simplified11.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.639043916588305 \cdot 10^{+143}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 5.046853365273247 \cdot 10^{-144}:\\ \;\;\;\;\left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right) \cdot \frac{\frac{1}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 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)))