Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Outcome-avoiding sampling and REACH

Definition
FormalizedScopeReach_REACH

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

monte-carloprobabilitystatistics

The outcome-avoiding transitions remove the outcome token and renormalize every other token probability. The law is the sum of their product masses over outcome-free timelines ending at the same first threshold crossing. The REACH score is one minus the product of the original model non-outcome probabilities along such a timeline. The REACH estimator averages those scores. The theorem targets explicitly require this sampling law to have total mass one; this is the confirmed additional almost-sure termination and viability assumption.

Definition code
import Definitions.Def_FormalizedScopeReach_SCOPE

noncomputable section
open scoped BigOperators ENNReal
open MeasureTheory

namespace FormalizedScopeReach
variable {V : Type}

def avoidingStepMass (M : Model V) (h : List V) (a : V) : ℝ≥0∞ := by
  classical
  exact if a = M.outcome then 0 else M.next h a / (1 - M.next h M.outcome)

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

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

def reachScore (M : Model V) (x : Timeline V) : ℝ :=
  1 - ∏ i : Fin x.length, (1 - hazard M (x.take i.val))

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

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 2.2 and 4.3; Appendix C
Read-back

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

Blind read-back: Def_FormalizedScopeReach_REACH.lean

avoidingStepMass

For any type VVV, a model MMM consisting of a distinguished element o∈Vo\in Vo∈V, a probability mass function ph:V→[0,∞]p_h:V\to[0,\infty]ph​:V→[0,∞] of total mass 111 for every finite list hhh, and a stopping predicate on such lists, any finite list hhh over VVV, and any a∈Va\in Va∈V, avoidingStepMass is 000 when a=oa=oa=o, and ph(a)/(1−ph(o))p_h(a)/(1-p_h(o))ph​(a)/(1−ph​(o)) otherwise. The subtraction and division take place in the extended nonnegative reals; subtraction is truncated at 000, and 0/0=00/0=00/0=0 in this arithmetic, whereas a positive numerator divided by 000 is ∞\infty∞. Since php_hph​ is a probability mass function, if ph(o)=1p_h(o)=1ph​(o)=1 then ph(a)=0p_h(a)=0ph​(a)=0 for every a≠oa\ne oa=o, and this definition consequently gives zero for every aaa in that case. There is no assumption that ph(o)<1p_h(o)<1ph​(o)<1, that hhh avoids ooo, or that the stopping predicate fails at hhh; the result is an individual mass value rather than a value whose type asserts a probability mass function. The model includes the requirement that its stopping predicate is false on the empty list.

avoidingPathMass

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 x=(x0,…,xL−1)x=(x_0,\ldots,x_{L-1})x=(x0​,…,xL−1​), avoidingPathMass is the extended nonnegative real product ∏i=0L−1qx<i(xi)\prod_{i=0}^{L-1}q_{x_{<i}}(x_i)∏i=0L−1​qx<i​​(xi​) if S(x)S(x)S(x) holds, S(x<i)S(x_{<i})S(x<i​) fails for every 0≤i<L0\le i<L0≤i<L, and ooo does not occur in xxx, and it is 000 otherwise. Here x<ix_{<i}x<i​ is the first iii entries, and qh(a)=0q_h(a)=0qh​(a)=0 for a=oa=oa=o, while qh(a)=ph(a)/(1−ph(o))q_h(a)=p_h(a)/(1-p_h(o))qh​(a)=ph​(a)/(1−ph​(o)) for a≠oa\ne oa=o, with extended nonnegative subtraction and division. No positive-denominator assumption is imposed: if ph(o)=1p_h(o)=1ph​(o)=1 then all qh(a)q_h(a)qh​(a) are zero, using the probability-mass-function constraints and 0/0=00/0=00/0=0. A zero factor therefore makes a nonempty product zero. For the empty list the avoidance and proper-prefix conditions hold automatically and the product is 111, but the model requires ¬S([])\neg S([])¬S([]), so the terminality condition fails and its mass is 000. There is no eventual-stopping assumption.

avoidingLaw

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, avoidingLaw is the measure on all finite lists over VVV, with every subset measurable, formed by summing weighted point masses over all such lists xxx. A list x=(x0,…,xL−1)x=(x_0,\ldots,x_{L-1})x=(x0​,…,xL−1​) has weight ∏i=0L−1qx<i(xi)\prod_{i=0}^{L-1}q_{x_{<i}}(x_i)∏i=0L−1​qx<i​​(xi​) when it contains no ooo, satisfies S(x)S(x)S(x), and has ¬S(x<i)\neg S(x_{<i})¬S(x<i​) for every 0≤i<L0\le i<L0≤i<L; all other lists have weight 000. Here x<ix_{<i}x<i​ is its prefix of length iii and qh(a)q_h(a)qh​(a) is 000 for a=oa=oa=o and ph(a)/(1−ph(o))p_h(a)/(1-p_h(o))ph​(a)/(1−ph​(o)) otherwise, using extended nonnegative arithmetic; if ph(o)=1p_h(o)=1ph​(o)=1, all qh(a)q_h(a)qh​(a) are zero. The value of the measure on a set AAA is the extended nonnegative sum of these weights for x∈Ax\in Ax∈A, with no countability assumption on VVV. The empty list contributes weight 000 because the model requires ¬S([])\neg S([])¬S([]). No argument assumes total mass 111 or eventual stopping, and no infinite lists are included; if SSS never holds the measure is zero.

reachScore

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 a stopping predicate SSS, and any finite list xxx of length LLL, reachScore is the real number 1−∏i=0L−1(1−px<i(o))1-\prod_{i=0}^{L-1}(1-p_{x_{<i}}(o))1−∏i=0L−1​(1−px<i​​(o)), where x<ix_{<i}x<i​ is the first iii entries and each transition mass is converted from an extended nonnegative real to its finite real value, which lies in [0,1][0,1][0,1]. Every listed prefix contributes a factor, regardless of whether SSS holds there or whether it contains ooo. There is no assumption that xxx is terminal, avoids ooo, has positive path weight, or is drawn from any measure. The full list is not itself an index in this product. For the empty list the product is 111 and the score is 000; if any indexed prefix has px<i(o)=1p_{x_{<i}}(o)=1px<i​​(o)=1, the product is zero and the score is 111. The model includes the requirement that its stopping predicate is false on the empty list.

reachEstimator

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, 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, reachEstimator is the real number 1n∑j=0n−1[1−∏i=0Lj−1(1−px<i(j)(o))]\frac{1}{n}\sum_{j=0}^{n-1}\left[1-\prod_{i=0}^{L_j-1}(1-p_{x^{(j)}_{<i}}(o))\right]n1​∑j=0n−1​[1−∏i=0Lj​−1​(1−px<i(j)​​(o))], where LjL_jLj​ is the length of x(j)x^{(j)}x(j), x<i(j)x^{(j)}_{<i}x<i(j)​ is its prefix of length iii, and probabilities are interpreted as their finite real values. It applies to arbitrary lists, without terminality, avoidance, positive-path-weight, sampling-law, or independence assumptions. The stopping predicate does not enter the formula. An empty list has score 000 because its product is 111. The sample count nnn may be 000, in which case the result is 000 by the empty-sum and real-division conventions. The model includes the requirement that its stopping predicate is false on the empty list.

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