Repository: sympy/sympy

Issue:
gamma._eval_is_positive is broken?
The first line in `gamma._eval_is_positive` is `if self.is_number`. Perhaps I don't understand it well, but even if `n` is a positive integer, `gamma(n).is_number` is `False`, and in particular, not positive.

I believe that the following code:
```python
>>> n = Symbol('n', real=True, positive=True)
>>> gamma(n).is_positive
```
should return `True`.

Discussion:
smichr: OK, this can be rebased over #8864 and the tests can be added.
aktech: @smichr 
Thanks, I will add tests when #8864 gets merged, so that test doesn't fails for this PR.
smichr: Could you pull my evalf branch and rebase this over that and force push it here again? There was another change that needed to be made. Then the other PR can just be closed (since tests will fail) and this one will contain the work of both PRs. If you want to wait until tests pass [here](https://travis-ci.org/smichr/sympy/builds/47805947), however, that would be best.
smichr: (After doing the above then you should be able to add the tests that we talked about in this PR.)
smichr: in commit title: ceilling -> ceiling
aktech: I have squashed all commits to one, shall I push that?

smichr: sure...let's see what that looks like.
aktech: I accidentally messed with that, let me fix that. 
aktech: I have squashed all commits in to one.

Patch:
diff --git a/sympy/core/evalf.py b/sympy/core/evalf.py
index 2d2fc08099..d628fc20a7 100644
--- a/sympy/core/evalf.py
+++ b/sympy/core/evalf.py
@@ -320,7 +320,7 @@ def get_integer_part(expr, no, options, return_ints=False):
     def calc_part(expr, nexpr):
         nint = int(to_int(nexpr, rnd))
         n, c, p, b = nexpr
-        if c != 1 and p != 0:
+        if (c != 1 and p != 0) or p < 0:
             expr = C.Add(expr, -nint, evaluate=False)
             x, _, x_acc, _ = evalf(expr, 10, options)
             try:
diff --git a/sympy/functions/special/gamma_functions.py b/sympy/functions/special/gamma_functions.py
index 54f13f745f..21341206e9 100644
--- a/sympy/functions/special/gamma_functions.py
+++ b/sympy/functions/special/gamma_functions.py
@@ -160,6 +160,13 @@ def _eval_is_real(self):
         if x.is_positive or x.is_noninteger:
             return True
 
+    def _eval_is_positive(self):
+        x = self.args[0]
+        if x.is_positive:
+            return True
+        elif x.is_noninteger:
+            return floor(x).is_even
+
     def _eval_rewrite_as_tractable(self, z):
         return C.exp(loggamma(z))
 


Test patch:
diff --git a/sympy/core/tests/test_evalf.py b/sympy/core/tests/test_evalf.py
index e5d222bb24..2d54ba1c4f 100644
--- a/sympy/core/tests/test_evalf.py
+++ b/sympy/core/tests/test_evalf.py
@@ -1,8 +1,9 @@
 from sympy import (Abs, Add, atan, ceiling, cos, E, Eq, exp, factorial,
                    fibonacci, floor, Function, GoldenRatio, I, Integral,
                    integrate, log, Mul, N, oo, pi, Pow, product, Product,
-                   Rational, S, Sum, sin, sqrt, sstr, sympify)
-from sympy.core.evalf import complex_accuracy, PrecisionExhausted, scaled_zero
+                   Rational, S, Sum, sin, sqrt, sstr, sympify, Symbol)
+from sympy.core.evalf import (complex_accuracy, PrecisionExhausted,
+    scaled_zero, get_integer_part)
 from sympy.core.compatibility import long
 from mpmath import inf, ninf
 from sympy.abc import n, x, y
@@ -455,3 +456,16 @@ def test_issue_8821_highprec_from_str():
     assert Abs(sin(p)) < 1e-15
     p = N(s, 64)
     assert Abs(sin(p)) < 1e-64
+
+
+def test_issue_8853():
+    p = Symbol('x', even=True, positive=True)
+    assert floor(-p - S.Half).is_even == False
+    assert floor(-p + S.Half).is_even == True
+    assert ceiling(p - S.Half).is_even == True
+    assert ceiling(p + S.Half).is_even == False
+
+    assert get_integer_part(S.Half, -1, {}, True) == (0, 0)
+    assert get_integer_part(S.Half, 1, {}, True) == (1, 0)
+    assert get_integer_part(-S.Half, -1, {}, True) == (-1, 0)
+    assert get_integer_part(-S.Half, 1, {}, True) == (0, 0)
diff --git a/sympy/functions/special/tests/test_gamma_functions.py b/sympy/functions/special/tests/test_gamma_functions.py
index 0ae9bc6ba5..ea2e7832ae 100644
--- a/sympy/functions/special/tests/test_gamma_functions.py
+++ b/sympy/functions/special/tests/test_gamma_functions.py
@@ -400,3 +400,21 @@ def test_issue_8657():
     assert gamma(o).is_real is True
     assert gamma(p).is_real is True
     assert gamma(w).is_real is None
+
+
+def test_issue_8524():
+    x = Symbol('x', positive=True)
+    y = Symbol('y', negative=True)
+    z = Symbol('z', positive=False)
+    p = Symbol('p', negative=False)
+    q = Symbol('q', integer=True)
+    r = Symbol('r', integer=False)
+    e = Symbol('e', even=True, negative=True)
+    assert gamma(x).is_positive is True
+    assert gamma(y).is_positive is None
+    assert gamma(z).is_positive is None
+    assert gamma(p).is_positive is None
+    assert gamma(q).is_positive is None
+    assert gamma(r).is_positive is None
+    assert gamma(e + S.Half).is_positive is True
+    assert gamma(e - S.Half).is_positive is False