gfun[nth_term] - compute one term of the solution of a recurrence relation
NumGfun[fnth_term] - compute a floating-point approximation to one term of the solution of a recurrence relation, with guaranteed precision
Calling Sequences
nth_term(rec, u(n), k, [series])
fnth_term(rec, u(n), k, [precision], [series])
Parameters
rec - linear recurrence relation with coefficients in Q[n]
u - name; holonomic sequence name
n - name; variable of the holonomic sequence u
k - nonnegative integer; index
precision - (optional) positive integer; number of digits (of absolute precision)
Description
- The
nth_term(rec, u(n), k)command computes thekth term of the solution ofrec. - The
fnth_term(rec, u(n), k,precision)command computes a floating-point approximation to thekth term of the solution ofrec, with an error less than 10^(-precision). It is basically equivalent tonth_term(rec, u(n), k)followed by floating-point evaluation to a suitable precision, but usually more efficient whenkis large. - If the option
seriesis present, instead ofu(k), these functions compute thekth partial sum of the series with general term u(n), that is, Sum(u(n), n = 0..k-1). - The default (absolute) precision is the current value of
Digits. - These functions are designed to compute exact values or high-precision approximations of remote terms (
kandprecisionin the millions) efficiently. They are inefficient when the order of the recurrence relation rec is too large. For orders in the hundreds, naive unrolling will likely be faster except fo hugek.
Examples
> with(gfun): with(NumGfun):
> nth_term({(n^2+1)*u(n+2)+u(n+1)=(2*n+2*I+5)*u(n), u(0)=1, u(1)=0}, u(n), 20);
\[\frac{569008109867936731210287799}{8922539920387740732999062500000}+\frac{860326427452337891464669037 \,\mathrm{I}}{4461269960193870366499531250000}\]
> nth_term(u(n+2)=u(n)+u(n+1), u(n), 50);
\[7778742049 u \! \left(0\right)+12586269025 u \! \left(1\right)\]
> nth_term(u(n+1)=u(n)/(n+1), u(n), 40, 'series');
\[\frac{2772359610018469067133291773316444867218087189 u \! \left(0\right)}{1019894104059872167932014086995144867840000000}\]
> fnth_term(u(n+1)=u(n)/(n+1), u(n), 30, 30, 'series');
\[ 2.718281828459045235360287471353 u \! \left(0\right)\]