Average Error: 33.4 → 10.0
Time: 24.2s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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 - \left(4 \cdot a\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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 - \left(4 \cdot a\right) \cdot c} - b}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r3041717 = b;
        double r3041718 = -r3041717;
        double r3041719 = r3041717 * r3041717;
        double r3041720 = 4.0;
        double r3041721 = a;
        double r3041722 = c;
        double r3041723 = r3041721 * r3041722;
        double r3041724 = r3041720 * r3041723;
        double r3041725 = r3041719 - r3041724;
        double r3041726 = sqrt(r3041725);
        double r3041727 = r3041718 + r3041726;
        double r3041728 = 2.0;
        double r3041729 = r3041728 * r3041721;
        double r3041730 = r3041727 / r3041729;
        return r3041730;
}

double f(double a, double b, double c) {
        double r3041731 = b;
        double r3041732 = -4.639043916588305e+143;
        bool r3041733 = r3041731 <= r3041732;
        double r3041734 = c;
        double r3041735 = r3041734 / r3041731;
        double r3041736 = a;
        double r3041737 = r3041731 / r3041736;
        double r3041738 = r3041735 - r3041737;
        double r3041739 = 5.046853365273247e-144;
        bool r3041740 = r3041731 <= r3041739;
        double r3041741 = 0.5;
        double r3041742 = r3041741 / r3041736;
        double r3041743 = 1.0;
        double r3041744 = r3041731 * r3041731;
        double r3041745 = 4.0;
        double r3041746 = r3041745 * r3041736;
        double r3041747 = r3041746 * r3041734;
        double r3041748 = r3041744 - r3041747;
        double r3041749 = sqrt(r3041748);
        double r3041750 = r3041749 - r3041731;
        double r3041751 = r3041743 / r3041750;
        double r3041752 = r3041742 / r3041751;
        double r3041753 = -r3041735;
        double r3041754 = r3041740 ? r3041752 : r3041753;
        double r3041755 = r3041733 ? r3041738 : r3041754;
        return r3041755;
}

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

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - 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(4 \cdot a\right) \cdot c} - 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(4 \cdot a\right) \cdot c} - b}}}\]
    8. Applied associate-/r*10.5

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

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

    if 5.046853365273247e-144 < b

    1. Initial program 49.8

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

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

Reproduce

herbie shell --seed 2019132 
(FPCore (a b c)
  :name "quadp (p42, positive)"

  :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)))