Basic Set Manipulation

It’s not uncommon to ask students to compute small examples of groups, ring or fields, and then find specific elements in that structure to help understand characteristics. Magma always keeps track of where the elements live and calls that set the Parent. Let’s use some basic Magma commands to explore this a bit.

Let’s create a set by listing its elements explicitly.

> S := { (7^2+1)/5, (8^2+1)/5, (9^2-1)/5 };
> S;
{ 10, 13, 16 }
> Parent(S);
Set of subsets of Rational Field

Thus S was created as a set of rationals, because the operation “/” on integers has a rational result. If one wishes to obtain a set of integers, one could specify the universe (or one could use div). Also, one could use ! on every element to coerce it into the ring of integers. When you type P!x, you are telling Magma to think of x as being an element of P.

> T := { Integers() | (7^2+1)/5, (8^2+1)/5, (9^2-1)/5 };
> T;
{ 10, 13, 16 }
> Parent(T);
Set of subsets of Integer Ring

If you want the set of integers, you use Integers(). But that command is more general. Using Integers(n) creates the ring of residue classes of integers modulo n. Let’s look the group Z12 and see which elements are squares and which are cubes.

> Z12 := Integers(12);
> Z12;
Residue class ring of integers modulo 12
> Squares := { x^2 : x in Z12 };
> Cubes := { x^3 : x in Z12 };
> Squares;
{ 0, 1, 4, 9 }
> Cubes;
{ 0, 11, 1, 3, 4, 5, 7, 8, 9 }

So, it appears that all of the squares are also cubes. We can confirm this using the Magma command meet which computes a set intersection.

> Squares meet Cubes eq Squares;

The union command in Magma is join.

> Squares join Cubes;
{ 0, 11, 1, 3, 4, 5, 7, 8, 9 }

Suppose you want to know if there is some element which squares to 1, but is not equal to 1. We could compute via brute force:

> S := { x^2 : x in Z12 | x ne 1};
> S;
{ 0, 1, 4, 9 }

So it looks like there is some other element out there that squares to 1.  Can you figure it out?  Is there more than one of them?

Finally, if you try to do set computations with something that Magma considers to be an algebraic object, you’ll get an error. Suppose we want to compute which elements of Z12 are not cubes. One might try this:

> Z12 diff Cubes;

>> Z12 diff Cubes;
Runtime error in 'diff': Bad argument types
Argument types given: RngIntRes, SetEnum[RngIntResElt]

Instead, we need to first tell Magma to think of the algebraic structure Z12 as a set. Then we can compute the set difference:

> Set(Z12) diff Cubes;
{ 2, 6, 10 }

Exercise: The Magma command for a finite field is GF(q) where q is the order of the field. So, the command F := GF(8) will let F be the field with 8 elements.

  1. Create the field with 7 elements, compute the set of non-zero squares and the set of non-squares. Check that these sets have the same size.
  2. Create the field with 8 elements and check that every element is a square.
  3. Find an element x of GF(23) such that x is a square and x+1 is also a square.