From 6fca15d764b1dab10eba8ffd89618a04e9dd8706 Mon Sep 17 00:00:00 2001 From: Marc Ilunga Date: Thu, 26 Nov 2026 12:19:10 +0100 Subject: [PATCH] Encode the register addresses used by a bounded caller --- REUSE.md | 1 + src/Commons.lean | 2 + .../AbstractModel/FiniteAddresses.lean | 74 +++++++++++++++++++ src/Tests.lean | 1 + src/Tests/AbstractModelFiniteAddresses.lean | 62 ++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 src/Commons/Definitions/AbstractModel/FiniteAddresses.lean create mode 100644 src/Tests/AbstractModelFiniteAddresses.lean diff --git a/REUSE.md b/REUSE.md index 56f194c..ee7023d 100644 --- a/REUSE.md +++ b/REUSE.md @@ -74,6 +74,7 @@ named `budget` argument. The object index below supplies owners for those declar | Needed object | Declaration and module | | --- | --- | | Decode register commands using inverses only on their operands and destinations | `mapCommand_mapCommand_eq_of_inverse_on` in `Commons.Definitions.AbstractModel.Domain` | +| Encode the register addresses used by a finite command set or bounded caller | `exists_fin_address_encoding`, `exists_fin_address_encoding_of_queryBounded` in `Commons.Definitions.AbstractModel.FiniteAddresses` | | Move outside query and reply maps through attachment | `relabel_apply_outside_both` in `RandomSystems.DDC.DDCRelabel` | | Extend distinct list-position labels to evaluated inputs | `List.exists_perm_apply_idxOf_eq` in `Probability.List.Permutation` | | Compare chronological and evaluated inputs under one uniform permutation | `chronologicalLabelingProgram_uniform_mass_replies_eq_of_injOn` in `RandomSystems.Converter.ChronologicalLabeling.Uniform` | diff --git a/src/Commons.lean b/src/Commons.lean index b2fc01d..b4e84e3 100644 --- a/src/Commons.lean +++ b/src/Commons.lean @@ -92,6 +92,8 @@ public import Commons.Definitions.AbstractModel.DomainExpansion public import Commons.Definitions.AbstractModel.DomainExpansion.Laws public import Commons.Definitions.AbstractModel.RegisterDDC.AddressMap +public import Commons.Definitions.AbstractModel.FiniteAddresses + /-! Common ideal systems, primitive syntax, domain restrictions and security definitions. `Definitions` holds these interfaces and contracts; `Schemes` holds concrete schemes, and `Tests` their known-answer tests. -/ diff --git a/src/Commons/Definitions/AbstractModel/FiniteAddresses.lean b/src/Commons/Definitions/AbstractModel/FiniteAddresses.lean new file mode 100644 index 0000000..0df6a57 --- /dev/null +++ b/src/Commons/Definitions/AbstractModel/FiniteAddresses.lean @@ -0,0 +1,74 @@ +module + +public import Commons.Definitions.AbstractModel.Domain +public import RandomSystems.System.FiniteQueries +public import Mathlib.Data.Finset.Option + +/-! +# Finite register addresses + +`exists_fin_address_encoding` codes a finite set of commands using a finite +address footprint containing the initial register, all operands, and every destination. +`exists_fin_address_encoding_of_queryBounded` applies it to the finite query support of +an adaptive bounded caller. Decoding recovers each supported command and its submitted value. +-/ + +@[expose] public section + +namespace Commons.AbstractModel + +open SystemAlgebra + +variable + -- `S` carries register values, `P` model parameters, and `ι` register addresses. + -- `M` supplies the operation and observation arities that determine command operands. + {S P ι : Type} {M : Commons.AbstractModel S P} [DecidableEq ι] + +/-- A finite command set uses finitely many operands, destinations and initial addresses. -/ +theorem exists_fin_address_encoding + -- `input` is the initial register; `K` is the finite set of possible caller commands. + (input : ι) (K : Set (M.Command ι)) (finite : K.Finite) : + -- `code` assigns finite addresses; `decode` embeds them back into the original registers. + ∃ (n : ℕ) (code : ι → Fin n) (decode : Fin n ↪ ι), + decode (code input) = input ∧ + (∀ z ∈ K, ∀ a, a ∈ M.reads z ∨ M.target z = some a → decode (code a) = a) ∧ + (∀ z ∈ K, M.mapCommand decode (M.mapCommand code z) = z) := by + let addresses : M.Command ι → Finset ι := fun z => M.reads z ∪ (M.target z).toFinset + let footprint : Set ι := insert input (⋃ z ∈ K, (addresses z : Set ι)) + have small : footprint.Finite := + (finite.biUnion (fun z _ => (addresses z).finite_toSet)).insert input + obtain ⟨n, code, decode, inverse⟩ := small.exists_fin_encoding + have initial : decode (code input) = input := inverse input (Set.mem_insert _ _) + have covers (z : M.Command ι) (hz : z ∈ K) (a : ι) + (ha : a ∈ M.reads z ∨ M.target z = some a) : decode (code a) = a := by + apply inverse a + apply Set.mem_insert_of_mem + refine Set.mem_iUnion.mpr ⟨z, Set.mem_iUnion.mpr ⟨hz, ?_⟩⟩ + change a ∈ M.reads z ∪ (M.target z).toFinset + rcases ha with operand | target + · exact Finset.mem_union_left _ operand + · exact Finset.mem_union_right _ (by rw [target]; exact Finset.mem_singleton_self a) + refine ⟨n, code, decode, initial, covers, ?_⟩ + intro z hz + exact mapCommand_mapCommand_eq_of_inverse_on code decode z + (fun a ha => covers z hz a (Or.inl ha)) (fun a ha => covers z hz a (Or.inr ha)) + +/-- A bounded caller has one address code valid across every adaptive reply branch. -/ +theorem exists_fin_address_encoding_of_queryBounded + -- `B` carries replies; the command and register alphabets remain arbitrary. + {B : Type} [_root_.Finite B] (input : ι) (E : DDE (M.Command ι) B) + -- `bounded` limits every adaptive branch to fewer than `q` replies before another query. + {q : ℕ} (bounded : QueryBounded q E) : + -- `code` assigns finite addresses; `decode` embeds them back into the original registers. + ∃ (n : ℕ) (code : ι → Fin n) (decode : Fin n ↪ ι), + decode (code input) = input ∧ + (∀ ys z, z ∈ E.1 ys → ∀ a, + a ∈ M.reads z ∨ M.target z = some a → decode (code a) = a) ∧ + (∀ ys z, z ∈ E.1 ys → M.mapCommand decode (M.mapCommand code z) = z) := by + obtain ⟨n, code, decode, initial, addresses, commands⟩ := + exists_fin_address_encoding input {z | ∃ ys, z ∈ E.1 ys} + (finite_queries_of_queryBounded E bounded) + exact ⟨n, code, decode, initial, + fun ys z hz => addresses z ⟨ys, hz⟩, fun ys z hz => commands z ⟨ys, hz⟩⟩ + +end Commons.AbstractModel diff --git a/src/Tests.lean b/src/Tests.lean index 95ee589..89bfbd4 100644 --- a/src/Tests.lean +++ b/src/Tests.lean @@ -237,6 +237,7 @@ public import Tests.CollectCallsTrace public import Tests.CollectAttachment public import Tests.ChronologicalSampling +public import Tests.AbstractModelFiniteAddresses public import Tests.ListPermutation public import Tests.ChronologicalPermutation diff --git a/src/Tests/AbstractModelFiniteAddresses.lean b/src/Tests/AbstractModelFiniteAddresses.lean new file mode 100644 index 0000000..bfefc85 --- /dev/null +++ b/src/Tests/AbstractModelFiniteAddresses.lean @@ -0,0 +1,62 @@ +module + +public import Commons.Definitions.AbstractModel.FiniteAddresses +public import Tests.AbstractModelAddressMap + +/-! +# Finite-address encoding checks + +The existing register model checks unused initial registers, never-read destinations, +and the same command code across every reply history, including a caller that stops immediately. +-/ + +@[expose] public section + +open SystemAlgebra Commons.AbstractModel + +namespace Tests.AbstractModelFiniteAddresses + +open Tests.AbstractModel + +/-- Address coding leaves the existing submitted value unchanged. -/ +example : model.mapCommand (fun _ : ℕ => (0 : Fin 1)) submit = + (⟨.submit, 3⟩ : model.Command (Fin 1)) := rfl + +/-- The footprint includes an unused initial address and a stored destination never read later. -/ +example : ∃ (n : ℕ) (code : ℕ → Fin n) (decode : Fin n ↪ ℕ), + decode (code 5) = 5 ∧ decode (code 7) = 7 ∧ code 5 ≠ code 7 ∧ + model.mapCommand decode (model.mapCommand code submit) = submit := by + obtain ⟨n, code, decode, initial, addresses, commands⟩ := + exists_fin_address_encoding (M := model) 5 {store, submit} + ((Set.finite_singleton submit).insert store) + have destination : decode (code 7) = 7 := + addresses store (Set.mem_insert _ _) 7 (Or.inr rfl) + refine ⟨n, code, decode, initial, destination, ?_, ?_⟩ + · intro collision + have impossible := congrArg decode collision + rw [initial, destination] at impossible + cases impossible + · exact commands submit (Set.mem_insert_of_mem _ (Set.mem_singleton _)) + +/-- One code handles every branch of the existing fixed-query environment. -/ +example : ∃ (n : ℕ) (code : ℕ → Fin n) (decode : Fin n ↪ ℕ), + decode (code 0) = 0 ∧ + ∀ ys z, z ∈ (DDE.ofQueries (Y := Bool) [store, submit]).1 ys → + model.mapCommand decode (model.mapCommand code z) = z := by + obtain ⟨n, code, decode, initial, _, commands⟩ := + exists_fin_address_encoding_of_queryBounded (M := model) 0 + (DDE.ofQueries (Y := Bool) [store, submit]) (DDE.ofQueries_queryBounded _) + exact ⟨n, code, decode, initial, commands⟩ + +/-- Even a caller that asks nothing retains an exact code for the initial register. -/ +example : ∃ (n : ℕ) (code : ℕ → Fin n) (decode : Fin n ↪ ℕ), decode (code 5) = 5 := by + obtain ⟨n, code, decode, initial, _, _⟩ := + exists_fin_address_encoding_of_queryBounded (M := model) 5 + (DDE.ofQueries (Y := Bool) []) (DDE.ofQueries_queryBounded _) + exact ⟨n, code, decode, initial⟩ + +#print axioms Commons.AbstractModel.mapCommand_mapCommand_eq_of_inverse_on +#print axioms Commons.AbstractModel.exists_fin_address_encoding +#print axioms Commons.AbstractModel.exists_fin_address_encoding_of_queryBounded + +end Tests.AbstractModelFiniteAddresses