Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
Extend the pure term grammar of chapter 3 by 𝑒::=⋯∣𝖿𝗂𝗑𝑓.𝑒. The constructor 𝖿𝗂𝗑𝑓.𝑒 binds 𝑓 in 𝑒. Terms are identified up to alpha-renaming of that binder, and substitution is the capture-avoiding substitution of definition 1.58 with the new clause (𝖿𝗂𝗑𝑓.𝑒)[𝑢/𝑥]=𝖿𝗂𝗑𝑓.(𝑒[𝑢/𝑥])(𝑓≠𝑥,𝑓∉FV(𝑢)), after alpha-renaming 𝑓 when the freshness condition fails. Operationally, one step unfolds one copy: 𝖿𝗂𝗑𝑓.𝑒⟶𝑒[𝖿𝗂𝗑𝑓.𝑒/𝑓]. The monomorphic-recursion baseline assigns one monotype 𝜏 to the binder and requires the body to have that same monotype: Γ,𝑓:𝜏⊢𝑒:𝜏Γ⊢𝖿𝗂𝗑𝑓.𝑒:𝜏Mono−Fix.
Now consider 𝖿𝗂𝗑𝑓.𝜆𝑥.𝑓(𝜆𝑦.𝑥). Choose fresh type variables 𝛼,𝛽,𝛾. If the argument of the outer abstraction has type 𝛼, then 𝜆𝑦.𝑥 has type 𝛽→𝛼. The recursive occurrence therefore needs an instance 𝑓:(𝛽→𝛼)→𝛾 of ∀𝜁𝜂.𝜁→𝜂; polymorphic recursion will assign this scheme to 𝑓. Under monomorphic recursion, the whole body 𝜆𝑥.𝑓(𝜆𝑦.𝑥) has type 𝛼→𝛾, so Mono-Fix assigns 𝑓 that same type. Equating it with the occurrence type and decomposing the outer arrows gives 𝛼→𝛾=(𝛽→𝛼)→𝛾⟹𝛼=𝛽→𝛼, which fails the occurs check: a finite first-order type cannot equal a type containing itself as a proper subtree. The missing operation is not another equality solver: each recursive occurrence must be allowed a separate instance of the scheme assigned to the definition. Equation (5.1) also shows that the term diverges when it is applied; typability here is a static property, not a termination claim.
One outer substitution and many matchers
Fix the arrow signature with a countably infinite set V of type variables. Its first-order terms are 𝑀,𝑁::=𝛼∣𝑀→𝑁,𝛼∈V. A finite substitution 𝑆 maps finitely many variables to arrow terms, fixes every other variable, and extends homomorphically, so 𝑆(𝑀→𝑁)=𝑆(𝑀)→𝑆(𝑁).
An arrow term 𝑀matches an arrow term 𝑁, written 𝑀⪯𝗌𝗎𝑁, if and only if there is a finite substitution 𝑅 such that 𝑅(𝑀)=𝑁. The substitution 𝑅 may replace variables of 𝑀; it does not first change 𝑁.
Thus 𝛼⪯𝗌𝗎𝛽→𝛽, witnessed by 𝑅=[𝛽→𝛽/𝛼]. In contrast, 𝛼→𝛼⪯𝗌𝗎𝛽→𝛾 holds exactly when 𝛽=𝛾: because equal arrow trees have equal left and right children, decomposition gives both 𝑅(𝛼)=𝛽 and 𝑅(𝛼)=𝛾. Conversely, if 𝛽=𝛾, the matcher [𝛽/𝛼] witnesses the relation.
A semi-unification problem is a finite family I={𝑀𝑖⪯𝗌𝗎𝑁𝑖}𝑛𝑖=1. A semi-unifier of I is a finite outer substitution 𝑆 such that, for every 𝑖, there is a finite matching substitution 𝑅𝑖 with 𝑅𝑖(𝑆(𝑀𝑖))=𝑆(𝑁𝑖). The matchers 𝑅𝑖 may differ; the outer substitution 𝑆 is shared by all inequalities. A mixed problem may also contain equations 𝑃𝑗≐𝑄𝑗; then 𝑆(𝑃𝑗)=𝑆(𝑄𝑗) is required in addition to equation 5.3. We continue to call this finite mixture a semi-unification problem.
The distinction between 𝑆 and the 𝑅𝑖 is load-bearing. The problem {𝛼⪯𝗌𝗎𝛼→𝛼,𝛼⪯𝗌𝗎𝛼→(𝛼→𝛼)} has the outer solution 𝑆=𝗂𝖽. Its first matcher sends 𝛼 to 𝛼→𝛼; its second matcher sends 𝛼 to 𝛼→(𝛼→𝛼). Requiring one matcher for the whole family would reject equation 5.4 and would define a different problem.
Unification is recovered by forcing a matcher to give the same result in two positions.
For arrow terms 𝑀,𝑁 and a finite substitution 𝑆, 𝑆(𝑀)=𝑆(𝑁)⟺(𝑆(𝑀),𝑆(𝑀))⪯𝗌𝗎(𝑆(𝑀),𝑆(𝑁)). Here (𝑃,𝑄) abbreviates the arrow term 𝑃→𝑄; longer tuples associate to the right. Thus the same binary constructor forms both the source trees and the pair used by the equation encoding. The right side of equation 5.5 is precisely the replay condition for 𝑆 on the untransformed inequality because homomorphic extension gives 𝑆((𝑀,𝑀))=(𝑆(𝑀),𝑆(𝑀)) and 𝑆((𝑀,𝑁))=(𝑆(𝑀),𝑆(𝑁)). Consequently 𝑆 unifies 𝑀≐𝑁 if and only if 𝑆 semi-unifies (𝑀,𝑀)⪯𝗌𝗎(𝑀,𝑁).
Proof. If 𝑆(𝑀)=𝑆(𝑁), the identity matcher witnesses the right side of equation 5.5. Conversely, let 𝑅 witness the right side. Decomposition gives 𝑅(𝑆(𝑀))=𝑆(𝑀),𝑅(𝑆(𝑀))=𝑆(𝑁). Transitivity of syntactic equality gives 𝑆(𝑀)=𝑆(𝑁). ◻
★☆☆ Use proposition 5.3 to encode (𝛼→𝛽)≐(𝛾→𝛾) as one inequality. Give its most general unifier and a matcher witnessing the encoded inequality after that unifier is applied.
Proof. Suppose 𝑆 and 𝑅 satisfied 𝑅(𝑆(𝛼)→𝑆(𝛼))=𝑆(𝛼). Homomorphic extension gives 𝑅(𝑆(𝛼)→𝑆(𝛼))=𝑅(𝑆(𝛼))→𝑅(𝑆(𝛼)). Define the node count by |𝛼|=1 and |𝑃→𝑄|=1+|𝑃|+|𝑄|. The assumed equality and equation 5.6 give |𝑆(𝛼)|=1+2|𝑅(𝑆(𝛼))|. Every variable leaf of 𝑆(𝛼) is replaced by a nonempty term, and every arrow node is retained. Hence |𝑅(𝑆(𝛼))|≥|𝑆(𝛼)|. Equation 5.7 would imply |𝑆(𝛼)|≥1+2|𝑆(𝛼)|, which is impossible in ℕ. ◻
The complete programming language is the pure extended lambda calculus: 𝑒::=𝑥∣𝜆𝑥.𝑒∣𝑒𝑒∣𝗅𝖾𝗍𝑥=𝑒𝗂𝗇𝑒∣𝖿𝗂𝗑𝑥.𝑒. The binders and operational clause for 𝖿𝗂𝗑 are those stated at the chapter opening. Constants can be represented by variables in a fixed global environment. Monotypes and predicative schemes are 𝜏::=𝛼∣𝜏→𝜏,𝜎::=𝜏∣∀𝛼.𝜎. Quantifiers occur only in the prefix of a scheme and range over monotypes. For a scheme 𝜎=∀¯𝛼.𝜏, write 𝜎≽𝜏′ when 𝜏′=𝜏[¯𝜈/¯𝛼] for a positionwise vector of monotypes ¯𝜈.
The judgment Γ⊢𝖬𝖬𝑒:𝜎 is generated by the HM rules of definition 3.16—Var, Inst, Gen, Lam, App, and Let—together with Γ,𝑥:𝜎⊢𝖬𝖬𝑒:𝜎Γ⊢𝖬𝖬𝖿𝗂𝗑𝑥.𝑒:𝜎MM−Fix. In Gen, the quantified variable is not free in Γ. In MM-Fix, the recursive occurrences and the body share a scheme, not one monotype. Replacing 𝜎 in the premise by a monotype 𝜏 gives the ordinary monomorphic-recursion rule, called Mono-Fix below.
The opening term has a complete finite derivation. Put 𝜎=∀𝜁𝜂.𝜁→𝜂 and Γ𝑓=𝑓:𝜎 and Δ=Γ𝑓,𝑥:𝛼. The quantified variables 𝜁,𝜂 are distinct from the free variables 𝛼,𝛽,𝛾. Substituting 𝛽→𝛼 for 𝜁 and 𝛾 for 𝜂 witnesses the instance used below. Its application subderivation is Dapp=(𝑓:𝜎)∈ΔΔ⊢𝖬𝖬𝑓:𝜎Var𝜎≽(𝛽→𝛼)→𝛾Δ⊢𝖬𝖬𝑓:(𝛽→𝛼)→𝛾Inst(𝑥:𝛼)∈(Δ,𝑦:𝛽)Δ,𝑦:𝛽⊢𝖬𝖬𝑥:𝛼VarΔ⊢𝖬𝖬𝜆𝑦.𝑥:𝛽→𝛼LamΔ⊢𝖬𝖬𝑓(𝜆𝑦.𝑥):𝛾App. Recall that ftv(Γ𝑓) is the set of type variables free in the schemes of Γ𝑓. Since 𝜎 is closed, ftv(Γ𝑓)=∅, so both generalization side conditions below hold. The second Gen conclusion is ∀𝛼.∀𝛾.𝛼→𝛾, which is 𝜎 up to alpha-equivalence. Using the application subtree, the complete outer derivation is DappΓ𝑓⊢𝖬𝖬𝜆𝑥.𝑓(𝜆𝑦.𝑥):𝛼→𝛾Lam𝛾∉ftv(Γ𝑓)Γ𝑓⊢𝖬𝖬𝜆𝑥.𝑓(𝜆𝑦.𝑥):∀𝛾.𝛼→𝛾Gen𝛼∉ftv(Γ𝑓)Γ𝑓⊢𝖬𝖬𝜆𝑥.𝑓(𝜆𝑦.𝑥):𝜎Gen⊢𝖬𝖬𝖿𝗂𝗑𝑓.𝜆𝑥.𝑓(𝜆𝑦.𝑥):𝜎MM−Fix. The derivation is finite even though the unannotated program diverges when called.
A constraint generator needs to remember which type variables may be instantiated. A simple environment 𝐴 maps term variables to monotypes. The corresponding MM environment Γ maps the same term variables to schemes; 𝐴 is obtained by erasing each scheme’s quantifier prefix. The formerly bound variables thereby become free in 𝐴 and remain available to matchers. The nongeneric variables of Γ are the members of ftv(Γ). Initially, the finite sequence ¯𝜌 contains each such variable 𝛼 as the variable monotype 𝛼, in any fixed order. While the derivation enters a lambda body, it appends that binder’s monotype; leaving the body removes it. The protected set is ⋃𝜌∈¯𝜌ftv(𝜌). Every other variable of a let- or fix-bound type may be changed by a matcher. Omitting the ambient nongeneric variables would incorrectly permit a monomorphic assumption 𝑥:𝛼 to be used at the unrelated type 𝛽→𝛽.
If ¯𝜌=(𝜌1,…,𝜌𝑘), then (𝜏,¯𝜌) denotes the right-associated arrow tuple (𝜏,𝜌1,…,𝜌𝑘); when 𝑘=0, it denotes 𝜏 itself. The notation (¯𝜌,𝜏) appends 𝜏 to that sequence.
The protected side condition can be calculated before stating the rules. Take Γ𝑓=𝑓:∀𝛿.𝛿→𝛾. Erasing its prefix gives 𝐴(𝑓)=𝛿→𝛾, while its free variable gives the initial protected sequence ¯𝜌=(𝛾). Using 𝑓 at the opening’s occurrence type (𝛽→𝛼)→𝛾 requires (𝛿→𝛾,𝛾)⪯𝗌𝗎((𝛽→𝛼)→𝛾,𝛾). The matcher [𝛽→𝛼/𝛿] changes the first component and fixes the protected component 𝛾. Distinct variables 𝛿 and 𝛼 permit this inequality. Rule Mono-Fix would identify 𝛿, the domain of the recursive function’s assumed type, with 𝛼, the domain of the outer abstraction, and would impose the occurs-check equation 𝛼=𝛽→𝛼.
As in equation 5.5, tuples use right-associated arrows. A matcher witnessing a side condition must fix every component of ¯𝜌 because the same component occurs on both sides. In FO-Let, occurrence typing through FO-Var may change exactly the variables of 𝜏1 absent from ¯𝜌; that is where let-generalization is represented. In FO-Fix, the first two side conditions mutually match the assumed type 𝜏𝑥 and body type 𝜏𝑏, so they represent one scheme up to renaming of unprotected variables. The third side condition instantiates that body scheme to the conclusion type 𝜏.
Here is one complete use of the new variable rule. With 𝐴=(𝑓:𝛿→𝛾) and protected sequence (𝛾), the calculated matcher above supplies the only nonlookup premise: 𝐴(𝑓)=𝛿→𝛾(𝛿→𝛾,𝛾)⪯𝗌𝗎((𝛽→𝛼)→𝛾,𝛾)𝐴;(𝛾)⊢𝖥𝖮𝑓:(𝛽→𝛼)→𝛾FO−Var.
For a monotype 𝜏, let GenΓ(𝜏)=∀¯𝛼.𝜏,{¯𝛼}=ftv(𝜏)∖ftv(Γ), where the prefix is standardized apart before use. The syntax-directed Milner–Mycroft judgmentΓ⊢𝖲𝖣𝑒:𝜏 has the five rules
Γ(𝑥)≽𝜏
Γ⊢𝖲𝖣𝑥:𝜏
SD-Var
Γ,𝑥:𝜏1⊢𝖲𝖣𝑒:𝜏2
Γ⊢𝖲𝖣𝜆𝑥.𝑒:𝜏1→𝜏2
SD-Abs
Γ⊢𝖲𝖣𝑒1:𝜏2→𝜏Γ⊢𝖲𝖣𝑒2:𝜏2
Γ⊢𝖲𝖣𝑒1𝑒2:𝜏
SD-App
Γ⊢𝖲𝖣𝑒1:𝜏1Γ,𝑥:GenΓ(𝜏1)⊢𝖲𝖣𝑒2:𝜏2
Γ⊢𝖲𝖣𝗅𝖾𝗍𝑥=𝑒1𝗂𝗇𝑒2:𝜏2
SD-Let
𝜎=𝛼GenΓ(𝜏𝑏)Γ,𝑥:𝜎⊢𝖲𝖣𝑒:𝜏𝑏𝜎≽𝜏
Γ⊢𝖲𝖣𝖿𝗂𝗑𝑥.𝑒:𝜏
SD-Fix
Thus instantiation is explicit only at a variable leaf and at the result of a recursive definition; let and fix generalize exactly the variables absent from the ambient environment.
Proof of Theorem 5.8 — Local syntax-directed normalization
Proof. Two transformations are used in the induction. If a type substitution 𝑈 fixes ftv(Γ), applying 𝑈 to every displayed monotype in a derivation preserves each rule and its freshness premise. The proof is rule induction; at Gen, rename the quantified variable away from dom(𝑈)∪ftv(rng(𝑈)) before applying the induction hypothesis. Also, replacing an assumption by a scheme with at least the same monotype instances preserves derivability. This is rule induction again; only Var changes, and its old instance remains available.
For the forward direction, strengthen the induction statement by fixing a requested monotype instance of the concluding scheme. Standardize every prefix and the range of the requested instantiation apart. In Var, the requested monotype is an instance of Γ(𝑥), so SD-Var applies. In Inst, compose the displayed instantiation with the requested one. In Gen, substitute the requested monotype for the freshly bound variable; the side condition ensures that this substitution fixes Γ.
The Lam case applies the induction hypothesis to the body and then SD-Abs. The App case freshens the private variables of its two premises, invokes both induction hypotheses at the common argument monotype, and uses SD-App. For Let, normalize the bound expression to 𝜏1. The scheme GenΓ(𝜏1) contains every instance supplied by the old bound scheme. Replace the old assumption by this standardized-apart maximal scheme, normalize the body, and apply SD-Let.
For MM-Fix, expose the body monotype 𝜏𝑏 immediately below the final generalizations and instantiations. Standardize its recursive prefix apart, replace the recursive assumption by GenΓ(𝜏𝑏), and apply the induction hypothesis to the body. The requested result monotype is an instance of that same scheme, so SD-Fix closes the case. This treats Var, Inst, Gen, Lam, App, Let, and MM-Fix; no rule family is delegated.
For the reverse direction, induct on the syntax-directed derivation. SD-Var expands to Var followed by Inst. The abstraction and application cases use the corresponding MM rules. In SD-Let, apply Gen once for each variable in the displayed maximal prefix before Let. In SD-Fix, generalize the body to 𝜎, use MM-Fix, and instantiate its result to 𝜏. Alpha-equivalent prefixes are identified by the binding convention. The construction preserves a specified monotype conclusion. ◻
Let 𝑃 be a finite tuple of arrow terms. If (𝑀,𝑃)⪯𝗌𝗎(𝑁,𝑃)and(𝑁,𝑃)⪯𝗌𝗎(𝑀,𝑃), then the variables of 𝑀 outside ftv(𝑃) are carried to the variables of 𝑁 outside ftv(𝑃) by a bijective renaming that fixes every variable occurring in 𝑃. Conversely, every such renaming supplies the two matchers. Thus generalizing exactly the variables absent from 𝑃 gives alpha-equivalent schemes.
Proof of Lemma 5.9 — Mutual protected matching is renaming
Proof. Let 𝑅(𝑀,𝑃)=(𝑁,𝑃) and 𝑄(𝑁,𝑃)=(𝑀,𝑃). A substitution on finite arrow trees never decreases node count: it retains every arrow node and replaces a variable leaf by a nonempty tree. Hence |𝑀|≤|𝑁|≤|𝑀|. Both inequalities are equalities. Every variable leaf changed by either matcher is therefore replaced by one variable leaf, never by an arrow. If two distinct leaf classes of 𝑀 were identified by 𝑅, the corresponding leaves of 𝑁 would be identical and 𝑄 could not recover their distinct occurrence classes. The same argument with 𝑀,𝑁 interchanged proves that the leaf-class map is surjective. The resulting bijection preserves the complete occurrence pattern. The tuple equations 𝑅(𝑃)=𝑃=𝑄(𝑃) force it to fix the variables of 𝑃. A renaming and its inverse prove the converse, and quantifying the variables outside 𝑃 turns that renaming into alpha-equivalence. ◻
Let Γ be a scheme environment. Choose bound variables in its schemes disjoint from one another and from ftv(Γ). Let 𝐴 erase the quantifier prefixes, and let ¯𝜌 contain one variable monotype for every member of ftv(Γ). During the induction on 𝑒, append the monotype of each lambda binder when entering its body and remove it when leaving that body. Then Γ⊢𝖲𝖣𝑒:𝜏 exists if and only if 𝐴;¯𝜌⊢𝖥𝖮𝑒:𝜏 exists, up to consistent renaming of variables absent from ¯𝜌.
Proof. Rule induction on the syntax-directed derivation proves the forward implication.
In the variable case, write Γ(𝑥)=∀¯𝛼.𝜏𝑥. The MM instance replaces only ¯𝛼 and fixes every nongeneric variable. The latter variables are exactly those occurring in ¯𝜌. The same replacement therefore witnesses (𝜏𝑥,¯𝜌)⪯𝗌𝗎(𝜏,¯𝜌) and derives FO-Var. The ambient free variables already occur in ¯𝜌, and the abstraction case adds its domain type, so subsequent matchers fix every nongeneric variable. The application case turns the final App premise into the equality 𝜏1=𝜏2→𝜏. At a let, variables free in the inferred type of 𝑒1 but absent from ¯𝜌 are precisely the variables generalized by SD-Let. At a fix, standardize the recursive prefix apart from the body monotype. Their erased monotypes are variants outside ¯𝜌, so lemma 5.9 supplies both protected matchings. The result instance supplies the third protected matching.
For the reverse implication, induct on the first-order derivation. In FO-Var, a witnessing matcher changes no variable of ¯𝜌; quantify the other variables of 𝐴(𝑥), apply Inst, and obtain the conclusion type. In FO-Abs, extend the MM environment by the monomorphic domain and apply the induction hypothesis to the body. The equality side condition then permits Lam. The FO-App case applies the two induction hypotheses and App. In FO-Let, generalize exactly the variables of 𝜏1 absent from ¯𝜌 before applying the induction hypothesis to 𝑒2. In FO-Fix, mutual protected matching makes the recursive template and body variants by lemma 5.9. Quantify their variables absent from ¯𝜌, identify the resulting schemes up to alpha-renaming, and use SD-Fix; the remaining inequality supplies its result instance. These five cases exhaust the term grammar. ◻
Constraint generation and the forward reduction
Let 𝑉0 be the finite set of type-variable names already used in the destination problem. For each syntax-node occurrence 𝑝 in a term, choose a root type variable 𝑎𝑝; for each lambda or fix binder at 𝑝, choose a binder variable 𝑏𝑝. The entire family {𝑎𝑝}∪{𝑏𝑝} is pairwise distinct and disjoint from ftv(𝐴)∪ftv(¯𝜌) and from every member of 𝑉0. Write 𝑒𝑝 when 𝑝 is the root occurrence of 𝑒.
Before giving the general recursion, run it on 𝜆𝑥.𝑥. Let 𝑞 be the lambda root and 𝑝 its variable child. The binder has variable 𝑏𝑞; the two root variables are 𝑎𝑞,𝑎𝑝. The variable occurrence contributes (𝑏𝑞,𝑏𝑞)⏟bindertypeandprotectedbinder⪯𝗌𝗎(𝑎𝑝,𝑏𝑞)⏟occurrencerootandsameprotectedbinder, and the lambda contributes 𝑎𝑞≐𝑏𝑞→𝑎𝑝. Thus the generator must remember both the root 𝑞 and the binder selected by the occurrence at 𝑝. The procedure 𝖲𝖤𝖨(𝐴,¯𝜌,𝑒𝑝) traverses the syntax once and returns 𝑎𝑝 with a finite mixed problem.
If the immediate subterms below have roots 𝑞 and 𝑟, the clauses of 𝖲𝖤𝖨 are: 𝖲𝖤𝖨(𝐴,¯𝜌,𝑥𝑝)=(𝑎𝑝,{(𝐴(𝑥),¯𝜌)⪯𝗌𝗎(𝑎𝑝,¯𝜌)}),𝖲𝖤𝖨(𝐴,¯𝜌,(𝜆𝑥.𝑒𝑞)𝑝)=(𝑎𝑝,𝐸∪{𝑎𝑝≐𝑏𝑝→𝑎𝑞}),𝖲𝖤𝖨(𝐴,¯𝜌,(𝑒𝑞1𝑒𝑟2)𝑝)=(𝑎𝑝,𝐸1∪𝐸2∪{𝑎𝑞≐𝑎𝑟→𝑎𝑝}),𝖲𝖤𝖨(𝐴,¯𝜌,(𝗅𝖾𝗍𝑥=𝑒𝑞1𝗂𝗇𝑒𝑟2)𝑝)=(𝑎𝑝,𝐸1∪𝐸2∪{𝑎𝑝≐𝑎𝑟}),𝖲𝖤𝖨(𝐴,¯𝜌,(𝖿𝗂𝗑𝑥.𝑒𝑞)𝑝)=(𝑎𝑝,𝐸∪{(𝑏𝑝,¯𝜌)⪯𝗌𝗎(𝑎𝑞,¯𝜌),(𝑎𝑞,¯𝜌)⪯𝗌𝗎(𝑏𝑝,¯𝜌),(𝑎𝑞,¯𝜌)⪯𝗌𝗎(𝑎𝑝,¯𝜌)}). For the abstraction clause, compute (𝑎𝑞,𝐸)=𝖲𝖤𝖨(𝐴[𝑥↦𝑏𝑝],(¯𝜌,𝑏𝑝),𝑒𝑞). For application, compute the two subproblems under 𝐴,¯𝜌. For let, compute 𝑒1 under 𝐴,¯𝜌 and 𝑒2 under 𝐴[𝑥↦𝑎𝑞],¯𝜌. For fix, compute the body under 𝐴[𝑥↦𝑏𝑝],¯𝜌. Thus two occurrences of the same source variable have different roots, while every occurrence governed by one binder reads the same binder monotype from 𝐴.
The construction records equations separately from inequalities. Applying proposition 5.3 converts the result to inequalities only, with a linear increase in size.
The opening term is the smallest useful complete run. Give its fix, abstraction, application, variable, inner abstraction, and inner variable roots the names 𝑝,𝑞,𝑟,𝑠,𝑡,𝑢, respectively. The generator returns (𝑏𝑝,𝑏𝑞)⪯𝗌𝗎(𝑎𝑠,𝑏𝑞),(𝑏𝑞,𝑏𝑞,𝑏𝑡)⪯𝗌𝗎(𝑎𝑢,𝑏𝑞,𝑏𝑡),𝑎𝑡≐𝑏𝑡→𝑎𝑢,𝑎𝑠≐𝑎𝑡→𝑎𝑟,𝑎𝑞≐𝑏𝑞→𝑎𝑟,𝑏𝑝⪯𝗌𝗎𝑎𝑞,𝑎𝑞⪯𝗌𝗎𝑏𝑝,𝑎𝑞⪯𝗌𝗎𝑎𝑝.
Diagram
node
generated clause
𝑝
𝑏𝑝⪯𝗌𝗎𝑎𝑞,𝑎𝑞⪯𝗌𝗎𝑏𝑝,𝑎𝑞⪯𝗌𝗎𝑎𝑝
𝑞
𝑎𝑞≐𝑏𝑞→𝑎𝑟
𝑟
𝑎𝑠≐𝑎𝑡→𝑎𝑟
𝑠
(𝑏𝑝,𝑏𝑞)⪯𝗌𝗎(𝑎𝑠,𝑏𝑞)
𝑡
𝑎𝑡≐𝑏𝑡→𝑎𝑢
𝑢
(𝑏𝑞,𝑏𝑞,𝑏𝑡)⪯𝗌𝗎(𝑎𝑢,𝑏𝑞,𝑏𝑡)
Figure . One complete generator run. Solid edges are syntax edges; dashed edges point from a variable occurrence to its binder. Each node label pairs a root-variable subscript with its source constructor. Each dashed edge is labelled by the binder variable that the occurrence retrieves from 𝐴. The table partitions equation 5.10 by the node that emits each clause.
The following outer substitution solves the equations: 𝑆(𝑏𝑝)=𝛿→𝛾(chosenrecursivetemplate),𝑆(𝑏𝑞)=𝛼(chosenouter-lambdadomain),𝑆(𝑏𝑡)=𝛽(choseninner-lambdadomain),𝑆(𝑎𝑢)=𝛼(identitywitnessfortheoccurrenceof𝑥),𝑆(𝑎𝑡)=𝛽→𝛼(innerabstractionequation),𝑆(𝑎𝑟)=𝛾(chosenapplicationresult),𝑆(𝑎𝑠)=(𝛽→𝛼)→𝛾(applicationequation),𝑆(𝑎𝑞)=𝛼→𝛾(outerabstractionequation),𝑆(𝑎𝑝)=𝛼→𝛾(identityresultmatcher). The first inequality uses 𝑅𝑠=[𝛽→𝛼/𝛿]; the second uses the identity; the two recursive variant inequalities use 𝑅𝑥𝑏=[𝛼/𝛿] and 𝑅𝑏𝑥=[𝛿/𝛼]; the result inequality uses the identity. Each matcher fixes its displayed protected components. For example, 𝑅𝑠(𝑆(𝑏𝑝),𝑆(𝑏𝑞))=((𝛽→𝛼)→𝛾,𝛼)=(𝑆(𝑎𝑠),𝑆(𝑏𝑞)). The independent variables 𝛿 and 𝛼 are essential: the two opposite matchers identify their generalized schemes without forcing the recursive template to equal the monomorphic outer-lambda domain.
The same witness gives the complete first-order derivation. With 𝐴(𝑓)=𝛿→𝛾, let Dapp be the following complete application subderivation: (𝛿→𝛾,𝛼)⪯𝗌𝗎((𝛽→𝛼)→𝛾,𝛼)𝑓:𝛿→𝛾,𝑥:𝛼;(𝛼)⊢𝖥𝖮𝑓:(𝛽→𝛼)→𝛾FO−Var(𝛼,𝛼,𝛽)⪯𝗌𝗎(𝛼,𝛼,𝛽)𝑓:𝛿→𝛾,𝑥:𝛼,𝑦:𝛽;(𝛼,𝛽)⊢𝖥𝖮𝑥:𝛼FO−Var𝑓:𝛿→𝛾,𝑥:𝛼;(𝛼)⊢𝖥𝖮𝜆𝑦.𝑥:𝛽→𝛼FO−Abs𝑓:𝛿→𝛾,𝑥:𝛼;(𝛼)⊢𝖥𝖮𝑓(𝜆𝑦.𝑥):𝛾FO−App. The remaining two rule instances are Dapp𝑓:𝛿→𝛾;()⊢𝖥𝖮𝜆𝑥.𝑓(𝜆𝑦.𝑥):𝛼→𝛾FO−Abs𝛿→𝛾⪯𝗌𝗎𝛼→𝛾𝛼→𝛾⪯𝗌𝗎𝛿→𝛾𝛼→𝛾⪯𝗌𝗎𝛼→𝛾∅;()⊢𝖥𝖮𝖿𝗂𝗑𝑓.𝜆𝑥.𝑓(𝜆𝑦.𝑥):𝛼→𝛾FO−Fix. Here the three final matchers are 𝑅𝑥𝑏, 𝑅𝑏𝑥, and the identity.
Let (𝑎𝑝,𝐸)=𝖲𝖤𝖨(𝐴,¯𝜌,𝑒𝑝), and let 𝑆 be any finite substitution. Then 𝑆semi-unifies𝐸⟺𝑆(𝐴);𝑆(¯𝜌)⊢𝖥𝖮𝑒:𝑆(𝑎𝑝). The matcher attached to each generated inequality is used as the matcher of the corresponding first-order rule premise. Consequently a closed term is Milner–Mycroft typable exactly when its generated mixed problem is semi-unifiable.
Proof of Theorem 5.12 — Constraint characterization
Proof. Proceed by structural induction on 𝑒 while keeping the same outer substitution 𝑆 throughout. This formulation avoids combining independently chosen substitutions from sibling subterms.
Variable. The only generated constraint is (𝐴(𝑥),¯𝜌)⪯𝗌𝗎(𝑎𝑝,¯𝜌). A first-order variable derivation has exactly that side condition after applying 𝑆. The generated matcher is therefore equivalent to the premise of FO-Var.
Abstraction. The induction hypothesis identifies the body constraints with 𝑆(𝐴)[𝑥↦𝑆(𝑏𝑝)];(𝑆(¯𝜌),𝑆(𝑏𝑝))⊢𝖥𝖮𝑒:𝑆(𝑎𝑞). The remaining generated equation says 𝑆(𝑎𝑝)=𝑆(𝑏𝑝)→𝑆(𝑎𝑞), exactly the conclusion type of FO-Abs.
Application. The two induction hypotheses use the restrictions of the same 𝑆 to 𝐸1 and 𝐸2. The final equation is 𝑆(𝑎𝑞)=𝑆(𝑎𝑟)→𝑆(𝑎𝑝), which is precisely the arrow premise of FO-App. Reading this argument backward proves the converse.
Let. The first induction hypothesis derives 𝑒1:𝑆(𝑎𝑞). The second derives 𝑒2:𝑆(𝑎𝑟) under 𝑥:𝑆(𝑎𝑞). Rule FO-Let gives the body type, and 𝑆(𝑎𝑝)=𝑆(𝑎𝑟) is the remaining generated equation. Conversely, inversion of FO-Let and that equality recovers both subproblem solutions.
Fix. The body induction hypothesis derives 𝑆(𝐴)[𝑥↦𝑆(𝑏𝑝)];𝑆(¯𝜌)⊢𝖥𝖮𝑒:𝑆(𝑎𝑞). The three remaining generated inequalities are, in order, the two mutual protected matchings between 𝑆(𝑏𝑝) and 𝑆(𝑎𝑞) and the protected matching from 𝑆(𝑎𝑞) to 𝑆(𝑎𝑝). They are exactly the three side conditions of FO-Fix. Inverting that rule reads the same argument backward.
These five constructor cases establish both directions. For empty 𝐴 and ¯𝜌, combine this result with lemma 5.10, theorem 5.8 to obtain the final closed-term claim. ◻
A closed source term is serialized in prefix form by 𝗏𝑗∣𝗅𝖺𝗆𝐸∣𝖺𝗉𝗉𝐸𝐸∣𝗅𝖾𝗍𝐸𝐸∣𝖿𝗂𝗑𝐸, where a de Bruijn index names a binder by distance: index 0 names the nearest enclosing binder and indices increase outwards. Number syntax nodes in prefix-tree order: visit the root first and then visit children from left to right. Assign each constructor a fixed binary payload and frame every payload 𝑤 by 𝖿𝗋(𝑤)=1|𝑤|0𝑤. Binary numerals use the same frame. Fix the constructor payloads 𝗏=00, 𝗅𝖺𝗆=01, 𝖺𝗉𝗉=10, 𝗅𝖾𝗍=110, and 𝖿𝗂𝗑=111. The exact token stream for 𝜆𝑥.𝑥 is 𝖿𝗋(01)𝖿𝗋(00)𝖿𝗋(0). Well-formedness requires every variable index to be smaller than the number of enclosing binders.
For output records, fix payloads 𝗑=000, 𝖺𝗋𝗋=001, 𝖾𝗊=010, and 𝗅𝖾𝗊=011. Encode 𝑎𝑖 by numeral 2𝑖 and 𝑏𝑖 by numeral 2𝑖+1. Thus arrow terms are framed prefix records, and a mixed problem begins with framed binary counts of its equations and inequalities, followed by that many framed records. These choices define the decision problems below; malformed strings are negative instances.
A log-space many-one reduction from a language 𝑃 to a language 𝑄 is a deterministic transducer with read-only two-way input, write-only output, and 𝑂(log𝑛) work bits that emits a string 𝐹(𝑤) satisfying 𝑤∈𝑃 if and only if 𝐹(𝑤)∈𝑄. The output head is not readable, so a transducer may rescan its input but may not use its output as storage.
The two-node input 𝜆𝑥.𝑥 gives an exact emission trace. A preliminary scan validates the stream, counts two nodes, one equation, and one inequality, and emits the equation and inequality counts 𝖿𝗋(1)𝖿𝗋(1). Prefix-tree nodes 0 and 1 are the lambda and variable. In the remaining output, each underbrace decodes the framed field above it: 𝖾𝗊:𝖿𝗋(010)⏟equationtag𝖿𝗋(000)𝖿𝗋(0)⏟__⏟__⏟𝑎0𝖿𝗋(001)𝖿𝗋(000)𝖿𝗋(1)𝖿𝗋(000)𝖿𝗋(2)⏟________⏟________⏟𝑏0→𝑎1,𝗅𝖾𝗊:𝖿𝗋(011)⏟inequalitytag𝖿𝗋(001)𝖿𝗋(000)𝖿𝗋(1)𝖿𝗋(000)𝖿𝗋(1)⏟________⏟________⏟(𝑏0,𝑏0)𝖿𝗋(001)𝖿𝗋(000)𝖿𝗋(2)𝖿𝗋(000)𝖿𝗋(1)⏟________⏟________⏟(𝑎1,𝑏0). The row labels are the decoded clauses 𝑎0≐𝑏0→𝑎1 and (𝑏0,𝑏0)⪯𝗌𝗎(𝑎1,𝑏0). Resolving index 0 at node 1 selects the binder at node 0; no path is stored between the two scans.
First make one validation pass. Framing lets the transducer advance from one record to the next with an input-position and payload-length counter. It checks constructor arities and binder-index bounds while maintaining the current binder depth. The same pass computes the exact syntax-node count 𝑁 and the numbers of generated equation and inequality clauses: a variable contributes one inequality clause, a lambda or application one equation clause, a let one equation clause, and a fix three inequality clauses. It emits the latter two counts before the records. Put I−={𝛼→𝛼⪯𝗌𝗎𝛼}. If the input is malformed or open, the transducer emits I− and stops.
For each number 𝑖=0,…,𝑁−1, the record-emission pass rescans the input with a node counter and a prefix-tree depth counter until it reaches node 𝑖, then emits the clause determined by that constructor. Root and binder variables are the binary node numbers tagged by 𝑎 or 𝑏. To find the binder of a variable occurrence, enumerate earlier binder nodes. For each candidate, a rescan computes the interval of node positions occupied by its body and tests whether the occurrence lies in that interval; counting the containing candidates from inside outwards resolves the de Bruijn index. The same enumeration, restricted to lambda candidates, emits the protected sequence from the outermost enclosing lambda to the innermost. Returning from a child requires no stored path: another rescan finds the child’s interval of prefix-tree positions and its parent’s constructor.
Every live value is an input position, node number, depth, binder count, or output-length counter, hence uses 𝑂(log𝑛) bits. There are 𝑂(𝑛) constraints and each protected tuple contains at most 𝑛 tagged variables, so the mixed output has 𝑂(𝑛2) tokens. Converting an equation to the pair inequality of proposition 5.3 adds a fixed wrapper around two copies addressed by rescans and keeps the same polynomial bound. The transducer therefore satisfies definition 5.13. ◻
The converse reduction and the exact negative boundary
The converse construction must preserve one outer substitution while allowing a different matcher for each inequality. A plain lambda binding preserves one type for repeated occurrences and therefore encodes equations. A polymorphic recursive binding permits its occurrences to instantiate the definition type and therefore encodes inequalities. Moving all ordinary bindings under one outer recursive binder leaves only one occurrence of 𝖿𝗂𝗑; pairing collects the finitely many checks without changing their individual matching substitutions.
It is useful first to separate an auxiliary product calculation from its pure-lambda implementation. In the auxiliary calculation, products have types 𝜏×𝜌, introduction ⟨𝑃,𝑄⟩:𝜏×𝜌, and the two projections. These are derived bookkeeping rules, not constructors of the target language.
The implementation uses the following pure lambda terms: ⟨𝑃,𝑄⟩≡𝜆𝑘.𝑘𝑃𝑄,𝑃.1≡𝑃(𝜆𝑢.𝜆𝑣.𝑢),𝑃.2≡𝑃(𝜆𝑢.𝜆𝑣.𝑣), with right-nested tuples and their projections defined recursively. Even a one-component tuple is ⟨𝑃,𝐾⟩ and its component is the first projection; this convention makes the singleton calculation below exercise the same eliminator as a longer family. Write 𝑃≐𝜆𝑄 for 𝜆𝑧.⟨𝑧𝑃,𝑧𝑄⟩, and put 𝐾≡𝜆𝑢.𝜆𝑣.𝑢. For the expansion, use the result-indexed abbreviation (𝜏,𝜌)𝛿:=(𝜏→𝜌→𝛿)→𝛿. Then ⟨𝑃,𝑄⟩:(𝜏,𝜌)𝛿 whenever 𝑃:𝜏 and 𝑄:𝜌. The result type 𝛿 is an index, not a uniquely determined type: the same pair introduction has this type for every 𝛿. A first projection fixes 𝛿=𝜏 and a second projection fixes 𝛿=𝜌. Applying both projections to one monomorphic pair could therefore force 𝜏=𝜌. The encoder below projects each instantiated recursive occurrence once, so every elimination determines only its own result index. The equality gadget is typable exactly when 𝑃 and 𝑄 receive the same monotype.
Rename the arrow constructor of a source problem to the formal product constructor; this signature isomorphism preserves semi-unifiers in both directions. For a vector ⃗𝑧=(𝑧𝛼) indexed by the source variables, define ⌜𝑀⌝⃗𝑧 by replacing a variable 𝛼 with 𝑧𝛼 and a binary node with the auxiliary pair. A simple type environment 𝐴 on those term variables extends homomorphically through the formal product constructor; write the resulting product type as 𝐴(𝑀). In particular, 𝐴(𝑀) does not mistake a source binary node for a function type.
Let 𝐴 be a simple type environment. Let 𝑀,𝑁 be source trees whose variables belong to dom(𝐴), and let {𝑀𝑖⪯𝗌𝗎𝑁𝑖}𝑚𝑖=1 be a finite family whose variables also belong to dom(𝐴).
𝐴⊢𝖬𝖬⌜𝑀⌝⃗𝑧:𝜏 holds in the derived pair rules exactly when 𝜏=𝐴(𝑀).
If 𝐴(𝑀)=𝐴(𝑁), then 𝑀 and 𝑁 have a first-order unifier.
If 𝐴(𝑀𝑖)⪯𝗌𝗎𝐴(𝑁𝑖) for every member of a finite family, then that family has a semi-unifier obtained by quotienting the auxiliary types back to source trees.
Proof of Lemma 5.15 — Representation and substitution correctness
Proof. For item 1, induct on 𝑀. A variable uses its unique assumption in 𝐴. At a binary node, the two induction hypotheses and the derived pair rule give the homomorphic pair type; inversion of that rule gives the converse.
For items 2 and 3, the auxiliary signature must first be returned to the one-constructor source signature. Serialize each non-product-rooted auxiliary monotype 𝑇, and let 𝜄(𝑇) be the source variable whose index is that serialization. Thus 𝜄 is injective. Define the quotient 𝑞 by 𝑞(𝑇1×𝑇2)=𝑞(𝑇1)→𝑞(𝑇2),𝑞(𝑇)=𝜄(𝑇)when𝑇isnotproduct-rooted. Although 𝜄 is defined on every finite auxiliary monotype, evaluating 𝑞 on the present finite family queries only finitely many of its values. Define the source substitution 𝑆𝐴(𝛼)=𝑞(𝐴(𝛼)). Structural induction on 𝑀 gives the commuting equation 𝑆𝐴(𝑀)=𝑞(𝐴(𝑀)). If 𝐴(𝑀)=𝐴(𝑁), applying 𝑞 and equation 5.11 shows that 𝑆𝐴 unifies 𝑀 and 𝑁.
For item 3, let 𝑅𝑖(𝐴(𝑀𝑖))=𝐴(𝑁𝑖). A maximal nonproduct component of 𝐴(𝑀𝑖) is a non-product-rooted subtree whose parent, if it has one, is a product. Define a finite source matcher 𝑟𝑖 by 𝑟𝑖(𝜄(𝑇))=𝑞(𝑅𝑖(𝑇)) for every such component 𝑇, and let 𝑟𝑖 fix all other variables. A second structural induction, now on the product skeleton of 𝐴(𝑀𝑖), gives 𝑟𝑖(𝑞(𝐴(𝑀𝑖)))=𝑞(𝑅𝑖(𝐴(𝑀𝑖))). Combining the two commuting equations with the witness equality gives the annotated calculation 𝑟𝑖(𝑆𝐴(𝑀𝑖))=𝑟𝑖(𝑞(𝐴(𝑀𝑖)))byequation5.11=𝑞(𝑅𝑖(𝐴(𝑀𝑖)))byequation5.12=𝑞(𝐴(𝑁𝑖))because𝑅𝑖(𝐴(𝑀𝑖))=𝐴(𝑁𝑖)=𝑆𝐴(𝑁𝑖)byequation5.11. Thus 𝑆𝐴 is one shared outer substitution and the 𝑟𝑖 are the required source matchers. ◻
Give every syntactic pair occurrence 𝑜 in ⌜𝑀⌝⃗𝑧 a result index 𝛿𝑜. Define CΔ(𝐴,𝑥𝛼)=𝐴(𝛼),CΔ(𝐴,(𝑃,𝑄)𝑜)=(CΔ(𝐴,𝑃)→CΔ(𝐴,𝑄)→𝛿𝑜)→𝛿𝑜. The Church expansion of ⌜𝑀⌝⃗𝑧 has type CΔ(𝐴,𝑀) for every index assignment Δ. Conversely, every typing of that expansion is CΔ(𝐴,𝑀) for a uniquely determined type at each leaf and some, generally nonunique, result-index assignment Δ.
Proof of Lemma 5.16 — Result-indexed Church formation and inversion
Proof. Induct on 𝑀. At a variable leaf, Var gives the type selected by 𝐴. At a binary node 𝑜, the induction hypotheses type the two expanded children. Assign 𝑘 the arrow type CΔ(𝐴,𝑃)→CΔ(𝐴,𝑄)→𝛿𝑜; two applications followed by one abstraction give the displayed type.
For inversion, a typing of 𝜆𝑘.𝑘𝑃𝑄 ends, after theorem 5.8, with abstraction and two applications. Their arrow equations force types 𝜏𝑃,𝜏𝑄,𝛿𝑜 and the result (𝜏𝑃→𝜏𝑄→𝛿𝑜)→𝛿𝑜. Apply the induction hypotheses to 𝑃 and 𝑄. No rule equates 𝛿𝑜 with another index unless the surrounding term eliminates this occurrence, which is why the assignment is not claimed unique. ◻
For I={𝑀𝑖⪯𝗌𝗎𝑁𝑖}𝑚𝑖=1, let ⃗𝑥 list its source variables. For each 𝑖, use a fresh vector ⃗𝑦𝑖 of the same length. The subscript on ⌜−⌝ states which vector represents source variables. Define 𝑒I≡𝖿𝗂𝗑𝑓.𝜆⃗𝑥.𝐾⟨⌜𝑀1⌝⃗𝑥,…,⌜𝑀𝑚⌝⃗𝑥⟩⟨𝜆⃗𝑦1.((𝑓⃗𝑦1).1≐𝜆⌜𝑁1⌝⃗𝑥),…,𝜆⃗𝑦𝑚.((𝑓⃗𝑦𝑚).𝑚≐𝜆⌜𝑁𝑚⌝⃗𝑥)⟩. The first argument of 𝐾 fixes the result type of the recursive definition to the tuple of the 𝐴(𝑀𝑖). The second argument is checked but hidden from that result. The local vector ⃗𝑦𝑖 supplies an independent instance of the recursive scheme, whereas the right side uses the outer vector ⃗𝑥. The equality gadget therefore imposes 𝑅𝑖(𝐴(𝑀𝑖))=𝐴(𝑁𝑖) rather than comparing two locally instantiated trees.
For the singleton problem {𝛼⪯𝗌𝗎𝛽→𝛼}, the source-variable order (𝛼,𝛽) gives the auxiliary term 𝖿𝗂𝗑𝑓.𝜆𝑥𝛼𝑥𝛽.𝐾⟨𝑥𝛼,𝐾⟩⟨𝜆𝑦𝛼𝑦𝛽.((𝑓𝑦𝛼𝑦𝛽).1≐𝜆⟨𝑥𝛽,𝑥𝛼⟩),𝐾⟩. Its pure expansion replaces ⟨𝑥𝛼,𝐾⟩ by 𝜆𝑘.𝑘𝑥𝛼𝐾 and (𝑓𝑦𝛼𝑦𝛽).1 by (𝑓𝑦𝛼𝑦𝛽)(𝜆𝑢.𝜆𝑣.𝑢); expanding the equality gadget gives 𝜆𝑧.𝜆𝑘.𝑘(𝑧((𝑓⃗𝑦)(𝜆𝑢.𝜆𝑣.𝑢)))(𝑧(𝜆ℎ.ℎ𝑥𝛽𝑥𝛼)). With outer substitution 𝑆=𝗂𝖽, the local matcher 𝑅=[𝛽→𝛼/𝛼] types the recursive occurrence at the required component: its projected type becomes 𝛽→𝛼, the type of the source tree on the right. In the auxiliary calculation, the outer pair ⟨𝑥𝛽,𝑥𝛼⟩ has the renamed product type 𝛽×𝛼. This one inequality exercises the tuple, first projection, equality gadget, 𝐾, and the independent recursive instance.
Expand every auxiliary pair and projection in equation 5.13 by the displayed pure lambda terms. The expanded term is MM typable if and only if the auxiliary-product term is typable.
Proof of Lemma 5.17 — Whole-encoder Church adequacy
Proof. For the forward construction, process each pair occurrence from its enclosing elimination inward. A first projection assigns its pair index the first component type; an 𝑖th projection down a right-nested tuple assigns the successive indices to the right-tail types and the final selected index to the 𝑖th component type. Pair occurrences used only for formation receive fresh indices. The two applications in every projection and the formation calculation of lemma 5.16 then expand the auxiliary derivation. Different recursive occurrences first instantiate the scheme of 𝑓, so their index assignments are independent.
Conversely, normalize a typing of the pure expansion. Invert each 𝜆𝑘.𝑘𝑃𝑄 by lemma 5.16. Invert 𝑃(𝜆𝑢.𝜆𝑣.𝑢): the application equation forces the result index of 𝑃 to equal the first component type. The second projection forces the analogous second-component equation. Replace these introduction and elimination subderivations by the corresponding auxiliary product rules. The equality gadget has body ⟨𝑧𝑃,𝑧𝑄⟩; its two applications force 𝑃 and 𝑄 to have the same domain type. The remaining cases are variables, abstraction, application, 𝐾, and the single fix; their rules are unchanged. Structural induction over the fixed encoder syntax therefore reconstructs the complete auxiliary derivation. ◻
Let I be a finite semi-unification problem over arrow terms. In logarithmic work space, the construction above computes a pure term of the form 𝑒I=𝖿𝗂𝗑𝑓.𝑒′, obtained by expanding equation 5.13, such that 𝑒′ contains neither 𝖿𝗂𝗑 nor 𝗅𝖾𝗍 and Iissemi-unifiable⟺𝑒IisMilner--Mycrofttypable. The target is the exact pure calculus of definition 5.5; in particular, the construction does not add products as source primitives.
Proof. Work first in the auxiliary product calculation. Suppose that 𝑆 and 𝑅𝑖 semi-unify I. Let 𝐽(𝑇) replace every source arrow in 𝑇 by the auxiliary product. For a source substitution 𝑈, define the auxiliary substitution 𝐽∗𝑈 by (𝐽∗𝑈)(𝛼)=𝐽(𝑈(𝛼)). Structural induction on 𝑇 gives (𝐽∗𝑈)(𝐽(𝑇))=𝐽(𝑈(𝑇)). Assign each source term variable 𝑥𝛼 the type (𝐽∗𝑆)(𝛼). By lemma 5.15(1), the first tuple in equation 5.13 has component types 𝐽(𝑆(𝑀𝑖)). Generalize the type of 𝑓 at MM-Fix. At its 𝑖th occurrence, instantiate that scheme with 𝐽∗𝑅𝑖; the 𝑖th projection therefore has type (𝐽∗𝑅𝑖)(𝐽(𝑆(𝑀𝑖)))=𝐽(𝑅𝑖(𝑆(𝑀𝑖)))=𝐽(𝑆(𝑁𝑖)). The equality gadget, tuple formation, the lambda binders, and 𝐾 give a typing of the auxiliary term. Apply lemma 5.17 to obtain a pure typing.
Conversely, use lemma 5.17 to reconstruct an auxiliary typing, and normalize it by theorem 5.8. Invert the outer fix, lambdas, and the first tuple. The types of the bound 𝑥𝛼 determine a simple environment 𝐴, and lemma 5.15(1) makes the 𝑖th result component 𝐴(𝑀𝑖). Each recursive occurrence is an independent instance of the generalized type of 𝑓. Inverting its projection and equality gadget therefore supplies a matcher with 𝐴(𝑀𝑖)⪯𝗌𝗎𝐴(𝑁𝑖). Item 3 of the lemma gives one shared outer substitution and one matcher per source inequality. Hence I is semi-unifiable.
For the space bound, first validate the framed counts and every tree record. Put 𝑒−:=𝖿𝗂𝗑𝑓.𝜆𝑥.𝑥𝑥,𝑒+:=𝖿𝗂𝗑𝑓.𝜆𝑥.𝑥. A malformed string is sent to the fixed untypable restricted term 𝑒−. A valid empty family is sent to the fixed typable restricted term 𝑒+. For a nonempty valid family, use the serializations of definition 5.13. Enumerate distinct source variables by their first input occurrence: for each candidate, rescan the earlier prefix to test whether the same length-delimited name has appeared. To emit the 𝑖th tuple component or projection, store only the binary counters 𝑖,𝑚 and rescan to the corresponding inequality. A source tree is emitted by its node number in prefix-tree order; returning from a child is reconstructed by rescanning with node and depth counters, not by storing its path. Right-nested tuples and Church templates add 𝑂(𝑚) wrappers, and copied trees give at most quadratic output size. All live counters use 𝑂(log𝑛) bits, so the encoder meets definition 5.13. ◻
Deleting polymorphic recursion collapses the separate occurrences of 𝑓 to one monotype and destroys equation 5.15.
Proof. The first reduction is corollary 5.14. The second is theorem 5.18. For the remaining reduction, parse the input as the item-3 fragment. A well-formed fragment term is copied unchanged. A malformed string or a well-formed term outside the fragment is sent to the fixed untypable unrestricted term 𝑢−:=𝜆𝑥.𝑥𝑥. The parser uses counters for framing, binder depth, and the number and position of 𝖿𝗂𝗑 tokens, hence logarithmic work space. This guarded copy preserves both positive and negative instances on the whole string language. ◻
The source of undecidability can be stated at an even smaller signature.
A deterministic one-tape Turing machine consists of finite state and tape alphabets, a start state, a halting state, a blank symbol, and a partial transition function 𝑄×Σ⇀𝑄×Σ×{𝖫,𝖱}. Its input word occupies consecutive cells of an otherwise blank two-way infinite tape. Let 𝖼𝗈𝖽𝖾(𝑇) be the prefix structural serialization of the finite transition table, and put 𝗃𝗈𝗂𝗇(𝑢,𝑣)=𝖿𝗋(𝑢)𝖿𝗋(𝑣) using the framing function of definition 5.13. Let 𝖧𝖺𝗅𝗍𝖳𝖬1 be the language of strings 𝗃𝗈𝗂𝗇(𝖼𝗈𝖽𝖾(𝑇),𝑤) for which this machine reaches its halting state. Malformed pairs are outside the language.
A total function on strings is computable when a one-tape machine halts on every input and writes its output. A language 𝑃many-one reduces to 𝑄 when a total computable function 𝐹 satisfies 𝑤∈𝑃 if and only if 𝐹(𝑤)∈𝑄. A language is A machine decides𝑃 when it halts on every string and returns 1 exactly on members of 𝑃 and 0 on nonmembers. A language is undecidable when no one-tape machine decides it. A language is recursively enumerable when some one-tape machine halts exactly on its members. It is r.e.-hard when every recursively enumerable language many-one reduces to it, and r.e.-complete when it is both recursively enumerable and r.e.-hard.
Proof of Lemma 5.21 — The one-tape source is r.e.-complete
Proof. A one-tape universal simulator recognizes 𝖧𝖺𝗅𝗍𝖳𝖬1: it stores the simulated finite nonblank tape interval with a marked head, scans to the encoded transition table, rewrites the marked cell, and repeats. It halts exactly when the simulated machine halts, so the source is recursively enumerable.
Let 𝑃 be recursively enumerable, witnessed by a fixed one-tape machine 𝑇𝑃. The function 𝑤↦𝗃𝗈𝗂𝗇(𝖼𝗈𝖽𝖾(𝑇𝑃),𝑤) is total computable and its output belongs to 𝖧𝖺𝗅𝗍𝖳𝖬1 exactly when 𝑤∈𝑃. Hence every recursively enumerable language reduces to the source. ◻
Proof of Lemma 5.22 — The one-tape source is undecidable
Proof. Suppose a total machine 𝐻 returned yes exactly on the halting pairs. Build a one-tape machine 𝐷 which, on input 𝑥, runs 𝐻 on the framed pair 𝗃𝗈𝗂𝗇(𝑥,𝑥), loops when 𝐻 returns 1, and halts when 𝐻 returns 0. The finite transition table of 𝐷 has the structural serialization 𝑑=𝖼𝗈𝖽𝖾(𝐷). On input 𝑑, 𝐷(𝑑)halts⟺𝐻(𝗃𝗈𝗂𝗇(𝑑,𝑑))returns0⟺𝐷(𝑑)doesnothalt, a contradiction. ◻
The total valuations used in the imported semi-unification problem and the finite substitutions of definition 5.2 have the same solutions on a finite input. An outer valuation need only be retained on ftv(I); after it is chosen, matcher 𝑖 need only be retained on ftv(𝑆(𝑀𝑖)).
Proof of Lemma 5.23 — Finite support for semi-unification
Proof. Every replay inspects the outer valuation only at variables in the input trees. Its matched left side then inspects 𝑅𝑖 only at variable leaves of 𝑆(𝑀𝑖). Restricting the valuations to those finite domains therefore preserves every replay equation. Conversely, extend each finite map by the identity on variables outside its domain. Homomorphic extension on the finite input trees gives the same replay, so the extensions are total solutions. ◻
Dudenhefner’s one-tape library model packages a finite state type, a total transition on a state and one optional tape symbol, a Boolean halting test, and an initial tape. The value 𝖭𝗈𝗇𝖾 denotes a blank cell and 𝖲𝗈𝗆𝖾(𝑎) denotes a cell containing 𝑎; the move component is left, right, or stationary. Write 𝖧𝖺𝗅𝗍𝖳𝖬lib1 for its halting language.
From a local string 𝗃𝗈𝗂𝗇(𝖼𝗈𝖽𝖾(𝑇),𝑤) one can compute a machine ̂𝑇 and initial tape 𝑡𝑤 in Dudenhefner’s library model such that 𝑇haltson𝑤⟺(̂𝑇,𝑡𝑤)∈𝖧𝖺𝗅𝗍𝖳𝖬lib1. The conversion and both structural serializers are total computable.
Proof. Use the local tape alphabet as the library alphabet and represent a blank cell by 𝖭𝗈𝗇𝖾 and a written symbol by 𝖲𝗈𝗆𝖾(𝑎). The library state type is the finite local state set plus one fresh sink. On a defined local transition, ̂𝑇 writes the corresponding optional symbol, moves left or right, and enters the corresponding state. On an undefined nonhalting transition, it enters the sink; the sink writes the same symbol, does not move, and loops. The library Boolean halting test is true exactly at the image of the designated local halting state. Place the letters of 𝑤 in consecutive optional cells to obtain 𝑡𝑤.
Let 𝜄𝑄 be the inclusion of the local state set into the enlarged library state set. For a local configuration 𝑐=(𝑞,ℎ,𝑡), define 𝐸(𝑐)=(𝜄𝑄(𝑞),ℎ,̂𝑡),̂𝑡(𝑛)={𝖭𝗈𝗇𝖾,𝑡(𝑛)isblank,𝖲𝗈𝗆𝖾(𝑡(𝑛)),𝑡(𝑛)iswritten. For every defined nonhalting local step 𝑐⟶𝑇𝑐′, direct inspection of the transition table gives 𝐸(𝑐)⟶̂𝑇𝐸(𝑐′). Induction on the number of local steps gives the forward simulation. Conversely, a library run that reaches a Boolean-halting state never entered the sink, so inversion of each preceding transition reconstructs the local run. The construction traverses finite transition tables, state lists, and the word 𝑤, so a one-tape transducer computes its framed serialization by repeated scans and copying. ◻
For the source language 𝖧𝖺𝗅𝗍𝖳𝖬1 above and the arrow-only semi-unification problem of definition 5.2, there is a total computable function 𝐹 such that 𝗃𝗈𝗂𝗇(𝖼𝗈𝖽𝖾(𝑇),𝑤)∈𝖧𝖺𝗅𝗍𝖳𝖬1⟺𝐹(𝗃𝗈𝗂𝗇(𝖼𝗈𝖽𝖾(𝑇),𝑤))issemi-unifiable.
Proof of Theorem 5.25 — Exact constructive reduction import
Proof. The imported theorem has the library source 𝖧𝖺𝗅𝗍𝖳𝖬lib1, not the local partial-transition source. Dudenhefner’s Theorem 5.23 and its mechanized Section 6 endpoint prove 𝖧𝖺𝗅𝗍𝖳𝖬lib1▹𝗆𝖲𝖾𝗆𝗂𝖴[Dud23]. The imported construction is the composition through binary Post correspondence, binary stack-machine halting, two-counter halting, one-counter halting, deterministic and confluent stack-machine uniform boundedness, simple semi-unification, and right-uniform two-inequality semi-unification. The source proves every component reduction and their composition; reconstructing that development would require more than ten pages. The paper’s variables are natural numbers, its terms are generated only by variables and one binary arrow, and its solutions are total valuations.
Let 𝐺 denote the imported Coq reducer. It is a terminating structural program on finite inductive encodings. A one-tape evaluator stores the current framed constructor record beside an explicit stack of pending subterms, scans the finite program table to select the next clause, and writes the resulting framed constructor record at the right end of its work tape. Induction on the finite recursive call tree shows that, on input 𝑥, this evaluator writes the structural serialization of 𝐺(𝑥). Termination of 𝐺(𝑥) therefore gives termination of the evaluator. The input and output serializers consequently realize a total computable string function.
Compose that function with lemma 5.24. A malformed local source string is sent to the named negative problem I− from the forward reduction. Lemma 5.23 supplies exactly the finite-substitution consequence used in this chapter. ◻
Let arrow terms be generated by variables and one binary constructor (−→−). The many-one problem of definition 5.2 is recursively enumerable complete. More precisely, one-tape Turing-machine halting constructively many-one reduces to this problem.
For recursive enumerability, code variables as 𝛼0,𝛼1,…. At stage 𝑛, enumerate every outer substitution on ftv(I) whose range trees have total size at most 𝑛 and use only 𝛼0,…,𝛼𝑛. For each candidate 𝑆 and each inequality 𝑀𝑖⪯𝗌𝗎𝑁𝑖, compute the finite domain 𝐷𝑖=ftv(𝑆(𝑀𝑖)); enumerate all matchers on 𝐷𝑖 with the same size and variable bound. Test the equations and all structural replays. Every loop at stage 𝑛 is finite. Every finite witness is alpha-renamable into some stage, and lemma 5.23 shows that no total valuation witness is missed. Dovetailing the stages therefore halts exactly on the semi-unifiable inputs. Thus the problem is recursively enumerable as well as r.e.-hard. ◻
Proof. If the restricted typability problem were decidable, compose its decider with theorem 5.18. This would decide the recursively enumerable complete problem of theorem 5.26, contradicting lemma 5.22. ◻
The corollary concerns inference of whether an unannotated term has any Milner–Mycroft typing. It does not concern ordinary HM inference, whose principal algorithm was proved in chapter 3. The local Mono-Fix rule is this chapter’s monomorphic-recursion comparison baseline; the HM theorem in chapter 3 made no claim about recursive bindings. The corollary also does not make checking a supplied finite typing derivation undecidable. The 2023 construction imported above is the load-bearing reduction.
To check a supplied recursive annotation 𝜎=∀¯𝛼.𝜏, replace ¯𝛼 by fresh rigid constants¯𝜅. A rigid constant is a type name that unification may compare but may not replace. The ambient variables ftv(Γ) are rigid for the same run. All unknown types introduced while checking lambdas and applications are flexible variables; unification may replace only these variables. Each occurrence of the recursive name receives a fresh flexible instance of the written scheme.
Assign every rigid constant 𝜅 and flexible variable 𝜇 the binder depth ℓ(𝜅) or ℓ(𝜇) at which it was created, with depth increasing under a binder. A substitution 𝜃 is well scoped when 𝜅∈ftv(𝜃(𝜇))⟹ℓ(𝜅)≤ℓ(𝜇). A rigid escape is a pair (𝜇,𝜅) that violates this inequality. The checker accepts exactly when the body checks against 𝜏[¯𝜅/¯𝛼], rigid constants remain unchanged, the occurs check succeeds, and no rigid escape occurs.
For example, the annotation ∀𝛼.𝛼→𝛼 accepts the body 𝜆𝑥.𝑥: replacing 𝛼 by 𝜅 gives target 𝜅→𝜅, so the lambda binds 𝑥:𝜅 and its variable body checks at 𝜅. The annotation ∀𝛼.𝛼 rejects the same body. The lambda would require the equation 𝜅=𝛽→𝛽 for a flexible 𝛽, but solving it would replace the rigid constant 𝜅.
Suggested first pass.
None of these problems is a prerequisite for later chapters. Use the two board problems exercise 5.4, exercise 5.5; leave the fragment checker in exercise 5.6 and the three-star project in exercise 5.7 for an extended pass.
★★☆ For I={𝛼→𝛼⪯𝗌𝗎𝛽→𝛾,𝛽≐𝛾}, give an outer substitution 𝑆 and the matching substitution for the inequality. Prove that every semi-unifier of I makes 𝛽 and 𝛾 equal, and explain why this restriction belongs to 𝑆, not to the per-inequality matcher.
★★☆ For a problem containing only equations, use proposition 5.3 to prove that semi-unifiability coincides with first-order unifiability. Then identify the exact FO-Fix side condition that introduces a genuine inequality. State why deleting 𝗅𝖾𝗍 does not delete that condition.
★★☆ Replace MM-Fix by a rule requiring the recursive scheme ∀𝛼.𝛼→𝛾 to be written as a source annotation. Implement the checker of definition 5.29 for one annotated rule instance. Prove soundness and completeness for a fixed annotation. Explain why this does not decide whether an annotation exists.
★★★Practical project.semi-unification-reduction-checker Implement a checker for finite arrow terms, outer substitutions, and one matcher per inequality. Maintain the invariant that a reported SOLVED result is accompanied by substitutions whose structural replay verifies every instance of equation 5.3. Print the generated or supplied constraints and each replay result. For this executable corpus only, extend the arrow signature by the rigid nullary constructor 𝖡𝗈𝗈𝗅. It is a test constant, not a type variable and not part of the arrow-only undecidability statements. The acceptance test must:
solve the ordinary unification equation 𝛼≐𝖡𝗈𝗈𝗅;
solve both inequalities in equation 5.4 using distinct matchers;
reject 𝛼→𝛼⪯𝗌𝗎𝛼 with the finite-tree certificate of lemma 5.4, derived from that exact input rather than supplied independently; and
solve (𝛿→𝛾,𝛾)⪯𝗌𝗎((𝛽→𝛼)→𝛾,𝛾), the protected polymorphic-recursion constraint of equation 5.9.
A bounded search may also print UNKNOWN; fuel exhaustion is never reported as rejection.
The rejection certificate is a quadruple (𝑐𝐿,𝑘𝐿,𝑐𝑅,𝑘𝑅) representing 𝑐𝐿+𝑘𝐿𝑛>𝑐𝑅+𝑘𝑅𝑛(𝑛∈ℕ). Accept this symbolic certificate only when 𝑐𝐿>𝑐𝑅 and 𝑘𝐿≥𝑘𝑅. For lemma 5.4, use (1,2,0,1) after substitution monotonicity has reduced the replay to 1+2𝑛>𝑛. This check is independent of a supplied candidate substitution.
Construct every printed constraint, substitution, replay, status, and final summary from computed data. Each inequality trace must show its outer substitution, including outer=[], and its local matcher. As a mutation test, omit application of every local matcher. The two matcher-dependent families contain three inequality traces, all of which must change to FAILED. The two aggregate status lines must change to FAIL, and the aggregate must report failure.
The Milner–Mycroft calculus, syntax-directed normalization, and the two reduction architectures originate in Henglein’s development [Hen93]; the recursive typing discipline was introduced by Mycroft [Myc84]. The constructive arrow-only boundary and exact import used here are due to Dudenhefner [Dud23]; the earlier proof route and a compact mechanized middle reduction are recorded in [Dud20].