Examples of semigroups in cython¶
- class sage.categories.examples.semigroups_cython.IdempotentSemigroups[source]¶
Bases:
Category
- class ElementMethods¶
Bases:
object
- is_idempotent()[source]¶
EXAMPLES:
sage: from sage.categories.examples.semigroups_cython import LeftZeroSemigroup sage: S = LeftZeroSemigroup() sage: S(2).is_idempotent() True
>>> from sage.all import * >>> from sage.categories.examples.semigroups_cython import LeftZeroSemigroup >>> S = LeftZeroSemigroup() >>> S(Integer(2)).is_idempotent() True
- super_categories()[source]¶
EXAMPLES:
sage: from sage.categories.examples.semigroups_cython import IdempotentSemigroups sage: IdempotentSemigroups().super_categories() [Category of semigroups]
>>> from sage.all import * >>> from sage.categories.examples.semigroups_cython import IdempotentSemigroups >>> IdempotentSemigroups().super_categories() [Category of semigroups]
- class sage.categories.examples.semigroups_cython.LeftZeroSemigroup[source]¶
Bases:
LeftZeroSemigroup
An example of semigroup.
This class illustrates a minimal implementation of a semi-group where the element class is an extension type, and still gets code from the category. The category itself must be a Python class though.
This is purely a proof of concept. The code obviously needs refactorisation!
Comments:
one cannot play ugly class surgery tricks (as with _mul_parent). available operations should really be declared to the coercion model!
EXAMPLES:
sage: from sage.categories.examples.semigroups_cython import LeftZeroSemigroup sage: S = LeftZeroSemigroup(); S An example of a semigroup: the left zero semigroup
>>> from sage.all import * >>> from sage.categories.examples.semigroups_cython import LeftZeroSemigroup >>> S = LeftZeroSemigroup(); S An example of a semigroup: the left zero semigroup
This is the semigroup which contains all sort of objects:
sage: S.some_elements() [3, 42, 'a', 3.4, 'raton laveur']
>>> from sage.all import * >>> 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 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_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 * >>> S('hello') * S('world') 'hello' >>> S(Integer(3))*S(Integer(1))*S(Integer(2)) 3 >>> S(Integer(3))**Integer(12312321312321) 3 >>> TestSuite(S).run(verbose = True) running ._test_an_element() . . . pass running ._test_associativity() . . . 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
That’s really the only method which is obtained from the category …
sage: S(42).is_idempotent <bound method IdempotentSemigroups.ElementMethods.is_idempotent of 42> sage: S(42).is_idempotent() True sage: S(42)._pow_int <bound method IdempotentSemigroups.ElementMethods._pow_int of 42> sage: S(42)^10 42 sage: S(42).is_idempotent <bound method IdempotentSemigroups.ElementMethods.is_idempotent of 42> sage: S(42).is_idempotent() True
>>> from sage.all import * >>> S(Integer(42)).is_idempotent <bound method IdempotentSemigroups.ElementMethods.is_idempotent of 42> >>> S(Integer(42)).is_idempotent() True >>> S(Integer(42))._pow_int <bound method IdempotentSemigroups.ElementMethods._pow_int of 42> >>> S(Integer(42))**Integer(10) 42 >>> S(Integer(42)).is_idempotent <bound method IdempotentSemigroups.ElementMethods.is_idempotent of 42> >>> S(Integer(42)).is_idempotent() True
- Element[source]¶
alias of
LeftZeroSemigroupElement
- class sage.categories.examples.semigroups_cython.LeftZeroSemigroupElement[source]¶
Bases:
Element
EXAMPLES:
sage: from sage.categories.examples.semigroups_cython import LeftZeroSemigroup sage: S = LeftZeroSemigroup() sage: x = S(3) sage: TestSuite(x).run()
>>> from sage.all import * >>> from sage.categories.examples.semigroups_cython import LeftZeroSemigroup >>> S = LeftZeroSemigroup() >>> x = S(Integer(3)) >>> TestSuite(x).run()