Trajectories, return times, and hitting times of a finite chain
Definitionmm_pathThis file develops the finite-horizon trajectory calculus of a finite chain, following Sections 1.5 and 2.1 of Levin-Peres-Wilmer. A trajectory of length is a map , carrying the weight ; the probability of any event determined by the first steps of the chain started at is the finite sum of the weights of the trajectories with realizing it. In this way the file defines the tail probabilities of the first hitting time (the starting state is exempt from the avoidance constraint), the refined event , the tails of the hitting time of a set of states (here the starting state is not exempt), and the first-passage probabilities . On top of these, expectations of hitting times are defined by the tail-sum formula
as infinite series in : the expected hitting time , the expected return time , and the expected hitting time of a set; and the probability of visiting strictly before is defined as the series of first-passage probabilities. All infinite series follow the convention that a non-summable family sums to .
import Definitions.Def_mm_basic
import Mathlib.Analysis.SpecificLimits.Basic
/-!
Finite trajectories, return times and hitting times for a finite Markov chain,
following Levin–Peres–Wilmer, *Markov Chains and Mixing Times*, §1.5 and §2.1.
A length-`t` trajectory is a function `ω : Fin (t+1) → V` recording the states
at times `0, 1, …, t`. Under the chain law started at `x`, the trajectory `ω`
with `ω 0 = x` has probability `∏ i, P (ω i) (ω (i+1))`; every event
depending on the first `t` steps is a finite sum of such products. Tail
probabilities of hitting times are expressed this way, and expectations are
recovered as `E Y = ∑_{t ≥ 0} P{Y > t}` for a nonnegative integer variable `Y`
(the identity used throughout LPW, e.g. in the proof of Lemma 1.13).
-/
namespace MarkovMixing
noncomputable section
open scoped BigOperators
variable {V : Type*} [Fintype V] [DecidableEq V]
/-- The probability weight `∏_{i<t} P(ω_i, ω_{i+1})` of the length-`t`
trajectory `ω` (conditional on its starting state `ω 0`). -/
def pathWeight (P : Matrix V V ℝ) {t : ℕ} (ω : Fin (t + 1) → V) : ℝ :=
∏ i : Fin t, P (ω i.castSucc) (ω i.succ)
/-- `P_x{τ⁺_z > t, X_t = y}`: the chain started at `x` is at `y` at time `t`
without having visited `z` at any of the times `1, …, t` (LPW §1.5.3,
Eq. (1.19), where `τ⁺_z = min {t ≥ 1 : X_t = z}` is the first return time). -/
def avoidHitProb (P : Matrix V V ℝ) (x z y : V) (t : ℕ) : ℝ :=
∑ ω : Fin (t + 1) → V,
if ω 0 = x ∧ (∀ i : Fin (t + 1), i ≠ 0 → ω i ≠ z) ∧ ω (Fin.last t) = y then
pathWeight P ω
else 0
/-- `P_x{τ⁺_z > t}`: the chain started at `x` does not visit `z` at any of the
times `1, …, t` (LPW §1.5.2). -/
def avoidTailProb (P : Matrix V V ℝ) (x z : V) (t : ℕ) : ℝ :=
∑ ω : Fin (t + 1) → V,
if ω 0 = x ∧ (∀ i : Fin (t + 1), i ≠ 0 → ω i ≠ z) then pathWeight P ω else 0
/-- `E_x(τ⁺_z)`, the expected first time `≥ 1` at which the chain started at
`x` visits `z`, via the tail-sum formula `E Y = ∑_{t≥0} P{Y > t}`
(LPW §1.5.2–§1.5.3; junk value `0` when the tails are not summable). -/
def expHitTimePos (P : Matrix V V ℝ) (x z : V) : ℝ :=
∑' t : ℕ, avoidTailProb P x z t
/-- `E_x(τ⁺_x)`, the expected first return time to `x` (LPW §1.5.3). -/
def expReturnTime (P : Matrix V V ℝ) (x : V) : ℝ :=
expHitTimePos P x x
/-- `P_x{τ_a = t, τ_b > t}`: started at `x`, the chain first visits `a` at
time `t` and has not visited `b` at any time `≤ t`. (Here `τ_a` is the first
time `≥ 0` at which the chain is at `a`.) -/
def firstHitBeforeProb (P : Matrix V V ℝ) (x a b : V) (t : ℕ) : ℝ :=
∑ ω : Fin (t + 1) → V,
if ω 0 = x ∧ ω (Fin.last t) = a ∧
(∀ i : Fin (t + 1), i ≠ Fin.last t → ω i ≠ a) ∧ (∀ i : Fin (t + 1), ω i ≠ b) then
pathWeight P ω
else 0
/-- `P_x{τ_a < τ_b}`: started at `x`, the chain visits `a` (at some finite
time) strictly before it visits `b` (LPW §2.1). -/
def hitBeforeProb (P : Matrix V V ℝ) (x a b : V) : ℝ :=
∑' t : ℕ, firstHitBeforeProb P x a b t
/-- `P_x{τ_S > t}`: the chain started at `x` stays outside the set `S` up to
and including time `t`, where `τ_S = min {t ≥ 0 : X_t ∈ S}`. -/
def setAvoidTailProb (P : Matrix V V ℝ) (x : V) (S : Finset V) (t : ℕ) : ℝ :=
∑ ω : Fin (t + 1) → V,
if ω 0 = x ∧ (∀ i : Fin (t + 1), ω i ∉ S) then pathWeight P ω else 0
/-- `E_x(τ_S)`, the expected first time `≥ 0` at which the chain started at `x`
is in `S`, via the tail-sum formula (LPW §2.1; junk value `0` when the tails
are not summable). -/
def expSetHitTime (P : Matrix V V ℝ) (x : V) (S : Finset V) : ℝ :=
∑' t : ℕ, setAvoidTailProb P x S t
end
end MarkovMixing
Read-back
What the Lean code literally says, in plain math · claude-fable-5
Read-back: Def_mm_path
Throughout, is an arbitrary finite type with decidable equality, and is an arbitrary matrix of real numbers — no assumption is made anywhere in this file that is stochastic, nonnegative, or otherwise probability-like. A "path of length " below means a function assigning a state to each of the time indices; the sums below range over all such functions.
pathWeight. Given the matrix , a natural number (implicit), and a path , the path weight is defined as the product of the matrix entries along the consecutive steps of the path:
When (a path consisting of a single state), this is the empty product and equals , regardless of or . Since is not assumed nonnegative, the weight may be any real number.
avoidHitProb. Given , three states (not assumed distinct), and , this is the real number
i.e. the sum of path weights over all length- paths that start at , end at at time , and avoid at every time index except possibly time (the starting state is exempt from the avoidance requirement, so is allowed; but the final index is not exempt when , so for and every summand vanishes). Degenerate case : the only time index is , the avoidance condition is vacuous, and the value is if and otherwise (in particular it is when ).
avoidTailProb. Given , states , and , this is
the sum of weights of all length- paths that start at and avoid at every time index from through inclusive; time is again exempt, so is permitted. No condition is placed on the endpoint. Degenerate case : the condition reduces to , so the value is (the weight of the single one-point path at ).
expHitTimePos. Given and states , this is the value of the infinite series
where the sum is a topological sum over : if the family is not (unconditionally) summable, this expression is by convention equal to , not . Note the series starts at , and the term always equals .
expReturnTime. Given and a state , this is literally : the (topological) sum over of the total weight of length- paths that start at and do not visit at any time in . Again, if the series is not summable the value is by convention.
firstHitBeforeProb. Given , states (not assumed distinct), and , this is
the sum of weights of all length- paths that start at , are at at time but at no earlier time (including time , so for this forces ), and never equal at any time, including time and time . Consequences of the literal reading: if every summand is (the constraints and conflict); if every summand is (the constraints and conflict). Degenerate case : the "no earlier visit to " condition is vacuous and the value is if and , else .
hitBeforeProb. Given and states , this is the topological sum
with the same convention: the value is if the family of terms is not summable.
setAvoidTailProb. Given , a state , a finite subset , and , this is
the sum of weights of all length- paths that start at and avoid the set at every time index, including time — unlike avoidTailProb, the starting state is not exempt here, so if the value is for every . may be empty, in which case the avoidance condition is vacuous. Degenerate case : the value is if and if .
expSetHitTime. Given , a state , and a finite subset , this is the topological sum
equal by convention to whenever the family of terms is not summable. If , every term of the series is and the sum is .
Confirmed by the mission captain (proposal self-audit).