K-semimodules and the free K-tensor #
This file develops the algebraic infrastructure required to interpret the
aggregation operator on K-annotated relations, following the framework of
Amsterdamer, Deutch & Tannen, Provenance for aggregate queries
(Section IV-B, Definition 7 of Sen, Maniu & Senellart, ProvSQL).
Main definitions #
KSemiModule K M– a left action of aCommSemiringWithMonus Kon anAddCommMonoid Msatisfying the six standard semimodule axioms (zero_smul,one_smul,add_smul,smul_add,smul_zero,mul_smul). The same axioms as Mathlib'sModule, exposed under our own name so that downstream provenance proofs depend onCommSemiringWithMonusdirectly (not on the more abstractSemiring).KTensor K M– a representation of the free formal sums∑ αᵢ ⊗ mᵢ, realised as aMultiset (K × M)of monomials. HasZero,AddandAddCommMonoid, plus a scalar actionKTensor.smul, anembedmap(K × M) → KTensor K M, and a contractionbindoperator.Note:
KTensor K Mis not claimed to be aKSemiModule K. The underlyingMultiset (K × M)is the free formal sum modulo permutation only; bilinearity relations such as(α + β) ⊗ m = α ⊗ m + β ⊗ m,0 ⊗ m = 0, andα ⊗ (m₁ + m₂) = α ⊗ m₁ + α ⊗ m₂are not enforced. Quotienting by those relations gives Mathlib-styleTensorProduct, which is the right target for correctness theorems but adds substantial setoid-quotient machinery; the un-quotiented representation is enough for evaluating aggregations end-to-end.
Main results #
instance : KSemiModule K K– the canonical action of aCommSemiringWithMonus Kon itself via multiplication.
References #
- Amsterdamer, Deutch & Tannen
- Sen, Maniu & Senellart (Section IV-B, Def. 7)
The KSemiModule typeclass #
A K-semimodule structure on an additive commutative monoid M,
relative to a CommSemiringWithMonus K. The six axioms are the
bilinearity of the action (α, m) ↦ α • m, matching Mathlib's Module
over a semiring.
- smul : K → M → M
Left action of
KonM. 0 • m = 0: the zero ofKannihilatesm.1 • m = m: the multiplicative unit ofKacts trivially.(α + β) • m = α • m + β • m: distributivity overK's addition.α • (m + n) = α • m + α • n: distributivity overM's addition.α • 0 = 0: the action sends0 : Mto0.(α * β) • m = α • (β • m): the action is multiplicative inK.
Instances
Infix notation for the KSemiModule action. We deliberately do not use
Mathlib's • to avoid forcing instance resolution on every
SemiringWithMonus-flavoured proof.
Equations
- KSemiModule.«term_⋆ₖ_» = Lean.ParserDescr.trailingNode `KSemiModule.«term_⋆ₖ_» 73 74 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⋆ₖ ") (Lean.ParserDescr.cat `term 73))
Instances For
Canonical instance: every CommSemiringWithMonus acts on itself. #
The canonical K-semimodule structure on K itself: the action is the
semiring's multiplication.
Equations
- CommSemiringWithMonus.instKSemiModuleSelf = { smul := fun (x1 x2 : K) => x1 * x2, zero_smul := ⋯, one_smul := ⋯, add_smul := ⋯, smul_add := ⋯, smul_zero := ⋯, mul_smul := ⋯ }
The free K-tensor KTensor K M #
A formal-sum representation of the free K-module generated by M.
Each element is a multiset of monomials (α, m) : K × M. Addition is
multiset union; the scalar action (β, t) ↦ β • t multiplies the
K-coefficient of each monomial by β on the left.
The representation is the free formal sum modulo permutation only:
bilinearity relations like (α₁ + α₂) ⊗ m = α₁ ⊗ m + α₂ ⊗ m are not
enforced. Equality in the un-quotiented KTensor K M is stricter than
in the proper tensor product K ⊗ M. We expose this data structure
because it is enough to evaluate aggregations; the proper quotient
will appear once we state and prove correctness theorems for the
aggregation semantics.
Equations
- KTensor.instZero = { zero := KTensor.instZero._aux_1 }
Equations
- KTensor.instAdd = { add := KTensor.instAdd._aux_1 }
Equations
- One or more equations did not get rendered due to their size.
Equations
- KTensor.instRepr = { reprPrec := KTensor.instRepr._aux_1 }
Push a KTensor K M forward along a function f : K → K', mapping each
monomial's K-coefficient through f. Used in particular to push forward
along a SemiringWithMonusHom.
Equations
- KTensor.mapHom f t = Multiset.map (fun (p : K × M) => (f p.1, p.2)) t
Instances For
Scalar action of K on KTensor K M: multiply the K-coefficient of
each monomial by β on the left. This is not the action of a
KSemiModule instance, because the un-quotiented representation does
not satisfy add_smul or zero_smul; we expose it as a plain function
for use in the aggregation evaluator.
Equations
- KTensor.smul β t = Multiset.map (fun (p : K × M) => (β * p.1, p.2)) t