Examples of semirings

sage.categories.examples.semirings.Example[source]

alias of TernaryLogic

class sage.categories.examples.semirings.Ternary(parent, n)[source]

Bases: Element

Elements of the ternary-logic ring.

The semantic is as follows:

  • 0 – the integer 0

  • 1 – the integer 1

  • 2 – some integer greater than 1

An alternative semantic is:

  • 0 – an empty set

  • 1 – a connected set

  • 2 – a disconnected set

The same semantic works for graphs instead of sets.

class sage.categories.examples.semirings.TernaryLogic[source]

Bases: UniqueRepresentation, Parent

An example of a semiring.

This class illustrates a minimal implementation of a semiring.

EXAMPLES:

sage: S = Semirings().example(); S
An example of a semiring: the ternary-logic semiring
>>> from sage.all import *
>>> S = Semirings().example(); S
An example of a semiring: the ternary-logic semiring

This is the semiring that contains 3 objects:

sage: S.some_elements()
[0, 1, many]
>>> from sage.all import *
>>> S.some_elements()
[0, 1, many]

The product rule is as expected:

sage: S(1) * S(1)
1
sage: S(1) + S(1)
many
>>> from sage.all import *
>>> S(Integer(1)) * S(Integer(1))
1
>>> S(Integer(1)) + S(Integer(1))
many
Element[source]

alias of Ternary

an_element()[source]

Return an element of the semiring.

EXAMPLES:

sage: Semirings().example().an_element()
many
>>> from sage.all import *
>>> Semirings().example().an_element()
many
one()[source]

Return the unit of self.

EXAMPLES:

sage: S = Semirings().example()
sage: S.one()
1
>>> from sage.all import *
>>> S = Semirings().example()
>>> S.one()
1
product(x, y)[source]

Return the product of x and y in the semiring as per Semirings.ParentMethods.product().

EXAMPLES:

sage: S = Semirings().example()
sage: S(1) * S(2)
many
>>> from sage.all import *
>>> S = Semirings().example()
>>> S(Integer(1)) * S(Integer(2))
many
some_elements()[source]

Return a list of some elements of the semiring.

EXAMPLES:

sage: Semirings().example().some_elements()
[0, 1, many]
>>> from sage.all import *
>>> Semirings().example().some_elements()
[0, 1, many]
summation(x, y)[source]

Return the sum of x and y in the semiring as per Semirings.ParentMethods.summation().

EXAMPLES:

sage: S = Semirings().example()
sage: S(1) + S(1)
many
>>> from sage.all import *
>>> S = Semirings().example()
>>> S(Integer(1)) + S(Integer(1))
many