Average Error: 33.8 → 8.9
Time: 4.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 -7912379577645.802:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -7.525896497608905 \cdot 10^{-142}:\\ \;\;\;\;-0.5 \cdot \frac{\frac{4 \cdot \left(c \cdot a\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\ \mathbf{elif}\;b \leq 6.526889854778783 \cdot 10^{+49}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\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 -7912379577645.802:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

\mathbf{elif}\;b \leq 6.526889854778783 \cdot 10^{+49}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\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 -7912379577645.802)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b -7.525896497608905e-142)
     (*
      -0.5
      (/ (/ (* 4.0 (* c a)) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))) a))
     (if (<= b 6.526889854778783e+49)
       (* -0.5 (/ (+ b (sqrt (+ (* b b) (* a (* c -4.0))))) 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 <= -7912379577645.802) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= -7.525896497608905e-142) {
		tmp = -0.5 * (((4.0 * (c * a)) / (b - sqrt((b * b) - (4.0 * (c * a))))) / a);
	} else if (b <= 6.526889854778783e+49) {
		tmp = -0.5 * ((b + sqrt((b * b) + (a * (c * -4.0)))) / 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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.8
Target20.9
Herbie8.9
\[\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 4 regimes
  2. if b < -7912379577645.80176

    1. Initial program 56.3

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Taylor expanded around -inf 4.9

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

    if -7912379577645.80176 < b < -7.5258964976089047e-142

    1. Initial program 34.5

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Using strategy rm
    4. Applied flip-+_binary6434.5

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

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

    if -7.5258964976089047e-142 < b < 6.5268898547787833e49

    1. Initial program 11.6

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Using strategy rm
    4. Applied sub-neg_binary6411.6

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

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

    if 6.5268898547787833e49 < b

    1. Initial program 38.7

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a}}\]
    3. Taylor expanded around inf 5.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -7912379577645.802:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq -7.525896497608905 \cdot 10^{-142}:\\ \;\;\;\;-0.5 \cdot \frac{\frac{4 \cdot \left(c \cdot a\right)}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}{a}\\ \mathbf{elif}\;b \leq 6.526889854778783 \cdot 10^{+49}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\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 2020219 
(FPCore (a b c)
  :name "quadm (p42, negative)"
  :precision binary64
  :herbie-expected #f

  :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)))