Native electron–photon support from ParticleWalk
DefinitionMarkovScatteringJoint_NativeSupport_01markov-scattering
Source context for the measured electron–photon line, carrying these native mathematical modules and their certified helper results: ParticleWalk, ParticleFamilyCertificate.
Definition code
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Group.Subgroup.Lattice
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Real.Basic
import Mathlib.GroupTheory.Perm.Basic
section
open scoped BigOperators
namespace MarkovScattering.ParticleWalk
variable {X I : Type*} [Fintype I]
/-- Each update is a permutation of the state space of order at most two.
Rates are nonnegative, with zero representing an absent update. -/
structure Walk (X I : Type*) [Fintype I] where
reflection : I → Equiv.Perm X
involutive : ∀ i, Function.Involutive (reflection i)
rate : I → ℝ
nonneg : ∀ i, 0 ≤ rate i
total_pos : 0 < ∑ i, rate i
namespace Walk
variable (W : Walk X I)
noncomputable def kernel (x y : X) : ℝ := by
classical
exact (∑ i, if W.reflection i x = y then W.rate i else 0) / ∑ i, W.rate i
theorem kernel_nonneg (x y : X) : 0 ≤ W.kernel x y := by
classical
unfold kernel
exact div_nonneg (Finset.sum_nonneg fun i _ => by
split <;> simp [W.nonneg]) W.total_pos.le
theorem kernel_pos_iff (x y : X) :
0 < W.kernel x y ↔ ∃ i, 0 < W.rate i ∧ W.reflection i x = y := by
classical
rw [kernel, div_pos_iff_of_pos_right W.total_pos, Finset.sum_pos_iff_of_nonneg]
· simp only [Finset.mem_univ, true_and]
constructor
· rintro ⟨i, hi⟩
by_cases h : W.reflection i x = y
· exact ⟨i, by simpa [h] using hi, h⟩
· simp [h] at hi
· rintro ⟨i, hi, h⟩
exact ⟨i, by simpa [h] using hi⟩
· intro i _
split <;> simp [W.nonneg]
theorem kernel_symm (x y : X) : W.kernel x y = W.kernel y x := by
classical
unfold kernel
congr 1
apply Finset.sum_congr rfl
intro i _
have h : W.reflection i x = y ↔ W.reflection i y = x := by
constructor <;> intro he
· rw [← he, W.involutive i x]
· rw [← he, W.involutive i y]
rw [← h]
variable [Fintype X]
/-- One update of an observable averages its values at the reflected states. -/
theorem kernel_apply_eq_reflection_sum (x : X) (f : X → ℝ) :
∑ y, W.kernel x y * f y =
(∑ i, W.rate i * f (W.reflection i x)) / ∑ i, W.rate i := by
classical
simp only [kernel, div_eq_mul_inv]
calc
_ = (∑ y, (∑ i, if W.reflection i x = y then W.rate i else 0) * f y) *
(∑ i, W.rate i)⁻¹ := by
rw [Finset.sum_mul]
apply Finset.sum_congr rfl
intro y _
ac_rfl
_ = _ := by
congr 1
simp only [Finset.sum_mul]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro i _
simp only [ite_mul, zero_mul]
simp
theorem kernel_row_sum (x : X) : ∑ y, W.kernel x y = 1 := by
classical
simp only [kernel, div_eq_mul_inv, ← Finset.sum_mul]
rw [Finset.sum_comm]
simp [W.total_pos.ne']
theorem kernel_col_sum (y : X) : ∑ x, W.kernel x y = 1 := by
simp only [W.kernel_symm _ y]
exact W.kernel_row_sum y
/-- The (n)-step transition probabilities, starting from the identity at time zero. -/
noncomputable def stepProb (W : Walk X I) : ℕ → X → X → ℝ
| 0, x, y => by classical exact if x = y then 1 else 0
| n + 1, x, y => ∑ z, stepProb W n x z * W.kernel z y
theorem stepProb_nonneg (n : ℕ) (x y : X) : 0 ≤ W.stepProb n x y := by
induction n generalizing y with
| zero =>
classical
simp only [stepProb]
split <;> norm_num
| succ n ih =>
exact Finset.sum_nonneg fun z _ => mul_nonneg (ih z) (W.kernel_nonneg z y)
theorem stepProb_succ_pos_iff (n : ℕ) (x y : X) :
0 < W.stepProb (n + 1) x y ↔ ∃ z, 0 < W.stepProb n x z ∧ 0 < W.kernel z y := by
change 0 < ∑ z, W.stepProb n x z * W.kernel z y ↔ _
rw [Finset.sum_pos_iff_of_nonneg]
· simp only [Finset.mem_univ, true_and]
apply exists_congr
intro z
refine ⟨fun h => ⟨?_, ?_⟩, fun h => mul_pos h.1 h.2⟩
· by_contra! hn
exact (not_lt_of_ge (mul_nonpos_of_nonpos_of_nonneg hn (W.kernel_nonneg z y))) h
· by_contra! hn
exact (not_lt_of_ge (mul_nonpos_of_nonneg_of_nonpos (W.stepProb_nonneg n x z) hn)) h
· exact fun z _ => mul_nonneg (W.stepProb_nonneg n x z) (W.kernel_nonneg z y)
def Reaches (x y : X) : Prop := ∃ n, 0 < W.stepProb n x y
def Communicates (x y : X) : Prop := W.Reaches x y ∧ W.Reaches y x
def generators : Set (Equiv.Perm X) :=
{g | ∃ i, 0 < W.rate i ∧ W.reflection i = g}
def group : Subgroup (Equiv.Perm X) := Subgroup.closure W.generators
def Orbit (x y : X) : Prop := ∃ g : Equiv.Perm X, g ∈ W.group ∧ g x = y
theorem reaches_self (x : X) : W.Reaches x x := by
classical
exact ⟨0, by simp [stepProb]⟩
/-- Any statistic fixed by the positive-rate updates is fixed along positive
probability paths. -/
theorem reaches_preserves {A : Type*} (label : X → A)
(invariant : ∀ i, 0 < W.rate i → ∀ x, label (W.reflection i x) = label x)
{x y : X} (h : W.Reaches x y) : label x = label y := by
classical
obtain ⟨n, hn⟩ := h
induction n generalizing y with
| zero =>
by_cases hxy : x = y
· rw [hxy]
· simp [stepProb, hxy] at hn
| succ n ih =>
obtain ⟨z, hz, hzy⟩ := (W.stepProb_succ_pos_iff n x y).1 hn
obtain ⟨i, hi, rfl⟩ := (W.kernel_pos_iff z y).1 hzy
exact (ih hz).trans (invariant i hi z).symm
theorem reaches_append {x y z : X} (hxy : W.Reaches x y) (hyz : 0 < W.kernel y z) :
W.Reaches x z := by
obtain ⟨n, hn⟩ := hxy
exact ⟨n + 1, (W.stepProb_succ_pos_iff n x z).2 ⟨y, hn, hyz⟩⟩
theorem reaches_trans {x y z : X} (hxy : W.Reaches x y) (hyz : W.Reaches y z) :
W.Reaches x z := by
obtain ⟨n, hn⟩ := hyz
induction n generalizing z with
| zero =>
classical
by_cases h : y = z
· simpa [← h] using hxy
· simp [stepProb, h] at hn
| succ n ih =>
obtain ⟨a, ha, haz⟩ := (W.stepProb_succ_pos_iff n y z).1 hn
exact W.reaches_append (ih ha) haz
theorem orbit_of_reaches {x y : X} (h : W.Reaches x y) : W.Orbit x y := by
obtain ⟨n, hn⟩ := h
induction n generalizing y with
| zero =>
classical
by_cases hxy : x = y
· exact ⟨1, Subgroup.one_mem _, hxy⟩
· simp [stepProb, hxy] at hn
| succ n ih =>
obtain ⟨z, hz, hzy⟩ := (W.stepProb_succ_pos_iff n x y).1 hn
obtain ⟨g, hg, rfl⟩ := ih hz
obtain ⟨i, hi, hiy⟩ := (W.kernel_pos_iff (g x) y).1 hzy
exact ⟨W.reflection i * g, W.group.mul_mem (Subgroup.subset_closure ⟨i, hi, rfl⟩) hg,
hiy⟩
omit [Fintype X] in
private theorem reflection_inv (i : I) : (W.reflection i)⁻¹ = W.reflection i := by
ext x
apply (W.reflection i).injective
simp [W.involutive i x]
theorem reaches_of_orbit {x y : X} (h : W.Orbit x y) : W.Reaches x y := by
obtain ⟨g, hg, rfl⟩ := h
suffices h : ∀ z, W.Reaches z (g z) ∧ W.Reaches z (g⁻¹ z) from (h x).1
refine Subgroup.closure_induction (p := fun g _ =>
∀ z, W.Reaches z (g z) ∧ W.Reaches z (g⁻¹ z)) ?_ ?_ ?_ ?_ hg
· rintro _ ⟨i, hi, rfl⟩ z
rw [W.reflection_inv]
have h := W.reaches_append (W.reaches_self z)
((W.kernel_pos_iff z (W.reflection i z)).2 ⟨i, hi, rfl⟩)
exact ⟨h, h⟩
· intro z
simpa using And.intro (W.reaches_self z) (W.reaches_self z)
· intro a b _ _ ha hb z
rw [mul_inv_rev]
exact ⟨W.reaches_trans (hb z).1 (ha (b z)).1,
W.reaches_trans (ha z).2 (hb (a⁻¹ z)).2⟩
· intro a _ ha z
rw [inv_inv]
exact (ha z).symm
theorem reaches_iff_orbit (x y : X) : W.Reaches x y ↔ W.Orbit x y :=
⟨W.orbit_of_reaches, W.reaches_of_orbit⟩
/-- The orbits of the actual permutation subgroup generated by positive-rate updates
are the communicating classes of the normalized stochastic kernel. -/
theorem communicates_iff_orbit (x y : X) : W.Communicates x y ↔ W.Orbit x y := by
refine ⟨fun h => W.orbit_of_reaches h.1, ?_⟩
rintro ⟨g, hg, rfl⟩
exact ⟨W.reaches_of_orbit ⟨g, hg, rfl⟩,
W.reaches_of_orbit ⟨g⁻¹, W.group.inv_mem hg, by simp⟩⟩
/-- Closedness is the finite-chain recurrence criterion. -/
theorem orbit_closed {x y z : X} (hy : W.Orbit x y) (hz : 0 < W.kernel y z) :
W.Orbit x z :=
W.orbit_of_reaches (W.reaches_append (W.reaches_of_orbit hy) hz)
theorem communicates_iff_reaches (x y : X) : W.Communicates x y ↔ W.Reaches x y :=
(W.communicates_iff_orbit x y).trans (W.reaches_iff_orbit x y).symm
theorem kernel_zero_of_not_orbit {x y z : X} (hy : W.Orbit x y)
(hz : ¬ W.Orbit x z) : W.kernel y z = 0 := by
apply le_antisymm _ (W.kernel_nonneg y z)
exact le_of_not_gt fun h => hz (W.orbit_closed hy h)
noncomputable def orbitFinset (x : X) : Finset X := by
classical
exact Finset.univ.filter (W.Orbit x)
theorem mem_orbitFinset (x y : X) : y ∈ W.orbitFinset x ↔ W.Orbit x y := by
classical
simp [orbitFinset]
theorem orbitFinset_nonempty (x : X) : (W.orbitFinset x).Nonempty :=
⟨x, (W.mem_orbitFinset x x).2 (W.orbit_of_reaches (W.reaches_self x))⟩
theorem orbit_row_sum {x y : X} (hy : W.Orbit x y) :
∑ z ∈ W.orbitFinset x, W.kernel y z = 1 := by
rw [← W.kernel_row_sum y]
apply Finset.sum_subset (Finset.subset_univ _)
intro z _ hz
exact W.kernel_zero_of_not_orbit hy (fun h => hz ((W.mem_orbitFinset x z).2 h))
/-- The uniform probability law on a communication class is stationary for
the restriction to that class. -/
theorem uniform_stationary_on_orbit {x y : X} (hy : W.Orbit x y) :
∑ z ∈ W.orbitFinset x, ((W.orbitFinset x).card : ℝ)⁻¹ * W.kernel z y =
((W.orbitFinset x).card : ℝ)⁻¹ := by
simp only [W.kernel_symm _ y, ← Finset.mul_sum, W.orbit_row_sum hy, mul_one]
end Walk
end MarkovScattering.ParticleWalk
end
section
/-! Exact certificates for communicating classes of finite reflection walks.
The same certificate works for all positive assignments of the specified rates. -/
namespace MarkovScattering.ParticleFamily
open ParticleWalk
variable {X I L : Type*} [Fintype X] [Fintype I]
/-- A class invariant and a descending reflection path to one representative
per label. Certificates can use small integer ranks and one reflection index
per state. -/
structure ClassCertificate (reflect : I → X → X) (label : X → L) where
representative : L → X
depth : X → ℕ
nextMove : X → I
preserves : ∀ i x, label (reflect i x) = label x
depth_zero : ∀ x, depth x = 0 → x = representative (label x)
descends : ∀ x, 0 < depth x → depth (reflect (nextMove x) x) < depth x
/-- If every reflection has positive rate, the labels of a valid certificate
are exactly the communicating classes. -/
theorem ClassCertificate.communicates_iff (W : Walk X I) (pos : ∀ i, 0 < W.rate i)
(label : X → L) (C : ClassCertificate (fun i x => W.reflection i x) label)
(x y : X) : W.Communicates x y ↔ label x = label y := by
have inv (u v : X) (h : W.Reaches u v) : label u = label v := by
obtain ⟨n, hn⟩ := h
induction n generalizing v with
| zero =>
classical
by_cases h : u = v
· exact congrArg label h
· simp [Walk.stepProb, h] at hn
| succ n ih =>
obtain ⟨z, hz, hv⟩ := (W.stepProb_succ_pos_iff n u v).1 hn
obtain ⟨i, _, rfl⟩ := (W.kernel_pos_iff z v).1 hv
exact (ih z hz).trans (C.preserves i z).symm
have descend (u : X) : W.Reaches u (C.representative (label u)) := by
induction u using (measure C.depth).wf.induction with
| h u ih =>
by_cases h0 : C.depth u = 0
· rw [← C.depth_zero u h0]
exact W.reaches_self u
· let i := C.nextMove u
let v := W.reflection i u
have huv : W.Reaches u v :=
W.reaches_append (W.reaches_self u) ((W.kernel_pos_iff u v).2 ⟨i, pos i, rfl⟩)
have hv : C.depth v < C.depth u := C.descends u (Nat.pos_of_ne_zero h0)
have hvr := ih v hv
rw [C.preserves i u] at hvr
exact W.reaches_trans huv hvr
constructor
· exact fun h => inv x y h.1
· intro h
have hx := descend x
have hy := descend y
rw [h] at hx
apply (W.communicates_iff_reaches x y).2
exact W.reaches_trans hx ((W.communicates_iff_reaches _ _).2 hy).2
/-- Positive paths are exactly finite words in the active reflections. -/
theorem reaches_iff_word (W : Walk X I) (x y : X) :
W.Reaches x y ↔ ∃ word : List I, (∀ i ∈ word, 0 < W.rate i) ∧
word.foldl (fun u i => W.reflection i u) x = y := by
constructor
· rintro ⟨n, hn⟩
induction n generalizing y with
| zero =>
classical
by_cases h : x = y
· exact ⟨[], by simp, h⟩
· simp [Walk.stepProb, h] at hn
| succ n ih =>
obtain ⟨z, hz, he⟩ := (W.stepProb_succ_pos_iff n x y).1 hn
obtain ⟨i, hp, hi⟩ := (W.kernel_pos_iff z y).1 he
obtain ⟨word, hw, rfl⟩ := ih z hz
refine ⟨word ++ [i], ?_, by simpa using hi⟩
intro j hj
rcases List.mem_append.mp hj with hj | hj
· exact hw j hj
· simpa using (List.mem_singleton.mp hj) ▸ hp
· rintro ⟨word, hw, rfl⟩
induction word generalizing x with
| nil => exact W.reaches_self x
| cons i word ih =>
have hi : W.Reaches x (W.reflection i x) :=
W.reaches_append (W.reaches_self x)
((W.kernel_pos_iff _ _).2 ⟨i, hw i (List.mem_cons_self ..), rfl⟩)
exact W.reaches_trans hi (ih _ (fun j hj => hw j (List.mem_cons_of_mem i hj)))
end MarkovScattering.ParticleFamily
end
Source