Average Error: 34.3 → 12.3
Time: 13.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 -4.848123900391362 \cdot 10^{-140}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 9.052048006936924 \cdot 10^{+27}:\\ \;\;\;\;\frac{-\left(b + \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -4\right)}, b\right)\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \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 -4.848123900391362 \cdot 10^{-140}:\\
\;\;\;\;-\frac{c}{b}\\

\mathbf{elif}\;b \leq 9.052048006936924 \cdot 10^{+27}:\\
\;\;\;\;\frac{-\left(b + \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -4\right)}, b\right)\right)}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{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 -4.848123900391362e-140)
   (- (/ c b))
   (if (<= b 9.052048006936924e+27)
     (/ (- (+ b (hypot (sqrt (* c (* a -4.0))) b))) (* a 2.0))
     (- (/ c b) (/ b 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 <= -4.848123900391362e-140) {
		tmp = -(c / b);
	} else if (b <= 9.052048006936924e+27) {
		tmp = -(b + hypot(sqrt(c * (a * -4.0)), b)) / (a * 2.0);
	} else {
		tmp = (c / b) - (b / 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

Target

Original34.3
Target21.0
Herbie12.3
\[\begin{array}{l} \mathbf{if}\;b < 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 < -4.84812390039136203e-140

    1. Initial program 50.1

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Taylor expanded in b around -inf 12.0

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

    if -4.84812390039136203e-140 < b < 9.05204800693692385e27

    1. Initial program 12.9

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

      \[\leadsto \frac{\color{blue}{\left(0 - b\right)} - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    3. Applied associate--l-_binary6412.9

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

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

    if 9.05204800693692385e27 < b

    1. Initial program 35.8

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Taylor expanded in b around inf 6.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -4.848123900391362 \cdot 10^{-140}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq 9.052048006936924 \cdot 10^{+27}:\\ \;\;\;\;\frac{-\left(b + \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -4\right)}, b\right)\right)}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array} \]

Reproduce

herbie shell --seed 2021275 
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))