1 @c -----------------------------------------------------------------------------
2 @c File : solve_rec.de.texi
3 @c License : GNU General Public License (GPL)
4 @c Original : solve_rec.texi revision 1.13
6 @c Revision : 25.03.2011
8 @c This file is part of Maxima -- GPL CAS based on DOE-MACSYMA
9 @c -----------------------------------------------------------------------------
12 * Introduction to solve_rec::
13 * Functions and Variables for solve_rec::
16 @c -----------------------------------------------------------------------------
17 @node Introduction to solve_rec, Functions and Variables for solve_rec, solve_rec, solve_rec
18 @section Introduction to solve_rec
19 @c -----------------------------------------------------------------------------
21 @code{solve_rec} is a package for solving linear recurrences with polynomial
24 A demo is available with @code{demo(solve_rec)}.
29 (%i1) load("solve_rec")$
31 (%i2) solve_rec((n+4)*s[n+2] + s[n+1] - (n+1)*s[n], s[n]);
35 (%o2) s = -------------------- + ---------------
36 n (n + 1) (n + 2) (n + 1) (n + 2)
40 @c -----------------------------------------------------------------------------
41 @node Functions and Variables for solve_rec, , Introduction to solve_rec, solve_rec
42 @section Functions and Variables for solve_rec
43 @c -----------------------------------------------------------------------------
45 @c -----------------------------------------------------------------------------
46 @deffn {Function} reduce_order (@var{rec}, @var{sol}, @var{var})
48 Reduces the order of linear recurrence @var{rec} when a particular solution
49 @var{sol} is known. The reduced reccurence can be used to get other solutions.
55 (%i3) rec: x[n+2] = x[n+1] + x[n]/n;
62 (%i4) solve_rec(rec, x[n]);
63 WARNING: found some hypergeometrical solutions!
68 (%i5) reduce_order(rec, n, x[n]);
80 (%o6) (- n - 2) %u - %u
84 (%i6) solve_rec((n+2)*%u[n+1] + %u[n], %u[n]);
91 So the general solution is
96 %k n > -------- + %k n
104 @c -----------------------------------------------------------------------------
105 @anchor{simplify_products}
106 @defvr {Option variable} simplify_products
107 Default value: @code{true}
109 If @code{simplify_products} is @code{true}, @code{solve_rec} will try to
110 simplify products in result.
112 See also: @code{solve_rec}.
115 @c -----------------------------------------------------------------------------
116 @anchor{simplify_sum}
117 @deffn {Function} simplify_sum (@var{expr})
119 Tries to simplify all sums appearing in @var{expr} to a closed form.
121 To use this function first load the @code{simplify_sum} package with
122 @code{load("simplify_sum")}.
127 (%i1) load("simplify_sum")$
129 (%i2) sum(binom(n+k,k)/2^k, k, 0, n)
130 + sum(binom(2*n, 2*k), k, 0, n);
133 \ binomial(n + k, k) \
134 (%o2) > ------------------ + > binomial(2 n, 2 k)
140 (%i3) simplify_sum(%);
149 @c -----------------------------------------------------------------------------
150 @anchor{solve_rec_function}
151 @deffn {Function} solve_rec (@var{eqn}, @var{var}, [@var{init}])
153 Solves for hypergeometrical solutions to linear recurrence @var{eqn} with
154 polynomials coefficient in variable @var{var}. Optional arguments @var{init}
155 are initial conditions.
157 @code{solve_rec} can solve linear recurrences with constant coefficients,
158 finds hypergeometrical solutions to homogeneous linear recurrences with
159 polynomial coefficients, rational solutions to linear recurrences with
160 polynomial coefficients and can solve Ricatti type recurrences.
162 Note that the running time of the algorithm used to find hypergeometrical
163 solutions is exponential in the degree of the leading and trailing
166 To use this function first load the @code{solve_rec} package with
167 @code{load("solve_rec");}.
169 Example of linear recurrence with constant coefficients:
173 (%i2) solve_rec(a[n]=a[n-1]+a[n-2]+n/2^n, a[n]);
175 (sqrt(5) - 1) %k (- 1)
177 (%o2) a = ------------------------- - ----
183 + ------------------ - ----
189 Example of linear recurrence with polynomial coefficients:
193 (%i7) 2*x*(x+1)*y[x] - (x^2+3*x-2)*y[x+1] + (x-1)*y[x+2];
195 (%o7) (x - 1) y - (x + 3 x - 2) y + 2 x (x + 1) y
199 (%i8) solve_rec(%, y[x], y[1]=1, y[3]=3);
207 Example of Ricatti type recurrence:
211 (%i2) x*y[x+1]*y[x] - y[x+1]/(x+2) + y[x]/(x-1) = 0;
214 (%o2) x y y - ------ + ----- = 0
217 (%i3) solve_rec(%, y[x], y[3]=5)$
219 (%i4) ratsimp(minfactorial(factcomb(%)));
222 (%o4) y = - -------------------------------------------------
224 5 x - 3 x - 25 x + 15 x + 20 x - 12 x - 1584
228 See also: @code{solve_rec_rat}, @code{simplify_products}, and
229 @code{product_use_gamma}.
232 @c -----------------------------------------------------------------------------
233 @anchor{solve_rec_rat}
234 @deffn {Function} solve_rec_rat (@var{eqn}, @var{var}, [@var{init}])
236 Solves for rational solutions to linear recurrences. See solve_rec for
237 description of arguments.
239 To use this function first load the @code{solve_rec} package with
240 @code{load("solve_rec");}.
246 (%i1) (x+4)*a[x+3] + (x+3)*a[x+2] - x*a[x+1] + (x^2-1)*a[x];
247 (%o1) (x + 4) a + (x + 3) a - x a
254 (%i2) solve_rec_rat(% = (x+2)/(x+1), a[x]);
256 (%o2) a = ---------------
261 See also: @code{solve_rec}.
264 @c -----------------------------------------------------------------------------
265 @anchor{product_use_gamma}
266 @defvr {Option variable} product_use_gamma
267 Default value: @code{true}
269 When simplifying products, @code{solve_rec} introduces gamma function
270 into the expression if @code{product_use_gamma} is @code{true}.
272 See also: @code{simplify_products}, @code{solve_rec}.
275 @c -----------------------------------------------------------------------------
276 @anchor{summand_to_rec}
277 @deffn {Function} summand_to_rec (@var{summand}, @var{k}, @var{n})
278 @deffnx {Function} summand_to_rec (@var{summand}, [@var{k}, @var{lo}, @var{hi}], @var{n})
280 Returns the recurrence sattisfied by the sum
294 where summand is hypergeometrical in @var{k} and @var{n}. If @var{lo} and
295 @var{hi} are omited, they are assumed to be @code{lo = -inf} and
298 To use this function first load the @code{simplify_sum} package with
299 @code{load("simplify_sum")}.
304 (%i1) load("simplify_sum")$
306 (%i2) summand: binom(n,k);
310 (%i3) summand_to_rec(summand,k,n);
315 (%i7) summand: binom(n, k)/(k+1);
321 (%i8) summand_to_rec(summand, [k, 0, n], n);
322 (%o8) 2 (n + 1) sm - (n + 2) sm = - 1
328 @c --- End of file solve_rec.de.texi -------------------------------------------