Average Error: 32.8 → 6.4
Time: 15.1s
Precision: 64
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.1214768270116103 \cdot 10^{+154}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.199441090208904 \cdot 10^{-250}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 3.3389954009657566 \cdot 10^{+124}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -1.1214768270116103 \cdot 10^{+154}:\\
\;\;\;\;\frac{-c}{b}\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r1499922 = b;
        double r1499923 = -r1499922;
        double r1499924 = r1499922 * r1499922;
        double r1499925 = 4.0;
        double r1499926 = a;
        double r1499927 = c;
        double r1499928 = r1499926 * r1499927;
        double r1499929 = r1499925 * r1499928;
        double r1499930 = r1499924 - r1499929;
        double r1499931 = sqrt(r1499930);
        double r1499932 = r1499923 - r1499931;
        double r1499933 = 2.0;
        double r1499934 = r1499933 * r1499926;
        double r1499935 = r1499932 / r1499934;
        return r1499935;
}

double f(double a, double b, double c) {
        double r1499936 = b;
        double r1499937 = -1.1214768270116103e+154;
        bool r1499938 = r1499936 <= r1499937;
        double r1499939 = c;
        double r1499940 = -r1499939;
        double r1499941 = r1499940 / r1499936;
        double r1499942 = 1.199441090208904e-250;
        bool r1499943 = r1499936 <= r1499942;
        double r1499944 = 2.0;
        double r1499945 = r1499944 * r1499939;
        double r1499946 = r1499936 * r1499936;
        double r1499947 = 4.0;
        double r1499948 = a;
        double r1499949 = r1499939 * r1499948;
        double r1499950 = r1499947 * r1499949;
        double r1499951 = r1499946 - r1499950;
        double r1499952 = sqrt(r1499951);
        double r1499953 = -r1499936;
        double r1499954 = r1499952 + r1499953;
        double r1499955 = r1499945 / r1499954;
        double r1499956 = 3.3389954009657566e+124;
        bool r1499957 = r1499936 <= r1499956;
        double r1499958 = r1499953 - r1499952;
        double r1499959 = r1499948 * r1499944;
        double r1499960 = r1499958 / r1499959;
        double r1499961 = r1499953 / r1499948;
        double r1499962 = r1499957 ? r1499960 : r1499961;
        double r1499963 = r1499943 ? r1499955 : r1499962;
        double r1499964 = r1499938 ? r1499941 : r1499963;
        return r1499964;
}

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.8
Target20.1
Herbie6.4
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -1.1214768270116103e+154

    1. Initial program 62.9

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

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

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

    if -1.1214768270116103e+154 < b < 1.199441090208904e-250

    1. Initial program 32.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity32.2

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Applied *-un-lft-identity32.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    5. Applied distribute-lft-out--32.2

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    7. Using strategy rm
    8. Applied flip--32.3

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

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

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

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

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

    if 1.199441090208904e-250 < b < 3.3389954009657566e+124

    1. Initial program 7.8

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

    if 3.3389954009657566e+124 < b

    1. Initial program 50.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity50.5

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Applied *-un-lft-identity50.5

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    5. Applied distribute-lft-out--50.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.1214768270116103 \cdot 10^{+154}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.199441090208904 \cdot 10^{-250}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le 3.3389954009657566 \cdot 10^{+124}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))