Download Maple Advanced Programming Guide

Transcript
2.6 Interfaces and Implementations
•
145
>
do
>
for s in gens[ 1 .. i ] do
>
elt := G:-mul( elements[ rep_pos ], s );
>
if not G:-member( elt, Entries( elements ) ) then
>
addElt( elt );
>
for j from 2 to prev_ord do
>
addElt( G:-‘.‘( elements[ j ], elt ) )
>
end do
>
end if
>
end do;
>
rep_pos := rep_pos + prev_ord;
>
if rep_pos > ord then
>
break
>
end if
>
end do
>
end if
>
end do;
>
Entries( elements )
> end proc:
The coding of this algorithm is generic. The exported members of the
group object G are used to effect computations within the procedure.
Even comparisons of equality use the export eq instead of the built-in
comparison operator ‘=‘. (The need for this is illustrated below.)
Using the Symmetric constructor previously defined, you can compute
the elements of the symmetric group S4 , using Dimino’s algorithm, as
follows.
> G := Symmetric( 4 );
G := module()
export
id , ‘.‘, mul , inv , eq , member , gens , order , elements ;
option record ;
end module
> Dimino( G );
{[2, 1, 3, 4], [2, 3, 1, 4], [1, 2, 3, 4], [3, 2, 1, 4],
[2, 3, 4, 1], [3, 2, 4, 1], [1, 3, 4, 2], [3, 1, 4, 2],
[3, 4, 1, 2], [4, 3, 1, 2], [2, 4, 1, 3], [4, 2, 1, 3],
[3, 4, 2, 1], [4, 3, 2, 1], [4, 1, 2, 3], [1, 4, 2, 3],
[3, 1, 2, 4], [1, 3, 2, 4], [4, 1, 3, 2], [1, 4, 3, 2],
[4, 2, 3, 1], [2, 4, 3, 1], [1, 2, 4, 3], [2, 1, 4, 3]}