Skip to content

Commit

Permalink
src/sage/groups/group_exp.py: In doctest, import GroupExpElement expl…
Browse files Browse the repository at this point in the history
…icitly; doctest cosmetics
  • Loading branch information
Matthias Koeppe committed Jun 19, 2024
1 parent 39442e7 commit a19d2de
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/sage/groups/group_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************

from sage.categories.commutative_additive_groups import CommutativeAdditiveGroups
from sage.categories.groups import Groups
from sage.structure.element import MultiplicativeGroupElement
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.categories.morphism import SetMorphism
from sage.categories.functor import Functor
from sage.categories.groups import Groups
from sage.categories.homset import Hom
from sage.categories.morphism import SetMorphism
from sage.structure.element import MultiplicativeGroupElement
from sage.structure.element_wrapper import ElementWrapper
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation


class GroupExp(Functor):
Expand Down Expand Up @@ -59,7 +60,7 @@ class GroupExp(Functor):
-3
sage: x.parent()
Multiplicative form of Integer Ring
sage: EZ(-1)*EZ(6) == EZ(5)
sage: EZ(-1) * EZ(6) == EZ(5)
True
sage: EZ(3)^(-1)
-3
Expand All @@ -77,9 +78,10 @@ class GroupExp(Functor):
....: return s2.action(mu)
sage: from sage.categories.morphism import SetMorphism
sage: from sage.categories.homset import Hom
sage: f = SetMorphism(Hom(L,L,CommutativeAdditiveGroups()), my_action)
sage: f = SetMorphism(Hom(L, L, CommutativeAdditiveGroups()), my_action)
sage: F = E(f); F
Generic endomorphism of Multiplicative form of Ambient space of the Root system of type ['A', 2]
Generic endomorphism of
Multiplicative form of Ambient space of the Root system of type ['A', 2]
sage: v = L.an_element(); v
(2, 2, 3)
sage: y = F(EL(v)); y
Expand Down Expand Up @@ -114,8 +116,8 @@ def _apply_functor(self, x):
OUTPUT: an isomorphic group whose operation is multiplication rather
than addition
In the following example, ``self`` is the functor `GroupExp()`,
`x` is the additive group `QQ^2`, and the output group is stored as `EQ2`.
In the following example, ``self`` is the functor ``GroupExp()``,
``x`` is the additive group ``QQ^2``, and the output group is stored as ``EQ2``.
EXAMPLES::
Expand Down Expand Up @@ -145,8 +147,6 @@ def _apply_functor_to_morphism(self, f):
OUTPUT: the above homomorphism, but between the corresponding
multiplicative groups
- The above homomorphism, but between the corresponding multiplicative groups.
In the following example, ``self`` is the functor :class:`GroupExp` and `f`
is an endomorphism of the additive group of integers.
Expand All @@ -156,22 +156,23 @@ def _apply_functor_to_morphism(self, f):
....: return x + x
sage: from sage.categories.morphism import SetMorphism
sage: from sage.categories.homset import Hom
sage: f = SetMorphism(Hom(ZZ,ZZ,CommutativeAdditiveGroups()),double)
sage: f = SetMorphism(Hom(ZZ, ZZ, CommutativeAdditiveGroups()), double)
sage: E = GroupExp()
sage: EZ = E._apply_functor(ZZ)
sage: F = E._apply_functor_to_morphism(f)
sage: F.domain() == EZ
True
sage: F.codomain() == EZ
True
sage: F(EZ(3)) == EZ(3)*EZ(3)
sage: F(EZ(3)) == EZ(3) * EZ(3)
True
"""
new_domain = self._apply_functor(f.domain())
new_codomain = self._apply_functor(f.codomain())
new_f = lambda a: new_codomain(f(a.value))
return SetMorphism(Hom(new_domain, new_codomain, Groups()), new_f)


class GroupExpElement(ElementWrapper, MultiplicativeGroupElement):
r"""
An element in the exponential of a commutative additive group.
Expand All @@ -184,13 +185,14 @@ class GroupExpElement(ElementWrapper, MultiplicativeGroupElement):
EXAMPLES::
sage: from sage.groups.group_exp import GroupExpElement
sage: G = QQ^2
sage: EG = GroupExp()(G)
sage: z = GroupExpElement(EG, vector(QQ, (1,-3))); z
sage: z = GroupExpElement(EG, vector(QQ, (1, -3))); z
(1, -3)
sage: z.parent()
Multiplicative form of Vector space of dimension 2 over Rational Field
sage: EG(vector(QQ,(1,-3)))==z
sage: EG(vector(QQ, (1, -3))) == z
True
"""
Expand All @@ -202,7 +204,7 @@ def __init__(self, parent, x):
sage: EG = GroupExp()(G)
sage: x = EG.an_element(); x
(1, 0)
sage: TestSuite(x).run(skip = "_test_category")
sage: TestSuite(x).run(skip="_test_category")
See the documentation of :meth:`sage.structure.element_wrapper.ElementWrapper.__init__`
for the reason behind skipping the category test.
Expand Down Expand Up @@ -233,7 +235,7 @@ def __mul__(self, x):
sage: x = G(2)
sage: x.__mul__(G(3))
5
sage: G.product(G(2),G(3))
sage: G.product(G(2), G(3))
5
"""
return GroupExpElement(self.parent(), self.value + x.value)
Expand All @@ -245,7 +247,7 @@ class GroupExp_Class(UniqueRepresentation, Parent):
INPUT:
- `G` -- a commutative additive group
- ``G`` -- a commutative additive group
OUTPUT: the multiplicative form of `G`
Expand All @@ -260,7 +262,7 @@ def __init__(self, G):
EXAMPLES::
sage: EG = GroupExp()(QQ^2)
sage: TestSuite(EG).run(skip = "_test_elements")
sage: TestSuite(EG).run(skip="_test_elements")
"""
if G not in CommutativeAdditiveGroups():
raise TypeError("%s must be a commutative additive group" % G)
Expand All @@ -286,7 +288,7 @@ def _element_constructor_(self, x):
EXAMPLES::
sage: G = GroupExp()(ZZ)
sage: G(4) # indirect doctest
sage: G(4) # indirect doctest
4
"""
return GroupExpElement(self, x)
Expand Down

0 comments on commit a19d2de

Please sign in to comment.