Average Error: 33.4 → 10.0
Time: 24.7s
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}:\\ \;\;\;\;\frac{\frac{\frac{1}{2}}{a}}{\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \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}:\\
\;\;\;\;\frac{\frac{\frac{1}{2}}{a}}{\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r3928657 = b;
        double r3928658 = -r3928657;
        double r3928659 = r3928657 * r3928657;
        double r3928660 = 4.0;
        double r3928661 = a;
        double r3928662 = r3928660 * r3928661;
        double r3928663 = c;
        double r3928664 = r3928662 * r3928663;
        double r3928665 = r3928659 - r3928664;
        double r3928666 = sqrt(r3928665);
        double r3928667 = r3928658 + r3928666;
        double r3928668 = 2.0;
        double r3928669 = r3928668 * r3928661;
        double r3928670 = r3928667 / r3928669;
        return r3928670;
}

double f(double a, double b, double c) {
        double r3928671 = b;
        double r3928672 = -4.639043916588305e+143;
        bool r3928673 = r3928671 <= r3928672;
        double r3928674 = c;
        double r3928675 = r3928674 / r3928671;
        double r3928676 = a;
        double r3928677 = r3928671 / r3928676;
        double r3928678 = r3928675 - r3928677;
        double r3928679 = 5.046853365273247e-144;
        bool r3928680 = r3928671 <= r3928679;
        double r3928681 = 0.5;
        double r3928682 = r3928681 / r3928676;
        double r3928683 = 1.0;
        double r3928684 = r3928671 * r3928671;
        double r3928685 = 4.0;
        double r3928686 = r3928674 * r3928676;
        double r3928687 = r3928685 * r3928686;
        double r3928688 = r3928684 - r3928687;
        double r3928689 = sqrt(r3928688);
        double r3928690 = r3928689 - r3928671;
        double r3928691 = r3928683 / r3928690;
        double r3928692 = r3928682 / r3928691;
        double r3928693 = -r3928675;
        double r3928694 = r3928680 ? r3928692 : r3928693;
        double r3928695 = r3928673 ? r3928678 : r3928694;
        return r3928695;
}

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 *-un-lft-identity57.1

      \[\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*57.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 *-un-lft-identity57.1

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{a}}}}\]
    10. 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 *-un-lft-identity10.3

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

      \[\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 div-inv10.5

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

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

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

    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. Taylor expanded around inf 11.6

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. 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}:\\ \;\;\;\;\frac{\frac{\frac{1}{2}}{a}}{\frac{1}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}}\\ \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)))