The two-stage Bernoulli experiment
DefinitionFormalizedScopeReach_TrialsFor each outcome-free timeline, independent Bernoulli trials use the original next-token outcome probabilities along its prefixes. The joint experiment first draws an independent pool of timelines from the outcome-avoiding law and then draws the corresponding conditional trials. Its Monte Carlo average records which timelines have at least one success. The retained information consists of the entire indexed pool of outcome-free timelines. All conditional trials and the joint law are explicitly constructed, so the conditional-expectation identity is a theorem rather than a defining assumption.
import Definitions.Def_FormalizedScopeReach_Times
import Mathlib.Probability.Distributions.Bernoulli
import Mathlib.MeasureTheory.Function.ConditionalExpectation.Basic
noncomputable section
open scoped BigOperators ENNReal
open MeasureTheory ProbabilityTheory
namespace FormalizedScopeReach
variable {V : Type}
/-- Conditional independent Bernoulli trials from Appendix C. -/
def trialLaw (M : Model V) (x : Timeline V) : Measure (Fin x.length → Bool) :=
Measure.pi (fun i : Fin x.length => bernoulliMeasure true false
⟨hazard M (x.take i.val), ENNReal.toReal_nonneg,
by simpa [hazard] using (ENNReal.toReal_mono ENNReal.one_ne_top ((M.next (x.take i.val)).coe_le_one M.outcome))⟩)
instance trialLaw_probability (M : Model V) (x : Timeline V) :
IsProbabilityMeasure (trialLaw M x) := by unfold trialLaw; infer_instance
/-- Indicator of at least one success on a fixed timeline. -/
def trialSuccess (x : Timeline V) (c : Fin x.length → Bool) : ℝ := by
classical
exact if c = (fun _ => false) then 0 else 1
/-- Store the finite list of trial results for a timeline. -/
def trialListLaw (M : Model V) (x : Timeline V) : Measure (List Bool) :=
(trialLaw M x).map List.ofFn
/-- Conditional trial law for a pool of independent timelines. -/
def poolTrialLaw (M : Model V) {n : ℕ} (xs : Fin n → Timeline V) :
Measure (Fin n → List Bool) := Measure.pi (fun i => trialListLaw M (xs i))
/-- The joint two-stage experiment: sample timelines, then their Bernoulli trials. -/
def twoStageLaw (M : Model V) [IsProbabilityMeasure (avoidingLaw M)] (n : ℕ) :
Measure ((Fin n → Timeline V) × (Fin n → List Bool)) :=
Measure.sum (fun xs : Fin n → Timeline V =>
(iidLaw (avoidingLaw M) n) {xs} •
(poolTrialLaw M xs).map (fun cs => (xs, cs)))
/-- The sampled indicator average in the paper's two-stage experiment. -/
def trialMean (n : ℕ) (z : (Fin n → Timeline V) × (Fin n → List Bool)) : ℝ := by
classical
exact (∑ i, if true ∈ z.2 i then (1 : ℝ) else 0) / (n : ℝ)
/-- The information retained when the outcome-free timelines are observed. -/
def timelineInformation (n : ℕ) :
MeasurableSpace ((Fin n → Timeline V) × (Fin n → List Bool)) :=
MeasurableSpace.comap Prod.fst inferInstance
end FormalizedScopeReach
Read-back
What the Lean code literally says, in plain math · GPT-6 (Codex independent sub-agent)
Read-back: Def_FormalizedScopeReach_Trials
trialLaw
For any type V, any Model V named M, and any Timeline V named x, trialLaw is a measure on the Boolean-valued functions whose indices are the natural numbers strictly less than the length of x. A Timeline V is a finite list of elements of V. The model supplies an element M.outcome of V, a probability mass function M.next on V for every finite list of elements of V, a predicate M.stop on those lists, and a proof that M.stop is false on the empty list; no measurable-space or countability assumption on V is required. For each index i, the coordinate measure gives true probability hazard M (x.take i.val) and gives false probability one minus that number. Here x.take i.val is the prefix containing exactly the entries before position i, and the stated hazard is the real-valued conversion of the probability mass assigned to M.outcome by M.next at that prefix. Every such probability mass is finite and between zero and one, so this real-valued conversion supplies a parameter in the closed unit interval. trialLaw is the finite product of these coordinate measures, making the coordinates independent for this fixed x. Its measurable space is the finite product of the Boolean measurable spaces. The first coordinate uses the empty prefix, and the final coordinate uses the prefix omitting the final entry of x; the full prefix x supplies no additional coordinate. The definition accepts every finite list x, whether or not it satisfies M.stop, whether or not an earlier prefix satisfies M.stop, and whether or not it contains M.outcome; no coordinate is removed on account of these conditions. A zero hazard forces false, a hazard of one forces true, and an empty x gives the probability measure concentrated on the unique function with no coordinates.
trialLaw_probability
For any type V, every Model V named M, and every finite list x of elements of V, trialLaw_probability asserts that the measure trialLaw M x has total mass one. The model consists of an element M.outcome, a probability mass function M.next on V at each finite list, a predicate M.stop on finite lists, and a proof that this predicate is false on the empty list. The measure in this assertion is the finite product of Boolean measures, one for each natural-number position strictly below the length of x, in which true has probability equal to the real conversion of the mass of M.outcome under M.next at the prefix before that position, and false has the complementary probability. There is no additional hypothesis that x avoids the outcome or stops at any particular position, and no assumption that either of the model's timeline measures is a probability measure. The assertion includes the empty list, whose product measure has mass one on its unique empty Boolean function, and includes hazards equal to either endpoint zero or one.
trialSuccess
For any type V, any finite list x of elements of V, and any function c assigning a Boolean to each natural-number position strictly below the length of x, trialSuccess is the real number zero if c equals the function that is false at every position, and is the real number one otherwise. Equivalently, it is one exactly when at least one position is assigned true. It does not count how many positions are assigned true. The entries of x are irrelevant except for determining the number of positions; there is no model, distribution, stopping condition, or other hypothesis on either x or c. If x is empty, there is only one possible function c, it equals the all-false function on the empty index set, and the result is zero.
trialListLaw
For any type V, any Model V named M, and any finite list x of elements of V, trialListLaw is a measure on finite lists of Booleans, with every subset of those lists measurable. The model supplies an element M.outcome, a probability mass function M.next on V for every finite list, a predicate M.stop on finite lists, and a proof that the predicate is false on the empty list. The measure is the pushforward of trialLaw M x by List.ofFn: first take an independent Boolean at each position strictly below the length of x, with probability of true equal to the real conversion of the mass that M.next assigns to M.outcome at the prefix before that position, and then list those Booleans in increasing position order. Thus the measure of a set of Boolean lists is the trialLaw probability that the resulting ordered list belongs to that set. Every resulting list has exactly the length of x, and all lists of other lengths have measure zero. The construction includes arbitrary x, with no terminal or outcome-avoidance requirement, and includes probabilities zero and one. It has total mass one; for empty x, it is concentrated on the empty Boolean list.
poolTrialLaw
For any type V, any Model V named M, any natural number n supplied as an implicit argument, and any function xs assigning a finite list of elements of V to each natural-number index strictly less than n, poolTrialLaw is a measure on the functions assigning a finite Boolean list to each such index. The model supplies an element M.outcome, a probability mass function M.next on V at every finite list, a predicate M.stop on finite lists, and a proof that the predicate is false on the empty list. This measure is the finite product, over the indices i, of trialListLaw M (xs i). At index i, this factor is obtained by taking independent Boolean trials at all positions of xs i, using the real probability mass of M.outcome under M.next at the prefix before each position as its probability of true, and placing the results in their original position order. The product makes the Boolean lists for distinct indices independent, for the fixed function xs. It uses the product measurable space of Boolean lists, each of whose subsets is measurable, and has total mass one. At every index, the Boolean-list length equals the length of the corresponding timeline with probability one. The timelines xs i are fixed inputs here and need not be distinct, terminal, outcome-free, or independently sampled. Empty timelines give empty Boolean lists. When n is zero, there is a unique function xs and a unique function of Boolean lists, and the measure is concentrated on that unique function with no coordinates.
twoStageLaw
For any type V, any Model V named M, under the typeclass assumption that avoidingLaw M has total mass one, and for every natural number n, twoStageLaw is a measure on pairs consisting of a function of n finite timelines and a function of n finite Boolean lists, using their product measurable space. The model supplies an element M.outcome, a probability mass function M.next on V at each finite list, a predicate M.stop on finite lists, and a proof that M.stop is false on the empty list. The timeline space is the space of finite lists of elements of V, with every subset measurable. The assumed measure avoidingLaw M is the sum, over all such finite lists, of a point mass at that list multiplied by its avoidingPathMass. This mass is zero unless the list satisfies M.stop, every proper prefix fails M.stop, and the list contains no M.outcome. For a list meeting all three conditions, its mass is the product over its positions of avoidingStepMass at the prefix before that position and the entry at that position. This step mass is zero when the entry equals M.outcome; otherwise it is the mass that M.next at the prefix assigns to that entry, divided by one minus the mass assigned there to M.outcome. These operations take place in the extended nonnegative real numbers, with subtraction truncated at zero and with zero divided by zero defined as zero. In particular, if the probability mass of M.outcome is one, every other entry has zero mass and its step mass is zero. The empty timeline has mass zero because the model requires that M.stop be false there. The definition does not impose countability on V or boundedness on timeline lengths. To construct twoStageLaw, for every possible function xs of n timelines, form the probability of the singleton consisting of xs under iidLaw (avoidingLaw M) n; this latter measure is the finite product of n copies of avoidingLaw M. Multiply that singleton probability by the pushforward of poolTrialLaw M xs under the map sending a function cs of Boolean lists to the pair consisting of this fixed xs and cs, and then sum these measures over all possible xs. In this description, poolTrialLaw M xs is the independent product across the timeline indices of ordered Boolean-list distributions; within each timeline, its positions are independent trials, with probability of true equal to the real conversion of the M.next mass of M.outcome at the preceding prefix. Each Boolean list has exactly the length of its corresponding timeline with probability one. Thus, on any measurable set of pairs, the measure is the sum over all xs of its singleton timeline probability multiplied by the probability that the corresponding pair with random cs belongs to that set. The indexed sums are sums of nonnegative extended real masses, understood as suprema of finite subsums even if the index types are uncountable. A timeline pool of singleton weight zero contributes the zero measure. The hypothesis that avoidingLaw M is a probability measure is required; for example, a model for which M.stop is false on every list has zero avoidingLaw and does not satisfy it. When n is zero, the resulting measure is concentrated on the unique pair of functions with no coordinates.
trialMean
For any type V, any natural number n, and any pair z whose first component assigns a finite timeline over V to each natural-number index strictly below n and whose second component assigns a finite Boolean list to each such index, trialMean is the real-valued sum, over those indices i, of one when true occurs in the Boolean list z.2 i and zero otherwise, divided by the real-valued conversion of n. Each list contributes at most one even if true occurs several times, and an empty Boolean list contributes zero. The first component of z is not used in this value. No model, probability measure, relationship between the timeline lengths and Boolean-list lengths, stopping condition, or outcome-avoidance condition is required. When n is positive, the value is the fraction of the n Boolean lists that contain at least one true. When n is zero, the sum and denominator are both zero, and the real-number division convention makes the result zero.
timelineInformation
For any type V and any natural number n, timelineInformation defines a measurable space on pairs consisting of a function assigning a finite timeline over V to each natural-number index strictly below n and a function assigning a finite Boolean list to each such index. The timeline space consists of finite lists over V, with every subset measurable; its function space carries the finite product measurable space. A set of pairs is measurable for timelineInformation exactly when it is the inverse image, under the projection onto the timeline function, of a measurable subset of that timeline function space. Equivalently, such a measurable set specifies a measurable condition on the complete collection of timelines and contains every Boolean-list function paired with any timeline function that satisfies that condition. No condition involving the Boolean-list component can distinguish pairs with the same timelines. There is no model or probability measure in this declaration, and it adds no events merely because they have probability zero under a particular measure. When n is zero, the space of pairs has one element and the measurable sets are the empty set and the whole space. If V is empty, each timeline must be empty, so for any n the measurable sets are again only the empty set and the whole space, even though for positive n the Boolean-list component can vary.
Confirmed by the mission captain (proposal self-audit).