On Mon, Jan 19, 2009 at 02:31:37PM -0800, Ondrej Certik wrote:
> 
> On Mon, Jan 19, 2009 at 2:17 PM, Fabian Seoane <[email protected]> 
> wrote:
> > Hi!
> >
> > Could someone please explain the syntax for rsolve_ratio ?
> >
> > I'ver read the docstrings, but they are not very helpful for someone that
> > does not know much about recurrence relations.  I can clearly understand
> > mathematica's RSolve:
> > http://reference.wolfram.com/mathematica/ref/RSolve.html, but when
> > confronted with the following
> >
> > rsolve_ratio([-2*n**3+n**2+2*n-1, 2*n**3+n**2-6*n,
> >         -2*n**3-11*n**2-18*n-9, 2*n**3+13*n**2+22*n+8], 0, n)
> >
> > I fail to see where is the recurrence relation f[n] = ?.
> 
> I think that's a question for Mateusz. :)
> 
> Ondra
> 

Hi,

rsolve_X functions were meant as a low level interface for rsolve()
which would use Mathematica's syntax. Anyway it's true that docstrings
for rsolve_X aren't much helpful, so here is a brief guide.

Given a recurrence relation:

    a_{k}(n) y(n+k) + a_{k-1}(n) y(n+k-1) + ... + a_{0}(n) y(n) = f(n)

where k > 0 and a_{i}(n) are polynomials in n. To use rsolve_X we need
to put all coefficients in to a list L of k+1 elements the following
way:

    L = [ a_{0}(n), ..., a_{k-1}(n), a_{k}(n) ]

where L[i], for i=0..k, maps to a_{i}(n) y(n+i) (y(n+i) is implicit).

For example if we would like to compute m-th Bernoulli polynomial up to
a constant (example was taken from rsolve_poly docstring), then we would
use b(n+1) - b(n) == m*n**(m-1) recurrence, which has solution b(n) = B_m + C.

Then L = [-1, 1] and f(n) = m*n**(m-1) and finally for m=4:

 >>> from sympy.core import Symbol
 >>> n = Symbol('n', integer=True)

 >>> rsolve_poly([-1, 1], 4*n**3, n)
 C0 + n**2 - 2*n**3 + n**4

 >>> bernoulli(4, n)
 -1/30 + n**2 - 2*n**3 + n**4

For the sake of completeness, f(n) can be:

 [1] a polynomial              -> rsolve_poly
 [2] a rational function       -> rsolve_ratio
 [3] a hypegeometric function  -> rsolve_hyper

I hope now it's much clearer and I hope someone will consider writing
rsolve() as an easy to fix task. It might be also beneficial to put this
guide into rsolve_X docstrings.

-- 
Mateusz

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to