SharedBasic Rings Tutorial.sagewsOpen in CoCalc
Basic Rings Examples
# **************************************************************
#         How to define basic rings in SAGE: Z/n, Z[i] ...
# **************************************************************

# Working with congruences is called "Modular Arithmetic" Z/n
# Define variables for this type of numbers:
n=11 # define the modulue
a=mod(2,n) # a is now 2 mod n
a^4 # expect 16 mod 11, that is 5

# Copy an example from SAGE Quick Start - Number Theory:
# http://doc.sagemath.org/html/en/prep/Quickstarts/Number-Theory.html
a = mod(2,11); a; type(a); a^10; a^1000000

# *********************************************
#          Number Fields:
# Extensions of Q the field of rational numbers
# *********************************************
#
L1.<x> = NumberField(x^2 + x + 1); # defined by an irreducible polynomial
L1
x
x^2+x+1
5 2 <type 'sage.rings.finite_rings.integer_mod.IntegerMod_int'> 1 1 Number Field in x with defining polynomial x^2 + x + 1 x 0
#
# **********   Cyclotomic Fields  *************
#
# Cyclotomic fields are a special case of number fields:
#   - See https://en.wikipedia.org/wiki/Cyclotomic_field
#   - Important case: n=p is a prime
#
# Example p=3, x3-1=(x-1)(x^2+x+1),
#         Phi(3)=x^2+x+1 is the 3rd cyclotomic polynomial
#         see https://en.wikipedia.org/wiki/Cyclotomic_polynomial
# It yields a quadratic extension: [L:Q]=2
L=CyclotomicField(3); L # special case of number field defined by x^p-1
z3=L.gen(); z3
z3^2+z3+1
Cyclotomic Field of order 3 and degree 2 zeta3 0
# Comparing the two presentations:
a^2+a+1
z3^2+z3+1
if z3==a:
    print "z3=a both are zeta3"
else:
    print "different implementations ..."

0 0 different implementations ...
# Basis in the cyclotomic field
1; z3; z3^2
z3^3
1 zeta3 -zeta3 - 1 1