Average Error: 34.1 → 10.0
Time: 6.9s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{b}{a \cdot 2}\\ \mathbf{if}\;b \leq -9.578396010459488 \cdot 10^{+102}:\\ \;\;\;\;\left(\frac{c}{b} + \frac{b}{a} \cdot -0.5\right) - t_0\\ \mathbf{elif}\;b \leq 3.2185716802555982 \cdot 10^{-80}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2} - t_0\\ \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}
t_0 := \frac{b}{a \cdot 2}\\
\mathbf{if}\;b \leq -9.578396010459488 \cdot 10^{+102}:\\
\;\;\;\;\left(\frac{c}{b} + \frac{b}{a} \cdot -0.5\right) - t_0\\

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

\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
 (let* ((t_0 (/ b (* a 2.0))))
   (if (<= b -9.578396010459488e+102)
     (- (+ (/ c b) (* (/ b a) -0.5)) t_0)
     (if (<= b 3.2185716802555982e-80)
       (- (/ (sqrt (- (* b b) (* 4.0 (* c a)))) (* a 2.0)) t_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 t_0 = b / (a * 2.0);
	double tmp;
	if (b <= -9.578396010459488e+102) {
		tmp = ((c / b) + ((b / a) * -0.5)) - t_0;
	} else if (b <= 3.2185716802555982e-80) {
		tmp = (sqrt((b * b) - (4.0 * (c * a))) / (a * 2.0)) - t_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

Target

Original34.1
Target20.9
Herbie10.0
\[\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 3 regimes
  2. if b < -9.5783960104594883e102

    1. Initial program 47.6

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

      \[\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-sub_binary6447.6

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

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

      \[\leadsto \color{blue}{\left(\frac{c}{b} - 0.5 \cdot \frac{b}{a}\right)} - \frac{b}{a \cdot 2} \]
    7. Simplified3.6

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

    if -9.5783960104594883e102 < b < 3.21857168025559822e-80

    1. Initial program 12.5

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

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

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

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

    if 3.21857168025559822e-80 < b

    1. Initial program 52.6

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.578396010459488 \cdot 10^{+102}:\\ \;\;\;\;\left(\frac{c}{b} + \frac{b}{a} \cdot -0.5\right) - \frac{b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 3.2185716802555982 \cdot 10^{-80}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2} - \frac{b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Reproduce

herbie shell --seed 2021207 
(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)))