Average Error: 34.4 → 9.1
Time: 20.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 -2.297624534318876743725099723501638614139 \cdot 10^{152}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.752932492055353784538521387722087830871 \cdot 10^{-90}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 683389336.59924924373626708984375:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot 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 -2.297624534318876743725099723501638614139 \cdot 10^{152}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r56819 = b;
        double r56820 = -r56819;
        double r56821 = r56819 * r56819;
        double r56822 = 4.0;
        double r56823 = a;
        double r56824 = r56822 * r56823;
        double r56825 = c;
        double r56826 = r56824 * r56825;
        double r56827 = r56821 - r56826;
        double r56828 = sqrt(r56827);
        double r56829 = r56820 + r56828;
        double r56830 = 2.0;
        double r56831 = r56830 * r56823;
        double r56832 = r56829 / r56831;
        return r56832;
}

double f(double a, double b, double c) {
        double r56833 = b;
        double r56834 = -2.2976245343188767e+152;
        bool r56835 = r56833 <= r56834;
        double r56836 = 1.0;
        double r56837 = c;
        double r56838 = r56837 / r56833;
        double r56839 = a;
        double r56840 = r56833 / r56839;
        double r56841 = r56838 - r56840;
        double r56842 = r56836 * r56841;
        double r56843 = 7.752932492055354e-90;
        bool r56844 = r56833 <= r56843;
        double r56845 = -r56833;
        double r56846 = r56833 * r56833;
        double r56847 = 4.0;
        double r56848 = r56847 * r56839;
        double r56849 = r56848 * r56837;
        double r56850 = r56846 - r56849;
        double r56851 = sqrt(r56850);
        double r56852 = r56845 + r56851;
        double r56853 = 2.0;
        double r56854 = r56853 * r56839;
        double r56855 = r56852 / r56854;
        double r56856 = 683389336.5992492;
        bool r56857 = r56833 <= r56856;
        double r56858 = r56845 - r56851;
        double r56859 = r56849 / r56858;
        double r56860 = r56859 / r56854;
        double r56861 = -1.0;
        double r56862 = r56861 * r56838;
        double r56863 = r56857 ? r56860 : r56862;
        double r56864 = r56844 ? r56855 : r56863;
        double r56865 = r56835 ? r56842 : r56864;
        return r56865;
}

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.4
Target21.4
Herbie9.1
\[\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 < -2.2976245343188767e+152

    1. Initial program 63.3

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

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

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

    if -2.2976245343188767e+152 < b < 7.752932492055354e-90

    1. Initial program 11.9

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

    if 7.752932492055354e-90 < b < 683389336.5992492

    1. Initial program 39.9

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

      \[\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. Simplified18.6

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

    if 683389336.5992492 < b

    1. Initial program 56.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.297624534318876743725099723501638614139 \cdot 10^{152}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 7.752932492055353784538521387722087830871 \cdot 10^{-90}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{elif}\;b \le 683389336.59924924373626708984375:\\ \;\;\;\;\frac{\frac{\left(4 \cdot a\right) \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

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