Lectures onType Theory
Solutions for Chapters 64–66
appendix sectionsolutions

Solutions for Chapters 64–66

exercise 64.1.

The supports are {b} and {b,c}, respectively. Moreover a(a,b)=c(c,b). To verify the equation, choose fresh d. Both transposition actions, (a d)(a,b) and (c d)(c,b), give (d,b). The second abstraction cannot equal c(c,b), because equal nominal elements have equal least support, while {b,c}{b}.

exercise 64.2.

Restriction at a discards z, retains the later fresh declaration of b, discards y, removes a, and returns x:X;fresh b:β. Restriction at b discards z, removes b, and returns x:X;fresh a:α,y:P(a). Rule R-Var discards y because P(a) may mention the name being removed; R-Name retains b because its freshness declaration is stable under removal of the earlier name.

exercise 64.3.

Assume Γ;fresh a:αM:B and Γrestrictb:αΓ. Name abstraction gives Γa:αM:Na:α.B, and concretion gives Γ(a:αM)@b:B[b/a]. The name-substitution instance of general substitution gives the same type to M[b/a], hence beta is typed. If M used a variable declared after b, it would not type in Γ, so the concretion premise would fail.

exercise 64.4.

Represent the terms as aba and cdc. Extend by one fresh e, restrict the extension back to the common prefix, and concrete both outer abstractions at e. Name beta gives be and de. Extensional equality at the inner abstraction type opens both at another fresh f, producing e on each side. Structural name comparison closes the derivation. The first opening is the explicit use of restriction.

exercise 64.5.

Frozen DNTT can introduce an abstraction and open it at a chosen literal, but it cannot inspect whether the opened body is that literal. The proposed function needs a name-equality/name-case eliminator. Adding it changes the canonical neutral heads, so algorithmic-equality completeness and adequacy must be proved again; normalization or canonicalization for the enlarged calculus must also be re-established.

exercise 65.1.

Unfold x.fx=gx; this is the one definition-dependent step. It says that the predicate λx.fx=gx equals the constantly true predicate. Rule COMB specializes this equality at fresh x, and EQ-MP with the closed proof of yields fx=gx. Rule ABS now gives equality of λx.fx and λx.gx. Eta rewrites both sides, and two uses of transitivity give f=g.

exercise 65.2.

For ABS, equality of the bodies in every environment satisfying Γ gives equality of the denoted functions. Freshness of x for Γ ensures that changing the argument does not change whether the assumptions hold. Without it, from assumption x=0 one could abstract the derivation of x=0 and conclude the false equation (λx.x)=(λx.0) on a type with two elements. For DEDUCT-ANTISYM, under the undischarged assumptions the first premise excludes (p,q)=(0,1) and the second excludes (1,0); hence their Boolean denotations agree. The requirement that assumptions and conclusions have type bool is essential to that truth-value argument.

exercise 65.3.

Transitivity follows pointwise from transitivity of equality on counts. The equation count(a,xs++ys)=count(a,xs)+count(a,ys) proves respectfulness. Apply rep to two lifted unions; their representatives have the same count at every a by commutativity of addition, so quotient extensionality gives AB=BA. Nonemptiness is used once to introduce the new HOL type and once to choose the default value of abs outside the representing subset.

exercise 65.4.

Use VecPred(A,n,xs)All(A,xs)length(xs)=n. A translated function f must satisfy n,xs.VecPred(A,n,xs)length(fnxs)=n+1, together with its chosen codomain predicate. HOL assigns f an ordinary simple type; dependency appears in the theorem guarding admissible arguments and results, not in its typing judgment.

exercise 65.5.

Beta is a primitive rule. Eta, choice, and infinity are closed axioms. Functional and propositional extensionality are derived theorems; the latter also uses the two-valued Boolean encoding. The choice function and the infinite set interpreting ind are semantic constructions that validate the corresponding axioms, not additional inference rules.

exercise 65.6.

The oracle lies inside the trusted base because it manufactures abstract theorem values without a kernel trace. Confinement is recovered exactly if every returned oracle(s) is semantically valid at its recorded assumptions and conclusion. Decidability, completeness, and termination of the oracle are unnecessary for soundness.

exercise 66.1.

Take F=RNN(λx.x)(λn.λh.λx.h(Sx)). Then F044, F14F054+1, and repeating gives F34F25F16F077.

exercise 66.2.

For candidate closure at στ, apply a reduct of the function to arbitrary uRσ and use closure at τ. For neutral expansion, reductions of tu reduce t, reduce u, or expose a head redex; induct lexicographically on the type and the sum of their finite reduction heights. Candidate fact 1 follows by applying an arrow term to a fresh reducible variable. Finally, reducible n is strongly normalizing. Every reduction of Sn is induced by a reduction of n, so Sn is strongly normalizing and therefore belongs to RN.

exercise 66.3.

The first formula becomes FNNn.P(n,Fn). The implication becomes U(NN)N,Y(NN)N F.(P(YF,F(YF))Q(UF)). Here U turns the premise’s candidate witness function into the existential witness for Q, while Y chooses the premise input to challenge.

exercise 66.4.

At zero choose zero. If m=n2, choose m+(n+n+1); arithmetic gives m+2n+1=(n+1)2. Extraction yields λn.RN0(λk.λr.r+(k+k+1))n. At 3 it reduces through accumulators 0,1,4,9. The reduction trace calculates the numeral; the target induction, using the recursor equations and ring equalities, proves that the numeral satisfies m=nn.

exercise 66.5.

The witness player maps a proposed witness x for A forward to Ux for B. Given a challenge v to that result, the same strategy maps backwards to Yxv, a challenge to A. For (nm.P(n,m))k.Q(k), deleting Y loses the input n=YF at which the premise function must be tested before concluding Q(UF).

exercise 66.6.

The chapter proves the direct HA-to-T theorem. The selected intensional, weakly extensional, and type-zero-equality higher-type variants, including HA0ω, admit corresponding direct variants. Full E-HAω first needs a formal interpretation into the type-zero-equality system at the stated low-type boundary. Classical arithmetic first needs negative translation. General countable choice and classical analysis are not covered here; their selected realizers use the separately developed bar-recursive extension.

exercise 67.1.

The final maximizing selector always chooses one. Hence the continuation at stage one is x13x0+x1+5, whose minimizing selector chooses zero. The first continuation is x03x0+5, so the maximizing selector chooses one. Thus the tuple is (1,0,1) and its score is eight. No comparison at stage zero is a tie, so reversing only its tie convention changes nothing.

exercise 67.2.

The printed test asks 2<2, which is false, and therefore computes c=ε2(p2) before recursing. The mutant asks 22, which is true, and returns the zero stream. Consequently the mutant may have α(2)=0X while the printed equation requires α(2)=ε2(p2). A selector that always returns 1X0X witnesses the failure.

exercise 67.3.

At |s|=2, qsω:XNXN×N,l:XN×NN, P:XXN×N,δ~s(P)=δs(λx.π1(Px)):X,c:X. The streams s(xβ) and (sx)β agree coordinatewise. For i<2, both return s(i); at i=2, both return x; and above two both return β(i3). Hence s(xβ)=(sx)β. Substitution of that identity into the definition of qsω gives (qsω)x=qsxω. Therefore the EPS recursive branch has exactly the child SBR call required by the SBR equation. Since that child has the form (sx)β, it already preserves s. Therefore put(s,SBRsx)=SBRsx, while the EPS branch is s(xβ)=(sx)β. This is the final prefix-preservation step.

exercise 67.4.

Choose n=α(0)+2. Since n1, the zero extension α^n retains coordinate zero, and ω(α^n)=α(0)+1<n. For the second specification, continuity at a stream with no zero would require a finite prefix deciding the value zero. Extend any such prefix by a zero at a later coordinate. The value then becomes that later index, a contradiction. Thus the finite observation bound used in lemma 67.15 is unavailable.

exercise 67.5.

Apply DNS to B(n)x.A(n,x): (n¬¬x.A(n,x))¬¬nx.A(n,x). Inside the final double negation, intuitionistic countable choice gives fn.A(n,fn), which is cACN. In Spector’s equations, εn is the premise selector, q is the outcome challenger, ω selects the challenged coordinate, α is the proposed choice sequence, and pn is its local counterexample continuation. A fixed horizon m fails for a control that reads coordinate m, as in proposition 67.7.

exercise 67.6.

Assume il(q(α)). If the stage-i call stopped, prefix factorization would give α=[α](i)0, and hence i>l(q[α](i)(0))=l(q(α))i, a contradiction. The recursive equation therefore gives α(i)=εi(pi). Prefix factorization at i+1 then rewrites the tail in pi(α(i)) to the tail of α, yielding pi(α(i))=q(α).

exercise 67.7.

At the all-one stream the proposed control returns one. For every finite prefix of that stream, append a zero beyond the prefix. The altered stream agrees on the entire observed prefix but receives value zero. Thus no finite observation determines the value at the all-one stream. Without continuity, Spector’s condition is not obtained, so D(s)ω(put(s,0))<|s| is not known to be a bar.

exercise 67.8.

The forward ledger is EPSSBR:R=XN×N,l=π2, qsω, δ~s; it is verified in finite-type arithmetic and uses neither BIrel nor SPEC. The reverse ledger is SBRBREPQepqepsEPS. The BREPQ and epqeps arrows use BIrel; the former also uses SPEC. The forward adapter therefore cannot establish the reverse arrow: definability in one direction is not symmetric.

exercise 68.1.

Write W for the loop followed by the final assertion and write A1,A2,D for the two body assertions and decrement. For input n, the loop-head stores are exactly (i,n), 0in. At every positive i, the reachable control suffixes are A1;A2;D;W,A2;D;W,D;W, all at store (i,n), followed by W at (i1,n); the while-unrolling conditional and the administrative skip;c residuals add no stores. At i=0, the false guard reaches the final assertion and then skip, still at (0,n). Taking n=0,1,2 gives the six distinct loop-head stores (0,0),(1,1),(0,1),(2,2),(1,2),(0,2). Each positive-body store satisfies 0in, and each exit store has i=0. Hence no reachable configuration is a predecessor of error.

exercise 68.2.

Let the bad entry be {0,+}{0,+}={0,+}. The smallest witness is 01=1: both operands lie in the declared concretizations, but the result does not. The best entry is αs{mnm,n0}={,0,+}, because 01, 00, and 10 witness the three signs.

exercise 68.3.

For decrement by one, the loop-head iteration is , then x,y[0,4], then the same store: the true filter gives x[1,4], decrement gives [0,3], and joining with entry restores [0,4]. The false filter gives x=[0,0]. Thus 0x and the final x=0 are proved; independent intervals report the relational assertion xy as possible error.

With decrement by two, the loop-head sequence is , [0,4], [1,4], then stable at [1,4] for x, while y=[0,4]. The true filter [1,4] maps to [1,2]; the false exit is [1,0]. Inputs 1 and 3 reach x=1, so both the body nonnegativity assertion and final equality can fail.

exercise 68.4.

Adjoin ± to the ordered threshold set T={1,0,1,10}. When a lower bound decreases, replace it by the greatest threshold not above the proposal; when an upper bound increases, replace it by the least threshold not below the proposal. Otherwise retain the old endpoint. The chosen interval contains both arguments, so coverage holds. Each endpoint moves only upward through the finite threshold list and then to infinity, so every finite product iteration terminates. On the counter chain the upper endpoints are 0,1,10,+, whereas ordinary widening jumps from 0 directly to +.

exercise 68.5.

Before assignment, intervals give x,y[0,+] and the DBM gives xy0. Assignment z:=y copies the entire row and column of y: Dzw=Dyw and Dwz=Dwy. Hence zy0, yz0, and closure with xy0 yields xz0, that is, xz. Interval reduction alone leaves z[0,+], but the relational component proves the comparison. The rule Dzw=Dyw while leaving the column of z unchanged is unsound: from y=0,z=1, executing z:=y makes yz=0, contradicting the retained old bound yz1.

exercise 68.6.

Before deleting u, add Borrow(a,p::q,b). Concretely, if a.p reaches the reference stored at u, and following q from that reference reaches the reference at b, then a.(p::q) reaches b. Omitting the edge makes b an unrooted live reference after u is popped, violating the no-dangling-reference/rooted-path clause of Inv.

exercise 68.7.

Order types by inclusion of concretizations and take join to be . The constant-guard term has type IntBool under a purely structural branch rule; a filter that evaluates the guard reduces it to Int. The union rules are sound by set union. They remain incomplete for safe higher-order programs that require intersections, polymorphism, or relational facts. Principality is not a proposition in this fragment: there are no type variables, substitutions, or instantiation preorder from which to define a most general type.

exercise 68.8.

Let alloc^ return (x,), where is the most recent call site. Map a concrete binding address created at to that pair; then αa(alloc(ς))=alloc^(ας) by definition, which is the allocation premise of the simulation. Monovariant allocation joins the two arguments to x in {0,true}. Call-site allocation stores {0} at the first (x,1) and {true} at the second (x,2); the closure for f may still be shared.

exercise 68.9.

Use the chapter’s two-condition program. The edge combination x0;y:=1;y=0 is a syntactic path but has no concrete trace. Joining after the first conditional gives x top and y=[0,1]; the second true filter leaves x top, so the syntactic-path interval result reports a possible failure of x=0. Every semantic trace taking the second true edge previously took the first true edge and therefore has x=0,y=0; its assertion succeeds. The first claim follows by abstract edge composition; the second follows by induction over concrete transitions.

exercise 68.10.

The concrete sum set is {1,0,,7}, so its interval hull is [1,7]. This is exactly the endpoint calculation [1+(2),3+4]. The result [,7] is also sound but less precise, because [1,7][,7]; optimality of the hull excludes any strictly smaller sound interval.

exercise 68.11.

For c1;c2, a terminal execution first reaches a terminal store of c1 and then one of c2. Apply the two induction hypotheses in that order. An error occurs either in c1, or in c2 after such a terminal store, exactly matching the disjunction in err. For a loop, induction on completed iterations puts every head store in every X satisfying ΦA(X)X; hence it lies in the selected least pre-fixed invariant. A false guard uses the exit refinement, while an error during a true-guard body uses the body error flag.

exercise 68.12.

At entry, (Dxy,Dyx)=(0,0). One body step proposes (1,1), and entrywise join gives (0,1). The next two proposals and joins give (0,2) and (0,3). Widening retains stable Dxy=0 and drops the weakened reverse entry to +. Applying the body again proposes (1,+); join with entry returns (0,+), so the widened matrix is pre-fixed and still entails xy0.

exercise 68.13.

The local analyzer assumes the concrete semantics, concretizations, local transformer proofs, and checked pre-fixed point. The machine theorem assumes the CEK/CESK rules, abstraction map, finite store order, and tick/allocation contracts. Verasco’s imported theorem additionally fixes its C#minor semantics and five section parameters. The interval-trace bound assumes the paper’s typed probabilistic language plus countability and compatibility or exhaustivity. For example, moving exhaustivity to the local interval analyzer would not justify an upper measure bound: ordinary store coverage is not an almost-everywhere trace cover.

exercise 69.1.

The left branch stores σ(y)=α0+1. At ρ(0)=2, the instance is s(x)=2,s(y)=1. Both 20 and 12 hold.

exercise 69.2.

S-If-T adds α00, and S-If-F adds 0α01. The feasible pass models are 2 on the left and 1 on the right. The right failure has model 4. Replays yield (x,y)=(2,1),(1,0),(4,3), with only the last assertion failing. The left failure condition α00α02 has no model.

exercise 69.3.

Take s(x)=0, σ(x)=α0, and ρ(0)=0. Concrete assignment sets y=1, while the erroneous symbolic store instantiates to y=0. The repaired rule stores [x+1]σ=α0+1; the copy-plus-constant line of expression correspondence then proves both sides equal to 1.

exercise 69.4.

The stronger state x1y1 is subsumed by x0y1. For the first consequent, add its complement x1; the edges for x1 and x1 form a cycle of total weight 2. The second consequent is already an atom. If the stores differ, the two path conditions may describe equal inputs but instantiate different concrete stores, so the representation inclusion used by the proof does not follow.

exercise 69.6.

Use m inputs and branch independently on xi0, with skip in both branches. Every Boolean branch vector has a model, hence there are 2m feasible leaves. Depth-first reaches one complete vector before siblings; breadth-first reaches all depth-d prefixes first; concolic negation follows one vector and schedules selected prefixes. Completeness requires that every pending node, respectively every retained branch-negation obligation, is eventually selected and that each supported solver query eventually returns checkable evidence.

exercise 69.7.

Assignment maps each guarded term through the same copy-plus-constant operation. Evaluation distributes over ite, so the branch selected by Φi produces exactly the post-store obtained by assigning in σi. For a near miss, merge x=0,y=0,z=0 and x=1,y=1,z=1 with the disjunctive condition but select the first store for y and the second for z. Input x=0 then yields y=0,z=1, represented by neither input state.

exercise 69.8.

Extend representation by requiring equal domains and H(a)=[[H^(a)]]ρ at every allocated address. The read rules require [[σ(p)]]ρ to lie in both domains. They update x with H(s(p)) and H^(σ(p)), respectively. Heap representation makes those values equal, while all other variables and heap cells are unchanged.

exercise 70.1.

Without the pc premise, each branch derives l:=0 or l:=1 from a low constant. Stores s0(h)=0,s1(h)=7 agreeing on l select opposite branches and finish with public values 0 and 1. Thus the derived program violates low equivalence.

exercise 70.2.

From psecp, join monotonicity gives psecp. An IF-While derivation at p types its body at p; the induction hypothesis therefore types the body at p, and IF-While rebuilds the conclusion at p.

exercise 70.3.

Relabel l as H; each branch then satisfies HsecH. Alternatively make both branches assign 0. The latter has equal public results in all terminating runs, but the checker still requires HsecL, so it is a secure rejected program.

exercise 70.4.

(a) is accepted and secure. (b) is rejected but secure: both runs write zero. (c) is rejected and leaks by the two stores from exercise 70.1. (d) is accepted and secure because a public value may flow into a secret location and the public projection does not change.

exercise 70.6.

Let the guard label be seco. Every body derivation is typed at pseco, so confinement relates its input and output. Induction on the finite first loop evaluation composes those relations until its exit store is low-equivalent to its initial store; repeat independently for the second run. Symmetry and transitivity compose s1Γos1, s1Γos2, and s2Γos2.

exercise 70.7.

Take while h=0 do skip. Stores agreeing on all low variables but with secrets 0 and 1 yield divergence and termination. An observation with a termination bit distinguishes them. TINI requires two terminating derivations, so termination-sensitive noninterference must relate divergence as well as final stores.

exercise 70.8.

Let l:=hmod2 be the intended release. A policy may relate two initial stores only when their secrets have equal parity; the required conclusion is ordinary low equivalence of outputs. Original low equivalence relates all secret values, including different parity, so the command violates the old theorem even though it meets the new policy.

Search the book

Type to search the local edition.