The final equality premise in each term rule compares the supplied expected type 𝐶 with the type computed from the annotations and elaborated subterms. No such premise belongs in Pre-Sg, whose output is itself a type.
Determinism is syntactic at the outermost constructor. The heads 𝖲𝗀, 𝗉𝖺𝗂𝗋, 𝖿𝗌𝗍, and 𝗌𝗇𝖽 are pairwise distinct and each appears in the conclusion of exactly one rule. Once that rule is selected, all recursive inputs and the result-equality query are fixed; therefore no second rule can elaborate the same constructor in the same mode.
Choose de Bruijn indices for bound variables and a Gödel coding of finite lists and finite rooted ordered trees. Because the signature is recursive, we can effectively code every operator and rule name and decide whether a number is such a code. Decode a natural number 𝑛 as a candidate tree whose nodes carry:
a rule name and one of the five judgment forms;
codes for its context and constituent raw expressions; and
an ordered list of immediate subtrees.
Let 𝖣𝖾𝗋(𝑛) hold precisely when a bottom-up check accepts this tree. At a node the checker verifies the rule’s arity, matches the conclusion and premises against the corresponding recursive rule schema, and checks all side conditions. Raw substitution, lifting of de Bruijn indices, equality of alpha-classes, list membership, and freshness are recursive operations, so 𝖣𝖾𝗋 is a decidable predicate. The accepted numbers, in numerical order, are an effective enumeration of all derivations, possibly with harmless duplicate derivations.
Suppose total decision procedures 𝖽𝖾𝖼𝖳𝗒𝖤𝗊 and 𝖽𝖾𝖼𝖳𝗆𝖤𝗊 are given. On a derivation 𝑑 of Γ⊢𝐴𝗍𝗒𝗉𝖾, define the decidable predicate 𝑃Γ,𝐴(𝑛)⟺⎧{
{⎨{
{⎩𝖣𝖾𝗋(𝑛),root(𝑛)=Γ⊢𝐴𝑛𝗍𝗒𝗉𝖾,𝖽𝖾𝖼𝖳𝗒𝖤𝗊(𝐴,𝐴𝑛)=𝗒𝖾𝗌. The equality decider receives the input formation derivation 𝑑 and the formation derivation decoded from 𝑛. Put nfTy(𝑑):=𝜇𝑛.𝑃Γ,𝐴(𝑛). Unbounded minimization of a recursive predicate is partial recursive. It is total on the stated domain because the code of 𝑑 itself satisfies the predicate, by reflexivity.
For terms, let 𝑑 derive Γ⊢𝑎:𝐴. Define 𝑄Γ,𝑎,𝐴(𝑛) to say that 𝑛 is a derivation of some Γ⊢𝑏𝑛:𝐵𝑛, that the type decider accepts 𝐴≡𝐵𝑛, and that, after converting the decoded derivation of 𝑏𝑛:𝐵𝑛 to 𝑏𝑛:𝐴, the term decider accepts 𝑎≡𝑏𝑛:𝐴. A positive answer from the type decider can be turned effectively into an equality derivation: dovetail the recursive enumeration until a derivation of 𝐴≡𝐵𝑛 appears. This secondary search terminates exactly in the positive branch, after which the conversion tree is computably assembled. Thus 𝑄 is decidable, and nfTm(𝑑):=𝜇𝑛.𝑄Γ,𝑎,𝐴(𝑛) is partial recursive and total on typing derivations, since the code of 𝑑 itself is a witness.
It remains to verify the classifying properties. If 𝐴≡𝐴′, then by symmetry and transitivity a candidate 𝐴𝑛 is equal to 𝐴 exactly when it is equal to 𝐴′. Hence 𝑃Γ,𝐴 and 𝑃Γ,𝐴′ have the same accepted indices and their least indices coincide. Conversely, a common accepted least index provides 𝐴≡𝐴𝑛≡𝐴′, so 𝐴≡𝐴′. The term argument is identical after the classifier conversions: candidates for two judgmentally equal terms form the same set, and a common candidate gives the desired equality by symmetry and transitivity.
Finally suppose the same raw term has converted typings Γ⊢𝑎:𝐴,Γ⊢𝑎:𝐴′,Γ⊢𝐴≡𝐴′𝗍𝗒𝗉𝖾. If 𝑏𝑛:𝐵𝑛 is admissible for the first search, then 𝐴′≡𝐴≡𝐵𝑛, and conversion of the term equality 𝑎≡𝑏𝑛:𝐴 gives 𝑎≡𝑏𝑛:𝐴′. Thus it is admissible for the second search; the converse is symmetric. The candidate sets, and hence the least term index, are independent of which converted classifier was supplied. This completes every computability and totality obligation suppressed in the proposition.
Despite the exercise label, the requested extension is by coproducts. Add the type and universe-code rules
Γ⊢𝜏0⇐𝗍𝗒𝗉𝖾⇝𝐴Γ⊢𝜏1⇐𝗍𝗒𝗉𝖾⇝𝐵
Γ⊢𝜏0+𝜏1⇐𝗍𝗒𝗉𝖾⇝𝐴+𝐵
Ty-Sum
The universe-code rule is separate:
unUniv(Γ,𝐶)=𝑖Γ⊢𝜏0⇐U𝑖⇝𝐴Γ⊢𝜏1⇐U𝑖⇝𝐵
Γ⊢𝜏0+𝜏1⇐𝐶⇝𝐴+𝐵
Chk-Code-Sum
The two introduction forms check against an expected coproduct:
unSum(Γ,𝐶)=(𝐴,𝐵)Γ⊢𝑒⇐𝐴⇝𝑎
Γ⊢𝗂𝗇𝗅(𝑒)⇐𝐶⇝𝗂𝗇𝗅(𝑎)
Chk-Inl
unSum(Γ,𝐶)=(𝐴,𝐵)Γ⊢𝑒⇐𝐵⇝𝑏
Γ⊢𝗂𝗇𝗋(𝑒)⇐𝐶⇝𝗂𝗇𝗋(𝑏)
Chk-Inr
Soundness of unSum includes a derivation 𝐶≡𝐴+𝐵; it is the implicit conversion that validates the returned constructor at the original expected type. Universal coherence says that these 𝐴,𝐵 agree with the components of every other coproduct presentation of 𝐶.
Retain an explicit motive in the surface eliminator and write it as 𝗂𝗇𝖽+(𝑧.𝜏;𝑒ℓ,𝑒𝑟;𝑒). Its synthesis rule is
For termination, the head constructor chooses one rule. Every recursive query is on a proper subexpression: the summands, injected term, scrutinee, motive, or one of the two branches. Calls to unSum and unUniv are total by hypothesis, and all substitutions only construct expected types. Hence the same lexicographic (mode, expression-size) argument as for the original rules terminates.
For soundness of Syn-SumInd, the induction hypotheses give Γ⊢𝑠:𝐷,Γ,𝑧:𝐴+𝐵⊢𝐶𝗍𝗒𝗉𝖾,Γ⊢𝑓:∏𝑥:𝐴𝐶[𝗂𝗇𝗅(𝑥)/𝑧],Γ⊢𝑔:∏𝑦:𝐵𝐶[𝗂𝗇𝗋(𝑦)/𝑧]. Soundness of unSum gives 𝐷≡𝐴+𝐵, so conversion yields 𝑠:𝐴+𝐵. The primitive coproduct eliminator then derives Γ⊢𝗂𝗇𝖽+(𝑓,𝑔,𝑠):𝐶[𝑠/𝑧], which is exactly the synthesized output judgment. No unstated inversion of 𝐷 is used; all such information is supplied by the coherent unSum call.
Put Γ:=⋅, 𝐴:=ℕ, 𝑎:=𝟢, 𝜏:=ℕ, and 𝑒:=𝟢. Then Γ⊢𝜏⇐𝗍𝗒𝗉𝖾⇝𝐴 and Γ⊢𝑒⇐𝐴⇝𝑎 are the two base rules. Use the annotated eliminand 𝑞:=(𝗋𝖾𝖿𝗅(𝑒):𝖨𝖽𝜏(𝑒,𝑒)). Rule Syn-Ann first checks 𝖨𝖽𝜏(𝑒,𝑒) as a type. Its three queries are Γ⊢𝜏⇐𝗍𝗒𝗉𝖾⇝𝐴,Γ⊢𝑒⇐𝐴⇝𝑎,Γ⊢𝑒⇐𝐴⇝𝑎, followed by Ty-Id. It then checks 𝗋𝖾𝖿𝗅(𝑒) at the resulting core type. Here unId returns (𝐴,𝑎,𝑎); the single recursive query checks 𝑒 against 𝐴 and returns 𝑎, and the two conversion tests 𝑎⇔𝑎:𝐴 are reflexive. Thus Γ⊢𝑞⇒𝖨𝖽𝐴(𝑎,𝑎)⇝𝗋𝖾𝖿𝗅𝑎.
Put Δ:=Γ,𝑥:𝐴,𝑦:𝐴,𝑝:𝖨𝖽𝐴(𝑥,𝑦). Rule Ty-ℕ elaborates 𝜏 to 𝐴 in every displayed context, so Ty-Id checks the surface motive 𝖨𝖽𝜏(𝑥,𝑦) by Δ⊢𝜏⇐𝗍𝗒𝗉𝖾⇝𝐴,Δ⊢𝑥⇐𝐴⇝𝑥,Δ⊢𝑦⇐𝐴⇝𝑦. It returns 𝐶(𝑥,𝑦,𝑝):=𝖨𝖽𝐴(𝑥,𝑦). After substituting 𝑥=𝑧, 𝑦=𝑧, and 𝑝=𝗋𝖾𝖿𝗅𝑧, the required branch type is 𝖨𝖽𝐴(𝑧,𝑧). A second use of Chk-Refl gives Γ,𝑧:𝐴⊢𝗋𝖾𝖿𝗅(𝑧)⇐𝖨𝖽𝐴(𝑧,𝑧)⇝𝗋𝖾𝖿𝗅𝑧. Its queries are unId(Γ,𝑧:𝐴,𝖨𝖽𝐴(𝑧,𝑧))=(𝐴,𝑧,𝑧),Γ,𝑧:𝐴⊢𝑧⇐𝐴⇝𝑧, followed by the two reflexive conversion tests 𝑧⇔𝑧:𝐴. Thus the branch call has no suppressed algorithmic premise. All premises of Syn-𝐽 are now present. With 𝜏𝐶(𝑥,𝑦,𝑝):=𝖨𝖽𝜏(𝑥,𝑦) and 𝑐(𝑧):=𝗋𝖾𝖿𝗅𝑧, its output is Γ⊢𝖩(𝑥.𝑦.𝑝.𝜏𝐶;𝑧.𝗋𝖾𝖿𝗅(𝑧);𝑞)⇒𝖨𝖽𝐴(𝑎,𝑎)⇝𝖩𝐴;𝑎;𝑎(𝑥.𝑦.𝑝.𝐶;𝑧.𝑐;𝗋𝖾𝖿𝗅𝑎). The annotation is essential: reflexivity is an introduction and therefore does not synthesize by itself.
Fix 𝑎:𝐴 and define 𝖲𝗂𝗇𝗀𝐴(𝑎):=∑𝑥:𝐴𝖤𝗊𝐴(𝑥,𝑎). Its canonical introduction and underlying-value projection are 𝗌𝗂𝗇𝗀𝑎:=(𝑎,𝗋𝖾𝖿𝗅𝑎):𝖲𝗂𝗇𝗀𝐴(𝑎),𝗈𝗎𝗍(𝑢):=𝗉𝗋1(𝑢):𝐴. For arbitrary 𝑢:𝖲𝗂𝗇𝗀𝐴(𝑎), the second projection has type 𝗉𝗋2(𝑢):𝖤𝗊𝐴(𝗈𝗎𝗍(𝑢),𝑎). One use of Eq-Reflect therefore gives the defining judgmental equality 𝗈𝗎𝗍(𝑢)≡𝑎:𝐴.
For eta, Σ-eta first gives 𝑢≡(𝗉𝗋1(𝑢),𝗉𝗋2(𝑢)). The defining equality compares the first components 𝗉𝗋1(𝑢)≡𝑎. Rule Eq-Uniq gives 𝗉𝗋2(𝑢)≡𝗋𝖾𝖿𝗅:𝖤𝗊𝐴(𝗉𝗋1(𝑢),𝑎), where the reflexivity classifier is converted along the equality of first components. Dependent pair congruence now yields (𝗉𝗋1(𝑢),𝗉𝗋2(𝑢))≡(𝑎,𝗋𝖾𝖿𝗅𝑎). Composing with Σ-eta proves 𝑢≡𝗌𝗂𝗇𝗀𝑎:𝖲𝗂𝗇𝗀𝐴(𝑎). Thus the encoding has the expected point, projection equation, and judgmental singleton eta law.
After the first two declarations, let 𝑎:=𝗌𝗎𝖼(𝗌𝗎𝖼(𝟢)). The defined context contains 𝐷(𝑐)=(ℕ,𝑎),𝐷(𝑝)=(𝖨𝖽ℕ(𝑎,𝑎),𝗋𝖾𝖿𝗅𝑎). In the third declared type, both occurrences of 𝑐 elaborate by Syn-Var-Def to 𝑎, so the type elaborates to 𝖨𝖽ℕ(𝑎,𝑎). Its body 𝗋𝖾𝖿𝗅(𝑐) checks at this type: the endpoint elaborates to 𝑎, and Chk-Refl returns 𝗋𝖾𝖿𝗅𝑎. Hence the updated map stores 𝐷(𝑞)=(𝖨𝖽ℕ(𝑎,𝑎),𝗋𝖾𝖿𝗅𝑎). If a recursive query is made under a fresh local declaration 𝑦:𝐵, the entry for 𝑐 does not become a variable. It returns the weakening 𝑎↑𝑦:ℕ in the enlarged context; similarly the entries for 𝑝 and 𝑞 return the weakened term 𝗋𝖾𝖿𝗅𝑎↑𝑦.
The hypotheses 𝑒𝐾 and 𝑒𝑆 are needed only for the two generating steps. Applying them to encoded arguments produces terms of the appropriate extensional equality types, and Eq-Reflect turns those terms into the judgmental equations encoding SK-K and SK-S.
Everything used to close those equations is already built into judgmental equality. If the induction derivation of 𝑡∼𝑢 ends in reflexivity, use term-equality reflexivity on ⌜𝑡⌝:𝑋. If it ends in symmetry or transitivity, apply the corresponding structural rule to the induction hypothesis or hypotheses. In the application case, the two induction hypotheses are combined by congruence of the context variable 𝑎𝑝𝑝:𝑋→𝑋→𝑋, yielding ⌜𝑡𝑣⌝=𝑎𝑝𝑝⌜𝑡⌝⌜𝑣⌝≡𝑎𝑝𝑝⌜𝑢⌝⌜𝑤⌝=⌜𝑢𝑤⌝:𝑋. Thus reflexive, symmetric, transitive, and congruence closure are rules of the ambient judgmental equality, not additional assumptions in Γ𝖲𝖪. The context need hypothesize only the two nonstructural generating equations.
Write 𝑟𝑡:=𝖾𝗊𝗋𝖾𝖿𝗅⌜𝑡⌝. If ⌜𝑡⌝≡⌜𝑢⌝:𝑋, then Eq congruence gives 𝖤𝗊𝑋(⌜𝑡⌝,⌜𝑡⌝)≡𝖤𝗊𝑋(⌜𝑡⌝,⌜𝑢⌝)𝗍𝗒𝗉𝖾. The conversion direction is the tree Γ𝖲𝖪⊢⌜𝑡⌝:𝑋Γ𝖲𝖪⊢𝑟𝑡:𝖤𝗊𝑋(⌜𝑡⌝,⌜𝑡⌝)Eq−IΓ𝖲𝖪⊢𝖤𝗊𝑋(⌜𝑡⌝,⌜𝑡⌝)≡𝖤𝗊𝑋(⌜𝑡⌝,⌜𝑢⌝)𝗍𝗒𝗉𝖾Γ𝖲𝖪⊢𝑟𝑡:𝖤𝗊𝑋(⌜𝑡⌝,⌜𝑢⌝)Conv. The second premise is the Eq-congruence judgment displayed just above; its nonreflexive endpoint premise is the assumed ⌜𝑡⌝≡⌜𝑢⌝:𝑋. Conversely, reflection is the one-step tree Γ𝖲𝖪⊢𝑟𝑡:𝖤𝗊𝑋(⌜𝑡⌝,⌜𝑢⌝)Γ𝖲𝖪⊢⌜𝑡⌝≡⌜𝑢⌝:𝑋Eq−Reflect. Thus the term-typing query and the SK equality query are equivalent, with no appeal to an unannotated surface 𝗋𝖾𝖿𝗅.
Application synthesizes 𝖺𝗉𝗉(𝑓,𝑎;𝐴,𝐵) after normalizing the type of 𝑓 and inverting its Π head; the independent check rechecks 𝑓, checks 𝑎:𝐴, and substitutes 𝑎 into 𝐵. Natural elimination records the motive 𝑘.𝐶, zero branch, and step branch 𝑛:ℕ,𝑦:𝐶[𝑛/𝑘]⊢𝑠:𝐶[𝗌𝗎𝖼(𝑛)/𝑘]; rechecking repeats these three premises and returns 𝐶[𝑚/𝑘]. Identity elimination records 𝑥,𝑦,𝑝.𝐶 and the reflexive branch after 𝑦,𝑥,𝑝 are replaced by 𝑥,𝑥,𝗋𝖾𝖿𝗅𝑥. Normalization occurs only before head inversion; constructor inversion chooses the rule; context conversion transports a checked branch when its reconstructed type is judgmentally, but not syntactically, the stored annotation.