Exercise 127.1.
Rule PE-Dynamic gives 𝑥 ⇓𝗋𝖾𝗌(𝑥). Rule PE-Op-S gives 2 +3 ⇓𝗄𝗇𝗈𝗐𝗇(5). The derivations 𝑦 ⇓𝗋𝖾𝗌(𝑦) and 1 ⇓𝗄𝗇𝗈𝗐𝗇(1), followed by PE-Op-D, give 𝑦 ⋅1 ⇓𝗋𝖾𝗌(𝑦 ⋅1). Therefore PE-If-D returns 𝑟=𝗂𝖿𝟢 𝑥 𝗍𝗁𝖾𝗇 5 𝖾𝗅𝗌𝖾 𝑦⋅1. At (𝑥,𝑦) =(0,7), source and residual select the first branch and return 5. At (1,7), both select the second branch and return 7. These are the two branch instances of theorem 127.4.
Exercise 127.2.
At budget zero, PE-Fuel emits 𝑔(0;𝑥). At budget one, the new pattern (𝑔,0) is allocated and unfolded once; its body reaches (𝑔,1) at exhausted budget and emits 𝑔(1;𝑥). At budget two, the patterns (𝑔,0) and (𝑔,1) are allocated, and the frontier emits 𝑔(2;𝑥). The retained equations therefore describe 𝑔0(𝑥)=𝑔1(𝑥),𝑔1(𝑥)=𝑔(2;𝑥) up to the number of allocated residual names. The source has no finite evaluation derivation returning a numeral. Replacing the frontier call by zero gives the mutated residual program a finite derivation returning zero. At 𝑛 =0, the two sides of the finite-return equivalence in theorem 127.9 are therefore false and true, respectively. This is a counterexample to the theorem’s stated finite-return conclusion for the mutation; it does not invoke a divergence-preservation theorem.
Exercise 127.3.
The only rule for a static conditional is BT-If-S, whose first premise would be 𝜏 ⊢𝑥 :𝑆. But BT-Var gives 𝜏 ⊢𝑥 :𝐷, so the derivation fails at that premise. The least well-annotated repair changes the conditional annotation and inserts the two forced embeddings: 𝗂𝖿𝑑(𝑥,𝗅𝗂𝖿𝗍(0),𝗅𝗂𝖿𝗍(1)). Rule BT-Lift gives all three premises binding time 𝐷, and Off-Lift followed by Off-If-D gives 𝑃𝑏;(∅;[𝑥↦𝑥])⊢𝗈𝖿𝖿𝗂𝖿𝑑(𝑥,𝗅𝗂𝖿𝗍(0),𝗅𝗂𝖿𝗍(1))⇓𝖼𝗈𝖽𝖾(𝗂𝖿 𝑥 𝗊𝗎𝗈𝗍𝖾(0) 𝗊𝗎𝗈𝗍𝖾(1)).
Exercise 127.4.
The monovariant division assigns 𝗉𝗈𝗐𝖾𝗋(𝐷,𝐷) :𝐷, so even a call at exponent four residualizes the test, decrement, recursive call, and multiplication. Splitting gives 𝗉𝗈𝗐𝖾𝗋𝑑(𝐷,𝐷) :𝐷 and 𝗉𝗈𝗐𝖾𝗋𝑠(𝑆;𝐷) :𝐷. The known-exponent call selects the second copy; its recursive static argument decreases through 4,3,2,1,0, and specialization returns 𝑥⋅(𝑥⋅(𝑥⋅(𝑥⋅1))). Both copied definitions erase to the original two equations for power. By induction on 𝑘, the zero calls all return 1, and the successor calls all return 𝑥 times the equal recursive result. Thus replacing a call by the copy selected at its call site preserves every erased call.
Exercise 127.5.
Use quoted lists as the exact Scheme0 data representation: ⌜𝖭𝗎𝗆(𝑛)⌝=(𝗇𝗎𝗆,𝑛),⌜𝖵𝖺𝗋(𝑥)⌝=(𝗏𝖺𝗋,𝑥),⌜𝖠𝖽𝖽(𝑞1,𝑞2)⌝=(𝖺𝖽𝖽,⌜𝑞1⌝,⌜𝑞2⌝). The tags and variable names are quoted symbols; the tuples are quoted-list values built with 𝖼𝗈𝗇𝗌. In Scheme0 notation, the interpreter definition is the first-order equation 𝗂𝗇𝗍+(𝑞,𝑑)=𝗂𝖿(𝖼𝖺𝗋(𝑞)=𝗊𝗎𝗈𝗍𝖾(𝗇𝗎𝗆))𝖼𝖺𝗋(𝖼𝖽𝗋(𝑞))𝖾𝗅𝗌𝖾 𝗂𝖿(𝖼𝖺𝗋(𝑞)=𝗊𝗎𝗈𝗍𝖾(𝗏𝖺𝗋))𝗅𝗈𝗈𝗄𝗎𝗉(𝖼𝖺𝗋(𝖼𝖽𝗋(𝑞)),𝑑)𝖾𝗅𝗌𝖾𝗂𝗇𝗍+(𝖼𝖺𝗋(𝖼𝖽𝗋(𝑞)),𝑑)+𝗂𝗇𝗍+(𝖼𝖺𝗋(𝖼𝖽𝗋(𝖼𝖽𝗋(𝑞))),𝑑), The environment is a quoted list of pairs. Its Scheme0 lookup definition is 𝗅𝗈𝗈𝗄𝗎𝗉(𝑥,𝑑)=𝗂𝖿(𝑥=𝖼𝖺𝗋(𝖼𝖺𝗋(𝑑)),𝖼𝖺𝗋(𝖼𝖽𝗋(𝖼𝖺𝗋(𝑑))), 𝗅𝗈𝗈𝗄𝗎𝗉(𝑥,𝖼𝖽𝗋(𝑑))). The represented program is evaluated only under environments containing each of its free variable names, so the undefined empty-list primitive case is not reached. The final interpreter branch is reached only for the 𝖺𝖽𝖽 tag, because the represented language has exactly the three forms listed in the exercise. Represent the object program by 𝑞=𝖠𝖽𝖽(𝖠𝖽𝖽(𝖵𝖺𝗋(𝑥),𝖭𝗎𝗆(2)),𝖭𝗎𝗆(3)). The interpreter 𝗂𝗇𝗍+ dispatches on 𝖭𝗎𝗆, 𝖵𝖺𝗋, and 𝖠𝖽𝖽, recursively interpreting the two children of an addition. Assume at this point that the call 𝗆𝗂𝗑(𝗂𝗇𝗍𝑎+,⌜𝑞⌝) terminates and returns 𝑟. The mix equation then gives, for every input environment 𝑑, 𝖾𝗏𝖺𝗅(𝑟,𝑑)=𝑣⟺𝖾𝗏𝖺𝗅(𝑞,𝑑)=𝑣. The displayed interpreter has no reassociation rule, so specializing its three dispatches leaves exactly the residual arithmetic (𝑥 +2) +3. The termination assumption is used exactly to obtain the returned residual program 𝑟; the implication in (127.2) has no conclusion when mix does not return.
Exercise 127.7.
Let | −| count syntax nodes. Residualizing the dynamic test duplicates its two branches, so |𝐸𝑛+1| =2|𝐸𝑛| +2, with |𝐸0| =1. Hence |𝐸𝑛| =3 ⋅2𝑛 −2. Instead bind the residual for 𝐸𝑛 once: 𝗅𝖾𝗍 𝑧𝑛 =𝐸𝑛 𝗂𝗇 𝗂𝖿𝟢 𝑦𝑛 𝗍𝗁𝖾𝗇 𝑧𝑛 𝖾𝗅𝗌𝖾 𝑧𝑛. Each level adds one test, one let, and two variable edges to the dag, so its number of distinct nodes is linear in 𝑛. At every level the already constructed residual 𝐸𝑛 terminates under the exercise’s total arithmetic environment; proposition 127.11 therefore preserves each finite-return observation. Induction on 𝑛 composes these equivalences.
Exercise 127.8.
The polyvariant key produces distinct entries 𝗉𝗈𝗐𝖾𝗋2(𝑥) =𝑥 ⋅(𝑥 ⋅1) and 𝗉𝗈𝗐𝖾𝗋3(𝑦) =𝑦 ⋅(𝑦 ⋅(𝑦 ⋅1)), with the displayed association inherited from the source. A monovariant key 𝗉𝗈𝗐𝖾𝗋 cannot reuse one specialized equation for both static exponents without losing correctness; it must merge the exponent to a dynamic parameter and retain the test, decrement, and recursive call in the residual program 𝗉𝗈𝗐𝖾𝗋𝑚(𝑘,𝑧)=𝗂𝖿𝟢 𝑘 𝗍𝗁𝖾𝗇 1 𝖾𝗅𝗌𝖾 𝑧⋅𝗉𝗈𝗐𝖾𝗋𝑚(𝑘−1,𝑧),𝗆𝖺𝗂𝗇(𝑥,𝑦)=(𝗉𝗈𝗐𝖾𝗋𝑚(2,𝑥),𝗉𝗈𝗐𝖾𝗋𝑚(3,𝑦)). The corresponding polyvariant main expression is 𝗆𝖺𝗂𝗇(𝑥,𝑦)=(𝗉𝗈𝗐𝖾𝗋2(𝑥),𝗉𝗈𝗐𝖾𝗋3(𝑦)). Thus the monovariant program loses the distinction between two and three but remains sound. In the polyvariant program, each new-call case unfolds the equation at its exact static tuple. The new-pattern and recursive-hit cases of theorem 127.9 therefore prove preservation of that residual program.
The monovariant policy is a different algorithm. For its direct proof, let 𝑧 be a natural and induct on the promoted exponent 𝑘. At zero, both the source call and 𝗉𝗈𝗐𝖾𝗋𝑚(0,𝑧) select the first branch and return 1. At 𝑘 +1, both select the second branch, multiply by 𝑧, and make their respective call at 𝑘; the induction hypothesis identifies the returned recursive values. Hence 𝗉𝗈𝗐𝖾𝗋𝑚(𝑘,𝑧) and 𝗉𝗈𝗐𝖾𝗋(𝑘,𝑧) have the same finite return for every natural 𝑘,𝑧. Instantiating this result at (2,𝑥) and (3,𝑦), then applying the pair constructor congruence, proves preservation of the displayed monovariant main expression. No case of theorem 127.9 is used for the promoted-parameter table.
Exercise 127.9.
Put 𝖼𝗈𝗆𝗉𝗂𝗅𝖾𝗋 =𝗋𝗎𝗇(𝗆𝗂𝗑,[𝗆𝗂𝗑𝑎,𝗂𝗇𝗍𝑎]) :𝖯𝗋𝗈𝗀. Assuming this specialization terminates, (127.2) gives, for every represented 𝑞, 𝗋𝗎𝗇(𝖼𝗈𝗆𝗉𝗂𝗅𝖾𝗋,⌜𝑞⌝)=𝗋𝗎𝗇(𝗆𝗂𝗑,[𝗂𝗇𝗍𝑎,⌜𝑞⌝])=𝖼𝗈𝗆𝗉𝗂𝗅𝖾(𝑞):𝖯𝗋𝗈𝗀. For the third projection, put 𝖼𝗈𝗀𝖾𝗇 =𝗋𝗎𝗇(𝗆𝗂𝗑,[𝗆𝗂𝗑𝑎,𝗆𝗂𝗑𝑎]) :𝖯𝗋𝗈𝗀. Assuming that self-specialization terminates, instantiate its dynamic input with 𝗂𝗇𝗍𝑎 :𝖲𝗍𝖺𝗍𝗂𝖼𝖳𝗎𝗉𝗅𝖾 to obtain 𝗋𝗎𝗇(𝖼𝗈𝗀𝖾𝗇,𝗂𝗇𝗍𝑎)=𝖼𝗈𝗆𝗉𝗂𝗅𝖾𝗋:𝖯𝗋𝗈𝗀. The inclusions 𝖠𝗇𝗇𝖯𝗋𝗈𝗀 ⊆𝖲𝗍𝖺𝗍𝗂𝖼𝖳𝗎𝗉𝗅𝖾 ⊆𝖣𝖺𝗍𝖺 type both displayed static tuples. No equation is asserted without the named termination assumption.