diff options
| author | Georg Brandl <georg@python.org> | 2016-01-17 17:00:26 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2016-01-17 17:00:26 +0100 |
| commit | fc55dc2e95bcea03fbc0d8e1d130c9e53f3f1dad (patch) | |
| tree | 2a06d2fac7321452513bda7739e297a7e9848ec4 /tests/examplefiles/AlternatingGroup.mu | |
| download | pygments-git-fc55dc2e95bcea03fbc0d8e1d130c9e53f3f1dad.tar.gz | |
merge default into stable
Diffstat (limited to 'tests/examplefiles/AlternatingGroup.mu')
| -rw-r--r-- | tests/examplefiles/AlternatingGroup.mu | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/examplefiles/AlternatingGroup.mu b/tests/examplefiles/AlternatingGroup.mu new file mode 100644 index 00000000..2cb19924 --- /dev/null +++ b/tests/examplefiles/AlternatingGroup.mu @@ -0,0 +1,102 @@ +/*++ $Id: AlternatingGroup.mu,v 1.4 2003/09/08 15:00:47 nthiery Exp $ + +Dom::AlternatingGroup(n) -- the Alternating Group of {1..n} + +n - integer >= 1 + +Elements are represented as in Dom::PermutationGroup(n) + +Author: Nicolas M. Thiéry <nthiery@users.sourceforge.net> +License: LGPL +Created: August 8th, 1999 +Last update: $Date: 2003/09/08 15:00:47 $ +++*/ + +domain Dom::AlternatingGroup(n: Type::PosInt) + inherits Dom::PermutationGroup(n,toBeDefined); + category Cat::PermutationGroup; + axiom Ax::canonicalRep; + +/*-- + size + + Size of the group. +--*/ + + size := fact(n)/2; + +/*-- + generators + + A list of generators of the group + + The first 3-cycle (1,2,3), and a maximal even cycle (1,...,n) or + (2,...,n) depending on the parity of n + +--*/ + + generators := + if n<=2 then generators:=[dom([[1]])]; + elif n=3 then generators:=[dom([[1,2,3]])]; + elif n mod 2=0 then generators:=[dom([[1,2,3]]), dom([[$2..n]])]; + else generators:=[dom([[1,2,3]]), dom([[$1..n]])]; + end_if; + +/*-- + allElements + + List of all the elements of the group +--*/ + + allElements := + proc() + option remember; + local p; + begin + [new(dom,p) $ p in select(combinat::permutations(n), + p->bool(combinat::permutations::sign(p)=1))]; + end_proc; + +/*-- + cycleTypes: + + Count the elements of the group by cycle type. + (Cf Cat::PermutationGroupModule). + + Same algorithm as for Dom::SymmetricGroup, but only even permutations + are considered. This is done by disregarding partitions p such + that n-length(p) is odd. +--*/ + + cycleTypes := + proc() + option remember; + local t, p, gen; + begin + userinfo(3, "cycleTypes: starting computation"); + t:=table(); + + gen := combinat::partitions::generator(n); + while (p:=gen()) <> FAIL do + userinfo(5, "working on partition", p); + if(n-nops(p) mod 2=0) then + // Compute the size of the conjugacy class of Sn indexed by p + // and the cycle type of a permutation in this conjugacy class + t[combinat::partitions::toExp(p,n)] + := combinat::partitions::conjugacyClassSize(p); + end_if; + end_while; + t; + end_proc; + +begin + if testargs() then + if args(0) <> 1 then error("wrong no of args"); end_if; + if not testtype(n,DOM_INT) then + error("argument must be integer") + end_if; + if n < 1 then + error("argument must be positive") + end_if; + end_if; +end_domain: |
