Average Error: 34.2 → 6.5
Time: 6.0s
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 -6.97667166683124 \cdot 10^{+151}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.3856076934378627 \cdot 10^{-242}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 8.912861377839782 \cdot 10^{+134}:\\ \;\;\;\;-2 \cdot \frac{c}{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 -6.97667166683124 \cdot 10^{+151}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\mathbf{elif}\;b \leq 8.912861377839782 \cdot 10^{+134}:\\
\;\;\;\;-2 \cdot \frac{c}{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 -6.97667166683124e+151)
   (- (/ c b) (/ b a))
   (if (<= b -3.3856076934378627e-242)
     (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
     (if (<= b 8.912861377839782e+134)
       (* -2.0 (/ c (+ 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 <= -6.97667166683124e+151) {
		tmp = (c / b) - (b / a);
	} else if (b <= -3.3856076934378627e-242) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) - b) / (a * 2.0);
	} else if (b <= 8.912861377839782e+134) {
		tmp = -2.0 * (c / (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 < -6.97667166683124e151

    1. Initial program 62.7

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

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

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

    if -6.97667166683124e151 < b < -3.3856076934378627e-242

    1. Initial program 8.3

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

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

    if -3.3856076934378627e-242 < b < 8.91286137783978178e134

    1. Initial program 31.7

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

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

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

      \[\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 *-un-lft-identity_binary64_280615.8

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

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

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

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

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

    if 8.91286137783978178e134 < b

    1. Initial program 61.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.97667166683124 \cdot 10^{+151}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -3.3856076934378627 \cdot 10^{-242}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 8.912861377839782 \cdot 10^{+134}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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