CONSTRUCTIVE MANY-ONE REDUCTION FROM THE HALTING PROBLEM TO SEMI-UNIFICATION (EXTENDED VERSION ∗ )

. Semi-unification is the combination of first-order unification and first-order matching. The undecidability of semi-unification has been proven by Kfoury, Tiuryn, and Urzyczyn in the 1990s by Turing reduction from Turing machine immortality (existence of a diverging configuration). The particular Turing reduction is intricate, uses non-computational principles, and involves various intermediate models of computation. The present work gives a constructive many-one reduction from the Turing machine halting problem to semi-unification. This establishes RE -completeness of semi-unification under many-one reductions. Computability of the reduction function, constructivity of the argument, and correctness of the argument is witnessed by an axiom-free mechanization in the Coq proof assistant. Arguably, this serves as comprehensive, precise, and surveyable evidence for the result at hand. The mechanization is incorporated into the existing, well-maintained Coq library of undecidability proofs. Notably, a variant of Hooper’s argument for the undecidability of Turing machine immortality is part of the mechanization.


Introduction
Semi-unification is the following decision problem: given a finite set of pairs of first-order terms, is there a substitution φ such that for each pair (σ, τ ) in the set of first-order terms we have ψ(φ(σ)) = φ(τ ) for some substitution ψ?
Semi-unification was formulated independently by Henglein [Hen88], by Leiß [Lei89b], and by Kapur, Musser, Narendran and Stillman [KMNS88].Both Henglein [Hen88] and Leiß [Lei89b] show that semi-unification is equivalent with type inference for functional programming languages with recursive polymorphism 1 [Myc84] (for a detailed account constructivity of the argument.Specifically, the notion of a constructive proof is identified with an axiom-free Coq mechanization (cf.calculus of inductive constructions).It neither assumes functional extensionality 3 , Markov's principle 4 , nor the fan theorem 5 .Finally, the mechanization is integrated into the Coq Library of Undecidability Proofs [FLWD + 20], and contributes a (first of its kind) mechanized variant of Hooper's immortality construction [Hoo66].
The described improvements allow for an alternative approach to show many-one equivalence of System F typability and System F type checking, compared to the argument established in the 1990s by Wells [Wel99].The original argument interreduces type checking and typability directly, which requires a technically sophisticated argument.Having a constructive many-one reduction from Turing machine halting to semi-unification at our disposal (together with recursive enumerability of System F typability and type checking), it suffices (and is simpler) to reduce semi-unification to type checking and typability individually [Dud21].
Synopsis.The reduction from Turing machine halting to semi-unification is divided into several reduction steps.Each reduction step is many-one and constructive.That is, a predicate P over the domain X constructively many-one reduces to a predicate Q over the domain Y , if there exists a computable function f : X → Y such that for all x ∈ X we constructively have P (x) ⇐⇒ Q(f (x)).Additionally, each reduction step is mechanized as part of the Coq Library of Undecidability Proofs [FLWD + 20].Section 2: Turing machine halting is reduced to two-counter machine halting (Lemma 2.4) using Minsky's argument [Min67, Section 14.1].This step simplifies the starting machine model.Section 3: Two-counter machine halting is reduced to one-counter machine 1-halting (Lemma 3.7), adapting Minsky's observation [Min67,Section 14.2].This step prepares the machine model for nested simulation via two-stack machines without symbol search.Section 4.1: One-counter machine 1-halting is reduced to deterministic, length-preserving two-stack machine uniform boundedness (Lemma 4.16), adapting Hooper's construction for Turing machine immortality [Hoo66].This step transitions the machine problem from halting to uniform boundedness.Section 4.2: Deterministic, length-preserving two-stack machine uniform boundedness is reduced to confluent, simple two-stack machine uniform boundedness (Lemma 4.27), simplifying machine structure.This step enables reuse of the existing mechanized reduction from a uniform boundedness problem to semi-unification [Dud20].Section 5.1: Confluent, simple two-stack machine uniform boundedness is reduced to simple semi-unification (Lemma 5.13), strengthening previous work [Dud20].This step transitions to an undecidable fragment of semi-unification.Section 5.2: Simple semi-unification is reduced to right-uniform, two-inequality semi-unification (Lemma 5.18), establishing the main result (Theorem 5.23).Section 6: Outline of the mechanization of the above reduction steps.Section 7: Concluding remarks.

Two-counter Machines
The key insight of recent work [Dud20] establishes a direct correspondence between semiunification and a uniform boundedness problem for a machine model.In order to reduce Turing machine halting to such a problem, in this section we consider two-counter machines as a well-understood, mechanized [FL19], and more convenient intermediate model of computation.
Two-counter machines, pioneered by Minsky [Min67, Section 14.1], constitute a particularly simple, Turing-complete model of computation.A two-counter machine (Definition 2.1) stores data in two counters, each containing a natural number.A program instruction may either increment or decrement a counter value, and modify the current program index.The size of a two-counter machine is the length, denoted | • |, of the list, denoted [. ..], of its instructions.Individual instructions in the list are indexed starting from index 0. Definition 2.1 (Two-counter Machine (M)).A two-counter machine M is a list of instructions of shape either inc 0 , inc 1 , dec 0 j, or dec 1 j, where j ∈ N is a program index.
A configuration of M is of shape (i, (a, b)), where i ∈ N is the current program index and a, b ∈ N are the current counter values.
The step relation of M on configurations, written (−→ M ), is given by and (i, (a, b + 1)) −→ M (j, (a, b)); • otherwise, we say that the configuration (i, (a, b)) is halting.
The reachability relation of M on configurations, written (−→ * M ), is the reflexive, transitive closure of (−→ M ).
A configuration (i, (a, b)) Remark 2.2.The above Definition 2.1 is proposed by Forster and Larchey-Wendling [FL19] as a slight variation of the definition given by Minsky [Min67, Table 11.1-1].In particular, the conditional jump on decrement is on a strictly positive counter value (and not on zero).Intuitively, conditional jumps on zero (as in Minsky's original definition) severely restrict meaningful control flow when only two counters are available.In fact, in the setting with only two counters the halting problem for the original definition is decidable [Dud22a, Remark 1], and for universality requires additional control flow instructions.
Remark 2.6.Minsky's original argument is constructive and, despite some confusion (Remark 2.2), is sufficient for our technical result.However, to avoid ambiguity with respect to the instruction set used, for mechanization we rely on existing work by Forster and Larchey-Wendling [FL19].This approach emerged as part of the effort to mechanize Hilbert's tenth problem [LF22].Specifically, it many-one reduces Turing machine halting via the Post correspondence problem [Pos46,FHS18] to n-counter machine halting, and ultimately to two-counter machine halting.
Remark 2.7.Besides Minsky's original definition, there are several different universal instruction sets for two-counter machines [Kor96, Section 2].The particular choice in the present work is motivated by the following two facts.First, the instruction set is sufficiently restricted 6 .This allows for shorter proofs based on reductions from properties of the particular machine model.Second, the existing mechanization for the undecidability of the corresponding halting problem is well-maintained, and is readily available in the Coq Library of Undecidability Proofs.
Commonly, two-counter machines are easily simulated by other machine models, and therefore serve a key role in undecidability proofs for machine immortality and boundedness problems [Hoo66,KO08].However, they have one drawback with respect to boundedness properties.Specifically, there is no natural increasing measure on configurations along the step relation, as it allows for cycles (Example 2.8).Still, the configuration (0, (a, b)) is bounded, because from it only a finite number of distinct configurations is reachable.In fact, from any configuration at most 2 distinct configurations are reachable in M.
One could eliminate cycles by introducing a third counter, which increases at every step.This establishes an equivalence between mortality and corresponding boundedness properties.While inducing a natural increasing measure (value of the third counter), it incurs additional bookkeeping.A simulation of such a three-counter machine by an acyclic two-counter machine is possible [KO08], however, it again obscures the underlying measure.
We address this drawback of two-counter machines with respect to boundedness properties in the following Section 3, building upon Minsky's notion of machines with one counter.

One-counter Machines
As Minsky originally observed [Min67, Section 14.2], with multiplication and division by constants the halting problem is undecidable for one-counter machines.Specifically, increase and decrease operations for two values a and b can be simulated by multiplication and division respectively by 2 and 3 respectively for one value 2 a 3 b .
In this section, we further develop Minsky's construction (similarly to [Woj99]) of universal machines with one counter in pursuit of two goals.First, machine runs should be easy to simulate in the stack machine model (Remark 3.11) used in Section 4. Second, we require a measure on machine configurations that increases along the step relation, directly connecting non-termination and unboundedness (Lemma 3.5).Both goals are motivated by the effort necessary to mechanize the overarching result 7 .
A program instruction of a one-counter machine (Definition 3.1), besides modifying the program index, conditionally multiplies the current counter value with either 2 1 , 3 2 , 4 3 , or 5 4 .Notably, such a multiplication by d+1 d for d ∈ {1, 2, 3, 4} is both easy to simulate uniformly, and strictly increases a positive counter value.Definition 3.1 (One-counter Machine (P)).A one-counter machine P is a list of instructions of shape (j, d), where j ∈ N is a program index and d ∈ {1, 2, 3, 4} is a counter modifier.
A configuration of P is a pair (i, c), where i ∈ N is the current program index and c ∈ N such that c > 0 is the current counter value.
The step relation of P on configurations, written (−→ P ), is given by The n-fold step relation is denoted −→ n P .The reachability relation of P on configurations, written (−→ * P ), is the reflexive, transitive closure of (−→ P ).A configuration (i, c) terminates in P, if we have (i, c) −→ * P (i ′ , c ′ ) for some halting configuration (i ′ , c ′ ).
The above Lemma 3.4(4) gives a strictly increasing measure |P| • c + i on non-halting configurations (i, c) with respect to the step relation (−→ P ).Therefore, any configuration cycle is trivial, i.e. the corresponding configuration is halting.Additionally, by Lemma 3.4(5), the counter value is guaranteed to increase after |P| + 1 steps, unless a halting configuration is reached.This results in a characterization of termination via boundedness of reachable counter values (Lemma 3.5).
Lemma 3.5.Let P be a one-counter machine.A configuration (i, c) terminates in P iff there is a k ∈ N such that for all configurations (i ′ , c ′ ) with (i, c) −→ * P (i ′ , c ′ ) we have c ′ < k.Proof.If from the configuration (i, c) the machine P halts after n steps, then k = 1 + c • 2 n bounds the reachable from (i, c) counter values.Conversely, if k bounds the reachable from the configuration (i, c) counter values, then after at most k • (|P| + 1) steps a halting configuration is reached by Lemma 3.4(5).
The halting problem for one-counter machines (Problem 3.6) starting from the fixed 8 configuration (0, 1) is undecidable by reduction from the halting problem for two-counter machines (Lemma 3.7).
Proof.Let M be a two-counter machine and let a 0 , b 0 ∈ N be two starting counter values.
We represent a pair (a, b) of counter values of M by the family of counter values 2 a 3 b 5 m where m ∈ N. The purpose of the factor 5 m is to increase whenever either the factor 2 a or the factor 3 b decreases.We simulate instructions of M on two counters (a, b) by instructions of P on one counter c = 2 a 3 b 5 m as follows.
The following Example 3.9 illustrates the construction in the proof of Lemma 3.7, simulating a looping two-counter machine from Example 2.8.
Remark 3.11.It is possible to use the fractions 6 1 , 5 2 , and 5 3 to establish an increasing measure.In comparison, the deliberate choice of counter multiplication by d+1 d for a counter modifier d ∈ {1, 2, 3, 4} has several benefits.First, instructions are of uniform shape.Therefore, simulation of and reasoning about such instructions requires less case analysis, also impacting the underlying mechanization.Second, for a counter value c = k • d multiplication by d+1 d results in c • d+1 d = c + k, which is easy to simulate in the two-stack machine model.

Two-stack Machines
In this section, our goal is the simulation of one-counter machines in a stack machine model of computation without unbounded symbol search.Specifically, given a one-counter machine P, we construct a two-stack machine S such that the configuration (0, 1) terminates in P iff there is a uniform bound on the number of configurations reachable in S from any configuration.
The main difficulty, similar to the undecidability proof for Turing machine immortality [Hoo66], is to simulate symbol search (traverse data, searching for a particular symbol) using a uniformly bounded machine.Most problematic are unsuccessful searches that may traverse an arbitrary, i.e. not uniformly bounded, amount of data.The key idea [Hoo66, Part IV] (see also [KO08,Jea12]) is to implement unbounded symbol search by nested bounded symbol search.
In the present work, we supplement a high level explanation of the construction (cf.proof of Lemma 4.16) with a comprehensive case analysis as a mechanized proof in the Coq proof assistant.This approach, arguably worth striving for in general, has three advantages over existing work.First, the proof idea is not cluttered with mundane technical details, while the mechanized proof is highly precise.Second, a mechanized proof leaves little doubt regarding proof correctness and is open to scrutiny, as there is nothing left to imagination.Third, the Coq proof assistant tracks any non-constructive assumptions which may hide beneath technical details.
Let us specify the two-stack machine (Definition 4.1) model of computation, which we use to simulate one-counter machines.An instruction of such a machine may modify the current machine state, pop from, and push onto two stacks of binary symbols.We denote the empty word by ϵ, and the concatenation of words A and B by AB.
Definition 4.1 (Two-stack Machine (S)).Let S be a countably infinite set.A two-stack machine S is a list of instructions of shape A p B → A ′ q B ′ , where A, B, A ′ , B ′ ∈ {0, 1} * are binary words and p, q ∈ S are states.
A configuration of S is of shape A p B where p ∈ S is the current state, A ∈ {0, 1} * is the (reversed) content of the left stack and B ∈ {0, 1} * is the content of the right stack.
The step relation of S on configurations, written (−→ S ), is given by The reachability relation of S on configurations, written (−→ * S ), is the reflexive, transitive closure of (−→ S ).
Remark 4.2.A two-stack machine can be understood as a restricted semi-Thue system on the alphabet {0, 1} ∪ S in which each word contains exactly one symbol from S. Such rewriting systems are employed in the setting of synchronous distributivity [AEL + 12].
Remark 4.3.To accommodate for arbitrary large machines, the state space S is not finite.However, the effective state space of any two-stack machine S is bounded by the finitely many states occurring in the instructions of S (a list of finite length).
The key undecidable property of two-stack machines, used in [Dud20], is whether the number of distinct, reachable configurations from any configuration is uniformly bounded (Definition 4.4).Definition 4.4 (Uniformly Bounded).A two-stack machine S is uniformly bounded if there exists an n ∈ N such that for any configuration A p B we have Example 4.6.Consider the two-stack machine S = [0 p ϵ → ϵ p 1]. From the configuration 0 m p ϵ, where m ∈ N, reachable in S configurations are exactly 0 m−i p 1 i for i = 0, . . ., m.Therefore, there is no uniform bound on the number of reachable configurations.However, the length of every configuration chain in S is finite (bounded by one plus the length of the left stack).Overall, S does uniformly terminate but is not uniformly bounded.
Example 4.7.Consider the two-stack machine S = [(0 p ϵ → ϵ q 1), (ϵ q 1 → 0 p ϵ)].The number of distinct configurations reachable in S from any configuration is uniformly bounded by n = 2.However, S admits an infinite configuration chain 0 p ϵ −→ S ϵ q 1 −→ S 0 p ϵ −→ S ϵ q 1 −→ S . . .In summary, S is uniformly bounded, but does not uniformly terminate.In literature [Hoo66,KO08], counter machine termination is simulated using uniformly bounded Turing machines directly rather than by two-stack machines.This is reasonable when omitting technical details regarding the exact Turing machine construction.However, for verification in full detail, Turing machines are quite unwieldy, compared to two-stack machines.Unfortunately, we cannot rely on existing mechanized Turing machine programming techniques [FKW20], as they establish only functional properties, and are incapable to establish uniform boundedness.4.1.Deterministic, Length-preserving Two-stack Machines.There are several properties of two-stack machines that are of importance in our construction in order to reuse existing work [Dud20].
For length-preserving two-stack machines (Definition 4.9) the sum of lengths of the two stacks is invariant wrt.reachability.For each configuration, length-preservation bounds (albeit, not uniformly) the number of distinct, reachable configurations.Therefore, reachability is decidable (in polynomial space) for length-preserving two-stack machines.Definition 4.9 (Length-preserving).A two-stack machine S is length-preserving if for all instructions (A p B → A ′ q B ′ ) ∈ S we have 0 Definition 4.10 (Deterministic).A two-stack machine S is deterministic if for all configurations A p B, A ′ p ′ B ′ , and Example 4.11.Two-stack machines in Examples 4.5-4.7 are deterministic and lengthpreserving.The two-stack machine S = [0 p ϵ → ϵ p 1, ϵ p 1 → 0 p ϵ] from Example 4.8 is length-preserving, but not deterministic because of 0 p 1 −→ S ϵ p 11 and 0 p 1 −→ S 00 p ϵ.
Remark 4.12.Deterministic, length-preserving two-stack machines can be understood as a generalization of intercell Turing machines [KTU93b, Section 3], for which the transition rule has a bounded read/write/move radius around the current head position.Tape content on the left (resp.right) of the current head position is exactly the content of the left (resp.right) stack.
The key undecidable problem, that in our argument assumes the role of Turing machine immortality of previous approaches [KTU93b,Dud20], is uniform boundedness of deterministic, length-preserving two-stack machines (Problem 4.13).A central insight of the present work is that using this problem as an intermediate step we neither require Turing reductions, König's lemma (cf.[KTU93b]), nor the fan theorem (cf.[Dud20]).Additionally, a mechanization for both the reduction from counter machine halting to this problem and the reduction from this problem to semi-unification is of manageable size.Problem 4.13 (Deterministic, Length-preserving Two-stack Machine Uniform Boundedness).Given a deterministic, length-preserving two-stack machine S, is S uniformly bounded?
The original undecidability proof of semi-unification contains a hint [KTU93b, Proof of Corollary 6] that Turing machine immortality may be avoided.Accordingly, Lemma 4.16 captures the decisive step, which avoids Turing machine immortality.
Remark 4.14 (Naive Simulation).Given a one-counter machine P, we can construct a length-preserving two-stack machine S such that (0, 1) terminates in P iff configurations A1 0 01B for A, B ∈ {0, 1} * are uniformly bounded in S.
A P-configuration (i, c) can be represented by the S-configuration 1 i 0 c 10 m , where m ∈ N, such that 0 m is long enough to simulate a terminating run.In particular, the counter value c is unary encoded as 0 c 1 with 1 as separator.A P-instruction (j, d) at index i is simulated as follows.The S-instruction ϵ i ?0 d −→ S 0 d i ?ϵ tests for divisibility by d, moving consecutive blocks of d zeroes from the right stack to the left stack.The divisibility test either fails or succeeds.Failure (i, c) −→ P (i + 1, c): The S-instruction ϵ i ?0 k 1 −→ S ϵ i # 0 k 1 can be applied, where k is the remainder such that 0 < k < d.In this case, we move the zeroes back to the right stack, and via the S-instruction 1 i # ϵ −→ S 1 i + 1 ϵ we reach the S-configuration 1 i + 1 0 c 10 m , representing the next P-configuration (i + 1, c).Success (i, c) −→ P (j, c • d+1 d ): The S-instruction ϵ i ? 1 −→ S ϵ i ! 1 can be applied.In this case, multiplication by d+1 d is simulated as follows.For each block of consecutive d zeroes on the left stack shift the separator 1 on the right stack one position to the right (Remark 3.11).Finally, via the S-instruction 1 i !ϵ −→ S 1 j ϵ, we arrive at the for all words A, B ∈ {0, 1} * .Therefore, the configuration (0, 1) terminates in P iff configurations A1 0 01B are uniformly bounded in S (the uniform bound is derived from the halting counter value).
Unfortunately, the naive construction in the above Remark 4.14 in general does not describe a uniformly bounded two-stack machine.Most importantly, the naive construction assumes and preserves the "safe" format A1 i 0 c 1B of machine configurations (i, c), where c is less or equal to the halting counter value.Arbitrary configurations do not need to follow this format.At fault is a symbol search (for the symbol 1 on the right stack) that needs to traverse an arbitrary amount of data, illustrated by the following Example 4.15.
Example 4.15.Consider a one-counter machine P containing the instruction (j, d) at index i.The naive construction of a two-stack machine S from Remark 4.14 contains the S-instruction ϵ i ?0 d −→ S 0 d i ?ϵ.For any bound n ∈ N we have that The ingenious idea by Hooper [Hoo66, Part IV] is to use nested simulation for symbol search.In the present scenario, to search for the symbol 1 on the right stack, start a new simulation from the P-configuration (0, 1) inside the space of consecutive zeroes on the right stack.Nested simulation achieves three goals.First, it transitions into a "safe" configuration format A1 i 0 c 1B, where c is less or equal to the halting counter value.Second, by inspecting symbols in the immediate neighborhood of the separator 1 on the right stack, it checks whether the original search for the symbol 1 succeeds in appropriately limited space.Third, in case the space limit for symbol search is exceeded, it simulates a terminating run of the given machine.
Similarly to [KO08, Theorem 7], we adapt Hooper's nested simulation for symbol search in the following Lemma 4.16.
Proof.Let P be a one-counter machine.We follow the naive construction in Remark 4.14 with the following difference.In order to search for the symbol 1 on the right stack in some configuration A p 0 k+3 B, transition into the configuration AC1 0 01B, i.e. reset the program index p to 0 and retain the binary encoding of p in C of fixed length k.
Assume that the P-configuration (0, 1) terminates in P and let c be the counter value of the halting configuration.For a nested simulation from the configuration AC1 0 01B in search of symbol 1 in B, there are three cases.Case B = 0 m 1D, where m < c − 1 and D ∈ {0, 1} * : The number m of zeroes on the right stack is too small to accommodate for c.Eventually, the nested simulation is unable to simulate counter increase.This is detected by inspecting symbols in the immediate neighborhood of the separator 1 on the right stack.In this situation, the initial search for the symbol 1 in B succeeds, the previous level configuration is restored, and control is returned to the previous level.The content of D is not accessed, and symbol search succeeds in bounded space (the bound is derived from m < c − 1).Case B = 0 m , where m < c − 1: The size of the right stack is too small to accommodate for c.Eventually, the nested simulation is unable to shift the separator 1 to the right (in fact, apply any instruction), and halts.In this situation, the initial search for the symbol 1 fails in bounded space (the bound is derived from m < c − 1).Since the original configuration A p 0 k+3 B is not in the "safe" format (missing separator 1 on the right stack), this case handles ill-formed configurations in bounded space, and the search is immaterial.Case B = 0 c−1 D, where D ∈ {0, 1} * : There are enough consecutive zeroes in B to simulate a terminating run of P from the initial configuration (0, 1).The content of D is not accessed, and the simulation terminates in bounded space (the bound is derived from c − 1).Since the original configuration A p 0 k+3 B is not in the "safe" format (too many consecutive zeroes on the right stack), this case handles ill-formed configurations in bounded space, and the search is immaterial.Each case may require further symbol search, and therefore introduce further nested simulation.Notably, consecutive nested simulation is performed inside the space of at most c consecutive zeroes (followed by the separator 1 in the "safe" format).Therefore, the nesting depth is at most c.In each case (using Lemma 3.4) a bound on the number of configurations for the nested simulation can be derived from c. Therefore, S is uniformly bounded.
For the converse, assume that the P-configuration (0, 1) does not terminate in P. By Lemma 3.5, there is no bound on reachable counter values.Therefore, there is no uniform bound on the number of configurations reachable from configurations 1 0 010 m , where m ∈ N is arbitrary large.
Remark 4.18.At first glance, recursive nested simulation in the proof of Lemma 4.16 seems superfluous.After all, a nested simulation establishes a "safe" configuration format with bounded (naive) symbol search.However, it is not possible to remember reliably in the current configuration (e.g. in the current state) whether a nested simulation is running.An ill-formed configuration may be locally indistinguishable from a configuration of a nested simulation.Therefore, any (recursive) symbol search is performed using nested simulation.
Remark 4.19.The exact analysis of the nested simulation in the proof of Lemma 4.16 requires a tremendous inductive proof with many corner cases.Arguably, it is unreasonable for a human without mechanical assistance to write it down in full detail (cf.Hooper's remark in Section 1).Additionally, it would require a comparable amount of effort for others to verify such a massive construction.This is why, in order to guarantee its correctness, a mechanized proof of Lemma 4.16 is adequate (Section 6) to establish the result.Lemma 4.24.If a two-stack machine S is deterministic, then S is confluent.

Proof. For a deterministic two-stack machine S we have that
Example 4.25.The two-stack machine S = [0 p ϵ → ϵ p 1, ϵ p 1 → 0 p ϵ] from Example 4.8 is non-deterministic, as observed in Example 4.11.However, S is confluent.The instruction 0 p ϵ → ϵ p 1 can be "undone" by the instruction ϵ p 1 → 0 p ϵ and vice versa.Therefore, configuration chains can be reversed to join branching computation.This technique is used in the proof of Lemma 4.27.
Notably, it is difficult to maintain determinism for failed look-ahead, when we want to preserve elegance of the above simulation.However, in order to maintain confluence it suffices to add reverse instructions from fresh states, that is ϵ p 1 0 −→ 0 p ϵ, ϵ p 2 0 −→ 0 p 1 ϵ, and 1 p 3 ϵ −→ ϵ p 2 0. Therefore, any failed attempt to read local stack information can be reversed (cf.Example 4.25) and computation is confluent.
Finally, let us justify the detour from one-counter machines via deterministic, lengthpreserving two-stack machines to confluent, simple two-stack machines.By far the most complicated part of the overall reduction is the simulation of a terminating machine by a uniformly bounded machine (cf.Lemma 4.16).For this reduction, it is beneficial to have a restricted source machine model and an expressive target machine model.Of course, a direct simulation of terminating one-counter machines by uniformly bounded, confluent, simple two-stack machines is possible.However, the restricted nature of simple instructions would induce an unwieldy two-stack machine construction, rendering the mechanization more laborious.
For languages with parametric polymorphism, recursive calls are considered monomorphic.Therefore, type inference for f unifies the type of x and the type of not b.This results in the inferred type f : bool → bool → bool.
For languages with recursive polymorphism the type of each individual recursive call can be instantiated separately.The problematic recursive call f (not b) (not b) is associated with the inequality σ ≤ τ , where σ = bool → α → α is the global type scheme and τ = bool → bool → bool is the local type scheme.Any substitution φ such that φ(α) = β for some β ∈ V solves the inequality σ ≤ τ setting ψ(β) = bool.That is, we have ψ(φ(σ)) = φ(τ ).This results in the inferred type f : bool → α → α.
Unfortunately, semi-unification does not admit a decision procedure based on an occurscheck, which is a common approach to both first-order unification and first-order matching [BSN + 01].However, it is challenging to construct an unsolvable example of manageable size, for which the occurs-check is not triggered.
Originally [KTU93b, Theorem 12], semi-unification is proven undecidable by Turing reduction from Turing machine immortality [Hoo66].As intermediate problems, the argument relies on symmetric intercell Turing machine boundedness, path equation derivability, and termination of a custom-tailored redex contraction procedure.Additionally, the argument uses König's lemma and it is not obvious whether it can be presented constructively.
A modern approach [Dud20, Theorem 4] simplifies the original argument.It still relies on a Turing reduction from Turing machine immortality, but uses only deterministic, simple two-stack machine uniform boundedness to show undecidability of a fragment of semiunification.Additionally, it relies on the fan theorem, which is strictly weaker than König's lemma and is valid in Brouwer's intuitionism.The argument is partially mechanized in Coq.
In the remainder of this section we briefly recapitulate and reuse the modern approach [Dud20] in the more general case of confluent, simple two-stack machines.This allows us to avoid Turing machine immortality, Turing reductions, and the fan theorem in the overall argument.
Problem 2.3 (Two-counter Machine Halting).Given a two-counter machine M and two natural numbers a, b ∈ N, does the configuration (0, (a, b)) terminate in M? Vol.19:4 FROM HALTING TO SEMI-UNIFICATION 22:5
uniform boundedness and uniform termination [MS96] (is every configuration chain finite?) are orthogonal notions, illustrated by the following Examples 4.5-4.8.Example 4.5.Consider the empty two-stack machine S = [].It is uniformly bounded by n = 1 and does uniformly terminate as it admits only singleton configuration chains.

4. 2 .
Confluent, Simple Two-stack Machines.To further simplify the construction, we consider confluent (instead of deterministic), simple (Definition 4.20, cf.[Dud20, Definition 16]) two-stack machines.Uniform boundedness for such two-stack machines (Problem 4.26) is well-suited for reduction to a fragment of semi-unification (cf.Section 5.1).Definition 4.20 (Simple).A two-stack machine S is simple if for all instructions(A p B → A ′ q B ′ ) ∈ S we have 1 = |A| + |B| = |A ′ | + |B ′ | = |A| + |A ′ | = |B| + |B ′ |.Remark 4.21.A deterministic, simple two-stack machine is just another way to present a deterministic Turing machine.The left and right stacks contain the respective tape content to the left and to the right from the current head.Reading and writing at the head while moving the head position is easily presented as simple instructions (cf.[Dud20, Remark 19]).Remark 4.22.Turing machine immortality is reducible to uniform boundedness of deterministic, simple two-stack machines by a bounded Turing reduction [Dud20, Theorem 2].However, the argument uses the fan theorem, therefore, it is crucial for the present argument to not rely on this particular reduction.
Definition 4.23 (Confluent).A two-stack machine S is confluent if for all configurations A p B, A ′ p ′ B ′ , andA ′′ p ′′ B ′′ such that A p B −→ * S A ′ p ′ B ′ and A p B −→ * S A ′′ p ′′ B ′′ there exists a configuration C q D such that A ′ p ′ B ′ −→ * S C q D and A ′′ p ′′ B ′′ −→ * S C q D.Any deterministic two-stack machine is confluent (Lemma 4.24), but not necessarily vice versa (Example 4.25).