Average Error: 34.4 → 9.1
Time: 13.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 -2.297624534318876743725099723501638614139 \cdot 10^{152}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.752932492055353784538521387722087830871 \cdot 10^{-90}:\\ \;\;\;\;\frac{-\left(b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{2 \cdot a}\\ \mathbf{elif}\;b \le 683389336.59924924373626708984375:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{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 -2.297624534318876743725099723501638614139 \cdot 10^{152}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r119113 = b;
        double r119114 = -r119113;
        double r119115 = r119113 * r119113;
        double r119116 = 4.0;
        double r119117 = a;
        double r119118 = r119116 * r119117;
        double r119119 = c;
        double r119120 = r119118 * r119119;
        double r119121 = r119115 - r119120;
        double r119122 = sqrt(r119121);
        double r119123 = r119114 + r119122;
        double r119124 = 2.0;
        double r119125 = r119124 * r119117;
        double r119126 = r119123 / r119125;
        return r119126;
}

double f(double a, double b, double c) {
        double r119127 = b;
        double r119128 = -2.2976245343188767e+152;
        bool r119129 = r119127 <= r119128;
        double r119130 = 1.0;
        double r119131 = c;
        double r119132 = r119131 / r119127;
        double r119133 = a;
        double r119134 = r119127 / r119133;
        double r119135 = r119132 - r119134;
        double r119136 = r119130 * r119135;
        double r119137 = 7.752932492055354e-90;
        bool r119138 = r119127 <= r119137;
        double r119139 = r119127 * r119127;
        double r119140 = 4.0;
        double r119141 = r119140 * r119133;
        double r119142 = r119141 * r119131;
        double r119143 = r119139 - r119142;
        double r119144 = sqrt(r119143);
        double r119145 = r119127 - r119144;
        double r119146 = -r119145;
        double r119147 = 2.0;
        double r119148 = r119147 * r119133;
        double r119149 = r119146 / r119148;
        double r119150 = 683389336.5992492;
        bool r119151 = r119127 <= r119150;
        double r119152 = -r119127;
        double r119153 = r119152 - r119144;
        double r119154 = r119142 / r119153;
        double r119155 = r119154 / r119148;
        double r119156 = -1.0;
        double r119157 = r119156 * r119132;
        double r119158 = r119151 ? r119155 : r119157;
        double r119159 = r119138 ? r119149 : r119158;
        double r119160 = r119129 ? r119136 : r119159;
        return r119160;
}

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.4
Target21.4
Herbie9.1
\[\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.2976245343188767e+152

    1. Initial program 63.3

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

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

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

    if -2.2976245343188767e+152 < b < 7.752932492055354e-90

    1. Initial program 11.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 neg-sub011.9

      \[\leadsto \frac{\color{blue}{\left(0 - b\right)} + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    4. Applied associate-+l-11.9

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

    if 7.752932492055354e-90 < b < 683389336.5992492

    1. Initial program 39.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-+40.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.6

      \[\leadsto \frac{\frac{\color{blue}{0 + \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 683389336.5992492 < b

    1. Initial program 56.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.297624534318876743725099723501638614139 \cdot 10^{152}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.752932492055353784538521387722087830871 \cdot 10^{-90}:\\ \;\;\;\;\frac{-\left(b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{2 \cdot a}\\ \mathbf{elif}\;b \le 683389336.59924924373626708984375:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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