Timeline sampling and SCOPE
DefinitionFormalizedScopeReach_SCOPEThe 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.
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
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 , a model consists of a distinguished element , a function assigning to every finite list of elements of a probability mass function with , a predicate on finite lists, and the requirement . 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 ; each individual mass function has countable support and values at most . 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 holds, and lists containing . Apart from the requirement that 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 and no termination assumption. An empty type cannot admit such a model because the model includes .
Timeline
For an arbitrary type , a timeline is exactly a finite list of elements of , 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 is empty, the empty timeline exists.
timelineMeasurableSpace
For every type , the space of all finite lists of elements of is equipped with the measurable structure in which every subset is measurable. No measurable structure on and no model are assumed.
timelineMeasurableSingletonClass
For every type , each singleton set consisting of one finite list of elements of 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 .
active
For any type , a model with distinguished element , transition probability mass functions on all finite lists, and stopping predicate , and any finite list of elements of , active means exactly . Both conjuncts are required. In particular, the empty list is always active because it contains no and the model requires . The definition checks the stopping predicate only at and imposes no condition on its earlier prefixes; absence of concerns the whole list .
running
For any type , any model with distinguished element, transition probability mass functions, and stopping predicate , and any finite list over , running means exactly . Membership of the distinguished element in , earlier stopping predicates, and transition probabilities are not part of this condition. The empty list is always running because the model requires .
terminal
For any type , any model with stopping predicate , distinguished element, and transition probability mass functions, and any finite list over of length , terminal means and, for every integer with , , where is the prefix consisting of the first entries. Thus the full list satisfies and every strictly shorter prefix, including the empty prefix when , does not. No condition excludes the distinguished element from , and no transition mass is required to be positive. For , the universal condition has no indices, so terminality would be exactly ; the model requires , so the empty list is never terminal.
pathMass
For any type , any model with distinguished element, transition probability mass functions of total mass on , and stopping predicate , and any finite list , the extended nonnegative real pathMass is if holds and is false for every , and is otherwise; denotes the first 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 , but the model requires , so the empty list fails the terminality condition and has mass . No assumption of eventual stopping is imposed.
originalLaw
For any type and any model with distinguished element, transition probability mass functions of total mass on , and stopping predicate , originalLaw is the measure on all finite lists over , with every subset measurable, obtained by summing one weighted point mass at each finite list : its weight is when is the length of , holds, and fails for every , and its weight is otherwise. Consequently its value on a set of finite lists is the extended nonnegative sum of these weights over all ; the sum is meaningful without a countability assumption on . The empty list contributes weight because the model requires . There is no assumption here that this measure has total mass or that stopping eventually occurs, and there are no infinite timelines in its space; for example, when is false on every list the measure is zero.
hazard
For any type , any model with distinguished element , transition probability mass functions on , and stopping predicate, and any finite list over , hazard is the real number obtained from by the extended-nonnegative-real-to-real conversion. This conversion preserves finite values and sends to ; here , so the result is its ordinary real probability and lies in . It is defined at every list, including the empty list, stopped lists, and lists containing , 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 , any model with distinguished element , transition probability mass functions of total mass , and stopping predicate , and any finite list of length , scopeScore is the real sum , where is the first entries, the indicator is when its condition holds and 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 first occurs can have a contributing preceding prefix; all later prefixes contain 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 . The model includes the requirement that its stopping predicate is false on the empty list.
scopeEstimator
For any type , any model with distinguished element , transition probability mass functions of total mass , and stopping predicate , any natural number , including , and any indexed family of finite lists over for , scopeEstimator is the real number , where is the length of , the prefix has its first entries, the indicator is or 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 , and when the value is , using the empty outer sum and the total real-division convention . The model includes the requirement that its stopping predicate is false on the empty list.
monteCarloScore
For any type , any model with distinguished element , transition probability mass functions, and stopping predicate, and any finite list over , monteCarloScore is the real number if occurs anywhere in , and otherwise. Neither transition probabilities nor the stopping predicate enter this value, and need not be terminal. An occurrence in the final entry counts, multiple occurrences still give , and the empty list gives . The model includes the requirement that its stopping predicate is false on the empty list.
monteCarloEstimator
For any type , any model with distinguished element , transition probability mass functions, and stopping predicate, any natural number , and any family of finite lists over indexed by , monteCarloEstimator is as a real number, where the indicator is if the list contains and otherwise. An occurrence in the final entry is included. No sampling law, independence, or stopping condition is imposed on the family. The natural number may be , in which case the empty sum divided by zero is under real division. The model includes the requirement that its stopping predicate is false on the empty list.
eventProbability
For any type and any model with distinguished element , transition probability mass functions of total mass , and stopping predicate , eventProbability is the conversion to a real number of the extended nonnegative sum over all finite lists over , where if has length , holds, and fails for every , and otherwise. Equivalently this is the measure of the set of lists containing 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 to . A first occurrence at the final entry is included, whereas the empty list is excluded. No assumption that the weighted measure has total mass 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 , any measure on the space of all finite lists over with all subsets measurable, the explicit assumption that is a probability measure, meaning its total mass is , and any natural number , iidLaw is the finite product measure on families of finite lists indexed by , with the product measurable structure. Its value on a measurable rectangle is . This definition takes no model and does not require to equal either of the weighted path measures. When , the family space has the unique empty family and the product measure assigns it mass .
iidLaw_probability
For any type , any measure on the space of all finite lists over equipped with the measurable structure in which every subset is measurable, the assumption that has total mass , and any natural number , the finite product measure on families of finite lists indexed by , equipped with the product measurable structure, is declared to be a probability measure: its total mass is . This product is the measure whose value on every measurable rectangle is . There is no model argument and no requirement identifying with a weighted path measure. When , the family space contains the unique empty family, to which this probability measure assigns mass .
Confirmed by the mission captain (proposal self-audit).