> with(linalg):
Here we study computations in the field Q(a=sqrt(2),b=sqrt(3)). Let M be the submodule spanned by
1, a and N that spanned by 1, b. Then MN is spanned by 1, a, b, ab. First we write the matrices
corresponding to the action of a and b respectively on this generating set.
a:=matrix(4,4,[[0,1,0,0],[2,0,0,0],[0,0,0,1],[0,0,2,0]]);
> b:=matrix(4,4,[[0,0,1,0],[0,0,0,1],[3,0,0,0],[0,3,0,0]]);
Now we can calculate the characteristic polynomial of the sum and product of a and b.
> evalm(a+b);
>
>
> charpoly(%,x);
We can verify that this polynomial has a+b as a root:
> subs(x=sqrt(2)+sqrt(3),%);
> simplify(%);
Now we can work out the case of ab:
> multiply(a,b);
> charpoly(%,t);
>
> subs(t=sqrt(6),%);