Sagebrush · Examples · Notebooks

Polynomials (Sage)

Factoring over ZZ and QQ, cyclotomic and Swinnerton-Dyer polynomials, roots and gcds.

notebook · Sage · course · by Sagebrush · MIT license

polynomialsalgebra

Download (ZIP)Source on GitHub

Preview

# Polynomials over ZZ and QQ, factored by Sagebrush's Rust engine (Zassenhaus with Hensel lifting)
R.<x> = ZZ[]
f = (x^4 - 1)*(2*x + 3)^2*(x^2 - x - 1)
f, f.factor()
(4*x^8 + 8*x^7 - 7*x^6 - 21*x^5 - 13*x^4 - 8*x^3 + 7*x^2 + 21*x + 9, (x - 1) * (x + 1) * (2*x + 3)^2 * (x^2 - x - 1) * (x^2 + 1))
factor(x^105 - 1)
(x - 1) * (x^2 + x + 1) * (x^4 + x^3 + x^2 + x + 1) * (x^6 + x^5 + x^4 + x^3 + x^2 + x + 1) * (x^8 - x^7 + x^5 - x^4 + x^3 - x + 1) * (x^12 - x^11 + x^9 - x^8 + x^6 - x^4 + x^3 - x + 1) * (x^24 - x^23 + x^19 - x^18 + x^17 - x^16 + x^14 - x^13 + x^12 - x^11 + x^10 - x^8 + x^7 - x^6 + x^5 - x + 1) * (x^48 + x^47 + x^46 - x^43 - x^42 - 2*x^41 - x^40 - x^39 + x^36 + x^35 + x^34 + x^33 + x^32 + x^31 - x^28 - x^26 - x^24 - x^22 - x^20 + x^17 + x^16 + x^15 + x^14 + x^13 + x^12 - x^9 - x^8 - 2*x^7 - x^6 - x^5 + x^2 + x + 1)
# The Swinnerton-Dyer polynomial for 2, 3, 5, 7: irreducible, but it splits modulo every prime
g = x^16 - 136*x^14 + 6476*x^12 - 141912*x^10 + 1513334*x^8 - 7453176*x^6 + 13950764*x^4 - 5596840*x^2 + 46225
g.is_irreducible(), factor(g.discriminant())
(True, 2^312 * 3^20 * 5^26 * 7^8 * 43^2 * 59^4)
S.<y> = QQ[]
h = (y^2 - 1/4)*(3*y + 2)
h.factor(), h.roots(), gcd(h, y^3 - 1/8)
((3) * (y - 1/2) * (y + 1/2) * (y + 2/3), [(1/2, 1), (-1/2, 1), (-2/3, 1)], y - 1/2)

Files

Open the ZIP's notebook in Sagebrush (File, Open) to run and change it.