// Simple arithmetic 12+5; 5-12; 5-12*3; (5-12)*3; 12*5; 12/5; 12/5.0; 13 div 5; 13 mod 5; 12^2; Sqrt(144); Sqrt(143); // Help ?Sin ?1 // Comparison a ge b; a gt b; a eq b; a ne b; b le a; not (b ge a); // Tab completion IsPrimePower(7^3); // Try double clicking on Tab after IaPri (for instance) // Simple click on Tab makes IsPrimeP into IsPrimePower // Assignments, Types and Parents a := 12; a; b := 5; Parent(a); Parent(b); Type(a); Type(b); c := a/b; c; Parent(c); d := 5.0; Parent(d); e := a/d; e; Parent(e); Type(e); // Element Coercion - changing parents Q := RationalField(); a in Q; Z := Integers(); a in Z; c in Z; a := Q!a; Parent(a); a in Z; Q!e; // Polynomial Rings and Generators R := PolynomialRing(RationalField()); f := (R.1)^2 - 1; f; Factorisation(f); Roots(f); R := PolynomialRing(RationalField()); R.1; f; Factorisation(f); Roots(f); S := PolynomialRing(RationalField(),2); S.1; S.2; S.3; g := x^2 + y^2 - 25; Evaluate(g,[3,4]); // Finite Fields F := GF(2); F; b in F; print b, F!b; F!a; F!a/F!b; F!(a/b); F := GF(4); F.1; MinimalPolynomial(F.1); F := GF(4); F.1; T := PolynomialRing(GF(2)); MinimalPolynomial(w); // Residue Rings R := Integers(10); R; R!a; R!b; R!a/R!b; R!(a/b); R!2/R!7; // Quotients and sub-constructors R := quo < Integers() | 10 >; I := sub < Integers() | 10 >; 3 in I; 30 in I; J := sub < Integers() | 3,5 >; J; J := sub < Integers() | 3,6 >; J; // Mappings R, phi := quo < Integers() | 10>; R; phi; phi(37); // Some useful non-sense psi := Inverse(phi); psi(7); psi(R!32523525234); f := hom Z | a :-> 2*a>; f(6); g := Inverse(f); g(24); // Sets, Sequences and Lists L := [2,5,7,11]; L[2]; Append(L,17); Append(~L,19); L; M := Append(L,19); M[2] := 3; M; #M; L := {2,5,7,11}; Include(L,17); Include(~L,19); L; M := Include(L,19); M; #M; L := {*2,5,7,11*}; Include(L,17); Include(~L,19); L; M := Include(L,19); M; #M; 3 in L; 5 in L; M := [5..16]; M; M[3]; M[2] := 12; M; [a : a in M | 2 * a in M]; [a : a in M | IsPrime(a)]; [a mod 5 : a in M]; {a mod 5 : a in M}; {*a mod 5 : a in M*}; // Loops for p := 1 to 10 do a := 2*p; print a; end for; p := 1; while p le 10 do a := 2*p; print a; p := p + 1; end while; p := 1; repeat a := 2*p; print a; p := p + 1; until p gt 10; // If-statements p := 27; if IsPrime(p) then print "Magma says that",p,"is a prime. Can I trust Magma?"; else print "I did not know that",p,"is not a prime."; end if; for p := 1 to 50 do if IsPrime(p) then print "Magma says that",p,"is a prime. Can I trust Magma?"; else print "I did not know that",p,"is not a prime."; end if; end for; // Procedures MyProc := procedure (p) if IsPrime(p) then print "Magma says that",p,"is a prime. Can I trust Magma?"; else print "I did not know that",p,"is not a prime."; end if; end procedure; MyProc(235325244325321457234521); MyProc(NextPrime(235325244325321457234521)); // Functions MyFunc := function (p) if IsPrime(p) then return 2*p; else return 3*p; end if; end function; for i := 1 to 20 do print MyFunc(i); end for; [MyFunc(i) mod 5 : i in [1..20]]; {MyFunc(i) mod 5 : i in [1..20]}; {*MyFunc(i) mod 5 : i in [1..20]*};