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 @@ -77,6 +77,7 @@ named `budget` argument. The object index below supplies owners for those declar
| Locate a program query, including its final pending call | `DDC.exists_after_busy_of_mem_insideQueries` in `RandomSystems.Converter.ProgramTrace` |
| Preserve a caller's stopping bound under query recoding | `queryBounded_ddeOf_relabelQueries_iff` in `RandomSystems.System.QueryRelabel.Laws` |
| Close a one-query probe from a correctly tagged reply | `close_envProbe_ofQueries_singleton` in `RandomSystems.Distance.Transcript` |
| Evaluate a register observation against retained inside state | `registerProgram_combine_query` in `Commons.Definitions.AbstractModel.RegisterProgram.Laws` |
| 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` |
Expand Down
39 changes: 39 additions & 0 deletions src/Commons/Definitions/AbstractModel/RegisterProgram/Laws.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module

public import Commons.Definitions.AbstractModel.RegisterProgram
public import Commons.Definitions.AbstractModel.Registers.Laws
public import RandomSystems.Converter.ProgramTrace

/-!
# Laws of the register program
Expand All @@ -11,6 +12,8 @@ The outside command history and replies stay fixed. `registerProgram_costs` and
`registerProgram_bounded` derive the exact 0/1/0 call pattern
from the call/return laws. `observationCost_sum_le` compares its total with the ordinary-command
budget. These are the certificates used by the typed register converter.
`registerProgram_combine_query` identifies one successful read against a deterministic inside
component, retaining both its updated state and the appended command history.
-/

@[expose] public section
Expand Down Expand Up @@ -74,6 +77,42 @@ lemma registerProgram_bounded (input : ι)
| query ρ => exact callBound_call _ _ _ (fun _ => callBound_return 0 _)
| submit => exact callBound_return 1 _

/-- A successful register read supplies the one observation call; both retained states advance. -/
lemma registerProgram_combine_query
-- `input` starts with `w`; `op` interprets the computation symbols.
(input : ι) (op : (o : M.Operation) → (Fin (M.arity o) → W) → W) (w : W)
-- `stepR` is the inside component on its retained state `R`.
{R : Type} (stepR : R → (ρ : M.Query) → (Fin (M.queryArity ρ) → W) → R × M.Reply ρ)
-- `h` is the completed command history; `ρ` reads the selected `addresses`.
(h : List (M.Command ι)) (ρ : M.Query) (addresses : Fin (M.queryArity ρ) → ι)
-- `present` certifies that the complete read succeeds with operand tuple `values`.
(values : Fin (M.queryArity ρ) → W)
(present : read (M.registers op (initial input w) h) addresses = some values)
-- `r` is the inside state before the observation call; `stepR` supplies its next state.
(r : R) :
(M.registerProgram input op w).combine stepR (M.registerProgram_bounded input op w)
(h, r) (.query ρ) addresses =
((h ++ [⟨.query ρ, addresses⟩], (stepR r ρ values).1), (stepR r ρ values).2) := by
let q : Σ ρ, Fin (M.queryArity ρ) → W := ⟨ρ, values⟩
let t := [(q, (⟨ρ, (stepR r ρ values).2⟩ : Σ ρ, M.Reply ρ))]
have issued : M.registerProgram input op w h (.query ρ) addresses [] = .inr q := by
simp only [registerProgram, present, Option.getD_some, callProg, q]
have consistent : (M.registerProgram input op w).Consistent h (.query ρ) addresses t :=
(Program.consistent_nil (M.registerProgram input op w) h (.query ρ) addresses).snoc
(q := q) issued (stepR r ρ values).2
have actual : Replies (automatonSystem stepR r) (t.map Prod.fst) (t.map Prod.snd) := by
change Replies (automatonSystem stepR r) ([] ++ [q])
([] ++ [⟨ρ, (stepR r ρ values).2⟩])
refine replies_snoc.mpr ⟨replies_nil _, ?_⟩
rw [automatonSystem_snoc]
rfl
have returned : M.registerProgram input op w h (.query ρ) addresses t =
.inl (h ++ [⟨.query ρ, addresses⟩], (stepR r ρ values).2) := by
simp only [registerProgram, t, callProg, ↓reduceDIte, returnProg]
exact (M.registerProgram input op w).combine_eq_of_consistent_replies stepR
(M.registerProgram_bounded input op w) h (.query ρ) addresses r t
consistent actual returned

/-- The exact observation cost is 0 for compute/submit and 1 for query, including pending calls. -/
lemma registerProgram_costs (input : ι)
(op : (o : M.Operation) → (Fin (M.arity o) → W) → W) (w : W) :
Expand Down
1 change: 1 addition & 0 deletions src/Tests.lean
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public import Tests.ListPermutation
public import Tests.ChronologicalPermutation
public import Tests.RestrictMembership
public import Tests.ProgramIssuedQuery
public import Tests.RegisterProgramAttachment

/-! Axiom audits per layer and of the Commons library, the checks of the
authenticated-encryption example,
Expand Down
37 changes: 37 additions & 0 deletions src/Tests/RegisterProgramAttachment.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module

public import Commons.Definitions.AbstractModel.RegisterProgram.Laws
public import Tests.AbstractModel

/-!
# Register invocation with a stateful observation component

The existing model reads its initial value through an arbitrary deterministic inside component.
The result keeps that component's updated state and records the completed outside command.
-/

@[expose] public section

namespace Tests.RegisterProgramAttachment

open Commons.AbstractModel SystemAlgebra Tests.AbstractModel

/-- The query reads the actual initial register, then uses the inside component's own result. -/
theorem initial_query {R : Type}
(stepR : R → (ρ : model.Query) → (Fin (model.queryArity ρ) → ℕ) → R × model.Reply ρ)
(r : R) :
(model.registerProgram 0 (model.operate 0) 7).combine stepR
(model.registerProgram_bounded 0 (model.operate 0) 7)
([], r) (.query false) (fun _ => 0) =
(([⟨.query false, fun _ => 0⟩], (stepR r false (fun _ => 7)).1),
(stepR r false (fun _ => 7)).2) := by
apply model.registerProgram_combine_query 0 (model.operate 0) 7 stepR [] false
(fun _ => 0) (fun _ => 7)
apply (read_eq_some_iff _ _ _).mpr
intro j
exact initial_self 0 7

#print axioms registerProgram_combine_query
#print axioms initial_query

end Tests.RegisterProgramAttachment