Average Error: 32.9 → 10.6
Time: 20.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 -6.1701110130378705 \cdot 10^{+68}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.4352467544377554 \cdot 10^{-114}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}} - \frac{b}{a \cdot 2}\\ \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 -6.1701110130378705 \cdot 10^{+68}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r5023871 = b;
        double r5023872 = -r5023871;
        double r5023873 = r5023871 * r5023871;
        double r5023874 = 4.0;
        double r5023875 = a;
        double r5023876 = r5023874 * r5023875;
        double r5023877 = c;
        double r5023878 = r5023876 * r5023877;
        double r5023879 = r5023873 - r5023878;
        double r5023880 = sqrt(r5023879);
        double r5023881 = r5023872 + r5023880;
        double r5023882 = 2.0;
        double r5023883 = r5023882 * r5023875;
        double r5023884 = r5023881 / r5023883;
        return r5023884;
}

double f(double a, double b, double c) {
        double r5023885 = b;
        double r5023886 = -6.1701110130378705e+68;
        bool r5023887 = r5023885 <= r5023886;
        double r5023888 = c;
        double r5023889 = r5023888 / r5023885;
        double r5023890 = a;
        double r5023891 = r5023885 / r5023890;
        double r5023892 = r5023889 - r5023891;
        double r5023893 = 1.4352467544377554e-114;
        bool r5023894 = r5023885 <= r5023893;
        double r5023895 = 1.0;
        double r5023896 = 2.0;
        double r5023897 = r5023890 * r5023896;
        double r5023898 = r5023885 * r5023885;
        double r5023899 = 4.0;
        double r5023900 = r5023888 * r5023890;
        double r5023901 = r5023899 * r5023900;
        double r5023902 = r5023898 - r5023901;
        double r5023903 = sqrt(r5023902);
        double r5023904 = r5023897 / r5023903;
        double r5023905 = r5023895 / r5023904;
        double r5023906 = r5023885 / r5023897;
        double r5023907 = r5023905 - r5023906;
        double r5023908 = -r5023889;
        double r5023909 = r5023894 ? r5023907 : r5023908;
        double r5023910 = r5023887 ? r5023892 : r5023909;
        return r5023910;
}

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

Original32.9
Target20.2
Herbie10.6
\[\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 < -6.1701110130378705e+68

    1. Initial program 38.1

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

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

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

    if -6.1701110130378705e+68 < b < 1.4352467544377554e-114

    1. Initial program 12.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified12.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-sub12.0

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

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

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

    if 1.4352467544377554e-114 < b

    1. Initial program 50.9

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

      \[\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-sub51.3

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified11.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.1701110130378705 \cdot 10^{+68}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.4352467544377554 \cdot 10^{-114}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}} - \frac{b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019133 
(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)))