Average Error: 34.2 → 6.8
Time: 5.0s
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 -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.17047858644702483 \cdot 10^{-264}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.7711811459025421 \cdot 10^{84}:\\ \;\;\;\;1 \cdot \frac{\frac{1}{\frac{2}{4}}}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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 -5.2389466313579672 \cdot 10^{127}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r77174 = b;
        double r77175 = -r77174;
        double r77176 = r77174 * r77174;
        double r77177 = 4.0;
        double r77178 = a;
        double r77179 = r77177 * r77178;
        double r77180 = c;
        double r77181 = r77179 * r77180;
        double r77182 = r77176 - r77181;
        double r77183 = sqrt(r77182);
        double r77184 = r77175 + r77183;
        double r77185 = 2.0;
        double r77186 = r77185 * r77178;
        double r77187 = r77184 / r77186;
        return r77187;
}

double f(double a, double b, double c) {
        double r77188 = b;
        double r77189 = -5.238946631357967e+127;
        bool r77190 = r77188 <= r77189;
        double r77191 = 1.0;
        double r77192 = c;
        double r77193 = r77192 / r77188;
        double r77194 = a;
        double r77195 = r77188 / r77194;
        double r77196 = r77193 - r77195;
        double r77197 = r77191 * r77196;
        double r77198 = 7.170478586447025e-264;
        bool r77199 = r77188 <= r77198;
        double r77200 = -r77188;
        double r77201 = r77188 * r77188;
        double r77202 = 4.0;
        double r77203 = r77202 * r77194;
        double r77204 = r77203 * r77192;
        double r77205 = r77201 - r77204;
        double r77206 = sqrt(r77205);
        double r77207 = r77200 + r77206;
        double r77208 = 2.0;
        double r77209 = r77208 * r77194;
        double r77210 = r77207 / r77209;
        double r77211 = 3.771181145902542e+84;
        bool r77212 = r77188 <= r77211;
        double r77213 = 1.0;
        double r77214 = r77208 / r77202;
        double r77215 = r77213 / r77214;
        double r77216 = r77200 - r77206;
        double r77217 = r77216 / r77192;
        double r77218 = r77215 / r77217;
        double r77219 = r77213 * r77218;
        double r77220 = -1.0;
        double r77221 = r77220 * r77193;
        double r77222 = r77212 ? r77219 : r77221;
        double r77223 = r77199 ? r77210 : r77222;
        double r77224 = r77190 ? r77197 : r77223;
        return r77224;
}

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.6
Herbie6.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 4 regimes
  2. if b < -5.238946631357967e+127

    1. Initial program 54.2

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

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

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

    if -5.238946631357967e+127 < b < 7.170478586447025e-264

    1. Initial program 8.9

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

    if 7.170478586447025e-264 < b < 3.771181145902542e+84

    1. Initial program 34.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-+34.1

      \[\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. Simplified16.5

      \[\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 *-un-lft-identity16.5

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{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}\]
    9. Applied associate-/l*16.7

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

      \[\leadsto \frac{\frac{1}{1}}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    11. Using strategy rm
    12. Applied times-frac16.1

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

      \[\leadsto \frac{\frac{1}{1}}{\left(\frac{2}{4} \cdot \color{blue}{\frac{1}{c}}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    14. Using strategy rm
    15. Applied div-inv9.7

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

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

    if 3.771181145902542e+84 < b

    1. Initial program 58.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.17047858644702483 \cdot 10^{-264}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.7711811459025421 \cdot 10^{84}:\\ \;\;\;\;1 \cdot \frac{\frac{1}{\frac{2}{4}}}{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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