Average Error: 33.9 → 9.7
Time: 12.6s
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 -1.8342337024011525 \cdot 10^{+138}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 2.900768719258459 \cdot 10^{-65}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\\ \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 -1.8342337024011525 \cdot 10^{+138}:\\
\;\;\;\;-\frac{b}{a}\\

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

\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 -1.8342337024011525e+138)
   (- (/ b a))
   (if (<= b 2.900768719258459e-65)
     (/ 1.0 (/ (* a 2.0) (- (sqrt (- (* b b) (* 4.0 (* a c)))) b)))
     (- (/ 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 <= -1.8342337024011525e+138) {
		tmp = -(b / a);
	} else if (b <= 2.900768719258459e-65) {
		tmp = 1.0 / ((a * 2.0) / (sqrt((b * b) - (4.0 * (a * c))) - b));
	} 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.9
Target21.0
Herbie9.7
\[\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 < -1.83423370240115254e138

    1. Initial program 57.7

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

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

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

    if -1.83423370240115254e138 < b < 2.9007687192584592e-65

    1. Initial program 12.4

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

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

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

    if 2.9007687192584592e-65 < b

    1. Initial program 54.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.8342337024011525 \cdot 10^{+138}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 2.900768719258459 \cdot 10^{-65}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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