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

laurent series Fibonacci generating fuction #21245

Closed
lukaskiss222 opened this issue Apr 5, 2021 · 2 comments · Fixed by #21253
Closed

laurent series Fibonacci generating fuction #21245

lukaskiss222 opened this issue Apr 5, 2021 · 2 comments · Fixed by #21253
Labels

Comments

@lukaskiss222
Copy link

Hi all,

I play little bit with Fibonacci gf.
fi = (1+sp.sqrt(5))/2 # this is singularity of Fib. gf. (inverse of golden ratio)
(1/(1-x-x**2)).series(x,1/fi,2) and I get

image

This is clearly not a laurent series in 1/fi and the first therm is /0.

@jksuom
Copy link
Member

jksuom commented Apr 5, 2021

The implementation of the series expansion starts by computing the leading term of the denominator at 1/fi:

In [1]: f = 1 - x - x**2                                                        

In [2]: fi = (1 + sqrt(5))/2                                                    

In [3]: f.subs(x, y + 1/fi).leadterm(y)                                         
Out[3]: 
⎛                    2   ⎞
⎜-6 - 2⋅√5 + (1 + √5)    ⎟
⎜─────────────────────, 0⎟
⎜              2         ⎟
⎝      (1 + √5)          ⎠

This fails because expand_mul in Add._eval_as_leading_term does not simplify the constant term to zero. It seems that _mexpand could be used instead:

--- a/sympy/core/add.py
+++ b/sympy/core/add.py
@@ -978,11 +978,12 @@ def as_real_imag(self, deep=True, **hints):
         return (self.func(*re_part), self.func(*im_part))
 
     def _eval_as_leading_term(self, x, cdir=0):
-        from sympy import expand_mul, Order
+        from sympy.core.function import _mexpand
+        from sympy.series.order import Order
 
         old = self
 
-        expr = expand_mul(self)
+        expr = _mexpand(self)
         if not expr.is_Add:
             return expr.as_leading_term(x, cdir=cdir)
 
@@ -1004,7 +1005,7 @@ def _eval_as_leading_term(self, x, cdir=0):
         except TypeError:
             return expr
 
-        new_expr=new_expr.together()
+        new_expr = _mexpand(new_expr.together())
         if new_expr.is_Add:
             new_expr = new_expr.simplify()

@jksuom
Copy link
Member

jksuom commented Apr 5, 2021

Maybe all expand functions can be dispensed with if new_expr is tested with .is_zero (in which case there will be no need to assign to expr).

--- a/sympy/core/add.py
+++ b/sympy/core/add.py
@@ -978,11 +978,10 @@ def as_real_imag(self, deep=True, **hints):
         return (self.func(*re_part), self.func(*im_part))
 
     def _eval_as_leading_term(self, x, cdir=0):
-        from sympy import expand_mul, Order
+        from sympy import Order
 
         old = self
-
-        expr = expand_mul(self)
+        expr = self
         if not expr.is_Add:
             return expr.as_leading_term(x, cdir=cdir)
 
@@ -1003,12 +1002,11 @@ def _eval_as_leading_term(self, x, cdir=0):
 
         except TypeError:
             return expr
 
-        new_expr=new_expr.together()
+        new_expr = new_expr.together()
         if new_expr.is_Add:
             new_expr = new_expr.simplify()
 
-        if not new_expr:
+        if new_expr.is_zero:
             # simple leading term analysis gave us cancelled terms but we have to send
             # back a term, so compute the leading term (via series)
             n0 = min.getn()

skirpichev added a commit to skirpichev/diofant that referenced this issue Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants