Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/monoids/monoid.py
4056 views
1
r"""
2
Monoids
3
"""
4
5
from sage.structure.parent import Parent
6
from sage.misc.cachefunc import cached_method
7
8
def is_Monoid(x):
9
r"""
10
Returns True if ``x`` is of type ``Monoid_class``.
11
12
EXAMPLES::
13
14
sage: from sage.monoids.monoid import is_Monoid
15
sage: is_Monoid(0)
16
False
17
sage: is_Monoid(ZZ) # The technical math meaning of monoid has
18
... # no bearing whatsoever on the result: it's
19
... # a typecheck which is not satisfied by ZZ
20
... # since it does not inherit from Monoid_class.
21
False
22
sage: is_Monoid(sage.monoids.monoid.Monoid_class(('a','b')))
23
True
24
sage: F.<a,b,c,d,e> = FreeMonoid(5)
25
sage: is_Monoid(F)
26
True
27
"""
28
return isinstance(x, Monoid_class)
29
30
class Monoid_class(Parent):
31
def __init__(self,names):
32
r"""
33
EXAMPLES::
34
35
sage: from sage.monoids.monoid import Monoid_class
36
sage: Monoid_class(('a','b'))
37
<class 'sage.monoids.monoid.Monoid_class_with_category'>
38
39
TESTS::
40
41
sage: F.<a,b,c,d,e> = FreeMonoid(5)
42
sage: TestSuite(F).run()
43
"""
44
from sage.categories.monoids import Monoids
45
Parent.__init__(self, base=self,names=names,category=Monoids())
46
47
@cached_method
48
def gens(self):
49
r"""
50
Returns the generators for ``self``.
51
52
EXAMPLES::
53
54
sage: F.<a,b,c,d,e> = FreeMonoid(5)
55
sage: F.gens()
56
(a, b, c, d, e)
57
"""
58
return tuple(self.gen(i) for i in range(self.ngens()))
59
60