A three-cell shifting control model
DefinitionAPFReachKernel_CAControlapfconditional-referencereachkernel
Three Boolean cells evolve by a deterministic shift. Finite trajectories form the continuations, their lengths provide loads, and concatenation provides composition. The interface includes a glider configuration, a readout, alignments and their induced realignment model. These objects make profile and alignment change concrete within the finite model; no physical occupant or whole-protocol bill is constructed.
Definition code
import Definitions.Def_APFReachKernel_ContinuationModel
import Definitions.Def_APFReachKernel_Foundation
import Definitions.Def_APFReachKernel_RealignmentModel
namespace ReachKernel.CAControl
end ReachKernel.CAControl
/-
ReachKernel/CAControl.lean
A three-cell deterministic shift model with finite trajectories and
word-length load. It supplies change-of-profile and alignment witnesses
for the displayed structures. It makes no claim about a physical occupant.
Compatibility repair for Lean4.33.1 uses if_pos/if_neg in proof bodies only.
-/
set_option autoImplicit false
namespace ReachKernel.CAControl
/-- Three cells on a ring. -/
abbrev Cfg := Bool × Bool × Bool
/-- The rule: shift right (elementary rule 170 on a ring). -/
def step : Cfg → Cfg
| (a, b, c) => (c, a, b)
def iter : Nat → Cfg → Cfg
| 0, x => x
| k + 1, x => iter k (step x)
theorem iter_add (k m : Nat) (x : Cfg) : iter m (iter k x) = iter (k + m) x := by
induction k generalizing x with
| zero => rw [Nat.zero_add]; rfl
| succ k ih =>
show iter m (iter k (step x)) = iter (k + 1 + m) x
rw [ih (step x), Nat.add_right_comm]
rfl
/-- The finite trajectory of `k` steps from `x`, initial configuration included. -/
def traj : Cfg → Nat → List Cfg
| x, 0 => [x]
| x, k + 1 => x :: traj (step x) k
theorem traj_length (x : Cfg) (k : Nat) : (traj x k).length = k + 1 := by
induction k generalizing x with
| zero => rfl
| succ k ih => show (traj (step x) k).length + 1 = k + 1 + 1; rw [ih]
theorem traj_ne_nil (x : Cfg) (k : Nat) : traj x k ≠ [] := by
cases k <;> simp [traj]
theorem traj_head (x : Cfg) (k : Nat) : ∃ t, traj x k = x :: t := by
cases k with
| zero => exact ⟨[], rfl⟩
| succ k => exact ⟨traj (step x) k, rfl⟩
/-- Concatenating the trajectory of `k` steps with the trajectory of `m` more
steps from where it ended (dropping the duplicated junction) is the trajectory
of `k + m` steps. -/
theorem traj_append (x : Cfg) (k m : Nat) :
traj x k ++ (traj (iter k x) m).tail = traj x (k + m) := by
induction k generalizing x with
| zero =>
rw [Nat.zero_add]
show [x] ++ (traj x m).tail = traj x m
obtain ⟨t, ht⟩ := traj_head x m
rw [ht]; rfl
| succ k ih =>
rw [Nat.add_right_comm]
show x :: (traj (step x) k ++ (traj (iter k (step x)) m).tail) = x :: traj (step x) (k + m)
rw [ih (step x)]
/-- Nonempty initial segments of trajectories are trajectories. -/
theorem traj_prefix (l₁ l₂ : List Cfg) (x : Cfg) (j : Nat)
(h : l₁ ++ l₂ = traj x j) (hne : l₁ ≠ []) :
∃ k, k ≤ j ∧ l₁ = traj x k := by
induction l₁ generalizing x j with
| nil => exact absurd rfl hne
| cons a l₁ ih =>
cases j with
| zero =>
have h' : a :: (l₁ ++ l₂) = x :: [] := h
have hax : a = x := (List.cons.inj h').1
have hl : l₁ ++ l₂ = [] := (List.cons.inj h').2
have hl₁ : l₁ = [] := (List.append_eq_nil_iff.mp hl).1
subst hax; subst hl₁
exact ⟨0, Nat.le_refl 0, rfl⟩
| succ j =>
have h' : a :: (l₁ ++ l₂) = x :: traj (step x) j := h
have hax : a = x := (List.cons.inj h').1
have hrest : l₁ ++ l₂ = traj (step x) j := (List.cons.inj h').2
subst hax
cases l₁ with
| nil => exact ⟨0, Nat.zero_le _, rfl⟩
| cons b l₁' =>
obtain ⟨k, hk, hl⟩ := ih (step a) j hrest (by simp)
refine ⟨k + 1, Nat.succ_le_succ hk, ?_⟩
show a :: (b :: l₁') = a :: traj (step a) k
rw [hl]
/-- Step budget of the context. -/
def B : Nat := 2
/-- Available continuations from `x`: trajectories of at most `B` steps. -/
def cont : Cfg → Set (List Cfg) := fun x t => ∃ k, k ≤ B ∧ t = traj x k
def calib : Nat → Nat := fun n => n
/-- Continuations record their start, so profiles separate configurations:
B01 classes are exactly configurations in this model. -/
theorem cont_inj (x y : Cfg) (h : cont x = cont y) : x = y := by
have hx : traj x 0 ∈ cont x := ⟨0, Nat.zero_le _, rfl⟩
rw [h] at hx
obtain ⟨k, _, hk⟩ := hx
obtain ⟨t, ht⟩ := traj_head y k
have : [x] = y :: t := by rw [← ht]; exact hk
exact (List.cons.inj this).1
theorem class_eq_iff (x y : Cfg) : physicalClass cont x = physicalClass cont y ↔ x = y :=
⟨fun h => cont_inj x y ((physicalClass_eq_iff cont x y).1 h), fun h => h ▸ rfl⟩
def load (t : List Cfg) : Nat := t.length - 1
def concat (t' t : List Cfg) : List Cfg := if t = [] then [] else t ++ t'.tail
theorem load_traj (x : Cfg) (k : Nat) : load (traj x k) = k := by
simp [load, traj_length]
theorem load_concat (t' t : List Cfg) : load (concat t' t) ≤ load t + load t' := by
unfold concat load
by_cases h : t = []
· simp [h]
· simp [h, List.length_append]
cases t' <;> simp <;> omega
/-- The CA continuation model. Reach is the class of the end configuration. -/
def model : ContinuationModel cont calib B where
Reaches x t y := ∃ k, k ≤ B ∧ t = traj x k ∧ y = physicalClass cont (iter k x)
load := load
concat := concat
reaches_descends := by
intro x x' c y hxx' hr
rw [(class_eq_iff x x').1 hxx'] at hr
exact hr
identity := fun x => ⟨traj x 0, ⟨0, Nat.zero_le _, rfl⟩, 0, Nat.zero_le _, rfl, rfl⟩
concat_mem := by
intro x c c' y _ hr ha hb
obtain ⟨k, hk, rfl, rfl⟩ := hr
obtain ⟨m, hm, rfl⟩ := (availableAt_mk cont c' (iter k x)).1 ha
refine ⟨k + m, ?_, ?_⟩
· have hcat : concat (traj (iter k x) m) (traj x k) = traj x (k + m) := by
unfold concat; rw [if_neg (traj_ne_nil x k), traj_append]
have : calib (load (concat (traj (iter k x) m) (traj x k))) ≤ B := hb
rw [hcat] at this
simp [calib, load_traj] at this
exact this
· show concat (traj (iter k x) m) (traj x k) = traj x (k + m)
unfold concat
rw [if_neg (traj_ne_nil x k), traj_append]
concat_reaches := by
intro x c c' y z _ hr ha hb hall
obtain ⟨k, hk, rfl, rfl⟩ := hr
obtain ⟨m, hm, rfl⟩ := (availableAt_mk cont c' (iter k x)).1 ha
obtain ⟨m', hm', hc', hz⟩ := hall (iter k x) rfl
have hmm : m' = m := by
have := congrArg List.length hc'
rw [traj_length, traj_length] at this
omega
subst hmm
refine ⟨k + m', ?_, ?_, ?_⟩
· have hcat : concat (traj (iter k x) m') (traj x k) = traj x (k + m') := by
unfold concat; rw [if_neg (traj_ne_nil x k), traj_append]
have : calib (load (concat (traj (iter k x) m') (traj x k))) ≤ B := hb
rw [hcat] at this
simp [calib, load_traj] at this
exact this
· show concat (traj (iter k x) m') (traj x k) = traj x (k + m')
unfold concat
rw [if_neg (traj_ne_nil x k), traj_append]
· rw [hz, iter_add]
prefix_mem := by
intro x c c' h
obtain ⟨j, hj, hcc⟩ := h
unfold concat at hcc
by_cases hc : c = []
· rw [if_pos hc] at hcc
exact absurd hcc.symm (traj_ne_nil x j)
· rw [if_neg hc] at hcc
obtain ⟨k, hk, rfl⟩ := traj_prefix c c'.tail x j hcc hc
exact ⟨k, Nat.le_trans hk hj, rfl⟩
/-- The glider: one lit cell. -/
def glider : Cfg := (true, false, false)
/-! ### The alignment level -/
/-- The distinction "cell 0 is lit", descended to physical classes (B01). -/
def d0 : PhysicalState cont → Bool :=
Quotient.lift (fun x : Cfg => x.1) (fun x y (h : cont x = cont y) => by rw [cont_inj x y h])
def D : Set (PhysicalState cont → Bool) := fun d => d = d0
def dist0 : {d : PhysicalState cont → Bool // d ∈ D} := ⟨d0, rfl⟩
/-- (a₊, {d}) : the glider at cell 0 with "cell 0 lit" held. -/
def aPlus : Alignment cont D where
carrier := physicalClass cont glider
carried := fun d => d = dist0
active := by
intro d hd
have : d = dist0 := hd
subst this
rfl
/-- (a₋, ∅) : the glider moved on, nothing held. -/
def aMinus : Alignment cont D where
carrier := physicalClass cont (step glider)
carried := fun _ => False
active := fun _ h => absurd h id
def stepsOf (t : List Cfg) : Nat := t.length - 1
/-- Protocols connect alignments by running a trajectory from a
representative of the source carrier to the destination carrier. -/
def realignment : RealignmentModel cont D calib B where
Connects π a b := ∃ x, physicalClass cont x = a.carrier ∧
∃ k, k ≤ B ∧ π = traj x k ∧ b.carrier = physicalClass cont (iter k x)
load := load
concat := concat
Admissible π := stepsOf π ≤ B
zero := 0
zero_le := Nat.zero_le
identity_protocol := by
intro a
obtain ⟨x, hx⟩ := Quotient.exists_rep a.carrier
exact ⟨traj x 0, ⟨x, hx, 0, Nat.zero_le _, rfl, hx.symm⟩, rfl⟩
concat_connects := by
intro π₁ π₂ a₁ a₂ a₃ h₁ h₂ hadm
obtain ⟨x, hx, k, hk, rfl, hb⟩ := h₁
obtain ⟨x', hx', m, hm, rfl, hc⟩ := h₂
have hxx' : x' = iter k x := (class_eq_iff _ _).1 (hx'.trans hb)
subst hxx'
have hcat : concat (traj (iter k x) m) (traj x k) = traj x (k + m) := by
unfold concat; rw [if_neg (traj_ne_nil x k), traj_append]
refine ⟨x, hx, k + m, ?_, hcat, ?_⟩
· have : stepsOf (concat (traj (iter k x) m) (traj x k)) ≤ B := hadm
rw [hcat] at this
simp [stepsOf, traj_length] at this
exact this
· rw [hc, iter_add]
cost_subadditive := fun π₁ π₂ => load_concat π₂ π₁
end ReachKernel.CAControl
Source
APF ReachKernel; original archive f05a126714fe8d24a4377f87a7e460777555e19227087abb6c18dbe2ffae959e, ReachKernel/CAControl.lean; corrected compatible source manifest 2c8ccc43b416ba6e4f1b9eb02d4780b828e8dab689651eb567f7d159065cdfd2. Private conditional/reference model.