Average Error: 33.1 → 10.3
Time: 18.7s
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 -1.7729369216517423 \cdot 10^{+64}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 9.831724396970673 \cdot 10^{-110}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \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 -1.7729369216517423 \cdot 10^{+64}:\\
\;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r4586931 = b;
        double r4586932 = -r4586931;
        double r4586933 = r4586931 * r4586931;
        double r4586934 = 4.0;
        double r4586935 = a;
        double r4586936 = r4586934 * r4586935;
        double r4586937 = c;
        double r4586938 = r4586936 * r4586937;
        double r4586939 = r4586933 - r4586938;
        double r4586940 = sqrt(r4586939);
        double r4586941 = r4586932 + r4586940;
        double r4586942 = 2.0;
        double r4586943 = r4586942 * r4586935;
        double r4586944 = r4586941 / r4586943;
        return r4586944;
}

double f(double a, double b, double c) {
        double r4586945 = b;
        double r4586946 = -1.7729369216517423e+64;
        bool r4586947 = r4586945 <= r4586946;
        double r4586948 = c;
        double r4586949 = r4586948 / r4586945;
        double r4586950 = a;
        double r4586951 = r4586945 / r4586950;
        double r4586952 = r4586949 - r4586951;
        double r4586953 = 2.0;
        double r4586954 = r4586952 * r4586953;
        double r4586955 = r4586954 / r4586953;
        double r4586956 = 9.831724396970673e-110;
        bool r4586957 = r4586945 <= r4586956;
        double r4586958 = r4586945 * r4586945;
        double r4586959 = 4.0;
        double r4586960 = r4586950 * r4586948;
        double r4586961 = r4586959 * r4586960;
        double r4586962 = r4586958 - r4586961;
        double r4586963 = sqrt(r4586962);
        double r4586964 = r4586963 - r4586945;
        double r4586965 = r4586964 / r4586950;
        double r4586966 = r4586965 / r4586953;
        double r4586967 = -2.0;
        double r4586968 = r4586967 * r4586949;
        double r4586969 = r4586968 / r4586953;
        double r4586970 = r4586957 ? r4586966 : r4586969;
        double r4586971 = r4586947 ? r4586955 : r4586970;
        return r4586971;
}

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

Original33.1
Target20.2
Herbie10.3
\[\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 < -1.7729369216517423e+64

    1. Initial program 37.7

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}{2}\]
    10. Simplified5.2

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

    if -1.7729369216517423e+64 < b < 9.831724396970673e-110

    1. Initial program 12.1

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

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

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

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

    if 9.831724396970673e-110 < b

    1. Initial program 51.0

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7729369216517423 \cdot 10^{+64}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 9.831724396970673 \cdot 10^{-110}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2 \cdot \frac{c}{b}}{2}\\ \end{array}\]

Reproduce

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