Average Error: 33.5 → 6.6
Time: 6.1s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \leq -3.7496976833374853 \cdot 10^{+80}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq -1.705747609312796 \cdot 10^{-292}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}}{2}\\ \mathbf{elif}\;b \leq 2.2974215110058318 \cdot 10^{+148}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -3.7496976833374853 \cdot 10^{+80}:\\
\;\;\;\;\frac{-b}{a}\\

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

\mathbf{elif}\;b \leq 2.2974215110058318 \cdot 10^{+148}:\\
\;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\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 -3.7496976833374853e+80)
   (/ (- b) a)
   (if (<= b -1.705747609312796e-292)
     (/ (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) a) 2.0)
     (if (<= b 2.2974215110058318e+148)
       (/ (* c -2.0) (+ b (sqrt (- (* b b) (* 4.0 (* a c))))))
       (- (/ 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.7496976833374853e+80) {
		tmp = -b / a;
	} else if (b <= -1.705747609312796e-292) {
		tmp = ((sqrt((b * b) - (4.0 * (a * c))) - b) / a) / 2.0;
	} else if (b <= 2.2974215110058318e+148) {
		tmp = (c * -2.0) / (b + sqrt((b * b) - (4.0 * (a * c))));
	} 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

Target

Original33.5
Target20.9
Herbie6.6
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -3.7496976833374853e80

    1. Initial program 42.9

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified4.9

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

    if -3.7496976833374853e80 < b < -1.70574760931279604e-292

    1. Initial program 8.9

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

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

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

    if -1.70574760931279604e-292 < b < 2.2974215110058318e148

    1. Initial program 32.9

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(b \cdot b - \left(4 \cdot \left(a \cdot c\right) + b \cdot b\right)\right) \cdot \frac{0.5}{a}}}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} + b}\]
    10. Taylor expanded around 0 8.2

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

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

    if 2.2974215110058318e148 < b

    1. Initial program 63.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.7496976833374853 \cdot 10^{+80}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq -1.705747609312796 \cdot 10^{-292}:\\ \;\;\;\;\frac{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a}}{2}\\ \mathbf{elif}\;b \leq 2.2974215110058318 \cdot 10^{+148}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2021174 
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :precision binary64

  :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)))