Average Error: 34.1 → 9.3
Time: 5.3s
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 -2.3044033969831823 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 8.9305277508569929 \cdot 10^{-82}:\\ \;\;\;\;\frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-2 \cdot a}\\ \mathbf{elif}\;b \le 4.01993084419163312 \cdot 10^{109}:\\ \;\;\;\;\frac{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \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 -2.3044033969831823 \cdot 10^{153}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

\mathbf{elif}\;b \le 4.01993084419163312 \cdot 10^{109}:\\
\;\;\;\;\frac{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\

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

\end{array}
double f(double a, double b, double c) {
        double r95207 = b;
        double r95208 = -r95207;
        double r95209 = r95207 * r95207;
        double r95210 = 4.0;
        double r95211 = a;
        double r95212 = r95210 * r95211;
        double r95213 = c;
        double r95214 = r95212 * r95213;
        double r95215 = r95209 - r95214;
        double r95216 = sqrt(r95215);
        double r95217 = r95208 + r95216;
        double r95218 = 2.0;
        double r95219 = r95218 * r95211;
        double r95220 = r95217 / r95219;
        return r95220;
}

double f(double a, double b, double c) {
        double r95221 = b;
        double r95222 = -2.3044033969831823e+153;
        bool r95223 = r95221 <= r95222;
        double r95224 = 1.0;
        double r95225 = c;
        double r95226 = r95225 / r95221;
        double r95227 = a;
        double r95228 = r95221 / r95227;
        double r95229 = r95226 - r95228;
        double r95230 = r95224 * r95229;
        double r95231 = 8.930527750856993e-82;
        bool r95232 = r95221 <= r95231;
        double r95233 = r95221 * r95221;
        double r95234 = 4.0;
        double r95235 = r95234 * r95227;
        double r95236 = r95235 * r95225;
        double r95237 = r95233 - r95236;
        double r95238 = sqrt(r95237);
        double r95239 = r95221 - r95238;
        double r95240 = 2.0;
        double r95241 = r95240 * r95227;
        double r95242 = -r95241;
        double r95243 = r95239 / r95242;
        double r95244 = 4.019930844191633e+109;
        bool r95245 = r95221 <= r95244;
        double r95246 = 1.0;
        double r95247 = -r95221;
        double r95248 = r95247 - r95238;
        double r95249 = cbrt(r95248);
        double r95250 = r95249 * r95249;
        double r95251 = r95246 / r95250;
        double r95252 = r95227 * r95225;
        double r95253 = r95234 * r95252;
        double r95254 = r95241 / r95253;
        double r95255 = r95254 * r95249;
        double r95256 = r95251 / r95255;
        double r95257 = -1.0;
        double r95258 = r95257 * r95226;
        double r95259 = r95245 ? r95256 : r95258;
        double r95260 = r95232 ? r95243 : r95259;
        double r95261 = r95223 ? r95230 : r95260;
        return r95261;
}

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.1
Target20.7
Herbie9.3
\[\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 4 regimes
  2. if b < -2.3044033969831823e+153

    1. Initial program 63.5

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

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

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

    if -2.3044033969831823e+153 < b < 8.930527750856993e-82

    1. Initial program 12.5

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

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

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

    if 8.930527750856993e-82 < b < 4.019930844191633e+109

    1. Initial program 43.0

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

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

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt15.6

      \[\leadsto \frac{\frac{0 + 4 \cdot \left(a \cdot c\right)}{\color{blue}{\left(\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\right) \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity15.6

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

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

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

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

    if 4.019930844191633e+109 < b

    1. Initial program 59.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.3044033969831823 \cdot 10^{153}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 8.9305277508569929 \cdot 10^{-82}:\\ \;\;\;\;\frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{-2 \cdot a}\\ \mathbf{elif}\;b \le 4.01993084419163312 \cdot 10^{109}:\\ \;\;\;\;\frac{\frac{1}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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