Skip to content

Commit

Permalink
More robust doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Feb 5, 2024
1 parent 888eb3f commit 490ffcb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/sage/rings/finite_rings/hom_finite_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Construction of an embedding::
sage: f(t) # random
T^20 + 2*T^18 + T^16 + 2*T^13 + T^9 + 2*T^8 + T^7 + T^6 + T^5 + T^3 + 2*T^2 + T
sage: f(t) == f.im_gens()[0]
True
The map `f` has a method ``section`` which returns a partially defined
map which is the inverse of `f` on the image of `f`::
Expand All @@ -33,8 +35,9 @@ map which is the inverse of `f` on the image of `f`::
From: Finite Field in t of size 3^7
To: Finite Field in T of size 3^21
Defn: t |--> T^20 + 2*T^18 + T^16 + 2*T^13 + T^9 + 2*T^8 + T^7 + T^6 + T^5 + T^3 + 2*T^2 + T
sage: g(f(t^3+t^2+1))
t^3 + t^2 + 1
sage: a = k.random_element()
sage: g(f(a)) == a
True
sage: g(T)
Traceback (most recent call last):
...
Expand Down Expand Up @@ -130,8 +133,9 @@ cdef class SectionFiniteFieldHomomorphism_generic(Section):
sage: K.<T> = GF(3^21)
sage: f = FiniteFieldHomomorphism_generic(Hom(k, K))
sage: g = f.section()
sage: g(f(t^3+t^2+1))
t^3 + t^2 + 1
sage: a = k.random_element()
sage: g(f(a)) == a
True
sage: g(T)
Traceback (most recent call last):
Expand Down Expand Up @@ -207,6 +211,10 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens):
From: Finite Field in t of size 3^7
To: Finite Field in T of size 3^21
Defn: t |--> T^20 + 2*T^18 + T^16 + 2*T^13 + T^9 + 2*T^8 + T^7 + T^6 + T^5 + T^3 + 2*T^2 + T
sage: a = k.random_element()
sage: b = k.random_element()
sage: f(a) + f(b) == f(a + b)
True
sage: k.<t> = GF(3^6)
sage: K.<t> = GF(3^9)
Expand Down Expand Up @@ -373,8 +381,10 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens):
From: Finite Field in t of size 3^7
To: Finite Field in T of size 3^21
Defn: t |--> T^20 + 2*T^18 + T^16 + 2*T^13 + T^9 + 2*T^8 + T^7 + T^6 + T^5 + T^3 + 2*T^2 + T
sage: g(f(t^3+t^2+1))
t^3 + t^2 + 1
sage: a = k.random_element()
sage: b = k.random_element()
sage: g(f(a) + f(b)) == a + b
True
sage: g(T)
Traceback (most recent call last):
...
Expand Down Expand Up @@ -421,7 +431,7 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens):
sage: k.<t> = GF(5^3)
sage: Frob = k.frobenius_endomorphism()
sage: embed = Frob.fixed_field()[1]
sage: hash(embed) # random
sage: hash(embed) # random
-2441354824160407762
"""
return Morphism.__hash__(self)
Expand Down Expand Up @@ -760,6 +770,8 @@ cdef class FrobeniusEndomorphism_finite_field(FrobeniusEndomorphism_generic):
sage: tfixed = kfixed.gen()
sage: embed(tfixed) # random
4*t^5 + 2*t^4 + 4*t^2 + t
sage: embed(tfixed) == embed.im_gens()[0]
True
"""
if self._degree_fixed == 1:
k = FiniteField(self.domain().characteristic())
Expand Down
10 changes: 10 additions & 0 deletions src/sage/rings/finite_rings/hom_finite_field_givaro.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ cdef class SectionFiniteFieldHomomorphism_givaro(SectionFiniteFieldHomomorphism_
From: Finite Field in t of size 3^2
To: Finite Field in T of size 3^4
Defn: t |--> 2*T^3 + 2*T^2 + 1
sage: a = k.random_element()
sage: b = k.random_element()
sage: g(f(a) + f(b)) == g(f(a)) + g(f(b)) == a + b
True
"""
if not isinstance(inverse, FiniteFieldHomomorphism_givaro):
raise TypeError("The given map is not an instance of FiniteFieldHomomorphism_givaro")
Expand Down Expand Up @@ -145,6 +149,10 @@ cdef class FiniteFieldHomomorphism_givaro(FiniteFieldHomomorphism_generic):
From: Finite Field in t of size 3^2
To: Finite Field in T of size 3^4
Defn: t |--> 2*T^3 + 2*T^2 + 1
sage: a = k.random_element()
sage: b = k.random_element()
sage: f(a) + f(b) == f(a + b)
True
sage: k.<t> = GF(3^10)
sage: K.<T> = GF(3^20)
Expand Down Expand Up @@ -184,6 +192,8 @@ cdef class FiniteFieldHomomorphism_givaro(FiniteFieldHomomorphism_generic):
sage: f = FiniteFieldHomomorphism_givaro(Hom(k, K))
sage: f(t) # random
2*T^3 + 2*T^2 + 1
sage: f(t) == f.im_gens()[0]
True
"""
if x.parent() != self.domain():
raise TypeError("%s is not in %s" % (x, self.domain()))
Expand Down

0 comments on commit 490ffcb

Please sign in to comment.