Average Error: 33.8 → 6.9
Time: 8.3s
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 -9.78240408384728 \cdot 10^{+119}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 2.0018226176283294 \cdot 10^{-297}:\\ \;\;\;\;-0.5 \cdot \frac{1}{\frac{\frac{1}{c}}{4} \cdot \left(b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}\\ \mathbf{elif}\;b \leq 2.79442743178515 \cdot 10^{+92}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{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 -9.78240408384728 \cdot 10^{+119}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

\mathbf{elif}\;b \leq 2.79442743178515 \cdot 10^{+92}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{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 -9.78240408384728e+119)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b 2.0018226176283294e-297)
     (*
      -0.5
      (/ 1.0 (* (/ (/ 1.0 c) 4.0) (- b (sqrt (- (* b b) (* 4.0 (* c a))))))))
     (if (<= b 2.79442743178515e+92)
       (* -0.5 (/ (+ b (sqrt (+ (* b b) (* c (* a -4.0))))) 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 <= -9.78240408384728e+119) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= 2.0018226176283294e-297) {
		tmp = -0.5 * (1.0 / (((1.0 / c) / 4.0) * (b - sqrt((b * b) - (4.0 * (c * a))))));
	} else if (b <= 2.79442743178515e+92) {
		tmp = -0.5 * ((b + sqrt((b * b) + (c * (a * -4.0)))) / 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

Original33.8
Target20.9
Herbie6.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 < -9.7824040838472795e119

    1. Initial program 60.8

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

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

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

    if -9.7824040838472795e119 < b < 2.001822617628329e-297

    1. Initial program 32.2

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

      \[\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 clear-num_binary6432.2

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

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

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

      \[\leadsto -0.5 \cdot \frac{1}{\frac{a}{\frac{\color{blue}{4 \cdot \left(c \cdot a\right)}}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}}} \]
    9. Using strategy rm
    10. Applied associate-/r/_binary6415.2

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

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

    if 2.001822617628329e-297 < b < 2.7944274317851502e92

    1. Initial program 8.9

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

      \[\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_binary649.0

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

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

    if 2.7944274317851502e92 < b

    1. Initial program 45.6

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

      \[\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.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 4 regimes into one program.
  4. Final simplification6.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -9.78240408384728 \cdot 10^{+119}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 2.0018226176283294 \cdot 10^{-297}:\\ \;\;\;\;-0.5 \cdot \frac{1}{\frac{\frac{1}{c}}{4} \cdot \left(b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right)}\\ \mathbf{elif}\;b \leq 2.79442743178515 \cdot 10^{+92}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b \cdot 2}{a}\\ \end{array} \]

Reproduce

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