Average Error: 30.6 → 9.4
Time: 9.6s
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 := 2 \cdot \frac{c}{b}\\ \mathbf{if}\;b \leq -6.264481518257526 \cdot 10^{-16}:\\ \;\;\;\;-0.5 \cdot t_0\\ \mathbf{elif}\;b \leq 3.394384461911073 \cdot 10^{+120}:\\ \;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a} - t_0\right)\\ \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 := 2 \cdot \frac{c}{b}\\
\mathbf{if}\;b \leq -6.264481518257526 \cdot 10^{-16}:\\
\;\;\;\;-0.5 \cdot t_0\\

\mathbf{elif}\;b \leq 3.394384461911073 \cdot 10^{+120}:\\
\;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a} - t_0\right)\\


\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 (* 2.0 (/ c b))))
   (if (<= b -6.264481518257526e-16)
     (* -0.5 t_0)
     (if (<= b 3.394384461911073e+120)
       (* -0.5 (/ 1.0 (/ a (+ b (sqrt (fma a (* c -4.0) (* b b)))))))
       (* -0.5 (- (* 2.0 (/ b a)) t_0))))))
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 = 2.0 * (c / b);
	double tmp;
	if (b <= -6.264481518257526e-16) {
		tmp = -0.5 * t_0;
	} else if (b <= 3.394384461911073e+120) {
		tmp = -0.5 * (1.0 / (a / (b + sqrt(fma(a, (c * -4.0), (b * b))))));
	} else {
		tmp = -0.5 * ((2.0 * (b / a)) - t_0);
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original30.6
Target19.0
Herbie9.4
\[\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 < -6.2644815182575259e-16

    1. Initial program 54.4

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}} \]
    3. Taylor expanded in b around -inf 6.7

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

    if -6.2644815182575259e-16 < b < 3.3943844619110728e120

    1. Initial program 14.0

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}} \]
    3. Applied clear-num_binary6414.1

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

    if 3.3943844619110728e120 < b

    1. Initial program 32.5

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}} \]
    3. Taylor expanded in b around inf 2.1

      \[\leadsto -0.5 \cdot \color{blue}{\left(2 \cdot \frac{b}{a} - 2 \cdot \frac{c}{b}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.264481518257526 \cdot 10^{-16}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 3.394384461911073 \cdot 10^{+120}:\\ \;\;\;\;-0.5 \cdot \frac{1}{\frac{a}{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{b}{a} - 2 \cdot \frac{c}{b}\right)\\ \end{array} \]

Reproduce

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