Average Error: 34.2 → 10.4
Time: 9.4s
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.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2} \cdot \frac{\sqrt[3]{1}}{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 -4.12310353364421125 \cdot 10^{95}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r153197 = b;
        double r153198 = -r153197;
        double r153199 = r153197 * r153197;
        double r153200 = 4.0;
        double r153201 = a;
        double r153202 = r153200 * r153201;
        double r153203 = c;
        double r153204 = r153202 * r153203;
        double r153205 = r153199 - r153204;
        double r153206 = sqrt(r153205);
        double r153207 = r153198 + r153206;
        double r153208 = 2.0;
        double r153209 = r153208 * r153201;
        double r153210 = r153207 / r153209;
        return r153210;
}

double f(double a, double b, double c) {
        double r153211 = b;
        double r153212 = -4.123103533644211e+95;
        bool r153213 = r153211 <= r153212;
        double r153214 = 1.0;
        double r153215 = c;
        double r153216 = r153215 / r153211;
        double r153217 = a;
        double r153218 = r153211 / r153217;
        double r153219 = r153216 - r153218;
        double r153220 = r153214 * r153219;
        double r153221 = 3.446447862996811e-75;
        bool r153222 = r153211 <= r153221;
        double r153223 = r153211 * r153211;
        double r153224 = 4.0;
        double r153225 = r153224 * r153217;
        double r153226 = r153225 * r153215;
        double r153227 = r153223 - r153226;
        double r153228 = sqrt(r153227);
        double r153229 = r153228 - r153211;
        double r153230 = 2.0;
        double r153231 = r153229 / r153230;
        double r153232 = 1.0;
        double r153233 = cbrt(r153232);
        double r153234 = r153233 / r153217;
        double r153235 = r153231 * r153234;
        double r153236 = -1.0;
        double r153237 = r153236 * r153216;
        double r153238 = r153222 ? r153235 : r153237;
        double r153239 = r153213 ? r153220 : r153238;
        return r153239;
}

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.2
Target21.1
Herbie10.4
\[\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 < -4.123103533644211e+95

    1. Initial program 47.3

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

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

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

    if -4.123103533644211e+95 < b < 3.446447862996811e-75

    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 div-inv13.4

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

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

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\left(\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{2} \cdot \frac{\sqrt[3]{1}}{a}\right)}\]
    7. Applied associate-*r*13.4

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

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

    if 3.446447862996811e-75 < b

    1. Initial program 52.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2} \cdot \frac{\sqrt[3]{1}}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020042 
(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)))