Lectures onType Theory
Chapter 171
Chapter 171Optional

Probabilistic Lambda Calculi and Program Equivalence

Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.

Consider two closed programs that each produce a bit. The first flips a fair coin; the second flips a coin that falls on 0 once in three times. Write them, for the moment informally, as coin(1/2) and coin(1/3), and let a transition relation record which results are possible: coin(1/2)0,coin(1/2)1,coin(1/3)0,coin(1/3)1. The two programs have the same reachable set {0,1}, so every equivalence defined from the reachable set identifies them. A gambler who is paid one euro when the result is 0 does not identify them. The quantity that separates them — the probability that the program returns 0 — is not a set of successor states but a number, and the relation does not carry it.

Three things must therefore be built, and the chapter builds them in this order. The operational semantics must assign to each pair of terms the probability of a transition, and must accumulate those probabilities along possibly infinite reduction sequences into a subprobability distribution over results; a diverging program then contributes missing mass rather than a default value. The program equivalence must observe those numbers through arbitrary program contexts. Finally, a denotational model must compute the same numbers compositionally, and must do so exactly: an inequality between the model and the operational probabilities is not enough to decide the equivalence, and a model that identifies more terms than contexts do would answer the wrong question. The invariant that organizes the whole chapter is the equality between an operational convergence probability and a coefficient of a power series, first for ground results and then, through a family of testing programs, for every type.

The calculus pPCF

Convention 171.1 — The pPCF system card

pPCF is the calculus of Ehrhard–Pagani–Tasson with one ground type ι of natural numbers, ordinary function types, a call-by-name fix, a value-passing conditional, and one probabilistic constructor. Types and terms are σ,τ::=ιστ,M,N::=nxsucc(M)if(M,P,zR)λxσ.MMNcoin(p)fix(M), where n ranges over N, the numeral n is the constant naming n, and p ranges over the rational numbers in [0,1]. In if(M,P,zR) the variable z is bound in R and in no other subterm. Terms are identified up to renaming of bound variables, and M[N/x] is capture-avoiding substitution. A typing context Γ=(x1:σ1,,xk:σk) has pairwise distinct variables, and the typing rules are

Γn:ι
Num
Γ,x:σx:σ
Var
ΓM:ι
Γsucc(M):ι
Succ
p[0,1]Q
Γcoin(p):ι
Coin
ΓM:ιΓP:σΓ,z:ιR:σ
Γif(M,P,zR):σ
If
Γ,x:σM:τ
Γλxσ.M:στ
Lam
ΓM:στΓN:σ
ΓMN:τ
App
ΓM:σσ
Γfix(M):σ
Fix

Write ΛΓσ for the set of terms M with ΓM:σ, and Λ0σ when Γ is empty. This card is frozen: no continuous distribution, no scoring or conditioning construct, and no reference or exception belongs to pPCF, and no theorem proved below is claimed for a calculus with those constructs.

Two features of the card do work that a reader of an ordinary call-by-name PCF should notice at once.

The conditional binds its scrutinee’s value. In PCF one writes if(M,P,Q) and, in the branch taken when M is nonzero, recovers the value of M by evaluating M again. Under a probabilistic semantics that second evaluation is a second experiment: it need not return what the first returned. The pPCF conditional therefore passes the predecessor of the scrutinee to the branch through the bound variable z, so that the outcome of the single experiment performed on M is available without repeating it.

The bound variable makes the predecessor definable, which is where the mechanism is easiest to see: pred=λxι.if(x,0,zz).

Definition 171.2 — Deterministic contraction

The relation M0M on pPCF terms is generated by (λxσ.M)N0M[N/x],fix(M)0Mfix(M),succ(n)0n+1, if(0,P,zR)0P,if(n+1,P,zR)0R[n/z]. These are root contractions: no clause reduces a proper subterm.

Definition 171.3 — Weak probabilistic reduction

The relation MpM, read “M reduces in one step to M with probability p”, is generated by

M0M
M1M
Det
coin(p)p0
Coin-0
coin(p)1p1
Coin-1
MpM
MNpMN
Ctx-App
MpM
succ(M)psucc(M)
Ctx-Succ
MpM
if(M,P,zR)pif(M,P,zR)
Ctx-If

A term M is weak-normal when there are no p and M with MpM. The three context rules descend only into the leftmost outermost position, so no rule reduces under a λ, inside the branches of a conditional, or in the argument of an application.

The closed weak-normal terms of type ι are exactly the numerals, and the closed weak-normal terms of type στ are exactly the abstractions. Both facts are read off the rules: every other closed term has a leftmost outermost redex.

Example 171.4 — Two experiments, two numbers

For p=1/3 the rules give exactly two steps from coin(1/3), namely coin(1/3)1/30 and coin(1/3)2/31, while coin(1/2)1/20 and coin(1/2)1/21. Erasing the labels erases the distinction between the two programs; keeping them is the whole content of definition 171.3.

The next calculation exercises the value-passing conditional and produces the running program of the chapter.

Example 171.5 — A geometric program

Let G=fix(λgι.if(coin(1/2),0,zsucc(g))),G:ι. Its first two steps are deterministic: GDet(λgι.if(coin(1/2),0,zsucc(g)))GDetif(coin(1/2),0,zsucc(G)). From there the coin is the leftmost outermost redex, so Ctx-If applies and the computation splits: if(coin(1/2),0,zsucc(G))1/2if(0,0,zsucc(G))Det0,if(coin(1/2),0,zsucc(G))1/2if(1,0,zsucc(G))Detsucc(G). The second branch reproduces G under one succ. Iterating, the program reaches the numeral n exactly along the single reduction path that answers “1n times and then “0”, and the product of the labels along that path is 2(n+1). The chapter’s operational semantics must therefore assign to G the distribution n2(n+1) on N, whose total mass is 1.

Exercise 171.1

★☆☆ Using definition 171.2, definition 171.3, write the complete reduction of pred3, labelling every step with the rule that produces it, and state which rule fails to apply to predcoin(1/2) at its first step.

Exercise 171.2

★☆☆ Let Ωσ=fix(λxσ.x). Show Ωσ:σ, and show that every reduction sequence from Ωσ has all labels equal to 1 and never reaches a weak-normal term.

Exercise 171.3

★★☆ Let D=if(coin(1/2),0,zz),D=if(coin(1/2),0,zif(coin(1/2),0,zz)). Compute, for each of the two terms and each n{0,1}, the sum of the products of the labels along every reduction path ending at n. Conclude that a conditional which re-evaluates its scrutinee instead of binding its value does not define the same program.

Convergence probabilities

Example 171.5 multiplied labels along a path and summed over paths. That informal recipe must become a definition that also survives infinitely many paths, and the following device — reduction as a stochastic matrix — makes the sum a supremum of finite approximations.

Definition 171.6 — The reduction matrix

Let Γ be a typing context and σ a type. Define Red(Γ,σ)[0,1]ΛΓσ×ΛΓσ by Red(Γ,σ)M,M={pif MpM,1if M is weak-normal and M=M,0otherwise. Write Red(σ) when Γ is empty. The matrix product is (ST)M,M=MSM,MTM,M, and Sk is the k-fold product.

The first clause is unambiguous because a non-weak-normal term has exactly one leftmost outermost redex, and that redex is either deterministic — giving one successor with label 1 — or a coin, giving two successors with labels summing to 1. Hence every row of Red(Γ,σ) sums to 1: the matrix is stochastic, and a weak-normal term is a state that only steps to itself.

Lemma 171.7 — Monotone approximation

Let S be a stochastic matrix indexed by a countable set I, and let I1={iISi,i=1}. For iI and jI1 the sequence k(Sk)i,j is nondecreasing, and the matrix (S)i,j={supkN(Sk)i,jif jI1,0otherwise satisfies jI(S)i,j1 for every i.

Proof of Lemma 171.7 — Monotone approximation

Proof. Fix iI and jI1. Then (Sk+1)i,j=lI(Sk)i,lSl,j  (Sk)i,jSj,j=jI1(Sk)i,j, where the inequality drops all summands except l=j, each of which is nonnegative. So the sequence is nondecreasing and its supremum exists in [0,1]. For the mass bound, exchange a supremum of a nondecreasing sequence with a countable sum of nonnegative terms: jI(S)i,j=jI1supk(Sk)i,j=monotoneconvergencesupkjI1(Sk)i,j  supkjI(Sk)i,j=1. The last equality holds because a product of stochastic matrices is stochastic. ◻

Definition 171.8 — Convergence probability

For M,MΛΓσ with M weak-normal, write MpM for p=Red(Γ,σ)M,M. For a closed MΛ0ι, the family (Red(ι)M,n)nN is the result distribution of M; by lemma 171.7 its total mass is at most 1, and the missing mass 1nRed(ι)M,n is the probability of divergence.

The supremum in lemma 171.7 is a sum over reduction paths, which is how the calculations in this chapter are actually performed.

Lemma 171.9 — Path decomposition

Let S be stochastic on I, let iI and jI1. Call a sequence w=(i1,,ik) with k1 a path from i to j when i1=i, ik=j, and ikil for 1l<k; its weight is wt(w)=l=1k1Sil,il+1. Then (S)i,j=wwt(w), the sum ranging over all paths from i to j.

Proof of Lemma 171.9 — Path decomposition

Proof. Because j is stationary, for each k the number (Sk)i,j is the sum of the weights of all length-k sequences from i to j; grouping such a sequence by the first index at which it reaches j and using Sj,j=1 for the remaining steps, (Sk)i,j is the sum of wt(w) over paths w of length at most k. The paths form a countable set of nonnegative summands, so the supremum over k of these partial sums is the total sum. The requirement that j occurs only at the end of a path is what prevents a path from being counted twice. ◻

Example 171.10 — The result distribution of the geometric program

Continue example 171.5. Exactly one path leads from G to n: it performs two deterministic steps, then n times the pair “coin answers 1, conditional selects the branch”, then the coin answers 0, then the remaining deterministic steps that turn succn(0) into n. Its weight is the product of its labels, in which every deterministic step contributes 1: Red(ι)G,n=lemma171.91212n12=2(n+1),nN2(n+1)=1. The program terminates with probability 1 although it has an infinite reduction path, namely the one on which the coin always answers 1. That path has weight 0 in the limit and contributes nothing.

Remark 171.11 — Why weak-normal terms are made stationary

Delete the second clause of definition 171.6 and the row of a weak-normal term becomes zero, so (Sk)i,j is the probability of reaching j in exactly k steps. That sequence is not monotone — for G above it is 0 at every k except the one length at which n is reached — so no supremum computes the accumulated probability. Making results stationary converts “reached at step k” into “reached within k steps”, which is the monotone quantity.

Exercise 171.4

★☆☆ Compute Red(ι)coin(p),n for every n, and compute the result distribution of succ(coin(1/3)).

Exercise 171.5

★★☆ Let H=if(coin(1/2),0,zΩι) with Ωι as in exercise 171.2. Compute the result distribution of H and its total mass, and identify the reduction paths that carry the missing mass.

Exercise 171.6

★★☆ Give a closed term K of type ι whose result distribution has total mass 1/2 and is supported on {0}, and a closed term whose result distribution has infinite support and total mass 1/2. Prove the mass claims by lemma 171.9.

Observational equivalence

A single number, the probability of returning 0, is enough to separate coin(1/2) from coin(1/3). Terms of higher type produce no number by themselves; they must first be placed in a program that consumes them. The definition therefore quantifies over contexts.

Definition 171.12 — Observation contexts

Observation contexts are generated by the term formers of convention 171.1 together with a hole symbol []Δτ. Their typing judgment ΓCΔτ:σ is generated by the rules of convention 171.1 read as rules for contexts, together with

Γ,Δ[]Δτ:τ
Hole

Filling every hole with a term M such that ΔM:τ produces the term C[M]; free variables of M may be captured by abstractions of C, which is the point of recording Δ in the hole. If ΓCΔτ:σ and ΔM:τ then ΓC[M]:σ, by induction on the derivation of the context judgment.

Definition 171.13 — Observational equivalence

For M,MΛΓσ, write MM when for every observation context CΓσ with CΓσ:ι, Red(ι)C[M],0=Red(ι)C[M],0.

Only the probability of the single result 0 is compared. This is no restriction, because the family of tests below moves any other result into that position.

Definition 171.14 — Tests

Define closed terms probk with probk:ιι by prob0=λxι.if(x,0,zΩι),probk+1=λxι.if(x,Ωι,zprobkz).

Lemma 171.15 — What a test measures

For every closed M of type ι and every kN, Red(ι)probkM,0=Red(ι)M,k.

Proof of Lemma 171.15 — What a test measures

Proof. Induction on k. For k=0: the term prob0M contracts in one deterministic step to if(M,0,zΩι), and by Ctx-If every reduction of M is copied inside the conditional with the same label. A path from prob0M to 0 therefore consists of that first step, a path of M to some numeral n, and then the contraction of if(n,0,zΩι). The last contraction reaches 0 when n=0 and reaches Ωι[n1/z]=Ωι when n>0; no path from Ωι reaches a weak-normal term by exercise 171.2. Summing weights by lemma 171.9 leaves exactly the paths of M to 0.

For k+1: the same analysis leaves the paths of M to numerals n+1, each continued by probkn, and the induction hypothesis gives Red(ι)probkn,0=Red(ι)n,k, which is 1 when n=k and 0 otherwise. Hence the total weight is Red(ι)M,k+1. ◻

Example 171.16 — Two terms and four numbers

Let M=coin(1/2),N=if(coin(1/2),0,z1). Both are closed of type ι. Their result distributions coincide: Red(ι)M,0=12,Red(ι)M,1=12,Red(ι)N,0=Coin0,Det12,Red(ι)N,1=Coin1,Det12, the second line because N1/2if(0,0,z1)00 and N1/2if(1,0,z1)01[0/z]=1. With the two contexts C0=prob0[] and C1=prob1[], lemma 171.15 turns those four numbers into the four observations Red(ι)C0[M],0=Red(ι)C1[M],0=Red(ι)C0[N],0=Red(ι)C1[N],0=12. These two contexts do not separate M and N. They cannot: the quantification in definition 171.13 is over all contexts, and no finite table of contexts decides it. Deciding it is the work of the model.

Exercise 171.7

★☆☆ Using lemma 171.15, prove that MM implies Red(ι)C[M],n=Red(ι)C[M],n for every observation context C of type ι and every nN.

Exercise 171.8

★☆☆ Exhibit an observation context that separates coin(1/2) from coin(1/3), and give the two numbers it produces.

Exercise 171.9

★★☆ Prove that is an equivalence relation and that it is preserved by every term former: if MM then D[M]D[M] for every observation context D of the appropriate typing. (Compose contexts; two lines.)

Probabilistic coherence spaces

The equivalence of definition 171.13 quantifies over infinitely many contexts, so it cannot be decided by running programs. A model is wanted whose elements are the numbers the contexts measure. For the ground type the answer is forced: an element must be a subprobability distribution on N. The question is what an element of a function type is, and the requirement that settles it is that a program of type ιι transforms subprobability distributions into subprobability distributions by a rule that is stable under composition and under limits of increasing chains.

Definition 171.17 — Orthogonality

Let I be a countable set. For u,u(R+)I put u,u=aIuauaR+{}, and for X(R+)I put X={uuX u,u1}.

Lemma 171.18 — Closure

For X,Y(R+)I: XY implies YX; XX⟂⟂; and X⟂⟂⟂=X.

Proof of Lemma 171.18 — Closure

Proof. The first two claims are immediate from the definition. For the third, apply the second to X to get XX⟂⟂⟂, and apply the first to XX⟂⟂ to get X⟂⟂⟂X. ◻

Definition 171.19 — Probabilistic coherence space

A probabilistic coherence space is a pair X=(|X|,PX) where |X| is a countable set, called the web, and PX(R+)|X| satisfies

  1. PX⟂⟂=PX;

  2. for every a|X| there is uPX with ua>0;

  3. for every a|X| there is Aa>0 with uaAa for all uPX.

Clause (i) is a closure condition; clauses (ii) and (iii) say that no web point is unusable and that no coordinate is unbounded. Both are used below: (iii) bounds the coefficients of the power series to come, and (ii), sharpened in lemma 171.25, provides the arguments at which those series are compared.

Lemma 171.20 — Downward closure and increasing limits

Let X be a probabilistic coherence space. If uv coordinatewise and vPX, then uPX; in particular 0PX. If u(0)u(1) all lie in PX, then their coordinatewise supremum lies in PX.

Proof of Lemma 171.20 — Downward closure and increasing limits

Proof. For uPX we have u,uv,u1, so uPX⟂⟂=PX. Taking vPX — one exists by (ii) — and u=0 gives 0PX. For the supremum w=supku(k) and uPX, w,u=a(supkua(k))ua=monotoneconvergencesupku(k),u1, so wPX⟂⟂=PX. ◻

Example 171.21 — The ground space

Let N=(N,PN) with PN={u(R+)Nnun1}, the set of subprobability distributions on N. Then PN=[0,1]N: if un1 for all n then u,unun1 for uPN; conversely enPN, where (en)m=1 when m=n and 0 otherwise, and en,u=un1. Applying again, PN⟂⟂={uu[0,1]N nunun1}=PN, the second equality because taking u with un=1 for nk and 0 beyond gives nkun1 for every k. Clause (ii) holds with u=ea and clause (iii) with Aa=1. So N is a probabilistic coherence space, and its elements are exactly the result distributions permitted by definition 171.8.

A morphism must send PX to PY, preserve increasing limits, and compose. Power series with nonnegative coefficients do all three, and the exponents are recorded by finite multisets.

Definition 171.22 — Multisets and monomials

A finite multiset over a set I is a function μ:IN with finite support supp(μ)={aμ(a)>0}; write Mfin(I) for the set of these and #μ=aμ(a) for the cardinality. For u(R+)I put uμ=asupp(μ)uaμ(a), with uμ=1 when μ is empty.

Definition 171.23 — The function form of a matrix, and the arrow

Let X,Y be probabilistic coherence spaces. For t(R+)Mfin(|X|)×|Y| define t^(u)b=μMfin(|X|)tμ,buμ(u(R+)|X|, b|Y|), a sum of nonnegative terms, hence a well-defined element of (R+{})|Y|. Set XY=(Mfin(|X|)×|Y|,P(XY)),P(XY)={tuPX t^(u)PY}.

Proposition 171.24 — The arrow is a probabilistic coherence space

Let X and Y be probabilistic coherence spaces such that, for every finite F|X| and every finite F|Y|, there are ε>0 and ε>0 with ε1FPX and ε1FPY, where 1F is the indicator vector of F. Then XY is a probabilistic coherence space, and it satisfies the same finite-support condition: for every finite GMfin(|X|)×|Y| there is η>0 with η1GP(XY).

Proof of Proposition 171.24 — The arrow is a probabilistic coherence space

Proof. Closure. For u(R+)|X| and v(R+)|Y| let uv be the vector on the web of XY with (uv)(μ,b)=uμvb. Then t,uv=μ,btμ,buμvb=b(μtμ,buμ)vb=t^(u),v, the middle step by rearranging a double sum of nonnegative terms. Hence t^(u)PY=PY⟂⟂ for all uPX if and only if t,uv1 for all uPX and vPY, that is, if and only if tZ for Z={uvuPX, vPY}. So P(XY)=Z, which is biorthogonally closed by lemma 171.18.

Clause (ii). Fix (μ,b). By clause (iii) for X, put Cμ=asupp(μ)Aaμ(a)>0, so that uμCμ for every uPX. By hypothesis choose ε>0 with εebPY, and set t=(ε/Cμ)e(μ,b). Then t^(u)=(ε/Cμ)uμebεeb, which lies in PY by lemma 171.20; and tμ,b>0.

Clause (iii). Fix (μ,b) and let F=supp(μ). By hypothesis choose δ>0 with u=δ1FPX. For any tP(XY), dropping all summands but one, t^(u)b  tμ,b(u)μ=tμ,bδ#μ, while t^(u)bAb by clause (iii) for Y. Hence tμ,bAbδ#μ, a bound depending only on (μ,b).

Finite supports. Let G be finite, let G2={bμ (μ,b)G}, and let C=max{Cμ(μ,b)G} with Cμ as above. Choose ε>0 with ε1G2PY and put η=ε/(|G|C). For uPX, η1G^(u)b=ημ:(μ,b)Guμη|G|C=ε for bG2 and 0 otherwise, so η1G^(u)ε1G2PY, and lemma 171.20 finishes. ◻

Lemma 171.25 — The invariants of the interpreted types

Define [[ι]]=N and [[στ]]=[[σ]][[τ]]. Then for every type σ, the pair [[σ]] is a probabilistic coherence space, and for every finite F|[[σ]]| there is ε>0 with ε1FP[[σ]].

Proof of Lemma 171.25 — The invariants of the interpreted types

Proof. Induction on σ. For ι, example 171.21 gives the space, and ε=1/|F| makes ε1F a subprobability distribution. For στ the induction hypothesis supplies both components of the hypothesis of proposition 171.24, whose conclusion is exactly the claim. ◻

The next theorem is the reason the model can decide an equivalence. It says that a morphism is recoverable from the function it induces, so that two programs with different matrices differ at some argument — and, as the proof shows, at an argument with rational coordinates and finite support, which is the kind of argument a pPCF program can produce.

Lemma 171.26 — Coefficients from values

Let I be a finite set, A>0, and let (cν)νMfin(I) and (cν)ν be families of nonnegative reals such that f(x)=νcνxν and f(x)=νcνxν are finite for all x[0,A]I. If f=f on [0,A]I then cν=cν for every ν.

Proof of Lemma 171.26 — Coefficients from values

Proof. Induction on |I|. If I= both sums have the single term c=f=f=c.

Let |I|=k+1 and fix aI, writing I=I{a} and x=(xa,x). Grouping the terms by the exponent of xa, f(xa,x)=m=0gm(x)xam,gm(x)=ν:νMfin(I)cν+ma(x)ν, where ν+ma is the multiset ν extended by m copies of a; the rearrangement is legitimate because all terms are nonnegative and the total sum is finite. Fix x[0,A]I. Then xaf(xa,x) is a power series in one variable with nonnegative coefficients gm(x), convergent on [0,A]; inside its interval of convergence it may be differentiated term by term, so gm(x)=1m!xamf(0,x). The same computation applies to f, and f=f gives gm(x)=gm(x) for every m and every x[0,A]I. Each pair gm,gm satisfies the hypotheses of the lemma on I, so the induction hypothesis gives cν+ma=cν+ma for all ν and m. Every νMfin(I) has this form. ◻

Theorem 171.27 — Determination

Let X,Y satisfy the hypotheses of proposition 171.24 and let t,tP(XY). Then t=t as matrices if and only if t^=t^ as functions PXPY. Moreover, if tt then already t^(u)t^(u) for some uPX with finite support and rational coordinates.

Proof of Theorem 171.27 — Determination

Proof. One direction is trivial. For the other, suppose tμ,btμ,b for some (μ,b), and let I=supp(μ), a finite set. By proposition 171.24 there is δ>0 with δ1IPX, and by lemma 171.20 every u supported in I with coordinates at most δ lies in PX. Consider f(x)=t^(x)b=νMfin(I)tν,bxν,f(x)=t^(x)b,x[0,δ]I, where a vector x on I is read as the element of (R+)|X| that vanishes outside I; only multisets over I contribute, since xν=0 as soon as ν charges a point outside I. Both are finite on [0,δ]I, being coordinates of elements of PY, which are bounded by clause (iii). Their coefficients differ at μ, so lemma 171.26 gives a point of [0,δ]I at which ff. Both are continuous on that closed box: with Mν=tν,bδ#ν one has |tν,bxν|Mν for every x[0,δ]I, and νMν=f(δ,,δ)<, so the series converges uniformly on the box and its partial sums are polynomials. Hence the set where f and f differ is a nonempty relatively open subset of [0,δ]I and therefore contains a point with rational coordinates. That point is supported in the finite set I. ◻

Remark 171.28 — What the model is, and what is imported

Definition 171.19, Definition 171.23 are Ehrhard–Pagani–Tasson’s probabilistic coherence spaces and the function form of the Kleisli morphisms of the exponential comonad; their XY=!XY has the web and the elements printed above, and their Theorem 11 states the bijection between matrices and their function forms which theorem 171.27 proves here for the interpreted types. The following facts about that model are imported and used with no further appeal to linear logic: for each type σ the space [[σ]] of lemma 171.25 is their interpretation of σ; for each typing derivation of ΓM:σ there is a matrix [[M]]ΓP([[Γ]][[σ]]), where [[Γ]] is the space of tuples (u1,,uk) with uiP[[σi]], whose function form obeys the clauses of definition 171.29; and their Theorem 11 identifies equality of matrices with equality of function forms. Everything proved after definition 171.29 uses only those clauses, the invariants of lemma 171.25, and theorem 171.27.

Definition 171.29 — Interpretation of terms

For ΓM:σ with Γ=(x1:σ1,,xk:σk), the function form of [[M]]Γ is written [[M]]Γ(u)P[[σ]] for u=(u1,,uk) with uiP[[σi]], and satisfies [[xi]]Γ(u)=ui,[[n]]Γ(u)=en,[[coin(p)]]Γ(u)=pe0+(1p)e1,[[succ(P)]]Γ(u)=nN[[P]]Γ(u)nen+1,[[PQ]]Γ(u)=[[P]]Γ(u)^([[Q]]Γ(u)),[[λxσ.P]]Γ(u)^(v)=[[P]]Γ,x:σ(u,v), [[if(P,Q,zR)]]Γ(u)=[[P]]Γ(u)0[[Q]]Γ(u)+nN[[P]]Γ(u)n+1[[R]]Γ,z:ι(u,en), [[fix(P)]]Γ(u)=supmNfm(0),f(v)=[[P]]Γ(u)^(v). In the clause for fix the sequence mfm(0) is nondecreasing because f is monotone — its coefficients are nonnegative — and 0f(0); its supremum lies in P[[σ]] by lemma 171.20.

Example 171.30 — The model computes the geometric distribution

Continue example 171.5. Write P=λgι.if(coin(1/2),0,zsucc(g)), so that G=fix(P). For vPN the clauses give f(v)=[[P]]^(v)=λ[[if(coin(1/2),0,zsucc(g))]]g:ι(v)=if,coin12e0+12nvnen+1, because [[coin(1/2)]]0=[[coin(1/2)]]1=1/2 and all further coefficients vanish, and because the branch succ(g) is interpreted at the single argument e0 supplied by the summand n=0. Iterating from 0, f1(0)=12e0,f2(0)=12e0+14e1,,fm(0)=n<m2(n+1)en, so [[G]]=supmfm(0) has [[G]]n=2(n+1). This is the distribution computed operationally in example 171.10. The agreement is not an accident of this program; it is the adequacy theorem of section 171.5.

Exercise 171.10

★☆☆ Compute [[pred]]^(u) for uPN from definition 171.29, and check the value at u=e3 against exercise 171.1.

Exercise 171.11

★☆☆ Compute [[Ωσ]] for every type σ, and state which clause of definition 171.29 forces the answer.

Exercise 171.12

★★☆ Let g:[0,1][0,1] be g(u)=0 for u1/2 and g(u)=2u1 for u>1/2. Show that g is monotone and preserves suprema of increasing sequences, and that there is no tP(NN) with t^(u)0=g(u0) and t^(u)n=0 for n>0. (Use lemma 171.26 at the point 1/2.) Conclude that the model is not the model of all monotone continuous maps.

Exercise 171.13

★★☆ Prove [[probk]]^(u)=uke0 for every uPN, by induction on k using definition 171.29.

Adequacy

Example 171.30 computed the same distribution twice, once by summing path weights and once by iterating a power series. The two computations must agree for every closed term of ground type. One inequality follows from a single invariance equation; the other needs a logical relation, because a term of higher type has no result distribution of its own.

Lemma 171.31 — Substitution

If Γ,x:σM:τ and ΓP:σ, then for all u, [[M[P/x]]]Γ(u)=[[M]]Γ,x:σ(u,[[P]]Γ(u)).

Proof of Lemma 171.31 — Substitution

Proof. Induction on M. Variable case. For M=x both sides are [[P]]Γ(u) by the variable clause; for M=xi with xix both sides are ui. Application case. [[(M1M2)[P/x]]]Γ(u)=substitution[[M1[P/x]M2[P/x]]]Γ(u)=definition171.29[[M1[P/x]]]Γ(u)^([[M2[P/x]]]Γ(u))=IHtwice[[M1]]Γ,x:σ(u,w)^([[M2]]Γ,x:σ(u,w))=definition171.29[[M1M2]]Γ,x:σ(u,w), writing w=[[P]]Γ(u). Binder case. For M=λyρ.M1 with y chosen outside FV(P){x}dom(Γ), the abstraction clause evaluates both sides at an arbitrary vP[[ρ]] and the induction hypothesis for M1 in the context Γ,y:ρ applies; the two function forms agree at every v, hence the two matrices agree by theorem 171.27. The remaining formers — numerals, coins, succ, if, fix — are treated as the application case: each clause is built from the interpretations of the immediate subterms by an operation not depending on the substituted term, so the induction hypothesis may be applied to each subterm in turn. In the if case the third subterm is interpreted in the context extended by z:ι, and the argument supplied for z is en, which does not involve P. ◻

Theorem 171.32 — Invariance under one step

If ΓM:σ then [[M]]Γ=MΛΓσRed(Γ,σ)M,M[[M]]Γ, an equation between matrices, in which the sum has at most two nonzero terms.

Proof of Theorem 171.32 — Invariance under one step

Proof. Induction on M. If M is weak-normal the right-hand side is 1[[M]]Γ. There remain the terms with a leftmost outermost redex.

Coin. coin(p)p0 and coin(p)1p1, so the right-hand side is pe0+(1p)e1, which is [[coin(p)]]Γ by definition 171.29.

Beta. (λxσ.P)N has the unique successor P[N/x] with label 1, and [[(λxσ.P)N]]Γ(u)=definition171.29[[λxσ.P]]Γ(u)^([[N]]Γ(u))=λclause[[P]]Γ,x:σ(u,[[N]]Γ(u))=lemma171.31[[P[N/x]]]Γ(u).

Fixed point. fix(P) has the unique successor Pfix(P) with label 1. With f=[[P]]Γ(u)^, [[Pfix(P)]]Γ(u)=definition171.29f(supmfm(0))=monotoneconvergencesupmfm+1(0)=f0(0)=0supmfm(0)=definition171.29[[fix(P)]]Γ(u), where the second step holds because each coefficient of f(v) is a sum of nonnegative monomials in the coordinates of v, and such a sum commutes with the supremum of a nondecreasing sequence.

Successor at a numeral, conditional at a numeral. succ(n) has successor n+1, and [[succ(n)]]Γ=en+1 by the succ clause applied to en. For if(0,P,zR) the successor is P, and the if clause at [[0]]=e0 leaves the single summand [[P]]Γ. For if(n+1,P,zR) the successor is R[n/z], and the same clause at en+1 leaves [[R]]Γ,z:ι(u,en), which is [[R[n/z]]]Γ(u) by lemma 171.31.

Context cases. Let M be one of M1N, succ(M1), if(M1,P,zR) with M1 not weak-normal. Then M is not weak-normal, its successors are obtained from those of M1 by the same construction, and the labels are unchanged, so RedM,M=Red(Γ,ι)M1,M1 for the matching successor M. In each of the three clauses the interpretation of M is obtained from the matrix [[M1]]Γ by an operation that is linear in it: for the successor and the conditional this is visible in the displayed formulas, and for the application it is the identity (iλiti)^(v)=iλit^i(v), which holds because t^(v)b=μtμ,bvμ is linear in t. Applying that linear operation to the induction hypothesis for M1 gives the claim for M. ◻

Theorem 171.33 — The model dominates the operational semantics

If M:ι then Red(ι)M,n[[M]]n for every nN.

Proof of Theorem 171.33 — The model dominates the operational semantics

Proof. Iterating theorem 171.32 k times gives [[M]]=MRed(ι)M,Mk[[M]]. All summands are nonnegative, so keeping only M=n and reading the coordinate n, for which [[n]]n=1, gives [[M]]nRed(ι)M,nk. Take the supremum over k; by definition 171.8 it is Red(ι)M,n. ◻

The converse inequality cannot be proved by the same route: iterating an equation produces upper bounds on operational quantities, not lower bounds, and a term of type στ has no operational quantity at all until it is applied. The standard repair is a relation, defined by induction on types, that says at ground type “the model underestimates the operational probabilities” and at higher type “the term maps related arguments to related results”.

Definition 171.34 — The adequacy relation

For each type σ define RσΛ0σ×P[[σ]] by MRιunNunRed(ι)M,n,MRστtPΛ0σ uP[[σ]](PRσuMPRτt^(u)).

Lemma 171.35 — Zero and limits

For every type σ and every MΛ0σ: first, MRσ0; second, if u(0)u(1) in P[[σ]] and MRσu(i) for all i, then MRσsupiu(i).

Proof of Lemma 171.35 — Zero and limits

Proof. Induction on σ. At ι the first claim is 0Red(ι)M,n and the second is the statement that a supremum of numbers each bounded by Red(ι)M,n is bounded by it. At στ: for the first claim, 0^(u)=0 and the induction hypothesis at τ gives MPRτ0. For the second, let PRσu; then supit(i)^(u)=supit(i)^(u), because each coefficient is a sum of nonnegative terms and commutes with the supremum of a nondecreasing sequence, and the induction hypothesis at τ applies to the sequence t(i)^(u). ◻

Lemma 171.36 — Convergence through a conditional

Let M:ι, P:σ and z:ιQ:σ with σ=σ1σhι, and let Nj:σj for j=1,,h. Then for every nN, Red(ι)if(M,P,zQ)N1Nh,n=Red(ι)M,0Red(ι)PN1Nh,n+kNRed(ι)M,k+1Red(ι)Q[k/z]N1Nh,n.

Proof of Lemma 171.36 — Convergence through a conditional

Proof. Write E[] for the evaluation context []N1Nh. By Ctx-App and Ctx-If, every step of E[if(M,P,zQ)] is either a step of M copied with the same label, or — once M has become a numeral — the contraction of the conditional. A path from E[if(M,P,zQ)] to n therefore factors uniquely as a path of M to some numeral m, the contraction of the conditional, and a path from E[P] (if m=0) or from E[Q[m1/z]] (if m>0) to n. The weight of the composite path is the product of the weights of the factors, so summing over all paths by lemma 171.9 and grouping by m gives the displayed equation. ◻

Lemma 171.37 — One step backwards

Let M,MΛ0σ and uP[[σ]]. If MRσu then MRσRed(σ)M,Mu.

Proof of Lemma 171.37 — One step backwards

Proof. Induction on σ. Ground case. Let σ=ι and nN. Because n is weak-normal, Red(ι)M,n=MRed(ι)M,MRed(ι)M,n, all terms being nonnegative; keeping the summand M=M and using unRed(ι)M,n gives Red(ι)M,MunRed(ι)M,n, which is the claim.

Arrow case. Let σ=τφ. If M is weak-normal, then either M=M and Red(σ)M,M=1, so the hypothesis is the conclusion; or MM and Red(σ)M,M=0, so the conclusion is MRσ0, which is lemma 171.35. Assume M is not weak-normal and let PRτv. Since the leftmost outermost redex of MP is that of M, the rule Ctx-App gives Red(φ)MP,MP=Red(σ)M,M. By hypothesis MPRφu^(v), so the induction hypothesis at φ gives MPRφRed(σ)M,Mu^(v), and Red(σ)M,Mu^(v)=(Red(σ)M,Mu)^(v) by linearity of tt^(v). ◻

Theorem 171.38 — Fundamental lemma

Let ΓM:σ with Γ=(x1:σ1,,xl:σl). For all closed terms PiΛ0σi and all uiP[[σi]], (i PiRσiui)M[P1/x1,,Pl/xl]Rσ[[M]]Γ(u1,,ul).

Proof of Theorem 171.38 — Fundamental lemma

Proof. Induction on the typing derivation. Write θ for the substitution [P1/x1,,Pl/xl] and assume PiRσiui throughout.

Variables and numerals. xiθ=Pi and [[xi]]Γ(u)=ui. For n, [[n]]Γ(u)=en and Red(ι)n,n=1.

Coin. coin(p)θ=coin(p) and its result distribution is p at 0, 1p at 1, and 0 elsewhere, which is exactly [[coin(p)]]Γ(u).

Successor. By the induction hypothesis [[P]]Γ(u)nRed(ι)Pθ,n for all n. Every path of Pθ to n yields, under Ctx-Succ followed by the contraction succ(n)0n+1, a path of succ(Pθ) to n+1 of the same weight, so [[succ(P)]]Γ(u)n+1Red(ι)succ(Pθ),n+1; at index 0 the left-hand side is 0.

Conditional. Let M=if(P,Q,zR) at type σ=σ1σhι. The induction hypothesis gives [[P]]Γ(u)mRed(ι)Pθ,m (mN),QθRσ[[Q]]Γ(u),Rθ[k/z]Rσ[[R]]Γ,z:ι(u,ek), the third by applying the induction hypothesis in the context Γ,z:ι with the pair kRιek. Let NjRσjvj for jh and let nN. Lemma 171.36 expands Red(ι)MθN1Nh,n into the two groups of summands displayed there; bounding each factor from below by the corresponding denotational quantity, and using the definition of Rσ for Qθ and for each Rθ[k/z], gives Red(ι)MθN1Nh,n  ([[P]]Γ(u)0[[Q]]Γ(u)+k[[P]]Γ(u)k+1[[R]]Γ,z:ι(u,ek)) ^(v1)(vh)n, whose right-hand side is [[M]]Γ(u) ^(v1)(vh)n by the if clause. This is the definition of MθRσ[[M]]Γ(u).

Application. For M=PQ, the induction hypothesis gives PθRτσ[[P]]Γ(u) and QθRτ[[Q]]Γ(u); the definition of R at the arrow type applied to this pair gives PθQθRσ[[P]]Γ(u)^([[Q]]Γ(u)), and the right-hand side is [[PQ]]Γ(u).

Abstraction. For M=λxτ.P at type τφ, let t=[[M]]Γ(u) and let QRτv. Since (λxτ.Pθ)Q0Pθ[Q/x] with label 1, lemma 171.37 reduces the goal (λxτ.Pθ)QRφt^(v) to Pθ[Q/x]Rφt^(v), and t^(v)=[[P]]Γ,x:τ(u,v) by the abstraction clause, so the induction hypothesis in the extended context finishes the case.

Fixed point. For M=fix(P) let t=[[P]]Γ(u) and f=t^. By lemma 171.35 it suffices to prove fix(Pθ)Rσfm(0) for every m, and this is an induction on m. The case m=0 is lemma 171.35. Assume fix(Pθ)Rσfm(0). Since fix(Pθ)0Pθfix(Pθ) with label 1, lemma 171.37 reduces the goal at m+1 to Pθfix(Pθ)Rσfm+1(0). The outer induction hypothesis gives PθRσσt, which applied to the pair fix(Pθ)Rσfm(0) yields exactly Pθfix(Pθ)Rσf(fm(0)). ◻

Theorem 171.39 — Adequacy

If M:ι then Red(ι)M,n=[[M]]n for every nN.

Proof of Theorem 171.39 — Adequacy

Proof. Theorem 171.38 with the empty context gives MRι[[M]], that is [[M]]nRed(ι)M,n. Theorem 171.33 gives the reverse inequality. ◻

Lemma 171.40 — Contexts act on denotations

Let ΓCΔτ:σ. There is a function fC such that [[C[M]]]Γ=fC([[M]]Δ) for every MΛΔτ.

Proof of Lemma 171.40 — Contexts act on denotations

Proof. Induction on the derivation of ΓCΔτ:σ. For the hole, C=[]Δτ and C[M]=M with Γ=Γ,Δ; take fC to be the map that reads [[M]]Δ and returns the interpretation of M in the larger context, which the clauses of definition 171.29 obtain by ignoring the extra coordinates. For every other rule, C is a term former applied to smaller contexts C1,,Cr and possibly to terms not containing the hole; the corresponding clause of definition 171.29 expresses [[C[M]]]Γ as an operation applied to [[Ci[M]]]Γ and to interpretations of hole-free subterms, and composing that operation with the functions fCi given by the induction hypothesis produces fC. ◻

Theorem 171.41 — Denotational equality implies observational equivalence

Let M,MΛΓσ. If [[M]]Γ=[[M]]Γ then MM.

Proof of Theorem 171.41 — Denotational equality implies observational equivalence

Proof. Let CΓσ be an observation context with CΓσ:ι. Then Red(ι)C[M],0=theorem171.39[[C[M]]]0=lemma171.40fC([[M]]Γ)0=hypothesisfC([[M]]Γ)0=lemma171.40[[C[M]]]0=theorem171.39Red(ι)C[M],0. ◻

Exercise 171.14

★☆☆ Compute [[M]] and [[N]] for the two terms of example 171.16 and conclude MN from theorem 171.41. State which single hypothesis of theorem 171.41 the four hand computations of example 171.16 do not establish.

Exercise 171.15

★★☆ Deduce from theorem 171.39 that the probability that a closed M:ι converges to some numeral equals n[[M]]n, and compute that number for H of exercise 171.5.

Exercise 171.16

★★☆ In the context cases of theorem 171.32, the application case used linearity of tt^(v) in the matrix t. Show by example that the map tt^ is not linear in the argument: exhibit tP(NN) and u,vPN with t^(12u+12v)12t^(u)+12t^(v).

Separating two denotations by a program

Theorem 171.41 settles one implication. Its converse — if no context separates M from M, then their denotations are equal — is what makes the model an answer to the original question rather than an approximation to it. Its proof must, from a single web point a at which two elements w,wP[[σ]] differ, manufacture a pPCF program that observes the difference.

Two obstructions stand in the way, and the construction is determined by removing them.

First, the coefficient wa is not the value of any definable map at any argument. A closed term F of type σι has [[F]]^(w)0=μtμ,0wμ, a sum of monomials in the coordinates of w; no such sum is the single coordinate wa. The repair is not to read wa off but to expose it as a coefficient: build a family of programs, indexed by a supply of randomness uPN, whose observation is a power series in u in which the coefficient of one designated monomial is exactly wa. Lemma 171.26 then converts a difference of coefficients into a difference of values at a rational argument, and ran below turns a rational argument into a program.

Second, the designated monomial must be multilinear, u0u1un1, with each parameter used once. A parameter consumed twice would contribute ui2 and land in a different coefficient. Since a web point of an arrow type carries several subtests — one for each element of the multiset in its domain component, and one for its codomain component — each subtest must read a block of parameters disjoint from every other block. That constraint determines the whole shape of the construction: a counter |a|± that records how many parameters a test consumes, and a shift operator that moves a test onto its own block.

Definition 171.42 — Auxiliary programs

Define closed terms and record their denotations, each computed from definition 171.29 by induction on the index: shift0=λxι.x,shiftk+1=λxι.succ(shiftkx),[[shiftk]]^(u)=nunen+k;prod0=0,prodk+1=λxι.if(x,prodk,zΩ),[[prodk]]^(u1)(uk)=(i=1ku0i)e0 choose0=λξι.Ωσ,choosek+1=λξι.λx1σ.λxk+1σ.if(ξ,x1,ζchoosekζx2xk+1), with [[choosek]]^(u)(w1)(wk)=i=0k1uiwi+1, where shiftk:ιι, prodk:ιιι with k arguments, and choosek:ισσσ with k arguments of type σ. Finally, for rationals p0,,pn[0,1] with p0++pn1, define ran(p0,,pn)={0if p0=1,if(coin(p0),0,zΩι)if n=0,if(coin(p0),0,zsucc(ran(p)))otherwise, where p=(p11p0,,pn1p0), so that [[ran(p0,,pn)]]=i=0npiei.

Proof of Definition 171.42 — Auxiliary programs

Verification of the four denotations. For shiftk: at k=0 the abstraction clause gives the identity function; at k+1 the succ clause shifts the induction hypothesis by one index. For prodk: at k=0 the value is e0, the empty product; at k+1 the if clause selects u01 times the interpretation of prodk and discards the diverging branch, since [[Ω]]=0 by exercise 171.11. For choosek: at k=0 the value is 0; at k+1 the if clause contributes u0w1 from the zero branch and, from the summand indexed m+1, the value um+1 times the interpretation of choosekmw2, which the induction hypothesis evaluates to wm+2 for m+1k. For ran: the first clause is immediate, the second gives p0e0, and in the third the coin contributes p0e0 from the zero branch and (1p0) times the shifted interpretation of the recursive call from the other, which is (1p0)i1pi1p0ei. ◻

Definition 171.43 — Counters and testing terms

For a type σ and a|[[σ]]| define natural numbers |a|+,|a| and closed terms a+,a with a+:ισ and a:ισι, by mutual induction on σ.

At σ=ι a web point is a natural number m, and |m|+=|m|=0,m+=λξι.m,m=λξι.probm. At σ=φψ a web point is a pair a=([b1,,bk],c) with bi|[[φ]]| and c|[[ψ]]|, and |a|+=|c|++i=1k|bi|,|a|=|c|+k+i=1k|bi|+. Writing βi=j<i|bj| and γi=k+j<i|bj|+, a+=λξι.λxφ.if( prodk(b1ξx)(b2(shiftβ2ξ)x)(bk(shiftβkξ)x),c+(shiftβk+1ξ), zΩψ), a=λξι.λfφψ. c(shiftγk+1ξ)(f(choosekξ(b1+(shiftγ1ξ))(bk+(shiftγkξ)))). Write u{p} for the shifted supply, (u{p})i=ui+p. Reading the clauses of definition 171.29 through definition 171.42 gives, for uPN, wP[[φ]] and tP[[φψ]], [[a+]]^(u)(w)=i=1k[[bi]]^(u{βi})(w)0[[c+]]^(u{βk+1}), [[a]]^(u)(t)=[[c]]^(u{γk+1})(t^(i=1kui1[[bi+]]^(u{γi}))).

The two displays record where each block of parameters goes. The test a spends its first k parameters u0,,uk1 on choosek, which decides which of the k arguments is offered to f; it then gives the i-th argument-builder bi+ the block starting at γi, and the codomain test c the block starting at γk+1. The blocks are consecutive and disjoint, which is what makes the designated monomial multilinear.

Lemma 171.44 — Parameter budget

Say that a closed F with F:ιρ depends on at most n parameters when [[F]]^(u)=[[F]]^(un) for all uPN, where (un)i=ui for i<n and 0 otherwise. Then a+ depends on at most |a|+ parameters and a on at most |a| parameters.

Proof of Lemma 171.44 — Parameter budget

Proof. Induction on σ. At ι, the interpretations [[m+]]^(u)=em and [[m]]^(u)(w)=wme0 do not mention u, and |m|±=0.

At φψ, read the second display of definition 171.43. The coordinates of u that occur are u0,,uk1; those occurring in [[bi+]]^(u{γi}), which by the induction hypothesis are among uγi,,uγi+|bi|+1, that is among uγi,,uγi+11; and those occurring in [[c]]^(u{γk+1}), which are among uγk+1,,uγk+1+|c|1. The union of these index sets is {0,,|a|1} because γk+1+|c|=k+i|bi|++|c|=|a|. The argument for a+ is the same computation with β in place of γ and |a|+=βk+1+|c|+. ◻

Example 171.45 — The designated coefficient at the first arrow type

Let σ=ιι and a=([m],c), so k=1, |b1|+=|c|=0 and |a|=1. The displays give, for tP[[σ]], [[a]]^(u)(t)=definition171.43[[c]]^(u{1})(t^(u0em))=groundcaset^(u0em)ce0=definition171.23(j0tj[m],cu0j)e0, where j[m] is the multiset with j copies of m; every other multiset contributes 0 because (u0em)μ=0 unless supp(μ){m}. The coefficient of the multilinear monomial u0 is t[m],c=ta. This is the pattern that the general lemma establishes at every type: the designated monomial reads off the designated coefficient.

Convention 171.46 — The imported coefficient lemma

The following is Ehrhard–Pagani–Tasson’s Lemma 26 together with the coefficient computation opening their §4.3.1, imported at exactly this signature. For every type σ, every a|[[σ]]| with n=|a|, and every wP[[σ]], the function u[[a]]^(u)(w)0 is, by lemma 171.44, a power series with nonnegative coefficients in u0,,un1; the coefficient of the multilinear monomial u0u1un1 in that series equals wa. What the source supplies is the combinatorial identification of that one coefficient, by an induction over σ that tracks how the multiset structure of a is distributed over the parameter blocks; example 171.45 verifies its conclusion at σ=ιι, and the ground case a=m, n=0 is the identity [[m]]^(u)(w)0=wm with the empty monomial. Everything below is proved from the statement just displayed.

Theorem 171.47 — Separation

Let σ be a type, a|[[σ]]|, n=|a|, and let w,wP[[σ]] satisfy wawa. Then there are rationals q0,,qn1[0,1] with iqi1 such that, for u=i<nqieiPN, [[a]]^(u)(w)[[a]]^(u)(w).

Proof of Theorem 171.47 — Separation

Proof. Put φ(x)=[[a]]^(x)(w)0 and φ(x)=[[a]]^(x)(w)0 for x ranging over the box B=[0,1/n]{0,,n1}, each such x being read as the element of (R+)N that vanishes from index n on. Every such x lies in PN, since i<nxin1n=1. By lemma 171.44 both functions are power series in x0,,xn1 with nonnegative coefficients, and both are finite on B, being coordinates of elements of PN. By convention 171.46 their coefficients at the monomial x0xn1 are wa and wa, which differ. By lemma 171.26 the two functions are not equal on B.

Both are continuous on B: with δ=1/n, the series νcνδ#ν converges, so the series converges uniformly on B by comparison, and each partial sum is a polynomial. Hence {xBφ(x)φ(x)} is a nonempty relatively open subset of B, and therefore contains a point q all of whose coordinates are rational. For that point, [[a]]^(q)(w)0[[a]]^(q)(w)0, which is stronger than the stated inequality. Finally i<nqi1 because qB. ◻

Theorem 171.48 — Observational equivalence implies denotational equality

Let M,MΛΓσ. If MM then [[M]]Γ=[[M]]Γ.

Proof of Theorem 171.48 — Observational equivalence implies denotational equality

Proof. Contrapositive. Assume [[M]]Γ[[M]]Γ with Γ=(x1:σ1,,xl:σl). Close both terms: N=λx1σ1.λxlσl.M and N=λx1σ1.λxlσl.M, both closed of type τ=σ1σlσ. By the abstraction clause of definition 171.29 and theorem 171.27, w=[[N]] and w=[[N]] differ, so wawa for some a|[[τ]]|. Let n=|a| and let q0,,qn1 be the rationals given by theorem 171.47, so that with u=i<nqiei, [[a]]^(u)(w)0[[a]]^(u)(w)0. By definition 171.42, u=[[ran(q0,,qn1)]]. Take the observation context CΓσ=aran(q0,,qn1)(λx1σ1.λxlσl.[]Γσ), which satisfies CΓσ:ι. Its two fillings have, by definition 171.29, [[C[M]]]=[[a]]^(u)(w) and [[C[M]]]=[[a]]^(u)(w). Hence Red(ι)C[M],0=theorem171.39[[C[M]]]0[[C[M]]]0=theorem171.39Red(ι)C[M],0, so M and M are not observationally equivalent. ◻

Corollary 171.49 — Equational full abstraction

For M,MΛΓσ: MM if and only if [[M]]Γ=[[M]]Γ.

Proof of Corollary 171.49 — Equational full abstraction

Proof. Theorem 171.41 and theorem 171.48. ◻

The boundary of the theorem

Corollary 171.49 is an equality of equivalences, not of orders, and it is proved for the frozen calculus of convention 171.1. Both restrictions are real.

Proposition 171.50 — The matrix order is finer than the pointwise order

Let M1=λxι.if(x,0,zΩι),M2=λxι.if(x,if(x,0,zΩι),zΩι). Then [[M1]]^(u)=u0e0 and [[M2]]^(u)=u02e0 for every uPN, so [[M2]]^(u)[[M1]]^(u) at every argument, while the matrices [[M1]] and [[M2]] are incomparable: the first has the entry 1 at ([0],0) and 0 at ([0,0],0), and the second the reverse.

Proof of Proposition 171.50 — The matrix order is finer than the pointwise order

Proof. The if clause of definition 171.29 applied to [[x]]x:ι(u)=u gives [[M1]]^(u)=u0e0+nun+10=u0e0, and applying it twice gives [[M2]]^(u)=u0(u0e0). Since u01 we have u02u0. The entries are read off definition 171.23: u0=u[0] and u02=u[0,0]. ◻

Remark 171.51 — No inequational statement is proved here

Write MM for the observational preorder: for every closed C with C:σι, Red(ι)CM,0Red(ι)CM,0. The argument of theorem 171.41 shows that [[M]][[M]] as matrices implies MM. Ehrhard–Pagani–Tasson state that the converse fails, and that the two terms of proposition 171.50 witness the failure with M2M1; they prove no inequational full-abstraction theorem, and neither does this chapter. Proposition 171.50 records what is proved here: the order that corollary 171.49 does not characterize is already visible in the model, because pointwise domination of function forms does not imply domination of matrices.

Remark 171.52 — What does not transfer

Every theorem of this chapter is stated for convention 171.1. Three extensions change the mathematics rather than the notation. A continuous sampler makes the space of results uncountable, so the web of definition 171.19 — a countable set — no longer indexes it, and the coefficient-extraction argument of theorem 171.47 has nothing to extract. A scoring or conditioning construct produces unnormalized weights above 1, so PN is no longer the space of results and the mass bound of lemma 171.7 fails. A dependent or effectful successor calculus changes the typing judgment on which every induction in this chapter is performed. No theorem proved here is claimed for such a calculus without a translation proved to preserve the operational quantity Red(ι),0.

Exercise 171.17

★☆☆ Take σ=ι and a=m. Write out theorem 171.47 in this case, and check that the separating observation context produced by the proof of theorem 171.48 is probm[].

Exercise 171.18

★★☆ Compute |a| and |a|+ for a=([[0],0],0)|[[(ιι)ι]]|, and list which parameter block each subtest of a reads.

Exercise 171.19

★★☆ Modify definition 171.43 by deleting every shift, so that all subtests read the same parameters. Recompute example 171.45 for a=([m,m],c) with mm and exhibit two distinct web points whose designated coefficients then collide in the same monomial. State which step of the proof of theorem 171.47 the modification breaks.

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 171.20, then exercise 171.21, then the practical project exercise 171.25.

Exercise 171.20

★☆☆ For the two terms of example 171.16 and the two contexts C0=prob0[] and C1=prob1[], write the four complete reduction trees, label every edge with its probability, and confirm the four numbers 1/2 by lemma 171.9.

Exercise 171.21

★★☆ Write in full the case M=if(P,Q,zR) of theorem 171.38 for h=1, displaying the instance of lemma 171.36 used, the three consequences of the induction hypothesis, and the final inequality. State where the hypothesis kRιek is used.

Exercise 171.22

★★☆ Let Gp be the program of example 171.5 with coin(1/2) replaced by coin(p) for a rational p(0,1). Compute its result distribution operationally and its denotation, and determine for which pairs pp the observation context prob0[] separates Gp from Gp.

Exercise 171.23

★★☆ Exhibit a closed M:ι with [[M]]=0 that is not Ωι, prove MΩι using theorem 171.41, and explain why no finite set of observation contexts establishes this equivalence.

Exercise 171.24

★★★ Reconstruct the proof of theorem 171.47 for σ=ιι without appealing to convention 171.46: compute [[a]]^(u)(t) for a general a=([b1,,bk],c) at this type, identify the coefficient of u0uk1 directly, and carry out the analytic argument. State exactly which part of the general induction the computation replaces.

Exercise 171.25

★★★ Practical project.ppcf-exact-enumerator Build an exact enumerator for the recursion-free fragment of convention 171.1: numerals, variables, succ, coin(p) with p a reduced rational, if, abstraction, and application, extended by the closed terms prob0 and prob1 of definition 171.14 with Ωι represented as an explicit divergent constant. The program has three parts: a weak-reduction stepper implementing Det, Coin-0, Coin-1, Ctx-App, Ctx-Succ and Ctx-If with capture-avoiding substitution; an enumerator that accumulates path weights into a finite map from numerals to exact rationals, following lemma 171.9; and a stream-driven tracer that consumes a fixed list of bits and prints one line per draw, conditional and return.

The invariant to maintain is that the accumulated weights of a term never exceed 1 and that a term with no applicable rule contributes its own weight to the divergence mass rather than to any numeral. The concrete result is the pair of exact rational tables for M=coin(1/2) and N=if(coin(1/2),0,z1) together with the four context probabilities of example 171.16.

The acceptance test is decidable and exact: the tables for M and for N must both be {01/2, 11/2}; each of the four terms C0[M], C1[M], C0[N], C1[N] must have Red(ι),0=1/2; the trace on the bit stream beginning with 0 must be draw 0, cond 0, return 0 for N, and the trace on the stream beginning with 1 must be draw 1, cond 1, return 1; and the enumerator must report divergence mass 1/2 for if(coin(1/2),0,zΩι). All arithmetic is on reduced rationals; a frequency obtained by sampling is not an accepted answer, and the rational tables decide equality of result distributions only, not the universal quantification over contexts in definition 171.13.

Search the book

Type to search the local edition.