diff --git a/REUSE.md b/REUSE.md index 383b072..56f194c 100644 --- a/REUSE.md +++ b/REUSE.md @@ -73,6 +73,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` | | 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/Definitions/AbstractModel/Domain.lean b/src/Commons/Definitions/AbstractModel/Domain.lean index 597745d..5b7c45a 100644 --- a/src/Commons/Definitions/AbstractModel/Domain.lean +++ b/src/Commons/Definitions/AbstractModel/Domain.lean @@ -87,19 +87,35 @@ lemma admitted_snoc_iff /-! ## Address maps -/ +/-- Decoding a command needs an inverse only on its operand and destination addresses. -/ +lemma mapCommand_mapCommand_eq_of_inverse_on + -- `f` encodes addresses and `g` decodes them; `z` is the command being transported. + {κ : Type} (f : ι → κ) (g : κ → ι) (z : M.Command ι) + -- `operands` and `destination` cover every address mentioned by `z`. + (operands : ∀ a ∈ M.reads z, g (f a) = a) + (destination : ∀ a, M.target z = some a → g (f a) = a) : + M.mapCommand g (M.mapCommand f z) = z := by + obtain ⟨o | ρ | _, z⟩ := z + · obtain ⟨a, target⟩ := z + have values (j : Fin (M.arity o)) : g (f (a j)) = a j := + operands (a j) (Finset.mem_image.mpr ⟨j, Finset.mem_univ j, rfl⟩) + have target_eq := destination target rfl + simp only [mapCommand, Sigma.map, id_eq, mapInput, Function.comp_def, values, target_eq] + · have values (j : Fin (M.queryArity ρ)) : g (f (z j)) = z j := + operands (z j) (Finset.mem_image.mpr ⟨j, Finset.mem_univ j, rfl⟩) + simp only [mapCommand, Sigma.map, id_eq, mapInput, Function.comp_def, values] + · rfl + omit [DecidableEq ι] in /-- An address decoder also decodes operand vectors, destinations, and complete commands. -/ lemma mapCommand_leftInverse -- `f` encodes addresses and `g` decodes them; submitted values are unchanged. {κ : Type} (f : ι → κ) (g : κ → ι) (inverse : Function.LeftInverse g f) : Function.LeftInverse (M.mapCommand g) (M.mapCommand f) := by - have decoded (x : ι) : g (f x) = x := inverse x + classical intro z - obtain ⟨o | ρ | _, z⟩ := z - · obtain ⟨a, destination⟩ := z - simp only [mapCommand, Sigma.map, id_eq, mapInput, Function.comp_def, decoded] - · simp only [mapCommand, Sigma.map, id_eq, mapInput, Function.comp_def, decoded] - · rfl + exact mapCommand_mapCommand_eq_of_inverse_on f g z + (fun a _ => inverse a) (fun a _ => inverse a) /-- The operands of a renamed command are the image of its original operands. -/ lemma reads_mapCommand diff --git a/src/Tests/AbstractModelDomainMap.lean b/src/Tests/AbstractModelDomainMap.lean index 8f71b7d..55d09b0 100644 --- a/src/Tests/AbstractModelDomainMap.lean +++ b/src/Tests/AbstractModelDomainMap.lean @@ -56,6 +56,27 @@ example : model.Admitted () 1 [model.mapCommand (fun _ : ℕ => ()) observe] ∧ have impossible := operands (Finset.mem_image.mpr ⟨0, Finset.mem_univ _, rfl⟩) simp [initialized] at impossible +/-- Keep addresses 0 and 7, but collapse every other address to 0. -/ +def collapse (a : ℕ) : ℕ := if a == 7 then 7 else 0 + +/-- The store reads 0 and writes 7, so decoding it requires no inverse elsewhere. -/ +lemma store_local_inverse : + model.mapCommand id (model.mapCommand collapse store) = store := by + apply mapCommand_mapCommand_eq_of_inverse_on + · intro a present + obtain ⟨j, _, rfl⟩ := Finset.mem_image.mp present + rfl + · intro a destination + have address : 7 = a := Option.some.inj destination + subst a + rfl + +/-- Distinct addresses outside that command's footprint may receive the same code. -/ +example : collapse 1 = collapse 2 := rfl + +#print axioms store_local_inverse +#print axioms mapCommand_mapCommand_eq_of_inverse_on + #print axioms mapCommand_leftInverse #print axioms initialized_mapCommand #print axioms Admitted.mapCommand