Average Error: 33.5 → 8.7
Time: 48.1s
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 -6.376253530740768 \cdot 10^{+152}:\\ \;\;\;\;\frac{\left(a \cdot \frac{c}{b} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.2059736638617364 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}\\ \mathbf{elif}\;b \le 8.834167001137509 \cdot 10^{-10}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\frac{a}{\frac{1}{2}}} \cdot \frac{-1}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \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 -6.376253530740768 \cdot 10^{+152}:\\
\;\;\;\;\frac{\left(a \cdot \frac{c}{b} - b\right) \cdot 2}{2 \cdot a}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r4979594 = b;
        double r4979595 = -r4979594;
        double r4979596 = r4979594 * r4979594;
        double r4979597 = 4.0;
        double r4979598 = a;
        double r4979599 = r4979597 * r4979598;
        double r4979600 = c;
        double r4979601 = r4979599 * r4979600;
        double r4979602 = r4979596 - r4979601;
        double r4979603 = sqrt(r4979602);
        double r4979604 = r4979595 + r4979603;
        double r4979605 = 2.0;
        double r4979606 = r4979605 * r4979598;
        double r4979607 = r4979604 / r4979606;
        return r4979607;
}

double f(double a, double b, double c) {
        double r4979608 = b;
        double r4979609 = -6.376253530740768e+152;
        bool r4979610 = r4979608 <= r4979609;
        double r4979611 = a;
        double r4979612 = c;
        double r4979613 = r4979612 / r4979608;
        double r4979614 = r4979611 * r4979613;
        double r4979615 = r4979614 - r4979608;
        double r4979616 = 2.0;
        double r4979617 = r4979615 * r4979616;
        double r4979618 = r4979616 * r4979611;
        double r4979619 = r4979617 / r4979618;
        double r4979620 = 3.2059736638617364e-150;
        bool r4979621 = r4979608 <= r4979620;
        double r4979622 = 0.5;
        double r4979623 = r4979608 * r4979608;
        double r4979624 = 4.0;
        double r4979625 = r4979611 * r4979612;
        double r4979626 = r4979624 * r4979625;
        double r4979627 = r4979623 - r4979626;
        double r4979628 = sqrt(r4979627);
        double r4979629 = r4979628 - r4979608;
        double r4979630 = r4979629 / r4979611;
        double r4979631 = r4979622 * r4979630;
        double r4979632 = 8.834167001137509e-10;
        bool r4979633 = r4979608 <= r4979632;
        double r4979634 = r4979611 / r4979622;
        double r4979635 = r4979626 / r4979634;
        double r4979636 = -1.0;
        double r4979637 = r4979608 + r4979628;
        double r4979638 = r4979636 / r4979637;
        double r4979639 = r4979635 * r4979638;
        double r4979640 = -r4979612;
        double r4979641 = r4979640 / r4979608;
        double r4979642 = r4979633 ? r4979639 : r4979641;
        double r4979643 = r4979621 ? r4979631 : r4979642;
        double r4979644 = r4979610 ? r4979619 : r4979643;
        return r4979644;
}

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.5
Target20.4
Herbie8.7
\[\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 4 regimes
  2. if b < -6.376253530740768e+152

    1. Initial program 60.5

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    4. Simplified2.0

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

    if -6.376253530740768e+152 < b < 3.2059736638617364e-150

    1. Initial program 10.4

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

      \[\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-identity10.4

      \[\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*10.6

      \[\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 *-un-lft-identity10.6

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{1 \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}} - 1 \cdot b}}\]
    9. Applied distribute-lft-out--10.6

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{1 \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b\right)}}}\]
    10. Applied times-frac10.6

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{1} \cdot \frac{a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}}\]
    11. Applied add-sqr-sqrt10.6

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\frac{2}{1} \cdot \frac{a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}}\]
    12. Applied times-frac10.6

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

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

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

    if 3.2059736638617364e-150 < b < 8.834167001137509e-10

    1. Initial program 32.0

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

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

      \[\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*32.1

      \[\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 flip--32.2

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}}}}\]
    8. Applied associate-/r/32.2

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}}\]
    9. Applied *-un-lft-identity32.2

      \[\leadsto \frac{\color{blue}{1 \cdot 1}}{\frac{2 \cdot a}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} \cdot \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b \cdot b} \cdot \left(\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b\right)}\]
    10. Applied times-frac32.3

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

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

    if 8.834167001137509e-10 < b

    1. Initial program 54.0

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified6.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.376253530740768 \cdot 10^{+152}:\\ \;\;\;\;\frac{\left(a \cdot \frac{c}{b} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.2059736638617364 \cdot 10^{-150}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}\\ \mathbf{elif}\;b \le 8.834167001137509 \cdot 10^{-10}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\frac{a}{\frac{1}{2}}} \cdot \frac{-1}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019104 
(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)))