// Extracted from MagmaOverview.tex by MagmaCode 1.2 on Thu Feb 9 00:02:30 2012 // // Symmetries of Discrete Objects // Conference and MAGMA Workshop // Queenstown, New Zealand, 13-17 February 2012 // Lecturer: Don Taylor // *************************** // Legendre polynomial example // *************************** LegendrePolynomial; R := PolynomialRing(Rationals()); P := func< n | Derivative((z^2-1)^n,n)/(2^n*Factorial(n))>; P(7); P(7) eq LegendrePolynomial(7); L := [ n eq 0 select 1 else n eq 1 select z else ((2*n-1)*z*Self(n)-(n-1)*Self(n-1))/n : n in [0..7]]; L[8]; // *************************** // Number fields // *************************** E := CyclotomicField(3); E; a := Matrix(2,2,[E| w, 0, w^2, 1]); b := Matrix(2,2,[E| 1, -w^2, 0, w]); c := Matrix(2,2,[E| 2*w+1, 2*w, w^2, -w]); G1 := sub; G2 := sub; #G1, IsFinite(G2); // *************************** // Strings // *************************** base := "E"; for n := 6 to 8 do print base*IntegerToString(n); end for; // *************************** // Sequences // *************************** a := [2,3,5,7,11]; b := [ x^2 : x in a ]; T := [ x : x in Sym(5) | Order(x) eq 2 ]; Universe(a); // *************************** // Tuples // *************************** X := [ < x , Order(x) > : x in Sym(3) ]; Universe(X):Minimal; // *************************** // Sets // *************************** V := VectorSpace(GaloisField(4),4); G := SpecialUnitaryGroup(4,2); e := { V.1^g : g in G }; #e; // *************************** // Indexed sets // *************************** A := {@ 3,3,2,1,5,3,5 @}; print A; print A[3]; // *************************** // Lists // *************************** L := [* 3, G.1 *] where G is SymmetricGroup(4); L; Append(~L, "symmetric group"); L; // *************************** // Attributes // *************************** G := CoxeterGroup(GrpMat,"H4"); G`Order; // *************************** // Associative arrays // *************************** A := AssociativeArray(); for n in [6,7,8] do name := "E"*IntegerToString(n); A[name] := CoxeterGroup(name); end for; Order(A["E6"]); // *************************** // Functions and procedures // *************************** BinaryOctahedral := function() P := PolynomialRing(IntegerRing()); K := NumberField([x^2+1,x^2-2]); a := [g/2 : g in [-i-1, -i+1, -i-1, i-1]]; c := [(1-i)/q,0,0,(1+i)/q]; return sub< GL(2,K) | a, c >; end function; addrow := procedure( ~A, i, j, m ) n := Ncols(A); for k := 1 to n do A[j,k] +:= m*A[i,k]; end for; end procedure; // *************************** // Maps // *************************** G := Sym(5); H,f := sub< G | (1,2)(3,4), (1,2,3,4) >; f; q := 3; F := GF(q^2); sigma := map< F -> F | x :-> x^q >; sigma(iota+2); // *************************** // Types // *************************** G := Alt(4); // the alternating group on {1,2,3,4} G; Type(G); Parent(G); Generic(G); // *************************** // Coercion // *************************** V := VectorSpace(Rationals(),3); v := [2,3,7]; // v in V; vec := V!v; vec in V; // *************************** // Closures // *************************** add_three := function() y := 3; return func< x | x + y >; end function; y := 7; add_three()(10); add_factory := function(y) return func< x | x + y >; end function; add3 := add_factory(3); add3(10); // *********************************** // Efficient recursion with attributes // *********************************** chebyshev := function(n) chebyshev_ := procedure(~Z,z,n) if not IsDefined(Z`cheb_poly,n+1) then $$(~Z,z,n-1); Append(~Z`cheb_poly, 2*z*Z`cheb_poly[n]-Z`cheb_poly[n-1]); end if; end procedure; AddAttribute(Rng,"cheb_poly"); P := PolynomialRing(Integers()); P`cheb_poly := [P| 1, z]; chebyshev_(~P,z,n); return P`cheb_poly[n+1]; end function; time _ := chebyshev(500); // *************************** // Inefficient recursion // *************************** slowcheb := function(n) chebyshev_ := func< z, n | case< n | 0 : Parent(z)!1, 1 : z, default : 2*z*$$(z,n-1)-$$(z,n-2) >>; P := PolynomialRing(Integers()); return chebyshev_(z,n); end function; time _ := slowcheb(30);