Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summation of geometric series with non-real exponent does not evaluate #21557

Open
oscarbenjamin opened this issue Jun 1, 2021 · 1 comment
Labels

Comments

@oscarbenjamin
Copy link
Contributor

From SO:
https://stackoverflow.com/questions/67789161/converge-of-a-symbolic-infinite-series

It seems that summation is unable to recognise a geometric series if the coefficient of the index variable in the exponent is non-real:

In [42]: s = Sum(2**(-k)*exp(I*k), (k, 1, oo))

In [43]: s
Out[43]: 
  ∞           
 ___          
 ╲            
  ╲    -k  k2   
 ╱            
 ‾‾‾          
k = 1         

In [44]: s.doit()
Out[44]: 
  ∞           
 ___          
 ╲            
  ╲    -k  k2   
 ╱            
 ‾‾‾          
k = 1         

In [45]: s.rewrite(exp).powsimp(deep=True)
Out[45]: 
  ∞                   
 ___                  
 ╲                    
  ╲    -klog(2) + k               
 ╱                    
 ‾‾‾                  
k = 1                 

In [46]: s.rewrite(exp).powsimp(deep=True).doit()
Out[46]: 
  ∞                   
 ___                  
 ╲                    
  ╲    -klog(2) + k               
 ╱                    
 ‾‾‾                  
k = 1                 

In [47]: Sum(x**k, (k, 1, oo)).doit().subs(x, exp(I - log(2)))
Out[47]: 
         
         
──────────
  ⎛     ⎞
  ⎜    2⋅⎜1 - ──⎟
  ⎝    2In [48]: Sum(x**k, (k, 1, oo)).doit().subs(x, exp(I - log(2))).n()
Out[48]: 0.0283939952189359 + 0.592837620697943

In [49]: s.n()
Out[49]: 0.0283939952189359 + 0.592837620697943

A simpler example:

In [55]: Sum(2**(k*(I-1)), (k, 1, oo)).doit()
Out[55]: 
  ∞              
 ___             
 ╲               
  ╲    k⋅(-1 + )
  ╱   2          
 ╱               
 ‾‾‾             
k = 1 
@Maelstrom6
Copy link
Contributor

I could be completely wrong but maybe #20531 has something to do with it. It certainly deals with the same part of the code. However, I tried it on 1.7.1 (before this merge) and it wasn't able to complete it.

Here is the main section that I think needs to be adjusted (give or take 10 lines above and below):

# Here we first attempt powsimp on f for easier matching with the
# exponential pattern, and attempt expansion on the exponent for easier
# matching with the linear pattern.
e = f.powsimp().match(c1 ** wexp)
if e is not None:
e_exp = e.pop(wexp).expand().match(c2*i + c3)
if e_exp is not None:
e.update(e_exp)
p = (c1**c3).subs(e)
q = (c1**c2).subs(e)
r = p*(q**a - q**(b + 1))/(1 - q)
l = p*(b - a + 1)
return Piecewise((l, Eq(q, S.One)), (r, True))

skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 2, 2021
Added powsimp().cancel() heuristics to catch some cases
when the term is not in a canonical form.

Added regression test.

Closes sympy/sympy#21557
skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 2, 2021
Added powsimp().cancel() heuristics to catch some cases
when the term is not in a canonical form.

Added regression test.

Closes sympy/sympy#21557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants