# Semiring

Short description: Algebraic ring that need not have additive negative elements

In abstract algebra, a semiring is an algebraic structure similar to a ring, but without the requirement that each element must have an additive inverse.

The term rig is also used occasionally—this originated as a joke, suggesting that rigs are rings without negative elements, similar to using rng to mean a ring without a multiplicative identity.

Tropical semirings are an active area of research, linking algebraic varieties with piecewise linear structures.

## Definition

A semiring is a set $\displaystyle{ R }$ equipped with two binary operations $\displaystyle{ \,+\, }$ and $\displaystyle{ \,\cdot,\, }$ called addition and multiplication, such that:

• $\displaystyle{ (R, +) }$ is a commutative monoid with identity element $\displaystyle{ 0 }$:
• $\displaystyle{ (a + b) + c = a + (b + c) }$
• $\displaystyle{ 0 + a = a = a + 0 }$
• $\displaystyle{ a + b = b + a }$
• $\displaystyle{ (R, \,\cdot\,) }$ is a monoid with identity element $\displaystyle{ 1 }$:
• $\displaystyle{ (a \cdot b) \cdot c = a \cdot (b \cdot c) }$
• $\displaystyle{ 1 \cdot a = a = a \cdot 1 }$
• Multiplication left and right distributes over addition:
• $\displaystyle{ a \cdot (b + c) = (a \cdot b) + (a \cdot c) }$
• $\displaystyle{ (a + b) \cdot c = (a \cdot c) + (b \cdot c) }$
• Multiplication by $\displaystyle{ 0 }$ annihilates $\displaystyle{ R }$:
• $\displaystyle{ 0 \cdot a = 0 = a \cdot 0 }$

The symbol $\displaystyle{ \cdot }$ is usually omitted from the notation; that is, $\displaystyle{ a \cdot b }$ is just written $\displaystyle{ ab. }$ Similarly, an order of operations is conventional, in which $\displaystyle{ \,\cdot\, }$ is applied before $\displaystyle{ \,+\, }$; that is, $\displaystyle{ a + b c }$ is $\displaystyle{ a + (b c). }$

Compared to a ring, a semiring omits the requirement for inverses under addition; that is, it requires only a commutative monoid, not a commutative group. In a ring, the additive inverse requirement implies the existence of a multiplicative zero, so here it must be specified explicitly. If a semiring's multiplication is commutative, then it is called a commutative semiring.

There are some authors who prefer to leave out the requirement that a semiring have a 0 or 1. This makes the analogy between ring and semiring on the one hand and group and semigroup on the other hand work more smoothly. These authors often use rig for the concept defined here.[note 1]

## Theory

One can generalize the theory of (associative) algebras over commutative rings directly to a theory of algebras over commutative semirings.

A semiring in which every element is an additive idempotent (that is, $\displaystyle{ a + a = a }$ for all elements $\displaystyle{ a }$) is called an idempotent semiring. Idempotent semirings are specific to semiring theory since any idempotent semiring that is also a ring is in fact trivial.[note 2] One can define a partial order $\displaystyle{ \,\leq\, }$ on an idempotent semiring by setting $\displaystyle{ a \leq b }$ whenever $\displaystyle{ a + b = b }$ (or, equivalently, if there exists an $\displaystyle{ x }$ such that $\displaystyle{ a + x = b }$). The least element with respect to this order is $\displaystyle{ 0, }$ meaning that $\displaystyle{ 0 \leq a }$ for all $\displaystyle{ a. }$ Addition and multiplication respect the ordering in the sense that $\displaystyle{ a \leq b }$ implies $\displaystyle{ a c \leq b c }$ and $\displaystyle{ c a \leq c b }$ and $\displaystyle{ (a + c) \leq (b + c). }$

### Applications

The $\displaystyle{ (\max, +) }$ and $\displaystyle{ (\min, +) }$ tropical semirings on the reals are often used in performance evaluation on discrete event systems. The real numbers then are the "costs" or "arrival time"; the "max" operation corresponds to having to wait for all prerequisites of an events (thus taking the maximal time) while the "min" operation corresponds to being able to choose the best, less costly choice; and + corresponds to accumulation along the same path.

The Floyd–Warshall algorithm for shortest paths can thus be reformulated as a computation over a $\displaystyle{ (\min, +) }$ algebra. Similarly, the Viterbi algorithm for finding the most probable state sequence corresponding to an observation sequence in a hidden Markov model can also be formulated as a computation over a $\displaystyle{ (\max, \times) }$ algebra on probabilities. These dynamic programming algorithms rely on the distributive property of their associated semirings to compute quantities over a large (possibly exponential) number of terms more efficiently than enumerating each of them.

## Examples

By definition, any ring is also a semiring. A motivating example of a semiring is the set of natural numbers $\displaystyle{ \N }$ (including the number zero) under ordinary addition and multiplication. Likewise, the non-negative rational numbers and the non-negative real numbers form semirings. All these semirings are commutative.

### In general

• The set of all ideals of a given ring form an idempotent semiring under addition and multiplication of ideals.
• Any unital quantale is an idempotent semiring under join and multiplication.
• Any bounded, distributive lattice is a commutative, idempotent semiring under join and meet.
• In particular, a Boolean algebra is such a semiring. A Boolean ring is also a semiring (indeed, a ring) but it is not idempotent under addition. A Boolean semiring is a semiring isomorphic to a subsemiring of a Boolean algebra.
• A normal skew lattice in a ring $\displaystyle{ R }$ is an idempotent semiring for the operations multiplication and nabla, where the latter operation is defined by $\displaystyle{ a \nabla b = a + b + ba - aba - bab. }$
• Any c-semiring is also a semiring, where addition is idempotent and defined over arbitrary sets.
• Isomorphism classes of objects in any distributive category, under coproduct and product operations, form a semiring known as a Burnside rig. A Burnside rig is a ring if and only if the category is trivial.

#### Semiring of sets

A semiring (of sets) is a (non-empty) collection $\displaystyle{ \mathcal{S} }$ of subsets of $\displaystyle{ X }$ such that

1. $\displaystyle{ \varnothing \in \mathcal{S}. }$
• If (3) holds, then $\displaystyle{ \varnothing \in \mathcal{S} }$ if and only if $\displaystyle{ \mathcal{S} \neq \varnothing. }$
2. If $\displaystyle{ E, F \in \mathcal{S} }$ then $\displaystyle{ E \cap F \in \mathcal{S}. }$
3. If $\displaystyle{ E, F \in \mathcal{S} }$ then there exists a finite number of mutually disjoint sets $\displaystyle{ C_1, \ldots, C_n \in \mathcal{S} }$ such that $\displaystyle{ E \setminus F = \bigcup_{i=1}^n C_i. }$

Conditions (2) and (3) together with $\displaystyle{ S \neq \varnothing }$ imply that $\displaystyle{ \varnothing \in S. }$ Such semirings are used in measure theory. An example of a semiring of sets is the collection of half-open, half-closed real intervals $\displaystyle{ [a, b) \subset \R. }$

A semialgebra or elementary family  is a collection $\displaystyle{ \mathcal{S} }$ of subsets of $\displaystyle{ X }$ satisfying the semiring properties except with (3) replaced with:

• If $\displaystyle{ E \in \mathcal{S} }$ then there exists a finite number of mutually disjoint sets $\displaystyle{ C_1, \ldots, C_n \in \mathcal{S} }$ such that $\displaystyle{ X \setminus E = \bigcup_{i=1}^n C_i. }$

This condition is stronger than (3), which can be seen as follows. If $\displaystyle{ \mathcal{S} }$ is a semialgebra and $\displaystyle{ E, F \in \mathcal{S} }$, then we can write $\displaystyle{ F^c = F_1 \cup ... \cup F_n }$ for disjoint $\displaystyle{ F_i \in S }$. Then: $\displaystyle{ E \setminus F = E \cap F^c = E \cap (F_1 \cup ... \cup F_n) = (E \cap F_1) \cup ... \cup (E \cap F_n) }$

and every $\displaystyle{ E \cap F_i \in S }$ since it is closed under intersection, and disjoint since they are contained in the disjoint $\displaystyle{ F_i }$'s. Moreover the condition is strictly stronger: any $\displaystyle{ S }$ that is both a ring and a semialgebra is an algebra, hence any ring that is not an algebra is also not a semialgebra (e.g. the collection of finite sets on an infinite set $\displaystyle{ X }$).

### Specific examples

• The (non-negative) terminating fractions $\displaystyle{ \frac{\N_0}{b^{\N_0}} := \left\{ mb^{-n} : m, n \in \N_0 \right\} }$ in a positional number system to a given base $\displaystyle{ b\in \N. }$ We have $\displaystyle{ \frac{\N_0}{b^{\N_0}} \subseteq \frac{\N_0}{c^{\N_0}} }$‍ if $\displaystyle{ b }$ divides $\displaystyle{ c. }$ Furthermore, $\displaystyle{ \frac{\Z_0}{b^{\Z_0}} := \frac{\N_0}{b^{\N_0}} \cup \left(-\frac{\N_0}{b^{\N_0}}\right) }$ is the ring of all terminating fractions to base $\displaystyle{ b, }$ and is dense in $\displaystyle{ \Q }$ for $\displaystyle{ |b| \gt 1. }$
• The extended natural numbers $\displaystyle{ \N \cup \{ \infty \} }$ with addition and multiplication extended (and $\displaystyle{ 0 \cdot \infty = 0 }$).
• Given a semiring $\displaystyle{ S, }$ the matrix semiring $\displaystyle{ M_n(S) }$ of the square $\displaystyle{ n \text{ by } n }$ matrices form a semiring under ordinary addition and multiplication of matrices, and this semiring of matrices is generally non-commutative even though $\displaystyle{ S }$ may be commutative. For example, the matrices with non-negative entries, $\displaystyle{ M_n(\N), }$ form a matrix semiring.
• If $\displaystyle{ A }$ is a commutative monoid, the set $\displaystyle{ \operatorname{End}(A) }$ of endomorphisms $\displaystyle{ f : A \to A }$ forms a semiring, where addition is pointwise addition and multiplication is function composition. The zero morphism and the identity are the respective neutral elements. If $\displaystyle{ A }$ is the additive monoid of natural numbers we obtain the semiring of natural numbers as $\displaystyle{ \operatorname{End}(A), }$ if $\displaystyle{ A = S^n }$ with $\displaystyle{ S }$ a semiring, we obtain (after associating each morphism to a matrix) the semiring of square $\displaystyle{ n \text{ by } n }$ matrices with coefficients in $\displaystyle{ S, }$ and if $\displaystyle{ A }$ is a (commutative) group, then $\displaystyle{ \operatorname{End}(A) }$ is a (not necessarily commutative) ring.
• Given a set $\displaystyle{ U, }$ the set of binary relations over $\displaystyle{ U }$ is a semiring with addition the union (of relations as sets) and multiplication the composition of relations. The semiring's zero is the empty relation and its unit is the identity relation. These relations correspond to the matrix semiring (indeed, matrix semialgebra) of square matrices indexed by $\displaystyle{ U }$ with entries in the Boolean semiring, and then addition and multiplication are the usual matrix operations, while zero and the unit are the usual zero matrix and identity matrix.
• The set of polynomials with natural number coefficients, denoted $\displaystyle{ \N[x], }$ forms a commutative semiring. In fact, this is the free commutative semiring on a single generator $\displaystyle{ \{ x \}. }$
• The set of cardinal numbers smaller than any given infinite cardinal form a semiring under cardinal addition and multiplication. The class of all cardinals of an inner model form a (class) semiring under (inner model) cardinal addition and multiplication.
• The probability semiring of non-negative real numbers under the usual addition and multiplication.
• The log semiring on $\displaystyle{ \R \cup \{ \pm \infty \} }$ with addition given by

$\displaystyle{ x \oplus y = - \log\left(e^{-x} + e^{-y}\right) }$

with multiplication $\displaystyle{ \,+,\, }$ zero element $\displaystyle{ + \infty, }$ and unit element $\displaystyle{ 0. }$
• The family of (isomorphism equivalence classes of) combinatorial classes (sets of countably many objects with non-negative integer sizes such that there are finitely many objects of each size) with the empty class as the zero object, the class consisting only of the empty set as the unit, disjoint union of classes as addition, and Cartesian product of classes as multiplication.
• The Łukasiewicz semiring: the closed interval $\displaystyle{ [0, 1] }$ with addition given by taking the maximum of the arguments ($\displaystyle{ a + b = \max(a, b) }$) and multiplication $\displaystyle{ a b }$ given by $\displaystyle{ \max(0, a + b - 1) }$ appears in multi-valued logic.
• The Viterbi semiring is also defined over the base set $\displaystyle{ [0, 1] }$ and has the maximum as its addition, but its multiplication is the usual multiplication of real numbers. It appears in probabilistic parsing.
• Given an alphabet (finite set) Σ, the set of formal languages over $\displaystyle{ \Sigma }$ (subsets of $\displaystyle{ \Sigma^* }$) is a semiring with product induced by string concatenation $\displaystyle{ L_1 \cdot L_2 = \left\{ w_1 w_2 : w_1 \in L_1, w_2 \in L_2 \right\} }$ and addition as the union of languages (that is, ordinary union as sets). The zero of this semiring is the empty set (empty language) and the semiring's unit is the language containing only the empty string.
• Generalizing the previous example (by viewing $\displaystyle{ \Sigma^* }$ as the free monoid over $\displaystyle{ \Sigma }$), take $\displaystyle{ M }$ to be any monoid; the power set $\displaystyle{ \wp(M) }$ of all subsets of $\displaystyle{ M }$ forms a semiring under set-theoretic union as addition and set-wise multiplication: $\displaystyle{ U \cdot V = \{ u \cdot v : u \in U,\ v \in V \}. }$
• Similarly, if $\displaystyle{ (M, e, \cdot) }$ is a monoid, then the set of finite multisets in $\displaystyle{ M }$ forms a semiring. That is, an element is a function $\displaystyle{ f : M \to \N }$; given an element of $\displaystyle{ M, }$ the function tells you how many times that element occurs in the multiset it represents. The additive unit is the constant zero function. The multiplicative unit is the function mapping $\displaystyle{ e }$ to $\displaystyle{ 1, }$ and all other elements of $\displaystyle{ M }$ to $\displaystyle{ 0. }$ The sum is given by $\displaystyle{ (f + g)(x) = f(x) + g(x) }$ and the product is given by $\displaystyle{ (fg)(x) = \sum\{ f(y) g(z) : y \cdot z = x \}. }$

## Variations

### Complete and continuous semirings

A complete semiring is a semiring for which the additive monoid is a complete monoid, meaning that it has an infinitary sum operation $\displaystyle{ \Sigma_I }$ for any index set $\displaystyle{ I }$ and that the following (infinitary) distributive laws must hold: $\displaystyle{ \sum_{i \in I}{\left(a \cdot a_i\right)} = a \cdot \left(\sum_{i \in I}{a_i}\right), \qquad \sum_{i \in I}{\left(a_i \cdot a\right)} = \left(\sum_{i \in I}{a_i}\right) \cdot a. }$

Examples of a complete semiring are the power set of a monoid under union and the matrix semiring over a complete semiring.

A continuous semiring is similarly defined as one for which the addition monoid is a continuous monoid. That is, partially ordered with the least upper bound property, and for which addition and multiplication respect order and suprema. The semiring $\displaystyle{ \N \cup \{ \infty \} }$ with usual addition, multiplication and order extended is a continuous semiring.

Any continuous semiring is complete: this may be taken as part of the definition.

### Star semirings

A star semiring (sometimes spelled starsemiring) is a semiring with an additional unary operator , satisfying $\displaystyle{ a^* = 1 + a a^* = 1 + a^* a. }$

A Kleene algebra is a star semiring with idempotent addition and some additional axioms. They are important in the theory of formal languages and regular expressions.

#### Complete star semirings

In a complete star semiring, the star operator behaves more like the usual Kleene star: for a complete semiring we use the infinitary sum operator to give the usual definition of the Kleene star: $\displaystyle{ a^* = \sum_{j \geq 0}{a^j}, }$ where $\displaystyle{ a^j = \begin{cases} 1, & j = 0,\\ a \cdot a^{j-1} = a^{j-1} \cdot a, & j \gt 0. \end{cases} }$

Note that star semirings are not related to *-algebra, where the star operation should instead be thought of as complex conjugation.

#### Conway semiring

A Conway semiring is a star semiring satisfying the sum-star and product-star equations: \displaystyle{ \begin{align} (a + b)^* &= \left(a^* b\right)^* a^*, \\ (ab)^* &= 1 + a(ba)^* b. \end{align} }

Every complete star semiring is also a Conway semiring, but the converse does not hold. An example of Conway semiring that is not complete is the set of extended non-negative rational numbers $\displaystyle{ \Q_{\geq 0} \cup \{ \infty \} }$ with the usual addition and multiplication (this is a modification of the example with extended non-negative reals given in this section by eliminating irrational numbers).

An iteration semiring is a Conway semiring satisfying the Conway group axioms, associated by John Conway to groups in star-semirings.

#### Examples

Examples of star semirings include:

• the (aforementioned) semiring of binary relations over some base set $\displaystyle{ U }$ in which $\displaystyle{ R^* = \bigcup_{n \geq 0} R^n }$ for all $\displaystyle{ R\subseteq U \times U. }$ This star operation is actually the reflexive and transitive closure of $\displaystyle{ R }$ (that is, the smallest reflexive and transitive binary relation over $\displaystyle{ U }$ containing $\displaystyle{ R. }$).
• the semiring of formal languages is also a complete star semiring, with the star operation coinciding with the Kleene star (for sets/languages).
• The set of non-negative extended reals $\displaystyle{ [0, \infty] }$ together with the usual addition and multiplication of reals is a complete star semiring with the star operation given by $\displaystyle{ a^* = \frac{1}{1 - a} }$ for $\displaystyle{ 0 \leq a \lt 1 }$ (that is, the geometric series) and $\displaystyle{ a^* = \infty }$ for $\displaystyle{ a \geq 1. }$
• The Boolean semiring with $\displaystyle{ 0^* = 1^* = 1. }$[lower-alpha 1]
• The semiring on $\displaystyle{ \N \cup \{ \infty \}, }$ with extended addition and multiplication, and $\displaystyle{ 0^* = 1, a^* = \infty }$ for $\displaystyle{ a \geq 1. }$[lower-alpha 1]

### Dioid

The term dioid (for "double monoid") has been used to mean various types of semirings:

• It was used by Kuntzman in 1972 to denote what is now termed semiring.
• The use to mean idempotent subgroup was introduced by Baccelli et al. in 1992.
• The name "dioid" is also sometimes used to denote naturally ordered semirings.

## Generalizations

A generalization of semirings does not require the existence of a multiplicative identity, so that multiplication is a semigroup rather than a monoid. Such structures are called hemirings or pre-semirings. A further generalization are left-pre-semirings, which additionally do not require right-distributivity (or right-pre-semirings, which do not require left-distributivity).

Yet a further generalization are near-semirings: in addition to not requiring a neutral element for product, or right-distributivity (or left-distributivity), they do not require addition to be commutative. Just as cardinal numbers form a (class) semiring, so do ordinal numbers form a near-semiring, when the standard ordinal addition and multiplication are taken into account. However, the class of ordinals can be turned into a semiring by considering the so-called natural (or Hessenberg) operations instead.

In category theory, a 2-rig is a category with functorial operations analogous to those of a rig. That the cardinal numbers form a rig can be categorified to say that the category of sets (or more generally, any topos) is a 2-rig.