Semirings with monus #
This file defines semirings with monus and introduces their main properties.
Many semirings relevant for provenance can be equipped with a monus - operator, resulting in what is called a semiring with monus, or m-semiring. This is standard in semiring theory [Ame84] and was introduced in the setting of provenance semirings by Geerts and Poggi [GP10]. The class is the algebraic structure underlying the annotated query semantics of Section IV-A of Sen, Maniu & Senellart, ProvSQL: A General System for Keeping Track of the Provenance and Probability of Data (Definition 5).
References #
Definition of a SemiringWithMonus #
A SemiringWithMonus is a naturally ordered semiring
with a monus operation that is compatible with the natural order.
We do not require the semiring to be necessarily commutative.
In addition to monus, the class carries a δ : α → α operator subject
to three axioms (delta_zero, delta_natCast_pos, and
delta_absorb). This is the duplicate-eliminating support
operator used to interpret aggregation in the framework of
Amsterdamer, Deutch & Tannen, Provenance for aggregate queries,
mirroring ProvSQL's Semiring::delta.
- add : α → α → α
- zero : α
- mul : α → α → α
- one : α
- sub : α → α → α
- delta : α → α
Duplicate-eliminating support operator. Sends
0to0and any positive integer iterate of1to1. δsends0to0.δsends every positive integer iterate of1(i.e., every positive natural-number cast) to1.A δ-guard is absorbed by any multiple of one of its summands:
a ⊗ δ(a ⊕ b) = a. This is what makes a group-existence factor redundant next to any provenance that already contains an occurrence of the group:δreally acts as “the group exists” and nothing more. Both usual choices ofδsatisfy it in their natural habitat: the indicator (δ x = 𝟙forx ≠ 𝟘) in any canonically ordered semiring (delta_absorb_indicator), and the identity in lattice-like semirings, where it is absorptiona ⊓ (a ⊔ b) = a.
Instances
Dependency graph
Main properties #
In a SemiringWithMonus, a - b is the smallest element c
satisfying a ≤ b + c.
Dependency graph
Uniqueness of monus. The monus operation is determined by its
adjunction property: any binary operation s satisfying
s a b ≤ c ↔ a ≤ b + c coincides with ⊖. Consequently, a naturally
ordered semiring admits at most one monus operation.
Dependency graph
In a SemiringWithMonus, δ 1 = 1.
Dependency graph
In a SemiringWithMonus, a - a = 0.
Dependency graph
In a SemiringWithMonus, 0 - a = 0.
Dependency graph
In a SemiringWithMonus, a - 0 = a.
Dependency graph
In a SemiringWithMonus, a + (b -a) = b + (a - b).
Dependency graph
In a SemiringWithMonus, monus is left-distributive over plus.
Dependency graph
Additional properties #
The following properties do not always hold in an arbitrary m-semiring.
A Semiring is idempotent if a + a = a.
Equations
- idempotent α = ∀ (a : α), a + a = a
Instances For
Dependency graph
A Semiring is absorptive (also called 0-closed or 0-bounded) if 1 + a = a.
Equations
- absorptive α = ∀ (a : α), 1 + a = 1
Instances For
Dependency graph
We define left-distributivity of times over monus in a SemiringWithMonus.
Instances For
Dependency graph
Absorptivity implies idempotence
Dependency graph
In an idempotent SemiringWithMonus, a ≤ b iff a + b = b.
Dependency graph
In an idempotent SemiringWithMonus, plus is the join of the
semilattice
Dependency graph
In a SemiringWithMonus, right-distributivity of monus
over plus implies idempotence.
Dependency graph
In a SemiringWithMonus, idempotence implies right-distributivity of monus
over plus.
Dependency graph
A SemiringWithMonus is idempotent iff monus is right-distributive
over plus.
Dependency graph
Finite-family version of add_monus_of_idempotent: in an idempotent
SemiringWithMonus, monus distributes over the sum of any multiset of
annotations, (⨁ᵢ aᵢ) ⊖ c = ⨁ᵢ (aᵢ ⊖ c).
Dependency graph
Dependency graph
Monus is antitone in its second argument: subtracting more leaves less.
Together with monus_le this is what lets a subtrahend be replaced by a
larger one inside an upper bound.
Dependency graph
Characteristic of idempotent semirings #
In an idempotent semiring (a + a = a), every positive natural-number cast
collapses to 1. With 1 ≠ 0 this yields CharP K 0. Note that this is
strictly weaker than CharZero K, which fails for idempotent semirings since
the cast ℕ → K is not injective.
In a semiring with idempotent addition, the cast of any positive natural
number equals 1.
Dependency graph
A nontrivial idempotent semiring has characteristic 0 in the CharP sense.
Unlike CharZero, this does not require the natural-number cast to be injective:
in an idempotent semiring every positive natural maps to 1, but 1 ≠ 0 still
suffices to give CharP K 0.
Dependency graph
Generic constructions of δ #
In the m-semirings used for provenance the δ operator is invariably
realized in one of two ways: as the identity (when the semiring is
idempotent, so every positive natural cast already equals 1) or as the
indicator-of-nonzero (a ↦ if a = 0 then 0 else 1). The lemmas below
package the proofs of the δ axioms for both candidates so each
concrete instance can plug them in directly.
δ := id satisfies delta_natCast_pos in any idempotent semiring:
every positive natural-number cast collapses to 1.
Dependency graph
The “indicator-of-nonzero” recipe: δ a = 0 when a = 0 and
δ a = 1 otherwise. Captured abstractly so a single set of axioms can
serve all the concrete instances that use it (ℕ, ℕ[X], Tropical,
Viterbi, Lukasiewicz).
Instances For
Dependency graph
Any δ matching the indicator recipe satisfies delta_natCast_pos
in a nontrivial semiring of characteristic 0 (in the CharP sense):
positive natural-number casts are nonzero, so δ sends them to 1.
Dependency graph
Any δ matching the indicator recipe satisfies delta_absorb in a
canonically ordered semiring: if a ⊕ b = 𝟘 then a = 𝟘 by zero-sum
freeness, and otherwise δ(a ⊕ b) = 𝟙.
Dependency graph
Admissibility of a candidate δ #
δ is not determined by the axioms, and the two operators used in practice
are the identity and the support indicator. IsDelta states the axioms as a
predicate on a candidate operator, so that a semiring can record which of
the two it must use: the identity is preferred where it is admissible, and
the indicator is forced exactly where ¬ IsDelta id holds. The three
not_isDelta_id_of_* lemmas below cover the three ways the identity fails,
in increasing order of subtlety.
A candidate operator δ : K → K satisfies the δ-axioms of
SemiringWithMonus.
δsends𝟘to𝟘.δsends every positive natural-number cast to𝟙.A δ-guard is absorbed by any multiple of one of its summands.
Instances For
Dependency graph
The δ carried by a SemiringWithMonus is admissible, by definition of
the class. In particular, in a semiring whose instance takes δ := id this
gives IsDelta id for free.
Dependency graph
To refute δ := id, exhibit a pair violating the lattice absorption law
a ⊗ (a ⊕ b) = a, which is what delta_absorb demands of the identity.
Dependency graph
δ := id requires the semiring to be idempotent: delta_natCast_pos at
n = 2 reads 𝟙 ⊕ 𝟙 = 𝟙, whence a ⊕ a = a ⊗ (𝟙 ⊕ 𝟙) = a. This is the
crudest of the three obstructions, and the one that rules the identity out
of the counting semirings (ℕ, ℕ[X]).
Dependency graph
δ := id requires multiplicative idempotence as soon as addition is
idempotent: delta_absorb at b = a reads a ⊗ (a ⊕ a) = a ⊗ a = a. This is
the obstruction in the absorptive semirings whose ⊗ is a genuine product
(Viterbi, Łukasiewicz), where the two coarser tests below say nothing.
Dependency graph
δ := id requires absorptivity: delta_absorb at a = 𝟙 reads
𝟙 ⊗ (𝟙 ⊕ b) = 𝟙, i.e., 𝟙 ⊕ b = 𝟙.
Dependency graph
Existence of a δ-like operator #
This is the abstract counterpart of the SemiringWithMonus δ-axioms: we
characterize, in an arbitrary nontrivial semiring (no order assumed), when
a function δ : K → K satisfying δ 0 = 0 and δ ((n : K)) = 1 for
0 < n can exist. The class also demands delta_absorb, which the iff
below ignores, so it should be read as a statement about how much of the
ProvSQL δ interface is consistent with a given characteristic, not as a
full existence proof for the class. (Constructing a witness for
delta_absorb requires more structure: in a canonically ordered semiring
the indicator works, see delta_absorb_indicator.)
In any nontrivial semiring, a function δ : K → K satisfying δ 0 = 0
and δ ((n : K)) = 1 for every positive natural cast n exists if and only
if K has characteristic 0 in the CharP sense. The forward direction
follows because δ 0 = 0 and δ ((n : K)) = 1 are inconsistent when
(n : K) = 0 for some 0 < n (it would force 0 = 1). The backward
direction defines δ as the indicator of being nonzero.
Note that the δ operator is not uniquely determined by these axioms: they
only pin its values on the image of ℕ. Two typical choices are δ as the
indicator of being nonzero (δ x = if x = 0 then 0 else 1, used in the
backward direction below) and, in an idempotent semiring, δ as the identity
(since every positive natural cast then equals 1, see
natCast_pos_eq_one_of_idempotent). Both are idempotent (δ (δ a) = δ a);
adding idempotence as a third requirement would leave the statement
unchanged, since the forward direction never uses it and the indicator
witness satisfies it.
Dependency graph
The third axiom is free. In a canonically ordered semiring, a full
IsDelta operator exists as soon as some function satisfies the first two
axioms: the indicator witnessing delta_exists_iff_charP_zero satisfies
delta_absorb as well (delta_absorb_indicator). So the admissibility
question for a candidate δ is never one of existence – it is only about
whether the preferred candidate, the identity, is among the admissible
ones (not_isDelta_id_of_*).
Dependency graph
The companion of delta_exists_iff_charP_zero for the full axiom set: in a
nontrivial canonically ordered semiring, an admissible δ exists if and only if
the characteristic is 0.
Dependency graph
Commutative SemiringWithMonuss #
SemiringWithMonus is intentionally not assumed to be commutative; however, every
provenance semiring used in this library is in fact commutative, and the algebraic
identities that drive HAVING-style aggregate provenance (see Provenance.Having)
require it. CommSemiringWithMonus packages a SemiringWithMonus together with
the commutativity axiom, producing a CommMonoid instance whose Mul matches
the one already supplied by SemiringWithMonus, so no Mul diamond appears when
Finset.prod is used.
A SemiringWithMonus whose multiplication is commutative.
- add : K → K → K
- zero : K
- mul : K → K → K
- one : K
- sub : K → K → K
- delta : K → K
Multiplication on
Kis commutative.
Instances
Dependency graph
A CommSemiringWithMonus is automatically a CommMonoid, sharing its
multiplicative structure with the underlying SemiringWithMonus. This makes
Finset.prod usable without introducing a separate CommSemiring hypothesis
that would cause a Mul diamond.
Equations
- instCommMonoidOfCommSemiringWithMonus = { toMonoid := h.toMonoid, mul_comm := ⋯ }
Dependency graph
Homomorphisms of SemiringWithMonuss #
Definition of a homomorphism of SemiringWithMonuss. Preserves the
semiring structure (via RingHom), the monus (map_sub), and the δ
operator (map_delta). The latter is required for hom commutation of the
aggregation operator, where δ appears on the row-annotation column
(Definition 7 / R5 of Sen, Maniu & Senellart).
- toFun : α → β
- map_delta (a : α) : self.toRingHom (SemiringWithMonus.delta a) = SemiringWithMonus.delta (self.toRingHom a)
The hom preserves
δ:h (δ a) = δ (h a).
Instances
Dependency graph
Equations
- instCoeFunSemiringWithMonusHomForall α β = { coe := fun (f : SemiringWithMonusHom α β) (x : α) => f.toRingHom x }
Dependency graph
If ν is an injective m-semiring homomorphism from α to β, and β is idempotent, so is α.
Dependency graph
If ν is an m-semiring homomorphism from α onto β, and α is idempotent, so is β.
Dependency graph
If ν is an injective m-semiring homomorphism from α to β, and β has left-distributivity of times over monus, so has α.
Dependency graph
If ν is an m-semiring homomorphism from α onto β, and α has left-distributivity of times over monus, so has β.
Dependency graph
Miscellaneous #
On an arbitrary semiring the natural relation a ≼ b ↔ ∃ c, b = a + c
is always a preorder (reflexive by c = 0, transitive by adding witnesses)
but not always antisymmetric: on ℤ, any two elements are related in both
directions, e.g., 0 ≼ 1 ≼ 0 with 0 ≠ 1. This is why SemiringWithMonus
assumes the canonically ordered structure instead of deriving an order
from +.