|
Calling Sequence
|
|
TopologicalSorts(n,rels,opts)
|
|
Parameters
|
|
n
|
-
|
nonnegint; the size of the set
|
rels
|
-
|
set(`<`); relations restricting the permutations
|
opts
|
-
|
(optional) equation(s) of the form option = value; specify options for the TopologicalSorts command
|
|
|
|
|
Options
|
|
|
True means compile the iterator. The default is true.
|
|
True means return the inverse permutations. False means return the normal permutations. The default is false.
|
|
|
Description
|
|
•
|
The TopologicalSorts command returns an iterator that generates the permutations of the integers 1 to n that obey specified restrictions.
|
•
|
The n parameter is a nonnegative integer that specifies the set of integers, 1 to n, with 0 specifying the empty set.
|
•
|
The rels parameter specifies the relations that restrict the permutations. The relations are true strict-inequalities between integers.
|
•
|
If the relation appears in rels, precedes in all permutations.
|
|
|
Examples
|
|
Create all permutations of the integers 1 to 4 such that 1 precedes 2, and 3 precedes 4.
>
|
|
| (1) |
Count the number of permutations that meet the restrictions.
|
Young rectangle
|
|
A Young rectangle is a specialization of a Young tableau. It consists of an rectangular arrangement of the integers such that each row is increasing from left to right and each column from top to bottom. In a permutation of the integers precedes if and only if in the inverse permutation . Consequently, specifying that means that, in all the inverse permutations, the value in position is less than that in position .
Label the cells of a 3x2 matrix as shown.
>
|
|
If an inverse permutation meets the requirement of the Young rectangle, the corresponding relations are
>
|
|
Construct the iterator; use the inverse option to generate the inverse permutations.
>
|
|
Generate and display the results as Matrices. Use ArrayTools[Alias] to create a 3x2 Matrix representation of the Vector output.
>
|
|
| (4) |
Assign a procedure that counts Young rectangles of a given size.
>
|
YoungNum := proc(m::nonnegint,n::nonnegint)
local i,j,pos,rels,Y;
pos := (i,j) -> (i-1)*n+j;
rels := {seq(seq(pos(i,j) < pos(i,j+1), j=1..n-1), i=1..m),
seq(seq(pos(i,j) < pos(i+1,j), i=1..m-1), j=1..n)
};
Y := Iterator:-TopologicalSorts(m*n, rels);
add(1, y=Y);
end proc:
|
|
|
|
References
|
|
|
Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 2; generating all tuples and permutations, sec. 7.2.1.2, p. 63, generating all permutations, algorithm V, all topological sorts.
|
|
|
Compatibility
|
|
•
|
The Iterator[TopologicalSorts] command was introduced in Maple 2016.
|
•
|
The Iterator[TopologicalSorts] command was updated in Maple 2022.
|
•
|
The n parameter was updated in Maple 2022.
|
|
|
|