Transcript
Page 1: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Under consideration for publication in Math. Struct. in Comp. Science

An introduction to decidability ofhigher-order matching

Colin Stirling

School of Informatics, Informatics Forum, University of Edinburgh

email: [email protected]

Received July 2013

Keywords: simply typed lambda calculus, higher-order matching, games, tree automata.

Contents

1 Introduction 22 Background 3

2.1 Simply typed lambda calculus 32.2 Higher-order matching and interpolation 6

3 Tree automata and interpolation 93.1 Terms as trees 93.2 Tree automata 11

4 Games and interpolation 184.1 Interpolation games 194.2 Properties of game playing 234.3 Parent and child positions 28

5 Tree automata revisited 305.1 Variable profiles 315.2 Tree automata for interpolation at all orders 325.3 Dependency tree automata 36

6 Decidability 396.1 Uniformity properties of game playing 396.2 Two transformations 436.3 Partitioning play 466.4 Unfolding 496.5 Removing restrictions 54

7 Conclusion 55References 55

Page 2: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 2

1. Introduction

Higher-order unification is the problem given an equation t = u containing free variablesis there a solution substitution θ such that tθ and uθ have the same normal form? Theterms t and u belong to the simply typed lambda calculus and the same normal form iswith respect to βη-equivalence. Higher-order matching is the particular instance when theterm u is closed; can the free variables in t be instantiated to produce a term that matchesu? Although higher order unification is undecidable (even if free variables are only second-order (Goldfarb 1982)), higher-order matching was conjectured to be decidable by Huet(Huet 1976). If matching is decidable then it is known to have non-elementary complexity(Statman 1979; Vorobyov 1997; Wierzbicki 1999). Decidability had been proved for thegeneral problem up to order 4 (by showing decidability of observational equivalence oflambda terms) and for various special cases (Padovani 1996; Padovani 2000; Schubert1997; Schmidt-Schauß 2003; Dougherty and Wierzbicki 2002). Comon and Jurski definetree automata that characterise all solutions to a 4th-order problem, thereby, showingthat they form a regular set (Comon and Jurski 1997). Loader showed that matchingis undecidable for the variant definition of the same normal form that only uses β-equivalence by encoding lambda definability as matching (Loader 2003): see (Joly 2005)for a proof that uses the halting problem.

In (Stirling 2009A) we confirmed Huet’s conjecture that matching is decidable. Itappeals to Padovani’s and Schubert’s reduction of matching to the interpolation problemconsisting of equations of the form xw1 . . . wk = u where there is only one free variableoccurrence x (Schubert 1997; Padovani 2000). The proof technique is then somewhatdifferent from the methods used in (Padovani 1996; Padovani 2000). It starts with a gametheoretic understanding of a solution to an interpolation problem which is essentially agame semantic understanding of typed lambda calculus. The aim is to avoid explicit β-reduction and substitution by understanding them in terms of sequences of positions in aplay on the fixed term tree tw1 . . . wk; t is a potential solution term which is applied to thearguments w1 . . . wk; and we want to know whether the normal form of the application isu; the terms t, w1, . . . , wk, u are all in η-long normal form. The decidability proof is verycomplicated. It isolates uniformity properties of game playing and shows that based onthem, subterms can be manipulated so that an interpolation problem has a solution iffit has a small solution. This is in the same spirit as the small model property in modalor temporal logics; if a formula is satisfiable then it is satisfiable in a model bounded inthe size of the formula.

One aim of this paper is to introduce the topic to a wider audience; so we include a briefintroduction to simply typed lambda calculus, matching and interpolation with concreteexamples. Another aim of the paper is to offer a simpler proof of decidability which stilluses games. With the game theoretic characterisation of solutions to an interpolationproblem tw1 . . . wk in (Stirling 2009A) play only traverses nodes of the potential solutionterm t; its arguments w1, . . . , wk are coded within states of a play position. Here, instead,we employ a symmetric game where positions may jump from nodes of t to nodes of wjand back again. There still is the asymmetry in the analysis as the terms wj are fixed inadvance. The proof still involves identifying uniformity properties of sequences of posi-

Page 3: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 3

tions and manipulating subterms. We also describe an alternative framework using treeautomata for understanding interpolation trees tw1 . . . wk. We start with (Comon andJurski 1997) characterisation of solutions to 4th-order problems and then consider how togeneralise tree automata to higher-orders. This requires an excursion into automata thatcan cope with an infinite alphabet. Although we introduce a new kind of tree automatonand characterise solutions to interpolation problems this does not lead to decidabilitybecause the non-emptiness problem of such automata is undecidable. Much of the treeautomata discussion is from (Stirling 2007; Stirling 2009).

In Section 2 simply typed lambda calculus, higher-order matching and interpolationare briefly introduced. In Section 3 we describe tree automata and how they can be usedfollowing (Comon and Jurski 1997) to characterise solutions of interpolation equationsof order 4. We then provide the game theoretic characterisation of interpolation, givean example and start to analyse properties of games in Section 4. Tree automata arerevisited in Section 5 where we describe a new kind of such automata that leads to newcharacterisations of solutions to interpolation problems but not to decidability. Finallywe proceed to the proof of decidability using the small solution property in Section 6.Then we conclude with general remarks and ideas for future work.

2. Background

2.1. Simply typed lambda calculus

Simple types are generated from base types using the binary function operator →. Forease of exposition, we assume that there is just one base type 0: what is to follow can beextended to the case when there are arbitrary many base types as we discuss further inSection 6.5.

Definition 1. Simple types are defined by the following grammar.

A ::= 0 | A→ A

We use capital letters from the initial part of the alphabet to range over types. A → B

is the type of functions that take elements of type A and return elements of type B.Assuming → associates to the right, so A → B → C is A → (B → C), if A is notthe base type 0 then it has the form A1 → . . . → An → 0 which is abbreviated to(A1, . . . , An,0).

Definition 2. The order of 0 is 1 and the order of (A1, . . . , An,0) is k+1 where k is themaximum of the orders of A1, . . . , An. The arity of 0 is 0 and the arity of (A1, . . . , An,0)is m where m is the maximum of n and the arities of A1, . . . , An.

Example 1. (0,0,0) is the type of a function that takes two elements of base type,in turn, and returns an element of base type; it has order 2 and arity 2. ((0,0),0)has arity 1 and order 3 because it is the type of a function that takes a function(from base type to base type) and returns an element of base type. The monster typeM = ((((0,0),0),0),0,0), see (Joly 2001), has arity 2 and order 5: order(M) = 1 +order((((0,0),0),0)) = 2 + order(((0,0),0)) = 3 + order((0,0)) = 4 + order(0) = 5. It is

Page 4: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 4

the type of a function that takes two arguments, the second of which has base type, andreturns an element of base type; the first argument has type (((0,0),0),0) that takes afunction of type ((0,0),0) and returns an element of base type.

Terms that have simple types are generated from a countable set of typed variablesxA, yB , . . . and typed constants a0, fA, . . . (and, therefore, in Church style (Barendregt1992)) using the operators of lambda abstraction and function application. We write t : Ato mean term t has type A.

Definition 3. The set of simply typed terms is the smallest set T such that

1. if xA then x : A ∈ T ,2. if fA then f : A ∈ T ,3. if t : B ∈ T and x : A ∈ T then λx.t : A→ B ∈ T ,4. if t : A→ B ∈ T and u : A ∈ T then (tu) : B ∈ T .

We let s, t, . . . range over terms in T . Function abstraction is given by lambda abstrac-tion: λx.t has type A → B, if x : A and t : B. Function application is written usingjuxtaposition; t : A → B applied to u : A is (tu) of type B. In a sequence of unparen-thesised applications, we adopt the familiar convention that application associates to theleft, so tu1 . . . uk is ((. . . (tu1) . . .)uk).

Usual definitions of when a variable occurrence is free or bound and when a termis closed are assumed: for instance, both occurrences of x in xy(λu.xzu) in the termλx.λy.xy(λu.xzu) are bound (by λx) whereas the occurrence of z is free; this term is,therefore, not closed. As this example illustrates, we shall avoid explicitly presentingtypes when they are not germane to the discussion. We also assume the usual notion ofα-equivalence between terms where bound variable occurrences and their binders maybe renamed with fresh variables of the same type; thus, λx1.λy1.x1y1(λu.x1zu) is α-equivalent to the term above.

Definition 4. The order of a term t : A is the order of A.

Example 2. Let f : (0,0,0) and a, b : 0 be constants; the term fab : 0 because unab-breviated f : 0→ (0→ 0), so (fa) : 0→ 0 and ((fa)b) : 0. The term t = λx.λy.x(λz.zy)is closed and has the monster type M of Example 1 when x : ((((0,0),0)),0), y : 0 andz : (0,0); so, zy : 0, λz.zy : ((0,0),0), x(λz.zy) : 0, and, therefore, λy.x(λz.zy) : (0,0)and t : M has order 5.

Another abbreviation is λz1 . . . zm for λz1 . . . λzm; so the term t : M in Example 2 isλxy.x(λz.zy).

Terms have dynamics through rewriting or reduction rules.

β-reduction (λx.t)u→β t{u/x}η-reduction λx.tx→η t if x is not free in t

Here {u1/x1} and, more generally, {u1/x1, . . . , un/xn} is (simultaneous) substitutionwhere each xi is distinct, of simultaneously replacing all free occurrences of xi with ui,and avoiding variable capture by renaming bound variables; ui and xi must have the same

Page 5: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 5

type for each i. The application of a rewrite rule to a term consists of replacing a subtermby its reduction: for instance, λz.((λx.x)(faz))→β λz.faz because (λx.x)(faz)→β faz;and λz.faz →η fa. Some well known properties of reduction are now described, see, forinstance, (Barendregt 1984; Barendregt 1992; Dowek 2001; Hindley and Seldin 1986); weuse standard notation, →βη is →β ∪ →η and →∗δ is the reflexive and transitive closureof →δ.

Fact 1. Let t : A and δ ∈ {β, η, βη}.1. (Subject reduction) If t→δ t

′ then t′ : A.2. (Strong normalisation) There is not an infinite sequence of the form t →δ t1 →δ

. . .→δ tn →δ . . ..3. (Confluence) If t→∗δ t1 and t→∗δ t2 then for some s, t1 →∗δ s and t2 →∗δ s.

Definition 5. Assume δ ∈ {β, η, βη}. Terms t, t′ are δ-equivalent, t =δ t′, if there are s,

s′ such that t→∗δ s and t′ →∗δ s′ and s is α-equivalent to s′.

We are primarily interested in βη-equivalence, =βη, between terms. Confluence andstrong normalisation ensure that terms reduce to (unique) normal forms; that is, to termswhere there is no application of reduction. However, as is common, we wish to understandβη-equivalence without invoking η-reductions; the method for doing this uses β-normalforms of a particular kind.

Definition 6.

1. Term t is in β-normal form if there is not a t′ such that t→β t′.

2. Term t in β-normal form is η-long if there is not a t′ such that t′ →η t.

We abbreviate η-long β-normal form to long normal form, or lnf for short. Lnfs arepreserved under β-reductions.

Fact 2. If t : A→ B and u : A are both in lnf, and tu→∗β t′ and t′ is in β-normal formthen t′ is in lnf.

Fact 3.

1. If t =β t′ then there is a unique s (up to α-equivalence) in β-normal form such that

t =β s and t′ =β s.2. If t =βη t

′ then there is a unique s (up to α-equivalence) in lnf such that t =βη s andt′ =βη s.

Next we characterise syntactically terms that are in normal form. The two kinds ofnormal form are similar. We proceed by cases on the type. A term of type 0 is in β-normalform if it is

— a constant or a variable u : 0, or— u t1 . . . tk where u : (A1, . . . , Ak,0) is a constant or a variable and each ti : Ai is in

β-normal form.

A lnf of type 0 is

— a constant or a variable u : 0, or

Page 6: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 6

— u t1 . . . tk where u : (A1, . . . , Ak,0) is a constant or a variable and each ti : Ai is inlnf.

A term of type (A1, . . . , An,0) is in β-normal form if it is

— ut1 . . . tm, m ≥ 0 where u : (B1, . . . , Bm, A1, . . . , An,0) is a constant or variable andeach ti : Bi is in β-normal form, or

— λx1 . . . xk.t′, 1 ≤ k ≤ n, each xi : Ai, t′ is in β-normal form and if k < n then

t′ : (Ak+1, . . . , An,0) and if k = n then t′ : 0.

For lnf it is much simpler; a term of type (A1, . . . , An,0) is in lnf if it is

— λx1 . . . xn.t′, each xi : Ai and t′ : 0 is in lnf.

Example 3. Assume x : (0,0). Then x and λx.x : ((0,0),0,0) are in β-normal formbut not lnf. If z : 0 then both λz.xz : (0,0) and λxz.xz : ((0,0),0,0) are in lnf.

Definition 7. For any type A and set of constants C, TA(C) is the set of closed lnfterms of type A whose constants belong to C.

Example 4. Let A = (0,0,0) and C = {f, g} where f : (0,0,0) and g : (0,0). The setTA(C) consists of the terms λx1x2.s with s ::= x1 | x2 | gs1 | fs1s2. An example of a termin TM (∅) where M is the monster type is λxy.x(λz1.x(λz2.z1y)) when x : (((0,0),0),0),each zi : (0,0) and y : 0.

2.2. Higher-order matching and interpolation

We now introduce the higher-order matching problem, posed in (Huet 1976), and also(Statman 1982).

Definition 8. A matching equation has the form v = u where v, u : 0 are in lnf and u

is closed. The order of the equation is the maximum of the orders of the free variablesx1, . . . , xn in v. A solution is a sequence of terms t1, . . . , tn such that v{t1/x1, . . . , tn/xn}=βη u. The arity of the equation is the largest arity of the types Ai such that xi : Ai.

The matching problem is: given a matching equation v = u, does it have a solution;can v be pattern matched to u by instantiating its variables? Matching is an instance oftwo undecidable problems, higher-order unification and higher-order β-matching. A uni-fication equation is similar v = u except that free variables may occur on both sides, in vand u; so, a solution is a sequence of terms t1, . . . , tn such that v{t1/x1, . . . , tn/xn} =βη

u{t1/x1, . . . , tn/xn}. A β-matching equation is v = u where v, u : 0 are in β-normal formand u is closed; a solution is a sequence of terms t1, . . . , tn such that v{t1/x1, . . . , tn/xn}=β u. The unification or β-matching problem is: given a unification or β-matching equa-tion, does it have a solution? Unification is undecidable, even at order 2 (Goldfarb 1982)and β-matching is undecidable at order 5 and beyond (Loader 2003; Joly 2005) (anddecidable at orders below 5 (Padovani 2000)). There are other closely related problemsthat are undecidable which if they were decidable would imply that matching is decid-able; the most famous of which is lambda definability (Loader 2001; Statman 1982); theothers are the type inhabitation problem in the presence of intersection types (Urzyczyn

Page 7: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 7

1999) and the non-emptiness problem for a particular kind of alternating tree automatawhich we shall see later (Stirling 2009; Ong and Tzevelekos 2009); this last result appealsto the undecidability of observational equivalence for finitary PCF (Loader 2001A).

In the literature there are alternative versions of matching. First is the general case ofan equation v = u when v, u : A for arbitrary A and u is closed. If A = (A1, . . . , Ak,0)then the term u has the form λz1 . . . zk.u

′; therefore, there is the matching equationv′ = u′′ when v′, u′′ are the lnfs of vc1 . . . ck and u′{c1/z1, . . . , ck/zk}, and each ci is anew constant of correct type that cannot occur in a solution term. Statman presents “therange question” (Statman 1982): given closed v : (A1, . . . , An, B) and u : B are thereterms t1 : A1, . . . , tn : An such that vt1 . . . tn =βη u? This is equivalent to the matchingproblem v′ = u where v′ is the lnf of vx1 . . . xn where each xi has type Ai. In (Padovani2000) a matching problem is a family of matching equations v1 = u1, . . . , vm = um to besolved uniformly, as all occurrences of a free xi in each equation must be instantiated withthe same ti: this problem reduces to the single matching equation fv1 . . . vm = fu1 . . . umwhere f is a constant of the appropriate type.

There is a simplified version of matching which is essentially monadic, involving asingle free variable.

Definition 9. Assume u : 0 and wi : Ai, 1 ≤ i ≤ k, are closed terms in lnf andx : (A1, . . . , Ak,0). An interpolation equation is xw1 . . . wk = u. The type and order ofthe equation is that of x. A solution is a closed term t : (A1, . . . , Ak,0) in lnf such thattw1 . . . wk =βη u. The term u of the equation xw1 . . . wk = u is called its goal term.

Proposition 4. If t solves xw1 . . . wk = u then there is a lnf u′ such that tw1 . . . wk →∗β u′and u′ is α-equivalent to u.

Proof. If t solves xw1 . . . wk = u then tw1 . . . wk =βη u and the result therefore followsfrom Fact 2 because the terms t, w1, . . . , wk, u are in lnf.

Interpolation equations appear as a component in Dowek’s proof of decidability of 3rd-order matching (Dowek 1994); they are used by Padovani alongside interpolation disequa-tions to characterise observational equivalence between terms (Padovani 1996; Padovani1995; Padovani 2000). An interpolation disequation has the form xw1 . . . wk 6= u and issolved by t of correct type and in lnf if tw1 . . . wn 6=βη u. At each type observationalequivalence has finite index; decidability of observational equivalence and its representa-tives implies decidability of matching (Padovani 2000). Via this route, Padovani provesdecidability of 4th-order matching (including β-matching).

Conceptually, interpolation is simpler than matching because there is a single variablex that appears at the head of the equation. If v = u is a matching equation with free vari-ables x1 : A1, . . . , xn : An then its associated interpolation equation is x(λx1 . . . xn.v) = u

where x : ((A1, . . . , An,0),0). This appears to raise order by 2 as with reduction ofmatching to pairs of interpolation equations in (Schubert 1997). However, we only needto consider potential solution terms (in lnf of the right type) λz.zt1 . . . tn where eachti : Ai is closed and so cannot contain z: we say that such terms are canonical solutions.

Page 8: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 8

Proposition 5. A matching equation has a solution iff its associated interpolation equa-tion has a canonical solution.

Proof. Assume v = u is a matching equation, x1 : A1, . . . , xn : An are the free variablesthat occur in v and x(λx1 . . . xn.v) = u is its associated interpolation equation. If thematching equation has solution t1, . . . , tn then it follows that v{t1/x1, . . . , tn/xn} =βη u.Therefore, λz.zt1 . . . tn is a canonical solution to the associated interpolation equationbecause (λz.zt1 . . . tn)(λx1 . . . xn.v) →β (λx1 . . . xn.v)t1 . . . tn →∗β v{t1/x1, . . . , tn/xn}.Conversely, if λz.zt1 . . . tn is a canonical solution to the equation x(λx1 . . . xn.v) = u

then v{t1/x1, . . . , tn/xn} =βη u and, so, the closed terms t1, . . . , tn solve the matchingequation v = u.

Similarly, a β-matching equation v = u also has an associated β-interpolation equa-tion x(λx1 . . . xn.v) = u; and the equation has a solution iff the associated interpolationequation has a canonical solution λz.zt1 . . . tn in β-normal form. Although Proposition 5implies that interpolation equations need only have one argument, we forgo this restric-tion in what follows.

Example 5. The matching equation x1(λz.x1(λz′.za)) = a from (Comon and Jurski1997) is 4th-order when z, z′ : (0,0) and x1 : (((0,0),0),0). The associated interpolationequation is xw = a where w = λx1.x1(λz.x1(λz′.za)) and x : (((((0,0),0),0),0),0). Acanonical solution has the form t = λx.x(λy.y(λy1 . . . y(λyk.s)...)) where s is the constanta or one of the variables yj , 1 ≤ j ≤ k. To see this assume w1 = λy.y(λy1 . . . y(λyk.s)...):so, tw →β ww1 →β w1(λz.w1(λz′.za)) →∗β w1(λz.za) →∗β a. Conversely, assume λx.xt1is a canonical solution to xw = a; so, wt1 →∗β a and, therefore, t1(λz.t1(λz′.za)) →∗β awhere t1 : (((0,0),0),0) is λy.s′ and s′ is the constant a : 0 or y(λyi.s′′) and s′′ is a : 0,a variable yi or of the form y(λyj .s′′′).

It is worthwhile in the light of the undecidability of β-matching to try to distinguishbetween it and matching. The following is an illustrative example which we shall returnto.

Example 6. Consider the following 3rd-order interpolation equation with two argumentsx(λy1y2.y2)a = a where x : ((0,0,0),0,0). As a β-matching equation, a solution isthe term t = λx1.x1b where x1 : (0,0,0) and x1b : (0,0) because t(λy1y2.y2)a →β

(λy1y2.y2)ba →∗β a.

We now restrict which constants can occur in a potential solution term to an interpo-lation equation.

Definition 10. If E is the interpolation equation xw1 . . . wk = u then CE is the set ofconstants that occur in the goal u together with one fresh constant b : 0 (that does notoccur in u).

Fact 6. If E is an interpolation equation of type A, t solves E and t ∈ TA(C) then thereis a t′ ∈ TA(CE) such that t′ solves E.

Page 9: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 9

@

~~~~

~~~~

QQQQQQQQQQQQQQQ

t w1 . . . wk

Fig. 1. An interpolation tree

In general the goal u of an interpolation equation may contain bound variables: forinstance, x(λz.z) = h(λx1x2x3.x1x3)a has order 3 where x has type ((0,0),0) and theconstant h : (((0,0),0,0,0),0,0) assuming x2 : 0. An example solution is the termλy.y(y(h(λxz1z2.x(yz2))(ya))). For convenience, as it simplifies the presentation consid-erably, we restrict ourselves to the case where the goal u does not contain bound variables;the extension of what is to follow to include bound variables is discussed in Section 6.5.As u does not contain bound variables, Proposition 4 can be slightly strengthened: if tsolves xw1 . . . wk = u then tw1 . . . wk →∗β u.

Definition 11. Assume u : 0 is closed, in lnf and does not contain bound variables.

1. The subterms of u, Sub(u), is: if u = a : 0 then Sub(u) = {u} and if u = fu1 . . . umthen Sub(u) = {u} ∪

⋃1≤i≤m Sub(ui).

2. The depth of u, depth(u), is: if u = a : 0 then depth(u) = 0 and if u = fu1 . . . umthen depth(u) = 1 + max{depth(u1), . . . ,depth(um)}.

3. Tree automata and interpolation

3.1. Terms as trees

Given a potential solution term t (of the right type and in lnf) to an interpolationequation E, xw1 . . . wk = u, there is the tree in Figure 1. If x : (A1, . . . , Ak,0) then theexplicit application operator @ : ((A1, . . . , Ak,0), A1, . . . , Ak,0) has its expected meaningλz0z1 . . . zk.z0z1 . . . zk; so @tw1 . . . wk →∗β tw1 . . . wk.

An objective is to understand the reduction of tw1 . . . wk to normal form by examiningthe tree in Figure 1, avoiding the use of substitution (and β-reduction). In fact we willpresent different ways of achieving this using automata and games. (Type checking withintersection types inspired by the work in (Kobayashi and Ong 2009) offers a third waywhich we do not expand on here.)

The terms t, w1, . . . , wk in Figure 1 are represented as a special kind of tree (that wecall binding trees) with dummy lambdas and an explicit binding relation. A term of theform y : 0 or a : 0 is represented as a tree with a single node labelled y or a. In the caseof u v1 . . . vn when u is a variable or a constant of type (A1, . . . , An,0) including @, weassume that a dummy lambda with the empty sequence of variables is placed directlyabove any subterm vi : Ai = 0 in its tree representation. With this understanding, thetree for u v1 . . . vn consists of a root node labelled u and n-successor trees representingv1, . . . , vn. We also use the standard vector abbreviation λy for λy1 . . . ym for some m ≥ 0,so y is possibly the empty sequence of variables in the case of a dummy lambda. Thetree representation of λy.t′ consists of a root node labelled λy with a single successor

Page 10: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 10

tree for t′ : 0. (Thus, we do not use Bohm trees.) Therefore, in any interpolation tree, asin Figure 1, a node that is at odd depth is labelled with a λy and a node that is at evendepth is labelled with @, a constant or a variable.

The other elaboration is that we assume an extra binary relation ↓ between nodes ina tree that represents binding ; that is, between a node labelled λy1 . . . yn and a nodelabelled yj (that it binds). We assume the following convention for binders and variables.A binder λy is such that either y is empty and therefore is a dummy lambda and cannotbind a variable occurrence or y = y1 . . . yk and λy can only then bind variable occurrencesof the form yi, 1 ≤ i ≤ k. Consequently, in the binding tree representation if n ↓ m andn is labelled λy1 . . . yk then m is labelled yi for some i : 1 ≤ i ≤ k (and node m mustoccur below n).

Example 7. An example of the tree representation of an interpolation equation witha solution term is Figure 2; its equation is in Example 8. We have identified each nodewith a unique integer. There are dummy lambdas such as at nodes (5) and (21). Thebinding relation is given by pairs such as (1) ↓ (2), (1) ↓ (4), (17) ↓ (18) and (19) ↓ (22).All nodes such as (1), (7) and (23) at odd depth are labelled with a lambda.

We assume standard terminology of finite trees. We let n, m range over nodes of atree: in the case of a term tree nodes are labelled with variables, constants or lambdas;so, we say that a node is a variable node if it is labelled with a variable and similarly fora constant and a lambda node (which may also be a binding node). More generally, if Σis an alphabet then a Σ-tree is a finite tree whose nodes are labelled with elements of Σ(see Definition 13). Nodes have successors: often we use the notation that ni is the ithsuccessor of n. We say that a node n occurs above m if n = m or there is a path from n

down to m in the tree; m occurs below n if there is a path from m up to n in the tree.The following is a formal definition of a binding tree.

Definition 12. Assume Σ is a finite graded alphabet where each element s ∈ Σ has anarity ar(s) ≥ 0. Moreover, Σ consists of three disjoint sets Σ1 that are the binders whichhave arity 1, Σ2 are (the bound) variables and Σ3 are the remaining symbols. A bindingΣ-tree is a finite tree where each node is labelled with an element of Σ together witha binary relation ↓ (representing binding). If node n in the tree is labelled with s andar(s) = k then n has precisely k successors in the tree, the nodes n1, . . . , nk. Also, if anode m is labelled with a variable in Σ2 then there is a unique node n labelled with abinder occurring above m in the tree such that n ↓ m. For ease of exposition we alsoassume the following restrictions on binding Σ-trees: if node n is labelled with a binderthen n1 is labelled with an element of Σ2 ∪ Σ3 and if n is labelled with an element ofΣ2 ∪ Σ3 and ni is a successor then it is labelled with a binder.

The tree representation of an interpolation equation obeys the regulations for a bindingtree. However, in actual examples such as Figure 2 we use integers to identify tree nodesinstead of words.

Page 11: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 11

3.2. Tree automata

Given an interpolation equation E of type A, xw1 . . . wk = u, is there a method forgenerating or recognising its set of solutions? Here is a naive technique: relative to anenumeration t1, t2, . . . of terms in TA(CE) we know that ti solves E iff tiw1 . . . wk →∗β u;so, it is enough to calculate the normal form of tiw1 . . . wk for each ti in turn. This isonly a decision procedure when TA(CE) is a finite set of terms (such as for a fixed k ifthe order of A is at most 2 and a term contains at most k constants); otherwise, it is asemi-decision procedure.

A systematic approach to solving problems over trees is to show that their solutionsare recognised by an appropriate tree automaton: there is an automaton that accepts atree if, and only if, it solves the problem (Comon et al 2002). This is a decision procedurefor the problem when the non-emptiness question for the automaton is decidable; thatis, whether it accepts at least one tree. In this section, we investigate the applicationof classical bottom-up tree automata to 4th-order interpolation equations described in(Comon and Jurski 1997). (In fact, they prove the more general result that the set ofsolutions of a 4th-order matching problem, including β-matching, is recognisable by atree automaton.)

First, we define bottom-up tree automata that operate on Σ-trees which are finite treeswhere each node is labelled with an element of Σ (Comon et al 2002).

Definition 13. Assume Σ is a finite graded alphabet where each element s ∈ Σ has anarity ar(s) ≥ 0. A Σ-tree is a finite tree where each node is labelled with an elementof Σ. If node n in t is labelled with s and ar(s) = k then n has precisely k successorsn1, . . . , nk in t. Let TΣ be the set of Σ-trees.

Binding trees as in Definition 12 are a particular case of Σ-trees.

Definition 14. A Σ-tree automaton A = (Q,Σ, F,∆) where Q is a finite set of states,Σ is the finite alphabet, F ⊆ Q is the set of final states and ∆ is a finite set of transitionrules of the form sq1 . . . qk ⇒ q where k ≥ 0, s ∈ Σ, ar(s) = k and q1, . . . , qk, q ∈ Q.

Definition 15. A run of A = (Q,Σ, F,∆) on t ∈ TΣ is a labelling of t with elementsof Q that is defined bottom-up, starting from the leaves of t. If a node n of t is labelleds ∈ Σ, ar(s) = k ≥ 0, sq1 . . . qk ⇒ q ∈ ∆ and q1, . . . , qk label n1, . . . , nk the k successorsof n, then n is labelled q. A accepts the Σ-tree t iff there is a run of A on t such thatthe root node of t is labelled with a final state q ∈ F . Let TΣ(A) be the set of Σ-treesaccepted by A.

A Σ-tree automaton A has a finite set of states and transitions (which can be nonde-terministic). A run of A on a Σ-tree t is a labelling of t with elements of Q that startsat the leaves (hence “bottom-up”). If n in t is a leaf then it is labelled with an s ∈ Σwith ar(s) = 0: ∆ may contain a transition of the form s⇒ q, so n can be labelled withq. States may then percolate through t using ∆: if n is labelled s and n1, . . . , nk arelabelled with the states q1, . . . , qk and sq1 . . . qk ⇒ q ∈ ∆ then n can be labelled q. Thisis repeated until no further nodes can be labelled. A run is then accepting if the root oft is labelled with a final state q ∈ F .

Page 12: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 12

We state some key properties of tree automata (Comon et al 2002).

Fact 7. Assume A and A′ are Σ-tree automata.

1. The non-emptiness problem for A (is TΣ(A) 6= ∅?) is decidable in linear time.2. There is a Σ-tree automaton A such that TΣ(A) = TΣ − TΣ(A).3. There is a Σ-tree automaton A′′ such that TΣ(A′′) = TΣ(A) ∩ TΣ(A′).

Whether a tree automaton accepts at least one tree is decidable. Its proof uses a small treeproperty: if an automaton accepts a tree then it accepts a tree whose depth is boundedby the number of states of the automaton. The other properties have the consequencethat the sets of Σ-trees that are tree recognisable are regular (closed under the usualboolean operations).

If we can design a tree automaton to recognise exactly the solutions of an interpolationequation then matching is decidable: there is a slight gap here; more precisely, we needthe slightly stronger, and easily attainable, requirement of decidability of non-emptinessof the tree automaton with respect to canonical solutions, see Proposition 5.

We start with a 3rd-order interpolation equation E, xw1 . . . wk = u. To define a treeautomaton that accepts its solutions, first we need to isolate a finite alphabet Σ. Apotential solution term has the form λx1 . . . xk.s where s is given by the following simplegrammar

s ::= fs1 . . . sm | xis1 . . . sm

where f range over the constants in CE , xi over {x1, . . . , xk} and m ≥ 0. A potentialsolution term is, therefore, built from a fixed finite alphabet; the only constants allowedin s belong to CE and the only free variables belong to {x1, . . . , xk}. The set of termsallowed by this grammar may not be finite because of arbitrary embeddings of constantsand variables, such as with λx1 . . . xk.x1(x1 . . . (x1x2) . . .).

Example 8. Consider the interpolation equation xw1w2 = faa from (Comon andJurski 1997) where w1 is λy1y2.y1, w2 is λy3.fy3y3, y1, y2, y3 : 0, f : (0,0,0) andx : ((0,0,0), (0,0),0) is 3rd-order. The alphabet Σ is {a, b, f, x1, x2, λ, λx1x2}; f andx1 have arity 2, λ, λx1x2 and x2 have arity 1, and a, b arity 0. A solution termt = λx1x2.x1(x2(x1(x1ab)b))b is shown in Figure 2: tw1w2 →∗β w1(w2(w1(w1ab)b))b →∗βw1(w2a)b →β w1(faa)b →β faa.

We describe how to define a simple tree automaton that captures all solution terms ofE (represented as trees). Consider any node n within a solution term t that is labelledwith a variable or a constant. The subterm rooted at that node has type 0; it maycontain occurrences of free variables belonging to {x1, . . . , xk}. The first issue is whetherthis node in t contributes to the normal form of tw1 . . . wk. If it does not then it is saidto be inaccessible (Padovani 2000): that is, replacing the subtree rooted at n with anyother term of type 0, and in particular the constant b : 0 (which does not occur in u),will not change the normal form; so, adopting the notation t[b/n] meaning t where thesubtree at node n is replaced with the single node tree labelled b, (t[b/n])w1 . . . wk hasthe same normal form, u, as tw1 . . . wk. Otherwise n does contribute and so the node isthen said to be accessible; next, we examine its evaluation (Padovani 2000; Comon and

Page 13: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 13

(0)@

iiiiiiiiiiiiiiiiiii

UUUUUUUUUUUUUUUUUUU

(1)λx1x2 (17)λy1y2 (19)λy3

(2)x1

JJJJJJJJJ(18)y1 (20)f

uuuuuuuuu

IIIIIIIII

(3)λ (11)λ (21)λ (23)λ

(4)x2 (12)b (22)y3 (24)y3

(5)λ

(6)x1

JJJJJJJJJ

(7)λ (13)λ

(8)x1

JJJJJJJJJ(14)b

(9)λ (15)λ

(10)a (16)b

Fig. 2. A 3rd-order example

Page 14: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 14

Jurski 1997), the normal form of t′{w1/x1, . . . , wk/xk} when t′ is the subterm rooted atn; this normal form must be a subterm of u, an element of Sub(u). For instance, nodes(12), (14) and (16) of Figure 2 are inaccessible. Node (6) is accessible; its subterm isx1(x1ab)b whose evaluation is the normal form of x1(x1ab)b{λy1y2.y1/x1, λy3.fy3y3/x2}which is a. In contrast, the evaluation of (2) is faa. This analysis is extended to nodesof t that are labelled with dummy lambdas and the root node labelled λx1 . . . xk; sucha node n is inaccessible if its successor n1 is inaccessible; otherwise, its evaluation is thevalue at n1 prefaced with the lambda at n.

States of the tree automaton for E are defined from these values. We need the elementsSub(u) where u is the goal term and one other state for inaccessible nodes plus theirversions for lambda nodes.

Q = {[e], [λ.e] | e ∈ Sub(u) ∪ {−}} ∪ {[λx1 . . . xk.u]}

The states [−] and [λ.−], are for inaccessible nodes; the states [u′] and [λ.u′] are for ac-cessible nodes whose evaluation or successor’s evaluation is u′ ∈ Sub(u) and [λx1 . . . xk.u]is the final state of the automaton for the root node.

Next we define the transitions. The intention is that t is a solution of E if there is alabelling of t with states such that its root is labelled with the final state [λx1 . . . xk.u].Transitions are of the form sq1 . . . qk ⇒ q where s ∈ Σ has arity k and q1, . . . , qk, q arestates. First when s is a constant or a λ there are the following transitions.

f [λ.u1] . . . [λ.um]⇒ [fu1 . . . um] m ≥ 0f [λ.−] . . . [λ.−]⇒ [−]λ[u′]⇒ [λ.u′]λ[−]⇒ [λ.−]λx1 . . . xk[u]⇒ [λx1 . . . xk.u]

Transitions are of two kinds, for accessible and inaccessible nodes. If m = 0 then thesetransitions have the form a ⇒ [a] and a ⇒ [−]. Next we examine the transitions for anode n labelled with a variable xi ∈ {x1, . . . , xk}. If n is accessible then its evaluationemploys wi for xi; therefore, we are interested in the normal form of wie1 . . . em when foreach j state [λ.ej ] labels nj; ej ∈ Sub(u)∪ {−}; so, if ej is − then it does not contributeto the normal form.

xi[λ.e1] . . . [λ.em]⇒ [u′] m ≥ 0 and wie1 . . . em →∗β u′ ∈ Sub(u)xi[λ.−] . . . [λ.−]⇒ [−]

Example 9. The automaton for the equation in Example 8 has, as we have seen, alpha-bet Σ = {a, b, f, x1, x2, λ, λx1x2}. Q is {[faa], [λ.faa], [a], [λ.a], [−], [λ.−], [λx1x2.faa]}and its last element is the final state. Transitions are as follows where e ranges over{a, faa,−}.

Page 15: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 15

a⇒ [a] a⇒ [−] b⇒ [−]f [λ.a][λ.a]⇒ [faa] f [λ.−][λ.−]⇒ [−]x1[λ.e][λ.−]⇒ [e]x2[λ.a]⇒ [faa] x2[λ.−]⇒ [−]λ[e]⇒ [λ.e]λx1x2[faa]⇒ [λx1x2.faa]

In the rule for x1, the second argument of w1e1e2 does not contribute to normal formbecause w1 is λy1y2.y1. The solution term in Figure 2 is accepted as follows. For the leavesnode (10) is labelled with [a] and (12), (14), (16) with [−]. Using transitions λ[e]⇒ [λ.e],node (9) is labelled with [λ.a] and (15), (13), (11) with [λ.−]. The rule x1[λ.a][λ.−]⇒ [a]allows (8) to be labelled [a]; so (7) can be labelled [λ.a]; therefore, node (6) can also belabelled [a] and, therefore, (5) can be labelled [λ.a]. The transition x2[λ.a]⇒ [faa] is nowapplied and (4) is labelled [faa] and (3) [λ.faa]. Using x1[λ.faa][λ.−]⇒ [faa] node (2)is labelled [faa] and, therefore, (1) is labelled with the final state. We leave the readerto verify that this automaton recognises the solutions of the equation in Example 8.

Extending the construction to a 4th-order interpolation equation E requires care withvariables (Comon and Jurski 1997). If E, xw1 . . . wk = u, is 4th-order then a solutionterm has the form λx1 . . . xk.s where s is given by the following grammar.

s ::= zj | fs1 . . . sm | xiv1 . . . vmv ::= s | λz1 . . . zm.s

Again f ranges over CE , xi over {x1, . . . , xk} and m ≥ 0: a variable xi may take asargument a term of the form λz1 . . . zm.s where each zj is of ground type. Therefore,with this grammar we can write 4th-order terms which use arbitrarily many variablessuch as

λx1x2.x1(λz1.x1(λz2.x1 . . . x1(λzn.x2(x2 . . . (x2(x2z1z2)z3) . . .)zn) . . .))

where zi : 0 for each i, x1 : ((0,0),0) and x2 : (0,0,0).However, there is an upper bound on the number of variables that are needed to

label the accessible nodes of any solution term. Any occurrence of a free variable zjin a subterm has ground type and, therefore, occurs at a leaf of the tree. If we nowexamine an accessible node of a solution term that is labelled with a constant or avariable then the term t′ rooted there has gound type. Its evaluation, the normal formof t′{w1/x1, . . . , wk/xk}, may contain free variables zj of ground type: therefore, itsevaluation is either an element of Sub(u) or what happens to an element of Sub(u)when subterms of it are replaced by variables zj . Consequently, if t′{w1/x1, . . . , wk/xk}contains a large number of free variable occurrences then they are mostly at inaccessiblenodes. There is, therefore, an upper bound on the number of accessible leaves labelledwith a free variable zj in any subterm of a solution term; this bound is |u|, the size ofu. Consequently, by reusing variables there is an overall upper bound on the number ofvariables zj needed in the abstract syntax for a solution term λx1 . . . xk.s, as describedabove, which leads to a finite alphabet Σ for the tree automaton.

Page 16: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 16

[λx1.ga](1)λx1

[ga](2)x1

WWWWWWWWWWWWWWWWWWWWWWWW

[λz.gz](3)λz [λ.a](11)λ

[gz](4)g [a](12)x1

ppppppppppp

[λ.z](5)λ [λz.z](13)λz [λ.a](19)λ

[z](6)x1

nnnnnnnnnnnn[z](14)x1

NNNNNNNNNNN[a](20)a

[λy.z](7)λy [λ.−](9)λ [λz.z](15)λz [λ.z](17)λ

[z](8)z [−](10)b [z](16)z [z](18)z

Fig. 3. A successful run of the automaton of Example 10

The states of the automaton consist of elements [e], [λ.e], [λz1 . . . zm.e] and the finalstate [λx1 . . . xk.u] where e not only ranges over subterms of u and − but also oversubterms of u when their subterms are replaced with variables zj . The full definition ofthe transition relation of the automaton is left as an exercise for the reader; we illustrateit with an example.

Example 10. The equation xw1 = ga is 4th-order where w1 = λy1y2.y1y2, g : (0,0),a : 0 and x : (((0,0),0,0),0). Any solution term with b : 0 at an inaccessible non-lambdanode has the form λx1.s where s is constrained by the following finite alphabet.

s ::= a | b | z | gs | x1(λz.s)s | x1(λy.s)s

So, Σ is {a, b, z, g, x1, λ, λz, λy, λx1}. The states of the automaton are as follows wherethe final state is [λx1.ga].

Q = {[e], [λ.e], [λy.e], [λz.e], [λx1.ga] | e ∈ {−, z, a, gz, ga}}

Page 17: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 17

Below are the transitions where e′ ∈ {−, z, a, gz, ga}.

a⇒ [a] a⇒ [−] b⇒ [−]z ⇒ [z] z ⇒ [−]g[λ.e]⇒ [ge] for e ∈ {a, z} λ[e′]⇒ [λ.e′]λy[e]⇒ [λy.e] for e ∈ {a, z, ga, gz} λz[e]⇒ [λz.e] for e ∈ {a, z, ga, gz}λx1[ga]⇒ [λx1.ga] x1[λy.e][λ.e′]⇒ [e] for e ∈ {a, z, ga, gz}x1[λz.e][λ.e′]⇒ [e] for e ∈ {a, ga} x1[λz.z][λ.e]⇒ [e] for e ∈ {a, z, ga, gz}x1[λz.gz][λ.e]⇒ [ge] for e ∈ {z, a}

The interesting transitions cover the cases for x1 whose interpretation is w1: there-fore, for instance, w1(λy.e)e′ →∗β e and w1(λz.z)e →∗β e. An example solution termis λx1.x1(λz.g(x1(λy.z)b))(x1(λz.x1(λz.z)z)a). The successful run of the automaton onits tree is presented in Figure 3. In contrast, the automaton will not accept the termwhen the label at node (7) of Figure 3 is changed to λz; then we would have state [λz.z]at node (7) and [λ.−] at node (9); now the run of the automaton becomes stuck as thereis no transition that allows (6) to be labelled with a state.

The following result is now clear, see (Comon and Jurski 1997).

Fact 8. The tree automaton associated with a 4th-order interpolation equation E acceptsthe term t iff t solves E.

There are serious problems with extending the definition of a tree automaton associatedwith an interpolation equation beyond 4th-order. If E, xw1 . . . wk = u, is 5th-order, thena solution term has the form λx1 . . . xk.s where s is given by the following grammar

s ::= zjs1 . . . sm | fs1 . . . sm | xiv1 . . . vmv ::= s | λz1 . . . zm.s

where f ranges over CE , xi over {x1, . . . , xk} and m ≥ 0. Now it is possible to produceterms whose accessible nodes involve subterms containing arbitrary many different freezj variables because they can be 2nd-order. A first problem is that the alphabet Σ forthe automaton need not be finite. A second problem is related; how to restrict the stateset Q of the automaton to be finite. Even if the syntax is restricted to be finite thereneed not be an upper bound on the number of different evaluations of accessible nodesbecause the same free variable zj may occur embedded multiple times. Comon and Jurskiillustrate the problems with the following example (Comon and Jurski 1997).

Example 11. The equation xλyz.y(λz′.zz′) = a where z′ : 0, z : (0,0), y : ((0,0),0)and x : ((((0,0),0), (0,0),0),0) is 5th-order. Solutions include the terms

λx1.x1(λz1.x1(. . . x1(λzn.zi1(zi2(. . . (zika) . . .)))un . . .)u2)u1

where for some m ≤ k, every uij , j ≤ m, is the identity and uim+1 is the constant functiona. The point is that the variables zi are 2nd-order; and so they can be “stacked”. Torecognise this family of terms requires an unbounded alphabet. Moreover, even if we dorestrict the number of different variables zj we may still end up with arbitrary many

Page 18: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 18

evaluations: for instance, assume that they are all zn and consider the evaluation at theposition of the first zn which is zn(zn(. . . (zna) . . .)).

Similarly, the monster type M , ((((0,0),0),0),0,0), has, as we have seen, order 5.Assume x : (((0,0),0),0), y : 0 and zi : (0,0) for i ≥ 1. The following family of terms inlnf λxy.x(λz1.x(λz2 . . . (λzn.zn(zn−1(. . . z1(y)) . . .)) . . .)) for n ≥ 0 belong to TM (∅). Towrite down this subset of terms requires an alphabet of unbounded size.

A solution to the problem of a potentially infinite alphabet is to represent terms asbinding trees as defined in Section 3.1. For instance, there is a straightforward represen-tation of the family of terms of type M in Example 11 as binding trees (with dummylambdas). Nodes are labelled with binders λxy, λz, λ, or with variables x, z of arity 1and y of arity 0: in linear form

λxy.x(λz.x(λz . . . x(λz.z(λ.z(. . . λ.z(λ.y)) . . .)) . . .))

where there is an edge ↓ from the node labelled λxy to each node labelled x or y, and anedge ↓ from the first node labelled λz to the last node labelled z, and so on.

Fact 9. For any type A and finite C, there is a finite alphabet Σ such that everyt ∈ TA(C) up to α-equivalence is represented as a binding Σ-tree.

However this does not help with the issue of how to define an automaton that onlyinvolves a finite number of states. To understand this better, we need a finer analysisthan that of the evaluation of an accessible node. Indeed, we shall now present a finerstatic analysis of β-reduction using games.

4. Games and interpolation

We now describe a game theoretic characterisation of whether t is a solution to aninterpolation equation xw1 . . . wk = u. The game board is the interpolation tree ofFigure 1. The idea is as with game semantics (Ong 2006), see Figure 4. Player Opponent,∀, chooses a branch of u. Then, there is a finite play that starts at the root of t labelledλx1 . . . xk which may repeatedly jump from t into a wj and back again. At a constanta : 0 the play ends. At other constants f , player Proponent, ∃, matches Opponent’schoice of branch. Proponent wins, when the play finishes, if the sequence of constantsencountered matches the branch chosen by Opponent. Play, for example, may reach anode labelled xj in t and then jump to the root labelled λy of wj because wj is the jthargument that is applied to λx1 . . . xk at the root of t, and then when at a node labelledyn in wj play returns to the nth successor of xj in t, to the node labelled λz; play thenmay proceed to a node zl and return to the lth successor of the node labelled yn inwj , and so on. The game models β-reduction on the fixed structure of Figure 4 withoutchanging it using substitution. The game we now develop avoids questions, answers andjustification pointers of game semantics and uses iteratively defined look-up tables asdeveloped in (Stirling 2005; Stirling 2006; Stirling 2007).

Page 19: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 19

@

uuuuuuuuuu

BBBB

BBBB

QQQQQQQQQQQQQQQ

λx1 . . . xk

��

w1 λy

��

wk u

xj

55

yn

uuλz

��

λv

��zl

55

vm

uuλ

��

Fig. 4. Game-theoretic view

4.1. Interpolation games

Assume E is the equation xw1 . . . wk = u and t is a potential solution term. We definethe game G(t, E) played by one participant, player ∀, the refuter who attempts to showthat t is not a solution of E. The game is played on the interpolation tree @tw1 . . . wk ofFigure 1. In the following we use the interpolation tree notation that was introduced inSection 3.1.

Definition 16. Let N be the set of nodes of the interpolation tree @ tw1 . . . wk andN1 ⊂ N be the binding nodes (labelled with binders in Σ1). S is the set {[ r ] | r ∈Sub(u) ∪ {∀,∃}} of game states. [ ∀ ] and [∃ ] are the final game states.

Definition 17. For each i ≥ 1, the set of look-up tables Θi is iteratively defined:

1. Θ1 = {θ1} where θ1 = ∅,2. Θi+1 is the set of partial maps N1 → (

⋃λy1...yp∈Σ1

Np ×⋃j≤i Θj).

Definition 18. A play of G(t, E) is a finite sequence n1q1θ1, . . . , nlqlθl of positions whereeach ni ∈ N , each qi ∈ S with ql a final state and each θi ∈ Θi is a look-up table. Forthe initial position n1 is the root of the interpolation tree labelled @, q1 = [u ] where uis the goal term of E and θ1 is the empty look-up table. Player ∀ wins the play if thefinal state is [ ∀ ] and loses it otherwise (when the final state is [ ∃ ]).

The game G(t, E) appeals to a finite set of states S with elements [ r ], r ∈ Sub(u)where u is the goal term of E, and final states, [∀ ], winning for the refuter, and [ ∃ ],losing for the refuter. The central feature of a play of G(t, E), as depicted in Figure 4,

Page 20: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 20

Current position is n[r]θ. The next position is by cases on the label at node n:

— @ then n1[r]θ′ where θ′ = θ{((n2, . . . , n(k + 1)), θ)/n1}— λy then n1[r]θ

— a : 0 if r = a then n[ ∃ ]θ else n[∀ ]θ

— f : (B1, . . . , Bp,0) if r = fr1 . . . rp then ∀ chooses j ∈ {1, . . . , p} and nj [rj ]θ else

n[ ∀ ]θ

— yj : 0 if m ↓ n and θ(m) = ((m1, . . . ,ml), θ′) then mj [r]θ′

— yj : (B1, . . . , Bp,0) if m ↓ n and θ(m) = ((m1, . . . ,ml), θ′) then mj [r]θ′′ where

θ′′ = θ′{((n1, . . . , np), θ)/mj}

Fig. 5. Game moves

is that repeatedly control may jump from a node of t to a node of wj for some j andthen later jump back into t. Therefore, as play proceeds, one needs an account of themeaning of free variables in subtrees. A free variable in a subtree of t is associated witha subtree of wj for some j; similarly, a free variable in a subtree of wj is associated witha subtree of t. This is the role of the look-up table θk ∈ Θk at position k ≥ 1. If n ∈ N1

is a binder labelled λy1 . . . yp and θk(n) is defined then it has the form ((n1, . . . , np), θj)which tells us that any node m labelled yi such that n ↓ m is associated with the subtreerooted at node ni: that subtree may itself contain free variables, hence, the presence ofa previous look-up table θj . Formally, as we shall see, one can view a look-up table as asubstitution.

Definition 19. If the current position in a play of G(t, E) is n[r]θ and [r] is not finalthen the next position is determined by a unique move in Figure 5 according to the labelat node n (and where ni is the ith successor node of n).

At the initial node labelled @, play proceeds to its first successor labelled with λx1 . . . xkand the look-up table is updated as this binding node is associated with the other succes-sors of the root; so any free variable xj in the subtree below λx1 . . . xk is associated withthe subtree wj rooted at the (j+ 1)th successor of the root and the empty look-up table.Later, if play reaches a node labelled xj (bound by this initial binder) then there is a jumpto the (j+ 1)th successor of the root node; it is this jumping that, thereby, simulates thesubstitution of wj for xj . Standard update notation is assumed: γ{((m1, . . . ,ml), γ′)/n}is the partial function similar to γ except that γ(n) = ((m1, . . . ,ml), γ′) where n islabelled λz1 . . . zl for some z. If play is at a lambda node then the next position is atits successor. At a node labelled with the constant a : 0, the refuter loses if the stateis [a] and wins otherwise. At a node labelled with a constant f with arity more than0, ∀ immediately wins if the state is not of the form [fr1 . . . rm]. Otherwise ∀ choosesa successor j and play moves to its jth successor with the new state [rj ]. If play is atnode n labelled with variable yj : 0 and θ(m) = ((m1, . . . ,ml), θ′) when m ↓ n then playjumps to the lambda node mj which has type 0 (so, is labelled with a dummy lambda)and θ′ is then the look-up table; θ′ consists of entries for the binders that occur abovemj in the interpolation tree (for interpreting the free variables in the subtree at mj). Ifn is labelled yj : (B1, . . . , Bp,0) and θ(m) = ((m1, . . . ,ml), θ′) when m ↓ n then playjumps to the lambda node mj which is labelled λz1 . . . zp for some z (because mj has

Page 21: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 21

(0)@

hhhhhhhhhhhhhhhhhhhhhh

NNNNNNNNNNN

(1)λx1x2 (17)λy1y2 (23)λy3

(2)x2 (18)y2

qqqqqqqqqq(24)y3

NNNNNNNNNN

(3)λz1z2 (19)λ (21)λ (25)λ (31)λv1v2

(4)x1

MMMMMMMMMM(20)y1 (22)y1 (26)y3

qqqqqqqqqqq(32)g

(5)λ (7)λs1s2 (27)λ (29)λw1w2 (33)λ

(6)z1 (8)x1

qqqqqqqqqqq(28)a (30)w1 (34)v2

(9)λ (11)λu1u2

(10)b (12)z2

qqqqqqqqqq

(13)λ (15)λ

(14)s1 (16)s2

Fig. 6. The interpolation tree of Example 12

the same type as yj): the new look-up table is θ′ plus the entry ((n1, . . . , np), θ) for thebinder mj ; each zi bound by mj is associated with the ith successor of n and θ for eachi : 1 ≤ i ≤ p.

Definition 20. Player ∀ wins the game G(t, E) if there is a play that she wins; otherwiseshe loses the game (when she loses every play).

Example 12. The equation, xw1w2 = ga is 5th-order with w1 = λy1y2.y2y1y1, w2 =λy3.y3(y3aλw1w2.w1)(λv1v2.gv2), x : ((0, (0,0,0)), ((0, (0,0,0),0),0),0) and g : (0,0).

Page 22: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 22

1. (0)[ga]θ1 = ∅ 25. (6)[a]θ42. (1)[ga]θ2 = {((17, 23), θ1)/1} 26. (25)[a]θ33. (2)[ga]θ2 27. (26)[a]θ34. (23)[ga]θ3 = {((3), θ2)/23} 28. (3)[a]θ10 = θ2{((27, 29), θ3)/3}5. (24)[ga]θ3 29. (4)[a]θ106. (3)[ga]θ4 = θ2{((25, 31), θ3)/3} 30. (17)[a]θ11 = {((5, 7), θ10)/17}7. (4)[ga]θ4 31. (18)[a]θ118. (17)[ga]θ5 = {((5, 7), θ4)/17} 32. (7)[a]θ13 = θ10{((19, 21), θ11)/7}9. (18)[ga]θ5 33. (8)[a]θ1310. (7)[ga]θ6 = θ4{((19, 21), θ5)/7} 34. (17)[a]θ14 = {((9, 11), θ13)/17}11. (8)[ga]θ6 35. (18)[a]θ1412. (17)[ga]θ7 = {((9, 11), θ6)/17} 36. (11)[a]θ15 = θ13{((19, 21), θ14)/11}13. (18)[ga]θ7 37. (12)[a]θ1514. (11)[ga]θ8 = θ6{((19, 21), θ7)/11} 38. (29)[a]θ16 = θ3{((13, 15), θ15)/29}15. (12)[ga]θ8 39. (30)[a]θ1616. (31)[ga]θ9 = θ3{((13, 15), θ8)/31} 40. (13)[a]θ1517. (32)[ga]θ9 41. (14)[a]θ1518. (33)[a]θ9 42. (19)[a]θ1119. (34)[a]θ9 43. (20)[a]θ1120. (15)[a]θ8 44. (5)[a]θ1021. (16)[a]θ8 45. (6)[a]θ1022. (21)[a]θ5 46. (27)[a]θ323. (22)[a]θ5 47. (28)[a]θ324. (5)[a]θ4 48. (28)[∃]θ3

Fig. 7. The single play of Example 12

The interpolation tree with a solution term is presented in Figure 6. We now examinethe game for this tree which consists of the single play in Figure 7. The positions 1 to 48are presented in two columns; each position has the form n[r]θ where n is a node of theinterpolation tree, r ∈ {ga, a, ∃,∀} and θ is a look-up table.

The initial position is at the root (0). Play descends to the binding node (1); any noden such that (1) ↓ n is, therefore, either associated with (the subtree at) (17) or (23) andthe empty look-up table θ1; this means that the look-up table θ2 at this position hasthe single entry θ2(1) = ((17, 23), θ1): in examples, we reduce the number of bracketsby abbreviating nodes such as (1) and (21) to 1 and 21 in look-up tables. Position 3 istherefore at node (2) labelled x2 which is bound by (1); therefore, play jumps to node(23) with look-up table θ1 which is updated because (23) is a binding node; therefore,the look-up table θ3 at position 4 has the single entry θ3(23) = ((3), θ2) which representsthat any node labelled y3 bound by (23) is associated with (3), the successor of (2), andlook-up table θ2. Position 5 is at node (24) which is bound by (23); so, play jumps to (3)and θ2 is updated with the entry ((25, 31), θ3)/3; the successors of (24) are associatedwith the nodes bound by (3) and the look-up table θ3. Position 7 is at (4); so play nowjumps to (17), descends to (18) and then jumps to node (7) and then to (8). Therefore,play jumps to (17), descends to (18) and jumps to (11), the second successor of (8).

Page 23: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 23

@

wwww

wwww

w

DDDD

DDDD

D @

uuuuuu

uuuu

DDDD

DDDD

D

λx1 λy1y2 λ λx1x2 λy1y2 λ

x1 y2 a x1

yyyy

yyyy

yy2 a

λ λ λ

b b x2

Fig. 8. Why long normal forms matter

Position (15) is, therefore, at node (12) which is bound by (3): so play jumps to (31)and descends to (32) labelled with the constant g; the current state is [ga] and so playproceeds to node (33) with new state [a]. After position 19 it jumps to (15), the secondsuccessor of (12), and then to (16) which is bound by (7). Play therefore jumps to (21),the second successor of (18), and so position 23 is at node (22) which is bound by (17).Play thereby jumps to (5), the first successor of (4), and then to (6) before jumping to(25) at position 26. The reader is invited to check the rest of the play and why positions44 and 45 at (5) and (6) are followed by a jump to (27) (and not (25)); so, play ends at(28) with refuter losing.

4.2. Properties of game playing

A key feature of the game is that terms must be in lnf. Consider what happens if we allowβ-normal forms instead as in Example 6 with interpolation equation x(λy1y2.y2)a = a

where x : ((0,0,0),0,0). As a β-matching problem, one solution is t = λx1.x1b andanother is its lnf; these interpolation trees are presented in Figure 8. The tree on the leftis in β-normal form whereas the tree on the right is in lnf. It is clear how play proceedson the second tree; there is a jump from the node labelled x1 to the node labelled λy1y2,and a return jump from the node labelled y2 to the dummy lambda above x2, so thatat x2 play jumps to the third successor of @ and so ∀ loses. However, in the first treeit is unclear how play should proceed because of incomplete information; what shouldhappen after the jump from (the node labelled) x1 to λy1y2 and the descent to y2?; thereis not a place to jump to in the first subtree.

We examine properties of game playing and prove that the game G(t, E) characteriseswhen t solves E. Further properties are described which are useful for defining treeautomata that recognise the set of solutions to interpolation equations. Also, these prop-erties underpin uniformity features of game playing that account for the decidability ofmatching as described in Section 6.

Page 24: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 24

First, some notational abbreviations that we will employ. We assume that if π is a playin G(t, E) then it has the form n1[r1]θ1, . . . , nl[rl]θl and πi is the ith position ni[ri]θi fori : 1 ≤ i ≤ l. Given π ∈ G(t, E), we allow ourselves to write ni or [ri] or θi to mean thenode or state or look-up table of position πi.

We begin with some simple observations; the number of branches in a term u is thenumber of leaves in its tree representation.

Fact 10. Assume u is the goal term of E and t solves E then the number of plays inG(t, E) is the number of branches in u.

If t does not solve E then the number of plays in G(t, E) can be less than the number ofbranches u.

Fact 11. Assume π ∈ G(t, E).

1. If i < l and i = 2k for k > 0 then ni is a lambda node.2. If i = 2k + 1 for k > 0 then ni is a variable or a constant node.3. nl is a constant node and rl ∈ {∀,∃}.4. If i < j < l then rj ∈ Sub(ri).

Figure 7 illustrates these features; because ga has only one branch there is a single play;each even position that is not final is at a lambda node such as positions 6 at node (3)and 18 at node (33); odd positions are at variable or constant nodes with the initialposition at the root labelled @. A term of a later state is a subterm of that of an earlierstate: after position 17, the term is a and until then it is ga. Play must end at a constantnode.

The same look-up table may occur multiple times in a play. To be precise, two look-uptables θ, θ′ are equal, θ = θ′, if they have the same entries. That is, they are defined forthe same nodes and for each m, θ(m) = ((n1, . . . , np), θi) iff θ′(m) = ((n1, . . . , np), θ′i)and θi = θ′i: this is well-defined (and not “circular”) because for each play position j, ifθj(m) = ((n1, . . . , np), θ′) then θ′ is the look-up table at some earlier position i < j (aswe now show).

Proposition 12. Assume π ∈ G(t, E), 1 ≤ j ≤ l and θj(m) = ((m1, . . . ,mp), θ′).

1. θj(n) is defined iff n is a binding node above nj .2. θ′(n) is defined iff n is a binding node strictly above each mk, 1 ≤ k ≤ p.3. For some y, m is labelled λy1 . . . yp and each yk has the same type as mk, 1 ≤ k ≤ p.4. There is an i < j such that θ′ = θi and either i = 1 and each mk = n1(k+ 1) or ni is

a variable node and each mk = nik, 1 ≤ k ≤ p.

Proof. We prove the four properties together by simultaneous induction on the positionj. For the base case j = 1, they all hold because θ1 is empty, there are no nodes abovethe root labelled @ and the root node is not a binding node.

For the general case assume that the four properties hold for all positions beforens[rs]θs. We show that they hold at ns[rs]θs by cases on the label at node n = ns−1.

@: this means that s = 2 and ns = n1. The only entry of θ2 is that for n1 which islabelled λx1 . . . xk, which shows 1 (as n1 is above n1). For 2, we note that θ2(n1) =

Page 25: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 25

((n2, . . . , n(k+1)), θ1), θ1 has no entries and there are no binding nodes strictly aboven2, . . . , n(k + 1). 3 is clear as each xk has the same type as n(k + 1). 4 is also clear.

λy: so ns = n1 and θs = θs−1. We know that n1 is not a binding node and so all fourhold by the induction hypothesis.

a: so ns = n and θs = θs−1. Therefore, the results hold by the induction hypothesis.f : so ns = n or ns = nq for some q and in both cases θs = θs−1. Node nq is not a

binding node (by assumption) and so the results follow by the induction hypothesis.yq: assume m ↓ n and θs−1(m) = ((m1, . . . ,mp), θ′) for some p ≥ q. Therefore, ns = mq

and θs = θ′ when yq : 0 and so by the induction hypothesis mq is then labelled witha dummy lambda (as it has type 0 too). Otherwise, θs = θ′{((n1, . . . , nr), θs−1)/mq}and yq : (B1, . . . , Br,0) and by the induction hypothesis mq has the same type (so,is labelled λz1 . . . zr for some z). As ns = mq we note that the binding nodes abovemq are those strictly above m1, . . . ,mp (which by the induction hypothesis on 4 havethe form n′1, . . . n′p) and so are strictly above mq and the node mq when yq is notof base type. Thus, 1 holds for θs using the induction hypothesis for 2 (for θ′) andthe entry for mq in θs when yq has higher type. For the remaining cases assumeθs(m′) = ((m′1, . . . ,m

′p′), θ

′′). So, either this is also an entry for θ′ and therefore 2, 3and 4 follow by the induction hypothesis on θ′ (which is θi for i < s) or m′ = mq,θ′′ = θs−1 and m′1, . . . ,m

′p′ are n1, . . . , nr; and so 2, 3 and 4 hold.

The binding nodes (1), (3) and (7) occur above (7) in Figure 6. At position 10 inthe game of Figure 7 at (7), θ6 = {((17, 23), θ1)/1, ((25, 31), θ3)/3, ((19, 21), θ5)/7} hasprecisely three entries: moreover, the only entry for θ5 is node (17) which is strictly abovenodes (19) and (21) (which are successors of (16)). A simple corollary of this propositionpart 3 is a type preservation feature that we have already described: if a position is ata variable of type A then the next position (involving a “jump”) is at a lambda nodewith the same type A. Together with part 1 and the definition of a next position, playin a game cannot become stuck: if a current position is at a lambda node then the nextposition is at its successor node; if it is at a variable node then there is an entry for itsbinder in the current look-up table.

Although the game abstracts from β-reduction there is an intimate relationship be-tween positions and stages of β-reduction when look-up tables are interpreted as substi-tutions as the proof of the following theorem, that the game characterises interpolation,shows.

Theorem 13. Player ∀ loses G(t, E) iff t solves E.

Proof. Assume E is xw1 . . . wk = u where x : A and t : A is a closed term in lnf. Wedefine leftmost reduction sequences using the following two rules:

1. (λy1 . . . yp.t′)t1 . . . tp → t′{t1/y1, . . . , tp/yp},

2. ft1 . . . tp → tj for j : 1 ≤ j ≤ p.The second rule allows for reduction under constants. A term t′ is terminal if neitherrule applies to it. Assume v : 0 is closed in normal form and does not contain binders.

Page 26: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 26

A reduction sequence of length 0 of the form t1 is compatible with v iff if t1 is terminalthen t1 = v. When the sequence t1 → . . .→ tk of length more than 0 is compatible withv is defined by cases on the initial reduction step t1 → t2,

— instance of rule 1: iff t2 → . . .→ tk is compatible with v.— t1 = fs1 . . . sp and t2 = sj : iff v = fv1 . . . vp and t2 → . . .→ tk is compatible with vj .

We slightly enlarge reduction sequences by allowing a third reduction rule for padding:t → t. A padding of t1 → . . . → tm includes 0 or more applications of the padding ruleas well as each ti → ti+1. Let σ range over reduction sequences.

Consider the game G(t, E). The tree representation of t and each wi introduces extradummy lambda nodes which we assume are not present in the reduction sequences. Givena node of the interpolation tree n and a look-up table θ we define the associated term asθ[n] as follows by cases on the label at n:

@: θ[n1] θ[n2] . . . θ[n(k + 1)],a: a,f : f θ[n1] . . . θ[np], f has arity pλ: θ[n1],λz: λz.θ[n1], z not emptyyj : of type 0; if m ↓ n and θ(m) = ((m1, . . . ,mp), θ′) then θ′[mj ] else yj ,yj : of type (B1, . . . , Bq,0); ifm ↓ n and θ(m) = ((m1, . . . ,mp), θ′) then θ′[mj ] θ[n1] . . . θ[nq]

else yj θ[n1] . . . θ[nq].

We shall show that there is a correspondence between terms in reduction sequences andassociated terms in game plays.

Assume a reduction sequence σ that is compatible with u and whose initial term ist1 = tw1 . . . wk. We show that there is a play π ∈ G(t, E) and a padding of σ of theform t1 → . . . → tm such that tj = θ2j−1[n2j−1] for all j : 1 ≤ j ≤ m. The proof is byinduction on i equal to the length of σ.

The base case is i = 1. The first position of any play π ∈ G(t, E) is n[u]θ1 where n isthe root of the interpolation tree. So, θ1[n] = θ1[n1] θ1[n2] . . . θ1[n(k+ 1)] as n is labelled@. As θ1 is empty, and the definition of θ[n] removes dummy lambdas θ1[n1] = t andθ1[n(i+ 1)] = wi. So, θ1[n1] = t1.

Assume the result holds for i ≤ q: there is a π ∈ G(t, E) and a padding t1 → . . . →ts such that ti = θ2i−1[n2i−1]. This means that if ti−1 = ft′1 . . . t

′p and ti = t′j then

θ2i−3[n2i−3] = ti−1 and θ2i−1[n2i−1] = ti; so, π follows the same branch of u as thereduction sequence. We consider i = q+1 and assume a reduction step tq → tq+1 so thatt1 → . . .→ tq+1 is compatible with u. We know that tq = ts = θ2s−1[n2s−1]. We proceedby cases on the label at n2s−1 (which cannot be a lambda node by Fact 10).

@: therefore, s = 1. Assume t = λx1 . . . xk.t′ So, t1 → t′{w1/x1, . . . , wk/xk} = t2. Con-

sider π3 (for any play): n3 is the root of t′ and θ3 = θ2 = {((n2, . . . , n(k+1)), θ1)/n2}where n is the root of the interpolation tree. Node n2 binds each node labelled with xi.By the induction hypothesis we know that θ1[n(i+ 1)] = wi. Therefore, θ3[n3] = t2.

a: cannot arise as then ts = a.f : so tq = ts = ft′1 . . . t

′p and tq+1 = ts+1 = t′j . Consequently, θ2s−1[ns−1] = ft′1 . . . t

′p =

fθ2s−1[n1] . . . θ2s−1[np]. Because t1 → . . .→ tq+1 is compatible with u and π1, . . . , π2s−1

Page 27: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 27

has followed the same branch of u as t1 → . . .→ tq, π2s will not be the final positionof π. We choose as the play π a continuation of π1, . . . , π2s−1 such that n2s is the jthsuccessor of n2s−1. So, n2s+1 is the successor of n2s and θ2s+1 = θ2s−1. Therefore,θ2s+1[n2s+1] = t′j .

yj : by Proposition 12 we know that there is an entry in θ2s−1 for the binding nodem such that m ↓ n2s−1. Let θ2s−1(m) = ((m1, . . . ,mp), θ′). First, assume yj :(B1, . . . , Br,0). So, tq = ts = θ2s−1[n2s−1] = θ′[mj ]θ2s−1[n1] . . . θ2s−1[nr] where niis the ith successor of n2s−1. This has the form (λy1 . . . yr.t

′)w′1 . . . w′r. So, ts+1 =

tq+1 = t′{w′1/y1, . . . , w′r/yr}. Now n2s = mj and θ2s = θ′{((n1, . . . , nr), θ2s−1)/mj}.

By the induction hypothesis wi = θ2s−1[ni] and θ′[mj ] = λy1 . . . yr.t′; therefore,

θ2s+1 = ts+1, as required. Next, assume yj : 0. It is only this case that introducespadding. So, ts = θ2s−1[n2s−1] which is θ′[mj ]. Moreover, θ′[mj ] = θ′[m′] when m′ isthe successor of mj since it is labelled with a dummy lambda. However, n2s = mj andθ2s = θ′; so, n2s+1 = m′ and θ2s+1 = θ′. Therefore, θ2s+1[n2s+1] = ts so we add thepadding move ts → ts+1 = ts. Notice, by Proposition 12 that θ′ = θi for i < 2s − 1.Now, we repeat this argument for node n2s+1 by examining its label. It is not possibleto enter into an infinite sequence of paddings because each time we invoke a look-uptable from an earlier position.

An almost identical argument shows that given any prefix π of a play in G(t, E) thereis a reduction sequence σ and a padding of σ of the form t1 → . . . → tm such thatθ2j−1[n2j−1] = tj for j : 1 ≤ j ≤ m. The proof proceeds by induction on the length ofπ. One imediate corollary of this argument is that because of strong normalisation therecannot be an infinite length play in G(t, E).

Now we can prove the main theorem. A maximal reduction sequence is one whose lastterm is terminal. If t solves E then by strong normalisation every maximal reductionsequence is finite and compatible with u. So there are corresponding plays π ∈ G(t, E)which ∀ loses. Moreover, there cannot be any other plays (as there would be correspondingreduction sequences). So ∀ loses the game G(t, E). Conversely, if ∀ loses G(t, E) thenfor each play π there is a corresponding reduction sequence compatible with u and allbranches of u are covered, so t solves E.

One corollary of the proof of this result is that there cannot be an infinite length playin G(t, E). Another is the following result that the same look-up table cannot occur indifferent positions at the same node.

Proposition 14. Assume π ∈ G(t, E) and i 6= j. If ni = nj then θi 6= θj .

Proof. This follows from the proof of Theorem 13. Given a prefix of π of length at leastj + 1 there is a reduction sequence σ and a padding of σ of the form t1 → . . .→ tm suchthat tk = θ2k−1[n2k−1] for all k : 1 ≤ k ≤ m. Assume ni = nj and θi = θj ; if i is eventhen ni+1 = nj+1 and θi+1 = θj+1; so, assume i = 2l − 1 and j = 2q − 1 are odd. Nowsince θi[ni] = θj [nj ] we have that tl → . . .→ tq = tl. Now using the observation from theproof in Theorem 13 that they cannot all be padding steps this would contradict strongnormalisation.

Page 28: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 28

λy1 . . . yp ni[ri]θi θi(ni) = ((m1, . . . ,mp), θ)

yk nj [rj ]θj θj(ni) = ((m1, . . . ,mp), θ)

Fig. 9. Position πi is the parent of the position πj

4.3. Parent and child positions

When a position is at a variable node, we identify the earlier position at its binding nodewhich determines where play will jump to next.

Definition 21. Assume that π ∈ G(t, E) and nj is a variable node. The position πi isthe parent of the later position πj if ni ↓ nj and θi(ni) = θj(ni). We also say that πj isa child of πi.

Besides the condition that ni binds nj , there is also the requirement that the look-uptables agree on their entry for the binder at ni. Node ni is labelled with λy1 . . . yp forsome p > 0 and nj is labelled with yk for some k, a situation depicted in Figure 9.

In Figure 7 node (3) binds (6) label. In the play in Figure 6 position 6 at (3) is theparent of position 25 at (6). However, position 6 is not the parent of 45 at (6) becauseθ45(3) = ((27, 29), θ3) and θ6(3) = ((25, 31), θ3); the parent of 45 is position 28.

Proposition 15. Assume π ∈ G(t, E) and nj is at a variable node. There is a uniquei < j such that πi is the parent of πj .

Proof. Assume π ∈ G(t, E), ni ↓ nj , θj(ni) = ((m1, . . . ,mp), θ) and nj is a variablenode. The first possibility is that there is not an earlier position πk at node ni withθk(ni) = θj(ni). However, the only time an entry for a binding node m enters a look-uptable is when play is at m; see the two cases @ and yj : (B1, . . . , Bp,0) of Figure 5.Therefore there must be at least one such position. Next assume that there is more thanone, πk and πk′ . So, θk(ni) = θk′(ni) = θj(ni). However, πk−1 and πk′−1 must be at thesame node (labelled with a variable or @) since m1, . . . ,mp are its successors with thesame look-up table θ; this contradicts Proposition 14.

We extend the definition of parent position to positions at lambda nodes.

Definition 22. Assume π ∈ G(t, E) and nj is a lambda node. We define πi the parentof πj by cases on the label at the node n directly above nj in the interpolation tree:

@: i = 1;f : i = j − 1;z: i is such that πi+1 is the parent of πj−1 (according to Definition 21).

For these three cases if πi is the parent of πj then nj is a successor of ni in the interpolationtree. For example, the third case is illustrated in Figure 10. Position πi is at a nodelabelled with a variable z and πj is at its kth successor; position πj−1 is at a variable ykand it is a child of position πi+1.

Page 29: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 29

λy πi+1

πi z

==

yk

}}

πj−1

πj λu

Fig. 10. Position πj is a child of the position πi

We illustrate these cases with the play of Figure 7 on the tree of Figure 6. Position 1at the root labelled @ is the parent of position 8. Position 17 at the constant node is theparent of 18. Position 27 at the variable node labelled y is the parent of 46: position 45at the variable node 6 is a child of position 28 at the lambda node 3.

Fact 16. Assume π ∈ G(t, E) and nj is a lambda node. There is a unique i < j suchthat πi is the parent of πj .

A very useful abstraction is to chain together sequences of parent child positions.

Definition 23. Assume π ∈ G(t, E) and πj is a lambda node. The sequence πj1 , . . . , πj2p

is a chain (of parent child positions) for πj if

1. πj = πj2p,

2. for 1 ≤ m ≤ p, πj2m−1 is the parent of πj2m,

3. for 1 ≤ m < p, πj2mis the position preceding πj2m+1 .

If πj1 , . . . , πj2pis a chain for πj then nj1 , . . . , nj2p

is a path (a contiguous sequence ofnodes) in the interpolation tree. For instance, in the case of the play in Figure 6 thereis the following chain for position 38 which starts at the root of the tree in Figure 6; weinclude the position, the node of the interpolation tree and its label.

1 (0)@, 4 (23)λy3, 5 (24)y3, 26 (25)λ, 27 (26)y3, 38 (29)λw1w2

Assume a position πj at a lambda node nj and a node m that occurs above nj (so,there is a path from m to nj) that is labelled with a constant, variable or @; usingFact 16, there is a unique chain πj1 , . . . , πj2p

whose first position is at m and whose lastposition is πj .

Definition 24. The look-up table θ′ extends θ, written θ ≤ θ′, if for all nodes m if θ(m)is defined then θ′(m) = θ(m).

Proposition 17. Assume π ∈ G(t, E) and nj is a lambda node. If πi is the parent of πjthen θi ≤ θj .

Page 30: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 30

Proof. Assume πi is the parent of πj when nj is a lambda node. We consider the labelof ni (which is directly above nj). If it is @ then i = 1 and θ1 ≤ θk for all k because θ1 = ∅.If it is a constant f then i = j−1 and θj = θi. The final case is a variable z of higher type,see Figure 10. So, θi+1 = θ′{((m1, . . . ,mp), θi)/ni+1} for some θ′ and where m1, . . . ,mp

are the successors of ni. Assume ni+1 is labelled λy1 . . . yp, nj−1 is labelled yk and πi+1

is the parent of πj−1: so θj−1(ni+1) = θi+1(ni+1). If yk : 0 then θj = θi and the resultholds. Otherwise yk : (B1, . . . , Bq,0) for some q and so θj = θi{((m′1, . . . ,m′q), θj−1)/nj}where m′1, . . . ,m

′q are the successors of nj−1. By Proposition 12 part 1, θi does not have

an entry for the node nj ; therefore, θi ≤ θj .

Proposition 17 also holds for the case that πi is a parent of πj when nj is a variable,which is a corollary of the next result.

Proposition 18. Assume π ∈ G(t, E) and πj1 , . . . , πj2pis a chain for πj .

1. θj1 ≤ . . . ≤ θj2p .2. If njm ↓ njn then πjm is the parent of πjn .

Proof. Assume πj1 , . . . , πj2pis a chain for πj . For 1, by Proposition 17 we know θ2m−1 ≤

θ2m, 1 ≤ m ≤ p. Moreover, since πj2k+1 is the next position after πj2kand nj2k

is a lambdanode, 1 ≤ k < p, it follows that θj2k+1 = θj2k

according to Figure 5. For 2 we use 1 andProposition 15: assume njm ↓ njn , so the parent of πjn is at node njm ; however, θjm ≤ θjnso θjm(njm) = θjn(njm).

The following is another useful consequence of the notion of chain.

Proposition 19. Assume π ∈ G(t, E), θi(m), θj(m) are both defined and θi(m) = θj(m).If m′ is a binding node above m in the interpolation tree then θi(m′) = θj(m′).

Proof. Assume π ∈ G(t, E), θi(m), θj(m) are both defined and θi(m) = θj(m) =((m′1, . . . ,m

′k), θ). By Proposition 12 node m is a binding node above ni and nj . Without

loss of generality assume ni and nj are both lambda nodes: if not then use their previousposition at a lambda node with the same look-up table. Assume m′ is a binding nodeabove m and m′ is a successor of n. Therefore, there is the chain πi1 , . . . , πi2p for πistarting at node n and there is the chain πj1 , . . . , πj2q

for πj also starting at n. Considerthe prefixes πi1 , . . . , πi2r πj1 , . . . , πj2r that end at node m. Because θi2r ≤ θi, θj2r ≤ θjand θi(m) = θj(m) it follows that θi2r

(m) = θj2r(m) = ((m′1, . . . ,m

′k), θ). Therefore,

πi2r= πj2r

; otherwise πi2r−1 and πj2r−1 are at the same node with the same look-up tablecontrary to Proposition 14. So, these prefixes are the same sequence; so, θi(m′) = θj(m′)since θi2 ≤ θi and θi2 ≤ θj .

5. Tree automata revisited

In Section 3.2 we defined tree automata following (Comon and Jurski 1997) for recognis-ing solutions of 4th-order interpolation equations. The alphabet of the automaton rangesover the variables, constants and binders of potential solution terms and the states ofthe automaton use evaluation to normal form of a node of the tree of such a term. There

Page 31: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 31

are two problems with extending the automata beyond 4th-order; first, a set of solutionsmay require an infinite alphabet; second, the set of states of the automaton may also beinfinite even when the alphabet is restricted to be finite. As mentioned in Section 3.2 wecan overcome the first problem by representing terms as binding trees.

In this section, using the game theoretic characterisation of interpolation, we definetree automata that work at all orders. There are two stages. First is a restricted result:for any interpolation equation at any order and for a fixed finite alphabet, there is aclassical tree automaton that recognises the solutions to the equation that are built fromthat alphabet. As with the game, we define the tree automata to recognise interpolationtrees of Figure 1. The second stage involves new kinds of tree automata that operate onbinding trees called dependency tree automata. The set of solutions of an interpolationequation is characterised using alternating dependency tree automata. However, the non-emptiness problem for such automata is in general undecidable as shown in (Ong andTzevelekos 2009); so, this characterisation does not lead to decidability of matching.

5.1. Variable profiles

In the game, play jumps around the interpolation tree as illustrated in Example 12. Thequestion is how to abstract from this motion statically using states of a tree automaton.Our solution is based on Ong (Ong 2006) (which is a different setting, with a fixed infinitelambda term and an alternating parity tree automaton). We break apart the motion ofjumping into and out of components into constituents using variable profiles.

Definition 25. Assume V is a finite set of variables and u : 0 is a goal term. Foreach y ∈ V , Γ(y) is the set of y profiles defined inductively: if y : 0 then Γ(y) ={(y, r, ∅) | r ∈ Sub(u)}; if y : (B1, . . . , Bp,0) then Γ(y) = {(y, r,Γ) | r ∈ Sub(u),Γ ⊆⋃

1≤i≤p⋃z:Bi∈V Γ(z)}. A mode is a pair (r,Γ) where r ∈ Sub(u) and Γ ⊆

⋃y∈V Γ(y).

Although a variable profile is defined independently of the interpolation game, it isintended, as we shall see, to be an abstraction from subsequences of positions. Considerthe play in Figure 7 on the interpolation tree of Figure 6. A z1 : 0 profile has the form(z1, r, ∅) where r ∈ Sub(u), which captures a game position at node (6) labelled z1;there are two such positions 25 and 45 with the same associated profile (z1, a, ∅). Thekey point is that there is the upper bound of the size of Sub(u) on the number of suchprofiles (which, in principle, is much smaller than an upper bound on the number of timesa play may be at a node labelled z1). In this sense a variable profile is an abstraction.A y2 : (0,0,0) profile captures positions at node (18) and has the form (y2, r,Γ′) whereΓ′ is a set of profiles for variables z : 0. Assume a position n[r]θ at a node labelled y2

and a next position n′[r]θ′. The associated profile is (y2, r,Γ′) where Γ′ is (the possiblyempty) set of associated profiles of any position that is a child of n′[r]θ′; for instance, inthe case of position 9 the corresponding profile is (y2, ga, ∅) whereas for position 31 it is(y2, a, {(s1, a, ∅)}) (as position 41 is a child of 32).

For higher-order variables such as x2 : ((0, (0,0,0),0),0) of Figure 6 the pattern ofa profile is the same. For instance, position 3 of Figure 6 has the associated profile in

Page 32: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 32

(x2, ga, { (y3, ga, {(z2, ga, {(v2, a, ∅)}), (z1, a, ∅)})(y3, a, {(z2, a, {(w1, a, ∅)}), (z1, a, ∅)})}

Fig. 11. A x2 profile for Example 12

Figure 11. There are two children of position 4, namely positions 5 and 27 at nodes (24)and (26) labelled with y3: in turn, positions 6 and 28 both have two children.

A mode is a pair (r,Γ) where r ∈ Sub(u) and Γ is a set of variable profiles. BecauseSub(u) is finite and Σ is fixed, there can only be boundedly many different modes (r,Γ).

5.2. Tree automata for interpolation at all orders

We now come to the formal definition of the tree automaton whose states are sets ofmodes. For ease of exposition, we assume well-named interpolation trees where eachoccurrence of a variable in a binder is distinct. This means that binders cannot sharevariables; for any tree which is not well-named, there is a well-named tree that is α-equivalent to it (with a larger alphabet). It is possible to avoid this assumption but atthe expense of a more complicated definition of the tree automaton.

Definition 26. Assume an interpolation equation E, xw1 . . . wk = u, a fixed finite al-phabet Σ and an interpolation Σ-tree @tw1 . . . wk where t has the form λx1 . . . xk.t

′.Let V ⊂ Σ be the variables in Σ. The Σ-tree automaton for E is AE = (Q,Σ, F,∆)where each q ∈ Q is a set of modes {(r1,Γ1), . . . , (rm,Γm)}, m ≥ 0, ri ∈ Sub(u) andΓi ⊆

⋃y∈V Γ(y), F = {{(u, ∅)}} and the transition relation ∆ is defined on nodes of the

interpolation tree by cases on its label in Σ.

a : 0; then a⇒ Λ for each Λ ⊆ {(a, ∅)}.y : 0; then y ⇒ Λ for each Λ ⊆ {(r, {(y, r, ∅)}) | r ∈ Sub(u)}.f : (A1, . . . , Ap,0); then fΛ1 . . .Λp ⇒ Λ for each Λ1, . . . ,Λp,Λ such that

(a) if (r,Γ) ∈ Λ then r = fr1 . . . rp and for each i : 1 ≤ i ≤ p there is (ri,Γi) ∈ Λi andΓ =

⋃Γi; and

(b) if (ri,Γi) ∈ Λi then there is (fr1 . . . rp,Γ) ∈ Λ and Γi ⊆ Γ.

y : (A1, . . . , Ap,0); then yΛ1 . . .Λp ⇒ Λ for each Λ1, . . . ,Λp,Λ such that

(a) if (r,Γ) ∈ Λ then there is a (y, r,Γ′) ∈ Γ and

Γ′ = { (z1, r11,Γ′11), . . . , (z1, r1m1 ,Γ′1m1

)...(zp, rp1,Γ′p1), . . . , (zp, rpmp

,Γ′pmp) }

for some z1, . . . , zp and mi ≥ 0 and for each i : 1 ≤ i ≤ p and j : 1 ≤ j ≤ mj ,(rij ,Γ′ij ∪ Σij) ∈ Λi when Γ =

⋃ ⋃Σij ∪ {(y, r,Γ′)}; and

(b) if (ri,Γi) ∈ Λi then there is a (r,Γ) ∈ Λ and (y, r,Γ′) ∈ Γ such that (zi, ri,Γ′′) ∈ Γ′

for some zi and Γ′′ ⊆ Γi and Γi − Γ′′ ⊆ Γ.

λ y; then λyΛ⇒ Λ for each Λ.

Page 33: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 33

@ : ((A1, . . . , Ak,0), A1, . . . , Ak,0); then @Λ1 . . .Λk+1 ⇒ {(u, ∅)} for each Λ1, . . . ,Λk+1

such that Λ1 = {(u,Γ)} for some Γ and

(a) if (z, r′,Γ′) ∈ Γ then z = xi for some i and (r′,Γ′) ∈ Λi+1; and

(b) if (ri,Γi) ∈ Λi+1 then (xi, ri,Γi) ∈ Γ.

A run of the automaton on an interpolation tree accumulates modes: the idea is thatpositions in a play at a node are associated with modes at that node; and vice versa.For example, if (r,Γ) is at the constant node n labelled f then r is fr1 . . . rp, for somer1, . . . , rp, and for each i, there is a mode (ri,Γi) at the ith successor ni of n so thatΓ =

⋃Γi. If (z, r′,Γ′) is a variable profile in Γ and (r,Γ) is a mode at node n then z

occurs free in the subtree rooted at n or in the subtree rooted at its successor if n islabelled λz. If (r,Γ) is at a variable node n labelled y : (A1, . . . , Ap,0) and n[r]θ is itsassociated position in a play, then there is a variable profile (y, r,Γ′) ∈ Γ such that Γ′ isthe set of variable profiles associated with the children of the next position in the play:this position is at a lambda node labelled λz1 . . . zp for some z1, . . . , zp. In the case of thetransition for @, there is a single mode (u, ∅) at the root of the interpolation tree andthere is a single mode (u,Γ) at its first successor (the root of t labelled λx1 . . . xk); eachvariable profile in Γ is of the form (xi, ri,Γi) representing a later position in a play m[ri]θ′

at a node m labelled xi and so (ri,Γi) is therefore a mode at the (i + 1)th successor ofthe root (the root of wi) as play jumps from m to this node.

Example 13. We describe the automaton for Example 8 (which should be comparedwith the Comon and Jurski tree automaton of Example 9). A potential solution termsuch as the one depicted in Figure 2 has the form λx1x2.w. So the alphabet Σ is theset {a, b, f, x1, x2, y1, y3, λ, λy3, λy1y2, λx1x2}. The variable set V is {x1, x2, y1, y3} andSub(faa) = {faa, a}. A mode is (r,Γ) where r ∈ Sub(u) and Γ is a set of variable profiles.Next, we consider the transitions, first for constants.

a⇒ Λ ⊆ {(a, ∅)} b⇒ ∅ f ∅ ∅ ⇒ ∅

f{(a,Γ1)} {(a,Γ2)} ⇒ {(faa,Γ1 ∪ Γ2)}The last rule allows f to be labelled with the state {(faa,Γ1 ∪ Γ2)} when its successorsare labelled with the states {(a,Γ1)} and {(a,Γ2)}. The transitions for variables y1 andy3 of type 0 are as follows.

y1 ⇒ Λ ⊆ {(faa, {(y1, faa, ∅)}), (a, {(y1, a, ∅)})}

y3 ⇒ Λ ⊆ {(a, {(y3, a, ∅)})}It is unnecessary to include (faa, {(y3, faa, ∅)}) as a mode because it could never ap-pear within a state of an accepting run of the automaton. The rules for x1 and x2

are more interesting. Assume Γ′ is {A(x1), A′(x1), A(x2)} where A(x1) is the profile(x1, faa, {(y1, faa, ∅)}), A′(x1) is (x1, a, {(y1, a, ∅)}) and A(x2) is (x2, faa, {(y3, a, ∅)}).

x1 ∅ ∅ ⇒ ∅ x2 ∅ ⇒ ∅

x2{(a,Γ)} ⇒ {(faa,Γ ∪ {A(x2)})} Γ ⊆ {A′(x1)}

Page 34: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 34

x1 {(a,Γ)} ∅ ⇒ {(a,Γ ∪ {A′(x1)})} Γ ⊆ {A′(x1)}

x1 {(faa,Γ)} ∅ ⇒ {(faa,Γ ∪ {A(x1)})} Γ ⊆ Γ′

A variable occurrence x1 can be labelled with the state {(faa,Γ′′)} provided that A(x1) ∈Γ′′ and its first successor is labelled {(faa,Γ)} such that Γ∪{A(x1)} = Γ′′. Finally, thereare the rules for the λ’s and @.

λ Λ⇒ Λ λx1x2 Λ⇒ Λ

λy1y2 Λ⇒ Λ λy3 Λ⇒ Λ

@ {(faa,Γ)} Λ1 Λ2 ⇒ {(faa, ∅)} if (1)

where (1) is the condition: A(x1) ∈ Γ iff (faa, {(y1, faa, ∅)}) ∈ Λ1, A′(x1) ∈ Γ iff(a, {(y1, a, ∅)}) ∈ Λ1 and A(x2) ∈ Γ iff (faa, {(y3, a, ∅)}) ∈ Λ2. Using these rules, it iseasy to show that the tree of Figure 2 is accepted. The rules for x1 allow “pumping” inthe sense of (Dowek 1994): the automaton accepts the interpolation tree when t is anyterm of the form λx1x2.x1(x1 . . . x1(x2(x1 . . . x1ab)b . . .) . . .)b.

Theorem 20. Assume E is the interpolation equation xw1 . . . wk = u and Σ is a fixedfinite alphabet. If @tw1 . . . wk is a well-named Σ-tree then the automaton AE accepts@tw1 . . . wk iff t solves E.

Proof. Let E be xw1 . . . wk = u and assume @tw1 . . . wk is a well-named Σ-tree. Let tbe a solution to E. Therefore, player ∀ loses G(t, E). We show how to build an acceptingrun of AE on @tw1 . . . wk. The main construction is to transform each position n[r]θ intoa mode (r,Γ) at n in the successful run; consequently, the set of all positions at a nodeis transformed into a state of the automaton. The construction starts from leaf nodes of@tw1 . . . wk. If n is labelled a : 0 then the state of the successful run at this node is either{(a, ∅)} if there is a position n[a]θ or ∅ if there is no such position. These both obey theconditions on a transition in Definition 26. If n is labelled y : 0 then the state of the suc-cessful run at this node is {(r, {(y, r, ∅)}) | there is a position n[r]θ of a play in G(t, E)}.Again, this obeys the transition condition. Next we consider the general case of an arbi-trary node n of @tw1 . . . wk. If n is labelled λy and n[r]θ is a position then as the nextposition in the play is n1[r]θ the automaton state at n1 includes a mode (r,Γ); therefore,the state at n is that at n1 as required by the transition rule for λy of Definition 26. Ifn is labelled f : (A1, . . . , Ap,0) then because t solves E every position at n has the formn[fr1 . . . rp]θ and every subsequent position has the form ni[ri]θ for 1 ≤ i ≤ p; therefore,for each such position at n there is a mode (fr1 . . . rp,Γ) where Γ =

⋃Γi such that

(ri,Γi) is a mode at ni. So, the conditions for a f transition in Definition 26 are fulfilled.If n is labelled y : (A1, . . . , Ap,0) and n[r]θ is a position then any child of this positionis at ni for some i; conversely, any position at ni has a parent at n. Assume positionn[r]θ. We associate the mode (r,Γ) with it as follows. Consider the next position n′[r]θ′

at n′ labelled with λz1 . . . zp for some z1, . . . , zp. Assume all the children of n′[r]θ′ are as

Page 35: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 35

follows

{ m11[r11]θ11, . . . ,m1l1 [r1l1 ]θ1l1...mp1[rp1]θp1, . . . ,mplp [rplp ]θplp }

where each mij is labelled with zi. The next position of each mij [rij ]θij is ni[rij ]θ′ij :associated with it is the mode (rij ,Γ′ij ∪ Σij) where if ni is labelled λs1 . . . sq then Γ′ijis the set of variable profiles for each si′ (and Σij does not contain any such profiles).Therefore, (r,Γ) is the mode at n such that (y, r,Γ′) ∈ Γ and Γ =

⋃Σij ∪{(y, r,Γ′)} and

Γ′ is

{ (z1, r11,Γ′11), . . . , (z1, r1l1 ,Γ′1l1

)...(zp, rp1,Γ′p1), . . . , (zp, rplp ,Γ

′plp

) }

Now this is repeated for every position at n; it follows that the conditions for a transi-tion at n are thereby obeyed. If n is labelled @ then there is the single initial positionn[u]θ1 at n; its associated mode is (u, ∅). There is also just a single position at n1 withcorresponding mode (u,Γ); for each child of this position, by construction, there is acorresponding variable profile (xi, ri,Γi) such that there is a child of n[u]θ1 at n(i + 1)whose corresponding mode is (ri,Γi). We leave the reader to check the details.

Assume AE accepts @tw1 . . . wk but t does not solve E. We derive a contradiction.There is, therefore, a play π = π1, . . . , πl of G(t, E) that ∀ wins. As there is a successfulrun of AE on @tw1 . . . wk we are interested in modes that are associated with positionsin π at the same nodes; for the initial position there is the associated mode (u, ∅); forthe penultimate position πl−1 either nl−1 is labelled with a : 0 and rl−1 6= a or nl−1 islabelled with f and rl−1 does not have the form fr′1 . . . r

′p; therefore, there cannot be a

mode in the successful run of AE at nl−1 that corresponds to this position because itwould violate the transition rules of Definition 26. Therefore, consider the latest positionnj [rj ]θj in π for which there is a corresponding mode (rj ,Γj) at nj in the acceptingrun of AE . We now examine the label at nj ; it cannot be a constant a, f , @ or a λy.Therefore, it must be a variable y. There is at least one variable profile (y, rj ,Γ′′) ∈ Γjas (rj ,Γj) is a corresponding mode at nj , by the transition rule for a variable y inDefinition 26. Consider the next position πj+1 at nj+1 labelled λz for some z. So, foreach profile (y, rj ,Γ′) ∈ Γj , (rj ,Γ′′) is not a mode at nj+1. Assume πi is the parent ofπj , so ni is labelled λy. There is a corresponding mode (ri,Γi) to this position such that(y, rj ,Γ′′) ∈ Γi: node ni occurs above nj ; as the interpolation tree is well-named, theonly way the variable profile (y, rj ,Γ′′) would not occur in Γi is if the binder for y occursbelow ni, as can be seen by examining the transition rules for AE . If y is level 1 in t,so, y = xm for some m, then ni is the root of t; so, nj+1 is the (m + 1)th successor ofthe root and (rj ,Γ′′) corresponds to position πj+1 is a mode at nj+1 by the transitionrule for @. Otherwise, πj+1 is a child of πi−1 and ni−1 is labelled with a variable s andthe result follows by considering the corresponding mode for πi−1 which must contain(s, ri−1,Γ′′′) with (y, rj ,Γ′′) ∈ Γ′′′ and therefore (rj ,Γ′′) is a mode at node nj+1.

Page 36: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 36

5.3. Dependency tree automata

The question is how to extend Thereom 20 and overcome the restriction to the finitealphabet Σ. First, we represent terms as binding trees as defined in Section 3.1. Next, weintroduce a special kind of tree automaton that can recognise binding trees that we calldependency tree automata. These are a top-down tree automaton (unlike the previoustree automata) that start at the root of the tree and work down to the leaves; the maindifference is that the transition rules are therefore reversed, of the form sq ⇒ q1 . . . qk: ifs has arity k and state q labels a node labelled s then q1, . . . , qk can label its successors;compare Definition 14 and see (Comon et al 2002).

Definition 27. A dependency Σ-tree automaton A = (Q,Σ, q0,∆) where Q is a finiteset of states, Σ is the finite alphabet (Σ = Σ1 ∪ Σ2 ∪ Σ3 where Σ1 are the binders, Σ2

the bound variables and Σ3 the remaining symbols), q0 ∈ Q is the initial state and ∆ isa finite set of transition rules each of which has one of the following three forms.

1. qs⇒ (q1, . . . , qk) where s ∈ Σ2 ∪ Σ3, ar(s) = k, q, q1, . . . , qk ∈ Q;2. qs⇒ q′s′ where s ∈ Σ1, s′ ∈ Σ3 and q, q′ ∈ Q;3. (q′, q)s⇒ q1x where s ∈ Σ1, x ∈ Σ2 and q′, q, q1 ∈ Q.

Definition 28. A run of A = (Q,Σ, q0,∆) on t ∈ TΣ is a (Σ × Q)-tree whose nodesare pairs (n, q) where n is a node of t and q ∈ Q labelled (s, q) if n is labelled s in t

which is defined top-down with root (ε, q0) where ε is the root of t. Consider a node (n, q)labelled (s, q) of a partial run tree which does not have successors. If s ∈ Σ2 ∪ Σ3 andqs ⇒ (q1, . . . , qk) ∈ ∆ then the successors of (n, q) are the nodes (ni, qi), 1 ≤ i ≤ k.If s ∈ Σ1, n1 is labelled s′ ∈ Σ3 and qs ⇒ q′s′ ∈ ∆ then (n1, q′) is the successor of(n, q). If s ∈ Σ1, n1 is labelled x ∈ Σ2, m ↓ n1 in t, (m, q′) occurs above or at (n, q) and(q′, q)s⇒ q1x ∈ ∆ then (n1, q1) is the successor of (n, q). A accepts the Σ-tree t iff thereis a run of A on t such that if (n, q) is a leaf then n is a leaf of t. Let TΣ(A) be the setof Σ-trees accepted by A.

A dependency tree automaton A has a finite set of states Q and transitions ∆ (whichcan be nondeterministic). A run of A on a Σ-tree t adds an additional Q labelling to (asubtree of) t as we described in Section 3.2: so, it is a (Σ×Q)-tree. It starts with (ε, q0)where ε is the root of t and q0 is the initial state of A. Subsequent nodes are derivedby percolating states down t. The state at a node that is labelled with a variable notonly depends on the state of its immediate predecessor but also on the state of the nodethat labels its binder. This introduces non-local dependence in the automaton (hence thename). A run on t is accepting if it is complete in the sense that each node of t is labelledwith an element of Q: if (n, q) is a leaf of the run tree then n is a leaf of t.

Dependency tree automata were partly inspired by nested word and tree automata(Alur and Madhusudan 2006; Alur, Chaudhuri and Madhusudan 2006) which are also anamalgam of a traditional automaton and a binary relation ↓ on nodes of the (possiblyinfinite) word or tree. However, in that setting ↓ represents nesting such as provided bybracketing and useful for modelling procedure calls and returns. Nesting involves naturalrestrictions on the relation ↓ such as “no-crossings”: if m1 ↓ m2 and n1 ↓ n2 and m1

Page 37: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 37

is above n1 then either m2 is above n1 or n2 is above m2. Such restrictions are notappropriate when modelling binding, for instance as with a formula ∀f.∃x.φ(f(x)).

Theorem 21. Assume A, A1 and A2 are dependency Σ-tree automata and n is the sizeof A

1. The non-emptiness problem, given A is TΣ(A) 6= ∅?, is decidable in order n4 time.2. Given A1 and A2, there is an A such that TΣ(A) = TΣ(A1) ∩ TΣ(A2).3. Given A1 and A2, there is an A such that TΣ(A) = TΣ(A1) ∪ TΣ(A2).

Proof. Assume A = (Q,Σ, q0,∆) is a Σ-tree automaton and Σ = Σ1 ∪ Σ2 ∪ Σ3 whereΣ1 are the binders, Σ2 the variables and Σ3 the other symbols. Let depth(t) be thedepth of the Σ-tree t and |S| be the size of the finite set S. We show that if TΣ(A) 6= ∅then A accepts a Σ-tree t such that depth(t) ≤ (|Σ1||Q| + 1)(|Σ||Q| + 1). If A accepts tand depth(t) > l(|Σ||Q| + 1) then in the accepting run of A on t there are l nodes of t,n1, . . . , nl with the same label in Σ and labelled with the same state q ∈ Q such thateach ni occurs above nj when i < j. Let B(i, j), where 1 ≤ i < j ≤ l, be the set ofpairs binders a ∈ Σ1 and states q′ ∈ Q such that there is a node n′ between ni and nj(excluding nj) labelled with a and q′ in the successful run of A on t such that there isan edge n′ ↓ n′′ where n′′ is nj or occurs below it in t. Also, let U(i) be the set of pairsbinders a ∈ Σ1 and states q ∈ Q such that there is a node n′ above ni in t labelled witha and q in the successful run of A on t. Clearly, if B(i, j) ⊆ U(i) then there is a smallerΣ-tree t′ which is accepted by A: the subtree at node ni is replaced with the subtree at njand any edge n′ ↓ n′′ where n′′ is nj or below it and n′ is between ni and nj (excludingnj) is replaced with an edge n ↓ n′′ where n is the node above ni labelled with the samebinder and state as n′. Clearly, if A accepts t then it accepts t′. By simple counting,there must be an i, j with 1 ≤ i < j ≤ (|Σ1||Q|+ 1) such that B(i, j) ⊆ U(i). Therefore,non-emptiness is decidable in at most order n4. The other parts of the theorem followfrom the usual product and disjoint union of automata (extended here with the bindingrelations).

We now extend the definition to alternating dependency tree automata.

Definition 29. An alternating dependency Σ-tree automaton A = (Q,Σ, q0,∆) is as inDefinition 27 except for the first clause for transitions which is now

1. qs⇒ (Q1, . . . , Qk) where s ∈ Σ2 ∪ Σ3, ar(s) = k, q ∈ Q and Q1, . . . , Qk ⊆ Q.

Definition 30. A run of an alternating dependency Σ-automaton A = (Q,Σ, q0,∆) ont ∈ TΣ is a (Σ×Q)-tree whose nodes are pairs (n, α) where n is a node of t and α ∈ Q∗ isa sequence of states, labelled (s, q) if n is labelled s in t and α = α′q which is defined top-down with root (ε, q0) where ε is the root of t. Consider a node (n, α) labelled (s, q) of apartial run tree which does not have successors. If s ∈ Σ2∪Σ3 and qs⇒ (Q1, . . . , Qk) ∈ ∆then the successors of (n, α) are {(ni, αq′) | 1 ≤ i ≤ k and q′ ∈ Qi}. If s ∈ Σ1, n1 islabelled s′ ∈ Σ3 and qs⇒ q′s′ ∈ ∆ then (n1, αq′) is the successor of (n, α). If s ∈ Σ1, n1is labelled x ∈ Σ2, m ↓ n1 in t, (m,α′q′) occurs above or at (n, α) and (q′, q)s⇒ q1x ∈ ∆then (n1, αq1) is the successor of (n, α). A accepts the Σ-tree t iff there is a run of A on

Page 38: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 38

t such that if (n, αq) is a leaf labelled (s, q) of the run tree then either s has arity 0 orqs⇒ (∅, . . . , ∅) ∈ ∆. Let TΣ(A) be the set of Σ-trees accepted by A.

A run of an alternating automaton on a Σ-tree t is itself a tree built out of the nodesof t and sequences of states Q+. There can be multiple copies of nodes of t within a runbecause a transition applied to a node n qs⇒ (Q1, . . . , Qk) spawns individual copies atni for each state in Qi. These automata are alternating as each set Qi can be viewed asthe conjunct

∧q∈Qi

q and nondeterminism provides the disjuncts.Classically, nondeterministic and alternating tree automata accept the same families of

trees and the non-emptiness problem for alternating automata is decidable in exponentialtime (Comon et al 2002). However, this is not the case for dependency tree automata;the non-emptiness problem for alternating dependency tree automata is undecidable asshown in (Ong and Tzevelekos 2009); the proof encodes the observational equivalenceproblem for finitary PCF in terms of nonemptiness of such automata; this problem isundecidable (Loader 2001A).

We now describe how alternating dependency automata characterise solutions to in-terpolation problems. Because of the binding relation, we can fix a finite alphabet Σ (asdescribed in Section 3.1). Again we appeal to variable profiles.

Definition 31. Assume the associated binding tree for the interpolation equation E,xw1 . . . wk = u, Σ is its alphabet. The alternating dependency tree automaton is AP =(Q,Σ, q0,∆) where Q is the set of modes (ri,Γi), ri ∈ Sub(u), q0 = (u, ∅) and thetransition relation ∆ is defined on nodes of the binding Σ-tree by cases on Σ.

1. (u, ∅)@⇒ ({(u,Γ)},Σ1, . . . ,Σk) where Σi = {(rij ,Γij ) | (xi, rij ,Γij ) ∈ Γ}2. ((r,Γ), (r′,Γ′))λy ⇒ (r′,Σ)zi if (zi, r′,Σ) ∈ Γ3. (fr1 . . . rk,Γ)λy ⇒ (fr1 . . . rk, ∅)f4. (a, ∅)λy ⇒ (a, ∅)a5. (r,Γ)zj ⇒ (Q1, . . . , Qk) if Qi = {(r′,Γ′) | (yi, r′,Γ′) ∈ Γ} for each i : 1 ≤ i ≤ k and

ar(zj) = k > 06. (fr1 . . . rk, ∅)f ⇒ ({(r1, ∅)}, . . . , {(rk, ∅)})

The root of the interpolation tree labelled @ has k+ 1 successors, the first of which ist of the form λx1 . . . xk.t

′ and the (i + 1)th wi. The automaton starts with state (u, ∅)at @ and then a family of variable profiles Σi each of the form (xi, rij ,Γij ) is chosen foreach i : 1 ≤ i ≤ k. The state at the node labelled λx1 . . . xk is then (u,

⋃Σi) and then

for each i and for each j there is the state (rij ,Γij ) at the (i + 1)th successor of @; thesame node of the interpolation tree is repeated. Assume the current state is (r′,Γ′) atnode n of the interpolation tree labelled λy. If n1 is labelled with variable zi and m ↓ n1then m is labelled λz1 . . . zp for some p and the state above (r′,Γ′) at m has the form(r,Γ) where Γ is a set of profiles for each zj , 1 ≤ j ≤ p. One of the zi profiles, (zi, r′,Σ)where the right term r′ is as in the state at n is chosen and state (r′,Σ) labels n1. Ifn1 is labelled f then for the automaton to proceed from node n to n1, r′ must have theform fr1 . . . rk. In which case n1 is labelled with state (r′, ∅). Similarly, if n1 is labelledwith the constant a : 0 then r′ must be a and Γ′ = ∅. If the state is (r,Γ) at node nof the interpolation tree and n is labelled zj with arity p > 0 then Γ consists of sets of

Page 39: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 39

yi profiles, 1 ≤ i ≤ p for some y1, . . . , yp. For each yi profile (yi, r′,Γ′) the automatonspawns a copy at ni with state (r′,Γ′). Finally, if the state is (fr1 . . . rk, ∅) at node n ofthe interpolation tree labelled with f then the automaton proceeds down each successorni with state (ri, ∅).

The proof of the following characterisation result is very similar to Theorem 20, so weomit it here.

Theorem 22. Assume E is the interpolation equation xw1 . . . wk = u and Σ is a fi-nite alphabet. If @tw1 . . . wk is a binding Σ-tree then the alternating dependency Σ-treeautomaton AE (of Definition 31) accepts @tw1 . . . wk iff t solves E.

6. Decidability

In this section we prove decidability of higher order matching; the proof essentially de-pends on the game theoretic characterisation of interpolation. The main theorem, The-orem 37 of Section 6, is a small solution property: if an interpolation problem has a(canonical) solution then it has a small solution that is bounded in the size of the prob-lem.

6.1. Uniformity properties of game playing

We now examine further properties of game playing and, in particular, repeating patternsof sequences of positions that build on properties described in Sections 4.2 and 4.3.

First, we isolate a key technical property of multiple child positions; see Definitions 21and 22 for when a position is the parent of another position.

Proposition 23. Assume π ∈ G(t, E) and j < m. If πi is the parent of πj and πm thenthere is a k : j < k < m such that πj is the parent of πk.

Proof. We start with the case where ni is a lambda node that binds both nj and nmand πi is the parent of both πj and πm. So, by Definition 21, πi(ni) = ((m1, . . . ,mp), θl)= πj(ni) = πm(ni) for some m1, . . . ,mp and for some l < i by Proposition 12. Positionπj+1 is at mq for some q and θj+1 = θl{((n1, . . . , nr), θj)/mq} where n1, . . . , nr are thesuccessors of nj . The look-up table θl does not have an entry for ni (because the movefrom nj to nj+1 is a jump from t into some ws or vice-versa, and so ni cannot occurabove nj+1). If play does reach a variable node bound with a binder at nb whose entryis in θl, say θl(nb) = (((m′1, . . . ,m

′a), θc) then c < l. θc cannot have an entry for ni of the

form ((n1, . . . , nr), θj); for suppose it does then there there is a position πd at ni beforeposition πi such that πd−1 and πi−1 are at the same node with the same look-up tablewhich contradicts Proposition 14. Therefore, the only opportunity to reach position πmwith its look-up entry for ni is after a position bound by mq; that is, a position that isa child of πj .

We next consider the cases where πi is the parent of πj and πm according to Defini-tion 22, when nj and nm are lambda nodes. We now proceed by cases on the label at ni.@ : then nj and nm are root nodes of t or wq. Without loss of generality assume nj is

Page 40: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 40

the root of t. There is a first position πk after πj (and before πm) such that πk+1 is theresult of a jump from t into some wp; otherwise, πm could not be at the root of t or wq.Therefore, πj is the parent of πk. f : this case cannot arise as πi has at most one child.y : therefore, πi+1 is the parent of πj−1 and of πm−1. Therefore, by the first part of theproof, πj−1 is the parent of some πk+1 (before πm−1); however, this means that πj is theparent of πk as required.

In the play of Figure 7 on the tree of Figure 6, position 2 is the parent of positions 3and 11; in this case position 3 is the parent of 6. Also, position 5 is the parent of 16 and26; position 19 is a child of 16.

We now introduce interval notation on plays: π[i, j] is the sequence of positions πi, . . . , πj .Intervals correspond when they pass through the same sequence of nodes.

Definition 32. Assume π ∈ G(t, E). Two intervals π[i, i+m] and π[j, j+m] correspondif ni+k = nj+k for each k : 0 ≤ k ≤ m.

We now present the key uniformity property when there are corresponding intervalswith almost the same look-up tables.

Proposition 24. Assume π ∈ G(t, E), πi is the parent of πj , πm, j < m, nj , nm areboth labelled with the same variable and nj 6= nm. There is a k such that π[j + 1, j + k]and π[m+ 1,m+ k] correspond and

1. (a) πj is the parent of πj+k+1 and πm is the parent of πm+k+1, and (b) nj+k+1 isthe pth successor of nj iff nm+k+1 is the pth successor of nm, or

2. nj+k is labelled with a constant and (a) πm+k is the final position of π or (b)nj+k+1 6= nm+k+1.

Proof. Assume πi is the parent of πj , πm and nj , nm are labelled with the samevariable. Therefore, θi(ni) = θj(ni) = θm(ni) = ((m1, . . . ,mp), θl) for some m1, . . . ,mp

and l < i. As nj and nm are labelled with the same variable yq, nj+1 = mq = nm+1,θj+1 = θl{((nj1, . . . , njr), θj)/mq} and θm+1 = θl{((nm1, . . . , nmr), θm)/mq} for somer. So, positions πj+1, πm+1 correspond as do their continuations because θj+1, θm+1

have the same entries except for mq. There are two possibilities. First that play reachesπj+k and mq ↓ nj+k (and nm+k = nj+k); so, πj+k+1 is a child of πj and πm+k+1 is achild of πm; moreover, nj+k+1 is the qth successor of nj iff nm+k+1 is the qth successorof nm. Second is that play reaches πj+k and nj+k is labelled with a constant f ; alsonm+k = nj+k and either πm+k is the final position of π or nj+k+1 is a different successorthan nm+k+1 of nj+k.

The conditions described in this Proposition are now used in the following definition.

Definition 33. Assume π ∈ G(t, E) and nj , nm are both labelled with the same variablefor j < m. We say that π[j + 1, j + k] and π[m+ 1,m+ k] are complementary intervalsif 1 or 2 of Proposition 24 holds.

This definition does not require positions πj and πm to have a common parent.

Page 41: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 41

In the play of Figure 12 on the tree of Figure 6, π[6, 15] and π[28, 37] are complemen-tary; first, these intervals correspond; nodes (24) and (26) at positions 5 and 27 are bothlabelled with y3; position 5 is a parent of 16 and 27 is a parent of 38; finally, the nodeat position 16 is the second successor of the node at position 5, and also the node atposition 38 is the second successor of the node at position 27.

To apply these properties, first we structurally identify particular nodes of interpolationtrees.

Definition 34. Assume an interpolation tree @tw1 . . . wk. A variable node in this treeis level 1 if it is bound by the root of t or wq for some q. A variable node is level j + 1 ifit is bound by a successor node of a level j node.

4th or 5th order interpolation trees contain at most two levels of node. In Figure 6 nodessuch as (2) or (24) are level 1 whereas (12) and (34) are level 2. In the general case, a 2nor 2n+ 1 interpolation tree can contain level k nodes for k : 1 ≤ k ≤ n.

Definition 35. Assume n′ ↓ n, n′ ↓ m and n, m are distinct nodes of an interpolationtree labelled with the same variable. Node m is embedded if m occurs below n in the tree.

In Figure 6, node (8) is embedded because it is below (4) and both (1) ↓ (4) and (1) ↓ (8);node (26) is also embedded since (23) ↓ (24) and (23) ↓ (26).

Definition 36. Assume n, m are variable nodes of an interpolation tree.

1. n is a descendant under binding of m (m is an ancestor under binding of n) if m = n

or m′ is a successor of m, m′ ↓ n′ and n is a descendant under binding of n′.2. n and m belong to the same family if they have a common ancestor under binding.3. n is end if it has no descendants under binding except itself.

Node (2) of Figure 6 is an ancestor under binding of (6) and (12). Nodes (4) and (16)belong to the same family (but (8) and (12) do not). Node (8) is an example of an endnode (because there are no nodes bound by (11)).

We now examine some further uniformity features in plays of a game. The first followsfrom Proposition 23.

Fact 25. Assume π ∈ G(t, E). If ni is end then there is at most one position πj , j > i,that is a child of πi.

The next property follows from Proposition 24.

Fact 26. Assume π ∈ G(t, E), and nj , nm are level 1 nodes in t labelled with the samevariable. Then there is a k such that π[j+1, j+k] and π[m+1,m+k] are complementary.

In the play π of Figure 7 on the tree in Figure 6, π7 and π11 are at level 1 nodes labelledwith x1. Here π[8, 9] and π[12, 13] are complementary (with π10 a child of π7 and π14 achild of π11).

The next property concerns embedded nodes and is a consequence of Propositions 23and 24.

Page 42: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 42

Fact 27. Assume π ∈ G(t, E), n, m are labelled with the same variable, m is below thepth successor of n in the interpolation tree and nj = m. Then there is an i and k suchthat

1. ni = n, π[i+ 1, i+ k] and π[j + 1, j + k] are complementary, and2. if n,m are end and [ri+1] = [ri+k] then nj+k+1 is the pth successor of nj .

Node (26) in the tree in Figure 6 is an embedded node because of (24) and position27 in the play π of Figure 7 is at (26). There is an earlier position 5 at 24 and π[6, 15]and π[28, 37] are complementary.

Next, we examine a feature of chains; recall that a chain πj1 , . . . , πj2p is a sequence ofparent child positions, Definition 23. We are mostly interested in chains of an interpola-tion tree @tw1 . . . wk when nj1 , . . . , nj2p

is a path in some wq.

Proposition 28. Assume π ∈ G(t, E), πj is a position in wq for some q and πj1 , . . . , πj2p

is a chain for πj . If πj2k−1 and πj2m−1 are positions in t, 1 ≤ k ≤ m ≤ p, then nj2k−1

and nj2m−1 belong to the same family.

Proof. Let πj1 , . . . , πj2p be a chain for πj where π ∈ G(t, E) and nj is in wq. Assumethat πj2k−1 and πj2m−1 are positions in t, 1 ≤ k ≤ m ≤ p. We show that nj2k−1 andnj2m−1 belong to the same family. First, both are variable nodes since nj2k

and nj2m

are in wq. Let πi1 , . . . , πi2r, πj1 , . . . , πj2p

be the chain for πj where ni1 the successor ofthe root node of wq for some r ≥ 0. So, the position πi1−1 is at the root of wq and theprevious position πi1−2 is at a level 1 node n of t; it is straightforward to see that n isan ancestor under binding of both nj2k−1 and nj2m−1.

We also want to consider chains that start from a particular node in wq. To help withthis we define a special kind of chain.

Definition 37. Assume π ∈ G(t, E). The chain πj1 , . . . , πj2pfor πj has the recurrence

property if for each i : 1 ≤ i ≤ p, if nj2i−1 is a variable node then there is a j < j2i−1 anda k such that π[j + 1, j + k] and π[m + 1,m + k] are complementary where m = j2i−1

and j2i = m+ k + 1.

Proposition 29. Assume π ∈ G(t, E) and ni is a variable or constant node in wq forsome q. Then there is a largest p ≥ 0 such that πj1 , . . . , πj2p

is a chain with the recurrenceproperty where i = j1.

Proof. Let π ∈ G(t, E) and ni be a variable or constant node in wq for some q. Assumewe have so far constructed a chain πj1 , . . . , πj2r

with the recurrence property where r ≥ 0and i = j1. We let πi′ = πi if r = 0 and otherwise πi′ = πj2r+1 at the successor node ofnj2r

. Consider the first position after πi′ , if there is one, which is a child of πi′ . If there isno such position then p = r. Otherwise πj′ is this position. If ni′ is a constant node thenπj′ = πi′+1; therefore we can (uniquely) extend the chain with πi′ , πj′ and the argumentis then repeated for πi′ = πj′+1. If ni′ is a variable node then we consider any previousposition πl at a node labelled with the same variable and examine whether π[l+ 1, l+ k]and π[i′ + 1, i′ + k] when k + 1 = j′ − i′ are complementary; if there is such an l thenwe can (uniquely) extend the chain with πi′ , πj′ and the argument is then repeated for

Page 43: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 43

πi′ = πj′+1; if there is no such πl then p = r. As nj1 , . . . , nj2ris a path in wq, the size of

p in this contruction is bounded by the depth of wq.

6.2. Two transformations

We now define two local transformations on terms that preserve being a solution to aninterpolation equation. A transformation T of t has the form t[s/n] where s : 0 is alsoa term and n is a node of t labelled with a variable or a constant: this transformationproduces the term t′ which is the result of replacing the subtree rooted at n in t with s;we assume that if t : A is closed then t′ has type A and is also closed; we write tT t′ if t′

is the result of applying T to t.For the first transformation, we remind the reader of Definition 10 of the constant b : 0

(which does not occur in the goal term of the interpolation equation).

Definition 38. Assume the game G(t, E) and n is a variable node or a constant node la-belled with some f : A 6= 0 of t. If for every π ∈ G(t, E) and i, ni 6= n then transformationT1 is t[b/n].

If there is not a position of any play π ∈ G(t, E) at the variable or constant node nthen it is inaccessible in the sense described in Section 3.2; the subtree rooted at n doesnot contribute to the normal form and therefore can be replaced. Application of thistransformation either reduces the number of nodes or the number of variable nodes of aterm.

Fact 30. If t solves E and tT1t′ then t′ solves E.

The second transformation uses the notion of an end path which generalises Defini-tion 36 of end node.

Definition 39. The path m1, . . . ,m2p is end in t if

1. m1 is a variable node,2. for each i : 1 < i ≤ p, m2i−1 is a variable node whose binder occurs in the path,3. every variable node below m2p in t is bound by a node that either occurs above m1

or below m2p in t.

For instance, the path (8), (11) in Figure 6 is end because node (11) does not bindnodes below it in t (and, so, all the variable nodes (12), (14) and (16) below (11) arebound above (8) or below (11) in t).

We define when an end path of nodes in t is redundant in the game G(t, E); whichappeals to a notion of contribution towards a solution (of an interpolation equation).

Definition 40. Assume π ∈ G(t, E) and nj is a lambda node. The interval π[i, j] con-tributes if [ri] 6= [rj ].

An interval that contributes must contain a position at a constant node. However, notall intervals with constant nodes contribute since the definition applies only to intervalswhose last position is at a lambda node; in particular, an interval whose final position isat a constant node does not contribute.

Page 44: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 44

Definition 41. Assume γ = m1, . . . ,m2p is an end path in t.

1. γ is redundant in the interval π[i, k] of π ∈ G(t, E) when: if πj1 , j1 < k, is the firstposition after πi with nj1 = m1 then

(a) there is a later position πj , j ≤ k, and a chain πj1 , . . . , πj2pfor πj where nj = m2p,

(b) π[j1, j] does not contribute, and

(c) γ is redundant in the interval π[j, k].

2. γ is redundant in the game G(t, E) if γ is redundant in every play π[1, l] (where πl isthe final position of π).

The end path m1, . . . ,m2p is redundant in the interval π[i, k] of π ∈ G(t, E) if noposition in this interval is at m1, or there is a first position πj1 at m1 and a later positionπj at m2p such that there is a chain πj1 , . . . , πj2p for πj , π[j1, j] does not contribute(so, the states [rj1 ] and [rj ] are the same) and the end path is redundant in the smallerinterval π[j, k]. It is redundant in G(t, E) if for each π ∈ G(t, E) it is redundant for thecomplete play interval π[1, l].

Definition 42. Assume the end path m1, . . . ,m2p is redundant in G(t, E). If t′ is thesubterm whose root is the successor node of m2p then transformation T2 is t[t′/m1].

This transformation disposes of the path m1, . . . ,m2p in t (and all paths below mi thatdo not pass through m2p) by replacing the subtree at m1 with t′ that is rooted at thesuccessor of m2p: this preserves being a closed term (of the right type) because all freevariable occurrences in t′ are bound above m1 in t. Application of this transformationreduces the size of a term.

Proposition 31. If t solves E and tT2t′ then t′ solves E.

Proof. Assume that t solves E, the end path m1, . . . ,m2p is redundant in G(t, E), t′

is the subtree rooted at the successor of m2p and t1 = t[t′/m1]. We show that t1 solvesE. First, t1 is a closed term with the same type as t: by the definition of end path, ifnode m occurs below m2p in t and n ↓ m then either n occurs above m1 or below m2p.We next show that ∀ loses the game G(t1, E). We assume that the nodes in t1 retain thesame names as in t. Consider any play π ∈ G(t, E). Assume πi1 is the first position in π

at m1, if there is one. By Definition 41, there is a later position πk1 at m2p and a chainπj1 , . . . , πj2p

for πk1 where j1 = i1. Therefore, by repeated application of Definition 41, πcan be decomposed into subintervals σ1, π[i1, k1], σ2, . . . , π[iq, kq], σq+1 for q ≥ 0, whereeach σj is an interval, πir is the first position in π after πkr−1 at m1 and πkr

is at m2p

(and there is a chain for πkr that starts at πir ). No interval π[ir, kr] contributes and noposition in any interval σj is at m1.

Next, we show that if there is a position in some σl that is below m1 then it is belowm2p. Assume not. Let the earliest such position be πj which is at a lambda node. Thereis an earlier position πi that is the parent of πj . Position πi belongs to an intervalπ[is, ks] and ni is a variable node: if πi does not belong to such an interval then ni − 1is below m1 and πi−1 is in σl for some l which is a contradiction as i − 1 < j; if niis a constant node then j = i + 1 and so this contradicts that πj is in σl. Therefore,

Page 45: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 45

there is the chain πj1 , . . . , πj2pwhere is = j1 and ks = j2p. So, πi belongs to one of the

intervals π[j2m−1, j2m]. Consider position πi+1 which is in some wq such that θi+1 =θl{((n′1, . . . , n′r), θi)/ni+1} where nj = n′s for some s. It cannot be the case that j2m−1 <

i < j2m. because either θj2m= θj2m−1 or θj2m

= θj2m−1{((m′1, . . . ,m′s), θk)/nj2m} where

k < j2m−1 by Propositions 12 and 18; so, there is no way to access the binder for ni+1

after position j2m which contradicts that πj occurs later. Therefore, i = j2m−1 and soπj2m and πj are children of πi. Consider the chain πj2m−1 , . . . , πj2p where πj2p = πks . ByProposition 18, θj2m−1 ≤ . . . ≤ θj2p

. Now, we employ a similar argument to above toshow that the only access to the binder ni+1 is through a descendant under binding of anode at a position in this chain which is impossible because it is an end path. Formally,one can proceed by induction on the number of positions in the interval π[j′, j] when nj′is a variable or constant node of t and j > j′ ≥ ks + 1. Without loss of generality wejust examine the case j′ = ks + 1. If nj′ is a constant node the result follows from theinterval π[j′ + 2, j]. If n′j is a variable node then n′j+1 is a lambda node of some wq andθj′+1 = θr{((m′1, . . . ,m′s), θj′)/n′j+1} where r < j1 as nj1 , . . . , nj2p

is an end path andm′1, . . . ,m

′s are the successors of n′j . Now the only access to the entry for ni+1 is through

a child of πj′+1, say πr, and so the result follows from the interval π[r + 2, j].Assume m1 is the successor of m and n is the successor of m2p; so, in t1 n is the

successor of m. It follows that π′ = σ1 . . . σq+1 with the following minor change to look-up tables is a play of G(t1, E); for any position π′i of π′ where n′i = m and so n′i+1 is nthe look-up table θ′i+1 is changed by removing all entries for binders that occur in theend path and this is maintained for subsequent positions.

Conversely, assume that π′ ∈ G(t1, E). Then by almost identical reasoning to thatabove there is a play π ∈ G(t, E) such that π′ can be decomposed into intervals σ1, . . . , σq+1

and π = σ1, π[i1, k1], σ2, . . . , π[iq, kq], σq+1 where, for each π[is, ks] there is a chain πj1 , . . . , πj2p ,is = j1, ks = j2p, and for each l, njl = mjl ; and the look-up tables in π are amended toinclude the binders in the end path; moreover, no π[is, js] contributes.

Consider Figure 6 with the single play of Figure 7. The sequence of nodes (8), (11)is an end path. It is also redundant in its only play; 11 is the first position at (8) andthen its child 14 is at (11); later, position 33 is at (8) and its child position 36 is at(11); neither π[11, 14] nor π[33, 36] contributes. Therefore, replacing node (8) with thetree of the subterm zs1s2 rooted at (12) is a smaller term that solves the equation ofExample 12.

The transformations T1 and T2, by themselves, are not sufficient for proving decidabil-ity of matching (by showing a small solution property as in Theorem 37). However, usingFact 27, they do provide immediate bounds on how many times an embedded node withthe same label can occur in a path of a smallest solution term.

Proposition 32. Assume t is a smallest solution to E whose goal is u, m1, . . . ,mp areboth embedded and end nodes (Definitions 35 and 36) of t labelled with the same variablebound by a binder at a node n. If the node mi+1 occurs below mi for each i : 1 ≤ i ≤ p.then p ≤ depth(u).

Proof. The proof uses Fact 27. Consider mp; if it is below the lth successor of mp−1

Page 46: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 46

then mpm where m is the lth successor of mp is an end path. If this path is redundant forevery play in G(t, E) then T2 applies to t which contradicts that it is a smallest solutionterm to E. Otherwise, there is an interval π[ip, jp] such that mp = ip− 1 and π[ip, jp + 1]contributes, and p − 1 earlier complementary intervals π[ik, jk] with mk = ik − 1; ifp > depth(u) then this contradicts that t solves E.

This proposition shows in the 5th order case that there cannot be an arbitrary amountof “stacking” of the same variable zn in a smallest solution term t; see the discussion inExample 11. However, this does not preclude the possibility that a solution term containsarbitrarily many level 1 nodes and more generally, at higher orders, arbitrarily many levelk nodes that are not end nodes.

6.3. Partitioning play

Transformations T1 and T2 apply to potential solution terms of interpolation equations.We shall introduce a third transformation that works on a different tree representationof an interpolation equation that is built out of partitioning of plays and which usesDefinition 37.

Definition 43. Assume π ∈ G(t, E) and t solves E. We define a partition of π into stagesas follows. Stage 1 consists of π[1, 2]. Assume stage N finishes at a lambda node of t atposition πi−1; stage N + 1 is defined by cases on ni.

1. constant node: stage N + 1 is π[i, i+ 1],2. variable node: if πj1 , . . . , πj2p

, p ≥ 0, is the longest chain for some πk, k > i, suchthat

— πj1 = πi+2,

— the chain satisfies the recurrence property,

— π[j1, j2p] does not contain a child of πi

then stage N + 1 is π[i, i+ 3] when p = 0 and is π[i, j2p + 2] when p 6= 0.

When defining stage N + 1, if the initial position is at a variable node then we say thatthe chain πj1 , . . . , πj2p

in the definition is the chain associated with stage N + 1.The first stage π[1, 2] of the partition of π finishes at the root of the solution term t.

Every stage except the final stage finishes at a lambda node of t. Stage N+1 starts at thesuccessor node of where stage N finishes; assume πi is this position. If ni is a constantnode then this stage is π[i, i+1] which is the final stage if the constant is a : 0; otherwiseni+1 is a successor of ni. When ni is a variable node, play jumps to a lambda node ni+1

of wq for some q. By Proposition 29 there is a largest r ≥ 0 such that πj1 , . . . , πj2ris a

chain with the recurrence property when πj1 = πi+2: if for p < r, πj2p+2 is a child of πithen we take this subchain or let p = r. If p = 0 then this stage is π[i, i+ 3] and if p 6= 0then it is π[i, j2p + 2]: the partition can only finish in wq at a constant a : 0 when thestage is final; otherwise, it must finish at a lambda node of t.

Page 47: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 47

Example 14. Consider the partition of the single play π of Figure 7 on the interpolationtree of Figure 6. There are nine stages S1 − S9 as follows.

S1 π[1, 2] S2 π[3, 6] S3 π[7, 10]S4 π[11, 14] S5 π[15, 20] S6 π[21, 24]S7 π[25, 40] S8 π[41, 44] S9 π[45, 48]

S1 is the typical example of the initial segment. S3 and S8 are standard cases whoseassociated chains are empty: in S3 the last node is a child of the first node unlike S8. S5

and S7 are the only cases whose associated chains are non-empty: in the case of S5 thereis the chain π17, π18 where n17 is the constant node (32); for S7 it is π27, π38; n27 is the(embedded) node (26) and π[28, 37] corresponds to the earlier π[6, 15] (and π38 is a childof π27). Stage S9 is final. Both stages S6 and S8 finish at the same node (and, so, stagesS7 and S9 start at the same node).

The following is a direct consequence of Proposition 29.

Fact 33. If π ∈ G(t, E) and t solves E then there is a unique partition of π.

The following uses Definition 40.

Definition 44. Assume π[i, j] is stage N of the partition of π ∈ G(t, E). Stage N isfinal if [rj ] = [∃]. If stage N is not final then it contributes (to the solution) when π[i, j]contributes. If stage N is final then it contributes when π[i, j − 1] contributes.

A stage contributes to the solution if it contains a position that is at a node labelledwith a constant f with arity > 0. In any play, the number of stages of its partition thatcontribute to a solution is at most depth(u), where u is the goal term. In the case ofExample 14, as u = ga there is a single stage, S5, that contributes; its initial state is [ga]and its last state is [a]; stage S9 is final.

Proposition 34. Assume π[i, j] is stage N of the partition of π ∈ G(t, E).

1. If ni is labelled a : 0 then stage N is final.2. If stage N is not final and ni is level 1 or a constant node then πj is a child of πi.3. If stage N does not contribute and ni is embedded then πj is a child of πi.4. If stage N is not final and ni is a variable node then nj is a successor of a node in

the same family as ni.

Proof. Part 1 is clear since t solves E. For 2, assume stage N is not final. If ni is aconstant node then j = i+1 and so πj is a child of πi. If ni is level 1 then ni+1 is the rootnode of some wq: consider the chain that determines stage N , πj1 , . . . , πj2p , p ≥ 0 whereπj1 = πi+2. By definition π[j1, j2p] does not contain a child of πi; therefore, every nodenj2m−1 is a constant node and because stage N is not final, it follows that ni+1 ↓ nj2p+1

and so, πj is a child of πi. For 3 assume stage N does not contribute; the result nowfollows from Fact 27. For 4 assume that stage N is not final, ni is a variable node andπj1 , . . . , πj2p , p ≥ 0, is the chain in wq that determines this stage. Now we make use ofProposition 28 as follows. We extend this chain so that πl1 , . . . , πl2r

, πj1 , . . . , πj2pis the

chain that starts at the successor of the root node of wq; so, nl1−1 is the root node of

Page 48: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 48

wq and one of the positions πl1−1, πl2 , . . . , πj2p, say πk, is the parent of πj−2; so, nj is a

successor of a node in the same family as ni, as it is a successor of nk−1.

S2, S3 and S4 of the partition in Example 14 on the tree in Figure 6 start at level 1nodes and finish with a child position at some successor. S4 also starts at an embeddednode. Except for the final stage, every stage of the partition in this example finishes ata successor of a node in the same family as the start node: for instance, in the case ofS7, it starts at node (6) labelled z1 and ends at a successor of (12) labelled z2; node (2)is the common ancestor of (6) and (12).

Now we will build the partition tree for G(t, E).

Definition 45. Assume π[i, j] is stage N of the partition of π ∈ G(t, E).

1. The comb at stage N of π is the node ni of t and its successors ni1, . . . , nip for p ≥ 0.2. The path at stage N of π is defined by cases on ni: if ni is a constant node or labelled

@ then it is ε (the empty sequence); if ni is a variable node and πj1 , . . . , πj2p, p ≥ 0,

is the chain associated with stage N then it is the path ni+1, nj1 , . . . , nj2p , nj−1.

If the path at stage N is non-empty then it is a path in some wq. In the case of S3 inExample 14 on the tree in Figure 6 the comb is the node (4) and its successors (5) and(7) and the path is (17), (18) of the first argument w1. The comb for S5 is node (12) andits successors (13) and (15); its path is (31), (32), (33), (34) in the second argument w2.In the case of S7, its comb is the singleton node (6) and its path is (25), (26), (29), (30)of w2.

We transfer notations from nodes to stages:

— a stage is a constant (variable) stage if the root of its comb is a constant (variable)node,

— a stage is level k if the root node of its comb is level k,— two stages belong to the same family if the root nodes of their combs do,— a stage is embedded if the root node of its comb is embedded.

We also write M < N to mean M is an earlier stage than N (in the partition of π). Iftwo stages belong to the same family then their paths belong to the same wq.

We next define the partition tree.

Definition 46. A partition tree is a tree whose nodes are triples (N, c, γ) where N is astage, c is the comb at the stage and γ is the path at the stage. The nodes are identifiedby their first coordinate so we write just N to represent a node (N, c, γ). The root of thetree is the first stage π[1, 2] whose comb is rooted at @ and whose path is empty. Weiteratively define an edge π−→ from the node at stage N + 1 to the lambda node of thecomb at an earlier stage K where stage N finishes: to avoid heavy notation we write thisas N + 1 π−→ K. Assume π[i, j] is stage N of the partition and edges have been definedfor all stages before and including N . Then N + 1 π−→ K where K ≤ N is the largeststage whose comb contains nj and where there is an M ≤ N such that N π−→∗ M andK

π−→∗ M (where π−→∗ is the reflexive and transitive closure of π−→).

The term t can be recovered from the partition tree when the edge relation π−→ is asuccessor on combs (as the comb at stage N + 1 is placed beneath the lambda node of

Page 49: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 49

S7

))S6

// S5// S4

// S3// S2

// S1

S8

77

S9

66

Fig. 12. Partition tree for Example 14

the earlier stage). A simple consequence of the definition of π−→ and Proposition 34 isthat N + 1 π−→ N if N is a constant, level 1 or embedded stage; and if N is a variablestage and N + 1 π−→ K then N and K belong to the same family.

The partition tree for Example 14 is in Figure 12 (where we omit the index π fromπ−→). Both stages S6 and S8 finish at node (5) of the comb at stage (3). When −→ is

viewed as the successor relation then the combs of this partition tree form the solutionterm in Figure 6: for instance, the comb of S4 is beneath node (7) of the comb at S3 andthe comb of S7 (and S9) is beneath node (5) (of the comb at node (3)).

The following is a simple consequence of Definition 43.

Fact 35. Assume π[i, j] is stage N of the partition of π ∈ G(t, E) which contributes.Then one of the following is true.

1. N is a constant stage,2. the path at N contains a constant node,3. there is k : i < k < j, and a stage K < N in the same family as N such that nk is a

constant node and nk occurs in K.

In the example above, the only stage that contributes is S5.

6.4. Unfolding

In this section we complete the proof of decidability of matching by introducing a trans-formation that applies to individual stages of a partition tree: we call it “unfolding” asit is reminiscent of unravelling a model as in modal logic.

Given a partition tree, we define compositions of combs and paths to form largerunits: compositions of combs (unfolding a comb into others) produce larger subterms;compositions of paths produce trees (subtrees of some wq). To give the reader a clearidea we first present an example.

Consider the partition tree of Figure 12 for Example 14. This is for the play of Figure 7on the tree in Figure 6. S5 contributes and S2 is in the same family. However, S3 andits descendants under binding, S6 and S8, do not contribute. So, we can unfold S3 into

Page 50: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 50

(4)x1

xxxxxxxx

IIIIIIIII(17)λy1y2

(5)λ (7)λs1s2 (18)y2

(16)s2 (21)λ

(22)y1

(4)x1

xxxxxxxx

IIIIIIIII(17)λy1y2

(5)λ (7)λs1s2 (18)y2

(14)s1 (19)λ

(20)y1

Fig. 13. Unfolding of S3 into S6, S3 into S8 and their trees

S7// S′6 // S5

// S4// S3

// S2// S1

S9// S′8

77

Fig. 14. Unfolded partition tree of Figure 12

S6 and S3 into S8. These are pictured in Figure 13. The unfolding of S3 into S6 placesthe comb at S6 directly beneath node (7) of the comb of S3: we also include the subtreewhich is the composition of the paths of S3 and S6 next to it: the path for S3 is (17), (18)and (21), (22) for S6; it is slightly different for S3 and S8.

The idea is to replace stage S6 with the new S′6, S3 unfolded into S6, whose enlargedcomb and subtree are depicted in Figure 13; similarly, S8 is replaced by S′8, the unfoldingof S3 into S8. Both S′6 and S′8 start at the root of their enlarged combs and finish atnode (5); their associated trees show that the new stages consist of appending S6 and S8

to S3. So, the new partition tree is as in Figure 14. Although the initial solution tree hasincreased in size because of the enlarged combs at S′6 and S′8 bindings are more local ; so,the first occurrence of node (7) in S3 no longer binds (14) and (16). Now we can applytransformation T2 of Section 6.2 to the expanded tree; in fact, before unfolding, we could

Page 51: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 51

(1)λx1x2

(2)x2

(3)λz1z2

(12)z2

ttttttttt

JJJJJJJJJ

(13)λ (15)λ

(6)z1 (6)z1

Fig. 15. Reduced solution term for Example 14

have omitted the comb at S4 so node (12) would be directly below (7) because the endpath (8), (11) is redundant as described in Section 6.2 (after the proof of Proposition 31).T2 now applies to the combs at S3, S′6 and S′8 as they now involve redundant end paths:the path (4), (7) in S3, and (4), (5) in both S′6 and S′8. Therefore, the resulting term afterthese applications of T2, in Figure 15, is a “small” solution to the interpolation equation.

Definition 47. Assume Ni, 1 ≤ i ≤ k, are some stages of the partition of π ∈ G(t, E)where ci is the comb at Ni and γi is the path at stage i and which obey the followingconditions.

(a) N1, . . . , Nk belong to the same family, do not contribute and Ni < Nj for i ≤ j,(b) for all 1 ≤ i < j ≤ k, ci 6= cj and γi 6= γj ,(c) for all j ≤ k, there is an i ≤ j such that Nj + 1 π−→ Ni, except for j = k if Nk is

final for π,(d) for all j ≤ k there is an i < j such that the root of γj is a successor of the leaf node

of γi.

We iteratively define N1 unfolded into N2, . . . , Nj for j ≤ k as (N1 . . . Nj) with enlargedcomb (c1 . . . cj) and enlarged tree (γ1 . . . γj) as follows.

1. (N1) = N1, (c1) = c1 and (γ1) = γ1,2. Assume (N1 . . . Nj) with (c1 . . . cj) and (γ1 . . . γj). The comb cj+1 is placed beneath

the leaf of (c1 . . . cj) where Nj finishes to form (c1 . . . cj+1); (γ1 . . . γj+1) is the treewhen γj+1 is placed beneath the node of (γ1 . . . , γj) which it is a successor of.

The play of (N1 . . . Nj), the new stage N ′j for π, starts from the root of (c1 . . . cj) andfinishes at a leaf of (c1 . . . cj).

Page 52: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 52

Many assumptions are needed to define unfolding of stage N1 into stages N2, . . . , Nkof a play π. The stages belong to the same family, do not contribute and have distinctcombs and paths. Each stage Nj finishes at a node of a comb of some Ni, i ≤ j, (exceptNk if it is final for π). The recurrence property in Definition 43 guarantees this: moregenerally, it guarantees that any position at a node of t in stage N is at a node of a combof some stage before and including N . The root of each path γj is below the leaf of apath γi, i < j. Therefore, we can iteratively compose the combs and paths into subtrees:in the latter case they are expanding subtrees of some wq. The examples above of S3

unfolded into S6 and S3 into S8 are instances of this definition. The following is clearfrom the definition of unfolding. Notice that we are defining a new play that takes placein a different game than the initial one. We do not provide the game to save notation, asit should be clear from the discussion how to define the new game.

Fact 36. Assume N1, . . . , Nk are stages of the partition of π ∈ G(t, E) and N1 is unfoldedinto N2, . . . , Nk. For each 1 ≤ j ≤ k, the play of (N1 . . . Nj) does not contribute, andfinishes at node n of ci in (c1 . . . cj) iff stage Nj finishes at n of ci.

To finish the proof of decidability of matching, we show that given a large solutionterm to an equation such that transformations T1 and T2 do not apply to it, we canfind a smaller solution term: first, the partition tree is built and then unfolded and thentransformations T1 and T2 are applied.

Unfolding happens with embedded stages of the partition: a stage is embedded if theroot node of its comb is embedded. We now extend this definition first to enlarged combs.

Definition 48. The comb (c1 . . . ck) is c-embedded (comb-embedded) if its only freevariable occurrence is that of the head of c1 and there is a comb (c′1 . . . c

′k) above it in

the partition tree which is α-equivalent to it.

Therefore if (c1 . . . ck) is c-embedded because of (c′1 . . . c′k) above it then the root node

of c1 is embedded (because of the root node of c′1) and the variable nodes in cj , c′j forj > 1, are bound by (α-equivalent) nodes within some ci, c′i where i < j. We can saythat the unfolding of N1 into (N2 . . . Nk) is embedded if there is an unfolding of N ′1into (N ′2 . . . N

′k) such that the enlarged comb of the first is c-embedded because of the

enlarged comb of the second.The central theorem is a small solution property (see Definitions 2, 8 and 11 for arity

and depth and where |t| is the size, the number of nodes, of the tree representation oft). If the interpolation problem E has a (canonical) solution then it has a small solutionthat is bounded in the size of the problem: the parameter n is the highest level of a nodein a potential solution term, Definition 34. Therefore, there is a tree automaton such thatAE is non-empty iff E has a (canonical) solution.

Theorem 37. If E, xw1 . . . wk = u, has order 2p or 2p + 1 and arity q then it has a(canonical) solution iff it has a (canonical) solution whose depth is at most 4(p2q2p−2|u|).

Proof. Assume E, xw1 . . . wk = u, has order 2p or 2p+1 and arity q. Let t be a smallest(canonical) solution. Therefore, t can contain nodes whose level is at most p.

We make some simple observations about nodes in t. The arity q of E, see Definitions 8

Page 53: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 53

and 2, prescribes the maximum branching at a node in t and the maximum length of avector y in a binder λy. Recall, Definition 35, that a node n labelled with variable y isembedded if there is another node m above it also labelled y where n and m are boundby the same binder: therefore, for any k ≥ 0, if a binder binds (k + 1)q nodes in somepath in t then at least k are embedded nodes that are labelled with the same variable(and are bound by the same binder). A variable node is end, Definition 36, if it has nodescendants under binding: for instance, this must be true for all level p nodes.

We now examine the game G(t, E). The number of plays is the number of branchesin u which is bounded by |u|. Because t is a smallest solution term, transformations T1

and T2 of Section 6.2 do not apply to t (as they would produce a smaller solution term).One simple consequence is that in any path of t, the number of occurrences of constantswhose arity is more than 0 is bounded by depth(u).

The construction proceeds as follows:

(a) build the partition tree for G(t, E),(b) then apply unfolding exhaustively,(c) then transformations T1 and T2 are done exhaustively.

After that we then show that the size of the resulting solution term (reconstructed fromthe resulting partition tree and its combs) is bounded.

Assume the partition tree for the game G(t, E). Each play π has the same first stageand shares the same comb at stage 2. Stage N is a separator if there are two differentplays that share the same combs before and including N , and finish stage N at differentnodes. Next, we apply the unfolding wherever possible starting with a stage N1 that hasno descendants under binding that contribute. In particular, a suitable N1 is level 1 orembedded.

For any k ≥ 0, consider a least j such that a path of t contains at least (k+ 1)qj levelj nodes: so, at least k of them are embedded and labelled with the same variable; if theyare also end nodes then k ≤ depth(u) by Proposition 32; if they are not end nodes andk > q then at least one, say N1, can be unfolded into N2 such that (N1N2) is embedded.We now repeat this argument for paths for a least j containing at least (k + 1)qj level jwhere k > ql for some l; N1 can be unfolded into the embedded (N2 . . . Nr) for r ≤ l+ 1.We assume that in an unfolding (N1 . . . Nk) no Nj is embedded because of an earlier Ni,i < j: therefore, the maximum depth of an enlarged comb is bounded by 2pqp−1 (when alevel 1 node is unfolded into q level 2 nodes and together they are unfolded into q2 level3 nodes and so on). Clearly, if stage N of π contributes then it still contributes after allunfoldings; and no new unfolded stage can contribute by construction. With an unfolding(N1 . . . Nk) whose comb is (c1 . . . ck) the play starts at the root of c1 and finishes at aleaf n′ of (c1 . . . ck), see Definition 47: so transformation T2 applies to this unfolding ifthe path from the root of c1 to n′ is a redundant end path. Once a maximum amount ofunfolding has taken place, we apply transformations T1 and T2 of Section 6.2 to reducethe size of the unfolded term.

The number of stages that can contribute is at most |u|. Assume c is the comb at stageN which contributes. The number of stages later than N that start from a node that isa descendant under binding of the root of c and that is not embedded is at most pqp−1.

Page 54: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 54

We now consider for which stages the transformation T2 is not applicable. These are thestages that contribute and those later stages that start from descendant nodes underbinding and that are not embedded. There is also the issue that in the partition tree thesame node may have more than one edge entering it from two different later stages ofthe same or different plays; we need to guarantee the same subterm is rooted at thoselater stages. To do this, we may need extra later stages that are also play separators; thenumber of such separators is bounded by pqp−1|u| which is at most the number of stagesthat either contribute or start from a descendant under binding that is not embedded.This, therefore, gives an upper bound of 4(p2q2p−2|u|) on the depth of t.

The bound in Theorem 37 is very crude. For instance, for Example 12 whose order is5, arity is 2 and where the size of the goal term is also 2, the bound on the depth of asmallest solution term is 128.

6.5. Removing restrictions

The decidability proof presented is for the restricted case when there is a single base typeand when the goal term u of an interpolation equation does not contain bound variables.We now describe how the proof can be easily extended to the unrestricted case.

Assume that there is a family B of base types. The sets of terms, lnfs, matchingequations and interpolation equations carry over to this more general setting: for instance,an interpolation equation xw1 . . . wk = u now has the type (A1, . . . , Ak, B) and u : Bwhere B ∈ B. We extend the tree representation of terms and interpolation equations toinclude at each node its result type: if the node is a variable, constant or lambda nodeof type (A1, . . . , Al, B) or B then B is its result type; in the case of Figure 6 this wouldmean including 0 at each node. Consider consecutive positions of a play on such a tree: ifa position is at a lambda node with result type B then its successor node must also haveresult type B; if a postion is at a variable node with result type B then the next position(involving a jump) must be at a lambda node with result type B; therefore, a change inresult type can only occur at a constant node. Therefore, in any play there can only be atmost depth(u) changes in the result type. Furthermore, this also constrains the numberof times that there can be a change in the result types in a path of a smallest solutionterm t. Now the ingredients of the proof are easily generalised: for transformation T1 weassume a constant bB : B for each B ∈ B and for transformation T2 we assume thateach node in an end path has the same result type; a similar restriction applies to theunfolding. The overall effect on Theorem 37 is to replace |u| by |u|2 in the bound to takeaccount of changes in result types.

Next, the case when the goal term u can contain bound variables (also allowed forin (Stirling 2009A)). This requires a change in the definition of the interpolation game.We extend the look-up tables to include direct entries for binders that are successors ofdecendants under binding of constant nodes: an entry for such a binder labelled λv1 . . . vphas the form (c1, . . . , cp) where each ci is a fresh constant that does not occur in thesolution term or in the interpolation equation and which has the same type as vi. Next,we need to change the rule for a constant f and add rules of Figure 5 for the next position

Page 55: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 55

Current position is n[r]θ. The next position is by cases on the label at node n:

— f : (B1, . . . , Bp,0) if r 6= fr1 . . . rp then n[ ∀ ]θ else ∀ chooses j ∈ {1, . . . , p} and

– rj : 0 then nj [rj ] θ,

– rj = λv1 . . . vm.r′ then nj [r′{c1/v1, . . . , cm/vm}] θ{(c1, . . . , cm)/nj}.

— vi : 0, m ↓ n and θ(m) = (c1, . . . , cl); if r = ci then n [ ∃ ] θ else n [ ∀ ] θ.

— vi : (B1, . . . , Bp,0), m ↓ n and θ(m) = (c′1, . . . , c′l); if r 6= c′ir1 . . . rp then n [ ∀ ] θ else ∀

chooses j ∈ {1, . . . , p} and

– rj : 0 then nj [rj ] θ,

– rj = λs1 . . . sm.r′ then nj [r′{c1/s1, . . . , cm/sm}] θ{(c1, . . . , cm)/nj}.

Fig. 16. Amended game moves

in a play; the new rules are presented in Figure 16. In effect, nodes bound by a binderthat is a successor of a constant or of a descendant under binding of a constant in a termt or a term wi are really constant nodes: these are the nodes labelled with a variablevj ; the rules associate constants cj with their binder; moreover in the goal subterm theconstant cj is substituted for the bound variable sj . Theorem 13 holds for the new game.The decidability proof then proceeds as before: the definitions of the transformations andunfolding remain unchanged.

7. Conclusion

We have described a proof of decidability of higher-order matching that is simpler thanthat presented in (Stirling 2009A) mainly because it uses a more symmetric game-theoretic characterisation of solutions of interpolation equations; the notions of unifor-mity properties of game playing, partitioning plays and unfolding are common to bothproofs. We also described how tree automata provide a different characterisation of solu-tions to interpolation equations. It is an open question whether such a characterisationcan also lead to decidability. There is a third characterisation that uses type checking;the types are intersection types generated by subterms of u, based on (Kobayashi andOng 2009); in this way one can also reduce the interpolation problem, whether it has a(canonical) solution, to the (undecidable) type inhabitation problem (Urzyczyn 1999),whether there is a term that has a given intersection type.

It still remains to be seen whether there is a simpler proof of decidability; for in-stance, although we tried (Stirling 2005), one possibility is a proof using further simpletransformations on terms such as T1 and T2 of Section 6.2.

There is an intimate relationship between observational equivalence of terms and fam-ilies of interpolation equations (Padovani 1995; Padovani 2000). We have started toexamine whether there is a simple characterisation of observational equivalence usingcomparison games on terms (similar in spirit to bisimulation games).

References

Alur, R. and Madhusudan P. Adding nested structure to words Lecture Notes in Computer

Science, 4036, 1-13, (2006).

Page 56: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

Colin Stirling 56

Alur, R., Chaudhuri S. and Madhusudan, P. Languages of nested trees, Lecture Notes in Com-

puter Science, 4144, 329-342, (2006).

Barendregt, H. The Lambda Calculus Its Syntax and Semantics, Studies in Logic and the Foun-

dations of Mathematics, Vol 103, North-Holland, (1984).

Barendregt, H. Lambda calculi with types. In Handbook of Logic in Computer Science, Vol 2,

ed. Abramsky, S., Gabbay, D. and Maibaum, T., Oxford University Press, 118-309, (1992).

Comon, H., Dauchet, M., Gilleron, R., Jacquemard, F., Lugiez, D., Tison, S. and Tommasi, M.

Tree Automata Techniques and Applications. Draft Book, http://l3ux02.univ-lille3.fr/tata/

(2002).

Comon, H. and Jurski, Y. Higher-order matching and tree automata. Lecture Notes in Computer

Science, 1414, 157-176, (1997).

Dougherty, D. and Wierzbicki, T. A decidable variant of higher order matching. Lecture Notes

in Computer Science, 2378, 340-351, (2002).

Dowek, G. Third-order matching is decidable. Annals of Pure and Applied Logic, 69, 135-155,

(1994).

Dowek, G. Higher-order unification and matching. In A. Robinson and A. Voronkov ed. Handbook

of Automated Reasoning, Vol 2, 1009-1062, North-Holland, (2001).

Goldfarb, W. The undecidability of the second-order unification problem. Theoretical Computer

Science, 13, 225-230, (1982).

Hindley, J. and Seldin, J. Introduction to Combinators and λ-Calculus, London Mathematical

Society Student Texts 1, Cambridge University Press, (1986).

Huet, G. Resolution d’equations dans les langages d’ordre 1, 2, . . . ω. These de doctorat d’etat,

Universite Paris VII, (1976).

Joly, T. The finitely generated types of the lambda calculus. Lecture Notes in Computer Science,

2044, 240-252, (2001).

Joly, T. On λ-definability I: the fixed model problem and generalizations of the matching prob-

lem. Fundamenta Informaticae, 65, 135-151, (2005).

Jung, A. and Tiuryn, J. A new characterisation of lambda definability. Lecture Notes in Com-

puter Science, 664, 245-257, (1993).

Kobayashi, N. and Ong, C.-H. L. A type system equivalent to the modal mu-calculus model

checking of higher-order recursion schemes. Procs. LICS 2009, 179-188, (2009).

Loader, R. Unary PCF is decidable. Theoretical Computer Science, 206, 317-329, (1998).

Loader, R. Undecidability of λ-definability. In Logic, Meaning and Computation, Synthese Li-

brary, 305, 331-342, (2002).

Loader, R. Finitary PCF is not decidable. Theoretical Computer Science, 266, 342-362, (2001).

Loader, R. Higher-order β-matching is undecidable, Logic Journal of the IGPL, 11(1), 51-68,

(2003).

Ong, C.-H. L. On model-checking trees generated by higher-order recursion schemes, Procs LICS

2006, 81-90. (Longer version available from Ong’s web page, 55 pages preprint, 2006.)

Ong and Tzevelekos. Functional Reachability. Procs LICS 2009, 286-295, (2009).

Padovani, V. On equivalence classes of interpolation equations. Lecture Notes in Computer

Science, 902, 335-349, (1995).

Padovani, V. Decidability of all minimal models. Lecture Notes in Computer Science, 1158,

201-215, (1996).

Padovani, V. Decidability of fourth-order matching. Mathematical Structures in Computer Sci-

ence, 10(3), 361-372, (2000).

Schmidt-Schauß, M. Decidability of arity-bounded higher-order matching. Lecture Notes in Ar-

tificial Intelligence, 2741, 488-502, (2003)

Page 57: An introduction to decidability of higher-order matchinghomepages.inf.ed.ac.uk/cps/newnewj.pdfUnder consideration for publication in Math. Struct. in Comp. Science An introduction

An introduction to decidability of higher-order matching 57

Schubert, A. Linear interpolation for the higher-order matching problem. Lecture Notes in Com-

puter Science, 1214, 441-452, (1997).

Segoufin, L. Automata and logics for words and trees over an infinite alphabet. Lecture Notes

in Computer Science, 4207, 41-57, (2006).

Statman, R. The typed λ-calculus is not elementary recursive. Theoretical Computer Science,

9, 73-81, (1979).

Statman, R. Completeness, invariance and λ-definability. The Journal of Symbolic Logic, 47,

17-26, (1982).

Stirling, C. Higher-order matching and games. Lecture Notes in Computer Science, 3634, 119-

134, (2005).

Stirling, C. A game-theoretic approach to deciding higher-order matching. Lecture Notes in

Computer Science, 4052, 348-359, (2006).

Stirling, C. Higher-order matching, games and automata. Procs LICS 2007, 326-335, (2007).

Stirling, C. Dependency tree automata. Lecture Notes in Computer Science, 5504, 92-106, (2009).

Stirling, C. Decidability of higher-order matching Logical Methods in Computer Science, 5(3:2),

1-52, (2009).

Vorobyov, S. The “hardest” natural decidable theory. Procs LICS 1997, 294-305, (1997).

Wierzbicki, T. Complexity of higher-order matching. Lecture Notes in Computer Science, 1632,

82-96, (1999).

Støvring, K. Higher-order beta matching with solutions in long beta-eta normal form. Nordic

Journal of Computing, 13, 117-126, (2006).

Urzyczyn, P. The emptiness problem for intersection types. Journal of Symbolic logic, 64(3),

1195-1215, (1999).


Recommended