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
| Extend distinct list-position labels to evaluated inputs | `List.exists_perm_apply_idxOf_eq` in `Probability.List.Permutation` |
| Evaluate a completed adaptive invocation from its local trace | `Program.combine_eq_of_consistent_replies` in `RandomSystems.Converter.ProgramTrace` |
| Certify a scheduled collection and attach it to retained state | `DSL.collectCalls_exchangesOf` in `RandomSystems.Typed.DSL.Collect`; `Program.combine_eq_of_collectCalls` in `CollectAttachment` |
| Compare chronological labels under an invariant retained-function law | `chronologicalLabelingProgram_mass_replies_eq_of_fTransform_eq` in `RandomSystems.Converter.ChronologicalLabeling.Sampling` |
| Transport complete register converters through address embeddings | `registersDDC_mapCommand` in `Commons.Definitions.AbstractModel.RegisterDDC.AddressMap` |
| Transport oracle bodies through state and outside-query maps | `Program.step_stateInputMap` in `RandomSystems.Converter.Program`; `DSL.callProg_map` in `RandomSystems.Typed.DSL.Programs` |
| Rename register addresses while preserving contents | `AbstractModel.mapInput`, `mapCommand`, `registers_mapCommand` in `Commons.Definitions.AbstractModel` and `Registers.Laws` |
Expand Down
1 change: 1 addition & 0 deletions src/RandomSystems.lean
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public import RandomSystems.Converter.ChronologicalLabeling.Laws

public import RandomSystems.Converter.ProgramTrace
public import RandomSystems.Typed.DSL.CollectAttachment
public import RandomSystems.Converter.ChronologicalLabeling.Sampling


/-!
Expand Down
99 changes: 99 additions & 0 deletions src/RandomSystems/Converter/ChronologicalLabeling/Sampling.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module

public import RandomSystems.Converter.ChronologicalLabeling.Laws
public import RandomSystems.System.Replies
public import Probability.Distribution

/-!
# Chronological labeling under a retained function law

`chronologicalLabelingProgram_replies_iff_of_prefix_alignment` compares chronological and
evaluated inputs on one history. Its one-call replay law supplies the deterministic comparison.
`chronologicalLabelingProgram_mass_replies_eq_of_fTransform_eq` then transports this comparison
through any retained function law invariant under the selected input map.

```text
outside a ── chronological label ── θ ── retained g ── reply
= evaluated input a ────────── retained g ── reply
```
-/

@[expose] public section

open Probability Probability.Distribution

namespace SystemAlgebra

-- `A` carries outside inputs, `B` the finite labels, and `C` the forwarded replies.
variable {A B C : Type} [BEq A] [Fintype B]
-- `labels` orders the label pool; exhausted fresh inputs use `fallback`.
(labels : Fin (Fintype.card B) ≃ B) (fallback : B)
-- `E` admits inside histories and `F` outside histories.
{E : List (Σ _ : Unit, B) → Prop} {F : List (Σ _ : Unit, A) → Prop}
-- `hE` and `hF` exclude empty histories and admit every nonempty prefix.
(hE : ¬ E [] ∧ ∀ {p h}, p <+: h → p ≠ [] → E h → E p)
(hF : ¬ F [] ∧ ∀ {p h}, p <+: h → p ≠ [] → F h → F p)
-- `domain` certifies the encoder's one-call action from `E` to `F`.
(domain : IsDDCFrom E F 1
(DDC.ofProgramOn [] (chronologicalLabelingProgram (C := C) labels fallback) F))
-- `θ` maps label inputs; `evaluate` maps the original outside inputs to inside inputs.
(θ : B → B) (evaluate : A → B)
-- `us` is the fixed outside history whose coefficient is compared.
(us : List (Σ _ : Unit, A))
-- `aligned` identifies the label mapped by `θ` with `evaluate a` at admitted prefixes of `us`.
(aligned : ∀ vs a, vs ++ [⟨(), a⟩] <+: us → F (vs ++ [⟨(), a⟩]) →
θ (if h : (vs.map Sigma.snd ++ [a]).eraseDups.idxOf a < Fintype.card B then
labels ⟨(vs.map Sigma.snd ++ [a]).eraseDups.idxOf a, h⟩ else fallback) = evaluate a)

include domain aligned

/-- On the selected prefixes, input relabeling turns chronological replies into evaluation. -/
lemma chronologicalLabelingProgram_replies_iff_of_prefix_alignment
-- `g` is retained across all calls; `ys` lists their candidate replies.
(g : B → C) (ys : List (Σ _ : Unit, C)) :
Replies (trim (apply
(DDC.ofProgramOn [] (chronologicalLabelingProgram labels fallback) F)
(DDS.ofFunction E hE (fun b => ⟨b.1, g (θ b.2)⟩)).1)) us ys ↔
Replies (DDS.ofFunction F hF (fun a => ⟨a.1, g (evaluate a.2)⟩)).1 us ys := by
classical
-- Every completed reply depends only on its input prefix.
apply replies_congr_of_prefix
intro p hp
rcases List.eq_nil_or_concat p with rfl | ⟨vs, ⟨o, a⟩, rfl⟩
· simp only [trim, reach_nil, ite_true, apply_eq, interconnect_nil]
exact (Part.eq_none_iff'.mpr (DDS.ofFunction F hF
(fun a => (⟨a.1, g (evaluate a.2)⟩ : Σ _ : Unit, C))).2.1).symm
· cases o
simp only [List.concat_eq_append] at hp ⊢
-- The replay law keeps the original domain; alignment identifies its admitted reply.
rw [chronologicalLabelingProgram_apply_ofFunction_snoc labels fallback hE hF domain
(fun b => g (θ b)) vs a, DDS.ofFunction_snoc]
by_cases legal : F (vs ++ [⟨(), a⟩])
· simp only [legal, ↓reduceIte, aligned vs a hp legal]
· simp only [legal, ↓reduceIte]

/-- A retained function law invariant under `g ↦ g ∘ θ` has equal transcript coefficients. -/
theorem chronologicalLabelingProgram_mass_replies_eq_of_fTransform_eq
-- `μ` assigns finite signed weights to functions retained across all calls.
(μ : Distribution (B → C))
-- `invariant` says replacing `g` by `g ∘ θ` preserves this same retained law.
(invariant : fTransform (fun g => g ∘ θ) μ = μ)
-- `ys` is the fixed reply history, including any repeated replies.
(ys : List (Σ _ : Unit, C)) :
μ.mass (fun g => Replies (trim (apply
(DDC.ofProgramOn [] (chronologicalLabelingProgram labels fallback) F)
(DDS.ofFunction E hE (fun b => ⟨b.1, g b.2⟩)).1)) us ys) =
μ.mass (fun g =>
Replies (DDS.ofFunction F hF (fun a => ⟨a.1, g (evaluate a.2)⟩)).1 us ys) := by
let event := fun g : B → C => Replies (trim (apply
(DDC.ofProgramOn [] (chronologicalLabelingProgram labels fallback) F)
(DDS.ofFunction E hE (fun b => ⟨b.1, g b.2⟩)).1)) us ys
-- Reindex the retained draw, then use deterministic prefix agreement at each function.
calc
μ.mass event = (fTransform (fun g => g ∘ θ) μ).mass event := by rw [invariant]
_ = μ.mass (fun g => event (g ∘ θ)) := mass_fTransform _ _ _
_ = _ := mass_congr μ fun g =>
chronologicalLabelingProgram_replies_iff_of_prefix_alignment
labels fallback hE hF domain θ evaluate us aligned g ys

end SystemAlgebra
1 change: 1 addition & 0 deletions src/Tests.lean
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public import Tests.RegisterAddressCompiler
public import Tests.ProgramTrace
public import Tests.CollectCallsTrace
public import Tests.CollectAttachment
public import Tests.ChronologicalSampling

public import Tests.ListPermutation

Expand Down
79 changes: 79 additions & 0 deletions src/Tests/ChronologicalSampling.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module

public import RandomSystems.Converter.ChronologicalLabeling.Sampling
public import Tests.ChronologicalLabeling

/-!
# Retained sampling through chronological labels

A nonuniform law chooses one constant function, retained across repeated queries.
Collapsing both label inputs to zero preserves that law. Its positive repeated-reply mass
and zero conflicting-reply mass exercise the coefficient theorem with a noninjective map.
-/

@[expose] public section

namespace Tests.ChronologicalSampling

open Probability Probability.Distribution SystemAlgebra Tests.ChronologicalLabeling

/-- One retained function is constantly `42` with mass `1/3`, or constantly `7` with mass `2/3`. -/
noncomputable def retainedLaw : Distribution (Fin 2 → ℕ) :=
Finsupp.single (fun _ => 42) (1 / 3) + Finsupp.single (fun _ => 7) (2 / 3)

/-- Collapsing both labels to `0` leaves either constant function unchanged. -/
lemma retainedLaw_invariant :
fTransform (fun g : Fin 2 → ℕ => g ∘ fun _ => (0 : Fin 2)) retainedLaw = retainedLaw := by
rw [retainedLaw, fTransform_add, fTransform_single, fTransform_single]
rfl

/-- The chosen input map is genuinely noninjective. -/
example : ¬ Function.Injective (fun _ : Fin 2 => (0 : Fin 2)) := by
intro injective
have equal : (0 : Fin 2) = 1 := injective rfl
norm_num at equal

-- `labels` may use either enumeration of the two-label pool.
variable (labels : Fin (Fintype.card (Fin 2)) ≃ Fin 2)

/-- Three replies use one retained draw, so their joint mass is `1/3`. -/
lemma repeated_reply_mass :
retainedLaw.mass (fun g => Replies (trim (apply
(DDC.ofProgramOn [] (chronologicalLabelingProgram labels 0) (outsideDomain 3))
(DDS.ofFunction (insideDomain 3) (insideDomain_prefix 3)
(fun b => ⟨b.1, g b.2⟩)).1))
[⟨(), 7⟩, ⟨(), 9⟩, ⟨(), 7⟩] [⟨(), 42⟩, ⟨(), 42⟩, ⟨(), 42⟩]) = 1 / 3 := by
classical
have coefficient := chronologicalLabelingProgram_mass_replies_eq_of_fTransform_eq
labels 0 (insideDomain_prefix 3) (outsideDomain_prefix 3)
(chronologicalLabelingProgram_isDDCFrom labels 0 3)
(fun _ => (0 : Fin 2)) (fun _ : ℕ => (0 : Fin 2))
[⟨(), 7⟩, ⟨(), 9⟩, ⟨(), 7⟩] (fun _ _ _ _ => rfl)
retainedLaw retainedLaw_invariant [⟨(), 42⟩, ⟨(), 42⟩, ⟨(), 42⟩]
rw [coefficient]
norm_num [retainedLaw, mass_add, mass_single, DDS.replies_ofFunction_iff, outsideDomain]

/-- Inconsistent replies on the repeated input cannot come from the retained draw. -/
lemma conflicting_reply_mass :
retainedLaw.mass (fun g => Replies (trim (apply
(DDC.ofProgramOn [] (chronologicalLabelingProgram labels 0) (outsideDomain 3))
(DDS.ofFunction (insideDomain 3) (insideDomain_prefix 3)
(fun b => ⟨b.1, g b.2⟩)).1))
[⟨(), 7⟩, ⟨(), 9⟩, ⟨(), 7⟩] [⟨(), 42⟩, ⟨(), 42⟩, ⟨(), 7⟩]) = 0 := by
classical
have coefficient := chronologicalLabelingProgram_mass_replies_eq_of_fTransform_eq
labels 0 (insideDomain_prefix 3) (outsideDomain_prefix 3)
(chronologicalLabelingProgram_isDDCFrom labels 0 3)
(fun _ => (0 : Fin 2)) (fun _ : ℕ => (0 : Fin 2))
[⟨(), 7⟩, ⟨(), 9⟩, ⟨(), 7⟩] (fun _ _ _ _ => rfl)
retainedLaw retainedLaw_invariant [⟨(), 42⟩, ⟨(), 42⟩, ⟨(), 7⟩]
rw [coefficient]
norm_num [retainedLaw, mass_add, mass_single, DDS.replies_ofFunction_iff, outsideDomain]

#print axioms chronologicalLabelingProgram_replies_iff_of_prefix_alignment
#print axioms chronologicalLabelingProgram_mass_replies_eq_of_fTransform_eq
#print axioms retainedLaw_invariant
#print axioms repeated_reply_mass
#print axioms conflicting_reply_mass

end Tests.ChronologicalSampling