betaFeedback

WorksComputer Science

Tree Equivalence of Higher-Order Recursion Schemes Is Undecidable

Abstract

Higher-order recursion schemes (HORS) are finite, simply typed recursive programs that generate potentially infinite trees. Their monadic second-order model-checking problem is decidable. We prove that tree equivalence of deterministic HORS is undecidable and, more precisely, Π10Π^0_1-complete under total computable many-one reductions. The lower bound holds for safe, productive schemes of order at most four over the fixed ranked alphabet Σ2={e:0,d:2}Σ_2=\{e:0,d:2\}, consisting of one nullary and one binary symbol. Adapting the counter-guard witness of Boiret, Piorkowski, and Schmude, we generate all candidate executions of a two-counter machine by producing both continuations at every counter test. An integer weight is nonzero exactly on legal prefixes. Functions at fixed simple types represent the polynomial of growing degree. A shift recurrence updates them without storing a separate step counter, allowing the witness to be implemented by safe applicative HORS rules. At candidate halts, the intermediate schemes generate unary observation subtrees whose lengths encode the two natural-number components of the signed weight. Invalid candidates give matching observations; a legal halt produces a finite discrepancy. Fixed constructor contexts encode these intermediate trees over Σ2Σ_2. For the upper bound, a finite monotone semantics decides head convergence and supports an algorithm computing exact tree prefixes at any prescribed finite depth, including positions labelled ⊥\bot.

Introduction

Higher-order recursion schemes (HORS) are finite, simply typed recursive programs generating potentially infinite, ordered, labelled trees. Their parameters may be functions, while terminal symbols act as tree constructors. HORS also generate binder-free encodings of the η\eta-long Böhm trees of λY\lambda Y-terms, with binding information represented by de Bruijn levels [5 Theorem 11, p. 96].

Given such a finite description, a basic verification task is to decide whether the generated tree satisfies a specification. Monadic second-order logic (MSO) provides a language for these specifications, with quantification over nodes and sets of nodes. Given a scheme and an MSO sentence, one can decide whether its generated tree satisfies the sentence [13 Theorem 1]. This model-checking result supports verification of higher-order functional programs [11].

A second task is to compare two descriptions. Tree equivalence asks whether two independently given schemes generate the same tree. At order one it is decidable via language equivalence for deterministic pushdown automata [15, 9]. The higher-order case has long remained open [5, 14, 9].

For nondeterministic pushdown processes, Broadbent and Göller prove that strong bisimilarity is undecidable already for ε\varepsilon-free order-two automata [BG12, Theorem 5, p. 167]. Their construction uses the choice among transitions with the same action label. In deterministic ranked-tree equality, child addresses fix which subtrees must be compared. The nondeterministic bisimilarity lower bound therefore does not settle this equality problem.

We prove that exact tree equality is undecidable already when both schemes are safe and productive, their type order is at most four, and their terminal alphabet consists of one nullary and one binary symbol. In a productive scheme, every output node can be exposed after finitely many unfolding steps. Safety imposes a standard syntactic discipline on types and parameter dependencies [8 Definition 1, p. 8]. In particular, a function passed as an argument may depend only on rule parameters whose orders are at least its own; § 3 gives the full definition. The construction uses a fixed finite collection of simple types, independent of the source machine and the length of a candidate execution.

Main result and a scheme example

For a scheme GG, write BT⁡(G)\operatorname{BT}(G) for the tree it generates, with ⊥\perp marking a position where no terminal head is ever exposed. A productive scheme has no ⊥\perp nodes; finite leaves are allowed. Equality compares labels at the same child addresses, retaining child order and ignoring the number of unfolding steps used to expose a node.

Theorem 1.1 (Tree equivalence). Tree equivalence of deterministic higher-order recursion schemes is undecidable and, more precisely, Π10\Pi^0_1-complete (co-c.e.-complete) under total computable many-one reductions. This remains true when both schemes are required simultaneously to be safe and productive, to have order at most four, and to use the fixed ranked alphabet

Σ2={ε:0,d:2}.\Sigma_2 = \{ \varepsilon: 0, d : 2 \}.

Two consequences concern other models of computation. The effective, order-preserving correspondence for safe schemes [10 Theorems 5.1 and 5.3] (see also [8 Theorem 2, p. 14]) gives undecidability of ranked-tree equality for deterministic order-four higher-order pushdown automata without collapse (Corollary 7.1). The translations of [5 Theorem 11 and Corollary 19] give Π10\Pi^0_1-completeness of η\eta-long Böhm-tree equality for simply typed λY\lambda Y-terms, up to α\alpha-equivalence (Corollary 7.2). The latter transfer makes no claim that the same order bound or safety restriction is preserved.

For the construction, we use the intermediate alphabet Σ0={z:0,a:1,b:3}\Sigma_0 = \{ z : 0, a : 1, b : 3 \}: zz ends an observation, aa counts one unit, and bb groups an observation with two continuations. A routine injective encoding replaces these constructors by fixed Σ2\Sigma_2-tree contexts, preserving safety, productivity, and the order-four bound. This is the final pass of the compiler; § 5.6 proves its specification.

Figure 1 gives a scheme with types S : oo, F : (o→o)→o(o \to o) \to o, and D : (o→o)→o→o(o \to o) \to o \to o. The parameter ff denotes a unary context, and D ff composes that context with itself. Passing it to the next call of F gives observation subtrees azaz, a2za^2z, a4za^4z, …\ldots along a right spine, where anza^nz is a chain of nn nodes labelled aa ending in the leaf zz. Their unbounded distinct lengths make the resulting tree nonregular, although its description consists of three rules of order at most two.

A finite order-two scheme and its unique output tree

Figure 1. A finite order-two scheme and its unique output tree. Each expression anza^nz abbreviates a finite unary subtree. Passing D ff to the recursive call doubles the context used for the next observation.

S→F a,F f→c (f z) (F (D f)),D f x→f (f x).\begin{aligned} \mathrm{S} &\to\mathrm{F}\ a,\\ \mathrm{F}\ f &\to c\ (f\ z)\ (\mathrm{F}\ (\mathrm{D}\ f)),\\ \mathrm{D}\ f\ x &\to f\ (f\ x). \end{aligned}

z:0,a:1,c:2z : 0,\quad a : 1,\quad c : 2

The main theorem also rules out a computable input-size bound on the depth of a distinguishing node for unequal pairs in this class (Corollary 7.4).

Putting two output trees below a common root does not by itself compare labels at corresponding addresses. More generally, no total computable construction can map each pair of safe, productive schemes of order at most four over Σ2\Sigma_2 to a HORS whose tree satisfies a fixed MSO sentence exactly when the input trees differ. Composing such a construction with an MSO model checker would decide the equivalence problem in Theorem 1.1.

Contributions

Boiret, Piórkowski, and Schmude [3 Section 4, Theorem 20, p. 48:14] prove undecidability for deterministic polynomial-register automata with substitution, even on word inputs. We adapt their counter-guard witness, retaining the polynomial Zm(X)=∏j=1m(X−j)Z_m(X) = \prod_{j=1}^{m}(X-j), the multipliers Zm(c)Z_m(c) and cc for zero and positive guesses, and the first-error argument. § 4 specifies the different control checks and resulting weights.

The compiler realizes arithmetic on pairs of natural numbers, evaluation of the witness polynomial, and its shift update. Its safe, productive HORS implementation has three parts:

  1. State calls enforce control flow and identify halts, removing the register construction’s polynomial tests of control states. The weight checks only the selected counter guard.

  1. Functions store the evolving polynomial at fixed simple types. A shift recurrence constructs new components from the old ones without retaining the step count as a lower-order parameter. The stored polynomial terms satisfy the operand condition for safety as the degree grows.

  1. Tree equality expresses cancellation. A signed weight W=W+−W−W = W^{+} - W^{-} is zero exactly when its natural components are equal, even if both are large. Generating a unary observation subtree for each component expresses cancellation as equality of two varying trees.

Proof architecture

Let MM be a deterministic two-counter Minsky machine. Write M↓M\downarrow for halting from the first instruction with both counters zero, and M↑M\uparrow for ¬(M↓)\neg(M\downarrow). This zero-start halting problem is undecidable [6]. § 2.1 gives the instruction semantics; § 3 fixes the source decision problem. The first compiler stage produces GML,GMRG_M^L,G_M^R over the intermediate alphabet Σ0={z:0,a:1,b:3}\Sigma_0 = \{z : 0, a : 1, b : 3\}. Its final pass replaces the constructors by fixed tree contexts EE and outputs G^M⋄=(GM⋄)E\widehat{G}_M^\diamond= (G_M^\diamond)^E over Σ2\Sigma_2, for ⋄∈{L,R}\diamond\in\{L,R\}. We prove

M↑⟺BT⁡(G^ML)=BT⁡(G^MR).(1)M\uparrow\qquad\Longleftrightarrow\qquad\operatorname{BT}(\widehat{G}_M^L) = \operatorname{BT}(\widehat{G}_M^R). \tag*{(1)}

In the intermediate trees, each zero test generates two continuation subtrees: one follows the instruction for a zero counter, the other the instruction for a positive counter. Both are generated without checking which answer is correct. A path through these continuations describes a candidate execution. Its guessed answers may be wrong; a finite prefix is legal when every guess agrees with the counter value at that step. Wrong guesses can even make the candidate’s counters negative.

Along each candidate, arithmetic updates maintain an integer weight WW that is nonzero exactly on legal prefixes. We represent it as W=W+−W−W = W^+ - W^- with natural components. If the candidate reaches a halting position, the left and right schemes generate the unary observation subtrees aW+za^{W^+}z and aW−za^{W^-}z, respectively. These observations agree exactly when W=0W = 0. An illegal candidate therefore gives matching observations, while a legal halt gives a finite discrepancy. Outside these observations, the two trees have matching labels and branching, so every discrepancy comes from a legal halt.

We prove that the stored functions can be reused in arithmetic and that every candidate branch remains productive. An address argument shows that all mismatches occur at halt observations. The technical overview follows a two-instruction machine through the witness updates and HORS rules to a distinguishing address.

Jochems’s effective transformation replaces every ⊥\perp node by an infinite chain of a fresh terminal, preserving and reflecting tree equality [9 Lemma 2.7 and Proposition 2.8, p. 42]. Its outputs are productive, so enumerating their finite prefixes semidecides inequality and yields the general co-c.e. upper bound. We give a direct finite-semantics adequacy proof [16 Theorem 4.1, p. 10] and an algorithm computing exact prefixes at any prescribed depth.

Organization. After the technical overview, § 3 fixes the standard syntax, observations, and source convention. § 4 defines candidate executions and their arithmetic witness. § 5 proves the compiler’s correctness, typing, safety, and two-terminal output. § 6 supplies the matching upper bound, and § 7 derives the mathematical consequences.

Technical overview

Given a two-counter machine MM, we construct two safe, productive HORS of order at most four whose trees agree exactly when MM does not halt. The first stage uses Σ0={z:0,a:1,b:3}\Sigma_0 = \{z : 0, a : 1, b : 3\} to separate observations from continuations; fixed constructor contexts then give the final alphabet Σ2={e:0,d:2}\Sigma_2 = \{e : 0, d : 2\}. The counter-guard witness and its first-error argument are adapted from Boiret, Piórkowski, and Schmude [3 Section 4]. The construction below stores the evolving polynomial at fixed types and expresses a zero weight by comparing two unary observation trees.

Candidate executions and the adapted witness

We use deterministic two-counter Minsky machines with instruction forms

ι::=inc⁡A∣inc⁡B∣dec⁡A(j)∣dec⁡B(j),j∈N.\iota::= \operatorname{inc}_{A} \mid\operatorname{inc}_{B} \mid\operatorname{dec}_{A}(j) \mid\operatorname{dec}_{B}(j), \qquad j \in\mathbb{N}.

A program is a finite list M=[ι1,…,ιL]M = [\iota_1,\ldots,\iota_L], with L=∣M∣L = |M| and instruction positions IM={1,…,L}I_M = \{1,\ldots,L\}. The lookup M(i)=ιiM(i) = \iota_i is defined exactly for i∈IMi \in I_M. Jump targets may be any natural number, including zero and positions beyond LL.

For X∈{A,B}X \in\{A,B\}, an instruction inc⁡X\operatorname{inc}_{X} increments counter XX and advances to the next instruction. An instruction dec⁡X(j)\operatorname{dec}_{X}(j) advances when X=0X = 0; otherwise it decrements XX and jumps to jj. The other counter is unchanged. Execution starts at position 1 with both counters zero and halts exactly when the program counter is outside IMI_M; no separate halt instruction is needed. The empty program has IM=∅I_M = \varnothing and halts immediately.

To construct the candidate tree, unfold this finite control from the initial configuration. At each test, generate both successors without checking their guards, labelled 1 for the zero choice and 2 for the positive choice. An increment gives two copies of its successor; a halt gives a leaf. A path describes a candidate execution, whose virtual counters may become negative after a wrong positive choice. § 4.1 defines this unfolding and its relation to the source steps.

Write CM⊆{1,2}∗C_M \subseteq\{1,2\}^{*} for these finite candidate prefixes, including ϵ\epsilon. Let LM⊆CML_M \subseteq C_M be the set of prefixes on which every guessed guard holds. For v∈CMv \in C_M, let pc⁡M(v)\operatorname{pc}_M(v) be its final program counter.

The unfolding fixes the control flow, so the weight only needs to detect incorrect counter guards. After mm instructions of a legal execution, each counter lies in [0,m][0,m]. The polynomial

Zm(X)=∏j=1m(X−j),Z0(X)=1,Z_m(X) = \prod_{j=1}^{m}(X-j), \qquad Z_0(X) = 1,

satisfies Zm(0)=(−1)mm!≠0Z_m(0) = (-1)^m m! \ne0 and Zm(c)=0Z_m(c) = 0 for 1≤c≤m1 \le c \le m. Initialize W=1W = 1. For the current instruction ι\iota on counter X∈{A,B}X \in\{A,B\}, let cc be its old value and e∈{1,2}e \in\{1,2\} the candidate choice: at a test, e=1e = 1 guesses zero and e=2e = 2 guesses positive. Update the selected counter and weight simultaneously:

(c′,W′)={(c+1,W),ι=inc⁡X,(c,WZm(c)),ι=dec⁡X(j)∧e=1,(c−1,Wc),ι=dec⁡X(j)∧e=2.(2)(c',W') = \begin{cases} (c+1,W), & \iota= \operatorname{inc}_{X},\\ (c,WZ_m(c)), & \iota= \operatorname{dec}_{X}(j) \land e = 1,\\ (c-1,Wc), & \iota= \operatorname{dec}_{X}(j) \land e = 2. \end{cases} \tag*{(2)}

All right-hand sides use the old values. Every instruction also advances mm and replaces ZmZ_m by Zm+1Z_{m+1}. Write WM(v)W_M(v) for the resulting weight of a prefix vv; in particular, WM(ϵ)=1W_M(\epsilon) = 1.

Correct choices multiply the weight by a nonzero integer. At the first wrong choice the tested counter is still in [0,m][0,m]: a false zero choice has 1≤c≤m1 \le c \le m and multiplies by Zm(c)=0Z_m(c) = 0; a false positive choice has c=0c = 0 and also multiplies by zero. Later updates preserve zero even if the virtual counters become negative. Consequently

∀v∈CM,WM(v)≠0⟺v∈LM.(3)\forall v \in C_M,\qquad W_M(v) \ne0 \quad\Longleftrightarrow\quad v \in L_M. \tag*{(3)}

This is the first-error argument of the polynomial-register construction. § 4 proves the invariant and its correspondence with the precise source-machine convention.

To realize the witness in HORS, we represent signed integers by pairs of natural numbers and the evolving polynomial by functions at fixed types. Comparing unary subtrees generated from the two integer components expresses the zero condition. The polynomial-register construction uses polynomial-substitution primitives; our function representation implements the required evaluations and updates by ordinary HORS application.

Encoding cancellation by comparison

Represent an integer by a pair (u,v)∈N2(u,v) \in\mathbb{N}^{2} with value u−vu-v. The pair is not normalized. Increment, decrement, and multiplication are realized by

inc⁡(u,v)=(u+1,v),dec⁡(u,v)=(u,v+1),\operatorname{inc}(u,v)=(u+1,v), \qquad\operatorname{dec}(u,v)=(u,v+1),
(u,v)⊗(r,s)=(ur+vs,us+vr).(u,v)\otimes(r,s)=(ur+vs,us+vr).

The multiplication components have difference (u−v)(r−s)(u-v)(r-s). All component operations use successor, addition, and multiplication on naturals. A negative virtual counter after an invalid choice still has two natural components, and decrement requires no predecessor operation.

Keep the weight as W=W+−W−W=W^{+}-W^{-}. In each intermediate output tree, a candidate node has label bb: child 0 carries an observation, and children 1, 2 carry the continuations. At nonhalting candidates the observation is zz. At a candidate halt, the left scheme generates the observation subtree aW+za^{W^{+}}z and the right scheme generates aW−za^{W^{-}}z. Each is a finite chain of aa-nodes ending in zz; the continuation children then use the shared padding defined in § 2.4. The two observations satisfy

aW+z=aW−z⟺W=0.(4)a^{W^{+}}z=a^{W^{-}}z \Longleftrightarrow W=0. \tag*{(4)}

Equality of the generated trees supplies this comparison. For example, the pair (1,1)(1,1) represents zero and gives azaz on both sides. Comparing its left observation with zz would report a discrepancy. Thus the register construction’s comparison with a constant-zero function becomes a comparison of two varying output trees.

A safe polynomial representation at fixed types

The polynomial ZmZ_m has degree mm. Listing all its coefficients would require a growing collection of coordinates. We retain two functions Pm+,Pm−:N2→NP_m^{+},P_m^{-}:\mathbb{N}^{2}\to\mathbb{N} satisfying

Pm+(u,v)−Pm−(u,v)=Zm(u−v).P_m^{+}(u,v)-P_m^{-}(u,v)=Z_m(u-v).

To represent their inputs and outputs in HORS, use the simple types

C=o→o,N=C→C,P=N→N→N.C=o\to o, \qquad N=C\to C, \qquad P=N\to N\to N.

A Church numeral of type N represents iteration: the numeral for nn, applied to f,xf,x, gives fn(x)f^{n}(x). A stored polynomial component has type P and maps two such numerals to a numeral for its value. The order function

ord⁡(o)=0,ord⁡(σ→τ)=max⁡{ord⁡(σ)+1,ord⁡(τ)}(5)\operatorname{ord}(o)=0, \qquad\operatorname{ord}(\sigma\to\tau)=\max\{\operatorname{ord}(\sigma)+1,\operatorname{ord}(\tau)\} \tag*{(5)}

gives ord⁡(C)=1\operatorname{ord}(C)=1, ord⁡(N)=2\operatorname{ord}(N)=2, and ord⁡(P)=3\operatorname{ord}(P)=3.

Safety requires homogeneous types and a bound on the parameters of operands [8 Definition 1]. Homogeneity means that curried parameter orders are nonincreasing, recursively at argument types: N=C→o→oN=C\to o\to o has parameter orders 1, 0, and P=N→N→C→o→oP=N\to N\to C\to o\to o has orders 2, 2, 1, 0. A term ss supplied as an argument must satisfy ord⁡(s)≤ord⁡(x)\operatorname{ord}(s)\le\operatorname{ord}(x) for every rule parameter xx occurring in ss. § 3 gives the full definition.

This condition constrains how we update the stored functions p,q:Pp,q:P. The polynomial-register construction stores the step counter mm and uses Zm+1(x)=Zm(x)(x−m−1)Z_{m+1}(x)=Z_m(x)(x-m-1) [3 Section 4]. A direct encoding that passes the operand Upd⁡ p q t:P\operatorname{Upd}\ p\ q\ t:P, with a rule parameter t:Nt:N representing mm, violates safety: the order-three operand contains an order-two parameter. We therefore use the shift identity

Zm+1(x)=(x−1)Zm(x−1).Z_{m+1}(x)=(x-1)Z_m(x-1).

Writing Cm=(Pm+,Pm−)C_m=(P_m^+,P_m^-), it yields

C0(u,v)=(1,0),Cm+1(u,v)=(u,v+1)⊗Cm(u,v+1).(6)C_0(u,v)=(1,0), \qquad C_{m+1}(u,v)=(u,v+1)\otimes C_m(u,v+1). \tag*{(6)}

Taking differences proves the representation for all natural u,vu,v, including u<vu<v. In particular,

Pm+1+(u,v)=uPm+(u,v+1)+(v+1)Pm−(u,v+1),P_{m+1}^+(u,v)=uP_m^+(u,v+1)+(v+1)P_m^-(u,v+1),

and the negative component interchanges Pm+P_m^+ and Pm−P_m^-. The index mm belongs to this mathematical invariant; the compiled state does not carry a step-counter parameter.

Ordinary Church arithmetic implements the component operations. The helpers Pos, Neg compute ur+vsur+vs and us+vrus+vr; for example,

Pos⁡ u v r s f x→Add⁡(Mul⁡ u r)(Mul⁡ v s) f x.\operatorname{Pos}\ u\ v\ r\ s\ f\ x\mathbin{\to}\operatorname{Add}(\operatorname{Mul}\ u\ r)(\operatorname{Mul}\ v\ s)\ f\ x.

The full rules for numerals, successor, addition and multiplication are given in Section 5.1; these helpers have order at most three. Introduce Next⁡±:P→P→P\operatorname{Next}_{\pm}:\mathrm{P}\to\mathrm{P}\to\mathrm{P}, of order four. If p,qp,q represent Pm+,Pm−P_m^+,P_m^-, then Next⁡+ p q\operatorname{Next}_+\,p\,q and Next⁡− p q\operatorname{Next}_-\,p\,q represent the next components. The positive rule is

Next⁡+ p q u v f x→Pos⁡ u (Succ⁡ v)(p u (Succ⁡ v)) (q u (Succ⁡ v)) f x.(7)\begin{aligned} \operatorname{Next}_+\,p\,q\,u\,v\,f\,x&\mathbin{\to}\operatorname{Pos}\ u\ (\operatorname{Succ}\ v)\\ &\quad(p\ u\ (\operatorname{Succ}\ v))\ (q\ u\ (\operatorname{Succ}\ v))\ f\ x. \tag*{(7)} \end{aligned}

The negative update replaces Pos by Neg. Here p,q:Pp,q:\mathrm{P}, u,v:Nu,v:\mathrm{N}, f:Cf:\mathrm{C}, and x:ox:o; the right-hand side has ground type oo. The two polynomial calls evaluate the old components at the same shifted argument pair.

The stored operand Next⁡± p q:P\operatorname{Next}_{\pm}\ p\ q:\mathrm{P} depends only on the order-three parameters p,qp,q. Numeral arguments are supplied later: p u (Succ⁡ v)p\ u\ (\operatorname{Succ}\ v) has order two, at most the order of each parameter it contains. Its order-three prefix p up\ u is in function position and has no operand inequality of its own. Section 5.3 checks all operand families and homogeneous types.

Repeated updates build nested applications of these fixed nonterminals. The terms grow in size and represent polynomials of increasing degree, while their type remains P; Lemma 5.4 proves the invariant.

Control rules, reusable representations, and productivity

The arithmetic terms now form the parameters of state calls that generate the candidate tree. Each source instruction at position ii is compiled into the rule defining a control nonterminal FiF_i; F0F_0 handles halts. A state call has the form

Fi p q u v r s h k,Fi:P→P→N6→o.F_i\ p\ q\ u\ v\ r\ s\ h\ k,\qquad F_i:\mathrm{P}\to\mathrm{P}\to\mathrm{N}^6\to o.

The terms p,qp,q represent the current polynomial components. The numeral pairs (u,v),(r,s),(h,k)(u,v),(r,s),(h,k) represent the signed values of the counters AA, BB and weight WW, respectively. The start rule supplies representations of C0C_0, zero counter pairs, and weight pair (1,0)(1,0). The control type also has order four. The source program determines the number of control rules, while their types are fixed; Lemma 5.1 gives the complete type audit. Normalize source positions by

j^={j,j∈IM,0,j∉IM.\hat{j}= \begin{cases} j, & j\in I_M,\\ 0, & j\notin I_M. \end{cases}

Thus every out-of-range program position uses the halting nonterminal F0F_0. Write p′=Next⁡+ p qp'=\operatorname{Next}_+\,p\,q and q′=Next⁡− p qq'=\operatorname{Next}_-\,p\,q as textual abbreviations. If instruction ii is dec⁡A(j)\operatorname{dec}_A(j), its control rule is

Fi p q u v r s h k→ bz(Fi+1 p′ q′ u v r s(Pos⁡ h k (p u v) (q u v))(Neg⁡ h k (p u v) (q u v))(Fj^ p′ q′ u (Succ⁡ v) r s(Pos⁡ h k u v) (Neg⁡ h k u v))).(8)\begin{aligned} F_i\ p\ q\ u\ v\ r\ s\ h\ k\mathbin{\to}\ b_z\bigl(&F_{i+1}\ p'\ q'\ u\ v\ r\ s\\ &(\operatorname{Pos}\ h\ k\ (p\ u\ v)\ (q\ u\ v))\\ &(\operatorname{Neg}\ h\ k\ (p\ u\ v)\ (q\ u\ v))\\ &\bigl(F_{\hat{j}}\ p'\ q'\ u\ (\operatorname{Succ}\ v)\ r\ s\\ &\quad(\operatorname{Pos}\ h\ k\ u\ v)\ (\operatorname{Neg}\ h\ k\ u\ v)\bigr)\bigr). \tag*{(8)} \end{aligned}

The ternary constructor bb reserves child 0 for an observation and children 1, 2 for the zero and positive continuations. Both use the old counter in the weight update; the zero choice also uses the old polynomial. Both pass the new polynomial. There is one production, so emitting both continuations introduces no nondeterminism. At an increment the two continuation children are identical.

At a halt, the numeral parameters h,k:Nh,k:\mathbb{N} represent the weight components W+,W−W^{+},W^{-}. Applying them to the constructors a,za,z gives ground terms h a zh\,a\,z and k a zk\,a\,z, which generate the observation chains aW+za^{W^{+}}z and aW−za^{W^{-}}z. Introduce a shared padding nonterminal K:oK:o with rule K→b z K KK \to b\,z\,K\,K for the two continuation children after a halt. The left halting rule has body b (h a z) K Kb\,(h\,a\,z)\,K\,K and the right has body b (k a z) K Kb\,(k\,a\,z)\,K\,K. These are the only different rules; the padding subtrees are identical and productive in both outputs.

Running example. Take M=inc⁡A;dec⁡A(0)M=\operatorname{inc}_{A};\operatorname{dec}_{A}(0), starting from zero. After the increment, A=1A=1, m=1m=1, and W=1W=1. The zero choice advances to position 3, while the positive choice decrements AA and jumps to 0. Both positions are out of range, but only the positive choice is legal. From Equation (6), C1(u,v)=(u,v+1)C_{1}(u,v)=(u,v+1). The false zero choice therefore multiplies the initial weight pair (1,0)(1,0) by C1(1,0)=(1,1)C_{1}(1,0)=(1,1) and obtains (1,1)(1,1). The positive choice multiplies by the old counter pair (1,0)(1,0) and retains weight (1,0)(1,0). The observations appear in Figure 2.

Shared test node, invalid zero choice, and legal positive choice, showing the observation trees and weight components

Figure 2. The program inc⁡A;dec⁡A(0)\operatorname{inc}_{A};\operatorname{dec}_{A}(0) at its test after the increment. Both schemes generate this whole control skeleton; KK marks the common padding subtrees. The observations O1,O2O_{1},O_{2} correspond to the zero and positive choices, respectively. The invalid zero choice gives weight components (1,1)(1,1) and matching observations azaz; the legal positive choice gives (1,0)(1,0) and observations az,zaz,z. The differing labels are boxed.

In the compiled execution, the increment constructs U=Succ⁡ Zero⁡U=\operatorname{Succ}\ \operatorname{Zero}. This term and One both represent the number 1. Let p1,q1p_{1},q_{1} be the updated polynomial terms, representing P1+,P1−P_{1}^{+},P_{1}^{-}. The false zero branch passes the weight pair (h0,k0)(h_{0},k_{0}) in both schemes, where

h0=Pos⁡ One⁡ Zero⁡ (p1 U Zero⁡) (q1 U Zero⁡)h_{0}=\operatorname{Pos}\ \operatorname{One}\ \operatorname{Zero}\ (p_{1}\ U\ \operatorname{Zero})\ (q_{1}\ U\ \operatorname{Zero})

and k0k_{0} is the corresponding Neg term. Both components represent one. At the halt, the observation terms h0 a zh_{0}\ a\ z and k0 a zk_{0}\ a\ z both generate the chain azaz. On the positive branch, the multiplier pair is (U,Zero⁡)(U,\operatorname{Zero}), and the halt observations are az,zaz,z. Choosing child 1 at the increment, the corresponding observation addresses are 110 and 120; the latter already has different labels.

Representations on every candidate. The stored numerals must remain usable in later arithmetic, even when they are composed terms such as UU. Correctness only at the observation arguments a,za,z does not justify these uses. For example,

Mul⁡ m n f x→m (n f) x\operatorname{Mul}\ m\ n\ f\ x \to m\ (n\ f)\ x

supplies mm with a function computed from nn. A numeral must therefore implement the represented number of iterations for every related function and ground argument. If m,nm,n represent r,sr,s and ff represents a function FF, then nn ff represents FsF^{s}; applying mm gives rr ss iterations of FF. The typed realization relation in Equation (18) formalizes this requirement for numerals and polynomial functions.

Induction on candidate-prefix length maintains the numeral property for all six natural-number components and the function property for both polynomial terms. This includes illegal candidates with zero signed weight or negative virtual counters: every component still represents a finite natural number, as proved in Lemma 5.5. The witness invariant identifies legal prefixes through the signed weight; the representation invariant validates arithmetic on every candidate.

Productivity. A control rule exposes bb immediately, but its observation child may still require arithmetic. Numeral realization ensures that the selected component produces a finite chain. The continuation children again satisfy the representation invariant, or enter common padding. Induction on observation depth therefore proves productivity of both whole trees, including every illegal branch. Guarded control recursion alone would leave the arithmetic observations unjustified.

Closing both directions of the reduction

Let v∈{1,2}∗v \in\{1,2\}^{*} encode a candidate prefix by its continuation choices. Corresponding control nodes in the two schemes carry the same register terms. The all-address correspondence of Lemma 5.6 identifies their observations with those specified by the arithmetic updates, including the padding and absent addresses.

If vv reaches a legal halt with weight components rr, ss, then Equation (3) gives r≠sr \ne s. Its observation children are arza^{r}z and asza^{s}z. At the address

v00min⁡(r,s)(9)v00^{\min(r,s)} \tag*{(9)}

one tree has zz and the other has aa. Thus a source halt gives an actual finite HORS discrepancy.

For the converse, take a first discrepancy. Productivity and the ranked alphabet ensure that both nodes there exist: their agreeing ancestor labels determine the same child arities. Following only children 1, 2 cannot give different labels, since every control or padding root is bb. Padding subtrees agree completely. A discrepancy must therefore select child 0 of a candidate state. A nonhalting state has observation zz on both sides. At a halt the only possible disagreement is between unequal chains, so r≠sr \ne s and the signed weight is nonzero. The entire candidate is legal by Equation (3), and its control position is a source halt. Write T⋄=BT⁡(GM)T_{\diamond} = \operatorname{BT}(G_{M}), with dom⁡(T)\operatorname{dom}(T) denoting a tree’s address set and T(w)T(w) its label at ww. Then

M↓⟺∃v∈CM [pc⁡M(v)≠⊥∧WM(v)≠0]M\downarrow\Longleftrightarrow\exists v \in C_{M}\,[\operatorname{pc}_{M}(v) \ne\bot\land W_{M}(v) \ne0]
⟺∃w∈dom⁡(TL)∩dom⁡(TR) [TL(w)≠TR(w)]\Longleftrightarrow\exists w \in\operatorname{dom}(T_{L}) \cap\operatorname{dom}(T_{R})\,[T_{L}(w) \ne T_{R}(w)]
⟺BT⁡(GML)≠BT⁡(GMR).\Longleftrightarrow\operatorname{BT}(G_{M}^{L}) \ne\operatorname{BT}(G_{M}^{R}).

The intermediate compiler only inserts fixed finite templates into a table indexed by the source instructions, so it is total computable. Theorem 5.8 states this stage’s specification.

Realizing the two-terminal alphabet

The constructors zz, aa, bb separate the observation and control structure throughout the argument. The final compiler pass realizes each by a fixed tree context over Σ2={e:0,d:2}\Sigma_{2} = \{e : 0, d : 2\}:

E(z)=e,E(z) = e,
E(a t)=d(e,E(t)),E(a\,t) = d(e,E(t)),
E(b(t0,t1,t2))=d(d(e,e),d(E(t0),d(E(t1),E(t2)))).E(b(t_{0},t_{1},t_{2})) = d(d(e,e),d(E(t_{0}),d(E(t_{1}),E(t_{2})))).

The root separates zz from aa, bb, and the left child’s root separates aa from bb. Their source children occur at fixed target addresses, so decoding finite addresses recovers every source label. Thus E(T)=E(U)⟺T=UE(T) = E(U) \Longleftrightarrow T = U, for finite and infinite trees. Three helper rules implement these contexts at order at most one. They preserve safety and productivity; Lemma 5.9 gives the syntactic and semantic argument.

For the final schemes G^M⋄=(GM⋄)E\widehat{G}^{\diamond}_{M} = (G^{\diamond}_{M})^{E},

M↑⟺BT⁡(GML)=BT⁡(GMR)⟺BT⁡(G^ML)=BT⁡(G^MR).M{\uparrow} \Longleftrightarrow\operatorname{BT}(G^{L}_{M}) = \operatorname{BT}(G^{R}_{M}) \Longleftrightarrow\operatorname{BT}(\widehat{G}^{L}_{M}) = \operatorname{BT}(\widehat{G}^{R}_{M}).

This proves the lower bound of Theorem 1.1, including its two-terminal restriction. The constructor encoding is routine; the witness implementation and its type and safety arguments are unchanged by this final pass.

The upper bound and completeness

Since zero-start machine halting is c.e.-complete (§ 3), the reduction from its complement gives Π10\Pi^0_1-hardness for the stated restricted class. The general co-c.e. upper bound already follows from Jochems’s effective ⊥\perp-elimination [9 Lemma 2.7 and Proposition 2.8]. Its productive outputs permit finite-prefix search for a discrepancy. § 6 gives a direct argument using the standard finite model for head convergence [16 Section 4.1 and Theorem 4.1].

For a closed ground term, this model records only whether a terminal head can be exposed; zz and azaz both have value one. Higher-type values are finite function tables. Monotone iteration of the rule interpretations from the least values stabilizes, and head adequacy makes the final answer exact. To read an address, start at the root. A positive answer permits a terminating head search and, if the address continues, descent through a valid child index. A negative answer makes the current node ⊥\perp; all its proper descendants are absent. An out-of-range child index is also absent.

The resulting reader distinguishes a terminal label, a present ⊥\perp node, and an absent address, and computes an exact prefix Pref⁡(G,d)\operatorname{Pref}(G,d) at any prescribed finite depth dd. For well-formed schemes over a common ranked alphabet,

BT⁡(G)=BT⁡(H)⟺∀d Pref⁡(G,d)=Pref⁡(H,d).\operatorname{BT}(G) = \operatorname{BT}(H) \Longleftrightarrow\forall d\ \operatorname{Pref}(G,d) = \operatorname{Pref}(H,d).

Productivity means that no such prefix contains ⊥\perp. Together with the decidable syntactic restrictions, these universal conditions give a Π10\Pi^0_1 definition of the restricted problem as an ordinary language. Combining this upper bound with the reduction proves the completeness claim of Theorem 1.1.

Schemes, observations, and decision problems

Simple types are generated by oo and σ→τ\sigma\to\tau, with arrows associating to the right; σr→τ\sigma^r \to\tau denotes rr curried arguments of type σ\sigma. We use the order function defined in Equation (5). A ranked alphabet assigns a natural-number arity rr to each terminal aa, whose type is or→oo^r \to o. A deterministic higher-order recursion scheme GG consists of a finite such alphabet Σ\Sigma, a finite typed set of nonterminals, a start symbol S:oS : o, and exactly one rule Fx1⋯xr→tFF x_1 \cdots x_r \to t_F per nonterminal F:σ1→⋯→σr→oF : \sigma_1 \to\cdots\to\sigma_r \to o. The parameters are distinct, xi:σix_i : \sigma_i, and tF:ot_F : o is an applicative term over these parameters, terminals, and declared nonterminals. Terms have the syntax t::=x∣F∣a∣t tt ::= x \mid F \mid a \mid t\ t. Thus a rule has a ground body even when a partial application of its nonterminal has functional type. The scheme order is the maximum order of its nonterminal types. Concrete nonterminal names in the constructions, such as FiF_i, SS, and KK, are set in sans serif; schematic symbols and rule parameters are italic.

Safety. We use [8 Definition 1]. A type σ1→⋯→σr→o\sigma_1 \to\cdots\to\sigma_r \to o is homogeneous if each σi\sigma_i is homogeneous and ord⁡(σ1)≥⋯≥ord⁡(σr)\operatorname{ord}(\sigma_1) \ge\cdots\ge\operatorname{ord}(\sigma_r). A rule is safe if its nonterminal and all body subterms have homogeneous types, and every application operand ss satisfies ord⁡(s)≤ord⁡(x)\operatorname{ord}(s) \le\operatorname{ord}(x) for each rule parameter xx occurring in ss. In u su\ s, this condition applies to ss, not to the function prefix uu. Nonterminal constants do not count as parameters. A scheme is safe if all its rules are safe. Typing and finite syntax traversal decide this property.

Head rewriting. For closed ground terms, the only unfolding rule is

F u1⋯ur→htF[u1/x1,…,ur/xr],F\ u_1 \cdots u_r \mathrel{\xrightarrow{h}} t_F[u_1/x_1,\ldots,u_r/x_r],

where substitution is simultaneous. No reduction under a terminal is needed to expose its head. Write t⇓Ga(t0,…,tr−1)t \Downarrow_G a(t_0,\ldots,t_{r-1}) when finitely many head steps produce that terminal application. A well-typed closed ground term has either a terminal or a fully applied nonterminal at its head. Unfolding preserves typing, by induction on the body with simultaneous substitution. Since each nonterminal has one rule, head steps are deterministic, and two head exposures of the same term have the same terminal and the same list of children.

Addresses are words over N\mathbb{N}, with zero-based child indices. Define positive observations by

Obs⁡G(t,ϵ,a)⟺∃u⃗  t⇓Ga(u⃗)\operatorname{Obs}_G(t,\epsilon,a) \Longleftrightarrow\exists\vec{u}\; t \Downarrow_G a(\vec{u})
Obs⁡G(t,iw,a)⟺∃c,u⃗  [t⇓Gc(u⃗)∧i<∣u⃗∣∧Obs⁡G(ui,w,a)].\operatorname{Obs}_G(t,iw,a) \Longleftrightarrow\exists c,\vec{u}\; [t \Downarrow_G c(\vec{u}) \land i < |\vec{u}| \land\operatorname{Obs}_G(u_i,w,a)].

The value tree BT⁡G(t)\operatorname{BT}_G(t) has root aa and recursively these children when t⇓Ga(u⃗)t \Downarrow_G a(\vec{u}); otherwise its root is a fresh nullary symbol ⊥\perp. This defines a possibly infinite ranked tree over Σ∪{⊥:o}\Sigma\cup\{\perp: o\}. In particular, a child below a leaf is absent, whereas a divergent term at an actual child gives a present ⊥\perp node. The positive observations determine this tree: the root either has its unique observed label or is ⊥\perp, and the same reasoning applies to each child required by an observed label’s arity. Hence

BT⁡(G)=BT⁡(H)⟺∀w∈N∗, a∈Σ [Obs⁡G(SG,w,a)⟺Obs⁡H(SH,w,a)].(10)\operatorname{BT}(G) = \operatorname{BT}(H) \Longleftrightarrow\forall w \in\mathbb{N}^{*},\ a \in\Sigma\ [\operatorname{Obs}_G(S_G,w,a) \Longleftrightarrow\operatorname{Obs}_H(S_H,w,a)]. \tag*{(10)}

Here and below BT⁡(G)=BT⁡G(SG)\operatorname{BT}(G) = \operatorname{BT}_G(S_G), with a shared ranked alphabet.

A term is productive to depth zero unconditionally; it is productive to depth d+1d+1 if it exposes a terminal and every actual child is productive to depth dd. A scheme is productive if its start term is productive to every depth. This is equivalent to having no ⊥\perp node; finite terminal leaves are permitted.

Inputs. Source programs and HORS descriptions are finite syntax. Fix standard computable injective encodings by natural numbers, with total computable decoders that return syntax or reject the input. Validity, closed references, and a specified order bound are decidable by syntax-directed checks. We consider ordinary languages of encodings:

EqHORS={⟨G,H⟩:Valid⁡(G,H)∧BT⁡(G)=BT⁡(H)},Eq4,Σ2={⟨G,H⟩∈EqHORS:Σ=Σ2∧max⁡{ord⁡(G),ord⁡(H)}≤4},Eq4,Σ2prod={⟨G,H⟩∈Eq4,Σ2:Prod⁡(G)∧Prod⁡(H)},Eq4,Σ2safe,prod={⟨G,H⟩∈Eq4,Σ2prod:Safe⁡(G)∧Safe⁡(H)}.\begin{aligned} \mathrm{Eq}_{\mathrm{HORS}} &= \{\langle G,H\rangle: \operatorname{Valid}(G,H) \land\operatorname{BT}(G)=\operatorname{BT}(H)\},\\ \mathrm{Eq}_{4,\Sigma_2} &= \{\langle G,H\rangle\in\mathrm{Eq}_{\mathrm{HORS}} : \Sigma=\Sigma_2 \land\max\{\operatorname{ord}(G),\operatorname{ord}(H)\}\le4\},\\ \mathrm{Eq}^{\mathrm{prod}}_{4,\Sigma_2} &= \{\langle G,H\rangle\in\mathrm{Eq}_{4,\Sigma_2} : \operatorname{Prod}(G)\land\operatorname{Prod}(H)\},\\ \mathrm{Eq}^{\mathrm{safe,prod}}_{4,\Sigma_2} &= \{\langle G,H\rangle\in\mathrm{Eq}^{\mathrm{prod}}_{4,\Sigma_2} : \operatorname{Safe}(G)\land\operatorname{Safe}(H)\}. \end{aligned}

Malformed inputs are rejected. Membership in Eq4,Σ2prod\mathrm{Eq}^{\mathrm{prod}}_{4,\Sigma_2} includes productivity; the input supplies no semantic promise.

Source machines. We use the two-counter machine model with undecidable halting in [6 Definition 2 and Theorem 6, pp. 16:3–16:4], with instruction positions reindexed from zero to one. § 2.1 gives the instruction syntax and execution convention. A configuration (q,a,b)∈N3(q,a,b)\in\mathbb{N}^3 records the program position and the two counter values. It halts exactly when q∉IMq\notin I_M. Write →M\to_M for the configuration step relation and →M∗\to_M^* for its reflexive transitive closure. Our termination notation is

M↓⟺∃(q,a,b)∈N3[(1,0,0)→M∗(q,a,b)∧q∉IM],M\mathord{\downarrow}\Longleftrightarrow\exists(q,a,b)\in\mathbb{N}^3\left[(1,0,0)\to_M^*(q,a,b)\land q\notin I_M\right],
M↑⟺¬(M↓).M\mathord{\uparrow}\Longleftrightarrow\neg(M\mathord{\downarrow}).

The zero-start halting problem is c.e.-complete. The effective two-counter simulation gives c.e.-hardness for arbitrary initial configurations [6 Section 2, p. 16:4]. A finite prefix initializes the counters, then uses the two-instruction gadget inc⁡A;dec⁡A(j)\operatorname{inc}_A;\operatorname{dec}_A(j) to jump to the relocated initial position jj while restoring both counter values: the decrement necessarily takes its positive branch. Jump relocation keeps every halting target out of range, in particular leaving target zero at zero. This yields the fixed initial state (1,0,0)(1,0,0). Bounded simulation gives c.e. membership.

Arithmetic witnesses for candidate executions

We adapt the bounded-counter guard witness of Boiret, Piórkowski, and Schmude [3 Section 4, pp. 48:12–48:14] to the source instruction set in § 2.1. We first define the candidate unfolding, then assign weights that distinguish legal prefixes from illegal ones.

Candidate unfolding

A candidate follows the program’s control instructions but chooses either outcome of a decrement test without checking its guard. Its virtual counters range over Z\mathbb{Z}, since a wrong positive choice at zero produces −1-1. For an active configuration s=(i,a,b)s=(i,a,b), where i∈IMi\in I_M, and a choice e∈{1,2}e\in\{1,2\}, define

δeM(i,a,b)={(i+1,a+1,b),M(i)=inc⁡A,(i+1,a,b+1),M(i)=inc⁡B,(i+1,a,b),M(i)=dec⁡A(j)∧e=1,(j,a−1,b),M(i)=dec⁡A(j)∧e=2,(i+1,a,b),M(i)=dec⁡B(j)∧e=1,(j,a,b−1),M(i)=dec⁡B(j)∧e=2.(11)\delta_e^M(i,a,b)= \begin{cases} (i+1,a+1,b), & M(i)=\operatorname{inc}_A,\\ (i+1,a,b+1), & M(i)=\operatorname{inc}_B,\\ (i+1,a,b), & M(i)=\operatorname{dec}_A(j)\land e=1,\\ (j,a-1,b), & M(i)=\operatorname{dec}_A(j)\land e=2,\\ (i+1,a,b), & M(i)=\operatorname{dec}_B(j)\land e=1,\\ (j,a,b-1), & M(i)=\operatorname{dec}_B(j)\land e=2. \end{cases} \tag*{(11)}

Both choices have the same successor at an increment. The map is undefined when i∉IMi \notin I_M. For M(i)M(i) acting on counter X∈{A,B}X \in\{A,B\}, let cc be that counter’s value in ss. Its branch condition is

γeM(s)⟺{⊤,M(i)=inc⁡X,c=0,M(i)=dec⁡X(j)∧e=1,c>0,M(i)=dec⁡X(j)∧e=2.\gamma^M_e(s) \Longleftrightarrow\begin{cases} \top, & M(i)=\operatorname{inc}_X,\\ c=0, & M(i)=\operatorname{dec}_X(j) \land e=1,\\ c>0, & M(i)=\operatorname{dec}_X(j) \land e=2. \end{cases}

The successor δeM(s)\delta^M_e(s) is defined independently of γeM(s)\gamma^M_e(s). On natural-counter configurations, the choices satisfying γeM(s)\gamma^M_e(s) give exactly the source steps →M\to_M.

The candidate tree has domain CM⊆{1,2}∗C_M \subseteq\{1,2\}^* and configuration map sM:CM→N×Z2s_M:C_M\to\mathbb{N}\times\mathbb{Z}^2, generated by

ϵ∈CM,sM(ϵ)=(1,0,0),\epsilon\in C_M,\qquad s_M(\epsilon)=(1,0,0),
v∈CMpc⁡M(v)∈IMe∈{1,2}v\in C_M \qquad\operatorname{pc}_M(v)\in I_M \qquad e\in\{1,2\}
ve∈CMsM(ve)=δeM(sM(v)).ve\in C_M \qquad s_M(ve)=\delta^M_e(s_M(v)).

Here pc⁡M(v)\operatorname{pc}_M(v) is the first coordinate of sM(v)s_M(v), and CMC_M is the least set closed under these clauses. Every active node has two children; a node with pc⁡M(v)∉IM\operatorname{pc}_M(v)\notin I_M is a leaf. Thus a finite program may have an infinite candidate unfolding. The legal prefixes form LM⊆CML_M\subseteq C_M, defined by

ϵ∈LM,\epsilon\in L_M,
ve∈LM⟺v∈LM∧γeM(sM(v)),ve∈CM.ve\in L_M\Longleftrightarrow v\in L_M\land\gamma^M_e(s_M(v)),\qquad ve\in C_M.

They follow the source execution, with either label available at increments. The output trees in Equation (23) add observation children and common halt padding to this candidate tree.

Guard weights and halting correspondence

After mm instructions let

Zm(X)=∏j=1m(X−j),Z0(X)=1.Z_m(X)=\prod_{j=1}^{m}(X-j),\qquad Z_0(X)=1.

A legal prefix has 0≤A,B≤m0\leq A,B\leq m, because an instruction increases each counter by at most one. Also Zm(0)=(−1)mm!≠0Z_m(0)=(-1)^m m!\ne0, while Zm(c)=0Z_m(c)=0 for 1≤c≤m1\leq c\leq m. Each weight update multiplies by a factor determined by the current instruction ι\iota on counter XX, the candidate choice ee, and the old counter value cc:

ϕm(ι,e,c)={1,ι=inc⁡X,Zm(c),ι=dec⁡X(j)∧e=1,c,ι=dec⁡X(j)∧e=2.(12)\phi_m(\iota,e,c)=\begin{cases} 1, & \iota=\operatorname{inc}_X,\\ Z_m(c), & \iota=\operatorname{dec}_X(j)\land e=1,\\ c, & \iota=\operatorname{dec}_X(j)\land e=2. \end{cases} \tag*{(12)}

For ve∈CMve\in C_M, take m=∣v∣m=|v|, ι=M(pc⁡M(v))\iota=M(\operatorname{pc}_M(v)), and cc as the value of its selected counter after vv. Define

WM(ϵ)=1,WM(ve)=WM(v)ϕm(ι,e,c).(13)W_M(\epsilon)=1,\qquad W_M(ve)=W_M(v)\phi_m(\iota,e,c). \tag*{(13)}

Counter and control updates are given by Equation (11); the unselected counter is unchanged. Every instruction advances the clock to m+1m+1 and the polynomial to Zm+1Z_{m+1}. The multiplier in Equation (12) uses the pre-transition counter and polynomial, including before a decrement.

In the register construction of [3], an input word can name arbitrary transitions. Its weight update is rw←rwTqT1T2r_w\leftarrow r_wT_qT_1T_2: TqT_q checks the source control state, and T1,T2T_1,T_2 check both counter guards. A further state factor in the output selects the target state. Here candidates follow the finite control by construction; increments have no guard, and a decrement tests one counter. We retain exactly that guard’s multiplier and observe weights only at halts. The complete numerical weights therefore need not coincide with those of [3]; the shared ingredients are ZmZ_m, its guard factors, and the following first-error proof.

Lemma 4.1 (Witness invariant).

∀v∈CM,WM(v)≠0⟺v∈LM.\forall v \in C_M,\qquad W_M(v) \ne0 \Longleftrightarrow v \in L_M.

Proof. On a legal prefix, increments preserve the weight, positive choices multiply it by a positive integer, and zero choices multiply it by Zm(0)≠0Z_m(0) \ne0. Thus all legal prefixes have nonzero weight. If a prefix is illegal, consider its first erroneous choice. All earlier choices were legal, so the current tested counter lies in [0,m][0,m]. A false zero choice has 1≤c≤m1 \le c \le m and contributes Zm(c)=0Z_m(c) = 0. A false positive choice has c=0c = 0 and contributes zero. Subsequent updates only multiply the weight or leave it unchanged, so it remains zero, regardless of any later negative virtual counters.

Lemma 4.2 (Control correspondence).

M↓⟺∃v∈CM [pc⁡M(v)∉IM∧WM(v)≠0].M\downarrow\Longleftrightarrow\exists v \in C_M\ [\operatorname{pc}_M(v) \notin I_M \land W_M(v) \ne0].

Proof. Given a machine execution, choose its actual guard at each test and either label at an increment. Induction on its length identifies the candidate program counter and virtual counters with the source configuration; Lemma 4.1 gives nonzero weight. A source halt therefore supplies the required candidate. Conversely, nonzero weight makes every choice legal. Starting from natural counters zero, induction on the candidate steps shows that an increment is the source increment, a zero choice is its zero case, and a positive choice subtracts one from a positive natural counter and takes its jump. The final out-of-range control position has no source successor, so this candidate is a halting source execution.

The compiler and its correctness

The first compiler stage inserts fixed rule templates into a table indexed by the source instructions. These rules implement the arithmetic and control updates over Σ0\Sigma_0 described in Section 2. The final pass in Section 5.6 realizes the constructors over Σ2\Sigma_2. Every rule has an applicative ground body. Tuples, primed terms, and side selection below are textual abbreviations expanded before the rules are emitted.

Arithmetic rules and polynomial updates

For a natural pair C=(u,v)C = (u,v) write val⁡(C)=u−v∈Z\operatorname{val}(C) = u-v \in\mathbb{Z}, and put

inc⁡(u,v)=(u+1,v),dec⁡(u,v)=(u,v+1),\operatorname{inc}(u,v) = (u+1,v),\qquad\operatorname{dec}(u,v) = (u,v+1),
(u,v)⊗(r,s)=(ur+vs,us+vr).(u,v) \otimes(r,s) = (ur+vs,us+vr).

Thus val⁡(inc⁡C)=val⁡(C)+1\operatorname{val}(\operatorname{inc} C) = \operatorname{val}(C) + 1, val⁡(dec⁡C)=val⁡(C)−1\operatorname{val}(\operatorname{dec} C) = \operatorname{val}(C) - 1, and val⁡(C⊗D)=val⁡(C)val⁡(D)\operatorname{val}(C \otimes D) = \operatorname{val}(C)\operatorname{val}(D). All components remain natural numbers, including on illegal candidates.

Set C=o→oC = o \to o, N=C→CN = C \to C, and P=N→N→NP = N \to N \to N. The numerical rules are

Zero⁡ f x→x,One⁡ f x→f x,Succ⁡ n f x→f (n f x),Add⁡ m n f x→m f (n f x),Mul⁡ m n f x→m (n f) x,Pos⁡ u v r s f x→Add⁡ (Mul⁡ u r) (Mul⁡ v s) f x,Neg⁡ u v r s f x→Add⁡ (Mul⁡ u s) (Mul⁡ v r) f x.\begin{aligned} \operatorname{Zero}\ f\ x &\to x,\\ \operatorname{One}\ f\ x &\to f\ x,\\ \operatorname{Succ}\ n\ f\ x &\to f\ (n\ f\ x),\\ \operatorname{Add}\ m\ n\ f\ x &\to m\ f\ (n\ f\ x),\\ \operatorname{Mul}\ m\ n\ f\ x &\to m\ (n\ f)\ x,\\ \operatorname{Pos}\ u\ v\ r\ s\ f\ x &\to\operatorname{Add}\ (\operatorname{Mul}\ u\ r)\ (\operatorname{Mul}\ v\ s)\ f\ x,\\ \operatorname{Neg}\ u\ v\ r\ s\ f\ x &\to\operatorname{Add}\ (\operatorname{Mul}\ u\ s)\ (\operatorname{Mul}\ v\ r)\ f\ x. \end{aligned}

Here f:Cf : \mathrm{C} and x:ox : o; every right-hand side has type oo. Juxtaposition is left-associative. Define a pair of natural-valued functions Cm=(Pm+,Pm−)C_m = (P_m^{+}, P_m^{-}) by

C0(u,v)=(1,0),Cm+1(u,v)=(u,v+1)⊗Cm(u,v+1).(14)C_0(u,v) = (1,0), \qquad C_{m+1}(u,v) = (u,v+1) \otimes C_m(u,v+1). \tag*{(14)}

Induction on mm gives

∀u,v∈N,Pm+(u,v)−Pm−(u,v)=Zm(u−v).(15)\forall u,v \in\mathbb{N}, \qquad P_m^{+}(u,v) - P_m^{-}(u,v) = Z_m(u-v). \tag*{(15)}

The successor difference is (u−v−1)Zm(u−v−1)=Zm+1(u−v)(u-v-1)Z_m(u-v-1) = Z_{m+1}(u-v), using

Zm+1(x)=(x−1)Zm(x−1).(16)Z_{m+1}(x) = (x-1)Z_m(x-1). \tag*{(16)}

This identity holds for all integers xx, not only legal counter values. The seed nonterminals have type P\mathrm{P} and rules Seed+ u v f x→One f x\mathrm{Seed}_{+}\ u\ v\ f\ x \to\mathrm{One}\ f\ x and Seed− u v f x→Zero f x\mathrm{Seed}_{-}\ u\ v\ f\ x \to\mathrm{Zero}\ f\ x. The update nonterminals have type P→P→P\mathrm{P} \to\mathrm{P} \to\mathrm{P}:

Next+ p q u v f x→Pos u (Succ v)(p u (Succ v)) (q u (Succ v)) f x,Next− p q u v f x→Neg u (Succ v)(p u (Succ v)) (q u (Succ v)) f x.(17)\begin{aligned} \mathrm{Next}_{+}\ p\ q\ u\ v\ f\ x &\to\mathrm{Pos}\ u\ (\mathrm{Succ}\ v) \\ &\quad(p\ u\ (\mathrm{Succ}\ v))\ (q\ u\ (\mathrm{Succ}\ v))\ f\ x, \\ \mathrm{Next}_{-}\ p\ q\ u\ v\ f\ x &\to\mathrm{Neg}\ u\ (\mathrm{Succ}\ v) \\ &\quad(p\ u\ (\mathrm{Succ}\ v))\ (q\ u\ (\mathrm{Succ}\ v))\ f\ x. \tag*{(17)} \end{aligned}

Here p,q:Pp,q : \mathrm{P}, u,v:Nu,v : \mathrm{N}, f:Cf : \mathrm{C}, and x:ox : o. The right-hand sides have type oo. Each occurrence of pp or qq is an ordinary application to two numeral terms.

Compiling the control flow

Fix a side ⋄∈{L,R}\diamond\in\{L,R\}. Figure 3 gives a control-rule template for each source instruction. At position ii, M(i)M(i) selects the rule defining FiF_i. These selected rules form Rctrl(M)R_{\mathrm{ctrl}}(M). The program translation ⟦M⟧\llbracket M \rrbracket assembles them with the arithmetic library of § 5.1 and the halt, padding, and start rules to obtain GMG_M. All abbreviations are expanded before the rules are emitted.

Compilation of source control flow into the intermediate HORS

Figure 3. Compilation of source control flow into the intermediate HORS GM⋄=⟦M⟧⋄G_M^{\diamond}=\llbracket M\rrbracket^{\diamond}. Narith,Rarith\mathcal{N}_{\mathrm{arith}},\mathcal{R}_{\mathrm{arith}} are the arithmetic nonterminals and rules of Section 5.1. The first four templates select one rule per i∈IMi\in I_M by the right-hand conditions, forming Rctrl(M)\mathcal{R}_{\mathrm{ctrl}}(M); the last three rules form Raux⋄\mathcal{R}^{\diamond}_{\mathrm{aux}}. Primed terms, t⃗\vec{t}, and w⋄w_{\diamond} are textual abbreviations expanded before the rules are emitted.

Each source position contributes one rule. The common root bb has observation child zz and continuation children 1, 2. An increment duplicates its successor call. A decrement test generates both guesses: child 1 keeps the selected counter and advances to the next instruction; child 2 increments its negative component and jumps to the specified position.

Every continuation receives p′,q′p',q', so the polynomial advances on every instruction. The zero guess multiplies the weight by the old polynomial evaluated at the old counter pair. The positive guess uses the old counter pair as its multiplier, before the negative component is incremented. These simultaneous updates are explicit in the four control-rule templates.

Normalization sends every out-of-range position to 0, represented by F0F_0. The choice wL=hw_L = h, wR=kw_R = k is fixed by the output side: the two halt observations are h a zh\ a\ z and k a zk\ a\ z, and both use K for their continuation children. Only this halt rule differs between the two schemes. The start rule supplies the polynomial seeds, zero counter components, and weight components (One, Zero).

Rule context and shared abbreviations

L=∣M∣,t⃗=(p,q,u,v,r,s,h,k),p,q:P,u,v,r,s,h,k:N,L = |M|,\qquad\vec{t} = (p,q,u,v,r,s,h,k),\qquad p,q:\mathsf{P},\qquad u,v,r,s,h,k:\mathsf{N},
p′=Next⁡+ p q,q′=Next⁡− p q,ȷ^={j,j∈IM,0,j∉IM,wL=h,wR=k.p' = \operatorname{Next}_{+}\,p\,q,\qquad q' = \operatorname{Next}_{-}\,p\,q,\qquad\hat{\jmath} = \begin{cases} j, & j \in I_M,\\ 0, & j \notin I_M, \end{cases} \qquad w_L = h,\qquad w_R = k.

Control, halt, padding, and start rules ⋄∈{L,R}\diamond\in\{L,R\}.

Fi p q u v r s h k→b z (Fi+1 p′ q′ (Succ⁡ u) v r s h k)F_i\,p\,q\,u\,v\,r\,s\,h\,k \to b\,z\,(F_{i+1}\,p'\,q'\,(\operatorname{Succ}\,u)\,v\,r\,s\,h\,k)
(Fi+1 p′ q′ (Succ⁡ u) v r s h k)M(i)=inc⁡A(F_{i+1}\,p'\,q'\,(\operatorname{Succ}\,u)\,v\,r\,s\,h\,k) \qquad M(i)=\operatorname{inc}_A
Fi p q u v r s h k→b z (Fi+1 p′ q′ u v (Succ⁡ r) s h k)F_i\,p\,q\,u\,v\,r\,s\,h\,k \to b\,z\,(F_{i+1}\,p'\,q'\,u\,v\,(\operatorname{Succ}\,r)\,s\,h\,k)
(Fi+1 p′ q′ u v (Succ⁡ r) s h k)M(i)=inc⁡B(F_{i+1}\,p'\,q'\,u\,v\,(\operatorname{Succ}\,r)\,s\,h\,k) \qquad M(i)=\operatorname{inc}_B
Fi p q u v r s h k→b z (Fi+1 p′ q′ u v r sF_i\,p\,q\,u\,v\,r\,s\,h\,k \to b\,z\,(F_{i+1}\,p'\,q'\,u\,v\,r\,s
(Pos⁡ h k (p u v) (q u v))(\operatorname{Pos}\,h\,k\,(p\,u\,v)\,(q\,u\,v))
(Neg⁡ h k (p u v) (q u v)))(\operatorname{Neg}\,h\,k\,(p\,u\,v)\,(q\,u\,v)))
(Fȷ^ p′ q′ u (Succ⁡ v) r s(F_{\hat{\jmath}}\,p'\,q'\,u\,(\operatorname{Succ}\,v)\,r\,s
(Pos⁡ h k u v) (Neg⁡ h k u v))M(i)=dec⁡A(j)(\operatorname{Pos}\,h\,k\,u\,v)\,(\operatorname{Neg}\,h\,k\,u\,v)) \qquad M(i)=\operatorname{dec}_A(j)
Fi p q u v r s h k→b z (Fi+1 p′ q′ u v r sF_i\,p\,q\,u\,v\,r\,s\,h\,k \to b\,z\,(F_{i+1}\,p'\,q'\,u\,v\,r\,s
(Pos⁡ h k (p r s) (q r s))(\operatorname{Pos}\,h\,k\,(p\,r\,s)\,(q\,r\,s))
(Neg⁡ h k (p r s) (q r s)))(\operatorname{Neg}\,h\,k\,(p\,r\,s)\,(q\,r\,s)))
(Fȷ^ p′ q′ u v r (Succ⁡ s)(F_{\hat{\jmath}}\,p'\,q'\,u\,v\,r\,(\operatorname{Succ}\,s)
(Pos⁡ h k r s) (Neg⁡ h k r s))M(i)=dec⁡B(j)(\operatorname{Pos}\,h\,k\,r\,s)\,(\operatorname{Neg}\,h\,k\,r\,s)) \qquad M(i)=\operatorname{dec}_B(j)
F0 p q u v r s h k→b (w⋄ a z) K KF_0\,p\,q\,u\,v\,r\,s\,h\,k \to b\,(w_{\diamond}\,a\,z)\,K\,K
K→b z K KK \to b\,z\,K\,K
S→F1 Seed⁡+ Seed⁡−S \to F_1\,\operatorname{Seed}_{+}\,\operatorname{Seed}_{-}
Zero⁡ Zero⁡ Zero⁡ Zero⁡ One⁡ Zero⁡.\operatorname{Zero}\ \operatorname{Zero}\ \operatorname{Zero}\ \operatorname{Zero}\ \operatorname{One}\ \operatorname{Zero}.

Scheme assembly ⋄∈{L,R}\diamond\in\{L,R\}.

⟦M⟧⋄=(Σ0,NM,RM⋄,S),\llbracket M\rrbracket^{\diamond} = (\Sigma_0,\mathcal{N}_M,\mathcal{R}^{\diamond}_M,S),
NM=Narith∪{S:o,K:o}∪{Fi:P→P→N6→o∣0≤i≤L},\mathcal{N}_M = \mathcal{N}_{\mathrm{arith}} \cup\{S:o,K:o\} \cup\{F_i:\mathsf{P}\to\mathsf{P}\to\mathsf{N}^{6}\to o \mid0\le i\le L\},
RM⋄=Rarith∪Rctrl(M)∪Raux⋄.\mathcal{R}^{\diamond}_M = \mathcal{R}_{\mathrm{arith}} \cup\mathcal{R}_{\mathrm{ctrl}}(M)\cup\mathcal{R}^{\diamond}_{\mathrm{aux}}.

Well-formedness, order, and safety

The construction contains eleven arithmetic nonterminals, S, K, and the L+1L+1 control nonterminals. The source instruction list selects one control template per state; no source counter or execution is evaluated during compilation.

Lemma 5.1 (Syntactic compilation). The construction produces two finite, closed, well-typed deterministic HORS over Σ0\Sigma_0, of order at most four.

Proof. There are L+1L+1 states and thirteen other nonterminals, each with one rule. All referenced state indices have been normalized into 0,…,L0,\ldots,L. The type audit is

Zero,One:N2Succ:N→N3Add,Mul:N→N→N3Pos,Neg:N4→N3Seed+,Seed−:P3Next+,Next−:P→P→P4Fi:P→P→N6→o4S,K:o0.\begin{aligned} \mathrm{Zero},\mathrm{One} &: \mathrm{N} && 2\\ \mathrm{Succ} &: \mathrm{N}\to\mathrm{N} && 3\\ \mathrm{Add},\mathrm{Mul} &: \mathrm{N}\to\mathrm{N}\to\mathrm{N} && 3\\ \mathrm{Pos},\mathrm{Neg} &: \mathrm{N}^{4}\to\mathrm{N} && 3\\ \mathrm{Seed}_{+},\mathrm{Seed}_{-} &: \mathrm{P} && 3\\ \mathrm{Next}_{+},\mathrm{Next}_{-} &: \mathrm{P}\to\mathrm{P}\to\mathrm{P} && 4\\ F_i &: \mathrm{P}\to\mathrm{P}\to\mathrm{N}^{6}\to o && 4\\ S,K &: o && 0. \end{aligned}

The last column is the order of the whole nonterminal type. For example, in Equation (17), Succ v:N\mathrm{Succ}\ v:\mathrm{N}, p u (Succ v):Np\ u\ (\mathrm{Succ}\ v):\mathrm{N}, and the saturated Pos or Neg application has type oo. In the instruction clauses of Figure 3, p′,q′:Pp',q':\mathrm{P} and every remaining state argument has type N\mathrm{N}, so each continuation has type oo. In its halt clause, h a zh\ a\ z and k a zk\ a\ z have type oo. The numeral parameter context for Add and Mul is m:N,n:N,f:C,x:om:\mathrm{N}, n:\mathrm{N}, f:\mathrm{C}, x:o. For addition, n f x:on\ f\ x:o and m f:Cm\ f:\mathrm{C}, giving a ground body. For multiplication, n f:Cn\ f:\mathrm{C}, m (n f):Cm\ (n\ f):\mathrm{C}, and application to xx again yields oo. For Pos and Neg, each partial multiplication has type N\mathrm{N}; their sum has type N\mathrm{N} before the final f,xf,x applications. The seed rules ignore their first two N\mathrm{N} arguments and apply a numeral of type N\mathrm{N} to f,xf,x. For a polynomial update, the parameter context has two P\mathrm{P} arguments followed by two N\mathrm{N} arguments, ff, and xx. Its two polynomial calls have type N\mathrm{N}, so the component multiplication rule gives the required ground result. □

Lemma 5.2 (Safety of the compiler). For every MM and side ⋄\diamond, the compiled scheme GM⋄G_M^{\diamond} is safe.

Proof. We use the syntactic condition of [8], Definition 1. The types oo, C\mathrm{C}, N\mathrm{N}, P\mathrm{P} are homogeneous, of orders 0,1,2,30,1,2,3. Every arithmetic type in the preceding audit expands to Pr→Ns→C→o→o\mathrm{P}^{r}\to\mathrm{N}^{s}\to\mathrm{C}\to o\to o for some r,s∈Nr,s\in\mathbb{N}. Its parameter orders are therefore nonincreasing. The same holds for the state type P2→N6→o\mathrm{P}^{2}\to\mathrm{N}^{6}\to o, the ground types of S, K, and terminal types with only ground arguments. Every subterm type is a codomain suffix of the type of its head symbol, which is a parameter, nonterminal, or terminal. Those suffixes remain homogeneous.

The table lists every family of compound nonground operands after expansion of the rule abbreviations, up to renaming parameters of the same type. Here p,q:Pp,q:\mathrm{P}, u,v,h,k,n:Nu,v,h,k,n:\mathrm{N}, and f:Cf:\mathrm{C}. Each Pos row also covers the corresponding Neg term. The last column gives the set of orders of parameters occurring in the operand. The same numeric families cover the BB-counter parameters rr, ss. Ground operands impose only a lower bound of zero. A single parameter has exactly its own order, and a closed operand has no parameters. The start rule uses closed seeds and numerals. Halt observations and padding add only ground operands, the closed terminal aa, and K. This checks the condition at every application node in every rule.

Operand ssord⁡(s)\operatorname{ord}(s)Parameter orders
Next±_{\pm} p qp\ q3{3}\{3\}
Succ uu, Mul u vu\ v2{2}\{2\}
p u vp\ u\ v, q u vq\ u\ v2{2,3}\{2,3\}
p u (Succ⁡ v)p\ u\ (\operatorname{Succ}\ v), q u (Succ⁡ v)q\ u\ (\operatorname{Succ}\ v)2{2,3}\{2,3\}
Pos h k u vh\ k\ u\ v2{2}\{2\}
Pos h k (p u v) (q u v)h\ k\ (p\ u\ v)\ (q\ u\ v)2{2,3}\{2,3\}
n fn\ f1{1,2}\{1,2\}

Table 1.

For example, in p u (Succ⁡ v)p\ u\ (\operatorname{Succ}\ v) the prefix p up\ u has order three and contains the order-two parameter uu. It is the function child of the outer application, so it has no operand inequality of its own. The whole polynomial application has order two, and its uses as an operand are safe. Applying the inequality to every application prefix would impose a different restriction. □

A representation invariant that supports application

Multiplication reuses a numeral at a functional argument of the form n fn\ f. Correctness only at the observation arguments aa, zz would leave this application unproved. We therefore require correctness at every represented function and ground argument.

Fix one compiled scheme GG. Let VoV_o be the set of partial observation maps T:N∗⇀Σ0T : \mathbb{N}^{*} \rightharpoonup\Sigma_0, writing T(w)=†T(w) = \dagger for w∉dom⁡(T)w \notin\operatorname{dom}(T). These maps record terminal observations only. We allow arbitrary partial maps here; Section 5.5 shows that the constructed output maps satisfy the rank conditions and define productive trees. Set Vσ→τ=VτVσV_{\sigma\to\tau} = V_\tau^{V_\sigma}. For a closed term t:σt : \sigma and V∈VσV \in V_\sigma, define a logical relation by

t⊩oT⟺∀w,a [Obs⁡G(t,w,a)⟺T(w)=a],t \mathrel{\Vdash_o} T \Longleftrightarrow\forall w,a\ [\operatorname{Obs}_G(t,w,a) \Longleftrightarrow T(w)=a],
t⊩σ→τF⟺∀u,U [u⊩σU⟹t u⊩τF(U)].(18)t \mathrel{\Vdash_{\sigma\to\tau}} F \Longleftrightarrow\forall u,U\ [u \mathrel{\Vdash_\sigma} U \Longrightarrow t\ u \mathrel{\Vdash_\tau} F(U)]. \tag*{(18)}

In the second line uu ranges over closed terms of type σ\sigma. Ground realization is preserved when a head unfolding is performed in reverse: if t→ht′t \to_h t' and t′⊩oTt' \mathrel{\Vdash_o} T, then t⊩oTt \mathrel{\Vdash_o} T, by determinism and the definition of observations.

For any closed t:Nt : \mathbb{N} and n∈Nn \in\mathbb{N}, define Num⁡(t,n)\operatorname{Num}(t,n) to mean t⊩N(λf X. fn(X))t \mathrel{\Vdash_\mathbb{N}} (\lambda f\ X.\ f^n(X)). The term tt may contain nonterminals and partial applications, such as Succ Zero; its numerical behavior is specified under further application. The observation t a zt\ a\ z is one instance of this requirement.

Lemma 5.3 (Church arithmetic). Num⁡(Zero⁡,0)\operatorname{Num}(\operatorname{Zero},0) and Num⁡(One⁡,1)\operatorname{Num}(\operatorname{One},1) hold. If Num⁡(t,m)\operatorname{Num}(t,m) and Num⁡(u,n)\operatorname{Num}(u,n), then

Num⁡(Succ⁡ t,m+1),Num⁡(Add⁡ t u,m+n),Num⁡(Mul⁡ t u,mn).\operatorname{Num}(\operatorname{Succ}\ t,m+1),\qquad\operatorname{Num}(\operatorname{Add}\ t\ u,m+n),\qquad\operatorname{Num}(\operatorname{Mul}\ t\ u,mn).

For closed terms t1,t2,t3,t4:Nt_1,t_2,t_3,t_4 : \mathbb{N} and α,β,γ,δ∈N\alpha,\beta,\gamma,\delta\in\mathbb{N}, if

Num⁡(t1,α)∧Num⁡(t2,β)∧Num⁡(t3,γ)∧Num⁡(t4,δ),\operatorname{Num}(t_1,\alpha)\land\operatorname{Num}(t_2,\beta)\land\operatorname{Num}(t_3,\gamma)\land\operatorname{Num}(t_4,\delta),

then

Num⁡(Pos⁡ t1 t2 t3 t4,αγ+βδ),\operatorname{Num}(\operatorname{Pos}\ t_1\ t_2\ t_3\ t_4,\alpha\gamma+\beta\delta),
Num⁡(Neg⁡ t1 t2 t3 t4,αδ+βγ).\operatorname{Num}(\operatorname{Neg}\ t_1\ t_2\ t_3\ t_4,\alpha\delta+\beta\gamma).

The two represented numbers are the coordinates of the signed-pair product (α,β)⊗(γ,δ)(\alpha,\beta)\otimes(\gamma,\delta). Moreover, Num⁡(t,n)\operatorname{Num}(t,n) implies t a z⊩oanzt\ a\ z \mathrel{\Vdash_o} a^n z.

Proof. Use the arithmetic rules of Section 5.1 with arbitrary related arguments f⊩CFf \mathrel{\Vdash_{\mathrm C}} F and x⊩oXx \mathrel{\Vdash_{\mathrm o}} X. The zero and one rules return xx and f xf\,x; the successor rule returns f(t f x)f(t\,f\,x), realizing Fm+1(X)F^{m+1}(X). For addition the body t f (u f x)t\,f\,(u\,f\,x) realizes Fm(Fn(X))=Fm+n(X)F^{m}(F^{n}(X)) = F^{m+n}(X). For multiplication, Equation (18) first gives u f⊩CFnu\,f \mathrel{\Vdash_{\mathrm C}} F^{n}. Applying the realization of tt to this functional argument and then to xx shows that t (u f) xt\,(u\,f)\,x realizes (Fn)m(X)=Fmn(X)(F^{n})^{m}(X) = F^{mn}(X). One head unfolding of each saturated arithmetic call gives the corresponding conclusion. For Pos, multiplication gives numerals for αγ\alpha\gamma and βδ\beta\delta, and addition gives αγ+βδ\alpha\gamma+ \beta\delta. The Neg rule similarly uses αδ\alpha\delta and βγ\beta\gamma. Finally, the terminal aa realizes the unary constructor on observation maps and zz realizes the one-node tree, giving the observation claim; Equation (24) below defines these constructor maps explicitly. □

To verify the polynomial update, we relate the stored HORS terms to the mathematical functions Pm+,Pm−P_m^{+}, P_m^{-}. For closed p,q:Pp,q : \mathrm P, the representation predicate Pol⁡m(p,q)\operatorname{Pol}_m(p,q) requires that their applications to any numeral representations of u,vu,v represent the corresponding function values. Here t,st,s range over closed N-terms:

Pol⁡m(p,q)⟺∀u,v∈N ∀t,s:N,(Num⁡(t,u)∧Num⁡(s,v))⇒(Num⁡(p t s,Pm+(u,v))∧Num⁡(q t s,Pm−(u,v))).(19)\operatorname{Pol}_m(p,q) \Longleftrightarrow\forall u,v \in\mathbb{N}\ \forall t,s:\mathsf{N},\quad \begin{aligned} &(\operatorname{Num}(t,u) \land\operatorname{Num}(s,v)) \Rightarrow\\ &(\operatorname{Num}(p\,t\,s,P_m^{+}(u,v)) \land\operatorname{Num}(q\,t\,s,P_m^{-}(u,v))). \end{aligned} \tag*{(19)}

The index mm specifies the polynomial after mm candidate steps. The next lemma shows that the two Next applications preserve this relation at step m+1m+1.

Lemma 5.4 (Polynomial realization). The seeds satisfy Pol⁡0(Seed⁡+,Seed⁡−)\operatorname{Pol}_0(\operatorname{Seed}_+,\operatorname{Seed}_-). The update property is

Pol⁡m(p,q)⟹Pol⁡m+1(Next⁡+ p q,Next⁡− p q).\operatorname{Pol}_m(p,q) \Longrightarrow\operatorname{Pol}_{m+1}(\operatorname{Next}_+\,p\,q,\operatorname{Next}_-\,p\,q).

Proof. The seed rules reduce to one and zero on their last two arguments. For the step, let t,st,s represent u,vu,v. By Lemma 5.3, Succ ss represents v+1v+1, so the hypothesis applies to p t (Succ⁡ s)p\,t\,(\operatorname{Succ}\,s) and q t (Succ⁡ s)q\,t\,(\operatorname{Succ}\,s). The two rules in Equation (17) and the Pos/Neg clauses of Lemma 5.3 therefore give exactly the two components of (u,v+1)⊗Cm(u,v+1)(u,v+1)\otimes C_m(u,v+1) in Equation (14). This argument applies to all u,vu,v, including u<vu<v. □

We combine the polynomial and numeral relations into an invariant for a complete state call. Let t⃗=(p,q,u,v,r,s,h,k)\vec{t}=(p,q,u,v,r,s,h,k) be its closed argument tuple, with p,q:Pp,q:\mathrm P and u,v,r,s,h,k:Nu,v,r,s,h,k:\mathsf N. For natural-number pairs A=(A+,A−)A=(A^{+},A^{-}), B=(B+,B−)B=(B^{+},B^{-}), and W=(W+,W−)W=(W^{+},W^{-}), define

Reg⁡m(t⃗;A,B,W)⟺Pol⁡m(p,q)∧Num⁡(u,A+)∧Num⁡(v,A−)∧Num⁡(r,B+)∧Num⁡(s,B−)∧Num⁡(h,W+)∧Num⁡(k,W−).(20)\operatorname{Reg}_m(\vec{t};A,B,W) \Longleftrightarrow\operatorname{Pol}_m(p,q) \begin{aligned} &\land\operatorname{Num}(u,A^{+}) \land\operatorname{Num}(v,A^{-})\\ &\land\operatorname{Num}(r,B^{+}) \land\operatorname{Num}(s,B^{-})\\ &\land\operatorname{Num}(h,W^{+}) \land\operatorname{Num}(k,W^{-}). \end{aligned} \tag*{(20)}

This relates every stored component to its mathematical value; the signed counter and weight values are val⁡(A)\operatorname{val}(A), val⁡(B)\operatorname{val}(B), val⁡(W)\operatorname{val}(W). The initial terms in Figure 3 represent A=B=(0,0)A=B=(0,0) and W=(1,0)W=(1,0). For the current instruction ι\iota on counter XX and choice ee, update the selected counter pair CC and the weight pair simultaneously:

(C′,W′)={(inc⁡C,W),ι=inc⁡X,(C,W⊗Cm(C)),ι=dec⁡X(j)∧e=1,(dec⁡C,W⊗C),ι=dec⁡X(j)∧e=2.(21)(C',W') = \begin{cases} (\operatorname{inc} C,W), & \iota=\operatorname{inc}_X,\\ (C,W\otimes C_m(C)), & \iota=\operatorname{dec}_X(j)\land e=1,\\ (\operatorname{dec} C,W\otimes C), & \iota=\operatorname{dec}_X(j)\land e=2. \end{cases} \tag*{(21)}

Here Cm(C)=Cm(u,v)C_m(C)=C_m(u,v) for C=(u,v)C=(u,v), and the other counter is unchanged. Taking signed values gives counter changes +1,0,−1+1,0,-1, respectively, and, by Equation (15),

val⁡(W′)=val⁡(W) ϕm(ι,e,val⁡(C)).(22)\operatorname{val}(W')=\operatorname{val}(W)\,\phi_m(\iota,e,\operatorname{val}(C)). \tag*{(22)}

Thus these natural-pair operations realize the integer updates of Equations (2) and (13). The witness invariant identifies legal prefixes through val⁡(W)\operatorname{val}(W). The representation invariant also covers prefixes with val⁡(W)=0\operatorname{val}(W)=0 or negative virtual counters. Every stored component represents a natural number, so arithmetic observations terminate on every generated branch.

Lemma 5.5 (All-candidate invariant). If Reg⁡m(t⃗;A,B,W)\operatorname{Reg}_{m}(\vec{t};A,B,W) holds, each continuation of the corresponding nonhalting state rule satisfies Reg⁡m+1\operatorname{Reg}_{m+1} for its updated natural pairs. Hence every finite candidate prefix has such a representation.

Proof. The polynomial coordinates follow from Lemma 5.4. An increment applies Succ to the positive coordinate; a positive choice applies it to the negative coordinate and uses Pos, Neg on the old weight and old counter. A zero choice first applies Pol⁡m\operatorname{Pol}_{m} to the old counter’s two numeral terms and then uses the two multiplication components. The unchanged coordinates retain their realizations. This proves the step for each counter; induction from the seeds proves the last claim. There is no legality or nonzero-weight hypothesis. □

Operational correspondence, productivity, and disagreement

Let K=b z KK\mathcal{K}=b\,z\,\mathcal{K}\mathcal{K}. For an arbitrary triple R=(A,B,W)∈(N2)3R=(A,B,W)\in(\mathbb{N}^{2})^{3}, write W=(WL,WR)W=(W^{L},W^{R}): WLW^{L} is its first component and WRW^{R} its second. For ⋄∈{L,R}\diamond\in\{L,R\}, define T⋄(m,i,R)T^{\diamond}(m,i,R) by its finite-address observations, or equivalently by the equations

T⋄(m,i,R)={b (aW⋄z) KK,i∉IM,b z T⋄(m+1,i1,R1) T⋄(m+1,i2,R2),i∈IM.(23)T^{\diamond}(m,i,R)= \begin{cases} b\,(a^{W^{\diamond}}z)\,\mathcal{K}\mathcal{K}, & i\notin I_{M},\\ b\,z\,T^{\diamond}(m+1,i_{1},R_{1})\,T^{\diamond}(m+1,i_{2},R_{2}), & i\in I_{M}. \end{cases} \tag*{(23)}

The ie,Rei_{e},R_{e} are the candidate successor and pair update for choice e∈{1,2}e\in\{1,2\}; an increment duplicates its successor. The definition is well founded when evaluated at a finite address, since a recursive call consumes one address symbol. Every required finite node is present: the root is bb, observation children are finite chains, and continuation children satisfy the same equations or are K\mathcal{K}.

Every address is either ϵ\epsilon or iviv, with i∈Ni\in\mathbb{N} and v∈N∗v\in\mathbb{N}^{*}. The three constructors act on observation maps by

z(ϵ)=z,z(\epsilon)=z,
(aT)(ϵ)=a,(aT)(0v)=T(v),(aT)(\epsilon)=a,\qquad(aT)(0v)=T(v),
(bT0T1T2)(ϵ)=b,(bT0T1T2)(iv)=Ti(v)(i<3).(24)(bT_{0}T_{1}T_{2})(\epsilon)=b,\qquad(bT_{0}T_{1}T_{2})(iv)=T_{i}(v)\quad(i<3). \tag*{(24)}

All unlisted cases have value †. They realize these functions under ordinary terminal-head exposure. The intermediate semantic domain contains arbitrary observation maps, but the chains and the trees in (23) satisfy the rank conditions. Induction on finite depth establishes their totality. The operational correspondence transfers this totality to the compiled terms under ordinary HORS head rewriting.

Lemma 5.6 (Operational correspondence). If Reg⁡m(t⃗;R)\operatorname{Reg}_{m}(\vec{t};R), then, for every address ww and terminal aa,

Obs⁡GM∘(Fi→t⃗,w,a)⟺T⋄(m,i,R)(w)=a.\operatorname{Obs}_{G^{\circ}_{M}}\left(F^{\to}_{i}\vec{t},w,a\right)\Longleftrightarrow T^{\diamond}(m,i,R)(w)=a.

Proof. First, induction on the address proves that the rule for K\mathcal{K} realizes K\mathcal{K}. For the state assertion, induct on ww, universally over m,i,t⃗,Rm,i,\vec{t},R. Unfold the state once. At the empty address both sides have root bb. At a child index at least three neither side has an observation. Child zero is zz in a nonhalting state; in a halting state, Lemma 5.3 identifies it with the selected finite chain. At child one or two of a nonhalting state, apply Lemma 5.5 and the induction hypothesis to the shorter address. At a halt these children use the assertion for K\mathcal{K}. Normalization of ii preserves instruction lookup, including halts. □

Exposing bb gives the control node. Productivity also requires its observation child to finish evaluating the selected arithmetic term; Lemmas 5.3 and 5.5 establish its termination.

Lemma 5.7 (Productivity). Both compiled schemes are productive.

Proof. Prove the stronger assertion for every represented state by induction on observation depth. Depth zero is immediate. A state exposes bb after one head unfolding. At child zero, the nonhalting case is zz, and the halting case realizes a finite chain by Lemma 5.3; a chain produces every required node to the remaining depth. The continuation children satisfy the induction hypothesis with the updated invariant, or use K, whose depth productivity follows from its rule by the same induction. Apply this assertion to the initial representation and the start rule. This proves productivity even on illegal candidate paths and when the signed weight is zero. □

Theorem 5.8 (Intermediate compilation). The construction M↦(GML,GMR)M \mapsto(G^L_M,G^R_M) is effective and produces well-formed safe productive schemes of order at most four over Σ0\Sigma_0. Moreover, writing S for the start symbol in each scheme,

M↓⟺∃w∈N∗ ∃a,b∈Σ0 [a≠b∧Obs⁡GML(S,w,a)∧Obs⁡GMR(S,w,b)].M\mathord{\downarrow}\Longleftrightarrow\exists w\in\mathbb{N}^{*}\ \exists a,b\in\Sigma_0\ [a\ne b\land\operatorname{Obs}^{G^L_M}(S,w,a)\land\operatorname{Obs}^{G^R_M}(S,w,b)].

Proof. The static and productivity claims are Lemmas 5.1, 5.2 and 5.7. The compiler traverses the finite instruction list and inserts the displayed fixed templates, so it is total computable.

A candidate prefix of length mm determines an address v∈{1,2}mv\in\{1,2\}^{m}, ending at its state in Equation (23). This follows by induction on the prefix, using the chosen continuation child at each step; all preceding states are nonhalting. A legal halt gives weight components r≠sr\ne s, by Lemma 4.2 and val⁡(W)=r−s\operatorname{val}(W)=r-s. The two trees therefore differ at

v00min⁡(r,s).(25)v00^{\min(r,s)}. \tag*{(25)}

One chain ends with zz there, while the other still has label aa. By Lemma 5.6, the compiled HORS have this observation.

Conversely, consider any common address with different terminal labels. As long as the address follows children one or two, both roots are bb and both computations have the same candidate control and pair data. If such a path enters padding after a halt, the two subtrees coincide. An out-of-range child cannot give a common observation. Consequently a discrepancy must select child zero of a genuine candidate state. At a nonhalting state both observation subtrees are zz. At a halt they are arza^r z and asza^s z, whose only possible label mismatch at a common address occurs at suffix 0min⁡(r,s)0^{\min(r,s)}, with r≠sr\ne s. Thus the candidate halt has nonzero weight and is a legal source halt by Lemma 4.2.

Finally, two unequal productive ranked trees have different labels at some address present in both trees: choose a shortest address of disagreement. Its proper ancestors agree, and their labels determine their child arities, so both nodes at that address exist. This also proves the intermediate equivalence

M↑⟺BT⁡(GML)=BT⁡(GMR).M\mathord{\uparrow}\Longleftrightarrow\operatorname{BT}(G^L_M)=\operatorname{BT}(G^R_M).

□

The two-terminal target

The final pass replaces the intermediate constructors by fixed contexts over Σ2\Sigma_2. Define

E(z)=e,E(at)=d(e,E(t)),E(b(t0,t1,t2))=d(d(e,e),d(E(t0),d(E(t1),E(t2)))).(26)\begin{aligned} E(z)&=e,\\ E(at)&=d(e,E(t)),\\ E(b(t_0,t_1,t_2))&=d(d(e,e),d(E(t_0),d(E(t_1),E(t_2)))). \tag*{(26)} \end{aligned}

These guarded equations define EE on finite and infinite Σ0\Sigma_0-trees.

Lemma 5.9 (Binary output encoding). Every productive HORS GG over Σ0\Sigma_0 can be effectively translated to a productive HORS GEG^{E} over Σ2\Sigma_2 such that

ord⁡(GE)≤max⁡{1,ord⁡(G)},BT⁡(GE)=E(BT⁡(G)).\operatorname{ord}(G^{E}) \le\max\{1,\operatorname{ord}(G)\}, \qquad\operatorname{BT}(G^{E}) = E(\operatorname{BT}(G)).

If GG is safe, then GEG^{E} is safe. For any productive HORS GG, HH over Σ0\Sigma_0,

BT⁡(GE)=BT⁡(HE)⟺BT⁡(G)=BT⁡(H).\operatorname{BT}(G^{E}) = \operatorname{BT}(H^{E}) \Longleftrightarrow\operatorname{BT}(G) = \operatorname{BT}(H).

Proof. The root label distinguishes zz from a,ba,b; in the latter case, the left child’s label distinguishes aa from bb. The encoded child of aa occurs at address 1, and the encoded children of bb occur at 10, 110, 111. Decoding along finite addresses therefore gives

E(T)=E(U)⟺T=U.E(T) = E(U) \Longleftrightarrow T = U.

For a scheme GG, rename its nonterminals to reserve three fresh names, then replace its terminals zz, aa, bb by Z:oZ:o, A:o→oA:o\to o, and B:o3→oB:o^3\to o, with rules

Z→e,A x→d e x,B x0x1x2→d (d e e) (d x0 (d x1 x2)).\begin{aligned} Z &\to e,\\ A\ x &\to d\ e\ x,\\ B\ x_0x_1x_2 &\to d\ (d\ e\ e)\ (d\ x_0\ (d\ x_1\ x_2)). \end{aligned}

Call the result GEG^{E}. The replacements have the original terminal types, so all old subterm types and parameter occurrences are preserved. The new helpers have order at most one, giving the claimed order bound. Their types are homogeneous, and every operand containing a parameter has ground type. Thus safety is preserved. The translation commutes with substitution. Each exposed source constructor is implemented by one helper unfolding and a finite terminal context, giving BT⁡(GE)=E(BT⁡(G))\operatorname{BT}(G^{E}) = E(\operatorname{BT}(G)). Every finite target observation visits finitely many source nodes and context nodes, so productivity is preserved. Injectivity of EE now gives both directions of equivalence preservation. □

Set G^M⋄=(GM⋄)E\widehat{G}_{M}^{\diamond} = (G_{M}^{\diamond})^{E} for ⋄∈{L,R}\diamond\in\{L,R\}. By Theorem 5.8 and Lemma 5.9, these are safe, productive HORS of order at most four over Σ2\Sigma_2, and

M↑⟺BT⁡(GML)=BT⁡(GMR)⟺BT⁡(G^ML)=BT⁡(G^MR).M \mathord{\uparrow} \Longleftrightarrow\operatorname{BT}(G_{M}^{L}) = \operatorname{BT}(G_{M}^{R}) \Longleftrightarrow\operatorname{BT}(\widehat{G}_{M}^{L}) = \operatorname{BT}(\widehat{G}_{M}^{R}).

Both passes are total syntax transformations. Extend the compiler to natural-number codes by mapping malformed source codes, which are excluded from the halting set, to two copies of S→eS\to e over Σ2\Sigma_2. This establishes the total computable reduction in (1). The reduction from the halting complement yields Π10\Pi^0_1-hardness for Eq4,Σ2safe,prod\mathrm{Eq}_{4,\Sigma_2}^{\mathrm{safe,prod}}, and for the classes obtained by omitting safety, productivity, or the order restriction. The matching upper bound is proved next.

Π10\Pi^0_1-completeness

Jochems provides an effective ⊥\bot-elimination transform that replaces every ⊥\bot node by an infinite chain of a fresh terminal, preserving and reflecting tree equality [9 Lemma 2.7 and Proposition 2.8]. Its outputs are productive, so enumerating their finite prefixes semidecides inequality and yields the general co-c.e. upper bound.

Here we give a direct proof using finite monotone semantics for head convergence [16 Section 4.1 and Theorem 4.1]. We construct the finite model and prove that it decides whether a closed ground term exposes a terminal. This allows us to compute the original tree’s prefix at any prescribed finite depth, distinguishing terminal labels, ⊥\bot nodes, and absent addresses, even for nonproductive schemes. Equality and productivity are then universal conditions on these computable prefixes. Together with the decidable syntactic restrictions and the lower bound in § 5.6, this establishes the Π10\Pi^0_1-completeness claims of Theorem 1.1.

A finite semantics for head convergence

Our immediate task is to decide whether a closed ground term t:ot : o exposes a terminal after finitely many head steps. This concerns only the current root: a scheme with the rule S→a S\mathrm{S} \to a\,\mathrm{S} exposes aa, although it generates an infinite tree, whereas S→S\mathrm{S} \to\mathrm{S} never exposes a terminal.

We interpret recursive definitions by least fixed points, following the standard domain-theoretic construction [1 Theorem 2.1.19]. We assign each type σ\sigma a finite semantic domain DσD_\sigma. At ground type we retain only convergence information, using

Do={0<1}.D_o = \{0 < 1\}.

The value 11 records head convergence; 00 is the least approximation, providing no convergence guarantee. The order 0<10 < 1 expresses increasing information. Labels and descendants are forgotten: zz and a za\,z both have value 11, as does a ua\,u even when uu diverges.

For a function type, the abstract value describes how argument information determines result information. Define Dσ→τD_{\sigma\to\tau} to consist of all monotone maps Dσ→DτD_\sigma\to D_\tau, ordered pointwise. Monotonicity ensures that increasing argument information cannot decrease result information. For example,

Do→o={d↦0, d↦d, d↦1}.D_{o \to o} = \{d \mapsto0,\ d \mapsto d,\ d \mapsto1\}.

These describe, respectively, an always-divergent result, returning the argument, and an always-convergent head such as a fixed terminal. Each domain is finite by induction on types, since there are only finitely many maps between finite sets. Its least element is ⊥o=0\bot_o = 0 at ground type and the constant-⊥τ\bot_\tau map at type σ→τ\sigma\to\tau.

Let F:τFF : \tau_F range over the input scheme GG’s finite list of nonterminals, each with its given rule F x1⋯xk→tFF\,x_1 \cdots x_k \to t_F. A global environment η\eta assigns a current approximation η(F)∈DτF\eta(F) \in D_{\tau_F} to every such symbol. All these environments form the finite poset EG=∏F:τFDτFE_G = \prod_{F:\tau_F} D_{\tau_F}, ordered pointwise.

The parameters of a rule receive values locally. For a rule with xi:σix_i : \sigma_i and each tuple of abstract arguments v⃗∈Dσ1×⋯×Dσk\vec{v} \in D_{\sigma_1} \times\cdots\times D_{\sigma_k}, form

ρv⃗=[x1↦v1,…,xk↦vk].\rho_{\vec{v}} = [x_1 \mapsto v_1, \ldots, x_k \mapsto v_k].

A rule without parameters uses the empty local environment. For given global and local environments, define the term denotation ⟦t⟧η,ρ\llbracket t \rrbracket_{\eta,\rho} recursively by

⟦x⟧η,ρ=ρ(x),⟦F⟧η,ρ=η(F),⟦a⟧η,ρ=λd1⋯dr. 1(a:or→o),⟦t u⟧η,ρ=⟦t⟧η,ρ(⟦u⟧η,ρ).(27)\begin{aligned} \llbracket x \rrbracket_{\eta,\rho} &= \rho(x),\\ \llbracket F \rrbracket_{\eta,\rho} &= \eta(F),\\ \llbracket a \rrbracket_{\eta,\rho} &= \lambda d_1 \cdots d_r .\,1 \qquad(a : o^r \to o),\\ \llbracket t\,u \rrbracket_{\eta,\rho} &= \llbracket t \rrbracket_{\eta,\rho}(\llbracket u \rrbracket_{\eta,\rho}). \tag*{(27)} \end{aligned}

For a nullary terminal the third clause gives 11. For closed terms we omit ρ\rho, since there are no free parameters. Typing induction shows that ⟦t⟧η,ρ∈Dσ\llbracket t \rrbracket_{\eta,\rho} \in D_\sigma whenever t:σt : \sigma. The interpretation is also monotone in both environments. For application, increasing the function and argument values from f,df,d to g,eg,e gives (f≤g∧d≤e)⟹f(d)≤f(e)≤g(e)(f \leq g \mathbin{\land} d \leq e) \Longrightarrow f(d) \leq f(e) \leq g(e): the first inequality uses monotonicity of ff, and the second the pointwise order f≤gf \leq g.

The rules determine a single update of the global environment:

ΦG(η)(F)(v⃗)=⟦tF⟧η,ρv⃗.\Phi_G(\eta)(F)(\vec{v}) = \llbracket t_F \rrbracket_{\eta,\rho_{\vec{v}}}.

Typing and monotonicity make ΦG\Phi_G a monotone endomap of EGE_G. We next compute its least fixed point by finite iteration.

Effective computation of the least fixed point

To compute with this model, represent each domain by a list of distinct elements with decidable order and a least element. At ground type use the list [0,1][0,1] with 0<10 < 1. Given representations of DσD_{\sigma}, DτD_{\tau}, enumerate the ∣Dτ∣∣Dσ∣|D_{\tau}|^{|D_{\sigma}|} function tables and retain exactly those satisfying

∀x,y∈Dσx≤y⇒f(x)≤f(y).\forall x,y \in D_{\sigma}\quad x \le y \mathbin{\Rightarrow} f(x) \le f(y).

This finite test enumerates Dσ→τD_{\sigma\to\tau}. Equality and order are pointwise, application is lookup, and the constant-⊥τ\bot_{\tau} table is least.

To compute ΦG(η)\Phi_G(\eta), enumerate each rule’s abstract argument tuples and evaluate its body by Equation (27); higher-type arguments are finite function tables. Grouping the results by successive arguments constructs the curried table for each nonterminal. Thus the update, equality, and cardinality of the finite product EGE_G are computable.

Use the standard ascending fixed-point iteration of abstract interpretation [4 Section 8]: initialize η0(F)=⊥τF\eta_0(F) = \bot_{\tau_F} for every declared nonterminal and iterate ηn+1=ΦG(ηn)\eta_{n+1} = \Phi_G(\eta_n). Each round updates all entries simultaneously, using the same old environment ηn\eta_n throughout. For example, take S:oS : o and F:o→oF : o \to o with rules S→F zS \to F\,z and F x→xF\,x \to x. For each d∈Dod \in D_o, the local environment is [x↦d][x \mapsto d], so

ΦG(η)(F)(d)=⟦x⟧η,[x↦d]=d,\Phi_G(\eta)(F)(d) = \llbracket x \rrbracket_{\eta,[x\mapsto d]} = d,
ΦG(η)(S)=η(F)(1).\Phi_G(\eta)(S) = \eta(F)(1).

The pair (ηn(S),ηn(F))(\eta_n(S),\eta_n(F)) therefore evolves as

(0,d↦0)⟼(0,d↦d)⟼(1,d↦d)⟼(1,d↦d).(0,d \mapsto0) \longmapsto(0,d \mapsto d) \longmapsto(1,d \mapsto d) \longmapsto(1,d \mapsto d).

The start value stays 0 in the first update, while the function table changes. This shows why an unchanged start value alone cannot justify stopping.

Stop when ηn+1=ηn\eta_{n+1} = \eta_n, comparing all entries of all function tables. Subsequent environments then remain equal. Since η0\eta_0 is least and ΦG\Phi_G is monotone, the sequence is increasing and stabilizes by B=∣EG∣B = |E_G|: the chain cannot contain B+1B+1 distinct environments. Hence one can stop at the first equality or compute exactly BB rounds; write η∗=ηB\eta_* = \eta_B. For any fixed point θ\theta, induction gives ηn≤θ\eta_n \le\theta for every nn, so η∗\eta_* is the least fixed point. This computes ⟦t⟧η∗\llbracket t \rrbracket_{\eta_*} for every closed typed term tt. The next subsection proves that its ground value distinguishes head convergence from divergence.

Adequacy for head convergence

The preceding construction computes ⟦t⟧η∗\llbracket t \rrbracket_{\eta_*}. We now prove that, for a closed ground term, this value is 1 exactly when actual head unfolding exposes a terminal after finitely many steps.

Lemma 6.1 (Head adequacy). For a well-formed scheme and a closed ground term tt,

⟦t⟧η∗=1⟺∃a,u⃗  t⇓Ga(u⃗).\llbracket t \rrbracket_{\eta_*} = 1 \quad\Longleftrightarrow\quad\exists a,\vec{u}\; t \mathrel{\Downarrow_G} a(\vec{u}).

Proof. We first record that substitution preserves typing. Induction on the term proves this: variables take the types of their substituted arguments, constants are unchanged, and application uses the induction hypotheses. Thus head unfolding preserves typing and exposes well-typed children.

(1) Soundness (⇒\Rightarrow). We must show that a semantic value of 1 has a finite operational witness. To carry this guarantee through higher-order application, we relate terms to abstract values: at ground type, value 1 requires head convergence; at function types, related arguments must produce related results. For closed t:σt : \sigma and v∈Dσv \in D_\sigma, define tRσvt \mathrel{R_\sigma} v by

tRov⟺v=1⟹∃a,u⃗  t⇓Ga(u⃗),tRσ→τf⟺∀u,v [uRσv⟹t uRτf(v)].t \mathrel{R_o} v \Longleftrightarrow v = 1 \Longrightarrow\exists a,\vec{u}\; t \mathrel{\Downarrow_G} a(\vec{u}), \\ t \mathrel{R_{\sigma\to\tau}} f \Longleftrightarrow\forall u,v\,[u \mathrel{R_\sigma} v \Longrightarrow t\,u \mathrel{R_\tau} f(v)].

Every closed typed term is related to the least element at its type. This follows by induction on the type: the base implication for zero imposes no convergence claim, and a bottom function always returns a bottom value. A terminal is related to its constant-one interpretation, since its saturated application exposes that terminal without evaluating its children.

The relation is preserved by interpreting terms. More precisely, for a term t:σt : \sigma, if every nonterminal FF is related to η(F)\eta(F) and each closed argument uiu_i is related to ρ(xi)\rho(x_i), then

t[u⃗/x⃗]Rσ⟦t⟧η,ρ.t[\vec{u}/\vec{x}] \mathrel{R_\sigma} \llbracket t \rrbracket_{\eta,\rho}.

Induction on tt proves it: lookup handles variables and nonterminals, the preceding observation handles terminals, and the function clause handles application.

We now induct on the iteration number nn to show FRτFηn(F)F \mathrel{R_{\tau_F}} \eta_n(F) for every nonterminal. The base case follows from η0(F)=⊥τF\eta_0(F) = \bot_{\tau_F}. For the step, take arbitrary closed arguments uiu_i related to values viv_i. The substitution property relates the instantiated body tF[u⃗/x⃗]t_F[\vec{u}/\vec{x}] to ΦG(ηn)(F)(v⃗)\Phi_G(\eta_n)(F)(\vec{v}). Prepending the actual head step F u⃗→htF[u⃗/x⃗]F\,\vec{u} \to_h t_F[\vec{u}/\vec{x}] preserves the ground relation: any head exposure of the body is also a head exposure of the call. Quantifying over the arguments gives the required function relation for FF at ηn+1(F)\eta_{n+1}(F). At n=Bn = B, all nonterminals are therefore related to their values in η∗\eta_*. Applying the substitution property to the closed ground term tt gives tRo⟦t⟧η∗t \mathrel{R_o} \llbracket t \rrbracket_{\eta_*}. If this value is 11, the ground clause yields the required finite head exposure.

(2) Completeness (⇐\Leftarrow). Suppose a finite head-unfolding sequence takes tt to a terminal application. We show that each head step preserves the interpretation in η∗\eta_*. Semantic substitution, proved by structural induction, and the fixed-point equation η∗=ΦG(η∗)\eta_* = \Phi_G(\eta_*) give, for each rule F x⃗→tFF\,\vec{x} \to t_F and matching closed arguments u⃗\vec{u},

⟦F u⃗⟧η∗=η∗(F)(⟦u⃗⟧η∗)=⟦tF⟧η∗,[x⃗↦⟦u⃗⟧η∗]=⟦tF[u⃗/x⃗]⟧η∗.\begin{aligned} \llbracket F\,\vec{u} \rrbracket_{\eta_*} = \eta_*(F)(\llbracket\vec{u} \rrbracket_{\eta_*}) \\ &= \llbracket t_F \rrbracket_{\eta_*,[\vec{x}\mapsto\llbracket\vec{u}\rrbracket_{\eta_*}]} \\ &= \llbracket t_F[\vec{u}/\vec{x}] \rrbracket_{\eta_*}. \end{aligned}

Here the denotation of a tuple is taken componentwise. The first equality is application, the second uses the fixed point and the definition of ΦG\Phi_G, and the third is semantic substitution. The terminal application at the end of the finite head-unfolding sequence has value 11, independently of its children. Induction along that sequence therefore gives ⟦t⟧η∗=1\llbracket t \rrbracket_{\eta_*} = 1, proving the reverse implication. □

Exact finite prefixes

Define head⁡G(t)\operatorname{head}_G(t) as follows. If ⟦t⟧η∗=0\llbracket t \rrbracket_{\eta_*} = 0, return ⊥\bot. Otherwise run deterministic head unfolding until a terminal a(u⃗)a(\vec{u}) is reached, and return that terminal and its arguments. The search terminates by Lemma 6.1 and requires no a priori bound on the number of head steps. Typing is preserved, so each returned child can be processed in turn.

Head search can try successive finite unfolding budgets, since success at any budget is decidable. It is invoked only after head adequacy has proved that some budget succeeds. This gives a total computable head reader. On a negative finite-model answer, no search is performed.

The exact address reader read⁡G(t,w)\operatorname{read}_{G}(t,w) returns a terminal label a∈Σa \in\Sigma at an existing node, ⊥\bot at a present divergent node, and †\dagger when the address is absent. Define it by recursion on ww:

read⁡G(t,ϵ)={⊥,head⁡G(t)=⊥,a,head⁡G(t)=a(u⃗),\operatorname{read}_{G}(t,\epsilon) = \begin{cases} \bot, & \operatorname{head}_{G}(t)=\bot,\\ a, & \operatorname{head}_{G}(t)=a(\vec{u}), \end{cases}
read⁡G(t,iw′)={read⁡G(ui,w′),head⁡G(t)=a(u⃗)∧i<∣u⃗∣,†,otherwise.\operatorname{read}_{G}(t,iw') = \begin{cases} \operatorname{read}_{G}(u_i,w'), & \operatorname{head}_{G}(t)=a(\vec{u}) \land i < |\vec{u}|,\\ \dagger, & \text{otherwise}. \end{cases}

The recursion terminates by address length, with each head call total.

Lemma 6.2 (Exact prefixes). For every well-formed GG, closed ground tt, and finite address ww, the reader returns exactly the label, bottom node, or absence at address ww in BTG(t)\mathrm{BT}_{G}(t). Consequently exact prefixes of any specified finite depth are total computable.

Proof. Induct on ww. At ϵ\epsilon, Lemma 6.1 determines convergence and head unfolding supplies the terminal label. At iw′iw', bottom has no children, invalid terminal-child indices are absent, and valid indices invoke the induction hypothesis. Let bb be the maximum terminal arity, or zero for an empty alphabet. Reading all w∈{0,…,b−1}∗w \in\{0,\ldots,b-1\}^{*} with ∣w∣<d|w| < d in a fixed order computes Pref⁡(G,d)\operatorname{Pref}(G,d). Every actual node has such an address, so equality of all prefix tables is equivalent to tree equality. □\square

Finally, define the Boolean depth test by

Q(G,t,0)=true,Q(G,t,0)=\mathrm{true},
Q(G,t,d+1)={false,head⁡G(t)=⊥,⋀i<rQ(G,ui,d),head⁡G(t)=a(u0,…,ur−1).Q(G,t,d+1)= \begin{cases} \mathrm{false}, & \operatorname{head}_{G}(t)=\bot,\\ \bigwedge_{i<r} Q(G,u_i,d), & \operatorname{head}_{G}(t)=a(u_0,\ldots,u_{r-1}). \end{cases}

Induction on dd identifies this total test with depth-dd productivity. A nullary terminal passes because the conjunction is empty. For start terms abbreviate it to Q(G,d)Q(G,d). Hence

⟨G,H⟩∈Eq4,Σ2prod⟺∀d [Valid4,Σ2(G,H)∧Pref⁡(G,d)=Pref⁡(H,d)∧Q(G,d)∧Q(H,d)].\langle G,H\rangle\in\mathrm{Eq}^{\mathrm{prod}}_{4,\Sigma_2} \Longleftrightarrow \forall d\,[\mathrm{Valid}_{4,\Sigma_2}(G,H)\land\operatorname{Pref}(G,d)=\operatorname{Pref}(H,d) \land Q(G,d)\land Q(H,d)].

On invalid input the matrix is defined to be false before any semantic operation. This is a computable universal Boolean definition. Conjoining the decidable checks Safe(G)∧Safe(H)\mathrm{Safe}(G)\land\mathrm{Safe}(H) gives the same upper bound for Eq4,Σ2safe,prod\mathrm{Eq}^{\mathrm{safe,prod}}_{4,\Sigma_2}. Omitting the QQ tests or the syntactic restrictions gives the bounds for Eq4,Σ2\mathrm{Eq}_{4,\Sigma_2} and EqHORS\mathrm{Eq}_{\mathrm{HORS}}. Together with the reduction in § 5.6, this proves Theorem 1.1.

Consequences

For pushdown automata we use the ranked-tree convention of [8 Section 3.3]: a deterministic higher-order automaton without collapse, together with its output labelling, generates a tree by unfolding transitions and contracting silent steps. Infinite silent runs give ⊥\perp leaves.

Corollary 7.1 (Pushdown-tree equivalence). Equality of the labelled trees generated by deterministic order-four higher-order pushdown automata without collapse under this convention is undecidable.

Proof. The effective, order-preserving translation of Theorem 2 of [8 p. 14] converts each safe final compiled scheme into an order-four automaton with the same ordered labelled tree. The convention’s one-based child indices correspond to our zero-based indices by uniform reindexing. By Equation (1), equality of the two translated trees is equivalent to source nonhalting. A decision procedure for these automata would therefore decide source halting. □

Corollary 7.2 (λY\lambda Y Böhm-tree equivalence). Equality of the η\eta-long Böhm trees of simply typed λY\lambda Y-terms up to α\alpha-equivalence is Π10\Pi^0_1-complete under total computable many-one reductions. Inputs are pairs of terms of the same type in a common typed context.

Proof. The translations of [5 Theorem 11 and Corollary 19, pp. 96, 101] give computable many-one reductions in both directions between HORS equivalence and this problem. The Böhm-tree encoding preserves binding information through de Bruijn levels, using a common enumeration of free variables. The HORS-to-λY\lambda Y direction transfers Π10\Pi^0_1-hardness from Theorem 1.1. The reverse direction transfers its Π10\Pi^0_1 upper bound. □

Limits of effective comparison. The main theorem also rules out complete effective methods for certifying equality or bounding the depth of disagreement.

Corollary 7.3. No sound and complete effective system of finite certificates recognizes tree equality throughout the safe productive order-four class, even over Σ2\Sigma_2.

Proof. Enumerating and checking the certificates would semidecide equality. Exact-prefix search semidecides inequality. Dovetailing these searches would decide equality on the final compiler’s outputs, contradicting Equation (1) and source undecidability. □

Corollary 7.4. There is no total computable function BB of input-description size such that every unequal safe productive order-four pair over Σ2\Sigma_2 has a discrepancy at an address of length at most B(n)B(n).

Proof. Compare the depth-B(n)+1B(n)+1 prefixes of the final compiled pair of size nn. A difference implies source halting; agreement forces tree equality and hence nonhalting. This would decide the source halting problem. □

The order-three boundary. The order-four bound arises from the stored polynomial interface. While arithmetic helpers have order at most three, NN has order two; hence P=N→N→NP = N \to N \to N has order three, which pushes Next±\mathrm{Next}_{\pm} and the control nonterminals FiF_i to order four (Lemma 5.1). Inlining update helpers cannot eliminate this bottleneck. Reducing the target order three would require either storing polynomial representations of order at most two capable of subsequent updates and evaluations, or bypassing stored polynomials entirely. We therefore leave HORS equivalence at orders two and three open for future work.

Formalization. A supplementary Rocq development covers both compiler stages, including typing, safety, the order bound, productivity, and correspondence with standard HORS head rewriting, as well as the finite semantics and observation algorithms used for the upper bound. It relies on the Rocq standard library and the Library of Undecidability Proofs [12], with completeness formulated in the synthetic computability framework of [7]; conventional effectivity is established by the paper’s explicit algorithms. The consequences in § 7, including the pushdown-automata translation, remain paper-level deductions. Codex was used as an interactive aid during formalization development (e.g., for boilerplate and proof scripts) and for revising the paper’s prose. All formal definitions, theorems, and proofs were audited and verified by the authors. The underlying theory was developed independently by the authors. The artifact is available at doi:10.5281/zenodo.23734555; its README provides the precise theorem statements, assumptions, and reproduction instructions.

References

  1. [1]Samson Abramsky and Achim Jung. Domain theory. In Samson Abramsky, Dov M. Gabbay, and Thomas S. E. Maibaum, editors, Handbook of Logic in Computer Science, volume 3, pages 1–168. Oxford University Press, 1994. URL: https://www.cs.ox.ac.uk/people/samson.abramsky/handbook.pdf.
  2. [3]Adrien Boiret, Radosław Piórkowski, and Janusz Schmude. Reducing transducer equivalence to register automata problems solved by “Hilbert Method”. In 38th IARCS Annual Conference on Foundations of Software Technology and Theoretical Computer Science (FSTTCS), volume 122 of Leibniz International Proceedings in Informatics, pages 48:1–48:16. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2018. URL: https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.FSTTCS.2018.48, doi:10.4230/LIPIcs.FSTTCS.2018.48.DOI
  3. [4]Patrick Cousot and Radhia Cousot. Abstract interpretation: A unified lattice model for static analysis of programs by construction or approximation of fixpoints. In Conference Record of the Fourth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 238–252. ACM, 1977. URL: https://www.di.ens.fr/~cousot/COUSOTpapers/POPL77.shtml, doi:10.1145/512950.512973.DOI
  4. [5]Pierre Clairambault and Andrzej S. Murawski. Böhm trees as higher-order recursive schemes. In 33rd IARCS Annual Conference on Foundations of Software Technology and Theoretical Computer Science (FSTTCS), volume 24 of Leibniz International Proceedings in Informatics, pages 91–102. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2013. URL: https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.FSTTCS.2013.91, doi:10.4230/LIPIcs.FSTTCS.2013.91.DOI
  5. [6]Andrej Dudenhefner. Certified decision procedures for two-counter machines. In 7th International Conference on Formal Structures for Computation and Deduction (FSCD), volume 228 of Leibniz International Proceedings in Informatics, pages 16:1–16:18. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. URL: https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.FSCD.2022.16, doi:10.4230/LIPIcs.FSCD.2022.16.DOI
  6. [7]Yannick Forster, Dominik Kirst, and Gert Smolka. On synthetic undecidability in Coq, with an application to the Entscheidungsproblem. In Proceedings of the 8th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP), pages 38–51. ACM, 2019. URL: https://www.ps.uni-saarland.de/Publications/documents/ForsterEtAl_2018_On-Synthetic-Undecidability.pdf, doi:10.1145/3293880.3294091.DOI
  7. [8]Matthew Hague, Andrzej S. Murawski, C.-H. Luke Ong, and Olivier Serre. Collapsible pushdown automata and recursion schemes. ACM Transactions on Computational Logic, 18(3):25:1–25:42, 2017. Cited version: accepted author manuscript (47 pages); DOI for the published version. URL: https://pure.royalholloway.ac.uk/ws/portalfiles/portal/28424477/HMOS_Easychair.pdf, doi:10.1145/3091122.DOI
  8. [9]Jerome Jochems. Reducing higher-order recursion scheme equivalence to coinductive higher-order constrained Horn clauses. Electronic Proceedings in Theoretical Computer Science, 344:36–64, 2021. URL: https://arxiv.org/abs/2109.04632, doi:10.4204/EPTCS.344.4.
  9. [10]Teodor Knapik, Damian Niwiński, and Paweł Urzyczyn. Higher-order pushdown trees are easy. In Foundations of Software Science and Computation Structures (FoSSaCS), volume 2303 of Lecture Notes in Computer Science, pages 205–222. Springer, 2002. URL: https://link.springer.com/chapter/10.1007/3-540-45931-6_15, doi:10.1007/3-540-45931-6_15.DOI
  10. [11]Naoki Kobayashi. Types and higher-order recursion schemes for verification of higher-order programs. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 416–428. ACM, 2009. URL: https://www-kb.is.s.u-tokyo.ac.jp/~koba/papers/popl2009.pdf, doi:10.1145/1480881.1480933.DOI
  11. [12]Library of Undecidability Proofs contributors. The Coq/Rocq library of undecidability proofs. Source code, 2026. Revision c7257b736763d7b2bc3bd25ac47d5fb7ce749c9c; accessed October 27, 2026. URL: https://github.com/uds-psl/coq-library-undecidability/tree/c7257b736763d7b2bc3bd25ac47d5fb7ce749c9c.
  12. [13]C.-H. Luke Ong. On model-checking trees generated by higher-order recursion schemes. In Proceedings of the 21st Annual IEEE Symposium on Logic in Computer Science (LICS), pages 81–90. IEEE Computer Society, 2006. URL: https://www.cs.ox.ac.uk/people/luke.ong/personal/publications/lics06.pdf, doi:10.1109/LICS.2006.38.DOI
  13. [14]Luke Ong. Higher-order model checking: An overview. In Proceedings of the 30th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), pages 1–15. IEEE Computer Society, 2015. URL: https://www.cs.ox.ac.uk/people/luke.ong/personal/publications/LICS15.pdf, doi:10.1109/LICS.2015.9.DOI
  14. [15]Géraud Sénizergues. The equivalence problem for deterministic pushdown automata is decidable. In Automata, Languages and Programming (ICALP), volume 1256 of Lecture Notes in Computer Science, pages 671–681. Springer, 1997. doi:10.1007/3-540-63165-8_221.DOI
  15. [16]Sylvain Salvati and Igor Walukiewicz. Using models to model-check recursive schemes. Logical Methods in Computer Science, 11(2):1–27, 2015. Article 7. URL: https://lmcs.episciences.org/1567, doi:10.2168/LMCS-11(2:7)2015.DOI

Paper details

vlnc:W_upbffd78
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 2

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents