Idempotent Semiring
An idempotent semiring is a semiring that is also idempotent, i.e. adding a value to itself yields the same value.
All laws of a semiring must hold for an idempotent 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 additive idempotency:
- Idempotency (idempotency): for \(\forall x \in S\), \(x + x = x\).
Code
trait ISemiring[A] extends Semiring[A], IdempotentMonoid[A]
Laws
- Laws of a semiring
- Idempotency is stated as:
s.combine(x, x)must equalx. This means that combining an element with itself does not change it.
Diagram
classDiagram
class Semigroup~A~{
+combine(x: A, y: A) A
}
class IdempotentSemigroup~A~
Semigroup <|-- IdempotentSemigroup
class Monoid~A~{
+empty() A
}
Semigroup <|-- Monoid
class CommutativeSemigroup~A~
Semigroup <|-- CommutativeSemigroup
class IdempotentMonoid~A~
IdempotentSemigroup <|-- IdempotentMonoid
Monoid <|-- IdempotentMonoid
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 IdempotentSemiring~A~
IdempotentMonoid <|-- IdempotentSemiring
Semiring <|-- IdempotentSemiring
References: