Average Error: 34.4 → 10.0
Time: 5.5s
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 -9.91243958875386880555748684589545292526 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.209120745343099452134664059704875392955 \cdot 10^{-70}:\\ \;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - {\left(4 \cdot \left(a \cdot c\right)\right)}^{1}}}{2}}{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 -9.91243958875386880555748684589545292526 \cdot 10^{101}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r79081 = b;
        double r79082 = -r79081;
        double r79083 = r79081 * r79081;
        double r79084 = 4.0;
        double r79085 = a;
        double r79086 = r79084 * r79085;
        double r79087 = c;
        double r79088 = r79086 * r79087;
        double r79089 = r79083 - r79088;
        double r79090 = sqrt(r79089);
        double r79091 = r79082 + r79090;
        double r79092 = 2.0;
        double r79093 = r79092 * r79085;
        double r79094 = r79091 / r79093;
        return r79094;
}

double f(double a, double b, double c) {
        double r79095 = b;
        double r79096 = -9.912439588753869e+101;
        bool r79097 = r79095 <= r79096;
        double r79098 = 1.0;
        double r79099 = c;
        double r79100 = r79099 / r79095;
        double r79101 = a;
        double r79102 = r79095 / r79101;
        double r79103 = r79100 - r79102;
        double r79104 = r79098 * r79103;
        double r79105 = 1.2091207453430995e-70;
        bool r79106 = r79095 <= r79105;
        double r79107 = -r79095;
        double r79108 = r79095 * r79095;
        double r79109 = 4.0;
        double r79110 = r79101 * r79099;
        double r79111 = r79109 * r79110;
        double r79112 = 1.0;
        double r79113 = pow(r79111, r79112);
        double r79114 = r79108 - r79113;
        double r79115 = sqrt(r79114);
        double r79116 = r79107 + r79115;
        double r79117 = 2.0;
        double r79118 = r79116 / r79117;
        double r79119 = r79118 / r79101;
        double r79120 = -1.0;
        double r79121 = r79120 * r79100;
        double r79122 = r79106 ? r79119 : r79121;
        double r79123 = r79097 ? r79104 : r79122;
        return r79123;
}

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.4
Target21.0
Herbie10.0
\[\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 < -9.912439588753869e+101

    1. Initial program 46.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf 3.6

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

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

    if -9.912439588753869e+101 < b < 1.2091207453430995e-70

    1. Initial program 13.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied pow113.3

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

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \left(\color{blue}{{4}^{1}} \cdot {a}^{1}\right) \cdot {c}^{1}}}{2 \cdot a}\]
    6. Applied pow-prod-down13.3

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - \color{blue}{{\left(4 \cdot a\right)}^{1}} \cdot {c}^{1}}}{2 \cdot a}\]
    7. Applied pow-prod-down13.3

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

      \[\leadsto \frac{\left(-b\right) + \sqrt{b \cdot b - {\color{blue}{\left(4 \cdot \left(a \cdot c\right)\right)}}^{1}}}{2 \cdot a}\]
    9. Using strategy rm
    10. Applied associate-/r*13.3

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

    if 1.2091207453430995e-70 < b

    1. Initial program 53.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 8.7

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

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

Reproduce

herbie shell --seed 2020002 +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)))