Average Error: 34.3 → 8.0
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} \mathbf{if}\;b \leq -1.3199871431635179 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := c \cdot \left(a \cdot -4\right)\\ \mathbf{if}\;b \leq -2.07694009677386 \cdot 10^{-291}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.718007789643402 \cdot 10^{-35}:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{t_0}\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\\ \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.3199871431635179 \cdot 10^{+153}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := c \cdot \left(a \cdot -4\right)\\
\mathbf{if}\;b \leq -2.07694009677386 \cdot 10^{-291}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 5.718007789643402 \cdot 10^{-35}:\\
\;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{t_0}\right)}\\

\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\


\end{array}\\


\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.3199871431635179e+153)
   (- (/ c b) (/ b a))
   (let* ((t_0 (* c (* a -4.0))))
     (if (<= b -2.07694009677386e-291)
       (/ (- (sqrt (fma b b t_0)) b) (* a 2.0))
       (if (<= b 5.718007789643402e-35)
         (* 2.0 (/ c (- (- b) (hypot b (sqrt t_0)))))
         (- (/ 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.3199871431635179e+153) {
		tmp = (c / b) - (b / a);
	} else {
		double t_0 = c * (a * -4.0);
		double tmp_1;
		if (b <= -2.07694009677386e-291) {
			tmp_1 = (sqrt(fma(b, b, t_0)) - b) / (a * 2.0);
		} else if (b <= 5.718007789643402e-35) {
			tmp_1 = 2.0 * (c / (-b - hypot(b, sqrt(t_0))));
		} else {
			tmp_1 = -(c / b);
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.3
Target21.0
Herbie8.0
\[\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 4 regimes
  2. if b < -1.3199871431635179e153

    1. Initial program 63.7

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

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

    if -1.3199871431635179e153 < b < -2.0769400967738599e-291

    1. Initial program 8.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Using strategy rm
    3. Applied fma-neg_binary648.8

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

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

    if -2.0769400967738599e-291 < b < 5.71800778964340195e-35

    1. Initial program 22.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Using strategy rm
    3. Applied flip-+_binary6422.6

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

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

      \[\leadsto \frac{\frac{4 \cdot \left(c \cdot a\right)}{\color{blue}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}}{2 \cdot a} \]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary6416.4

      \[\leadsto \frac{\frac{4 \cdot \left(c \cdot a\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}\right)}}}{2 \cdot a} \]
    8. Applied times-frac_binary6416.4

      \[\leadsto \frac{\color{blue}{\frac{4}{1} \cdot \frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}}{2 \cdot a} \]
    9. Applied times-frac_binary6416.4

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

      \[\leadsto \color{blue}{2} \cdot \frac{\frac{c \cdot a}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}}{a} \]
    11. Simplified12.6

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

    if 5.71800778964340195e-35 < b

    1. Initial program 54.9

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    3. Simplified6.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3199871431635179 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -2.07694009677386 \cdot 10^{-291}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 5.718007789643402 \cdot 10^{-35}:\\ \;\;\;\;2 \cdot \frac{c}{\left(-b\right) - \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Reproduce

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