Horn Clause Specifications

with Polymorphic Types

Dissertation zur Erlangung des Grades des

Doktors der Naturwissenschaften der Universität Dortmund am Fachbereich Informatik

von Michael Hanus

Dortmund

Tag der mündlichen Prüfung:  20. Dezember 1988
Dekan:  Prof. Dr. H. Weber
Gutachter:  Prof. Dr. H. Ganzinger

Prof. Dr. A. B. Cremers

Abstract

This thesis presents a Horn clause logic with equality where functions and predicates are declared with polymorphic types. Types are parameterized with type variables. This leads to an ML-like polymorphic type system. A type declaration of a function or predicate restricts the possible use of this function or predicate so that only certain terms are allowed to be arguments for this function or predicate. The semantic models of polymorphic Horn clause specifications are defined and several proof methods (deduction, resolution, paramodulation, rewriting and narrowing) for this kind of specifications are given. Moreover, it is shown that higher-order programming techniques can be applied in our framework.

Preface

Horn clause logic with equality is an integration of logic programming based on predicates and functional programming based on equations. In logic programming the basic objects (terms) are not classified: Each function and predicate may have any term as an argument. Modern functional programming languages have polymorphic type systems which make it possible to detect specific programming errors at compile time. Hence a polymorphic type system for Horn clause logic with equality is a better integration of the features of functional and logic programming languages. This thesis presents a Horn clause logic with equality, where functions and predicates are declared with polymorphic types. This is done in a fully declarative way: First, a modeltheoretic semantics of types is defined. Then several proof methods are presented for Horn clause specifications with polymorphic types, starting from deduction and ending in a narrowing procedure combined with resolution (the completeness of the latter proof procedure is only ensured for a restricted class of specifications). Finally, some implementation aspects are discussed (optimization and permitting higher-order programming). Chapter 1 presents examples, basic notions and the syntactic portion of Horn clause specifications with polymorphic types. Chapter 2 defines the semantics of polymorphic specifications by the notion of “validity”. Chapter 3 presents a complete polymorphic Horn clause calculus for the deduction of valid properties. The calculus is also used for the construction of an initial model. The unification procedure for polymorphic terms presented in chapter 4 is the basis of various proof procedures: Chapter 5 presents a resolution procedure, where additional equality axioms define the equality predicate as a congruence relation on polymorphic terms. Chapter 6 presents a paramodulation procedure as a refinement of resolution with a particular inference rule for the equality predicate. Chapter 7 introduces reduction and conditional rewriting to define the Church-Rosser property of polymorphic Horn clause specifications. For such specifications there exists a more efficient proof procedure than paramodulation: The narrowing procedure is introduced in chapter 8. It serves as the operational semantics of polymorphic Horn clause specifications. Possibilities for optimizations that are related to types are presented in chapter 9. Chapter 10 discusses higher-order programming techniques in the context of polymorphic specifications. Chapter 11 describes some implementation aspects.

Acknowledgements

I would like to thank Prof. Harald Ganzinger for his guidance in carrying out this research. I am also grateful to Hubert Bertling for many discussions on logical foundations.

Dortmund, September 1988 Michael Hanus

Contents

1 Polymorphic specifications 5 1.1 Basic notions and notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.2 The signature of types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.3 Syntax of polymorphic specifications . . . . . . . . . . . . . . . . . . . . . . . . 11

2 Semantics of polymorphic specifications 19

3 Deduction 29 3.1 The polymorphic Horn clause calculus . . . . . . . . . . . . . . . . . . . . . . . 29 3.2 Initial model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

4 Unification 42

5 Resolution 48 5.1 Soundness and completeness of resolution . . . . . . . . . . . . . . . . . . . . . 48 5.2 Resolution with most general unifiers . . . . . . . . . . . . . . . . . . . . . . . . 56

6 Paramodulation 61 6.1 Soundness and completeness of paramodulation . . . . . . . . . . . . . . . . . . 61 6.2 Paramodulation with most general unifiers . . . . . . . . . . . . . . . . . . . . . 72

7 Reduction and conditional rewriting 79 7.1 Reductions for polymorphic specifications . . . . . . . . . . . . . . . . . . . . . 79 7.2 Confluence and conditional rewriting . . . . . . . . . . . . . . . . . . . . . . . . 83

8 Narrowing 93 8.1 Soundness and completeness of narrowing . . . . . . . . . . . . . . . . . . . . . 94 8.2 Narrowing with most general unifiers . . . . . . . . . . . . . . . . . . . . . . . . 98 9 Optimization 107

9.1 Type-generally defined predicates . . . . . . . . . . . . . . . . . . . . . . . . . . 107 9.2 Relational specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

10 Higher-order programming 124

11 Implementation 130 11.1 Type checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 11.2 Operational semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 11.3 Efficiency improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

12 Conclusions 137

Bibliography 139

Index 147

Chapter 1

Polymorphic specifications

During recent years, various attempts have been made to integrate functional and logic programming languages (for an outline, see [Bellia/Levi 86]). Several authors have shown that Horn clause logic with equality is an amalgamation of functional and logic languages ([Goguen/ Meseguer 86], [Dershowitz/Plaisted 85], among others). Although [van Emden/Yukawa 87] state “One of the reasons why logic programming succeeded where other resolution theorem proving had failed … was that in logic programming equality was avoided like the plague”, much progress has been made to include equality in logic programming with an acceptable operational semantics (see [DeGroot/Lindstrom 86] for a collection of system proposals that combine functional and logic programming). In logic programming the basic objects (terms) are not classified: Each function and predicate may have any term as an argument [Lloyd 87]. This point of view is not justified for the logic programming language Prolog [Clocksin/Mellish 87]: Several predefined predicates have restrictions on their arguments (e.g., is or name). In application programs only certain terms are allowed to be arguments for a function or predicate. It is impossible to express these restrictions in a natural way in Prolog. Modern functional programming languages, like ML [Milner 84] [Harper 86], Miranda [Turner 85] [Turner 86] and HOPE [Burstall/MacQueen/ Sannella 80], have polymorphic type systems which make it possible to detect specific programming errors at compile time. Therefore a polymorphic type system for Horn clause logic with equality is a better integration of the features of functional and logic programming languages. Although the languages OBJ2 [Futatsugi et al. 85] and EQLOG [Goguen/Meseguer 86], which are based on an equational logic, offer parametric polymorphism by a concept of parameterized modules, this form of polymorphism is different from the parametric polymorphism in functional languages. For instance, the application of a generic OBJ2-module for sorting a list of an arbitary type to a list of integers and a list of strings requires the creation of two new modules for sorting lists of integers and lists of strings, respectively. The sort and function names in these new modules are different. In a functional programming language, a polymorphic sort function can be applied to lists of different types without creating new functions. This will also be the case in our polymorphic Horn clause logic with equality. Therefore the features of polymorphically typed functional languages and logic programming languages will be both available in our polymorphic equational logic language. In addition, programs of typed logic programming languages may be more efficient than programs of an untyped language. For instance, we want to define the predicate append that is satisfied if and only if the three arguments are lists and the third list is the concatenation of the first and the second. The following solution is wrong from a typing point of view:

     append([],L,L) ←
     append([E|R],L,[E|RL]) ← append(R,L,RL)

By this definition, the goal append([],3,3) is provable in contrast to our intuition. A correct definition is:

     append([],[],[]) ←
     append([],[E|R],[E|R]) ← append([],R,R)
     append([E|R],L,[E|RL]) ← append(R,L,RL)

If the first and second argument of an append-literal are non-empty lists, a proof with the second definition needs more steps than a proof with the first one. In a typed logic language the first definition can already be correct. Many authors have investigated types in logic programming languages. There are two principal starting points in research:

1. The declarative approach: The programmer has to declare all types he wants to use and the types of all functions and predicates in the program. These proposals have a formal semantics of the notion of a type, i.e., types represent subsets of carrier sets of interpretations. [Padawitz 88] has proposed a Horn clause logic with equality with a many-sorted type structure. There each type corresponds to a subset of the carrier set in the interpretation. He restricts the interpretations to non-empty carrier sets for all types, which simplifies the proof procedures. [Goguen/Meseguer 84] have shown the problems that occur if the carrier sets are empty, which might arise in practice. [Goguen/Meseguer 86] and [Smolka 86b] have proposed ordered sorted type systems for Horn clause logic with equality. Each type represents a subset of the carrier set in an interpretation, and the ordering of types implies a subset relation on the corresponding sets. [Aït-Kaci/Nasr 86] have proposed a type system with subtypes and inheritence based on a similar semantics. From an operational point of view, the approaches with subtypes require a unification procedure

that takes account of types, i.e., types are present at run time.

2. The operational approach: The aim of these type systems is to ensure that predicates are only called with appropriate arguments at run time. This should be achieved by a static analysis of the program. A lot of these approaches do not require any type declaration but the types will be inferred by a type checker. These approaches have only a syntactic notion of a type. [Mishra 84] and [Zobel 87] have presented type inference systems for detecting programming errors in a given Prolog program. [Kanamori/Horiuchi 85] and [Kluźniak 87] have developed algorithms for inferring types of variables in a Prolog program. [Horiuchi/ Kanamori 87] have applied abstract interpretation techniques to infer polymorphic types that are specified by Horn clauses. [Yardeni/Shapiro 87] have presented a type-checking algorithm where types are regular sets of ground atoms.

We are interested in a polymorphic type system where type declarations may contain type variables that are universally quantified over all types [Damas/Milner 82]. [Mycroft/O’Keefe 84] have investigated such a type system for Prolog. In their proposal, the programmer has to declare the types of functions and predicates. But it is not a declarative approach because they have no semantic notion of a type. They have put restrictions on the use of polymorphic types in function declarations and clauses. Their programs can be executed without dynamic type checking. But their type system cannot be easily extended to Horn clause logic with equality because they forbid type declarations of the form

func length: list(α) → nat

(in their type system, each type variable occurring in the argument type of a function must also occur in the result type [Mycroft 87]). Unfortunately, types of this kind are typical in functional programming. To exclude these is too restrictive for functional languages. [Dietrich/Hagl 88] have extended this type system to subtypes on the basis of mode declarations for the predicates. They have also only a syntactic notion of a type. TEL [Smolka 88] is a logic language with functions and a polymorphic type system with subtypes. Since subtypes are included, there are several restrictions on the use of polymorphic types which prevents in particular the application of higher-order programming techniques. This thesis presents a declarative approach to a generalized polymorphic type system for Horn clause logic with equality. The topics of this thesis are:

• We present a rather general polymorphic type system: We do not restrict the use of types. In contrast to [Mycroft/O’Keefe 84] and [Smolka 88] (among others), any polymorphic type expression may be argument or result type of a function or predicate. No difference will be made in the typing of the head and the body of a clause.

• Our approach is declarative: The semantics of types is defined in a model-theoretic way in contrast to other type systems for Prolog where types are viewed as sets of ground terms.

• We investigate several proof methods for our specifications (deduction, resolution, paramodulation, reduction, narrowing) and prove soundness and completeness.

• Several optimizations of the proof procedures are presented for specific subclasses of programs.

• Higher-order programming techniques can be applied in our framework. We present an interesting class of specifications (logic programs) that are ill-typed in the sense of other polymorphic type systems for logic programming but are well-typed in our framework.

Let us start by looking at an example of a polymorphically typed Horn clause specification in our sense. First the programmer has to specify the types that he wants to use in the clauses. There are basic types like int or bool, and type constructors that create new types from given types. E.g., the type constructor list with arity 1 creates from the type int the type of integer lists list(int). Type expressions may contain type variables which are universally quantified over all types. In the following we use α, β for type variables. The type expression list(α) represents the types

list(int)  list(bool)  list(list(int))  …

or, in general, a list of any type. Two functions are defined on any list: The constant function [] that represents the empty list, and the function • that concatenates an element with a list of the same type (throughout this thesis we use the Prolog notation for lists [Clocksin/Mellish 87]). The type declarations for these two functions are:

func []: → list(α)
func •: α, list(α) → list(α)

The function append has two arguments and concatenates two lists of the same type. Therefore append has the following type declaration:

func append: list(α), list(α) → list(α)

The following two unconditional equations define the semantics of append and are well-typed in our sense, if the variables L and R are of type list(α) and the variable E is of type α:

     append([],L) ≡ L ←

     append([E|R],L) ≡ [E|append(R,L)] ←

Next we define a predicate member with two arguments. It is satisfied if the second argument (a list) contains the first argument as an element. The predicate member has the following type declaration:

pred member: α, list(α)

The following three clauses define the semantics of member and are well-typed in our sense, if variable L is of type list(α) and variables E and F are of type α:

     member(E,[E|L]) ←
     member(E,[F|L]) ← member(E,L)
     member(4,[1,2,3,4]) ←

The last clause is redundant but can be used for a quick proof of the literal member(4,[1,2,3,4]). Note that the arguments of the head of the last clause have types int and list(int). Hence it is not a well-typed clause in the sense of [Mycroft/O’Keefe 84] since the head of the clause has not the most general type. The application of this feature in order to express higher-order programming techniques and more examples are given in the rest of this thesis.

1.1 Basic notions and notations

The following conventions are used in this thesis: The symbols □ and designate the end of definitions and end of proofs, respectively. Example specifications are written in this font. If M and N are sets, then M − N denotes the difference of these sets defined by M − N := {x ∈ M | x ∉ N}. If f: A → B is a function and A′ ⊆ A, then f|_{A′} denotes the restriction of f to the domain A′. The composition of two functions f: A → B and g: B → C, denoted g ∘ f, is defined by (g ∘ f)(x) := g(f(x)) for all x ∈ A. In the rest of this section we review some basic definitions from many-sorted algebraic specifications (e.g., [Goguen/Thatcher/Wagner 78]) that will be used in this thesis. A signature Σ is a pair (S, O), where S is a set of sorts and O is a family of operator sets of the form O = (O_{w,s}|w ∈ S^{∗}, s ∈ S). We write o: s_{1}, …, s_{n} → s ∈ O instead of o ∈ O_{(s_{1},...,s_{n}),s}. An operator of the form o: → s is also called a constant of sort s. A signature Σ = (S, O) is interpreted by a Σ-algebra A = (S_{A}, O_{A}) which consists of an Ssorted domain S_{A} = (S_{A,s}|s ∈ S) and an operation o_{A}: S_{A,s_{1}}, …, S_{A,s_{n}} → S_{A,s} ∈ O_{A} for any o: s_{1}, …, s_{n} → s ∈ O. A set of Σ-variables is an S-sorted set V = (V_{s}|s ∈ S). The set of Σ-terms of sort s with variables from V, denoted T_{Σ,s}(V), is inductively defined by x ∈ T_{Σ,s}(V) for all x ∈ V_{s}, c ∈ T_{Σ,s}(V) for all c: → s ∈ O, and o(t_{1}, …, t_{n}) ∈ T_{Σ,s}(V) for all o: s_{1}, …, s_{n} → s ∈ O (n > 0) and all t_{i} ∈ T_{Σ,s_{i}}(V). We write T_{Σ}(V) for all Σ-terms with variables from V and T_{Σ} for the set of ground terms T_{Σ}(∅). By T_{Σ}(V) we also denote the term algebra. A variable assignment is a mapping a: V → S_{A} with a(x) ∈ S_{A,s} for all variables x ∈ V_{s} (more precisely, it is a family of mappings (a_{s}: V_{s} → S_{A,s}|s ∈ S)). A Σ-homomorphism from a Σ-algebra A = (S_{A}, O_{A}) into a Σ-algebra B = (S_{B}, O_{B}) is a mapping (family of mappings) h: S_{A} → S_{B} with the properties h_{s}(c_{A}) = c_{B} for all c: → s ∈ O and h_{s}(o_{A}(a_{1}, …, a_{n})) = o_{B}(h_{s_{1}}(a_{1}), …, h_{s_{n}}(a_{n})) for all o: s_{1}, …, s_{n} → s ∈ O (n > 0) and all a_{i} ∈ S_{A,s_{i}}. The following lemma shows an important property of term algebras:

Lemma 1.1 (Free term algebra) Let Σ be a signature, A = (S_{A}, O_{A}) be a Σ-algebra and a: V → S_{A} be an assignment for variables from V. There exists a unique Σ-homomorphism h: T_{Σ}(V) → S_{A} with h(v) = a(v) for all v ∈ V.

1.2 The signature of types

In a type declaration of a function or predicate each argument/result type is a term in a signature of types. A signature of types contains basic types like int as constants and type constructors like list(⋯).

Definition 1.2 H = (T y, Ht) is a signature of types if H is a single-sorted signature with T y = {type}. By ar(h) we denote the arity of an operator: Operators of the form

h: → type

are called basic types and have arity ar(h) = 0, whereas operators of the form

h: \underbrace{type, …, type}_{n} → type

are called type constructors and have arity ar(h) = n > 0. By X we denote a set of type variables. A type expression or (polymorphic) type is a term from T_{H}(X), a monomorphic type is a term from T_{H}. Since we have only one sort in the signature of types, we will also use H to denote the set of type constructors Ht. □

In the following we assume that T_{H} ≠ ∅, i.e., there exist basic types like bool, int ∈ T_{H}. Later we shall need the notion of type substitutions:

Definition 1.3 A type substitution σ is an H-homomorphism σ: T_{H}(X) → T_{H}(X). We use the following notation for the class of all type substitutions:

T S(H, X) := {σ: T_{H}(X) → T_{H}(X) | σ is a type substitution}

Type substitutions are extended to tuples of type expressions in the following way (whereas (τ_{1}, …, τ_{n} → τ) is an (n + 1)-tuple of types):

\begin{aligned}σ ((τ_{1}, …, τ_{n})) & := & (σ(τ_{1}), …, σ(τ_{n})) \\ σ ((τ_{1}, …, τ_{n} → τ)) & := & σ(τ_{1}), …, σ(τ_{n}) → σ(τ) \end{aligned} □

We remark that the composition of two type substitutions and the inverse of a bijective type substitution are again type substitutions. This motivates the next definition.

Definition 1.4 τ, τ′ ∈ T_{H}(X) are called equivalent if there exists a bijective type substitution σ with σ(τ) = τ′. □

Type variables in type expressions will be universally quantified over all types. Therefore the names of the type variables are irrelevant. The notion of a type variable renaming will express this property.

Definition 1.5 Let σ ∈ T S(H, X) and X′ ⊆ X be a subset of X. σ is called a renaming of the type variables in X′, if the following conditions hold:

a) ∀α ∈ X′: σ(α) ∈ X

b) ∀α ∈ X − X′: σ(α) = α

c) ∀α, β ∈ X′: σ(α) = σ(β) ⇒ α = β

□

The proof of the next proposition is obvious:

Proposition 1.6 Let X′ ⊆ X be a finite subset of X and σ ∈ T S(H, X) be a renaming of type variables from X′. Then the types τ and σ(τ) are equivalent for all types τ ∈ T_{H}(X′).

1.3 Syntax of polymorphic specifications

A polymorphic specification consists of a specification of a signature of types, type declarations of functions and predicates and a set of well-typed Horn clauses. A polymorphic signature contains all type declarations of a polymorphic specification. In the rest of this thesis we will assume that X is an infinite set of type variables with α, β, γ ∈ X.

Definition 1.7 A polymorphic signature Σ for specifications is a triple (H, F unc, P red) with:

• H is a signature of types with T_{H} ≠ ∅

• F unc is a set of function declarations of the form f:τ_{1}, …, τ_{n} → τ with τ_{i}, τ ∈ T_{H}(X), n ≥ 0, where, in addition, τ_{f} = τ′_{f} whenever f:τ_{f}, f:τ′_{f} ∈ F unc.

• P red is a set of predicate declarations of the form p:τ_{1}, …, τ_{n} (p ≠ ‘≡’) with τ_{i} ∈ T_{H}(X) (n ≥ 0) and ‘≡’:α, α ∈ P red, where, in addition, τ_{p} = τ′_{p} whenever p:τ_{p}, p:τ′_{p} ∈ P red.

□

The additional restrictions exclude overloading. With these restrictions it is possible to compute the most general type of a term. Therefore the user need not annotate terms in a clause with type expressions (see section 11.1). Note that there are no restrictions on the use of type variables in function declarations in contrast to other polymorphic type systems for logic programming, e.g., [Mycroft/O’Keefe 84], [Smolka 88]. The following specification of a polymorphic signature will be used in later examples. Declarations of basic types and type constructors, functions, and predicates are preceded by the keywords “type”, “func” and “pred”, respectively.

type int/0, bool/0, list/1, pred2/2

     func true, false: → bool

func []: → list(α)

func •: α, list(α) → list(α)

func pred member: → pred2(α, list(α))

pred member: α, list(α)

pred apply2: pred2(α, β), α, β

int and bool are basic types, list is a type constructor with arity 1 and pred2 is a type constructor with arity 2. The predicate apply2 will be interpreted like call in Prolog: If the first argument has type pred2(α, β) and the next arguments have types α and β, then it is equivalent to the application of the first argument to the other two arguments. pred member is a constant of type pred2(α, list(α)). The equivalence of apply2(pred member,…) and member(…) will be stated in a specific clause (see below). The variables in a polymorphic specification are not quantified over all objects, but vary only over objects of a particular type. Thus each variable is annotated with a type expression:

Definition 1.8 V ar is an infinite set of variable names that are distinguishable from symbols in polymorphic signatures and type variables. If Σ = (H, F unc, P red) is a polymorphic signature, the set of typed variables V ar_{Σ,X} is defined as follows:

V ar_{Σ,X} := {x:τ | x ∈ V ar, τ ∈ T_{H}(X)}

V is a set of typed variables with unique types, written V ⊆_{U}V ar_{Σ,X}, if V ⊆ V ar_{Σ,X} and τ = τ′ whenever x:τ, x:τ′ ∈ V. □

The notion of “typed variables with unique types” is not necessary for the definition of the semantics and the proof procedures, but it is useful for optimization and detection of type errors at compile time. Hence we define the semantics for arbitrary sets of typed variables, whereas in polymorphic specifications the clauses must have variables with unique types so that optimizations and type-checking are possible. According to [Church 40], we embed types in terms, i.e., each symbol in a term is annotated with an appropriate type expression. These annotations are useful for the unification of polymorphic terms (cf. chapter 4). The type annotations need not be provided by the user, as most general type annotations can be computed automatically (cf. section 11.1).

Definition 1.9 Let Σ = (H, F unc, P red) be a polymorphic signature and V ⊆ V ar_{Σ,X}. A (Σ, X, V)-term of type τ ∈ T_{H}(X) is either

• a variable x:τ ∈ V,

• a constant c:τ with c: → τ_{c} ∈ F unc so that there exists a type substitution σ ∈ T S(H, X) with σ(τ_{c}) = τ, or

• a composite term of the form f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ (n > 0) with f:τ_{f} ∈ F unc so that there exists a type substitution σ ∈ T S(H, X) with σ(τ_{f}) = τ_{1}, …, τ_{n} → τ and t_{i}:τ_{i} is a (Σ, X, V)-term of type τ_{i} (i = 1, …, n).

Furthermore we define the following sets:

T erm_{Σ,τ} (X, V ) := { t | t is a (Σ, X, V)-term of type τ}
T erm_{Σ}(X, V )  := { t | ∃τ ∈ T_{H}(X) with t ∈ T erm_{Σ,τ} (X, V)}

A ground term is a term of the set T erm_{Σ}(X, ∅). □

Each occurrence of a variable in a term has the same type, whereas different occurrences of a function may have different types. We call terms from T erm_{Σ}(X, V) well-typed terms, whereas terms that have the same structure as well-typed terms but violate the type conditions are called ill-typed terms. Examples: If we have the declarations

func f: int, bool → bool
var x:α

then the term f(x:α,x:α):bool is ill-typed. If we have the additional declaration

func id: α → α

then the term

f(id(2:int):int, id(true:bool):bool):bool ∈ T erm_{Σ,bool}(∅, ∅)

is a well-typed ground term.

Definition 1.10 Let Σ = (H, F unc, P red) be a polymorphic signature and V ⊆ V ar_{Σ,X}.

• A (Σ, X, V)-atom has the form p(t_{1}:τ_{1}, …, t_{n}:τ_{n}), where p:τ_{p} ∈ P red and there exists a type substitution σ ∈ T S(H, X) with σ(τ_{p}) = τ_{1}, …, τ_{n} and t_{i}:τ_{i} ∈ T erm_{Σ}(X, V) (i = 1, …, n). If p = ‘≡’ and n = 2, then we call ‘≡’(t_{1}:τ, t_{2}:τ) a (Σ, X, V)-equation and use the infix notation t_{1}:τ_{1} ≡ t_{2}:τ_{2}. We denote by pred(A) the predicate name of an atom A: If A = p(⋯) is a (Σ, X, V)-atom, then pred(A) = p.

• A (Σ, X, V)-goal is a finite set of (Σ, X, V)-atoms.

• A (Σ, X, V)-clause is a pair (P, G), where P is a (Σ, X, V)-atom and G is a (Σ, X, V)- goal. If G = {A_{1}, …, A_{n}}, we also write

P ← A_{1}, …, A_{n}.

P is called head and G body of the clause. P ← G is called conditional equation if P is an equation, otherwise it is called relational clause. A conditional equation P ← G is called unconditional equation if G = ∅.

A Σ-term (atom, goal, clause) is a (Σ, X, V)-term (atom, goal, clause) for some V ⊆ V ar_{Σ,X}. □

For convenience we sometimes omit the curly brackets around a goal and we identify a goal containing only one atom with that atom. Note that again there are no restrictions on the use of types in clauses in contrast to other polymorphic type systems for logic programming, e.g., [Mycroft/O’Keefe 84] and [Smolka 88] (in these type systems the left-hand side of a clause must have a type which is equivalent to the declared type of the predicate). If Σ is the above signature, then

apply2(pred member:pred2(α, list(α)), E:α, L:list(α)) ← member(E:α, L:list(α))

is a Σ-clause that defines the semantics of apply2 with pred member as the first argument. Note that this clause is not well-typed in the sense of [Mycroft/O’Keefe 84] since apply2 has the declared type

pred apply2: pred2(α, β), α, β

but is used in the clause head with the specialized type

pred2(α, list(α)), α, list(α)

This example illustrates the possibility of higher-order programming in our framework. The application of higher-order programming techniques will be further investigated in chapter 10. In the following, if s is a syntactic construction (type, term, atom, …), tvar(s) and var(s) will denote the set of type variables and typed variables occurring in s, respectively. Furthermore, we define

uvar(s) := {x | ∃τ ∈ T_{H}(X): x:τ ∈ var(s)}

as the set of variable names that occur in s. Since [Padawitz 88] has shown that Horn clause logic with equality is a framework for formal specification, we use the term “specification” instead of “program”:

Definition 1.11 A polymorphic specification or polymorphic Horn clause specification S = (Σ, C) consists of a polymorphic signature Σ and a set C of Σ-clauses, where var(c) ⊆_{U} V ar_{Σ,X} for all c ∈ C. □

In the last definition we require var(c) ⊆_{U} V ar_{Σ,X} rather than var(c) ⊆ V ar_{Σ,X}. In practice, the user may omit the type annotations in the clauses of a polymophic specification and the most general type of a term which satisfies the uniqueness requirement can be computed (cf. section 11.1). Therefore we will omit the type annotations in the clauses of subsequent examples. The first example is a specification of an evaluator for Boolean terms. A Boolean term contains the constants true or false, the Boolean functions and and or, and the function equal to compare arbitrary terms of the same type. The evaluator is a predicate isTrue which is satisfied if such a term can be simplified to true by the common interpretation: type bool/0 func true: → bool func false: → bool func and: bool, bool → bool func or: bool, bool → bool func equal: α, α → bool pred isTrue: bool

clauses:

isTrue(true) ←
isTrue(and(B1,B2)) ← isTrue(B1), isTrue(B2)
isTrue(or(B1,B2)) ← isTrue(B1)
isTrue(or(B1,B2)) ← isTrue(B2)
isTrue(equal(T,T)) ←

Note that this specification is well-typed in our sense but not a well-typed program in the sense of [Mycroft/O’Keefe 84] because of the type of the function equal. The second example gives a polymorphic specification of some operations on lists:

type nat/0, list/1, pred2/2 func 0: → nat func s: nat → nat func []: → list(α) func •: α, list(α) → list(α) func append: list(α), list(α) → list(α) func length: list(α) → nat func max: pred2(α, α), list(α) → α pred apply2: pred2(α, β), α, β pred natless: nat, nat func pred natless: → pred2(nat, nat)

clauses:

append([],L) ≡ L ←
append([E|R],L) ≡ [E|append(R,L)] ←
length([]) ≡ 0 ←
length([E|L]) ≡ s(length(L)) ←
max(LessEq,[E]) ≡ E ←
max(LessEq,[E1,E2|L]) ≡ max(LessEq,[E2|L]) ← apply2(LessEq,E1,E2)

     max(LessEq,[E1,E2|L]) ≡ max(LessEq,[E1|L]) ← apply2(LessEq,E2,E1)
     natless(0,N) ←
     natless(s(N1),s(N2)) ← natless(N1,N2)
     apply2(pred natless,N1,N2) ← natless(N1,N2)

The definition of the function max, which computes the maximum element of a given list relative to a given predicate that compares two elements, is another example of higher-order programming techniques in our framework. Later we will see that the equation

     max(pred natless,[s(s(z)),z,s(s(s(z))),s(z)]) = s(s(s(z)))

is true in all models of the above specification. The semantic properties of the equality predicate can be defined by the following clauses:

Definition 1.12 Let Σ = (H, F unc, P red) be a polymorphic signature. The clauses

x:α ≡ x:α ←
x:α ≡ y:α ← y:α ≡ x:α
x:α ≡ z:α ← x:α ≡ y:α, y:α ≡ z:α
f(x_{1}:τ_{1}, …, x_{n}:τ_{n}):τ ≡ f(y_{1}:τ_{1}, …, y_{n}:τ_{n}):τ ← x_{1}:τ_{1} ≡ y_{1}:τ_{1}, …, x_{n}:τ_{n} ≡ y_{n}:τ_{n}
for all f:τ_{1}, …, τ_{n} → τ ∈ F unc
p(x_{1}:τ_{1}, …, x_{n}:τ_{n}) ← p(y_{1}:τ_{1}, …, y_{n}:τ_{n}), x_{1}:τ_{1} ≡ y_{1}:τ_{1}, …, x_{n}:τ_{n} ≡ y_{n}:τ_{n}
for all p:τ_{1}, …, τ_{n} ∈ P red − {`≡':α, α}

(all x, y, z, x_{i}, y_{j} ∈ V ar are pairwise distinct variable names) are called the equality axioms of Σ. The first three clauses are called reflexivity, symmetry and transitivity axiom, respectively. The last two sets of clauses are the congruence axioms for functions and predicates. The set of equality axioms will be denoted by EAX(Σ). □

We remark that the semantic properties of the equality predicate can also be defined by only using the reflexivity axiom and the congruence axioms for functions and predicates including the equality predicate. In this case the symmetry and transitivity axiom can be derived from the congruence axiom for the equality predicate (see [Loveland 78], section 5.1). If we prove a goal relative to a given specification by deduction (cf. chapter 3) or resolution (cf. chapter 5), then the symmetry and transitivity axioms are frequently applied. Therefore we include these axioms in the set of equality axioms. Up to now we have defined the syntax of polymorphic specifications. In order to attach truth values to goals and clauses, we will have to define the semantics of polymorphic specifications.

This will be the subject of the following chapter. For the rest of this thesis we assume that X is an infinite set of type variables, Σ = (H, F unc, P red) is a given polymorphic signature and V ar is an infinite set of variable names.

Semantics of polymorphic specifications

We use algebraic structures for the interpretation of polymorphic specifications [Poigné 86]. Variables in untyped logic vary over the carrier set of the interpretation. Consequently, type variables in polymorphic specifications vary over all types of the interpretation and typed variables vary over appropriate carrier sets. Hence an interpretation of a polymorphic specification consists of an algebra for the signature of types and a structure for the derived polymorphic signature. A structure is an interpretation of types (elements of sort type) as sets, function symbols as operations on these sets and predicate symbols as predicates on these sets. We give an outline of the necessary notions (for details, see [Ehrig/Mahr 85]).

Definition 2.1 Let H = (T y, Ht) be a signature of types. An H-algebra A = (T y_{A}, Ht_{A}) is also called H-type algebra. H-homomorphisms σ: T_{H}(X) → T y_{A} are extended to tuples of type expressions as in definition 1.3. Let A = (T y_{A}, Ht_{A}) be an H-type algebra and Σ = (H, F unc, P red) be a polymorphic signature. The polymorphic signature Σ(A) = (T y_{A}, F unc_{A}, P red_{A}) derived from Σ and A is defined by

F unc_{A} := {f:σ(τ_{f}) | f:τ_{f} ∈ F unc, σ: X → T y_{A} is a type variable assignment}
P red_{A} := {p:σ(τ_{p}) | p:τ_{p} ∈ P red, σ: X → T y_{A} is a type variable assignment}
□

The interpretation of polymorphic signatures is based on a given H-type algebra for the signature of types:

Definition 2.2 An interpretation of a polymorphic signature Σ is an H-type algebra A = (T y_{A}, Ht_{A}) together with a Σ(A)-structure (S, δ), where the following conditions hold:

1. S is a T y_{A}-sorted set, the carrier of the interpretation.

2. If f:τ_{1}, …, τ_{n} → τ ∈ F unc_{A}, then δ_{f:τ_{1},...,τ_{n}→τ}: S_{τ_{1}} × ⋯ × S_{τ_{n}} → S_{τ} is a function.

3. If p:τ_{1}, …, τ_{n} ∈ P red_{A}, then δ_{p:τ_{1},...,τ_{n}} ⊆ S_{τ_{1}} × ⋯ × S_{τ_{n}} is a relation.

4. If ‘≡’:τ, τ ∈ P red_{A}, then δ_{≡:τ,τ} = {(a, a) | a ∈ S_{τ} }

□

Polymorphic functions and predicates are interpreted as families of functions and predicates on the given types. The equality predicate ‘≡’ is always interpreted as the identity on the carrier sets. In general, a polymorphic signature has infinitely many interpretations. In order to compare different interpretations, we define homomorphisms between them. At first, we define Σ(A)- homomorphisms to compare different Σ(A)-structures:

Definition 2.3 Let A = (T y_{A}, Ht_{A}) be an H-type algebra and (S, δ), (S′, δ′) be Σ(A)- structures. A Σ(A)-homomorphism h from (S, δ) into (S′, δ′) is a family of functions (h_{τ} |τ ∈ T y_{A}) with:

1. h_{τ}: S_{τ} → S′_{τ}

2. If f:τ_{f} ∈ F unc_{A} with τ_{f} = τ_{1}, …, τ_{n} → τ (n ≥ 0) and a_{i} ∈ S_{τ_{i}} (i = 1, …, n), then: h_{τ} (δ_{f:τ_{f}} (a_{1}, …, a_{n})) = δ′_{f:τ_{f}} (h_{τ_{1}}(a_{1}), …, h_{τ_{n}}(a_{n}))

3. If p:τ_{p} ∈ P red_{A} with τ_{p} = τ_{1}, …, τ_{n} (n ≥ 0) and (a_{1}, …, a_{n}) ∈ δ_{p:τ_{p}}, then: (h_{τ_{1}}(a_{1}), …, h_{τ_{n}}(a_{n})) ∈ δ′_{p:τ_{p}}

□

If it is clear from the context we omit the indices τ in the functions h_{τ}. Note that the composition of two Σ(A)-homomorphisms is again a Σ(A)-homomorphism. The class of all Σ(A)-structures together with the Σ(A)-homomorphisms is a category [Ehrig/Mahr 85]. We denote this category by Cat_{Σ(A)}.

Definition 2.4 Let A, A′ be H-type algebras. Every H-homomorphism σ: A → A′ induces

1. a signature morphism σ: Σ(A) → Σ(A′) consisting of the H-homomorphism σ: A → A′ and mappings σ_{F unc}: F unc_{A} → F unc_{A′} and σ_{P red}: P red_{A} → P red_{A′} with

σ_{F unc}(f:τ_{1}, …, τ_{n} → τ) = f:σ(τ_{1}), …, σ(τ_{n}) → σ(τ)

for all f:τ_{1}, …, τ_{n} → τ ∈ F unc_{A} and

σ_{P red}(p:τ_{1}, …, τ_{n}) = p:σ(τ_{1}), …, σ(τ_{n})

for all p:τ_{1}, …, τ_{n} ∈ P red_{A}, and

2. a forgetful functor U_{σ}: Cat_{Σ(A′)} → Cat_{Σ(A)} defined by: If (S′, δ′) is a Σ(A′)-structure, then U_{σ}((S′, δ′)) = (S, δ) with S_{τ} = S′_{σ(τ)} for all τ ∈ T y_{A}, δ_{f:τ_{f}} = δ′_{σ_{F unc}(f:τ_{f})} for all f:τ_{f} ∈ F unc_{A} and δ_{p:τ_{p}} = δ′_{σ_{P red}(p:τ_{p})} for all p:τ_{p} ∈ P red_{A}. If h′: S′_{1} → S′_{2} is a Σ(A′)-homomorphism, then U_{σ}(h′) = h: S_{1} → S_{2} is a Σ(A)-homo-morphism with h_{τ} = h′_{σ(τ)} for all τ ∈ T y_{A}.

□

Now we can define Σ-homomorphisms between Σ-interpretations.

Definition 2.5 Let (A, S, δ) and (A′, S′, δ′) be Σ-interpretations, where A and A′ are Htype algebras, and (S, δ) and (S′, δ′) are Σ(A)- and Σ(A′)-structures, respectively. A Σhomomorphism from (A, S, δ) into (A′, S′, δ′) is a pair (σ, h), where σ: A → A′ is an Hhomomorphism and h: (S, δ) → U_{σ}((S′, δ′)) is a Σ(A)-homomorphism. □

The class of all Σ-interpretations with the composition (σ′, h′) ∘ (σ, h) := (σ′ ∘ σ, U_{σ}(h′) ∘ h) of two Σ-homomorphisms is a category. Hence we define:

Definition 2.6 A Σ-interpretation (A, S, δ) is called initial iff for all Σ-interpretations (A′, S′, δ′) there exists a unique Σ-homomorphism from (A, S, δ) into (A′, S′, δ′). □

Later we will see that for any polymorphic specification (Σ, C) an initial Σ-model exists. We need term interpretations for the construction of an initial model (in the following we assume that V ⊆ V ar_{Σ,X} is a set of typed variables):

Definition 2.7 T_{Σ}(X, V) = (T_{H}(X), T erm_{Σ}(X, V), δ) is called the free term interpretation over X and V if the following conditions hold:

1. The carrier of the free term interpretation T erm_{Σ}(X, V) is the set of all well-typed terms with type variables from X and typed variables from V.

2. If f:τ_{f} ∈ F unc_{T_{H}(X)} with τ_{f} = τ_{1}, …, τ_{n} → τ and t_{i} ∈ T erm_{Σ,τ_{i}}(X, V) (i = 1, …, n), then δ_{f:τ_{f}} (t_{1}, …, t_{n}) = f(t_{1}, …, t_{n}):τ

3. If p:τ_{p} ∈ P red_{T_{H}(X)} and p ≠ ‘≡’, then δ_{p:τ_{p}} = ∅ 4. If ‘≡’:τ, τ ∈ P red_{T_{H}(X)}, then δ_{≡:τ,τ} = {(t, t) | t ∈ T erm_{Σ,τ} (X, V)}.

□

It is easy to show that T_{Σ}(X, V) is a Σ-interpretation.

Definition 2.8 Let I = ((T y_{A}, Ht_{A}), S, δ) be a Σ-interpretation. A variable assignment for (X, V) in I is a pair of mappings (μ, val) with μ: X → T y_{A} and val: V → S′, where (S′, δ′) := U_{μ} ((S, δ)) and val(x:τ) ∈ S′_{τ} (= S_{μ(τ)}) for all x:τ ∈ V. □

By lemma 1.1, the mapping μ can be uniquely extended to an H-homomorphism and therefore the forgetful functor U_{μ} exists. The following lemma is the extension of lemma 1.1 to Σinterpretations [Poigné 86].

Lemma 2.9 (Free term structure) Let (A, S, δ) be a Σ-interpretation and (μ, val) be an assignment for (X, V) in (A, S, δ). There exists a unique Σ-homomorphism (σ, h) from T_{Σ}(X, V) into (A, S, δ) with the properties σ(α) = μ(α) for all α ∈ X and h(v) = val(v) for all v ∈ V.

As a special case (X = V = ∅) the lemma shows that every ground term with monomorphic types corresponds to a unique value in a given Σ-interpretation. Generally, any variable assignment (μ, val) can be extended to a Σ-homomorphism in a unique way. In the following we denote that Σ-homomorphism again by (μ, val). We are not interested in all interpretations of a polymorphic signature but only in those interpretations that satisfies the clauses of a given polymorphic specification. To formalize that we define validity of atoms, goals and clauses relative to a given interpretation:

Definition 2.10 (Validity) Let I = (A, S, δ) be a Σ-interpretation. The validity relation ⊧ is defined as follows:

• Let v = (μ, val) be an assignment for (X, V) in I.

I, v ⊧ L if L = p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) is a (Σ, X, V)-atom with

(val_{τ_{1}}(t_{1}:τ_{1}), …, val_{τ_{n}}(t_{n}:τ_{n})) ∈ δ′_{p:τ_{1},...,τ_{n}} where U_{μ}((S, δ)) = (S′, δ′)

I, v ⊧ G if G is a (Σ, X, V)-goal with I, v ⊧ L for all L ∈ G

I, v ⊧ L ← G if L ← G is a (Σ, X, V)-clause where I, v ⊧ G implies I, v ⊧ L

• I, V ⊧ L if L is a (Σ, X, V)-atom with I, v ⊧ L for all variable assignments v for (X, V) in I I, V ⊧ G if G is a (Σ, X, V)-goal with I, v ⊧ G for all variable assignments v for (X, V) in I

I, V ⊧ L ← G if L ← G is a (Σ, X, V)-clause with I, v ⊧ L ← G for all variable assignments v for (X, V) in I

We say “L is valid in I” if I is a Σ-interpretation with I, var(L) ⊧ L (analogously for goals and clauses). □

This notion of validity is the extension of validity in untyped Horn clause logic to the polymorphic case: In untyped Horn clause logic an atom, goal or clause is said to be true iff it is true for all variable assignments. In the polymorphic case an atom, goal or clause is said to be true iff it is true for all assignments for type variables and typed variables.

Definition 2.11 (Model) Let C be a set of Σ-clauses. A Σ-interpretation I is called model for (Σ, C) if I, var(L ← G) ⊧ L ← G is true for all clauses L ← G ∈ C. A (Σ, X, V)-goal G is called valid in (Σ, C) relative to V if I, V ⊧ G for every model I of (Σ, C). We shall write:

(Σ, C, V ) ⊧ G

The validity of atoms and clauses in (Σ, C) is analogously defined. □

The reason for the definition of validity relative to a set of variables is that carrier sets in our interpretations may be empty in contrast to untyped Horn logic. This is also the case in many-sorted logic [Goguen/Meseguer 84]. Validity relative to variables is different from validity in the sense of untyped logic. The following example shows such a difference. Example: Let T_{H} = {void, zero}, F unc = {0: → zero}, P red = {p:void, q:zero} and x ∈ V ar. If C consists of the clauses

     p(x:void) ←
     q(0:zero) ← p(x:void)

then M := (({void, zero}, Ht), S, δ) with Ht_{void} = void, Ht_{zero} = zero, S_{void} = ∅, S_{zero} = {0}, δ_{0:→zero} = 0 and δ_{p} = δ_{q} = ∅ is a model for (Σ, C). It can be shown with the Horn clause calculus (see chapter 3) that

(Σ, C, {x:void}) ⊧ q(0:zero)

Hence q(0:zero) is valid in M relative to {x:void}, but q(0:zero) is not valid in M. Validity in our sense is equivalent to validity in the sense of untyped logic if the types of variables denotes non-empty sets in all interpretations. To be more precise we use the notion of strictness [Huet/Oppen 80]:

Definition 2.12 A type τ ∈ T_{H}(X) is called strict in Σ if T erm_{Σ,τ} (X, ∅) ≠ ∅, i.e., there exists at least one ground term of this type. □

By this definition, the type zero in the last example is strict, whereas void is not strict. Note that every type σ(τ) is strict if τ is strict and σ ∈ T S(H, X) is a type substitution.

Lemma 2.13 If a type τ ∈ T_{H}(X) is strict in Σ, then S_{μ(τ)} ≠ ∅ for all Σ-interpretations (A, S, δ) and all type variable assignments μ: X → T y_{A}.

Proof: If τ ∈ T_{H}(X) is strict in Σ, then a ground term t:τ ∈ T erm_{Σ}(X, ∅) exists. Let μ: X → T y_{A} be a type variable assignment. Lemma 2.9 shows the existence of a unique Σ-homomorphism (μ, h): T_{Σ}(X, ∅) → (A, S, δ). Therefore h(t:τ) ∈ S_{μ(τ)} and S_{μ(τ)} ≠ ∅.

The next theorem shows the relation between validity in our sense and validity in untyped logic:

Theorem 2.14 Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and G be a (Σ, X, V)-goal. If the types of all variables from V − var(G) are strict and (Σ, C, V) ⊧ G, then (Σ, C, var(G)) ⊧ G.

The last example shows that the implication in the theorem does not hold if the types of variables in V − var(G) are not strict. Proof: Let M be a model for (Σ, C) and v be a variable assignment for (X, var(G)) in M. Since all types of variables from V − var(G) are strict, by lemma 2.13 we can extend v to a variable assignment v′ for (X, V) in M. We can infer M, v′ ⊧ G from (Σ, C, V) ⊧ G. Since v and v′ are identical on var(G), we have M, v ⊧ G.

If we want to relate validity in the polymorphic case to validity in the sense of untyped logic, we must know whether a type of a variable not occurring in a goal is strict. The next lemma states a negative result for the decidability of the strictness in polymorphic signatures.

Lemma 2.15 (Undecidability of strictness) It is not recursively decidable whether or not a type is strict in a given polymorphic signature Σ.

Proof: We show that the termination problem of Turing machines can be reduced to the strictness problem of polymorphic signatures. We assume a given Turing machine with states S = {s_{1}, …, s_{k}}, alphabet A = {blank, c_{1}, …, c_{l}} and state transition function

δ: S × A → S × A × {left, right, stop}.

We define a polymorphic signature with the following basic types and type constructors:

1. The states s_{1}, …, s_{k} and the elements of the alphabet blank, c_{1}, …, c_{l} of the Turing machine are basic types.

2. empty is a basic type and represents the empty tape (blank tape).

3. tape is a type constructor of arity 2 and represents a one-sided infinite tape. The first parameter will be the first element of the tape and the second parameter will be the rest of the tape.

4. state is a type constructor of arity 4 and represents the computation state of the Turing machine. The second parameter will be the character on the current position of the tape, the first and third parameter will be the parts of the tape left and right from the current position. The fourth parameter will be the current state of the Turing machine.

We code each pair (s, c) ∈ S × A with state transition δ(s, c) = (s′, c′, p) as a function f. Thus we get k ∗ (l + 1) different functions f (α, β, γ, ϵ are type variables):

func f: state(α, γ, tape(c′, β), s′) → state(tape(γ, α), c, β, s)

is the function declaration corresponding to state transition δ(s, c) = (s′, c′, left).

func f: state(tape(c′, α), γ, β, s′) → state(α, c, tape(γ, β), s)

is the function declaration corresponding to state transition δ(s, c) = (s′, c′, right).

func f: → state(α, c, β, s)

is the function declaration corresponding to state transition δ(s, c) = (s′, c′, stop). We define two additional functions for the extension of the tape:

func extendleft: state(tape(blank, empty), γ, β, ϵ) → state(empty, γ, β, ϵ)
func extendright: state(α, γ, tape(blank, empty), ϵ) → state(α, γ, empty, ϵ)

Now it is straightforward to show that the Turing machine stops with initial configuration

([c_{i_{1}}, …, c_{i_{n−1}}, c_{i_{n}}, c_{i_{n+1}}, …, c_{i_{n+m}}], s_{j})

(s_{j} is the initial state and n is the initial tape position) iff the type

state(tape(c_{i_{n−1}}, tape(…, tape(c_{i_{1}}, empty) …)),
c_{i_{n}},
tape(c_{i_{n+1}}, tape(…, tape(c_{i_{n+m}}, empty) …)),
s_{j})

is strict.

If all carrier sets of an interpretation are non-empty, then validity in our sense is equivalent to validity in untyped Horn logic and we need not take care of the strictness of variable types. But a requirement for the strictness of all types is not reasonable. For a more detailed discussion of this subject compare [Goguen/Meseguer 84]. Later we shall see that the strictness of the variable types is irrelevant for a specific class of specifications (cf. proposition 8.8). In later chapters we will use the equality axioms for proving validity of goals. The next lemma shows that this is semantically correct because the equality axioms are valid in any model:

Proposition 2.16 Let C be a set of Σ-clauses. Every model for (Σ, C) is also a model for (Σ, C ∪ EAX(Σ)).

Proof: Let M = (A, S, δ) be a model for (Σ, C). Therefore δ_{≡:τ,τ} = {(a, a) | a ∈ S_{τ} }. Let (μ, val) be an arbitrary variable assignment for (X, {x:α}) in M. Then

(val_{α}(x:α), val_{α}(x:α)) ∈ δ_{≡:μ(α),μ(α)}.

Hence M, {x:α} ⊧ x:α ≡ x:α. The validity of the symmetry and transitivity clauses can be analogously shown. Let V = {x_{1}:τ_{1}, …, x_{n}:τ_{n}, y_{1}:τ_{1}, …, y_{n}:τ_{n}} and (μ, val) be a variable assignment for (X, V) in M with M, (μ, val) ⊧ x_{1}:τ_{1} ≡ y_{1}:τ_{1} , …, x_{n}:τ_{n} ≡ y_{n}:τ_{n} and f:τ_{1}, …, τ_{n} → τ ∈ F unc. Then we can infer that val_{τ_{i}}(x_{i}:τ_{i}) = val_{τ_{i}}(y_{i}:τ_{i}) for i = 1, …, n and

val_{τ} (f(x_{1}:τ_{1}, …, x_{n}:τ_{n}):τ) = δ_{f:μ(τ_{1},...,τ_{n}→τ)}(val_{τ_{1}}(x_{1}:τ_{1}), …, val_{τ_{n}}(x_{n}:τ_{n}))
= δ_{f:μ(τ_{1},...,τ_{n}→τ)}(val_{τ_{1}}(y_{1}:τ_{1}), …, val_{τ_{n}}(y_{n}:τ_{n}))
= val_{τ} (f(y_{1}:τ_{1}, …, y_{n}:τ_{n}):τ)

Hence we have

M, V ⊧ f(x_{1}:τ_{1}, …, x_{n}:τ_{n}):τ ≡ f(y_{1}:τ_{1}, …, y_{n}:τ_{n}):τ ← x_{1}:τ_{1} ≡ y_{1}:τ_{1} , …, x_{n}:τ_{n} ≡ y_{n}:τ_{n}

The validity of the remaining clauses of the equality axioms can be shown in a similar way.

At the end of this chapter we show a relation between the validity of a clause and the validity of all its instances. At first, we have to define the notions of “typed substitutions” and “instances”. A typed substitution is a combination of a substitution on type expressions and a substitution which replaces typed variables by well-typed terms. Thus a typed substitution replaces a type variable from X by a type expression from T_{H}(X) and a typed variable from a set of typed variables V by a well-typed term from T erm_{Σ}(X, V′). A typed substitution keeps the set of type variables X but may change the set of typed variables because the types of the variables influence validity (cf. Theorem 2.14).

Definition 2.17 Let V, V′ ⊆ V ar_{Σ,X} be sets of typed variables. A typed substitution σ is a Σ-homomorphism σ = (σ_{X}, σ_{V}) from T_{Σ}(X, V) into T_{Σ}(X, V′). Since σ_{X} and σ_{V} are only applied to type expressions and typed terms, respectively, we omit the indices X and V and write σ for both σ_{X} and σ_{V} if there is no confusion about the meaning. We extend typed substitutions on Σ-atoms by:

σ (p(t_{1}, …, t_{n})) = p(σ(t_{1}), …, σ(t_{n}))

Furthermore we define: Sub(Σ, X, V, V′) := {σ | σ is a typed substitution from T_{Σ}(X, V) into T_{Σ}(X, V′)} tdom(σ) := {α ∈ X | σ(α) ≠ α} is the type domain of a typed substitution σ. id_{X,V} ∈ Sub(Σ, X, V, V) is defined as the identity typed substitution from T_{Σ}(X, V) into T_{Σ}(X, V) with id_{X,V} (α) = α for all α ∈ X and id_{X,V} (x:τ) = x:τ for all x:τ ∈ V. □

The next proposition shows that typed substitutions are determined by their behaviour on type variables and typed variables. It is a consequence of lemma 2.9.

Proposition 2.18 Let σ_{X} be a mapping from X into T_{H}(X) and σ_{V} be a mapping from V into T_{Σ}(X, V′) with σ_{V} (x:τ) ∈ T erm_{Σ,σ_{X}(τ)}(X, V′) for all x:τ ∈ V. Under these conditions there exists a unique typed substitution from T_{Σ}(X, V) into T_{Σ}(X, V′) with σ(α) = σ_{X}(α) for all α ∈ X and σ(x:τ) = σ_{V} (x:τ) for all x:τ ∈ V.

If σ is a typed substitution and the sets

{α | σ(α) ≠ α, α ∈ X}  and  {x:τ | σ(x:τ) ≠ x:σ(τ), x:τ ∈ V }

are finite, we represent σ by the following set:

{α/σ(α) | σ(α) ≠ α, α ∈ X} ∪ {x:τ/σ(x:τ) | σ(x:τ) ≠ x:σ(τ), x:τ ∈ V }

A typed substitution replaces type variables by type expressions and typed variables by welltyped terms. The set

σ = {α/nat, x:α/0:nat}

represents a typed substitution that replaces the type variable α by the monomorphic type nat and the typed variable x:α by the ground term 0:nat. Hence the result of applying σ to the atom x:α ≡ y:α is the atom 0:nat ≡ y:nat.

Lemma 2.19 Let M be a Σ-interpretation, G be a (Σ, X, V)-goal, σ ∈ Sub(Σ, X, V, V′) and v be a variable assignment for (X, V′) in M. Then M, v ⊧ σ(G) iff M, v ∘ σ ⊧ G.

Proof: Let G, σ, v = (μ, val) and M = (A, S, δ) be given. The composition v′ := v ∘ σ is defined by v′ = (μ′, val′) with μ′(α) = μ(σ(α)) for all α ∈ X and

val′_{τ} (x:τ) = (U_{σ}(val) ∘ σ)_{τ} (x:τ) = val_{σ(τ)}(σ(x:τ))

for all x:τ ∈ V. Thus v′ is a variable assignment for (X, V) in M. Let p(… t_{i}:τ_{i} …) ∈ G. Then

M, v ⊧ σ (p(… t_{i}:τ_{i} …)) ⟺ M, v ⊧ p(… σ(t_{i}:τ_{i}) …)
⟺ (… val_{σ(τ_{i})}(σ(t_{i}:τ_{i})) …) ∈ δ_{p:...μ(σ(τ_{i}))...}
⟺ (… val′_{τ_{i}}(t_{i}:τ_{i}) …) ∈ δ_{p:...μ′(τ_{i})...}
⟺ M, v′ ⊧ p(… t_{i}:τ_{i} …)

This proves the lemma.

Definition 2.20 A term t′ ∈ T erm_{Σ}(X, V′) is called an instance of a term t ∈ T erm_{Σ}(X, V) if a typed substitution σ ∈ Sub(Σ, X, V, V′) exists with t′ = σ(t). The definition of instances can be extended on atoms, goals and clauses. We omit the simple definitions here. □

The next lemma shows the relationship between the validity of a clause and the validity of all its instances:

Lemma 2.21 Let I = (A, S, δ) be a Σ-interpretation and L ← G be a (Σ, X, V)-clause. Then:

I, V ⊧ L ← G  ⟺  I, V′ ⊧ σ(L) ← σ(G) for all σ ∈ Sub(Σ, X, V, V′)

Proof: The direction “⟸” is trivial if we use id_{X,V} for the typed substitution σ. Let I, V ⊧ L ← G be true and σ ∈ Sub(Σ, X, V, V′) be a typed substitution. We have to show that I, V′ ⊧ σ(L) ← σ(G) is true. Let v be a variable assignment for (X, V′) in I with I, v ⊧ σ(G) (if there exists no such variable assignment, I, V′ ⊧ σ(L) ← σ(G) is trivially true). By lemma 2.19, I, v ∘ σ ⊧ G. This implies I, v ∘ σ ⊧ L since I, V ⊧ L ← G. Again by lemma 2.19, it follows I, v ⊧ σ(L).

In the next chapter we define an inference system for proving validity in the class of all models. Moreover, the construction of an initial model for any polymorphic specification is based on that inference system.

Deduction

3.1 The polymorphic Horn clause calculus

In this chapter, we define an inference system for proving validity in polymorphic specifications and show soundness and completeness of this inference system. In contrast to the untyped Horn clause calculus it is necessary to collect all variables used in a derivation of the inference system since validity depends on the types of variables (cf. theorem 2.14). In the following we assume that EAX(Σ) are the equality axioms of the given polymorphic signature Σ.

Definition 3.1 Let C be a set of Σ-clauses. The polymorphic Horn clause calculus consists of the following inference rules:

1. Axioms: If V ⊆ V ar_{Σ,X} is a set of typed variables and L ← G ∈ C is a (Σ, X, V)-clause, then (Σ, C, V) ⊢ L ← G.

2. Substitution rule: If (Σ, C, V) ⊢ L ← G and σ ∈ Sub(Σ, X, V, V′), then (Σ, C, V′) ⊢ σ(L) ← σ(G).

3. Cut rule: If (Σ, C, V) ⊢ L ← G ∪ {L′} and (Σ, C, V) ⊢ L′ ← G′, then (Σ, C, V) ⊢ L ← G ∪ G′.

A deduction for (Σ, C, V) ⊢ L ← G is a sequence of the form

(Σ, C, V_{1}) ⊢ L_{1} ← G_{1} (Σ, C, V_{2}) ⊢ L_{2} ← G_{2} ⋯ (Σ, C, V_{n}) ⊢ L_{n} ← G_{n}

where V_{n} = V, L_{n} ← G_{n} = L ← G and each element of the sequence follows from previous elements by an application of an inference rule. We write

(Σ, C, V ) ⊢ L

if (Σ, C, V) ⊢ L ← ∅ can be deduced by the polymorphic Horn clause calculus. □

We give an example for a simple deduction in the polymorphic Horn clause calculus: Let T_{H} = {void, zero}, F unc = {0: → zero}, P red = {p:void, q:zero} and x ∈ V ar and C be the set of clauses

     p(x:void) ←
     q(0:zero) ← p(x:void)

Then the following sequence is a deduction for (Σ, C, {x:void}) ⊢ q(0:zero):

(Σ, C, {x:void}) ⊢ p(x:void) ←
(Σ, C, {x:void}) ⊢ q(0:zero) ← p(x:void)
(Σ, C, {x:void}) ⊢ q(0:zero) ←

This example shows the need for the explicit mentioning of the variables in the deduction since (Σ, C, ∅) ⊧ q(0:zero) is not true (cf. example on page 23). The soundness of the polymorphic Horn clause calculus can be shown by proving the soundness of each inference rule:

Theorem 3.2 (Soundness of deduction) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and L be a (Σ, X, V)-atom. If (Σ, C ∪ EAX(Σ), V) ⊢ L, then (Σ, C, V) ⊧ L.

Proof: Let M be a model for (Σ, C) and Ce := C ∪EAX(Σ). By proposition 2.16, M is also a model for (Σ, Ce). By induction on the length of a deduction we show that M, V_{i} ⊧ L_{i} ← G_{i} for each element (Σ, Ce, V_{i}) ⊢ L_{i} ← G_{i} in a deduction for L ← ∅.

1. Axioms: If L_{i} ← G_{i} ∈ Ce, then M, var(L_{i} ← G_{i}) ⊧ L_{i} ← G_{i}. Let v = (μ, val) be a variable assignment for (X, V_{i}) in M (if there exists no such variable assignment, then M, V_{i} ⊧ L_{i} ← G_{i} is trivially true). Let v′ = (μ, val|_{var(L_{i}←G_{i})}) be the restriction of v to (X, var(L_{i} ← G_{i})). Then M, v′ ⊧ L_{i} ← G_{i} is true and therefore M, v ⊧ L_{i} ← G_{i} is also true.

2. Substitution rule: Let σ ∈ Sub(Σ, X, V_{i}, V′_{i}) be a typed substitution and v′ be a variable assignment for (X, V′_{i}) in M (if there exists no such variable assignment, then M, V′_{i} ⊧ σ(L_{i}) ← σ(G_{i}) is trivially true). v := v′ ∘ σ is a variable assignment for (X, V_{i}) in M. By induction hypothesis, M, v ⊧ L_{i} ← G_{i}. Suppose now that M, v′ ⊧ σ(G_{i}). By lemma 2.19, we can infer that M, v ⊧ G_{i}. This implies M, v ⊧ L_{i} and, again by lemma 2.19, M, v′ ⊧ σ(L_{i}). Therefore, M, v′ ⊧ σ(L_{i}) ← σ(G_{i}).

3. Cut rule: Let (Σ, Ce, V_{i}) ⊢ L_{i} ← G_{i} ∪ {L_{j}} and (Σ, Ce, V_{j}) ⊢ L_{j} ← G_{j} be elements of the deduction with V_{i} = V_{j}. Let v be a variable assignment for (X, V_{i}) in M with M, v ⊧ G_{i}∪G_{j} (if there exists no such variable assignment, then M, V_{i} ⊧ L_{i} ← G_{i}∪G_{j} is trivially true). By induction hypothesis, M, v ⊧ L_{i} ← G_{i} ∪ {L_{j}} and M, v ⊧ L_{j} ← G_{j}. Since M, v ⊧ G_{j}, we obtain M, v ⊧ L_{j}. On the other hand, M, v ⊧ G_{i}. Hence M, v ⊧ G_{i} ∪ {L_{j}} and M, v ⊧ L_{i}. Therefore, M, v ⊧ L_{i} ← G_{i} ∪ G_{j}, as required.

The completeness of deduction is proved by the construction of a particular model that is the quotient of a free term interpretation and a congruence relation.

Definition 3.3 Let V ⊆ V ar_{Σ,X} be a set of typed variables. A congruence ∼ on T erm_{Σ}(X, V) is a T_{H}(X)-sorted family of relations (∼_{τ} |τ ∈ T_{H}(X)) with:

1. ∼_{τ} is an equivalence relation on T erm_{Σ,τ} (X, V) for all τ ∈ T_{H}(X).

2. If t_{i}:τ_{i} ∼_{τ_{i}} t′_{i}:τ_{i} for i = 1, …, n and f:τ_{1}, …, τ_{n} → τ ∈ F unc_{T_{H}(X)}, then:

f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ ∼_{τ} f(t′_{1}:τ_{1}, …, t′_{n}:τ_{n}):τ
□

The equality axioms EAX(Σ) generate a congruence on T erm_{Σ}(X, V):

Lemma 3.4 Let V ⊆ V ar_{Σ,X} be a set of typed variables and the T_{H}(X)-sorted relation ∼_{Σ,C,V} be defined by

t_{1}:τ ∼_{Σ,C,V,τ} t_{2}:τ :⟺ (Σ, C ∪ EAX(Σ), V) ⊢ t_{1}:τ ≡ t_{2}:τ

for all t_{1}:τ, t_{2}:τ ∈ T erm_{Σ}(X, V). Then ∼_{Σ,C,V} is a congruence on T erm_{Σ}(X, V).

Proof: First we show that ∼_{Σ,C,V} is a T_{H}(X)-sorted equivalence relation on T erm_{Σ}(X, V). Let t:τ ∈ T erm_{Σ}(X, V). Since x:α ≡ x:α ← is an equality axiom,

(Σ, C ∪ EAX(Σ), V ∪ {x:α}) ⊢ x:α ≡ x:α ←

An application of the substitution rule with typed substitution σ ∈ Sub(Σ, X, V ∪ {x:α}, V), where σ(α) = τ and σ(x:α) = t:τ, yields

(Σ, C ∪ EAX(Σ), V) ⊢ t:τ ≡ t:τ ←

This implies t:τ ∼_{Σ,C,V,τ} t:τ. For the symmetry of ∼_{Σ,C,V} we assume t_{1}:τ ∼_{Σ,C,V,τ} t_{2}:τ for t_{1}:τ, t_{2}:τ ∈ T erm_{Σ}(X, V). This implies

(Σ, C ∪ EAX(Σ), V) ⊢ t_{1}:τ ≡ t_{2}:τ

An application of the symmetry clause in EAX(Σ) with an appropriate application of the substitution rule yields

(Σ, C ∪ EAX(Σ), V) ⊢ t_{2}:τ ≡ t_{1}:τ ← t_{1}:τ ≡ t_{2}:τ

Thus we obtain

(Σ, C ∪ EAX(Σ), V) ⊢ t_{2}:τ ≡ t_{1}:τ ←

by the cut rule. Therefore t_{2}:τ ∼_{Σ,C,V,τ} t_{1}:τ is true. The transitivity and congruence property of ∼_{Σ,C,V} can be similarly derived from the transitivity and congruence clauses in EAX(Σ).

Definition 3.5 Let V ⊆ V ar_{Σ,X} and ∼_{Σ,C,V} be the congruence defined in the last lemma. The quotient of the term interpretation T_{Σ}(X, V) by ∼_{Σ,C,V}, denoted T_{Σ,C}(X, V), is the triple (T_{H}(X), S, δ) with:

1. For all τ ∈ T_{H}(X),

S_{τ} = T erm_{Σ,τ} (X, V)/ ∼_{Σ,C,V,τ} := {[t:τ] | t:τ ∈ T erm_{Σ,τ} (X, V)},

where [t:τ] denotes the equivalence class {t′:τ ∈ S_{τ} | t:τ ∼_{Σ,C,V,τ} t′:τ}.

2. If f:τ_{1}, …, τ_{n} → τ ∈ F unc_{T_{H}(X)} and [t_{i}:τ_{i}] ∈ S_{τ_{i}} for i = 1, …, n, then

δ_{f:τ_{1},...,τ_{n}→τ} ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}]) := [f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ]

3. If p:τ_{1}, …, τ_{n} ∈ P red_{T_{H}(X)}, then

δ_{p:τ_{1},...,τ_{n}} := {([t_{1}:τ_{1}], …, [t_{n}:τ_{n}]) | (Σ, C ∪ EAX(Σ), V) ⊢ p(t_{1}:τ_{1}, …, t_{n}:τ_{n})}

nat_{Σ,C,V} is the family of canonical mappings (nat_{Σ,C,V,τ} |τ ∈ T_{H}(X)) with

nat_{Σ,C,V,τ}: T erm_{Σ,τ} (X, V) → S_{τ}

defined by nat_{τ} (t:τ) := [t:τ]. □

The mappings δ_{f:τ_{1},...,τ_{n}→τ} in the definition are well-defined because ∼_{Σ,C,V} is a congruence relation. The next corollary shows that T_{Σ,C}(X, V) is also well-defined for the relations:

Corollary 3.6 Let T_{Σ,C}(X, V) = (T_{H}(X), S, δ) be the triple defined in the last definition. If ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}]) ∈ δ_{p:τ_{1},...,τ_{n}}, then (Σ, C∪EAX(Σ), V) ⊢ p(t_{1}:τ_{1}, …, t_{n}:τ_{n}), for any selection of the representatives t_{i}:τ_{i} of [t_{i}:τ_{i}].

Proof: Let Ce := C ∪ EAX(Σ) and ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}]) ∈ δ_{p:τ_{1},...,τ_{n}}. Then there exist t′_{i}:τ_{i} (i = 1, …, n) with (Σ, C ∪ EAX(Σ), V) ⊢ p(t′_{1}:τ_{1}, …, t′_{n}:τ_{n}) and t_{i}:τ_{i} ∼_{Σ,C,V,τ_{i}} t′_{i}:τ_{i}, for i = 1, …, n. By definition of ∼_{Σ,C,V}, (Σ, C ∪ EAX(Σ), V) ⊢ t_{i}:τ_{i} ≡ t′_{i}:τ_{i} ←, for i = 1, …, n. With the EAX(Σ)-clause

p(x_{1}:τ_{1}, …, x_{n}:τ_{n}) ← p(y_{1}:τ_{1}, …, y_{n}:τ_{n}), x_{1}:τ_{1} ≡ y_{1}:τ_{1} , …, x_{n}:τ_{n} ≡ y_{n}:τ_{n}

and the substitution and cut rule we obtain (Σ, C ∪ EAX(Σ), V) ⊢ p(t_{1}:τ_{1}, …, t_{n}:τ_{n}).

The completeness proof of the polymorphic Horn clause calculus is based on the fact that T_{Σ,C}(X, V) is a model for (Σ, C). Therefore we need the following lemma:

Lemma 3.7 Let C be a set of Σ-clauses and V ⊆ V ar_{Σ,X} be a set of typed variables. T_{Σ,C}(X, V) is a model for (Σ, C) and nat_{Σ,C,V} is a Σ(T_{H}(X))-homomorphism.

Proof: It is clear that conditions 1–3 of definition 2.2 are satisfied by T_{Σ,C}(X, V) = (T_{H}(X), S, δ). Condition 4 follows from

δ_{≡:τ,τ} = {([t:τ], [t′:τ]) | (Σ, C ∪ EAX(Σ), V) ⊢ t:τ ≡ t′:τ}
= {([t:τ], [t′:τ]) | t:τ ∼_{Σ,C,V,τ} t′:τ}
= {([t:τ], [t:τ]) | t:τ ∈ T erm_{Σ}(X, V)}
= {(a, a) | a ∈ S_{τ} }

Therefore T_{Σ,C}(X, V) is a Σ-interpretation. Next we show that q := nat_{Σ,C,V} is a Σ(T_{H}(X))-homomorphism.

1. By definition, q_{τ}: T erm_{Σ,τ} (X, V) → S_{τ}.

2. Let f:τ_{1}, …, τ_{n} → τ ∈ F unc_{T_{H}(X)} and t_{i}:τ_{i} ∈ T erm_{Σ}(X, V) for i = 1, …, n. Then

q_{τ} (f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ) = [f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ]
= δ_{f:τ_{1},...,τ_{n}→τ} ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}])
= δ_{f:τ_{1},...,τ_{n}→τ} (q_{τ_{1}}(t_{1}:τ_{1}), …, q_{τ_{n}}(t_{n}:τ_{n}))

3. Let p:τ_{1}, …, τ_{n} ∈ P red_{T_{H}(X)} and (t_{1}:τ_{1}, …, t_{n}:τ_{n}) ∈ δ′_{p:τ_{1},...,τ_{n}} with T_{Σ}(X, V) = (T_{H}(X), T erm_{Σ}(X, V), δ′). By definition of T erm_{Σ}(X, V), only the equality relation is non-empty. Hence n = 2 and p = ‘≡’. Thus τ_{1} = τ_{2} and t_{1}:τ_{1} = t_{2}:τ_{2}. This implies [t_{1}:τ_{1}] = [t_{2}:τ_{2}] and (q_{τ_{1}}(t_{1}:τ_{1}), q_{τ_{2}}(t_{2}:τ_{2})) ∈ δ_{≡:τ_{1},τ_{2}}.

Now we have to prove that all clauses from C are valid in T_{Σ,C}(X, V). Let L ← G be a clause from C and v = (μ, val) be a variable assignment for (X, V_{c}) in T_{Σ,C}(X, V) with T_{Σ,C}(X, V), v ⊧ G, where V_{c} := var(L ← G). For all x:τ ∈ V_{c}, val_{τ} (x:τ) ∈ S_{μ(τ)}, i.e., each variable from V_{c} is mapped into an equivalence class. We choose from each equivalence class val_{τ} (x:τ) a representative t_{x:τ} with val_{τ} (x:τ) = q_{μ(τ)}(t_{x:τ}). Hence there exists an assignment val′ for the variables from V_{c} into T_{Σ}(X, V) with val = U_{μ}(q) ∘ val′. If G = L_{1}, …, L_{k}, then T_{Σ,C}(X, V), v ⊧ L_{i}, for i = 1, …, k. If L_{i} = p_{i}(t_{i1}:τ_{i1}, …, t_{in_{i}}:τ_{in_{i}}), we obtain

(val_{τ_{i1}}(t_{i1}:τ_{i1}), …, val_{τ_{in_{i}}} (t_{in_{i}}:τ_{in_{i}})) ∈ δ_{p_{i}:μ(τ_{i1}),...,μ(τ_{in_{i}})}

and, by definition of val′,

(q_{μ(τ_{i1})}(val′_{τ_{i1}}(t_{i1}:τ_{i1})), …, q_{μ(τ_{in_{i}})}(val′_{τ_{in_{i}}} (t_{in_{i}}:τ_{in_{i}}))) ∈ δ_{p_{i}:μ(τ_{i1}),...,μ(τ_{in_{i}})}

By corollary 3.6,

(Σ, Ce, V) ⊢ p_{i}(val′_{τ_{i1}}(t_{i1}:τ_{i1}), …, val′_{τ_{in_{i}}} (t_{in_{i}}:τ_{in_{i}}))

where Ce := C ∪ EAX(Σ). On the other hand, (Σ, Ce, V_{c}) ⊢ L ← G is true, and therefore (Σ, Ce, V) ⊢ v′(L) ← v′(G) since v′ := (μ, val′) is a typed substitution. By the cut rule, we can infer (Σ, Ce, V) ⊢ v′(L) ←. If L = p(t_{1}:τ_{1}, …, t_{n}:τ_{n}), then

(Σ, Ce, V) ⊢ p(val′_{τ_{1}}(t_{1}:τ_{1}), …, val′_{τ_{n}}(t_{n}:τ_{n}))

By definition of T_{Σ,C}(X, V),

(q_{μ(τ_{1})}(val′_{τ_{1}}(t_{1}:τ_{1})), …, q_{μ(τ_{n})}(val′_{τ_{n}}(t_{n}:τ_{n}))) ∈ δ_{p:μ(τ_{1}),...,μ(τ_{n})}

This implies

(val_{τ_{1}}(t_{1}:τ_{1}), …, val_{τ_{n}}(t_{n}:τ_{n})) ∈ δ_{p:μ(τ_{1}),...,μ(τ_{n})}

and T_{Σ,C}(X, V), v ⊧ L.

Now we are prepared to state the completeness of the polymorphic Horn clause calculus:

Theorem 3.8 (Completeness of deduction) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and L be a (Σ, X, V)-atom with (Σ, C, V) ⊧ L. Then (Σ, C ∪ EAX(Σ), V) ⊢ L.

Proof: Let (Σ, C, V) ⊧ L and L = p(t_{1}:τ_{1}, …, t_{n}:τ_{n}). By the last lemma, T_{Σ,C}(X, V) = (T_{H}(X), S, δ) is a model for (Σ, C). This implies T_{Σ,C}(X, V), V ⊧ L. Also by the last lemma, q := nat_{Σ,C,V} is a Σ(T_{H}(X))-homomorphism. id ∈ T S(H, X) with id(α) = α for all α ∈ X is a type substitution. Hence (id, q) is a variable assignment for (X, V) in T_{Σ,C}(X, V). Therefore T_{Σ,C}(X, V), (id, q) ⊧ L. This implies

(q_{τ_{1}}(t_{1}:τ_{1}), …, q_{τ_{n}}(t_{n}:τ_{n})) ∈ δ_{p:τ_{1},...,τ_{n}}

By corollary 3.6, (Σ, C ∪ EAX(Σ), V) ⊢ L is true.

In the rest of this section we want to show a method for proving the validity of clauses by deduction. We need two lemmas to prove soundness and completeness of the method. The first lemma states that validity is invariant under the extension of signatures:

Lemma 3.9 (Extended signatures) Let C be a set of Σ-clauses, τ_{1}, …, τ_{k} be new basic types or type constructors and Σ′ = (H′, F unc′, P red) be an extended polymorphic signature with H′ = H ∪{τ_{1}, …, τ_{k}} and F unc ⊆ F unc′. If V ⊆ V ar_{Σ,X}, then the following implication is true for any (Σ, X, V)-clause L ← G:

(Σ, C, V) ⊧ L ← G  ⟹  (Σ′, C, V) ⊧ L ← G

Proof: We assume (Σ, C, V) ⊧ L ← G. Let M′ = (A′, S′, δ′) be a model for (Σ′, C) with A′ = (T y_{A′}, Ht_{A′}). Let A := (T y_{A}, Ht_{A}) with T y_{A} := T y_{A′} and Ht_{A} := {h_{A′}|h ∈ Ht}. A is an H-type algebra. Let S := S′, δ_{f:τ_{f}} := δ′_{f:τ_{f}} for all f:τ_{f} ∈ F unc_{A} and δ_{p:τ_{p}} := δ′_{p:τ_{p}} for all p:τ_{p} ∈ P red_{A}. (S, δ) is a Σ(A)-structure. M = (A, S, δ) is a Σ-interpretation and all clauses from C are valid in M. Therefore M is a model for (Σ, C) and M, V ⊧ L ← G is true. Let v be a variable assignment for (X, V) in M′. Since V ⊆ V ar_{Σ,X}, T y_{A} = T y_{A′} and S = S′, v is also a variable assignment for (X, V) in M. Therefore M, v ⊧ L ← G. Since δ_{p:τ_{p}} = δ′_{p:τ_{p}} for all p:τ_{p} ∈ P red_{A}, it follows M′, v ⊧ L ← G. Hence M′, V ⊧ L ← G is true.

The next lemma is the basis for proving the validity of clauses by deduction:

Lemma 3.10 (Constants) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} be a finite set of typed variables and L ← G be a (Σ, X, V)-clause with tvar(L ← G) ∪ tvar(V) = {α_{1}, …, α_{m}} and V = {x_{1}:τ_{1}, …, x_{n}:τ_{n}}. Let γ_{1}, …, γ_{m} be new basic types (with ar(γ_{i}) = 0) and c_{1}, …, c_{n} be new constant symbols. Let Σ′ = (H ∪ {γ_{1}, …, γ_{m}}, F unc ∪ {c_{i}: → σ(τ_{i}) | i = 1, …, n}, P red) be an extended polymorphic signature, where σ ∈ Sub(Σ′, X, V, ∅) is a typed substitution with σ(α_{i}) = γ_{i} (i = 1, …, m), σ(α) = α for all other type variables α, and σ(x_{j}:τ_{j}) = c_{j}:σ(τ_{j}) (j = 1, …, n). Then:

(Σ, C, V) ⊧ L ← G ⟺ (Σ′, C, ∅) ⊧ σ(L) ← σ(G)

Proof: “⟹”: Let (Σ, C, V) ⊧ L ← G. By lemma 3.9, (Σ′, C, V) ⊧ L ← G. This implies (Σ′, C, ∅) ⊧ σ(L) ← σ(G) by lemma 2.21. “⟸”: Let (Σ′, C, ∅) ⊧ σ(L) ← σ(G), M = (A, S, δ) be a model for (Σ, C) and v = (μ, val) be a variable assignment for (X, V) in M. We have to show: M, v ⊧ L ← G. If A = (T y_{A}, Ht_{A}), then we define A′ = (T y_{A′}, Ht_{A′}) with T y_{A′} := T y_{A} and Ht_{A′} := Ht_{A} ∪ {γ_{i,A′} | i = 1, …, m} where γ_{i,A′} = μ(α_{i}). A′ is a H ∪ {γ_{1}, …, γ_{m}}-algebra. Furthermore, we define S′ := S, δ′_{f:τ_{f}} := δ_{f:τ_{f}} for all f:τ_{f} ∈ F unc_{A′} with f ≠ c_{i} for all i, and δ′_{c_{i}:μ(σ(τ_{i}))} := val(x_{i}:τ_{i}) (i = 1, …, n) (μ is the only assignment for tvar(σ(τ_{i})) in T y_{A′} because of tvar(σ(τ_{i})) = ∅). This is well-defined since μ(σ(τ_{i})) = μ(τ_{i}) by definition of A′. The denotation of predicates is defined as δ′_{p:τ_{p}} := δ_{p:τ_{p}} for all p:τ_{p} ∈ P red_{A′}. Hence (S′, δ′) is a Σ(A′)-structure and M′ := (A′, S′, δ′) is a Σ′-interpretation. Since each clause is valid in M and there is no difference in the denotation of predicates between M′ and M, each clause from C is valid in M′. Thus M′ is a model for (Σ′, C). This implies M′, ∅ ⊧ σ(L) ← σ(G). v is an assignment for (X, V) in M. Since T y_{A′} = T y_{A} and S′ = S, v is also an assignment for (X, V) in M′. Therefore M′, v ⊧ σ(L) ← σ(G) is true because σ(L) ← σ(G) contains no type variables or typed variables. By construction of M′, μ(α_{i}) = μ(σ(α_{i})) and val(x_{i}:τ_{i}) = val(σ(x_{i}:τ_{i})). Hence M, v ⊧ L ← G since δ′_{p:τ_{p}} = δ_{p:τ_{p}} for all p:τ_{p} ∈ P red_{A′}.

The next theorem supplies a proof method for the validity of clauses:

Theorem 3.11 (Deduction of clauses) Let (Σ, C) be a polymorphic specification, V ⊆ V ar_{Σ,X} be a finite set of typed variables, L ← G be a (Σ, X, V)-clause and γ_{i}, c_{j}, σ and Σ′ be as in the last lemma. Let C′ := C ∪ {σ(P) ← | P ∈ G}. Then:

(Σ, C, V) ⊧ L ← G ⟺ (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢ σ(L)

Proof: “⟹”: Let (Σ, C, V) ⊧ L ← G be true. By lemma 3.10, (Σ′, C, ∅) ⊧ σ(L) ← σ(G). If M′ is a model for (Σ′, C′), then M′, ∅ ⊧ σ(P) ← for all P ∈ G, which implies M′, ∅ ⊧ σ(G). Hence M′, ∅ ⊧ σ(L) because M′ is also a model for (Σ′, C). Thus we have (Σ′, C′, ∅) ⊧ σ(L). By theorem 3.8, (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢ σ(L). “⟸”: Let (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢ σ(L) be true. Theorem 3.2 implies (Σ′, C′, ∅) ⊧ σ(L). Let M be a model for (Σ′, C) and v be a variable assignment for (X, ∅) in M with M, v ⊧ σ(G). Therefore M, v ⊧ σ(P) for all P ∈ G. Since tvar(σ(P)) = ∅ and var(σ(P)) = ∅, M is also a model for (Σ′, C′). This implies M, ∅ ⊧ σ(L) and M, v ⊧ σ(L). Hence (Σ′, C, ∅) ⊧ σ(L) ← σ(G). By lemma 3.10, (Σ, C, V) ⊧ L ← G.

We give an example for proving validity of clauses by deduction. Let (Σ, C) be the polymorphic specification for list operations on page 16. We want to prove that the clause

max(L:pred2(α, α),[A1:α,A2:α,A3:α]:list(α)) ≡ A2:α ←

          apply2(L:pred2(α, α),A1:α,A2:α), apply2(L:pred2(α, α),A3:α,A2:α)

is valid in all models for (Σ, C). We extend the polymorphic signature Σ to a signature Σ′ by adding a new basic type τ and the following new constant symbols:

func l: → pred2(τ, τ)

func a1: → τ func a2: → τ func a3: → τ

Furthermore, we add the following clauses to C:

apply2(l:pred2(τ, τ),a1:τ,a2:τ) ← apply2(l:pred2(τ, τ),a3:τ,a2:τ) ←

The extended clause set is denoted by C′. The validity of the clause

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]:list(τ)) ≡ a2:τ ←

can be proved by the following deduction in the polymorphic Horn clause calculus (in terms of type list(⋯) we omit some type annotations and write only the types of the elements of the list terms):

Axiom: (Σ′, C′ ∪ EAX(Σ′), {LessEq:pred2(α, α),E1:α,E2:α,L:list(α)}) ⊢

max(LessEq:pred2(α, α),[E1:α,E2:α|L:list(α)])

≡ max(LessEq:pred2(α, α),[E2:α|L:list(α)]) ←

     apply2(LessEq:pred2(α, α),E1:α,E2:α)

Substitution rule: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ,a3:τ]) ←

     apply2(l:pred2(τ, τ),a1:τ,a2:τ)

Axiom: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

apply2(l:pred2(τ, τ),a1:τ,a2:τ) ←

Cut rule: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ,a3:τ]) ←

Axiom: (Σ′, C′ ∪ EAX(Σ′), {LessEq:pred2(α, α),E1:α,E2:α,L:list(α)}) ⊢

max(LessEq:pred2(α, α),[E1:α,E2:α|L:list(α)])

≡ max(LessEq:pred2(α, α),[E1:α|L:list(α)]) ←

     apply2(LessEq:pred2(α, α),E2:α,E1:α)

Substitution rule: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ]) ←

     apply2(l:pred2(τ, τ),a3:τ,a2:τ)

Axiom: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

apply2(l:pred2(τ, τ),a3:τ,a2:τ) ←

Cut rule: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ]) ←

Axiom: (Σ′, C′ ∪ EAX(Σ′), {x:α,y:α,z:α}) ⊢

x:α ≡ z:α ← x:α ≡ y:α, y:α ≡ z:α

Substitution rule: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ]) ← max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ,a3:τ]), max(l:pred2(τ, τ),[a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ])

Cut rule: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ]) ← max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ,a3:τ])

Cut rule: (Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ]) ←

Axiom: (Σ′, C′ ∪ EAX(Σ′), {LessEq:pred2(α, α),E:α}) ⊢

max(LessEq:pred2(α, α),[E:α]) ≡ E:α ←

Substitution rule:

(Σ′, C′ ∪ EAX(Σ′), ∅) ⊢ max(l:pred2(τ, τ),[a2:τ]) ≡ a2:τ ←

Substitution rule:

(Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ a2:τ ← max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ]),

max(l:pred2(τ, τ),[a2:τ]) ≡ a2:τ

Cut rule:

(Σ′, C′ ∪ EAX(Σ′), ∅) ⊢

max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ a2:τ ← max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ max(l:pred2(τ, τ),[a2:τ])

Cut rule:

(Σ′, C′ ∪ EAX(Σ′), ∅) ⊢ max(l:pred2(τ, τ),[a1:τ,a2:τ,a3:τ]) ≡ a2:τ ←

Hence the validity of our first clause follows from theorem 3.11.

3.2 Initial model

This section shows the existence of an initial model for any polymorphic specification. This is a consequence of the results of the previous section on the polymorphic Horn clause calculus. We remark that it is also possible to construct the initial model as the quotient of the intersection of all Herbrand interpretations (cf. [Lloyd 87]) and a congruence generated by the equality axioms. In [Hanus 88b] this is done for Horn clause programs without equality.

Theorem 3.12 (Initial model) Let Σ be a polymorphic signature and C be a set of Σclauses. Then T_{Σ,C} := T_{Σ,C}(∅, ∅) is an initial model for (Σ, C).

Proof: Let T_{Σ,C} = (T_{H}, S_{I}, δ_{I}). By lemma 3.7, this is a model for (Σ, C). Let I = (A, S, δ) be another model for (Σ, C) and T_{Σ}(∅, ∅) = (T_{H}, S′, δ′) be the term interpretation with ground terms. By lemma 2.9 (free term structure), there exists a unique Σ-homomorphism (σ, h) from T_{Σ}(∅, ∅) into I. Let (k_{τ} | τ ∈ T_{H}) be the family of mappings defined by k_{τ} ([t:τ]) := h_{τ} (t:τ) for all t:τ ∈ T erm_{Σ}(∅, ∅), where [t:τ] denotes the equivalence class of t:τ with respect to ∼_{Σ,C,∅}. The mappings are well-defined: If [t_{1}:τ] = [t_{2}:τ], then t_{1}:τ ∼_{Σ,C,∅,τ} t_{2}:τ. By definition of ∼_{Σ,C,∅}, (Σ, C ∪ EAX(Σ), ∅) ⊢ t_{1}:τ ≡ t_{2}:τ. By theorem 3.2, (Σ, C, ∅) ⊧ t_{1}:τ ≡ t_{2}:τ. This implies I, ∅ ⊧ t_{1}:τ ≡ t_{2}:τ and I, (σ, h) ⊧ t_{1}:τ ≡ t_{2}:τ since (σ, h) is a variable assignment.

Therefore (h_{τ} (t_{1}:τ), h_{τ} (t_{2}:τ)) ∈ δ_{≡:τ,τ} and h_{τ} (t_{1}:τ) = h_{τ} (t_{2}:τ) since I is a Σ-interpretation. Thus the mappings k_{τ} are well-defined. We show that k is a Σ(T_{H})-homomorphism from (S_{I}, δ_{I}) into U_{σ}((S, δ)):

1. k_{τ}: S_{I,τ} → S_{σ(τ)} since (σ, h) is a Σ-homomorphism.

2. Let f:τ_{f} ∈ F unc_{T_{H}} with τ_{f} = τ_{1}, …, τ_{n} → τ and t_{i}:τ_{i} ∈ T erm_{Σ}(∅, ∅) for i = 1, …, n. Then

k_{τ} (δ_{I,f:τ_{f}} ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}])) = k_{τ} ([f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ])
= h_{τ} (f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ)
= h_{τ} (δ′_{f:τ_{f}} (t_{1}:τ_{1}, …, t_{n}:τ_{n}))
= δ_{f:σ(τ_{f})}(h_{τ_{1}}(t_{1}:τ_{1}), …, h_{τ_{n}}(t_{n}:τ_{n}))
= δ_{f:σ(τ_{f})}(k_{τ_{1}}([t_{1}:τ_{1}]), …, k_{τ_{n}}([t_{n}:τ_{n}]))

3. Let p:τ_{1}, …, τ_{n} ∈ P red_{T_{H}} and ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}]) ∈ δ_{I,p:τ_{1},...,τ_{n}}. Corollary 3.6 implies

(Σ, C ∪ EAX(Σ), ∅) ⊢ p(t_{1}:τ_{1}, …, t_{n}:τ_{n})

Theorem 3.2 implies (Σ, C, ∅) ⊧ p(t_{1}:τ_{1}, …, t_{n}:τ_{n}).

⟹ I, ∅ ⊧ p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) ⟹ I, (σ, h) ⊧ p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) ⟹ (h_{τ_{1}}(t_{1}:τ_{1}), …, h_{τ_{n}}(t_{n}:τ_{n})) ∈ δ_{p:σ(τ_{1}),...,σ(τ_{n})} ⟹ (k_{τ_{1}}([t_{1}:τ_{1}]), …, k_{τ_{n}}([t_{n}:τ_{n}])) ∈ δ_{p:σ(τ_{1}),...,σ(τ_{n})}

Therefore (σ, k) is a Σ-homomorphism from T_{Σ,C} into I. Let (σ′, k′) be another Σ-homomorphism from T_{Σ,C} into I. Since σ and σ′ are H-homo-morphisms from T_{H} into A, it follows σ = σ′ by lemma 1.1. We show by induction on the size of terms that k_{τ} ([t:τ]) = k′_{τ} ([t:τ]) for all t:τ ∈ T erm_{Σ}(∅, ∅). If c:τ ∈ T erm_{Σ}(∅, ∅), then k_{τ} ([c:τ]) = h_{τ} (c:τ) = δ_{c:→σ(τ)} = k′_{τ} (δ_{I,c:→τ}) = k′_{τ} ([c:τ]) since h and k are Σ(T_{H})-homomorphisms. For the induction step let f:τ_{1}, …, τ_{n} → τ ∈ F unc_{T_{H}} and t_{i}:τ_{i} ∈ T erm_{Σ}(∅, ∅) with k_{τ_{i}}([t_{i}:τ_{i}]) = k′_{τ_{i}}([t_{i}:τ_{i}]) for i = 1, …, n. Then:

k_{τ} ([f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ]) = k_{τ} (δ_{I,f:τ_{1},...,τ_{n}→τ} ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}]))
= δ_{f:σ(τ_{1}),...,σ(τ_{n})→σ(τ)}(k_{τ_{1}}([t_{1}:τ_{1}]), …, k_{τ_{n}}([t_{n}:τ_{n}]))
= δ_{f:σ(τ_{1}),...,σ(τ_{n})→σ(τ)}(k′_{τ_{1}}([t_{1}:τ_{1}]), …, k′_{τ_{n}}([t_{n}:τ_{n}]))
= k′_{τ} (δ_{I,f:τ_{1},...,τ_{n}→τ} ([t_{1}:τ_{1}], …, [t_{n}:τ_{n}]))
= k′_{τ} ([f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ])

Therefore (σ, k) = (σ, k′). This implies the initiality of T_{Σ,C}.

Note that we have constructed a set-theoretic model for any given polymorphic specification. This is not a contradiction to the result of Reynolds [Reynolds 84], because Reynolds has a different semantic basis. Reynolds foundation is the polymorphic typed lambda calculus [Reynolds 74] which allows computations with higher-order functions. Our basis is not the lambda calculus but we use algebraic interpretations. All functions in our specifications are first-order and therefore we can construct a set-theoretic model in contrast to Reynolds. But Reynolds’ result shows that the extension of polymorphic specifications to higher-order functions is a difficult task. Nevertheless we will see that it is possible to simulate some features of higher-order programming in our framework (cf. chapter 10).

Unification

We are interested in a systematic method for proving validity of goals. The Horn clause calculus is one possibility, but in general it is far from being efficient. In untyped Horn clause logic (without equality) the resolution principle [Robinson 65] with SLD-refutation [Apt/van Emden 82] is the basic proof method. The basic operation in a resolution step is the computation of a most general unifier of two terms. We need a similar operation for the resolution method in the polymorphic case. This chapter defines the unification in the polymorphic case and presents an algorithm for computing the most general unifier that is based on the method in [Launay 86]. Example: Let a polymorphic signature contain the declarations p:α ∈ P red, q:int ∈ P red and r:α ∈ P red (α is a type variable). X,Y,Z ∈ V ar are variable names and assume the following two clauses to be given:

     p(X:int) ← q(X:int)
     p(Y:α) ← r(Y:α)

The first clause is not allowed for proving the goal p(Z:bool). We can use the second clause and have to prove in the next step the goal r(Z:bool). For proving the goal p(Z:int) the first clause can be used. In this case we are left with the goal q(Z:int) for the next resolution step. As we see, unification of two atoms has to take into account the types of the terms. Untyped unification cannot be applied in our case. In chapter 2 typed substitutions were defined. The composition of two typed substitutions is again a typed substitution. Therefore we define the usual relations on typed substitutions:

Definition 4.1 Let V ⊆ V ar_{Σ,X}.

• Let V_{1}, V_{2} ⊆ V ar_{Σ,X} and σ ∈ Sub(Σ, X, V, V_{1}) and σ′ ∈ Sub(Σ, X, V, V_{2}) be typed substitutions. σ is more general than σ′, denoted σ ≤ σ′, iff there exists ϕ ∈ Sub(Σ, X, V_{1}, V_{2})

with ϕ ∘ σ = σ′. σ and σ′ are equivalent, denoted σ ≡ σ′, iff σ ≤ σ′ and σ′ ≤ σ.

• Let t and t′ be (Σ, X, V)-terms. t and t′ are unifiable if there exists a typed substitution σ ∈ Sub(Σ, X, V, V′) with σ(t) = σ(t′) for a set V′ ⊆ V ar_{Σ,X}. In this case σ is called a unifier for t and t′. σ is a most general unifier (mgu) for t and t′ if σ ≤ σ′ for all unifiers σ′ for t and t′.

□

We want to show that the well-known algorithms for the unification of two terms in a term algebra (without equality) can be applied for the unification in the polymorphic case if we use a particular term algebra.

Definition 4.2 The untyped signature corresponding to the polymorphic signature Σ = (H, F unc, P red), denoted Σ^{u} = (T erm, Op), is defined as follows:

• T erm = {term}

• h: \underbrace{term, …, term}_{n} → term ∈ Op for all h ∈ H with ar(h) = n (n ≥ 0)

• f: \underbrace{term, …, term}_{n} → term ∈ Op for all f:τ_{1}, …, τ_{n} → τ ∈ F unc (n ≥ 0)

• ‘:’: term, term → term ∈ Op

The signature Σ^{u} has only one sort term. If V ⊆ V ar is a set of variable names and X is a set of type variables, we interpret V and X also as variables of sort term and denote by T_{Σ^{u}}(X ∪ V) the algebra of Σ^{u}-terms with variables from X ∪ V. □

T_{Σ^{u}}(X ∪ V) is a single-sorted free term algebra over X ∪ V, where the operation symbols are type constructors from H, function symbols from F unc and the symbol ‘:’ with arity 2. The notions of “substitution” and “unifier” for the algebra T_{Σ^{u}}(X ∪ V) are defined as usual (e.g., [Lloyd 87]) and we omit the details here. [Robinson 65] has found an algorithm for computing a most general unifier in a single-sorted free term algebra. We present the algorithm and the result of Robinson. The algorithm of Robinson uses disagreement sets to specify the differences of terms. For our purpose it is important to inspect the differences in type expressions first. Therefore we define:

Definition 4.3 Let t_{0}, t_{1} ∈ T_{Σ^{u}}(X ∪ V). The disagreement set of t_{0} and t_{1}, ds(t_{0}, t_{1}), is defined as follows:

If t_{0} = t_{1} then ds(t_{0}, t_{1}) := ∅ else:

If t_{0} = t:τ and t_{1} = t′:τ′ then ds(t_{0}, t_{1}) := \{ \begin{matrix}ds(t, t′) & if τ = τ′ \\ ds(τ, τ′) & otherwise \end{matrix} else:

If t_{0} ∈ X ∪ V or t_{1} ∈ X ∪ V then ds(t_{0}, t_{1}) := {t_{0}, t_{1}} else:

If t_{0} = f(r_{1}, …, r_{m}) and t_{1} = g(s_{1}, …, s_{n}) (m, n ≥ 0) then:

If f ≠ g or m ≠ n then ds(t_{0}, t_{1}) := {t_{0}, t_{1}} else:

If r_{i} = s_{i} (i = 1, …, j − 1) and r_{j} ≠ s_{j} then ds(t_{0}, t_{1}) := ds(r_{j}, s_{j})

□

If σ is a substitution in T_{Σ^{u}}(X ∪ V) and the set {x ∈ X ∪ V | σ(x) ≠ x} is finite, we denote σ by the set

{x/σ(x) | x ∈ X ∪ V and σ(x) ≠ x}.

Then the following algorithm computes a most general unifier in T_{Σ^{u}}(X ∪ V): Algorithm mgu Input: t_{0}, t_{1} ∈ T_{Σ^{u}}(X ∪ V) Output: An mgu σ for t_{0} and t_{1} in T_{Σ^{u}}(X ∪ V) or fail, if t_{0} and t_{1} are not unifiable in T_{Σ^{u}}(X ∪ V)

1. k := 0; σ_{0} := {}

2. If σ_{k}(t_{0}) = σ_{k}(t_{1}) then stop “σ_{k} is the mgu”

3. If {x, t} ⊆ ds(σ_{k}(t_{0}), σ_{k}(t_{1})) and x ∈ X ∪ V and x does not occur in t then σ_{k+1} := {x/t} ∘ σ_{k}; k := k + 1; go to 2. else stop “fail: t_{0} and t_{1} are not unifiable”

The following theorem is due to [Robinson 65]:

Theorem 4.4 If t_{0}, t_{1} ∈ T_{Σ^{u}}(X ∪ V) are unifiable in T_{Σ^{u}}(X ∪ V), then the algorithm “mgu” terminates and gives an mgu for t_{0} and t_{1}, otherwise the algorithm “mgu” terminates and reports “fail: t_{0} and t_{1} are not unifiable”.

In the rest of this chapter we show that the polymorphic unification problem can be reduced to the unification problem in T_{Σ^{u}}(X ∪V). We assume a given signature Σ = (H, F unc, P red), a set of type variables X and a set of variable names V ar.

Lemma 4.5 If V ⊆ V ar_{Σ,X} and V_{0} := uvar(V), then T erm_{Σ}(X, V) ⊆ T_{Σ^{u}}(X ∪ V_{0}).

Proof: By induction on the size of terms from T_{H}(X) and T erm_{Σ}(X, V).

Thus we can treat typed terms as terms over the signature Σ^{u} if we view typed variables as composite ‘:’-terms with the variable name as the first and the variable type as the second component. For instance, the typed term []:list(α) is also a term over Σ^{u} (actually, `:'([],list(α)) is a term over Σ^{u}, but we use the infix notation for the operator ‘:’). The converse is not true, because equal(1:int,true:bool):bool is a Σ^{u}-term, but not a Σ-term if equal:α, α → bool ∈ F unc. In the following we assume that a set V ⊆_{U} V ar_{Σ,X} of typed variables with unique types is given and V_{0} := uvar(V).

Lemma 4.6 Let t_{0} and t_{1} be unifiable (Σ, X, V)-terms and σ be a unifier for t_{0} and t_{1}. Let σ′ be a substitution in T_{Σ^{u}}(X ∪ V_{0}) with σ′(α) := σ(α) for any α ∈ X and σ′(x) := t if x:τ ∈ V and σ(x:τ) = t:σ(τ) for any x ∈ V_{0}. Then σ′ is a unifier for t_{0} and t_{1} in T_{Σ^{u}}(X ∪ V_{0}).

Proof: It is straightforward to show (by induction on the size of terms) that σ|_{T_{H}(X)} = σ′|_{T_{H}(X)} and σ|_{T erm_{Σ}(X,V)} = σ′|_{T erm_{Σ}(X,V)}. Therefore σ′(t_{0}) = σ(t_{0}) = σ(t_{1}) = σ′(t_{1}).

Hence each unifier corresponds to a unifier in T_{Σ^{u}}(X ∪ V_{0}). The converse is only true for most general unifiers in T_{Σ^{u}}(X ∪ V_{0}). The following lemma is due to [Launay 86].

Lemma 4.7 Let t_{0} and t_{1} be two (Σ, X, V)-terms unifiable in T_{Σ^{u}}(X ∪ V_{0}) with σ a most general unifier in T_{Σ^{u}}(X ∪ V_{0}). Then there exists a typed substitution σ′ ∈ Sub(Σ, X, V, V′) such that σ′(α) = σ(α) for any α ∈ X, σ′(x:τ) = σ(x):σ(τ) for any x:τ ∈ V and V′ := ⋃_{x:τ∈V} var(σ(x:τ)). Moreover, σ′ is a most general unifier for t_{0} and t_{1}.

Proof: At first we show σ(x):σ(τ) ∈ T erm_{Σ}(X, V′) for all x:τ ∈ V. By theorem 4.4, an mgu σ_{k} in T_{Σ^{u}}(X ∪V_{0}) can be computed by the algorithm “mgu” presented above. We show by induction on the computation steps the following property of the computed substitutions σ_{i} in the algorithm “mgu”:

Let W_{i} := {x:σ_{i}(τ) | x:τ ∈ V }, t ∈ T erm_{Σ}(X, V). Then σ_{i}(t) ∈ T erm_{Σ}(X, W_{i}).

For i = 0 we have W_{0}=V and σ_{0}(t) = t. Let i > 0 and σ_{i−1}(t) ∈ T erm_{Σ}(X, W_{i−1}) for all t ∈ T erm_{Σ}(X, V). By the algorithm “mgu”, σ_{i} = {v/u} ∘ σ_{i−1} for a v ∈ X ∪ V_{0} and u ∈ T_{Σ^{u}}(X ∪ V_{0}).

a) v ∈ X: Since σ_{i−1}(t_{0}), σ_{i−1}(t_{1}) ∈ T erm_{Σ}(X, W_{i−1}), it must be u ∈ T_{H}(X). It is straightforward to show that {v/u}(t) ∈ T erm_{Σ}(X, W_{i}) for all t ∈ T erm_{Σ}(X, W_{i−1}). b) v ∈ V_{0}: Since σ_{i−1}(t_{0}), σ_{i−1}(t_{1}) ∈ T erm_{Σ}(X, W_{i−1}), v:τ_{v} (for a τ_{v} ∈ T_{H}(X)) must occur

in σ_{i−1}(t_{0}) or σ_{i−1}(t_{1}) and therefore u:τ_{v} ∈ T erm_{Σ}(X, W_{i−1}) (otherwise v and u are not in the disagreement set). It is straightforward to show that {v/u}(t) ∈ T erm_{Σ}(X, W_{i}) for all t ∈ T erm_{Σ}(X, W_{i−1}) since W_{i} = W_{i−1} and V ⊆_{U} V ar_{Σ,X} is a set of typed variables with unique types.

By induction hypothesis, it follows that σ_{i}(t) ∈ T erm_{Σ}(X, W_{i}) for all t ∈ T erm_{Σ}(X, V). Since t_{0} and t_{1} are unifiable in T_{Σ^{u}}(X ∪ V_{0}), the algorithm “mgu” stops with an mgu σ_{k} and σ_{k}(t) ∈ T erm_{Σ}(X, W_{k}) for all t ∈ T erm_{Σ}(X, V). If σ is another mgu in T_{Σ^{u}}(X ∪ V_{0}), then σ(τ) and σ_{k}(τ) are equivalent types for all τ ∈ T_{H}(X). Therefore σ(t) ∈ T erm_{Σ}(X, V′) for all t ∈ T erm_{Σ}(X, V), in particular σ(x):σ(τ) = σ(x:τ) ∈ T erm_{Σ}(X, V′) for all x:τ ∈ V. It can be shown in a similar way that σ(α) ∈ T_{H}(X) for all α ∈ X since t_{0}, t_{1} ∈ T erm_{Σ}(X, V). By proposition 2.18, there exists a typed substitution σ′ with the conditions described in the lemma. It is straightforward to show (by induction on the size of terms) that σ|_{T_{H}(X)} = σ′|_{T_{H}(X)} and σ|_{T erm_{Σ}(X,V)} = σ′|_{T erm_{Σ}(X,V)}. Therefore σ′(t_{0}) = σ(t_{0}) = σ(t_{1}) = σ′(t_{1}), i.e., σ′ is a unifier for t_{0} and t_{1}. By lemma 4.6, σ′ is a most general unifier.

The requirement for a most general unifier in the last lemma is essential. If the unifier in T_{Σ^{u}}(X ∪ V_{0}) is not most general, then the proposition does not hold: If Σ is a polymorphic signature with basic types bool and int, and V = {x:bool, y:bool}, then the substitution σ = {x/1, y/1} is a unifier for x:bool and y:bool in T_{Σ^{u}}(X ∪ V_{0}), but σ(x:bool) = 1:bool ∉ T erm_{Σ}(X, V′) is an ill-typed term. The requirement for typed variables with unique types is also essential for the correspondence of most general unifiers in T_{Σ^{u}}(X ∪ V_{0}) to unifiers in T erm_{Σ}(X, V): Let X,Y∈ V ar and Σ be a polymorphic signature with basic types bool and int and a function declaration

func f: int, bool → bool

Then the terms f(X:int,X:bool):bool and f(0:int,Y:bool):bool are unifiable in T_{Σ^{u}}({X, Y}) and

     σ = {X/0, Y/0}

is an mgu in T_{Σ^{u}}({X, Y}). But σ(Y:bool) = 0:bool is an ill-typed term and therefore the theorem does not hold for this case.

Theorem 4.8 (Unification) Let V ⊆_{U} V ar_{Σ,X} and V_{0} := uvar(V). Two (Σ, X, V)-terms are unifiable iff they are unifiable in T_{Σ^{u}}(X ∪ V_{0}). A most general unifier can be computed from a most general unifier in T_{Σ^{u}}(X ∪ V_{0}).

Proof: If two (Σ, X, V)-terms are not unifiable, then they are not unifiable in T_{Σ^{u}}(X ∪ V_{0}) by lemma 4.7. If two (Σ, X, V)-terms are unifiable, then (by lemma 4.6) they are unifiable in T_{Σ^{u}}(X ∪ V_{0}). Theorem 4.4 yields a most general unifier in T_{Σ^{u}}(X ∪ V_{0}), and lemma 4.7 converts the mgu in T_{Σ^{u}}(X ∪ V_{0}) into a most general unifier in T erm_{Σ}(X, V).

The unification problem in the polymorphic case is solved by this theorem. There exist more efficient unification algorithms ([Martelli/Montanari 82] [Bidoit/Corbin 83] [Paterson/ Wegman 78]) that can also be used instead of the classical one presented above. We only require the following technical restriction that will be needed for later proofs: If V ⊆ V ar_{Σ,X}, t and t′ are (Σ, X, V)-terms and σ is a most general unifier for t and t′, then σ = {x_{1}/t_{1}, …, x_{n}/t_{n}} and the following conditions hold:

1. uvar(t_{i}) ⊆ uvar(t) ∪ uvar(t′) and tvar(t_{i}) ⊆ tvar(t) ∪ tvar(t′) for i = 1, …, n.

2. x_{i} ∉ var(t_{j}) ∪ tvar(t_{j}) for all i, j ∈ {1, …, n}, i.e., the most general unifier is an idempotent substitution.

3. If V ⊆_{U} V ar_{Σ,X}, then ⋃_{x:τ∈V} var(σ(x:τ)) ⊆_{U} V ar_{Σ,X}.

The classical unification algorithm meets these requirements.

Resolution

In this chapter we will show that the resolution principle in untyped Horn logic can be used in the polymorphic case with only a few changes. At first we prove soundness and completeness of resolution with arbitrary unifiers. In a subsequent step we will show these properties for resolution with most general unifiers.

5.1 Soundness and completeness of resolution

In untyped Horn logic an atom is unified with the head of a variant of a clause in each resolution step [Lloyd 87]. Therefore we have to define the concept of variable renaming for clauses.

Definition 5.1 Let V, V′ ⊆ V ar_{Σ,X} and c = L_{0} ← L_{1}, …, L_{m} be a (Σ, X, V)-clause. The (Σ, X, V′)-clause L′_{0} ← L′_{1}, …, L′_{m} is called a variant of c, if a typed substitution σ ∈ Sub(Σ, X, V, V′) exists with:

1. σ|_{T_{H}(X)} is a renaming of the type variables in tvar(c).

2. σ(x:τ) ∈ V′, for all x:τ ∈ V

3. v, v′ ∈ var(c) with σ(v) = σ(v′) implies v = v′.

4. σ(L_{i}) = L′_{i} for i = 0, …, m

□

Since the composition of two injective homomorphisms is again an injective homomorphism, we get the following

Proposition 5.2 Let V ⊆ V ar_{Σ,X} and c_{0}, c_{1}, c_{2} be (Σ, X, V)-clauses so that c_{1} is a variant of c_{0} and c_{2} is a variant of c_{1}. Then c_{2} is also a variant of c_{0}.

Now we have the prerequisites for defining the notion of resolution in the polymorphic case:

Definition 5.3 (Resolution) Let C be a set of Σ-clauses.

a) Let V, V′ ⊆ V ar_{Σ,X}, G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom and the (Σ, X, V)- clause L′ ← G′ be a variant of a clause from C. If there exists a unifier σ ∈ Sub(Σ, X, V, V′) for L and L′, then σ(G) ∪ σ(G′) is said to be derived by resolution from G ∪ {L} relative to σ and L′ ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{R} σ σ(G) ∪ σ(G′)

In a resolution step of this form, L′ ← G′ is called the used clause.

b) Let V ⊆ V ar_{Σ,X} and G be a (Σ, X, V)-goal. A (Σ, C, V)-resolution of G is a sequence

of the form

(Σ, C, V_{0}) G_{0} ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} G_{n}

where G_{0} = G, V_{0} = V, and (Σ, C, V_{i}) G_{i} ⊢_{R} σ_{i+1} G_{i+1} with σ_{i+1} ∈ Sub(Σ, X, V_{i}, V_{i+1}) for i = 0, 1, 2, …, n − 1. The (Σ, C, V)-resolution is called successful if G_{n} = ∅. In this case n is called the length of the (Σ, C, V)-resolution, and σ := σ_{n} ∘ ⋯ ∘ σ_{1} is called an R-computed answer. Notation:

(Σ, C, V) ⊢_{R} σ G

□

For the completeness of resolution it is necessary to use variants of clauses in a resolution step, otherwise the goal {z:list(α) ≡ z:list(α)} cannot be resolved with the clause x:α ≡ x:α ← ∅ since α and list(α) are not unifiable. A resolution with the variant x:β ≡ x:β ← ∅ is possible:

(Σ, C, {x:β, z:list(α)}) {z:list(α) ≡ z:list(α)} ⊢_{R} σ ∅

where σ(β) = list(α) and σ(x:β) = z:list(α). The variants of a clause used in a resolution step should not contain type variables or typed variables that also occur in the goal or in preceding resolution steps. The use of variants is unnecessary in the Horn clause calculus because it is possible to rename the type variables and typed variables by an explicit application of the substitution rule:

(Σ, C, {x:α}) ⊢ x:α ≡ x:α ←
(Σ, C, {x:β}) ⊢ x:β ≡ x:β ←
(Σ, C, {z:list(α)}) ⊢ z:list(α) ≡ z:list(α) ←

The soundness of resolution can be shown by simulating a resolution sequence by a derivation in the polymorphic Horn clause calculus:

Theorem 5.4 (Soundness of resolution) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful resolution (Σ, C ∪ EAX(Σ), V) ⊢_{R} σ G with R-computed answer σ ∈ Sub(Σ, X, V, V′), then (Σ, C, V′) ⊧ σ(G).

Proof: We define Ce := C ∪ EAX(Σ) and assume that there is a successful resolution (Σ, Ce, V) ⊢_{R} σ G. Thus there is a (Σ, Ce, V)-resolution of the form

(Σ, Ce, V) G_{0} ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅

with G_{0} = G and σ = σ_{n} ∘ ⋯ ∘ σ_{1}. We show the following proposition by induction on the resolution steps:

For i = 0, …, n: If P ∈ G_{n−i}, then (Σ, Ce, V′) ⊢ σ_{n} ∘ ⋯ ∘ σ_{n−i+1}(P)

This is true for i = 0 since G_{n} = ∅. For the induction step we assume that (Σ, Ce, V′) ⊢ σ_{n}∘⋯∘σ_{n−i+1}(P) is true for all P ∈ G_{n−i}. The (n − i)-th resolution step has the form

(Σ, Ce, V_{n−i−1}) G_{n−i−1} ⊢_{R} σ_{n−i} G_{n−i}

and there is a variant L′ ← G′ of a clause from Ce and a Σ-atom L ∈ G_{n−i−1} with

σ_{n−i}(L) = σ_{n−i}(L′)  and  G_{n−i} = σ_{n−i}((G_{n−i−1} − {L}) ∪ G′).

We have to show that (Σ, Ce, V′) ⊢ σ_{n} ∘ ⋯ ∘ σ_{n−i}(P) is true for all P ∈ G_{n−i−1}. As the (Σ, X, V_{n−i−1})-clause L′ ← G′ is a variant of a clause from Ce, there exist V′′ ⊆ V ar_{Σ,X}, L′′ ← G′′ ∈ Ce and σ′′ ∈ Sub(Σ, Ce, V′′, V_{n−i−1}) with σ′′(L′′ ← G′′) = L′ ← G′. Therefore, (Σ, Ce, V′′) ⊢ L′′ ← G′′ and

(Σ, Ce, V_{n−i−1}) ⊢ L′ ← G′

by the substitution rule. If we apply the substitution rule with typed substitution σ_{n}∘⋯∘σ_{n−i}, we obtain

(Σ, Ce, V′) ⊢ σ_{n} ∘ ⋯ ∘ σ_{n−i}(L′ ← G′)

By induction hypothesis, (Σ, Ce, V′) ⊢ σ_{n} ∘⋯∘σ_{n−i+1}(P), for all P ∈ G_{n−i}. Since σ_{n−i}(G′) ⊆ G_{n−i}, we get from multiple applications of the cut rule

(Σ, Ce, V′) ⊢ σ_{n} ∘ ⋯ ∘ σ_{n−i}(L′)

If P ∈ G_{n−i−1} − {L}, then σ_{n−i}(P) ∈ G_{n−i}, and, therefore,

(Σ, Ce, V′) ⊢ σ_{n} ∘ ⋯ ∘ σ_{n−i}(P)

by induction hypothesis. This completes the induction step. We obtain the following proposition for i = n:

For all P ∈ G, (Σ, Ce, V′) ⊢ σ(P).

Let M be a model for (Σ, C) and v be a variable assignment for (X, V′) in M (if there exists no such variable assignment, then M, V′ ⊧ σ(G) is trivially true). By theorem 3.2 (soundness of deduction), we obtain M, v ⊧ σ(P) for all P ∈ G. This implies M, v ⊧ σ(G). Hence (Σ, Ce, V′) ⊧ σ(G) is true.

The completeness of resolution in untyped Horn logic can be proved by a fixpoint theorem using a transformation on Herbrand interpretations [van Emden/Kowalski 76] [Lloyd 87]. In [Hanus 88b] it is shown that this proof method can be adapted to the polymorphic case. In this thesis we will show the completeness of resolution for polymorphic Horn clause logic with equality by simulating each deduction in the polymorphic Horn clause calculus by resolution. [Padawitz 88] has presented such a proof for many-sorted Horn logic with equality. However, he has required the strictness of all types which simplifies the proof. The simulation of deduction by resolution is more difficult than the simulation of resolution by deduction. A few technical lemmas will help to structure the completeness proof.

Definition 5.5 Along with a set of Σ-clauses C we define the set of instantiated clauses Ĉ as follows:

Ĉ := {L ← G | L ← G is an instance of a clause from C}

□

The set Ĉ contains all clauses which are obtained from clauses in C by substituting type expressions for type variables and well-typed terms for typed variables.

Corollary 5.6 A Σ-interpretation is a model for (Σ, C) iff it is a model for (Σ, Ĉ).

Proof: The theorem follows by definition of Ĉ and lemma 2.21.

The next lemma shows that the substitution rule is not necessary if Ĉ is used in a deduction.

Lemma 5.7 Let C be a set of Σ-clauses, V, V′ ⊆ V ar_{Σ,X} and (Σ, C, V) ⊢ L ← G. For any typed substitution σ ∈ Sub(Σ, X, V, V′) there exists a deduction (Σ, Ĉ, V′) ⊢ σ(L ← G) where only axioms and cut rules are applied.

Proof: We prove the lemma by induction on the number n of cut rule applications in a shortest deduction of (Σ, C, V) ⊢ L ← G. The case n = 0 is trivial since σ_{0}(L_{0}) ← σ_{0}(G_{0}) ∈ Ĉ for all L_{0} ← G_{0} ∈ C and all appropriate typed substitutions σ_{0}. Otherwise there is a last application of the cut rule in the deduction, say

(Σ, C, V_{i}) ⊢ L_{i} ← G_{i} ∪ {L_{j}}  and  (Σ, C, V_{i}) ⊢ L_{j} ← G_{j}

occur in the deduction before the last application of the cut rule. We have to show that (Σ, Ĉ, V′_{i}) ⊢ σ_{1}(L_{i}) ← σ_{1}(G_{i} ∪G_{j}) can be deduced without an application of the substitution rule for all typed substitutions σ_{1} ∈ Sub(Σ, X, V_{i}, V′_{i}). The number of cut rule applications in shortest derivations of

(Σ, C, V_{i}) ⊢ L_{i} ← G_{i} ∪ {L_{j}}  and  (Σ, C, V_{i}) ⊢ L_{j} ← G_{j}

is less than n. By induction hypothesis,

(Σ, Ĉ, V′_{i}) ⊢ σ_{1}(L_{i}) ← σ_{1}(G_{i} ∪ {L_{j}})  and  (Σ, Ĉ, V′_{i}) ⊢ σ_{1}(L_{j}) ← σ_{1}(G_{j})

can be deduced without an application of the substitution rule for all typed substitutions σ_{1} ∈ Sub(Σ, X, V_{i}, V′_{i}). By an application of the cut rule, we obtain

(Σ, Ĉ, V′_{i}) ⊢ σ_{1}(L_{i}) ← σ_{1}(G_{i} ∪ G_{j})

This proves the lemma.

Lemma 5.8 Let C be a set of Σ-clauses and V ⊆ V ar_{Σ,X}. If (Σ, C, V) ⊢ L ← G where only axioms and cut rules are applied, then (Σ, C′, V) ⊢_{R} id_{X,V} L with C′ = C ∪ {P ← | P ∈ G}, and each substitution in the resolution is equal to id_{X,V}.

Proof: The lemma is proved by induction on the length of the deduction. Let d_{1}, …, d_{n} be a deduction for (Σ, C, V) ⊢ L ← G where only axioms and cut rules are applied. If L ← G ∈ C, then (Σ, C′, V) L ⊢_{R} id_{X,V} G is a resolution step. If G consists of k Σ-atoms, then we achieve the empty goal with k further resolution steps with substitutions id_{X,V}. If L ← G ∉ C, then the clause must be derived by an application of the cut rule, i.e., there are

d_{i} = (Σ, C, V) ⊢ L ← G_{0} ∪ {L_{1}}
d_{j} = (Σ, C, V) ⊢ L_{1} ← G_{1}

with G = G_{0} ∪ G_{1} and i, j < n. By induction hypothesis,

(Σ, C ∪ {P ← | P ∈ G_{0} ∪ {L_{1}}}, V) ⊢_{R} id_{X,V} L

and

(Σ, C ∪ {P ← | P ∈ G_{1}}, V) ⊢_{R} id_{X,V} L_{1}

and, therefore,

(Σ, C′ ∪ {L_{1} ←}, V) ⊢_{R} id_{X,V} L  (1)

and

(Σ, C′, V) ⊢_{R} id_{X,V} L_{1}  (2)

since G = G_{0} ∪ G_{1}. If the clause L_{1} ← is used in resolution (1), then, by (2), it is possible to replace the resolution step by a sequence of resolution steps that derives L_{1} to the empty goal using clauses from C′. Thus (Σ, C′, V) ⊢_{R} id_{X,V} L and each substitution in this resolution is equal to id_{X,V}.

Now we can prove the completeness of the resolution method:

Theorem 5.9 (Completeness of resolution for atoms) Let C be a set of Σ-clauses, V, V′ ⊆ V ar_{Σ,X} be finite and A be a (Σ, X, V)-atom. If σ ∈ Sub(Σ, X, V, V′) is a typed substitution with (Σ, C, V′) ⊧ σ(A), then there exists a set V_{0} ⊆ V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V′) with (Σ, C ∪ EAX(Σ), V_{0}) ⊢_{R} σ_{0} A and σ_{0}(A) = σ(A).

Proof: W.l.o.g. we assume that tdom(σ) is finite since V is finite. Let (Σ, C, V′) ⊧ σ(A). By theorem 3.8, (Σ, Ce, V′) ⊢ σ(A), where Ce := C ∪ EAX(Σ). By lemma 5.7, there exists a deduction (Σ, Ĉe, V′) ⊢ σ(A) where only axioms and cut rules are applied. By lemma 5.8, there exists a successful resolution of the form

(Σ, Ĉe, V′) σ(A) ⊢_{R} id_{X,V′} G_{1} ⊢_{R} id_{X,V′} ⋯ ⊢_{R} id_{X,V′} ∅

Let L′_{0} ← R′_{0} ∈ Ĉe be the clause used in the first resolution step, i.e., there exist L_{0} ← R_{0} ∈ Ce, V′_{0} ⊆ V ar_{Σ,X} and σ_{0} ∈ Sub(Σ, X, V′_{0}, V′) with σ_{0}(L_{0} ← R_{0}) = L′_{0} ← R′_{0}. Furthermore we have σ_{0}(L_{0}) = σ(A) and σ_{0}(R_{0}) = G_{1}. W.l.o.g. we assume that tdom(σ) ∩ tdom(σ_{0}) = ∅ and uvar(V) ∩ uvar(V′_{0}) = ∅ (otherwise we choose an appropriate variant of L_{0} ← R_{0} and an appropriate typed substitution σ_{0}). We define V_{0} := V ∪ var(L_{0} ← R_{0}). Thus there exists a typed substitution σ_{1} ∈ Sub(Σ, X, V_{0}, V′) with

σ_{1}(α) = \{ \begin{matrix}σ(α) & if α ∈ tdom(σ) \\ σ_{0}(α) & otherwise \end{matrix}

and

σ_{1}(x:τ) = \{ \begin{matrix}σ(x:τ) & if x:τ ∈ V \\ σ_{0}(x:τ) & if x:τ ∈ var(L_{0} ← R_{0}) \end{matrix}

Then σ_{1}(A) = σ(A) = σ_{0}(L_{0}) = σ_{1}(L_{0}) and σ_{1}(R_{0}) = σ_{0}(R_{0}) = G_{1}. Therefore

(Σ, Ce, V_{0}) A ⊢_{R} σ_{1} G_{1}

is a resolution step. If G_{1} = ∅, then the proof is finished, otherwise there is a second resolution step

(Σ, Ĉe, V′) G_{1} ⊢_{R} id_{X,V′} G_{2}

Let L′_{1} ← R′_{1} ∈ Ĉe be the clause used in this resolution step, i.e., there exist L_{1} ← R_{1} ∈ Ce, V′_{1} ⊆ V ar_{Σ,X} and σ′_{1} ∈ Sub(Σ, X, V′_{1}, V′) with σ′_{1}(L_{1} ← R_{1}) = L′_{1} ← R′_{1}. W.l.o.g. we assume that tdom(σ′_{1}) ⊆ tvar(V′_{1}), tdom(σ′_{1}) ∩ tvar(V′) = ∅ and uvar(V′) ∩ uvar(V′_{1}) = ∅ (otherwise we choose an appropriate variant of L_{1} ← R_{1} and an appropriate typed substitution σ′_{1}). We define V_{1} := V′ ∪ var(L_{1} ← R_{1}). Thus there exists a typed substitution σ_{2} ∈ Sub(Σ, X, V_{1}, V′) with

σ_{2}(α) = \{ \begin{matrix}σ′_{1}(α) & if α ∈ tdom(σ′_{1}) \\ α & otherwise \end{matrix}

and

σ_{2}(x:τ) = \{ \begin{matrix}σ′_{1}(x:τ) & if x:τ ∈ var(L_{1} ← R_{1}) \\ x:τ & otherwise \end{matrix}

Then σ_{2}(L_{1} ← R_{1}) = L′_{1} ← R′_{1} and σ_{2}(G_{1}) = G_{1}. Therefore

(Σ, Ce, V_{1}) G_{1} ⊢_{R} σ_{2} G_{2}

is a resolution step. Since V′ ⊆ V_{1}, we can extend σ_{1} to a typed substitution σ_{1} ∈ Sub(Σ, X, V_{0}, V_{1}). Hence we get the resolution

(Σ, Ce, V_{0}) A ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2}

with σ_{2}(σ_{1}(A)) = σ_{2}(σ(A)) = σ(A) and σ_{2} ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V′). If we apply the transformation of the second resolution step in the same way to the remaining resolution steps, we obtain a resolution

(Σ, Ce, V_{0}) A ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} ⋯ ⊢_{R} σ_{n} ∅

with σ_{n} ∘ ⋯ ∘ σ_{1}(A) = σ(A) and σ_{n} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V′).

If (Σ, C, V) ⊧ L, then we have proved that there is another set of typed variables V_{0} ⊆ V ar_{Σ,X} so that (Σ, C ∪ EAX(Σ), V_{0}) ⊢_{R} σ L with σ ∈ Sub(Σ, X, V_{0}, V) and σ(L) = L. In general, it is not possible to do the resolution with variable set V because additional variables are needed for the application of Σ-clauses in resolution steps. For example, if there is the clause

p(x:int) ←

in the polymorphic specification (Σ, C), then (Σ, C, ∅) ⊧ p(1:int) is true. But we need at least one variable of type int for the resolution of p(1:int). We need the next lemma to prove the completeness of resolution for general goals:

Lemma 5.10 Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and G be a (Σ, X, V)-goal with var(G) = {x_{1}:τ_{1}, …, x_{n}:τ_{n}}. Let p be a new symbol that does not occur in Σ, Σ′ := (H, F unc, P red ∪ {p:τ_{1}, …, τ_{n}}), L := p(x_{1}:τ_{1}, …, x_{n}:τ_{n}) and C′ := C ∪ {L ← G}. Then

(Σ, C, V′) ⊧ σ(G) ⟹ (Σ′, C′, V′) ⊧ σ(L)

for all σ ∈ Sub(Σ′, X, V, V′).

Proof: Let (Σ, C, V′) ⊧ σ(G) and M′ be a model for (Σ′, C′). Then M′ is also a model for (Σ′, C) and M′, var(L ← G) ⊧ L ← G. By lemma 2.21, M′, V′ ⊧ σ(L) ← σ(G). Let v be a variable assignment for (X, V′) in M′ (if there exists no such variable assignment, then M′, V′ ⊧ σ(L) is trivially true). M′ is also a model for (Σ, C) if we omit the interpretation of the predicate symbol p in M′. Therefore M′, v ⊧ σ(G). M′, v ⊧ σ(L) ← σ(G) implies M′, v ⊧ σ(L). Hence we obtain M′, V′ ⊧ σ(L).

Theorem 5.11 (Completeness of resolution) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} be finite and G be a (Σ, X, V)-goal. If σ ∈ Sub(Σ, X, V, V′) is a typed substitution with (Σ, C, V′) ⊧ σ(G), then there exist a set V_{0} ⊆ V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V′) with (Σ, C ∪ EAX(Σ), V_{0}) ⊢_{R} σ_{0} G and σ_{0}(G) = σ(G).

Proof: Let var(G) = {x_{1}:τ_{1}, …, x_{n}:τ_{n}}. Then we define p, L, Σ′ and C′ as in the last lemma. (Σ, C, V′) ⊧ σ(G) implies (Σ′, C′, V′) ⊧ σ(L). By theorem 5.9, there exist V_{0} ⊆ V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V′) with (Σ′, C′ ∪ EAX(Σ′), V_{0}) ⊢_{R} σ_{0} L and σ_{0}(L) = σ(L). Only the clause L ← G can be used for the elimination of an atom with predicate symbol p. Therefore we can assume that the used clause in the first resolution step is L ← G (applications of the clause

p(x_{1}:τ_{1}, …, x_{n}:τ_{n}) ← p(y_{1}:τ_{1}, …, y_{n}:τ_{n}), x_{1}:τ_{1} ≡ y_{1}:τ_{1} , …, x_{n}:τ_{n} ≡ y_{n}:τ_{n}

can be simulated by equality axioms in later steps). Therefore there is a resolution

(Σ, C′ ∪ EAX(Σ′), V_{0}) L ⊢_{R} σ_{1} σ_{1}(G) ⊢_{R} σ_{2} G_{2} ⋯ ⊢_{R} σ_{n} ∅

with σ_{0} = σ_{n} ∘⋯∘σ_{1}. Hence there exist a variant L′ ← G′ of a clause from C ∪EAX(Σ), a Σgoal G_{1}, a Σ-atom L_{1} with G = G_{1}∪{L_{1}}, σ_{2}(σ_{1}(L_{1})) = σ_{2}(L′) and G_{2} = σ_{2}(σ_{1}(G_{1}))∪σ_{2}(G′). W.l.o.g. we assume that σ_{1} does not alter type variables or typed variables from L′ ← G′, i.e., σ_{1}(L′ ← G′) = L′ ← G′ (otherwise we choose a variant of L′ ← G′ and extend the set V_{0} as in the proof of theorem 5.9). Thus σ_{2} ∘ σ_{1} is a unifier for L_{1} and L′ and G_{2} = σ_{2}(σ_{1}(G_{1})) ∪ σ_{2}(σ_{1}(G′)). Therefore

(Σ′, C′ ∪ EAX(Σ′), V_{0}) G ⊢_{R} σ_{2} ∘ σ_{1} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅

is a resolution for G with R-computed answer σ_{n} ∘ ⋯ ∘ σ_{2} ∘ σ_{1} = σ_{0}. Now σ_{0}(L) = σ(L) implies σ_{0}(G) = σ(G) (we assume that tvar(G) = tvar(L), otherwise it is possible to define L so that this condition holds). Since predicate p does not occur in this resolution, we obtain (Σ, C ∪ EAX(Σ), V_{0}) ⊢_{R} σ_{0} G.

5.2 Resolution with most general unifiers

In this section we are interested in resolutions where each unifier in a resolution step is a most general one. Such resolutions are common in logic programming [Lloyd 87]. The requirement for most general unifiers influences only completeness. To prove completeness of resolution with most general unifiers we need the following lemma:

Lemma 5.12 (mgu-lemma) Let (Σ, C) be a polymorphic specification, V ⊆_{U} V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there exists a resolution of the form

(Σ, C, V) G ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅

for G, then there exists a resolution of the form

(Σ, C, V) G ⊢_{R} σ′_{1} G′_{1} ⊢_{R} σ′_{2} G′_{2} ⊢_{R} ⋯ ⊢_{R} σ′_{n} ∅

where each σ′_{i} is a most general unifier and σ′_{n} ∘⋯∘σ′_{1} ∈ Sub(Σ, X, V, V′). Furthermore, there exists a typed substitution ϕ ∈ Sub(Σ, X, V′, V′′) with ϕ ∘ σ′_{n} ∘ ⋯ ∘ σ′_{1} = σ_{n} ∘ ⋯ ∘ σ_{1}.

Proof: By induction on the length n of the resolution: n = 1: Then (Σ, C, V) G ⊢_{R} σ_{1} ∅. Hence there exists a variant L ← ∅ of a clause from C with σ_{1}(G) = σ_{1}(L). By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V, V′) for G and L and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V′, V′′) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V) G ⊢_{R} σ′_{1} ∅

is a resolution for G. n > 0: Then there is a resolution of the form

(Σ, C, V) G ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅

Hence there exists a variant L′ ← G′ of a clause from C with σ_{1}(L′) = σ_{1}(L) where G = G_{0} ∪{L}. By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V, V′) for L′ and L and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V′, V′′) with ϕ∘σ′_{1} = σ_{1}. Let G′_{1} := σ′_{1}(G_{0} ∪ G′). Then

(Σ, C, V) G ⊢_{R} σ′_{1} G′_{1} ⊢_{R} σ_{2} ∘ ϕ G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅

is a resolution for G (w.l.o.g. we assume that ϕ does not alter any type variables or typed variables from the clause used in the second resolution step) and

(Σ, C, V′) G′_{1} ⊢_{R} σ_{2} ∘ ϕ G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅

is a resolution for G′_{1} of length n − 1. Since V′ ⊆_{U} V ar_{Σ,X} and by induction hypothesis, there exists a resolution

(Σ, C, V′) G′_{1} ⊢_{R} σ′_{2} G′_{2} ⊢_{R} ⋯ ⊢_{R} σ′_{n} ∅

where each σ′_{i} is a most general unifier, σ′_{n} ∘ ⋯ ∘ σ′_{2} ∈ Sub(Σ, X, V′, V_{1}), and there exists a typed substitution ρ ∈ Sub(Σ, X, V_{1}, V_{2}) with ρ ∘ σ′_{n} ∘ ⋯ ∘ σ′_{2} = σ_{n} ∘ ⋯ ∘ σ_{2} ∘ ϕ. Hence we obtain a resolution

(Σ, C, V) G ⊢_{R} σ′_{1} G′_{1} ⊢_{R} σ′_{2} G′_{2} ⊢_{R} ⋯ ⊢_{R} σ′_{n} ∅

where each σ′_{i} is a most general unifier, σ′_{n}∘⋯∘σ′_{1} ∈ Sub(Σ, X, V, V_{1}), and ρ ∈ Sub(Σ, X, V_{1}, V_{2}) is a typed substitution with ρ ∘ σ′_{n} ∘ ⋯ ∘ σ′_{1} = σ_{n} ∘ ⋯ ∘ σ_{2} ∘ ϕ ∘ σ′_{1} = σ_{n} ∘ ⋯ ∘ σ_{2} ∘ σ_{1}.

Now we define the notion of most general resolution as resolution with most general unifiers where in each resolution step the (type) variables in the goal and the applied clause are disjoint:

Definition 5.13 (Most general resolution) Let (Σ, C) be a polymorphic specification.

a) Let V, V′ ⊆_{U} V ar_{Σ,X}, G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom and the (Σ, X, V)- clause L′ ← G′ be a variant of a clause from C with tvar(G ∪ {L}) ∩ tvar(L′ ← G′) = ∅ and var(G ∪ {L}) ∩ var(L′ ← G′) = ∅. If there exists a most general unifier σ ∈ Sub(Σ, X, V, V′) for L and L′, then σ(G)∪σ(G′) is said to be derived by most general resolution from G ∪ {L} relative to σ and L′ ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{GR} σ σ(G) ∪ σ(G′)

b) Let V ⊆_{U} V ar_{Σ,X} and G be a (Σ, X, V)-goal. A most general (Σ, C, V)-resolution of G is a sequence of the form

(Σ, C, V_{0}) G_{0} ⊢_{GR} σ_{1} G_{1} ⊢_{GR} σ_{2} G_{2} ⊢_{GR} ⋯ ⊢_{GR} σ_{n} G_{n}

where G_{0} = G, V_{0} = V and (Σ, C, V_{i}) G_{i} ⊢_{GR} σ_{i+1}G_{i+1} with σ_{i+1} ∈ Sub(Σ, X, V_{i}, V_{i+1}) for i = 0, 1, 2, …, n − 1. The most general (Σ, C, V)-resolution is called successful if G_{n} = ∅. In this case n is called the length of the most general (Σ, C, V)-resolution, and σ := σ_{n} ∘ ⋯ ∘ σ_{1} is called a GR-computed answer. Notation:

(Σ, C, V) ⊢_{GR} σ G

□

We remark that V_{i} ⊆_{U} V ar_{Σ,X} for i = 0, 1, 2, …, n − 1 since V ⊆_{U} V ar_{Σ,X}. Most general resolution is a special case of resolution and therefore we get the following result:

Theorem 5.14 (Soundness of most general resolution) Let (Σ, C) be a polymorphic specification, V ⊆_{U} V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful most general resolution (Σ, C ∪ EAX(Σ), V) ⊢_{GR} σ G with GR-computed answer σ ∈ Sub(Σ, X, V, V′), then (Σ, C, V′) ⊧ σ(G).

The completeness of most general resolution follows from completeness of resolution and mgulemma 5.12:

Theorem 5.15 (Completeness of most general resolution) Let (Σ, C) be a polymorphic specification, V ⊆_{U} V ar_{Σ,X} be finite and G be a (Σ, X, V)-goal. If σ ∈ Sub(Σ, X, V, V′) is a typed substitution with (Σ, C, V′) ⊧ σ(G), then there exist a set V_{0} ⊆_{U} V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V_{1}) with (Σ, C ∪ EAX(Σ), V_{0}) ⊢_{GR} σ_{0} G and there is a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′) with ϕ(σ_{0}(G)) = σ(G).

Proof: Let Ce := C ∪ EAX(Σ). By completeness theorem 5.11, there exist V_{2} ⊆ V ar_{Σ,X} and a resolution of the form

(Σ, Ce, V_{2}) G ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅  (1)

with σ_{n} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{2}, V′) and σ_{n} ∘ ⋯ ∘ σ_{1}(G) = σ(G). W.l.o.g. we assume that V_{2} is finite. V_{2} ⊆_{U} V ar_{Σ,X} is not true in general. Hence we construct a set V_{0} ⊆_{U} V ar_{Σ,X} corresponding to V_{2}: If V_{2} = var(G) ∪ {x_{1}:τ_{1}, …, x_{m}:τ_{m}}, then we define V_{0} := var(G) ∪ {y_{1}:τ_{1}, …, y_{m}:τ_{m}} where y_{i} are pairwise distinct new variable names from V ar. Let ρ ∈ Sub(Σ, X, V_{0}, V_{2}) with ρ(α) = α for all α ∈ X, ρ(x:τ) = x:τ for all x:τ ∈ var(G) and ρ(y_{i}:τ_{i}) = x_{i}:τ_{i} for i = 1, …, m. V_{0} ⊆_{U} V ar_{Σ,X} and ρ is invertible so that ρ ∘ ρ^{−1} = id_{X,V_{2}}. We show that

(Σ, Ce, V_{0}) G ⊢_{R} σ_{1} ∘ ρ G_{1} ⊢_{R} σ_{2} G_{2} ⋯ ⊢_{R} σ_{n} ∅  (2)

is a resolution for G: Let L′ ← G′ be the clause used in the first resolution step in (1). Therefore G = G_{0} ∪ {L_{0}} with σ_{1}(L_{0}) = σ_{1}(L′) and G_{1} = σ_{1}(G_{1} ∪ G′). ρ^{−1}(L′ ← G′) is also a variant of a clause from Ce. ρ(G) = G since ρ(x:τ) = x:τ for all x:τ ∈ var(G). Thus σ_{1}(ρ(L_{0})) = σ_{1}(L_{0}) = σ_{1}(L′) = σ_{1}(ρ(ρ^{−1}(L′))) and σ_{1}(ρ(G_{0} ∪ ρ^{−1}(G′))) = σ_{1}(G_{0} ∪ G′) = G_{1}. Therefore (2) is indeed a resolution for G. We assume for the resolution (2) that tvar(G_{i}) ∩ tvar(c_{i}) = ∅ and var(G_{i}) ∩ var(c_{i}) = ∅ where c_{i} is the clause used in the i-th resolution step. If this is not the case then we choose an appropriate variant of c_{i} and extend V_{0} and the preceding substitutions as in the proof of theorem 5.9. By the mgu-lemma 5.12, we obtain from (2) a most general resolution

(Σ, Ce, V_{0}) G ⊢_{GR} σ′_{1} G_{1} ⊢_{GR} σ′_{2} G_{2} ⋯ ⊢_{GR} σ′_{n} ∅

and a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′) (where σ_{0} := σ′_{n} ∘ ⋯ ∘ σ′_{1} ∈ Sub(Σ, X, V_{0}, V_{1})) with ϕ ∘ σ_{0} = σ_{n} ∘ ⋯ ∘ σ_{1} ∘ ρ. Hence ϕ(σ_{0}(G)) = σ_{n} ∘ ⋯ ∘ σ_{1} ∘ ρ(G) = σ_{n} ∘ ⋯ ∘ σ_{1}(G) = σ(G).

Example for most general resolution: The following polymorphic specification defines a function append for the concatenation of two lists and a predicate member that is true if the first argument is contained in the second argument. We omit the type annotations in the clauses and goals:

type int/0, list/1

func 0, 1, 2: → int func []: → list(α) func •: α, list(α) → list(α) func append: list(α), list(α) → list(α)

pred member: α, list(α)

clauses:

(Type of variables:  E,E1:α, L,R:list(α))
1:    append([],L) ≡ L ←
2:    append([E|R],L) ≡ [E|append(R,L)] ←
3:    member(E,[E|R]) ←
4:    member(E,[E1|R]) ← member(E,R)

The following derivation is a most general polymorphic resolution for the goal

member(2,append([1],[2])):
member(2,append([1],[2]))

⊢_{GR} congruence clause for member

member(E1,L1), 2 ≡ E1, append([1],[2]) ≡ L1

⊢_{GR} reflexivity

member(2,L1), append([1],[2]) ≡ L1

⊢_{GR} clause 2

member(2,[1|append([],[2])])

⊢_{GR} congruence clause for member

member(E2,L2), 2 ≡ E2, [1|append([],[2])] ≡ L2

⊢_{GR} reflexivity

member(2,L2), [1|append([],[2])] ≡ L2

⊢_{GR} congruence clause for `•'

member(2,[E3|L3]), 1 ≡ E3, append([],[2]) ≡ L3

⊢_{GR} reflexivity

member(2,[1|L3]), append([],[2]) ≡ L3

⊢_{GR} clause 4

member(2,L3), append([],[2]) ≡ L3

⊢_{GR} clause 1

member(2,[2])

⊢_{GR} clause 3 ∅

Generally, the resolution needs many steps and the search space is huge because of the equality axioms. Therefore we define in the next chapter a more efficient proof method, called paramodulation.

Paramodulation

6.1 Soundness and completeness of paramodulation

We want to define a more efficient proof procedure for polymorphic Horn clause specifications than resolution. This proof procedure is known in untyped Horn logic as paramodulation, introduced by [Robinson/Wos 69] for general clauses in untyped first-order logic. The general idea is to avoid resolution with clauses from EAX(Σ) − {x:α ≡ x:α ←}. This optimiziation significantly reduces the search space. But the completeness can only be preserved by introducing a new inference rule called paramodulation rule that applies a conditional equation to any subterm in the given goal. In order to formalize the notion of subterms of a term we define occurrences: An occurrence is a sequence of integers that denotes a path in a term.

Definition 6.1 Let V ⊆ V ar_{Σ,X} and t:τ ∈ T erm_{Σ,τ} (X, V). Then O(t:τ) is the set of occurrences in t:τ: An occurrence denotes a position in a term, represented by a list of natural numbers, and is defined in the following way:

• Λ ∈ O(t:τ) (Λ is the empty list of natural numbers)

• i ⋄ π ∈ O(t:τ) if t:τ = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ, π ∈ O(t_{i}:τ_{i}) and 1 ≤ i ≤ n (⋄ denotes the concatenation of a natural number with a list of natural numbers)

Let π ∈ O(t:τ) be an occurrence in t:τ. Then t:τ[π] denotes the subterm of t:τ at position π, and t:τ[π ← t′:τ′] denotes the result of the replacement of the subterm t:τ[π] by the term t′:τ′, provided t′:τ′ and t:τ[π] have the same type:

• t:τ[Λ] = t:τ

• f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ[i ⋄ π] = t_{i}:τ_{i}[π] , for 1 ≤ i ≤ n

• t:τ[Λ ← t′:τ′] = t′:τ′ , if τ = τ′

• f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ[i⋄π ← t′:τ′] = f(t_{1}:τ_{1}, …, t_{i}:τ_{i}[π ← t′:τ′], …, t_{n}:τ_{n}):τ, for 1 ≤ i ≤ n

Let π ∈ O(t:τ) be an occurrence in t:τ with π = i_{1} ⋄ ⋯ ⋄ i_{n} ⋄ Λ. Then i_{1} ⋄ ⋯ ⋄ i_{j} ⋄ Λ is called a prefix of π for all 0 ≤ j ≤ n. If L = p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) is a (Σ, X, V)-atom, 1 ≤ i ≤ n and π ∈ O(t_{i}:τ_{i}), then i ⋄ π ∈ O(L) is an occurrence in the Σ-atom L, L[i ⋄ π] = t_{i}:τ_{i}[π] is the subterm at position i ⋄ π in L, and

L[i ⋄ π ← t′:τ′] = p(t_{1}:τ_{1}, …, t_{i}:τ_{i}[π ← t′:τ′], …, t_{n}:τ_{n})

is the replacement of the subterm L[i ⋄ π] by t′:τ′ in L if t′:τ′ and t_{i}:τ_{i}[π] are of the same type. □

For example, if t = f(id(2:int):int, ‘+’(3:int, 4:int):int):int, then O(t) = {Λ, 1 ⋄ Λ, 1 ⋄ 1 ⋄ Λ, 2 ⋄ Λ, 2⋄1⋄Λ, 2⋄2⋄Λ} is the set of occurrences in t and t[2⋄Λ ← 7:int] = f(id(2:int):int, 7:int):int. In the last definition, the subterm replacement is restricted to terms of the same type, which ensures that the result term is well-typed. Now we can define the notion of paramodulation in the polymorphic case:

Definition 6.2 (Paramodulation) Let C be a set of Σ-clauses and V ⊆ V ar_{Σ,X}.

a) 1. Paramodulation rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom, π ∈ O(L) and the (Σ, X, V)-clause v ≡ w ← G′ or w ≡ v ← G′ be a variant of a clause from C. If there exists a unifier σ ∈ Sub(Σ, X, V, V′) for L[π] and v, then σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′) is said to be derived by paramodulation from G ∪ {L} relative to σ and v ≡ w ← G′ or w ≡ v ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{P} σ σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′)

2. Restricted resolution rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom and the (Σ, X, V)-clause L′ ← G′ be a variant of a clause from C with pred(L′) ≠ ‘≡’. If there exists a unifier σ ∈ Sub(Σ, X, V, V′) for L and L′, then σ(G) ∪ σ(G′) is said to be derived by restricted resolution from G ∪ {L} relative to σ and L′ ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{P} σ σ(G) ∪ σ(G′)

3. Unification rule: Let G be a (Σ, X, V)-goal, v ≡ w be a (Σ, X, V)-equation and σ ∈ Sub(Σ, X, V, V′) be a unifier for v and w. Then σ(G) is said to be derived by unification from G ∪ {v ≡ w} relative to σ. Notation:

(Σ, C, V) G ∪ {v ≡ w} ⊢_{P} σ σ(G)

b) Let G be a (Σ, X, V)-goal. A (Σ, C, V)-paramodulation of G is a sequence of the form

(Σ, C, V_{0}) G_{0} ⊢_{P} σ_{1} G_{1} ⊢_{P} σ_{2} G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} G_{n}

where G_{0} = G, V_{0} = V and (Σ, C, V_{i}) G_{i} ⊢_{P} σ_{i+1} G_{i+1} with σ_{i+1} ∈ Sub(Σ, X, V_{i}, V_{i+1}) for i = 0, 1, 2, …, n − 1. The (Σ, C, V)-paramodulation is called successful if G_{n} = ∅. In this case n is called the length of the (Σ, C, V)-paramodulation, and σ := σ_{n} ∘ ⋯ ∘ σ_{1} is called a P-computed answer. Notation:

(Σ, C, V) ⊢_{P} σ G

□

The following example shows the improvement of proofs by paramodulation. We assume that the example specification for lists on page 59 is given. Then the following derivation is a paramodulation proof for the goal member(2,append([1],[2])):

     member(2,append([1],[2]))

⊢_{P} paramodulation with clause 2 in subterm append([1],[2])

     member(2,[1|append([],[2])])

⊢_{P} resolution with clause 4

     member(2,append([],[2]))

⊢_{P} paramodulation with clause 1 in subterm append([],[2])

     member(2,[2])

⊢_{P} resolution with clause 3 ∅

Hence we need 4 steps for the paramodulation proof in contrast to 10 steps in the resolution proof. Another example can be found in [Robinson/Wos 69]: They have proved a group theory problem with 136 steps using resolution and with 47 steps using paramodulation. We need less variables in a proof with paramodulation than in a proof with resolution. For example, we need no variables in the following paramodulation proof:

(Σ, C, ∅) 1:int ≡ 1:int ⊢_{P} id_{X,∅} ∅

But in the proof with resolution we need at least one variable for the application of the reflexivity axiom:

(Σ, C, {x:α}) 1:int ≡ 1:int ⊢_{R} σ ∅

with σ(α) = int and σ(x:α) = 1:int.

If we want to simulate paramodulation by resolution we need additional variables for the application of equality axioms. But these variables do not occur in the result of the resolution because they are replaced by other terms. Hence we can directly prove the soundness of paramodulation:

Theorem 6.3 (Soundness of paramodulation) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful paramodulation (Σ, C, V) ⊢_{P} σ G with P-computed answer σ ∈ Sub(Σ, X, V, V′), then (Σ, C, V′) ⊧ σ(G).

Proof: Let Ce := C ∪ EAX(Σ). We show that each paramodulation can be transformed into a corresponding resolution. Then the theorem follows by theorem 5.4. The application of the restricted resolution rule corresponds to one step in the resolution calculus. The application of the unification rule with unifier σ ∈ Sub(Σ, X, V, V′) to an equation t_{1}:τ ≡ t_{2}:τ corresponds to a resolution step with clause x:α ≡ x:α ← where x ∉ uvar(V) and α is a new type variable. For the application of the clause in the resolution calculus we must add the typed variable x:α to the set V and we extend σ to a typed substitution σ ∈ Sub(Σ, X, V ∪ {x:α}, V′) by σ(α) = τ and σ(x:α) = σ(t_{1}:τ). Next we show that an application of the paramodulation rule can be simulated by a sequence of resolution steps with equality axioms. Let

(Σ, C, V) G ∪ {L} ⊢_{P} σ σ(G) ∪ {L′} ∪ σ(G′)

be an application of the paramodulation rule with clause v ≡ w ← G′ or w ≡ v ← G′ and unifier σ ∈ Sub(Σ, X, V, V′). Therefore L = p(…, t_{i}:τ_{i}, …), π ∈ O(t_{i}:τ_{i}), σ(t_{i}:τ_{i}[π]) = σ(v) and L′ = p(…, σ(t_{i}:τ_{i})[π ← σ(w)], …). The (Σ, X, V)-goal G ∪ {L} can be derived with congruence axiom

p(x_{1}:τ_{1}, …, x_{n}:τ_{n}) ← p(y_{1}:τ_{1}, …, y_{n}:τ_{n}), x_{1}:τ_{1} ≡ y_{1}:τ_{1} , …, x_{n}:τ_{n} ≡ y_{n}:τ_{n}

to the goal

G ∪ {p(y_{1}:τ_{1}, …, y_{n}:τ_{n}), t_{1}:τ_{1} ≡ y_{1}:τ_{1} , …, t_{n}:τ_{n} ≡ y_{n}:τ_{n}}

by a step in the resolution calculus. We obtain from n − 1 resolution steps with reflexivity axioms the goal

G ∪ {p(t_{1}:τ_{1}, …, y_{i}:τ_{i}, …, t_{n}:τ_{n}), t_{i}:τ_{i} ≡ y_{i}:τ_{i}}

Several resolution steps with congruence axioms of the form

f(⋯):τ ≡ f(⋯):τ ← ⋯

and reflexivity axioms yield the goal

G ∪ {p(t_{1}:τ_{1}, …, t_{i}:τ_{i}[π ← y:τ], …, t_{n}:τ_{n}), t_{i}:τ_{i}[π] ≡ y:τ}

The unifiers in the last resolution steps replace only type variables and typed variables in the used equality axioms. σ is a unifier for t_{i}:τ_{i}[π] and v. Hence we can do a resolution step with the clause v ≡ w ← G′ (if w ≡ v ← G′ is the clause applied in the paramodulation rule, then we have to apply the symmetry axiom first) and obtain the goal

σ(G) ∪ {p(σ(t_{1}:τ_{1}), …, σ(t_{i}:τ_{i})[π ← σ(w)], …, σ(t_{n}:τ_{n}))} ∪ σ(G′)

Therefore it is possible to simulate the paramodulation step by a sequence of resolution steps. The set V must be extended by new variables that occur in the used equality axioms, but the substitutions in the resolution steps map the new variables into terms from T erm_{Σ}(X, V′).

As in the resolution calculus, we want to show the completeness of paramodulation by simulating resolution by paramodulation. The completeness of paramodulation can also be proved by using the least fixpoint of a transformation on Herbrand interpretations. This is done in [Furbach/Hölldobler/Schreiber 88] for untyped Horn logic with equality. Another technique for proving completeness of paramodulation for first-order logic, based on semantic trees [Kowalski/Hayes 69], is shown in [Hsiang/Rusinowitch 86]. Paramodulation is only complete if we add to the set of axioms the functional-reflexive axioms of Σ:

Definition 6.4 The set of functional-reflexive axioms F AX(Σ) of a polymorphic signature Σ consists of the following clauses:

f(x_{1}:τ_{1}, …, x_{n}:τ_{n}):τ ≡ f(x_{1}:τ_{1}, …, x_{n}:τ_{n}):τ ←

for all f:τ_{1}, …, τ_{n} → τ ∈ F unc where x_{i} ∈ V ar are pairwise distinct variable names. □

The following example shows the necessity of functional-reflexive axioms. We assume three basic types τ_{0}, τ_{1} and τ_{2}. There are the following declarations of constants and functions:

func a,b: → τ_{0}
func f: τ_{0} → τ_{1}
func f1,f2: τ_{1}, τ_{1} → τ_{2}

The specification contains the two clauses

a:τ_{0} ≡ b:τ_{0} ←
f1(f(a:τ_{0}):τ_{1},f(b:τ_{0}):τ_{1}):τ_{2} ≡ f2(f(a:τ_{0}):τ_{1},f(b:τ_{0}):τ_{1}):τ_{2} ←

If σ(x:τ_{1}) = f(a:τ_{0}):τ_{1}, then

(Σ, C, ∅) ⊧ σ(f1(x:τ_{1}, x:τ_{1}):τ_{2} ≡ f2(x:τ_{1}, x:τ_{1}):τ_{2})

but a paramodulation step cannot be applied to the goal f1(x:τ_{1}, x:τ_{1}):τ_{2} ≡ f2(x:τ_{1}, x:τ_{1}):τ_{2}. If we add the functional-reflexive axioms to the set of clauses, we obtain the following paramodulation:

f1(x:τ_{1},x:τ_{1}):τ_{2} ≡ f2(x:τ_{1},x:τ_{1}):τ_{2}

⊢_{P} paramodulation with functional-reflexive axiom for f f1(f(y:τ_{0}):τ_{1},f(y:τ_{0}):τ_{1}):τ_{2} ≡ f2(f(y:τ_{0}):τ_{1},f(y:τ_{0}):τ_{1}):τ_{2}

⊢_{P} paramodulation with the first clause f1(f(b:τ_{0}):τ_{1},f(a:τ_{0}):τ_{1}):τ_{2} ≡ f2(f(a:τ_{0}):τ_{1},f(a:τ_{0}):τ_{1}):τ_{2}

⊢_{P} paramodulation with the first clause f1(f(a:τ_{0}):τ_{1},f(a:τ_{0}):τ_{1}):τ_{2} ≡ f2(f(a:τ_{0}):τ_{1},f(a:τ_{0}):τ_{1}):τ_{2}

⊢_{P} unification rule ∅

The functional-reflexive axioms are valid in every model of a polymorphic specification (Σ, C):

Corollary 6.5 Let C be a set of Σ-clauses. Then (Σ, C, var(c)) ⊧ c for all c ∈ F AX(Σ).

Lemma 6.6 Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X}, G be a (Σ, X, V)-goal with (Σ, C ∪ F AX(Σ), V) ⊢_{P} σ G with P-computed answer σ ∈ Sub(Σ, X, V, V′). Then (Σ, C, V′) ⊧ σ(G).

Proof: By theorem 6.3, (Σ, C ∪ F AX(Σ), V′) ⊧ σ(G). Let M be a model for (Σ, C). By the last corollary, M is also a model for (Σ, C ∪ F AX(Σ)). Therefore M, V′ ⊧ σ(G).

If there exists a successful paramodulation of an instance of a goal, then the next lemma shows that there is also a successful paramodulation of the original goal.

Lemma 6.7 (Lifting lemma for paramodulation) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} be finite, G be a (Σ, X, V)-goal and σ ∈ Sub(Σ, X, V, V′) with σ(α) = α for all α ∈ X − tvar(V). If (Σ, C ∪ F AX(Σ), V′) ⊢_{P} σ_{p} σ(G) with P-computed answer σ_{p} ∈ Sub(Σ, X, V′, V_{1}), then there exist V_{0} ⊆ V ar_{Σ,X} with V ⊆ V_{0} and σ_{0} ∈ Sub(Σ, X, V_{0}, V_{1}) so that (Σ, C ∪ F AX(Σ), V_{0}) ⊢_{P} σ_{0} G and σ_{p} ∘ σ = σ_{0}|_{T_{Σ}(X′,V)} with X′ = tvar(V).

Proof: Let CF := C ∪ F AX(Σ) and let

(Σ, CF, V′) σ(G) ⊢_{P} σ_{1} G_{1}

be the first step in the paramodulation for σ(G) with σ_{1} ∈ Sub(Σ, X, V′, V′_{1}). We show that there exist V_{0} ⊆ V ar_{Σ,X} with V ⊆ V_{0} and typed substitutions σ′_{i} with

(Σ, CF, V_{0}) G ⊢_{P} σ′_{1} G′_{1} ⊢_{P} ⋯ ⊢_{P} σ′_{m} G′_{m}

where G′_{m} = G_{1}, σ_{1} ∘ σ = σ′_{m} ∘ ⋯ ∘ σ′_{1}|_{T_{Σ}(X′,V)} and σ′_{m} ∘ ⋯ ∘ σ′_{1} ∈ Sub(Σ, X, V_{0}, V′_{1}). This implies the lemma. We distinguish the following cases for the applied rule in the first paramodulation step:

a) The unification rule is applied in the first step, i.e., G = G′ ∪ {t_{0}:τ_{0} ≡ t_{1}:τ_{1}} and σ_{1}(σ(t_{0}:τ_{0})) = σ_{1}(σ(t_{1}:τ_{1})). Let V_{0} := V. Then

(Σ, CF, V_{0}) G ⊢_{P} σ_{1} ∘ σ G_{1}

is a paramodulation step (application of the unification rule) for G.

b) The restricted resolution rule is applied in the first step, i.e., there exists a variant L′ ← G′ of a clause from C with σ_{1}(L′) = σ_{1}(σ(L_{0})) where G = G_{0} ∪{L_{0}}. Let V_{0} := V. W.l.o.g. we assume that σ(L′ ← G′) = L′ ← G′ (otherwise we choose an appropriate variant of L′ ← G′ and extend the set V_{0}). Then

(Σ, CF, V_{0}) G ⊢_{P} σ_{1} ∘ σ G_{1}

is a paramodulation step (application of the restricted resolution rule) for G.

c) The paramodulation rule is applied with clause v ≡ w ← G′ at position π ∈ O(σ(L_{0})) in the first step, where G = G_{0} ∪ {L_{0}}, and σ_{1}(σ(L_{0})[π]) = σ_{1}(v).

1. π ∈ O(L_{0}): Let t:τ = L_{0}[π]. We have σ_{1}(σ(t:τ)) = σ_{1}(v). Let V_{0} := V. W.l.o.g. we assume that σ(v ≡ w ← G′) = v ≡ w ← G′ (otherwise we choose an appropriate variant of v ≡ w ← G′ and extend the set V_{0}). Thus σ_{1}(σ(t:τ)) = σ_{1}(σ(v)) and

(Σ, CF, V_{0}) G ⊢_{P} σ_{1} ∘ σ G_{1}

is a paramodulation step (application of the paramodulation rule) for G.

2. π ∉ O(L_{0}): Since π ∈ O(σ(L_{0})), there exists a prefix π_{1} ∈ O(L_{0}) of π with L_{0}[π_{1}] ∈ V. σ(L_{0})[π_{1}] is not a variable and therefore

σ(L_{0})[π_{1}] = f(r_{1}:ρ_{1}, …, r_{p}:ρ_{p}):ρ

for some f and terms r_{i}:ρ_{i}. Let

f(y_{1}:ν_{1}, …, y_{p}:ν_{p}):ν ≡ f(y_{1}:ν_{1}, …, y_{p}:ν_{p}):ν ←

be a variant of a functional-reflexive axiom with new type variables and new typed variables. Let V_{0} := V ∪ {y_{1}:ν_{1}, …, y_{p}:ν_{p}} and σ_{0} ∈ Sub(Σ, X, V_{0}, V′) be the extension of σ on V_{0} so that σ_{0}(f(y_{1}:ν_{1}, …, y_{p}:ν_{p}):ν) = σ(L_{0})[π_{1}]. If we apply the paramodulation rule with this functional-reflexive axiom at position π_{1}, we obtain the paramodulation

(Σ, CF, V_{0}) G ⊢_{P} σ_{0} σ_{0}(G_{0}) ∪ {σ_{0}(L_{0})[π_{1} ← σ(L_{0})[π_{1}]]}

The result goal of this paramodulation step is identical to σ(G). Therefore we have the paramodulation sequence

(Σ, CF, V_{0}) G ⊢_{P} σ_{0} σ(G) ⊢_{P} σ_{1} G_{1}

d) The paramodulation rule is applied with clause w ≡ v ← G′ at position π ∈ O(σ(L_{0})) in the first step, where G = G_{0} ∪ {L_{0}}, and σ_{1}(σ(L_{0})[π]) = σ_{1}(v). This is analogous to case c).

The next lemma is the dual to the last lifting lemma:

Lemma 6.8 Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} be finite, G be a (Σ, X, V)-goal and σ ∈ Sub(Σ, X, V, V′). If (Σ, C, V) ⊢_{P} σ G, then there exist V_{0} ⊆ V ar_{Σ,X} with V′ ⊆ V_{0} and σ′ ∈ Sub(Σ, X, V_{0}, V′) so that (Σ, C, V_{0}) ⊢_{P} σ′ σ(G) and σ′(x:τ) = x:τ for all x:τ ∈ V′.

Proof: Let

(Σ, C, V) G_{0} ⊢_{P} σ_{1} G_{1} ⊢_{P} σ_{2} G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} G_{n}

be a paramodulation for G with G_{0} = G, G_{n} = ∅ and σ = σ_{n} ∘ ⋯ ∘ σ_{1}. W.l.o.g. we assume that σ(α) ≠ α only for a finite number of type variables. Let (Σ, C, V_{i}) G_{i} ⊢_{P} σ_{i+1} G_{i+1} be a paramodulation step. We show that there exists a set V_{0} ⊆ V ar_{Σ,X} with V′ ⊆ V_{0}, where the names of the additional variables are new, so that

(Σ, C, V_{0}) σ_{n} ∘ ⋯ ∘ σ_{i+1}(G_{i}) ⊢_{P} σ′_{i+1} σ_{n} ∘ ⋯ ∘ σ_{i+2}(G_{i+1})

is a paramodulation step, σ′_{i+1} ∈ Sub(Σ, X, V_{0}, V′), and σ′_{i+1}(x:τ) = x:τ for all x:τ ∈ V′. This implies the proposition. We distinguish the kind of rule applied in the paramodulation step:

1. Unification rule: Then G_{i} = G′ ∪ {v ≡ w}, σ_{i+1}(v) = σ_{i+1}(w) and G_{i+1} = σ_{i+1}(G′). Thus σ_{n} ∘ ⋯ ∘ σ_{i+1}(v) = σ_{n} ∘ ⋯ ∘ σ_{i+1}(w), i.e., there is the paramodulation step

(Σ, C, V′) σ_{n} ∘ ⋯ ∘ σ_{i+1}(G_{i}) ⊢_{P} id_{X,V′} σ_{n} ∘ ⋯ ∘ σ_{i+2}(G_{i+1})

2. Restricted resolution rule: Then G_{i} = G′ ∪ {L′}, L′′ ← G′′ is a (Σ, X, V_{i})-clause, σ_{i+1}(L′) = σ_{i+1}(L′′) and G_{i+1} = σ_{i+1}(G′ ∪ G′′). Let L_{i} ← R_{i} be a variant of L′′ ← G′′ with new type variables and new typed variables. We define V_{0} := V′ ∪ var(L_{i} ← R_{i}). Then L_{i} ← R_{i} is a (Σ, X, V_{0})-clause. Since L_{i} ← R_{i} is a variant of L′′ ← G′′, there exists a typed substitution σ′_{i+1} ∈ Sub(Σ, X, V_{0}, V′) with σ′_{i+1}(L_{i} ← R_{i}) = σ_{n} ∘⋯∘σ_{i+1}(L′′ ← G′′) and σ′_{i+1}(x:τ) = x:τ for all x:τ ∈ V′. Thus σ′_{i+1} is a unifier for σ_{n} ∘ ⋯ ∘ σ_{i+1}(L′) and L_{i}, σ′_{i+1}(σ_{n} ∘ ⋯ ∘ σ_{i+1}(G′)) = σ_{n} ∘ ⋯ ∘ σ_{i+1}(G′), and σ′_{i+1}(R_{i}) = σ_{n} ∘ ⋯ ∘ σ_{i+1}(G′′). Hence

(Σ, C, V_{0}) σ_{n} ∘ ⋯ ∘ σ_{i+1}(G_{i}) ⊢_{P} σ′_{i+1} σ_{n} ∘ ⋯ ∘ σ_{i+2}(G_{i+1})

is a paramodulation step.

3. Paramodulation rule: Analogous to the restricted resolution rule.

If a goal is provable by paramodulation, then there exists a successful paramodulation for each subset of the goal:

Lemma 6.9 Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} be finite, G be a (Σ, X, V)-goal and (Σ, C, V) ⊢_{P} σ G with P-computed answer σ ∈ Sub(Σ, X, V, V′). If G′ ⊆ G, then there exist V_{0} ⊆ V ar_{Σ,X} with V ⊆ V_{0} and σ′ ∈ Sub(Σ, X, V_{0}, V′) so that (Σ, C ∪ F AX(Σ), V_{0}) ⊢_{P} σ′ G′ with σ′(x:τ) = σ(x:τ) for all x:τ ∈ V.

Proof: We have to distinguish between paramodulation steps for proving G′ and paramodulation steps for proving G − G′. Typed substitutions that are used in a paramodulation step for G − G′ are composed with the previous step for G′ (as in the proof of lifting-lemma 6.7). If the first paramodulation step is a step for G − G′, then we apply lifting-lemma 6.7. Thus all paramodulation steps for G − G′ can be eliminated and we obtain a paramodulation for G′.

Now we are able to prove the completeness of paramodulation.

Theorem 6.10 (Completeness of paramodulation) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} be finite and G be a (Σ, X, V)-goal. If σ ∈ Sub(Σ, X, V, V′) is a typed substitution with (Σ, C, V′) ⊧ σ(G), then there exist a set V_{0} ⊆ V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V′) with (Σ, C ∪ F AX(Σ), V_{0}) ⊢_{P} σ_{0} G and σ_{0}(G) = σ(G).

Proof: We assume that tvar(G) ⊆ tvar(V) and σ(α) = α for all α ∈ X−tvar(V) (otherwise we choose an appropriately extended set V and σ). By theorem 5.11 (completeness of resolution), there exist V_{0} ⊆ V ar_{Σ,X} and σ_{1} ∈ Sub(Σ, X, V_{0}, V′) with (Σ, C ∪ EAX(Σ), V_{0}) ⊢_{R} σ_{1} G and σ_{1}(G) = σ(G). W.l.o.g. we assume that V_{0} is finite and σ_{1}(α) = α for all α ∈ X − tvar(V_{0}). Let

Ce := {v ≡ w ← G′ | v ≡ w ← G′ ∈ C} ∪ (EAX(Σ) − {x:α ≡ x:α ←})

be the set of conditional equations except the reflexivity axiom. First we show that resolution steps with conditional equations can be simulated by paramodulation, i.e., we prove the following proposition:

(*) Let V_{0} ⊆ V ar_{Σ,X} be finite, σ_{0} ∈ Sub(Σ, X, V_{0}, V_{1}), G_{1} be a (Σ, X, V_{1})-goal and the (Σ, X, V_{0})-clause L_{0} ← G_{0} be a variant of a clause from Ce. If (Σ, C, V_{1}) ⊢_{P} σ_{1} G_{1} ∪ σ_{0}(G_{0}) for a σ_{1} ∈ Sub(Σ, X, V_{1}, V′_{1}), then there exists V_{2} ⊆ V ar_{Σ,X} with V_{1} ⊆ V_{2} and (Σ, C, V_{2}) ⊢_{P} σ_{2} G_{1} ∪ σ_{0}(L_{0}) with σ_{2}|_{V_{1}} = σ_{1}|_{V_{1}}.

Let (Σ, C, V_{1}) ⊢_{P} σ_{1} G_{1} ∪ σ_{0}(G_{0}). By lemma 6.9, there exists V_{2} ⊆ V ar_{Σ,X} with V_{1} ⊆ V_{2}, and there are paramodulations (Σ, C ∪F AX(Σ), V_{2}) ⊢_{P} σ_{2} G_{1} and (Σ, C ∪F AX(Σ), V_{2}) ⊢_{P} σ_{2} σ_{0}(G_{0}) with σ_{2} ∈ Sub(Σ, X, V_{2}, V′_{1}) and σ_{2}|_{V_{1}} = σ_{1}|_{V_{1}}. We distinguish the following cases for the rule L_{0} ← G_{0}:

1. L_{0} ← G_{0} is a variant of the symmetry axiom, i.e., L_{0} = x:α ≡ y:α and G_{0} = {y:α ≡ x:α}. Since σ_{0}(G_{0}) can be derived to the empty goal by paramodulation and the only way to eliminate equations is the unification rule, we can apply the same paramodulation steps to σ_{0}(L_{0}). Hence there is a paramodulation

(Σ, C, V_{2}) ⊢_{P} σ_{2} G_{1} ∪ σ_{0}(L_{0})

2. L_{0} ← G_{0} is a variant of the transitivity axiom, i.e., L_{0} = x:α ≡ z:α and G_{0} = {x:α ≡ y:α, y:α ≡ z:α}. Since σ_{0}(G_{0}) can be derived to the empty goal by paramodulation and the only way to eliminate equations is the unification rule, there is a paramodulation from σ_{0}(G_{0}) to {t_{0}:τ ≡ t_{1}:τ, t_{2}:τ ≡ t_{3}:τ} with computed substitution ϕ_{1}, and there exists a typed substitution ϕ_{2} with ϕ_{2} ∘ ϕ_{1} = σ_{2} that unifies t_{0}:τ with t_{1}:τ and t_{2}:τ with t_{3}:τ. Since equations can be applied in both directions in the paramodulation rule and by lemma 6.8, there is a paramodulation from σ_{1}(σ_{0}(L_{0})) via {ϕ_{2}(t_{0}:τ) ≡ ϕ_{2}(t_{3}:τ)}, which is identical to {ϕ_{2}(t_{1}:τ) ≡ ϕ_{2}(t_{2}:τ)}, to {σ_{1}(σ_{0}(y:α)) ≡ σ_{1}(σ_{0}(y:α))} and to the empty goal by one application of the unification rule. Since the computed answer of the last paramodulation is the identity on V′_{1}, the proposition is true by lifting lemma 6.7.

3. L_{0} ← G_{0} is a variant of a congruence axiom. This case can be shown analogously to the second case.

4. L_{0} ← G_{0} ∈ Ce − EAX(Σ), i.e., L_{0} = v ≡ w. Hence we have a paramodulation

(Σ, C, V_{2}) G_{1} ∪ σ_{0}(L_{0}) ⊢_{P} ϕ_{1} ⋯ ⊢_{P} ϕ_{k} {σ_{1}(σ_{0}(v ≡ w))}

with σ_{2} = ϕ_{k} ∘ ⋯ ∘ ϕ_{1}. By an application of the paramodulation rule with (a variant of) the clause v ≡ w ← G_{0}, we obtain

{σ_{1}(σ_{0}(w ≡ w))} ∪ σ_{1}(σ_{0}(G_{0})) ⊢_{P} id_{X,V′_{1}} σ_{1}(σ_{0}(G_{0}))

where the last step is an application of the unification rule. As mentioned above, there is a paramodulation for σ_{0}(G_{0}) with P-computed answer σ_{2}, which is identical to σ_{1} on V_{1}. By lemma 6.8, there is a paramodulation for σ_{1}(σ_{0}(G_{0})).

Hence proposition (*) is true. Now we prove the completeness of paramodulation by proving that each resolution may be simulated by a paramodulation with the same answer. We proceed by induction on the length of resolutions. Let

(Σ, C ∪ EAX(Σ), V_{0}) G ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{n} ∅

be a resolution for G with σ_{n} ∘ ⋯ ∘ σ_{1} = σ ∈ Sub(Σ, X, V_{0}, V′). If there are only applications of clauses from C − Ce in this resolution, then this is also a paramodulation for G. Otherwise, let

(Σ, C ∪ EAX(Σ), V_{0}) G ⊢_{R} σ_{1} G_{1} ⊢_{R} σ_{2} G_{2} ⊢_{R} ⋯ ⊢_{R} σ_{k} G_{k}  (1)

be a resolution where only clauses from C − Ce are used and v ≡ w ← G′ be the clause used in the next resolution step, i.e., G_{k} = G′′ ∪ {L′′}, G_{k+1} = σ_{k+1}(G′′ ∪ G′) and σ_{k+1}(L′′) = σ_{k+1}(v ≡ w). Then

(Σ, C ∪ EAX(Σ), V_{k+1}) G_{k+1} ⊢_{R} σ_{k+2} ⋯ ⊢_{R} σ_{n} ∅

is a shorter resolution, where σ_{k+1} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V_{k+1}). By induction hypothesis, there exist W_{1} ⊆ V ar_{Σ,X} and a paramodulation

(Σ, C ∪ F AX(Σ), W_{1}) ⊢_{P} ϕ G_{k+1}

with ϕ ∈ Sub(Σ, X, W_{1}, V′) and ϕ|_{T_{Σ}(X′,V_{k+1})} = σ_{n} ∘ ⋯ ∘ σ_{k+2}|_{T_{Σ}(X′,V_{k+1})}, where X′ = tvar(V_{k+1}). W.l.o.g. W_{1} is finite. By the above proposition (*), there exist W_{2} ⊆ V ar_{Σ,X} with W_{1} ⊆ W_{2} and ϕ′ with ϕ′|_{W_{1}} = ϕ|_{W_{1}} so that

(Σ, C ∪ F AX(Σ), W_{2}) ⊢_{P} ϕ′ σ_{k+1}(G′′ ∪ {v ≡ w})

Since σ_{k+1}(v ≡ w) = σ_{k+1}(L′′),

(Σ, C ∪ F AX(Σ), W_{2}) ⊢_{P} ϕ′ σ_{k+1}(G_{k})

Now we apply lifting lemma 6.7 and obtain a set W_{3} ⊆ V ar_{Σ,X} and a typed substitution σ′_{k+1} ∈ Sub(Σ, X, W_{3}, V′) so that

(Σ, C ∪ F AX(Σ), W_{3}) ⊢_{P} σ′_{k+1} G_{k}

with ϕ′ ∘ σ_{k+1} = σ′_{k+1}|_{T_{Σ}(X′′,W_{3})} and X′′ = tvar(W_{3}). If we extend the typed substitution σ_{k} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V_{k}) to a typed substitution σ_{k} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V_{k} ∪ W_{3}), we can combine the paramodulation for G_{k} with paramodulation (1) and we obtain a paramodulation

(Σ, C ∪ F AX(Σ), V_{0}) ⊢_{P} σ_{0} G

with σ_{0} = σ′_{k+1} ∘ σ_{k} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V′). Therefore σ_{0} = σ_{n} ∘ ⋯ ∘ σ_{1}|_{T_{Σ}(X′,V)} with X′ = tvar(V).

6.2 Paramodulation with most general unifiers

In this section we want to show that paramodulation with most general unifiers is also a complete proof method. Analogous to resolution, we need an mgu-lemma for paramodulation. The proof of this mgu-lemma is more difficult than the proof of the mgu-lemma for resolution, because we need also the functional-reflexive axioms if we use most general unifiers instead of unifiers.

Lemma 6.11 (mgu-lemma for paramodulation) Let (Σ, C) be a polymorphic specification, V ⊆_{U} V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there exists a paramodulation of the form

(Σ, C, V) G ⊢_{P} σ_{1} G_{1} ⊢_{P} σ_{2} G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} ∅

for G, then there exists a paramodulation of the form

(Σ, C ∪ F AX(Σ), V) G ⊢_{P} σ′_{1} G′_{1} ⊢_{P} σ′_{2} G′_{2} ⊢_{P} ⋯ ⊢_{P} σ′_{m} ∅ (m ≥ n)

where each σ′_{i} is a most general unifier and σ′_{m} ∘ ⋯ ∘ σ′_{1} ∈ Sub(Σ, X, V, V_{1}). Furthermore, there exists a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V_{2}) with ϕ ∘ σ′_{m} ∘ ⋯ ∘ σ′_{1} = σ_{n} ∘ ⋯ ∘ σ_{1}.

Proof: By induction on the length n of the paramodulation: Let CF := C ∪ F AX(Σ). n = 1: Then (Σ, C, V) G ⊢_{P} σ_{1} ∅.

a) The unification rule is applied in the paramodulation step: Then G = {v ≡ w} and σ_{1} is a unifier for v and w. By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V, V_{1}) for v and w and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V_{2}) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V) G ⊢_{P} σ′_{1} ∅

is a paramodulation for G. b) The restricted resolution rule is applied in the paramodulation step: Then there exists a

variant L ← of a clause from C with σ_{1}(G) = σ_{1}(L) and pred(L) ≠ ‘≡’. By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V, V_{1}) for G and L and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V_{2}) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V) G ⊢_{P} σ′_{1} ∅

is a paramodulation for G.

n > 0: Then there is a paramodulation of the form

(Σ, C, V) G ⊢_{P} σ_{1} G_{1} ⊢_{P} σ_{2} G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} ∅

First we show: There exist σ′_{1} ∈ Sub(Σ, X, V, V_{1}) and ϕ ∈ Sub(Σ, X, V_{1}, V′_{1}) with ϕ ∘ σ′_{1} = σ_{1} and (Σ, C, V) G ⊢_{P} σ′_{1} G′_{1} where σ′_{1} is a most general unifier and ϕ(G′_{1}) = G_{1}.

a) The unification rule is applied in the first paramodulation step: Then G = G_{0} ∪{v ≡ w} and σ_{1} is a unifier for v and w. By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V, V_{1}) for v and w and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′_{1}) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V) G ⊢_{P} σ′_{1} σ′_{1}(G_{0})

is a paramodulation step and ϕ(σ′_{1}(G_{0})) = σ_{1}(G_{0}) = G_{1}.

b) The restricted resolution rule is applied in the first paramodulation step: Then G = G_{0} ∪ {L_{0}} and there exists a variant L′ ← G′ of a clause from C with pred(L′) ≠ ‘≡’, σ_{1}(L_{0}) = σ_{1}(L′) and G_{1} = σ_{1}(G_{0}) ∪ σ_{1}(G′). By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V, V_{1}) for L_{0} and L′ and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′_{1}) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V) G ⊢_{P} σ′_{1} σ′_{1}(G_{0} ∪ G′)

is a paramodulation step and ϕ(σ′_{1}(G_{0} ∪ G′)) = σ_{1}(G_{0} ∪ G′) = G_{1}.

c) The paramodulation rule is applied in the first paramodulation step: Then G = G_{0}∪{L_{0}} and there exists a position π ∈ O(L_{0}) and a variant v ≡ w ← G′ (or w ≡ v ← G′) of a clause from C with σ_{1}(L_{0}[π]) = σ_{1}(v) and G_{1} = σ_{1}(G_{0}) ∪ {σ_{1}(L_{0})[π ← σ_{1}(w)]} ∪ σ_{1}(G′). By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V, V_{1}) for L_{0}[π] and v and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′_{1}) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V) G ⊢_{P} σ′_{1} G′_{1}

with G′_{1} = σ′_{1}(G_{0})∪{σ′_{1}(L_{0})[π ← σ′_{1}(w)]}∪σ_{1}(G′) is a paramodulation step and ϕ(G′_{1}) = σ_{1}(G_{0}) ∪ {σ_{1}(L_{0})[π ← σ_{1}(w)]} ∪ σ_{1}(G′) = G_{1}.

Note that V_{1} ⊆_{U} V ar_{Σ,X} because V ⊆_{U} V ar_{Σ,X} and σ′_{1} is a most general unifier. Next we distinguish the kind of rule applied in the second paramodulation step:

a) The unification rule is applied: Then G_{1} = G_{R} ∪ {v ≡ w} and σ_{2} is a unifier for v and w. Hence G′_{1} = G′_{R} ∪ {v′ ≡ w′} with ϕ(G′_{R}) = G_{R}, ϕ(v′) = v and ϕ(w′) = w. σ_{2} ∘ ϕ is a unifier for v′ and w′, i.e., (Σ, C, V_{1}) G′_{1} ⊢_{P} σ_{2} ∘ ϕ G_{2} is a paramodulation step. Therefore

(Σ, C, V_{1}) G′_{1} ⊢_{P} σ_{2} ∘ ϕ G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} ∅

is a paramodulation for G′_{1} of length n − 1. By induction hypothesis, there exists a paramodulation

(Σ, CF, V_{1}) G′_{1} ⊢_{P} σ′_{2} G′_{2} ⊢_{P} ⋯ ⊢_{P} σ′_{m} ∅ (m ≥ n)

where each σ′_{i} is a most general unifier (2 ≤ i ≤ m) and σ′_{m} ∘ ⋯ ∘ σ′_{2} ∈ Sub(Σ, X, V_{1}, V_{2}). Furthermore, there exists a typed substitution ρ ∈ Sub(Σ, X, V_{2}, V_{3}) with ρ∘σ′_{m}∘⋯∘σ′_{2} = σ_{n} ∘ ⋯ ∘ σ_{2} ∘ ϕ. Altogether, there is a paramodulation

(Σ, CF, V) G ⊢_{P} σ′_{1} G′_{1} ⊢_{P} σ′_{2} G′_{2} ⊢_{P} ⋯ ⊢_{P} σ′_{m} ∅ (m ≥ n)

where each σ′_{i} is a most general unifier, σ′_{m} ∘ ⋯ ∘ σ′_{1} ∈ Sub(Σ, X, V, V_{2}), ρ ∈ Sub(Σ, X, V_{2}, V_{3}), and ρ ∘ σ′_{m} ∘ ⋯ ∘ σ′_{1} = σ_{n} ∘ ⋯ ∘ σ_{2} ∘ ϕ ∘ σ′_{1} = σ_{n} ∘ ⋯ ∘ σ_{1}.

b) The restricted resolution rule is applied: Then G_{1} = G_{R} ∪{L} and there exists a variant L′′ ← G′′ of a clause from C with pred(L′′) ≠ ‘≡’ and σ_{2} is a unifier for L and L′′. Hence G′_{1} = G′_{R} ∪ {L′} with ϕ(G′_{R}) = G_{R} and ϕ(L′) = L. We assume that ϕ does not alter the type variables and typed variables from L′′ ← G′′ (otherwise we choose a variant). Therefore σ_{2}∘ϕ is a unifier for L and L′′ and ϕ(G′′) = G′′, i.e., (Σ, C, V_{1}) G′_{1} ⊢_{P} σ_{2}∘ϕ G_{2} is a paramodulation step. Thus

(Σ, C, V_{1}) G′_{1} ⊢_{P} σ_{2} ∘ ϕ G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} ∅

is a paramodulation for G′_{1} of length n − 1. Now we proceed as in case a).

c) The paramodulation rule is applied: Then G_{1} = G_{R} ∪ {L} and there exists a position π ∈ O(L) and a variant v ≡ w ← G′′ (or w ≡ v ← G′′) of a clause from C so that σ_{2} is a unifier for L[π] and v and G_{2} = σ_{2}(G_{R}) ∪ {σ_{2}(L)[π ← σ_{2}(w)]} ∪ σ_{2}(G′′). Hence G′_{1} = G′_{R} ∪ {L′} with ϕ(G′_{R}) = G_{R} and ϕ(L′) = L. We assume that ϕ does not alter the type variables and typed variables from v ≡ w ← G′′ (or w ≡ v ← G′′), otherwise we choose a variant.

1. π ∈ O(L′): Then ϕ(L′[π]) = L[π] and therefore σ_{2} ∘ ϕ is a unifier for L′[π] and v. (Σ, C, V_{1}) G′_{1} ⊢_{P} σ_{2} ∘ ϕ G_{2} is a paramodulation step since σ_{2}(ϕ(L′))[π ← σ_{2}(ϕ(w))] = σ_{2}(L)[π ← σ_{2}(w)] and ϕ(G′′) = G′′. Hence

(Σ, C, V_{1}) G′_{1} ⊢_{P} σ_{2} ∘ ϕ G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} ∅

is a paramodulation for G′_{1} of length n − 1. Now we proceed as in case a).

2. π ∉ O(L′): Then π = j_{1} ⋄ ⋯ ⋄ j_{k} ⋄ Λ and there exists 1 ≤ l < k with π_{l} := j_{1} ⋄ ⋯ ⋄ j_{l} ⋄ Λ ∈ O(L′) and L′[π_{l}] ∈ V_{1}. Now we apply paramodulation rules successively at positions π_{l}, π_{l+1}, …, π_{k}, where π_{i} := j_{1}⋄⋯⋄j_{i}⋄Λ, with functional-reflexive axioms and most general unifiers: At position π_{i} we use a variant of the functional-reflexive axiom

f(x_{1}:τ_{1}, …, x_{n}:τ_{n}):τ ≡ f(x_{1}:τ_{1}, …, x_{n}:τ_{n}):τ ←

with new type variables and new typed variables, if L[π_{i}] = f(⋯):.... For this purpose we must extend the variable set V_{1} to the variables occurring in the new variants of the functional-reflexive axioms, but subsequent unifiers map the new variables into terms with ‘old’ variables. Thus we have to extend the mgu σ′_{1} in the first step to an mgu σ′_{1} ∈ Sub(Σ, X, V, W_{1}), where W_{1} is the union of V_{1} and the new typed variables. By these paramodulation steps, the Σ-atom L′ will be transformed into a new Σatom that contains the position π and differs from L by a substitution on the (type) variables. Hence we proceed as in case 1.

The following example shows the necessity of functional-reflexive axioms in the mgu-lemma: We assume two basic types τ_{1} and τ_{2}. There are the following declarations of constants, functions and predicates:

func a,b: → τ_{1} func f: τ_{1} → τ_{2} pred p: τ_{2}, τ_{2} pred q:

(the predicate q has no arguments). The specification contains the clauses

a:τ_{1} ≡ b:τ_{1} ← p(f(a:τ_{1}):τ_{2},f(b:τ_{1}):τ_{2}) ←

q ← p(x:τ_{2},x:τ_{2})

Then there is the following paramodulation for q:

q

⊢_{P} with unifier σ = {x:τ_{2} / f(a:τ_{1}):τ_{2}}

p(f(a:τ_{1}):τ_{2},f(a:τ_{1}):τ_{2})

⊢_{P} paramodulation with the first clause

p(f(a:τ_{1}):τ_{2},f(b:τ_{1}):τ_{2})

⊢_{P} resolution with the second clause ∅

But there is no most general paramodulation for q without using the functional-reflexive axioms:

q

⊢_{GP}

p(x:τ_{2},x:τ_{2})

A further paramodulation step is not applicable to the last atom. Now we define the notion of most general paramodulation as paramodulation with most general unifiers where in each step the (type) variables in the goal and the applied clause are disjoint:

Definition 6.12 (Most general paramodulation) Let (Σ, C) be a polymorphic specification and V ⊆_{U} V ar_{Σ,X}.

a) 1. Paramodulation rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom, π ∈ O(L) and the (Σ, X, V)-clause v ≡ w ← G′ or w ≡ v ← G′ be a variant of a clause from C with tvar(G∪{L})∩tvar(v ≡ w ← G′) = ∅ and var(G∪{L})∩var(v ≡ w ← G′) = ∅. If there exists a most general unifier σ ∈ Sub(Σ, X, V, V′) for L[π] and v, then σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′) is said to be derived by most general paramodulation from G ∪ {L} relative to σ and v ≡ w ← G′ or w ≡ v ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{GP} σ σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′)

2. Restricted resolution rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom and the (Σ, X, V)-clause L′ ← G′ be a variant of a clause from C with pred(L′) ≠ ‘≡’ and tvar(G ∪ {L}) ∩ tvar(L′ ← G′) = ∅ and var(G ∪ {L}) ∩ var(L′ ← G′) = ∅. If there exists a most general unifier σ ∈ Sub(Σ, X, V, V′) for L and L′, then σ(G)∪σ(G′) is said to be derived by restricted most general resolution from G ∪ {L} relative to σ and L′ ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{GP} σ σ(G) ∪ σ(G′)

3. Unification rule: Let G be a (Σ, X, V)-goal, v ≡ w be a (Σ, X, V)-equation and σ ∈ Sub(Σ, X, V, V′) be a most general unifier for v and w. Then σ(G) is said to be derived by most general unification from G ∪ {v ≡ w} relative to σ. Notation:

(Σ, C, V) G ∪ {v ≡ w} ⊢_{GP} σ σ(G)

b) Let G be a (Σ, X, V)-goal. A most general (Σ, C, V)-paramodulation of G is a sequence of the form

(Σ, C, V_{0}) G_{0} ⊢_{GP} σ_{1} G_{1} ⊢_{GP} σ_{2} G_{2} ⊢_{GP} ⋯ ⊢_{GP} σ_{n} G_{n}

where G_{0} = G, V_{0} = V and (Σ, C, V_{i}) G_{i} ⊢_{GP} σ_{i+1} G_{i+1} with σ_{i+1} ∈ Sub(Σ, X, V_{i}, V_{i+1}) for i = 0, 1, 2, …, n − 1. The most general (Σ, C, V)-paramodulation is called successful if G_{n} = ∅. In this case n is called the length of the most general (Σ, C, V)-paramodulation, and σ := σ_{n} ∘ ⋯ ∘ σ_{1} is called a GP-computed answer. Notation:

(Σ, C, V) ⊢_{GP} σ G

□

Most general paramodulation is a special case of paramodulation and hence we get the following result:

Theorem 6.13 (Soundness of most general paramodulation) Let (Σ, C) be a polymorphic specification, V ⊆_{U} V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful paramodulation (Σ, C, V) ⊢_{GP} σ G with GP-computed answer σ ∈ Sub(Σ, X, V, V′), then (Σ, C, V′) ⊧ σ(G).

The completeness of most general paramodulation follows by completeness of paramodulation and mgu-lemma 6.11:

Theorem 6.14 (Completeness of most general paramodulation) Let (Σ, C) be a polymorphic specification, V ⊆_{U} V ar_{Σ,X} be finite and G be a (Σ, X, V)-goal. If σ ∈ Sub(Σ, X, V, V′) is a typed substitution with (Σ, C, V′) ⊧ σ(G), then there exist a set V_{0} ⊆_{U} V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V_{1}) with (Σ, C ∪ F AX(Σ), V_{0}) ⊢_{GP} σ_{0} G and there is a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′) with ϕ(σ_{0}(G)) = σ(G).

Proof: By completeness theorem 6.10, there exist V_{0} ⊆ V ar_{Σ,X} and a paramodulation of the form

(Σ, C ∪ F AX(Σ), V_{0}) G ⊢_{P} σ_{1} G_{1} ⊢_{P} σ_{2} G_{2} ⋯ ⊢_{P} σ_{n} ∅

with σ_{n} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V′) and σ_{n} ∘ ⋯ ∘ σ_{1}(G) = σ(G). If V_{0} ⊆_{U} V ar_{Σ,X} is not true, we construct a corresponding set with that property as in the proof of theorem 5.15. By mgu-lemma 6.11, we obtain a paramodulation of the form

(Σ, C ∪ F AX(Σ), V_{0}) G ⊢_{P} σ′_{1} G′_{1} ⊢_{P} σ′_{2} G′_{2} ⊢_{P} ⋯ ⊢_{P} σ′_{m} ∅ (m ≥ n)

where each σ′_{i} is a most general unifier and σ′_{m} ∘ ⋯ ∘ σ′_{1} ∈ Sub(Σ, X, V_{0}, V_{1}). Furthermore, there exists a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′) with ϕ ∘ σ′_{m} ∘ ⋯ ∘ σ′_{1} = σ_{n} ∘ ⋯ ∘ σ_{1}. We assume that tvar(G′_{i}) ∩ tvar(c_{i}) = ∅ and var(G′_{i}) ∩ var(c_{i}) = ∅ where c_{i} is the clause used in the i-th paramodulation step of the latter paramodulation. If this is not the case, we proceed as in the proof of theorem 5.15.

Now we have proved that the paramodulation calculus with polymorphic unification is sound and complete for the theory of Horn clause specifications with polymorphic types if we add the functional-reflexive axioms to the set of clauses. Although [Robinson/Wos 69] have shown that paramodulation proofs are more efficient than proofs by resolution, paramodulation is far away from being an efficient proof procedure for Horn clause logic with equality. This is due to the fact that

• in the paramodulation rule equations can be used in both directions, and

• it is possible to replace only goal variables by one side of an equation which leads to infinite and huge search spaces.

To improve these drawbacks of the paramodulation rule we will define the narrowing procedure. For completeness results of narrowing we need some results about rewriting systems. Therefore we define in the next chapter the notions of reduction and conditional rewriting for polymorphic Horn clause specifications.

Reduction and conditional rewriting

This chapter defines the notions that are necessary for the narrowing calculus. The notion of reduction is the basis for the definition of the Church-Rosser property. The Church-Rosser property is a requirement for the completeness of narrowing. In the area of term rewriting confluence criteria are used to prove Church-Rosser properties [Knuth/Bendix 70]. Much research has been carried out in order to prove confluence of conditional term rewriting systems (see remarks at the end of this chapter). Hence we define the notion of conditional rewriting in our context and show that confluence of the conditional term rewriting relation implies the Church-Rosser property of the polymorphic specification.

7.1 Reductions for polymorphic specifications

Reduction is a method for proving validity of goals. There are two differences between paramodulation and reduction: Equations are only applied in left-to-right order and the substitution in each reduction step is only applied to the clause and not to the goal. Therefore reduction is a method for goal proving and not for goal solving.

Definition 7.1 (Reduction) Let C be a set of Σ-clauses and V ⊆ V ar_{Σ,X}.

a) 1. Reduction rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom, π ∈ O(L) be an occurrence in L and the (Σ, X, V)-clause v ≡ w ← G′ be an instance of a clause from C. If L[π] = v, then G∪{L[π ← w]}∪G′ is said to be derived by reduction from G ∪ {L} relative to v ≡ w ← G′. Notation:

(Σ, C, V) G ∪ {L} → G ∪ {L[π ← w]} ∪ G′

2. Deduction rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom and the (Σ, X, V)-clause L′ ← G′ be an instance of a clause from C with pred(L′) ≠ ‘≡’. If L = L′, then G ∪ G′ is said to be derived by deduction from G ∪ {L} relative to L′ ← G′. Notation:

(Σ, C, V) G ∪ {L} → G ∪ G′

3. Reflexivity rule: Let G be a (Σ, X, V)-goal, t:τ ≡ t:τ be a (Σ, X, V)-equation. Then G is said to be derived by reflexivity from G ∪ {t:τ ≡ t:τ}. Notation:

(Σ, C, V) G ∪ {t:τ ≡ t:τ} → G

b) Let G be a (Σ, X, V)-goal. A (Σ, C, V)-reduction of G is a sequence of the form

(Σ, C, V) G_{0} → G_{1} → G_{2} → ⋯ → G_{n}

where G_{0} = G and (Σ, C, V) G_{i} → G_{i+1} for i = 0, 1, 2, …, n − 1. The (Σ, C, V)- reduction is called successful if G_{n} = ∅. In this case n is called the length of the (Σ, C, V)-reduction. Notation:

(Σ, C, V) → G

□

Reduction is a special case of paramodulation. Therefore soundness of reduction follows from soundness of paramodulation and completeness of (undirected) reduction can be proved by using completeness of paramodulation (see below). If there are only unconditional equations in the specification, reductions are similar to demodulations which are introduced by [Wos et al. 67] in the context of theorem proving. Thus our notion of reduction is a generalization of demodulation to conditional equations. Since we are mainly interested in functional and logic programming and conditional term rewriting, we use the more customary expression reduction [Barendregt 81] [Huet/Oppen 80]. Our reductions are also related to proofs of equalities by conditional term rewriting. The basic difference between conditional term rewriting in the sense of [Kaplan 84a] and our notion of reduction is the treatment of conditional equations where the conditions are not provable: In conditional term rewriting, conditional equations can only be applied if the conditions are provable. In our reductions, conditional equations can always be applied, but we add the conditions to the goal. Our notion of reduction, which is motivated by the reduction calculus of [Padawitz 88], is more related to the contextual rewriting of [Zhang/Remy 85], but they require that the conditions are “primitive” with respect to the specification. Therefore they have a separation between rewriting and proofs for conditions. Hence our notion of reduction is related to, but more general than contextual rewriting because we treat also predicates by the deduction rule and we have no separation between the theory of equations and the theory of conditions. Reduction is paramodulation restricted to directed applications of equations and substituting only variables in clauses. Hence the proof of soundness of reduction is based on the soundness of paramodulation:

Theorem 7.2 (Soundness of reduction) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful reduction (Σ, C, V) → G, then (Σ, C, V) ⊧ G.

Proof: Let

(Σ, C, V) G → G_{1} → G_{2} → ⋯ → ∅

be a reduction for G. We show that for each reduction step (Σ, C, V) G_{i} → G_{i+1} there exists a set V′ ⊇ V with new additional variables so that (Σ, C, V′) G_{i} ⊢_{P} σ_{i+1} G_{i+1} is a paramodulation step with σ_{i+1} ∈ Sub(Σ, X, V′, V) and σ_{i+1}(x:τ) = x:τ for all x:τ ∈ V. By theorem 6.3 (soundness of paramodulation), this implies the soundness of reduction. Let (Σ, C, V) G_{i} → G_{i+1} be a reduction step. We distinguish the following cases for the applied rule:

1. Reduction rule: Then G_{i} = G′′ ∪ {L′′}, π ∈ O(L′′), v = w ← G′ is a clause from C, σ is a typed substitution with L′′[π] = σ(v) and G_{i+1} = G′′ ∪ {L′′[π ← σ(w)]} ∪ σ(G′). We assume that the type variables and typed variables in V and G_{i} are disjoint from those in v ≡ w ← G′, otherwise we choose an appropriate variant of v ≡ w ← G′. Let V′ := V ∪ var(v ≡ w ← G′) and σ_{i+1} be the combination of the identity typed substitution on V and σ on type variables and typed variables from v ≡ w ← G′. Then

(Σ, C, V′) G_{i} ⊢_{P} σ_{i+1} G_{i+1}

is a paramodulation step and σ_{i+1} ∈ Sub(Σ, X, V′, V) since typed variables from V′ − V are mapped into (Σ, X, V)-terms.

2. Deduction and reflexivity rule: Analogous to the first case.

Conversely we can simulate paramodulation by reduction and get the following completeness result for undirected reduction:

Theorem 7.3 (Completeness of undirected reduction) Let C be a set of Σ-clauses and

C^{↔} := C ∪ {w ≡ v ← G′ | v ≡ w ← G′ ∈ C}.

If G is a Σ-goal with (Σ, C, V) ⊧ G, then (Σ, C^{↔}, V) → G.

Proof: By theorem 6.10 (completeness of paramodulation), there exist a set V_{0} ⊆ V ar_{Σ,X} and a paramodulation

(Σ, CF, V_{0}) G ⊢_{P} σ_{1} G_{1} ⊢_{P} σ_{2} G_{2} ⊢_{P} ⋯ ⊢_{P} σ_{n} ∅

where CF = C ∪ F AX(Σ), with σ_{n} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{0}, V) and σ_{n} ∘ ⋯ ∘ σ_{1}(G) = G. Let

CF^{↔} := CF ∪ {w ≡ v ← G′ | v ≡ w ← G′ ∈ CF }. We prove that

(Σ, CF^{↔} , V) σ_{n} ∘ ⋯ ∘ σ_{1}(G) → σ_{n} ∘ ⋯ ∘ σ_{2}(G_{1}) → σ_{n} ∘ ⋯ ∘ σ_{3}(G_{2}) → ⋯ → ∅

is a reduction for G. Let

(Σ, CF, V_{i}) G_{i} ⊢_{P} σ_{i+1} G_{i+1}

be a paramodulation step. We show that

(Σ, CF^{↔} , V) σ_{n} ∘ ⋯ ∘ σ_{i+1}(G_{i}) → σ_{n} ∘ ⋯ ∘ σ_{i+2}(G_{i+1})

is a reduction step.

1. The paramodulation rule is applied in the paramodulation step: Then G_{i} = G′′ ∪ {L′′}, π ∈ O(L′′), v ≡ w ← G′ (or w ≡ v ← G′) is a variant of a clause from CF, σ_{i+1} is a typed substitution with σ_{i+1}(L′′[π]) = σ_{i+1}(v) and

G_{i+1} = σ_{i+1}(G′′) ∪ {σ_{i+1}(L′′)[π ← σ_{i+1}(w)]} ∪ σ_{i+1}(G′).

Hence π ∈ O(σ_{n} ∘ ⋯ ∘ σ_{i+1}(L′′)), σ_{n} ∘ ⋯ ∘ σ_{i+1}(v ≡ w ← G′) is an instance of a clause

from CF^{↔} and σ_{n} ∘ ⋯ ∘ σ_{i+1}(L′′[π]) = σ_{n} ∘ ⋯ ∘ σ_{i+1}(v). Thus

(Σ, CF^{↔} , V) σ_{n} ∘ ⋯ ∘ σ_{i+1}(G_{i}) → σ_{n} ∘ ⋯ ∘ σ_{i+2}(G_{i+1})

is a reduction step.

2. The restricted resolution rule is applied in the paramodulation step: Then G_{i} = G′′ ∪ {L′′}, L′ ← G′ is a variant of a clause from CF with pred(L′) ≠ ‘≡’, σ_{i+1} is a typed substitution with σ_{i+1}(L′′) = σ_{i+1}(L′) and G_{i+1} = σ_{i+1}(G′′ ∪ G′). Hence σ_{n} ∘ ⋯ ∘ σ_{i+1}(L′ ← G′) is an instance of a clause from CF and σ_{n} ∘ ⋯ ∘ σ_{i+1}(L′′) = σ_{n} ∘ ⋯ ∘ σ_{i+1}(L′). Thus

(Σ, CF^{↔} , V) σ_{n} ∘ ⋯ ∘ σ_{i+1}(G_{i}) → σ_{n} ∘ ⋯ ∘ σ_{i+2}(G_{i+1})

is an application of the deduction rule.

3. The unification rule is applied in the paramodulation step: Then G_{i} = G′′ ∪ {v ≡ w}, σ_{i+1}(v) = σ_{i+1}(w) and G_{i+1} = σ_{i+1}(G′′). Hence σ_{n} ∘ ⋯ ∘ σ_{i+1}(v) = σ_{n} ∘ ⋯ ∘ σ_{i+1}(w) and

(Σ, CF^{↔} , V) σ_{n} ∘ ⋯ ∘ σ_{i+1}(G_{i}) → σ_{n} ∘ ⋯ ∘ σ_{i+2}(G_{i+1})

is an application of the reflexivity rule.

Therefore there exists a reduction for G with clauses from CF^{↔}. If an instance of a clause from F AX(Σ) is used in a reduction step, then the goal is left unchanged. Hence we can eliminate reduction steps with clauses from F AX(Σ), and we obtain (Σ, C^{↔}, V) → G.

Directed reduction is only complete if the set of Σ-clauses satisfies a Church-Rosser property:

Definition 7.4 Let C be a set of Σ-clauses and C^{↔} := C ∪ {w ≡ v ← G′ | v ≡ w ← G′ ∈ C}. C is called Church-Rosser if the following proposition holds: If V ⊆ V ar_{Σ,X} and G is a (Σ, X, V)-goal with (Σ, C^{↔}, V) → G, then (Σ, C, V) → G is also true. □

By this definition, a set of clauses is Church-Rosser if each goal that is provable with applications of equations in both directions is also provable with applications of equations in left-to-right order. In term rewriting, the Church-Rosser property of a specification is defined by: If two terms t_{1} and t_{2} are equal with respect to the specification, then there exists a term t′ so that both t_{1} and t_{2} can be rewritten into t′. This property is covered by our notion of Church-Rosser: If the Church-Rosser specification contains only conditional equations and two terms t_{1} and t_{2} are equal with respect to the specification, then t_{1} ≡ t_{2} is valid in the specification. By theorems 7.2 and 7.3 and our definition of Church-Rosser, this is equivalent to the existence of a directed reduction for t_{1} ≡ t_{2}. Since equations can only be eliminated by the reflexivity rule, t_{1} ≡ t_{2} can be reduced to an equation t′ ≡ t′. Consequently, both t_{1} and t_{2} can be rewritten into t′ in the sense of classical term rewriting. But we are more general than in the term rewriting approach because we allow the use of arbitrary predicates in conditions of equations (which will be solved by resolution) as well as the use of arbitrary functions and equalities in relational clauses. The Church-Rosser property is a requirement for the completeness of the narrowing procedure, a method for solving goals that is more efficient than paramodulation. Therefore we want to state in the next section some sufficient criteria for the Church-Rosser property.

7.2 Confluence and conditional rewriting

The first criterion that implies the Church-Rosser property is confluence of all goals (cf. [Furbach/Hölldobler/Schreiber 88]):

Definition 7.5 A set C of Σ-clauses is called goal confluent if for all Σ-goals G_{0}, G_{1} and G_{2} the following proposition is true: If G_{0} →_{Σ,C,V}^{∗} G_{1} and G_{0} →_{Σ,C,V}^{∗} G_{2}, then there exists a Σ-goal G_{3} with G_{1} →_{Σ,C,V}^{∗} G_{3} and G_{2} →_{Σ,C,V}^{∗} G_{3}, where →_{Σ,C,V}^{∗} is the reflexive and transitive closure of the relation →_{Σ,C,V} defined by: G →_{Σ,C,V} G′ iff (Σ, C, V) G → G′. □

Theorem 7.6 (Goal confluence implies Church-Rosser) Let C be a goal confluent set of Σ-clauses, V ⊆ V ar_{Σ,X} be finite and G be a (Σ, X, V)-goal with (Σ, C^{↔}, V) → G. Then (Σ, C, V) → G.

Proof: The theorem is a consequence of the following proposition:

Let v = w ← G′ be an instance of a clause from C, G_{0} be a (Σ, X, V)-goal, L_{0} be a

(Σ, X, V)-atom and π ∈ O(L_{0}) so that L_{0}[π] = w and
(Σ, C, V) → G_{0} ∪ {L_{0}[π ← v]} ∪ G′
Then there is a reduction (Σ, C, V) → G_{0} ∪ {L_{0}}.

Proof for this proposition: By definition of reduction and the assumptions,

(Σ, C, V) G_{0} ∪ {L_{0}[π ← v]} → G_{0} ∪ {L_{0}} ∪ G′

is a reduction step. Furthermore, G′ →_{Σ,C,V}^{∗} ∅. Altogether, we have the reductions

\begin{aligned}& G_{0} ∪ \{L_{0}[π ← v]\} →_{Σ,C,V}^{∗} G_{0} ∪ \{L_{0}\} \\ and & G_{0} ∪ \{L_{0}[π ← v]\} →_{Σ,C,V}^{∗} ∅ \end{aligned}

Since C is goal confluent, we obtain G_{0} ∪ {L_{0}} →_{Σ,C,V}^{∗} ∅.

Goal confluence is a sufficient criterion for the Church-Rosser property, but it is a severe restriction, as the following example shows: Example: C contains only the clauses

     max(x,y)≡y ← x≤y
     max(x,y)≡x ← x>y

(There is only one type int and therefore we omit the type annotations; ≤ and > are relations on integer numbers with the intended meaning “less than or equal to” and “greater than”.) Then there are the following reductions:

{max(3, 3) ≡ 3} →_{Σ,C,∅} {3 ≡ 3, 3 ≤ 3} →_{Σ,C,∅} {3 ≤ 3} →_{Σ,C,∅}^{∗} ∅
{max(3, 3) ≡ 3} →_{Σ,C,∅} {3 ≡ 3, 3 > 3} →_{Σ,C,∅} {3 > 3}

Hence C is not goal confluent, but the conditional equations are confluent in the sense of [Kaplan 84a], because in [Kaplan 84a] conditional equations can only be applied if the conditions are satisfied. Therefore we want to show that confluence of the conditional equations implies the Church-Rosser property of the whole specification if the clauses have a particular form. At first we define conditional rewriting in the sense of [Hussmann 85]:

Definition 7.7 (Conditional rewriting) Let C be a set of Σ-clauses. We define the following relations on Σ-terms and Σ-goals:

a) Let t_{1} and t_{2} be (Σ, X, V)-terms and G be a (Σ, X, V)-goal. t_{1} can be rewritten into t_{2} under condition G relative to C, denoted t_{1} ⇒_{Σ,C,V} t_{2} ← G, if it is provable by the following inference rules:

• t_{1} ⇒_{Σ,C,V} t_{2} ← G if t_{1} = t_{2}.

• t_{1} ⇒_{Σ,C,V} t_{2} ← G if the (Σ, X, V)-clause v ≡ w ← G is an instance of a clause from C and π ∈ O(t_{1}) so that t_{1}[π] = v and t_{2} = t_{1}[π ← w].

• t_{1} ⇒_{Σ,C,V} t_{2} ← G if t_{1} ⇒_{Σ,C,V} t_{3} ← G_{1}, t_{3} ⇒_{Σ,C,V} t_{2} ← G_{2} and G = G_{1} ∪ G_{2}.

b) Rewriting of goals:

• (Deduction) If L′ ← G′ ∈ C with pred(L′) ≠ ‘≡’ or L′ = x:α ≡ x:α and G′ = ∅, σ is a typed substitution and G ∪ {σ(L′)} ∪ σ(G′) is a (Σ, X, V)-goal, then G ∪ {σ(L′)} ⇒_{Σ,C,V} G ∪ σ(G′).

• (Rewriting) G ∪ {p(…, t_{i}:τ_{i}, …)} ⇒_{Σ,C,V} G ∪ {p(…, t′_{i}:τ_{i}, …)} if t_{i}:τ_{i} ⇒_{Σ,C,V} t′_{i}:τ_{i}.

• (Reflexivity) If G is a (Σ, X, V)-goal, then G ⇒_{Σ,C,V} G.

• (Transitivity) If G_{1}, G_{2} and G_{3} are (Σ, X, V)-goals with G_{1} ⇒_{Σ,C,V} G_{2} and G_{2} ⇒_{Σ,C,V} G_{3}, then G_{1} ⇒_{Σ,C,V} G_{3}.

c) Conditional term rewriting: t_{1} ⇒_{Σ,C,V} t_{2} if t_{1} ⇒_{Σ,C,V} t_{2} ← G and G ⇒_{Σ,C,V} ∅

□

Lemma 7.8 (Rewritings are reductions) Let C be a set of Σ-clauses and G, G′ be (Σ, X, V)-goals with G ⇒_{Σ,C,V} G′. Then there is a reduction of the form

(Σ, C, V) G → ⋯ → G′

Proof: If G ⇒_{Σ,C,V} G′, then there is a sequence

G_{1} ⇒_{Σ,C,V} G_{2} ⇒_{Σ,C,V} ⋯ ⇒_{Σ,C,V} G_{n}  (∗)

with G = G_{1}, G′ = G_{n}, and the i-th step is a deduction step with clause L′′ ← G′′ (an instance of a clause from C ∪ {x:α ≡ x:α ←}) or a rewriting step with t_{1} ⇒_{Σ,C,V} t_{2} ← G′′ and G′′ ⇒_{Σ,C,V} ∅. The derivation of t_{1} ⇒_{Σ,C,V} t_{2} ← G′′ and G′′ ⇒_{Σ,C,V} ∅ is also done in several steps. If we combine these steps with derivation (∗) we obtain a reduction from G to G′.

The converse of the last lemma is not true: If C contains only the clause

a:τ ≡ b:τ ← 1:int ≡ 2:int

then there is a reduction

(Σ, C, ∅) {a:τ ≡ b:τ} → {b:τ ≡ b:τ, 1:int ≡ 2:int} → {1:int ≡ 2:int}

but the rewriting

{a:τ ≡ b:τ} ⇒_{Σ,C,∅} {1:int ≡ 2:int}

is not valid since a:τ ⇒_{Σ,C,∅} b:τ is not true. Nevertheless, successful reductions can be simulated by rewriting:

Lemma 7.9 (Successful reductions are rewritings) Let C be a set of Σ-clauses. If V ⊆ V ar_{Σ,X} and G is a (Σ, X, V)-goal with (Σ, C, V) → G, then G ⇒_{Σ,C,V} ∅.

Proof: By induction on the length n of successful reductions: Let

(Σ, C, V) G_{0} → G_{1} → G_{2} → ⋯ → G_{n}

be a reduction with G_{n} = ∅. n = 1: If the deduction rule is applied, then G_{0} = {L} and L ← ∅ is an instance of a clause from C with pred(L) ≠ ‘≡’. Thus {L} ⇒_{Σ,C,V} ∅. If the reflexivity rule is applied, then G_{0} = {v ≡ v}. But {v ≡ v} ⇒_{Σ,C,V} ∅ is always true. n > 1: If the deduction rule is applied in the first step, then G_{0} = G′ ∪ {L′}, L′ ← G′′ is an instance of a clause from C with pred(L′) ≠ ‘≡’, and G_{1} = G′ ∪ G′′. Hence G_{0} ⇒_{Σ,C,V} G_{1}. By induction hypothesis, G_{1} ⇒_{Σ,C,V} ∅. Thus G_{0} ⇒_{Σ,C,V} ∅. If the reflexivity rule is applied in the first step, the proof is analogous. If the reduction rule is applied in the first step, then G_{0} = G′ ∪{p(…, t_{i}:τ_{i}, …)}, v ≡ w ← G′′ is an instance of a clause from C, π ∈ O(t_{i}:τ_{i}) so that t_{i}:τ_{i}[π] = v and

G_{1} = G′ ∪ {p(…, t_{i}:τ_{i}[π ← w], …)} ∪ G′′.

By definition of conditional rewriting, t_{i}:τ_{i} ⇒_{Σ,C,V} t_{i}:τ_{i}[π ← w] ← G′′. Since G′′ ⊆ G_{1}, there is a successful reduction (Σ, C, V) → G′′ with less than n steps. By induction hypothesis, G′′ ⇒_{Σ,C,V} ∅. Therefore t_{i}:τ_{i} ⇒_{Σ,C,V} t_{i}:τ_{i}[π ← w] and also G_{0} ⇒_{Σ,C,V} G′ ∪ {p(…, t_{i}:τ_{i}[π ← w], …)}. Let G′_{1} := G′ ∪ {p(…, t_{i}:τ_{i}[π ← w], …)}. Since G′_{1} ⊆ G_{1}, there is a successful reduction (Σ, C, V) → G′_{1} with less than n steps. By induction hypothesis, G′_{1} ⇒_{Σ,C,V} ∅. Altogether, we obtain G_{0} ⇒_{Σ,C,V} ∅.

Definition 7.10 (Confluence) A set C of Σ-clauses is called confluent if for all (Σ, X, V)- terms t_{0}, t_{1} and t_{2} the following proposition is true: If t_{0} ⇒_{Σ,C,V} t_{1} and t_{0} ⇒_{Σ,C,V} t_{2}, then there exists a (Σ, X, V)-term t_{3} with t_{1} ⇒_{Σ,C,V} t_{3} and t_{2} ⇒_{Σ,C,V} t_{3}. □

If C contains only conditional equations and no predicates, then this notion of confluence is equivalent to [Hussmann 85]. Confluence is less restrictive than goal confluence because it is defined on divergent terms (and not on divergent goals) and rewriting is only allowed if the conditions of a conditional equation are satisfied. We will show that this notion of confluence is sufficient for the Church-Rosser property of polymorphic Horn clause specifications. First we need two lemmas:

Lemma 7.11 Let C be a set of Σ-clauses, P C := {L ← G ∈ C | pred(L) ≠ ‘≡’} be the set of relational clauses and v ∉ V ar_{Σ,X} for all v ≡ w ← G′ ∈ C, i.e., v = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ and f does not occur in L for all L ← G ∈ P C. Then the following proposition is true: If

σ = {x_{1}:τ_{1}/t_{1}:τ_{1} , …, x_{k}:τ_{k}/t_{k}:τ_{k}} and σ′ = {x_{1}:τ_{1}/t′_{1}:τ_{1} , …, x_{k}:τ_{k}/t′_{k}:τ_{k}}

are two typed substitutions with t_{i}:τ_{i} ⇒_{Σ,C,V} t′_{i}:τ_{i} (i = 1, …, k) and G is a Σ-goal with σ(G) ⇒_{Σ,P C,V} ∅, then σ′(G) ⇒_{Σ,C,V} ∅.

Proof: Let

DF := {f | ∃f(⋯):τ ≡ w ← G′ ∈ C}

be the set of function symbols defined by conditional equations in C. Let O_{i} be a subset of the occurrences of t_{i}:τ_{i} where, for each π ∈ O_{i}, t_{i}:τ_{i}[π] = f(⋯):τ with f ∈ DF and there is no prefix of π in O_{i}. If O_{i} = {π_{1}, …, π_{m}}, then there are terms t_{i1}:τ_{i1}, …, t_{im}:τ_{im} with

t′_{i}:τ_{i} = t_{i}:τ_{i}[π_{1} ← t_{i1}:τ_{i1}] ⋯ [π_{m} ← t_{im}:τ_{im}]

since function symbols from DF occur in t_{i}:τ_{i} only in t_{i}:τ_{i}[π] for a π ∈ O_{i}. Hence we may assume for simplicity in our proof that t_{i}:τ_{i} = f(…):τ_{i} with f ∈ DF for i = 1, …, k. Since σ(G) ⇒_{Σ,P C,V} ∅, the derivation of σ(G) contains only deduction steps. We show the proposition by induction on the length n of the derivation with deduction steps. The case n = 0 is trivial. Otherwise the clause L_{1} ← G_{1} ∈ P C ∪ {x:α ≡ x:α ←} is applied in the first derivation step, i.e., there is a typed substitution ϕ with ϕ(L_{1}) = σ(L_{0}), where G = G_{0} ∪{L_{0}}. Assume that some t_{i}:τ_{i} is a subterm of σ(L_{0}) (otherwise σ(L_{0}) = σ′(L_{0})). Since the function symbol at the top of t_{i}:τ_{i} occurs on the left-hand side of some conditional equation from C and our assumption about relational clauses, there exist typed variables y:ξ ∈ var(L_{1}) so that t_{i}:τ_{i} is a subterm of ϕ(y:ξ). Let ϕ′ be the typed substitution obtained from ϕ by replacing all occurrences of t_{i}:τ_{i} by t′_{i}:τ_{i} for i = 1, …, k. Then the only difference between ϕ′(L_{1}) and σ′(L_{0}) may be the occurrence of subterms t_{i}:τ_{i} instead of t′_{i}:τ_{i} at some positions in σ′(L_{0}). Hence there is a derivation {σ′(L_{0})} ⇒_{Σ,C,V} {ϕ′(L_{1})} because of t_{i}:τ_{i} ⇒_{Σ,C,V} t′_{i}:τ_{i}. The length of the derivations for ϕ(G_{1}) ⇒_{Σ,P C,V} ∅ and σ(G_{0}) ⇒_{Σ,P C,V} ∅ is less than n. By induction hypothesis, ϕ′(G_{1}) ⇒_{Σ,C,V} ∅ and σ′(G_{0}) ⇒_{Σ,C,V} ∅. Altogether, there is a rewriting

σ′(G) ⇒_{Σ,C,V} σ′(G_{0}) ∪ {ϕ′(L_{1})} ⇒_{Σ,C,V} σ′(G_{0}) ∪ ϕ′(G_{1}) ⇒_{Σ,C,V} ∅

The proposition “σ(G) ⇒_{Σ,P C,V} ∅ implies σ′(G) ⇒_{Σ,P C,V} ∅” is not true in general: If C contains only the clauses

     a ≡ b ←
     p(x,x) ←

(there is only one basic type τ and therefore we omit the type annotations in this example), then a ⇒_{Σ,C,∅} b. Let G ={p(a,y)}, σ = {y/a} and σ′ = {y/b}. σ(G) ⇒_{Σ,P C,∅} ∅ is true, but not σ′(G) ⇒_{Σ,P C,∅} ∅. For σ′(G) there is only the successful rewriting

{p(a,b)} ⇒_{Σ,C,∅} {p(b,b)} ⇒_{Σ,P C,∅} ∅

i.e., we need at least one rewrite step for the proof. The condition in the last lemma on occurrences of function symbols in the heads of relational clauses is necessary for the correctness of the lemma: If C contains only the clauses

a:τ ≡ b:τ ←

     p(a:τ) ←

(for an arbitrary type τ), then {p(a:τ)} ⇒_{Σ,P C,∅} ∅, but not {p(b:τ)} ⇒_{Σ,C,∅} ∅. We remark that this condition can be achieved by replacing all terms in the head of a relational clause by new variables and adding new equations for the new variables and the terms to the clause body. Some authors call that the homogeneous form of a clause (e.g., [van Emden/ Yukawa 87]) which is a particular case of canonical clauses used in LEAF [Barbuti et al. 86]. For the last example we obtain the semantically equivalent set of clauses

a:τ ≡ b:τ ←
p(x:τ) ← x:τ ≡ a:τ

There exists a successful rewriting for {p(b:τ)} w.r.t. this specification:

{p(b:τ)} ⇒_{Σ,P C,∅} {b:τ ≡ a:τ} ⇒_{Σ,C,∅} {b:τ ≡ b:τ} ⇒_{Σ,P C,∅} ∅

The next lemma extends the result of the last lemma to rewritings with conditional equations:

Lemma 7.12 Let C be a confluent set of Σ-clauses with the following condition: For all conditional equations v ≡ w ← G′ ∈ C the left-hand side v is of the form f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ (n ≥ 0) and f does not occur in L for all L ← G ∈ C with pred(L) ≠ ‘≡’. If

σ = {x_{1}:τ_{1}/t_{1}:τ_{1} , …, x_{k}:τ_{k}/t_{k}:τ_{k}} and σ′ = {x_{1}:τ_{1}/t′_{1}:τ_{1} , …, x_{k}:τ_{k}/t′_{k}:τ_{k}}

are two typed substitutions with t_{i}:τ_{i} ⇒_{Σ,C,V} t′_{i}:τ_{i} (i = 1, …, k) and G is a Σ-goal with σ(G) ⇒_{Σ,C,V} ∅, then σ′(G) ⇒_{Σ,C,V} ∅.

Proof: If σ(G) ⇒_{Σ,C,V} ∅, then there exists a derivation

(Σ, C, V) σ(G) → ⋯ → ∅

by lemma 7.8. We show the proposition by induction on the length n of successful reductions. The case n = 0 is trivial. Let n > 0. If the deduction or reflexivity rule is applied in the first step, the proposition can be proved analogously to the last lemma. If the reduction rule is applied, then there are π ∈ O(σ(L_{0})) (with G = G_{0} ∪ {L_{0}}), v_{1} ≡ w_{1} ← G_{1} ∈ C and a typed substitution ϕ so that σ(L_{0})[π] = ϕ(v_{1}) and

σ(G_{0}) ∪ {σ(L_{0})[π ← ϕ(w_{1})]} ∪ ϕ(G_{1})

is the goal derived in the first step. The lengths of successful reductions for σ(G_{0}), σ(L_{0})[π ← ϕ(w_{1})] and ϕ(G_{1}) are less than n. We have to show: σ′(G) ⇒_{Σ,C,V} ∅

a) x_{i}:τ_{i} ∉ var(L_{0}) for all i ∈ {1, …, k}. Then σ(L_{0}) = σ′(L_{0}). Therefore we can do the same rewriting step for σ′(G) and we obtain the goal

σ′(G_{0}) ∪ {σ′(L_{0})[π ← ϕ(w_{1})]} ∪ ϕ(G_{1})

after the rewriting step. By induction hypothesis, this goal can be derived to the empty goal.

b) x_{i}:τ_{i} ∈ var(L_{0}) for some i ∈ {1, …, k}.

1. π ∈ O(L_{0}), but x_{i}:τ_{i} ∉ var(L_{0}[π]) for all i ∈ {1, …, k}. Then we can do the same rewriting step for σ′(G). We proceed as in case a).

2. π ∈ O(L_{0}) and x_{i}:τ_{i} ∈ var(L_{0}[π]) for some i ∈ {1, …, k}. Then t_{i}:τ_{i} is a subterm of ϕ(v_{1}). We have the following situation:

[figure: L_{0}; t_{i}:τ_{i}; ϕ(v_{1}); π]

Hence ϕ(v_{1}) ⇒_{Σ,C,V} ϕ(w_{1}) and ϕ(v_{1}) ⇒_{Σ,C,V} σ′(L_{0})[π] because each occurrence of a term t_{i}:τ_{i} in ϕ(v_{1}) can be replaced by t′_{i}:τ_{i}. By confluence of C, there exists a (Σ, X, V)-term z with

ϕ(w_{1}) ⇒_{Σ,C,V} z  and  σ′(L_{0})[π] ⇒_{Σ,C,V} z.

σ(G_{0}) and σ(L_{0})[π ← ϕ(w_{1})] are derivable to the empty goal with less than n reduction steps. Hence, by induction hypothesis, σ′(G_{0}) ⇒_{Σ,C,V} ∅ and σ′(L_{0})[π ← z] ⇒_{Σ,C,V} ∅. Altogether, we have

σ′(G) ⇒_{Σ,C,V} σ′(G_{0}) ∪ {σ′(L_{0})[π ← z]} ⇒_{Σ,C,V} ∅

3. π ∉ O(L_{0}). Then ϕ(v_{1}) must be a subterm of some t_{i}:τ_{i} in σ(L_{0}), i.e., we have the following situation:

[figure: L_{0}; t_{i}:τ_{i}; ϕ(v_{1}); x_{i}:τ_{i}]

There is a position π_{0} ∈ O(L_{0}) with L_{0}[π_{0}] = x_{i}:τ_{i} and π_{0} is a prefix of π. Thus there is a position π_{1} ∈ O(t_{i}:τ_{i}) with π = π_{0} ⋄ π_{1} (concatenation of the occurrences π_{0} and π_{1}). Hence t_{i}:τ_{i} ⇒_{Σ,C,V} t′_{i}:τ_{i} and t_{i}:τ_{i} ⇒_{Σ,C,V} t_{i}:τ_{i}[π_{1} ← ϕ(w_{1})] since t_{i}:τ_{i}[π_{1}] = ϕ(v_{1}). By confluence of C, there exists a (Σ, X, V)-term z with

t′_{i}:τ_{i} ⇒_{Σ,C,V} z  and  t_{i}:τ_{i}[π_{1} ← ϕ(w_{1})] ⇒_{Σ,C,V} z.

σ(G_{0}) and σ(L_{0})[π ← ϕ(w_{1})] are derivable to the empty goal with less than n reduction steps. Hence, by induction hypothesis, σ′(G_{0}) ⇒_{Σ,C,V} ∅ and σ′(L_{0})[π_{0} ← z] ⇒_{Σ,C,V} ∅. Altogether, we have

σ′(G) ⇒_{Σ,C,V} σ′(G_{0}) ∪ {σ′(L_{0})[π_{0} ← z]} ⇒_{Σ,C,V} ∅

Now we can prove our main theorem in this section:

Theorem 7.13 (Confluence implies Church-Rosser) Let C be a confluent set of Σclauses with the following condition: For all v ≡ w ← G′ ∈ C the left-hand side v is of the form f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ (n ≥ 0) and f does not occur in L for all L ← G ∈ C with pred(L) ≠ ‘≡’. Then C is Church-Rosser.

Proof: Let V ⊆ V ar_{Σ,X}, C^{↔} := C ∪{w ≡ v ← G′ | v ≡ w ← G′ ∈ C} and G be a (Σ, X, V)-goal

with (Σ, C^{↔}, V) → G. In order to show (Σ, C, V) → G, we prove the following proposition:

If G_{0} is a (Σ, X, V)-goal, L_{0} is a (Σ, X, V)-atom, π ∈ O(L_{0}), v ≡ w ← G_{1} ∈ C and σ is a typed substitution with L_{0}[π] = σ(w) and (Σ, C, V) → G_{0} ∪ {L_{0}[π ← σ(v)]} ∪ σ(G_{1}), then (Σ, C, V) → G_{0}∪{L_{0}}, i.e., reductions with applications of equations in right-to-left order are not necessary.

If (Σ, C, V) → G_{0}∪{L_{0}[π ← σ(v)]}∪σ(G_{1}), then σ(G_{1}) can be derived to the empty goal. Thus σ(v) ⇒_{Σ,C,V} σ(w). By lemma 7.12, {L_{0}[π ← σ(w)]} ⇒_{Σ,C,V} ∅. Hence G_{0} ∪ {L_{0}} ⇒_{Σ,C,V} ∅. The proposition follows by lemma 7.8.

The condition in the theorem on occurrences of function symbols in the heads of relational clauses is not a real restriction (see our remark on page 88) but necessary for the correctness of the theorem: We can infer from the example above that the clause set

a:τ ≡ b:τ ←

     p(a:τ) ←

has not the Church-Rosser property since the valid goal {p(b:τ)} can not be reduced to the empty goal, but the clause set

a:τ ≡ b:τ ←
p(x:τ) ← x:τ ≡ a:τ

is Church-Rosser. The last theorem is in comparison to theorem 7.8.2 in [Padawitz 88] an extended Church-Rosser criterion since the use of defined functions in relational clauses is not forbidden. If all conditional equations in C contain no predicate symbols except ‘≡’ in the condition (this can always be achieved by defining predicates as Boolean functions), then our notion of confluence is equivalent to [Hussmann 85]. In this case our theorem states that the Church-Rosser property depends only on the confluence of conditional equations but not on confluence properties of relational clauses that use the defined functions. If we view polymorphic specifications as an integration of functional and logic programming and there is a clear separation between the functional and the logical part so that functions are used in relational clauses but predicates are not used in function definitions, then it is only necessary to analyse the function definitions for confluence. The Church-Rosser property of the whole specification is a requirement for the completeness of an efficient operational semantics (narrowing). A lot of work on confluence criteria for conditional equations (without predicates) was done during the last years ([Kaplan 84b], [Zhang/Remy 85], [Ganzinger 87], among others). It should be possible to transfer results of that work to the polymorphic case. [Launay 86] has applied results from unconditional rewriting to equational specifications with polymorphic functions. Hence this may be a starting-point to transfer results from conditional rewriting to the polymorphic case.

Narrowing

We want to improve the efficiency of paramodulation by two optimizations:

1. The equations are applied in one direction.

2. If t is the subterm in the current goal which should be unified with the left-hand side of an equation, then t may not be a variable. This restriction reduces the number of applicable equations.

The proof procedure with these restrictions is called narrowing. It was introduced in the context of theorem proving by [Slagle 74]. Narrowing was applied to one-sorted specifications with a confluent set of unconditional equations by [Fay 79]. His completeness result holds under the condition that the set of equations is a “complete set of reductions” (or canonical term rewriting system) [Knuth/Bendix 70]. His narrowing procedure was improved by [Hullot 80] (among others) and extended to one-sorted specifications with conditional equations by [Hussmann 85] (see [Bockmayr 86] for a survey of conditional narrowing). In general, narrowing with most general unifiers is only complete under the following additional assumptions:

1. The specification is Church-Rosser.

2. All variables occurring in a clause must also occur in the clause head (in case of a relational clause) or in the left-hand side of the equation in the clause head (in case of conditional equations).

3. Only irreducible answer substitutions can be found by narrowing.

The second restriction is relevant for narrowing with most general unifiers and is not necessary for narrowing with arbitrary unifiers. But for practical purposes, only narrowing with most general unifiers is usable.

8.1 Soundness and completeness of narrowing

In this section, we define the narrowing calculus and prove soundness and completeness. Completeness of narrowing is based on completeness of reduction.

Definition 8.1 (Narrowing) Let C be a set of Σ-clauses and V ⊆ V ar_{Σ,X}.

a) 1. Narrowing rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom, π ∈ O(L) with L[π] ∉ V be a non-variable occurrence in L and the (Σ, X, V)-clause v ≡ w ← G′ be a variant of a clause from C. If there exists a unifier σ ∈ Sub(Σ, X, V, V′) for L[π] and v, then σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′) is said to be derived by narrowing from G ∪ {L} relative to σ and v ≡ w ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{N} σ σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′)

2. Restricted resolution rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom and the (Σ, X, V)-clause L′ ← G′ be a variant of a clause from C with pred(L′) ≠ ‘≡’. If there exists a unifier σ ∈ Sub(Σ, X, V, V′) for L and L′, then σ(G) ∪ σ(G′) is said to be derived by restricted resolution from G ∪ {L} relative to σ and L′ ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{N} σ σ(G) ∪ σ(G′)

3. Unification rule: Let G be a (Σ, X, V)-goal, v ≡ w be a (Σ, X, V)-equation and σ ∈ Sub(Σ, X, V, V′) be a unifier for v and w. Then σ(G) is said to be derived by unification from G ∪ {v ≡ w} relative to σ. Notation:

(Σ, C, V) G ∪ {v ≡ w} ⊢_{N} σ σ(G)

b) Let G be a (Σ, X, V)-goal. A (Σ, C, V)-narrowing of G is a sequence of the form

(Σ, C, V_{0}) G_{0} ⊢_{N} σ_{1} G_{1} ⊢_{N} σ_{2} G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} G_{n}

where G_{0} = G, V_{0} = V and (Σ, C, V_{i}) G_{i} ⊢_{N} σ_{i+1} G_{i+1} with σ_{i+1} ∈ Sub(Σ, X, V_{i}, V_{i+1}) for i = 0, 1, 2, …, n − 1. The (Σ, C, V)-narrowing is called successful if G_{n} = ∅. In this case n is called the length of the (Σ, C, V)-narrowing, and σ := σ_{n} ∘ ⋯ ∘ σ_{1} is called an N-computed answer. Notation:

(Σ, C, V) ⊢_{N} σ G

□

Our notion of narrowing is different from [Hussmann 85] because we handle predicates by the restricted resolution rule. In [Hussmann 85], predicates must be represented as Boolean functions. [Padawitz 88] has presented a narrowing calculus for many-sorted specifications with functions and predicates, but he has divided a specification into a base part and an extension part. The narrowing rule is only applied with conditional equations from the extension part until the goal is transformed into a goal provable with the base part by paramodulation or other complete proof procedures. Consequently, all predicates must be specified in the base part without the help of functions belonging to the extension part. For example, a binary predicate equalLength, which is satisfied if the two argument lists have the same length, cannot be specified if the length function on lists should be proved by narrowing. The only way is to introduce equalLength as a Boolean function in the extension part. Soundness of narrowing follows from soundness of paramodulation (theorem 6.3), because narrowing is a special case of paramodulation:

Theorem 8.2 (Soundness of narrowing) Let C be a set of Σ-clauses, V ⊆ V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful narrowing (Σ, C, V) ⊢_{N} σ G with N-computed answer σ ∈ Sub(Σ, X, V, V′), then (Σ, C, V′) ⊧ σ(G).

Narrowing is only complete if the answer substitutions are irreducible:

Definition 8.3 Let C be a set of Σ-clauses.

a) A Σ-term t:τ is reducible w.r.t. C if there is an occurrence π ∈ O(t:τ), a variant v ≡ w ← G of a clause from C and a typed substitution σ with t:τ[π] = σ(v).

b) A Σ-term t:τ is irreducible or in normal form w.r.t. C if t:τ is not reducible.

c) A typed substitution σ ∈ Sub(Σ, X, V, V′) is called irreducible or in normal form w.r.t. C if σ(x:τ) is irreducible for all x:τ ∈ V with σ(x:τ) ∉ V′, otherwise it is called reducible.

□

Hence a Σ-term is reducible if a reduction step is applicable to that term, otherwise the Σ-term is irreducible. Now we can state the completeness of narrowing.

Theorem 8.4 (Completeness of narrowing) Let C be a set of Σ-clauses with the Church-Rosser property and v ∉ V ar_{Σ,X} for each conditional equation v ≡ w ← G′ from C. Let V ⊆ V ar_{Σ,X} be finite and G be a (Σ, X, V)-goal. If σ ∈ Sub(Σ, X, V, V′) is irreducible w.r.t. C with (Σ, C, V′) ⊧ σ(G), then there exist a set V_{0} ⊆ V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V′) so that (Σ, C, V_{0}) ⊢_{N} σ_{0} G and σ_{0}(G) = σ(G).

Proof: By theorem 7.3 and the Church-Rosser property, (Σ, C, V′) → σ(G), i.e., there is a reduction

(Σ, C, V′) σ(G) → G_{1} → G_{2} → ⋯ → ∅

We show by induction on the length n of the reduction: There exist a set V_{0} ⊆ V ar_{Σ,X} with V ⊆ V_{0} and a (Σ, C, V_{0})-narrowing for G of the same length with N-computed answer σ_{c} ∈ Sub(Σ, X, V_{0}, V′) so that σ_{c}(α) = σ(α) for all α ∈ tvar(V)∪tvar(G) and σ_{c}(x:τ) = σ(x:τ) for all x:τ ∈ V. n = 1: Then (Σ, C, V′) σ(G) → ∅.

a) The reflexivity rule is applied: Then G = {v ≡ w} and σ(v) = σ(w). Thus (Σ, C, V) G ⊢_{N} σ ∅.

b) The deduction rule is applied: Then G = {L} and σ(L) ← is an instance of a clause from C. Hence there exist a variant L′ ← of a clause from C and a typed substitution σ′ so that σ′(L′) = σ(L) and the type variables and typed variables in V and L are disjoint from L′. Let V_{0} := V ∪ var(L′) and σ_{1} ∈ Sub(Σ, X, V_{0}, V′) be a typed substitution defined by

σ_{1}(α) = \{ \begin{matrix}σ′(α) & if α ∈ tvar(L′) \\ σ(α) & otherwise \end{matrix}

and

σ_{1}(x:τ) = \{ \begin{matrix}σ′(x:τ) & if x:τ ∈ var(L′) \\ σ(x:τ) & if x:τ ∈ V \end{matrix}

Then σ_{1} is a unifier for L and L′, i.e., (Σ, C, V_{0}) G ⊢_{N} σ_{1} ∅.

n > 1: We distinguish the kind of rule applied in the first narrowing step:

a) The reduction rule is applied: Then G = G′′ ∪ {L}, π ∈ O(σ(L)), v ≡ w ← G′ is a clause from C and σ′ is a typed substitution so that σ(L)[π] = σ′(v) and G_{1} = σ(G′′) ∪ {σ(L)[π ← σ′(w)]} ∪ σ′(G′). We assume that the type variables and typed variables in V and G are disjoint from those in v ≡ w ← G′ (otherwise we choose a variant of the clause). Let V_{1} := V ∪ var(v ≡ w ← G′) and σ_{1} ∈ Sub(Σ, X, V_{1}, V′) be the combination of σ and σ′ (cf. case b of n = 1). π ∈ O(σ(L)), σ is irreducible w.r.t. C, but σ(L)[π] = σ′(v) is reducible w.r.t. C and v ∉ V ar_{Σ,X}. Thus we infer that π ∈ O(L) and L[π] ∉ V_{1}. Hence σ(L)[π] = σ(L[π]), i.e., σ_{1} is a unifier for L[π] and v and

(Σ, C, V_{1}) G ⊢_{N} σ_{1} G_{1}

is a narrowing step. The reduction

(Σ, C, V′) G_{1} → G_{2} → ⋯ → ∅

has length n − 1. By induction hypothesis, there exist a set V_{2} ⊆ V ar_{Σ,X} with V′ ⊆ V_{2} and a (Σ, C, V_{2})-narrowing

(Σ, C, V_{2}) G_{1} ⊢_{N} σ_{2} G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} ∅

with σ_{n} ∘ ⋯ ∘ σ_{2} ∈ Sub(Σ, X, V_{2}, V′) so that σ_{n} ∘ ⋯ ∘ σ_{2}(α) = α for all α ∈ tvar(V′) ∪ tvar(G_{1}) and σ_{n} ∘ ⋯ ∘ σ_{2}(x:τ) = x:τ for all x:τ ∈ V′. We extend σ_{1} to a typed substitution σ_{1} ∈ Sub(Σ, X, V_{1}, V_{2}). Hence we obtain a narrowing

(Σ, C, V_{1}) G ⊢_{N} σ_{1} G_{1} ⊢_{N} σ_{2} G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} ∅

where the following conditions hold for σ_{c} := σ_{n} ∘ ⋯ ∘ σ_{1}: σ_{c} ∈ Sub(Σ, X, V_{1}, V′), σ_{c}(α) = σ(α) for all α ∈ tvar(V) ∪ tvar(G), and σ_{c}(x:τ) = σ(x:τ) for all x:τ ∈ V.

b) The deduction rule is applied: Then G = G′′ ∪ {L}, L′ ← G′ is a clause from C and σ′ is a typed substitution so that σ(L) = σ′(L′) and G_{1} = σ(G′′) ∪ σ′(G′). We assume that the type variables and typed variables in V and G are disjoint from those in L′ ← G′ (otherwise we choose a variant of the clause). Let V_{1} := V ∪ var(L′ ← G′) and σ_{1} ∈ Sub(Σ, X, V_{1}, V′) be the combination of σ and σ′. Then σ_{1} is a unifier for L and L′ and

(Σ, C, V_{1}) G ⊢_{N} σ_{1} G_{1}

is a narrowing step. Now we proceed as in case a).

c) The reflexivity rule is applied: Then G = G′′ ∪ {v ≡ w}, σ(v) = σ(w) and G_{1} = σ(G′′).

Then

(Σ, C, V) G ⊢_{N} σ G_{1}

is a narrowing step. Now we proceed as in case a).

The following example [Furbach/Hölldobler/Schreiber 88] shows the necessity of the irreducibility condition in the last theorem: We assume a basic type τ and the following declarations of constants and functions:

func a,b: → τ func f: τ → τ func f1,f2: τ, τ → τ

The specification contains the confluent set of clauses

a:τ ≡ b:τ ←

b:τ ≡ a:τ ←

     f1(f(a:τ):τ,f(b:τ):τ):τ ≡ f2(f(a:τ):τ,f(b:τ):τ):τ ←

(Σ, C, ∅) ⊧ σ(f1(x:τ, x:τ):τ ≡ f2(x:τ, x:τ):τ) with σ(x:τ) = f(a:τ):τ, but narrowing cannot be applied to the goal f1(x:τ, x:τ):τ ≡ f2(x:τ, x:τ):τ. From a programmer’s point of view the restriction to irreducible answers is not a real restriction because reducible answers are frequently useless. For instance, if the example specification for lists on page 59 is given and we want to prove the goal

     append([1],[2]) ≡ L

then σ = {L/append([1],[2])} is an N-computed answer obtained by one application of the unification rule. σ is reducible and obviously useless. Typically, the programmer wants to obtain the irreducible N-computed answer σ = {L/[1,2]}.

8.2 Narrowing with most general unifiers

In this section we define the notion of most general narrowing. In contrast to most general resolution and most general paramodulation it is only complete under additional conditions on the variables in the clauses.

Definition 8.5 (Most general narrowing) Let (Σ, C) be a polymorphic specification and V ⊆_{U} V ar_{Σ,X}.

a) 1. Narrowing rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom, π ∈ O(L) with L[π] ∉ V and the (Σ, X, V)-clause v ≡ w ← G′ be a variant of a clause from C with tvar(G ∪ {L}) ∩ tvar(v ≡ w ← G′) = ∅ and var(G ∪ {L}) ∩ var(v ≡ w ← G′) = ∅. If there exists a most general unifier σ ∈ Sub(Σ, X, V, V′) for L[π] and v, then σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′) is said to be derived by most general narrowing from G ∪ {L} relative to σ and v ≡ w ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{GN} σ σ(G) ∪ {σ(L)[π ← σ(w)]} ∪ σ(G′)

2. Restricted resolution rule: Let G be a (Σ, X, V)-goal, L be a (Σ, X, V)-atom and the (Σ, X, V)-clause L′ ← G′ be a variant of a clause from C with pred(L′) ≠ ‘≡’ and tvar(G ∪ {L}) ∩ tvar(L′ ← G′) = ∅ and var(G ∪ {L}) ∩ var(L′ ← G′) = ∅. If there exists a most general unifier σ ∈ Sub(Σ, X, V, V′) for L and L′, then σ(G)∪σ(G′) is said to be derived by restricted most general resolution from G ∪ {L} relative to σ and L′ ← G′. Notation:

(Σ, C, V) G ∪ {L} ⊢_{GN} σ σ(G) ∪ σ(G′)

3. Unification rule: Let G be a (Σ, X, V)-goal, v ≡ w be a (Σ, X, V)-equation and σ ∈ Sub(Σ, X, V, V′) be a most general unifier for v and w. Then σ(G) is said to be derived by most general unification from G ∪ {v ≡ w} relative to σ. Notation:

(Σ, C, V) G ∪ {v ≡ w} ⊢_{GN} σ σ(G)

b) Let G be a (Σ, X, V)-goal. A most general (Σ, C, V)-narrowing of G is a sequence of the form

(Σ, C, V_{0}) G_{0} ⊢_{GN} σ_{1} G_{1} ⊢_{GN} σ_{2} G_{2} ⊢_{GN} ⋯ ⊢_{GN} σ_{n} G_{n}

where G_{0} = G, V_{0} = V and (Σ, C, V_{i}) G_{i} ⊢_{GN} σ_{i+1} G_{i+1} with σ_{i+1} ∈ Sub(Σ, X, V_{i}, V_{i+1}) for i = 0, 1, 2, …, n − 1. The most general (Σ, C, V)-narrowing is called successful if G_{n} = ∅. In this case n is called the length of the most general (Σ, C, V)-narrowing, and σ := σ_{n} ∘ ⋯ ∘ σ_{1} is called a GN-computed answer. Notation:

(Σ, C, V) ⊢_{GN} σ G

□

Most general narrowing is a special case of narrowing and therefore we get the following result:

Theorem 8.6 (Soundness of most general narrowing) Let (Σ, C) be a polymorphic specification, V ⊆_{U} V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful most general narrowing (Σ, C, V) ⊢_{GN} σ G with GN-computed answer σ ∈ Sub(Σ, X, V, V′), then (Σ, C, V′) ⊧ σ(G).

Most general narrowing may be not complete even if the set of clauses is confluent: Example: [Giovannetti/Moiso 86] We assume a basic type τ and the following declarations of constants and functions:

     func a,b,c: → τ

func f: τ, τ → τ

The specification consists of the set of clauses

a:τ ≡ b:τ ←
a:τ ≡ c:τ ←
b:τ ≡ c:τ ← f(x:τ,c:τ):τ ≡ f(b:τ,x:τ):τ

which is confluent since b:τ ⇒_{Σ,C,∅} c:τ. If σ(x:τ) = c:τ, then

(Σ, C, ∅) ⊧ σ(f(x:τ, c:τ):τ ≡ f(b:τ, x:τ):τ).

σ is irreducible, but for proving the goal f(x:τ, c:τ):τ ≡ f(b:τ, x:τ):τ we obtain the following most general narrowing:

f(x:τ,c:τ):τ ≡ f(b:τ,x:τ):τ

⊢_{GN} unification rule ist not applicable, narrowing with the last clause f(x:τ,c:τ):τ ≡ f(c:τ,x:τ):τ, f(y:τ,c:τ):τ ≡ f(b:τ,y:τ):τ

⊢_{GN} unification rule f(y:τ,c:τ):τ ≡ f(b:τ,y:τ):τ

Hence the most general narrowing will be infinite and produces no answer. We need a restriction on the variable occurrences in the clauses for completeness of most general narrowing:

Theorem 8.7 (Completeness of most general narrowing) Let (Σ, C) be a polymorphic specification with the following properties:

1. (Σ, C) is Church-Rosser.

2. For each conditional equation v ≡ w ← G_{c} from C, var(w) ∪ var(G_{c}) ⊆ var(v) and v ∉ V ar_{Σ,X}.

3. For each clause L′ ← G′ ∈ C with pred(L′) ≠ ‘≡’: var(G) ⊆ var(L).

Let V ⊆_{U} V ar_{Σ,X} be finite and G be a (Σ, X, V)-goal. If σ ∈ Sub(Σ, X, V, V′) is irreducible w.r.t. C with (Σ, C, V′) ⊧ σ(G), then there exist a set V_{0} ⊆_{U} V ar_{Σ,X} and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, V_{1}) so that (Σ, C, V_{0}) ⊢_{GN} σ_{0} G and there exists a typed substitution ϕ ∈ Sub(Σ, X, V_{1}, V′) with ϕ(σ_{0}(G)) = σ(G).

Proof: By completeness theorem 8.4, there exist V_{1} ⊆ V ar_{Σ,X} and a narrowing sequence

(Σ, C, V_{1}) G ⊢_{N} σ_{1} G_{1} ⊢_{N} σ_{2} G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} ∅

with σ_{n} ∘ ⋯ ∘ σ_{1} ∈ Sub(Σ, X, V_{1}, V′) and σ_{n} ∘ ⋯ ∘ σ_{1}(G) = σ(G). We assume V_{1} ⊆_{U} V ar_{Σ,X}. Otherwise, we construct a corresponding set with that property as in the proof of theorem 5.15. We show by induction on the length n of the narrowing that there exist a set V_{2} ⊆_{U} V ar_{Σ,X} with V_{1} ⊆ V_{2} and a narrowing sequence

(Σ, C, V_{2}) G ⊢_{N} σ′_{1} G′_{1} ⊢_{N} σ′_{2} G′_{2} ⊢_{N} ⋯ ⊢_{N} σ′_{n} ∅

where each σ′_{i} is a most general unifier and σ′_{n}∘⋯∘σ′_{1} ∈ Sub(Σ, X, V_{2}, V_{3}). Furthermore, there exists a typed substitution ϕ ∈ Sub(Σ, X, V_{3}, V′) with ϕ ∘ σ′_{n} ∘ ⋯ ∘ σ′_{1}|_{T_{Σ}(X,V_{1})} = σ_{n} ∘ ⋯ ∘ σ_{1}. n = 1: Then (Σ, C, V_{1}) G ⊢_{N} σ_{1} ∅.

a) The restricted resolution rule is applied in the narrowing step: Then there exists a variant L ← of a clause from C with σ_{1}(G) = σ_{1}(L) and pred(L) ≠ ‘≡’. By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V_{1}, V_{3}) for G and L and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V_{3}, V′) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V_{1}) G ⊢_{N} σ′_{1} ∅

is a narrowing for G.

b) The unification rule is applied in the narrowing step: Then G = {v ≡ w} and σ_{1} is a unifier for v and w. By unification theorem 4.8, there exists a most general unifier σ′_{1} ∈ Sub(Σ, X, V_{1}, V_{3}) for v and w and therefore there is a typed substitution ϕ ∈ Sub(Σ, X, V_{3}, V′) with ϕ ∘ σ′_{1} = σ_{1}. Thus

(Σ, C, V_{1}) G ⊢_{N} σ′_{1} ∅

is a narrowing for G.

n > 0: Then there is a narrowing of the form

(Σ, C, V_{1}) G ⊢_{N} σ_{1} G_{1} ⊢_{N} σ_{2} G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} ∅

First we show: There exist a most general unifier σ′_{1} ∈ Sub(Σ, X, V_{1}, V′_{1}) and a typed substitution ϕ ∈ Sub(Σ, X, V′_{1}, V_{2}) with ϕ ∘ σ′_{1} = σ_{1} and (Σ, C, V_{1}) G ⊢_{N} σ′_{1} G′_{1} where ϕ(G′_{1}) = G_{1}. We omit the proof here, because this part is identical to the corresponding part in the proof of mgu-lemma 6.11. Next we distinguish the kind of rule applied in the second narrowing step:

a) The unification rule is applied: Then G_{1} = G_{R} ∪ {v ≡ w} and σ_{2} is a unifier for v and w. Hence G′_{1} = G′_{R} ∪ {v′ ≡ w′} with ϕ(G′_{R}) = G_{R}, ϕ(v′) = v and ϕ(w′) = w. σ_{2} ∘ ϕ is a unifier for v′ and w′, i.e., (Σ, C, V′_{1}) G′_{1} ⊢_{N} σ_{2} ∘ ϕ G_{2} is a narrowing step. Therefore

(Σ, C, V′_{1}) G′_{1} ⊢_{N} σ_{2} ∘ ϕ G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} ∅

is a narrowing for G′_{1} of length n − 1. By induction hypothesis, there exists a narrowing

(Σ, C, V_{3}) G′_{1} ⊢_{N} σ′_{2} G′_{2} ⊢_{N} ⋯ ⊢_{N} σ′_{n} ∅

where V_{3} ⊆_{U} V ar_{Σ,X}, V′_{1} ⊆ V_{3}, each σ′_{i} is a most general unifier (2 ≤ i ≤ n) and σ′_{n} ∘ ⋯ ∘ σ′_{2} ∈ Sub(Σ, X, V_{3}, V_{4}). Additionally, there exists a typed substitution ρ ∈ Sub(Σ, X, V_{4}, V′) with ρ ∘ σ′_{n} ∘ ⋯ ∘ σ′_{2}|_{T_{Σ}(X,V′_{1})} = σ_{n} ∘ ⋯ ∘ σ_{2} ∘ ϕ. We extend σ′_{1} to a typed substitution σ′_{1} ∈ Sub(Σ, X, V_{1}, V_{3}). Altogether, there is a narrowing

(Σ, C, V_{1}) G ⊢_{N} σ′_{1} G′_{1} ⊢_{N} σ′_{2} G′_{2} ⊢_{N} ⋯ ⊢_{N} σ′_{n} ∅

where each σ′_{i} is a most general unifier, σ′_{n} ∘ ⋯ ∘ σ′_{1} ∈ Sub(Σ, X, V_{1}, V_{4}) and ρ ∘ σ′_{n} ∘ ⋯ ∘ σ′_{1}|_{T_{Σ}(X,V_{1})} = σ_{n} ∘ ⋯ ∘ σ_{1}.

b) The restricted resolution rule is applied: Then G_{1} = G_{R} ∪{L} and there exists a variant L′′ ← G′′ of a clause from C with pred(L′′) ≠ ‘≡’ and σ_{2} is a unifier for L and L′′. Hence G′_{1} = G′_{R} ∪ {L′} with ϕ(G′_{R}) = G_{R} and ϕ(L′) = L. We assume that ϕ does not alter any type variables and typed variables from L′′ ← G′′ (otherwise choose a variant and extend the set V_{1}). Therefore σ_{2} ∘ ϕ is a unifier for L and L′′ and ϕ(G′′) = G′′, i.e., (Σ, C, V′_{1}) G′_{1} ⊢_{N} σ_{2} ∘ ϕ G_{2} is a narrowing step. Therefore

(Σ, C, V′_{1}) G′_{1} ⊢_{N} σ_{2} ∘ ϕ G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} ∅

is a narrowing for G′_{1} of length n − 1. Now we proceed as in case a).

c) The narrowing rule is applied: Then G_{1} = G_{R}∪{L} and there exists a position π ∈ O(L) with L[π] ∉ V_{2} and a variant v ≡ w ← G′′ of a clause from C so that σ_{2} is a unifier for L[π] and v and G_{2} = σ_{2}(G_{R}) ∪ {σ_{2}(L)[π ← σ_{2}(w)]} ∪ σ_{2}(G′′). Hence G′_{1} = G′_{R} ∪ {L′} with ϕ(G′_{R}) = G_{R} and ϕ(L′) = L. We assume that ϕ does not alter the type variables and typed variables from v ≡ w ← G′′, otherwise we choose a variant. Assume that π ∉ O(L′) or π ∈ O(L′) with L′[π] ∈ V′_{1}. Since π ∈ O(L), there exist x′:τ′ ∈ var(L′) and π′ ∈ O(ϕ(x′:τ′)) with ϕ(x′:τ′)[π′] = L[π] and ϕ(x′:τ′) ∉ V_{2}. Since G′_{1} is obtained from G by an application of the rule in the first step with typed substitution σ′_{1}, there are the following possibilities:

1. There is a typed variable x:τ ∈ var(G) with x′:τ′ ∈ var(σ′_{1}(x:τ)):

σ_{2}(σ_{1}(x:τ)) = σ_{2}(ϕ(σ′_{1}(x:τ))) is reducible since it contains the subterm σ_{2}(v). Thus σ_{n} ∘ ⋯ ∘ σ_{1}(x:τ) = σ(x:τ) is reducible. This is a contradiction to the fact that σ is irreducible since σ(x:τ) ∉ V′.

2. There is a typed variable x:τ ∈ var(c) with x′:τ′ ∈ var(σ′_{1}(x:τ)), where c is the

clause used in the first narrowing step.

• If c = v_{0} ≡ w_{0} ← G_{0}, then var(w_{0}) ∪ var(G_{0}) ⊆ var(v_{0}), and therefore x:τ ∈ var(v_{0}). Since σ′_{1} is an mgu for v_{0} and a subterm of G, x′:τ′ ∈ var(σ′_{1}(G)). Hence there exists x_{0}:τ_{0} ∈ var(G) with x′:τ′ ∈ var(σ′_{1}(x_{0}:τ_{0})). Now we proceed as in case 1.

• If c = L_{0} ← G_{0} is a relational clause, then var(G_{0}) ⊆ var(L_{0}), and therefore x:τ ∈ var(L_{0}). Since σ′_{1} is an mgu for L_{0} and an atom of G, x′:τ′ ∈ var(σ′_{1}(G)). Hence there exists x_{0}:τ_{0} ∈ var(G) with x′:τ′ ∈ var(σ′_{1}(x_{0}:τ_{0})). Now we proceed as in case 1.

The contradiction implies π ∈ O(L′) and L′[π] ∉ V′_{1}. Then ϕ(L′[π]) = L[π] and therefore σ_{2} ∘ ϕ is a unifier for L′[π] and v. (Σ, C, V′_{1}) G′_{1} ⊢_{N} σ_{2} ∘ ϕ G_{2} is a narrowing step since σ_{2}(ϕ(L′))[π ← σ_{2}(ϕ(w))] = σ_{2}(L)[π ← σ_{2}(w)] and ϕ(G′) = G′. Hence

(Σ, C, V′_{1}) G′_{1} ⊢_{N} σ_{2} ∘ ϕ G_{2} ⊢_{N} ⋯ ⊢_{N} σ_{n} ∅

is a narrowing for G′_{1} of length n − 1. Now we proceed as in case a).

Hence there exists a narrowing with most general unifiers. We assume that in the narrowing with most general unifiers tvar(G′_{i}) ∩ tvar(c_{i}) = ∅ and var(G′_{i}) ∩ var(c_{i}) = ∅, where c_{i} is the clause used in the i-th narrowing step. If this is not the case then we proceed as in the proof of theorem 5.15.

The condition var(G) ⊆ var(L) for relational clauses L ← G ∈ C is necessary for the completeness of most general narrowing: Example: This is a slight modification of our last example. We assume a basic type τ and the following declarations of constants, functions and predicates:

     func a,b,c: → τ

func f: τ, τ → τ

pred p:

The specification consists of the confluent set of clauses

a:τ ≡ b:τ ←
a:τ ≡ c:τ ←
b:τ ≡ c:τ ← p
p ← f(x:τ,c:τ):τ ≡ f(b:τ,x:τ):τ

We have (Σ, C, ∅) ⊧ p, but for proving the goal p we obtain the following most general narrowing:

     p

⊢_{GN} only the restricted resolution rule is applicable f(x:τ,c:τ):τ ≡ f(b:τ,x:τ):τ

⊢_{GN} unification rule ist not applicable

     f(x:τ,c:τ):τ ≡ f(c:τ,x:τ):τ, p

⊢_{GN} unification rule

     p

Hence most general narrowing will be infinite. Completeness of most general narrowing is only ensured for Church-Rosser specifications with the variable restrictions of theorem 8.7. On the other hand, those specifications are interesting because we need not care about the strictness of the variable types (cf. theorem 2.14):

Proposition 8.8 Let (Σ, C) be a polymorphic specification with the properties of theorem 8.7, V ⊆_{U} V ar_{Σ,X} and G be a (Σ, X, V)-goal. If there is a successful most general narrowing (Σ, C, V) ⊢_{GN} σ G with GN-computed answer σ ∈ Sub(Σ, X, V, V′), then (Σ, C, var(σ(G))) ⊧ σ(G).

Proof: Let

(Σ, C, V) G ⊢_{GN} σ_{1} G_{1} ⊢_{GN} σ_{2} G_{2} ⊢_{GN} ⋯ ⊢_{GN} σ_{n} ∅

be a most general narrowing for G with σ_{n} ∘ ⋯ ∘ σ_{1} = σ. We show by induction on the length n that there exist a set V_{0} ⊆ V and a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, var(σ(G))) with (Σ, C, V_{0}) ⊢_{GN} σ_{0} G and σ_{0}|_{V_{0}} = σ|_{V_{0}}. By theorem 8.6, this implies the proposition. n = 1: Then (Σ, C, V) G ⊢_{GN} σ_{1} ∅. Hence there exists a variant L ← of a clause from C (or L = x:α ≡ x:α) with σ_{1}(G) = σ_{1}(L). Let V_{0} := var(G) ∪ var(L) ⊆ V. We define a typed substitution σ_{0} ∈ Sub(Σ, X, V_{0}, var(σ_{1}(G))) by σ_{0}(x:τ) := σ_{1}(x:τ) for all x:τ ∈ V_{0}. Hence (Σ, C, V_{0}) G ⊢_{GN} σ_{0} ∅ and σ_{0}|_{V_{0}} = σ|_{V_{0}}. n > 1: Let ϕ := σ_{n} ∘ ⋯ ∘ σ_{2} and σ_{1} ∈ Sub(Σ, X, V, V′_{1}) be the typed substitution applied in the first narrowing step. By induction hypothesis, there exist a set V_{1} ⊆ V′_{1} and a typed substitution σ′_{0} ∈ Sub(Σ, X, V_{1}, var(ϕ(G_{1}))) with (Σ, C, V_{1}) ⊢_{GN} σ′_{0} G_{1} and σ′_{0}|_{V_{1}} = ϕ|_{V_{1}}. If the restricted resolution rule is applied in the first step, then G = G_{0} ∪ {L_{0}}, L′ ← G′ is a variant of a clause from C with σ_{1}(L_{0}) = σ_{1}(L′) and G_{1} = σ_{1}(G_{0}) ∪ σ_{1}(G′). Let V_{0} := var(G) ∪ var(L′ ← G′) ⊆ V and W := var(σ_{1}(G)) − V_{1}. We define a typed substitution σ′_{1} ∈ Sub(Σ, X, V_{0}, V_{1} ∪ W) by σ′_{1}(x:τ) := σ_{1}(x:τ) for all x:τ ∈ V_{0}. This is well-defined since σ_{1}(G_{0}) ∪ σ_{1}(G′) is a (Σ, X, V_{1})-goal. Since W ∩ V_{1} = ∅, we may assume that ϕ(x:τ) ∉ var(ϕ(G_{1})) for all x:τ ∈ W. We extend σ′_{0} to a typed substitution σ′_{0} ∈ Sub(Σ, X, V_{1} ∪ W, var(ϕ(G_{1})) ∪ W′) by σ′_{0}(x:τ) := ϕ(x:τ) for all x:τ ∈ W. The composition σ_{0} := σ′_{0}∘σ′_{1} is a typed substitution with σ_{0} ∈ Sub(Σ, X, V_{0}, var(ϕ(G_{1}))∪W′). We show that var(ϕ(G_{1})) ∪ W′ ⊆ var(σ(G)). If x:τ ∈ W′, then there exists y:ξ ∈ W with x:τ ∈ var(ϕ(y:ξ)), which implies x:τ ∈ var(ϕ(σ_{1}(G))). If x:τ ∈ var(ϕ(G_{1})), then, since ϕ(G_{1}) = σ(G_{0}) ∪ σ(G′), there are two possibilities:

1. If x:τ ∈ var(σ(G_{0})), then x:τ ∈ var(σ(G)) is trivially true.

2. If x:τ ∈ var(σ(G′)), then there is a typed variable y:ξ ∈ G′ with x:τ ∈ var(σ(y:ξ)). Since var(G′) ⊆ var(L′), y:ξ ∈ L′ and x:τ ∈ var(σ(G)) because σ(L′) = σ(L_{0}).

Thus there is a most general narrowing (Σ, C, V_{0}) ⊢_{GN} σ_{0} G with σ_{0} ∈ Sub(Σ, X, V_{0}, var(σ(G))) and σ_{0}|_{V_{0}} = σ|_{V_{0}}. This can be analogously shown for the narrowing and the unification rule, which completes the induction proof.

Many authors have investigated the narrowing rule for proofs in equational theories, but the narrowing rule is frequently restricted to specifications without predicates. For example, [Hussmann 85] has presented a completeness proof for narrowing with conditional equations without predicates, but the examples in this chapter show that his result holds only with the variable conditions on the conditional equations. [Dershowitz/Plaisted 85] have defined conditional rewrite programs, where each rule is of the form

l : − p → r

with the intended meaning l ≡ r ← p in our notation. They use conditional narrowing as the operational semantics and have only the restriction var(r) ⊆ var(l) ∪ var(p) on the variables in the rules. For completeness they require a well-founded ordering ≻ with “p implies l ≻ r” and l ≻ p for each rule. But such an ordering exists only in particular cases if var(p) ⊆ var(l) is not true. [Giovannetti/Moiso 86] have investigated the problem of “extra-variables” in conditions that do not occur in the left-hand side of a conditional equation. They have found a sufficient criterion for completeness of narrowing with extra-variables (level-confluence), but they require also the termination property. They have shown that level-confluence is not sufficient for completeness if the term rewriting system is non-terminating. SLOG [Fribourg 84] [Fribourg 85] is a logic language with equality where the operational semantics is based on innermost narrowing (see section 11.2) and rewriting. SLOG have no restrictions on the use of variables in clauses. The completeness is only ensured for a restricted class of programs, i.e., programs that are “lhs-innermost” (a syntactic condition), “ground-confluent” and “well-innermost reducing” (Fribourg has given sufficient criteria only for ground-canonical programs to be “well-innermost reducing”). In a recent paper, [Bertling/Ganzinger 88] have investigated the problem of extra-variables in conditions of conditional equations. They have no restrictions on the variables in conditional equations and give sufficient criteria for the completeness of the narrowing procedure. These criteria depend on the notion of rewriting. Various rewrite relations can be chosen for particular applications. In some cases it is possible to transform a given specification into another one which satisfies the completeness criterion. A particular variant of the Knuth-Bendix completion procedure [Knuth/Bendix 70] which considers the chosen rewrite relation is used to transform the specifications.

[Gallier/Raatz 86] have defined an SLD-resolution method with E-unifiers instead of unifiers. Their method is complete if the clause set is “well-behaved”, i.e., if G = ∅ for each conditional equation v ≡ w ← G (only unconditional equations are allowed) and there exists a procedure that enumerates a complete set of E-unifiers for any two terms (see [Siekmann/Szabó 82] for a survey of such equational theories). Similarly, [Yamamoto 87] has proved soundness and completeness of resolution combined with narrowing. In contrast to our result his specifications contain only relational clauses and unconditional equations which must be a canonical term rewriting system, and he has no variable restrictions in relational clauses. The theoretical foundation of resolution with modified unification to include equational theories was given by [Plotkin 72]. He has shown completeness of resolution with T -unification for full first-order logic, where T is an equational theory (e.g., associative functions, arithmetic) and T -unification is the process of finding unifiers under the theory T. Moreover, his result is also true if the clauses contain equations which are handled by the paramodulation rule. Thus, from an operational point of view, it may be better to divide a specification (Σ, C) into a specification (Σ, C′ ∪E) with C = C′ ∪E, where E is a set of unconditional equations with a well-known E-unification algorithm (e.g., associative-commutative functions [Stickel 81]), and modify the resolution and narrowing rule so that only clauses from C′ are used and unifiers are replaced by E-unifiers. A comprehensive survey of the integration of (untyped) functional programming into logic programming by modifying the unification in a resolution step can be found in [Dincbas/van Hentenryck 87]. They have restricted the functional part to canonical term rewriting systems defined by unconditional equations. [Subrahmanyam/You 86] require only the confluence of the rewriting relation. The operational semantics of their FUNLOG language is based on resolution with semantic unification which reduces the terms, if necessary, before unifying them. But their method is only complete if the terms are ground before the semantic unification. [Padawitz 88] has investigated specifications with predicates, but he restricts the use of functions in the definition of predicates (see above) so that a mixture of narrowing rule and restricted resolution rule applications is not allowed.

Optimization

The narrowing procedure, consisting of the narrowing rule, restricted resolution rule and unification rule with most general unifiers, is a sound and complete inference system for polymorphic specifications that are Church-Rosser and satisfy some restrictions on the variables in the clauses (see theorems 8.6 and 8.7). The narrowing procedure is more efficient than resolution with equality axioms (chapter 5) and paramodulation with functional-reflexive axioms (chapter 6). Hence these rules are suited for the operational semantics of Horn clause specifications with polymorphic types. The main difference to many-sorted specifications [Padawitz 88] is the fact that most general unifiers used in the inference rules must consider the types of polymorphic terms, otherwise the procedure is not sound. In chapter 4 we have proved that most general unifiers for polymorphic terms may be computed from most general unifiers in the sense [Robinson 65] if type expressions are represented as first-order terms. Therefore the unification in the polymorphic case is more complex than the unification in the untyped case. For the case of Horn clause programs without equality, [Mycroft/O’Keefe 84] have defined a specific class of polymorphic logic programs for which type checking is unnecessary at run time. Therefore it is possible to disregard type annotations in subterms at run time if the polymorphic specification has particular restrictions. This chapter presents some optimizations for the narrowing procedure.

9.1 Type-generally defined predicates

Generally, type annotations cannot be omitted in a correct narrowing derivation. The following examples illustrate that. Examples:

1. Assume the following specification is given:

type int/0, char/0 pred p: α pred q: int pred r: char

clauses: r(C:char) ← p(C:char) p(I:int) ← q(I:int)

A narrowing sequence for the goal r(C:char) is (we omit in the following examples the typed substitutions):

r(C:char) ⊢_{GN} p(C:char)

This narrowing is not successful because no rule can be applied to the last atom. If we omit the type annotations in the derivation and compute most general unifiers without type expressions, we obtain the derivation

r(C) ⊢_{GN} p(C) ⊢_{GN} q(C)

The last atom in the sequence is ill-typed since C is a variable of type char.

2. Assume the following specification is given:

type int/0, char/0 func 1: → int func f1: α → α func f2: α → α func f3: char → char pred p: char

pred isInt: α

clauses:

f1(X:α):α ≡ f2(X:α):α ← isInt(X:α)

f3(C:char):char ≡ f1(C:char):char ←

isInt(1:int) ←

A narrowing sequence for the goal p(f3(C:char):char) is:

p(f3(C:char):char)

⊢_{GN} p(f1(C:char):char)
⊢_{GN} p(f2(C:char):char), isInt(C:char)

This narrowing is not successful because no rule can be applied to the last goal. If we omit the type annotations in the derivation, we obtain the derivation

          p(f3(C)) ⊢_{GN} p(f1(C)) ⊢_{GN} p(f2(C)), isInt(C) ⊢_{GN} p(f2(1))

The last atom in the sequence is ill-typed since p has an argument term of type int.

Nevertheless it is possible to omit type annotations in the narrowing process if functions and predicates are defined with most general types, i.e., the type of the left-hand side of conditional equations and the head of relational clauses is equivalent to the declared type of the function and predicate, respectively. In functional languages this is always true, but in our specifications this is not required. In the following we develop the necessary definitions and results to prove this idea. If we omit type annotations, it must be possible to compute the omitted type annotations of a term. Hence we need the non-overloading property of polymorphic specifications (cf. definition 1.7). We assume in the following that V ⊆_{U} V ar_{Σ,X} is a set of typed variables with unique types.

Definition 9.1 A (Σ, X, V)-term t:τ is called type general if for any (Σ, X, V)-term t′:τ′ with ϕ(τ) = τ′ and ϕ ∈ T S(H, X) which is unifiable with t:τ and which has no type variables in common with t:τ, there exists a typed substitution σ ∈ Sub(Σ, X, V, V′) with σ(t:τ) = σ(t′:τ′) and σ(α) = α for all α ∈ tvar(t′:τ′). The property type general can be simply extended on atoms. □

Note that variables and constants are always type general. For type-general terms we do not require the result type to be most general as otherwise type-general terms may not have type-general subterms. But this is important for further results. Example: If there is a declaration f:α → bool, then f(X:α):bool is a type-general term, but not f(I:int):bool. If there is a declaration g:α, β → bool, then g(X:α, Y:β):bool is a type-general term, but neither g(X:α, I:int):bool nor g(X:α, Z:α):bool is type-general. Next we show that in case of type-general terms type annotations may be omitted in the unification. First we have to prove some properties of type-general terms.

Lemma 9.2 Let t = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ and t′ = f(t′_{1}:τ′_{1}, …, t′_{n}:τ′_{n}):τ′ be (Σ, X, V)-terms with ϕ(τ) = τ′ for a type substitution ϕ ∈ T S(H, X). If t is type general, then there exists a type substitution σ ∈ T S(H, X) with σ(τ_{1}, …, τ_{n} → τ) = τ′_{1}, …, τ′_{n} → τ′.

Proof: Let f:τ_{f} ∈ F unc with τ_{f} = ⋯ → τ_{0}. There exists ϕ′ ∈ T S(H, X) with ϕ′(τ_{f}) = τ_{1}, …, τ_{n} → τ. Let ϕ′′ ∈ T S(H, X) with ϕ′′(α) = ϕ′(α) for all α ∈ tvar(τ_{0}) and ϕ′′(α) = α for all other α ∈ X. Let r = f(x_{1}:ρ_{1}, …, x_{n}:ρ_{n}):ρ, where ϕ′′(τ_{f}) and ρ_{1}, …, ρ_{n} → ρ are equivalent and x_{i} ∈ V ar with x_{i} ≠ x_{j} for i ≠ j. We assume that type variables and typed variables in r and t are disjoint (otherwise rename them). By construction of r, there exist σ, σ′ ∈ T S(H, X) with

σ(ρ_{1}, …, ρ_{n} → ρ) = τ_{1}, …, τ_{n} → τ  and  σ′(ρ_{1}, …, ρ_{n} → ρ) = τ′_{1}, …, τ′_{n} → τ′.

Let V_{0} := var(r) ∪ var(t). We define θ ∈ Sub(Σ, X, V_{0}, V_{1}) by:

θ(α) = \{ \begin{matrix}σ(α) & if α ∈ tvar(ρ_{1}, …, ρ_{n} → ρ) \\ α & otherwise \end{matrix}

and:

θ(x:τ) = \{ \begin{matrix}t_{i}:τ_{i} & if x:τ = x_{i}:ρ_{i} \\ x:τ & otherwise \end{matrix}

Such a typed substitution exists since θ(ρ_{i}) = σ(ρ_{i}) = τ_{i}. Now we have θ(r) = f(θ(x_{1}:ρ_{1}), …, θ(x_{n}:ρ_{n})):θ(ρ) = t = θ(t), i.e., r and t are unifiable. By definition 9.1, there exists a type substitution θ′ ∈ T S(H, X) with ρ_{1}, …, ρ_{n} → ρ = θ′(ρ_{1}, …, ρ_{n} → ρ) = θ′(τ_{1}, …, τ_{n} → τ). Therefore σ′(θ′(τ_{1}, …, τ_{n} → τ)) = τ′_{1}, …, τ′_{n} → τ′.

Lemma 9.3 Let t = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ be a type general (Σ, X, V)-term. Then t_{i}:τ_{i} is a type general (Σ, X, V)-term and (tvar(τ) ∩ tvar(t_{i}:τ_{i})) − tvar(τ_{i}) = ∅ for i = 1, …, n. Furthermore, (tvar(t_{i}:τ_{i}) − tvar(τ_{i})) ∩ (tvar(t_{j}:τ_{j}) − tvar(τ_{j})) = ∅ for i ≠ j.

Proof: We prove the case i = 1. First we show that t_{1}:τ_{1} is type general. Let r_{1}:ρ_{1} be a (Σ, X, V)-term with ϕ(τ_{1}) = ρ_{1} for a ϕ ∈ T S(H, X), tvar(t)∩tvar(r_{1}:ρ_{1}) = ∅ and t_{1}:τ_{1} is unifiable with r_{1}:ρ_{1}. We assume that ϕ(α) = α for all α ∈ X −tvar(τ_{1}). Let x_{2}, …, x_{n} be pairwise distinct variable names not occurring in V and V_{0} := V ∪{x_{2}:ϕ(τ_{2}), …, x_{n}:ϕ(τ_{n})}. Then r := f(r_{1}:ρ_{1}, x_{2}:ϕ(τ_{2}), …, x_{n}:ϕ(τ_{n})):ϕ(τ) is a (Σ, X, V_{0})-term unifiable with t. Since t is type general, there exists a typed substitution σ ∈ Sub(Σ, X, V_{0}, V′_{0}) with σ(t) = σ(r) and σ(α) = α for all α ∈ tvar(r). It follows that σ(t_{1}:τ_{1}) = σ(r_{1}:ρ_{1}) and σ(α) = α for all α ∈ tvar(r_{1}:ρ_{1}). Hence t_{1}:τ_{1} is type general. Assumption: There exists α ∈ (tvar(τ) ∩ tvar(t_{1}:τ_{1})) − tvar(τ_{1}). Then α occurs in τ and in the subterm t_{1}:τ_{1}, but not in τ_{1}. Therefore the occurrences of α in t_{1} can be replaced by a monomorphic type γ_{1} and the occurrences of α in τ by another monomorphic type γ_{2}. The result is a term for which definition 9.1 does not hold. The last proposition in the lemma can be proved in the same way.

For a precise definition of “omitting all type annotations in a term” we define a mapping Ψ that deletes all type annotations in a term:

Definition 9.4 Let V_{0} ⊆ V ar. The mapping Ψ:T_{Σ^{u}}(X ∪ V_{0}) → T_{Σ^{u}}(X ∪ V_{0}) is defined as follows:

Ψ(x) := x for all x ∈ X ∪ V_{0}
Ψ(τ) := τ for all τ ∈ H with ar(τ) = 0
Ψ(c) := c for all c: → τ_{c} ∈ F unc
Ψ(h(t_{1}, …, t_{n})) := h(Ψ(t_{1}), …, Ψ(t_{n})) for all h ∈ H and t_{1}, …, t_{n} ∈ T_{Σ^{u}}(X ∪ V_{0})

Ψ(f(t_{1}, …, t_{n})) := f(Ψ(t_{1}), …, Ψ(t_{n})) for all functions f and t_{1}, …, t_{n} ∈ T_{Σ^{u}}(X ∪ V_{0})

Ψ(t_{1}:t_{2}) := Ψ(t_{1})

The definition of Ψ is extended on Σ-atoms p(t_{1}, …, t_{n}) by

Ψ(p(t_{1}, …, t_{n})) := p(Ψ(t_{1}), …, Ψ(t_{n}))
□

Theorem 9.5 (Unification with type general terms) Let t:τ, t′:τ′ be (Σ, X, V)-terms with tvar(t:τ)∩tvar(t′:τ′) = ∅, var(t:τ)∩var(t′:τ′) = ∅ and t:τ be type general with ϕ(τ) = τ′ for a type substitution ϕ ∈ T S(H, X). t:τ and t′:τ′ are unifiable iff Ψ(t:τ) and Ψ(t′:τ′) are unifiable in T_{Σ^{u}}(X ∪ uvar(V)).

Proof: Let t:τ and t′:τ′ be unifiable, σ ∈ Sub(Σ, X, V, V′) be a unifier for t_{0} and t_{1} and V_{0} := uvar(V). Let σ′ be a substitution in T_{Σ^{u}}(X ∪ V_{0}) with σ′(α) = σ(α) for all α ∈ X and σ′(x) = Ψ(σ(x:τ)) for all x:τ ∈ V. It is straightforward to show (by induction on the size of terms) that σ|_{T_{H}(X)} = σ′|_{T_{H}(X)} and σ′(Ψ(t)) = Ψ(σ(t)) for all t ∈ T erm_{Σ}(X, V). Therefore σ′(Ψ(t:τ)) = Ψ(σ(t:τ)) = Ψ(σ(t′:τ′)) = σ′(Ψ(t′:τ′)). Conversely, let Ψ(t:τ) and Ψ(t′:τ′) be unifiable in T_{Σ^{u}}(X ∪ V_{0}). We assume ϕ(α) = α for all α ∈ X − tvar(τ) and prove the proposition by induction on the size of the term t:τ: t:τ ∈ V: Let σ ∈ Sub(Σ, X, V, V′) with σ|_{T_{H}(X)} = ϕ, σ(x:ρ) = x:ϕ(ρ) for all x:ρ ∈ V − {t:τ} and σ(t:τ) = σ(t′:τ′). Then σ is a unifier for t:τ and t′:τ′. t:τ = c:τ with c: → τ_{c} ∈ F unc. Since ϕ(τ) = τ′ and c and t′ are unifiable in T_{Σ^{u}}(X ∪ V_{0}), t:τ and t′:τ′ are unifiable. t:τ = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ (n > 0): The case t′:τ′ ∈ V is the same as t:τ ∈ V. Therefore we assume t′:τ′ = f(t′_{1}:τ′_{1}, …, t′_{n}:τ′_{n}):τ′. By lemma 9.3, each t_{i}:τ_{i} is type general. By lemma 9.2, there exists ϕ′ ∈ T S(H, X) with ϕ′(τ_{1}, …, τ_{n} → τ) = τ′_{1}, …, τ′_{n} → τ′. Ψ(t_{i}:τ_{i}) and Ψ(t′_{i}:τ′_{i}) are unifiable in T_{Σ^{u}}(X ∪ V_{0}) since Ψ(t:τ) and Ψ(t′:τ′) are unifiable in T_{Σ^{u}}(X ∪ V_{0}). Thus we can apply the induction hypothesis and infer that t_{i}:τ_{i} and t′_{i}:τ′_{i} are unifiable, i.e., there exist unifiers σ_{i} for t_{i}:τ_{i} and t′_{i}:τ′_{i} with σ_{i}(α) = α for all α ∈ tvar(t′_{i}:τ′_{i}) (by definition 9.1). Let ϕ_{i} := σ_{i}|_{T_{H}(tvar(t_{i}:τ_{i}))} be type substitutions (i = 1, …, n). Then ϕ_{i}(τ_{i}) = σ_{i}(τ_{i}) = τ′_{i} = ϕ′(τ_{i}). This implies ϕ_{i}(α) = ϕ′(α) for all α ∈ tvar(τ_{i}) (i = 1, …, n). By lemma 9.3, the type substitutions ϕ_{i} can be combined to a type substitution θ with

θ(α) = \{ \begin{matrix}ϕ_{i}(α) & for all α ∈ tvar(t_{i}:τ_{i}) \\ ϕ′(α) & for all α ∈ tvar(τ) \\ α & for all other α ∈ X \end{matrix}

We extend θ to a typed substitution by θ(x:τ) := x:θ(τ) for all x:τ ∈ V. Then in θ(t:τ) and θ(t′:τ′) = t′:τ′ subterms at same positions have identical types: If we start the algorithm “mgu” with θ(t:τ) and θ(t′:τ′) at no time there are type expressions in the disagreement set. The unification does not depend on the types, and therefore θ(t:τ) and θ(t′:τ′) are unifiable since Ψ(t:τ) and Ψ(t′:τ′) are unifiable in T_{Σ^{u}}(X ∪ V_{0}).

The condition ϕ(τ) = τ′ in the last theorem is necessary, otherwise the theorem does not hold. For example, if there is a declaration

func id: α → α

then id(I:int):int is type general but not unifiable with the term id(B:bool):bool. Ψ(id(I:int):int) = id(I) and Ψ(id(B:bool):bool) = id(B) are unifiable in T_{Σ^{u}}(X ∪ {I, B}). If we want to omit type annotations, it is not sufficient that the left-hand sides of conditional equations are type-general terms (see the second example at the beginning of this section). It is necessary that all predicates in the body of a conditional equation are type-generally defined. Therefore we define:

Definition 9.6 Let (Σ, C) be a polymorphic specification and p:τ_{p} ∈ P red.

a) The predicate p ≠ ‘≡’ is type-generally defined in (Σ, C) relative to a set of predicates P if for every clause

p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) ← L_{1}, …, L_{k} ∈ C

the following conditions hold:

1. p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) is type general.

2. If pred(L_{i}) = q_{i} and q_{i} ∉ P ∪ {p, ‘≡’}, then q_{i} is type-generally defined in (Σ, C)

relative to P ∪ {p} (for i = 1, …, k).

b) The predicate p ≠ ‘≡’ is type-generally defined in (Σ, C) if p is type-generally defined in (Σ, C) relative to ∅.

c) The predicate ‘≡’ is type-generally defined in (Σ, C) if for every clause of the form

t_{1}:τ ≡ t_{2}:τ ← L_{1}, …, L_{k}

from C the following conditions hold:

1. t_{1}:τ = f(⋯):τ with f:τ_{1}, …, τ_{n} → τ_{0} ∈ F unc (n ≥ 0), τ_{0} and τ are equivalent, and t_{1}:τ is type general.

2. If pred(L_{i}) = p_{i} ≠ ‘≡’, then p_{i} is type-generally defined in (Σ, C) (for i = 1, …, k).

□

The next lemma shows that type variables are never instantiated in a most general narrowing step if the predicates are type-generally defined. Type variables can only be renamed depending on the computation method for the most general unifier.

Lemma 9.7 Let (Σ, C) be a polymorphic specification, ‘≡’ be type-generally defined in (Σ, C) and G be a (Σ, X, V)-goal. If (Σ, C, V) G ⊢_{GN} σ G′ is a most general narrowing step and pred(L) is type-generally defined in (Σ, C) for all L ∈ G, then pred(L′) is type-generally defined in (Σ, C) for all L′ ∈ G′ and σ|_{T_{H}(tvar(G))} is bijective, i.e., the types τ and σ(τ) are equivalent for each type τ in G.

Proof: We show that the proposition is true for each kind of rule applied in the most general narrowing step:

1. The restricted resolution rule is applied: Then G = G_{0} ∪ {L_{0}}, the (Σ, X, V)-clause L_{1} ← G_{1} is a variant of a clause from C with pred(L_{1}) = p ≠ ‘≡’, tvar(G) ∩ tvar(L_{1} ← G_{1}) = ∅, var(G) ∩ var(L_{1} ← G_{1}) = ∅, σ ∈ Sub(Σ, X, V, V_{1}) is an mgu for L_{0} and L_{1}, and G′ = σ(G_{0} ∪ G_{1}). Hence pred(L_{0}) = p and p is type-generally defined in (Σ, C). By definition 9.6, pred(L′) is type-generally defined in (Σ, C) for all L′ ∈ G_{1}. Thus pred(L′) is type-generally defined in (Σ, C) for all L′ ∈ G′ and L_{1} is type general. By definition 9.1, there exists a typed substitution σ′ ∈ Sub(Σ, X, V, V′) with σ′(L_{0}) = σ′(L_{1}) and σ′(α) = α for all α ∈ tvar(L_{0}). Hence σ′ is a unifier for L_{0} and L_{1} and there exists ϕ ∈ Sub(Σ, X, V_{1}, V′) with ϕ ∘ σ = σ′ since σ is an mgu for L_{0} and L_{1}. For all α ∈ tvar(L_{0}) we have α = σ′(α) = ϕ(σ(α)), which implies σ(α) ∈ X. Hence σ(α) ∈ X for all α ∈ tvar(G) because σ is an mgu for L_{0} and L_{1} and tvar(G) ∩ tvar(L_{1}) = ∅.

We have to show that σ is injective on tvar(G). σ is injective on tvar(L_{0}) because α_{1}, α_{2} ∈ tvar(L_{0}) with σ(α_{1}) = σ(α_{2}) implies α_{1} = ϕ(σ(α_{1})) = ϕ(σ(α_{2})) = α_{2}. Since σ is an mgu for L_{0} and L_{1}, we may assume that

σ(α) = α ∀α ∉ tvar(L_{0}) ∪ tvar(L_{1})  (1)

and

tvar(σ(α)) ∈ tvar(L_{0}) ∪ tvar(L_{1}) ∀α ∈ tvar(L_{0}) ∪ tvar(L_{1})  (2)

Suppose there are α_{1} ∈ tvar(L_{0}) and α_{2} ∈ tvar(G_{0}) − tvar(L_{0}) with σ(α_{1}) = σ(α_{2}). tvar(G_{0}) ∩ tvar(L_{1}) = ∅ and (1) implies σ(α_{2}) = α_{2}, i.e., σ(α_{1}) = α_{2}. (2) implies α_{2} = σ(α_{1}) ∈ tvar(L_{0}) ∪ tvar(L_{1}). This contradicts our assumption. Hence σ is injective on tvar(G), i.e., σ|_{T_{H}(tvar(G))} is bijective. The equivalence of the types follows by proposition 1.6.

2. The unification rule is applied: This is equivalent to a resolution step with the clause x:α ≡ x:α ←. Since x:α ≡ x:α is a type general atom, we argue as in the first case.

3. The narrowing rule is applied: Then G = G_{0} ∪ {L_{0}}, π ∈ O(L_{0}) with L_{0}[π] ∉ V, the (Σ, X, V)-clause v ≡ w ← G_{1} is a variant of a clause from C, tvar(G) ∩ tvar(v ≡ w ← G_{1}) = ∅, var(G) ∩ var(v ≡ w ← G_{1}) = ∅, σ is an mgu for L_{0}[π] and v, and G′ = σ(G_{0}) ∪ σ(L_{0})[π ← σ(w)] ∪ σ(G_{1}). Since ‘≡’ is type-generally defined, pred(L′) is type-generally defined in (Σ, C) for all L′ ∈ G_{1}. Thus pred(L′) is type-generally defined in (Σ, C) for all L′ ∈ G′ and v is type general. Hence we can show as in the first case that σ|_{T_{H}(tvar(G))} is bijective.

The next corollary extends the result of the last lemma to most general narrowing derivations:

Corollary 9.8 Let (Σ, C) be a polymorphic specification, ‘≡’ be type-generally defined in (Σ, C) and G be a (Σ, X, V)-goal. If

(Σ, C, V) G ⊢_{GN} σ_{1} G_{1} ⊢_{GN} ⋯ ⊢_{GN} σ_{n} G_{n}

is a sequence of narrowing steps and pred(L) is type-generally defined in (Σ, C) for all L ∈ G, then σ_{n} ∘ ⋯ ∘ σ_{1}|_{T_{H}(tvar(G))} is bijective.

Proof: Let G_{0} = G and X_{i} := tvar(G_{i}) ∪ … ∪ tvar(G_{0}). If c_{i} is the clause used in the i-th narrowing step, we can assume that tvar(c_{i}) ∩ X_{i−1} = ∅. Since each σ_{i} is an mgu, we may assume that σ_{i}(α) = α for all α ∈ X_{i−1} − tvar(G_{i−1}). By induction on the narrowing steps and lemma 9.7, it follows that σ_{i} ∘ ⋯ ∘ σ_{1}|_{T_{H}(X_{i−1})} is bijective.

Theorem 9.9 (Optimized unification for type-generally defined predicates) Let (Σ, C) be a polymorphic specification and the predicate ‘≡’ be type-generally defined in (Σ, C). If G is a Σ-goal where all predicates in G are type-generally defined in (Σ, C), then type annotations are unnecessary during a most general narrowing for G.

Proof: Only type general atoms or terms are unified during a most general narrowing for G. By theorem 9.5, type annotations have no influence on success or failure of the unification (if a term t:τ is unified with the left-hand side t′:τ′ of an equation in a narrowing step, then t:τ, t′:τ′ ∉ V ar_{Σ,X} and ϕ(τ′) = τ for a type substitution ϕ, since ‘≡’ is type-generally defined). By corollary 9.8, the types of G are not modified during a most general narrowing for G.

For the case of monomorphic signatures we get the following result:

Corollary 9.10 If the signature Σ is monomorphic, i.e., the function and predicate declarations contain no type variables, then type annotations are unnecessary during the narrowing of Σ-goals.

This corollary shows that in many-sorted Horn clause specifications the narrowing procedure has the same efficiency as in untyped specifications since types are not needed at run time. Next we want to develop an algorithm for deciding the property type general. We need the following definition for an alternative characterization of type general terms.

Definition 9.11 A (Σ, X, V)-term f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ with

1. (tvar(τ) ∩ tvar(t_{i}:τ_{i})) − tvar(τ_{i}) = ∅ for i = 1, …, n

2. (tvar(t_{i}:τ_{i}) − tvar(τ_{i})) ∩ (tvar(t_{j}:τ_{j}) − tvar(τ_{j})) = ∅ for i, j = 1, …, n with i ≠ j

3. f:ρ_{1}, …, ρ_{n} → ρ ∈ F unc, σ ∈ T S(H, X) with σ(ρ) = τ and σ(α) = α for all α ∈ X − tvar(ρ) implies that σ(ρ_{1}, …, ρ_{n} → ρ) and τ_{1}, …, τ_{n} → τ are equivalent

is called directly type general. □

The next lemma shows the relation between the properties directly type general and type general.

Lemma 9.12 Let t:τ be a (Σ, X, V)-term. If each subterm of t:τ is a variable, a constant, or a directly type general term, then t:τ is type general.

Proof: First we show by induction on the size of t:τ: For each t′:τ′ ∈ T erm_{Σ}(X, V) with σ_{0}(τ) = τ′ (for a type substitution σ_{0} ∈ T S(H, X)) that is unifiable with t:τ and that has no type variables in common with t:τ, there exists a type substitution σ ∈ T S(H, X) that affects only type variables from tvar(t:τ) so that subterms at identical occurrences in σ(t:τ) and t′:τ′ have identical types (in this proof we extend each type substitution σ to a typed substitution by σ(x:τ) := x:σ(τ)). If t:τ is a variable or a constant, then we define σ(α) = σ_{0}(α) if α ∈ tvar(τ) and σ(α) = α otherwise. Induction step: t:τ = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ. If t′:τ′ is a variable, then we define σ(α) = σ_{0}(α) for α ∈ tvar(τ) and σ(α) = α for all other α ∈ X. Otherwise, t′:τ′ = f(t′_{1}:τ′_{1}, …, t′_{n}:τ′_{n}):τ′. Let f:ρ_{1}, …, ρ_{n} → ρ ∈ F unc and σ_{1}, σ_{2} ∈ T S(H, X) with σ_{1}(ρ_{1}, …, ρ_{n} → ρ) = τ_{1}, …, τ_{n} → τ and σ_{2}(ρ_{1}, …, ρ_{n} → ρ) = τ′_{1}, …, τ′_{n} → τ′. σ_{2}(ρ) = τ′ = σ_{0}(τ) = σ_{0}(σ_{1}(ρ)) and therefore σ_{2}(α) = σ_{0}(σ_{1}(α)) for all α ∈ tvar(ρ). Since t:τ is directly type general (condition 3), there exists σ_{3} ∈ T S(H, X) with σ_{3}(τ_{1}, …, τ_{n} → τ) = τ′_{1}, …, τ′_{n} → τ′. We assume that σ_{3} alters only type variables from tvar(τ_{1}, …, τ_{n} → τ). By condition 1, each composite subterm of σ_{3}(t_{i}:τ_{i}) is directly type general. Thus we can apply the induction hypothesis and we get (for i = 1, …, n) type substitutions ϕ_{i} ∈ T S(H, X) that alters only type variables from tvar(t_{i}:τ_{i}) so that subterms at identical occurrences in ϕ_{i}(t_{i}:τ_{i}) and t′_{i}:τ′_{i} have identical types and ϕ_{i}(α) = σ_{3}(α) for all α ∈ tvar(τ_{i}). By conditions 2 and 1, we can combine the type substitutions ϕ_{1}, …, ϕ_{n} and σ_{3} to one type substitution σ with the desired properties. If t′:τ′ is a (Σ, X, V)-term with σ_{0}(τ) = τ′ that is unifiable with t:τ and that has no type variables in common with t:τ, there exists a type substitution σ ∈ T S(H, X) which alters only type variables from tvar(t:τ) so that subterms at identical occurrences in σ(t:τ) and t′:τ′ have identical types. If we compute a unifier σ′ for σ(t:τ) and t′:τ′ with algorithm “mgu”, we get σ′(α) = α for all α ∈ X. Therefore σ′ ∘ σ is a unifier for t:τ and t′:τ′ with σ′ ∘ σ(α) = α for all α ∈ tvar(t′:t′), i.e., t:τ is a type general term.

The next lemma is the justification for the following algorithm type general.

Lemma 9.13 (Type general) A (Σ, X, V)-term is type general iff each subterm is a variable, a constant, or a directly type general term.

Proof: “⟹”: By lemma 9.2 and lemma 9.3. “⟸”: By lemma 9.12.

Now we are able to present the algorithm type general. The ‘function’ skolemize replaces all type variables in a type expression by ‘new’ type constants. With the use of skolemize equivalence of type expressions can be decided by unification of type expressions. In the algorithm, each type substitution σ is extended to a typed substitution by σ(x:τ) := x:σ(τ). The algorithm must be called by type general(t:τ, τ).

Algorithm type general Input: Term t, type ρ Output: A type substition, if t is type general, and fail, otherwise.

1. ρ′ := skolemize(ρ)

2. If t = x:τ ∈ V ar_{Σ,X} then stop with mgu(τ, ρ′)

3. If t = c:τ with c: → τ_{c} ∈ F unc then stop with mgu(τ, ρ′)

4. If t = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ and f:ρ_{1}, …, ρ_{n} → ρ_{0} ∈ F unc and σ = mgu(ρ_{0}, ρ′) ≠ fail then: ρ′_{1}, …, ρ′_{n} → ρ′_{0} := skolemize(σ(ρ_{1}, …, ρ_{n} → ρ_{0})) If mgu(ρ′_{0}, τ) = σ_{0} ≠ fail and type general(σ_{0}(t_{1}:τ_{1}), ρ′_{1}) = σ_{1} ≠ fail and ⋯ type general(σ_{n−1}(… (σ_{0}(t_{n}:τ_{n})) …), ρ′_{n}) = σ_{n} ≠ fail then stop with σ_{n} ∘ ⋯ ∘ σ_{1} ∘ σ_{0} else stop with fail

5. stop with fail

9.2 Relational specifications

A relational specification is a specification without conditional equations. A relational specification is sometimes called logic program. The narrowing rule is not applicable for this kind of specifications and the resolution calculus is a sound and complete inference system without the equality axioms. In contrast to most general narrowing, most general resolution is complete without any restrictions on the variables in the clauses. Therefore relational specifications, which are the same as Horn clause programs with polymorphic types [Hanus 88b], are an interesting subclass of polymorphic specifications. Since the narrowing rule is not applicable, there is another possibility for optimization: The argument types of functions can be deleted during the resolution process if the functions are type preserving, i.e., all type variables in the argument types occur also in the result type. In the following, we give precise definitions and prove the results of this idea.

Definition 9.14 A function symbol f is called type preserving if f:τ_{1}, …, τ_{n} → τ ∈ F unc and tvar(τ_{i}) ⊆ tvar(τ) for i = 1, …, n. □

In the declaration of a type preserving function all type variables occurring in the argument types also occur in the result type. For example,

func nil: → list(α)
func cons: α, list(α) → list(α)

are type preserving functions, whereas

func equal: α, α → bool
func length: list(α) → nat

are not type preserving functions. We show that in the case of type preserving functions the type annotations in the arguments are unnecessary. For this purpose we define a mapping Φ that deletes the type annotations in the arguments of type preserving functions:

Definition 9.15 Let V_{0} ⊆ V ar. The mapping Φ:T_{Σ^{u}}(X ∪ V_{0}) → T_{Σ^{u}}(X ∪ V_{0}) is defined as follows:

Φ(x) := x for all x ∈ X ∪ V_{0}

Φ(τ) := τ for all τ ∈ H with ar(τ) = 0

Φ(c) := c for all c: → τ_{c} ∈ F unc

Φ(h(t_{1}, …, t_{n})) := h(Φ(t_{1}), …, Φ(t_{n}))

for all h ∈ H with ar(h) = n > 0 and t_{1}, …, t_{n} ∈ T_{Σ^{u}}(X ∪ V_{0})

Φ(f(t_{1}:τ_{1}, …, t_{n}:τ_{n})) := f(Φ(t_{1}), …, Φ(t_{n}))

for all type preserving functions f and t_{1}:τ_{1}, …, t_{n}:τ_{n} ∈ T_{Σ^{u}}(X ∪ V_{0})

Φ(g(t_{1}, …, t_{n})) := g(Φ(t_{1}), …, Φ(t_{n}))

if the function g is not type preserving or a t_{i} is not of the form r_{i}:ρ_{i}

Φ(t_{1}:t_{2}) := Φ(t_{1}):Φ(t_{2})

□

Corollary 9.16 If τ ∈ T_{H}(X), then Φ(τ) = τ.

We will use the mapping Φ only on terms from T erm_{Σ}(X, V). The next lemma states an important property of Φ on these terms.

Lemma 9.17 Let V ⊆_{U} V ar_{Σ,X}. The mapping Φ is injective on the set T erm_{Σ}(X, V).

Proof: We show by induction on the size of terms: If t, t′ ∈ T erm_{Σ}(X, V) with Φ(t) = Φ(t′), then t = t′. t = x:τ ∈ V: Then Φ(t) = Φ(x:τ) = x:τ = Φ(t′). By definition of Φ, t′ is of the form x′:τ′ with Φ(x′) = x and Φ(τ′) = τ. Since t′ ∈ T erm_{Σ}(X, V), τ′ ∈ T_{H}(X) and τ′ = τ by the last corollary. Therefore we obtain t′ = t. t = c:τ with c: → τ_{c} ∈ F unc. Then Φ(t) = c:τ = Φ(t′). By definition of Φ, t′ is of the form c′:τ′ with Φ(c′) = c and Φ(τ′) = τ. We obtain t = t′ as in the first case. t = f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ, where f is a type preserving function. Φ(t) = f(Φ(t_{1}), …, Φ(t_{n})):τ = Φ(t′). Thus t′ = r:ρ with Φ(r) = f(Φ(t_{1}), …, Φ(t_{n})) and Φ(ρ) = τ. Since t′ ∈ T erm_{Σ}(X, V), we infer ρ = τ and r = f(t′_{1}:τ′_{1}, …, t′_{n}:τ′_{n}) with Φ(t′_{i}) = Φ(t_{i}) (i = 1, …, n). If f:τ_{f} ∈ F unc, then there exist σ, σ′ ∈ T S(H, X) with σ(τ_{f}) = τ_{1}, …, τ_{n} → τ and σ′(τ_{f}) = τ′_{1}, …, τ′_{n} → τ since t, t′ ∈ T erm_{Σ}(X, V). Let τ_{f} = ϕ_{1}, …, ϕ_{n} → ϕ and X′ = tvar(ϕ). Since σ(ϕ) = τ = σ′(ϕ), it follows σ|_{T_{H}(X′)} = σ′|_{T_{H}(X′)} and σ(ϕ_{j}) = σ′(ϕ_{j}) (since tvar(ϕ_{j}) ⊆ tvar(ϕ)). Thus τ_{j} = τ′_{j} is true for j = 1, …, n, and we obtain Φ(t_{j}:τ_{j}) = Φ(t′_{j}:τ_{j}). It follows t = t′ by induction hypothesis. t = g(t_{1}, …, t_{n}):τ, where g is not type preserving. Then Φ(t) = g(Φ(t_{1}), …, Φ(t_{n})):τ = Φ(t′). Since t′ ∈ T erm_{Σ}(X, V), t′ = g(t′_{1}, …, t′_{n}):τ with Φ(t_{i}) = Φ(t′_{i}). It follows t = t′ by induction hypothesis.

Lemma 9.18 Let V ⊆_{U} V ar_{Σ,X} and V_{0} := uvar(V). If t_{0}, t_{1} ∈ T erm_{Σ}(X, V) are unifiable, then Φ(t_{0}) and Φ(t_{1}) are unifiable in T_{Σ^{u}}(X ∪ V_{0}).

Proof: Let σ ∈ Sub(Σ, X, V, V′) be a unifier for t_{0} and t_{1}. Let σ′ be a substitution in T_{Σ^{u}}(X ∪ V_{0}) with σ′(α) := σ(α) for all α ∈ X and σ′(x) := Φ(t) for all x:τ ∈ V with σ(x:τ) = t:σ(τ). It is straightforward to show (by induction on the size of terms) that σ|_{T_{H}(X)} = σ′|_{T_{H}(X)} and σ′(Φ(t)) = Φ(σ(t)) for all t ∈ T erm_{Σ}(X, V). Therefore σ′(Φ(t_{0})) = Φ(σ(t_{0})) = Φ(σ(t_{1})) = σ′(Φ(t_{1})).

Lemma 9.19 Let V ⊆_{U} V ar_{Σ,X}, V_{0} := uvar(V) and t_{0}, t_{1} ∈ T erm_{Σ}(X, V). If Φ(t_{0}) and Φ(t_{1}) are unifiable in T_{Σ^{u}}(X ∪ V_{0}), then t_{0} and t_{1} are unifiable.

Proof: Let Φ(t_{0}) and Φ(t_{1}) be unifiable in T_{Σ^{u}}(X ∪ V_{0}). By theorem 4.4, a most general unifier in T_{Σ^{u}}(X ∪ V_{0}) can be computed by the algorithm “mgu”. We show by induction on the computation steps the following property of the computed substitutions σ_{i} in the algorithm “mgu”:

Let W_{i} := {x:σ_{i}(τ) | x:τ ∈ V }, t ∈ T erm_{Σ}(X, V). Then σ_{i}(Φ(t)) ∈ Φ(T erm_{Σ}(X, W_{i})).

For i = 0, we have W_{0} = V and σ_{0}(Φ(t)) = Φ(t). Let i > 0 and σ_{i−1}(Φ(t)) ∈ Φ(T erm_{Σ}(X, W_{i−1})) for all t ∈ T erm_{Σ}(X, V). By the algorithm “mgu”, σ_{i} = {v/u} ∘ σ_{i−1} for a v ∈ V_{0} ∪ X and u ∈ T_{Σ^{u}}(X ∪ V_{0}). a) v ∈ X: Since σ_{i−1}(Φ(t_{0})), σ_{i−1}(Φ(t_{1})) ∈ Φ(T erm_{Σ}(X, W_{i−1})), it must be u ∈ T_{H}(X)

since in Φ(T erm_{Σ}(X, W_{i−1})) type expressions occur always as the second argument of a ‘:’-term. It is straightforward to show that {v/u}(Φ(t)) ∈ Φ(T erm_{Σ}(X, W_{i})) for all t ∈ T erm_{Σ}(X, W_{i−1}).

b) v ∈ V_{0}: Since σ_{i−1}(Φ(t_{0})), σ_{i−1}(Φ(t_{1})) ∈ Φ(T erm_{Σ}(X, W_{i−1})), v:τ_{v} (for a τ_{v} ∈ T_{H}(X)) and u:τ_{v} ∈ Φ(T erm_{Σ}(X, W_{i−1})) or the subterms f(…, v, …):τ and f(…, u, …):τ must occur at the same position in σ_{i−1}(Φ(t_{0})) and σ_{i−1}(Φ(t_{1})). In the latter case f is a type preserving function with f:τ_{f} ∈ F unc and there exists σ, σ′ ∈ T S(H, X) with σ(τ_{f}) = τ_{1}, …, τ_{n} → τ and σ′(τ_{f}) = τ′_{1}, …, τ′_{n} → τ, whereas f(…, v:τ_{j}, …) and f(…, u′:τ′_{j}, …) are the corresponding subterms in σ_{i−1}(t_{0}) and σ_{i−1}(t_{1}). Let τ_{f} = ρ_{1}, …, ρ_{n} → ρ and X′ = tvar(ρ). Since σ(ρ) = τ = σ′(ρ), it follows σ|_{T_{H}(X′)} = σ′|_{T_{H}(X′)} and σ(ρ_{j}) = σ′(ρ_{j}) (since tvar(ρ_{j}) ⊆ tvar(ρ)). Thus τ_{j} = τ′_{j} is true and f(…, v:τ_{j}, …) and f(…, u′:τ_{j}, …) are the corresponding subterms in σ_{i−1}(t_{0}) and σ_{i−1}(t_{1}) with Φ(u′) = u. Therefore v:τ_{j} ∈ W_{i−1} and u:τ_{j} ∈ Φ(T erm_{Σ}(X, W_{i−1})). Now it is straightforward to show that {v/u}(Φ(t)) ∈ Φ(T erm_{Σ}(X, W_{i})) for all t ∈ T erm_{Σ}(X, W_{i−1}) since W_{i} = W_{i−1}.

By induction hypothesis and a) and b), it follows σ_{i}(Φ(t)) ∈ Φ(T erm_{Σ}(X, W_{i})) for all t ∈ T erm_{Σ}(X, V). Since Φ(t_{0}) and Φ(t_{1}) are unifiable in T_{Σ^{u}}(X ∪ V_{0}), the algorithm “mgu” stops with an mgu σ_{k} and σ_{k}(Φ(t)) ∈ Φ(T erm_{Σ}(X, W_{k})) for all t ∈ T erm_{Σ}(X, V). By lemma 9.17, for each t ∈ T erm_{Σ}(X, V) there exists a unique term t′ ∈ T erm_{Σ}(X, W_{k}) with Φ(t′) = σ_{k}(Φ(t)). Hence we can define a typed substitution σ ∈ Sub(Σ, X, V, V′) with σ(α) = σ_{k}(α) for all α ∈ X and σ(x:τ) = t′ for all x:τ ∈ V, whereas t′ ∈ T erm_{Σ}(X, W_{k}) with Φ(t′) = σ_{k}(Φ(x:τ)). It is easy to show (by induction on the size of terms) that Φ(σ(t)) = σ_{k}(Φ(t)) for all t ∈ T erm_{Σ}(X, V). Therefore Φ(σ(t_{0})) = σ_{k}(Φ(t_{0})) = σ_{k}(Φ(t_{1})) = Φ(σ(t_{1})). By lemma 9.17, it follows σ(t_{0}) = σ(t_{1}), i.e., σ is a unifier for t_{0} and t_{1}.

Theorem 9.20 (Optimized unification for type preserving functions) Let V ⊆_{U} V ar_{Σ,X}, V_{0} := uvar(V) and t_{0}, t_{1} ∈ T erm_{Σ}(X, V). t_{0} and t_{1} are unifiable iff Φ(t_{0}) and Φ(t_{1}) are unifiable in T_{Σ^{u}}(X ∪ V_{0}). A most general unifier for t_{0} and t_{1} can be computed from a most general unifier in T_{Σ^{u}}(X ∪ V_{0}).

Proof: If t_{0} and t_{1} are not unifiable, then Φ(t_{0}) and Φ(t_{1}) are not unifiable in T_{Σ^{u}}(X ∪ V_{0}) by lemma 9.19. If t_{0} and t_{1} are unifiable, then Φ(t_{0}) and Φ(t_{1}) are unifiable in T_{Σ^{u}}(X ∪ V_{0}) by lemma 9.18. By theorem 4.4, a most general unifier for Φ(t_{0}) and Φ(t_{1}) in T_{Σ^{u}}(X ∪ V_{0}) can be computed, which can be transformed into a unifier for t_{0} and t_{1} (see proof of lemma 9.19). By the proof of lemma 9.18, this corresponds to a most general unifier for t_{0} and t_{1}.

The optimized unification can be extended to atoms if we interpret each predicate p:τ_{1}, …, τ_{n} ∈ P red as a function symbol with declaration p:τ_{1}, …, τ_{n} → bool and delete the result type bool in the unification. Therefore the optimized unification can be integrated in the resolution method defined in chapter 5. The optimization for type preserving functions cannot be used in the narrowing procedure because in the narrowing rule the left-hand side of a conditional equation is unified with any subterm in a goal. But in general Φ(f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ) = f(Φ(t_{1}:τ_{1}), …, Φ(t_{n}:τ_{n})):Φ(τ) is not true, and therefore theorem 9.20 cannot be applied to the narrowing rule. Example: Assume the following specification is given:

type int/0 func 1: → int func f: int → int clauses: f(1:int):int ≡ 1:int ←

A narrowing sequence for the goal f(f(1:int):int):int ≡ 1:int without any type optimization is:

f(f(1:int):int):int ≡ 1:int
⊢_{GN} f(1:int):int ≡ 1:int
⊢_{GN} 1:int ≡ 1:int
⊢_{GN} ∅

The function f is type preserving. If we apply Φ to the specification and the goal, we obtain the optimized clause

f(1):int ≡ 1:int ←

and the goal f(f(1)):int ≡ 1:int. The narrowing rule is not applicable in this optimized case because the subterm f(1) of the goal and the left-hand side f(1):int of the conditional equation are not unifiable. Relational specifications are the same as Horn clause programs with polymorphic types. [Mycroft/O’Keefe 84] have defined a particular subclass of these programs for which type-checking is unnecessary at run time. Their restrictions are:

1. All functions are type-preserving [Mycroft 87].

2. If p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) ← G is a programs clause and predicate p is defined with type τ_{p}, then τ_{1}, …, τ_{n} and τ_{p} are equivalent.

The next proposition shows an important property of the left-hand side of program clauses for that case:

Proposition 9.21 (Mycroft/O’Keefe-polymorphism) Let (Σ, C) be a polymorphic logic program and V ⊆_{U} V ar_{Σ,X}, where Σ contains only type preserving functions. If L = p(t_{1}:τ_{1}, …, t_{n}:τ_{n}) is a (Σ, X, V)-atom with p:τ_{p} ∈ P red and τ_{p} and τ_{1}, ..., τ_{n} are equivalent, then L is type general.

Proof: Let L′ = p(r_{1}:ρ_{1}, …, r_{n}:ρ_{n}) be a (Σ, X, V)-atom unifiable with L and tvar(L) ∩ tvar(L′) = ∅. Since τ_{p} and τ_{1}, …, τ_{n} are equivalent, there exists a type substitution ϕ ∈ T S(H, X) with ϕ(τ_{1}, …, τ_{n}) = τ_{p}. There exists another type substitution ϕ′ ∈ T S(H, X) with ϕ′(τ_{p}) = ρ_{1}, …, ρ_{n}. Therefore (ϕ′∘ϕ)(τ_{1}, …, τ_{n}) = ρ_{1}, …, ρ_{n}. We assume without loss of generality that ϕ′∘ϕ alters only type variables of τ_{1}, …, τ_{n}. Then ϕ′∘ϕ is an mgu for ρ_{1}, …, ρ_{n} and τ_{1}, …, τ_{n}. Let σ ∈ Sub(Σ, X, V, V′) with σ|_{T_{H}(X)} = ϕ′ ∘ ϕ and σ(x:τ) = x:σ(τ) for all x:τ ∈ V. Then σ(t_{i}:τ_{i}) = t′_{i}:ρ_{i}, where t_{i} and t′_{i} differ only in their types. By theorem 9.20, types are unnecessary for the unification of t′_{i}:ρ_{i} and r_{i}:ρ_{i}. Since the two terms have the same type, the computation of a most general unifier with the algorithm “mgu” has no influence on the type variables in ρ_{i}. Hence there exists a unifier σ′ for L and L′ with σ′(α) = α for all α ∈ tvar(L′), i.e., L is type general.

By this proposition, all predicates in a polymorphic logic program with the restrictions of [Mycroft/O’Keefe 84] are type-generally defined, i.e., type annotations are unnecessary during the resolution of a Σ-goal by theorem 9.9. Therefore the type system of Mycroft/O’Keefe is a special case of our work because:

1. Every polymorphic logic program in the sense of Mycroft/O’Keefe is a relational specification in our sense.

2. If we use the optimization techniques developed in this chapter, polymorphic logic programs in the sense of Mycroft/O’Keefe can be executed with the same efficiency as untyped Prolog programs.

On the other hand, our work is a proper extension of Mycroft/O’Keefe’s type system because we have no restrictions on the use of polymorphic predicates in the heads of clauses, and we have no restrictions on the use of type variables in function types (compare examples in chapter 1). For instance, the predicate isTrue in the evaluator of Boolean terms (cf. page 15) is type-generally defined and therefore resolution can be done with the same efficiency as in untyped logic programming, but it is not a well-typed program in the sense of [Mycroft/ O’Keefe 84]. Mycroft and O’Keefe have proposed to extend polymorphic Horn clause programs by a family of predefined apply predicates to permit higher-order programming. But this extension is only necessary because of the restrictions in their type system. In our framework it is possible to simulate higher-order programming techniques without any conceptual extensions. This will be shown in the next chapter.

Higher-order programming

A programming technique in functional languages is the application of higher-order functions. These are functions that take other functions as arguments or produce other functions as results. The usage of higher-order functions leads to smaller and more readable programs. Logic programming languages permit higher-order programming as well: For example, the Prolog predicate call interprets the input term as a predicate call. [Mycroft/O’Keefe 84] argue that for most practical purposes it is sufficient to have a predicate apply that takes something like a predicate name and a list of argument terms as input and that is satisfied if the corresponding predicate applied to the argument terms is provable. Hence they introduce a family of predefined predicates apply (one predicate for each arity) and a lambda notation for terms of predicate type, but they present only an informal definition of the meaning of

apply.

[Aït-Kaci/Lincoln/Nasr 87] have proposed an untyped language with functions and relations which permits higher-order functions. Although they have presented an operational semantics for this language based on delayed evaluation of expressions, a declarative semantics is not defined. Generally, a semantically clean amalgamation of higher-order functions with logic programming techniques like unification is not trivial since the unification of higher-order terms is undecidable in general [Goldfarb 81]. [Miller/Nadathur 86] have defined an extension of firstorder Horn clause logic to include predicate and function variables based on the typed lambda calculus. For the operational semantics it is necessary to unify typed lambda expressions, which leads to a complex and semi-decidable unification [Huet 75] [Snyder/Gallier 88]. Hence they have a system with a clearly defined underlying logic, their proof procedure is sound and complete for goals without type variables, but the proof procedure is costly because of the unification of typed lambda expressions. [Warren 82] argues that no extension to Prolog or to the underlying first-order logic is necessary because the usual higher-order programming techniques can be simulated in first-order logic. Since he is concerned with Prolog and its untyped logic, he does not have a clear distinction between first-order and higher-order objects. We suggest a ‘middle road’ approach to higher-order programming: To have an efficient operational semantics, we keep first-order logic as our theoretical framework. But we want to deal with higher-order objects in the sense of computing and distinguish between higher-order and first-order objects. Since we have an unrestricted mechanism of polymorphic types, we may integrate these higher-order programming techniques without any extensions to our concept of polymorphic specifications (in contrast to [Mycroft/O’Keefe 84]). We demonstrate this by some examples. Our first example defines the well-known function map. The higher-order function map takes a function and a list as an argument and applies the function to each element of the list. In order to define the type of map we introduce a type constructor ‘⇒’ of arity 2 that denotes the types of functional expressions. The type of map is

func map: (α ⇒ β), list(α) → list(β)

(for convenience we use the infix notation for the type constructor ‘⇒’). For each function f of type τ_{1} → τ_{2} (i.e., a function with one argument of type τ_{1} and a result of type τ_{2}) we introduce a corresponding functional constant λf of type (τ_{1} ⇒ τ_{2}). The relation between each function f and the functional constant λf is defined by clauses for the function apply. Hence we get the following example specification of the function map (we use the Prolog notation for lists and define a function not that negates a Boolean value and a function inc that increments a natural number):

type bool/0, nat/0, list/1, ⇒/2
func true : → bool
func false : → bool
func z : → nat
func s : nat → nat
func [] : → list(α)
func • : α, list(α) → list(α)
func map : (α ⇒ β), list(α) → list(β)
func not : bool → bool
func inc : nat → nat
func λnot : → (bool ⇒ bool)
func λinc : → (nat ⇒ nat)

func apply : (α ⇒ β), α → β

clauses:

     map( ,[]) ≡ [] ←
     map(F,[E|L]) ≡ [apply(F,E)|map(F,L)] ←
     not(true) ≡ false ←
     not(false) ≡ true ←
     inc(N) ≡ s(N) ←
     apply(λnot,B) ≡ not(B) ←
     apply(λinc,N) ≡ inc(N) ←

(We omit the type annotations in the clauses.) If we want to prove the goal

     map(λinc,[z,s(s(z))]) ≡ L

we get the answer substitution

     L = [s(z),s(s(s(z)))]

by the most general narrowing calculus. The above specification does not ensure that the constant λinc is interpreted as a function in every model since we require only first-order structures as interpretations for polymorphic specifications. But the last clause ensures that in any model the constant λinc and the function inc are related together. A similar solution to logic programming with higher-order functions was proposed by [Smolka 86a]. In his language Fresh higher-order functional programming is combined with unification. To avoid the difficulties with higher-order unification, he associates a name with each function and defines equality between functions as identity of associated names. This is similar to our approach except that Fresh is an untyped language. Our second example deals with higher-order predicates and predicate variables. We present a specification for a predicate have property whose first argument must be a unary predicate and whose second argument must be a list. have property(P,L) is satisfied if predicate P is true for all elements of list L. To define the type of have property we introduce a type constructor pred1 of arity 1 that denotes the type of all unary predicate expressions. Then we may declare the type of have property by

pred have property: pred1(α), list(α) For each unary predicate symbol p of type τ we declare a corresponding constant λp of type pred1(τ). Similarly to the first example, the relation between each unary predicate p and predicate constant λp is defined by clauses for the predicate apply1. The following specification is a complete example for the definition and an application of have property.

type nat/0, int/0, list/1, pred1/1 func z : → nat func s : nat → nat func + : nat → int func - : nat → int func [] : → list(α) func • : α, list(α) → list(α) func λis nat: → pred1(int) pred have property: pred1(α), list(α) pred is nat: int pred apply1: pred1(α), α

clauses:

-(z) ≡ +(z) ←
have property(P,[]) ←
have property(P,[E|L]) ← apply1(P,E), have property(P,L)
is nat(+(N)) ←
apply1(λis nat,Z) ← is nat(Z)

Note that the last clause is well-typed in our sense but not well-typed in the sense of [Mycroft/ O’Keefe 84], because apply1 is declared with polymorphic type “pred1(α), α” but used in the clause with monomorphic type “pred1(int), int”.

By this specification, the goal

     have property(λis nat,[+(s(z)),-(z),+(s(s(z)))])

is provable by most general narrowing. Another example is the list specification in chapter 1 on page 16. There a higher-order function max is defined to compute the maximum element of a list. max takes a binary predicate that represents the relation “less than or equal to” as an argument and uses the predicate apply2 for the application of a binary predicate variable to two appropriate terms. The examples in this chapter have shown the possibility to deal with higher-order objects in our framework. Higher-order objects are related to functions and predicates by particular clauses for an apply function or predicate. It is also possible to permit lambda expressions, which can be translated into new identifiers and apply clauses for these identifiers (see [Warren 82] for more discussion). If the underlying system implements indexing on the clauses [Wise/Powers 84], e.g., indexing on the first arguments of predicates (as done in most compilers for Prolog, cf. [Warren 83] and [Hanus 88a]), then there is no essential loss of efficiency in our translation scheme for higher-order objects in comparison to a specific implementation of higher-order objects [Warren 82]. The compilation of higher-order functions into first-order logic was also proposed by [Bosco/ Giovannetti 86], but they perform type-checking only for the source program and not for the target program. Clearly, the target program is not well-typed in the sense of [Mycroft/O’Keefe 84] because of the clauses for the apply predicate (see above). Since we have translated higher-order objects into polymorphic specifications, the use of higher-order objects is type secure in our framework. We have similar typing rules as in functional languages [Damas/Milner 82], i.e., a function or predicate is only called with appropriate arguments at run time. If we look at the map specification in this chapter, we see that ‘≡’ is not type-generally defined. Hence the optimization techniques presented in chapter 9 cannot be applied and therefore types cannot be omitted at run time in contrast to pure functional languages like ML. In our framework the presence of types is necessary because we do not require that all terms must be ground at run time. For instance, assume that the map specification is given and the following goal should be solved:

     map(F,[N1]) ≡ [N2],  apply(F,z) ≡ N

If we omit all type annotations and use the most general narrowing calculus with untyped unification, we may prove the first atom in the goal by replacing F by λnot, N1 by true, and N2 by false. So we are left with the remaining goal

     apply(λnot,z) ≡ N

which is ill-typed because λnot and z have types bool ⇒ bool and nat, respectively. If the types are not omitted in the narrowing procedure, then variable F (of type nat ⇒ nat) cannot be replaced by λnot (of type bool ⇒ bool) because of the incompatibility of the types. This example shows that, in general, types are necessary at run time for a correct derivation. But there are cases where types can be omitted also in the map specification (e.g., if the first argument of the map function is always ground). The characterization of such cases will be a topic for future research.

Implementation

This chapter discusses some details of the implementation of a proof system for polymorphic specifications. There are two interesting topics: Type checking and the operational semantics of polymorphic specifications.

11.1 Type checking

In the clauses of a polymorphic specification every variable and function symbol is annotated with a type expression. For practical purposes these type expressions need not be explicitly stated: If a polymorphic signature and a clause without type annotations are given, it is possible to infer the principal type for all variable and function symbol occurrences in the clause. This can be done with the technique of [Damas/Milner 82]. The definitions of section 1.3 can be equivalently expressed by the following inference rules (Σ = (H, F unc, P red) is a polymorphic signature, X is a set of type variables and V ⊆_{U} V ar_{Σ,X} is a set of typed variables):

V ar:  \overline{(Σ, X, V) |⊧ x:τ}  (x:τ ∈ V)
F unc:  \frac{(Σ, X, V) |⊧ t_{1}:τ_{1}, …, (Σ, X, V) |⊧ t_{n}:τ_{n}}{(Σ, X, V) |⊧ f(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ} (f:τ_{1}, …, τ_{n} → τ ∈ F unc_{T_{H}(X)}, n ≥ 0)
P red:  \frac{(Σ, X, V) |⊧ t_{1}:τ_{1}, …, (Σ, X, V) |⊧ t_{n}:τ_{n}}{(Σ, X, V) |⊧ p(t_{1}:τ_{1}, …, t_{n}:τ_{n})} (p:τ_{1}, …, τ_{n} ∈ P red_{T_{H}(X)}, n ≥ 0)
Clause:  \frac{(Σ, X, V) |⊧ L_{0}, …, (Σ, X, V) |⊧ L_{n}}{(Σ, X, V) |⊧ L_{0} ← L_{1}, …, L_{n}}  (L_{0}, …, L_{n} are (Σ, X, V)-atoms)

A polymorphic specification consists of a polymorphic signature Σ and a set C so that the members of C have the form L ← G with the property (Σ, X, V) |⊧ L ← G for some set V ⊆_{U} V ar_{Σ,X}. This inference system is a special case of the one presented in [Damas/Milner 82]. Therefore we can use their type checker with small adaptations. The unification of two type expressions is the basic operation in the type checker. The realization of the type checker is quite simple if we use Prolog as an implementation language.

11.2 Operational semantics

We have proved that the narrowing procedure with most general polymorphic unifiers is sound and complete for polymorphic specifications which are Church-Rosser and satisfy some restrictions on the variables in the clauses. Hence the narrowing procedure is the basis of an operational semantics for polymorphic specifications. In order to be complete, all possible narrowing derivations for a goal must be computed in parallel, but such an implementation is not useful for practical purposes. In this thesis we are mainly interested in a semantically clear foundation of programming with functions and relations with polymorphic types, and therefore we give only some hints for the implementation. Many authors have investigated implementations of languages with functions and relations. In this thesis, we have been able to prove many results from manysorted Horn logic with equality also for the polymorphic case if polymorphic unifiers are used. Hence it may be possible to transfer other results needed for efficient implementations to the polymorphic case. The TEL system [Smolka 88] is an implementation of a language with functions, relations, subtypes and polymorphic types. But the use of functions and relations is restricted so that an efficient implementation is possible. Functions are executed by rewriting instead of narrowing. In order to check the groundness of all function calls at compile time, all predicates must be declared with fixed input and output arguments. To have the possibility of goal solving with logical variables, open variables can be declared, but open variables have another behaviour than appropriate terms in the unification procedure. The explicit data flow declarations in TEL are an unsatisfactory solution from a theoretical point of view, and therefore this is only a first approach of an implementation of such a language. SLOG [Fribourg 84] [Fribourg 85] is an interpreter of a many-sorted Horn clause language where equality is the only predicate. Goals are proved by most general narrowing with a socalled innermost strategy: Following the terminology of [Huet/Hullot 82], the function symbols are partitioned into a set of constructors and defined operators. An innermost term is a term of the form f(t_{1}, …, t_{n}) where f is a defined function and all t_{i}’s are formed of variables and constructors. In a narrowing step, the subterm in the goal which is unified with the left-hand side of a conditional equation must be an innermost term. Fribourg has given sufficient criteria for the completeness of the innermost narrowing strategy. SLOG uses an SLD-like strategy for proving goals. In a narrowing step, an innermost subterm of the leftmost atom of the goal is selected. The body of the applied conditional equation is inserted at the beginning of the goal so that at first the conditions have to be proved in subsequent computation steps. The SLOG interpreter uses a backtracking strategy and selects the leftmost innermost subterm of the goal in each computation step. Our implementation of polymorphic specifications is based on the innermost strategy. First of all, the function symbols are divided into a set of constructors and a set of defined operators that we also call defined functions. A function symbol is a defined function if it is the top symbol of the left-hand side of some conditional equation, otherwise it is a constructor (this definition is sufficient for our purposes). A computation step from one goal to the next goal is done as follows (in our implementation, goals are treated as lists of atoms): Let G be the goal L_{1}, …, L_{n}.

1. (Flattening of constructor equations) If L_{1} is of the form

f(r_{1}:ρ_{1}, …, r_{m}:ρ_{m}):ρ ≡ g(t_{1}:τ_{1}, …, t_{n}:τ_{n}):τ

and f and g are constructors, then:

If f = g and m = n and there exists a most general unifier σ for ρ and τ, then

σ(r_{1}:ρ_{1}) ≡ σ(t_{1}:τ_{1}), …, σ(r_{m}:ρ_{m}) ≡ σ(t_{n}:τ_{n}), σ(L_{2}), …, σ(L_{n})

is the next goal, otherwise: fail.

otherwise:

2. (Narrowing rule) If there exist an occurrence π ∈ O(L_{1}), a conditional equation v ≡ w ← R_{1}, …, R_{m} and a typed substitution σ with

(a) L_{1}[π] is an innermost term and

(b) σ is a most general unifier for L_{1}[π] and v,

then

σ(R_{1}), …, σ(R_{m}), σ(L_{1})[π ← σ(w)], σ(L_{2}), …, σ(L_{n})

is the next goal, otherwise:

3. (Unification rule) If L_{1} = v ≡ w and there exists a most general unifier σ for v and

w, then

σ(L_{2}), …, σ(L_{n})

is the next goal, otherwise:

4. (Restricted resolution rule) If there exist a relational clause L ← R_{1}, …, R_{m} and a most general unifier σ for L_{1} and L, then

σ(R_{1}), …, σ(R_{m}), σ(L_{2}), …, σ(L_{n})

is the next goal, otherwise: fail.

Case 1 treats equations where the top symbol on each side is a constructor. Since there are no equations with a constructor as the top symbol on the left-hand side, such equations are provable iff the constructors are identical and the arguments are equal w.r.t. the specification. This case prevents many infinite computations. Case 2, 3 and 4 are applications of the narrowing rule to an innermost term, the unification rule and the restricted resolution rule, respectively. Alternative computations are handled by a backtracking strategy. The most general unifiers are computed as shown in chapter 4, i.e., type annotations are treated as first-order terms. There is also a static analyser that checks whether the specification has particular restrictions and type annotations can be omitted at run time (cf. chapter 9). The interpreter is completely implemented in Prolog. The overall structure is sketched in figure 11.1 on page 134. The following example shows a polymorphic specification of the higher-order function map (cf. example on page 125). The predefined equality predicate ‘≡’ is denoted by the infix operator ‘=’. The input to the system is:

     type nat/0, list/1, (->)/2.
     func z      :     --> nat.
     func s      : nat --> nat.
     func []     :            --> list(A).
     func '.'    : A, list(A) --> list(A).
     func map    : (A -> B), list(A) --> list(B).
     func inc    : nat --> nat.
     func f_inc  : --> (nat -> nat).
     func inclist: list(nat) --> list(nat).
     func apply  : (A -> B), A --> B.

     clauses.

Reading type declarations

Reading and type checking clauses, translating to Prolog terms

Analysing the clauses and omitting type annotations, where possible

Reading and type-checking a goal, translating to a Prolog term

Proving the goal

Figure 11.1: Structure of the interpreter for polymorphic specifications

     map(_,[]) = [].
     map(F,[E|L]) = [apply(F,E)|map(F,L)].
     inc(N) = s(N).
     inclist(L) = map(f_inc,L).
     apply(f_inc,N) = inc(N).

After reading and analysing this specification, the interpreter may prove goals. It follows a trace of the proof of the goal inclist([s(s(z)),z])=L. Type annotations are marked by the infix operator ‘::’. In order to keep typed goals small and readable, only the types of predicate arguments are shown by default. But it is also possible to show all type annotations of subterms.

     Goal? inclist([s(s(z)),z]) = L.
     0: inclist([s(s(z)),z])::list(nat) = A::list(nat).
     1: map(f_inc,[s(s(z)),z])::list(nat) = A::list(nat).
     2: [apply(f_inc,s(s(z)))|map(f_inc,[z])]::list(nat) = A::list(nat).
     3: [inc(s(s(z)))|map(f_inc,[z])]::list(nat) = A::list(nat).
     4: [s(s(s(z)))|map(f_inc,[z])]::list(nat) = A::list(nat).
     5: [s(s(s(z))),apply(f_inc,z)|map(f_inc,[])]::list(nat) = A::list(nat).
     6: [s(s(s(z))),inc(z)|map(f_inc,[])]::list(nat) = A::list(nat).
     7: [s(s(s(z))),s(z)|map(f_inc,[])]::list(nat) = A::list(nat).
     8: [s(s(s(z))),s(z)]::list(nat) = A::list(nat).
     This goal is valid wrt the current specification:
     inclist([s(s(z)),z])::list(nat) = [s(s(s(z))),s(z)]::list(nat).

Since the interpreter uses a backtracking strategy, it does not implement a complete proof system for polymorphic specifications. But it is sufficient for many practical problems. All example specifications in this thesis have been successfully executed by the interpreter.

11.3 Efficiency improvements

If we use polymorphic specifications in a functional programming style, i.e., the left-hand side of each conditional equation and the head of each relational clause has the most general type w.r.t. the declaration, then all type annotations can be omitted at run time (cf. theorem 9.9). Hence goal proving with polymorphic specifications has the same efficiency as goal proving in untyped Horn logic with equality. On the other hand, we need not define the predicates and functions by clauses where the left-hand side is type general. In contrast to other type systems, it is possible to define clauses for special cases in our type system. Such clauses can be used to reduce the search space in the narrowing process. Therefore the unification with types may be more efficient than in the untyped case. This is demonstrated by the following example:

type τ_{1}/0, τ_{2}/0
func f_{1}, …, f_{m}: → τ_{1}
func g_{1}, …, g_{n}: → τ_{2}
pred t: α

pred t1: τ_{1} pred t2: τ_{2}

clauses:

t(X:τ_{1}) ← t1(X:τ_{1})
t(Y:τ_{2}) ← t2(Y:τ_{2})

t1(f_{1}:τ_{1}) ← ⋯ t1(f_{m}:τ_{1}) ← t2(g_{1}:τ_{2}) ← ⋯ t2(g_{n}:τ_{2}) ←

This specification contains no conditional equations and therefore the narrowing rule is not needed. We want to prove the goal

t(Z:τ_{2}), Z:τ_{2} ≡ g_{i}:τ_{2}

If we omit all type annotations and use the Prolog backtracking strategy, then the goal is proved in m + i + 2 steps. If we use our interpreter and the types are not omitted, i.e., the unification considers the types of terms, then the goal is proved in i + 1 steps since the first clause of the predicate t cannot be applied. Therefore, type information may be useful to reduce the search space in the narrowing process. This is also true for order-sorted specifications. E.g., [Schmidt-Schauss 85] and [Huber/Varsek 87] have shown examples in order-sorted logic where typed unification leads to more efficient proofs than in untyped logic.

Conclusions

We have presented a polymorphic type system for Horn clause logic with equality. This may help to obtain a better amalgamation of functional and logic programming. The typing rules are quite simple: Each variable has a fixed type and each type instantiation of a polymorphic function or predicate can be used inside a clause if the result types of the argument terms are equal to the argument types. The semantics of polymorphic types is defined as a universal quantification over all possible types. We have shown that this semantics leads to similar results as in the untyped or many-sorted case: An initial model can be constructed as the quotient of the ground term interpretation by a congruence relation generated by the equality axioms. The Horn clause calculus can be extended to the polymorphic case if substitutions are replaced by typed substitutions. The other well-known proof methods for Horn logic with equality (resolution with equality axioms, paramodulation with functional-reflexive axioms, narrowing) can also be extended to the polymorphic case if the unification considers the types of terms. Hence our polymorphic specifications are related to “constraint logic programming” [Jaffar/Lassez 87], where the equality theory and the consideration of types corresponds to constraints. We have also shown that the unification can disregard types if declarations and clauses have a particular form. In that case the proof method has the same efficiency as in the untyped case. On the other hand, type information is useful to reduce the search space in the proof process. Thus there are examples where the unification with types leads to more efficient proofs than in the untyped case. In our type system it is allowed to have clauses where the left-hand side is not of the most general type. We have shown that this permits the application of higher-order programming techniques without breaking our type system. Since some proposals of modules for logic programming are based on (untyped) higher-order logic, it may be possible to use our type system to improve the security of module systems by specifying the types of interfaces with polymorphic functions and predicates (see [Chen 87], [Miller 86] and [Goguen/Meseguer 86] for some proposals of modules for logic programming). Further work remains to be done. If the narrowing process uses the standard Prolog leftto-right strategy, then further optimizations could be done to reduce the cases where type information is required for correct unification. Abstract interpretation techniques [Abramsky/ Hankin 87] may help to get necessary informations about the specification. If the modes of predicates are known, then there are further possibilities to omit type annotations [Dietrich/ Hagl 88]. The extension of our polymorphic type system to subtyping and inheritance would be useful.

Bibliography

[Abramsky/Hankin 87] S. Abramsky and C. Hankin, editors. Abstract Interpretation of Declarative Languages. Ellis Horwood, 1987.

[Aït-Kaci/Lincoln/Nasr 87] H. Aït-Kaci, P. Lincoln, and R. Nasr. Le Fun: Logic, equations, and Functions. In Proc. 4th IEEE Internat. Symposium on Logic Programming, pp. 17–23, San Francisco, 1987.

[Aït-Kaci/Nasr 86] H. Aït-Kaci and R. Nasr. LOGIN: A Logic Programming Language with Built-In Inheritance. Journal of Logic Programming (3), pp. 185–215, 1986.

[Apt/van Emden 82] K.R. Apt and M.H. van Emden. Contributions to the Theory of Logic Programming. Journal of the ACM, Vol. 29, No. 3, pp. 841–862, 1982.

[Barbuti et al. 86] R. Barbuti, M. Bellia, G. Levi, and M. Martelli. LEAF: a Language which Integrates Logic, Equations and Functions. In D. DeGroot and G. Lindstrom, editors, Logic Programming, Functions, Relations, and Equations, pp. 201–238. Prentice Hall, 1986.

[Barendregt 81] H.P. Barendregt. The Lambda Calculus. North-Holland, Amsterdam, 1981.

[Bellia/Levi 86] M. Bellia and G. Levi. The Relation between Logic and Functional Languages: A Survey. Journal of Logic Programming (3), pp. 217–236, 1986.

[Bertling/Ganzinger 88] H. Bertling and H. Ganzinger. Completion-Time Optimization of Rewrite-Time Goal Solving. FB Informatik, Univ. Dortmund, 1988. To appear in Proc. RTA-89.

[Bidoit/Corbin 83] M. Bidoit and J. Corbin. A Rehabilitation of Robinson’s Unification Algorithm. In Proc. IFIP ’83, pp. 909–914. North-Holland, 1983.

[Bockmayr 86] A. Bockmayr. Conditional rewriting and narrowing as a theoretical framework for logic-functional programming. Technical Report 10/86, Univ. Karlsruhe, 1986.

[Bosco/Giovannetti 86] W. Bosco and E. Giovannetti. IDEAL: An Ideal Deductive Applicative Language. In Proc. IEEE Internat. Symposium on Logic Programming, pp. 89–94, Salt Lake City, 1986.

[Burstall/MacQueen/Sannella 80] R.M. Burstall, D.B. MacQueen, and D.T. Sannella. HOPE: An Experimental Applicative Language. In Conference Record of the 1980 LISP Conference, pp. 136–143. ACM, 1980.

[Chen 87] W. Chen. A Theory of Modules Based on Second-Order Logic. In Proc. 4th IEEE Internat. Symposium on Logic Programming, pp. 24–33, San Francisco, 1987.

[Church 40] A. Church. A formulation of the simple theory of types. Journal of Symbolic Logic, Vol. 5, pp. 56–68, 1940.

[Clocksin/Mellish 87] W.F. Clocksin and C.S. Mellish. Programming in Prolog. Springer, third rev. and ext. edition, 1987.

[Damas/Milner 82] L. Damas and R. Milner. Principal type-schemes for functional programs. In Proc. 9th POPL, pp. 207–212, 1982.

[DeGroot/Lindstrom 86] D. DeGroot and G. Lindstrom, editors. Logic Programming, Functions, Relations, and Equations. Prentice Hall, 1986.

[Dershowitz/Plaisted 85] N. Dershowitz and D.A. Plaisted. Logic Programming cum Applicative Programming. In Proc. IEEE Internat. Symposium on Logic Programming, pp. 54–66, Boston, 1985.

[Dietrich/Hagl 88] R. Dietrich and F. Hagl. A polymorphic type system with subtypes for Prolog. In Proc. ESOP 88, Nancy, pp. 79–93. Springer LNCS 300, 1988.

[Dincbas/van Hentenryck 87] M. Dincbas and P. van Hentenryck. Extended Unification Algorithms for the Integration of Functional Programming into Logic Programming. Journal of Logic Programming (4), pp. 199–227, 1987.

[Ehrig/Mahr 85] H. Ehrig and B. Mahr. Fundamentals of Algebraic Specification 1: Equations and Initial Semantics, volume 6 of EATCS Monographs on Theoretical Computer Science. Springer, 1985.

[Fay 79] M.J. Fay. First-Order Unification in an Equational Theory. In Proc. 4th Workshop on Automated Deduction, pp. 161–167, Austin (Texas), 1979. Academic Press.

[Fribourg 84] L. Fribourg. Oriented Equational Clauses as a Programming Language. Journal of Logic Programming (1), pp. 165–177, 1984.

[Fribourg 85] L. Fribourg. SLOG: A Logic Programming Language Interpreter Based on Clausal Superposition and Rewriting. In Proc. IEEE Internat. Symposium on Logic Programming, pp. 172–184, Boston, 1985.

[Furbach/Hölldobler/Schreiber 88] U. Furbach, S. Hölldobler, and J. Schreiber. Horn Equality Theories and Paramodulation. Technical Report 8801, Universität der Bundeswehr, München, 1988.

[Futatsugi et al. 85] K. Futatsugi, J.A. Goguen, J.-P. Jouannaud, and J. Meseguer. Principles of OBJ2. In Proc. of the 1985 ACM Symposium on Principles of Programming Languages, pp. 52–66, 1985.

[Gallier/Raatz 86] J.H. Gallier and S. Raatz. SLD-Resolution Methods for Horn Clauses with Equality Based on E-Unification. In Proc. IEEE Internat. Symposium on Logic Programming, pp. 168–179, Salt Lake City, 1986.

[Ganzinger 87] H. Ganzinger. A Completion Procedure for Conditional Equations. Technical Report 234, FB Informatik, Univ. Dortmund, 1987. Revised version to appear in J. of Symb. Computation.

[Giovannetti/Moiso 86] E. Giovannetti and C. Moiso. A completeness result for E-unification algorithms based on conditional narrowing. In Proc. Workshop on Foundations of Logic and Functional Programming, pp. 157–167. Springer LNCS 306, 1986.

[Goguen/Meseguer 84] J.A. Goguen and J. Meseguer. Completeness of Many-Sorted Equational Logic. Report No. CSLI-84-15, Stanford University, 1984.

[Goguen/Meseguer 86] J.A. Goguen and J. Meseguer. Eqlog: Equality, Types, and Generic Modules for Logic Programming. In D. DeGroot and G. Lindstrom, editors, Logic Programming, Functions, Relations, and Equations, pp. 295–363. Prentice Hall, 1986.

[Goguen/Thatcher/Wagner 78] J.A. Goguen, J.W. Thatcher, and E.G. Wagner. An Initial Algebra Approach to the Specification, Correctness, and Implementation of Abstract Data Types. In R. Yeh, editor, Current Trends in Programming Methodology, volume 4, pp. 80–149. Prentice Hall, Englewood Cliffs NJ, 1978.

[Goldfarb 81] W. Goldfarb. The Undecidability of the Second-Order Unification Problem. Theoretical Computer Science 13, pp. 225–230, 1981.

[Hanus 88a] M. Hanus. Formal Specification of a Prolog Compiler. In Proc. of the Workshop on Programming Language Implementation and Logic Programming, Orléans, 1988. To appear in Springer LNCS.

[Hanus 88b] M. Hanus. Horn Clause Programs with Polymorphic Types. Technical Report 248, FB Informatik, Univ. Dortmund, 1988.

[Harper 86] Robert Harper. Introduction to Standard ML. LFCS Report Series ECS-LFCS-86-14, University of Edinburgh, 1986.

[Horiuchi/Kanamori 87] K. Horiuchi and T. Kanamori. Polymorphic Type Inference in Prolog by Abstract Interpretation. In Logic Programming ’87 (Tokyo), pp. 195–214. Springer LNCS 315, 1987.

[Hsiang/Rusinowitch 86] J. Hsiang and M. Rusinowitch. A New Method for Establishing Refutational Completeness in Theorem Proving. In Proc. 8th Conference on Automated Deduction, pp. 141–152. Springer LNCS 230, 1986.

[Huber/Varsek 87] M. Huber and I. Varsek. Extended Prolog with Order-Sorted Resolution. In Proc. 4th IEEE Internat. Symposium on Logic Programming, pp. 34–43, San Francisco, 1987.

[Huet 75] G.P. Huet. A Unification Algorithm for Typed λ-Calculus. Theoretical Computer Science, Vol. 1, pp. 27–57, 1975.

[Huet/Hullot 82] G. Huet and J.-M. Hullot. Proofs by Induction of Equational Theories with Constructors. Journal of Computer and System Sciences 25, pp. 239–266, 1982.

[Huet/Oppen 80] G. Huet and D.C. Oppen. Equations and Rewrite Rules: A Survey. In R.V. Book, editor, Formal Language Theory: Perspectives and Open Problems. Academic Press, 1980.

[Hullot 80] J.-M. Hullot. Canonical Forms and Unification. In Proc. 5th Conference on Automated Deduction, pp. 318–334. Springer LNCS 87, 1980.

[Hussmann 85] H. Hussmann. Unification in Conditional-Equational Theories. In Proc. EUROCAL ’85, pp. 543–553. Springer LNCS 204, 1985.

[Jaffar/Lassez 87] J. Jaffar and J.-L. Lassez. Constraint Logic Programming. In Proc. of the 14th ACM Symposium on Principles of Programming Languages, pp. 111–119, Munich, 1987.

[Kanamori/Horiuchi 85] T. Kanamori and K. Horiuchi. Type Inference in Prolog and Its Application. In Proc. 9th IJCAI, pp. 704–707. W. Kaufmann, 1985.

[Kaplan 84a] S. Kaplan. Conditional Rewrite Rules. Theoretical Computer Science 33, pp. 175–193, 1984.

[Kaplan 84b] S. Kaplan. Fair Conditional Term Rewriting Systems: Unification, Termination and Confluence. Report 194, L.R.I., Université de Paris-Sud, 1984.

[Kluźniak 87] F. Kluźniak. Type Synthesis for Ground Prolog. In Proc. Fourth International Conference on Logic Programming (Melbourne), pp. 788–816. MIT Press, 1987.

[Knuth/Bendix 70] D.E. Knuth and P.B. Bendix. Simple Word Problems in Universal Algebras. In J. Leech, editor, Computational Problems in Abstract Algebra, pp. 263–297. Pergamon Press, 1970.

[Kowalski/Hayes 69] R. Kowalski and P.J. Hayes. Semantic Trees in Automatic Theorem-Proving. In B. Meltzer and D. Michie, editors, Machine Intelligence 4, pp. 87–101, 1969.

[Launay 86] S. Launay. Complétion de systèmes de réécriture types dont les fonctions sont polymorphes (Thèse de 3ème cycle). Technical Report 86-5, C.N.R.S Université Paris VII, 1986.

[Lloyd 87] J.W. Lloyd. Foundations of Logic Programming. Springer, second, extended edition, 1987.

[Loveland 78] D.W. Loveland. Automated Theorem Proving: A Logical Basis. North-Holland, Amsterdam, 1978.

[Martelli/Montanari 82] A. Martelli and U. Montanari. An Efficient Unification Algorithm. ACM Transactions on Programming Languages and Systems, Vol. 4, No. 2, pp. 258–282, 1982.

[Miller 86] D. Miller. A Theory of Modules for Logic Programming. In Proc. IEEE Internat. Symposium on Logic Programming, pp. 106–114, Salt Lake City, 1986.

[Miller/Nadathur 86] D.A. Miller and G. Nadathur. Higher-Order Logic Programming. In Proc. Third International Conference on Logic Programming (London), pp. 448–462. Springer LNCS 225, 1986.

[Milner 84] R. Milner. A Proposal for Standard ML. In Conference Record of the 1984 ACM Symposium On Lisp and Functional Programming, pp. 184–197, Austin, Texas, 1984.

[Mishra 84] P. Mishra. Towards a theory of types in Prolog. In Proc. IEEE Internat. Symposium on Logic Programming, pp. 289–298, Atlantic City, 1984.

[Mycroft 87] A. Mycroft. Private Communication, 1987.

[Mycroft/O’Keefe 84] A. Mycroft and R.A. O’Keefe. A Polymorphic Type System for Prolog. Artificial Intelligence, Vol. 23, pp. 295–307, 1984.

[Padawitz 88] P. Padawitz. Computing in Horn Clause Theories, volume 16 of EATCS Monographs on Theoretical Computer Science. Springer, 1988.

[Paterson/Wegman 78] M.S. Paterson and M.N. Wegman. Linear Unification. Journal of Computer and System Sciences, Vol. 17, pp. 348–375, 1978.

[Plotkin 72] G.D. Plotkin. Building-in Equational Theories. In B. Meltzer and D. Michie, editors, Machine Intelligence 7, pp. 73–90, 1972.

[Poigné 86] A. Poigné. On Specifications, Theories, and Models with Higher Types. Information and Control, Vol. 68, No. 1-3, 1986.

[Reynolds 74] J.C. Reynolds. Towards a Theory of Type Structure. In Proc. Colloque sur la Programmation, pp. 408–425. Springer LNCS 19, 1974.

[Reynolds 84] J.C. Reynolds. Polymorphism is not set-theoretic. In Proc. of the Int. Symp. on the Semantics of Data Types, Sophia-Antipolis, pp. 145–156. Springer LNCS 173, 1984.

[Robinson 65] J.A. Robinson. A Machine-Oriented Logic Based on the Resolution Principle. Journal of the ACM, Vol. 12, No. 1, pp. 23–41, 1965.

[Robinson/Wos 69] G. Robinson and L. Wos. Paramodulation and Theorem-proving in First-Order Theories with Equality. In B. Meltzer and D. Michie, editors, Machine Intelligence 4, pp. 135–150, 1969.

[Schmidt-Schauss 85] M. Schmidt-Schauss. A Many Sorted Calculus with Polymorphic Functions Based on Resolution and Paramodulation. In Proc. 9th IJCAI. W. Kaufmann, 1985.

[Siekmann/Szabó 82] J. Siekmann and P. Szabó. Universal Unification and a Classification of Equational Theories. In Proc. 6th Conference on Automated Deduction, pp. 369–389. Springer LNCS 138, 1982.

[Slagle 74] J.R. Slagle. Automated Theorem-Proving for Theories with Simplifiers, Commutativity, and Associativity. Journal of the ACM, Vol. 21, No. 4, pp. 622–642, 1974.

[Smolka 86a] G. Smolka. Fresh: A Higher-Order Language Based on Unification and Multiple Results. In D. DeGroot and G. Lindstrom, editors, Logic Programming, Functions, Relations, and Equations, pp. 469–524. Prentice Hall, 1986.

[Smolka 86b] G. Smolka. Order-Sorted Horn Logic: Semantics and Deduction. SEKI Report SR-86-17, FB Informatik, Univ. Kaiserslautern, 1986.

[Smolka 88] G. Smolka. TEL (Version 0.9) Report and User Manual. SEKI Report SR-87-11, FB Informatik, Univ. Kaiserslautern, 1988.

[Snyder/Gallier 88] W. Snyder and J.H. Gallier. Higher-Order Unification Revisited: Complete Sets of Transformations. Univ. of Pennsylvania, Philadelphia, 1988.

[Stickel 81] M.E. Stickel. A Unification Algorithm for Associative-Commutative Functions. Journal of the ACM, Vol. 28, No. 3, pp. 423–434, 1981.

[Subrahmanyam/You 86] P.A. Subrahmanyam and J.-H. You. FUNLOG: a Computational Model Integrating Logic Programming and Functional Programming. In D. DeGroot and G. Lindstrom, editors, Logic Programming, Functions, Relations, and Equations, pp. 157–198. Prentice Hall, 1986.

[Turner 85] D. Turner. Miranda: A non-strict functional language with polymorphic types. In Conference on Functional Programming Languages and Computer Architecture, Nancy, France, pp. 1–16. Springer LNCS 201, 1985.

[Turner 86] D. Turner. An Overview of Miranda. SIGPLAN Notices, Vol. 21, No. 12, pp. 158–166, 1986.

[van Emden/Kowalski 76] M.H. van Emden and J.A. Kowalski. The Semantics of Predicate Logic as a Programming Language. Journal of the ACM, Vol. 23, No. 4, pp. 733–742, 1976.

[van Emden/Yukawa 87] M.H. van Emden and K. Yukawa. Logic Programming with Equations. Journal of Logic Programming (4), pp. 265–288, 1987.

[Warren 82] D.H.D. Warren. Higher-order extensions to PROLOG: are they needed? In Machine Intelligence 10, pp. 441–454, 1982.

[Warren 83] D.H.D. Warren. An Abstract Prolog Instruction Set. Technical Note 309, SRI International, Stanford, 1983.

[Wise/Powers 84] M.J. Wise and D.M.W. Powers. Indexing PROLOG Clauses via Superimposed Code Words and Field Encoded Words. In Proc. IEEE Internat. Symposium on Logic Programming, pp. 203–210, Atlantic City, 1984.

[Wos et al. 67] L. Wos, G.A. Robinson, D.F. Carson, and L. Shalla. The Concept of Demodulation in Theorem Proving. Journal of the ACM, Vol. 14, No. 4, pp. 698–709, 1967.

[Yamamoto 87] A. Yamamoto. A Theoretical Combination of SLD-Resolution and Narrowing. In Proc. Fourth International Conference on Logic Programming (Melbourne), pp. 470– 487. MIT Press, 1987.

[Yardeni/Shapiro 87] E. Yardeni and E. Shapiro. A Type System for Logic Programs. Technical Report CS87-05, The Weizmann Institute of Science, 1987.

[Zhang/Remy 85] H. Zhang and J.L. Remy. Contextual Rewriting. In First Conference on Rewriting Techniques and Applications, pp. 46–62, Dijon, 1985. Springer LNCS 202.

[Zobel 87] J. Zobel. Derivation of Polymorphic Types for Prolog Programs. In Proc. Fourth International Conference on Logic Programming (Melbourne), pp. 817–838. MIT Press,

Index

(Σ, C, V) ⊧ G . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 (Σ, C, V) ⊢ L . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 (Σ, C, V) ⊢_{GN} σ G . . . . . . . . . . . . . . . . . . . . . . . . 99 (Σ, C, V) ⊢_{GP} σ G . . . . . . . . . . . . . . . . . . . . . . . . .77 (Σ, C, V) ⊢_{GR} σ G . . . . . . . . . . . . . . . . . . . . . . . . 57 (Σ, C, V) ⊢_{N} σ G . . . . . . . . . . . . . . . . . . . . . . . . . 94 (Σ, C, V) ⊢_{P} σ G . . . . . . . . . . . . . . . . . . . . . . . . . .63 (Σ, C, V) ⊢_{R} σ G . . . . . . . . . . . . . . . . . . . . . . . . . .49 (Σ, C, V) → G . . . . . . . . . . . . . . . . . . . . . . . . . .80 (Σ, X, V) |⊧ L ← G . . . . . . . . . . . . . . . . . . . . . 130 EAX(Σ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 F AX(Σ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 id_{X,V} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 pred(⋯) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Sub(Σ, X, V, V′) . . . . . . . . . . . . . . . . . . . . . . . . . 27 tdom(⋯) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 T erm_{Σ}(X, V) . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 tvar(⋯) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 t_{1} ⇒_{Σ,C,V} t_{2} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 T_{Σ}(X, V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 T_{Σ,C}(X, V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 uvar(⋯) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 var(⋯) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Σ-homomorphism . . . . . . . . . . . . . . . . . . . . . . . .21 Σ-interpretation . . . . . . . . . . . . . . . . . . . . . . . . . 19

answer . . . . . . . . . . . . . . . . . . . . 49,57,63,77,94,99 assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 atom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

basic type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 body of a clause . . . . . . . . . . . . . . . . . . . . . . . . . 14 canonical mapping . . . . . . . . . . . . . . . . . . . . . . . 32 canonical term rewriting system . . . . . . . . . .93 carrier of an interpretation . . . . . . . . . . . . . . . 20 Church-Rosser . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 composite term . . . . . . . . . . . . . . . . . . . . . . . . . . 13 computed answer . . . . . . . . . . 49,57,63,77,94,99 conditional equation . . . . . . . . . . . . . . . . . . . . . 14 conditional rewriting . . . . . . . . . . . . . . . . . . . . . 85 confluence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83,87 congruence axiom . . . . . . . . . . . . . . . . . . . . . . . .17 congruence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

deduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29 demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 derived signature . . . . . . . . . . . . . . . . . . . . . . . . 19 disagreement set . . . . . . . . . . . . . . . . . . . . . . . . . 43

E-unification . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 equality axioms . . . . . . . . . . . . . . . . . . . . . . . . . . 17 equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 equivalent types . . . . . . . . . . . . . . . . . . . . . . . . . 11

forgetful functor . . . . . . . . . . . . . . . . . . . . . . . . . 21 free term interpretation . . . . . . . . . . . . . . . . . . 21 functional-reflexive axioms . . . . . . . . . . . . . . . 65

GN-computed answer . . . . . . . . . . . . . . . . . . . . 99 goal confluence . . . . . . . . . . . . . . . . . . . . . . . . . . 83 goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 GP-computed answer . . . . . . . . . . . . . . . . . . . . 77 GR-computed answer . . . . . . . . . . . . . . . . . . . . 57 ground term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

head of a clause . . . . . . . . . . . . . . . . . . . . . . . . . .14 higher-order functions . . . . . . . . . . . . . . . . . . 124 homomorphism . . . . . . . . . . . . . . . . . . . . . . . 20,21 Horn clause calculus . . . . . . . . . . . . . . . . . . . . . 29

ill-typed term . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 initial model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 initial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 innermost strategy . . . . . . . . . . . . . . . . . . . . . .131 innermost term . . . . . . . . . . . . . . . . . . . . . . . . . 131 instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . .19 irreducible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

logic program . . . . . . . . . . . . . . . . . . . . . . . . . . .117

mgu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 monomorphic signature . . . . . . . . . . . . . . . . . 115 monomorphic type . . . . . . . . . . . . . . . . . . . . . . . 10 most general narrowing . . . . . . . . . . . . . . . . . . 99 most general paramodulation . . . . . . . . . . . . 77 most general resolution . . . . . . . . . . . . . . . . . . 57 most general unifier . . . . . . . . . . . . . . . . . . . . . .43

N-computed answer . . . . . . . . . . . . . . . . . . . . . .94 narrowing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 normal form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

occurrence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

P-computed answer . . . . . . . . . . . . . . . . . . . . . . 63 paramodulation . . . . . . . . . . . . . . . . . . . . . . . . . .63 polymorphic Horn clause calculus . . . . . . . . 29 polymorphic Horn clause specification …. 15 polymorphic signature . . . . . . . . . . . . . . . . . . . 12 polymorphic specification . . . . . . . . . . . . . . . . 15 polymorphic term . . . . . . . . . . . . . . . . . . . . . . . .13 polymorphic type . . . . . . . . . . . . . . . . . . . . . . . . 10 position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 prefix of occurrences . . . . . . . . . . . . . . . . . . . . . 62

quotient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

R-computed answer . . . . . . . . . . . . . . . . . . . . . . 49 reducible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 reflexivity axiom . . . . . . . . . . . . . . . . . . . . . . . . . 17 relational clause . . . . . . . . . . . . . . . . . . . . . . . . . 14 relational specification . . . . . . . . . . . . . . . . . . 117 renaming of type variables . . . . . . . . . . . . . . . 11 replacement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49 rewriting, conditional . . . . . . . . . . . . . . . . . . . . 85

signature morphism . . . . . . . . . . . . . . . . . . . . . .20 signature of types . . . . . . . . . . . . . . . . . . . . . . . .10 signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9,12 specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 strict types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 subterm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 successful narrowing . . . . . . . . . . . . . . . . . . 94,99 successful paramodulation . . . . . . . . . . . . .63,77 successful reduction . . . . . . . . . . . . . . . . . . . . . . 80 successful resolution . . . . . . . . . . . . . . . . . . 49,57 symmetry axiom . . . . . . . . . . . . . . . . . . . . . . . . . 17

term interpretation . . . . . . . . . . . . . . . . . . . . . . 21 term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 transitivity axiom . . . . . . . . . . . . . . . . . . . . . . . .17 type algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 type constructor . . . . . . . . . . . . . . . . . . . . . . . . . 10 type domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 type general . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 type signature . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 type substitution . . . . . . . . . . . . . . . . . . . . . . . . 11 type variables . . . . . . . . . . . . . . . . . . . . . . . . . . . .10 type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 type-generally defined . . . . . . . . . . . . . . . . . . 113 typed substitution . . . . . . . . . . . . . . . . . . . . . . . 27 typed variable . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

unconditional equation . . . . . . . . . . . . . . . . . . .14 unifiable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 unifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

validity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 variable assignment . . . . . . . . . . . . . . . . . . . . . . 22 variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 variant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

well-typed term . . . . . . . . . . . . . . . . . . . . . . . . . . 13