We'll set up a number field defined by the minimum polynomial
> f=x^3+3*x-1
Let a be an element in the number field
> a=Mod(x^2+1,f)
We can compute a^2, a^3, (a+1)^2
> a^2
> a^3
> (a+1)^2
Let b be another element;
> b=Mod(x^2-3*x,f)
we can compute a*b, a+b, a-b, a/b
> a*b
> a+b
> a-b
> a/b
But what about ideals? For this we set up a Pari number field. We'll set up K=Q(a) where a is a
root of our polynomial f:
> K=nfinit(f)
It computes all sorts of information for us.
We can now get an integral basis for the ring of integers
> IntBas = K.zk
So the generators in an integral basis are
> a1 = Mod(IntBas[1],f)
> a2 = Mod(IntBas[2],f)
> a3 = Mod(IntBas[3],f)
So elements of the ring of integers are all of the form s1*a1+s2*a2+s3*a3 for si in Z.
E.g. b=3*a1+2*a2-5*a3 is an integer in the ring of integers of K
> b = 3*a1+2*a2-5*a3
But what if we wanted minimum polynomials for all these values? First we need to find a
complex root of f, so we can embed K into the complex numbers
> roots=polroots(f)
Let's select the second root, i.e. the second embedding of K into C (not that those roots
are in any particular order in the first place)
> a = roots[2]
Now let's see what the integral basis becomes when we substitute this value in for x
> IntBas2 = subst(IntBas,x,a)
Now we can find the minimum polynomial of the third element of the integral basis (which
was the value x^2+2). It's a field of degree 3 over Q, so we'll restrict to minimum polynomials
of degree up to 3. We'll also make sure it is correct to at least 20 decimal places.
> i3 = IntBas2[3]
> f3(x) = algdep(i3,3,20)
> f3(x)
We can see that it is an algebraic integer. Let's now verify that this integer really does
satisfy that minimum polynomial
> subst(f3,x,i3)
Computing the discriminant of k is easy
> K.disc
But that is cheating. let's compute it the old fashioned way. First we compute the three rows
of the determinant by substituting the different conjugates roots of f into the integral basis
> IntBas
> r1=subst(IntBas,x,roots[1])
> r2=subst(IntBas,x,roots[2])
> r3=subst(IntBas,x,roots[3])
Now we construct the matrix itself and take the square of its determinant
> A=Mat([r1[1],r1[2],r1[3];r2[1],r2[2],r2[3];r3[1],r3[2],r3[3]])
> matdet(A)^2
We see that we get precisely the discriminant of the field.
Now what about ideals. Lets construct a principal ideal
> P=idealprincipal(K,5)
Now let's factor that ideal into primes
> Pfact = idealfactor(K,P)
The ideal factors into P1*P2^2 for prime ideals P1 and P2
> P1=Pfact[1,1]
> P2=Pfact[2,1]
Let's see if either P1 or P2 are principal ideals. To do this, we need to compute more
information about our number field, so Pari can perform the computation
> Kbnf=bnfinit(f)
E.g. we now have generators for the group of units
> Kbnf.fu
Let's check those ideals
> bnfisprincipal(Kbnf,P1)
> bnfisprincipal(Kbnf,P2)
If the ideal is principal, the first vector is empty. It then gives a vector of coefficients
for the generator of the principal ideal in terms of the elements of the integral basis. Let's
compute these ideals and verify that they multiply together to give our original principal ideal
> Q1=idealprincipal(K,Mod(IntBas[1]+IntBas[2],f))
> Q2=idealprincipal(K,Mod(IntBas[1]-IntBas[3],f))
> idealmul(K,Q1,idealmul(K,Q2,Q2))
We can also take the norms of ideals, invert ideals, divide ideals, add ideals, intersect ideals,
and give the ideals in terms of two generators
> idealnorm(K,P1)
> idealinv(K,P1)
> idealdiv(K,P1,P2)
> idealadd(K,P1,P2)
> idealintersect(K,P1,P2)
> idealtwoelt(K,idealintersect(K,P1,P2))
We can see how far we are away from having unique factorization into irreducibles by computing
what is known as the class group
> Kbnf.clgp
In this case the class number is 1, which means we have unique factorization and all our ideals
will be principal
Let's compute another example where this is not the case
> f2 = x^2+5
> K2 = bnfinit(f2)
> K2.clgp
Here the class number is 2, so not all ideals are principal
> S=idealprincipal(K2,3)
> Sfact = idealfactor(K2,S)
> bnfisprincipal(K2,Sfact[1,1])
Here we see that the first vector is not empty and so the ideal is not principal.