Average Error: 34.2 → 11.6
Time: 19.8s
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 -1.555632367828988861043913196266489993904 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.455592343308264166675918758902222662503 \cdot 10^{-170}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot 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 -1.555632367828988861043913196266489993904 \cdot 10^{101}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r153004 = b;
        double r153005 = -r153004;
        double r153006 = r153004 * r153004;
        double r153007 = 4.0;
        double r153008 = a;
        double r153009 = r153007 * r153008;
        double r153010 = c;
        double r153011 = r153009 * r153010;
        double r153012 = r153006 - r153011;
        double r153013 = sqrt(r153012);
        double r153014 = r153005 + r153013;
        double r153015 = 2.0;
        double r153016 = r153015 * r153008;
        double r153017 = r153014 / r153016;
        return r153017;
}

double f(double a, double b, double c) {
        double r153018 = b;
        double r153019 = -1.555632367828989e+101;
        bool r153020 = r153018 <= r153019;
        double r153021 = 1.0;
        double r153022 = c;
        double r153023 = r153022 / r153018;
        double r153024 = a;
        double r153025 = r153018 / r153024;
        double r153026 = r153023 - r153025;
        double r153027 = r153021 * r153026;
        double r153028 = 7.455592343308264e-170;
        bool r153029 = r153018 <= r153028;
        double r153030 = r153018 * r153018;
        double r153031 = 4.0;
        double r153032 = r153031 * r153024;
        double r153033 = r153032 * r153022;
        double r153034 = r153030 - r153033;
        double r153035 = sqrt(r153034);
        double r153036 = r153035 - r153018;
        double r153037 = 2.0;
        double r153038 = r153037 * r153024;
        double r153039 = r153036 / r153038;
        double r153040 = -1.0;
        double r153041 = r153040 * r153023;
        double r153042 = r153029 ? r153039 : r153041;
        double r153043 = r153020 ? r153027 : r153042;
        return r153043;
}

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
Target20.8
Herbie11.6
\[\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 < -1.555632367828989e+101

    1. Initial program 47.4

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv47.4

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity47.4

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

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

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

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

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

    if -1.555632367828989e+101 < b < 7.455592343308264e-170

    1. Initial program 11.7

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

      \[\leadsto \color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied div-inv11.8

      \[\leadsto \color{blue}{\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{1}{2 \cdot a}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity11.8

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

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

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

    if 7.455592343308264e-170 < b

    1. Initial program 48.9

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

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

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

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

Reproduce

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