Using Mathematica
and Maple
TM
387
Permutations[Range[1,3]]
which results in
{{1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,1,2},{3,2,1}}
Mathematica also has functions for the Fibonacci and Lucas sequences.
Fibonacci[n] and LucasL[n] compute the n-th Fibonacci and Lucas number,
respectively. Combined with Table we can create the sequences of the first
ten Fibonacci and Lucas numbers:
Table[Fibonacci[n],{n,1,10}]
Table[LucasL[n],{n,1,10}]
which returns
{1,1,2,3,5,8,13,21,34,55}
{1,3,4,7,11,18,29,47,76,123}
The partitions of n are computed by the function IntegerPartitions.For
example, the partitions of 4 are computed as
IntegerPartitions[4]
which gives
{{4},{3,1},{2,2},{2,1,1},{1,1,1,1}}
So how can we compute the compositions of n? There is no built-in function,
so we apply the function Permutations to each of the partitions of n.For
example, the compositions of 3 are created by
Flatten[Map[Permutations, IntegerPartitions[3]], 1]
which produces the output
{{3},{2,1},{1,2},{1,1,1}}
Note that Map applies the function Permutations to each of the partitions
of [3]. Flatten is used to get the appropriate list structure, so that each
composition is in its own list.
F.1.3 Series manipulation
The function Series computes power series expansions in one or more
variables. Series[f, {x,x0,n}] generates the power series expansion of f
about the point x = x0toorder(x −x0)
n
. For functions of several variables,
Series[f, {x,x0,nx},{y,y0,ny},...] successively finds series expansions
with respect to x,theny, and so on. To see the first six terms of the power
series of the shifted Fibonacci sequence f(x)=
1
1−x−x
2
(see Table A.1) about
x =0weuse
Series[1/(1-x-x^2),{x,0,5}]
© 2010 by Taylor and Francis Group, LLC