Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions REUSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
2 changes: 2 additions & 0 deletions src/Commons.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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. -/
74 changes: 74 additions & 0 deletions src/Commons/Definitions/AbstractModel/FiniteAddresses.lean
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/Tests.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
62 changes: 62 additions & 0 deletions src/Tests/AbstractModelFiniteAddresses.lean
Original file line number Diff line number Diff line change
@@ -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