## Section 16.10 Sage

Rings are very important in your study of abstract algebra, and similarly, they are very important in the design and use of Sage. There is a lot of material in this chapter, and there are many corresponding commands in Sage.

### Subsection Creating Rings

Here is a list of various rings, domains and fields you can construct simply.

`Integers()`

,`ZZ`

: the integral domain of positive and negative integers, \({\mathbb Z}\text{.}\)`Integers(n)`

: the integers mod \(n\text{,}\) \({\mathbb Z_n}\text{.}\) A field when \(n\) is prime, but just a ring for composite \(n\text{.}\)`QQ`

: the field of rational numbers, \({\mathbb Q}\text{.}\)`RR`

,`CC`

: the field of real numbers and the field of complex numbers, \({\mathbb R}\text{,}\) \({\mathbb C}\text{.}\) It is impossible to create*every*real number inside a computer, so technically these sets do not behave as fields, but only give a good imitiation of the real thing. We say they are inexact rings to make this point.`QuadraticField(n)`

: the field formed by combining the rationals with a solution to the polynomial equation \(x^2-n=0\text{.}\) The notation in the text is \({\mathbb Q}[\sqrt{n}]\text{.}\) A functional equivalent can be made with the syntax`QQ[sqrt(n)]`

. Note that`n`

can be negative.`CyclotomicField(n)`

: the field formed by combining the rationals with the solutions to the polynomial equation \(x^n-1=0\text{.}\)`QQbar`

: the field formed by combining the rationals with the solutions to*every*polynomial equation with integer coefficients. This is known as a the field of algebraic numbers, denoted as \(\overline{{\mathbb Q}}\text{.}\)`FiniteField(p)`

: for a prime \(p\text{,}\) the field of integers \({\mathbb Z_p}\text{.}\)

If you print a description of some of the above rings, you will sometimes see a new symbol introduced. Consider the following example:

Here `Number Field`

describes an object generally formed by combining the rationals with another number (here \(\sqrt{7}\)). â€śaâ€ť is a new symbol which behaves as a root of the polynomial \(x^2-7\text{.}\) We do not say which root, \(\sqrt{7}\) or \(-\sqrt{7}\text{,}\) and as we understand the theory better we will see that this does not really matter.

We can obtain this root as a generator of the number field, and then manipulate it. First squaring `root`

yields 7. Notice that `root`

prints as `a`

. Notice, too, that computations with `root`

behave as if it was *either* root of \(x^2-7\text{,}\) and results print using `a`

.

This can get a bit confusing, inputing computations with `root`

and getting output in terms of `a`

. Fortunately, there is a better way. Consider the following example:

With the syntax `F.<b>`

we can create the field `F`

along with specifying a generator `b`

using a name of our choosing. Then computations can use `b`

in both input and output as a root of \(x^2-7\text{.}\)

Here are three new rings that are best created using this new syntax.

`F.<a> = FiniteField(p^n)`

: We will later have a theorem that tells us that finite fields only exist with orders equal to to a power of a prime. When the power is larger than 1, then we need a generator, here given as`a`

.`P.<x>=R[]`

: the ring of all polynomials in the variable`x`

, with coefficients from the ring`R`

. Notice that`R`

can be*any*ring, so this is a very general construction that uses one ring to form another. See an example below.`Q.<r,s,t> = QuaternionAlgebra(n, m)`

: the rationals combined with indeterminates`r`

,`s`

and`t`

such that \(r^2=n\text{,}\) \(s^2=m\) and \(t = rs = -sr\text{.}\) This is a generalization of the quaternions described in this chapter, though over the rationals rather than the reals, so it is an exact ring. Notice that this is one of the few noncommutative rings in Sage. The â€śusualâ€ť quaternions would be constructed with`Q.<I,J,K> = QuaternionAlgebra(-1, -1)`

. (Notice that using`I`

here is not a good choice, because it will then clobber the symbol`I`

used for complex numbers.)

Syntax specifying names for generators can be used for many of the above rings as well, such as demonstrated above for quadratic fields and below for cyclotomic fields.

### Subsection Properties of Rings

The examples below demonstrate how to query certain properties of rings. If you are playing along, be sure to execute the first compute cell to define the various rings involved in the examples.

Exact versus inexact.

Finite versus infinite.

Integral domain?

Field?

Commutative?

Characteristic.

Additive and multiplicative identities *print* like you would expect, but notice that while they may *print* identically, they could be *different* because of the ring they live in.

There is some support for subrings. For example, `Q`

and `S`

are extensions of the rationals, while `F`

is totally distinct from the rationals.

Not every element of a ring may have a multiplicative inverse, in other words, not every element has to be a unit (unless the ring is a field). It would now be good practice to check if an element is a unit before you try computing its inverse.

### Subsection Quotient Structure

Ideals are the normal subgroups of rings and allow us to build â€śquotientsâ€ť â€” basically new rings defined on equivalence classes of elements of the original ring. Sage support for ideals is variable. When they can be created, there is not always a lot you can do with them. But they work well in certain very important cases.

The integers, \({\mathbb Z}\text{,}\) have ideals that are just multiples of a single integer. We can create them with the `.ideal()`

method or just by wrting a scalar multiple of `ZZ`

. And then the quotient is isomorphic to a well-understood ring. (Notice that `I`

is a bad name for an ideal if we want to work with complex numbers later.)

We might normally be more careful about the last statement. The quotient is a set of equivalence classes, each infinite, and certainly not a single integer. But the quotient is *isomorphic* to \({\mathbb Z}_4\text{,}\) so Sage just makes this identification.

Notice that the construction of the quotient ring has created a new generator, converting `y`

(\(y\)) to `ybar`

(\(\overline{y}\)). We can override this as before with the syntax demonstrated below.

So from a quotient of an infinite ring and an ideal (which is also a ring), we create a field, which is finite. Understanding this construction will be an important theme in the next few chapters. To see how remarkable it is, consider what happens with just one little change.

There are a few methods available which will give us properties of ideals. In particular, we can check for prime and maximal ideals in rings of polynomials. Examine the results above and below in the context of TheoremÂ 16.35.

The fact that `M`

is a prime ideal is verification of CorollaryÂ 16.40.

### Subsection Ring Homomorphisms

When Sage is presented with `3 + 4/3`

, how does it know that 3 is meant to be an integer? And then to add it to a rational, how does it know that we really want to view the computation as 3/1 + 4/3? This is really easy for you and me, but devilishly hard for a program, and you can imagine it getting ever more complicated with the many possible rings in Sage, subrings, matrices, etc. Part of the answer is that Sage uses ring homomorphisms to â€śtranslateâ€ť objects (numbers) between rings.

We will give an example below, but not pursue the topic much further. For the curious, reading the Sage documentation and experimenting would be a good exercise.

So `phi`

is a homomorphism (â€śmorphismâ€ť) that converts integers (the domain is `ZZ`

) into rationals (the codomain is `QQ`

), whose parent is a set of homomorphisms that Sage calls a â€śhomset.â€ť Even though `a`

and `b`

both print as `3`

, which is indistinguishable to our eyes, the parents of `a`

and `b`

are different. Yet the numerical value of the two objects has not changed.