Average Error: 34.2 → 8.9
Time: 6.6s
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.50529903241060843 \cdot 10^{27}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -6.63395785424786023 \cdot 10^{-258}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.16896907782470713 \cdot 10^{-19}:\\ \;\;\;\;\frac{1 \cdot \frac{4}{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}}{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 -1.50529903241060843 \cdot 10^{27}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r80028 = b;
        double r80029 = -r80028;
        double r80030 = r80028 * r80028;
        double r80031 = 4.0;
        double r80032 = a;
        double r80033 = r80031 * r80032;
        double r80034 = c;
        double r80035 = r80033 * r80034;
        double r80036 = r80030 - r80035;
        double r80037 = sqrt(r80036);
        double r80038 = r80029 + r80037;
        double r80039 = 2.0;
        double r80040 = r80039 * r80032;
        double r80041 = r80038 / r80040;
        return r80041;
}

double f(double a, double b, double c) {
        double r80042 = b;
        double r80043 = -1.5052990324106084e+27;
        bool r80044 = r80042 <= r80043;
        double r80045 = 1.0;
        double r80046 = c;
        double r80047 = r80046 / r80042;
        double r80048 = a;
        double r80049 = r80042 / r80048;
        double r80050 = r80047 - r80049;
        double r80051 = r80045 * r80050;
        double r80052 = -6.63395785424786e-258;
        bool r80053 = r80042 <= r80052;
        double r80054 = -r80042;
        double r80055 = r80042 * r80042;
        double r80056 = 4.0;
        double r80057 = r80056 * r80048;
        double r80058 = r80057 * r80046;
        double r80059 = r80055 - r80058;
        double r80060 = sqrt(r80059);
        double r80061 = r80054 + r80060;
        double r80062 = 1.0;
        double r80063 = 2.0;
        double r80064 = r80063 * r80048;
        double r80065 = r80062 / r80064;
        double r80066 = r80061 * r80065;
        double r80067 = 1.1689690778247071e-19;
        bool r80068 = r80042 <= r80067;
        double r80069 = r80054 - r80060;
        double r80070 = r80069 / r80048;
        double r80071 = r80070 / r80046;
        double r80072 = r80056 / r80071;
        double r80073 = r80062 * r80072;
        double r80074 = r80073 / r80064;
        double r80075 = -1.0;
        double r80076 = r80075 * r80047;
        double r80077 = r80068 ? r80074 : r80076;
        double r80078 = r80053 ? r80066 : r80077;
        double r80079 = r80044 ? r80051 : r80078;
        return r80079;
}

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.2
Herbie8.9
\[\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 < -1.5052990324106084e+27

    1. Initial program 35.7

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

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

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

    if -1.5052990324106084e+27 < b < -6.63395785424786e-258

    1. Initial program 9.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 div-inv9.1

      \[\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}}\]

    if -6.63395785424786e-258 < b < 1.1689690778247071e-19

    1. Initial program 23.8

      \[\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-+23.9

      \[\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. Simplified17.8

      \[\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-identity17.8

      \[\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-identity17.8

      \[\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-frac17.8

      \[\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. Simplified17.8

      \[\leadsto \frac{\color{blue}{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}\]
    10. Simplified17.8

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

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

    if 1.1689690778247071e-19 < b

    1. Initial program 55.0

      \[\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 simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.50529903241060843 \cdot 10^{27}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -6.63395785424786023 \cdot 10^{-258}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.16896907782470713 \cdot 10^{-19}:\\ \;\;\;\;\frac{1 \cdot \frac{4}{\frac{\frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}}{c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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