1 "Demo file for the combinatorics package of Maxima.
3 let's start by loading the package..."$
5 load ("combinatorics.lisp");
7 "This gives the 24 permutations of order 4, in lexicographic order:"$
10 "Let's get the permutation of order 8 given by the cycles [1,4] and
13 p1: perm_undecomp ([[1,4], [2,6,5,7]], 8);
15 "The inverse operation, representing the permutation by cycles, is:"$
19 "Any permutation can also be decomposed into a product of adjacent
20 transpositions (cycles with only two consecutive integers). The
21 length of a permutation is the minimum number of such transpositions:"$
25 "Let's find that product of 12 adjacent transpositions and save it in t1."$
28 "Suppose we have a list with 8 elements:"$
30 lis1: [a, b*c^2, 4, z, x/y, 1/2, ff23(x), 0];
32 "We can permute its elements according to a permutation of degree 8:"$
34 lis2: permute (p1, lis1);
36 "A list of cycles can also be applied to the list. In the case of t1
37 above the inverse of the permutation is obtained just by inverting
38 the order of the transpositions. Therefore, if we apply t1 in
39 reverse order, to the list obtained in the previous command, the
40 result will give back the original list:"$
42 apply_cycles (reverse(t1), lis2);
44 "Let's save in p2 the permutation that goes after p1 in lexicographic
47 p2: perm_lex_next (p1);
49 "Two or several permutations can be multiplied together:"$
53 "The product of any permutation times its inverse gives the identity:"$
55 permult (p3, perm_inverse (p3));
57 "The rank of a permutation is the order in which it appears in the
58 lexicographic sequence:"$
60 map (perm_lex_rank, [p1, p2, p3]);
62 "The parity of a permutation, given in this package by 0 or 1, tells
63 whether the index of a permutation is even or odd. The product of
64 an even permutation by an odd one gives another odd permutation:"$
66 map (perm_parity, [p1, p2, p3]);