Average Error: 33.7 → 9.1
Time: 8.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 -3.061643530149749 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.4654087246385048 \cdot 10^{-119}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.480906013685845 \cdot 10^{+76}:\\ \;\;\;\;\left(\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt{0.5}\right) \cdot \frac{\sqrt{0.5}}{a}\\ \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 -3.061643530149749 \cdot 10^{+106}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\mathbf{elif}\;b \leq 3.480906013685845 \cdot 10^{+76}:\\
\;\;\;\;\left(\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt{0.5}\right) \cdot \frac{\sqrt{0.5}}{a}\\

\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 -3.061643530149749e+106)
   (- (/ c b) (/ b a))
   (if (<= b 2.4654087246385048e-119)
     (- (/ (sqrt (- (* b b) (* c (* a 4.0)))) (* a 2.0)) (/ b (* a 2.0)))
     (if (<= b 3.480906013685845e+76)
       (*
        (*
         (/ (* c (* a -4.0)) (+ b (sqrt (- (* b b) (* 4.0 (* c a))))))
         (sqrt 0.5))
        (/ (sqrt 0.5) a))
       (- (/ 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 <= -3.061643530149749e+106) {
		tmp = (c / b) - (b / a);
	} else if (b <= 2.4654087246385048e-119) {
		tmp = (sqrt((b * b) - (c * (a * 4.0))) / (a * 2.0)) - (b / (a * 2.0));
	} else if (b <= 3.480906013685845e+76) {
		tmp = (((c * (a * -4.0)) / (b + sqrt((b * b) - (4.0 * (c * a))))) * sqrt(0.5)) * (sqrt(0.5) / a);
	} 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 < -3.061643530149749e106

    1. Initial program 48.7

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

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

    if -3.061643530149749e106 < b < 2.4654087246385048e-119

    1. Initial program 11.3

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

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

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

    if 2.4654087246385048e-119 < b < 3.4809060136858447e76

    1. Initial program 40.5

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

      \[\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 div-inv_binary6440.5

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

      \[\leadsto \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \color{blue}{\frac{0.5}{a}} \]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary6440.5

      \[\leadsto \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{0.5}{\color{blue}{1 \cdot a}} \]
    8. Applied add-sqr-sqrt_binary6440.8

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

      \[\leadsto \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \color{blue}{\left(\frac{\sqrt{0.5}}{1} \cdot \frac{\sqrt{0.5}}{a}\right)} \]
    10. Applied associate-*r*_binary6440.7

      \[\leadsto \color{blue}{\left(\left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b\right) \cdot \frac{\sqrt{0.5}}{1}\right) \cdot \frac{\sqrt{0.5}}{a}} \]
    11. Simplified40.7

      \[\leadsto \color{blue}{\left(\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b\right) \cdot \sqrt{0.5}\right)} \cdot \frac{\sqrt{0.5}}{a} \]
    12. Using strategy rm
    13. Applied flip--_binary6440.6

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

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

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

    if 3.4809060136858447e76 < b

    1. Initial program 57.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.061643530149749 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 2.4654087246385048 \cdot 10^{-119}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.480906013685845 \cdot 10^{+76}:\\ \;\;\;\;\left(\frac{c \cdot \left(a \cdot -4\right)}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}} \cdot \sqrt{0.5}\right) \cdot \frac{\sqrt{0.5}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Reproduce

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