Coverage for local/lib/python2.7/site-packages/sage/categories/examples/semigroups.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" Examples of 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/ #*****************************************************************************
r""" An example of a semigroup.
This class illustrates a minimal implementation of a semigroup.
EXAMPLES::
sage: S = Semigroups().example(); S An example of a semigroup: the left zero semigroup
This is the semigroup that contains all sorts of objects::
sage: S.some_elements() [3, 42, 'a', 3.4, 'raton laveur']
with product rule given by $a \times b = a$ for all $a, b$::
sage: S('hello') * S('world') 'hello' sage: S(3)*S(1)*S(2) 3 sage: S(3)^12312321312321 3
TESTS::
sage: TestSuite(S).run(verbose = True) running ._test_an_element() . . . pass running ._test_associativity() . . . pass running ._test_cardinality() . . . 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_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 """ r""" The left zero semigroup
EXAMPLES::
sage: S = Semigroups().example(); S An example of a semigroup: the left zero semigroup
TESTS::
sage: TestSuite(S).run()
"""
r"""
EXAMPLES::
sage: Semigroups().example()._repr_() 'An example of a semigroup: the left zero semigroup'
"""
r""" Returns the product of ``x`` and ``y`` in the semigroup, as per :meth:`Semigroups.ParentMethods.product`.
EXAMPLES::
sage: S = Semigroups().example() sage: S('hello') * S('world') 'hello' sage: S(3)*S(1)*S(2) 3
"""
r""" Returns an element of the semigroup.
EXAMPLES::
sage: Semigroups().example().an_element() 42
"""
r""" Returns a list of some elements of the semigroup.
EXAMPLES::
sage: Semigroups().example().some_elements() [3, 42, 'a', 3.4, 'raton laveur']
"""
r""" Trivial implementation of ``Semigroups.Element.is_idempotent`` since all elements of this semigroup are idempotent!
EXAMPLES::
sage: S = Semigroups().example() sage: S.an_element().is_idempotent() True sage: S(17).is_idempotent() True
"""
r""" An example of semigroup.
The purpose of this class is to provide a minimal template for implementing of a semigroup.
EXAMPLES::
sage: S = Semigroups().example("free"); S An example of a semigroup: the free semigroup generated by ('a', 'b', 'c', 'd')
This is the free semigroup generated by::
sage: S.semigroup_generators() Family ('a', 'b', 'c', 'd')
and with product given by concatenation::
sage: S('dab') * S('acb') 'dabacb'
TESTS::
sage: TestSuite(S).run() """ r""" The free semigroup.
INPUT:
- ``alphabet`` -- a tuple of strings: the generators of the semigroup
EXAMPLES::
sage: from sage.categories.examples.semigroups import FreeSemigroup sage: F = FreeSemigroup(('a','b','c')); F An example of a semigroup: the free semigroup generated by ('a', 'b', 'c')
TESTS::
sage: F == loads(dumps(F)) True
"""
r""" EXAMPLES::
sage: from sage.categories.examples.semigroups import FreeSemigroup sage: FreeSemigroup(('a','b','c'))._repr_() "An example of a semigroup: the free semigroup generated by ('a', 'b', 'c')"
"""
r""" Returns the product of ``x`` and ``y`` in the semigroup, as per :meth:`Semigroups.ParentMethods.product`.
EXAMPLES::
sage: F = Semigroups().example('free') sage: F.an_element() * F('a')^5 'abcdaaaaa'
"""
def semigroup_generators(self): r""" Returns the generators of the semigroup.
EXAMPLES::
sage: F = Semigroups().example('free') sage: F.semigroup_generators() Family ('a', 'b', 'c', 'd')
"""
r""" Returns an element of the semigroup.
EXAMPLES::
sage: F = Semigroups().example('free') sage: F.an_element() 'abcd'
"""
r""" Construct an element of this semigroup from the data ``x``.
INPUT:
- ``x`` -- a string
EXAMPLES::
sage: F = Semigroups().example('free'); F An example of a semigroup: the free semigroup generated by ('a', 'b', 'c', 'd') sage: F._element_constructor_('a') 'a' sage: F._element_constructor_('bad') 'bad'
TESTS::
sage: F._element_constructor_('z') Traceback (most recent call last): ... assert a in self.alphabet AssertionError sage: bad = F._element_constructor_('bad'); bad 'bad' sage: bad in F True
sage: S = Semigroups().Subquotients().example() sage: type(S._element_constructor_(17)) <class 'sage.categories.examples.semigroups.QuotientOfLeftZeroSemigroup_with_category.element_class'>
"""
r""" The class for elements of the free semigroup. """
r""" Example of a quotient semigroup
EXAMPLES::
sage: S = Semigroups().Subquotients().example(); S An example of a (sub)quotient semigroup: a quotient of the left zero semigroup
This is the quotient of::
sage: S.ambient() An example of a semigroup: the left zero semigroup
obtained by setting `x=42` for any `x\geq 42`::
sage: S(100) 42 sage: S(100) == S(42) True
The product is inherited from the ambient semigroup::
sage: S(1)*S(2) == S(1) True
TESTS::
sage: TestSuite(S).run(verbose = True) running ._test_an_element() . . . pass running ._test_associativity() . . . pass running ._test_cardinality() . . . 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_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 """ r""" Convert ``x`` into an element of this semigroup.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: S._element_constructor_(17) 17
TESTS::
sage: S = Semigroups().Subquotients().example() sage: type(S._element_constructor_(17)) <class 'sage.categories.examples.semigroups.QuotientOfLeftZeroSemigroup_with_category.element_class'>
"""
r""" This quotient of the left zero semigroup of integers obtained by setting `x=42` for any `x\geq 42`.
EXAMPLES::
sage: S = Semigroups().Subquotients().example(); S An example of a (sub)quotient semigroup: a quotient of the left zero semigroup sage: S.ambient() An example of a semigroup: the left zero semigroup sage: S(100) 42 sage: S(100) == S(42) True sage: S(1)*S(2) == S(1) True
TESTS::
sage: TestSuite(S).run() """
r"""
EXAMPLES::
sage: Semigroups().Subquotients().example()._repr_() 'An example of a (sub)quotient semigroup: a quotient of the left zero semigroup'
"""
r""" Returns the ambient semigroup.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: S.ambient() An example of a semigroup: the left zero semigroup
"""
r""" Lift the element ``x`` into the ambient semigroup.
INPUT:
- ``x`` -- an element of ``self``.
OUTPUT:
- an element of ``self.ambient()``.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: x = S.an_element(); x 42 sage: S.lift(x) 42 sage: S.lift(x) in S.ambient() True sage: y = S.ambient()(100); y 100 sage: S.lift(S(y)) 42
"""
r""" Returns the Answer to Life, the Universe, and Everything as an element of this semigroup.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: S.the_answer() 42
"""
r""" Returns an element of the semigroup.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: S.an_element() 42
"""
r""" Returns a list of some elements of the semigroup.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: S.some_elements() [1, 2, 3, 8, 42, 42]
""" for i in [1, 2, 3, 8, 42, 100]]
r""" Returns the retract ``x`` onto an element of this semigroup.
INPUT:
- ``x`` -- an element of the ambient semigroup (``self.ambient()``).
OUTPUT:
- an element of ``self``.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: L = S.ambient() sage: S.retract(L(17)) 17 sage: S.retract(L(42)) 42 sage: S.retract(L(171)) 42
TESTS::
sage: S.retract(L(171)) in S True
""" else:
r""" An incompletely implemented subquotient semigroup, for testing purposes
EXAMPLES::
sage: S = sage.categories.examples.semigroups.IncompleteSubquotientSemigroup() sage: S A subquotient of An example of a semigroup: the left zero semigroup
TESTS::
sage: S._test_not_implemented_methods() Traceback (most recent call last): ... AssertionError: Not implemented method: lift
sage: TestSuite(S).run(verbose = True) running ._test_an_element() . . . pass running ._test_associativity() . . . fail Traceback (most recent call last): ... NotImplementedError: <abstract method retract at ...> ------------------------------------------------------------ running ._test_cardinality() . . . 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_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() . . . fail Traceback (most recent call last): ... AssertionError: Not implemented method: lift ------------------------------------------------------------ running ._test_pickling() . . . pass running ._test_some_elements() . . . pass The following tests failed: _test_associativity, _test_not_implemented_methods """
r""" Returns the ambient semigroup.
EXAMPLES::
sage: S = Semigroups().Subquotients().example() sage: S.ambient() An example of a semigroup: the left zero semigroup
"""
|