Average Error: 33.7 → 6.3
Time: 17.6s
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.9144452663620863 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.7940081798688815 \cdot 10^{-180}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.38510479181365363 \cdot 10^{104}:\\ \;\;\;\;\frac{\frac{4 \cdot c}{2}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \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 -1.9144452663620863 \cdot 10^{138}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

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

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

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

\end{array}
double f(double a, double b, double c) {
        double r98950 = b;
        double r98951 = -r98950;
        double r98952 = r98950 * r98950;
        double r98953 = 4.0;
        double r98954 = a;
        double r98955 = r98953 * r98954;
        double r98956 = c;
        double r98957 = r98955 * r98956;
        double r98958 = r98952 - r98957;
        double r98959 = sqrt(r98958);
        double r98960 = r98951 + r98959;
        double r98961 = 2.0;
        double r98962 = r98961 * r98954;
        double r98963 = r98960 / r98962;
        return r98963;
}

double f(double a, double b, double c) {
        double r98964 = b;
        double r98965 = -1.9144452663620863e+138;
        bool r98966 = r98964 <= r98965;
        double r98967 = 1.0;
        double r98968 = c;
        double r98969 = r98968 / r98964;
        double r98970 = a;
        double r98971 = r98964 / r98970;
        double r98972 = r98969 - r98971;
        double r98973 = r98967 * r98972;
        double r98974 = -3.7940081798688815e-180;
        bool r98975 = r98964 <= r98974;
        double r98976 = -r98964;
        double r98977 = r98964 * r98964;
        double r98978 = 4.0;
        double r98979 = r98978 * r98970;
        double r98980 = r98979 * r98968;
        double r98981 = r98977 - r98980;
        double r98982 = sqrt(r98981);
        double r98983 = r98976 + r98982;
        double r98984 = 1.0;
        double r98985 = 2.0;
        double r98986 = r98985 * r98970;
        double r98987 = r98984 / r98986;
        double r98988 = r98983 * r98987;
        double r98989 = 3.3851047918136536e+104;
        bool r98990 = r98964 <= r98989;
        double r98991 = r98978 * r98968;
        double r98992 = r98991 / r98985;
        double r98993 = r98976 - r98982;
        double r98994 = r98992 / r98993;
        double r98995 = -1.0;
        double r98996 = r98995 * r98969;
        double r98997 = r98990 ? r98994 : r98996;
        double r98998 = r98975 ? r98988 : r98997;
        double r98999 = r98966 ? r98973 : r98998;
        return r98999;
}

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.7
Target20.8
Herbie6.3
\[\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 < -1.9144452663620863e+138

    1. Initial program 58.1

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

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

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

    if -1.9144452663620863e+138 < b < -3.7940081798688815e-180

    1. Initial program 6.2

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

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

    if -3.7940081798688815e-180 < b < 3.3851047918136536e+104

    1. Initial program 28.2

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

      \[\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. Simplified15.4

      \[\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}\]
    5. Using strategy rm
    6. Applied div-inv15.4

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

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

      \[\leadsto \frac{0 + \left(4 \cdot a\right) \cdot c}{\color{blue}{\left(a \cdot 2\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    9. Using strategy rm
    10. Applied associate-/r*14.7

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

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

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

    if 3.3851047918136536e+104 < b

    1. Initial program 60.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.9144452663620863 \cdot 10^{138}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -3.7940081798688815 \cdot 10^{-180}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;b \le 3.38510479181365363 \cdot 10^{104}:\\ \;\;\;\;\frac{\frac{4 \cdot c}{2}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019198 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r1)"

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

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