Commutative Semiring
A commutative semiring is a semiring with a commutative multiplication operation: for \(\forall x, y \in S\), \(x * y = y * x\) holds.
All laws of a semiring must hold for a commutative semiring:
- Additive closure (closure): for \(\forall x, y \in S\), \(x + y \in S\).
- Additive associativity (associativity): for \(\forall x, y, z \in S\), \((x + y) + z = x + (y + z)\).
- Existence of zero element: there exists \(\exists 0 \in S\) such that for \(\forall x \in S\), \(0 + x = x + 0 = x\)
- Additive commutativity (commutative): for \(\forall x, y \in S\), \(x + y = y + x\).
- Multiplicative closure (closure): for \(\forall x, y \in S\), \(x * y \in S\).
- Multiplicative associativity (associativity): for \(\forall x, y, z \in S\), \((x * y) * z = x * (y * z)\).
- Distributivity (distributivus, distributive law): for \(\forall x, y, z \in S\), \(x * (y + z) = x * y + x * z\) and \((x + y) * z = x * z + y * z\).
- Multiplicative zero property: \(a * 0 = 0 * a = 0\)
as well as the law of multiplicative commutativity:
- Multiplicative commutativity (commutative): for \(\forall x, y \in S\), \(x * y = y * x\).
Code
trait CSemiring[A] extends Semiring[A]
Laws
- Laws of a semiring
- Commutativity of multiplication means that the order of elements when multiplying does not matter.
In other words, the result of the
timesoperation will be the same regardless of the order in which elementsxandyare passed. This can be written as:cs.times(x, y) == cs.times(y, x)
Diagram
classDiagram
class Semigroup~A~{
+combine(x: A, y: A) A
}
class Monoid~A~{
+empty() A
}
Semigroup <|-- Monoid
class CommutativeSemigroup~A~
Semigroup <|-- CommutativeSemigroup
class CommutativeMonoid~A~
Monoid <|-- CommutativeMonoid
CommutativeSemigroup <|-- CommutativeMonoid
class Semiring~A~
CommutativeMonoid <|-- Semiring
class MultiplicativeSemigroup~A~{
+times(x: A, y: A) A
}
MultiplicativeSemigroup <|-- Semiring
Semigroup .. MultiplicativeSemigroup
class CommutativeSemiring~A~
Semiring <|-- CommutativeSemiring
Implementation in Libraries
References: