Skip to content

Commit d5ba867

Browse files
author
Release Manager
committed
gh-38143: `sage.monoids`: Modularization fixes, `# needs` <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> - Cherry-picked from #35095. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #38143 Reported by: Matthias Köppe Reviewer(s): David Coudert
2 parents 2b74a38 + 5dda70f commit d5ba867

File tree

7 files changed

+77
-53
lines changed

7 files changed

+77
-53
lines changed

src/sage/monoids/automatic_semigroup.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
116116
sage: [ x.lift() for x in M.list() ]
117117
[1, 3, 5, 9]
118118
119-
sage: G = M.cayley_graph(side = "twosided"); G
119+
sage: # needs sage.graphs
120+
sage: G = M.cayley_graph(side="twosided"); G
120121
Looped multi-digraph on 4 vertices
121122
sage: G.edges(sort=True, key=str)
122123
[([1, 1], [1, 1], (2, 'left')),
@@ -142,14 +143,16 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
142143
sage: M.j_transversal_of_idempotents()
143144
[[1, 1], []]
144145
145-
sage: list(map(attrcall('pseudo_order'), M.list()))
146+
sage: list(map(attrcall('pseudo_order'), M.list())) # needs sage.graphs
146147
[[1, 0], [3, 1], [2, 0], [2, 1]]
147148
148149
We can also use it to get submonoids from groups. We check that in the
149150
symmetric group, a transposition and a long cycle generate the whole group::
150151
152+
sage: # needs sage.groups
151153
sage: G5 = SymmetricGroup(5)
152-
sage: N = AutomaticSemigroup(Family({1: G5([2,1,3,4,5]), 2: G5([2,3,4,5,1])}), one=G5.one())
154+
sage: N = AutomaticSemigroup(Family({1: G5([2,1,3,4,5]), 2: G5([2,3,4,5,1])}),
155+
....: one=G5.one())
153156
sage: N.repr_element_method("reduced_word")
154157
sage: N.cardinality() == G5.cardinality()
155158
True
@@ -161,23 +164,26 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
161164
We can also create a semigroup of matrices, where we define the
162165
multiplication as matrix multiplication::
163166
164-
sage: M1=matrix([[0,0,1],[1,0,0],[0,1,0]])
165-
sage: M2=matrix([[0,0,0],[1,1,0],[0,0,1]])
167+
sage: # needs sage.modules
168+
sage: M1 = matrix([[0,0,1],[1,0,0],[0,1,0]])
169+
sage: M2 = matrix([[0,0,0],[1,1,0],[0,0,1]])
166170
sage: M1.set_immutable()
167171
sage: M2.set_immutable()
168172
sage: def prod_m(x,y):
169173
....: z=x*y
170174
....: z.set_immutable()
171175
....: return z
172-
sage: Mon = AutomaticSemigroup([M1,M2], mul=prod_m, category=Monoids().Finite().Subobjects())
176+
sage: Mon = AutomaticSemigroup([M1,M2], mul=prod_m,
177+
....: category=Monoids().Finite().Subobjects())
173178
sage: Mon.cardinality()
174179
24
175-
sage: C = Mon.cayley_graph()
176-
sage: C.is_directed_acyclic()
180+
sage: C = Mon.cayley_graph() # needs sage.graphs
181+
sage: C.is_directed_acyclic() # needs sage.graphs
177182
False
178183
179184
Let us construct and play with the 0-Hecke Monoid::
180185
186+
sage: # needs sage.graphs sage.modules
181187
sage: W = WeylGroup(['A',4]); W.rename("W")
182188
sage: ambient_monoid = FiniteSetMaps(W, action="right")
183189
sage: pi = W.simple_projections(length_increasing=True).map(ambient_monoid)
@@ -199,9 +205,9 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
199205
We check that the 0-Hecke monoid is `J`-trivial and contains `2^4`
200206
idempotents::
201207
202-
sage: len(M.idempotents())
208+
sage: len(M.idempotents()) # needs sage.graphs sage.modules
203209
16
204-
sage: all(len(j) == 1 for j in M.j_classes())
210+
sage: all(len(j) == 1 for j in M.j_classes()) # needs sage.graphs sage.modules
205211
True
206212
207213
TESTS::
@@ -210,9 +216,9 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
210216
True
211217
sage: g[1] == g[1]*g[1]*g[1]
212218
True
213-
sage: M.__class__
219+
sage: M.__class__ # needs sage.graphs sage.modules
214220
<class 'sage.monoids.automatic_semigroup.AutomaticMonoid_with_category'>
215-
sage: TestSuite(M).run()
221+
sage: TestSuite(M).run() # needs sage.graphs sage.modules
216222
217223
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
218224
sage: R = IntegerModRing(34)
@@ -263,7 +269,10 @@ def __classcall_private__(cls, generators, ambient=None, one=None, mul=operator.
263269
sage: M.ambient() == R
264270
True
265271
sage: AutomaticSemigroup((0,)).category()
266-
Join of Category of finitely generated semigroups and Category of subquotients of semigroups and Category of commutative magmas and Category of subobjects of sets
272+
Join of Category of finitely generated semigroups
273+
and Category of subquotients of semigroups
274+
and Category of commutative magmas
275+
and Category of subobjects of sets
267276
sage: AutomaticSemigroup((0,), one=1).category()
268277
Join of Category of subquotients of monoids and
269278
Category of commutative monoids and
@@ -279,8 +288,8 @@ def __classcall_private__(cls, generators, ambient=None, one=None, mul=operator.
279288
sage: AutomaticSemigroup((0,), one=0, mul=operator.add).category()
280289
Join of Category of monoids and Category of subobjects of sets
281290
282-
sage: S5 = SymmetricGroup(5)
283-
sage: AutomaticSemigroup([S5((1,2))]).category()
291+
sage: S5 = SymmetricGroup(5) # needs sage.groups
292+
sage: AutomaticSemigroup([S5((1,2))]).category() # needs sage.groups
284293
Join of Category of finite groups and
285294
Category of subquotients of monoids and
286295
Category of finite finitely generated semigroups and
@@ -400,8 +409,9 @@ def _repr_(self):
400409
sage: AutomaticSemigroup(Family({1: R(3), 2: R(5)}), mul=operator.add, one=R.zero())
401410
A semigroup with 2 generators
402411
403-
sage: S5 = SymmetricGroup(5); S5.rename("S5")
404-
sage: AutomaticSemigroup(Family({1: S5((1,2))}), category=Groups().Finite().Subobjects())
412+
sage: S5 = SymmetricGroup(5); S5.rename("S5") # needs sage.groups
413+
sage: AutomaticSemigroup(Family({1: S5((1,2))}), # needs sage.groups
414+
....: category=Groups().Finite().Subobjects())
405415
A subgroup of (S5) with 1 generators
406416
"""
407417
categories = [Groups(), Monoids(), Semigroups()]
@@ -468,8 +478,9 @@ def ambient(self):
468478
sage: M.ambient()
469479
Ring of integers modulo 12
470480
471-
sage: M1=matrix([[0,0,1],[1,0,0],[0,1,0]])
472-
sage: M2=matrix([[0,0,0],[1,1,0],[0,0,1]])
481+
sage: # needs sage.modules
482+
sage: M1 = matrix([[0,0,1],[1,0,0],[0,1,0]])
483+
sage: M2 = matrix([[0,0,0],[1,1,0],[0,0,1]])
473484
sage: M1.set_immutable()
474485
sage: M2.set_immutable()
475486
sage: def prod_m(x,y):
@@ -488,9 +499,11 @@ def retract(self, ambient_element, check=True):
488499
489500
EXAMPLES::
490501
502+
sage: # needs sage.groups
491503
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
492504
sage: S5 = SymmetricGroup(5); S5.rename("S5")
493-
sage: M = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}), one=S5.one())
505+
sage: M = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}),
506+
....: one=S5.one())
494507
sage: m = M.retract(S5((3,1))); m
495508
(1,3)
496509
sage: m.parent() is M
@@ -504,7 +517,7 @@ def retract(self, ambient_element, check=True):
504517
505518
TESTS::
506519
507-
sage: len(M._retract.cache.keys())
520+
sage: len(M._retract.cache.keys()) # needs sage.groups
508521
24
509522
"""
510523
element = self._retract(ambient_element)
@@ -527,14 +540,15 @@ def _retract(self, ambient_element):
527540
EXAMPLES::
528541
529542
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
530-
sage: S5 = SymmetricGroup(5)
531-
sage: S4 = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}), one=S5.one())
532-
sage: S4._retract(S5((3,1)))
543+
sage: S5 = SymmetricGroup(5) # needs sage.groups
544+
sage: S4 = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}), # needs sage.groups
545+
....: one=S5.one())
546+
sage: S4._retract(S5((3,1))) # needs sage.groups
533547
(1,3)
534548
535549
No check is done::
536550
537-
sage: S4._retract(S5((4,5)))
551+
sage: S4._retract(S5((4,5))) # needs sage.groups
538552
(4,5)
539553
"""
540554
return self.element_class(self, ambient_element)
@@ -769,9 +783,11 @@ def from_reduced_word(self, l):
769783
770784
EXAMPLES::
771785
786+
sage: # needs sage.groups
772787
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
773788
sage: G4 = SymmetricGroup(4)
774-
sage: M = AutomaticSemigroup(Family({1:G4((1,2)), 2:G4((1,2,3,4))}), one=G4.one())
789+
sage: M = AutomaticSemigroup(Family({1:G4((1,2)), 2:G4((1,2,3,4))}),
790+
....: one=G4.one())
775791
sage: M.from_reduced_word([2, 1, 2, 2, 1]).lift()
776792
(1,3)
777793
sage: M.from_reduced_word([2, 1, 2, 2, 1]) == M.retract(G4((3,1)))
@@ -784,7 +800,7 @@ def from_reduced_word(self, l):
784800

785801
def construct(self, up_to=None, n=None):
786802
"""
787-
Construct the elements of the ``self``.
803+
Construct the elements of ``self``.
788804
789805
INPUT:
790806
@@ -800,6 +816,7 @@ def construct(self, up_to=None, n=None):
800816
801817
EXAMPLES::
802818
819+
sage: # needs sage.groups sage.modules
803820
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
804821
sage: W = WeylGroup(['A',3]); W.rename("W")
805822
sage: ambient_monoid = FiniteSetMaps(W, action="right")

src/sage/monoids/free_monoid_element.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def _latex_(self) -> str:
144144
145145
Check that :issue:`14509` is fixed::
146146
147+
sage: # needs sage.symbolic
147148
sage: K.< alpha,b > = FreeAlgebra(SR)
148149
sage: latex(alpha*b)
149150
\alpha b
@@ -171,14 +172,14 @@ def __call__(self, *x, **kwds):
171172
"""
172173
EXAMPLES::
173174
174-
sage: M.<x,y,z>=FreeMonoid(3)
175+
sage: M.<x,y,z> = FreeMonoid(3)
175176
sage: (x*y).subs(x=1,y=2,z=14)
176177
2
177178
sage: (x*y).subs({x:z,y:z})
178179
z^2
179-
sage: M1=MatrixSpace(ZZ,1,2)
180-
sage: M2=MatrixSpace(ZZ,2,1)
181-
sage: (x*y).subs({x:M1([1,2]),y:M2([3,4])})
180+
sage: M1 = MatrixSpace(ZZ,1,2) # needs sage.modules
181+
sage: M2 = MatrixSpace(ZZ,2,1) # needs sage.modules
182+
sage: (x*y).subs({x: M1([1,2]), y: M2([3,4])}) # needs sage.modules
182183
[11]
183184
184185
sage: M.<x,y> = FreeMonoid(2)

src/sage/monoids/hecke_monoid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.groups
12
"""
23
Hecke Monoids
34
"""

src/sage/monoids/monoid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.combinat
12
r"""
23
Monoids
34
"""

src/sage/monoids/string_monoid_element.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
# https://www.gnu.org/licenses/
2121
# ****************************************************************************
2222

23-
# import operator
23+
from sage.misc.lazy_import import lazy_import
2424
from sage.rings.integer import Integer
25-
from sage.rings.real_mpfr import RealField
26-
from .free_monoid_element import FreeMonoidElement
2725
from sage.structure.richcmp import richcmp
2826

27+
lazy_import('sage.rings.real_mpfr', 'RealField')
28+
29+
from .free_monoid_element import FreeMonoidElement
30+
2931

3032
def is_StringMonoidElement(x):
3133
r"""

src/sage/monoids/string_ops.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
# https://www.gnu.org/licenses/
99
# ****************************************************************************
1010

11-
from sage.rings.real_mpfr import RealField
11+
from sage.misc.lazy_import import lazy_import
12+
13+
lazy_import('sage.rings.real_mpfr', 'RealField')
14+
1215
from .string_monoid_element import StringMonoidElement
1316

1417

0 commit comments

Comments
 (0)