Generating functions in Sympy

177 views
Skip to first unread message

Thomas Baruchel

unread,
Jan 16, 2016, 2:59:05 AM1/16/16
to sympy
Hi,

I have been working for some weeks on implementing generating functions in Sympy, mostly in the new submodule sympy.concrete.guess. The currently submitted version of my function guess_generating_function (which should be imported with the shorter alias ggf) now is able to detect six types of generating functions. I took the definition of these variants at https://oeis.org/wiki/Generating_functions.

However I don't use myself all these variants equally and I would be happy if someone could have a quick look at the examples below in order to be sure all results are consistent with the definitions from the previous link. For instance, I have the feeling that I don't understand l.g.f. (logarithmic generating function) exactly the same way as some contributors in the OEIS (online encyclopedia of integer sequences) though I think that these contributors call l.g.f. what I would have called h.l.g.f. but maybe I am wrong myself.

Here is the output of my function in some examples:

>>> from sympy.concrete.guess import guess_generating_function as ggf
>>> from sympy import fibonacci, lucas, factorial
>>> ggf([k+1 for k in range(12)])
{'egf': (x + 1)*exp(x),
 'hlgf': 1/(-x + 1),
 'lgdegf': (x + 2)/(x + 1),
 'lgdogf': 2/(-x + 1),
 'lgf': 1/(x + 1),
 'ogf': 1/(x**2 - 2*x + 1)}

>>> ggf([factorial(k) for k in range(12)])
{'egf': 1/(-x + 1), 'lgdegf': 1/(-x + 1)}

>>> ggf([1 for k in range(12)])
{'lgdogf': 1/(-x + 1), 'ogf': 1/(-x + 1)}

>>> ggf([(-1)**k for k in range(12)])
{'lgdogf': -1/(x + 1), 'ogf': 1/(x + 1)}

>>> ggf([(k+1)*(-1)**k for k in range(12)])
{'egf': (x - 1)*exp(-x),
 'hlgf': 1/(x + 1),
 'lgdegf': (x - 2)/(-x + 1),
 'lgdogf': -2/(x + 1),
 'lgf': 1/(-x + 1),
 'ogf': 1/(x**2 + 2*x + 1)}

>>> ggf([(k+1)**2 for k in range(12)])
{'egf': (x**2 + 3*x + 1)*exp(x),
 'hlgf': 1/(x**2 - 2*x + 1),
 'lgdegf': (x**2 + 5*x + 4)/(x**2 + 3*x + 1),
 'lgdogf': (2*x + 4)/(-x**2 + 1),
 'lgf': 1/(x**2 + 2*x + 1),
 'ogf': (x + 1)/(-x**3 + 3*x**2 - 3*x + 1)}

Peter Luschny

unread,
Jan 16, 2016, 9:14:43 AM1/16/16
to sympy
are consistent with the definitions from the previous link. For instance, I have the feeling that I don't understand l.g.f. (logarithmic generating function) exactly the same way as some contributors in the OEIS 

The definitive guide for these definitions is Bruno Salvy's gefun package.

A similar approach is this SageMath toolbox:
See also the links at the bottom of this page.

Peter
 
Reply all
Reply to author
Forward
0 new messages