Skip to content

Commit

Permalink
sage.rings: Align # optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Apr 8, 2023
1 parent c1721ab commit a0e7176
Show file tree
Hide file tree
Showing 25 changed files with 1,970 additions and 1,899 deletions.
197 changes: 99 additions & 98 deletions src/sage/rings/polynomial/polynomial_element_generic.py

Large diffs are not rendered by default.

821 changes: 417 additions & 404 deletions src/sage/rings/polynomial/polynomial_quotient_ring.py

Large diffs are not rendered by default.

135 changes: 68 additions & 67 deletions src/sage/rings/polynomial/polynomial_quotient_ring_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@
::
sage: R.<x> = ZZ[]
sage: S.<a> = R.quotient(x^3 + 3*x - 1) # optional - sage.libs.pari
sage: 2 * a^3 # optional - sage.libs.pari
sage: S.<a> = R.quotient(x^3 + 3*x - 1) # optional - sage.libs.pari
sage: 2 * a^3 # optional - sage.libs.pari
-6*a + 2
Next we make a univariate polynomial ring over
`\ZZ[x]/(x^3+3x-1)`.
::
sage: S1.<y> = S[] # optional - sage.libs.pari
sage: S1.<y> = S[] # optional - sage.libs.pari
And, we quotient out that by `y^2 + a`.
::
sage: T.<z> = S1.quotient(y^2 + a) # optional - sage.libs.pari
sage: T.<z> = S1.quotient(y^2 + a) # optional - sage.libs.pari
In the quotient `z^2` is `-a`.
::
sage: z^2 # optional - sage.libs.pari
sage: z^2 # optional - sage.libs.pari
-a
And since `a^3 = -3x + 1`, we have::
sage: z^6 # optional - sage.libs.pari
sage: z^6 # optional - sage.libs.pari
3*a - 1
::
Expand All @@ -47,7 +47,7 @@
::
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3-2)
sage: S.<a> = R.quotient(x^3 - 2)
sage: a
a
sage: a^3
Expand Down Expand Up @@ -97,7 +97,7 @@ class PolynomialQuotientRingElement(polynomial_singular_interface.Polynomial_sin
EXAMPLES::
sage: P.<x> = QQ[]
sage: Q.<xi> = P.quo([(x^2+1)])
sage: Q.<xi> = P.quo([(x^2 + 1)])
sage: xi^2
-1
sage: singular(xi)
Expand Down Expand Up @@ -162,15 +162,15 @@ def _im_gens_(self, codomain, im_gens, base_map=None):
EXAMPLES::
sage: Zx.<x> = ZZ[]
sage: K.<i> = NumberField(x^2 + 1) # optional - sage.rings.number_field
sage: cc = K.hom([-i]) # optional - sage.rings.number_field
sage: S.<y> = K[] # optional - sage.rings.number_field
sage: Q.<q> = S.quotient(y^2*(y-1)*(y-i)) # optional - sage.rings.number_field
sage: T.<t> = S.quotient(y*(y+1)) # optional - sage.rings.number_field
sage: phi = Q.hom([t+1], base_map=cc) # optional - sage.rings.number_field
sage: phi(q) # optional - sage.rings.number_field
sage: K.<i> = NumberField(x^2 + 1) # optional - sage.rings.number_field
sage: cc = K.hom([-i]) # optional - sage.rings.number_field
sage: S.<y> = K[] # optional - sage.rings.number_field
sage: Q.<q> = S.quotient(y^2*(y-1)*(y-i)) # optional - sage.rings.number_field
sage: T.<t> = S.quotient(y*(y+1)) # optional - sage.rings.number_field
sage: phi = Q.hom([t+1], base_map=cc) # optional - sage.rings.number_field
sage: phi(q) # optional - sage.rings.number_field
t + 1
sage: phi(i*q) # optional - sage.rings.number_field
sage: phi(i*q) # optional - sage.rings.number_field
-i*t - i
"""
return self._polynomial._im_gens_(codomain, im_gens, base_map=base_map)
Expand Down Expand Up @@ -271,7 +271,7 @@ def _add_(self, right):
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3-2)
sage: S.<a> = R.quotient(x^3 - 2)
sage: (a^2 - 4) + (a+2)
a^2 + a - 2
sage: int(1) + a
Expand All @@ -287,7 +287,7 @@ def _div_(self, right):
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3-2)
sage: S.<a> = R.quotient(x^3 - 2)
sage: (a^2 - 4) / (a+2)
a - 2
"""
Expand All @@ -304,7 +304,7 @@ def _richcmp_(self, other, op):
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3-2)
sage: S.<a> = R.quotient(x^3 - 2)
sage: (a^2 - 4) / (a+2) == a - 2
True
sage: a^2 - 4 == a
Expand All @@ -322,7 +322,7 @@ def __int__(self):
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3-2)
sage: S.<a> = R.quotient(x^3 - 2)
sage: int(S(10))
10
sage: int(a)
Expand Down Expand Up @@ -469,51 +469,51 @@ def field_extension(self, names):
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: S.<alpha> = R.quotient(x^3-2)
sage: F.<a>, f, g = alpha.field_extension()
sage: F
sage: S.<alpha> = R.quotient(x^3 - 2)
sage: F.<a>, f, g = alpha.field_extension() # optional - sage.rings.number_field
sage: F # optional - sage.rings.number_field
Number Field in a with defining polynomial x^3 - 2
sage: a = F.gen()
sage: f(alpha)
sage: a = F.gen() # optional - sage.rings.number_field
sage: f(alpha) # optional - sage.rings.number_field
a
sage: g(a)
sage: g(a) # optional - sage.rings.number_field
alpha
Over a finite field, the corresponding field extension is not a
number field::
sage: R.<x> = GF(25,'b')['x']
sage: S.<a> = R.quo(x^3 + 2*x + 1)
sage: F.<b>, g, h = a.field_extension()
sage: h(b^2 + 3)
sage: R.<x> = GF(25,'b')['x'] # optional - sage.rings.finite_rings
sage: S.<a> = R.quo(x^3 + 2*x + 1) # optional - sage.rings.finite_rings
sage: F.<b>, g, h = a.field_extension() # optional - sage.rings.finite_rings
sage: h(b^2 + 3) # optional - sage.rings.finite_rings
a^2 + 3
sage: g(x^2 + 2)
sage: g(x^2 + 2) # optional - sage.rings.finite_rings
b^2 + 2
We do an example involving a relative number field::
sage: R.<x> = QQ['x']
sage: K.<a> = NumberField(x^3-2)
sage: S.<X> = K['X']
sage: Q.<b> = S.quo(X^3 + 2*X + 1)
sage: F, g, h = b.field_extension('c')
sage: K.<a> = NumberField(x^3 - 2) # optional - sage.rings.number_field
sage: S.<X> = K['X'] # optional - sage.rings.number_field
sage: Q.<b> = S.quo(X^3 + 2*X + 1) # optional - sage.rings.number_field
sage: F, g, h = b.field_extension('c') # optional - sage.rings.number_field
Another more awkward example::
sage: R.<x> = QQ['x']
sage: K.<a> = NumberField(x^3-2)
sage: S.<X> = K['X']
sage: f = (X+a)^3 + 2*(X+a) + 1
sage: f
sage: K.<a> = NumberField(x^3 - 2) # optional - sage.rings.number_field
sage: S.<X> = K['X'] # optional - sage.rings.number_field
sage: f = (X+a)^3 + 2*(X+a) + 1 # optional - sage.rings.number_field
sage: f # optional - sage.rings.number_field
X^3 + 3*a*X^2 + (3*a^2 + 2)*X + 2*a + 3
sage: Q.<z> = S.quo(f)
sage: F.<w>, g, h = z.field_extension()
sage: c = g(z)
sage: f(c)
sage: Q.<z> = S.quo(f) # optional - sage.rings.number_field
sage: F.<w>, g, h = z.field_extension() # optional - sage.rings.number_field
sage: c = g(z) # optional - sage.rings.number_field
sage: f(c) # optional - sage.rings.number_field
0
sage: h(g(z))
sage: h(g(z)) # optional - sage.rings.number_field
z
sage: g(h(w))
sage: g(h(w)) # optional - sage.rings.number_field
w
AUTHORS:
Expand Down Expand Up @@ -694,37 +694,37 @@ def minpoly(self):
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3 + 2*x - 5)
sage: (a+123).minpoly()
sage: (a + 123).minpoly()
x^3 - 369*x^2 + 45389*x - 1861118
sage: (a+123).matrix().minpoly()
sage: (a + 123).matrix().minpoly()
x^3 - 369*x^2 + 45389*x - 1861118
One useful application of this function is to compute a minimal
polynomial of a finite-field element over an intermediate extension,
rather than the absolute minimal polynomial over the prime field::
sage: F2.<i> = GF((431,2), modulus=[1,0,1])
sage: F6.<u> = F2.extension(3)
sage: (u+1).minpoly()
sage: F2.<i> = GF((431,2), modulus=[1,0,1]) # optional - sage.rings.finite_rings
sage: F6.<u> = F2.extension(3) # optional - sage.rings.finite_rings
sage: (u + 1).minpoly() # optional - sage.rings.finite_rings
x^6 + 425*x^5 + 19*x^4 + 125*x^3 + 189*x^2 + 239*x + 302
sage: ext = F6.over(F2)
sage: ext(u+1).minpoly() # indirect doctest
sage: ext = F6.over(F2) # optional - sage.rings.finite_rings
sage: ext(u + 1).minpoly() # indirect doctest # optional - sage.rings.finite_rings
x^3 + (396*i + 428)*x^2 + (80*i + 39)*x + 9*i + 178
TESTS:
We make sure that the previous example works on random examples::
sage: p = random_prime(50)
sage: K.<u> = GF((p, randrange(1,20)))
sage: L.<v> = K.extension(randrange(2,20))
sage: LK = L.over(K)
sage: a = L.random_element()
sage: poly = LK(a).minpoly() # indirect doctest
sage: poly(a)
sage: K.<u> = GF((p, randrange(1,20))) # optional - sage.rings.finite_rings
sage: L.<v> = K.extension(randrange(2,20)) # optional - sage.rings.finite_rings
sage: LK = L.over(K) # optional - sage.rings.finite_rings
sage: a = L.random_element() # optional - sage.rings.finite_rings
sage: poly = LK(a).minpoly() # indirect doctest # optional - sage.rings.finite_rings
sage: poly(a) # optional - sage.rings.finite_rings
0
sage: abs_deg = a.minpoly().degree()
sage: poly.degree() == abs_deg // gcd(abs_deg, K.degree())
sage: abs_deg = a.minpoly().degree() # optional - sage.rings.finite_rings
sage: poly.degree() == abs_deg // gcd(abs_deg, K.degree()) # optional - sage.rings.finite_rings
True
"""
poly = self.lift()
Expand All @@ -742,7 +742,7 @@ def norm(self):
EXAMPLES::
sage: R.<x> = PolynomialRing(QQ)
sage: S.<a> = R.quotient(x^3 -389*x^2 + 2*x - 5)
sage: S.<a> = R.quotient(x^3 - 389*x^2 + 2*x - 5)
sage: a.norm()
5
"""
Expand Down Expand Up @@ -772,13 +772,14 @@ def rational_reconstruction(self, *args, **kwargs):
EXAMPLES::
sage: R.<x> = GF(65537)[] # optional - sage.libs.pari
sage: m = (x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 + 17496*x^6 # optional - sage.libs.pari
....: + 30348*x^5 + 7440*x^4 + 65438*x^3 + 7676*x^2 + 54266*x + 47805)
sage: f = (20437*x^10 + 62630*x^9 + 63241*x^8 + 12820*x^7 + 42171*x^6 # optional - sage.libs.pari
sage: R.<x> = GF(65537)[] # optional - sage.rings.finite_rings
sage: m = (x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 # optional - sage.rings.finite_rings
....: + 17496*x^6 + 30348*x^5 + 7440*x^4 + 65438*x^3 + 7676*x^2
....: + 54266*x + 47805)
sage: f = (20437*x^10 + 62630*x^9 + 63241*x^8 + 12820*x^7 + 42171*x^6 # optional - sage.rings.finite_rings
....: + 63091*x^5 + 15288*x^4 + 32516*x^3 + 2181*x^2 + 45236*x + 2447)
sage: f_mod_m = R.quotient(m)(f) # optional - sage.libs.pari
sage: f_mod_m.rational_reconstruction() # optional - sage.libs.pari
sage: f_mod_m = R.quotient(m)(f) # optional - sage.rings.finite_rings
sage: f_mod_m.rational_reconstruction() # optional - sage.rings.finite_rings
(51388*x^5 + 29141*x^4 + 59341*x^3 + 7034*x^2 + 14152*x + 23746,
x^5 + 15208*x^4 + 19504*x^3 + 20457*x^2 + 11180*x + 28352)
"""
Expand Down
Loading

0 comments on commit a0e7176

Please sign in to comment.