Average Error: 34.3 → 10.2
Time: 8.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.5636004990570266 \cdot 10^{-52}:\\ \;\;\;\;-0.5 \cdot \left(-0.5 \cdot \frac{c \cdot -4}{b}\right)\\ \mathbf{elif}\;b \leq 8.470534450340484 \cdot 10^{+97}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b \cdot 2}{a}\\ \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.5636004990570266 \cdot 10^{-52}:\\
\;\;\;\;-0.5 \cdot \left(-0.5 \cdot \frac{c \cdot -4}{b}\right)\\

\mathbf{elif}\;b \leq 8.470534450340484 \cdot 10^{+97}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b}}{a}\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b \cdot 2}{a}\\


\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.5636004990570266e-52)
   (* -0.5 (* -0.5 (/ (* c -4.0) b)))
   (if (<= b 8.470534450340484e+97)
     (* -0.5 (/ (+ b (sqrt (+ (* c (* -4.0 a)) (* b b)))) a))
     (* -0.5 (/ (* b 2.0) 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 <= -2.5636004990570266e-52) {
		tmp = -0.5 * (-0.5 * ((c * -4.0) / b));
	} else if (b <= 8.470534450340484e+97) {
		tmp = -0.5 * ((b + sqrt((c * (-4.0 * a)) + (b * b))) / a);
	} else {
		tmp = -0.5 * ((b * 2.0) / a);
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original34.3
Target21.0
Herbie10.2
\[\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 < -2.5636004990570266e-52

    1. Initial program 54.0

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

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

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

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

      \[\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}\right)} \]
    7. Simplified7.9

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

    if -2.5636004990570266e-52 < b < 8.47053445034048353e97

    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. Using strategy rm
    4. Applied fma-udef_binary6414.0

      \[\leadsto -0.5 \cdot \frac{b + \sqrt{\color{blue}{a \cdot \left(c \cdot -4\right) + b \cdot b}}}{a} \]
    5. Simplified14.0

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

    if 8.47053445034048353e97 < b

    1. Initial program 47.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a} \]
    2. Simplified47.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 around inf 4.4

      \[\leadsto -0.5 \cdot \frac{\color{blue}{2 \cdot b}}{a} \]
    4. Simplified4.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.5636004990570266 \cdot 10^{-52}:\\ \;\;\;\;-0.5 \cdot \left(-0.5 \cdot \frac{c \cdot -4}{b}\right)\\ \mathbf{elif}\;b \leq 8.470534450340484 \cdot 10^{+97}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(-4 \cdot a\right) + b \cdot b}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b \cdot 2}{a}\\ \end{array} \]

Reproduce

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