Average Error: 33.6 → 9.9
Time: 19.3s
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.396811349079212 \cdot 10^{+61}:\\ \;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.3659668388152999 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\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.396811349079212 \cdot 10^{+61}:\\
\;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{2 \cdot a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r2368984 = b;
        double r2368985 = -r2368984;
        double r2368986 = r2368984 * r2368984;
        double r2368987 = 4.0;
        double r2368988 = a;
        double r2368989 = r2368987 * r2368988;
        double r2368990 = c;
        double r2368991 = r2368989 * r2368990;
        double r2368992 = r2368986 - r2368991;
        double r2368993 = sqrt(r2368992);
        double r2368994 = r2368985 + r2368993;
        double r2368995 = 2.0;
        double r2368996 = r2368995 * r2368988;
        double r2368997 = r2368994 / r2368996;
        return r2368997;
}

double f(double a, double b, double c) {
        double r2368998 = b;
        double r2368999 = -3.396811349079212e+61;
        bool r2369000 = r2368998 <= r2368999;
        double r2369001 = c;
        double r2369002 = a;
        double r2369003 = r2368998 / r2369002;
        double r2369004 = r2369001 / r2369003;
        double r2369005 = r2369004 - r2368998;
        double r2369006 = 2.0;
        double r2369007 = r2369005 * r2369006;
        double r2369008 = r2369006 * r2369002;
        double r2369009 = r2369007 / r2369008;
        double r2369010 = 1.3659668388152999e-67;
        bool r2369011 = r2368998 <= r2369010;
        double r2369012 = r2368998 * r2368998;
        double r2369013 = r2369001 * r2369002;
        double r2369014 = 4.0;
        double r2369015 = r2369013 * r2369014;
        double r2369016 = r2369012 - r2369015;
        double r2369017 = sqrt(r2369016);
        double r2369018 = r2369017 - r2368998;
        double r2369019 = r2369018 / r2369008;
        double r2369020 = -r2369001;
        double r2369021 = r2369020 / r2368998;
        double r2369022 = r2369011 ? r2369019 : r2369021;
        double r2369023 = r2369000 ? r2369009 : r2369022;
        return r2369023;
}

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

Original33.6
Target20.8
Herbie9.9
\[\begin{array}{l} \mathbf{if}\;b \lt 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.396811349079212e+61

    1. Initial program 37.6

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

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

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

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

    if -3.396811349079212e+61 < b < 1.3659668388152999e-67

    1. Initial program 13.9

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

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

    if 1.3659668388152999e-67 < b

    1. Initial program 53.0

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.396811349079212 \cdot 10^{+61}:\\ \;\;\;\;\frac{\left(\frac{c}{\frac{b}{a}} - b\right) \cdot 2}{2 \cdot a}\\ \mathbf{elif}\;b \le 1.3659668388152999 \cdot 10^{-67}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 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)))