Skip to content

Commit 67189c7

Browse files
examples: Example 5 — database provenance (K-provenance semiring) (#81)
Adds `proofs/agda/EchoExampleProvenance.agda` — Example 5 from the presentation-dependence cluster identified by PR #76. ## What lands - Concrete `Row` with payload (ℕ) + K-provenance Bool annotation - `project : Row → ℕ` (forgets provenance) — the Echo signal - Two distinct rows with the same payload but distinct provenances - Headlines pinned in `Smoke.agda`: - `provenance-collapses` — Σ-witness that projection is non-injective - `echo-prov-true` / `echo-prov-false` — concrete echo witnesses - `echoes-distinguish-provenance` — distinct prov on carriers at the same projected value ("Echo remembers what projection forgot") - `echo-prov-true≢echo-prov-false` — the two echoes themselves are constructively separated - `collapse-via-residue` — optional tie-in to the `EchoResidue` layer - Wired into `All.agda` alphabetically (before `EchoExamples`) ## Cluster relationship Example 5 is the canonical motivating example for "what does Echo carry?" — the shape is the same as Example 1 (`square9 / SignedNine` in `EchoExamples.agda`), with provenance semantics making the carried data load-bearing in the database setting. Module header has a 4–6 line comment making the analogy explicit. This slice lands the Agda half for Example 5 specifically; Examples 9 and 10 stay informal per PR #76's §5 "meta-pattern only — no new Agda module needed" verdict for the cluster as a whole. (One formalisation does not change that verdict — the cluster still doesn't motivate a new axis; this is just upgrading the one entry whose Σ-shape is small enough to ship as a thin slice.) ## Invariants - `--safe --without-K`; no postulates, no funext, no escape pragmas - No `EchoExamples.agda` modifications (new module is cleaner; lanes 4 and 5 also avoid it) - Clean-worktree Agda build green for the new module, `All.agda`, and `Smoke.agda` (all exit 0) Refs #76 (presentation-dependence cluster decision). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a1e9cbc commit 67189c7

3 files changed

Lines changed: 173 additions & 0 deletions

File tree

proofs/agda/All.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open import AntiEcho
77
open import EchoKernel
88
open import EchoCharacteristic
99
open import EchoResidue
10+
open import EchoExampleProvenance
1011
open import EchoExamples
1112
open import EchoExampleParser
1213

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{-# OPTIONS --safe --without-K #-}
2+
3+
-- Example 5 (docs/echo-types/examples.md) — database provenance via
4+
-- K-provenance semiring. A tiny model of a database row tagged with a
5+
-- K-provenance annotation, where the query projects to the payload
6+
-- only and forgets the annotation. `Echo project y` captures the lost
7+
-- provenance: distinct provenances at the same projected value give
8+
-- distinct echoes.
9+
--
10+
-- The shape is the same as Example 1 (`square9 / SignedNine` in
11+
-- EchoExamples.agda): a two-element source whose elements project to
12+
-- the same B-value, witnessed by a pair of constructively distinct
13+
-- echoes at that value. The semantic load shifts: where SignedNine
14+
-- carries the *sign* of a numerical preimage, the K-provenance Row
15+
-- carries the *origin annotation* of a database row. Both are the
16+
-- canonical "what does Echo carry?" demonstration; only the second
17+
-- makes the carried data load-bearing in the database setting.
18+
--
19+
-- The K-semiring is taken as the smallest non-trivial choice: Bool
20+
-- with ∧ as product and ∨ as sum (the trust-token / boolean
21+
-- provenance semiring). We do not need the semiring laws to land the
22+
-- echo lemmas — the constructive distinguishability of `true` and
23+
-- `false` is all the machinery the headline theorems consume.
24+
--
25+
-- Cluster context: this module is the formal Agda counterpart to the
26+
-- informal-only Example 5 in examples.md, which sits in the
27+
-- presentation-dependence cluster (PR #76) alongside the parser
28+
-- recovery (Example 9) and abstract-interpretation widening
29+
-- (Example 10) entries. The Σ-over-extra-parameter shape PR #76
30+
-- identifies for the cluster is, in this slice, the Σ on the row's
31+
-- `prov` field.
32+
33+
module EchoExampleProvenance where
34+
35+
open import Echo
36+
open import EchoResidue using
37+
( EchoR ; echo-to-residue )
38+
39+
open import Data.Bool.Base using (Bool; true; false; _∧_; _∨_)
40+
open import Data.Empty using (⊥)
41+
open import Data.Nat.Base using (ℕ)
42+
open import Data.Product.Base using (Σ; _×_; _,_; proj₁; proj₂)
43+
open import Data.Unit.Base using (⊤; tt)
44+
open import Relation.Binary.PropositionalEquality
45+
using (_≡_; _≢_; refl; cong; sym; trans; subst)
46+
open import Relation.Nullary using (¬_)
47+
48+
-- Reusable B-side disequality. Inlined to keep the module's
49+
-- dependency surface to its direct imports (EchoExamples carries the
50+
-- same lemma; we deliberately do not import it to avoid coupling
51+
-- two example modules).
52+
true≢false : true ≢ false
53+
true≢false ()
54+
55+
------------------------------------------------------------
56+
-- A tiny database row + K-provenance annotation.
57+
------------------------------------------------------------
58+
59+
-- A row carries its visible payload (`payload : ℕ`, the value a
60+
-- projection-only query would return) and its K-provenance
61+
-- annotation (`prov : Bool`, the boolean trust-token).
62+
record Row : Set where
63+
constructor mkRow
64+
field
65+
payload :
66+
prov : Bool
67+
open Row
68+
69+
-- The query: project to the payload, discarding the provenance
70+
-- annotation. This is the Echo signal — the function whose fibre at
71+
-- a payload `n` is the set of rows that would answer the query with `n`.
72+
project : Row
73+
project = payload
74+
75+
------------------------------------------------------------
76+
-- Two distinct rows with the same payload but distinct provenances.
77+
------------------------------------------------------------
78+
79+
row-with-prov-true : Row
80+
row-with-prov-true = mkRow 0 true
81+
82+
row-with-prov-false : Row
83+
row-with-prov-false = mkRow 0 false
84+
85+
------------------------------------------------------------
86+
-- Headline 1: projection is non-injective — the database query
87+
-- conflates rows that differ in provenance.
88+
------------------------------------------------------------
89+
90+
provenance-collapses :
91+
Σ Row (λ r₁ Σ Row (λ r₂ prov r₁ ≢ prov r₂ × project r₁ ≡ project r₂))
92+
provenance-collapses =
93+
row-with-prov-true , row-with-prov-false , true≢false , refl
94+
95+
------------------------------------------------------------
96+
-- Headline 2: concrete echoes at the same projected value carrying
97+
-- the two distinct provenances. These are the two inhabitants the
98+
-- query loses when it returns only the payload.
99+
------------------------------------------------------------
100+
101+
echo-prov-true : Echo project 0
102+
echo-prov-true = echo-intro project row-with-prov-true
103+
104+
echo-prov-false : Echo project 0
105+
echo-prov-false = echo-intro project row-with-prov-false
106+
107+
------------------------------------------------------------
108+
-- Headline 3: Echo remembers what projection forgets. The carriers
109+
-- of the two echoes at the same projected value can have distinct
110+
-- provenance annotations — the precise content the projection
111+
-- discarded.
112+
------------------------------------------------------------
113+
114+
echoes-distinguish-provenance :
115+
prov (proj₁ echo-prov-true) ≢ prov (proj₁ echo-prov-false)
116+
echoes-distinguish-provenance = true≢false
117+
118+
-- Strengthening: the two specific echoes above are themselves
119+
-- distinct as elements of `Echo project 0`. This is the analogue of
120+
-- `echo-plus3≢echo-minus3` in Example 1; the projection on the
121+
-- Σ-first component is `prov` here (not the SignedNine constructor),
122+
-- and that projection separates the two echoes.
123+
echo-prov-true≢echo-prov-false : echo-prov-true ≢ echo-prov-false
124+
echo-prov-true≢echo-prov-false p =
125+
true≢false (cong (λ e prov (proj₁ e)) p)
126+
127+
------------------------------------------------------------
128+
-- Headline 4 (optional residue tie-in): projecting an echo down to
129+
-- the trivial residue layer collapses the two distinct provenances
130+
-- to a single residue inhabitant. This is the database analogue of
131+
-- `collapse-residue-identifies` (Example 4): the residue layer
132+
-- forgets the provenance bit the full echo had been carrying, so
133+
-- the two formerly-distinct echoes become residue-indistinguishable.
134+
------------------------------------------------------------
135+
136+
-- Trivial cert over ℕ: the no-information residue layer, parallel
137+
-- to `EchoResidue.TrivialCert` but at the project-side codomain
138+
-- rather than at `⊤`.
139+
ProjCert : Set
140+
ProjCert _ _ =
141+
142+
prov-kappa : Row
143+
prov-kappa _ = tt
144+
145+
prov-sound : r ProjCert (prov-kappa r) (project r)
146+
prov-sound _ = tt
147+
148+
-- Lower a project-echo into the trivial residue layer. The Cert
149+
-- relation here is no-information at the projected ℕ — exactly
150+
-- the layer at which provenance becomes unrecoverable.
151+
project-to-residue : {n : ℕ} Echo project n EchoR ⊤ ProjCert n
152+
project-to-residue {n} =
153+
echo-to-residue project prov-kappa ProjCert prov-sound
154+
155+
collapse-via-residue :
156+
project-to-residue echo-prov-true ≡ project-to-residue echo-prov-false
157+
collapse-via-residue = refl

proofs/agda/Smoke.agda

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ open import EchoExampleParser using
9191
; paren-nested-balanced
9292
; paren-pair-balanced
9393
)
94+
95+
-- Example 5 (docs/echo-types/examples.md §5): database provenance via
96+
-- K-provenance semiring. Distinct Bool-provenance rows project to the
97+
-- same payload, witnessing the non-injectivity of `project` and
98+
-- producing distinct echoes at the same projected value.
99+
open import EchoExampleProvenance using
100+
( Row
101+
; project
102+
; provenance-collapses
103+
; echo-prov-true
104+
; echo-prov-false
105+
; echoes-distinguish-provenance
106+
; echo-prov-true≢echo-prov-false
107+
; collapse-via-residue
108+
)
94109
open import VecRotation using (rotL-alternating; rotR-alternating; map-alternating)
95110

96111
open import EchoApprox using

0 commit comments

Comments
 (0)