Average Error: 34.2 → 10.4
Time: 8.9s
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 -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2} \cdot \frac{1}{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 -4.12310353364421125 \cdot 10^{95}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r80849 = b;
        double r80850 = -r80849;
        double r80851 = r80849 * r80849;
        double r80852 = 4.0;
        double r80853 = a;
        double r80854 = r80852 * r80853;
        double r80855 = c;
        double r80856 = r80854 * r80855;
        double r80857 = r80851 - r80856;
        double r80858 = sqrt(r80857);
        double r80859 = r80850 + r80858;
        double r80860 = 2.0;
        double r80861 = r80860 * r80853;
        double r80862 = r80859 / r80861;
        return r80862;
}

double f(double a, double b, double c) {
        double r80863 = b;
        double r80864 = -4.123103533644211e+95;
        bool r80865 = r80863 <= r80864;
        double r80866 = 1.0;
        double r80867 = c;
        double r80868 = r80867 / r80863;
        double r80869 = a;
        double r80870 = r80863 / r80869;
        double r80871 = r80868 - r80870;
        double r80872 = r80866 * r80871;
        double r80873 = 3.446447862996811e-75;
        bool r80874 = r80863 <= r80873;
        double r80875 = r80863 * r80863;
        double r80876 = 4.0;
        double r80877 = r80876 * r80869;
        double r80878 = r80877 * r80867;
        double r80879 = r80875 - r80878;
        double r80880 = sqrt(r80879);
        double r80881 = r80880 - r80863;
        double r80882 = 2.0;
        double r80883 = r80881 / r80882;
        double r80884 = 1.0;
        double r80885 = r80884 / r80869;
        double r80886 = r80883 * r80885;
        double r80887 = -1.0;
        double r80888 = r80887 * r80868;
        double r80889 = r80874 ? r80886 : r80888;
        double r80890 = r80865 ? r80872 : r80889;
        return r80890;
}

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.1
Herbie10.4
\[\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 < -4.123103533644211e+95

    1. Initial program 47.3

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

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

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

    if -4.123103533644211e+95 < b < 3.446447862996811e-75

    1. Initial program 13.3

      \[\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-inv13.4

      \[\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}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity13.4

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{\color{blue}{1 \cdot 1}}{2 \cdot a}\]
    6. Applied times-frac13.4

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

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

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

    if 3.446447862996811e-75 < b

    1. Initial program 52.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.12310353364421125 \cdot 10^{95}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 3.446447862996811 \cdot 10^{-75}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{2} \cdot \frac{1}{a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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