Average Error: 34.0 → 9.0
Time: 18.2s
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 -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 3.243927964746086489471681708926883768814 \cdot 10^{-167}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.092314858884959904180796965245633627496 \cdot 10^{-13}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \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 -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\
\;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r4455238 = b;
        double r4455239 = -r4455238;
        double r4455240 = r4455238 * r4455238;
        double r4455241 = 4.0;
        double r4455242 = a;
        double r4455243 = r4455241 * r4455242;
        double r4455244 = c;
        double r4455245 = r4455243 * r4455244;
        double r4455246 = r4455240 - r4455245;
        double r4455247 = sqrt(r4455246);
        double r4455248 = r4455239 + r4455247;
        double r4455249 = 2.0;
        double r4455250 = r4455249 * r4455242;
        double r4455251 = r4455248 / r4455250;
        return r4455251;
}

double f(double a, double b, double c) {
        double r4455252 = b;
        double r4455253 = -8.035809894237901e+152;
        bool r4455254 = r4455252 <= r4455253;
        double r4455255 = c;
        double r4455256 = r4455255 / r4455252;
        double r4455257 = a;
        double r4455258 = r4455252 / r4455257;
        double r4455259 = r4455256 - r4455258;
        double r4455260 = 1.0;
        double r4455261 = r4455259 * r4455260;
        double r4455262 = 3.2439279647460865e-167;
        bool r4455263 = r4455252 <= r4455262;
        double r4455264 = r4455252 * r4455252;
        double r4455265 = 4.0;
        double r4455266 = r4455255 * r4455265;
        double r4455267 = r4455266 * r4455257;
        double r4455268 = r4455264 - r4455267;
        double r4455269 = sqrt(r4455268);
        double r4455270 = r4455269 - r4455252;
        double r4455271 = 2.0;
        double r4455272 = r4455257 * r4455271;
        double r4455273 = r4455270 / r4455272;
        double r4455274 = 1.0923148588849599e-13;
        bool r4455275 = r4455252 <= r4455274;
        double r4455276 = r4455264 - r4455264;
        double r4455277 = r4455265 * r4455257;
        double r4455278 = r4455255 * r4455277;
        double r4455279 = r4455276 + r4455278;
        double r4455280 = -r4455252;
        double r4455281 = r4455264 - r4455278;
        double r4455282 = sqrt(r4455281);
        double r4455283 = r4455280 - r4455282;
        double r4455284 = r4455279 / r4455283;
        double r4455285 = r4455284 / r4455272;
        double r4455286 = -1.0;
        double r4455287 = r4455286 * r4455256;
        double r4455288 = r4455275 ? r4455285 : r4455287;
        double r4455289 = r4455263 ? r4455273 : r4455288;
        double r4455290 = r4455254 ? r4455261 : r4455289;
        return r4455290;
}

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.1
Herbie9.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 4 regimes
  2. if b < -8.035809894237901e+152

    1. Initial program 63.6

      \[\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-inv63.6

      \[\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 associate-*r/63.6

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

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

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

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

    if -8.035809894237901e+152 < b < 3.2439279647460865e-167

    1. Initial program 10.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 div-inv10.6

      \[\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 associate-*r/10.5

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

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

    if 3.2439279647460865e-167 < b < 1.0923148588849599e-13

    1. Initial program 30.9

      \[\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-+31.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. Simplified18.4

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

    if 1.0923148588849599e-13 < b

    1. Initial program 55.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.035809894237901445931970544225072398237 \cdot 10^{152}:\\ \;\;\;\;\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 1\\ \mathbf{elif}\;b \le 3.243927964746086489471681708926883768814 \cdot 10^{-167}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.092314858884959904180796965245633627496 \cdot 10^{-13}:\\ \;\;\;\;\frac{\frac{\left(b \cdot b - b \cdot b\right) + c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019169 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))