This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
finite_semigroups.py
185 lines (143 loc) · 6.02 KB
/
finite_semigroups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"""
Examples of finite semigroups
"""
#*****************************************************************************
# Copyright (C) 2008-2009 Nicolas M. Thiery <nthiery at users.sf.net>
#
# Distributed under the terms of the GNU General Public License (GPL)
# http://www.gnu.org/licenses/
#******************************************************************************
from sage.misc.cachefunc import cached_method
from sage.sets.family import Family
from sage.categories.semigroups import Semigroups
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.element_wrapper import ElementWrapper
class LeftRegularBand(UniqueRepresentation, Parent):
r"""
An example of a finite semigroup
This class provides a minimal implementation of a finite semigroup.
EXAMPLES::
sage: S = FiniteSemigroups().example(); S
An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd')
This is the semigroup generated by::
sage: S.semigroup_generators()
Family ('a', 'b', 'c', 'd')
such that `x^2 = x` and `x y x = xy` for any `x` and `y` in `S`::
sage: S('dab')
'dab'
sage: S('dab') * S('acb')
'dabc'
It follows that the elements of `S` are strings without
repetitions over the alphabet `a`, `b`, `c`, `d`::
sage: S.list()
['a', 'c', 'b', 'bd', 'bda', 'd', 'bdc', 'bc', 'bcd', 'cb',
'ca', 'ac', 'cba', 'ba', 'cbd', 'bdca', 'db', 'dc', 'cd',
'bdac', 'ab', 'abd', 'da', 'ad', 'cbad', 'acb', 'abc',
'abcd', 'acbd', 'cda', 'cdb', 'dac', 'dba', 'dbc', 'dbca',
'dcb', 'abdc', 'cdab', 'bcda', 'dab', 'acd', 'dabc', 'cbda',
'bca', 'dacb', 'bad', 'adb', 'bac', 'cab', 'adc', 'cdba',
'dca', 'cad', 'adbc', 'adcb', 'dbac', 'dcba', 'acdb', 'bacd',
'cabd', 'cadb', 'badc', 'bcad', 'dcab']
It also follows that there are finitely many of them::
sage: S.cardinality()
64
Indeed::
sage: 4 * ( 1 + 3 * (1 + 2 * (1 + 1)))
64
As expected, all the elements of `S` are idempotents::
sage: all( x.is_idempotent() for x in S )
True
Now, let us look at the structure of the semigroup::
sage: S = FiniteSemigroups().example(alphabet = ('a','b','c'))
sage: S.cayley_graph(side="left", simple=True).plot()
Graphics object consisting of 60 graphics primitives
sage: S.j_transversal_of_idempotents() # random (arbitrary choice)
['acb', 'ac', 'ab', 'bc', 'a', 'c', 'b']
We conclude by running systematic tests on this semigroup::
sage: TestSuite(S).run(verbose = True)
running ._test_an_element() . . . pass
running ._test_associativity() . . . pass
running ._test_category() . . . pass
running ._test_elements() . . .
Running the test suite of self.an_element()
running ._test_category() . . . pass
running ._test_eq() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . pass
pass
running ._test_elements_eq_reflexive() . . . pass
running ._test_elements_eq_symmetric() . . . pass
running ._test_elements_eq_transitive() . . . pass
running ._test_elements_neq() . . . pass
running ._test_enumerated_set_contains() . . . pass
running ._test_enumerated_set_iter_cardinality() . . . pass
running ._test_enumerated_set_iter_list() . . . pass
running ._test_eq() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . pass
running ._test_some_elements() . . . pass
"""
def __init__(self, alphabet=('a','b','c','d')):
r"""
A left regular band.
EXAMPLES::
sage: S = FiniteSemigroups().example(); S
An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd')
sage: S = FiniteSemigroups().example(alphabet=('x','y')); S
An example of a finite semigroup: the left regular band generated by ('x', 'y')
sage: TestSuite(S).run()
"""
self.alphabet = alphabet
Parent.__init__(self, category = Semigroups().Finite().FinitelyGenerated())
def _repr_(self):
r"""
TESTS::
sage: S = FiniteSemigroups().example()
sage: S._repr_()
"An example of a finite semigroup: the left regular band generated by ('a', 'b', 'c', 'd')"
"""
return "An example of a finite semigroup: the left regular band generated by %s"%(self.alphabet,)
def product(self, x, y):
r"""
Returns the product of two elements of the semigroup.
EXAMPLES::
sage: S = FiniteSemigroups().example()
sage: S('a') * S('b')
'ab'
sage: S('a') * S('b') * S('a')
'ab'
sage: S('a') * S('a')
'a'
"""
assert x in self
assert y in self
x = x.value
y = y.value
return self(x + ''.join(c for c in y if c not in x))
@cached_method
def semigroup_generators(self):
r"""
Returns the generators of the semigroup.
EXAMPLES::
sage: S = FiniteSemigroups().example(alphabet=('x','y'))
sage: S.semigroup_generators()
Family ('x', 'y')
"""
return Family([self(i) for i in self.alphabet])
def an_element(self):
r"""
Returns an element of the semigroup.
EXAMPLES::
sage: S = FiniteSemigroups().example()
sage: S.an_element()
'cdab'
sage: S = FiniteSemigroups().example(("b"))
sage: S.an_element()
'b'
"""
return self(''.join(self.alphabet[2:]+self.alphabet[0:2]))
class Element (ElementWrapper):
wrapped_class = str
__lt__ = ElementWrapper._lt_by_value
Example = LeftRegularBand