Exercise 10.1.
First prove the requested commutation lemma by induction on 𝑒1: 𝑒1[𝑎/𝑥]▹𝑦𝑒2=(𝑒1▹𝑦𝑒2)[𝑎/𝑥].(∗) All binders are alpha-renamed fresh for 𝑎,𝑒2,𝑥,𝑦. If 𝑒1 =𝑏 is an atom, the two sides are 𝑒2[𝑏[𝑎/𝑥]/𝑦] and 𝑒2[𝑏/𝑦][𝑎/𝑥]; ordinary capture-avoiding substitution commutes because 𝑥 ≠𝑦, 𝑦 ∉fv(𝑎), and 𝑥 ∉fv(𝑒2). For 𝑒1 =𝗅𝖾𝗍 𝑧 =𝑐 𝗂𝗇 𝑒, both sides retain the same fresh head let and ( ∗) for 𝑒 identifies their tails. The conditional clause distributes bind composition into both branches, so the two branch induction hypotheses prove ( ∗). For 𝑒1 =𝖾𝗋𝗋𝗈𝗋, both sides are 𝖾𝗋𝗋𝗈𝗋.
Now induct on 𝑒0. If 𝑒0 =𝑎 is an atom, the desired equation is exactly ( ∗): (𝑒1[𝑎/𝑥])▹𝑦𝑒2=(𝑒1▹𝑦𝑒2)[𝑎/𝑥]. If 𝑒0 =𝗅𝖾𝗍 𝑧 =𝑐 𝗂𝗇 𝑒, alpha-rename 𝑧 fresh. Both sides retain 𝗅𝖾𝗍 𝑧 =𝑐 𝗂𝗇( −), and the induction hypothesis for 𝑒 equates the two tails. If 𝑒0 is a conditional, expanding the definition on both sides gives conditionals with the same test; apply the induction hypothesis separately to the then and else branches. Finally, (𝖾𝗋𝗋𝗈𝗋▹𝑥𝑒1)▹𝑦𝑒2=𝖾𝗋𝗋𝗈𝗋=𝖾𝗋𝗋𝗈𝗋▹𝑥(𝑒1▹𝑦𝑒2). These are all expression forms, so associativity holds modulo exactly the capture-avoiding renamings stipulated by the definition.
exercise 10.2.
Both (a) and (b) are well formed. In (a), the domain adds 𝐿𝑎 to the scope and the codomain binder adds 𝜈, so 𝜈 −𝐿𝑎 ≤ −1 passes WF-Base. In (b), the domain adds 𝑖 and the array codomain binder contributes 𝐿𝜈, so 𝐿𝜈 −𝑖 ≤0 is likewise scoped.
Expression (c) is rejected. A function-shaped declaration contributes no predicate vertex, so 𝑓 is absent from 𝑉(𝑓 :(𝗂𝗇𝗍 →𝗂𝗇𝗍)); the occurrence of 𝑓 in 𝜈 −𝑓 ≤0 fails the premise of WF-Base. Expression (d) is well formed in the empty context: 𝐿𝜈 is the distinguished vertex supplied by the array refinement binder itself, and 𝟎 is always available.
exercise 10.3.
The graph edges, written in the order of the hypotheses, are 𝑦2→𝑥,𝑧−4⟶𝑦,𝑥1→𝑧. Their identifiers form the adjacent cycle 𝑦 →𝑥 →𝑧 →𝑦. The replay checker verifies the common endpoints and calculates 2+1+(−4)=−1<0. Thus this three-edge list is a contradiction certificate.
After replacing the last constant by 2, take ℎ(𝟎)=0,ℎ(𝑥)=0,ℎ(𝑧)=2,ℎ(𝑦)=−2. Then ℎ(𝑥) −ℎ(𝑦) =2, ℎ(𝑦) −ℎ(𝑧) = −4, and ℎ(𝑧) −ℎ(𝑥) =2. All three constraints hold, so the zero-weight cycle is not a contradiction.
exercise 10.4.
Introduce the fresh vertex 𝑧 for the source refinement. Its upper-bound atom contributes the edge 𝐿𝑎−1⟶𝑧. The target asks for 𝑧 −𝐿𝑎 ≤0, and that one-edge path has weight −1 ≤0. Hence S-Base gives the displayed subtype judgment. The source’s lower-bound edge 𝑧0→𝟎 is present but is not needed for this goal.
For the reverse direction, let 𝑎 be a one-element array and assign 𝑧 =1. Then 𝑧 −𝐿𝑎 =0, so the weaker target refinement is satisfied. But the putative reverse target contains 𝑧 −𝐿𝑎 ≤ −1, namely 0 ≤ −1, which is false. This valuation refutes the entailment premise of the reverse S-Base instance.
exercise 10.5.
Without the nonempty input refinement, exact length and shift synthesis still give 𝑛 =𝐿𝑎 and 𝑖 =𝑛 −1. Therefore the upper-bound goal has the path 𝐿𝑎0→𝑛−1⟶𝑖, of weight −1, which certifies 𝑖 −𝐿𝑎 ≤ −1.
The lower-bound goal is 𝟎 −𝑖 ≤0. Its available route is 𝑖1→𝑛0→𝐿𝑎0→𝟎, whose weight is 1, not at most 0. This failure is genuine: set ℎ(𝟎)=0,ℎ(𝐿𝑎)=ℎ(𝑛)=0,ℎ(𝑖)=−1. The potential satisfies both equalities 𝑛 =𝐿𝑎, 𝑖 =𝑛 −1, and the implicit length constraint, but it makes ℎ(𝟎) −ℎ(𝑖) =1 >0. Hence no certificate for the lower bound exists.
exercise 10.6.
Write 𝐹 =𝖿𝗂𝗑 𝑓(𝑥).𝑒1 :𝑥 :𝑠 →𝑡. Inversion before the E-Fix step supplies 𝑓:(𝑥:𝑠→𝑡),𝑥:𝑠⊢𝑒1⇐𝑡,⋅⊢𝑣⇐𝑠,𝑦:𝑡[𝑣/𝑥]⊢𝑒2⇐𝑢, with 𝑦 ∉fv(𝑢). Rule D-Fix, followed by reflexive subtyping and D-Sub, gives ⋅⊢𝐹⇐𝑥:𝑠→𝑡. Substitution for the function variable is therefore 𝑥:𝑠⊢𝑒1[𝐹/𝑓]⇐𝑡; the types do not change because a function-shaped 𝑓 supplies no predicate vertex. Substitution for the argument is then ⋅⊢𝑒1[𝐹/𝑓,𝑣/𝑥]⇐𝑡[𝑣/𝑥]. Finally lemma 10.22, with the displayed continuation premise, gives ⋅⊢𝑒1[𝐹/𝑓,𝑣/𝑥]▹𝑦𝑒2⇐𝑢, which is exactly the reduct’s required type.
exercise 10.7.
With only 𝟎 −𝜈 ≤0, the candidate invariant says 𝑖 ≥0 and contains no relation between 𝑖 and 𝐿𝑎. Take 𝐿𝑎 =1, 𝑖 =2, and 𝑗 =1. The else guard is satisfied, the shift equation 𝑗 =𝑖 −1 holds, and 𝑗 ≥0. The read’s upper VC is nevertheless 𝑗−𝐿𝑎≤−1,that is0≤−1, so the assignment is rejected.
Now add 𝜈 −𝐿𝑎 ≤1. At entry, 𝑛 =𝐿𝑎 satisfies both 𝑛 ≥0 and 𝑛 −𝐿𝑎 ≤1. In the recursive branch, the guard gives 𝑖 ≥1, hence 𝑗 =𝑖 −1 ≥0, while 𝑖 −𝐿𝑎 ≤1 gives 𝑗 −𝐿𝑎 ≤0 ≤1. Thus the recursive call preserves both qualifiers. The same valuation 𝐿𝑎 =1,𝑖 =2,𝑗 =1 satisfies them, but still makes 𝑗 =𝐿𝑎 and falsifies the strict read bound. The nearby qualifier is inductive but too weak for array safety.
exercise 10.8.
For 𝐴 =⟨7⟩, E-Len first yields 𝐸=𝗅𝖾𝗍 𝑧=𝗀𝖾𝗍𝐴1 𝗂𝗇 𝑧. The bounds conjunction is 0 ≤1 followed by 1 <1. Guard elaboration therefore produces 𝗂𝖿 0≤1 𝗍𝗁𝖾𝗇(𝗂𝖿 1<1 𝗍𝗁𝖾𝗇 𝐸 𝖾𝗅𝗌𝖾𝖾𝗋𝗋𝗈𝗋) 𝖾𝗅𝗌𝖾𝖾𝗋𝗋𝗈𝗋. The first test is true, so E-IfT selects the inner conditional. The second test is false, so E-IfF yields 𝖾𝗋𝗋𝗈𝗋. The failing test is the strict upper bound 𝑖 <𝗅𝖾𝗇(𝐴); evaluation never reaches the stuck get.
Exercise 10.9.
The consumer does not compare the producer’s certificates with the producer’s claimed VC list. At protocol step 2 it reruns the deterministic generator on ⋅ ⊢last ⇐𝑡, producing the complete list C, including the bounds VC for the get. At step 3 it matches the supplied bundle Π against this recomputed list. Because Π has no certificate for the recomputed get VC, matching or replay fails and evaluation is never enabled at step 4.
If the consumer instead accepted a producer-supplied VC list, the malicious producer could delete precisely the obligations that make an unsafe term untypable and then provide valid certificates for the harmless remainder. Acceptance would no longer imply that every VC generated by the fixed checker is valid. Therefore checker correctness could not yield ⋅ ⊢𝑒 ⇐𝑡, and preservation/progress could not be invoked. The first implication of theorem 10.32 would be false; VC recomputation is the step that binds the evidence to the actual program and policy.
Exercise 10.10.
In the empty context the only nonconstant vertex available to a refinement is 𝜈. After normalization, every atom is one of 𝜈≤𝑘,𝑘≤𝜈,a constant truth value, for some 𝑘 ∈ℤ. A finite conjunction collects finitely many upper and lower bounds. If a constant conjunct is false, its denotation is empty. Otherwise, taking the least upper bound 𝑈 and greatest lower bound 𝐿 that occur, its denotation is one of ℤ,{𝑛∣𝑛≤𝑈},{𝑛∣𝐿≤𝑛},{𝑛∣𝐿≤𝑛≤𝑈},∅. Every nonempty unbounded case contains consecutive integers and hence an odd integer. Every bounded interval is finite, whereas the set of even integers is infinite in both directions. The empty case and all of ℤ are also plainly wrong. Thus no predicate in this conjunction-only difference fragment denotes exactly the even integers.