Average Error: 34.1 → 10.6
Time: 6.5s
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.3551211150485621 \cdot 10^{-134}:\\ \;\;\;\;-0.5 \cdot \frac{1}{\mathsf{fma}\left(-0.5, \frac{a}{b}, \frac{-2}{\frac{-4 \cdot c}{b}}\right)}\\ \mathbf{elif}\;b \leq 1.5471415872418694 \cdot 10^{+99}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \left(\frac{b}{a} - \frac{c}{b}\right)\right)\\ \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.3551211150485621 \cdot 10^{-134}:\\
\;\;\;\;-0.5 \cdot \frac{1}{\mathsf{fma}\left(-0.5, \frac{a}{b}, \frac{-2}{\frac{-4 \cdot c}{b}}\right)}\\

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

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \left(\frac{b}{a} - \frac{c}{b}\right)\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
 (if (<= b -1.3551211150485621e-134)
   (* -0.5 (/ 1.0 (fma -0.5 (/ a b) (/ -2.0 (/ (* -4.0 c) b)))))
   (if (<= b 1.5471415872418694e+99)
     (* -0.5 (/ (+ b (sqrt (fma a (* -4.0 c) (* b b)))) a))
     (* -0.5 (* 2.0 (- (/ b a) (/ 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.3551211150485621e-134) {
		tmp = -0.5 * (1.0 / fma(-0.5, (a / b), (-2.0 / ((-4.0 * c) / b))));
	} else if (b <= 1.5471415872418694e+99) {
		tmp = -0.5 * ((b + sqrt(fma(a, (-4.0 * c), (b * b)))) / a);
	} else {
		tmp = -0.5 * (2.0 * ((b / a) - (c / b)));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.1
Target21.4
Herbie10.6
\[\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 < -1.3551211150485621e-134

    1. Initial program 51.0

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

      \[\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_binary6450.9

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

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

      \[\leadsto -0.5 \cdot \frac{1}{\color{blue}{-\left(2 \cdot \frac{a \cdot b}{{\left(\sqrt{-4 \cdot \left(c \cdot a\right)}\right)}^{2}} + 0.5 \cdot \frac{a}{b}\right)}} \]
    6. Simplified12.7

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

    if -1.3551211150485621e-134 < b < 1.5471415872418694e99

    1. Initial program 11.2

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

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

    if 1.5471415872418694e99 < b

    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.7

      \[\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 3.3

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

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

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

Reproduce

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