-- Working with univariate polynomials R = QQ[x]; f = 2*x^4 + x^3 - x^2 + 3 g = 2*x^2 - 3*x -- To apply the division algorithm to find q,r with f=qg+r q = f // g r = f % g -- Check: q*g + r f == q*g + r -- -- Warning: The binary operators / and // do different things! -- a = (x^2 - 1) // (x+3) -- quotient without remainder b = (x^2 - 1) / (x+3) -- quotient as a rational function numerator(b) denominator(b) -- They given different results even when there is no remainder! a = (x^2 - 1) // (x-1) b = (x^2 - 1) / (x-1) a == b class(a) -- a is a POLYNOMIAL in R=QQ[x] class(b) -- b is a RATIONAL FUNCTION numerator(b) denominator(b) numerator(a) -- this gives an error -- this takes a rational function that with denominator 1 -- and considers is it as a polynomial in R c = lift(b,R) class(c) -- -- Polynomials gcds -- We can find the gcd of two polynomials: f = (x-2) * (x^2 + 1) * (x-3) g = (x+1) * (x-3) * (x-2) h = gcd(g,f) h == (x-3) * (x-2) -- -- Other things we can do with univariate polynomials. -- -- We can factor a polynomial. f = x^4-2*x^3-7*x^2+20*x-12 factor(f) -- If we demand rational coefficients, we cannot always factor completely. -- There may be some irreducible factors. g = x^12-1 factor(g) -- We can find (approximate) roots over the complex numbers, though. -- We even get the multiplicities right! froots = roots(f) groots = roots(g) -- You can access members of a list using the # sign. -- Every list starts with a "zeroth" element in Macaulay2. froots#0 froots#3 -- We will not systematically learn how to factor polynomials over QQ -- or how to find their roots numerically in this course. -- Nevertheless, it is nice to know it can be done!