Average Error: 33.5 → 6.5
Time: 9.7s
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 -2.471917755888911 \cdot 10^{+112}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -4.1182616308745104 \cdot 10^{-283}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.768600211528924 \cdot 10^{+70}:\\ \;\;\;\;\frac{1}{\left(b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}\right) \cdot \frac{-1}{\frac{c \cdot 4}{2}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \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 -2.471917755888911 \cdot 10^{+112}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -4.1182616308745104 \cdot 10^{-283}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 1.768600211528924 \cdot 10^{+70}:\\
\;\;\;\;\frac{1}{\left(b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}\right) \cdot \frac{-1}{\frac{c \cdot 4}{2}}}\\

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


\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 -2.471917755888911e+112)
   (- (/ c b) (/ b a))
   (if (<= b -4.1182616308745104e-283)
     (/ (- (sqrt (fma (* c a) -4.0 (* b b))) b) (* a 2.0))
     (if (<= b 1.768600211528924e+70)
       (/
        1.0
        (*
         (+ b (sqrt (- (* b b) (* (* c a) 4.0))))
         (/ -1.0 (/ (* c 4.0) 2.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 <= -2.471917755888911e+112) {
		tmp = (c / b) - (b / a);
	} else if (b <= -4.1182616308745104e-283) {
		tmp = (sqrt(fma((c * a), -4.0, (b * b))) - b) / (a * 2.0);
	} else if (b <= 1.768600211528924e+70) {
		tmp = 1.0 / ((b + sqrt((b * b) - ((c * a) * 4.0))) * (-1.0 / ((c * 4.0) / 2.0)));
	} else {
		tmp = -(c / b);
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.3
Herbie6.5
\[\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 < -2.471917755888911e112

    1. Initial program 50.3

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

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

    if -2.471917755888911e112 < b < -4.1182616308745104e-283

    1. Initial program 7.9

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

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

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

    if -4.1182616308745104e-283 < b < 1.7686002115289241e70

    1. Initial program 28.9

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}} \]
    3. Applied flip-+_binary6429.0

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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)}}}}} \]
    4. Applied associate-/r/_binary6429.1

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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)}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}} \]
    5. Simplified15.8

      \[\leadsto \frac{1}{\color{blue}{\frac{a \cdot 2}{4 \cdot \left(c \cdot a\right)}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)} \]
    6. Applied clear-num_binary6415.8

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

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

    if 1.7686002115289241e70 < b

    1. Initial program 58.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.471917755888911 \cdot 10^{+112}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -4.1182616308745104 \cdot 10^{-283}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.768600211528924 \cdot 10^{+70}:\\ \;\;\;\;\frac{1}{\left(b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}\right) \cdot \frac{-1}{\frac{c \cdot 4}{2}}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Reproduce

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