Exercise 84.1.
Let the result carrier be 𝜇𝖬𝐹𝐵 and define 𝜙𝑓(𝑅,rec,𝗂𝗇𝗅⋆):=𝗂𝗇𝖬𝐹𝐵(𝗂𝗇𝗅⋆),𝜙𝑓(𝑅,rec,𝗂𝗇𝗋(𝑎,𝑟)):=𝗂𝗇𝖬𝐹𝐵(𝗂𝗇𝗋(𝑓(𝑎),rec(𝑟))). In the cons clause rec :𝑅 →𝜇𝖬𝐹𝐵 and 𝑟 :𝑅. Mendler beta therefore gives map-nil as the target nil and map-cons as target cons applied to 𝑓(𝑎) and the recursively mapped tail.
Exercise 84.2.
The attempted algebra is 𝜙:∏𝑅:U𝑖(𝑅→(𝜇𝖬𝐹𝖳→𝟏))→(𝑅→𝟏)→(𝜇𝖬𝐹𝖳→𝟏) with 𝜙(𝑅,rec,𝑓):=𝑓. The extracted 𝑓 has domain 𝑅, while the expected result has domain 𝜇𝖬𝐹𝖳; abstract 𝑅 cannot be converted to that fixed type. Replacing the clause by 𝜆𝑥 :𝜇𝖬𝐹𝖳. ⋆ typechecks, but ignores 𝑓. Consequently it cannot expose the negative function needed for 𝗈𝗎𝗍(𝑥)(𝑥) and cannot recreate the self-application cycle.
Exercise 84.3.
Strengthen the claim to every 𝐴 and induct on 𝑡 :𝖳𝖾𝗋𝗆(𝐴). Variables and applications compute directly. In the lambda case the induction hypothesis at 𝖨𝗇𝖼𝗋(𝐴) applies because 𝗅𝗂𝖿𝗍(𝗂𝖽)(𝗓𝖾𝗋𝗈𝖵)=𝗓𝖾𝗋𝗈𝖵,𝗅𝗂𝖿𝗍(𝗂𝖽)(𝗌𝗎𝖼𝖵(𝑎))=𝗌𝗎𝖼𝖵(𝑎). Thus 𝗅𝗂𝖿𝗍(𝗂𝖽) is pointwise the identity, so 𝗋𝖾𝗇𝖺𝗆𝖾(𝗂𝖽,𝗅𝖺𝗆(𝑏))=𝗅𝖺𝗆(𝗋𝖾𝗇𝖺𝗆𝖾(𝗂𝖽,𝑏))=𝗅𝖺𝗆(𝑏).
Exercise 84.4.
First inspect 𝑧 :𝖨𝗇𝖼𝗋(𝐴). At 𝗓𝖾𝗋𝗈𝖵 both 𝗅𝗂𝖿𝗍𝖲𝗎𝖻(𝜂𝐴)(𝑧) and 𝜂𝖨𝗇𝖼𝗋(𝐴)(𝑧) are 𝗏𝖺𝗋(𝗓𝖾𝗋𝗈𝖵). At 𝗌𝗎𝖼𝖵(𝑎), 𝗅𝗂𝖿𝗍𝖲𝗎𝖻(𝜂𝐴)(𝗌𝗎𝖼𝖵(𝑎))=𝗋𝖾𝗇𝖺𝗆𝖾(𝗌𝗎𝖼𝖵,𝗏𝖺𝗋(𝑎))=𝗏𝖺𝗋(𝗌𝗎𝖼𝖵(𝑎)). Nested induction on 𝑡 now settles variables and applications by computation. In the lambda case use the displayed pointwise equality, the induction hypothesis at 𝖨𝗇𝖼𝗋(𝐴), and congruence for 𝗅𝖺𝗆.
Exercise 84.5.
At arbitrary 𝑅, the recursive placeholder has type rec :𝑅 →ℕ. In the nonempty layer, 𝑓 :𝑅 →𝑅 and 𝑟 :𝑅, so 𝑓(𝑟) :𝑅 and 𝗌𝗎𝖼(rec(𝑓(𝑟))) :ℕ. An unrolled parent instead has type 𝜇𝖬𝐹𝖥𝗈𝗈. It cannot be passed to rec because the latter’s domain is the universally quantified 𝑅, not the fixed point. This is the exact abstract-domain barrier.
Exercise 84.6.
In 𝜏0 =𝐴 →𝜏1 and 𝜏1 =𝐵 →𝜏0, each traversal follows an arrow codomain, so the occurrence returning to 𝜏0 is positive. The same argument starts at 𝜏1; property 𝑃 passes. If the second constraint is changed to 𝜏1 =𝜏0 →𝐵, the traversal from 𝜏0 to 𝜏1 preserves polarity and the arrow domain reverses it on returning to 𝜏0. Thus a type equal to 𝜏0 contains a negative occurrence of 𝜏0, and property 𝑃 fails.
Exercise 84.7.
For natural-number sum on lists, use result ℕ: 𝜙Σ(𝑅,rec,𝗂𝗇𝗅⋆)=0,𝜙Σ(𝑅,rec,𝗂𝗇𝗋(𝑛,𝑟))=𝑛+rec(𝑟). For append to a fixed second list 𝑦𝑠 :𝜇𝖬𝐹𝐴, use that list type as the result: 𝜙𝑦𝑠(𝑅,rec,𝗂𝗇𝗅⋆)=𝑦𝑠,𝜙𝑦𝑠(𝑅,rec,𝗂𝗇𝗋(𝑎,𝑟))=𝗂𝗇𝖬𝐹𝐴(𝗂𝗇𝗋(𝑎,rec(𝑟))). The beta rule gives the ordinary nil and cons equations. Only the first list is folded; the second is already the result value returned at nil, so no destructor for the first list is needed.
Exercise 84.8.
First prove, by cases on 𝑧 :𝖨𝗇𝖼𝗋(𝐴), 𝗌𝗎𝖻𝗌𝗍(𝗅𝗂𝖿𝗍𝖲𝗎𝖻(𝜏),𝗅𝗂𝖿𝗍𝖲𝗎𝖻(𝜎)(𝑧))=𝗅𝗂𝖿𝗍𝖲𝗎𝖻(𝜆𝑎.𝗌𝗎𝖻𝗌𝗍(𝜏,𝜎(𝑎)))(𝑧). The zero case is reflexivity. The successor case uses renaming–substitution fusion and 𝗅𝗂𝖿𝗍𝖲𝗎𝖻(𝜏)(𝗌𝗎𝖼𝖵(𝑏)) =𝗋𝖾𝗇𝖺𝗆𝖾(𝗌𝗎𝖼𝖵,𝜏(𝑏)). Now strengthen the main claim over the variable type and induct on 𝑡. The variable case is the definition, and the application case uses both induction hypotheses. In the lambda case, the induction hypothesis at 𝖨𝗇𝖼𝗋(𝐴) reduces the goal to the displayed lift equation; congruence for 𝗅𝖺𝗆 closes it.
Exercise 84.9.
For 𝐹𝖳(𝑅) =𝑅 →𝟏, the attempted destructor algebra extracts 𝑓 :𝑅 →𝟏 where a result 𝜇𝖬𝐹𝖳 →𝟏 is required; it fails because 𝑅 is abstract. By contrast, the nonempty 𝖥𝗈𝗈 layer contains 𝑓 :𝑅 →𝑅 and 𝑟 :𝑅, so rec(𝑓(𝑟)) is well typed for rec :𝑅 →ℕ.
In the source example, put 𝖼𝗈𝗈0 =𝖼𝗈𝗈(𝗂𝖽) and 𝑔 =𝖼𝗈𝗈(𝖼𝗈𝗈0)(𝗇𝗈𝗈). Then 𝖿𝗈𝗈 =𝖼𝗈𝗈0(𝑔). The histomorphism can unroll 𝑔, recover 𝖼𝗈𝗈0, and form 𝗅𝗈𝗈𝗉𝖥𝗈𝗈(𝖿𝗈𝗈)⟶1+𝗅𝗈𝗈𝗉𝖥𝗈𝗈(𝖼𝗈𝗈0(𝑔))≡1+𝗅𝗈𝗈𝗉𝖥𝗈𝗈(𝖿𝗈𝗈)⟶1+(1+𝗅𝗈𝗈𝗉𝖥𝗈𝗈(𝖿𝗈𝗈)). The catamorphism supplies only 𝑅 →ℕ; the histomorphism additionally supplies the unrolling observation that makes this larger self-containing argument available.