Average Error: 34.2 → 10.0
Time: 15.4s
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 -5.840382544825149510322162525528307154775 \cdot 10^{46}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -7.877985662156598668725484528840176897607 \cdot 10^{-94}:\\ \;\;\;\;\frac{\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(4 \cdot c\right)}{a}}{2}}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -6.596302400897661869317839215315745353488 \cdot 10^{-136}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 7.501979458872916117674264090696641915837 \cdot 10^{77}:\\ \;\;\;\;-\left(\frac{\frac{b}{a}}{2} + \frac{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{2 \cdot a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-1 \cdot 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 -5.840382544825149510322162525528307154775 \cdot 10^{46}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

\mathbf{elif}\;b \le -6.596302400897661869317839215315745353488 \cdot 10^{-136}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r52927 = b;
        double r52928 = -r52927;
        double r52929 = r52927 * r52927;
        double r52930 = 4.0;
        double r52931 = a;
        double r52932 = c;
        double r52933 = r52931 * r52932;
        double r52934 = r52930 * r52933;
        double r52935 = r52929 - r52934;
        double r52936 = sqrt(r52935);
        double r52937 = r52928 - r52936;
        double r52938 = 2.0;
        double r52939 = r52938 * r52931;
        double r52940 = r52937 / r52939;
        return r52940;
}

double f(double a, double b, double c) {
        double r52941 = b;
        double r52942 = -5.84038254482515e+46;
        bool r52943 = r52941 <= r52942;
        double r52944 = -1.0;
        double r52945 = c;
        double r52946 = r52945 / r52941;
        double r52947 = r52944 * r52946;
        double r52948 = -7.877985662156599e-94;
        bool r52949 = r52941 <= r52948;
        double r52950 = r52941 * r52941;
        double r52951 = r52950 - r52950;
        double r52952 = a;
        double r52953 = 4.0;
        double r52954 = r52953 * r52945;
        double r52955 = r52952 * r52954;
        double r52956 = r52951 + r52955;
        double r52957 = r52956 / r52952;
        double r52958 = 2.0;
        double r52959 = r52957 / r52958;
        double r52960 = r52945 * r52952;
        double r52961 = r52953 * r52960;
        double r52962 = r52950 - r52961;
        double r52963 = sqrt(r52962);
        double r52964 = -r52941;
        double r52965 = r52963 + r52964;
        double r52966 = r52959 / r52965;
        double r52967 = -6.596302400897662e-136;
        bool r52968 = r52941 <= r52967;
        double r52969 = 7.501979458872916e+77;
        bool r52970 = r52941 <= r52969;
        double r52971 = r52941 / r52952;
        double r52972 = r52971 / r52958;
        double r52973 = r52950 - r52955;
        double r52974 = sqrt(r52973);
        double r52975 = r52958 * r52952;
        double r52976 = r52974 / r52975;
        double r52977 = r52972 + r52976;
        double r52978 = -r52977;
        double r52979 = r52944 * r52941;
        double r52980 = r52979 / r52952;
        double r52981 = r52970 ? r52978 : r52980;
        double r52982 = r52968 ? r52947 : r52981;
        double r52983 = r52949 ? r52966 : r52982;
        double r52984 = r52943 ? r52947 : r52983;
        return r52984;
}

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.2
Herbie10.0
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -5.84038254482515e+46 or -7.877985662156599e-94 < b < -6.596302400897662e-136

    1. Initial program 54.4

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

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

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

    if -5.84038254482515e+46 < b < -7.877985662156599e-94

    1. Initial program 40.2

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    7. Applied add-cube-cbrt40.3

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

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

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

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

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

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

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

    if -6.596302400897662e-136 < b < 7.501979458872916e+77

    1. Initial program 12.1

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    5. Using strategy rm
    6. Applied div-inv12.2

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    7. Applied add-cube-cbrt12.2

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

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

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

      \[\leadsto \frac{1}{a \cdot 2} \cdot \color{blue}{\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}\]
    11. Using strategy rm
    12. Applied sub-neg12.2

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

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

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

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

    if 7.501979458872916e+77 < b

    1. Initial program 42.5

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}}\]
    7. Applied add-cube-cbrt42.7

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}}\]
    8. Applied times-frac42.7

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    12. Simplified5.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.840382544825149510322162525528307154775 \cdot 10^{46}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le -7.877985662156598668725484528840176897607 \cdot 10^{-94}:\\ \;\;\;\;\frac{\frac{\frac{\left(b \cdot b - b \cdot b\right) + a \cdot \left(4 \cdot c\right)}{a}}{2}}{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)}\\ \mathbf{elif}\;b \le -6.596302400897661869317839215315745353488 \cdot 10^{-136}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \mathbf{elif}\;b \le 7.501979458872916117674264090696641915837 \cdot 10^{77}:\\ \;\;\;\;-\left(\frac{\frac{b}{a}}{2} + \frac{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{2 \cdot a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-1 \cdot b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019196 
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))