Exercise 7.16.
The type of the unquoter gives 𝛼::𝑈;𝑥:𝖤𝗑𝗉𝛼⊢𝗎𝗇𝗊𝗎𝗈𝗍𝖾[𝛼]𝑥:𝖮𝗉𝖨𝖽𝛼. Hence an application to the same 𝑥 would require, for some formed type 𝐵, 𝖮𝗉𝖨𝖽𝛼=𝛽𝖤𝗑𝗉𝛼→𝐵.(1) The left side has the constructor reduction 𝖮𝗉𝖨𝖽𝛼→∗𝛽𝛼𝖨𝖽. Because 𝛼 is a constructor variable, the application 𝛼 𝖨𝖽 is neutral and constructor-normal. The right side of (1) has arrow head. Constructor confluence and disjointness of normal heads therefore refute (1).
Now let 𝐴 be closed and let D :𝑒 :𝐴 be a closed derivation. Then ̂D :𝖤𝗑𝗉 ̂𝐴, while type recovery gives the annotated chain 𝖮𝗉𝖨𝖽̂𝐴𝑢𝑛𝑓𝑜𝑙𝑑𝖮𝗉,̂𝐴→∗𝛽𝗉𝗋𝖾𝖨𝖽(𝐴)𝑙𝑒𝑚𝑚𝑎7.66→∗𝛽𝐴. Thus 𝗎𝗇𝗊𝗎𝗈𝗍𝖾[̂𝐴]̂D is well typed at 𝐴 by constructor conversion. This calculation uses constructor normalization only; it makes no appeal to term strong normalization.
exercise 7.17.
The copied abstraction and polymorphic identity contain no application node, so the only inserted occurrence of 𝑖 is at the root: (𝜆𝑥:𝐼.𝑥)𝗂𝖽𝐼⇝sh𝑖[𝐼→𝐼](𝜆𝑥:𝐼.𝑥)𝗂𝖽𝐼. Substituting the closed polymorphic identity gives 𝗂𝖽𝐼[𝐼→𝐼](𝜆𝑥:𝐼.𝑥)𝗂𝖽𝐼⟶𝛽(𝜆𝑧:𝐼→𝐼.𝑧)(𝜆𝑥:𝐼.𝑥)𝗂𝖽𝐼⟶𝛽(𝜆𝑥:𝐼.𝑥)𝗂𝖽𝐼⟶𝛽𝗂𝖽𝐼. Before the substitution, the application is headed by the variable 𝑖. Its proper subterms are normal, so the prequotation is normal even though the represented source has a beta-redex at its root.
Exercise 7.18.
The recursively chosen constructors at the relevant kinds are 𝑆𝖳𝗒=∀𝑌::𝖳𝗒.𝑌,𝑆𝖳𝗒→𝖳𝗒=𝜆𝐴::𝖳𝗒.𝑆𝖳𝗒,𝑆𝜅=𝜆𝐹::𝖳𝗒→𝖳𝗒.𝑆𝖳𝗒,𝜅=(𝖳𝗒→𝖳𝗒)→𝖳𝗒. Rule K-All gives 𝑆𝖳𝗒 ::𝖳𝗒. Rule K-Abs first gives 𝑆𝖳𝗒→𝖳𝗒 ::𝖳𝗒 →𝖳𝗒 and, with a binder of kind 𝖳𝗒 →𝖳𝗒, gives 𝑆𝜅 ::𝜅.
In the context 𝑋 ::𝖳𝗒,𝑇 ::𝜅 →𝖳𝗒, put 𝐾𝑋 =𝜆𝐴 ::𝖳𝗒.𝑋. Then 𝐾𝑋 ::𝖳𝗒 →𝖳𝗒 and 𝑇 𝑆𝜅 ::𝖳𝗒. Expand the stripping term as Λ𝐵::𝖳𝗒.𝜆𝑐:(∀𝐶::𝖳𝗒.𝐾𝑋𝐶→𝐵).𝜆𝑥:(∀𝑢::𝜅.𝐾𝑋(𝑇𝑢)).𝑐[𝑇𝑆𝜅](𝑥[𝑆𝜅]). Under the three displayed term binders, universal elimination gives 𝑥[𝑆𝜅]:𝐾𝑋(𝑇𝑆𝜅),𝑐[𝑇𝑆𝜅]:𝐾𝑋(𝑇𝑆𝜅)→𝐵,𝑐[𝑇𝑆𝜅](𝑥[𝑆𝜅]):𝐵. Here 𝐾𝑋(𝑇𝑆𝜅) ⟶𝛽𝑋, but conversion is not needed to match the argument and domain: they are already the same constructor expression. The two term lambdas and outer type lambda therefore give 𝗌𝗍𝗋𝗂𝗉𝐾𝑋,𝜅,𝑇:𝖲𝗍𝗋𝗂𝗉𝐾𝑋(∀𝑢::𝜅.𝐾𝑋(𝑇𝑢)).
For the calculation, let 𝑞 have the type required under 𝑢 ::𝜅. Suppressing only annotations already displayed above, 𝗌𝗍𝗋𝗂𝗉𝐾𝑋,𝜅,𝑇[𝑋](Λ𝐶::𝖳𝗒.𝜆𝑧:𝑋.𝑧)(Λ𝑢::𝜅.𝑞)⟶𝛽(𝜆𝑐.𝜆𝑥.𝑐[𝑇𝑆𝜅](𝑥[𝑆𝜅]))(Λ𝐶.𝜆𝑧:𝑋.𝑧)(Λ𝑢.𝑞)⟶𝛽(𝜆𝑥.(Λ𝐶.𝜆𝑧:𝑋.𝑧)[𝑇𝑆𝜅](𝑥[𝑆𝜅]))(Λ𝑢.𝑞)⟶𝛽(Λ𝐶.𝜆𝑧:𝑋.𝑧)[𝑇𝑆𝜅]((Λ𝑢.𝑞)[𝑆𝜅])⟶𝛽(𝜆𝑧:𝑋.𝑧)((Λ𝑢.𝑞)[𝑆𝜅])⟶𝛽(𝜆𝑧:𝑋.𝑧)𝑞[𝑆𝜅/𝑢]⟶𝛽𝑞[𝑆𝜅/𝑢]. This is (7.10) at the stated higher kind.
exercise 7.19.
The term tree consists of a variable, a term abstraction, a constructor abstraction, and the final constructor application. Hence |𝑒| =4. Its operator Λ𝐴::𝖳𝗒.𝜆𝑥:𝐴.𝑥 is normal but not neutral, so the strengthened normality fold first produces 𝖳𝖥. The final type-application case copies that pair’s neutral component, which is false, into both positions. It therefore produces 𝖥𝖥, and the public projection gives 𝗂𝗌𝖭𝗈𝗋𝗆𝖺𝗅[̂𝐼→𝐼] ̂D ⟶∗𝛽𝖿𝖺𝗅𝗌𝖾. This agrees with the visible type-beta redex at the root. The same outer constructor makes 𝗂𝗌𝖠𝖻𝗌[̂𝐼→𝐼] ̂D reduce to 𝖿𝖺𝗅𝗌𝖾, while the size theorem gives 𝗌𝗂𝗓𝖾[̂𝐼→𝐼]̂D⟶∗𝛽4――.
Exercise 17.4.
The copied variable has type 𝐹𝑍. Thus the term-abstraction case is instantiated at source domain and codomain 𝑍, giving 𝑞abs=abs[𝑍][𝑍](𝜆𝑧:𝐹𝑍.𝑧):𝐹(𝐹𝑍→𝐹𝑍). Abstracting 𝑍 produces a family of type Λ𝑍::𝖳𝗒.𝑞abs:∀𝑍::𝖳𝗒.𝐹(𝐹𝑍→𝐹𝑍)=𝑃𝐹. Put 𝑇𝐹:=𝗉𝗋𝖾𝐹(𝜆𝑍 ::𝖳𝗒.𝑍 →𝑍). Then 𝑇𝐹𝑍→𝛽(𝐹𝑍→𝐹𝑍), so the strip term has type 𝗌𝗍𝗋𝗂𝗉𝐹,𝖳𝗒,𝑇𝐹:𝖲𝗍𝗋𝗂𝗉𝐹𝑃𝐹 by constructor conversion. These are the two term arguments of the constructor-abstraction case, and therefore 𝑞tabs=tabs[𝑃𝐹]𝗌𝗍𝗋𝗂𝗉𝐹,𝖳𝗒,𝑇𝐹(Λ𝑍::𝖳𝗒.𝑞abs):𝐹𝑃𝐹.
The source operator has universal type represented by 𝑃𝐹, whereas the whole instance has arrow type represented by 𝑅𝐹 =𝐹𝑃𝐹 →𝐹𝑃𝐹. Hence the type-application interface first receives the operator index 𝑃𝐹 and its child 𝑞tabs :𝐹𝑃𝐹. It then receives the result index 𝑅𝐹 and the instantiation map 𝗂𝗇𝗌𝗍𝑃𝐹,𝑃𝐹 :𝑃𝐹 →𝐹𝑅𝐹. Therefore 𝑞0=tapp[𝑃𝐹]𝑞tabs[𝑅𝐹]𝗂𝗇𝗌𝗍𝑃𝐹,𝑃𝐹:𝐹𝑅𝐹. Reversing the two indices would require 𝑞tabs :𝐹𝑅𝐹 and is rejected before any reduction is considered.
Exercise 17.5.
Put 𝑃=𝗉𝗋𝖾𝖨𝖽(∀𝑢::𝜅.𝐴),𝑄=𝗉𝗋𝖾𝖨𝖽(𝐶),𝑅=𝗉𝗋𝖾𝖨𝖽(𝐴[𝐶/𝑢]). After the recursive child has become 𝑞′, the constructor-application branch is (Λ𝑋.𝜆𝑓:𝑋.Λ𝑌.𝜆𝑔:𝑋→𝑌.𝑔𝑓)[𝑃]𝑞′[𝑅](𝜆𝑥:𝑃.𝑥[𝑄]). Keeping the type-beta and term-beta contractions separate gives (Λ𝑋.𝜆𝑓:𝑋.Λ𝑌.𝜆𝑔:𝑋→𝑌.𝑔𝑓)[𝑃]𝑞′[𝑅](𝜆𝑥:𝑃.𝑥[𝑄])𝑡𝑦𝑝𝑒𝛽⟶𝛽(𝜆𝑓:𝑃.Λ𝑌.𝜆𝑔:𝑃→𝑌.𝑔𝑓)𝑞′[𝑅](𝜆𝑥:𝑃.𝑥[𝑄])𝑡𝑒𝑟𝑚𝛽⟶𝛽(Λ𝑌.𝜆𝑔:𝑃→𝑌.𝑔𝑞′)[𝑅](𝜆𝑥:𝑃.𝑥[𝑄])𝑡𝑦𝑝𝑒𝛽⟶𝛽(𝜆𝑔:𝑃→𝑅.𝑔𝑞′)(𝜆𝑥:𝑃.𝑥[𝑄])𝑡𝑒𝑟𝑚𝛽⟶𝛽(𝜆𝑥:𝑃.𝑥[𝑄])𝑞′𝑡𝑒𝑟𝑚𝛽⟶𝛽𝑞′[𝑄]. The induction hypothesis gives 𝑞′ ⟹∗𝛽𝑒 under the constructor variable 𝑢. The first use of type recovery is 𝑄 →∗𝛽𝐶; compatible mixed reduction therefore gives 𝑞′[𝑄] ⟹∗𝛽𝑒[𝐶]. The second use is 𝑅 →∗𝛽𝐴[𝐶/𝑢], which converts the branch result type to the source result type. The operator index 𝑃 already has universal outer form by its definition, so no third recovery step is needed to form 𝑞′[𝑄].
Exercise 17.7.
The source tree has an application root, a term-abstraction operator, and the closed identity argument. Counting the identity as its type abstraction, term abstraction, and variable body gives six nodes. The fold visits each child before the application case. Each copied variable is replaced by 𝗈𝗇𝖾 in the strengthened size proof; each unary abstraction case applies successor to its child’s count; and the application case returns one plus the two child counts. Thus 1+(1+1)+(1+(1+1))=6. The outer-constructor fold ignores both recursive results and selects its application result, so it returns 𝖿𝖺𝗅𝗌𝖾 for the abstraction test. Both answers follow the displayed source tree rather than its beta-normal form.
Exercise 17.8.
Under 𝑥 :𝐴, the fundamental lemma gives a prequotation 𝐹::𝖳𝗒→𝖳𝗒;𝑥:𝐹𝗉𝗋𝖾𝐹(𝐴),Ξ𝐹⊢𝑞:𝐹𝗉𝗋𝖾𝐹(𝐵). After substituting 𝖨𝖽 and the four unquoting cases, the open claim is 𝑞 ⟹∗𝛽𝑒 under 𝑥 :𝐴, up to the constructor conversions supplied by type recovery. The variable case is the copied variable. The term-abstraction case contracts 𝗎𝗇𝖠𝖻𝗌 and applies the induction hypothesis below the binder; the term-application case contracts 𝗎𝗇𝖠𝗉𝗉, then applies the two induction hypotheses. In the type-abstraction case, 𝗎𝗇𝖳𝖠𝖻𝗌 discards its strip argument and returns the copied type abstraction, after which compatible reduction applies the induction hypothesis below the type binder. In the type-application case, 𝗎𝗇𝖳𝖠𝗉𝗉 applies 𝗂𝗇𝗌𝗍 to the recursively unquoted operator. Expanding 𝗂𝗇𝗌𝗍 yields 𝑞′[𝑄], where 𝑄 =𝗉𝗋𝖾𝖨𝖽(𝐶), and type recovery converts (Q) to the source argument (C). Conversion changes no term, so the same induction hypothesis is reused at the converted result type. What is unavailable is the closure step used in the closed quotation theorem. The term 𝑞 still has the free variable 𝑥 :𝐹𝗉𝗋𝖾𝐹(𝐴). Abstracting 𝐹 and the four cases alone would leave a free variable whose type contains the bound 𝐹, so it does not produce a term of 𝖤𝗑𝗉 ̂𝐵. The prequotation and its unquotation property remain valid as open judgments.
Exercise 17.9.
The term 𝗃𝗎𝗇𝗄𝐵 has the required representation type by the four case interfaces. Its outer tapp child is nevertheless headed by abs at the arrow-normal index 𝑃𝐹. In a genuine type-application quotation, that child quotes an operator of universal type, so its first index is the representation of a universal. Constructor normalization and injectivity of outer normal forms separate these shapes. Thus 𝗃𝗎𝗇𝗄𝐵 is well typed but outside the quotation image; no normalization contradiction is needed.
An internal quoter at each fixed index would still not supply the typing equalities required by the diagonal. Write 𝑄(𝐴):=𝖤𝗑𝗉 ̂𝐴 and suppose, hypothetically, that 𝗊𝗎𝗈𝗍𝖾𝐴 :𝐴 →𝑄(𝐴) is available for each closed 𝐴. If 𝑢𝐴 :𝑄(𝐴) →𝐴, then typing (𝑢𝐴𝑥)𝑥 for 𝑥 :𝑄(𝐴) first requires 𝐴=𝛽𝑄(𝐴)→𝐵 for some 𝐵. If the resulting diagonal term has type 𝑃, its quotation has type 𝑄(𝑃), while the diagonal term expects 𝑄(𝐴); self-application therefore also requires 𝑄(𝑃) =𝛽𝑄(𝐴). To use the unquoting equation at that quotation requires 𝑃 =𝛽𝐴. The hypothetical family of quoters establishes none of these constructor equalities. Thus it does not by itself reinstate the raw diagonal. Strong normalization is used only after the missing equalities are assumed and the forbidden application has thereby been made well typed.