Average Error: 34.0 → 9.8
Time: 16.6s
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.285761821828269498914963771383359026418 \cdot 10^{115}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 4.089744618622775294902023307017914843593 \cdot 10^{-73}:\\ \;\;\;\;\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.285761821828269498914963771383359026418 \cdot 10^{115}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 4.089744618622775294902023307017914843593 \cdot 10^{-73}:\\
\;\;\;\;\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 r135113 = b;
        double r135114 = -r135113;
        double r135115 = r135113 * r135113;
        double r135116 = 4.0;
        double r135117 = a;
        double r135118 = r135116 * r135117;
        double r135119 = c;
        double r135120 = r135118 * r135119;
        double r135121 = r135115 - r135120;
        double r135122 = sqrt(r135121);
        double r135123 = r135114 + r135122;
        double r135124 = 2.0;
        double r135125 = r135124 * r135117;
        double r135126 = r135123 / r135125;
        return r135126;
}

double f(double a, double b, double c) {
        double r135127 = b;
        double r135128 = -1.2857618218282695e+115;
        bool r135129 = r135127 <= r135128;
        double r135130 = 1.0;
        double r135131 = c;
        double r135132 = r135131 / r135127;
        double r135133 = a;
        double r135134 = r135127 / r135133;
        double r135135 = r135132 - r135134;
        double r135136 = r135130 * r135135;
        double r135137 = 4.089744618622775e-73;
        bool r135138 = r135127 <= r135137;
        double r135139 = r135127 * r135127;
        double r135140 = 4.0;
        double r135141 = r135140 * r135133;
        double r135142 = r135141 * r135131;
        double r135143 = r135139 - r135142;
        double r135144 = sqrt(r135143);
        double r135145 = r135144 - r135127;
        double r135146 = 2.0;
        double r135147 = r135146 * r135133;
        double r135148 = r135145 / r135147;
        double r135149 = -1.0;
        double r135150 = r135149 * r135132;
        double r135151 = r135138 ? r135148 : r135150;
        double r135152 = r135129 ? r135136 : r135151;
        return r135152;
}

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.0
Target21.0
Herbie9.8
\[\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.2857618218282695e+115

    1. Initial program 50.6

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

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

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

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

    if -1.2857618218282695e+115 < b < 4.089744618622775e-73

    1. Initial program 12.6

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

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

    if 4.089744618622775e-73 < b

    1. Initial program 53.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.285761821828269498914963771383359026418 \cdot 10^{115}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 4.089744618622775294902023307017914843593 \cdot 10^{-73}:\\ \;\;\;\;\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 2019305 +o rules:numerics
(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)))