Average Error: 33.4 → 9.9
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 -5.148407540792454 \cdot 10^{+110}:\\ \;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\ \mathbf{elif}\;b \le 2.326372645943808 \cdot 10^{-74}:\\ \;\;\;\;\frac{\frac{1}{a} \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - \frac{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 -5.148407540792454 \cdot 10^{+110}:\\
\;\;\;\;\frac{\left(\frac{c}{b} - \frac{b}{a}\right) \cdot 2}{2}\\

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

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

\end{array}
double f(double a, double b, double c) {
        double r6264958 = b;
        double r6264959 = -r6264958;
        double r6264960 = r6264958 * r6264958;
        double r6264961 = 4.0;
        double r6264962 = a;
        double r6264963 = r6264961 * r6264962;
        double r6264964 = c;
        double r6264965 = r6264963 * r6264964;
        double r6264966 = r6264960 - r6264965;
        double r6264967 = sqrt(r6264966);
        double r6264968 = r6264959 + r6264967;
        double r6264969 = 2.0;
        double r6264970 = r6264969 * r6264962;
        double r6264971 = r6264968 / r6264970;
        return r6264971;
}

double f(double a, double b, double c) {
        double r6264972 = b;
        double r6264973 = -5.148407540792454e+110;
        bool r6264974 = r6264972 <= r6264973;
        double r6264975 = c;
        double r6264976 = r6264975 / r6264972;
        double r6264977 = a;
        double r6264978 = r6264972 / r6264977;
        double r6264979 = r6264976 - r6264978;
        double r6264980 = 2.0;
        double r6264981 = r6264979 * r6264980;
        double r6264982 = r6264981 / r6264980;
        double r6264983 = 2.326372645943808e-74;
        bool r6264984 = r6264972 <= r6264983;
        double r6264985 = 1.0;
        double r6264986 = r6264985 / r6264977;
        double r6264987 = r6264972 * r6264972;
        double r6264988 = 4.0;
        double r6264989 = r6264977 * r6264975;
        double r6264990 = r6264988 * r6264989;
        double r6264991 = r6264987 - r6264990;
        double r6264992 = sqrt(r6264991);
        double r6264993 = r6264986 * r6264992;
        double r6264994 = r6264993 - r6264978;
        double r6264995 = r6264994 / r6264980;
        double r6264996 = -2.0;
        double r6264997 = r6264996 * r6264976;
        double r6264998 = r6264997 / r6264980;
        double r6264999 = r6264984 ? r6264995 : r6264998;
        double r6265000 = r6264974 ? r6264982 : r6264999;
        return r6265000;
}

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.4
Target20.3
Herbie9.9
\[\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 < -5.148407540792454e+110

    1. Initial program 46.9

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

      \[\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-sub46.9

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}}}{2}\]
    12. Simplified3.6

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

    if -5.148407540792454e+110 < b < 2.326372645943808e-74

    1. Initial program 12.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified12.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-sub12.7

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

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

    if 2.326372645943808e-74 < 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. Simplified52.5

      \[\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-sub53.2

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

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

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

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

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

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

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

Reproduce

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