An

Efficient

Constraint

Language

for

Polymorphic

Order-sorted

Resolution

Christian

Prehofer

Technische

Universit?at

M?unchen

Abstract

In

recent

years

various

sorted

logics

have

been

developed

mostly

to

facilitate

knowledge

representation

and

to

speed

up

automated

deduction

We

present

a

polymorphic

order-sorted

logic

that

can

be

implemented

efficiently

Because

the

polymorphism

is

almost

unrestricted

it

is

possible

for

two

terms

to

have

an

exponential

number

of

maximally

general

unifiers

To

guarantee

a

single

most

general

unifier

we

embed

the

sorted

logic

into

a

more

general

constraint

logic

and

create

a

distinct

constraint

satisfaction

search

space

This

separates

the

total

search

space

into

two

orthogonal

ones

and

facilitates

many

optimizations

The

main

complexity

gains

are

that

the

unnecessary

generation

of

unifiers

can

be

avoided

and

that

the

primary

resolution

search

space

remains

constant

if

the

complexity

of

the

unification

grows

Introduction

In

recent

years

various

sorted

logics

have

been

developed

mostly

to

facilitate

knowledge

representation

and

to

speed

up

automated

deduction

In

sorted

logics

a

sort

represents

a

subset

of

the

domain

and

variables

range

only

over

a

specific

sort

If

sorts

can

be

ordered

by

set

inclusion

the

logic

is

called

order-sorted

It

is

also

desirable

to

specify

the

sortal

behavior

of

functions

A

sorted

logic

is

polymorphic

if

a

function

can

have

different

result

sorts

depending

on

the

argument

sorts

One

motivation

for

sorts

is

roughly

speaking

that

proofs

can

be

kept

at

a

more

general

level

compared

to

unsorted

logic

thus

reducing

the

search

space

-LSB-

Cohn

Frisch

Walther

-RSB-

It

has

also

been

argued

that

deduction

with

sorts

can

be

implemented

more

efficiently

by

specialized

procedures

-LSB-

Cohn

-RSB-

For

example

for

order-sorted

logics

there

are

efficient

methods

to

find

the

greatest

lower

bound

-LRB-

glb

-RRB-

of

two

sorts

in

a

sort

hierarchy

-LSB-

A

t-Kaci

et

al.

Huber

and

Varsek

-RSB-

Our

contribution

is

an

efficient

unification

method

for

a

very

general

class

of

polymorphism

Sorted

logics

only

constrain

variables

to

be

of

a

certain

sort

which

means

that

a

most

general

unifier

often

can

not

be

expressed

by

the

logic

Instead

we

attach

constraints

on

terms

in

order

to

represent

multiple

unifiers

For

instance

a

term

t

sum

-LRB-

X

Y

-RRB-

is

of

sort

evn

if

X

and

Y

are

both

of

sort

evn

or

both

of

Research

carried

out

at

the

University

of

Illinois

at

Urbana-Champaign

USA

Full

Address

Institut

f?ur

Informatik

Technische

Universit?at

M?unchen

Postfach

M?unchen

Germany

E-mail

prehofer@informatik.tu-muenchen.de

sort

odd

Then

t

and

a

variable

Z

evn

have

the

two

maximally

general

instances

sum

-LRB-

X

evn

Y

evn

-RRB-

and

sum

-LRB-

X

odd

Y

odd

-RRB-

In

general

in

this

order-sorted

logic

the

number

of

maximally

general

instances

grows

exponentially

with

the

term

size

and

to

decide

if

two

terms

unify

is

NP-complete

-LSB-

Schmidt-Schauss

-RSB-

We

express

the

above

two

terms

as

one

term

by

attaching

a

constraint

C

on

t

to

ensure

that

t

is

of

sort

evn

This

constrained

term

t

C

represents

all

corresponding

sorted

common

instances

If

unification

fails

for

t

C

an

up

to

exponential

number

of

maximally

general

sorted

instances

would

fail

also

Instead

of

an

exponential

number

of

unifiers

we

now

have

a

NP-complete

constraint

satisfaction

problem

for

which

we

create

a

distinct

search

space

This

means

that

the

primary

resolution

search

space

remains

constant

if

the

complexity

of

the

unification

grows

Furthermore

in

our

approach

an

exponential

number

of

maximal

sorted

unifiers

does

not

automatically

require

an

exponential

effort

we

show

that

it

suffices

to

find

a

single

representative

unifier

-LRB-

in

the

constraint

satisfaction

search

space

-RRB-

and

to

delay

further

search

The

following

section

presents

the

above

order-sorted

logic

formally

and

shows

the

problem

of

multiple

unifiers

Then

Section

introduces

a

more

general

logic

where

sort

constraints

are

attached

to

terms

This

is

used

in

Section

to

embed

the

order-sorted

logic

into

the

constraint

logic

CP

where

a

most

general

unifier

always

exists

for

unifiable

terms

In

Section

we

discuss

the

advantages

of

CP-logic

in

the

light

of

two

examples

The

first

example

shows

the

effect

of

CP-logic

on

the

search

space

graphically

the

second

shows

details

of

a

derivation

with

CP-terms

Order-sorted

Logic

The

syntax

of

our

sorted

logic

differs

from

standard

first-order

logic

only

in

variables

that

are

quantified

over

sorts

written

as

s

OE

where

X

is

a

variable

and

s

is

a

sort

We

specify

sorts

and

polymorphic

functions

by

a

sort

theory

in

unsorted

first-order

logic

Then

we

define

the

meaning

of

a

sorted

sentence

by

an

unsorted

sentence

contains

only

unary

predicate

symbols

from

a

distinct

set

of

sort

predicate

symbols

S

s

S

is

called

a

sort

An

atomic

formula

with

a

sort

predicate

is

called

characteristic

literal

These

literals

define

the

sorts

A

term

denotes

an

element

of

a

sort

s

if

the

interpretation

of

s

-LRB-

t

-RRB-

is

true

These

characteristic

literals

appear

in

the

sort

theory

only

In

examples

we

write

sorts

typographically

as

small

capitals

but

not

characteristic

literals

for

example

X

odd

and

ODD

-LRB-

X

-RRB-

contains

only

sentences

of

the

following

two

forms

ffl

Subsort

declarations

-LRB-

X

-RRB-

-LRB-

X

-RRB-

ffl

Function

declarations

Xn

-LRB-

-RRB-

sn

-LRB-

Xn

-RRB-

sn

-LRB-

f

-LRB-

Xn

-RRB-

-RRB-

A

sort

is

subsort

of

written

as

iff

j

-LRB-

X

-RRB-

-LRB-

X

-RRB-

We

require

that

OE

is

a

partial

order

on

the

sorts

i.e.

for

two

sorts

and

we

disallow

that

entails

both

OE

and

OE

Then

we

can

represent

the

sorts

in

a

diagram

-LRB-

see

Fig.

-RRB-

where

s

OE

if

there

is

a

downwards

path

from

to

s

We

abbreviate

a

function

declaration

-LRB-

or

declaration

for

short

-RRB-

d

Xn

-LRB-

-RRB-

sn

-LRB-

Xn

-RRB-

sn

-LRB-

f

-LRB-

Xn

-RRB-

-RRB-

by

f

-LRB-

sn

-RRB-

sn

The

sort

sn

Fig.

Sort

Hierarchy

Fig.

Sort

Hierarchy

is

called

the

result

sort

denoted

as

R

-LRB-

d

-RRB-

The

set

of

function

declarations

in

is

required

to

be

monotone

i.e.

if

contains

two

declarations

of

the

form

f

-LRB-

sn

-RRB-

sn

and

f

-LRB-

-RRB-

and

si

for

all

i

ng

then

sn

We

require

that

the

sorts

are

non-empty

i.e.

for

all

s

S

there

is

a

ground

term

t

such

that

j

s

-LRB-

t

-RRB-

We

also

assume

that

there

is

at

least

one

declaration

for

each

function

symbol

Now

we

can

define

the

meaning

of

a

sentence

s

OE

-LRB-

s

-LRB-

X

-RRB-

OE

-RRB-

To

ensure

that

substitutions

comply

with

the

restriction

of

a

variable

we

define

wellsorted

substitutions

with

respect

to

A

substitution

is

well-sorted

iff

j

-LRB-

X

-RRB-

for

all

variables

X

s.

A

term

t

is

a

instance

of

iff

t

for

a

well-sorted

substitution

A

set

of

terms

I

is

a

complete

set

of

incomparable

common

instances

-LRB-

or

cii

-RRB-

of

a

set

of

terms

E

iff

ffl

Each

element

of

I

is

a

instance

of

all

elements

of

E.

ffl

Every

term

which

is

a

instance

of

all

elements

of

E

is

a

instance

of

at

least

one

element

of

I.

ffl

No

element

of

I

is

a

instance

of

another

element

of

I

It

can

be

shown

that

a

cii

is

uniquely

defined

except

for

variants

of

its

elements

-LSB-

Frisch

-RSB-

A

well-sorted

substitution

is

a

unifier

of

a

set

of

terms

E

iff

e

for

all

e

E

and

e

is

a

instance

of

all

elements

of

E

We

say

a

term

t

is

of

sort

s

if

j

-LRB-

t

-RRB-

A

term

is

well-sorted

if

it

is

of

some

sort

This

corresponds

to

syntax-based

notions

of

well-sortedness

e.g.

-LSB-

Schmidt-Schauss

-RSB-

Example

Assuming

-LRB-

Fig.

-RRB-

a

cii

of

the

two

variables

X

a

and

Y

b

consists

of

X

c

and

X

:d

Example

Assuming

-LRB-

Fig.

-RRB-

with

the

function

declarations

ffl

sum

-LRB-

int

int

-RRB-

int

ffl

sum

-LRB-

odd

evn

-RRB-

odd

ffl

sum

-LRB-

evn

odd

-RRB-

odd

ffl

sum

-LRB-

odd

odd

-RRB-

evn

ffl

sum

-LRB-

evn

evn

-RRB-

evn

a

cii

of

sum

-LRB-

X

int

Y

int

-RRB-

and

Z

evn

is

fsum

-LRB-

X

odd

Y

odd

-RRB-

sum

-LRB-

X

evn

Y

evn

-RRB-

g

Here

and

in

general

an

expression

of

the

form

denotes

the

universal

closure

of

OE

that

is

the

formula

xn

OE

where

xn

are

the

freely-occurring

variables

of

OE

Similarly

denotes

the

existential

closure

of

OE

A

sort

theory

is

regular

if

every

well-sorted

term

has

one

least

sort

A

sort

s

is

the

least

sort

of

a

term

t

if

j

-LRB-

t

-RRB-

and

for

all

S

j

-LRB-

t

-RRB-

only

if

s

If

is

regular

Schmidt-Schauss

shows

that

in

a

sort

theory

as

above

a

cii

is

at

most

exponential

in

the

size

of

the

unified

terms

If

is

not

regular

cii

's

can

be

infinite

In

the

following

we

assume

that

the

sort

theories

are

regular

We

show

in

-LSB-

Prehofer

-RSB-

that

every

monotone

sort

theory

can

be

transformed

into

a

regular

one

We

confine

ourselves

to

sentences

in

Skolem

Normal

Form

-LRB-

SNF

-RRB-

For

translating

sentences

into

SNF

see

-LSB-

Frisch

and

Scherl

Frisch

-RSB-

We

often

take

the

view

that

a

sort

is

attached

to

a

variable

instead

of

to

the

quantifier

In

particular

we

often

omit

the

universal

quantifiers

for

sentences

in

SNF

and

simply

attach

the

sort

to

a

variable

for

instance

sum

-LRB-

X

odd

X

odd

-RRB-

Sort-Constraint

Logic

We

introduce

a

constraint

logic

where

sort-constraints

can

be

attached

to

every

-LRB-

sub

-RRB-

term

It

is

an

instance

of

the

frameworks

in

-LSB-

B?urkert

Frisch

-RSB-

and

will

be

used

as

the

formal

basis

for

CP-logic

in

the

next

section

The

only

novel

feature

attaching

constraints

to

subterms

will

be

important

for

implementing

polymorphic

order-sorted

logic

by

CP-logic

Sort-Constrained

Terms

Sort-constraints

are

quantifier-free

formulas

with

the

connectives

and

and

only

contain

positive

characteristic

literals

Every

unconstrained

term

is

a

sort-constrained

term

with

the

implicit

constraint

TRUE

Assume

a

term

t

is

a

variable

or

t

f

-LRB-

tn

-RRB-

where

tn

are

sortconstrained

terms

Then

t

C

is

a

sort-constrained

term

if

the

sort-constraint

C

only

contains

literals

of

the

form

s

-LRB-

-RRB-

where

is

a

subterm

of

t.

For

example

f

-LRB-

X

INT

-LRB-

X

-RRB-

g

-LRB-

Y

EVN

-LRB-

Y

-RRB-

-RRB-

-RRB-

-LRB-

ODD

-LRB-

X

-RRB-

ODD

-LRB-

g

-LRB-

Y

-RRB-

-RRB-

-RRB-

is

a

sort-constrained

term

Let

tC

denote

the

conjunction

of

all

constraints

that

occur

in

a

sort-constrained

formula

t

and

let

tN

denote

t

without

all

constraints

Then

we

define

the

meaning

of

a

constrained

formula

t

as

t

-LRB-

tC

tN

-RRB-

For

example

the

atom

p

-LRB-

-RRB-

is

logically

equivalent

to

-LRB-

INT

-LRB-

X

-RRB-

EVN

-LRB-

Y

-RRB-

-LRB-

ODD

-LRB-

X

-RRB-

ODD

-LRB-

g

-LRB-

Y

-RRB-

-RRB-

-RRB-

-RRB-

p

-LRB-

f

-LRB-

X

g

-LRB-

Y

-RRB-

-RRB-

-RRB-

To

ease

our

notation

we

often

write

p

-LRB-

t

-RRB-

C

instead

of

p

-LRB-

t

C

-RRB-

Notice

that

C

only

contains

characteristic

literals

and

does

not

contain

the

predicate

symbol

p

An

expression

t

is

in

normal

form

if

t

tN

tC

An

expression

t

is

satisfiable

if

j

Instance

Let

be

a

sort

theory

is

a

instance

of

e

-LRB-

often

written

e

-RRB-

if

and

only

if

for

some

substitution

eN

and

j

-LRB-

-LRB-

eC

-RRB-

-RRB-

Theorem

Let

and

be

variable-disjoint

expressions

in

normal

form

such

that

is

a

most

general

unifier

of

and

Then

-LRB-

-RRB-

is

a

most

general

common

instance

-LRB-

or

mgci

-RRB-

of

and

if

-LRB-

-RRB-

is

satisfiable

Finite

and

elementary

in

Schmidt-Schauss

's

terminology

Notice

that

t

is

a

subterm

of

itself

This

definition

and

the

following

theorem

are

adapted

from

-LSB-

Frisch

-RSB-

Input

-LRB-

ft

-RRB-

Output

-LRB-

;-RRB-

such

that

t

mgci

-LRB-

t

-RRB-

or

fail

Apply

the

following

rules

in

any

order

-LRB-

U

-LSB-

fX

C

Y

C

g

-RRB-

=-RRB-

-LRB-

U

-RRB-

where

f

X

C

X

-LRB-

C

C

-RRB-

Y

C

X

-LRB-

C

C

-RRB-

g

and

C

C

fY

Xg

IF

-LRB-

t

-RRB-

C

is

not

satisfiable

THEN

fail

-LRB-

U

-LSB-

ff

-LRB-

tn

-RRB-

C

X

Cg

-RRB-

=-RRB-

-LRB-

U

-LSB-

fX

C

f

-LRB-

tn

-RRB-

C

g

-RRB-

-LRB-

U

-LSB-

fX

C

f

-LRB-

tn

-RRB-

C

g

-RRB-

=-RRB-

-LRB-

U

-RRB-

where

f

X

C

f

-LRB-

tn

-RRB-

-LRB-

C

C

-RRB-

f

-LRB-

tn

-RRB-

C

f

-LRB-

tn

-RRB-

-LRB-

C

C

-RRB-

g

and

C

CfX

f

-LRB-

tn

-RRB-

g

IF

-LRB-

t

-RRB-

C

is

not

satisfiable

OR

X

occurs

in

f

-LRB-

:-RRB-

THEN

fail

-LRB-

U

-LSB-

ff

-LRB-

tn

-RRB-

C

f

-LRB-

-RRB-

C

g

-RRB-

=-RRB-

-LRB-

U

-LSB-

tn

-RRB-

where

f

f

-LRB-

tn

-RRB-

C

f

-LRB-

tn

-RRB-

-LRB-

C

C

-RRB-

f

-LRB-

-RRB-

C

f

-LRB-

tn

-RRB-

-LRB-

C

C

-RRB-

g

IF

-LRB-

t

-RRB-

C

is

not

satisfiable

OR

f

f

THEN

fail

Fig.

Constraint

Unification

Algorithm

To

unify

two

sort-constrained

terms

a

generalized

notion

of

substitution

is

required

Usually

a

substitution

is

a

mapping

from

variables

to

terms

We

present

T-substitutions

as

mappings

from

terms

to

terms

T-substitution

A

T-substitution

is

a

function

from

sort-constrained

terms

to

sort-constrained

terms

usually

written

as

a

set

of

mappings

t

where

t

and

are

sort-constrained

terms

The

composition

of

two

T-substitutions

is

defined

as

-LRB-

t

-RRB-

-LRB-

-LRB-

t

-RRB-

-RRB-

for

all

t

A

T-substitution

is

well-sorted

if

t

t

for

every

sort-constrained

term

t.

For

two

well-sorted

T-substitutions

and

is

more

general

than

if

there

is

a

well-sorted

T-substitution

such

that

A

well-sorted

T-substitution

is

a

T-unifier

of

two

terms

e

and

if

e

e

e

and

e

In

the

style

of

Martelli

and

Montanari

-LSB-

Martelli

and

Montanari

-RSB-

we

describe

unification

in

the

form

of

equations

The

unification

rules

in

Figure

compute

a

mgci

of

two

terms

not

necessarily

in

normal

form

The

rules

work

on

a

tuple

-LRB-

U

-RRB-

where

is

a

T-substitution

and

U

is

a

set

of

equations

To

obtain

a

mgci

of

two

variable-disjoint

terms

t

and

we

start

with

-LRB-

ft

-RRB-

Then

we

apply

the

conditional

rules

in

any

order

until

U

is

empty

or

until

one

rule

fails

If

we

succeed

and

U

is

empty

then

is

a

most

general

T-unifier

of

t

and

and

t

mgci

-LRB-

t

-RRB-

is

satisfiable

If

we

compute

a

mgci

of

two

terms

in

normal

form

with

Theorem

all

constraints

are

attached

to

the

outermost

term

The

rules

in

Figure

conjoin

the

constraints

of

the

subterms

locally

instead

of

conjoining

all

constraints

at

once

By

locally

we

mean

that

the

constraints

are

closer

to

the

terms

they

constrain

to

a

certain

sort

As

we

require

the

satisfiability

of

-LRB-

t

-RRB-

C

where

t

is

equal

to

mgci

-LRB-

t

-RRB-

if

the

rules

succeed

the

correctness

of

the

rules

follows

easily

from

Theorem

Let

L

be

positive

literals

and

let

Mi

Ni

be

literals

Then

the

-LRB-

binary

-RRB-

resolution

inference

rule

for

sort-constrained

terms

is

defined

as

L

Mm

Nn

-LRB-

Mm

Nn

-RRB-

if

is

a

most

general

T-unifier

of

L

and

and

-LRB-

-LRB-

Mm

Nn

-RRB-

-RRB-

C

is

satisfiable

The

satisfiability

test

in

this

rule

assures

that

the

derived

clause

represents

some

ground

instance

The

constraints

in

Mi

and

Ni

are

not

necessarily

satisfiable

if

mgci

-LRB-

L

-RRB-

is

satisfiable

For

instance

if

we

resolve

p

-LRB-

X

INT

-LRB-

X

-RRB-

-RRB-

q

-LRB-

f

-LRB-

X

-RRB-

EVN

-LRB-

X

-RRB-

-RRB-

with

:p

-LRB-

X

ODD

-LRB-

X

-RRB-

-RRB-

then

q

-LRB-

f

-LRB-

X

ODD

-LRB-

X

-RRB-

INT

-LRB-

X

-RRB-

-RRB-

EVN

-LRB-

X

-RRB-

-RRB-

is

not

satisfiable

One

problem

of

computing

mgci

's

is

to

simplify

the

conjunctions

of

constraints

-LRB-

C

-RRB-

otherwise

the

terms

grow

larger

and

larger

without

limit

In

the

above

rules

terms

do

not

have

to

be

in

normal

form

and

these

conjunctions

can

be

simplified

locally

because

constraints

only

contain

subterms

of

the

terms

to

which

they

are

attached

CP-Logic

CP-logic

is

a

sort-constraint

logic

with

a

specific

class

of

constraints

and

will

be

used

to

implement

the

sorted

logic

of

Section

In

Section

we

translate

well-sorted

terms

of

the

sorted

logic

into

CP-terms

Then

Section

shows

that

constraint

simplification

in

CP

can

be

performed

by

set

operations

To

solve

the

problem

of

satisfiability

of

CP-constraints

we

create

a

distinct

search

space

as

shown

in

Section

Embedding

the

Sorted

Logic

in

the

Constraint

Logic

CP

We

first

present

examples

of

the

class

of

constraints

that

is

used

to

translate

the

sorted

logic

into

CP-logic

and

give

examples

for

unification

of

CP-terms

The

CP-constraint

of

a

sorted

variable

X

s

is

the

disjunction

of

all

subsorts

of

s

including

s.

For

instance

in

Example

the

variables

X

a

and

Y

b

translate

into

X

-LRB-

A

-LRB-

X

-RRB-

C

-LRB-

X

-RRB-

D

-LRB-

X

-RRB-

-RRB-

and

Y

-LRB-

B

-LRB-

Y

-RRB-

C

-LRB-

Y

-RRB-

D

-LRB-

Y

-RRB-

-RRB-

respectively

Then

these

two

variables

have

the

mgci

Z

-LRB-

C

-LRB-

Z

-RRB-

D

-LRB-

Z

-RRB-

-RRB-

where

the

sorts

in

the

constraint

C

-LRB-

Z

-RRB-

D

-LRB-

Z

-RRB-

are

obtained

by

intersecting

the

sorts

in

the

constraints

of

X

and

Y

If

possible

we

will

use

the

notation

for

sorted

variables

in

examples

for

brevity

i.e.

X

a

instead

of

X

-LRB-

A

-LRB-

X

-RRB-

C

-LRB-

X

-RRB-

D

-LRB-

X

-RRB-

-RRB-

Similarly

we

attach

a

disjunction

to

every

non-variable

term

where

each

disjunct

stands

for

one

declaration

For

a

declaration

d

f

-LRB-

sn

-RRB-

sn

and

a

term

t

f

-LRB-

tn

-RRB-

we

define

d

-LRB-

t

-RRB-

as

-LRB-

-RRB-

sn

-LRB-

tn

-RRB-

Let

U

-LRB-

t

-RRB-

be

the

set

of

all

declarations

d

such

that

d

and

j

-LRB-

-RRB-

for

some

t

Then

a

CP-constraint

of

a

term

t

f

-LRB-

:-RRB-

is

the

disjunction

of

all

di

-LRB-

t

-RRB-

's

with

di

U

-LRB-

t

-RRB-

For

instance

in

Example

translating

sum

-LRB-

X

int

Y

int

-RRB-

We

choose

this

representation

to

motivate

constraints

on

non-variable

terms

More

efficient

versions

be

found

in

-LSB-

A

t-Kaci

et

al.

-RSB-

into

CP-logic

gives

sum

-LRB-

X

int

Y

int

-RRB-

-LRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-RRB-

In

examples

we

often

omit

the

argument

t

in

d

-LRB-

t

-RRB-

and

for

example

write

the

above

term

as

Then

the

logical

meaning

of

the

constraints

is

given

implicitly

by

their

position

in

the

term

A

mgci

of

Z

EVN

-LRB-

Z

-RRB-

and

using

Theorem

is

-LRB-

-LRB-

-RRB-

-LRB-

-RRB-

-RRB-

EVN

-LRB-

-RRB-

and

can

be

simplified

to

sum

-LRB-

X

int

Y

int

-RRB-

Only

the

two

declarations

with

result

sort

EVN

remained

We

eliminated

because

-LRB-

-RRB-

EVN

-LRB-

-RRB-

is

not

satisfiable

and

for

the

same

reason

Furthermore

is

redundant

because

whenever

entails

-LRB-

-RRB-

EVN

-LRB-

-RRB-

must

entail

-LRB-

-RRB-

-LRB-

-RRB-

also

In

general

to

obtain

the

constraint

of

the

mgci

of

a

variable

X

CX

and

a

term

t

Ct

we

simply

intersect

the

sorts

in

CX

with

the

result

sorts

of

the

declarations

in

Ct.

Instead

of

a

cii

of

size

two

we

now

have

only

one

CP-term

In

the

general

case

a

single

CP-mgci

represents

a

possibly

exponential

large

cii

in

the

sorted

logic

A

mgci

of

sum

-LRB-

X

int

Y

int

-RRB-

and

sum

-LRB-

int

Y

evn

-RRB-

is

sum

-LRB-

int

Y

evn

-RRB-

Again

we

only

have

to

intersect

the

declarations

of

both

constraints

The

next

step

is

to

make

the

constraints

minimal

For

example

sum

-LRB-

X

evn

Y

odd

-RRB-

has

the

constraint

For

all

instances

of

whenever

entails

-LRB-

-RRB-

must

entail

-LRB-

-RRB-

also

and

therefore

we

can

omit

-LRB-

-RRB-

Then

we

can

often

detect

that

two

terms

have

no

mgci

because

they

have

no

common

declarations

For

example

sum

-LRB-

int

Y

evn

-RRB-

-LRB-

-RRB-

and

have

no

mgci

and

we

can

see

this

by

examining

the

two

constraints

only

In

the

remainder

of

this

section

we

show

that

these

observations

hold

if

is

regular

Because

we

reduce

the

operations

on

constraints

to

set

operations

we

treat

constraints

as

sets

where

each

element

stands

for

one

disjunct

e.g.

instead

of

A

set

C

is

downwards

-LRB-

upwards

-RRB-

closed

w.r.t.

an

ordering

and

a

set

D

if

d

C

entails

C

for

all

D

with

d

-LRB-

d

-RRB-

CP-Variable

Assume

C

sng

S

is

downwards

closed

w.r.t.

OE

and

S

Then

the

variable

X

-LRB-

-LRB-

X

-RRB-

sn

-LRB-

X

-RRB-

-RRB-

is

a

CP-term

We

let

bC

denote

the

translation

of

C

into

-LRB-

-LRB-

X

-RRB-

sn

-LRB-

X

-RRB-

-RRB-

and

write

X

bC

Translating

a

sorted

variable

X

s

into

an

equivalent

CP-variable

gives

X

bC

with

C

j

sg

Two

constrained

variables

X

bC

and

Y

have

a

mgci

Notice

that

this

mgci

and

the

following

ones

obtained

by

set

operations

are

no

mgci

's

in

the

strict

logical

sense

because

they

have

slightly

stronger

constraints

As

they

preserve

the

set

of

ground

instances

this

can

be

justified

by

Herbrand

's

Theorem

since

has

a

minimal

model

Versions

of

Herbrand

's

Theorem

for

constraint

logics

can

be

found

in

in

-LSB-

B?urkert

Frisch

-RSB-

In

the

following

we

do

not

differentiate

between

true

mgci

's

and

terms

with

these

stronger

constraints

Fig.

Sort

Theory

Z

d

-LRB-

C

-RRB-

if

C

This

follows

from

Theorem

because

C

and

are

downwards

closed

and

the

sorts

are

non-empty

For

each

function

symbol

f

let

D

-LRB-

f

-RRB-

denote

the

set

of

function

declarations

for

f

in

The

partial

order

of

the

sorts

can

be

used

to

order

the

function

declarations

Two

declarations

are

ordered

denoted

by

f

-LRB-

sn

-RRB-

sn

f

-LRB-

-RRB-

if

si

ng

Observe

that

U

-LRB-

t

-RRB-

is

upwards

closed

w.r.t.

OE

and

D

-LRB-

f

-RRB-

but

not

downwards

For

a

declaration

d

f

-LRB-

sn

-RRB-

sn

the

corresponding

term

is

defined

as

f

-LRB-

Xn

sn

-RRB-

We

often

write

d

instead

of

d

's

corresponding

term

for

instance

we

write

instance

of

d

or

mgci

-LRB-

d

t

-RRB-

CP-Term

Assume

tn

are

CP-terms

and

t

f

-LRB-

tn

-RRB-

Assume

further

that

C

dng

D

-LRB-

f

-RRB-

is

non-empty

and

downwards

closed

w.r.t.

OE

and

U

-LRB-

t

-RRB-

Then

f

-LRB-

tn

-RRB-

-LRB-

-LRB-

t

-RRB-

dn

-LRB-

t

-RRB-

-RRB-

is

a

CP-term

We

let

bC

denote

the

translation

of

C

into

-LRB-

-LRB-

t

-RRB-

dn

-LRB-

t

-RRB-

-RRB-

and

write

as

t

bC

In

examples

we

often

write

C

instead

of

bC

To

translate

a

sorted

term

t

into

CP

it

would

be

possible

to

to

use

U

-LRB-

t

-RRB-

as

the

constraint

of

t.

For

further

optimization

we

show

that

the

smaller

set

I

-LRB-

t

-RRB-

defined

below

can

be

used

instead

Recall

that

using

smaller

constraints

facilitates

the

optimization

that

two

non-variable

terms

do

not

unify

if

their

constraints

have

no

common

declarations

The

idea

is

to

describe

a

term

more

accurately

with

the

declarations

in

the

constraint

We

write

t

ss

if

t

and

are

variants

Initial

Set

The

initial

set

I

-LRB-

t

-RRB-

of

a

sort-constrained

term

t

f

-LRB-

:-RRB-

is

defined

as

fd

U

-LRB-

t

-RRB-

j

there

exists

no

U

-LRB-

t

-RRB-

with

OE

d

and

mgci

-LRB-

t

d

-RRB-

ss

mgci

-LRB-

t

-RRB-

g.

Example

The

following

figure

shows

the

initial

sets

of

the

terms

in

the

left

column

w.r.t.

-LRB-

Fig.

-RRB-

and

two

variations

of

The

numbers

in

the

figure

refer

to

the

declarations

in

Figure

where

the

solid

lines

represent

the

relation

OE

F

and

-LRB-

-RRB-

-LRB-

-RRB-

and

-LRB-

-RRB-

f

-LRB-

X

b

Y

a

-RRB-

f

-LRB-

X

a

X

a

-RRB-

f

-LRB-

X

b

Y

b

-RRB-

The

following

theorem

shows

why

I

-LRB-

t

-RRB-

can

be

used

instead

of

U

-LRB-

t

-RRB-

Theorem

Let

t

be

two

non-variable

CP-terms

and

let

d

U

-LRB-

t

-RRB-

be

a

declaration

such

that

j

-LRB-

-RRB-

Then

there

exists

I

-LRB-

t

-RRB-

with

d

and

j

-LRB-

-RRB-

valid

Terms

All

CP-variables

are

valid

A

CP-term

f

-LRB-

:-RRB-

bC

is

valid

if

j

bC

and

all

subterms

of

f

-LRB-

:-RRB-

are

valid

To

translate

a

well-sorted

term

t

of

the

sorted

logic

into

a

CP-term

we

first

translate

all

variables

in

t

into

CP-variables

as

shown

in

the

previous

section

and

obtain

a

sort-constrained

term

Then

we

attach

the

constraint

d

I

-LRB-

-RRB-

on

each

non-variable

subterm

of

including

For

instance

in

Example

with

f

-LRB-

X

b

Y

a

-RRB-

is

translated

into

f

-LRB-

X

B

-LRB-

X

-RRB-

Y

A

-LRB-

Y

-RRB-

-RRB-

d

Since

t

is

a

well-sorted

non-variable

term

j

s

-LRB-

t

-RRB-

for

some

sort

s.

Hence

there

must

be

a

declaration

d

such

that

entails

d

-LRB-

t

-RRB-

Then

d

U

-LRB-

-RRB-

and

j

d

U

-LRB-

-RRB-

and

from

Theorem

follows

j

d

I

-LRB-

-RRB-

Hence

t

and

d

I

-LRB-

-RRB-

have

the

same

instances

and

the

CP-term

can

be

used

for

the

sorted

term

and

d

I

-LRB-

-RRB-

is

valid

Observe

that

a

valid

non-variable

CP-term

t

C

ensures

the

satisfiability

of

C

for

a

well-sorted

T-substitutions

if

t?C

is

satisfiable

Reducing

Constraint

Simplification

in

CP

to

Set

Operations

We

first

show

by

examples

under

what

conditions

the

logical

conjunction

of

two

CP-constraints

can

be

simplified

by

set

operations

If

t

is

a

mgci

of

a

term

t

bC

and

a

variable

it

is

possible

that

ae

I

-LRB-

t

-RRB-

as

sum

-LRB-

X

int

Y

int

-RRB-

-LRB-

-RRB-

above

Can

we

still

get

a

mgci

by

set

intersection

For

instance

assuming

of

Example

the

two

CP-terms

f

-LRB-

X

b

Y

a

-RRB-

and

f

-LRB-

X

c

Y

c

-RRB-

have

the

mgci

f

-LRB-

X

f

Y

f

-RRB-

but

no

common

declarations

We

need

another

invariant

which

will

be

preserved

by

our

unification

rules

Two

declarations

can

be

ordered

by

their

result

sorts

written

as

d

R

if

R

-LRB-

d

-RRB-

R

-LRB-

-RRB-

Because

is

monotone

d

entails

d

R

The

dotted

lines

in

Figure

indicate

where

d

R

but

not

d

Observe

that

R

is

not

anti-symmetric

for

example

-LRB-

-RRB-

-LRB-

-RRB-

and

-LRB-

-RRB-

-LRB-

-RRB-

for

the

declarations

in

Figure

Result-Complete

A

non-variable

CP-term

t

bC

is

result-complete

if

C

is

downwards

closed

w.r.t.

R

and

I

-LRB-

t

-RRB-

Can

a

similar

case

happen

if

two

terms

are

result-complete

For

example

if

we

change

R

-LRB-

-RRB-

to

C

in

and

become

result-complete

but

is

no

longer

regular

because

f

-LRB-

X

f

Y

f

-RRB-

no

longer

has

a

least

sort

We

show

that

this

observation

holds

for

constraint

simplification

in

the

general

case

Lemma

Let

t

be

two

non-variable

CP-terms

Then

I

-LRB-

-RRB-

I

-LRB-

t

-RRB-

t

bC

is

a

result-complete

mgci

of

the

two

result-complete

CP-terms

f

-LRB-

tn

-RRB-

and

f

-LRB-

-RRB-

iff

is

a

most

general

T-unifier

of

f

-LRB-

tn

-RRB-

and

f

-LRB-

-RRB-

t

f

-LRB-

tn

-RRB-

and

C

All

missing

proofs

can

be

found

in

-LSB-

Prehofer

-RSB-

Proof

We

show

that

t

bC

and

t

=-LRB-

bC

-RRB-

have

the

same

gound

instances

Assume

C

dng

g.

Using

distributivity

-LRB-

bC

-RRB-

gives

i

m

j

;p

-LRB-

-LRB-

t

-RRB-

-LRB-

t

-RRB-

-RRB-

All

disjuncts

with

are

in

bC

Hence

bC

-LRB-

-RRB-

and

we

only

have

to

show

that

all

disjuncts

with

are

redundant

ffl

If

OE

-LRB-

OE

is

symmetric

-RRB-

then

-LRB-

-LRB-

t

-RRB-

-LRB-

t

-RRB-

-RRB-

-LRB-

t

-RRB-

Now

U

-LRB-

t

-RRB-

implies

U

-LRB-

-RRB-

and

the

same

for

Hence

if

U

-LRB-

t

-RRB-

then

U

-LRB-

-RRB-

because

is

downwards

closed

Then

follows

ffl

If

and

then

if

t

have

no

common

instance

-LRB-

-LRB-

t

-RRB-

-LRB-

t

-RRB-

-RRB-

is

not

satisfiable

and

is

therefore

redundant

Otherwise

let

s

be

the

unique

least

sort

of

mgci

-LRB-

di

-RRB-

Then

there

has

to

be

at

least

one

declaration

with

R

-LRB-

-RRB-

s

and

mgci

-LRB-

di

-RRB-

Because

s

is

the

least

sort

s

R

-LRB-

-RRB-

and

s

R

-LRB-

-RRB-

Let

I

-LRB-

t

-RRB-

and

fd

j

d

We

show

first

that

C.

Because

t

is

a

instance

of

and

of

Lemma

entails

that

I

-LRB-

-RRB-

and

I

-LRB-

-RRB-

Then

the

result-completeness

of

and

entails

C

because

d

R

and

d

R

for

all

d

It

remains

to

show

that

j

-LRB-

-LRB-

t

-RRB-

-LRB-

t

-RRB-

-RRB-

Assume

t

with

j

-LRB-

-LRB-

-RRB-

-LRB-

-RRB-

-RRB-

Then

mgci

-LRB-

-RRB-

and

hence

and

entails

-LRB-

-RRB-

From

Theorem

follows

that

there

is

a

with

OE

-LRB-

i.e.

-RRB-

such

that

entails

-LRB-

-RRB-

For

S

S

D

D

we

define

S

uD

fd

D

j

R

-LRB-

d

-RRB-

Sg

Theorem

f

-LRB-

tn

-RRB-

is

a

mgci

of

the

CP-term

t

f

-LRB-

tn

-RRB-

bC

and

a

CP-variable

X

iff

u

X

does

not

occur

in

t

and

is

satisfiable

Furthermore

f

-LRB-

tn

-RRB-

is

result-complete

if

f

-LRB-

tn

-RRB-

bC

is

result-complete

It

is

easy

to

see

that

Theorem

and

Theorem

preserve

result-completeness

Using

Theorem

it

can

be

shown

that

applying

Theorem

preserves

validity

for

terms

t

bC

with

C

I

-LRB-

t

-RRB-

Constraint

Satisfaction

in

CP

In

the

previous

section

we

simplified

two

CP-constraints

locally

Now

we

show

how

to

ensure

global

satisfiability

for

the

rules

in

Figure

with

CP-constraints

In

the

original

sorted

logic

we

had

the

problem

of

multiple

unifiers

Each

one

of

these

corresponds

to

exactly

one

solution

of

the

corresponding

constraint

satisfaction

problem

in

CP-logic

Compared

to

sorted

logic

we

can

now

separate

the

problem

of

multiple

unifiers

-LRB-

i.e.

the

constraint

satisfaction

problem

in

CP

-RRB-

out

into

a

distinct

search

space

After

translating

the

sorted

logic

into

CP-logic

all

terms

are

valid

The

problem

is

that

computing

mgci

's

with

Theorem

does

not

preserve

validity

For

Efficient

implementations

of

this

set

operation

are

discussed

in

-LSB-

Prehofer

-RSB-

instance

in

Example

Theorem

gives

the

mgci

sum

-LRB-

X

fint

evn

oddg

Y

fint

evn

oddg

-RRB-

Assume

that

X

and

Y

have

additional

occurrences

Now

if

X

is

unified

with

a

variable

Z

fevng

and

Y

with

foddg

the

constraint

is

not

satisfiable

One

way

to

solve

this

problem

is

to

check

all

constraints

on

terms

whenever

a

term

is

substituted

for

another

term

but

these

constraint

checks

are

costly

and

often

redundant

Instead

to

guarantee

satisfiability

we

maintain

a

valid

instance

for

all

CP-terms

As

we

see

later

on

this

valid

instance

can

be

seen

as

a

representative

unifier

from

the

corresponding

cii

in

the

sorted

logic

If

we

in

the

unification

rules

solve

an

equation

s

Cs

t

Ct

we

also

solve

an

equation

with

the

two

corresponding

valid

instances

where

s

Cs

and

t

Ct.

Since

there

can

be

many

valid

terms

with

s

Cs

we

call

the

choice

term

of

s

Cs

If

s

Cs

is

valid

it

is

sufficient

to

use

s

Cs

as

the

choice

term

of

s

Cs

Consider

solving

an

equation

X

C

t

Ct

with

Theorem

where

X

is

a

variable

and

t

is

a

non-variable

term

Let

with

f

-LRB-

tn

-RRB-

be

the

mgci

of

X

C

and

t

Ct

and

let

f

-LRB-

-RRB-

be

the

mgci

of

the

choice

terms

of

X

and

t

Then

is

a

choice

term

of

Since

Theorem

does

not

preserve

validity

we

have

to

assure

that

the

choice

term

is

valid

For

that

purpose

the

unification

rules

select

a

declaration

d

f

-LRB-

sn

-RRB-

from

and

add

the

equations

-LRB-

-RRB-

Xn

sn

-LRB-

Xn

-RRB-

where

all

Xi

are

new

variables

to

the

set

of

equations

This

assures

that

j

d

-LRB-

-RRB-

and

is

valid

or

the

added

equations

are

not

solvable

Since

we

have

a

choice

for

selecting

d

we

call

a

choice

point

To

see

how

choice

terms

relate

to

choice

points

recall

that

a

term

t

is

valid

after

t

has

been

translated

from

the

sorted

logic

into

CP-logic

Therefore

t

itself

is

initially

used

as

the

choice

term

of

t

If

the

unification

rules

as

in

the

case

above

add

equations

that

only

affect

the

choice

terms

the

choice

terms

may

become

true

instances

of

their

corresponding

CP-terms

Since

the

added

equations

depend

on

the

declarations

chosen

at

some

choice

terms

these

choice

terms

are

called

choice

points

For

instance

solving

the

equation

evn

where

sum

-LRB-

X

int

sum

-LRB-

Y

int

Z

int

-RRB-

-RRB-

with

Theorem

gives

mgci

-LRB-

-RRB-

sum

-LRB-

X

int

sum

-LRB-

Y

int

Z

int

-RRB-

-RRB-

Since

and

are

valid

their

choice

terms

are

identical

to

and

respectively

To

obtain

a

choice

term

for

we

arbitrarily

select

from

This

adds

two

new

equations

evn

X

int

and

evn

sum

-LRB-

Y

int

Z

int

-RRB-

To

solve

these

we

have

to

make

sum

-LRB-

Y

Z

-RRB-

a

choice

point

We

select

at

sum

-LRB-

Y

Z

-RRB-

and

add

equations

similar

to

above

After

solving

all

these

equations

we

obtain

sum

-LRB-

X

evn

sum

-LRB-

Y

odd

Z

odd

-RRB-

-RRB-

where

the

selected

declarations

are

indicated

by

overlining

Then

all

the

subterms

of

the

choice

point

including

are

valid

Notice

that

without

constraints

on

terms

sum

-LRB-

X

evn

sum

-LRB-

Y

odd

Z

odd

-RRB-

-RRB-

is

a

common

instance

of

and

t

in

the

original

sorted

language

Obviously

a

term

differs

from

its

choice

term

only

in

the

constraints

Therefore

to

represent

the

CP-term

and

its

choice

term

it

is

sufficient

to

use

two

separate

constraints

on

one

term

The

first

one

called

cp

is

the

constraint

of

the

CP-mgci

The

second

called

ch

represents

a

choice

term

We

write

ch-constraints

as

subscripts

For

instance

we

write

and

as

one

term

sum

-LRB-

X

intevn

sum

-LRB-

Y

intodd

Z

intodd

-RRB-

-RRB-

Observe

that

the

first

choice

point

limits

the

choice

for

the

second

sum

-LRB-

Y

Z

-RRB-

to

Selecting

at

for

example

restricts

the

choices

at

sum

-LRB-

Y

Z

-RRB-

to

We

now

have

a

constraint

satisfaction

search

space

where

every

declaration

of

every

choice

point

is

a

possible

choice

Therefore

it

is

desirable

to

have

small

constraint

sets

as

pursued

in

Section

If

unification

fails

for

the

current

choice

term

we

have

to

search

for

another

choice

term

we

will

implement

this

search

with

backtracking

If

there

is

no

other

choice

term

unification

fails

for

the

CP-term

To

improve

backtracking

we

build

up

a

dependency

structure

between

choice

points

and

their

immediate

subterms

for

instance

the

subterms

X

and

sum

-LRB-

Y

Z

-RRB-

will

keep

a

reference

to

the

choice

point

One

term

can

be

subject

to

several

choices

so

a

set

of

references

is

maintained

in

the

CP-unification

rules

in

the

next

section

We

define

P

to

be

a

data

structure

that

contains

the

set

of

all

choice

points

that

have

been

created

so

far

Summarizing

the

above

observations

we

obtain

the

following

dual

terms

each

representing

two

CP-terms

ffl

Dual

Variables

Xcp

ch

bt

where

cp

ch

S

bt

P

ffl

Dual

Terms

fcp

ch

cd

bt

-LRB-

tn

-RRB-

where

cp

ch

D

-LRB-

f

-RRB-

cd

ch

bt

P

The

parameter

bt

of

a

term

t

will

always

be

the

set

of

all

choice

points

which

are

a

direct

superterm

of

some

occurrence

of

t

The

parameter

cd

indicates

the

chosen

declaration

if

t

is

a

choice

point

otherwise

if

cd

t

is

not

a

choice

point

Initially

after

translating

sorted

terms

into

CP-terms

ch

is

set

to

cp

cd

and

bt

The

parameters

cd

and

bt

are

used

to

organize

backtracking

and

have

no

-LRB-

logical

-RRB-

meaning

They

are

attached

to

terms

-LRB-

in

substitutions

-RRB-

for

notational

convenience

As

long

as

a

term

t

cp

and

all

superterms

of

t

cp

are

valid

t

's

bt

set

is

empty

and

cd

Only

if

bt

and

ch

cp

t

is

affected

by

a

choice

and

we

say

that

t

has

a

choice

term

as

described

above

A

T-substitution

with

dual

terms

such

as

ftcp

ch

cd

bt

g

stands

for

two

T-substitutions

ft

cp

and

ft

ch

if

we

represent

t

and

the

choice

term

of

t

separately

Furthermore

we

must

assure

for

the

above

T-substitution

on

dual

terms

that

and

that

is

the

set

of

all

choice

points

which

are

direct

superterms

of

It

is

sufficient

to

try

only

maximal

declarations

from

t

's

constraint

C

-LSB-

Prehofer

-RSB-

In

examples

as

above

we

attach

only

the

cp

and

ch

constraints

to

the

terms

and

show

the

chosen

declarations

and

the

dependence

structure

represented

by

the

bt

's

separately

The

Unification

Rules

The

rules

in

Figure

are

a

refinement

of

the

rules

in

Figure

and

apply

the

theorems

of

Section

to

dual

terms

The

rules

compute

the

CP-mgci

and

its

choice

term

at

the

same

time

We

showed

that

we

can

represent

CP-constraints

as

sets

and

implement

the

logical

conjunctions

as

set

operations

Therefore

in

the

rules

in

Figure

we

treat

constraints

as

sets

All

four

rules

unify

two

terms

t

and

both

are

throughout

replaced

by

their

mgci

hence

the

bt

set

of

their

mgci

is

obtained

by

the

union

of

the

bt

sets

of

t

and

of

To

assure

satisfiability

the

rules

have

to

check

that

no

constraints

are

empty

The

requirement

cd

ch

assures

that

the

choice

term

is

a

instance

of

the

CP-mgci

The

rules

operate

on

arbitrary

equations

between

dual

terms

which

possibly

represent

an

exponential

number

of

sorted

unifiers

In

practice

most

terms

do

not

represent

multiple

unifiers

Then

the

parameters

ch

bt

and

cd

are

not

needed

and

simpler

terms

and

simpler

rules

can

be

used

-LSB-

Prehofer

-RSB-

Rule

creates

choice

points

and

adds

new

equations

as

shown

above

The

new

variables

in

the

added

equations

have

S

as

cp-constraint

to

assure

that

the

cpconstraints

of

the

subterms

of

the

choice

points

are

not

affected

These

variables

also

have

a

bt

set

with

a

reference

to

the

newly

created

choice

point

This

reference

is

propagated

by

the

equations

to

all

direct

subterms

of

the

new

choice

term

Rule

makes

a

choice

by

arbitrarily

selecting

a

maximal

declaration

Whenever

a

failure

occurs

because

of

the

choices

at

the

choice

points

in

P

-LRB-

i.e.

cd

ch

or

ch

;-RRB-

the

procedure

backtracking

explained

in

the

next

section

is

invoked

Rule

is

complicated

because

both

terms

are

possible

choice

points

If

neither

of

them

is

a

choice

point

the

rule

is

simple

If

one

of

them

is

we

have

to

make

sure

that

its

choice

term

is

also

a

choice

term

of

the

resulting

mgci

If

both

are

choice

terms

their

chosen

declarations

cd

and

must

be

identical

if

not

the

previously

made

choices

fail

and

the

procedure

backtracking

is

invoked

Furthermore

if

both

are

choice

points

Rule

collapses

them

into

one

choice

point

Unification

Backtracking

To

get

a

new

valid

choice

term

we

have

to

search

through

the

choice

points

and

find

new

consistent

choices

We

perform

this

search

in

the

constraint

satisfaction

search

space

by

specialized

chronological

backtracking

If

we

apply

the

rule

of

resolution

as

presented

in

Section

L

Mm

Nn

-LRB-

Mm

Nn

-RRB-

we

first

compute

a

most

general

T-unifier

for

L

and

and

apply

it

to

the

remaining

literals

Mi

and

Ni

in

the

resolvent

Assume

Mi

and

Ni

contain

only

valid

terms

Then

applying

preserves

satisfiability

If

Mi

and

Ni

have

choice

-LRB-

U

-LSB-

fXcp

ch

bt

g

-RRB-

=-RRB-

-LRB-

U

-RRB-

where

cp

ch

bt

-LSB-

fXcp

ch

bt

g

IF

OR

-LRB-

AND

not

backtrack

-LRB-

max

-LRB-

P

-RRB-

max

-LRB-

-RRB-

-RRB-

-RRB-

THEN

fail

-LRB-

U

-LSB-

-LRB-

tn

-RRB-

Xcp

ch

btg

-RRB-

=-RRB-

-LRB-

U

-LSB-

fXcp

ch

bt

-LRB-

tn

-RRB-

g

-RRB-

-LRB-

U

-LSB-

fXcp

ch

bt

-LRB-

tn

-RRB-

g

-RRB-

=-RRB-

-LRB-

U

-LSB-

W

-RRB-

where

cp

u

ch

u

bt

-LSB-

fXcp

ch

bt

-LRB-

tn

-RRB-

-LRB-

tn

-RRB-

-LRB-

tn

-RRB-

g

W

IF

OR

X

occurs

in

-LRB-

tn

-RRB-

THEN

fail

IF

AND

not

backtrack

-LRB-

max

-LRB-

P

-RRB-

max

-LRB-

-RRB-

-RRB-

THEN

fail

IF

AND

AND

not

backtrack

-LRB-

max

-LRB-

P

-RRB-

-LRB-

:-RRB-

-RRB-

THEN

fail

IF

AND

THEN

make

-LRB-

:-RRB-

a

choice

point

P

P

-LSB-

-LRB-

tn

-RRB-

Select

a

maximal

declaration

f

-LRB-

sn

-RRB-

sn

from

and

W

fXiS

si

f

fg

ti

j

i

ngg

where

f

fg

is

a

one

element

set

containing

a

reference

to

-LRB-

tn

-RRB-

and

Xi

are

new

variables

-LRB-

U

-LSB-

ffcp

ch

cd

bt

-LRB-

tn

-RRB-

f

-LRB-

-RRB-

g

-RRB-

=-RRB-

-LRB-

U

-LSB-

tng

-RRB-

where

cp

ch

bt

-LSB-

ae

cd

IF

ELSE

ffcp

ch

cd

bt

-LRB-

tn

-RRB-

-LRB-

tn

-RRB-

f

-LRB-

-RRB-

-LRB-

tn

-RRB-

g

IF

f

f

OR

THEN

fail

IF

AND

not

backtrack

-LRB-

max

-LRB-

P

-RRB-

max

-LRB-

-RRB-

-RRB-

THEN

fail

IF

cd

AND

AND

cd

AND

not

backtrack

-LRB-

max

-LRB-

P

-RRB-

-LRB-

:-RRB-

-RRB-

THEN

fail

IF

AND

AND

not

backtrack

-LRB-

max

-LRB-

P

-RRB-

-LRB-

:-RRB-

-RRB-

THEN

fail

Fig.

CP-Unification

Rules

points

then

these

choice

points

must

have

been

created

at

previous

resolution

steps

Therefore

we

assume

that

P

includes

all

choice

points

of

all

previous

unifications

in

the

current

derivation

These

choice

points

can

affect

the

current

choices

even

if

they

do

not

appear

in

the

currently

resolved

clauses

Hence

backtracking

covers

all

choice

points

that

have

been

created

in

the

whole

derivation

of

the

two

resolved

clauses

FUNCTION

backtrack

-LRB-

P

term

min

backtrack

-RRB-

IF

min

backtrack

P

term

THEN

skip

TRUE

ELSE

skip

FALSE

found

FALSE

Assume

P

term

fcp

ch

cd

bt

-LRB-

tn

-RRB-

REPEAT

WHILE

-LRB-

not

found

AND

not

skip

AND

has

more

choices

-LRB-

ch

cd

-RRB-

-RRB-

cd

next

choice

-LRB-

ch

cd

-RRB-

found

try

declaration

-LRB-

P

term

cd

-RRB-

ENDWHILE

skip

FALSE

IF

-LRB-

not

found

-RRB-

THEN

IF

-LRB-

backtrack

-LRB-

previous

choice

point

-LRB-

Pterm

-RRB-

min

backtrack

-RRB-

-RRB-

THEN

cd

ELSE

RETURN

FALSE

UNTIL

-LRB-

found

-RRB-

RETURN

TRUE

FUNCTION

try

declaration

-LRB-

Pterm

;d

-RRB-

Undo

all

choices

at

choice

points

t

with

P

term

t

Assume

d

f

-LRB-

sn

-RRB-

sn

and

P

term

fcp

ch

cd

bt

-LRB-

tn

-RRB-

FOR

EACH

ti

DO

IF

ti

THEN

si

IF

THEN

RETURN

FALSE

ELSE

IF

ti

-LRB-

-RRB-

THEN

u

si

IF

THEN

RETURN

FALSE

IF

AND

ti

P

term

AND

THEN

RETURN

FALSE

RETURN

TRUE

Fig.

Backtracking

Algorithm

In

the

following

we

restrict

ourselves

to

SLD-resolution

such

as

in

Prolog

We

show

in

-LSB-

Prehofer

-RSB-

how

to

extend

unification

backtracking

to

general

resolution

This

unification

backtracking

is

independent

of

the

ordinary

Prolog

backtracking

Unification

backtracking

could

be

performed

like

ordinary

chronological

backtracking

After

a

failure

the

last

choice

point

is

selected

and

all

substitutions

since

this

point

are

undone

In

this

specialized

backtracking

we

will

find

the

first

choice

point

that

can

affect

the

failure

using

the

dependency

structure

Also

we

will

not

undo

substitutions

and

cp-constraints

Because

choice

terms

differ

only

in

the

ch-constraints

only

these

have

to

be

undone

Thus

we

solely

work

in

the

constraint

satisfaction

search

space

Furthermore

the

dependency

structure

is

constant

during

a

search

in

this

search

space

because

it

depends

only

on

the

primary

resolution

search

space

We

use

the

time

of

creation

to

order

the

choice

points

P

This

ordering

denoted

by

does

not

necessarily

reflect

the

term

structure

that

is

for

two

choice

points

t

that

can

be

a

subterm

of

t

or

vice

versa

Then

the

search

space

can

be

described

by

a

list

of

choice

points

cn

where

the

ci

's

appear

in

the

order

they

have

been

created

in

the

application

of

the

above

rules

At

each

ci

a

choice

is

made

that

is

if

possible

consistent

with

the

subterms

of

ci

If

a

variable

X

C

is

a

subterm

of

several

ci

's

the

constraint

of

its

choice

term

must

be

the

intersection

of

the

sorts

that

have

been

selected

for

X

at

each

occurrence

of

X.

Also

choice

points

can

be

subterms

of

each

other

and

limit

choices

of

other

choice

terms

Therefore

if

we

make

a

choice

at

ci

this

choice

may

invalidate

the

current

choice

at

another

choice

point

if

cd

ch

for

The

algorithm

in

Figure

modifies

ch

constraints

and

the

chosen

declarations

-LRB-

cd

-RRB-

to

obtain

a

satisfiable

choice

term

The

function

backtrack

handles

choice

points

recursively

in

descending

order

with

respect

to

and

is

called

with

the

maximal

element

of

P

The

second

argument

of

the

function

backtrack

min

backtrack

determines

the

minimal

backtracking

depth

It

indicates

the

maximal

choice

point

that

can

change

the

choice

for

a

term

t

with

ch

or

cd

ch

If

ch

the

maximal

element

in

the

bt

set

of

t

is

the

first

choice

point

that

affects

ch

In

the

second

case

cd

ch

we

have

to

backtrack

at

least

to

t

and

make

a

new

valid

choice

The

following

functions

are

used

to

iterate

over

the

maximal

elements

of

cd

First

in

Rule

a

maximal

declaration

is

selected

If

backtracking

is

invoked

the

function

next

choice

-LRB-

ch

cd

-RRB-

iterates

over

the

remaining

maximal

elements

of

cd

until

it

reaches

the

last

element

Only

then

the

function

has

more

choices

-LRB-

ch

cd

-RRB-

returns

false

In

that

case

cd

can

be

set

to

and

the

next

invocation

of

the

function

next

choice

-LRB-

ch

cd

-RRB-

starts

over

again

with

the

first

maximal

declaration

The

function

try

declaration

-LRB-

t

d

-RRB-

takes

a

choice

point

t

and

a

declaration

d

as

its

arguments

It

intersects

the

ch-constraints

of

the

subterms

of

t

with

the

sorts

of

d

and

returns

true

if

the

choice

is

consistent

with

the

choices

at

all

choice

points

with

t

If

this

succeeds

at

all

choice

points

we

obtain

a

new

choice

term

Examples

and

Comparisons

to

Sorted

Logic

The

first

example

is

intended

to

show

the

restructuring

of

the

search

space

by

using

CP-logic

We

assume

as

above

and

the

two

program

clauses

p

-LRB-

X

evn

-RRB-

p

-LRB-

X

odd

-RRB-

When

solving

the

goal

:p

-LRB-

sum

-LRB-

int

int

-RRB-

-RRB-

:p

-LRB-

sum

-LRB-

int

int

-RRB-

-RRB-

with

SLD-resolution

-LRB-

Prolog

-RRB-

there

are

two

choices

at

each

resolution

step

and

the

at

each

of

these

there

are

in

sorted

logic

two

unifiers

This

creates

the

search

space

in

Figure

The

choices

caused

by

multiple

unifiers

are

circled

The

search

space

for

CP-logic

-LRB-

see

Fig.

-RRB-

shows

the

constraint

satisfaction

search

space

in

the

form

of

the

curved

lines

Each

curved

line

corresponds

to

one

unifier

in

the

sorted

logic

At

every

resolution

step

we

only

have

to

select

one

of

these

unifiers

for

a

deduction

To

see

the

advantages

from

this

search

space

assume

the

number

of

multiple

unifiers

doubles

at

one

unification

Then

in

the

ordersorted

case

the

whole

subtree

doubles

in

CP-logic

only

the

constraint

search

space

doubles

We

assume

that

if

it

modifies

one

occurrence

of

a

term

t

it

also

modifies

all

occurrences

of

t.

Fig.

Search

Space

with

Sorted

Logic

Fig.

Search

Space

with

CP-Logic

Furthermore

a

CP-term

can

be

seen

as

an

upper

bound

-LRB-

w.r.t

-RRB-

of

all

its

choice

terms

which

correspond

to

common

instances

in

sorted

logic

If

this

single

CP-term

fails

all

sorted

common

instances

would

fail

also

That

means

in

the

sorted

case

we

would

have

to

generate

each

one

of

them

and

each

single

one

would

fail

Also

search

in

the

constraint

satisfaction

search

space

can

be

highly

optimized

as

shown

in

the

next

example

The

second

example

shows

the

details

of

a

derivation

with

CP-logic

in

particular

backtracking

We

again

use

SLD-resolution

and

assume

-LRB-

Fig.

-RRB-

and

the

two

program

clauses

p

-LRB-

X

evnevn

-RRB-

q

-LRB-

Y

pospos

-RRB-

Recall

that

the

sorts

and

declarations

in

subscripts

indicate

the

choice

terms

which

correspond

to

sorted

unifiers

The

top

section

of

Figure

shows

the

initial

goal

list

The

lower

five

sections

show

the

goals

after

each

of

the

five

resolution

steps

with

the

the

five

goals

Since

unification

backtracking

includes

the

already

resolved

goals

only

these

are

shown

The

second

section

of

Figure

shows

the

first

goal

after

unification

with

Fact

Both

sum

-LRB-

:-RRB-

terms

have

become

choice

points

At

the

outer

sum

-LRB-

:-RRB-

term

to

which

we

refer

as

choice

point

-LRB-

a

-RRB-

declaration

-LRB-

-RRB-

has

been

selected

Therefore

the

second

choice

point

sum

-LRB-

Y

Z

-RRB-

to

which

we

refer

as

-LRB-

b

-RRB-

is

restricted

to

the

declarations

because

declaration

-LRB-

-RRB-

at

-LRB-

a

-RRB-

restricts

-LRB-

b

-RRB-

to

sort

odd

At

choice

point

-LRB-

b

-RRB-

declaration

-LRB-

-RRB-

has

been

selected

Fig.

Sort

Theory

Initial

Goals

p

-LRB-

sum

-LRB-

X

intint

sum

-LRB-

Y

intint

Z

intint

-RRB-

-RRB-

-RRB-

-RRB-

q

-LRB-

prod

-LRB-

Y

intint

Z

intint

-RRB-

-RRB-

q

-LRB-

Z

intint

-RRB-

p

-LRB-

Y

intint

-RRB-

p

-LRB-

X

intint

-RRB-

p

-LRB-

sum

-LRB-

X

intodd

sum

-LRB-

Y

intevn

Z

intodd

-RRB-

-RRB-

-RRB-

-RRB-

p

-LRB-

sum

-LRB-

X

intodd

sum

-LRB-

Y

inte

pos

Z

into

pos

-RRB-

-RRB-

-RRB-

-RRB-

q

-LRB-

prod

-LRB-

Y

inte

pos

Z

into

pos

-RRB-

-RRB-

p

-LRB-

sum

-LRB-

X

intodd

sum

-LRB-

Y

inte

pos

Z

into

pos

-RRB-

-RRB-

-RRB-

-RRB-

q

-LRB-

prod

-LRB-

Y

inte

pos

Z

poso

pos

-RRB-

-RRB-

q

-LRB-

Z

poso

pos

-RRB-

p

-LRB-

sum

-LRB-

X

intodd

sum

-LRB-

Y

evne

pos

Z

into

pos

-RRB-

-RRB-

-RRB-

-RRB-

q

-LRB-

prod

-LRB-

Y

evne

pos

Z

poso

pos

-RRB-

-RRB-

q

-LRB-

Z

poso

pos

-RRB-

p

-LRB-

Y

evne

pos

-RRB-

p

-LRB-

sum

-LRB-

X

evnevn

sum

-LRB-

Y

evne

pos

Z

inte

pos

-RRB-

-RRB-

-RRB-

-RRB-

q

-LRB-

prod

-LRB-

Y

evne

pos

Z

pose

pos

-RRB-

-RRB-

q

-LRB-

Z

pose

pos

-RRB-

p

-LRB-

Y

evne

pos

-RRB-

p

-LRB-

X

evnevn

-RRB-

Fig.

Goal-Reduction

for

the

Prolog

Example

Fig.

Query

with

a

Possible

Dependency

Structure

Then

in

the

third

section

the

second

literal

in

the

goal

has

been

unified

with

the

second

program

clause

making

prod

-LRB-

Y

Z

-RRB-

the

third

choice

point

called

-LRB-

c

-RRB-

At

-LRB-

c

-RRB-

declaration

-LRB-

-RRB-

has

been

selected

Figure

shows

the

references

from

the

subterms

to

the

three

choice

points

-LRB-

a

-RRB-

-LRB-

c

-RRB-

The

bt

set

of

a

term

in

Figure

contains

all

the

terms

to

which

it

has

an

outgoing

arrow

For

instance

the

bt

set

of

Z

is

fb

cg

Now

there

are

two

choices

at

each

point

and

because

there

are

no

conflicts

between

any

choices

this

corresponds

to

a

cii

of

size

eight

in

the

sorted

language

Unifying

the

third

and

fourth

goals

with

the

above

program

clauses

changes

the

cp-constraints

of

Y

and

Z.

To

resolve

the

last

goal

unification

with

the

first

program

clause

fails

for

the

choice

term

of

X

which

is

of

sort

odd

but

not

for

the

cp-constraint

Then

the

function

backtracking

is

invoked

with

the

parameters

-LRB-

c

-RRB-

and

-LRB-

a

-RRB-

hence

skips

the

choice

points

-LRB-

c

-RRB-

and

-LRB-

b

-RRB-

At

-LRB-

a

-RRB-

backtracking

changes

cd

to

declaration

-LRB-

-RRB-

which

restricts

the

ch-constraint

of

-LRB-

b

-RRB-

to

Then

at

-LRB-

b

-RRB-

and

-LRB-

c

-RRB-

because

the

cp-constraints

of

Y

and

Z

have

have

been

reduced

-LRB-

-RRB-

and

-LRB-

-RRB-

respectively

are

the

only

possible

choices

which

give

the

final

instances

of

the

five

goals

Observe

that

Y

and

Z

have

become

more

restricted

in

the

primary

resolution

search

space

and

that

these

additional

cp-constraints

limit

our

choices

at

-LRB-

b

-RRB-

and

-LRB-

c

-RRB-

thus

pruning

the

constraint

search

space

This

can

be

seen

as

constraint

propagation

from

the

resolution

search

space

to

the

constraint

search

space

The

claim

is

that

if

there

are

many

sorted

unifiers

it

is

not

necessary

to

generate

all

of

them

With

sorted

logic

an

exponential

number

of

maximal

unifiers

directly

causes

an

exponential

blowup

of

the

resolution

search

space

Instead

we

simply

select

a

representative

unifier

in

the

form

of

a

choice

term

to

ensure

satisfiability

and

delay

further

search

Then

if

further

constraints

make

the

search

space

smaller

many

sorted

unifiers

would

fail

When

the

representative

fails

we

use

intelligent

backtracking

and

these

additional

constraints

to

effectively

reduce

the

search

space

Conclusions

Most

other

implementation-oriented

approaches

to

order-sorted

resolution

often

avoid

polymorphism

or

impose

strong

restrictions

on

it

e.g.

-LSB-

Beierle

et

al.

Huber

and

Varsek

Smolka

-RSB-

The

approaches

by

Beierle

and

Smolka

are

based

on

parametric

polymorphism

-LRB-

see

also

-LSB-

Hanus

Mycroft

and

O'Keefe

-RSB-

-RRB-

and

allow

for

sort

constructors

which

are

not

supported

here

Apart

from

this

our

approach

is

much

more

general

since

the

sortal

behavior

of

functions

can

be

specified

with

minimal

restrictions

It

our

view

the

existence

of

multiple

unifiers

is

not

an

obstacle

but

an

opportunity

for

efficient

implementations

To

handle

an

exponential

number

of

maximally

general

unifiers

in

a

polymorphic

sort

theory

we

propose

constraining

non-variable

terms

by

disjunctions

of

declarations

For

unification

the

logical

conjunction

of

these

constraints

can

be

reduced

to

set

operations

The

embedding

in

CP-logic

assures

a

single

most

general

unifier

and

creates

a

separate

constraint

satisfaction

search

space

The

complexity

of

the

constraint

search

space

does

not

affect

the

complexity

of

the

primary

resolution

search

space

Informally

speaking

with

sorted

logic

the

total

search

space

doubles

if

the

number

of

maximal

unifiers

doubles

with

CP-logic

only

the

constraint

search

space

doubles

Also

we

commit

ourselves

to

only

one

solution

of

the

constraint

satisfaction

problem

which

can

be

seen

as

selecting

a

representative

unifier

instead

of

generating

all

maximal

unifiers

a

priori

Furthermore

a

CP-term

can

be

seen

as

an

upper

bound

of

all

corresponding

unifiers

in

the

sorted

case

This

means

that

if

unification

fails

for

the

CP-term

an

exponential

number

of

sorted

unifiers

would

fail

also

The

restructuring

of

the

search

space

allows

for

additional

optimizations

For

instance

constraints

can

be

propagated

from

the

resolution

search

space

to

the

constraint

satisfaction

search

space

We

can

build

up

a

dependency

structure

which

only

depends

on

the

primary

resolution

search

space

to

perform

unification

backtracking

more

intelligently

and

to

propagate

constraints

within

the

constraint

satisfaction

search

space

These

results

motivate

shifting

search

from

the

main

reasoner

to

the

constraint

search

space

by

expressing

knowledge

with

sorts

and

sortal

behavior

of

functions

It

is

an

open

question

if

this

method

of

restructuring

the

search

space

can

be

applied

to

other

logics

in

a

similar

way

Acknowledgement

The

author

is

indebted

to

Alan

Frisch

for

numerous

valuable

discussions

Also

Rich

Scherl

Andreas

Werner

and

Christoph

Brzoska

contributed

to

this

work

References

-LSB-

A

t-Kaci

et

al.

-RSB-

H

A

t-Kaci

R.

Boyer

P.

Lincoln

and

R.

Nasr

Efficient

lattice

operations

ACM

Transactions

on

Programming

Languages

and

Systems

-LRB-

-RRB-

-LCB-

January

-LSB-

Beierle

et

al.

-RSB-

C.

Beierle

G.

Meyer

and

H.

Semle

Extending

the

Warren

abstract

machine

to

polymorphic

order-sorted

resolution

In

Logic

Programming

Proceedings

of

the

International

Symposium

pages

-LCB-

October

-LSB-

B?urkert

-RSB-

Hans-J

urgen

B?urkert

A

Resolution

Principle

for

a

Logic

with

Restricted

Quantifiers

Springer-LNAI

-LSB-

Cohn

-RSB-

Anthony

G.

Cohn

On

the

solution

of

Schubert

's

Steamroller

in

many

sorted

logic

In

Proceedings

of

the

Ninth

International

Joint

Conference

on

Artificial

Intelligence

pages

-LCB-

August

-LSB-

Cohn

-RSB-

Anthony

G.

Cohn

Taxonomic

reasoning

with

many-sorted

logics

Artificial

Intelligence

Review

-LCB-

-LSB-

Frisch

and

Scherl

-RSB-

Alan

M.

Frisch

and

Richard

B.

Scherl

A

general

framework

for

modal

deduction

In

Principles

of

Knowledge

Representation

and

Reasoning

Proceedings

of

the

Second

International

Conference

pages

-LCB-

Morgan

Kaufman

San

Mateo

CA

-LSB-

Frisch

-RSB-

Alan

M.

Frisch

An

investigation

into

inference

with

restricted

quantification

and

a

taxonomic

representation

SIGART

Newsletter

-LRB-

-RRB-

-LCB-

-LSB-

Frisch

-RSB-

Alan

M.

Frisch

The

substitutional

framework

for

hybrid

reasoning

Working

Notes

of

the

Fall

Symposium

on

Principles

of

Hybrid

Reasoning

Asilomar

CA.

November

-LSB-

Frisch

-RSB-

Alan

M.

Frisch

The

substitutional

framework

for

sorted

deduction

Fundamental

results

on

hybrid

reasoning

Artificial

Intelligence

-LCB-

-LSB-

Hanus

-RSB-

Michael

Hanus

Horn

clause

programs

with

polymorphic

types

semantics

and

resolution

pages

-LCB-

TAPSOFT

Springer

Verlag

-LSB-

Huber

and

Varsek

-RSB-

H.

Huber

and

L.

Varsek

Extended

Prolog

for

order-sorted

resolution

In

Proceedings

of

the

IEEE

Symposium

on

Logic

Programming

pages

-LCB-

-LSB-

Martelli

and

Montanari

-RSB-

Alberto

Martelli

and

Ugo

Montanari

An

efficient

unification

algorithm

ACM

Transactions

on

Programming

Languages

and

Systems

-LRB-

-RRB-

-LCB-

April

-LSB-

Mycroft

and

O'Keefe

-RSB-

A.

Mycroft

and

U.

O'Keefe

A

polymorphic

type

system

for

Prolog

Artificial

Intelligence

-LRB-

-RRB-

-LCB-

-LSB-

Prehofer

-RSB-

Christian

F.

Prehofer

A

constraint

language

for

order-sorted

polymorphic

resolution

Master

's

thesis

Univ.

of

Illinois

at

Urbana-Champaign

January

-LSB-

Schmidt-Schauss

-RSB-

Manfred

Schmidt-Schauss

Computational

Aspects

of

an

OrderSorted

Logic

with

Term

Declarations

Springer-LNAI

-LSB-

Smolka

-RSB-

Gert

Smolka

Logic

programming

over

polymorphically

order-sorted

types

PhD

thesis

Universit?at

Kaiserslautern

May

-LSB-

Walther

-RSB-

Christoph

Walther

A

mechanical

solution

of

Schubert

's

Steamroller

by

many-sorted

resolution

Artificial

Intelligence

-LRB-

-RRB-

-LCB-

This

article

was

processed

using

the

LaTEX

macro

package

with

LLNCS

style

constraints polymorphism resolution unification