// Using Magma in number theory // Assignment: see https://people.maths.bris.ac.uk/~matyd/amsmagma/index.html // Basic arithmetic 2+3; // -> 5 x:=10; Factorial(x); // -> 3628800 // Errors: everything has to be defined and live in the right place (y+1)^2; R:=PolynomialRing(Rationals()); (y+1)^2; (4/2) mod 3; // error: "mod" not defined on Q Parent(2); // -> Z Parent(4/2); // -> Q // Coercion ("!") r:=4/2; Z:=Integers(); r:=Z!r; // Force r into integers r mod 3; // -> 2 // Polynomials Q:=Rationals(); R:=PolynomialRing(Q); Factorization(x^8-1); // factors x-1, x+1, x^2+1, x^4+1, each with multiplicity 1 R:=PolynomialRing(GF(2)); // same over the finite field F_2 Factorization(x^8-1); // factor x+1, multiplicity 4 // Number fields K:=QuadraticField(-1); // K=Q(i), i=sqrt(-1) K:=CyclotomicField(4); // K=Q(i), i=zeta_4 R:=PolynomialRing(Rationals()); K:=NumberField(x^2+1); // K=Q(i), i=root of x^2+1 O:=Integers(K); // Basic invariants of O_K ClassNumber(O); // -> 1 (PID) Discriminant(O); // -> -4 #UnitGroup(O); // -> 4 [1,i,-i,-1] K:=SplittingField(x^3+11); // Q(all roots of x^3+11), r primitive element MinimalPolynomial(r); // -> x^6 + 3267 R:=Roots(x^3+11,K); assert #R eq 3; // if not 3, gives an error message R; // -> list of tuples [,...] r:=R[1][1]; // take the first root; assert r^3 eq -11; // check G:=GaloisGroup(K); G; // -> Permutation group on the roots of min poly GroupName(G); // -> S3 GroupName(GaloisGroup(x^24+16)); // -> C2*C4*S3 GroupName(GaloisGroup(x^41-x+1)); // -> S41 (can handle large groups) // Polynomials <-> list of coefficients R:=PolynomialRing(Rationals()); Coefficients(x^3+2); // -> [2,0,0,1] R![1,2,3]; // -> 3*x^2+2*x+1 // Finite fields for p in [2,3,5,7] do // or PrimesUpTo(7) GroupName(UnitGroup(GF(p))); end for; // -> C1, C2, C4, C6 // Ideals K:=QuadraticField(-5); // K=Q(sqrt(-5)), r=sqrt(-5) O:=Integers(K); I:=ideal; // set I=(2,1+sqrt(-5)) Norm(I); // -> 2 ok,g:=IsPrincipal(I); ok; // -> false ok,g:=IsPrincipal(I^2); ok; // -> true g; // -> 2, as I^2=(2) in O Factorization(ideal); // -> I1^2*I2*I3 // Units K:=QuadraticField(5); #UnitGroup(K); // -> Infinity UnitGroup(K); // returns two things, an abstract abelian group A=Z/2Z*Z and a map m: A->O_K^* A,m:=UnitGroup(K); [K!m(g): g in Generators(A)]; // -> [1/2*(r+1), -1], so 1/2*(1+sqrt(5)) is the fundamental unit Norm(r-13); // -> 164 = norm of sqrt(5)-13 from K to Q Trace(r-13); // -> -26 = trace of sqrt(5)-13 from K to Q NormEquation(K,41); // -> true [1/2*(r-13)] Is 41 a norm from K to Q? Returns yes and a sequence of solutions // Lists and conditions [p: p in [1..20] | (p gt 3) and IsPrime(p) and (p mod 4 eq 1)]; // -> [5,13,17] L:=[1,2,2,3]; L; // -> [1,2,2,3] (list) S:={1,2,2,3}; S; // -> {1,2,3} (set) {x: x in L}; // Convert list to set [x: x in S]; // Convert set to list // Built-in lists of primes PrimesUpTo(20); // -> [2,3,5,7,11,13,17,19] PrimesInInterval(10,20); // -> [11,13,17,19] // If, For, Continue, Break for i:=1 to 3 do // print pairs i,j with 1 <= i <= j <= 3 for j:=1 to 3 do if i gt j then continue; end if; i,j; end for; end for; // Find the first cyclotomic polynomial of degree >30 for n in [1..100] do f:=CyclotomicPolynomial(n); if Degree(f) gt 30 then N:=n; break; end if; end for; "Found",N; // -> "Found 37" // Lots more number theory, arithmetic geometry, group theory and representation theory // p-adic fields K:=pAdicField(5,10); // Q_5 with precision 10 IsSquare(K!-1); // -> true -3626068 + O(5^10) (-1 is a square in Q5) // character theory G:=SymmetricGroup(4); #ConjugacyClasses(G); // -> 5 [c: c in CharacterTable(G) | Degree(c) eq 2]; // -> [(2,2,0,-1,0)] // elliptic curves E:=EllipticCurve("11a3"); E; // -> y^2+y=x^3-x^2 over Q Rank(E); // -> 0 #TorsionSubgroup(E); // -> 5 // Artin representations and L-functions K:=CyclotomicField(5); A:=ArtinRepresentations(K); A; // -> four 1-dim characters of Gal(Q(zeta_5)/Q)=C4 L:=LSeries(A[1]); L; // Riemann zeta function Evaluate(L,2); // pi^2/6