Lectures onType Theory
ch:recursive-functions: ch:recursive-functions
appendix sectionsolutions

ch:recursive-functions: ch:recursive-functions

Exercise 123.1.

In the first call, m<sucm, so coordinate one is the decisive strict coordinate; the later increase is irrelevant and the call passes. In the second call, coordinate one is equal. If n=0, coordinate two is also equal and the call fails because no coordinate is strict. If n=suck, then 0<suck, so coordinate two is decisive and the call passes. In the third call the proposed first coordinate suc(sucm) is not smaller than the source coordinate sucm; the lexicographic premise fails before the second coordinate is inspected.

Exercise 123.2.

The selected successor row gives even(sucn)0RCallodd(n). Write FS for the compiled well-founded definition on StateS. At program granularity the corresponding target contraction is FS(ineven(sucn))0CCallFS(inodd(n)). To expose the raw proof arguments, write WS[x;p] for the internal accessibility worker at p:AccRS(x). The accepted proof at the source state has the form acc(αeven,sucn), where αeven,sucn(y,p) is the stored accessibility proof for the predecessor p:yRSineven(sucn). Let ES denote the generated state eliminator, and abbreviate psuc:=childsuc(n,sucn),kα:=λy.λp.WS[y;αeven,sucn(y,p)]. The complete administrative prefix is FS(ineven(sucn))0outerβ+ES(ineven(sucn);b)0BlockcompWS[ineven(sucn);acc(αeven,sucn)]0WFβ(λk.k(inodd(n),psuc))kα0adminβ+WS[inodd(n);αeven,sucn(inodd(n),psuc)]=compileG(odd(n)). Here b is the finite tuple of generated state branches, and its even-successor component is the displayed worker. The final line is what the program-level notation FS(inodd(n)) denotes inside this selected branch; its accessibility argument is frozen evidence. The named DChildN proof is exactly childsuc(n,sucn). Thus the displayed sequence contains the outer beta contractions, generated state-block equation, accessibility recursor redex, WF-β, and all administrative beta contractions licensed by C-Call.

Exercise 123.3.

Use StateS with constructors ineven(n) and inodd(n). Its relation has the two predecessor families inodd(n)RSineven(sucn),ineven(n)RSinodd(sucn). Both are witnessed by childsuc(n,sucn). With k the recursive hypothesis, the four step bodies are tt,k(inodd(n),childsuc),ff,k(ineven(n),childsuc), in the order even-zero, even-successor, odd-zero, odd-successor. Writing FS for the compiled recursor, its calculation is FS(ineven(suc(suc0)))0WFβFS(inodd(suc0))0WFβFS(ineven(0))0WFβtt. The first two steps consume the two displayed RS-predecessor proofs; the last selects the even-zero body.

Exercise 123.4.

The changed clause emits the self-edge inodd(sucn)inodd(sucn). The call supplies sucn again at the named position. By definition 123.3, that term is not a direct constructor child of itself, so no predecessor certificate exists. At n=0, source evaluation repeats odd(suc0)0odd(suc0)0odd(suc0)0. The failed certificate and the infinite trace expose the same unguarded self-edge.

Search the book

Type to search the local edition.