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

ch:dependent-partiality: partiality

Exercise 105.1.

For x=37, observe0(x)=later,observe2(x)=later,observe3(x)=done(7),observe4(x)=done(7). The convergence derivation is Conv-Return followed by three applications of Conv-Step. A result later describes only the inspected prefix. Even done(7) is a proof of convergence rather than a proof about the absence of all values. Hence none of the first three finite observations establishes the universal negation that defines divergence.

Exercise 105.2.

Take x=ξ, where ξ:Aν is neutral. One unfolding of the left side exposes ((ξ=f)=g)((ξ=f)=g), whereas the right side exposes ξ=(λa.f(a)=g)(ξ=(λa.f(a)=g)). Their guarded subterms are distinct raw syntax; identifying them would assume the associativity being proved. For every c:C, bind convergence gives ((x=f)=g)ca,b.xaf(a)bg(b)c(x=(λa.f(a)=g))c. The middle equivalence only reassociates the two existential witnesses and the conjunctions. Pointwise equivalence is exactly =ν.

Exercise 105.3.

No natural square equals two. For k=0,1, k2<2; for k2, monotonicity of multiplication gives k24>2. Therefore P(k)=false for every k, so no m can satisfy the P(m)=true conjunct in the right side of theorem 105.9.

Induct on the fuel j. At zero the observer returns later. At j+1, the predicate test at the current index is false, so search exposes one step; consuming one unit of fuel reduces the claim to the induction hypothesis at the successor index. Thus every finite observation is later. This proof uses the particular decidable arithmetic predicate; it does not invoke a general decision law for convergence.

Exercise 105.4.

For the forward direction of bind convergence, induction on the convergence derivation has two inversions. If the input is a, unfold bind and choose a; Conv-Return gives input convergence. If the input is x, inversion of the outer Conv-Step reduces the premise to (x=f)b; apply the induction hypothesis and rebuild input convergence with Conv-Step. Conversely, induction on xa uses Conv-Return to unfold bind to f(a), and uses Conv-Step plus the guarded bind equation in the step case.

Now assume x=νy and f(a)=νg(a) for every a. For each b, (x=f)ba.xaf(a)ba.yag(a)b(y=g)b. The outer equivalences are bind convergence; the middle one uses the two pointwise equality hypotheses. This is the required congruence at =ν.

Exercise 105.5.

Define the delayed subtraction program by gcdν(m,n)={n,m=0,m,n=0,gcdν(mn,n),0<nm,gcdν(m,nm),0<m<n. Use the measure μ(m,n)=m+n. In the first recursive branch, (mn)+n=m<m+n because n>0, including the equality case m=n, which takes one step to (0,n). In the second, m+(nm)=n<m+n because m>0. Well-founded induction on μ therefore supplies a convergence derivation in every input case; each recursive induction hypothesis is lifted once by Conv-Step. For the corpus input, the exact trace is (6,4)(2,4)(2,2)(0,2), so the returned two occurs below three guarded steps. Adding an immediate m=n return changes this observation and is not the displayed program.

Determinacy of convergence extracts a unique natural d. The subtraction equalities are gcd(m,n)=gcd(mn,n) for m>n and gcd(m,n)=gcd(m,nm) for n>m. The second is obtained from the first by swapping m and n. Induction on m+n, using the corresponding equality in each strict-order branch, gives d=gcd(m,n). An accessibility definition packages the well-founded proof as an argument and returns d:Nat directly. The delayed definition is accepted by guardedness before totality is proved and returns Natν; its separate convergence proof is what permits extraction of the same total value.

Search the book

Type to search the local edition.