Shared-site coefficient context · SpeciesTreeMarkov
DefinitionMarkovScatteringCharged_SpeciesTreeMarkovmarkov-scattering
Source context from the finite shared-site cubic model and its supporting definitions and checked lemmas.
Definition code
import Definitions.Def_MarkovScatteringCharged_SpeciesTree
import Definitions.Def_MarkovScatteringCharged_GraphMomentumVertices
/-! The configuration of a tree consists of independent species slots. The
initial transition allocates a configuration with unit coefficient, then
ordered local transfers apply leaves, vertex tensors, and propagators. -/
namespace MarkovScattering.SpeciesTree
open WordPlanarTrees GraphMomentum
noncomputable section
variable {m : ℕ} {A : Type*} [Fintype A]
/-- A leaf has an outgoing species. Each junction has an outgoing species and
two ordered incoming species, stored separately from its children's outputs. -/
def Config (A : Type*) : Tree m → Type _
| .tip => A
| .node _ L R => (A × A × A) × (Config A L × Config A R)
instance configFintype (T : Tree m) : Fintype (Config A T) := by
induction T with
| tip => exact inferInstanceAs (Fintype A)
| node j L R hL hR =>
letI := hL
letI := hR
exact inferInstanceAs (Fintype ((A × A × A) × (Config A L × Config A R)))
def output : (T : Tree m) → Config A T → A
| .tip, q => q
| .node _ _ _, q => q.1.1
variable [DecidableEq A]
/-- A tip's external vector is already amputated, so its connection is an
identity wire. Internal connections use the supplied full matrix. -/
def connection (d : LocalData m A) (T : Tree m) (a b : A) : ℂ := by
exact if T = .tip then if a = b then 1 else 0 else d.propagator T.gaps a b
omit [Fintype A] in
@[simp] theorem connection_tip (d : LocalData m A) (a b : A) :
connection d .tip a b = (if _ : a = b then 1 else 0) := by
unfold connection
simp
omit [Fintype A] in
@[simp] theorem connection_node (d : LocalData m A) (j : Fin m) (L R : Tree m) (a b : A) :
connection d (.node j L R) a b = d.propagator (WordPlanarTrees.Tree.node j L R).gaps a b := by
simp [connection]
/-- Each list entry is a single supplied local factor, evaluated on its own
species slots. A junction uses three slots and a propagator has two ends. -/
def localFactors (d : LocalData m A) : (T : Tree m) → ℕ → Config A T → List ℂ
| .tip, i, q => [d.external i q]
| .node j L R, i, q =>
[d.vertex j L.gaps R.gaps q.1.1 q.1.2.1 q.1.2.2,
connection d L q.1.2.1 (output L q.2.1), connection d R q.1.2.2 (output R q.2.2)] ++
localFactors d L i q.2.1 ++ localFactors d R (i+L.tips) q.2.2
def factorCount : Tree m → ℕ
| .tip => 1
| .node _ L R => 3 + factorCount L + factorCount R
omit [Fintype A] in
theorem localFactors_length (d : LocalData m A) (T : Tree m) (i : ℕ) (q : Config A T) :
(localFactors d T i q).length = factorCount T := by
induction T generalizing i with
| tip => rfl
| node j L R ihL ihR =>
simp [localFactors,factorCount,ihL,ihR]
omega
private theorem config_sums (T : Tree m) (f : A → ℂ) (g : Config A T → ℂ) :
(∑ q, f (output T q) * g q) = ∑ a, f a * ∑ q, if output T q = a then g q else 0 := by
classical
symm
simp_rw [Finset.mul_sum,mul_ite,mul_zero]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro q _
simp
/-- The branch current is exactly the contraction of its output current
with the species matrix on the attachment. -/
theorem branchCurrent_eq_connection (d : LocalData m A) (T : Tree m) (i : ℕ) (a : A) :
branchCurrent d T i a = ∑ b, connection d T a b * diagramCurrent d T i b := by
classical
cases T with
| tip =>
rw [branchCurrent_tip]
simp [ite_mul,diagramCurrent]
| node j L R => simp [branchCurrent_node]
private theorem localContraction_eq_current (d : LocalData m A) (T : Tree m) (i : ℕ) (a : A) :
(∑ q : Config A T, if output T q = a then (localFactors d T i q).prod else 0) =
diagramCurrent d T i a := by
classical
induction T generalizing i a with
| tip =>
simp [Config,output,localFactors,diagramCurrent]
intro h
exact (h (Finset.mem_univ a)).elim
| node j L R ihL ihR =>
rw [diagramCurrent_node]
change (∑ q : (A × A × A) × (Config A L × Config A R),
if q.1.1 = a then _ else 0) = _
simp only [Fintype.sum_prod_type]
let G (x b c : A) (p : Config A L) (q : Config A R) :=
(localFactors d (.node j L R) i ((x,b,c),p,q)).prod
change (∑ x, ∑ b, ∑ c, ∑ p, ∑ q, if x = a then G x b c p q else 0) = _
have h (x : A) : (∑ b, ∑ c, ∑ p, ∑ q, if x = a then G x b c p q else 0) =
if x = a then ∑ b, ∑ c, ∑ p, ∑ q, G x b c p q else 0 := by
by_cases hx : x = a <;> simp [hx]
simp_rw [h,Finset.sum_ite_eq',Finset.mem_univ,if_true]
apply Finset.sum_congr rfl
intro b _
apply Finset.sum_congr rfl
intro c _
simp only [G,localFactors,List.prod_append,List.prod_cons,List.prod_nil,mul_one]
have hL : (∑ q : Config A L, connection d L b (output L q) *
(localFactors d L i q).prod) = branchCurrent d L i b := by
rw [config_sums,branchCurrent_eq_connection]
exact Finset.sum_congr rfl (fun e _ => congrArg _ (ihL i e))
have hR : (∑ q : Config A R, connection d R c (output R q) *
(localFactors d R (i+L.tips) q).prod) = branchCurrent d R (i+L.tips) c := by
rw [config_sums,branchCurrent_eq_connection]
exact Finset.sum_congr rfl (fun e _ => congrArg _ (ihR (i+L.tips) e))
rw [← hL,← hR]
simp_rw [Finset.mul_sum,Finset.sum_mul]
rw [Finset.sum_comm]
exact Finset.sum_congr rfl (fun _ _ => Finset.sum_congr rfl (fun _ _ => by ring))
omit [Fintype A] in
instance configDecidableEq (T : Tree m) : DecidableEq (Config A T) := by
induction T with
| tip => exact inferInstanceAs (DecidableEq A)
| node j L R hL hR =>
letI := hL
letI := hR
exact inferInstanceAs (DecidableEq ((A × A × A) × (Config A L × Config A R)))
theorem factorCount_eq (T : Tree m) : factorCount T = 4*T.junctions+1 := by
induction T with
| tip => rfl
| node j L R ihL ihR =>
simp only [factorCount,Tree.junctions,ihL,ihR]
omega
abbrev Shape (S : Finset (Fin m)) := {T // T ∈ trees S}
abbrev DiagramConfig (A : Type*) (S : Finset (Fin m)) :=
Σ T : Shape S, Config A T.val
/-- The empty state is reserved for initialization. Active states retain a
labelled shape and a choice of the independent species slots. -/
abbrev ExperimentState (A : Type*) (S : Finset (Fin m)) := Option (DiagramConfig A S)
def allocate (S : Finset (Fin m)) : ExperimentState A S → ExperimentState A S → ℂ
| none, some _ => 1
| _, _ => 0
omit [Fintype A] in
theorem configFactors_length (d : LocalData m A) (S : Finset (Fin m))
(i : ℕ) (q : DiagramConfig A S) :
(localFactors d q.1.val i q.2).length = 4*S.card+1 := by
rw [localFactors_length,factorCount_eq,((mem_trees _ _).1 q.1.property).junctions]
/-- One local factor per time slot. The lengths coincide across the
ordered shapes because their junction sets coincide. -/
def gate (d : LocalData m A) (S : Finset (Fin m)) (i : ℕ) (k : Fin (4*S.card+1)) :
ExperimentState A S → ℂ
| none => 1
| some q => (localFactors d q.1.val i q.2).get
(Fin.cast (configFactors_length d S i q).symm k)
omit [Fintype A] in
private theorem prod_gate (d : LocalData m A) (S : Finset (Fin m)) (i : ℕ)
(q : DiagramConfig A S) :
(∏ k, gate d S i k (some q)) = (localFactors d q.1.val i q.2).prod := by
let w := localFactors d q.1.val i q.2
change (∏ k, w.get (Fin.cast (configFactors_length d S i q).symm k)) = w.prod
rw [show (fun k => w.get (Fin.cast (configFactors_length d S i q).symm k)) =
fun k => w.get (finCongr (configFactors_length d S i q).symm k) from rfl,
Equiv.prod_comp,← List.prod_ofFn,List.ofFn_get]
/-- The sole preparation step has fixed unit coefficients. The succeeding
steps apply the local leaf, vertex and propagator data on the prepared slots.
The requested root species is absent from the whole sequence. -/
def experimentSteps (d : LocalData m A) (S : Finset (Fin m)) (i : ℕ) :
List (ExperimentState A S → ExperimentState A S → ℂ) :=
allocate S :: indexedDiagonalSteps (gate d S i)
def endpoint (S : Finset (Fin m)) (a : A) : ExperimentState A S → ℂ
| none => 0
| some q => if output q.1.val q.2 = a then 1 else 0
/-- Nonnegative unit-row kernels, including the preparation and all gates. -/
theorem experimentSteps_stochastic (d : LocalData m A) (S : Finset (Fin m)) (i : ℕ)
(P : (ExperimentState A S × Fin 4) → (ExperimentState A S × Fin 4) → ℝ)
(hP : P ∈ (experimentSteps d S i).map FourPhase.kernel) :
(∀ a b, 0 ≤ P a b) ∧ ∀ a, ∑ b, P a b = 1 := by
obtain ⟨M,_,rfl⟩ := List.mem_map.mp hP
exact ⟨FourPhase.kernel_nonneg M,FourPhase.kernel_row M⟩
/-- The calibrated stochastic observable uses just the root species and
four-phase character. It never reads a local tensor or propagator. -/
def observe (d : LocalData m A) (S : Finset (Fin m)) (i : ℕ) (a : A) : ℂ :=
let w := experimentSteps d S i
calibration w * FourPhase.observeWord (FourPhase.lift (endpoint S a)) w (none,0)
theorem observe_eq_treeSum (d : LocalData m A) (S : Finset (Fin m)) (i : ℕ) (a : A) :
observe d S i a = treeSum d S i a := by
dsimp only [observe]
rw [FourPhase.observe_word]
change calibration (experimentSteps d S i) *
(FourPhase.phase 0 * _ / calibration (experimentSteps d S i)) = _
simp only [FourPhase.phase,Matrix.cons_val_zero,one_mul,mul_div_cancel₀ _ (calibration_ne_zero _)]
change FourPhase.act (allocate S) (FourPhase.applyWord (endpoint S a)
(indexedDiagonalSteps (gate d S i))) none = _
simp only [FourPhase.act,Fintype.sum_option,allocate,zero_add,one_mul,
apply_indexedDiagonalSteps,prod_gate,endpoint,mul_ite,mul_one,mul_zero]
rw [Fintype.sum_sigma]
simp_rw [localContraction_eq_current]
exact Finset.sum_attach (trees S) (fun T => diagramCurrent d T i a)
theorem observe_eq_amputated (d : LocalData m A) (S : Finset (Fin m)) (i : ℕ) (a : A) :
observe d S i a = amputated d S i a :=
(observe_eq_treeSum d S i a).trans (amputated_eq_treeSum d S i a).symm
end
end MarkovScattering.SpeciesTree
Source