forked from sagemath/sage
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadditive_monoids.py
95 lines (75 loc) · 3.44 KB
/
additive_monoids.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
# sage_setup: distribution = sagemath-categories
r"""
Additive monoids
"""
#*****************************************************************************
# Copyright (C) 2013-2014 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.lazy_import import LazyImport
from sage.categories.category_with_axiom import CategoryWithAxiom_singleton
from sage.categories.additive_semigroups import AdditiveSemigroups
from sage.categories.homsets import HomsetsCategory
class AdditiveMonoids(CategoryWithAxiom_singleton):
"""
The category of additive monoids.
An *additive monoid* is a unital :class:`additive semigroup
<sage.categories.additive_semigroups.AdditiveSemigroups>`, that
is a set endowed with a binary operation `+` which is associative
and admits a zero (see :wikipedia:`Monoid`).
EXAMPLES::
sage: from sage.categories.additive_monoids import AdditiveMonoids
sage: C = AdditiveMonoids(); C
Category of additive monoids
sage: C.super_categories()
[Category of additive unital additive magmas, Category of additive semigroups]
sage: sorted(C.axioms())
['AdditiveAssociative', 'AdditiveUnital']
sage: from sage.categories.additive_semigroups import AdditiveSemigroups
sage: C is AdditiveSemigroups().AdditiveUnital()
True
TESTS::
sage: C.Algebras(QQ).is_subcategory(AlgebrasWithBasis(QQ))
True
sage: TestSuite(C).run()
"""
_base_category_class_and_axiom = (AdditiveSemigroups, "AdditiveUnital")
AdditiveCommutative = LazyImport('sage.categories.commutative_additive_monoids', 'CommutativeAdditiveMonoids', at_startup=True)
AdditiveInverse = LazyImport('sage.categories.additive_groups', 'AdditiveGroups', at_startup=True)
class ParentMethods:
def sum(self, args):
r"""
Return the sum of the elements in ``args``, as an element
of ``self``.
INPUT:
- ``args`` -- a list (or iterable) of elements of ``self``
EXAMPLES::
sage: S = CommutativeAdditiveMonoids().example()
sage: (a,b,c,d) = S.additive_semigroup_generators()
sage: S.sum((a,b,a,c,a,b))
3*a + 2*b + c
sage: S.sum(())
0
sage: S.sum(()).parent() == S
True
"""
return sum(args, self.zero())
class Homsets(HomsetsCategory):
def extra_super_categories(self):
"""
Implement the fact that a homset between two monoids is
associative.
EXAMPLES::
sage: from sage.categories.additive_monoids import AdditiveMonoids
sage: AdditiveMonoids().Homsets().extra_super_categories()
[Category of additive semigroups]
sage: AdditiveMonoids().Homsets().super_categories()
[Category of homsets of additive unital additive magmas, Category of additive monoids]
.. TODO::
This could be deduced from
:meth:`AdditiveSemigroups.Homsets.extra_super_categories`.
See comment in :meth:`Objects.SubcategoryMethods.Homsets`.
"""
return [AdditiveSemigroups()]