Standard Semirings
Release 10.4

The Sage Development TeamJul 23, 2024

CONTENTS

1

Non Negative Integer Semiring

12

Tropical Semirings

33

Indices and Tables

9Python Module Index

11Index13i

ii

CHAPTERONENON NEGATIVE INTEGER SEMIRING

class
sage.rings.semirings.non_negative_integer_semiring.NonNegativeIntegerSemiring
Bases: NonNegativeIntegers
A class for the semiring of the non negative integers
This parent inherits from the infinite enumerated set of non negative integers and endows it with its natural semiring
structure.
EXAMPLES:
sage: NonNegativeIntegerSemiring()
Non negative integer semiring>>> from sage.all import *>>> NonNegativeIntegerSemiring()
Non negative integer semiring

For convenience, NN is a shortcut for NonNegativeIntegerSemiring():sage: NN == NonNegativeIntegerSemiring()True
sage: NN.category()
Category of facade infinite enumerated commutative semirings>>> from sage.all import *>>> NN == NonNegativeIntegerSemiring()
True>>> NN.category()
Category of facade infinite enumerated commutative semirings

Here is a piece of the Cayley graph for the multiplicative structure:sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7])
˓→needs sage.graphs
sage: G˓→needs sage.graphs
Looped multi-digraph on 9 vertices
sage: G.plot()
˓→needs sage.graphs sage.plot
Graphics object consisting of 48 graphics primitives

#␣
#␣

#␣

1

Standard Semirings, Release 10.4>>> from sage.all import *>>> G = NN.cayley_graph(elements=range(Integer(9)), generators=[Integer(0),˓→Integer(1),Integer(2),Integer(3),Integer(5),Integer(7)])# needs sage.
˓→graphs>>> G#␣˓→needs sage.graphs
Looped multi-digraph on 9 vertices>>> G.plot()#␣˓→needs sage.graphs sage.plot
Graphics object consisting of 48 graphics primitives

This is the Hasse diagram of the divisibility order on NN.
sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() # needs sage.combinat sage.graphs sage.plot
Note: as for NonNegativeIntegers, NN is currently just a “facade” parent; namely its elements are plain
Sage Integers with Integer Ring as parent:
sage: x = NN(15); type(x)<class sage.rings.integer.Integer >sage: x.parent()
Integer Ringsage: x+3
18>>> from sage.all import *>>> x = NN(Integer(15)); type(x)<class sage.rings.integer.Integer >>>> x.parent()
Integer Ring>>> x+Integer(3)18additive_semigroup_generators()
Returns the additive semigroup generators of self.
EXAMPLES:
sage: NN.additive_semigroup_generators()
Family (0, 1)>>> from sage.all import *>>> NN.additive_semigroup_generators()
Family (0, 1)

2

Chapter 1. Non Negative Integer Semiring

CHAPTERTWO

TROPICAL SEMIRINGSAUTHORS:• Travis Scrimshaw (2013-04-28) - Initial version
class sage.rings.semirings.tropical_semiring.TropicalSemiring(base, use_min=True)
Bases: Parent, UniqueRepresentation
The tropical semiring.
Given an ordered additive semigroup 𝑅, we define the tropical semiring 𝑇 = 𝑅 ∪ {+∞} by defining tropical
addition and multiplication as follows:𝑎 ⊕ 𝑏 = min(𝑎, 𝑏),𝑎 ⊙ 𝑏 = 𝑎 + 𝑏.

In particular, note that there are no (tropical) additive inverses (except for ∞), and every element in 𝑅 has a(tropical) multiplicative inverse.
There is an alternative definition where we define 𝑇 = 𝑅 ∪ {−∞} and alter tropical addition to be defined by𝑎 ⊕ 𝑏 = max(𝑎, 𝑏).
To use the max definition, set the argument use_min = False.
Warning: zero() and one() refer to the tropical additive and multiplicative identities respectively. These
are not the same as calling T(0) and T(1) respectively as these are not the tropical additive and multiplicativeidentities respectively.
Specifically do not use sum(...) as this converts 0 to 0 as a tropical element, which is not the same aszero(). Instead use the sum method of the tropical semiring:sage: T = TropicalSemiring(QQ)
sage: sum([T(1), T(2)]) # This is wrong
0sage: T.sum([T(1), T(2)]) # This is correct1>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> sum([T(Integer(1)), T(Integer(2))]) # This is wrong0>>> T.sum([T(Integer(1)), T(Integer(2))]) # This is correct
1Be careful about using code that has not been checked for tropical safety.

3

Standard Semirings, Release 10.4

INPUT:• base – the base ordered additive semigroup 𝑅• use_min – (default: True) if True, then the semiring uses 𝑎 ⊕ 𝑏 = min(𝑎, 𝑏); otherwise uses 𝑎 ⊕ 𝑏 =max(𝑎, 𝑏)
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: elt = T(2); elt
2>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> elt = T(Integer(2)); elt
2

Recall that tropical addition is the minimum of two elements:
sage: T(3) + T(5)3>>> from sage.all import *>>> T(Integer(3)) + T(Integer(5))
3Tropical multiplication is the addition of two elements:
sage: T(2) * T(3)5sage: T(0) * T(-2)-2>>> from sage.all import *>>> T(Integer(2)) * T(Integer(3))
5>>> T(Integer(0)) * T(-Integer(2))-2

We can also do tropical division and arbitrary tropical exponentiation:
sage: T(2) / T(1)1sage: T(2)^(-3/7)-6/7>>> from sage.all import *>>> T(Integer(2)) / T(Integer(1))
1>>> T(Integer(2))**(-Integer(3)/Integer(7))-6/7Note that “zero” and “one” are the additive and multiplicative identities of the tropical semiring. In general, theyare not the elements 0 and 1 of 𝑅, respectively, even if such elements exist (e.g., for 𝑅 = ), but instead the(tropical) additive and multiplicative identities +∞ and 0 respectively:

4Chapter 2. Tropical Semirings

Standard Semirings, Release 10.4

sage: T.zero() + T(3) == T(3)True
sage: T.one() * T(3) == T(3)True
sage: T.zero() == T(0)False
sage: T.one() == T(1)False>>> from sage.all import *>>> T.zero() + T(Integer(3)) == T(Integer(3))
True>>> T.one() * T(Integer(3)) == T(Integer(3))
True>>> T.zero() == T(Integer(0))
False>>> T.one() == T(Integer(1))
False

Element
alias of TropicalSemiringElement
additive_identity()
Return the (tropical) additive identity element +∞.
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: T.zero()+infinity>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> T.zero()+infinitygens()
Return the generators of self.
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: T.gens()(1, +infinity)>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> T.gens()(1, +infinity)

infinity()
Return the (tropical) additive identity element +∞.
EXAMPLES:5

Standard Semirings, Release 10.4

sage: T = TropicalSemiring(QQ)
sage: T.zero()+infinity>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> T.zero()+infinity

multiplicative_identity()
Return the (tropical) multiplicative identity element 0.
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: T.one()0>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> T.one()
0one()
Return the (tropical) multiplicative identity element 0.
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: T.one()0>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> T.one()
0zero()
Return the (tropical) additive identity element +∞.
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: T.zero()+infinity>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> T.zero()+infinity

class sage.rings.semirings.tropical_semiring.TropicalSemiringElement
Bases: Element
An element in the tropical semiring over an ordered additive semigroup 𝑅. Either in 𝑅 or ∞. The operators +, ·are defined as the tropical operators ⊕, ⊙ respectively.

6

Chapter 2. Tropical Semirings

Standard Semirings, Release 10.4

lift()
Return the value of self lifted to the base.
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: elt = T(2)sage: elt.lift()2
sage: elt.lift().parent() is QQ
True
sage: T.additive_identity().lift().parent()
The Infinity Ring>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> elt = T(Integer(2))>>> elt.lift()2>>> elt.lift().parent() is QQ
True>>> T.additive_identity().lift().parent()
The Infinity Ring

multiplicative_order()Return the multiplicative order of self.
EXAMPLES:
sage: T = TropicalSemiring(QQ)
sage: T.multiplicative_identity().multiplicative_order()1sage: T.additive_identity().multiplicative_order()+Infinity>>> from sage.all import *>>> T = TropicalSemiring(QQ)>>> T.multiplicative_identity().multiplicative_order()1>>> T.additive_identity().multiplicative_order()+Infinity

class sage.rings.semirings.tropical_semiring.TropicalToTropical
Bases: Map
Map from the tropical semiring to itself (possibly with different bases). Used in coercion.

7

Standard Semirings, Release 10.4

8Chapter 2. Tropical Semirings

CHAPTER

THREE

INDICES AND TABLES• Index• Module Index• Search Page

9

Standard Semirings, Release 10.4

10Chapter 3. Indices and Tables

PYTHON MODULE INDEXrsage.rings.semirings.non_negative_integer_semiring, 1
sage.rings.semirings.tropical_semiring, 311

Standard Semirings, Release 10.4

12

Python Module Index

INDEXAOadditive_identity() (sage.rings.semirings.tropi- one()(sage.rings.semirings.tropical_semiring.Tropical_semiring.TropicalSemiring method), 5
calSemiring method), 6
additive_semigroup_generators()S(sage.rings.semirings.non_negative_integer_semiring.NonNegativeIntegerSemiring
sage.rings.semirings.non_negative_inmethod), 2
teger_semiring
module, 1
Esage.rings.semirings.tropical_semiring
Element (sage.rings.semirings.tropical_semiring.Tropimodule, 3
calSemiring attribute), 5TG

TropicalSemiring (class in sage.rings.semirings.tropical_semiring), 3(sage.rings.semirings.tropical_semiring.TropiTropicalSemiringElement(classincalSemiring method), 5
sage.rings.semirings.tropical_semiring), 6
TropicalToTropical (class in sage.rings.semirIings.tropical_semiring), 7
infinity()(sage.rings.semirings.tropical_semirgens()

ing.TropicalSemiring method), 5L
lift()

Zzero()(sage.rings.semirings.tropical_semiring.TropicalSemiringElement method), 6(sage.rings.semirings.tropical_semiring.TropicalSemiring method), 6

M
modulesage.rings.semirings.non_negative_integer_semiring, 1
sage.rings.semirings.tropical_semiring, 3
multiplicative_identity() (sage.rings.semirings.tropical_semiring.TropicalSemiring method),6
multiplicative_order()(sage.rings.semirings.tropical_semiring.TropicalSemiringElementmethod), 7N
NonNegativeIntegerSemiring(classin
sage.rings.semirings.non_negative_integer_semiring), 1
13