Context (consumer)
AffineScript ships db-theory #3 in the next PR — a new stdlib/Aggregate.affine module exposing SQL group-by + aggregation primitives (count / sum / min / max / avg) plus a db_group_by convenience returning the grouped result-set as JSON. The proof-relevant property is the classical aggregation-as-monoid-homomorphism claim (Green / Karvounarakis / Tannen, provenance semirings): each aggregator is a commutative monoid; group-by is the indexed sum.
Sibling to echo-types#174 (Transaction safety / no-section-of-collapsing-map).
Audit summary (2026-06-01)
Echo-types currently carries no reusable monoid/semiring infrastructure. The closest scaffolding:
EchoCost.CostAlgebra — left-identity + monotonicity, no composition law. Reusable as a Monoid instance once Monoid exists.Ordinal/Brouwer/OmegaPow.agda#additive-principal — exactly the monoid closure property for ω^n exponents.EchoDecorationStructure.agda — observer-level lattice, not data-level algebra.
docs/adjacency/provenance-semirings.adoc already names the relevant distinctness story (echo adds types; semirings add scalars; this module bridges both).
Proposed module shape
moduleEchoAggregationwhereopen importLevelusing (Level; suc)
open importRelation.Binary.PropositionalEqualityusing (_≡_)
recordMonoid (ℓ : Level) :Set (suc ℓ) wherefieldElem :Set ℓ
ε : Elem
_⊕_ : Elem → Elem → Elem
assoc :∀ a b c → (a ⊕ b) ⊕ c ≡ a ⊕ (b ⊕ c)
identity-l :∀ a → ε ⊕ a ≡ a
identity-r :∀ a → a ⊕ ε ≡ a
-- A GroupAggregator over keys K, values V, monoid M is the data of:-- an aggregator agg : V → M.Elem-- that lifts to a fold over rows, indexed by their K-key.recordGroupAggregator {ℓ} (K V :Set) (M : Monoid ℓ) :Set ℓ whereopenMonoid M
fieldagg : V → Elem
-- Headline lemma (proof TBD upstream; consumer references):-- aggregation-as-fold :-- (rows : List (K × V)) →-- aggregate-by-key (partition rows by .fst)-- (λ vs → foldr (λ v acc → agg v ⊕ acc) ε vs)-- ≡ the actual SQL GROUP-BY semantics.-- Concrete instances:-- countMonoid : Monoid ℓ-zero (ℕ, 0, +)-- sumMonoid : Monoid ℓ-zero (ℕ, 0, +)-- minMonoid : Monoid ℓ-zero (ℕ ∪ {∞}, ∞, min)-- maxMonoid : Monoid ℓ-zero (ℕ ∪ {-∞}, -∞, max)-- -- avg is NOT a monoid (no identity); express as sum / count.Why this matters
Cross-doc
- Consumer cross-doc lands at
affinescript/docs/academic/proofs/db-theory-3-aggregation-as-fold.md and back-links this issue. - Sibling: echo-types#174 (Transaction safety / no-section-of-collapsing-map).
Context (consumer)
AffineScript ships db-theory #3 in the next PR — a new
stdlib/Aggregate.affinemodule exposing SQL group-by + aggregation primitives (count / sum / min / max / avg) plus adb_group_byconvenience returning the grouped result-set as JSON. The proof-relevant property is the classical aggregation-as-monoid-homomorphism claim (Green / Karvounarakis / Tannen, provenance semirings): each aggregator is a commutative monoid; group-by is the indexed sum.Sibling to echo-types#174 (Transaction safety / no-section-of-collapsing-map).
Audit summary (2026-06-01)
Echo-types currently carries no reusable monoid/semiring infrastructure. The closest scaffolding:
EchoCost.CostAlgebra— left-identity + monotonicity, no composition law. Reusable as aMonoidinstance onceMonoidexists.Ordinal/Brouwer/OmegaPow.agda#additive-principal— exactly the monoid closure property for ω^n exponents.EchoDecorationStructure.agda— observer-level lattice, not data-level algebra.docs/adjacency/provenance-semirings.adocalready names the relevant distinctness story (echo adds types; semirings add scalars; this module bridges both).Proposed module shape
Why this matters
EchoCostordered-monoid sketch (now formalisable as aMonoidinstance) and theprovenance-semirings.adocadjacency.Print Assumptionsclean); concretecountMonoid/sumMonoid/minMonoid/maxMonoidinstances; signature foraggregation-as-fold(the proof itself may follow in a stacked PR).Cross-doc
affinescript/docs/academic/proofs/db-theory-3-aggregation-as-fold.mdand back-links this issue.