-- In M2 things with a -- in front of them are comments, i.e. are ignored
-- by the software
--sometimes we want to resart to clear variables
restart
--Create a polynomial ring over the rationals
R=QQ[x]
--We can also do several variables
R=QQ[x,y,z]
R=QQ[w_1..w_6]
--Use coefficents from a finite feild
R=ZZ/32749[x]
R=ZZ/32749[v_1..v_4]
isPrime 977
R=ZZ/977[x]
--We can define ideals
R=ZZ/32749[v_1..v_4]
I=ideal(v_1^2-6*v_2,v_3*v_1-45)
--and check if they are prime
isPrime I
--back to one variable
R=QQ[x]
I=ideal(x^2-23*x+47)
isPrime I
--get the first (and only) generator of I
f=I_0
--we can try to factor it, and see it is irriducible (which we already knew since the ideal is prime)
factor(f)
--We can define a quotient ring
S=R/I
--we can do products of things in S
h=(x^7+24)*(x^2-x-34)
--since S is a feild we can also find inverses (note we need the two slashes)
g=1//h
g*h
--we could also do the following, sing S is a feild
(x^2-5)//(x+4)
--One should be careful about reusing names too much in different rings... this can cuase errors, we will restart to avoid this
restart
--We can also find gcd's
R=QQ[x]
f=x^2-23*x-2
g=23*x^3-34
gcd(f,g)
--since these polynomials have gcd 1 then an ideal containing both must be the whole ring
--we can check equality of rings and ideals and ideals and ideals with ==
ideal(f,g)==R
h=f*(x+5)
--now we will get a polynomial other than 1
b=gcd(h,f)
--note that the gcd(h,f) will define the same ideal as f and h
ideal(f,h)==ideal(b)
--We can also define Quotient rings in one line
S=QQ[z,y]/(z^2-y^2,z-1)
S=QQ[x]/(x^4-23*x^3-34)
describe S