// Construction of of Polynomial Rings and Quotients of them
Z := Integers();
// The tells Magma the variable that you want to use in
// the polynomial ring.
P := PolynomialRing(Z);
// Now here are some elements of P.
f := x^2+ 1; g := x^2+3*x+1;
// Note that the following is not allowed since Magma doesn't know who
// y is.
y^2+y;
// Try doing some arithmetic with f and g.
f-2; g*f;
// You can evaluate f at an integer, or at another algebraic expression.
Evaluate(f, 3); Evaluate(f, x^2); Evaluate(f, g);
// If you need to make a polynomial with several coefficients, just
// write the coefficients as a list and coerce it into P using ! .
h := P ! [ 0, 1, 2, 3, 4, 5, 7];
//******************************************
// You can also access data about a polynomial;
k := f^22;
Coefficients(k);
LeadingTerm(k);
LeadingCoefficient(k);
Degree(k);
// And compute GCD etc.
b := GCD(x^2+3* x^2 + 3*x + 2, x^3 + x^2- 3*x-2);
(x^2+3* x^2 + 3*x + 2)/b;
a, b := Quotrem(g, f);
//*********************************************
// The Gaussian integers are next. We take the quotient of Z[x] by the
// polynomial x^2 + 1;
// We will use i for the equivalence class of x.
R* := quo< P | f >;
i^2;
// Magma will automatically coerce f to be a polynomial over R
Evaluate(f,i);
// When something lives in P and you want to use it's image in R, use
// the coercion operator, ! .
R ! x; R ! x^2; R ! f;
IsIntegralDomain(R);
IsUnit(i);
IsField(R);
//************************************************
// Now let's take the quotient by a polynomial that is not irreducible.
g := x^2-1;
S := quo< P | g>;
j^2;
(j-1)*(j+1);
j^5-j^2+2;
IsIntegralDomain(S);
IsZeroDivisor(j-1);
*