Average Error: 34.5 → 6.5
Time: 9.5s
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.6495164398004875 \cdot 10^{+103}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 9.402708844729834 \cdot 10^{-273}:\\ \;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \leq 2.675726436471294 \cdot 10^{+140}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b + 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 -2.6495164398004875 \cdot 10^{+103}:\\
\;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\

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

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

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + 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 -2.6495164398004875e+103)
   (* -0.5 (* 2.0 (/ c b)))
   (if (<= b 9.402708844729834e-273)
     (* -0.5 (/ (* c 4.0) (- b (sqrt (- (* b b) (* 4.0 (* c a)))))))
     (if (<= b 2.675726436471294e+140)
       (* -0.5 (/ (+ b (sqrt (- (* b b) (* 4.0 (* c a))))) a))
       (* -0.5 (/ (+ 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 <= -2.6495164398004875e+103) {
		tmp = -0.5 * (2.0 * (c / b));
	} else if (b <= 9.402708844729834e-273) {
		tmp = -0.5 * ((c * 4.0) / (b - sqrt((b * b) - (4.0 * (c * a)))));
	} else if (b <= 2.675726436471294e+140) {
		tmp = -0.5 * ((b + sqrt((b * b) - (4.0 * (c * a)))) / a);
	} else {
		tmp = -0.5 * ((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.5
Target21.2
Herbie6.5
\[\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 < -2.64951643980048754e103

    1. Initial program 59.4

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

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

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

    if -2.64951643980048754e103 < b < 9.4027088447298342e-273

    1. Initial program 32.0

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

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

      \[\leadsto -0.5 \cdot \left(\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)}}} \cdot \frac{1}{a}\right)\]
    7. Applied associate-*l/_binary64_70332.1

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

      \[\leadsto -0.5 \cdot \frac{\color{blue}{\frac{4 \cdot \left(a \cdot c\right)}{a}}}{b - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\]
    9. Taylor expanded around 0 8.9

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

    if 9.4027088447298342e-273 < b < 2.675726436471294e140

    1. Initial program 8.3

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

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

    if 2.675726436471294e140 < b

    1. Initial program 58.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.6495164398004875 \cdot 10^{+103}:\\ \;\;\;\;-0.5 \cdot \left(2 \cdot \frac{c}{b}\right)\\ \mathbf{elif}\;b \leq 9.402708844729834 \cdot 10^{-273}:\\ \;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;b \leq 2.675726436471294 \cdot 10^{+140}:\\ \;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{b + b}{a}\\ \end{array}\]

Reproduce

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