Abstract 1 Introduction 2 Preliminaries 3 Undecidability of Higher-order 𝜷-Matching 4 Mechanization 5 On Intersection Type Inhabitation and 𝝀-Definability 6 Conclusion References

Mechanized Undecidability of Higher-Order Beta-Matching

Andrej Dudenhefner ORCID TU Dortmund University, Germany
Abstract

Higher-order β-matching is the following decision problem: given two simply typed λ-terms, can the first term be instantiated to be β-equivalent to the second term? This problem was formulated by Huet in the 1970s and shown undecidable by Loader in 2003 by reduction from λ-definability.

The present work provides a novel undecidability proof for higher-order β-matching, in an effort to verify this result by means of a proof assistant. Rather than starting from λ-definability, the presented proof encodes a restricted form of string rewriting as higher-order β-matching. The particular approach is similar to Urzyczyn’s undecidability result for intersection type inhabitation.

The presented approach has several advantages. First, the proof is simpler to verify in full detail due to the simple form of rewriting systems, which serve as a starting point. Second, undecidability of the considered problem in string rewriting is already certified using the Coq proof assistant. As a consequence, we obtain a certified many-one reduction from the Halting Problem to higher-order β-matching. Third, the presented approach identifies a uniform construction which shows undecidability of higher-order β-matching, λ-definability, and intersection type inhabitation.

The presented undecidability proof is mechanized in the Coq proof assistant and contributed to the existing Coq Library of Undecidability Proofs.

Keywords and phrases:
lambda-calculus, simple types, undecidability, higher-order matching, mechanization, Coq
Copyright and License:
[Uncaptioned image] © Andrej Dudenhefner; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Lambda calculus
Supplementary Material:
Software  (Source Code): https://github.com/uds-psl/coq-library-undecidability/
Acknowledgements:
I sincerely thank the anonymous reviewers for their constructive suggestions.
Editors:
Maribel Fernández

1 Introduction

Higher-order β-unification in the simply typed λ-calculus is the following decision problem: given two simply typed λ-terms M,N, is there a substitution S such that the instance S(M) is β-equivalent to the instance S(N)? Undecidability of higher-order β-unification was established by Huet [9] in the 1970s, raising the question whether β-matching [10] (the right-hand side term N does not contain free variables) is decidable111Dowek [5] gives a comprehensive overview over unification and matching problems for the λ-calculus.. An equivalent presentation of higher-order β-matching (cf. Statman’s range question [17]) is: given a term F typed by the simple type στ and a term N typed by the simple type τ, is there a term M typed by the simple type σ such that FM is β-equivalent to N?

Decidability of higher-order β-matching was answered negatively222Not to be confused with the positive answer by Stirling [18] for higher-order βη-matching. by Loader [13] by reduction from λ-definability. Loader introduces intricate machinery to formulate β-matching constraints which specify arbitrary finite functions. Later, Joly [11] refined Loader’s result, shifting technical challenges to underlying variant of λ-definability. The intricate machinery renders verification of both approaches by means of a proof assistant quite challenging.

The present work presents a novel proof of the undecidability of higher-order β-matching, which is mechanized using the Coq proof assistant [19]. The mechanization leaves no room for ambiguities and potential errors, complementing existing work on mechanized undecidability of higher-order β-unification [16].

The presented proof is not based on λ-definability; rather, we consider a known rewriting problem in a restricted class of semi-Thue systems [20, Lemma 2] as a starting point. The specific rewriting problem, referred to as 𝟎+𝟏+, is: given a collection of rewrite rules of shape abcd, where a,b,c,d are alphabet symbols, is there a non-empty sequence of 𝟎s which can be transformed into a non-empty sequence of 𝟏s? As a consequence of the different starting point, the presented proof is simpler to verify in full detail and yields a concise mechanization. The mechanization is incorporated into the existing Coq Library of Undecidability Proofs [8], alongside the existing mechanization333The (Turing machine) Halting Problem is easily presented as Problem 𝟎+𝟏+ [6, Lemma 3.3]. of undecidability of the problem 𝟎+𝟏+.

The main inspiration for the novel approach in the present work is Urzyczyn’s undecidability proof for intersection type inhabitation [20]. Considering the relationship between the intersection type discipline and finite model theory [15], the approach in the present work has an additional benefit: it is uniformly applicable to prove undecidability of higher-order β-matching, intersection type inhabitation, and λ-definability.

Paper organization.

The present work is structured as follows:

Section 2:

Preliminaries for the simply typed λ-calculus, higher-order β-matching, and simple semi-Thue systems (including the undecidable Problem 𝟎+𝟏+).

Section 3:

Reduction from Problem 𝟎+𝟏+ to higher-order β-matching.

Section 4:

Overview over the mechanization in the Coq proof assistant.

Section 5:

Applicability to intersection type inhabitation and λ-definability.

Section 6:

Concluding remarks.

Statements in the digital version of the present work are linked to the corresponding mechanization, which is marked by the symbol [ ].

2 Preliminaries

In this section we fix preliminaries and basic notation, following standard literature [2].

Higher-order 𝜷-Matching in the Simply Typed 𝝀-Calculus

The syntax of untyped λ-terms is given in the following Definition 1.

Definition 1 (λ-Terms).

margin: M,N::=xMNλx.M where a,,z range over term variables.

Substitution of the term variable x in the term M by the term N is denoted M[x:=N].As usual, term application associates to the left, and we may group consecutive λ-abstractions. We commonly refer to the term λx.x as I.

Definition 2 (β-Reduction).

margin: The relation β on terms is the contextual closure of (λx.M)NβM[x:=N].

The β-equivalence relation =β is the reflexive, transitive, symmetric closure of β.

In the simply typed λ-calculus we may assign to a term M a simple type τ in type environment Γ, written ΓM:τ. Similarly to prior work [13], one ground atom ι in the construction of simple types suffices for the negative result in the present work. Definition 5 contains the rules (Var), (I), and (E) of the simple type system.

Definition 3 (Simple Types with Ground Atom ι).

margin:

σ,τ::=ιστ

The arrow type constructor associates to the right.

Definition 4 (Type Environments).
Γ::={x1:σ1,,xn:σn} where xixj for ij
Definition 5 (Simple Type System).

margin:  

The following Example 6 illustrates a type derivation in the simple type system.

Example 6.

Higher-order β-matching is the following typed unification problem, for which only one side is subject to instantiation.

Problem 7 (Higher-order β-Matching (F𝖷=N)).

margin: Given terms F,N and simple types σ,τ such that F:στ and N:τ, is there a term M such that M:σ and FM=βN?

Undecidability of higher-order β-matching is shown by Loader [13] using a reduction from a variant of λ-definability.

Theorem 8 ([13, Theorem 5.5]).

Higher-order β-matching is undecidable.

For the remainder of the present work we use the term matching in order to refer to higher-order β-matching. Since simply typed terms are strongly normalizing and β-reduction is confluent [2], the it suffices in Problem 7 to consider terms F,M,N in normal form.

Let us get familiar with matching by means of several illustrating examples. The following Example 9 illustrates a positive matching instance.

Example 9.

Consider the terms F:=λx.λy.xyI and N:=I, for which we have F:(ι(ιι)ι)(ιι) and N:ιι.

The matching instance F𝖷=N is solvable, including the solution M:=λu.λf.fu.To be precise, we have the following two properties:

  • M:ι(ιι)ι (Example 6)

  • FM=βλy.(λu.λf.fu)yI=βλy.Iy=βN

We want to encode certain functional behavior as a matching instance. The following Example 10 shows a naive approach to such an encoding and its limitations.

Example 10.

Let us associate elements of the set {1,2,3} with projections π1:=λxyz.x, π2:=λxyz.y, and π3:=λxyz.z respectively. For the term G:=λh.λxyz.hyzx we have Gπ1=βπ2, Gπ2=βπ3, and Gπ3=βπ1. Therefore, G realizes a finite function fG:{1,2,3}{1,2,3} such that fG(1)=2, fG(2)=3, and fG(3)=1.

Let κ:=ιιιι be a simple type for which we have πi:κ for i{1,2,3}. Consider the matching instance F𝖷=π3, where F:=λt.tGπ1, and for which we have F:((κκ)κκ)κ. The intended “meaning” of this matching instance is: starting with the element 1, repeatedly apply the function fG in order to construct the element 3.

One solution for this instance is the term λf.λs.f(fs) for which we have:

F(λf.λs.f(fs))=βf(fs)[f:=G,s:=π1]=βGπ2=βπ3

This solution follows the intended meaning of the underlying representation, constructing the element fG(fG(1))=3. Another solution is λf.λs.f(f(f(f(fs)))), which utilizes fG(fG(fG(fG(fG(1)))))=3.

Unfortunately, there are solutions to the above matching instance which behave differently. One such solution is λf.λs.π3, for which we also have F(λf.λs.π3)=βπ3. In this case, the element 3 is constructed “ad hoc”, with no reference to the provided arguments. Another solution is the term λf.λs.λxyz.fszzz. This solution exploits the exact representation of elements via projections, disregarding any intended meaning of the underlying representation.

In the above Example 10 we would like to exclude certain ad hoc solutions, in order to faithfully encode intended functional behavior. Towards this aim, a known technique how to restrict the shape of solutions is illustrated in the following Example 11.

Example 11 ([5, Proposition 3.4]).

Consider a term M in normal form such that MIu=βu where u is a term variable, and M:(κκ)κκ. By case analysis on M we have that M=λf.λs.N for some term N in normal form. Furthermore, {f:κκ,s:κ}N:κ and N[f:=λx.x,s:=u]=βu. Therefore, the term N is not an abstraction. By induction on the size of N and case analysis of the normal form we have that N=s or N=f((fs)). Since the term M contains exactly two λ-abstractions, it cannot be an ad hoc solution from Example 10.

Combining Example 10 with Example 11, we formulate in the following Example 12 a matching instance which faithfully encodes the desired functional behavior.

Example 12.

Let F:=λt.λr.r(tGπ1)(λu.tIu) and N:=λr.rπ3(λu.u) where the term G=λh.λxyz.hyzx is from Example 10. We have

  • F:((κκ)κκ)(κ(κκ)ι)ι

  • N:(κ(κκ)ι)ι

The matching instance F𝖷=N combines the matching instance from Example 10 with the additional restriction from Example 11. Therefore, solutions such as λf.λs.f(fs) and λf.λs.f(f(f(f(fs)))) from Example 10 which follow the intended “meaning” of the underlying representation still solve F𝖷=N. However, ad hoc solutions such as λf.λs.π3 or λf.λs.λxyz.fszzz from Example 10 do not solve F𝖷=N because such solutions contain too many λ-abstractions.

 Remark 13.

Without the restriction M:(κκ)κκ in Example 11 the term M:=λf.λs.ffs satisfies MIu=βu. However, Example 12 does not admit M as a solution. The present work relies on well-typedness, but might be adapted to an untyped scenario.

The following Remark 14 illustrates how the addition of η-reduction would make the technique from Example 12 (as well as Loader’s approach) unsuitable.

 Remark 14.

Example 11 demonstrates how to restrict the number of abstractions in solutions. However, in the presence of η-reduction (contextual closure of λx.fxηf) this does not work, as shown below. Consider the terms G:=λh.λxyz.hyzx, π1=λxyz.x, π2=λxyz.y, and π3=λxyz.z from Example 11. The term M:=λg.λh.λxyz.h(gπ1xzy)yz solves the matching instance in Example 12 because:

MGπ1=β(λg.λh.λxyz.h(gπ1xzy)yz)Gπ1=βλxyz.π1(Gπ1xzy)yz=βλxyz.Gπ1xzy=βλxyz.π1zyx=βλxyz.z=π3
MIu=β(λg.λh.λxyz.h(gπ1xzy)yz)Iu=βλxyz.u(Iπ1xzy)yz=βλxyz.u(π1xzy)yz=βλxyz.uxyzηu

In particular, η-reduction allows for additional λ-abstractions in the solution, making the technique from Example 11 unsuitable.

The observation from Example 12 is generalized by Loader to encode arbitrary families of finite functions. This results in undecidability of higher-order β-matching by reduction from a variant of λ-definability. Loader’s generalization is quite sophisticated, as it requires construction principles to restrict shapes of realizers of arbitrary higher-order finite functions. In the present work, we focus on a fragment which can be identified by inspection of intersection types occurring in the undecidability proof of intersection type inhabitation [20, 6] and their relationship to finite model theory [15]. This leads to a simpler undecidability proof and reveals a connection between matching, intersection type inhabitation, and λ-definability. The presented approach has similarities with Joly’s [11] refinement of Loader’s proof. Joly shifts the technical burden to a particular λ-definability problem, which then is simpler to handle. Instead, we avoid λ-definability altogether and use a rewriting problem in a restricted class of simple semi-Thue systems as a starting point.

Simple Semi-Thue Systems

A simple semi-Thue system (Definition 15) is a rewriting system of restricted shape, introduced by Urzyczyn [20] in order to show undecidability of intersection type inhabitation.

Definition 15 (Simple Semi-Thue System).

margin: A semi-Thue system over an alphabet 𝒜 is simple, if each rule has the shape abcd for a,b,c,d𝒜.

The reflexive, transitive closure of the rewriting relation for a given simple semi-Thue system  is denoted . For arbitrary simple semi-Thue systems it is undecidable whether some non-empty sequence of 𝟎s can be transformed into a non-empty sequence of 𝟏s.

Problem 16 (𝟎+𝟏+).

margin: Given a simple semi-Thue system , does 𝟎n𝟏n hold for some n>0?

Theorem 17 ([6, Lemma 3.3]).

margin: Problem 𝟎+𝟏+ is undecidable.

The following Example 18 illustrates a positive instance of Problem 𝟎+𝟏+.

Example 18.

Let :={𝟎𝟎𝟐𝟐,𝟎𝟐𝟏𝟏,𝟐𝟎𝟏𝟏} be a simple semi-Thue system over the alphabet {𝟎,𝟏,𝟐}. We have 𝟎𝟎𝟎𝟎𝟎𝟐𝟐𝟎𝟏𝟏𝟐𝟎𝟏𝟏𝟏𝟏. As a side note, we have 𝟎n⇏ 1n for n{1,2,3}.

 Remark 19.

Problem 𝟎+𝟏+ is used as a starting point in a refinement [6, Lemma 4.4] of Urzyczyn’s undecidability result for intersection type inhabitation [20]. Undecidability of Problem 𝟎+𝟏+ is mechanized as part of Coq Library of Undecidability Proofs [8], making it a good starting point for further mechanized undecidability results.

3 Undecidability of Higher-order 𝜷-Matching

In this section we develop our main result (Theorem 39): a reduction from the rewriting problem 𝟎+𝟏+ to higher-order β-matching.

For the remainder of the section we fix the simple semi-Thue system :={R1,,RL} with L>0 rules over the finite alphabet {𝟎,𝟏,𝟐,,𝐊}. Our approach is to construct simply typed terms which capture the two main aspects of the rewriting problem 𝟎+𝟏+: the search for a sufficiently long starting sequence of 𝟎s, and the individual rewriting steps to the desired sequence of 𝟏s.

The remainder of the present section is structured as follows. First, we fix basic notation, encoding, and properties of the rewriting in the system . Second, we restrict the shape of potential solutions for the constructed matching instance, similarly to Example 11. Third, for solutions of restricted shape we capture the functional properties of the rewriting problem 𝟎+𝟏+.

Notation

We introduce four additional symbols in extended alphabet 𝒜:={𝟎,𝟏,,𝐊}{$,,,}. We represent an alphabet symbol i𝒜 as the projection πi:=λs𝟎s𝟏s𝐊s$sss.si typed by the simple type κ:=ιι|𝒜|timesι. The intended meaning of the additional symbols in the extended alphabet is as follows. The symbol $ marks the beginning of a word for word expansion, serves as symbol different from 𝟎 and 𝟏 for case analysis, serves as a constructible symbol, and serves as a non-constructible symbol.

For readability, we use the following case notation to match individual symbols.

Definition 20 (case).

For k, distinct i1,,ik𝒜, and terms M1,,Mk:

case x of Mi1M1ikMk:= xN𝟎N𝟏N𝐊N$NNN
where Ni={Mjif i=ijMotherwise

A particular term δi for i𝒜, which we use commonly is:

δi:=λx.λs𝟎s𝟏s𝐊s$sss.case x of ssi

We have δi:κκ, and the following Lemma 21 specifies the behavior of δi.

Lemma 21.

For i,j𝒜 such that ij we have δiπ=βπi and δiπj=βπ.

Syntactic Constraints

We identify the shape of “well-formed” terms, suitable to represent rewriting. In the following Definition 22 terms in the set 𝒬m capture consecutive rule application for a word of length m+1, ending in the word 𝟏m+1 (represented by z𝟏𝒬m). The subterm ripj (and ri(λw.pjw)) for i{1,,L} and j{1,,m} indicates an application of the rule Ri at position j. Additionally, terms in the set m capture consecutive increase of word length starting with m+1, and initialization with 𝟎s before rewriting (represented by z𝟎NMm for M𝒬m). Specifically, the subterm zN(λpm+1.M) introduces an additional bound variable pm+1 in order to argue about rule application at position m+1 in the longer word. Consequently, terms in 1 represent witnesses for an arbitrary expansion of a word starting with length 2, followed by initialization with 𝟎s, and consecutive rule application (potentially ending in 𝟏s).

Definition 22 (Sets 𝒬m, m of Terms).

For m>0, let 𝒬m and m be the smallest sets of terms satisfying the following rules:

  • z𝟏𝒬m

  • if M𝒬m then (ripjM)𝒬m for i{1,,L} and j{1,,m}

  • if M𝒬m then (ri(λw.pjw)M)𝒬m for i{1,,L} and j{1,,m}

  • if M𝒬m then (z𝟎NM)m

  • if Mm+1 then (zN(λpm+1.M))m

 Remark 23.

Terms in 1 are inspired by inhabitants in a refinement [6, Lemma 4.4] of Urzyczyn’s undecidability result for intersection type inhabitation [20].

Free variables occurring in terms in 𝒬m and m are assigned simple types according to the following type environment Γm, such that terms in 𝒬m and m can be assigned the simple type κ.

Definition 24 (Type Environment Γm).

margin: For m>0 let

Γm :={z𝟏:κ,z𝟎:(κκ)κκ,z:(κκ)((κκ)κ)κ,p1:κκ,,pm:κκ,r1:(κκ)κκ,,rL:(κκ)κκ}

Similarly to Example 11, we formulate typed terms (Definition 25) and β-equivalence constraints characterizing members of 𝒬m (Lemma 27) and m (Lemma 28).

Definition 25 (Typed Terms H, H𝟎, HR).
H:= λh.λg.λs𝟎s𝟏s𝐊s$sss.case gδ of s$s$
H𝟎:= λh.λx.λs𝟎s𝟏s𝐊s$sss.case x of s𝟏s$
HR:= λh.λx.λs𝟎s𝟏s𝐊s$sss.case hπ of scase x of s𝟏s𝟏
H:Γm(z)H𝟎:Γm(z𝟎)HR:Γm(ri) for i{1,,L}

We introduce substitutions SF and SH acting on the term variables z,z𝟏,z𝟎,r1,,rL, which occur in terms in 𝒬m and m.

Definition 26 (Substitutions SF, SH).
SF(z):=λh.λg.gISF(z𝟏):=uSF(z𝟎):=λh.ISF(rj):=I for j1,LSH(z):=HSH(z𝟏):=π𝟏SH(z𝟎):=H𝟎SH(rj):=HR for j1,L
Lemma 27.

margin: For m>0, if a term M is in normal form such that ΓmM:κ, SF(M)[p1:=I,,pm:=I]=βu, and SH(M)[p1:=δ,,pm:=δ]=βπ𝟏, then M𝒬m.

Proof.

Induction on the size of M and case analysis of the normal form.

Lemma 28.

margin: For m>0, if a term M is in normal form such that ΓmM:κ, SF(M)[p1:=I,,pm:=I]=βu, and SH(M)[p1:=δ,,pm:=δ]=βπ$, then Mm.

Proof.

Induction on the size of M, case analysis of the normal form, and Lemma 27.

As a consequence of the above Lemma 28, the following Theorem 29 presents β-equivalence constraints which suffice to restrict the shape of terms under consideration.

Theorem 29.

margin: If a term M is in normal form such that
M:Γ1(r1)Γ1(rL)Γ1(z𝟎)Γ1(z𝟏)Γ1(z)Γ1(p1)κ,
MII(λh.I)u(λh.λg.gI)I=βu, and MHRHRH𝟎π𝟏Hδ=βπ$,
then M=λr1rL.λz𝟎z𝟏zp1.N for some term N such that N1.

Proof.

Induction on the size of M, case analysis of the normal form, and Lemma 28.

Example 30.

Assume ={𝟎𝟎𝟐𝟐,𝟎𝟐𝟏𝟏,𝟐𝟎𝟏𝟏} over the alphabet {𝟎,𝟏,𝟐} from Example 18. Let N:=r1p2(r2p1(r3p3z𝟏)) and M:=zp1(λp2.zp2(λp3.z𝟎p3N)). We have N𝒬3 and M1. In congruence with Theorem 29 we have:

(λr1r2r3.λz𝟎z𝟏zp1.M)III(λh.I)u(λh.λg.gI)I=βu(λr1r2r3.λz𝟎z𝟏zp1.M)HRHRHRH𝟎π𝟏Hδ=βπ$

While Theorem 29 only establishes “well-formedness”, the term M has an intended meaning: An initial word of length 2 is expanded twice (using z) to a word of length 4 and initialized to 𝟎s (using z𝟎). The introduced variables p2 and p3 are used to address positions in the longer word. The intended meaning of N is that the first rule (using r1) is applied at position 2 (using p2), followed by the second rule at position 1, and third rule at position 3 accordingly. The resulting word contains only 𝟏s (indicated by z𝟏). Overall, this corresponds to 𝟎𝟎𝟎𝟎𝟎𝟐𝟐𝟎𝟏𝟏𝟐𝟎𝟏𝟏𝟏𝟏.

Having only “well-formed” terms to consider (cf. Example 10 and Example 11), we can focus on the functional properties of rewriting.

Semantic Constraints

We formulate typed terms (Definition 31) and β-equivalence constraints characterizing word expansion (Lemma 36) and rewriting (Lemma 34). The presented terms are programs which realize the intended meaning (Example 30) of “well-formed” terms in 𝒬m and m. Specifically, G realizes word expansion, G𝟎 realizes initialization with 𝟎s, Gabcd realizes rule application, and Gji controls the effect at position i for rule application at position j. A word of length m is represented by m+1 right-hand sides of β-equivalences.

Definition 31 (Typed Terms G, G𝟎, Gabcd, Gij).
G:= λh.λg.λs𝟎s𝟏s𝐊s$sss.case hπ of s
case gδ of s𝟎s𝟎$case gδ𝟎 of s𝟏s$
𝟎case gδ𝟏 of s𝟎s𝟏
𝟏case gδ of s𝟎s𝟎
G𝟎:= λh.λx.λs𝟎s𝟏s𝐊s$sss.case hπ of s
case x of s𝟎s𝟎𝟏s$
𝟎case x of s𝟎s𝟏
𝟏case x of s𝟎s𝟎
Gabcd:= λh.λx.λs𝟎s𝟏s𝐊s$sss.case hπ of s
xs𝟎s𝟏s𝐊s$sss
𝟎case x of sdsb
𝟏case x of scsa
Gji:= {δ𝟏if i=jδ𝟎if i=j+1δelse
G:Γm(z)G𝟎:Γm(z𝟎)Gabcd:Γm(ri) for i{1,,L}

Similarly to substitutions SF and SH, we introduce the following substitution SG.

Definition 32 (Substitution SG).

margin:

SG(z):=GSG(z𝟏):=π𝟏SG(z𝟎):=G𝟎SG(rj):=GRj for j1,L

The following Example 33 illustrates how the term Gabcd represents rule application.

Example 33.

Consider for symbols 𝟎,𝟏,,𝟓 an application of the rule 𝟏𝟐𝟒𝟓 at position 2 in order to rewrite the word 𝟎𝟏𝟐𝟑 to 𝟎𝟒𝟓𝟑. Accordingly, we have:

Position 1:

G𝟏𝟐𝟒𝟓G21π𝟎=βπ𝟎

Position 2:

G𝟏𝟐𝟒𝟓G22π𝟒=βπ𝟏

Position 3:

G𝟏𝟐𝟒𝟓G23π𝟓=βπ𝟐

Position 4:

G𝟏𝟐𝟒𝟓G24π𝟑=βπ𝟑

The above observation is generalized for terms in 𝒬m in the following Lemma 34.

Lemma 34.

margin: For m>0, let a1,,am+1{𝟎,𝟏,,𝐊} and M𝒬m. If ΓmM:κ,
SG(M)[p1:=G10,,pm:=Gm0]=βπ𝟏, and SG(M)[p1:=G1i,,pm:=Gmi]=βπai for i{1,,m+1}, then a1am+1𝟏m+1.

Proof.

Induction on the size of M and case analysis using Definition 22.

The following Example 35 builds upon the previous Example 30 and illustrates the intended meaning (rewriting 𝟎s to 𝟏s) of a “well-formed” example term in 𝒬3.

Example 35.

Assume ={𝟎𝟎𝟐𝟐,𝟎𝟐𝟏𝟏,𝟐𝟎𝟏𝟏} over the alphabet {𝟎,𝟏,𝟐}, and consider the term N=r1p2(r2p1(r3p3z𝟏)) from Example 30. Replacing Gji accordingly for i{0,,5} and j{1,2,3}, we have the following β-equivalences (0)(4).

(0)SG(N)[p1:=δ,p2:=δ,p3:=δ]=βπ𝟏(1)SG(N)[p1:=δ𝟏,p2:=δ,p3:=δ]=βπ𝟎(2)SG(N)[p1:=δ𝟎,p2:=δ𝟏,p3:=δ]=βπ𝟎(3)SG(N)[p1:=δ,p2:=δ𝟎,p3:=δ𝟏]=βπ𝟎(4)SG(N)[p1:=δ,p2:=δ,p3:=δ𝟎]=βπ𝟎

In accordance with Lemma 34, we have that 𝟎4𝟏4. Equivalences (1)(4) witness the particular rewriting steps at positions 14 (cf. Example 30 and Example 33).

Complementarily to word rewriting, the following Lemma 36 characterizes word expansion and initialization with 𝟎s.

Lemma 36.

margin: If M1 such that Γ1M:κ,
SG(M)[p1:=δ]=βπ$, SG(M)[p1:=δ𝟏]=βπ𝟎, and SG(M)[p1:=δ𝟎]=βπ𝟏,
then there exists an m>0 and an N𝒬m such that ΓmN:κ,
SG(N)[p1:=G10,,pm:=Gm0]=βπ𝟏, and SG(N)[p1:=G1i,,pm:=Gmi]=βπ𝟎 for i{1,,m+1}.

Proof.

Considering the general case Mm for m>0, induction on the size of M and case analysis using Definition 22.

The following Example 37 complements the previous Example 35 and illustrates the intended meaning (word expansion and initialization with 𝟎s) of a “well-formed” term in 1.

Example 37.

Assume ={𝟎𝟎𝟐𝟐,𝟎𝟐𝟏𝟏,𝟐𝟎𝟏𝟏} over the alphabet {𝟎,𝟏,𝟐}, and consider the terms M1:=zp1(λp2.M2), M2:=zp2(λp3.M3), M3:=z𝟎p3N, and N:=r1p2(r2p1(r3p3z𝟏)) from Example 35. Proceeding bottom up, we have M33 and the following β-equivalences hold:

SG(M3)[p1:=δ,p2:=δ,p3:=δ]=βπ$SG(M3)[p1:=δ𝟏,p2:=δ,p3:=δ]=βπ𝟎SG(M3)[p1:=δ𝟎,p2:=δ𝟏,p3:=δ]=βπ𝟎SG(M3)[p1:=δ,p2:=δ𝟎,p3:=δ𝟏]=βπ𝟎SG(M3)[p1:=δ,p2:=δ,p3:=δ𝟎]=βπ𝟏

Additionally, M22, M11, and the following β-equivalences hold:

SG(M2)[p1:=δ,p2:=δ]=βπ$SG(M1)[p1:=δ]=βπ$SG(M2)[p1:=δ𝟏,p2:=δ]=βπ𝟎SG(M1)[p1:=δ𝟏]=βπ𝟎SG(M2)[p1:=δ𝟎,p2:=δ𝟏]=βπ𝟎SG(M1)[p1:=δ𝟎]=βπ𝟏SG(M2)[p1:=δ,p2:=δ𝟎]=βπ𝟏

In combination with the previous Example 35, the term M11 represents word expansion up to length 4, followed by initialization with 𝟎s, and rewriting to 𝟏s.

Next, we combine syntactic and semantic constraints in the following key Lemma 38.

Lemma 38.

margin: There exists an n such that 𝟎n+1𝟏n+1 iff there exists a term M in normal form, such that the following conditions hold:

Proof.

The direction from left to right proceeds in two steps. First, by induction on the number of rewriting steps we construct a term N𝒬n (easy converse of Lemma 34). Second, by induction on n we construct a term M1 containing N𝒬n as a subterm (easy converse of Lemma 36). Then, the solution is M:=λr1rL.λz𝟎z𝟏zp1.M.

The direction from right to left proceeds in two steps. First, by Theorem 29 we have λr1rL.λz𝟎z𝟏zp1.M for some M1. Second, by Lemma 36 and Lemma 34 we have 𝟎n+1𝟏n+1 for some n.

Finally, we present the combination of constraints from the above Lemma 38 as a matching instance F𝖷=βN. This constitutes the main result of the present work.

Theorem 39.

margin: Problem 𝟎+𝟏+ many-one reduces to higher-order β-matching.

Proof.

Given a simple semi-Thue system ={R1,,RL} due to Lemma 38 there exists an n such that 𝟎n+1𝟏n+1 iff the instance F𝖷=βN of higher-order β-matching is solvable, where

  • N:=λy.y(λu.u)π$π$π𝟎π𝟏

  • σ:=Γ1(r1)Γ1(rL)Γ1(z𝟎)Γ1(z𝟏)Γ1(z)Γ1(p1)κ

  • τ:=((κκ)κκκκι)ι

  • F:στ

  • N:τ

Theorem 40.

margin: Higher-order β-matching (Problem 7) is undecidable.

Proof.

By reduction from the undecidable Problem 𝟎+𝟏+ (Theorem 17 and Theorem 39).

4 Mechanization

This section provides a brief overview over the mechanization of undecidability of higher-order β-matching (Theorem 40) using the Coq proof assistant [19]. The mechanization is constructive (in the technical sense of axiom-free Coq) and spans approximately 4000 lines of code, consisting of the following parts:

  • HOMatching.v contains definitions of the simply typed λ-calculus [ ] and higher-order β-matching [ ].

  • Util/stlc_facts.v and Util/term_facts.v contain basic properties of the simply typed λ-calculus, such as confluence of β-reduction [ ], substitution lemmas [ ], and type preservation properties [ ].

  • Reductions/SSTS01_to_HOMbeta.v contains the reduction from Problem 𝟎+𝟏+ to higher-order β-matching [ ].

  • HOMatching_undec.v contains the undecidability result for higher-order β-matching [ ].

The simple type system stlc is mechanized in HOMatching.v, borrowing the existing term definitions from the library [ ], for which variable binding is addressed via the unscoped de Bruijn approach [4]. The proposition stlc Gamma M t mechanizes that the term M is assigned the simple type t in the simple type environment Gamma.

Inductive ty : Type :=
| atom (* type variable *)
| arr (s t : ty). (* function type *)
Inductive term : Type :=
| var (n : nat) : term (* term variable *)
| app (s : term) (t : term) : term (* application *)
| lam (s : term). (* abstraction *)
Inductive stlc (Gamma : list ty) : term -> ty -> Prop :=
| stlc_var x t : nth_error Gamma x = Some t ->
stlc Gamma (var x) t (* variable rule *)
| stlc_app M N s t : stlc Gamma M (arr s t) -> stlc Gamma N s ->
stlc Gamma (app M N) t (* application rule *)
| stlc_lam M s t : stlc (cons s Gamma) M t ->
stlc Gamma (lam M) (arr s t). (* abstraction rule *)

Higher-order β-matching is mechanized as the predicate HOMbeta: given terms F of type arr s t and N of type t, is there a simply typed term M of type s such that app F M is β-equivalent (reflexive, symmetric, transitive closure of step) to N?

Definition HOMbeta : { ’(s, t, F, N) : (ty * ty * term * term)
| stlc nil F (arr s t) /\ stlc nil N t } -> Prop :=
fun ’(exist _ (s, t, F, N) _) =>
exists (M : term), stlc nil M s /\
clos_refl_sym_trans term step (app F M) N.

The proposition undecidable HOMbeta [ ] mechanizes the undecidability of the predicate HOMbeta, relying on the following library definition [7, Chapter 19]. A predicate p is undecidable, if existence of a computable decider for p implies recursive co-enumerability of the (Turing machine) Halting Problem.

Definition undecidable {X} (p : X -> Prop) :=
decidable p -> enumerable (complement SBTM_HALT).

Since the Halting Problem is recursively enumerable, decidability of p would imply decidability of the Halting Problem.

5 On Intersection Type Inhabitation and 𝝀-Definability

We conclude the technical presentation with the following observation: the presented approach reducing Problem 𝟎+𝟏+ to higher-order β-matching is easily transferred to intersection type inhabitation and λ-definability.

The following Remark 41 shows the structure of the corresponding finite model with respect to the present construction.

 Remark 41.

Terms in Definition 31 realize certain finite functions as follows.

  • δi for i𝒜 realizes a member of the finite function family specified by the partial function table (i).

  • G𝟎 realizes a member of the family specified by (()(𝟎𝟎)()(𝟏$)(𝟎)(𝟎𝟏)(𝟏)(𝟎𝟎)).

  • Gabcd realizes a member of the family specified by ((𝟏)(ca)(𝟎)(db)).

  • G realizes a member of the family specified by (()(()𝟎)𝟎)()((()$(𝟎)𝟏)$)(𝟎)((𝟏)𝟎)𝟏)(𝟏)(()𝟎)𝟎)).

The above specifications follow the intended meaning (Example 30) of the corresponding programs, when used in “well-formed” terms in 𝒬m and m. For example, we have G𝟎δπ1=βπ$, in agreement with the above Remark 41.

Let us state the relationship between simple semi-Thue system rewriting, higher-order β-matching, λ-definability, and intersection type inhabitation.

Proposition 42.

Given a simple semi-Thue system , one can construct simply typed terms F and N, an intersection type T, and a finite function such that the following statements are equivalent:

  1. 1.

    There exists an n such that 𝟎n+1𝟏n+1.

  2. 2.

    The instance F𝖷=βN of higher-order β-matching is solvable.

  3. 3.

    The intersection type T is inhabited.

  4. 4.

    The finite function is λ-definable.

The presented approach shows (1)(2). Of course, (1)(3) can be concluded from undecidability of intersection type inhabitation [20] and (1)(4) from undecidability of λ-definability [12], along with corresponding constructions. However, we make the following two observations regarding an alternative, uniform argument. First, based on Remark 23, the approach is easily adapted to show (1)(3), such that the inhabitant is essentially a member of 1. This is already done in the existing mechanized reduction from Problem 𝟎+𝟏+ to intersection type inhabitation [ ]. Second, based on Remark 41, the approach can be adapted to show (1)(4), such that the realizer is essentially a member of 1. This is further supported by the known correspondence between intersection type inhabitation (in the fragment at hand) and λ-definability [15].

6 Conclusion

The present work presents a new, mechanized proof of the undecidability of higher-order β-matching. The mechanization is contributed to the existing Coq Library of Undecidability Proofs [8].

While the existing proofs by Loader [13] and by Joly [11] are each based on variants of λ-definability, the presented proof reduces a rewriting problem (Problem 𝟎+𝟏+) to higher-order β-matching. As a result, the proof is simpler to verify in full detail and yields a concise mechanization. Additionally, undecidability of Problem 𝟎+𝟏+ is already mechanized, and is part of the Coq Library of Undecidability Proofs.

Besides the main technical result, we argue that the present approach is uniformly applicable to show undecidability of intersection type inhabitation and λ-definability. The former is already established and implemented as refinement [6] of Urzyczyn’s undecidability result [20]. The latter is an application of the known correspondence between intersection type inhabitation and λ-definability [15].

The order of a type is the maximal nesting depth of the arrow type constructor to the left, starting by order(ι)=1. The present approach agrees with Loader’s result that β-matching is undecidable at order 6. While Loader conjectures that order 5 may suffice, neither Loader’s technique (as observed by Joly [11, Section 5]), nor the present approach are applicable at order 5. Constraining the shape of candidate solutions both in the present work as well as in Loader’s proof seems to necessitate order 6. While β-matching at order 4 is decidable [14], decidability at order 5 remains an open question.

As pointed out in Remark 13, the presented approach might be adapted to scenarios beyond the simply typed λ-calculus. An interesting alternative to the simple type system is the Coppo-Dezani intersection type assignment system [3], which characterizes strong normalization [1]. Well-typedness in this system would allow for more solution candidates and require more effort with respect to syntactic constraints (cf. Section 3). It is reasonable to believe that higher-order β-matching is undecidable in any type system for the λ-calculus which includes the simple type system.

Interaction with a proof assistant supported the conception of the present approach both at the intuitive and at the technical level. The infrastructure for the λ-calculus provided by the undecidability library served as an excellent starting point for the development. While proofs of the individual lemmas (cf. Section 3) in the development are quite simplistic, they involve exhaustive case analyses and are sensitive to the exact details of the underlying construction. Bookkeeping capabilities of the Coq proof assistant, proof automation based on auto and lia tactics, and quick adaptability to an evolving construction were of great benefit. Additionally, once all cases are covered, there is no room for doubt that the construction is correct. As a result, the proof was developed via interaction with the proof assistant prior to being transcribed into a traditional written format.

References

  • [1] Roberto M. Amadio and Pierre-Louis Curien. Domains and lambda-calculi, volume 46 of Cambridge tracts in theoretical computer science. Cambridge University Press, 1998.
  • [2] Hendrik Pieter Barendregt, Wil Dekkers, and Richard Statman. Lambda Calculus with Types. Perspectives in logic. Cambridge University Press, 2013. URL: http://www.cambridge.org/de/academic/subjects/mathematics/logic-categories-and-sets/lambda-calculus-types.
  • [3] Mario Coppo and Mariangiola Dezani-Ciancaglini. An extension of the basic functionality theory for the lambda-calculus. Notre Dame Journal of Formal Logic, 21(4):685–693, 1980. doi:10.1305/ndjfl/1093883253.
  • [4] Nicolaas Govert De Bruijn. Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. In Indagationes Mathematicae (Proceedings), volume 75, pages 381–392. North-Holland, 1972.
  • [5] Gilles Dowek. Higher-order unification and matching. In John Alan Robinson and Andrei Voronkov, editors, Handbook of Automated Reasoning (in 2 volumes), pages 1009–1062. Elsevier and MIT Press, 2001. doi:10.1016/B978-044450813-3/50018-7.
  • [6] Andrej Dudenhefner and Jakob Rehof. Undecidability of intersection type inhabitation at rank 3 and its formalization. Fundam. Informaticae, 170(1-3):93–110, 2019. doi:10.3233/FI-2019-1856.
  • [7] Yannick Forster. Computability in constructive type theory. Die Publikationen der UdS, 2021. doi:10.22028/D291-35758.
  • [8] Yannick Forster, Dominique Larchey-Wendling, Andrej Dudenhefner, Edith Heiter, Dominik Kirst, Fabian Kunze, Gert Smolka, Simon Spies, Dominik Wehr, and Maximilian Wuttke. A Coq library of undecidable problems. In The Sixth International Workshop on Coq for Programming Languages (CoqPL 2020), 2020. URL: https://github.com/uds-psl/coq-library-undecidability.
  • [9] Gérard P. Huet. The undecidability of unification in third order logic. Inf. Control., 22(3):257–267, 1973. doi:10.1016/S0019-9958(73)90301-X.
  • [10] Gérard P. Huet. A unification algorithm for typed lambda-calculus. Theor. Comput. Sci., 1(1):27–57, 1975. doi:10.1016/0304-3975(75)90011-0.
  • [11] Thierry Joly. On lambda-definability I: the fixed model problem and generalizations of the matching problem. Fundam. Informaticae, 65(1-2):135–151, 2005. URL: http://content.iospress.com/articles/fundamenta-informaticae/fi65-1-2-07.
  • [12] Ralph Loader. The undecidability of λ-definability. In Logic, meaning and computation: Essays in memory of Alonzo church, pages 331–342. Springer, 2001.
  • [13] Ralph Loader. Higher order beta matching is undecidable. Log. J. IGPL, 11(1):51–68, 2003. doi:10.1093/JIGPAL/11.1.51.
  • [14] Vincent Padovani. Decidability of fourth-order matching. Mathematical Structures in Computer Science, 10(3):361–372, 2000. URL: http://journals.cambridge.org/action/displayAbstract?aid=44653.
  • [15] Sylvain Salvati, Giulio Manzonetto, Mai Gehrke, and Henk Barendregt. Loader and Urzyczyn are logically related. In Artur Czumaj, Kurt Mehlhorn, Andrew M. Pitts, and Roger Wattenhofer, editors, Automata, Languages, and Programming - 39th International Colloquium, ICALP 2012, Warwick, UK, July 9-13, 2012, Proceedings, Part II, volume 7392 of Lecture Notes in Computer Science, pages 364–376. Springer, 2012. doi:10.1007/978-3-642-31585-5_34.
  • [16] Simon Spies and Yannick Forster. Undecidability of higher-order unification formalised in Coq. In Jasmin Blanchette and Catalin Hritcu, editors, Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2020, New Orleans, LA, USA, January 20-21, 2020, pages 143–157. ACM, 2020. doi:10.1145/3372885.3373832.
  • [17] Richard Statman. Completeness, invariance and lambda-definability. J. Symb. Log., 47(1):17–26, 1982. doi:10.2307/2273377.
  • [18] Colin Stirling. Decidability of higher-order matching. Log. Methods Comput. Sci., 5(3), 2009. URL: http://arxiv.org/abs/0907.3804.
  • [19] The Coq Development Team. The Coq proof assistant, July 2023. doi:10.5281/zenodo.8161141.
  • [20] Paweł Urzyczyn. Inhabitation of low-rank intersection types. In Pierre-Louis Curien, editor, Typed Lambda Calculi and Applications, 9th International Conference, TLCA 2009, Brasilia, Brazil, July 1-3, 2009. Proceedings, volume 5608 of Lecture Notes in Computer Science, pages 356–370. Springer, 2009. doi:10.1007/978-3-642-02273-9_26.