Examples of commutative additive semigroups¶
- sage.categories.examples.commutative_additive_semigroups.Example[source]¶
- alias of - FreeCommutativeAdditiveSemigroup
- class sage.categories.examples.commutative_additive_semigroups.FreeCommutativeAdditiveSemigroup(alphabet=('a', 'b', 'c', 'd'))[source]¶
- Bases: - UniqueRepresentation,- Parent- An example of a commutative additive monoid: the free commutative monoid. - This class illustrates a minimal implementation of a commutative additive monoid. - EXAMPLES: - sage: S = CommutativeAdditiveSemigroups().example(); S An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') sage: S.category() Category of commutative additive semigroups - >>> from sage.all import * >>> S = CommutativeAdditiveSemigroups().example(); S An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') >>> S.category() Category of commutative additive semigroups - This is the free semigroup generated by: - sage: S.additive_semigroup_generators() Family (a, b, c, d) - >>> from sage.all import * >>> S.additive_semigroup_generators() Family (a, b, c, d) - with product rule given by \(a \times b = a\) for all \(a, b\): - sage: (a,b,c,d) = S.additive_semigroup_generators() - >>> from sage.all import * >>> (a,b,c,d) = S.additive_semigroup_generators() - We conclude by running systematic tests on this commutative monoid: - sage: TestSuite(S).run(verbose = True) running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_cardinality() . . . pass running ._test_category() . . . pass running ._test_construction() . . . pass running ._test_elements() . . . Running the test suite of self.an_element() running ._test_category() . . . pass running ._test_eq() . . . pass running ._test_new() . . . 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_eq() . . . pass running ._test_new() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass running ._test_some_elements() . . . pass - >>> from sage.all import * >>> TestSuite(S).run(verbose = True) running ._test_additive_associativity() . . . pass running ._test_an_element() . . . pass running ._test_cardinality() . . . pass running ._test_category() . . . pass running ._test_construction() . . . pass running ._test_elements() . . . Running the test suite of self.an_element() running ._test_category() . . . pass running ._test_eq() . . . pass running ._test_new() . . . 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_eq() . . . pass running ._test_new() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass running ._test_some_elements() . . . pass - class Element(parent, iterable)[source]¶
- Bases: - ElementWrapper- EXAMPLES: - sage: F = CommutativeAdditiveSemigroups().example() sage: x = F.element_class(F, (('a',4), ('b', 0), ('a', 2), ('c', 1), ('d', 5))) sage: x 2*a + c + 5*d sage: x.value {'a': 2, 'b': 0, 'c': 1, 'd': 5} sage: x.parent() An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - >>> from sage.all import * >>> F = CommutativeAdditiveSemigroups().example() >>> x = F.element_class(F, (('a',Integer(4)), ('b', Integer(0)), ('a', Integer(2)), ('c', Integer(1)), ('d', Integer(5)))) >>> x 2*a + c + 5*d >>> x.value {'a': 2, 'b': 0, 'c': 1, 'd': 5} >>> x.parent() An example of a commutative semigroup: the free commutative semigroup generated by ('a', 'b', 'c', 'd') - Internally, elements are represented as dense dictionaries which associate to each generator of the monoid its multiplicity. In order to get an element, we wrap the dictionary into an element via - ElementWrapper:- sage: x.value {'a': 2, 'b': 0, 'c': 1, 'd': 5} - >>> from sage.all import * >>> x.value {'a': 2, 'b': 0, 'c': 1, 'd': 5} 
 - additive_semigroup_generators()[source]¶
- Return the generators of the semigroup. - EXAMPLES: - sage: F = CommutativeAdditiveSemigroups().example() sage: F.additive_semigroup_generators() Family (a, b, c, d) - >>> from sage.all import * >>> F = CommutativeAdditiveSemigroups().example() >>> F.additive_semigroup_generators() Family (a, b, c, d) 
 - an_element()[source]¶
- Return an element of the semigroup. - EXAMPLES: - sage: F = CommutativeAdditiveSemigroups().example() sage: F.an_element() a + 2*b + 3*c + 4*d - >>> from sage.all import * >>> F = CommutativeAdditiveSemigroups().example() >>> F.an_element() a + 2*b + 3*c + 4*d 
 - summation(x, y)[source]¶
- Return the product of - xand- yin the semigroup, as per- CommutativeAdditiveSemigroups.ParentMethods.summation().- EXAMPLES: - sage: F = CommutativeAdditiveSemigroups().example() sage: (a,b,c,d) = F.additive_semigroup_generators() sage: F.summation(a,b) a + b sage: (a+b) + (a+c) 2*a + b + c - >>> from sage.all import * >>> F = CommutativeAdditiveSemigroups().example() >>> (a,b,c,d) = F.additive_semigroup_generators() >>> F.summation(a,b) a + b >>> (a+b) + (a+c) 2*a + b + c