Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Timeline sampling and SCOPE

Definition
FormalizedScopeReach_SCOPE

by burkh4rt · Sep 15, 2026 · Mathlib 0df444a (Lean v4.33.1)

monte-carloprobabilitystatistics

The model supplies an outcome token, a next-token probability mass function for each complete history, and a prefix-based threshold predicate that is false initially. Terminal timelines end exactly at their first threshold crossing, and the original law is the sum of their next-token product masses. SCOPE sums original outcome probabilities at each position through the first outcome or the threshold, including that position. Its estimator is the average over a positive number of independently sampled original timelines. Normalization and the no-tie condition are hypotheses of the theorem targets, not assumed identities of these definitions.

Definition code
import Mathlib.Probability.ProbabilityMassFunction.Basic
import Mathlib.Probability.Moments.Variance
import Mathlib.MeasureTheory.Constructions.Pi

noncomputable section
open scoped BigOperators ENNReal
open MeasureTheory

namespace FormalizedScopeReach

structure Model (V : Type) where
  outcome : V
  next : List V → PMF V
  stop : List V → Prop
  beforeThreshold : ¬ stop []

variable {V : Type}

abbrev Timeline (V : Type) := List V

instance timelineMeasurableSpace : MeasurableSpace (Timeline V) := ⊤

instance timelineMeasurableSingletonClass : MeasurableSingletonClass (Timeline V) :=
  ⟨fun _ => trivial⟩

def active (M : Model V) (h : List V) : Prop :=
  ¬ M.stop h ∧ M.outcome ∉ h

def running (M : Model V) (h : List V) : Prop := ¬ M.stop h

def terminal (M : Model V) (x : Timeline V) : Prop :=
  M.stop x ∧ ∀ i : Fin x.length, running M (x.take i.val)

def pathMass (M : Model V) (x : Timeline V) : ℝ≥0∞ := by
  classical
  exact if terminal M x then
    ∏ i : Fin x.length, M.next (x.take i.val) (x.get i)
  else 0

def originalLaw (M : Model V) : Measure (Timeline V) :=
  Measure.sum (fun x => pathMass M x • Measure.dirac x)

def hazard (M : Model V) (h : List V) : ℝ :=
  (M.next h M.outcome).toReal

def scopeScore (M : Model V) (x : Timeline V) : ℝ := by
  classical
  exact ∑ i : Fin x.length,
    if active M (x.take i.val) then hazard M (x.take i.val) else 0

def scopeEstimator (M : Model V) (n : ℕ)
    (xs : Fin n → Timeline V) : ℝ :=
  (∑ i, scopeScore M (xs i)) / (n : ℝ)

def monteCarloScore (M : Model V) (x : Timeline V) : ℝ := by
  classical
  exact if M.outcome ∈ x then 1 else 0

def monteCarloEstimator (M : Model V) (n : ℕ)
    (xs : Fin n → Timeline V) : ℝ :=
  (∑ i, monteCarloScore M (xs i)) / (n : ℝ)

def eventProbability (M : Model V) : ℝ :=
  ((originalLaw M) {x | M.outcome ∈ x}).toReal

def iidLaw (μ : Measure (Timeline V)) [IsProbabilityMeasure μ] (n : ℕ) :
    Measure (Fin n → Timeline V) :=
  Measure.pi (fun _ : Fin n => μ)

instance iidLaw_probability (μ : Measure (Timeline V)) [IsProbabilityMeasure μ] (n : ℕ) :
    IsProbabilityMeasure (iidLaw μ n) := by unfold iidLaw; infer_instance

end FormalizedScopeReach
Source
Solo et al., Efficient Generative Prediction for EHR Foundation Models: The SCOPE and REACH Estimators, arXiv:2602.03730v2 (2026), https://arxiv.org/abs/2602.03730v2, Sections 1.1 and 4.1; Appendix B
Read-back

What the Lean code literally says, in plain math · GPT-6 (Codex independent sub-agent)

Blind read-back: Def_FormalizedScopeReach_SCOPE.lean

Model

For an arbitrary type VVV, a model consists of a distinguished element o∈Vo\in Vo∈V, a function assigning to every finite list hhh of elements of VVV a probability mass function ph:V→[0,∞]p_h:V\to[0,\infty]ph​:V→[0,∞] with ∑a∈Vph(a)=1\sum_{a\in V}p_h(a)=1∑a∈V​ph​(a)=1, a predicate S(h)S(h)S(h) on finite lists, and the requirement ¬S([])\neg S([])¬S([]). The last requirement is the beforeThreshold field and says that the empty list does not satisfy the stopping predicate. Here the sum is the nonnegative extended-real sum over the whole type, with no countability assumption on VVV; each individual mass function has countable support and values at most 111. The distinguished element is the outcome, the mass-function assignment is next, and the predicate is stop. The assignment is defined for all finite lists, including the empty list, lists for which SSS holds, and lists containing ooo. Apart from the requirement that SSS is false on the empty list, no additional relation between the distinguished element, transition assignment, and stopping predicate is required; there is no monotonicity condition on SSS and no termination assumption. An empty type VVV cannot admit such a model because the model includes o∈Vo\in Vo∈V.

Timeline

For an arbitrary type VVV, a timeline is exactly a finite list of elements of VVV, including the empty list. This abbreviation imposes no model, stopping condition, length restriction, probability requirement, or exclusion of repeated elements; it includes no infinite lists. Even when VVV is empty, the empty timeline exists.

timelineMeasurableSpace

For every type VVV, the space of all finite lists of elements of VVV is equipped with the measurable structure in which every subset is measurable. No measurable structure on VVV and no model are assumed.

timelineMeasurableSingletonClass

For every type VVV, each singleton set consisting of one finite list of elements of VVV is declared measurable in the measurable structure on lists in which every subset is measurable. This includes the singleton containing the empty list and requires no model or measurable structure on VVV.

active

For any type VVV, a model MMM with distinguished element o∈Vo\in Vo∈V, transition probability mass functions on all finite lists, and stopping predicate SSS, and any finite list hhh of elements of VVV, active means exactly ¬S(h)∧o∉h\neg S(h)\land o\notin h¬S(h)∧o∈/h. Both conjuncts are required. In particular, the empty list is always active because it contains no ooo and the model requires ¬S([])\neg S([])¬S([]). The definition checks the stopping predicate only at hhh and imposes no condition on its earlier prefixes; absence of ooo concerns the whole list hhh.

running

For any type VVV, any model MMM with distinguished element, transition probability mass functions, and stopping predicate SSS, and any finite list hhh over VVV, running means exactly ¬S(h)\neg S(h)¬S(h). Membership of the distinguished element in hhh, earlier stopping predicates, and transition probabilities are not part of this condition. The empty list is always running because the model requires ¬S([])\neg S([])¬S([]).

terminal

For any type VVV, any model MMM with stopping predicate SSS, distinguished element, and transition probability mass functions, and any finite list xxx over VVV of length LLL, terminal means S(x)S(x)S(x) and, for every integer iii with 0≤i<L0\le i<L0≤i<L, ¬S(x<i)\neg S(x_{<i})¬S(x<i​), where x<ix_{<i}x<i​ is the prefix consisting of the first iii entries. Thus the full list satisfies SSS and every strictly shorter prefix, including the empty prefix when L>0L>0L>0, does not. No condition excludes the distinguished element from xxx, and no transition mass is required to be positive. For L=0L=0L=0, the universal condition has no indices, so terminality would be exactly S([])S([])S([]); the model requires ¬S([])\neg S([])¬S([]), so the empty list is never terminal.

pathMass

For any type VVV, any model MMM with distinguished element, transition probability mass functions php_hph​ of total mass 111 on VVV, and stopping predicate SSS, and any finite list x=(x0,…,xL−1)x=(x_0,\ldots,x_{L-1})x=(x0​,…,xL−1​), the extended nonnegative real pathMass is ∏i=0L−1px<i(xi)\prod_{i=0}^{L-1}p_{x_{<i}}(x_i)∏i=0L−1​px<i​​(xi​) if S(x)S(x)S(x) holds and S(x<i)S(x_{<i})S(x<i​) is false for every 0≤i<L0\le i<L0≤i<L, and is 000 otherwise; x<ix_{<i}x<i​ denotes the first iii entries. Occurrences of the distinguished element are permitted, and no extra transition factor is attached to the stopping predicate. A zero transition factor makes the product zero. The empty product is 111, but the model requires ¬S([])\neg S([])¬S([]), so the empty list fails the terminality condition and has mass 000. No assumption of eventual stopping is imposed.

originalLaw

For any type VVV and any model MMM with distinguished element, transition probability mass functions php_hph​ of total mass 111 on VVV, and stopping predicate SSS, originalLaw is the measure on all finite lists over VVV, with every subset measurable, obtained by summing one weighted point mass at each finite list xxx: its weight is ∏i=0L−1px<i(xi)\prod_{i=0}^{L-1}p_{x_{<i}}(x_i)∏i=0L−1​px<i​​(xi​) when LLL is the length of xxx, S(x)S(x)S(x) holds, and S(x<i)S(x_{<i})S(x<i​) fails for every 0≤i<L0\le i<L0≤i<L, and its weight is 000 otherwise. Consequently its value on a set AAA of finite lists is the extended nonnegative sum of these weights over all x∈Ax\in Ax∈A; the sum is meaningful without a countability assumption on VVV. The empty list contributes weight 000 because the model requires ¬S([])\neg S([])¬S([]). There is no assumption here that this measure has total mass 111 or that stopping eventually occurs, and there are no infinite timelines in its space; for example, when SSS is false on every list the measure is zero.

hazard

For any type VVV, any model MMM with distinguished element o∈Vo\in Vo∈V, transition probability mass functions php_hph​ on VVV, and stopping predicate, and any finite list hhh over VVV, hazard is the real number obtained from ph(o)p_h(o)ph​(o) by the extended-nonnegative-real-to-real conversion. This conversion preserves finite values and sends ∞\infty∞ to 000; here ph(o)≤1p_h(o)\le1ph​(o)≤1, so the result is its ordinary real probability and lies in [0,1][0,1][0,1]. It is defined at every list, including the empty list, stopped lists, and lists containing ooo, with no active or running condition. The model includes the requirement that its stopping predicate is false on the empty list.

scopeScore

For any type VVV, any model MMM with distinguished element o∈Vo\in Vo∈V, transition probability mass functions php_hph​ of total mass 111, and stopping predicate SSS, and any finite list xxx of length LLL, scopeScore is the real sum ∑i=0L−11{¬S(x<i) ∧ o∉x<i}px<i(o)\sum_{i=0}^{L-1}\mathbf{1}_{\{\neg S(x_{<i})\,\land\,o\notin x_{<i}\}}p_{x_{<i}}(o)∑i=0L−1​1{¬S(x<i​)∧o∈/x<i​}​px<i​​(o), where x<ix_{<i}x<i​ is the first iii entries, the indicator is 111 when its condition holds and 000 otherwise, and each probability is interpreted as its finite real value. This is defined on arbitrary lists, without requiring terminality or positive path mass. It evaluates only prefixes preceding entries, not the full list. The entry at which ooo first occurs can have a contributing preceding prefix; all later prefixes contain ooo and contribute zero. The stopping predicate is checked separately at each prefix, without requiring it to remain true after first holding. For the empty list the sum is 000. The model includes the requirement that its stopping predicate is false on the empty list.

scopeEstimator

For any type VVV, any model MMM with distinguished element o∈Vo\in Vo∈V, transition probability mass functions php_hph​ of total mass 111, and stopping predicate SSS, any natural number nnn, including 000, and any indexed family of finite lists x(j)x^{(j)}x(j) over VVV for 0≤j<n0\le j<n0≤j<n, scopeEstimator is the real number 1n∑j=0n−1∑i=0Lj−11{¬S(x<i(j)) ∧ o∉x<i(j)}px<i(j)(o)\frac{1}{n}\sum_{j=0}^{n-1}\sum_{i=0}^{L_j-1}\mathbf{1}_{\{\neg S(x^{(j)}_{<i})\,\land\,o\notin x^{(j)}_{<i}\}}p_{x^{(j)}_{<i}}(o)n1​∑j=0n−1​∑i=0Lj​−1​1{¬S(x<i(j)​)∧o∈/x<i(j)​}​px<i(j)​​(o), where LjL_jLj​ is the length of x(j)x^{(j)}x(j), the prefix has its first iii entries, the indicator is 111 or 000 according to its condition, and transition masses are read as real numbers. No distribution, independence, terminality, or occurrence restriction is assumed for the family. Empty-list inner sums are 000, and when n=0n=0n=0 the value is 000, using the empty outer sum and the total real-division convention 0/0=00/0=00/0=0. The model includes the requirement that its stopping predicate is false on the empty list.

monteCarloScore

For any type VVV, any model MMM with distinguished element o∈Vo\in Vo∈V, transition probability mass functions, and stopping predicate, and any finite list xxx over VVV, monteCarloScore is the real number 111 if ooo occurs anywhere in xxx, and 000 otherwise. Neither transition probabilities nor the stopping predicate enter this value, and xxx need not be terminal. An occurrence in the final entry counts, multiple occurrences still give 111, and the empty list gives 000. The model includes the requirement that its stopping predicate is false on the empty list.

monteCarloEstimator

For any type VVV, any model MMM with distinguished element o∈Vo\in Vo∈V, transition probability mass functions, and stopping predicate, any natural number nnn, and any family of finite lists x(j)x^{(j)}x(j) over VVV indexed by 0≤j<n0\le j<n0≤j<n, monteCarloEstimator is 1n∑j=0n−11{o∈x(j)}\frac{1}{n}\sum_{j=0}^{n-1}\mathbf{1}_{\{o\in x^{(j)}\}}n1​∑j=0n−1​1{o∈x(j)}​ as a real number, where the indicator is 111 if the list contains ooo and 000 otherwise. An occurrence in the final entry is included. No sampling law, independence, or stopping condition is imposed on the family. The natural number nnn may be 000, in which case the empty sum divided by zero is 000 under real division. The model includes the requirement that its stopping predicate is false on the empty list.

eventProbability

For any type VVV and any model MMM with distinguished element o∈Vo\in Vo∈V, transition probability mass functions php_hph​ of total mass 111, and stopping predicate SSS, eventProbability is the conversion to a real number of the extended nonnegative sum ∑xw(x)1{o∈x}\sum_{x}w(x)\mathbf{1}_{\{o\in x\}}∑x​w(x)1{o∈x}​ over all finite lists over VVV, where w(x)=∏i=0L−1px<i(xi)w(x)=\prod_{i=0}^{L-1}p_{x_{<i}}(x_i)w(x)=∏i=0L−1​px<i​​(xi​) if xxx has length LLL, S(x)S(x)S(x) holds, and S(x<i)S(x_{<i})S(x<i​) fails for every 0≤i<L0\le i<L0≤i<L, and w(x)=0w(x)=0w(x)=0 otherwise. Equivalently this is the measure of the set of lists containing ooo under the weighted point-mass measure just specified, converted to a real number; all sets of lists are measurable. The conversion preserves finite values and sends ∞\infty∞ to 000. A first occurrence at the final entry is included, whereas the empty list is excluded. No assumption that the weighted measure has total mass 111 is an argument to this definition, and no renormalization is performed. The model includes the requirement that its stopping predicate is false on the empty list.

iidLaw

For any type VVV, any measure μ\muμ on the space of all finite lists over VVV with all subsets measurable, the explicit assumption that μ\muμ is a probability measure, meaning its total mass is 111, and any natural number nnn, iidLaw is the finite product measure μ⊗n\mu^{\otimes n}μ⊗n on families of finite lists indexed by 0≤j<n0\le j<n0≤j<n, with the product measurable structure. Its value on a measurable rectangle ∏j=0n−1Aj\prod_{j=0}^{n-1}A_j∏j=0n−1​Aj​ is ∏j=0n−1μ(Aj)\prod_{j=0}^{n-1}\mu(A_j)∏j=0n−1​μ(Aj​). This definition takes no model and does not require μ\muμ to equal either of the weighted path measures. When n=0n=0n=0, the family space has the unique empty family and the product measure assigns it mass 111.

iidLaw_probability

For any type VVV, any measure μ\muμ on the space of all finite lists over VVV equipped with the measurable structure in which every subset is measurable, the assumption that μ\muμ has total mass 111, and any natural number nnn, the finite product measure μ⊗n\mu^{\otimes n}μ⊗n on families of finite lists indexed by 0≤j<n0\le j<n0≤j<n, equipped with the product measurable structure, is declared to be a probability measure: its total mass is 111. This product is the measure whose value on every measurable rectangle ∏j=0n−1Aj\prod_{j=0}^{n-1}A_j∏j=0n−1​Aj​ is ∏j=0n−1μ(Aj)\prod_{j=0}^{n-1}\mu(A_j)∏j=0n−1​μ(Aj​). There is no model argument and no requirement identifying μ\muμ with a weighted path measure. When n=0n=0n=0, the family space contains the unique empty family, to which this probability measure assigns mass 111.

Human review
  • Endorsed by Shuze Chen · Sep 15, 2026

  • Endorsed by burkh4rt · Sep 15, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me