Documentation

Docs / Proofs

Auditor.lean

Lean 4 source (with Mathlib). 11 theorems. Download Auditor.lean.

Theorems in this file
  • e_dot
  • not_determined_of_notMem_span
  • determined_of_mem_span
  • exposed_iff_determined
  • accept_hides_every_value
  • refuse_by_rank_iff
  • audit_simulatable
  • accept_size
  • accept_no_small_difference
  • one_person_difference_is_exposed
  • one_person_difference_refused
/-
  The auditor for aggregates (T8 of the Theorems page, SEMANTICS §3), machine-checked with Mathlib.
  25 November 2026.

  Model. Persons are a finite type `ι`; one measure is a value vector `m : ι → ℚ` (salaries, say).
  A sum or average over a known population `s` releases `ind s ⬝ᵥ m`. The history `H` is the list of
  populations whose sums were already released to the same requester on the same measure in the window.
  The auditor (SEMANTICS §3) refuses a new population `q` when
    (a) `|q| < k`,
    (b) some earlier population differs from `q` by 1 … k−1 people in either direction, or
    (c) some person's indicator `e_i` lies in the span of the released vectors and `q`  (the rank test of
        `core.py`'s `exposed()`).
  It accepts otherwise.

  What is proved here:
  * `not_determined_of_notMem_span`: if `e_i` is not in the span of the released vectors, then for every
    value vector `m` there is another `m'` that gives every released sum the same answer and differs on `i`.
  * `determined_of_mem_span`: the converse; if `e_i` is in the span, every `m'` that gives the same answers
    agrees with `m` on `i`. Together (`exposed_iff_determined`): the rank test is exact.
  * `accept_hides_every_value`: whatever the auditor accepts, no single person's value is determined by
    all released sums, the new one included (T8, part 1).
  * `refuse_by_rank_iff`: the rank clause refuses exactly when some value would be determined.
  * `audit_simulatable`: the decision is a function of populations only; two value vectors give the same
    decision (T8, part 2). The decision does not even take a value vector as input.
  * `accept_size`, `accept_no_small_difference`: the k-threshold and the differencing rule.
  * `one_person_difference_is_exposed`: two populations that differ by one person expose that person;
    the rank test catches it even when `k = 1`.

  Not modelled: the window, which measure, agents acting for the requester (the history is given), and
  bounds that are not exact (intervals, maxima, dominance), which T8 states as limits.
-/
import Mathlib

open Matrix

set_option linter.unusedSectionVars false

namespace Auditor

variable {ι : Type*} [Fintype ι] [DecidableEq ι]

/-- The vector that picks person `i`. -/
def e (i : ι) : ι → ℚ := fun j => if i = j then 1 else 0

/-- The indicator of a population. -/
def ind (s : Finset ι) : ι → ℚ := fun j => if j ∈ s then 1 else 0

lemma e_dot (i : ι) (m : ι → ℚ) : e i ⬝ᵥ m = m i := by
  simp [e, dotProduct]

/-! ## Linear algebra: the rank test is exact -/

/-- **No value determined.** If `e_i` is not in the span of the released vectors `S`, some other value
vector answers every released sum the same and differs on person `i`. -/
theorem not_determined_of_notMem_span (S : Set (ι → ℚ)) (i : ι)
    (h : e i ∉ Submodule.span ℚ S) (m : ι → ℚ) :
    ∃ m' : ι → ℚ, (∀ v ∈ S, v ⬝ᵥ m' = v ⬝ᵥ m) ∧ m' i ≠ m i := by
  obtain ⟨f, hfx, hmap⟩ := Submodule.exists_dual_map_eq_bot_of_notMem h
    (Module.Projective.of_free)
  -- represent the functional `f` by a vector `d`
  let d : ι → ℚ := fun j => f (e j)
  have hf : ∀ x : ι → ℚ, f x = x ⬝ᵥ d := by
    intro x
    rw [LinearMap.pi_apply_eq_sum_univ f x]
    simp only [dotProduct, d, smul_eq_mul]
    rfl
  refine ⟨m + d, ?_, ?_⟩
  · intro v hv
    have hv0 : f v = 0 := by
      have : f v ∈ Submodule.map f (Submodule.span ℚ S) :=
        Submodule.mem_map_of_mem (Submodule.subset_span hv)
      rw [hmap] at this
      simpa using this
    rw [dotProduct_add, ← hf v, hv0, add_zero]
  · intro heq
    apply hfx
    rw [hf, e_dot]
    have : (m + d) i - m i = 0 := by rw [heq]; ring
    simpa using this

/-- **Determined.** If `e_i` is in the span, every value vector that gives the same answers agrees on `i`. -/
theorem determined_of_mem_span (S : Set (ι → ℚ)) (i : ι)
    (h : e i ∈ Submodule.span ℚ S) (m m' : ι → ℚ)
    (hsame : ∀ v ∈ S, v ⬝ᵥ m' = v ⬝ᵥ m) : m' i = m i := by
  have key : ∀ v ∈ Submodule.span ℚ S, v ⬝ᵥ m' = v ⬝ᵥ m := by
    intro v hv
    induction hv using Submodule.span_induction with
    | mem x hx => exact hsame x hx
    | zero => simp
    | add x y _ _ hx hy => rw [add_dotProduct, add_dotProduct, hx, hy]
    | smul a x _ hx => rw [smul_dotProduct, smul_dotProduct, hx]
  have := key (e i) h
  rwa [e_dot, e_dot] at this

/-- **The rank test is exact.** `e_i` is in the span of the released vectors if and only if the released
sums determine person `i`'s value. -/
theorem exposed_iff_determined (S : Set (ι → ℚ)) (i : ι) :
    e i ∈ Submodule.span ℚ S ↔
      ∀ m m' : ι → ℚ, (∀ v ∈ S, v ⬝ᵥ m' = v ⬝ᵥ m) → m' i = m i := by
  constructor
  · exact fun h m m' hs => determined_of_mem_span S i h m m' hs
  · intro hdet
    by_contra hn
    obtain ⟨m', hs, hne⟩ := not_determined_of_notMem_span S i hn 0
    exact hne (hdet 0 m' hs)

/-! ## The auditor -/

/-- The vectors released after accepting `q` on top of history `H`. -/
def released (H : List (Finset ι)) (q : Finset ι) : Set (ι → ℚ) :=
  {v | ∃ s ∈ q :: H, v = ind s}

/-- The rank clause: some person's value would become computable. -/
def exposes (H : List (Finset ι)) (q : Finset ι) : Prop :=
  ∃ i : ι, e i ∈ Submodule.span ℚ (released H q)

/-- The differencing clause (F6): an earlier population differs from `q` by 1 … k−1 people. -/
def smallDifference (k : ℕ) (H : List (Finset ι)) (q : Finset ι) : Prop :=
  ∃ h ∈ H, (0 < (q \ h).card ∧ (q \ h).card < k) ∨ (0 < (h \ q).card ∧ (h \ q).card < k)

/-- The auditor's decision. Its inputs are `k`, the past populations and the new population: no values. -/
def accepts (k : ℕ) (H : List (Finset ι)) (q : Finset ι) : Prop :=
  k ≤ q.card ∧ ¬ smallDifference k H q ∧ ¬ exposes H q

/-- **T8, part 1.** If the auditor accepts, no person's value is determined by all the sums released so far,
the new one included: for every value vector and every person there is another value vector that answers
every released sum the same and differs on that person. -/
theorem accept_hides_every_value (k : ℕ) (H : List (Finset ι)) (q : Finset ι)
    (hacc : accepts k H q) (m : ι → ℚ) (i : ι) :
    ∃ m' : ι → ℚ, (∀ s ∈ q :: H, ind s ⬝ᵥ m' = ind s ⬝ᵥ m) ∧ m' i ≠ m i := by
  have hn : e i ∉ Submodule.span ℚ (released H q) := fun hm => hacc.2.2 ⟨i, hm⟩
  obtain ⟨m', hs, hne⟩ := not_determined_of_notMem_span _ i hn m
  exact ⟨m', fun s hsH => hs (ind s) ⟨s, hsH, rfl⟩, hne⟩

/-- The rank clause refuses exactly when, after the release, some person's value would be determined. -/
theorem refuse_by_rank_iff (H : List (Finset ι)) (q : Finset ι) :
    exposes H q ↔ ∃ i : ι, ∀ m m' : ι → ℚ,
      (∀ s ∈ q :: H, ind s ⬝ᵥ m' = ind s ⬝ᵥ m) → m' i = m i := by
  unfold exposes
  constructor
  · rintro ⟨i, hi⟩
    refine ⟨i, fun m m' hs => ?_⟩
    apply (exposed_iff_determined _ i).1 hi m m'
    rintro v ⟨s, hsH, rfl⟩
    exact hs s hsH
  · rintro ⟨i, hdet⟩
    refine ⟨i, (exposed_iff_determined _ i).2 ?_⟩
    intro m m' hs
    exact hdet m m' (fun s hsH => hs (ind s) ⟨s, hsH, rfl⟩)

/-- A decision procedure that is also handed the true values, as a deployed auditor could be. -/
def acceptsGiven (k : ℕ) (H : List (Finset ι)) (q : Finset ι) (_m : ι → ℚ) : Prop :=
  accepts k H q

/-- **T8, part 2 (simulatable).** The decision is the same for every value vector: whether it refuses can be
computed by the requester from the populations alone, so a refusal reveals nothing about the values. -/
theorem audit_simulatable (k : ℕ) (H : List (Finset ι)) (q : Finset ι) (m m' : ι → ℚ) :
    acceptsGiven k H q m ↔ acceptsGiven k H q m' := Iff.rfl

/-- The k-threshold. -/
theorem accept_size (k : ℕ) (H : List (Finset ι)) (q : Finset ι) (hacc : accepts k H q) :
    k ≤ q.card := hacc.1

/-- The differencing rule: an accepted population differs from every earlier one by 0 or at least k people,
in each direction. -/
theorem accept_no_small_difference (k : ℕ) (H : List (Finset ι)) (q : Finset ι)
    (hacc : accepts k H q) (h : Finset ι) (hh : h ∈ H) :
    ((q \ h).card = 0 ∨ k ≤ (q \ h).card) ∧ ((h \ q).card = 0 ∨ k ≤ (h \ q).card) := by
  have hn := hacc.2.1
  constructor
  · by_contra hc
    push Not at hc
    exact hn ⟨h, hh, Or.inl ⟨Nat.pos_of_ne_zero hc.1, hc.2⟩⟩
  · by_contra hc
    push Not at hc
    exact hn ⟨h, hh, Or.inr ⟨Nat.pos_of_ne_zero hc.1, hc.2⟩⟩

/-- **Differencing by one person is exposed.** If the new population is an earlier one plus one person,
that person's value is computable, so the rank clause refuses even when `k = 1`. -/
theorem one_person_difference_is_exposed (H : List (Finset ι)) (h : Finset ι) (hh : h ∈ H)
    (i : ι) (hi : i ∉ h) : exposes H (insert i h) := by
  refine ⟨i, ?_⟩
  have hq : ind (insert i h) ∈ Submodule.span ℚ (released H (insert i h)) :=
    Submodule.subset_span ⟨insert i h, List.mem_cons_self .., rfl⟩
  have hh' : ind h ∈ Submodule.span ℚ (released H (insert i h)) :=
    Submodule.subset_span ⟨h, List.mem_cons_of_mem _ hh, rfl⟩
  have : e i = ind (insert i h) - ind h := by
    funext j
    by_cases hj : j = i
    · subst hj; simp [e, ind, hi]
    · have : i ≠ j := fun hij => hj hij.symm
      simp [e, ind, hj, this]
  rw [this]
  exact Submodule.sub_mem _ hq hh'

/-- Corollary: with any `k`, a population one person away from an earlier one is never accepted. -/
theorem one_person_difference_refused (k : ℕ) (H : List (Finset ι)) (h : Finset ι) (hh : h ∈ H)
    (i : ι) (hi : i ∉ h) : ¬ accepts k H (insert i h) :=
  fun hacc => hacc.2.2 (one_person_difference_is_exposed H h hh i hi)

end Auditor

#print axioms Auditor.not_determined_of_notMem_span
#print axioms Auditor.determined_of_mem_span
#print axioms Auditor.exposed_iff_determined
#print axioms Auditor.accept_hides_every_value
#print axioms Auditor.refuse_by_rank_iff
#print axioms Auditor.audit_simulatable
#print axioms Auditor.accept_size
#print axioms Auditor.accept_no_small_difference
#print axioms Auditor.one_person_difference_is_exposed
#print axioms Auditor.one_person_difference_refused

Last built 2026-11-25