Average Error: 34.2 → 13.4
Time: 9.4s
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.330798537410596 \cdot 10^{+154}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 9.437780463281094 \cdot 10^{-94}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 7.001585617859764 \cdot 10^{+131}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a \cdot c}{b} \cdot -2}{2 \cdot a}\\ \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.330798537410596 \cdot 10^{+154}:\\
\;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\

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

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

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

\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.330798537410596e+154)
   (/ (* 2.0 (- (/ (* a c) b) b)) (* 2.0 a))
   (if (<= b 9.437780463281094e-94)
     (/ (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (* 2.0 a))
     (if (<= b 7.001585617859764e+131)
       (/
        (/ (* a (* c -4.0)) (+ b (sqrt (- (* b b) (* c (* a 4.0))))))
        (* 2.0 a))
       (/ (* (/ (* a c) b) -2.0) (* 2.0 a))))))
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.330798537410596e+154) {
		tmp = (2.0 * (((a * c) / b) - b)) / (2.0 * a);
	} else if (b <= 9.437780463281094e-94) {
		tmp = (sqrt((b * b) + (a * (c * -4.0))) - b) / (2.0 * a);
	} else if (b <= 7.001585617859764e+131) {
		tmp = ((a * (c * -4.0)) / (b + sqrt((b * b) - (c * (a * 4.0))))) / (2.0 * a);
	} else {
		tmp = (((a * c) / b) * -2.0) / (2.0 * a);
	}
	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.33079853741059594e154

    1. Initial program 64.0

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}{a \cdot 2}\]
    4. Simplified11.5

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

    if -1.33079853741059594e154 < b < 9.4377804632810941e-94

    1. Initial program 11.8

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

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

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

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

    if 9.4377804632810941e-94 < b < 7.0015856178597638e131

    1. Initial program 42.4

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

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

      \[\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.3

      \[\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.3

      \[\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}\]

    if 7.0015856178597638e131 < b

    1. Initial program 61.9

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.330798537410596 \cdot 10^{+154}:\\ \;\;\;\;\frac{2 \cdot \left(\frac{a \cdot c}{b} - b\right)}{2 \cdot a}\\ \mathbf{elif}\;b \leq 9.437780463281094 \cdot 10^{-94}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 7.001585617859764 \cdot 10^{+131}:\\ \;\;\;\;\frac{\frac{a \cdot \left(c \cdot -4\right)}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a \cdot c}{b} \cdot -2}{2 \cdot a}\\ \end{array}\]

Reproduce

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