Repository: sympy/sympy

Issue:
Incorrect binomial simplifications with constant n
SymPy incorrectly simplifies binomials coefficients of the form `binomial(1, k)` to zero for symbolic `k`, and `1` can be replaced by any integer constant. Below are some examples.

````python

# binomial(1, p) is zero if p < 0 or p > 1, and one for p = 0, 1.

binomial(1, -1) # 0
binomial(1, 1) # 1
binomial(1, 2) # 0

# Incorrect.
p = symbols("p")
binomial(1, p).simplify() # 0

# Also incorrect.
p = symbols("p", integer=True)
binomial(1, p).simplify() # 0

# Still incorrect.
p = symbols("p", positive=True, integer=True)
binomial(1, p).simplify() # 0
````
Replacing `.simplify` with `.combsimp` does not fix the issue, and the issue seems to exist for any positive integer upper value. Both `simplify` and `combsimp` are complicated, so I can't determine exactly where the simplifications are going wrong.

Discussion:

Patch:
diff --git a/sympy/functions/special/gamma_functions.py b/sympy/functions/special/gamma_functions.py
index 64013b1665..63a9bfd77e 100644
--- a/sympy/functions/special/gamma_functions.py
+++ b/sympy/functions/special/gamma_functions.py
@@ -134,9 +134,6 @@ def eval(cls, arg):
                     else:
                         return 2**n*sqrt(S.Pi) / coeff
 
-        if arg.is_integer and arg.is_nonpositive:
-            return S.ComplexInfinity
-
     def _eval_expand_func(self, **hints):
         arg = self.args[0]
         if arg.is_Rational:
diff --git a/sympy/simplify/gammasimp.py b/sympy/simplify/gammasimp.py
index ca51130eee..bce770fcc1 100644
--- a/sympy/simplify/gammasimp.py
+++ b/sympy/simplify/gammasimp.py
@@ -78,7 +78,7 @@ def _gammasimp(expr, as_comb):
 
     if as_comb:
         expr = expr.replace(_rf,
-            lambda a, b: binomial(a + b - 1, b)*gamma(b + 1))
+            lambda a, b: gamma(b + 1))
     else:
         expr = expr.replace(_rf,
             lambda a, b: gamma(a + b)/gamma(a))


Test patch:
diff --git a/sympy/functions/special/tests/test_gamma_functions.py b/sympy/functions/special/tests/test_gamma_functions.py
index 72c059d61a..848b3a52e7 100644
--- a/sympy/functions/special/tests/test_gamma_functions.py
+++ b/sympy/functions/special/tests/test_gamma_functions.py
@@ -68,11 +68,6 @@ def test_gamma():
     assert gamma(3*exp_polar(I*pi)/4).is_nonnegative is False
     assert gamma(3*exp_polar(I*pi)/4).is_nonpositive is True
 
-    # Issue 8526
-    k = Symbol('k', integer=True, nonnegative=True)
-    assert isinstance(gamma(k), gamma)
-    assert gamma(-k) == zoo
-
 
 def test_gamma_rewrite():
     assert gamma(n).rewrite(factorial) == factorial(n - 1)
@@ -410,7 +405,7 @@ def test_issue_8657():
     m = Symbol('m', integer=True)
     o = Symbol('o', positive=True)
     p = Symbol('p', negative=True, integer=False)
-    assert gamma(n).is_real is False
+    assert gamma(n).is_real is None
     assert gamma(m).is_real is None
     assert gamma(o).is_real is True
     assert gamma(p).is_real is True
@@ -440,3 +435,7 @@ def test_issue_14450():
     # some values from Wolfram Alpha for comparison
     assert abs(uppergamma(S(3)/8, 2).evalf() - 0.07105675881) < 1e-9
     assert abs(lowergamma(S(3)/8, 2).evalf() - 2.2993794256) < 1e-9
+
+def test_issue_14528():
+    k = Symbol('k', integer=True, nonpositive=True)
+    assert isinstance(gamma(k), gamma)
diff --git a/sympy/simplify/tests/test_combsimp.py b/sympy/simplify/tests/test_combsimp.py
index e67e4ed739..c7f95716b5 100644
--- a/sympy/simplify/tests/test_combsimp.py
+++ b/sympy/simplify/tests/test_combsimp.py
@@ -60,3 +60,8 @@ def test_combsimp():
         n*(n - 1)*(n - 2)
     assert combsimp(6*RisingFactorial(4, -n - 1)/factorial(-n - 1)) == \
         -n*(n - 1)*(n - 2)
+
+def test_issue_14528():
+    p = symbols("p", integer=True, positive=True)
+    assert combsimp(binomial(1,p)) == 1/(factorial(p)*factorial(1-p))
+    assert combsimp(factorial(2-p)) == factorial(2-p)
diff --git a/sympy/simplify/tests/test_gammasimp.py b/sympy/simplify/tests/test_gammasimp.py
index ab47db44d1..36e933857d 100644
--- a/sympy/simplify/tests/test_gammasimp.py
+++ b/sympy/simplify/tests/test_gammasimp.py
@@ -100,3 +100,6 @@ def test_gammasimp():
     assert gammasimp(e) == e
     e = gamma(m + 1)/(gamma(i + 1)*gamma(-i + m + 1))
     assert gammasimp(e) == e
+
+    p = symbols("p", integer=True, positive=True)
+    assert gammasimp(gamma(-p+4)) == gamma(-p+4)