Skip to content

Commit

Permalink
Merge pull request #68 from skirpichev/gruntz-use-subs
Browse files Browse the repository at this point in the history
Removed SubsSet in gruntz, use xreplace()
  • Loading branch information
skirpichev committed May 3, 2015
2 parents 674d0c6 + 9bc4f24 commit 94e3e73
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 421 deletions.
3 changes: 2 additions & 1 deletion sympy/concrete/tests/test_gosper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def test_gosper_sum():
# issue 6033:
assert gosper_sum(
n*(n + a + b)*a**n*b**n/(factorial(n + a)*factorial(n + b)), \
(n, 0, m)) == -a*b*(exp(m*log(a))*exp(m*log(b))*factorial(a)* \
(n, 0, m)).rewrite(factorial) == \
-a*b*(exp(m*log(a))*exp(m*log(b))*factorial(a)* \
factorial(b) - factorial(a + m)*factorial(b + m))/(factorial(a)* \
factorial(b)*factorial(a + m)*factorial(b + m))

Expand Down
4 changes: 2 additions & 2 deletions sympy/core/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2771,15 +2771,15 @@ def aseries(self, x, n=6, bound=0, hir=False):
xpos = Dummy('x', positive=True, finite=True)
return self.subs(x, xpos).aseries(xpos, n, bound, hir).subs(xpos, x)

omega, exps = mrv(self, x)
omega = mrv(self, x)
if x in omega:
s = self.subs(x, exp(x)).aseries(x, n, bound, hir).subs(x, log(x))
if s.getO():
o = Order(1/x**n, (x, S.Infinity))
return s + o
return s
d = Dummy('d', positive=True)
f, logw = rewrite(exps, omega, x, d)
f, logw = rewrite(self, x, d)

if self in omega:
# Need to find a canonical representative
Expand Down
7 changes: 7 additions & 0 deletions sympy/functions/combinatorial/factorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def _eval_rewrite_as_gamma(self, n):
from sympy import gamma
return gamma(n + 1)

def _eval_rewrite_as_tractable(self, n):
from sympy import loggamma, exp
return exp(loggamma(n + 1))

def _eval_rewrite_as_Product(self, n):
from sympy import Product
if n.is_nonnegative and n.is_integer:
Expand Down Expand Up @@ -459,6 +463,9 @@ def _eval_rewrite_as_gamma(self, x, k):
from sympy import gamma
return gamma(x + k) / gamma(x)

def _eval_rewrite_as_tractable(self, x, k):
return self._eval_rewrite_as_gamma(x, k).rewrite('tractable')

def _eval_is_integer(self):
return fuzzy_and((self.args[0].is_integer, self.args[1].is_integer,
self.args[1].is_nonnegative))
Expand Down
8 changes: 6 additions & 2 deletions sympy/functions/combinatorial/tests/test_comb_factorials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sympy import (S, Symbol, symbols, factorial, factorial2, binomial,
rf, ff, gamma, polygamma, EulerGamma, O, pi, nan,
oo, zoo, simplify, expand_func, Product)
rf, ff, gamma, polygamma, EulerGamma, O, pi, nan, exp,
oo, zoo, simplify, expand_func, Product, loggamma)
from sympy.functions.combinatorial.factorials import subfactorial
from sympy.functions.special.gamma_functions import uppergamma
from sympy.utilities.pytest import XFAIL
Expand Down Expand Up @@ -44,6 +44,9 @@ def test_rf_eval_apply():
assert rf(n, m + pi).is_integer is False
assert rf(pi, m).is_integer is False

assert rf(x, y).rewrite('tractable') == \
exp(-loggamma(x))*exp(loggamma(x + y))


def test_ff_eval_apply():
x, y = symbols('x,y')
Expand Down Expand Up @@ -151,6 +154,7 @@ def test_factorial_rewrite():

assert factorial(n).rewrite(gamma) == gamma(n + 1)
assert str(factorial(k).rewrite(Product)) == 'Product(_i, (_i, 1, k))'
assert factorial(n).rewrite('tractable') == exp(loggamma(n + 1))


def test_factorial2():
Expand Down
2 changes: 1 addition & 1 deletion sympy/functions/combinatorial/tests/test_comb_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_harmonic_rewrite_polygamma():
assert expand_func(harmonic(n+4)) == harmonic(n) + 1/(n + 4) + 1/(n + 3) + 1/(n + 2) + 1/(n + 1)
assert expand_func(harmonic(n-4)) == harmonic(n) - 1/(n - 1) - 1/(n - 2) - 1/(n - 3) - 1/n

assert harmonic(n, m).rewrite("tractable") == harmonic(n, m).rewrite(polygamma)
assert harmonic(n, m).rewrite("tractable") == harmonic(n, m).rewrite(polygamma).rewrite(gamma).rewrite("tractable")

@XFAIL
def test_harmonic_limit_fail():
Expand Down
Loading

0 comments on commit 94e3e73

Please sign in to comment.