Lectures onType Theory
Chapter 174
Chapter 174Core route

Continuous Probabilistic Languages and Quasi-Borel Semantics

A probabilistic program may sample a real number, and it may pass a function around. Combining the two is immediate in syntax: prior=snormal(0,3);bnormal(0,3);return (λx.sx+b), a program of type Dist(RR) that draws a random line. To interpret it in the vocabulary of chapter 172, the type RR must denote a measurable space in which the sampled line is a measurable function of the two draws, and applying the sampled line to an argument must again be measurable. Both requirements are about one map, evaluation.

They cannot both be met. Theorem 174.3 shows that the first σ-algebra a reader would try — the one generated by point evaluations — makes evaluation nonmeasurable, and Aumann’s theorem, recorded after it, shows that no σ-algebra succeeds. The obstruction is not a missing construction but a property of σ-algebras: membership in a product σ-algebra is decided by countably many generators, while evaluation consults uncountably many points.

The repair keeps the maps and discards the σ-algebras. A space will be a set together with a declared collection of random elements — maps from the real line into the set — closed under the operations that random variables must be closed under. Function spaces then exist, because a random element of a function space is exactly a jointly random family, and the monad of measures built on top of this notion inherits its laws from the kernels of convention 172.27. The chapter ends by adding recursion, where a measure on a space of computations must also be a limit of finite unfoldings, and states the contextual-soundness theorem that the resulting model satisfies.

Convention 174.1 — Imported interface

This chapter uses the frozen export PMK of convention 172.27, and specifically the groups PMK-map and PMK-bind: measurable spaces and maps, subprobability and probability measures, Dirac measures, pushforward and its functoriality, the change-of-variables formula theorem 172.14, products and Tonelli, kernels with ret and bind, lemma 172.19, and the monad laws theorem 172.20. It does not use the conditioning results of chapter 173, and adds only the structure that the developments below force.

The exponential obstruction

Lemma 174.2 — Countable dependence

Let GP(Z). Every Aσ(G) lies in σ(G0) for some countable G0G. Consequently, for measurable spaces F and Y, every AΣFΣY lies in σ({C×BCC, BΣY}) for some countable CΣF.

Proof of Lemma 174.2 — Countable dependence

Proof. Let H={σ(G0)G0G countable}. Then GH, and H is a σ-algebra: it contains Z; it is closed under complement, since σ(G0) is; and if Anσ(G0,n) for each n, then nAnσ(nG0,n), a countable union of countable families. Hence σ(G)H. The second claim is the first applied to the generating family of rectangles, followed by collecting the countably many first components that occur. ◻

Theorem 174.3 — The evaluation σ -algebra fails

Let F=Meas(R,R) be the set of Borel measurable functions and let Σev=σ({{ff(r)B}rR, B Borel}) be the σ-algebra generated by the point evaluations. Then ev:F×RR, ev(f,r)=f(r), is not measurable with respect to ΣevB(R).

Proof of Theorem 174.3 — The evaluation σ -algebra fails

Proof. Suppose it were. Then E=ev1((0,))={(f,r)f(r)>0} lies in ΣevB(R), so by lemma 174.2 there is a countable CΣev with Eσ({C×BCC, BB(R)}). Applying lemma 174.2 once more to each CC, which lies in the σ-algebra generated by point evaluations, produces a countable set R0R such that every CC lies in σ({{ff(r)B}rR0, B Borel}).

Two functions agreeing on R0 therefore lie in exactly the same members of C, hence in the same members of the generated σ-algebra; so for such f,g and every r, (f,r)E if and only if (g,r)E. Now let r1R0, which exists because R0 is countable, and take f=0 and g=1{r1}. Both are Borel measurable and agree on R0, yet (f,r1)E while (g,r1)E. ◻

Remark 174.4 — The general theorem

Theorem 174.3 refutes the first candidate. Aumann’s theorem, recorded by Heunen–Kammar–Staton–Yang as their Proposition 6, is the general statement: for no σ-algebra Σ on Meas(R,R) is ev:(Meas(R,R)×R,ΣB(R))(R,B(R)) measurable, so the category of measurable spaces is not cartesian closed. It is imported here at exactly that signature; the local theorem above supplies the mechanism, and the import supplies the universal quantifier over Σ.

Example 174.5 — What the obstruction costs the program

In prior the sampled object is the function α(s,b)=λx.sx+b, and the program’s use of it is ev(α(s,b),x)=sx+b, a jointly measurable function of (s,b,x). Nothing is wrong with the program; what fails is the demand that the intermediate set {λx.sx+bs,bR} carry a σ-algebra through which that joint measurability factors. The repair below keeps the joint measurability as the primitive datum and never asks for the intermediate σ-algebra.

Quasi-Borel spaces

Definition 174.6 — Quasi-Borel space

A quasi-Borel space is a set X together with a set MX[RX] of random elements such that

  1. αfMX whenever αMX and f:RR is measurable;

  2. every constant function RX is in MX;

  3. if R=iNSi with each Si Borel and αiMX for each i, then βMX, where β(r)=αi(r) for rSi.

A morphism (X,MX)(Y,MY) is a function g:XY with gαMY for every αMX. Write QBS(X,Y) for the set of morphisms.

The three clauses are the closure properties that random variables have: a random element may be reparameterized by a measurable change of the sample point, a constant is a random element, and a countable measurable case distinction between random elements is a random element. Since MR contains exactly the measurable functions in the example below, clause (i) says that MX is closed under precomposition and clause (iii) is what makes coproducts work.

Example 174.7 — Two ways to see a measurable space

For a measurable space (X,ΣX) put MXΣ={α:RXα measurable}. The three clauses hold: composition of measurable maps is measurable, constants are measurable, and a countable measurable gluing of measurable maps is measurable because β1(A)=i(Siαi1(A)). In the other direction, a quasi-Borel space (X,MX) determines the σ-algebra ΣMX={UXαMX. α1(U)B(R)}, which is a σ-algebra because preimage commutes with complement and countable union. Every morphism (X,MX)(Y,MY) is measurable (X,ΣMX)(Y,ΣMY): for UΣMY and αMX, α1(g1U)=(gα)1(U) is Borel because gαMY. The converse fails in general, and section 174.3 needs the difference.

Proposition 174.8 — Products

Let (Xi,MXi)iI be quasi-Borel spaces indexed by a set I. Then (iXi,MiXi) with MiXi={f:RiXii. πifMXi} is a quasi-Borel space, the projections are morphisms, and it is the product in QBS.

Proof of Proposition 174.8 — Products

Proof. Each clause of definition 174.6 is checked coordinatewise: for (i), πi(fg)=(πif)gMXi; for (ii), a constant into the product is coordinatewise constant; for (iii), the glued function has πiβ equal to the gluing of πiαj, which lies in MXi. The projections are morphisms by the definition of MiXi. For the universal property, given morphisms gi:ZXi, the pairing gii satisfies πigiiγ=giγMXi for γMZ, so it is a morphism, and it is the unique such function. ◻

Proposition 174.9 — Countable coproducts

Let (Xi,MXi)iI be quasi-Borel spaces with I countable and discrete. Then (iXi,MiXi) with MiXi={λr.(f(r),αf(r)(r)) | f:RI measurable,(αiMXi)iimage(f)} is a quasi-Borel space and is the coproduct in QBS.

Proof of Proposition 174.9 — Countable coproducts

Proof. Clause (i): precomposing with a measurable g replaces f by fg and αi by αig. Clause (ii): a constant is obtained with constant f. Clause (iii): given a Borel partition R=jSj and elements βj of the displayed form with data (fj,αij), define f by f(r)=fj(r) for rSj, measurable since I is countable and discrete, and define αi by gluing the αij over the partition, which lies in MXi by clause (iii) for Xi. For the universal property, let gi:XiZ be morphisms and let γ=λr.(f(r),αf(r)(r)) be a random element of the coproduct. Then [gi]iγ is the gluing over the Borel partition R=if1({i}) of the maps giαiMZ, hence lies in MZ by clause (iii) for Z. This is the step for which clause (iii) exists. ◻

Proposition 174.10 — Function spaces

Let (X,MX) and (Y,MY) be quasi-Borel spaces. Then YX=QBS(X,Y) with MYX={α:RYXuncurry(α)QBS(R×X,Y)} is a quasi-Borel space, evaluation ev:YX×XY is a morphism, and QBS is cartesian closed.

Proof of Proposition 174.10 — Function spaces

Proof. Here R carries MRΣ, the measurable functions RR, and R×X the product structure of proposition 174.8.

Clause (i). If uncurry(α) is a morphism and g:RR is measurable, then uncurry(αg)=uncurry(α)(g×id), a composite of morphisms.

Clause (ii). For a constant α=λr.h with h a morphism, the uncurried map sends (r,x) to h(x), so it sends a random element of R×X with second component χ to hχ, which lies in MY.

Clause (iii). Let R=iSi be Borel and αiMYX, and let β glue them. Let ρ,χMR×X. Then uncurry(β)ρ,χ= the gluing over the Borel partition (ρ1(Si))iof uncurry(αi)ρ,χ, each of which lies in MY; the partition is Borel because ρ is measurable, so clause (iii) for Y gives uncurry(β)ρ,χMY. This is where the countable gluing of proposition 174.9 is used in disguise.

Evaluation and the universal property. Let α,χMYX×X. Then evα,χ=uncurry(α)id,χMY, so ev is a morphism. For h:Z×XY a morphism, its curry Λh:ZYX satisfies, for γMZ, uncurry(Λhγ)=h(γ×id), a morphism; so Λh is a morphism, and it is the unique function with ev(Λh×id)=h. ◻

Example 174.11 — The random line, at last

In QBS the map α:R×RRR of example 174.5, sending (s,b) to λx.sx+b, is a morphism: its uncurrying (s,b,x)sx+b is jointly measurable, hence a morphism R×R×RR, and proposition 174.10 converts that into a morphism into the function space. No σ-algebra on RR was chosen; the joint measurability that the program already had is precisely the datum that MRR records.

Exercise 174.1

★☆☆ For a set X, verify that MXR=[RX] and the set MXL of functions constant on the parts of a countable Borel partition pulled back along a measurable map both satisfy definition 174.6, and show that the identity is a morphism (X,MXL)(X,MXR) but not conversely for X=R.

Exercise 174.2

★★☆ Give quasi-Borel spaces X,Y and a function XY that is measurable for ΣMX,ΣMY but is not a morphism, so that the passage of example 174.7 loses information.

Exercise 174.3

★★☆ Delete clause (iii) from definition 174.6 and show that the copairing in proposition 174.9 then need not be a morphism, by exhibiting two morphisms out of the summands whose copairing fails.

The probability monad on quasi-Borel spaces

A measure on a quasi-Borel space cannot be defined as a set function, because the space has no primitive σ-algebra. It is instead defined the way a probabilist produces measures in practice: push a measure on the sample line forward along a random element. Two such presentations describe the same measure exactly when the pushforwards agree.

Definition 174.12 — Measures on a quasi-Borel space

A probability measure on (X,MX) is a pair (α,μ) with αMX and μ a probability measure on R. Two pairs are equivalent, (α,μ)(β,ν), when αμ=βν as measures on (X,ΣMX). Write [α,μ] for the equivalence class and P(X)={(α,μ)}/,MP(X)={β:RP(X)αMX, g a kernel,r. β(r)=[α,g(r)]}, where a kernel means one from R to R in the sense of definition 172.16. For a morphism h:XY, integration of h against [α,μ] is hd[α,μ]=(hα)dμ, well defined by theorem 172.14 and independent of the representative.

Proof of Lemma 174.13 — P(X) is a quasi-Borel space

Proof. Clause (i): if β(r)=[α,g(r)] and f is measurable, then β(f(r))=[α,(gf)(r)] and gf is a kernel by proposition 172.18 applied to ret composed with f, or directly because rg(f(r))(A) is a composite of measurable maps. Clause (ii): a constant [α,μ] is obtained with the constant kernel g(r)=μ. Clause (iii): let R=iSi be Borel with βi(r)=[αi,gi(r)]. Choose a Borel partition R=iTi into uncountable Borel pieces together with Borel isomorphisms φi:RTi, and let ψi:RR be a measurable map restricting to φi1 on Ti. Each αiψi lies in MX by clause (i), so their gluing α along (Ti)i lies in MX by clause (iii) for X, and αφi=αi. Setting g(r)=(φi)gi(r) for rSi defines a kernel, and αg(r)=α(φi)gi(r)=lemma172.11(αφi)gi(r)=(αi)gi(r), so [α,g(r)]=[αi,gi(r)]=βi(r) for rSi. ◻

Definition 174.14 — Unit and bind

For xX put η(x)=[λr.x,μ] for an arbitrary probability measure μ on R; the class does not depend on μ, since (λr.x)μ=δx for every μ. For a morphism f:XP(Y) and [α,μ]P(X), choose by definition 174.12 a βMY and a kernel g:RR with (fα)(r)=[β,g(r)] for all r, and set [α,μ]=f=[β, μ=g], the inner bind being that of definition 172.16.

Lemma 174.15 — Bind is well defined

The class [β,μ=g] depends neither on the representative (α,μ) nor on the choice of (β,g), and it satisfies lY([α,μ]=f)=lX([α,μ])=(xlY(f(x))),lX([α,μ])=αμ, an equation between measures on (Y,ΣMY).

Proof of Lemma 174.15 — Bind is well defined

Proof. Compute the underlying measure of the right-hand side. For UΣMY, (αμ=(xlY(f(x))))(U)=definition172.16lY(f(x))(U)d(αμ)(x)=theorem172.14lY(f(α(r)))(U)dμ(r)=choiceof(β,g)βg(r)(U)dμ(r)=definition172.10g(r)(β1U)dμ(r)=definition172.16(μ=g)(β1U)=β(μ=g)(U). So the underlying measure of [β,μ=g] equals the displayed right-hand side, which mentions neither (β,g) nor the representative α except through αμ. Since the equivalence of definition 174.12 is exactly equality of underlying measures, the class is determined. ◻

Theorem 174.16 — The probability monad

(P,η,=) is a monad on QBS: for xX, pP(X), and morphisms f:XP(Y), h:YP(Z), η(x)=f=f(x),p=η=p,(p=f)=h=p=(xf(x)=h). Its functorial action is P(g)[α,μ]=[gα,μ], and it is strong.

Proof of Theorem 174.16 — The probability monad

Proof. By lemma 174.15 the underlying measure of each side may be computed, and two elements of P(X) with the same underlying measure are equal by definition 174.12. Transporting the three equations through l turns them into the three equations of theorem 172.20 for the kernels xlY(f(x)) and ylZ(h(y)), with lX(η(x))=δx. For the functorial action, lY(P(g)[α,μ])=(gα)μ=g(αμ) by lemma 172.11, which is the pushforward of the underlying measure, and this coincides with [α,μ]=(ηg) by lemma 172.22. Strength is the statement that = is itself a morphism P(Y)XP(Y)P(X); by proposition 174.10 this amounts to the joint claim that (α,f)[α,μ]=f sends random elements to random elements, which the construction of (β,g) in definition 174.14 produces uniformly in a random element of the function space. ◻

Proposition 174.17 — Commutativity

Let pP(X), qP(Y), and let f:X×YP(Z) be a morphism. Then p=λx.q=λy.f(x,y)=q=λy.p=λx.f(x,y).

Proof of Proposition 174.17 — Commutativity

Proof. Write p=[α,μ], q=[γ,ν], and apply lZ to both sides. By lemma 174.15 and theorem 172.14, the left-hand side becomes lZ(f(α(r),γ(s)))(U)dν(s)dμ(r), and the right-hand side is the same double integral in the opposite order. The integrand is nonnegative and jointly measurable, because f is a morphism and the pair of projections composed with α and γ is a random element of X×Y. Both μ and ν are probability measures, hence σ-finite, so Tonelli’s theorem exchanges the two integrations by convention 172.12. ◻

Example 174.18 — Two draws and a line

The program prior denotes [α,νν]P(RR), where ν is the normal measure with mean 0 and standard deviation 3 on R and α(s,b)=λx.sx+b, which is a morphism by example 174.11; the pair (R2,νν) is transported to the sample line by any Borel isomorphism RR2, and the class [α,νν] does not depend on which one, because two choices differ by a measurable reparameterization and pushforward composes. Evaluating the sampled line at x0 is the morphism ev(,x0), and P(ev(,x0))[α,νν]=[λ(s,b).sx0+b,νν], the normal measure with mean 0 and variance 9(x02+1). The obstruction of section 174.1 has been removed without approximating anything.

Convention 174.19 — The Heunen–Kammar–Staton–Yang structural card

Proposition 174.8, Proposition 174.9, Proposition 174.10, theorem 174.16 and proposition 174.17 are the reconstructions of Heunen–Kammar–Staton–Yang’s Propositions 16, 17 and 18, their Theorem 21 and their Proposition 22, at their signatures: products over an arbitrary index set, coproducts over a countable discrete index set, exponentials of arbitrary quasi-Borel spaces, a strong monad P, and its functorial action and commutativity. Their statement of Proposition 22 also records that P restricted along the embedding of standard Borel spaces agrees with the Giry monad; that agreement is the equation of lemma 174.15. This card is about QBS only. It does not include recursion, and nothing on it is transported to the ω-quasi-Borel card below without the proved restriction stated there.

Adding recursion: the ω-quasi-Borel card

A language with a fixed-point operator interprets a recursive definition as the supremum of its finite unfoldings, so both the spaces and the measures must carry an order in which those suprema exist. The following card is frozen; the chapter proves nothing about it beyond restating what is imported.

Convention 174.20 — The Vákár–Kammar–Staton system card

An ω-quasi-Borel space is a quasi-Borel space equipped with an ω-cpo structure whose random elements are compatible with the order, and ωQbs is the resulting category; J is the monad of measures on it and T, the statistical powerdomain, is the submonad generated by the two operations sample:1TR, the uniform measure on [0,1], and score:RT1, which multiplies the current weight by |r|. The language SFPC is call-by-value with sums, products, function types, recursive types μα.σ, term-level recursion, real arithmetic, sample and score; its operational semantics is a big-step relation whose induced map :TrmτTValτ is an s-finite kernel, and ts denotes contextual approximation: for every context C[] of type R, the weight of C[t] is at most that of C[s]; ts is approximation in both directions.

Convention 174.21 — Imported ω -quasi-Borel theorems

The following are imported at exactly these signatures and are the only statements about convention 174.20 used in this book.

Their Theorem 4.3: the unit and bind of J restrict to T, and the factorisation of the expectation operator RXTXJX into a densely strong epi followed by a full mono preserves the monad structures.

Their Theorem 4.6: T equips ωQbs with a measure-category structure — a cartesian closed category with countable limits and coproducts together with a commutative monad whose canonical maps T01 and TiXijTXj are invertible — with the countable semiring of scalars given by the weights T1.

Their Lemma 6.6, computational soundness: for every closed t:τ, [[t]][[t]]vT.

Their Lemma 6.8, the fundamental lemma of their logical relation: for every wValΓτ and sTrmΓτ, [[w]]vEΓτvw and [[s]]EΓτcs, whence [[t]][[t]]vT for closed t.

Their Theorem 6.9: for all SFPC types τ and closed t,sTrmτ, [[t]][[s]] implies ts; in particular [[t]]=[[s]] implies ts.

Remark 174.22 — The direction that is proved, and the one that is not

Convention 174.21 gives one implication: equal denotations imply contextual equivalence. The converse — contextually equivalent terms have equal denotations — is not stated there and is not claimed here. In particular the equational full-abstraction theorem of chapter 171 is a theorem about discrete pPCF and its probabilistic coherence spaces; it is not transported to SFPC, whose calculus has continuous sampling, scoring, recursive types, and a different notion of observation. A transport would require a proved translation between the two calculi carrying one notion of observation to the other, and no such translation is constructed in this book.

Example 174.23 — A weighted program, calculated twice

Consider the recursion-free program sensor=xuniform(0,1);score(if x<12 then 2 else 1);return (x<12). Operationally, the run whose first sampled real is 1/4 performs sample 1/4, score 2, return tt, and carries weight 2. Denotationally, the unnormalized measure on {tt,ff} is 01(21[0,1/2)(x)δtt+11[1/2,1](x)δff)dx=212δtt+112δff=δtt+12δff, of total weight 3/2; normalizing gives {tt2/3, ff1/3}. Replacing the uniform draw by coin(1/2) and the test x<1/2 by the drawn Boolean produces exactly the same three numbers by a finite rational computation, which is what the practical project checks.

Remark 174.24 — A synthetic reading, only now

Proposition 174.17 and the invertibility statements of convention 174.21 are the axioms of a measure category in Kock’s sense: a commutative monad on a cartesian closed category with countable coproducts whose measures on a countable coproduct decompose into tuples. Stating them as axioms is useful only after they have been verified, since each axiom is a calculation that has been performed above — commutativity is Tonelli’s theorem, the decomposition over a coproduct is countable additivity — and a reader who adopts the axioms first has no way to know which calculations they encode. What the synthetic vocabulary buys is that a later development may quote the axioms rather than the calculations, provided it quotes them for exactly the structure verified here.

Exercise 174.4

★☆☆ Prove directly from definition 174.12 that [λr.x,μ] does not depend on μ, and compute lX(η(x)).

Exercise 174.5

★★☆ Let X=Y=R, α=id, μ the uniform measure on [0,1], and f(x)=η(2x). Exhibit a pair (β,g) as required by definition 174.14, compute [α,μ]=f, and verify the equation of lemma 174.15 for the Borel set [0,1].

Exercise 174.6

★★☆ Give a monad on a cartesian closed category, other than P, for which the equation of proposition 174.17 fails, and identify which hypothesis of the proof it violates.

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 174.7, then exercise 174.8, then the practical project exercise 174.11.

Exercise 174.7

★★☆ Reconstruct theorem 174.3 with (0,) replaced by an arbitrary Borel set B with 0B and 1B, and state the two properties of the pair f=0, g=1{r1} that the argument uses.

Exercise 174.8

★★☆ Write out the proof of clause (iii) in proposition 174.10 for the special case X=Y=R and a partition into two Borel pieces, displaying the random element of R×X that is used.

Exercise 174.9

★★☆ Prove the right unit law of theorem 174.16 without transporting through l: work with representatives, choose (β,g) explicitly for f=η, and identify the resulting class.

Exercise 174.10

★★☆ State precisely which parts of convention 174.19 are claimed for the ω-quasi-Borel setting of convention 174.20, and give an example of a statement about P that is not claimed for T.

Exercise 174.11

★★★ Practical project.qbs-weighted-interpreter Build a two-back-end interpreter for the recursion-free weighted fragment with terms coin(p), score(w) for a positive rational weight, return, if, and bind. The first back end is an exact enumerator producing an unnormalized rational table together with the total weight; the second is a stream-driven tracer that consumes an explicit list of drawn values and prints one line per event: sample v, score w, return v, and a final weight w.

The invariant to maintain is that the tracer’s final weight equals the product of the scores encountered on the traced run, and that the enumerator’s total weight equals the sum over runs of that product; both are computed in exact rational arithmetic.

The concrete result is the pair of outputs for the finite analogue of example 174.23, namely bcoin(1/2); score(if b then 2 else 1); return b, and for the traced run of example 174.23 itself with the drawn real 1/4 supplied explicitly.

The acceptance test is decidable and exact: the enumerator must print the unnormalized table {tt1, ff1/2}, the normalizer 3/2, and the posterior {tt2/3, ff1/3}; the tracer on the supplied value 1/4 must print exactly sample 1/4; score 2; return tt; weight 2; and the checker must confirm that the enumerator’s total weight equals the sum of the two traced weights 212 and 112. Sampling frequencies may be displayed but are not an accepted answer, and this finite agreement illustrates convention 174.21 without proving any part of it.

Search the book

Type to search the local edition.