Average Error: 33.7 → 10.0
Time: 8.4s
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 -9.982919774802431 \cdot 10^{-83}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 5.986017873353636 \cdot 10^{+110}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \mathsf{fma}\left(0.5, \frac{c \cdot -4}{b}, 2 \cdot \frac{b}{a}\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 -9.982919774802431 \cdot 10^{-83}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \mathsf{fma}\left(0.5, \frac{c \cdot -4}{b}, 2 \cdot \frac{b}{a}\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 -9.982919774802431e-83)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b 5.986017873353636e+110)
     (* -0.5 (/ (+ b (sqrt (fma a (* c -4.0) (* b b)))) a))
     (* -0.5 (fma 0.5 (/ (* c -4.0) b) (* 2.0 (/ 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 <= -9.982919774802431e-83) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= 5.986017873353636e+110) {
		tmp = -0.5 * ((b + sqrt(fma(a, (c * -4.0), (b * b)))) / a);
	} else {
		tmp = -0.5 * fma(0.5, ((c * -4.0) / b), (2.0 * (b / a)));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target20.6
Herbie10.0
\[\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 < -9.98291977480243128e-83

    1. Initial program 52.2

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

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

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

    if -9.98291977480243128e-83 < b < 5.98601787335363621e110

    1. Initial program 12.6

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

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

    if 5.98601787335363621e110 < b

    1. Initial program 49.4

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

      \[\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_binary6449.4

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

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

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

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

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

Reproduce

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