Average Error: 34.6 → 9.6
Time: 11.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.0628887340948368 \cdot 10^{-15}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -2.5936672057451206 \cdot 10^{-222}:\\ \;\;\;\;-0.5 \cdot \frac{\frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c \cdot a}}}{a}\\ \mathbf{elif}\;b \leq 5.559837845063527 \cdot 10^{+97}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{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 -1.0628887340948368 \cdot 10^{-15}:\\
\;\;\;\;-\frac{c}{b}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{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 -1.0628887340948368e-15)
   (- (/ c b))
   (if (<= b -2.5936672057451206e-222)
     (*
      -0.5
      (/ (/ 4.0 (/ (- b (sqrt (- (* b b) (* 4.0 (* c a))))) (* c a))) a))
     (if (<= b 5.559837845063527e+97)
       (* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) a))
       (- (/ c b) (/ 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 <= -1.0628887340948368e-15) {
		tmp = -(c / b);
	} else if (b <= -2.5936672057451206e-222) {
		tmp = -0.5 * ((4.0 / ((b - sqrt((b * b) - (4.0 * (c * a)))) / (c * a))) / a);
	} else if (b <= 5.559837845063527e+97) {
		tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / a);
	} else {
		tmp = (c / b) - (b / 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.6
Target21.3
Herbie9.6
\[\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 < -1.06288873409483677e-15

    1. Initial program 55.5

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

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

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

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

    if -1.06288873409483677e-15 < b < -2.59366720574512058e-222

    1. Initial program 29.3

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

      \[\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-+_binary64_73429.3

      \[\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. Simplified19.7

      \[\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}\]
    6. Using strategy rm
    7. Applied associate-/l*_binary64_70519.8

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

    if -2.59366720574512058e-222 < b < 5.5598378450635267e97

    1. Initial program 10.9

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

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

    if 5.5598378450635267e97 < b

    1. Initial program 47.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.0628887340948368 \cdot 10^{-15}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \leq -2.5936672057451206 \cdot 10^{-222}:\\ \;\;\;\;-0.5 \cdot \frac{\frac{4}{\frac{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{c \cdot a}}}{a}\\ \mathbf{elif}\;b \leq 5.559837845063527 \cdot 10^{+97}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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