Lectures onType Theory
ch:dependent-refinement: ch:dependent-refinement
appendix sectionsolutions

ch:dependent-refinement: ch:dependent-refinement

Exercise 106.1.

The first product comparison uses the client domain P: P<:Ix:PQ0(x)<:Q1(x)(x:I)Q0(x)<:(x:P)Q1(x)ΠSub. The second uses reflexivity of the same domain: P<:Px:PQ1(x)<:Q2(x)(x:P)Q1(x)<:(x:P)Q2(x)ΠSub. Transitivity gives the required comparison. Reversing only the domain premise would let a function defined merely on positive integers P be used at a type whose domain is all integers I, because P<:I. A client may then pass 1:I. The provider has no premise that permits its body to use 1 as an element of P; the reversed rule is therefore not substitution safe.

Exercise 106.2.

The source predicate 1ν entails 0ν, so R-Base-Sub derives R2<:R1. Under x:R1, give an occurrence of x its singleton refinement Xx={ν:Intν=x}. Then λu:Xx.u:Πu:Xx{ν:Int0νx}, because the equality edges x0ν and ν0x certify xν0. Narrowing replaces the assumption edge for R1, x00, by the stronger edge x10 for R2. The result entailment still uses the two equality edges; the new bound edge is available but is not needed by the zero-weight path νx.

The subtype premise is what permits every old use of 0x. If a replacement declaration is admitted without that premise, take its unconstrained value to be x=1. It satisfies the replacement’s empty predicate but falsifies 0x, so any old derivation using the R1 assumption can no longer be rebuilt. Thus arbitrary context replacement is not narrowing.

Exercise 106.3.

The upcast to an unknown index retains the vector constructor and its index tag. Hence the nil calculation is cast[VecA0VecA?](cast[VecA?VecA0](nilA))nilA. For the cons value, the retained constructor announces successor index suc0. The downcast demands index 0, so its constructor/index test fails and the term reduces to errVecA0. The first equation is the projection after the embedding of a run-time representation. It compares constructor tags and returns data; it neither compares nor erases two proof terms, so it is not proof irrelevance.

Exercise 106.4.

From F:Πx:A1B1, N:A2, and A2<:A1, subsumption first gives N:A1. Rule Π-E therefore derives FN:B1[N/x]. The codomain premise is checked before substitution in the client context Γ,x:A2B1<:B2. Substitution of the already typed argument gives ΓB1[N/x]<:B2[N/x]. A final subsumption step yields FN:B2[N/x]. Thus the smaller-domain context occurs in the premise, and [N/x] occurs only after the application and codomain comparison have both been established.

Exercise 106.5.

Use a two-element type interpretation 0<1. Let P<:I, take B1(x)=1 and B2(x)=0 for every x:P, and consider Πx:IB1(x)andΠx:PB2(x). Both products are well formed, and the domain premise P<:I has the required contravariant orientation. The codomain premise would be 1<:0 under x:P, which is false in the interpretation. Therefore the product subtype judgment is not derivable. The same construction with any proper domain inclusion and constant top/bottom codomain families gives the requested pair; dependence does not make the codomain check optional.

Exercise 106.6.

Write L=len(a). The parameter refinement 0i0 contributes i00. The then-branch test iL1 contributes L1i. The goal is the latter constraint itself, so the one-edge path L1i is a shortest-path certificate of weight 1. After deleting the branch assumption, set L=0 and i=0. The parameter constraint holds, but the goal becomes 01, which is false. No certificate can be reconstructed from the remaining graph.

Exercise 106.7.

Prove the two statements simultaneously: checkn(forgetn(v))=some(v),checkn(l)=some(v)forgetn(v)=l. For n=0, a vector is nil; forgetting gives the empty list, and the zero checker returns some(nil). Conversely, the zero checker can return a vector only on the empty list, so the forgotten result is that list.

For n=sucm, write v=cons(a,w). The head calculation is the reflexive equality a=a. The recursive tail equation is checkm(forgetm(w))=some(w), by the induction hypothesis. The successor checker combines these two facts and returns some(cons(a,w)). Conversely, if checksucm(a::l)=some(cons(b,w)), its head test gives a=b, while its recursive call gives checkm(l)=some(w). The second induction hypothesis gives forgetm(w)=l; congruence of list cons with the head equality yields forgetsucm(cons(b,w))=a::l. These are all vector and list shapes accepted by the indexed checker.

Search the book

Type to search the local edition.