### From WeBWorK

# NAME

`Context("Permutation")`

- Provides contexts that allow the
entry of cycles and permutations.

# DESCRIPTION

These contexts allow you to enter permutations using cycle notation. The entries in a cycle are separated by spaces and enclosed in parentheses. Cycles are multiplied by juxtaposition. A permutation can be multiplied on the left by a number in order to obtain the result of that number under the action of the permutation. Exponentiation is alos allowed (as described below).

There are three contexts included here: `Context("Permutation")`

, which
allows permutations in any form, `Context("Permutation-Strict")`

, which
only allows permutations that use disjoint cycles, and
`Context("Permutation-Canonical")`

, which only allows permutations that
are written in canonical form (as described below).

# USAGE

loadMacros("contextPermutation.pl"); Context("Permutation"); $P1 = Compute("(1 4 2)(3 5)"); $P2 = Permutation([1,4,2],[3,5]); # same as $P1 $C1 = Cycle(1,4,2); $P3 = Cycle(1,4,2)*Cycle(3,5); # same as $P1 $n = 3 * $P1; # sets $n to 5 $m = Compute("3 (2 4 3 1)"); # sets $m to 1 $P4 = Compute("(1 2 3)^2"); # square a cycle $P5 = Compute("((1 2)(3 4))^2"); # square a permutation $I = Comptue("(1 2 3)^-1"); # inverse $L = Compute("(1 2),(1 3 2)"); # list of permutations $P = $P1->inverse; # inverse $P = $P1->canonical; # canonical representation $P1 = Compute("(1 2 3)(4 5)"); $P2 = Compute("(5 4)(3 1 2)"); $P1 == $P2; # is true

Cycles and permutations can be multiplied to obtain the permutation that consists of one followed by the other, or multiplied on the left by a number to obtain the image of the number under the permutation. A permutation raised to a positive integer is the permutation multiplied by itself that many times. A power of -1 is the inverse of the permutation, while a larger negative number is the inverse multiplied by itself that many times (the absolute value of the power).

There are times when you might not want to allow inverses to be computed automatically. In this case, set

Context()->flags->set(noInverses => 1);

This will cause an error message if a student enters a negative power for a cycle or permutation.

If you don't want to allow any powers at all, then set

Context()->flags->set(noPowers => 1);

Similarly, if you don't want to allow grouping of cycles via parentheses (e.g., "((1 2)(3 4))^2 (5 6)"), then use

Context()->flags->set(noGroups => 1);

The comparison between permutations is done by comparing the canonical forms, so even if they are entered in different orders or with the cycles rotated, two equivalent permutations will be counted as equal. If you want to perform more sophisticated checks, then a custom error checker could be used.

You can require that permutations be entered using disjoint cycles by setting

Context()->flags->set(requireDisjoint => 1);

When this is set, Compute("(1 2) (1 3)") will produce an error indicating that the permutation doesn't have disjoint cycles.

You can also require that students enter permutations in a canonical form. The canonical form has each cycle listed with its lowest entry first, and with the cycles ordered by their initial entries. So the canonical form for

(5 4 6) (3 1 2)

is

(1 2 3) (4 6 5)

To require that permutations be entered in canonical form, use

Context()->flags->set(requireCanonical => 1);

The `Permutation-Strict`

context has `noInverses`

, `noPowers`

, `noGroups`

, and
`requireDisjoint`

all set to 1, while the `Permutation-Canonical`

has
`noInverses`

, `noPowers`

, `noGroups`

, and `requireCanonical`

all set to 1.
The `Permutation`

context has all the flags set to 0, so any permutation
is allowed. All three contexts allow lists of permutations to be
entered.