Skip to content

Commit

Permalink
concrete: fix finite geometric sums
Browse files Browse the repository at this point in the history
Added powsimp().cancel() heuristics to catch some cases
when the term is not in a canonical form.

Added regression test.

Closes sympy/sympy#21557
  • Loading branch information
skirpichev committed Jun 2, 2021
1 parent 9d193cb commit c95bb45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions diofant/concrete/summations.py
Expand Up @@ -654,13 +654,13 @@ def eval_sum_symbolic(f, limits):
else:
return harmonic(b, abs(n)) - harmonic(a - 1, abs(n))

if not (a.has(oo, -oo) or
b.has(oo, -oo)):
if not (a.has(oo, -oo) or b.has(oo, -oo)):
# Geometric terms
c1 = Wild('c1', exclude=[i])
c2 = Wild('c2', exclude=[i])
c3 = Wild('c3', exclude=[i])

f = f.powsimp().cancel()
e = f.match(c1**(c2*i + c3))

if e is not None:
Expand Down
9 changes: 9 additions & 0 deletions diofant/tests/concrete/test_sums_products.py
Expand Up @@ -911,3 +911,12 @@ def test_sympyissue_10156():
def test_sympyissue_15943():
s = Sum(binomial(n, k)*factorial(n - k), (k, 0, n))
assert s.doit().simplify() == E*(gamma(n + 1) - lowergamma(n + 1, 1))


def test_sympyissue_21557():
f1 = 2**(-k)*exp(I*k)
assert summation(f1, (k, 1, oo)).simplify() == E**I/(2 - E**I)
f2 = 2**(k*(I - 1))
assert summation(f2, (k, 1, oo)).simplify() == 2**I/(2 - 2**I)
assert (summation(f2, (k, 1, x)).simplify() ==
2**(-x + I)*(-2**x + 2**(I*x))/(-2 + 2**I))
1 change: 1 addition & 0 deletions docs/release/notes-0.13.rst
Expand Up @@ -88,3 +88,4 @@ These Sympy issues also were addressed:
* :sympyissue:`21530`: Incorrect limit
* :sympyissue:`21166`: Wrong integration result involving square root of absolute value
* :sympyissue:`21549`: Bug: integrate(x*sqrt(abs(x)),(x,-1,0)) returns wrong result
* :sympyissue:`21557`: Summation of geometric series with non-real exponent does not evaluate

0 comments on commit c95bb45

Please sign in to comment.