Documentation

Provenance.SemiringWithMonus

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_regrouping). 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.

Instances

    Main properties #

    theorem monus_smallest {α : Type} [K : SemiringWithMonus α] (a b : α) :
    a b + (a - b) ∀ (c : α), a b + ca - b c

    In a SemiringWithMonus, a - b is the smallest element c satisfying a ≤ b + c.

    In a SemiringWithMonus, δ is idempotent: applying it twice equals applying it once. This is the singleton case of delta_regrouping: the fine partition with a single group reduces to applying δ once or twice on the same value.

    theorem monus_self {α : Type} [K : SemiringWithMonus α] (a : α) :
    a - a = 0

    In a SemiringWithMonus, a - a = 0.

    theorem zero_monus {α : Type} [K : SemiringWithMonus α] (a : α) :
    0 - a = 0

    In a SemiringWithMonus, 0 - a = 0.

    theorem monus_zero {α : Type} [K : SemiringWithMonus α] (a : α) :
    a - 0 = a

    In a SemiringWithMonus, a - 0 = a.

    theorem add_monus {α : Type} [K : SemiringWithMonus α] (a b : α) :
    a + (b - a) = b + (a - b)

    In a SemiringWithMonus, a + (b -a) = b + (a - b).

    theorem monus_add {α : Type} [K : SemiringWithMonus α] (a b c : α) :
    a - (b + c) = a - b - c

    In a SemiringWithMonus, monus is left-distributive over plus.

    Additional properties #

    The following properties do not always hold in an arbitrary m-semiring.

    @[reducible, inline]
    abbrev idempotent (α : Type u_1) [Semiring α] :

    A Semiring is idempotent if a + a = a.

    Equations
    Instances For
      @[reducible, inline]
      abbrev absorptive (α : Type u_1) [Semiring α] :

      A Semiring is absorptive (also called 0-closed or 0-bounded) if 1 + a = a.

      Equations
      Instances For
        @[reducible, inline]

        We define left-distributivity of times over monus in a SemiringWithMonus.

        Equations
        Instances For
          theorem idempotent_of_absorptive {α : Type u_1} [K : Semiring α] :

          Absorptivity implies idempotence

          theorem le_iff_add_eq {α : Type} [K : SemiringWithMonus α] (h : idempotent α) (a b : α) :
          a b a + b = b

          In an idempotent SemiringWithMonus, a ≤ b iff a + b = b.

          theorem plus_is_join {α : Type} [K : SemiringWithMonus α] (h : idempotent α) (a b : α) :
          (a a + b b a + b) ∀ (u : α), a u b ua + b u

          In an idempotent SemiringWithMonus, plus is the join of the semilattice

          theorem idempotent_of_add_monus {α : Type} [K : SemiringWithMonus α] (h : ∀ (a b c : α), a + b - c = a - c + (b - c)) :

          In a SemiringWithMonus, right-distributivity of monus over plus implies idempotence.

          theorem add_monus_of_idempotent {α : Type} [K : SemiringWithMonus α] (h : idempotent α) (a b c : α) :
          a + b - c = a - c + (b - c)

          In a SemiringWithMonus, idempotence implies right-distributivity of monus over plus.

          theorem idempotent_iff_add_monus {α : Type} [SemiringWithMonus α] :
          idempotent α ∀ (a b c : α), a + b - c = a - c + (b - c)

          A SemiringWithMonus is idempotent iff monus is right-distributive over plus.

          theorem add_monus_of_idempotent_multiset {α : Type} [SemiringWithMonus α] (h : idempotent α) (s : Multiset α) (c : α) :
          s.sum - c = (Multiset.map (fun (x : α) => x - c) s).sum

          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).

          theorem monus_le {α : Type} [SemiringWithMonus α] (a b : α) :
          a - b a
          theorem le_plus_monus {α : Type} [SemiringWithMonus α] (a b : α) :
          a b + (a - b)

          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.

          theorem natCast_pos_eq_one_of_idempotent {K : Type} [Semiring K] (h : idempotent K) {n : } :
          0 < nn = 1

          In a semiring with idempotent addition, the cast of any positive natural number equals 1.

          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.

          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 three δ axioms for both candidates so each concrete instance can plug them in directly.

          theorem delta_natCast_pos_id {K : Type} [Semiring K] (h : idempotent K) {n : } (hn : 0 < n) :
          id n = 1

          δ := id satisfies delta_natCast_pos in any idempotent semiring: every positive natural-number cast collapses to 1.

          theorem delta_regrouping_id {K : Type} [Semiring K] (s : Multiset K) :

          δ := id satisfies delta_regrouping in any semiring: both sides unfold to s.sum.

          structure IsDeltaIndicator {K : Type} [Zero K] [One K] (δ : KK) :

          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).

          • zero : δ 0 = 0
          • nonzero (a : K) : a 0δ a = 1
          Instances For
            theorem delta_natCast_pos_indicator {K : Type} [Semiring K] [Nontrivial K] [CharP K 0] {δ : KK} (h : IsDeltaIndicator δ) {n : } (hn : 0 < n) :
            δ n = 1

            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.

            Any δ matching the indicator recipe satisfies delta_regrouping in a nontrivial canonically ordered semiring: a sum is zero exactly when every summand is, so applying δ after summing indicators agrees with applying δ after summing the original values.

            Existence of a δ-like operator #

            This is the abstract counterpart of the SemiringWithMonus δ-axioms: we characterise, in an arbitrary nontrivial semiring (no order assumed), when a function δ : K → K satisfying δ 0 = 0, δ ((n : K)) = 1 for 0 < n, and idempotence δ (δ a) = δ a can exist. The class axiom delta_regrouping is strictly stronger than idempotence, so the iff below 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 axiom. (Constructing a witness for delta_regrouping itself requires more structure: in a canonically ordered semiring the indicator works, see delta_regrouping_indicator.)

            theorem delta_exists_iff_charP_zero {K : Type} [Semiring K] [Nontrivial K] :
            ( (δ : KK), δ 0 = 0 (∀ {n : }, 0 < nδ n = 1) ∀ (a : K), δ (δ a) = δ a) CharP K 0

            In any nontrivial semiring, a function δ : K → K satisfying δ 0 = 0, δ ((n : K)) = 1 for every positive natural cast n, and idempotence δ (δ a) = δ a 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); idempotence plays no role here. The backward direction defines δ as the indicator of being nonzero, which is automatically a fixed point of itself.

            Note that the δ operator is not uniquely determined by these axioms: they only pin its values on the image of (plus the requirement that any chosen value be a fixed point 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).

            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.

            Instances
              @[implicit_reducible, instance 100]

              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

              Homomorphisms of SemiringWithMonuss #

              class SemiringWithMonusHom (α β : Type) [SemiringWithMonus α] [SemiringWithMonus β] extends α →+* β :

              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).

              Instances
                @[implicit_reducible]
                Equations

                If ν is an injective m-semiring homomorphism from α to β, and β is idempotent, so is α.

                If ν is an m-semiring homomorphism from α onto β, and α is idempotent, so is β.

                If ν is an injective m-semiring homomorphism from α to β, and β has left-distributivity of times over monus, so has α.

                If ν is an m-semiring homomorphism from α onto β, and α has left-distributivity of times over monus, so has β.

                Miscellaneous #

                class HasAltLinearOrder (α : Type u) :
                Instances