Average Error: 34.0 → 9.8
Time: 19.1s
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 -3.028200009108187875261653423186597465196 \cdot 10^{115}:\\ \;\;\;\;\frac{-2 \cdot b}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.089744618622775294902023307017914843593 \cdot 10^{-73}:\\ \;\;\;\;\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 -3.028200009108187875261653423186597465196 \cdot 10^{115}:\\
\;\;\;\;\frac{-2 \cdot b}{2 \cdot a}\\

\mathbf{elif}\;b \le 4.089744618622775294902023307017914843593 \cdot 10^{-73}:\\
\;\;\;\;\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 r57137 = b;
        double r57138 = -r57137;
        double r57139 = r57137 * r57137;
        double r57140 = 4.0;
        double r57141 = a;
        double r57142 = r57140 * r57141;
        double r57143 = c;
        double r57144 = r57142 * r57143;
        double r57145 = r57139 - r57144;
        double r57146 = sqrt(r57145);
        double r57147 = r57138 + r57146;
        double r57148 = 2.0;
        double r57149 = r57148 * r57141;
        double r57150 = r57147 / r57149;
        return r57150;
}

double f(double a, double b, double c) {
        double r57151 = b;
        double r57152 = -3.028200009108188e+115;
        bool r57153 = r57151 <= r57152;
        double r57154 = -2.0;
        double r57155 = r57154 * r57151;
        double r57156 = 2.0;
        double r57157 = a;
        double r57158 = r57156 * r57157;
        double r57159 = r57155 / r57158;
        double r57160 = 4.089744618622775e-73;
        bool r57161 = r57151 <= r57160;
        double r57162 = r57151 * r57151;
        double r57163 = 4.0;
        double r57164 = r57163 * r57157;
        double r57165 = c;
        double r57166 = r57164 * r57165;
        double r57167 = r57162 - r57166;
        double r57168 = sqrt(r57167);
        double r57169 = r57168 - r57151;
        double r57170 = r57169 / r57158;
        double r57171 = -1.0;
        double r57172 = r57165 / r57151;
        double r57173 = r57171 * r57172;
        double r57174 = r57161 ? r57170 : r57173;
        double r57175 = r57153 ? r57159 : r57174;
        return r57175;
}

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.0
Herbie9.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 3 regimes
  2. if b < -3.028200009108188e+115

    1. Initial program 51.0

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

      \[\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 add-cube-cbrt51.1

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

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

      \[\leadsto \frac{\color{blue}{-2 \cdot b}}{2 \cdot a}\]
    7. Simplified3.4

      \[\leadsto \frac{\color{blue}{-2 \cdot b}}{2 \cdot a}\]

    if -3.028200009108188e+115 < b < 4.089744618622775e-73

    1. Initial program 12.6

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

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

    if 4.089744618622775e-73 < b

    1. Initial program 53.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.028200009108187875261653423186597465196 \cdot 10^{115}:\\ \;\;\;\;\frac{-2 \cdot b}{2 \cdot a}\\ \mathbf{elif}\;b \le 4.089744618622775294902023307017914843593 \cdot 10^{-73}:\\ \;\;\;\;\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 2019305 +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)))