Lectures onType Theory
Chapter 172
Chapter 172Core route

Probability, Measure, Kernels, and Computable Sampling

Run the program xor2=b1coin;b2coin;return(b1b2) in two different ways. Enumerate: there are four equiprobable assignments to (b1,b2), of which two make b1b2 true, so the program denotes the table {ff1/2, tt1/2}. Execute: feed the program a stream of fair bits, let the first coin consume the first bit and the second coin the second; on the stream beginning 0,1 the run performs draw 0, draw 1, return tt. The two answers agree, and for this program the agreement can be checked by inspecting four cases.

Now replace coin by a draw from the uniform distribution on [0,1]. The enumeration has no finite table to produce, and the two descriptions come apart: on one side a measure on an uncountable space, on the other a program that turns a bit stream into a real number. Neither side is automatically the other. A measure is a set function with no computational content; a sampler is a partial function on bit streams whose output distribution must be proved to be the intended measure.

This chapter builds the measure-theoretic vocabulary that the rest of the volume uses — measurable spaces, measures, integration, products, and kernels, each law calculated on finite distributions before it is proved at the general signature — and then proves the exact correspondence between the two descriptions for the class of spaces where both make sense. The organizing object is the kernel: it is what a probabilistic program of one argument denotes, its bind operation is what sequencing denotes, and every law exported by this chapter is a law of kernels or of the integrals that define them. Conditioning is not in this chapter. Conditioning asks for a family of measures indexed by an observed value, determined only up to a null set of those values, and neither its construction nor its computability is settled by anything proved here.

Finite distributions, exactly

Definition 172.1 — Finite distribution

Let A be a set. A finite subdistribution on A is a function m:AQ[0,1] with finite support supp(m)={am(a)>0} and |m|=am(a)1; it is a distribution when |m|=1. Write δa for the distribution with δa(a)=1, and for a family (ma)aA of subdistributions on B write (m=k)(b)=asupp(m)m(a)k(a)(b).

The fragment used throughout this section has terms t::=coinreturnvxt;t, where v ranges over Boolean expressions in the bound variables. Its exact denotation is the finite subdistribution E(t) defined by E(coin)={ff12,tt12},E(returnv)=δv,E(xt1;t2)=E(t1)=(aE(t2[a/x])).

Example 172.2 — The enumerated table

For xor2, E(xor2)=bindb112(b212δb1b2)=14(δff+δtt+δtt+δff)={ff12, tt12}. Every step is an exact rational computation; no approximation and no sampling occurs.

Definition 172.3 — Bit-stream sampler for the fragment

Let u2ω. Define S(t)(u), a pair of a value and the unconsumed suffix of u, by S(coin)(bu)=(b,u),S(returnv)(u)=(v,u),S(xt1;t2)(u)=S(t2[a/x])(u) where (a,u)=S(t1)(u). The trace of a run is the sequence of events draw b, one per consumed bit, followed by return v.

Example 172.4 — The executed trace

On the stream beginning 0,1 the run of xor2 is draw 0; draw 1; return tt, because S(coin)(01u)=(0,1u), then S(coin)(1u)=(1,u), and 01=tt. On the stream beginning 1,1 the trace is draw 1; draw 1; return ff.

Proposition 172.5 — The two executions agree on the fragment

For every term t of the fragment there is nN such that S(t)(u) depends only on the first n bits of u, and for every value v, E(t)(v)=#{w2nS(t)(wu) returns v}2n, the right-hand side being independent of the suffix u.

Proof of Proposition 172.5 — The two executions agree on the fragment

Proof. Induction on t. For coin, take n=1; the two words 0 and 1 return ff and tt, giving 1/2 each. For returnv, take n=0. For xt1;t2, let n1 work for t1 and, for each value a in the finite range of t1, let n2(a) work for t2[a/x]; take n=n1+maxan2(a). Splitting a word w2n as w1w2 with |w1|=n1, the run of the bind on w first runs t1 on w1, producing some a, and then runs t2[a/x] on w2. Counting words by this decomposition, #{wbind returns v}2n=a#{w1t1 returns a}2n1#{w2t2[a/x] returns v}2nn1=IH(E(t1)=E(t2[/x]))(v). The decomposition is legitimate because the run of t2[a/x] begins at the suffix left by t1, which is exactly w2u, and because E(t1) is a distribution supported on the finitely many values a. ◻

Proposition 172.5 is the whole sampler/measure correspondence in the one case where counting works. It fails to be a definition of anything beyond the fragment for two reasons: the count 2n presupposes that a fixed finite number of bits suffices, and the sum over values presupposes countably many outcomes. A draw from the uniform distribution on [0,1] violates both. The rest of the chapter replaces counting by measure and integration, and only then returns to samplers.

Exercise 172.1

★☆☆ Compute E(t) as an exact rational table for t=(bcoin;if b then coin else returnff), and give the trace of S(t) on the stream beginning 1,0.

Exercise 172.2

★★☆ Give a term of a fragment extended by while whose sampler consumes an unbounded number of bits with positive probability, and explain which step of the proof of proposition 172.5 fails for it.

Measurable spaces and measures

Definition 172.6 — Measurable space and measurable map

A σ-algebra on a set X is a family ΣXP(X) containing X and closed under complement and countable union. A measurable space is a pair (X,ΣX), written X when the σ-algebra is clear. A map g:XY is measurable when g1(B)ΣX for every BΣY.

Lemma 172.7 — Identity and composition

The identity idX is measurable, and if g:XY and h:YZ are measurable then so is hg.

Proof of Lemma 172.7 — Identity and composition

Proof. idX1(A)=A. For the composite, (hg)1(C)=g1(h1(C)), and h1(C)ΣY by measurability of h, so its g-preimage lies in ΣX. ◻

Lemma 172.8 — Measurability from a generating family

Let GP(Y) and let σ(G) be the least σ-algebra containing G, which exists because the intersection of any family of σ-algebras is one. If g1(B)ΣX for every BG, then g is measurable with respect to σ(G).

Proof of Lemma 172.8 — Measurability from a generating family

Proof. The family {BYg1(B)ΣX} contains G and is a σ-algebra, because preimage commutes with complement and countable union. Hence it contains σ(G). ◻

Three examples are used throughout. A countable set A carries the discrete σ-algebra P(A), and every map out of it is measurable. The real line carries the Borel σ-algebra generated by the open intervals. Given X and Y, the product X×Y carries ΣXΣY=σ({A×BAΣX,BΣY}); the two projections are measurable, and by lemma 172.8 a map g,h into a product is measurable as soon as g and h are.

Definition 172.9 — Measure, subprobability, Dirac

A measure on X is a function μ:ΣX[0,] with μ()=0 that is countably additive: μ(nAn)=nμ(An) for pairwise disjoint An. It is a subprobability measure when μ(X)1 and a probability measure when μ(X)=1. For xX the Dirac measure is δx(A)=1A(x), which is a probability measure.

Definition 172.10 — Pushforward

For measurable g:XY and a measure μ on X, define gμ(B)=μ(g1(B)).

Lemma 172.11 — Pushforward is functorial

gμ is a measure, of the same total mass as μ; (idX)μ=μ; and (hg)μ=h(gμ).

Proof of Lemma 172.11 — Pushforward is functorial

Proof. g1 preserves , disjointness, and countable unions, so countable additivity transfers; gμ(Y)=μ(g1Y)=μ(X). The two equations are id1(A)=A and (hg)1(C)=g1(h1(C)). ◻

Convention 172.12 — The imported integration toolkit

For a measurable f:X[0,] and a measure μ, the integral is fdμ=sup{i=1kciμ(Ai) | kN, ci[0,),AiΣX disjoint, ici1Aif}. The following four facts about this integral are imported from Tao, An Introduction to Measure Theory, at the stated signatures, and are used with no further appeal to the construction of the integral: additivity (f+g)dμ=fdμ+gdμ and homogeneity afdμ=afdμ for measurable f,g:X[0,] and a[0,) (Tao, §1.4); the monotone convergence theorem, that limnfndμ=limnfndμ for a pointwise nondecreasing sequence of measurable fn:X[0,] (Tao, Theorem 1.4.44); the existence and uniqueness of the product measure μν on ΣXΣY with (μν)(A×B)=μ(A)ν(B) for σ-finite μ,ν (Tao, §1.7); and Tonelli’s theorem, that for σ-finite μ,ν and measurable f:X×Y[0,] the functions xf(x,y)dν(y) and yf(x,y)dμ(x) are measurable and fd(μν)=f(x,y)dν(y)dμ(x)=f(x,y)dμ(x)dν(y) (Tao, Theorem 1.7.15). Every subprobability measure is finite, hence σ-finite, so the last two apply to all measures exported by this chapter. Monotonicity of the integral and the identity 1Adμ=μ(A) are immediate from the displayed definition and are proved below rather than imported.

Lemma 172.13 — Monotonicity and indicators

If fg pointwise then fdμgdμ, and 1Adμ=μ(A) for AΣX.

Proof of Lemma 172.13 — Monotonicity and indicators

Proof. Every competitor ici1Aif in the supremum defining fdμ also satisfies ici1Aig, so the supremum for f is over a subset of the competitors for g. For the indicator, the competitor 11A gives μ(A)1Adμ; conversely any competitor ici1Ai1A has ci1 and AiA whenever ci>0, so iciμ(Ai)μ(A) by additivity and monotonicity of μ. ◻

Theorem 172.14 — Change of variables

Let g:XY be measurable, μ a measure on X, and f:Y[0,] measurable. Then fd(gμ)=(fg)dμ.

Proof of Theorem 172.14 — Change of variables

Proof. The proof is the standard three-stage ascent, and each stage is used again in section 172.3.

Indicators. For f=1B with BΣY, the composite 1Bg is 1g1(B), so 1Bd(gμ)=lemma172.13gμ(B)=definition172.10μ(g1B)=lemma172.131g1Bdμ=(1Bg)dμ.

Simple functions. For f=i=1kci1Bi, apply additivity and homogeneity (convention 172.12) on both sides and the indicator case to each summand.

General f. Every measurable f:Y[0,] is the pointwise limit of the nondecreasing sequence of simple functions fn=j=1n2nj12n1f1[j12n,j2n)+n1f1[n,], and fng is then a nondecreasing sequence of simple functions with pointwise limit fg. Monotone convergence applied on each side gives the claim from the simple case. ◻

Lemma 172.15 — Dirac and products

For xX and measurable f:X[0,], fdδx=f(x); for xX, yY, δxδy=δ(x,y); and for a subprobability μ on X and the one-point probability space 1=({},{,{}}), the projection πX satisfies (πX)(μδ)=μ.

Proof of Lemma 172.15 — Dirac and products

Proof. For the first claim, 1Adδx=δx(A)=1A(x), and the ascent of theorem 172.14 carries this to simple and then to all measurable f. For the second, the two measures agree on the generating rectangles, (δxδy)(A×B)=1A(x)1B(y)=1A×B(x,y)=δ(x,y)(A×B), and by the uniqueness clause of convention 172.12 agreement on rectangles determines the product measure. For the third, (πX)(μδ)(A)=(μδ)(A×{})=μ(A)1. ◻

Exercise 172.3

★☆☆ Show that the family of finite and cofinite subsets of an uncountable set is not a σ-algebra, and identify which clause of definition 172.6 fails.

Exercise 172.4

★☆☆ Let A,B be countable with the discrete σ-algebras and let g:AB. Show that gμ({b})=ag1(b)μ({a}), and compute gE(xor2) for g the negation map.

Exercise 172.5

★★☆ Exhibit a set map g:XY that is not measurable and a measure μ for which the formula of theorem 172.14 has an undefined left-hand side. State precisely which stage of the proof uses measurability of g.

Kernels and their monad laws

A closed probabilistic program of type τ denotes a measure on [[τ]]. A program with one free variable denotes a family of measures indexed by the value of that variable, and sequencing composes two such families. The composition is an integral, so the family must be measurable in its index; that requirement is the definition of a kernel.

Definition 172.16 — Kernel

Let X,Y be measurable spaces. A kernel k:XY is a function assigning to each xX a subprobability measure k(x) on Y such that xk(x)(B) is measurable for every BΣY. The return kernel is retX(x)=δx, and for a subprobability measure μ on X and a kernel k:XY the bind is (μ=k)(B)=k(x)(B)dμ(x)(BΣY). For kernels k:XY and l:YZ, the composite is (k=l)(x)=k(x)=l.

Lemma 172.17 — The return kernel is a kernel

retX is a kernel, and for measurable g:XY the assignment xδg(x) is a kernel.

Proof of Lemma 172.17 — The return kernel is a kernel

Proof. δx(B)=1B(x) is measurable in x because 1B1({1})=BΣX. For the second claim, δg(x)(B)=1g1(B)(x), and g1(B)ΣX. ◻

Proposition 172.18 — Bind is well defined

Let μ be a subprobability measure on X and k:XY a kernel. Then μ=k is a subprobability measure on Y, with (μ=k)(Y)μ(X)1. If moreover l:WX is a kernel then w(l(w)=k)(B) is measurable, so l=k is a kernel.

Proof of Proposition 172.18 — Bind is well defined

Proof. Measure. (μ=k)()=0dμ=0. For pairwise disjoint (Bn)n, countable additivity of each k(x) gives k(x)(nBn)=nk(x)(Bn)=limNnNk(x)(Bn), a pointwise nondecreasing limit of measurable functions of x; so (μ=k)(nBn)=monotoneconvergencelimNnNk(x)(Bn)dμ(x)=additivitylimNnN(μ=k)(Bn)=n(μ=k)(Bn). Mass. k(x)(Y)1 pointwise, so (μ=k)(Y)1dμ=μ(X) by lemma 172.13.

Measurability of the composite. Fix B. The function (w,x)k(x)(B) is measurable in x by assumption, and wk(x)(B)dl(w)(x) is measurable by the following instance of the three-stage ascent: for k()(B)=1A it is wl(w)(A), measurable because l is a kernel; for a simple function it is a finite nonnegative combination of such maps; and in general it is the pointwise limit of a nondecreasing sequence of those, hence measurable. ◻

Lemma 172.19 — Integration against a bind

For a subprobability μ on X, a kernel k:XY, and a measurable f:Y[0,], fd(μ=k)=(fdk(x))dμ(x).

Proof of Lemma 172.19 — Integration against a bind

Proof. For f=1B both sides are k(x)(B)dμ(x), by lemma 172.13 on the left and inside the outer integral on the right. Additivity and homogeneity extend this to simple f. For general f, take the nondecreasing simple approximants fn of theorem 172.14; monotone convergence applies to the outer integral on the left, and on the right the inner integrals fndk(x) form a nondecreasing sequence in n for each x, so monotone convergence applies twice. ◻

Theorem 172.20 — Monad laws for kernels

Let μ be a subprobability measure on X, let k:XY and l:YZ be kernels, and let xX. Then δx=k=k(x),μ=retX=μ,(μ=k)=l=μ=(xk(x)=l).

Proof of Theorem 172.20 — Monad laws for kernels

Proof. Each equation is an equality of measures, so it suffices to evaluate both sides at an arbitrary measurable set.

Left unit. (δx=k)(B)=k()(B)dδx=lemma172.15k(x)(B).

Right unit. (μ=retX)(A)=δx(A)dμ(x)=1Adμ=lemma172.13μ(A).

Associativity. For CΣZ, ((μ=k)=l)(C)=definition172.16l(y)(C)d(μ=k)(y)=lemma172.19(l(y)(C)dk(x)(y))dμ(x)=definition172.16(k(x)=l)(C)dμ(x), and the last expression is (μ=(xk(x)=l))(C); the family xk(x)=l is a kernel by proposition 172.18, so the outer integral is defined. ◻

Example 172.21 — The laws on the finite fragment

On a countable space with the discrete σ-algebra, a subprobability measure is a family (μ({a}))a summing to at most 1, the integral is the sum fdμ=af(a)μ({a}), and bind is the operation of definition 172.1. Associativity becomes the interchange y(xμ(x)k(x)(y))l(y)(z)=xμ(x)(yk(x)(y)l(y)(z)), which is Tonelli’s theorem for counting measure. The general proof above is the same computation with sums replaced by integrals; the finite case is where the reader should first check the bracketing.

Lemma 172.22 — Pushforward as a bind, and the mass bound

For measurable g:XY and a subprobability μ on X, gμ=μ=(xδg(x)). Consequently (μ=k)(Y)=μ(X) whenever every k(x) is a probability measure, and the total mass of a bind is otherwise strictly smaller.

Proof of Lemma 172.22 — Pushforward as a bind, and the mass bound

Proof. (μ=(xδg(x)))(B)=1g1(B)dμ=μ(g1B)=gμ(B). For the mass, if k(x)(Y)=1 for all x then k(x)(Y)dμ(x)=μ(X); and if k(x)(Y)<1 on a set of positive μ-measure then monotonicity of the integral makes the value strictly smaller. ◻

Limits of subprobability measures

Recursive programs are interpreted as suprema of the finite unfoldings of their bodies, so the exported interface must say that such suprema exist and that sequencing preserves them.

Definition 172.23 — Pointwise order

For subprobability measures μ,ν on X write μν when μ(A)ν(A) for every AΣX.

Proposition 172.24 — Increasing chains

Let μ0μ1 be subprobability measures on X. Then Asupnμn(A) is a subprobability measure, written supnμn, it is the least upper bound of the chain in the order of definition 172.23, and for every measurable f:X[0,], fd(supnμn)=supnfdμn.

Proof of Proposition 172.24 — Increasing chains

Proof. Write μ(A)=supnμn(A)1. Then μ()=0, and for pairwise disjoint (Ak)k, μ(kAk)=supnkμn(Ak)=monotoneconvergenceforseriesksupnμn(Ak)=kμ(Ak), the middle step because the double family μn(Ak) is nondecreasing in n for each k, so the supremum over n of the sums equals the sum of the suprema. That μ is the least upper bound is immediate from the pointwise definition. For the integral, both sides are suprema of the same set of numbers when f is an indicator, additivity extends this to simple functions, and the approximants of theorem 172.14 together with monotone convergence give the general case. ◻

Proposition 172.25 — Bind preserves increasing suprema

Let μ0μ1 be subprobability measures on X, let k:XY be a kernel, and let k0k1 be kernels with km(x) increasing in m for each x. Then (supnμn)=k=supn(μn=k),μ=(supmkm)=supm(μ=km).

Proof of Proposition 172.25 — Bind preserves increasing suprema

Proof. For the first, evaluate at B and apply proposition 172.24 to the function xk(x)(B). For the second, evaluate at B; the integrands xkm(x)(B) form a pointwise nondecreasing sequence whose supremum is a subprobability measure in B by proposition 172.24 and is measurable in x as a pointwise supremum of measurable functions; monotone convergence gives the equality. ◻

Example 172.26 — Expectation of a finite rational mixture

Let μ=i=1kpiμi with rational pi0, ipi1, and subprobability measures μi. Then μ is a subprobability measure and fdμ=ipifdμi for measurable f0: both claims hold for indicators by definition, and extend by additivity, homogeneity and monotone convergence. For E(xor2) of example 172.2 and f=1{tt} this reads fdE(xor2)=1/2.

Convention 172.27 — The frozen export PMKPMK

The interface exported by this chapter to later chapters consists of exactly the following, in three groups.

PMK-map: definition 172.6, definition 172.9, definition 172.10; lemma 172.7, lemma 172.8, lemma 172.11; theorem 172.14; lemma 172.15; the product measure and Tonelli statements of convention 172.12.

PMK-bind: definition 172.16; lemma 172.17; proposition 172.18; lemma 172.19; theorem 172.20; lemma 172.22.

PMK-lim: lemma 172.13; the additivity, homogeneity and monotone convergence statements of convention 172.12; definition 172.23; proposition 172.24; proposition 172.25; example 172.26.

Nothing else is exported. In particular the export contains no conditioning or disintegration theorem, no computable metric space structure, no effective topology, no density or Radon–Nikodym statement, no s-finite kernel, no quasi-Borel exponential, and no domain-theoretic fixed point. The sampler-and-valuation development of section 172.5 is a separate system card and is not part of PMK.

Exercise 172.6

★★☆ Give a family (k(x))xR of probability measures on {0,1} that is not a kernel, and show that μ=k is then undefined for Lebesgue measure restricted to [0,1]. (Use a non-measurable subset of [0,1] as the set on which k(x)=δ1.)

Exercise 172.7

★☆☆ Verify the associativity law of theorem 172.20 by direct computation on the three-point discrete example μ={a1/3,b2/3}, k(a)={c1}, k(b)={c1/2,d1/2}, l(c)=δ0, l(d)=δ1.

Exercise 172.8

★★☆ Give an increasing chain of subprobability measures on N whose supremum has total mass 1/2 although each member has mass strictly less than 1/2, and compute fd(supnμn) for f(n)=n. State which hypothesis of proposition 172.24 would fail for a chain that is not nondecreasing.

Samplers, valuations, and computable distributions

The finite fragment of section 172.1 had two descriptions and one proof relating them. For distributions on a complete separable metric space the two descriptions are a point of a space of measures and a program that consumes fair bits. This section states both precisely, proves the correspondence that the chapter owns, and marks exactly where the imported computability result is used.

Definition 172.28 — The fair-bit measure and its splitting

Let 2ω carry the σ-algebra generated by the cylinders [w]={uu begins with w} for w2. The fair-bit measure μiid is the unique measure with μiid([w])=2|w|. Define split:2ω2ω×2ω by split(u)=(ue,uo), the subsequences of even and odd indices.

Lemma 172.29 — Uniqueness on a generating algebra

Let μ,ν be subprobability measures on X that agree on a Boolean algebra AΣX with σ(A)=ΣX and μ(X)=ν(X). Then μ=ν.

Proof of Lemma 172.29 — Uniqueness on a generating algebra

Proof. Let C={AΣXμ(A)=ν(A)}. It contains A. It is closed under increasing unions, because μ(nAn)=supnμ(An) for an increasing sequence, by countable additivity applied to the disjoint differences; and under decreasing intersections, because μ(X)< allows the same computation on complements. So C is a monotone class containing A, and by the monotone class lemma (Tao, Lemma 1.7.14) it contains σ(A)=ΣX. ◻

Lemma 172.30 — Splitting produces an independent pair

splitμiid=μiidμiid.

Proof of Lemma 172.30 — Splitting produces an independent pair

Proof. Both sides are probability measures on 2ω×2ω. On a rectangle of cylinders, split1([w1]×[w2]) is the set of streams whose even positions begin with w1 and whose odd positions begin with w2; this is the disjoint union of the cylinders [w] of length 2max(|w1|,|w2|) that meet those constraints, and counting them gives μiid(split1([w1]×[w2]))=2|w1|2|w2|=(μiidμiid)([w1]×[w2]). Finite unions of such rectangles form a Boolean algebra generating the product σ-algebra, and the two measures agree on it by finite additivity, so lemma 172.29 applies. ◻

Definition 172.31 — Sampler and its pushforward measure

Let X be a measurable space. A sampler for X is a measurable partial function s:2ωX whose domain has μiid-measure 1. Its pushforward measure is psh(s)=sμiid, a probability measure on X. The constant sampler is det(x)(u)=x, and for a sampler s for X and a family f assigning to each xX a sampler f(x) for Y, the sequenced sampler is samp(s,f)(u)=f(s(ue))(uo).

Theorem 172.32 — Pushforward correspondence

Let s be a sampler for X and let f assign to each xX a sampler f(x) for Y such that (x,u)f(x)(u) is measurable on its domain and xpsh(f(x))(B) is measurable for every BΣY. Then psh(det(x))=δx,psh(samp(s,f))=psh(s)=(xpsh(f(x))).

Proof of Theorem 172.32 — Pushforward correspondence

Proof. For the first equation, psh(det(x))(A)=μiid({uxA})=1A(x)=δx(A).

For the second, fix BΣY and compute psh(samp(s,f))(B)=definition172.31μiid({uf(s(ue))(uo)B})=lemma172.30(μiidμiid)({(u1,u2)f(s(u1))(u2)B})=Tonelli1B(f(s(u1))(u2))dμiid(u2)dμiid(u1)=definition172.31psh(f(s(u1)))(B)dμiid(u1)=theorem172.14psh(f(x))(B)dpsh(s)(x)=definition172.16(psh(s)=(xpsh(f(x))))(B). The second step uses lemma 172.30 through theorem 172.14 applied to the measurable map split; Tonelli applies because both measures are probability measures, hence σ-finite, and because the displayed set is measurable by the hypothesis on f. The last change of variables is theorem 172.14 for the measurable s and the function xpsh(f(x))(B), measurable by hypothesis. Both sides are defined off a μiid-null set, which does not affect any of the integrals. ◻

Remark 172.33 — What thm:pmk-push is, and is not

Theorem 172.32 is the measure-theoretic content of Huang–Morrisett–Spitters’ Proposition 5.1, restated in the vocabulary of convention 172.27 and proved here: the pushforward of a constant sampler is a Dirac measure, and the pushforward of a sequenced sampler is the bind of the pushforwards. Their statement is about topological domains — for countably based topological predomains D,E, pshD is a continuous map S(D)P(D) into valuations, and the second clause is proved for their samp, whose splitting must produce an independent stream — and the independence requirement is exactly lemma 172.30. It is a correspondence between two representations of the same distribution. It is not an operational adequacy theorem: it compares two denotations, and says nothing about the traces of a running implementation. A statement about traces belongs to proposition 172.5 and to the practical project below, both of which are confined to the finite fragment.

Convention 172.34 — The Huang–Morrisett–Spitters system card

The following interface is frozen and is not part of PMK. A computable metric space is a triple (X,d,S) with (X,d) a complete metric space, SX countable, enumerable and dense, and d(si,sj) a computable real uniformly in i,j. The space M(X) of Borel probability measures on X, equipped with the Prokhorov metric dρ(μ,ν)=inf{ε>0μ(A)ν(Aε)+ε for all Borel A} and the ideal points D(S) of finitely supported rational-mass distributions on S, is again a computable metric space; μ is a computable distribution when it is a computable point of it. A distribution μM(X) is samplable when there is a computable s:(2ω,μiid)(X,μ), computable on a domain of full measure, with μ=sμiid. The language λCD has types τ::=NatRealτττ×τDistτ, a judgment Dτ admitting Nat, Real and products of admissible types, PCF terms with pairs, real constants and primitive real operations, primitive distributions dist, returnM and xM1;M2, and the typing rules

Ψ(dist)=DistτDτ
Γdist:Distτ
Dist
ΓM:τDτ
ΓreturnM:Distτ
Ret
ΓM1:Distτ1Γ,x:τ1M2:Distτ2Dτ1,τ2
ΓxM1;M2:Distτ2
Bind

Types denote topological domains, with [[Distτ]]={(s,psh[[τ]](s))sS([[τ]])} for the sampler functor S(D)=2ωD; a valuation on a topological space is a strict, monotone and modular map O(X)[0,1], it is ω-continuous when it preserves suprema of increasing sequences of opens, and P is the resulting probability monad with η(x)(U)=1U(x) and (μf)(U)=fUdμ.

Convention 172.35 — Imported computability and well-definedness

Two statements of convention 172.34 are imported at exactly their source signatures and are used nowhere else in this book without being restated.

First, Huang–Morrisett–Spitters’ Proposition 2.11, attributed there to Freer and Roy (2010, Lemmas 2 and 3): a distribution μM(X) on a computable metric space (X,d,S) is computable if and only if it is samplable. What it supplies is the passage between the two descriptions of a distribution on a complete separable metric space, in both directions, and nothing about conditioning.

Second, their Proposition 5.2: for every well-typed ΓM:τ of λCD and every global environment with ΨΥ, the expression denotation [[M]]Γ is a well-defined morphism [[Γ]][[τ]] of topological domains. Its interesting cases are return and bind, where the sampler component must be shown to realize the valuation component; that is exactly the content of theorem 172.32, transported to their setting.

Example 172.36 — Uniform draws are computable, and the correspondence is not free

The bisection sampler unif(u)=limnbisect(u,n), which maintains an interval and halves it according to the next bit, is a sampler for [0,1] in the sense of definition 172.31, and psh(unif) is Lebesgue measure on [0,1]: on a dyadic interval [j2n,(j+1)2n] the preimage is a single cylinder of length n, of measure 2n, and lemma 172.29 extends the agreement from the algebra generated by dyadic intervals to all Borel sets. By convention 172.35 the same distribution is a computable point of (M([0,1]),dρ,D(Q)). Neither description follows from the other by unfolding definitions: the first is a statement about a measurable map on 2ω, the second about a computable Cauchy sequence in the Prokhorov metric, and Proposition 2.11 is the theorem that they coincide.

Remark 172.37 — Two representations, compared by translations

Three descriptions of a distribution have appeared: a subprobability measure (definition 172.9), an ω-continuous valuation (convention 172.34), and a sampler (definition 172.31). They are related by explicit translations and are not identified: a Borel measure restricts to an ω-continuous valuation on the open sets, and is determined by that restriction when the space is countably based, by lemma 172.29 applied to the algebra generated by a countable base; a sampler maps to a measure by psh; and convention 172.35 maps a computable distribution back to a sampler. Each translation has hypotheses — countable base, completeness, computability of the metric — and a claim proved for one representation transfers to another only through a translation whose hypotheses have been checked. Park’s typed language for probabilistic computation is used in this book only as a pedagogical comparison for the sampling view; it owns no theorem here, and no statement crosses from its syntax to convention 172.34 without a proved translation.

Remark 172.38 — The chapter's boundary

Nothing above conditions on an observation. Conditioning asks for a family xμ(Y=x) satisfying an integral equation, and such a family is determined only up to a null set of x; both its existence and its computability are outside this chapter, and neither follows from the exported interface. Densities and Radon–Nikodym derivatives are likewise absent: no statement above produces a density for a measure, and the export contains none. Finally, definition 172.6 provides no function space: there is no measurable structure here on the maps between two measurable spaces, and the chapter proves nothing about higher-order probabilistic programs.

Exercise 172.9

★☆☆ Write a sampler for the geometric distribution n2(n+1) on N and compute psh of it directly from definition 172.31, using cylinders.

Exercise 172.10

★★☆ Replace samp(s,f)(u)=f(s(ue))(uo) by f(s(u))(u), which feeds the same stream to both stages. Exhibit a sampler s and a family f for which the conclusion of theorem 172.32 then fails, and identify the step of the proof that breaks.

Exercise 172.11

★★☆ Let X be a countable discrete space. Show that every ω-continuous valuation on X with ν(X)1 is the restriction of a unique subprobability measure, and give the two directions of the translation explicitly.

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 172.12, then exercise 172.13, then the practical project exercise 172.16.

Exercise 172.12

★☆☆ Verify the three laws of theorem 172.20 on the discrete two-point space by direct rational computation, and then locate in the general proof the exact step that replaces each finite sum.

Exercise 172.13

★★☆ Write out the proof of theorem 172.32 for X=Y={0,1} with s reading one bit and f(x) reading one bit, replacing every integral by a finite sum, and check the result against example 172.2.

Exercise 172.14

★★☆ Give two subprobability measures and a nonnegative function for which the iterated integrals of convention 172.12 differ when the σ-finiteness hypothesis is dropped, and state where theorem 172.32 would use the hypothesis.

Exercise 172.15

★★☆ Let km be the kernel on N that halts within m steps in the geometric program of exercise 172.9 and returns the empty measure otherwise. Prove that (km)m is an increasing chain of kernels, compute supmkm, and check proposition 172.25 on this chain with k(n)=δn+1.

Exercise 172.16

★★★ Practical project.pmk-enumerator-sampler Build an interpreter with two back ends for the fragment of section 172.1 extended with xor, if, and biased coin(p) for reduced rational p. The first back end is the exact enumerator E of definition 172.1: it returns a finite map from values to reduced rationals, computed by the bind of that definition. The second is the bit-stream sampler S of definition 172.3: it consumes an explicit finite list of bits and emits one trace line per event, draw b or return v, reporting exhaustion of the list as a distinct outcome from a returned value.

The invariant to maintain is that the enumerator’s table has total mass exactly 1 for every term of the fragment and that every rational is kept in reduced form with no floating-point arithmetic anywhere; the sampler must consume exactly one bit per coin, in evaluation order.

The concrete result is the pair of outputs for the fixture xor2=b1coin;b2coin;return(b1b2). The acceptance test is decidable: the enumerator must print the table {ff1/2, tt1/2}; the sampler on the bit list 0,1 must print exactly draw 0; draw 1; return tt, and on 1,1 exactly draw 1; draw 1; return ff; the enumerator must print {ff2/3, tt1/3} for bcoin(1/3);returnb with tt the outcome of probability 1/3; and the checker must confirm, by exhausting the four bit lists of length two, the equality of proposition 172.5 for xor2. Observed frequencies from repeated sampling may be displayed but are not an accepted answer, and the finite agreement checked here illustrates theorem 172.32 without proving it.

Search the book

Type to search the local edition.