Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions src/sage/monoids/automatic_semigroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
sage: [ x.lift() for x in M.list() ]
[1, 3, 5, 9]

sage: G = M.cayley_graph(side = "twosided"); G
sage: # needs sage.graphs
sage: G = M.cayley_graph(side="twosided"); G
Looped multi-digraph on 4 vertices
sage: G.edges(sort=True, key=str)
[([1, 1], [1, 1], (2, 'left')),
Expand All @@ -142,14 +143,16 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
sage: M.j_transversal_of_idempotents()
[[1, 1], []]

sage: list(map(attrcall('pseudo_order'), M.list()))
sage: list(map(attrcall('pseudo_order'), M.list())) # needs sage.graphs
[[1, 0], [3, 1], [2, 0], [2, 1]]

We can also use it to get submonoids from groups. We check that in the
symmetric group, a transposition and a long cycle generate the whole group::

sage: # needs sage.groups
sage: G5 = SymmetricGroup(5)
sage: N = AutomaticSemigroup(Family({1: G5([2,1,3,4,5]), 2: G5([2,3,4,5,1])}), one=G5.one())
sage: N = AutomaticSemigroup(Family({1: G5([2,1,3,4,5]), 2: G5([2,3,4,5,1])}),
....: one=G5.one())
sage: N.repr_element_method("reduced_word")
sage: N.cardinality() == G5.cardinality()
True
Expand All @@ -161,23 +164,26 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
We can also create a semigroup of matrices, where we define the
multiplication as matrix multiplication::

sage: M1=matrix([[0,0,1],[1,0,0],[0,1,0]])
sage: M2=matrix([[0,0,0],[1,1,0],[0,0,1]])
sage: # needs sage.modules
sage: M1 = matrix([[0,0,1],[1,0,0],[0,1,0]])
sage: M2 = matrix([[0,0,0],[1,1,0],[0,0,1]])
sage: M1.set_immutable()
sage: M2.set_immutable()
sage: def prod_m(x,y):
....: z=x*y
....: z.set_immutable()
....: return z
sage: Mon = AutomaticSemigroup([M1,M2], mul=prod_m, category=Monoids().Finite().Subobjects())
sage: Mon = AutomaticSemigroup([M1,M2], mul=prod_m,
....: category=Monoids().Finite().Subobjects())
sage: Mon.cardinality()
24
sage: C = Mon.cayley_graph()
sage: C.is_directed_acyclic()
sage: C = Mon.cayley_graph() # needs sage.graphs
sage: C.is_directed_acyclic() # needs sage.graphs
False

Let us construct and play with the 0-Hecke Monoid::

sage: # needs sage.graphs sage.modules
sage: W = WeylGroup(['A',4]); W.rename("W")
sage: ambient_monoid = FiniteSetMaps(W, action="right")
sage: pi = W.simple_projections(length_increasing=True).map(ambient_monoid)
Expand All @@ -199,9 +205,9 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
We check that the 0-Hecke monoid is `J`-trivial and contains `2^4`
idempotents::

sage: len(M.idempotents())
sage: len(M.idempotents()) # needs sage.graphs sage.modules
16
sage: all(len(j) == 1 for j in M.j_classes())
sage: all(len(j) == 1 for j in M.j_classes()) # needs sage.graphs sage.modules
True

TESTS::
Expand All @@ -210,9 +216,9 @@ class AutomaticSemigroup(UniqueRepresentation, Parent):
True
sage: g[1] == g[1]*g[1]*g[1]
True
sage: M.__class__
sage: M.__class__ # needs sage.graphs sage.modules
<class 'sage.monoids.automatic_semigroup.AutomaticMonoid_with_category'>
sage: TestSuite(M).run()
sage: TestSuite(M).run() # needs sage.graphs sage.modules

sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
sage: R = IntegerModRing(34)
Expand Down Expand Up @@ -263,7 +269,10 @@ def __classcall_private__(cls, generators, ambient=None, one=None, mul=operator.
sage: M.ambient() == R
True
sage: AutomaticSemigroup((0,)).category()
Join of Category of finitely generated semigroups and Category of subquotients of semigroups and Category of commutative magmas and Category of subobjects of sets
Join of Category of finitely generated semigroups
and Category of subquotients of semigroups
and Category of commutative magmas
and Category of subobjects of sets
sage: AutomaticSemigroup((0,), one=1).category()
Join of Category of subquotients of monoids and
Category of commutative monoids and
Expand All @@ -279,8 +288,8 @@ def __classcall_private__(cls, generators, ambient=None, one=None, mul=operator.
sage: AutomaticSemigroup((0,), one=0, mul=operator.add).category()
Join of Category of monoids and Category of subobjects of sets

sage: S5 = SymmetricGroup(5)
sage: AutomaticSemigroup([S5((1,2))]).category()
sage: S5 = SymmetricGroup(5) # needs sage.groups
sage: AutomaticSemigroup([S5((1,2))]).category() # needs sage.groups
Join of Category of finite groups and
Category of subquotients of monoids and
Category of finite finitely generated semigroups and
Expand Down Expand Up @@ -400,8 +409,9 @@ def _repr_(self):
sage: AutomaticSemigroup(Family({1: R(3), 2: R(5)}), mul=operator.add, one=R.zero())
A semigroup with 2 generators

sage: S5 = SymmetricGroup(5); S5.rename("S5")
sage: AutomaticSemigroup(Family({1: S5((1,2))}), category=Groups().Finite().Subobjects())
sage: S5 = SymmetricGroup(5); S5.rename("S5") # needs sage.groups
sage: AutomaticSemigroup(Family({1: S5((1,2))}), # needs sage.groups
....: category=Groups().Finite().Subobjects())
A subgroup of (S5) with 1 generators
"""
categories = [Groups(), Monoids(), Semigroups()]
Expand Down Expand Up @@ -468,8 +478,9 @@ def ambient(self):
sage: M.ambient()
Ring of integers modulo 12

sage: M1=matrix([[0,0,1],[1,0,0],[0,1,0]])
sage: M2=matrix([[0,0,0],[1,1,0],[0,0,1]])
sage: # needs sage.modules
sage: M1 = matrix([[0,0,1],[1,0,0],[0,1,0]])
sage: M2 = matrix([[0,0,0],[1,1,0],[0,0,1]])
sage: M1.set_immutable()
sage: M2.set_immutable()
sage: def prod_m(x,y):
Expand All @@ -488,9 +499,11 @@ def retract(self, ambient_element, check=True):

EXAMPLES::

sage: # needs sage.groups
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
sage: S5 = SymmetricGroup(5); S5.rename("S5")
sage: M = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}), one=S5.one())
sage: M = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}),
....: one=S5.one())
sage: m = M.retract(S5((3,1))); m
(1,3)
sage: m.parent() is M
Expand All @@ -504,7 +517,7 @@ def retract(self, ambient_element, check=True):

TESTS::

sage: len(M._retract.cache.keys())
sage: len(M._retract.cache.keys()) # needs sage.groups
24
"""
element = self._retract(ambient_element)
Expand All @@ -527,14 +540,15 @@ def _retract(self, ambient_element):
EXAMPLES::

sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
sage: S5 = SymmetricGroup(5)
sage: S4 = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}), one=S5.one())
sage: S4._retract(S5((3,1)))
sage: S5 = SymmetricGroup(5) # needs sage.groups
sage: S4 = AutomaticSemigroup(Family({1:S5((1,2)), 2:S5((1,2,3,4))}), # needs sage.groups
....: one=S5.one())
sage: S4._retract(S5((3,1))) # needs sage.groups
(1,3)

No check is done::

sage: S4._retract(S5((4,5)))
sage: S4._retract(S5((4,5))) # needs sage.groups
(4,5)
"""
return self.element_class(self, ambient_element)
Expand Down Expand Up @@ -769,9 +783,11 @@ def from_reduced_word(self, l):

EXAMPLES::

sage: # needs sage.groups
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
sage: G4 = SymmetricGroup(4)
sage: M = AutomaticSemigroup(Family({1:G4((1,2)), 2:G4((1,2,3,4))}), one=G4.one())
sage: M = AutomaticSemigroup(Family({1:G4((1,2)), 2:G4((1,2,3,4))}),
....: one=G4.one())
sage: M.from_reduced_word([2, 1, 2, 2, 1]).lift()
(1,3)
sage: M.from_reduced_word([2, 1, 2, 2, 1]) == M.retract(G4((3,1)))
Expand All @@ -784,7 +800,7 @@ def from_reduced_word(self, l):

def construct(self, up_to=None, n=None):
"""
Construct the elements of the ``self``.
Construct the elements of ``self``.

INPUT:

Expand All @@ -800,6 +816,7 @@ def construct(self, up_to=None, n=None):

EXAMPLES::

sage: # needs sage.groups sage.modules
sage: from sage.monoids.automatic_semigroup import AutomaticSemigroup
sage: W = WeylGroup(['A',3]); W.rename("W")
sage: ambient_monoid = FiniteSetMaps(W, action="right")
Expand Down
9 changes: 5 additions & 4 deletions src/sage/monoids/free_monoid_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def _latex_(self) -> str:

Check that :issue:`14509` is fixed::

sage: # needs sage.symbolic
sage: K.< alpha,b > = FreeAlgebra(SR)
sage: latex(alpha*b)
\alpha b
Expand Down Expand Up @@ -171,14 +172,14 @@ def __call__(self, *x, **kwds):
"""
EXAMPLES::

sage: M.<x,y,z>=FreeMonoid(3)
sage: M.<x,y,z> = FreeMonoid(3)
sage: (x*y).subs(x=1,y=2,z=14)
2
sage: (x*y).subs({x:z,y:z})
z^2
sage: M1=MatrixSpace(ZZ,1,2)
sage: M2=MatrixSpace(ZZ,2,1)
sage: (x*y).subs({x:M1([1,2]),y:M2([3,4])})
sage: M1 = MatrixSpace(ZZ,1,2) # needs sage.modules
sage: M2 = MatrixSpace(ZZ,2,1) # needs sage.modules
sage: (x*y).subs({x: M1([1,2]), y: M2([3,4])}) # needs sage.modules
[11]

sage: M.<x,y> = FreeMonoid(2)
Expand Down
1 change: 1 addition & 0 deletions src/sage/monoids/hecke_monoid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.groups
"""
Hecke Monoids
"""
Expand Down
1 change: 1 addition & 0 deletions src/sage/monoids/monoid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.combinat
r"""
Monoids
"""
Expand Down
8 changes: 5 additions & 3 deletions src/sage/monoids/string_monoid_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

# import operator
from sage.misc.lazy_import import lazy_import
from sage.rings.integer import Integer
from sage.rings.real_mpfr import RealField
from .free_monoid_element import FreeMonoidElement
from sage.structure.richcmp import richcmp

lazy_import('sage.rings.real_mpfr', 'RealField')

from .free_monoid_element import FreeMonoidElement


def is_StringMonoidElement(x):
r"""
Expand Down
5 changes: 4 additions & 1 deletion src/sage/monoids/string_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.rings.real_mpfr import RealField
from sage.misc.lazy_import import lazy_import

lazy_import('sage.rings.real_mpfr', 'RealField')

from .string_monoid_element import StringMonoidElement


Expand Down
Loading