Prerequisites. Direct starred prerequisites: chapter 174. No later core chapter depends on this route.
Let 𝖻𝖺𝖽1 be the program 𝑏←𝖼𝗈𝗂𝗇(1/4);𝗋𝖾𝗍𝗎𝗋𝗇𝑏, where 𝗍𝗍 means failure, and let 𝖻𝖺𝖽2 run two independent copies and report whether either failed. Exact enumeration gives Pr[𝖻𝖺𝖽1]=14,Pr[𝖻𝖺𝖽2]=1−(34)2=716. Enumeration also gives the answer for three copies, and for four, and for a program whose two copies are drawn from a continuous distribution it gives nothing at all: the state space is uncountable, and the four cases become an integral.
What survives all these changes is an inequality and the way it was obtained: the probability of a disjunction is at most the sum of the probabilities, so Pr[𝖻𝖺𝖽2]≤Pr[𝖻𝖺𝖽1]+Pr[𝖻𝖺𝖽1]=1/2. That step used nothing about the value 1/4, nothing about the number of copies, and nothing about the type of the sampled value. A logic is what remains when such a step is separated from the program it was applied to: judgments that record a bound, rules that compose bounds, and a soundness theorem tying the rules to the measures of chapter 174.
The obstruction that organizes the chapter is that a denotational equality between whole programs, which is what the preceding chapters prove, does not compose with a bound. Knowing [[𝑒1]]=[[𝑒2]] says nothing about Pr[𝑒1fails], and knowing a bound for a subprogram says nothing about the whole unless there is a rule for the construct that joins them. The chapter builds those rules for a fixed language, proves them sound against the quasi-Borel semantics, and then applies them to three programs whose side conditions are displayed at the point of use.
Fix the call-by-value fragment HPProg with types 𝜏::=𝟏∣𝟐∣ℝ∣𝜏×𝜏∣𝜏⟶𝜏∣𝑀[𝜏], where 𝑀[𝜏] is the type of distributions over 𝜏; terms include variables, abstraction, application, pairing, projections, real constants, 𝖼𝗈𝗂𝗇(𝑝) for rational 𝑝∈[0,1], 𝗋𝖾𝗍𝗎𝗋𝗇𝑒, and 𝑥←𝑒1;𝑒2. A term of type 𝑀[𝜏] denotes an element of 𝑃[[𝜏]] in the sense of definition 174.12, and a term of a first-order type denotes a point.
Assertions 𝜑 are built from equalities and inequalities between enriched expressions, which extend the terms of definition 176.2 by two families: for 𝑑 of type 𝑀[𝜏] and a predicate 𝑝 over 𝜏, Pr𝑥∼𝑑[𝑝(𝑥)] of type ℝ, and for ℎ of type 𝜏⟶ℝ, 𝔼𝑥∼𝑑[ℎ(𝑥)] of type ℝ. Assertions are closed under ∧, ¬, and quantification over a type. Their meaning is the evident predicate on the denotation of the context, with Pr𝑥∼𝑑[𝑝(𝑥)]=∫1𝑝𝑑[[𝑑]],𝔼𝑥∼𝑑[ℎ(𝑥)]=∫[[ℎ]]𝑑[[𝑑]], both integrals in the sense of definition 174.12.
Γ∣Ψ⊢PL𝜑 asserts that 𝜑 holds in every environment satisfying the assumptions Ψ. Γ∣Ψ⊢UPL𝑒:𝜏∣𝜑 asserts the same for 𝜑 with a distinguished variable 𝑟 bound to the value of 𝑒. Γ∣Ψ⊢RPL𝑒1:𝜏1∼𝑒2:𝜏2∣𝜑 asserts it for 𝜑 with two distinguished variables 𝑟1,𝑟2 bound to the values of 𝑒1 and 𝑒2.
The unary and relational judgments are notation for the assertion judgment, not separate logics; the following equivalence is the precise form of that claim and is the reason a single soundness theorem suffices.
Proof. Each unary rule is, by construction, the assertion rule obtained by substituting the subject expression for 𝑟; the derivations are in bijection, and the substitution is meaningful because definition 176.3 allows enriched expressions inside assertions. The relational case substitutes both subjects. This is Sato et al.’s Theorem 6.1 and its relational counterpart Theorem 6.2, at their signatures. ◻
The rules below are stated for the fragment of definition 176.2; every premise is a judgment of definition 176.4 and every side condition is displayed. In Choice, 𝑒𝑝 abbreviates the biased branch (𝑏←𝖼𝗈𝗂𝗇(𝑝);𝗂𝖿𝑏𝗍𝗁𝖾𝗇𝑒1𝖾𝗅𝗌𝖾𝑒0).
Every rule of definition 176.6 is sound for the interpretation of definition 176.3: if the denotations of the premises hold in an environment satisfying Ψ, so does the denotation of the conclusion.
Proof of Theorem 176.7 — Soundness for the fragment
Proof. Fix an environment satisfying Ψ and write 𝜇=[[𝑒]] for the relevant subject.
Ret.[[𝗋𝖾𝗍𝗎𝗋𝗇𝑒]]=𝛿[[𝑒]] by definition 174.14, which is what the premise assumes about 𝑟.
Coin.Pr𝑥∼𝖼𝗈𝗂𝗇(𝑝)[𝑥]=∫1{𝗍𝗍}𝑑(𝑝𝛿𝗍𝗍+(1−𝑝)𝛿𝖿𝖿)=𝑝, by lemma 172.13.
Choice. The subject denotes 𝑝[[𝑒1]]+(1−𝑝)[[𝑒0]] by the bind clause and lemma 172.15; integrating 1𝑞 against a finite mixture is the corresponding combination of the integrals, by example 172.26. The premises bound the two integrals by 𝑎1 and 𝑎0, and the combination is monotone in each, so the conclusion follows.
Union. Pointwise 1𝑞1∨𝑞2≤1𝑞1+1𝑞2, so by monotonicity and additivity of the integral (lemma 172.13, convention 172.12) Pr[𝑞1∨𝑞2]≤Pr[𝑞1]+Pr[𝑞2]≤𝑎1+𝑎2. The two premises are about the same subject 𝑒, which is what makes the sum meaningful; nothing about independence is used or needed.
Bind. By lemma 172.19, Pr𝑦∼(𝑥←𝑒1;𝑒2)[𝑞(𝑦)]=∫Pr𝑦∼𝑒2[𝑞(𝑦)]𝑑[[𝑒1]](𝑥), and an integral of a function bounded by 𝑐 against a subprobability measure is at most 𝑐; here 𝑐 is the displayed supremum, which is finite because probabilities are bounded by 1. The second premise is what makes Pr𝑦∼𝑒2[𝑞(𝑦)] a function of 𝑥 satisfying the assumption 𝜑1[𝑥/𝑟] at [[𝑒1]]-almost every 𝑥.
Weaken. Immediate from the interpretation of implication as inclusion of predicates. ◻
Write 𝖻𝖺𝖽2=(𝑏1←𝖼𝗈𝗂𝗇(1/4);𝑏2←𝖼𝗈𝗂𝗇(1/4);𝗋𝖾𝗍𝗎𝗋𝗇(𝑏1∨𝑏2)). By Coin, Pr[𝑏𝑖]=1/4 for each copy; by Bind and Weaken each copy contributes Pr𝑥∼𝑟[𝑞𝑖(𝑥)]≤1/4, where 𝑞𝑖 is the predicate that the 𝑖-th draw is 𝗍𝗍; by Union, Pr𝑥∼𝑟[𝑞1∨𝑞2]≤1/2. The derived bound is 1/2 and the exact value, by enumeration, is 7/16. The gap is the price of a rule that never mentions independence: the same derivation applies verbatim when the two draws are dependent, and there 7/16 would be false.
The general soundness theorem is imported at exactly this signature. Formulas are interpreted as objects of Pred(QBS), the category of predicates on quasi-Borel spaces, obtained as the change of base of the predicate fibration along the forgetful functor QBS→Set; a well-formed formula Γ⊢𝜑 denotes a subset of [[Γ]], with conjunction as intersection, negation as complement, and universal quantification as an intersection over the interpretation of the bound type. Sato et al.’s Theorem 7.4: if Γ∣Ψ⊢PL𝜑 is derivable then ⋂𝜓∈Ψ[[Γ⊢𝜓]]⊆[[Γ⊢𝜑]], equivalently the identity on [[Γ]] is a morphism [[Γ⊢⋀𝜓∈Ψ𝜓]]→[[Γ⊢𝜑]] in Pred(QBS). Their Corollary 7.5 and Corollary 7.6 derive the unary and relational statements from it through the interderivability of proposition 176.5. Their proof of the axioms uses the isomorphism 𝑀𝟏≅[0,∞], the commutativity of the monad — proved here as proposition 174.17 — the agreement of the monadic integral with Lebesgue integration, and the fact that measurable maps between standard Borel spaces are exactly the quasi-Borel morphisms between them. Theorem 176.7 is the fragment instance proved locally; the import supplies the general case, including the higher-order rules not displayed in definition 176.6.
★★☆ In Bind, replace the supremum over 𝑥 by the value at one particular 𝑥 and exhibit a two-point example where the resulting rule is unsound. State which step of the proof of theorem 176.7 fails.
Let Γ⊢𝑒1:𝑀[𝜏1] and Γ⊢𝑒2:𝑀[𝜏2], and let Γ,𝑦:𝜏2⊢𝑒:𝑀[𝜎] with 𝑥 not free in 𝑒. Then [[𝑥←𝑒1;𝑦←𝑒2;𝑒]]=[[𝑦←𝑒2;𝑒]] whenever [[𝑒1]] is a probability measure, that is, of total mass 1.
Proof of Proposition 176.10 — Removing an unused draw
Proof. By proposition 174.17 the two binds may be exchanged, so the left-hand side equals [[𝑦←𝑒2;𝑥←𝑒1;𝑒]]. Since 𝑥 is not free in 𝑒, the inner bind is [[𝑒1]]≫=𝜆𝑥.[[𝑒]] with a constant integrand, whose value at a measurable set 𝐴 is [[𝑒]](𝐴)⋅[[𝑒1]](wholespace)=[[𝑒]](𝐴) by lemma 172.13 and the mass hypothesis. ◻
If 𝑒1 contains a score, its denotation has mass different from 1 and the conclusion is false by exactly that factor: with 𝑒1=𝗌𝖼𝗈𝗋𝖾(2), the left-hand side is twice the right-hand side. Slicing is therefore a statement about the sublanguage without scoring, or about programs whose sliced part is proved to have unit mass.
Let 𝜇 be a probability measure on 𝑋 and 𝑓:𝑋→[0,∞] measurable. Then 𝜇({𝑓≥𝑎})≤1𝑎∫𝑓𝑑𝜇 for every 𝑎>0. Consequently, if 𝑔:𝑋→ℝ has mean 𝑚=∫𝑔𝑑𝜇 and variance 𝜎2=∫(𝑔−𝑚)2𝑑𝜇<∞, then 𝜇({|𝑔−𝑚|≥𝜀})≤𝜎2/𝜀2 for every 𝜀>0.
Proof. Pointwise 𝑎⋅1{𝑓≥𝑎}≤𝑓, so integrating and using monotonicity and homogeneity (lemma 172.13, convention 172.12) gives 𝑎𝜇({𝑓≥𝑎})≤∫𝑓𝑑𝜇. For the second claim apply the first to 𝑓=(𝑔−𝑚)2 and 𝑎=𝜀2, noting {|𝑔−𝑚|≥𝜀}={(𝑔−𝑚)2≥𝜀2}. ◻
Let 𝑑 be a probability measure, let ℎ be measurable with 𝜇=𝔼𝑥∼𝑑[ℎ(𝑥)] and 𝜎2=Var𝑥∼𝑑[ℎ(𝑥)]<∞, and let mc𝑛 be the program that draws 𝑥1,…,𝑥𝑛 independently from 𝑑 and returns 1𝑛∑𝑖ℎ(𝑥𝑖). Then for every 𝜀>0, Pr𝑣∼mc𝑛[|𝑣−𝜇|≥𝜀]≤𝜎2𝑛𝜀2, so 𝑛≥𝜎2/(𝛿𝜀2) gives the bound 𝛿.
Proof of Proposition 176.13 — Monte Carlo sample size
Proof. The denotation of mc𝑛 is the pushforward of the 𝑛-fold product 𝑑⊗𝑛 along 𝜆⃗𝑥.1𝑛∑𝑖ℎ(𝑥𝑖), by lemma 172.22 and proposition 174.17, which permits the 𝑛 draws to be performed in any order. Its mean is 𝜇, by linearity of the integral and Tonelli, and its variance is 𝜎2/𝑛: expanding ∫(1𝑛∑𝑖(ℎ(𝑥𝑖)−𝜇))2𝑑𝑑⊗𝑛 by linearity gives 𝑛 diagonal terms 𝜎2/𝑛2 and 𝑛(𝑛−1) off-diagonal terms, each of which factors by Tonelli into 1𝑛2(∫(ℎ−𝜇)𝑑𝑑)2=0. Now apply lemma 176.12 with 𝑔 the identity on the pushed-forward measure. ◻
In the notation of definition 176.4, the proposition is the judgment (𝔼𝑥∼𝑑[1]=1),(𝜎2=Var𝑥∼𝑑[ℎ(𝑥)]),(𝜇=𝔼𝑥∼𝑑[ℎ(𝑥)]),(𝜀>0)⊢UPLmc𝑛:𝑀[ℝ]∣Pr𝑣∼𝑟[|𝑣−𝜇|≥𝜀]≤𝜎2𝑛𝜀2. The four assumptions are exactly the hypotheses used in the proof: total mass one, finite variance, the value of the mean, and positivity of 𝜀. Dropping the finiteness of 𝜎2 makes the right-hand side meaningless; dropping the mass condition makes the mean computation false.
The third reconstructed application is Sato et al.’s analysis of Gaussian mean learning, imported at its signature. Let the prior on the unknown mean be normal with mean 𝑚0 and variance 𝑣0, let each observation be normal about the unknown mean with known variance 𝑣, and let learn𝑛 be the program returning the posterior after 𝑛 observations. Their development derives, in UPL, that the posterior mean after 𝑛 observations is the stated weighted average of 𝑚0 and the empirical mean, that the posterior variance is (1/𝑣0+𝑛/𝑣)−1, and hence that the posterior variance converges to 0 at rate 𝑣/𝑛; the stability statement bounds the change in the posterior under a perturbation of one observation by a quantity proportional to 𝑣0/(𝑣0𝑛+𝑣). The hypotheses are that all variances are strictly positive, that the observations are conditionally independent given the mean, and that the prior is proper. Nothing in this chapter proves these; the Lipschitz analysis of generalized value iteration that the source also presents is comparison material and owns no statement here.
Two Isabelle developments accompany this material and their coverage is not the same as the paper’s. The Quasi-Borel Spaces entry of the Archive of Formal Proofs mechanizes quasi-Borel spaces, their products, coproducts and exponentials, and the probability monad with its laws — the content of convention 174.19 — and it does not by itself formalize conditioning. The S-Finite Measure Monad entry adds s-finite kernels and a monad supporting scoring, a richer measure interface, and still does not by itself prove every rule of definition 176.6 or the general soundness statement of convention 176.9. When a rule of the logic is said to be checked, the claim is about a named lemma of one of these entries; no claim of machine-checked status is made for the applications of section 176.3. Lilac, a separate logic for independence and conditional probability, is a comparison card: none of its rules or metatheorems is attributed to the logic of this chapter.
★★☆ Exhibit a distribution and an 𝜀 for which the Chebyshev bound of lemma 176.12 is attained with equality, and one for which it overestimates by a factor of 100.
★★☆ Carry out in full the variance computation in the proof of proposition 176.13 for 𝑛=2, displaying the diagonal and off-diagonal terms and the use of Tonelli.
★★☆ Write out the Bind case of theorem 176.7 for the special case where 𝑒1 is 𝖼𝗈𝗂𝗇(𝑝), replacing the integral by a two-term sum, and identify the exact inequality that the supremum supplies.
★★☆ Generalize example 176.8 to 𝑘 independent copies: derive the bound 𝑘/4 by Union, compute the exact probability 1−(3/4)𝑘, and determine the least 𝑘 for which the derived bound exceeds 1 while the exact probability does not.
★★★Practical project.finite-bound-certificate-checker Build a certificate checker for the finite fragment. A certificate is one of ret, bind(𝑐1,𝑐2), choice(𝑝,𝑐0,𝑐1), weaken(𝑞,𝑞′,𝑐), and union(𝑐1,𝑐2), where every probability is a reduced rational; the checker computes the claimed bound bottom-up according to definition 176.6 and compares it with the requested bound using integer arithmetic only. A second component enumerates the program exactly and reports its true probability.
The invariant to maintain is that no floating-point number appears anywhere and that a certificate is accepted only when every side condition of the corresponding rule is checked, including the requirement in Union that both premises concern the same subject program.
The concrete result is the pair of verdicts and the exact probability for the two programs of the chapter opening. The acceptance test is decidable and exact: the checker must accept Pr[𝖻𝖺𝖽1]≤1/4 by choice; accept Pr[𝖻𝖺𝖽2]≤1/2 by union; reject the same 𝖻𝖺𝖽2 certificate at the bound 1/4, reporting the derived bound 1/2 and the requested bound 1/4; and the enumerator must report Pr[𝖻𝖺𝖽2]=7/16 exactly. Successful checking is the oracle. The certificate language is a finite executable shadow of the logic of definition 176.6; its general soundness is theorem 176.7, which the checker does not prove.