Average Error: 34.5 → 6.8
Time: 6.6s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.3014879836557515 \cdot 10^{+97}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.8145284637786566 \cdot 10^{-293}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2}}}\\ \mathbf{elif}\;b \leq 6.972667102848289 \cdot 10^{+99}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\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 \leq -1.3014879836557515 \cdot 10^{+97}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -1.8145284637786566 \cdot 10^{-293}:\\
\;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2}}}\\

\mathbf{elif}\;b \leq 6.972667102848289 \cdot 10^{+99}:\\
\;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\

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

\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.3014879836557515e+97)
   (- (/ c b) (/ b a))
   (if (<= b -1.8145284637786566e-293)
     (/ 1.0 (/ a (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) 2.0)))
     (if (<= b 6.972667102848289e+99)
       (/ (* c -2.0) (+ b (sqrt (- (* b b) (* c (* a 4.0))))))
       (- (/ c b))))))
double code(double a, double b, double c) {
	return (-b + sqrt((b * b) - ((4.0 * a) * c))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.3014879836557515e+97) {
		tmp = (c / b) - (b / a);
	} else if (b <= -1.8145284637786566e-293) {
		tmp = 1.0 / (a / ((sqrt((b * b) - (c * (a * 4.0))) - b) / 2.0));
	} else if (b <= 6.972667102848289e+99) {
		tmp = (c * -2.0) / (b + sqrt((b * b) - (c * (a * 4.0))));
	} else {
		tmp = -(c / b);
	}
	return tmp;
}

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

Derivation

  1. Split input into 4 regimes
  2. if b < -1.3014879836557515e97

    1. Initial program 46.0

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

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

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

    if -1.3014879836557515e97 < b < -1.81452846377865664e-293

    1. Initial program 9.6

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

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

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

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

    if -1.81452846377865664e-293 < b < 6.97266710284828931e99

    1. Initial program 31.6

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

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

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

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

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

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

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

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

      \[\leadsto \left(c \cdot -4\right) \cdot \color{blue}{\frac{0.5}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    12. Using strategy rm
    13. Applied associate-*r/_binary64_3658.8

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

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

    if 6.97266710284828931e99 < b

    1. Initial program 59.4

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3014879836557515 \cdot 10^{+97}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -1.8145284637786566 \cdot 10^{-293}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2}}}\\ \mathbf{elif}\;b \leq 6.972667102848289 \cdot 10^{+99}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020292 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))