Full

Indexing

for

Lazy

Narrowing

Werner

Hans

Herbert

Kuchen

Stephan

Winkler

RWTH

Aachen

Lehrstuhl

fur

Informatik

II

Abstract

Indexing

improves

the

efficiency

of

many

logic

programs

considerably

Here

we

present

a

new

indexing

scheme

for

a

functional

logic

language

which

has

lazy

narrowing

as

operational

semantics

The

main

difficulty

is

that

the

arguments

of

a

function

may

be

unevaluated

and

that

the

indexer

has

to

incrementally

initiate

the

evaluation

of

the

arguments

to

head

normal

form

if

this

is

required

for

the

selection

of

a

rule

Moreover

each

argument

has

to

be

evaluated

as

early

as

possible

in

order

to

avoid

re-evaluations

of

arguments

due

to

backtracking

Introduction

Indexing

is

an

important

technique

for

improving

the

efficiency

of

logic

programs

The

idea

is

to

avoid

the

unification

of

the

considered

goal

with

the

left

hand

sides

of

those

rules

where

it

is

clear

that

this

unification

is

going

to

fail

and

to

access

applicable

rules

directly

by

using

information

about

the

arguments

If

only

one

rule

remains

applicable

the

computation

is

-LRB-

locally

-RRB-

deterministic

and

a

choice

point

is

not

needed

at

this

place

If

no

rule

remains

applicable

backtracking

can

be

initiated

directly

Several

indexing

schemes

have

been

proposed

which

differ

in

the

number

of

arguments

they

consider

-LRB-

e.g.

one

-LSB-

-RSB-

or

all

-RRB-

and

the

auxiliary

structures

used

e.g.

decision

trees

decision

graphs

Decision

trees

can

cause

an

exponential

code

explosion

By

using

decision

graphs

-LSB-

-RSB-

common

parts

can

be

shared

reducing

the

code

explosion

Another

alternative

-LSB-

-RSB-

is

to

handle

all

the

arguments

separately

and

to

compute

the

intersection

of

the

sets

of

rules

which

remain

applicable

after

investigating

each

individual

argument

All

these

approaches

rely

on

the

fact

that

the

arguments

of

a

predicate

are

known

when

the

indexing

scheme

is

applied

An

extension

of

logic

programming

languages

are

so-called

functional

logic

languages

-LSB-

-RSB-

They

have

a

syntax

like

purely

functional

languages

but

use

narrowing

-LCB-

a

unification

based

parameter

passing

mechanism

which

subsumes

rewriting

and

SLD

resolution

-LCB-

as

operational

semantics

Several

narrowing

strategies

can

be

considered

Eager

narrowing

evaluates

the

arguments

of

a

function

before

the

function

is

applied

For

eager

narrowing

the

indexing

schemes

for

logic

languages

are

-LRB-

almost

-RRB-

directly

applicable

More

interesting

is

a

lazy

narrowing

strategy

which

allows

to

handle

infinite

data

structures

and

Aachen

Germany

fhans,herbert,winklerg@zeus.informatik.rwth-aachen.de;

this

work

was

supported

by

DFG-grant

In

a

more

modular

style

of

programming

-LRB-

see

-LSB-

-RSB-

for

an

overview

of

the

advantages

of

lazy

evaluation

-RRB-

Lazy

narrowing

evaluates

the

arguments

of

a

function

as

late

as

possible

and

only

when

they

are

demanded

An

argument

is

demanded

if

it

has

to

be

unified

with

a

constructor

term

t

on

the

left

hand

side

of

a

rule

In

this

case

it

is

evaluated

to

so-called

head

normal

form

-LRB-

hnf

-RRB-

i.e.

to

an

expression

which

is

an

unbound

variable

or

which

has

a

constructor

at

the

top

-LRB-

and

some

possibly

unevaluated

subexpressions

-RRB-

If

the

topmost

constructor

matches

the

subexpressions

are

unified

analogously

with

the

corresponding

subterms

of

t.

For

lazy

narrowing

the

existing

indexing

schemes

can

not

be

used

since

they

expect

the

arguments

to

be

evaluated

Instead

an

indexing

scheme

is

needed

which

incrementally

initiates

the

evaluation

of

-LRB-

parts

of

-RRB-

the

arguments

to

hnf

if

this

is

needed

in

order

to

decide

which

rules

are

applicable

In

this

paper

we

will

present

such

an

indexing

scheme

It

uses

a

decision

graph

-LRB-

although

for

the

simplicity

of

presentation

we

will

use

decision

trees

here

-RRB-

as

auxiliary

structure

Moreover

the

indexing

code

has

to

initiate

the

evaluation

of

the

arguments

of

a

function

as

early

as

safely

possible

in

order

to

avoid

re-evaluations

of

arguments

This

will

be

explained

in

detail

in

Section

This

paper

is

organized

as

follows

In

Section

we

present

the

functional

logic

language

Babel

which

serves

as

an

example

language

with

lazy

narrowing

as

operational

semantics

In

Section

we

discuss

the

basic

ideas

and

some

pitfalls

for

the

implementation

of

lazy

narrowing

Section

contains

the

formal

specification

of

the

new

indexing

scheme

and

a

corresponding

example

Section

shows

some

experimental

results

In

Section

we

conclude

and

point

out

future

work

Lazy

Babel

The

language

Babel

integrates

functional

and

logic

programming

in

a

flexible

and

mathematically

well-founded

way

It

is

based

on

a

constructor

discipline

and

uses

narrowing

as

evaluation

mechanism

-LSB-

-RSB-

Babel

has

a

polymorphic

type

system

similar

to

that

of

-LSB-

-RSB-

For

simplicity

of

presentation

we

will

here

ignore

higher

order

functions

and

polymorphic

types

since

they

are

not

essential

for

the

present

paper

The

Syntax

of

Babel

Rather

than

giving

a

precise

description

of

the

syntax

and

semantics

of

Babel

-LRB-

which

can

be

found

in

-LSB-

-RSB-

-RRB-

we

will

first

show

a

small

example

program

and

then

present

some

basic

concepts

In

the

example

a

function

deriv

is

defined

which

computes

the

derivation

of

a

function

f

-LRB-

x

-RRB-

More

precisely

deriv

gets

the

body

of

f

as

an

argument

and

delivers

an

expression

such

that

f

-LRB-

x

-RRB-

datatype

expr

x

j

const

int

j

add

expr

expr

j

mul

expr

expr

j

exp

expr

j

fun

deriv

expr

expr

deriv

x

const

deriv

-LRB-

const

N

-RRB-

const

deriv

-LRB-

add

U

V

-RRB-

simplify

-LRB-

add

-LRB-

deriv

U

-RRB-

-LRB-

deriv

V

-RRB-

-RRB-

deriv

-LRB-

mul

U

V

-RRB-

simplify

-LRB-

add

-LRB-

mul

U

-LRB-

deriv

V

-RRB-

-RRB-

-LRB-

mul

V

-LRB-

deriv

U

-RRB-

-RRB-

deriv

-LRB-

exp

U

-RRB-

simplify

-LRB-

mul

-LRB-

exp

U

-RRB-

-LRB-

deriv

U

-RRB-

-RRB-

other

rules

for

deriv

fun

simplify

expr

expr

simplify

x

x.

simplify

-LRB-

mul

E

-LRB-

const

-RRB-

-RRB-

simplify

E.

simplify

-LRB-

exp

E

-RRB-

exp

-LRB-

simplify

E

-RRB-

other

rules

for

simplify

A

Babel

program

consists

of

a

sequence

of

datatype

definitions

and

a

sequence

of

function

definitions

The

program

can

be

queried

with

a

goal

expression

For

example

a

valid

query

for

the

previous

program

is

solve

deriv

E

E

true

This

goal

corresponds

to

the

differential

equation

f

-LRB-

x

-RRB-

f

-LRB-

x

-RRB-

A

possible

result

for

this

goal

is

true

provided

that

the

variable

E

is

bound

to

-LRB-

const

-RRB-

Another

solution

consists

of

the

result

true

and

the

substitution

of

E

by

exp

x

A

datatype

definition

introduces

a

new

type

e.g.

expr

and

a

sequence

of

data

constructors

-LRB-

separated

by

j

e.g.

x

-LRB-

of

arity

-RRB-

and

const

-LRB-

of

arity

-RRB-

-RRB-

A

data

constructor

is

an

uninterpreted

function

mapping

its

argument

types

-LRB-

given

behind

the

name

of

the

constructor

-RRB-

to

the

type

on

the

left

hand

side

of

the

datatype

definition

For

example

const

has

the

type

const

int

expr

A

Prolog-like

syntax

for

lists

is

allowed

i.e.

-LSB-

e

j

-RSB-

represents

the

list

with

head

e

and

tail

and

-LSB-

-RSB-

is

the

empty

list

For

each

function

its

type

and

a

sequence

of

defining

rules

are

specified

A

rule

for

a

function

f

has

the

form

f

tm

-LCB-

z

-RCB-

left

hand

side

fb

g

-LCB-

z

-RCB-

optional

guard

e

-LCB-

z

-RCB-

body

-LCB-

z

-RCB-

right

hand

side

where

tn

are

terms

sharing

no

variables

-LRB-

left

linear

-RRB-

b

is

a

boolean

expression

and

e

is

an

arbitrary

expression

A

term

is

either

a

-LRB-

logical

-RRB-

variable

-LRB-

denoted

by

an

identifier

beginning

with

a

capital

letter

-RRB-

or

an

application

of

a

n-ary

data

constructor

-LRB-

n

-RRB-

to

n

argument

terms

t

X

variable

j

-LRB-

c

tn

-RRB-

application

of

a

n-ary

data

constructor

c

-LRB-

n

-RRB-

to

n

terms

An

expression

has

the

form

e

X

variable

j

-LRB-

en

-RRB-

application

of

a

n-ary

data

constructor/function

-LRB-

n

-RRB-

j

-LRB-

b

e

-RRB-

guarded

expression

meaning

if

b

then

e

else

undefined

j

-LRB-

b

-RRB-

conditional

expression

meaning

if

b

then

else

All

expressions

have

to

be

well

typed

Parentheses

can

be

omitted

if

the

structure

of

an

expression

is

clear

Babel

functions

are

functions

in

the

mathematical

sense

i.e.

for

each

tuple

of

-LRB-

ground

-RRB-

arguments

there

is

at

most

one

result

This

is

ensured

by

syntactic

restrictions

for

the

rules

-LSB-

-RSB-

Another

restriction

is

left

linearity

allowing

only

unique

variable

occurrences

on

the

left

hand

side

of

the

rules

This

simplifies

the

specification

somewhat

The

types

bool

-LRB-

with

data

constructors

true

and

false

-RRB-

and

int

-LRB-

integer

numbers

-RRB-

are

predefined

Moreover

several

basic

-LRB-

infix

and

mixfix

-RRB-

operations

like

equality

-LRB-

=-RRB-

conjunction

-LRB-

-RRB-

disjunction

-LRB-

;-RRB-

negation

-LRB-

:-RRB-

and

so

on

are

predefined

Narrowing

Semantics

Here

we

will

present

an

operational

semantics

of

Babel

based

on

narrowing

To

use

narrowing

as

the

operational

semantics

of

functional

logic

languages

was

first

proposed

by

Reddy

-LSB-

-RSB-

Let

e

f

en

be

an

expression

and

let

f

tn

be

a

variant

of

a

rule

sharing

no

variables

with

e.

Moreover

let

oe

ffi

be

the

most

general

unifier

of

e

and

-LRB-

f

tn

-RRB-

i.e.

the

minimal

substitution

-LRB-

of

variables

by

expressions

-RRB-

such

that

eoe

is

syntactically

identical

to

-LRB-

f

tn

-RRB-

Then

e

can

be

narrowed

-LRB-

in

one

step

-RRB-

to

with

answer

substitution

oe

-LRB-

denoted

by

e

-RRB-

oe

-RRB-

Moreover

if

for

some

i

-LRB-

i

n

-RRB-

ei

-RRB-

oe

then

-LRB-

ei

en

-RRB-

-RRB-

oe

-LRB-

-RRB-

where

is

a

n-ary

defined

function

or

a

n-ary

constructor

If

after

several

steps

an

expression

e

is

narrowed

to

a

term

t

we

speak

of

a

computation

for

the

goal

e

with

result

t

and

answer

oe

where

oe

is

the

composition

of

the

answer

substitutions

of

all

the

individual

steps

If

e

can

not

be

narrowed

further

but

it

is

not

a

term

then

the

computation

fails

The

implementation

will

backtrack

in

such

a

situation

The

rules

are

tried

in

their

textual

order

In

the

present

paper

we

consider

a

lazy

narrowing

strategy

-LSB-

-RSB-

This

strategy

narrows

the

leftmost

outermost

redex

unless

an

inner

redex

needs

to

be

narrowed

first

in

order

to

decide

whether

the

currently

considered

rule

-LRB-

following

the

textual

order

of

rules

-RRB-

can

be

applied

or

not

Alternatively

an

innermost

-LRB-

eager

-RRB-

narrowing

strategy

-LSB-

-RSB-

can

be

considered

where

all

arguments

of

a

function

have

to

be

narrowed

before

a

rule

for

the

function

can

be

applied

The

goal

deriv

E

E

true

in

the

above

example

can

be

-LRB-

lazily

-RRB-

narrowed

as

follows

deriv

E

E

true

-RRB-

fE

xg

-LRB-

rule

-RRB-

const

x

true

-RRB-

fg

-LRB-

rule

for

equality

-RRB-

false

true

This

computation

fails

since

there

is

no

rule

for

with

first

argument

false

Another

computation

is

deriv

E

E

true

-RRB-

fE

-LRB-

const

N

-RRB-

g

-LRB-

rule

-RRB-

const

const

N

true

-RRB-

fg

-LRB-

rule

for

equality

-RRB-

N

true

-RRB-

fN

-LRB-

rule

for

equality

-RRB-

true

true

-RRB-

fg

-LRB-

rule

for

-RRB-

true

Hence

this

computation

leads

to

a

solution

consisting

of

the

result

true

and

the

answer

fE

-LRB-

const

-RRB-

g.

By

applying

other

rules

for

deriv

to

the

goal

more

solutions

can

be

reached

e.g.

the

result

true

with

answer

fE

-LRB-

exp

x

-RRB-

g

A

precise

definition

of

the

operational

semantics

of

Babel

is

found

in

-LSB-

-RSB-

This

paper

also

contains

the

declarative

semantics

as

well

as

correctness

and

completeness

results

Implementing

Lazy

Narrowing

Next

we

would

like

to

discuss

the

basic

concepts

for

an

efficient

implementation

of

lazy

narrowing

Several

approaches

-LRB-

e.g.

-LSB-

-RSB-

-RRB-

have

been

proposed

which

all

claim

to

be

lazy

but

differ

in

the

degree

of

laziness

reached

We

choose

as

a

starting

point

the

naive

lazy

narrowing

scheme

which

evaluates

a

function

application

en

as

follows

ffl

the

rules

for

f

are

tried

in

their

textual

order

ffl

for

a

given

rule

f

tn

e

the

arguments

en

are

unified

from

left

to

right

with

the

corresponding

terms

tn

If

such

an

unification

is

not

yet

possible

since

the

considered

expression

ei

is

not

evaluated

far

enough

ei

is

evaluated

to

some

which

is

evaluated

far

enough

If

the

unification

of

ei

and

ti

fails

alternative

solutions

for

ei

are

searched

by

backtracking

If

no

solution

for

ei

could

be

found

which

is

unifiable

with

ti

the

arguments

ei

en

are

not

evaluated

at

all

but

the

next

rule

is

tried

Let

us

explain

this

using

an

example

The

first

function

sprod

computes

the

scalar

product

of

two

dlst

generates

finite

descending

lists

of

natural

numbers

sprod

L

-LSB-

-RSB-

L

-RSB-

sprod

-LSB-

-RSB-

-LSB-

-RSB-

sprod

dlst

N

N

-LSB-

Njdlst

-LRB-

N

-LCB-

-RRB-

-RSB-

-LSB-

-RSB-

solve

sprod

-LRB-

dlst

-RRB-

-LRB-

dlst

-RRB-

Here

the

unification

of

L

and

-LRB-

dlst

-RRB-

does

not

force

any

evaluation

of

-LRB-

dlst

-RRB-

L

is

just

bound

to

it

In

order

to

unify

-LSB-

-RSB-

with

the

value

of

-LRB-

dlst

-RRB-

-LRB-

dlst

-RRB-

needs

to

be

evaluated

to

head

normal

form

Hence

the

rule

for

dlst

is

tried

delivering

the

result

-LSB-

-RSB-

Since

this

value

is

not

unifiable

with

the

corresponding

formal

argument

-LSB-

-RSB-

on

the

left

hand

side

of

the

first

rule

for

sprod

backtracking

to

the

last

function

call

in

this

case

-LRB-

dlst

-RRB-

occurs

Since

there

are

no

additional

rules

for

dlst

the

computation

of

-LRB-

dlst

-RRB-

fails

and

is

deleted

Backtracking

goes

on

and

the

second

rule

for

sprod

is

tried

Then

the

first

actual

argument

-LRB-

dlst

-RRB-

is

evaluated

matching

the

formal

paramenter

-LSB-

-RSB-

and

again

-LRB-

dlst

-RRB-

is

demanded

and

reevaluated

The

computation

proceeds

several

steps

but

fails

finally

Note

that

lazy

evaluation

causes

the

arguments

to

be

evaluated

after

the

function

call

for

sprod

This

means

that

alternative

computations

for

the

arguments

are

tried

before

the

next

rule

for

sprod

is

attempted

Moreover

it

implies

that

all

computations

for

the

arguments

are

forgotten

when

the

next

rule

is

tried

and

they

need

to

be

reevaluated

for

each

rule

We

can

conclude

that

the

naive

lazy

strategy

is

inefficient

since

it

leads

to

an

arbitrary

amount

of

re-evaluations

of

arguments

This

inefficiency

is

avoided

if

the

arguments

are

evaluated

before

the

function

call

This

is

only

safely

possible

if

the

evaluation

of

the

arguments

is

demanded

Furthermore

note

moved

the

restriction

on

the

first

argument

of

the

first

rule

to

the

body

in

order

to

stress

several

disadvantages

of

naive

lazy

narrowing

that

we

have

incrementally

evaluated

the

arguments

But

ideally

we

would

like

to

evaluate

both

arguments

before

the

selection

process

of

the

rules

by

using

demandedness

information

The

operational

notion

demandedness

must

not

be

confused

with

the

semantical

notion

strictness

A

function

is

strict

in

some

argument

if

the

result

is

undefined

provided

that

this

argument

is

undefined

Strictness

is

used

in

lazy

functional

languages

in

order

to

decide

which

arguments

are

needed

anyway

and

may

hence

be

evaluated

in

advance

avoiding

the

construction

of

some

intermediate

representation

of

unevaluated

expressions

In

purely

functional

programming

this

is

valid

since

the

whole

computation

fails

if

some

subexpression

fails

In

functional

logic

programming

a

failing

subexpression

causes

backtracking

and

some

alternative

computation

will

be

tried

Note

that

only

one

-LRB-

part

of

an

-RRB-

argument

can

be

demanded

at

a

time

If

its

evaluation

fails

all

remaining

arguments

are

not

evaluated

If

however

the

evaluation

succeeds

and

the

values

of

the

currently

evaluated

arguments

are

unifiable

with

the

corresponding

patterns

on

the

left

hand

side

of

a

rule

then

the

next

argument

may

be

demanded

and

can

be

evaluated

Hence

this

stepwise

notion

of

demandedness

allows

several

arguments

to

be

evaluated

in

advance

and

it

takes

into

account

the

patterns

on

the

left

hand

side

and

especially

their

dependencies

Below

this

will

explained

in

detail

How

to

Avoid

Re-evaluations

The

inefficiency

due

to

frequent

re-evaluations

of

the

arguments

can

be

avoided

if

the

arguments

are

evaluated

before

the

function

call

more

precisely

before

a

choice

point

for

the

function

is

created

In

fact

this

idea

has

already

been

followed

in

several

approaches

-LSB-

-RSB-

Note

that

this

preliminary

evaluation

of

the

arguments

is

much

more

important

for

functional

logic

languages

than

for

purely

functional

languages

where

just

the

construction

of

an

intermediate

representation

of

unevaluated

expressions

is

saved

However

the

mentioned

approaches

have

the

drawback

that

they

do

not

take

into

account

dependencies

between

the

arguments

but

consider

each

argument

separately

This

leads

to

a

blind

evaluation

of

arguments

even

if

it

is

already

clear

that

no

rule

will

be

applicable

since

no

left

hand

side

of

a

rule

is

unifiable

with

the

values

of

the

arguments

computed

up

to

now

Or

vice

versa

the

evaluation

of

some

argument

is

delayed

although

demandedness

is

derivable

The

approaches

presented

in

-LSB-

-RSB-

and

-LSB-

-RSB-

for

example

end

up

with

a

notion

of

demandedness

which

leads

to

the

evaluation

of

both

arguments

of

the

goal

in

the

sprod

example

The

approach

of

-LSB-

-RSB-

will

evaluate

the

second

argument

If

the

demanded

arguments

are

evaluated

before

the

function

call

this

has

an

additional

advantage

Since

backtracking

now

first

considers

all

the

rules

for

f

before

it

tries

alternative

computations

for

the

arguments

infinite

computations

due

to

infinitely

many

solutions

of

some

argument

expressions

can

be

avoided

Consider

the

following

rules

-LRB-

using

datatype

nat

zero

j

s

nat

-RRB-

one

zero

s

zero

one

-LRB-

s

N

-RRB-

one

N

The

goal

-LRB-

one

-LRB-

one

X

-RRB-

-RRB-

leads

to

an

infinite

computation

with

the

naive

lazy

strategy

since

the

first

rule

for

one

requires

to

find

a

solution

of

-LRB-

one

X

-RRB-

which

is

-LRB-

unifiable

with

-RRB-

zero

-LRB-

one

X

-RRB-

has

infinitely

many

solutions

each

binding

X

to

a

different

natural

number

but

all

of

them

fail

to

deliver

the

desired

value

zero

All

of

these

infinitely

many

solutions

are

tried

and

the

second

rule

for

one

is

never

reached

If

the

demanded

argument

-LRB-

one

X

-RRB-

of

the

outer

call

to

one

is

evaluated

before

the

call

to

one

the

second

rule

for

one

will

be

tried

before

a

new

solution

for

-LRB-

one

X

-RRB-

is

tried

In

the

present

example

the

second

rule

for

one

leads

to

infinitely

many

solutions

of

the

goal

Of

course

it

is

possible

to

find

examples

where

it

is

better

to

first

try

an

alternative

solution

of

an

argument

before

trying

the

next

rule

The

point

is

that

it

is

just

more

reasonable

to

explore

a

two

dimensional

search

space

which

has

one

finite

dimension

-LRB-

the

number

of

rules

-RRB-

and

one

possibly

infinite

dimension

-LRB-

the

number

of

solutions

of

an

expression

-RRB-

by

first

fixing

a

value

in

the

second

dimension

and

then

scanning

the

finite

dimension

instead

of

vice

versa

Another

problem

is

introduced

if

indexing

and

unification

are

separated

The

problem

occurs

if

a

binding

of

a

variable

in

the

goal

is

postponed

and

some

arguments

which

rely

on

this

binding

are

executed

in

advance

Consider

the

goal

foo

X

-LRB-

loop

X

-RRB-

and

the

additional

rules

foo

loop

loop

loop

The

first

argument

of

foo

is

demanded

but

it

is

already

in

hnf

Nevertheless

X

needs

to

be

bound

to

before

the

second

argument

loop

X

is

evaluated

Otherwise

the

search

space

for

loop

X

is

not

yet

restricted

by

the

requirement

X

and

the

first

rule

for

loop

is

applicable

leading

to

an

infinite

computation

Note

that

the

binding

of

X

has

to

be

deleted

before

the

next

rule

for

foo

is

considered

Otherwise

different

bindings

for

X

required

by

other

rules

could

not

be

tried

Demand

Patterns

The

degree

of

demandedness

of

the

arguments

is

expressed

by

a

demand

pattern

Since

in

this

paper

we

want

to

focus

on

indexing

we

will

consider

demand

patterns

which

only

reflect

the

demandedness

due

to

the

left

hand

sides

of

the

rules

-LSB-

-RSB-

show

how

to

use

demandedness

information

corresponding

to

the

right

hand

sides

of

the

rules

This

is

in

fact

independent

of

the

indexing

scheme

and

can

be

added

to

the

presented

approach

A

demand

pattern

has

the

form

ffl

or

-LRB-

pn

-RRB-

-LRB-

or-pattern

-RRB-

where

pi

is

a

demand

pattern

-LRB-

i

n

n

-RRB-

ffl

c

-LRB-

pn

-RRB-

-LRB-

and-pattern

-RRB-

where

pi

is

a

demand

pattern

-LRB-

i

n

n

-RRB-

ffl

any

In

the

sprod

example

we

get

the

following

demand

pattern

for

the

arguments

of

sprod

tupel

-LRB-

or

-LRB-

any

-LSB-

j

-RSB-

-LRB-

or

-LRB-

any

-RRB-

or

-LRB-

any

-RRB-

-RRB-

-RRB-

or

-LRB-

-LSB-

-RSB-

-LSB-

j

-RSB-

-LRB-

or

-LRB-

any

-RRB-

or

-LRB-

any

-RRB-

-RRB-

-RRB-

-RRB-

where

tupel

is

an

auxiliary

constructor

to

combine

the

arguments

of

sprod

and

-LSB-

j

-RSB-

is

used

in

prefix

instead

of

mixfix

notation

The

demand

patterns

will

be

used

by

the

indexing

scheme

in

order

to

guide

the

selection

of

an

applicable

rule

and

the

evaluation

of

the

arguments

Remember

that

an

indexing

scheme

for

lazy

narrowing

needs

to

cope

with

both

If

more

information

is

needed

to

select

a

rule

additional

evaluations

of

some

parts

of

the

arguments

are

incrementally

initiated

Since

the

demand

patterns

shall

be

used

to

select

a

rule

each

and-pattern

and

anypattern

needs

to

be

annotated

with

a

set

of

rule

numbers

The

corresponding

rules

are

possibly

applicable

if

this

pattern

is

reached

For

any-patterns

this

set

is

-LRB-

for

technical

reasons

-RRB-

the

set

of

rules

which

are

not

mentioned

in

the

other

cases

An

annotated

pattern

is

represented

by

a

pair

hp

Ri

where

p

is

an

and

or

any-pattern

and

R

is

the

corresponding

set

of

rule

numbers

For

the

above

example

we

get

the

following

annotated

demand

pattern

htupel

-LRB-

or

-LRB-

hany

h

-LSB-

j

-RSB-

-LRB-

or

-LRB-

hany

-RRB-

or

-LRB-

hany

-RRB-

-RRB-

-RRB-

or

-LRB-

h

-LSB-

-RSB-

h

-LSB-

j

-RSB-

-LRB-

or

-LRB-

hany

-RRB-

or

-LRB-

hany

-RRB-

-RRB-

-RRB-

-RRB-

gi

Formally

the

generation

of

annotated

demand

patterns

can

be

described

as

follows

generate

-LRB-

ff

ti

ti

n

ei

j

i

mg

-RRB-

h

tupel

-LRB-

gen

-LRB-

htm

fmgi

-RRB-

gen

-LRB-

n

htm

n

fmgi

-RRB-

mgi

gen

-LRB-

htn

rni

-RRB-

if

tng

V

ar

then

or

-LRB-

aux

-LRB-

-RRB-

aux

-LRB-

Mck

-RRB-

-RRB-

else

or

-LRB-

aux

-LRB-

-RRB-

aux

-LRB-

Mck

-RRB-

hany

Ri

-RRB-

where

ck

are

the

topmost

constructors

of

the

terms

tn

and

Mci

fht

ri

j

ht

ri

htn

rnig

t

-LRB-

ci

terms

-RRB-

g

-LRB-

i

k

-RRB-

R

fr

j

hX

ri

j

hX

ri

htn

rnig

X

V

arg

aux

-LRB-

fh

-LRB-

c

n

-RRB-

h

-LRB-

c

tm

tm

n

-RRB-

rmig

-RRB-

hc

-LRB-

gen

-LRB-

htm

rmi

-RRB-

gen

-LRB-

n

htm

n

rmi

-RRB-

-RRB-

rmgi

This

algorithm

ensures

that

each

pattern

has

for

each

constructor

at

most

one

direct

subpattern

and

that

the

direct

subpatterns

of

or-patterns

are

and-patterns

-LRB-

or

any-patterns

-RRB-

and

vice

versa

The

latter

property

is

used

by

the

indexer

in

Section

Moreover

for

an

orpattern

or

-LRB-

pn

-RRB-

the

annotations

-LRB-

i.e.

the

sets

of

possible

rules

-RRB-

of

different

subpatterns

pi

and

pj

-LRB-

for

i

j

-RRB-

are

disjoint

An

Indexing

Scheme

for

Babel

Before

we

come

to

a

detailed

explanation

of

the

indexing

scheme

let

us

first

discuss

the

main

ideas

using

the

sprod

example

The

demand

patterns

are

processed

from

left

to

right

In

the

example

we

handle

or

-LRB-

hany

h

-LSB-

j

-RSB-

-LRB-

or

-LRB-

hany

-RRB-

or

-LRB-

hany

-RRB-

-RRB-

-RRB-

first

Here

the

annotation

of

any

contains

a

smaller

rule

number

than

the

of

-LSB-

j

-RSB-

This

indicates

that

the

rule

which

does

not

demand

the

evaluation

of

the

first

argument

comes

-LRB-

textually

-RRB-

before

the

rule

which

does

According

to

our

strategy

to

try

the

rules

in

their

textual

order

we

are

not

allowed

to

evaluate

this

argument

right

now

After

this

we

consider

the

second

argument

of

sprod

and

the

corresponding

pattern

or

-LRB-

h

-LSB-

-RSB-

h

-LSB-

j

-RSB-

-LRB-

or

-LRB-

hany

-RRB-

or

-LRB-

hany

-RRB-

-RRB-

-RRB-

Since

both

rules

are

still

possible

we

have

to

check

whether

we

are

allowed

to

evaluate

the

second

argument

Here

both

rules

demand

the

evaluation

to

head

normal

form

If

this

evaluation

delivers

the

head

normal

form

-LSB-

-RSB-

we

have

to

select

rule

whereas

the

evaluation

to

-LSB-

j.

-RSB-

forces

rule

to

be

selected

If

the

result

is

a

variable

both

rules

keep

possible

and

will

be

tried

in

their

textual

order

After

these

preliminary

explanations

we

present

the

scheme

in

more

detail

Machine

Instructions

We

start

with

a

brief

description

of

the

instructions

used

in

the

scheme

Most

of

them

are

well

known

from

the

WAM

-LRB-

Warren

Abstract

Machine

-LSB-

-RSB-

-RRB-

although

we

use

the

slightly

different

abstract

machine

BAM

-LSB-

-RSB-

which

has

a

-LRB-

data

-RRB-

stack

-LCB-

based

parameter

passing

mechanism

rather

than

a

register

-LCB-

based

one

TryMeElse

l

creates

a

new

choice

point

on

top

of

the

runtime

stack

and

stores

the

essential

parameters

of

the

current

state

The

assigned

label

l

always

points

to

a

RetryMeElse

or

TrustMe

instruction

The

machine

will

jump

to

l

if

the

computation

fails

RetryMeElse

l

restores

the

previous

state

-LRB-

backtracking

-RRB-

The

topmost

choice

point

is

updated

and

points

now

to

label

l.

TrustMe

removes

the

topmost

choice

point

after

the

restoration

of

the

previous

state

All

three

instructions

increment

the

program

counter

by

one

Try/Retry/Trust

l

work

quite

similar

to

the

previous

instructions

They

differ

only

in

the

continuation

behaviour

They

store

the

address

of

the

following

instruction

in

the

choice

point

and

jump

to

l.

Switch

ln

ln

-LRB-

-RRB-

-LRB-

cn

ln

-RRB-

analyzes

the

topmost

data

stack

entry

and

jumps

depending

on

its

value

It

jumps

to

label

ln

if

it

is

a

variable

to

ln

if

it

is

a

constructor

not

contained

in

the

constructor

list

-LRB-

default

-RRB-

which

is

specified

by

the

third

parameter

If

it

matches

constructor

ci

it

jumps

to

the

label

li

Initiate

checks

the

item

pointed

to

by

the

topmost

entry

of

the

data

stack

and

initiates

its

evaluation

to

head

normal

form

BuildStructure

c

n

creates

a

n-ary

structure

node

in

the

heap

and

pushes

the

addresses

of

the

components

on

top

of

the

data

stack

Failure

causes

immediate

backtracking

and

Jump

l/Pop

have

the

usual

meaning

Compilation

Scheme

The

previous

discussion

has

shown

that

indexing

is

not

only

a

useful

mechanism

to

directly

access

the

applicable

rules

at

runtime

but

it

can

also

initiate

the

evaluation

of

demanded

arguments

An

example

which

explains

the

interaction

follows

below

Let

us

now

specify

the

compilation

scheme

formally

We

choose

a

top-down

style

i.e.

we

begin

with

the

translation

of

each

function

functrans

-LRB-

tin

ei

j

i

r

p

l

-RRB-

if

r

then

ruletrans

-LRB-

-RRB-

else

indextrans

-LRB-

n

b

rg

rg

-LRB-

p

;-RRB-

lr

-RRB-

ruletrans

-LRB-

-RRB-

lr

ruletrans

-LRB-

trn

er

lr

-RRB-

Clearly

if

the

function

consists

of

one

rule

indexing

makes

no

sense

Otherwise

the

indexing

code

precedes

the

usual

code

of

the

rules

It

is

produced

by

indextrans

taking

arguments

for

control

ffl

The

first

argument

lists

the

numbers

of

argument

positions

of

the

function

or

components

of

structures

This

sequence

contains

a

mark

b

-LRB-

boundary

-RRB-

behaving

as

a

delimiter

which

initiates

pop

operations

-LRB-

see

below

-RRB-

Initially

the

sequence

contains

the

argument

positions

in

left

to

right

order

ffl

Next

the

set

actually

a

subset

of

possibly

applicable

rules

-LRB-

identified

by

their

numbers

-RRB-

is

given

The

initial

value

contains

all

rules

ffl

Also

the

third

parameter

denotes

a

set

of

rules

Whenever

bindings

are

done

this

parameter

will

be

modified

in

order

to

store

the

rules

which

remain

applicable

and

respect

these

bindings

Without

such

a

set

the

indexer

would

forget

during

subsequent

steps

that

it

has

done

these

bindings

and

would

compute

a

superset

of

the

valid

rules

ffl

Whenever

the

indexer

looks

inside

a

structure

e.g.

s

-LRB-

-RRB-

inside

c

-LRB-

X

Y

s

-LRB-

-RRB-

Z

-RRB-

in

order

to

derive

further

restrictions

of

applicable

rules

the

visible

rules

are

temporarily

restricted

to

the

ones

being

suitable

for

this

structure

Other

rules

with

more

general

terms

like

X

or

c

-LRB-

X

Y

U

V

-RRB-

are

not

under

investigation

but

remain

valid

The

current

environment

consisting

of

the

current

pattern

and

these

remaining

rules

is

passed

as

the

fourth

parameter

It

will

be

restored

when

returning

from

the

deeper

level

Initially

the

passed

pattern

p

of

functrans

and

the

empty

set

are

pushed

ffl

The

next

parameter

is

used

for

technical

reasons

and

ensures

different

symbolic

labels

and

ffl

the

last

one

stores

the

entry

addresses

of

the

rules

as

a

sorted

list

which

is

passed

through

until

all

positions

are

processed

The

code

of

every

rule

is

produced

by

the

ruletrans

scheme

which

is

omitted

here

due

to

the

lack

of

space

-LRB-

see

-LSB-

-RSB-

for

details

-RRB-

In

contrast

to

our

implementation

we

have

not

merged

indexing

and

unification

code

here

for

simplicity

of

presentation

Indexing

can

be

seen

as

a

prepass

over

the

arguments

just

before

the

execution

of

a

rule

starts

indextrans

-LRB-

P

R

S

-LRB-

p

V

-RRB-

ST

l

L

-RRB-

if

-LRB-

R

-LSB-

V

-RRB-

S

then

Failure

else

if

P

then

build

try

trust

-LRB-

-LRB-

R

-LSB-

V

-RRB-

S

L

-RRB-

else

let

P

=p

:P

in

if

p

b

then

indextrans

-LRB-

P

R

-LSB-

V

S

ST

l

L

-RRB-

else

if

p

i

then

let

project

-LRB-

p

i

-RRB-

in

if

demanded

-LRB-

-LRB-

R

-LSB-

V

-RRB-

S

-RRB-

then

Initiate

switchtrans

-LRB-

P

R

S

-LRB-

p

V

-RRB-

ST

L

-RRB-

indexbindtrans

-LRB-

P

R

S

-LRB-

p

V

-RRB-

ST

n

L

-RRB-

else

switchtrans

-LRB-

P

R

S

-LRB-

p

V

-RRB-

ST

L

-RRB-

Pop

indextrans

-LRB-

P

R

S

-LRB-

p

V

-RRB-

ST

n

L

-RRB-

The

important

part

of

the

specification

is

indextrans

First

it

checks

whether

some

of

the

currently

considered

rules

are

applicable

-LRB-

i.e.

-LRB-

R

-LSB-

V

-RRB-

S

;-RRB-

If

no

applicable

rule

remains

an

instruction

is

generated

which

initiates

backtracking

Otherwise

if

all

arguments

and

inner

structure

positions

have

been

processed

-LRB-

P

-RRB-

the

code

chaining

the

rules

is

generated

by

the

build

try

trust

scheme

If

further

analysis

is

possible

and

the

delimiter

b

is

reached

-LRB-

denoting

that

a

structure

has

been

completely

considered

-RRB-

one

entry

of

the

environment

stack

is

popped

in

order

to

analyze

the

upper

level

Note

that

additional

rule

numbers

are

added

to

the

set

of

applicable

rules

These

rules

correspond

to

any

-LCB-

patterns

i.e.

variables

encountered

while

traversing

nested

structures

If

of

the

previous

checks

was

successful

the

code

generation

for

one

indexing

step

is

possible

First

the

demandedness

of

the

argument

position

is

checked

If

it

is

demanded

the

instruction

Initiate

is

generated

switchtrans

manages

nonvariable

-LRB-

hnf

-RRB-

expressions

and

indexbindtrans

handles

encountered

variables

which

must

now

be

bound

to

retain

safety

with

respect

to

laziness

Otherwise

the

expression

is

analyzed

without

initiating

any

evaluation

variables

are

simply

popped

switchtrans

-LRB-

p

P

R

S

ST

l

L

-RRB-

let

-LRB-

h

Avi

pn

-RRB-

split

-LRB-

p

-RRB-

and

pi

hci

-LRB-

pini

-RRB-

i

-RRB-

in

Switch

ln

ln

-LRB-

-LRB-

-RRB-

-LRB-

cn

ln

-RRB-

-RRB-

indexstructtrans

-LRB-

Av

P

R

S

ST

L

-RRB-

ln

indexstructtrans

-LRB-

pn

Av

P

R

S

ST

ln

L

-RRB-

ln

indextrans

-LRB-

P

R

Av

S

ST

ln

L

-RRB-

ln

indexstructtrans

-LRB-

hc

-LRB-

pn

-RRB-

Ai

Av

P

R

S

-LRB-

p

V

-RRB-

ST

l

L

-RRB-

indextrans

-LRB-

n

b

:P

R

A

S

-LRB-

hc

-LRB-

pn

-RRB-

Ai

V

-LSB-

-LRB-

Av

R

-RRB-

-RRB-

-LRB-

p

V

-RRB-

ST

l

L

-RRB-

indexbindtrans

-LRB-

P

R

S

-LRB-

p

V

-RRB-

ST

l

L

-RRB-

let

-LRB-

R

-LSB-

V

-RRB-

S

rng

and

ri

ri

in

if

n

then

buildtrans

-LRB-

-RRB-

indextrans

-LRB-

P

R

-LRB-

p

V

-RRB-

ST

L

-RRB-

else

li

TryMeElse

RetryMeElse

li

TrustMe

buildtrans

-LRB-

ri

-RRB-

indextrans

-LRB-

P

R

frig

-LRB-

p

V

-RRB-

ST

li

L

-RRB-

The

switchtrans

scheme

generates

code

which

expects

an

expression

in

hnf

on

top

of

the

data

stack

and

branches

depending

on

its

value

The

passed

or

-LCB-

pattern

is

split

into

one

any

-LCB-

pattern

and

one

or

-LCB-

pattern

for

each

occurring

top

level

The

current

context

is

saved

consisting

of

the

current

pattern

and

the

valid

rules

-LRB-

cf.

indexstructtrans

-RRB-

The

-LRB-

potentially

-RRB-

valid

rules

are

denoted

by

the

any

-LCB-

pattern

-LRB-

restricted

by

R

and

joined

with

the

rules

V

inherited

from

the

upper

levels

of

the

visited

structure

-RRB-

The

list

of

positions

simplicity

it

is

assumed

that

each

constructor

has

a

unique

arity

which

must

be

processed

is

extended

by

the

positions

of

the

components

of

the

considered

structure

and

terminates

with

a

delimiter

In

the

default

case

the

set

of

applicable

rules

can

be

restricted

in

a

similar

way

The

code

at

label

ln

is

the

code

following

the

code

produced

by

switchtrans

Let

us

now

discuss

the

demand-context

indexbindtrans

generates

code

which

builds

the

term

-LRB-

buildtrans

-RRB-

the

variable

must

be

bound

to

Due

to

the

possibility

of

different

bindings

reflecting

the

alternative

computation

paths

a

choice

point

may

become

necessary

chaining

the

alternatives

The

further

analysis

is

performed

by

recursive

calls

to

indextrans

The

rule

that

causes

the

binding

is

noted

and

must

remain

valid

during

the

following

process

Note

that

a

simple

optimization

can

check

contiguous

rules

on

variant

terms

at

the

current

position

and

can

group

them

We

restrict

this

grouping

to

contiguous

rules

-LRB-

omitting

the

invalid

ones

-RRB-

since

we

respect

the

textual

ordering

of

the

rules

buildtrans

-LRB-

hany

Ai

k

-RRB-

Pop

buildtrans

-LRB-

hc

-LRB-

pn

-RRB-

Ai

k

-RRB-

BuildStructure

c

n

buildtrans

-LRB-

k

-RRB-

buildtrans

-LRB-

pn

k

-RRB-

buildtrans

-LRB-

or

-LRB-

hpn

Ani

-RRB-

k

-RRB-

if

k

then

buildtrans

-LRB-

k

-RRB-

else

Pop

build

try

trust

-LRB-

rng

lm

-RRB-

if

n

then

Jump

else

let

ri

ri

in

Try

Retry

lri

Trust

lrn

Structures

are

created

by

the

instruction

BuildStructure

behaving

similar

to

a

unification

instruction

in

write

mode

It

puts

a

structure

tag

together

with

the

arguments

into

the

heap

Additionally

pointers

to

the

components

are

pushed

onto

the

data

stack

A

variable

-LRB-

inside

the

term

-RRB-

is

popped

project

-LRB-

hc

-LRB-

pn

-RRB-

Ai

i

-RRB-

pi

split

-LRB-

or

-LRB-

pn

-RRB-

-RRB-

if

fanyg

P

-LRB-

IN

-RRB-

then

-LRB-

pn

-RRB-

else

-LRB-

i

pn

-RRB-

demanded

-LRB-

or

-LRB-

pn

-RRB-

R

-RRB-

let

pi

=-LRB-

Ai

-RRB-

and

j

minR

in

if

j

fanyg

P

-LRB-

IN

-RRB-

then

true

else

false

The

indextrans

and

the

switchtrans

schemes

access

auxiliary

functions

project

split

and

demanded

project

extracts

components

from

an

and

-LCB-

pattern

and

split

distinguishes

between

any

-LCB-

and

and

-LCB-

patterns

considering

the

first

level

of

the

input

or

-LCB-

pattern

demanded

checks

whether

the

first

applicable

rule

-LRB-

in

textual

order

-RRB-

does

not

have

an

any

-LCB-

pattern

at

the

considered

position

An

Example

The

following

table

shows

the

indexing

code

for

the

sprod

example

We

assume

that

both

arguments

of

sprod

are

pushed

onto

the

data

stack

Switch

-LRB-

-LSB-

j

-RSB-

-RRB-

Switch

Switch

Initiate

Switch

-LRB-

-LSB-

-RSB-

-RRB-

:-LRB-

-LSB-

j

-RSB-

-RRB-

Jump

Switch

Switch

Jump

Pop

Jump

Pop

-LCB-

updated

copy

of

ll

-LCB-

Failure

TryMeElse

BuildStructure

-LSB-

-RSB-

Jump

TrustMe

BuildStructure

-LSB-

j

-RSB-

Pop

Pop

Jump

Pop

-LCB-

updated

copy

of

ll

-LCB-

Pop

-LCB-

updated

copy

of

ll

-LCB-

Switch

-LRB-

-LSB-

-RSB-

-RRB-

Jump

Failure

BuildStructure

-LSB-

-RSB-

Jump

Pop

-LCB-

updated

copy

of

ll

-LCB-

ruletrans

-LRB-

sprod

L

-LSB-

-RSB-

L

-RSB-

-RRB-

ruletrans

-LRB-

sprod

-LSB-

-RSB-

-LSB-

-RSB-

-LRB-

sprod

-RRB-

-RRB-

Code

sharing

decreases

the

number

of

instructions

e.g.

the

simple

replacement

of

updated

copy

of

ll

-LCB-

by

Jump

will

reduce

the

code

size

enormously

Machine

Implementation

and

Experimental

Results

The

following

example

programs

were

executed

on

a

stack-based

narrowing

machine

-LSB-

-RSB-

The

narrowing

machine

is

an

extension

of

a

pure

reduction

machine

enriched

by

mechanisms

for

performing

unification

and

backtracking

similar

to

the

Warren

Abstract

Machine

-LSB-

-RSB-

The

current

implementation

of

the

indexing

module

incorporates

several

optimizations

which

have

been

omitted

due

to

the

lack

of

space

-LRB-

see

-LSB-

-RSB-

for

details

-RRB-

These

optimizations

include

the

prevention

of

code

duplication

Moreover

the

code

for

unification

and

indexing

is

merged

All

these

improvements

are

straightforward

A

further

optimization

is

possible

by

using

knowledge

about

modes

Such

a

mode

analyser

for

lazy

narrowing

is

currently

under

investigation

However

our

examples

show

that

code

explosion

is

in

practice

not

as

harmful

as

it

seems

to

be

-LRB-

see

Table

-RRB-

The

naive

lazy

scheme

and

the

new

approach

have

been

compared

for

several

example

programs

We

have

tried

both

approaches

with

and

without

another

refinement

which

prevents

the

deletion

of

deterministic

computations

when

backtracking

This

also

avoids

some

superfluous

re-evaluations

-LRB-

see

-LSB-

-RSB-

for

details

-RRB-

The

example

programs

include

quicksort

with

a

list

of

n

elements

with

initially

reverse

ordering

the

computation

of

all

sublists

of

reverse

-LSB-

n

-RSB-

the

n-queens

problem

with

symbolic

representation

of

lists

and

natural

numbers

the

satisfiability

problem

-LRB-

-RRB-

with

n

variables

and

terms

the

n-th

symbolic

derivation

of

a

polynomial

the

computation

of

all

prime

numbers

up

to

n

and

a

Babel

parser

using

higher

order

functions

For

comparison

purposes

we

have

also

listed

the

runtimes

for

eager

narrowing

An

eager

strategy

yields

better

runtimes

for

some

example

programs

but

a

lazy

strategy

allows

of

course

a

more

flexible

and

powerful

way

of

programming

-LSB-

-RSB-

The

runtimes

in

Table

show

a

con

without

refinement

with

refinement

code

size

example

n

Eager

Naive

Lazy

with

Idxg

Naive

Lazy

with

Idxg

factor

quicksort

AE

sublists

queens

sat

AE

derivation

AE

sieve

AE

parser

population

Table

Runtimes

of

the

example

programs

in

seconds

and

increase

of

code

size

for

indexing

siderable

advantage

of

the

new

approach

due

to

the

prevention

of

multiple

re-evaluations

Note

that

in

some

cases

for

the

naive

strategy

the

programs

do

not

stop

in

an

acceptable

period

of

time

Note

that

the

new

approach

leads

to

a

considerable

improvement

of

runtimes

even

if

other

optimizations

are

added

which

prevent

some

-LRB-

successful

-RRB-

re-evaluations

of

deterministic

computations

The

best

runtimes

are

reached

by

the

combination

of

these

techniques

Some

remarkable

results

are

observed

for

the

program

The

new

approach

causes

a

high

speed

up

also

in

comparison

to

the

eager

evaluation

strategy

This

is

due

to

the

combination

of

the

two

following

effects

and

the

big

search

space

spawned

by

the

problem

On

the

one

hand

superfluous

computations

can

be

avoided

by

using

a

lazy

strategy

whereas

on

the

other

hand

multiple

re-evaluations

of

arguments

caused

by

the

naive

lazy

strategy

are

eliminated

Experiments

have

shown

that

even

the

naive

strategy

combined

with

a

static

demandedness

analysis

as

proposed

in

-LSB-

-RSB-

leads

to

multiple

re-evaluations

and

worse

runtimes

Moreover

notice

that

we

have

renounced

to

show

typical

database

applications

-LRB-

except

the

population

example

-RRB-

in

order

to

avoid

the

impression

that

we

have

used

custom

tailored

examples

Conclusions

and

Future

Work

A

new

full

indexing

scheme

for

lazy

narrowing

has

been

presented

that

incorporates

several

advantages

in

comparison

to

former

approaches

Firstly

the

new

technique

is

more

lazy

than

in

the

approaches

introduced

before

because

it

takes

into

account

the

dependencies

of

the

arguments

and

their

specific

instantiations

Secondly

the

integration

of

indexing

and

variable

bindings

guarantees

that

the

search

space

for

further

argument

computations

within

the

unification

process

is

decreased

A

further

essential

advantage

is

given

by

the

early

evaluation

of

demanded

arguments

that

prevents

re-evaluations

and

leads

to

dramatically

improved

runtimes

It

has

also

been

shown

that

a

combination

with

other

optimization

techniques

e.g.

a

refinement

of

backtracking

is

possible

In

the

future

we

will

extend

our

scheme

to

a

notion

of

demandedness

which

takes

into

account

the

right

hand

sides

of

the

rules

References

-LSB-

-RSB-

H.

Ait-Kaci

Warren

's

Abstract

Machine

A

Tutorial

Reconstruction

MIT

Press

-LSB-

-RSB-

M.

Bellia

G.

Levi

The

Relation

between

Logic

and

Functional

Languages

Journal

of

Logic

Programming

Vol

-LSB-

-RSB-

D.

DeGroot

G.

Lindstrom

-LRB-

eds

-RRB-

Logic

Programming

Functions

Relations

Equations

Prentice

Hall

-LSB-

-RSB-

W.

Hans

A

Complete

Indexing

Scheme

for

WAM-based

Abstract

Machines

Procs

PLILP

LNCS

-LSB-

-RSB-

W.

Hans

H.

Kuchen

S.

Winkler

Advanced

Indexing

Techniques

for

the

Functional

Logic

Programming

Language

BABEL

Technical

Report

to

appear

-LSB-

-RSB-

W.

Hans

R.

Loogen

S.

Winkler

On

the

Interaction

of

Lazy

Evaluation

and

Backtracking

Procs

PLILP

LNCS

-LSB-

-RSB-

T.

Hickey

S.

Mudambi

Global

Compilation

of

Prolog

Journal

of

Logic

Programming

Vol

-LSB-

-RSB-

J.

Hughes

Why

Functional

Programming

Matters

Technical

Report

Programming

Methodology

Group

University

of

Goteborg

November

-LSB-

-RSB-

J.A.

Jim?enez

Mart

n

J.

Mari

no-Carballo

J.J.

Moreno-Navarro

Some

Techniques

for

the

Efficient

Compilation

of

Lazy

Narrowing

into

Prolog

Procs

LOPSTR

Manchester

-LSB-

-RSB-

S.

Kliger

E.

Shapiro

A

Decision

Tree

Compilation

Algorithm

for

FCP

-LRB-

-LCB-

-RRB-

Procs

ICSLP

MIT

Press

-LSB-

-RSB-

M.

Korsloot

E.

Tick

Compilation

Techniques

for

Nondeterminate

Flat

Concurrent

Logic

Programming

Languages

Procs

ICSLP

MIT

Press

-LSB-

-RSB-

H.

Kuchen

R.

Loogen

J.J.

Moreno-Navarro

M.

Rodr

guez-Artalejo

GraphNarrowing

to

Implement

a

Functional

Logic

Language

Tech

Report

Univ.

Politecnica

Madrid

-LSB-

-RSB-

R.

Milner

A

Theory

of

Type

Polymorphism

in

Programming

JCSS

-LRB-

-RRB-

-LSB-

-RSB-

R.

Loogen

From

Reduction

Machines

to

Narrowing

Machines

TAPSOFT

LNCS

-LSB-

-RSB-

R.

Loogen

S.

Winkler

Dynamic

Detection

of

Determinism

in

Functional

Logic

Languages

Procs

PLILP

LNCS

-LSB-

-RSB-

J.J.

Moreno-Navarro

H.

Kuchen

R.

Loogen

M.

Rodr

guez-Artalejo

Lazy

Narrowing

in

a

Graph

Machine

Procs

ALP

LNCS

-LSB-

-RSB-

J.J.Moreno-Navarro

M.

Rodr

guez-Artalejo

Logic

Programming

with

Functions

and

Predicates

The

Language

Babel

J.

Logic

Programming

-LSB-

-RSB-

D.

Palmer

L.

Naish

NUA-Prolog

An

Extension

to

the

WAM

for

Parallel

Andorra

Procs

ICSLP

MIT

Press

-LSB-

-RSB-

U.S.

Reddy

Narrowing

as

the

Operational

Semantics

of

Functional

Languages

Procs

Int

Symp

on

Logic

Programming

IEEE

Comp

Soc

Press

-LSB-

-RSB-

D.H.D.

Warren

An

Abstract

Instruction

Set

Tech

Note

SRI

International

Menlo

Park

O B O O B O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O B O O O O O O B O O O O O O O O O O O O O O B O B O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O B O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O B O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O B O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O

functional logic programming
indexing
narrowing


An Adaptive Multilayer Optical Neural Network Design I. Saxena and E. Fiesler Institut Dalle Molle d'Intelligence Artificielle Perceptive -LRB- IDIAP -RRB- Case postale 609 , CH-1920 Martigny , Switzerland Electronic mail -LRB- Internet -RRB- : ISaxena@IDIAP.CH, EFiesler@IDIAP.CH Abstract An adaptive multilayer dual-wavelength optical neural network design with all-optical forward propagation , based on a large number of modifiable optical interconnections and a special weight discretization algorithm to compensate for system noise , is described . The presentation of input and interconnection weights is performed by liquid crystal television screens , and optical thresholding at the hidden layer by a liquid crystal light valve . Saxena & Fiesler An Adaptive Multilayer Optical NN Design IDIAP TR-94-04 2 1 Introduction Multilayer neural networks have proven their usefulness in an ever growing number of application domains . However , their main potential , which is their massive parallelism , is yet to be fully exploited , since they are usually simulated on electronic , single processor computers . Only true hardware implementations of neural networks , -LRB- NN s -RRB- , will be able to exploit their massive parallelism . The most common hardware approach is electronic , using parallel computers or dedicated neural network VLSIs . However , electronic hardware is approaching physical speed limitations due to the enormous number of interconnections required by NNs . Light , on the other hand , offers some very appealing characteristics : travelling at the ultimate speed , not requiring physically limiting wires , and having no cross coupling while several optical channels intersect in free space . Besides having these crucial advantages , optical NNs -LRB- ONNs -RRB- also have the potential to be scaled up in size without appreciable compromises . One of the main problems with analog hardware implementations of NNs is the system noise which limits the number of different values that can be distinguished . A NN weight discretization technique is therefore required that restricts the number of possible weight values without performance loss . Few multilayer ONNs , with limited applicability , have been suggested -LSB- 1 , 2 -RSB- . Some opto-electronicNNs have been demonstrated , for example , with fixed interconnection weights -LSB- 3 -RSB- , performing a ` recall-only ' function ; or the simulation of a multilayer NN by cycling through one perceptron many times -LSB- 4 -RSB- . Adaptivity refers to more than the updating of weights during the training process . Unlike \ hard-wired '' optoelectronic solutions where pre-trained weights of simulated NNs are fixed with masks or holograms , adaptive NNs are application independent . A paucity of techniques in implementing efficiently a large number of modifiable interconnects has prevented the realisation of practical adaptive ONNs . The availability of liquid crystal screens with high pixellation densities , has opened up new possibilities -LSB- 6 -RSB- by providing simpler modifiable interconnects . These high density liquid crystal television -LRB- LCTV -RRB- screens can be used for the interconnection weights in large multilayer optical NNs . The description of an ONN design with a large number of adaptable weights using LCTV screens and optical thresholding , follows . 2 Methodology Our three layer1 neural network has 256 input neurons , 256 hidden layer neurons , and 16 output neurons . The input layer consists of a 16 ? 16 data array , which is presented to the ONN for processing by LCTV1 ; -LRB- see figure 1 -RRB- . The hidden layer non-linearity , concerning 16 ? 16 neurons , is implemented by a Liquid Crystal Light Valve -LRB- or LCLV -RRB- . The 256 ? 256 interconnection weights between these first two layers are represented by the analog transmission values of the pixels of a second LCTV -LRB- LCTV2 -RRB- . Similarly , the 256 ? 16 interconnection weights between the hidden and output layer are represented by LCTV3 . Figure 1 shows the optical system for 1In this report , a layer of a neural network is defined as a layer of neurons -LRB- cf. -LSB- 7 -RSB- -RRB- . In the three layer neural network described in the text , the input layer is considered number one , the hidden layer number two , and the output layer as layer number three . Saxena & Fiesler An Adaptive Multilayer Optical NN Design IDIAP TR-94-04 3 replicating the 16 ? 16 data array -LRB- LCTV1 -RRB- 256 times onto the transmissive LCTV2 for the vector-matrix multiplication . The design is based on positive results obtained with smaller scale , -LRB- 7 ? 7 input -RRB- , NN implementations -LSB- 5 , 6 -RSB- . The information flow through the ONN described above is as follows . After presenting the inputs to LCTV1 , an initial random set of weights is presented to LCTV2 . The intensity of light transmitted by LCTV2 , representing the vector-matrix product of inputs and weights2 , is integrated by a micro-lens array and thresholded by the LCLV to form the outputs of the hidden layer . These outputs , read by a different light source , as explained in the following section , are similarly presented to LCTV3 and the following micro-lens array . The final outputs are detected by a 4 ? 4 photodetector array . If thresholding is desired at the output layer , it may be performed either optically or electronically . In this implementation of a multilayer ONN , training shall be performed with the aid of a personal computer . For a given input pattern on LCTV1 , the personal computer presents initial weights to the LCTVs and subsequently collects -LRB- photodetector -RRB- outputs of the hidden and output layers . With these outputs , weight updates shall be calculated -LRB- by the algorithm described in section 3.4 -RRB- which are again used to drive the LCTVs . This process is repeated iteratively , until the network has been trained . 3 Challenging Aspects 3.1 Three-layered structure Both Hopfield and two-layer -LRB- perceptron like -RRB- electro-optical neural networks have been demonstrated with relative ease , as only a single vector-matrix multiplication is performed optically , while the electronics does the rest -LRB- like thresholding and the calculation of new weights -RRB- . A three-layer ONN is more complicated . A large fraction of the light is attenuated after having transmitted through the optical elements comprising the first two layers of the ONN , namely LCTV1 , LCTV2 , the gratings , and the LCLV . Solutions which allow enough light for further processing are therefore desired . In our system , an Argon-ion laser -LRB- 480nm -RRB- provides the light which transmits through LCTV1 and LCTV2 , and writes to the LCLV . A He-Ne -LRB- 633nm -RRB- light source reads the -LRB- thresholded -RRB- hidden layer output from the LCLV . This method should compensate for the loss of light in the first two layers of the neural network , and maintain sufficient optical power to drive optical processing in the following layer . 3.2 Large number of interconnections A salient feature of this ONN is the large number of connections , nearing almost seventy thousand , inter-connecting the three layers of the network . The highest density of interconnections are implemented between the first two layers by LCTV2 , in which 256 ? 256 pixels shall be activated for the interconnection weights , -LRB- 410 ? 440 addressable pixels are available on each LCTV -RRB- . In order that 2562 -LRB- that is , 65,536 -RRB- 2When light of unit intensity transmits through a material , a fraction of it is transmitted corresponding to the product of the incident intensity with the transmittance of the material . Saxena & Fiesler An Adaptive Multilayer Optical NN Design IDIAP TR-94-04 4 InputLCLVLaserLCTV PBSLaserG2Personal Computer L4Photodiode ArrayLCTV3 PBSG3G4G1Hidden LayerLayer1 Output Photodiode Array Layer21Presents Input PatternsL1 , L2 , L3 , L4 : Lenses PBS : Polarizing Beam Splitter G3 , G2 , G1G4 , : GratingsMLAMLA MLA ? : Micro-Lens ArrayInterconnection Weight Matrices LCTV2LCTV2 , LCTV3 : Implement Adaptable Computes Inter - connection Weights Figure 1 : Schematic overview of the multilayer optical neural network . Saxena & Fiesler An Adaptive Multilayer Optical NN Design IDIAP TR-94-04 5 parallel beams be generated and correctly aligned to transmit through an identical number of pixels on the LCTVs requires the optical elements to have tight performance tolerances . This necessitates building precision optical systems which are stable , robust , and modular . 3.3 LCLVs as Optical Thresholding devices An LCLV is used as a non-linear optical thresholding device in the hidden layer . This reduces the overhead involved in conversion of optical signals into electronic , and re-conversion to opical after electronic thresholding . Such an ` all-optical ' process results directly in optical inputs for subsequent layers , and a truly optical interface is established . The incorporation of LCLV thresholding into the ONN , however , strongly influences the algorithm employed in the training process . Even though the transfer characteristic of the LCLV resembles that of a standard-sigmoid normally used in computer simulations of neural networks , it is truncated , non-centred , and largely assymetric in comparison . The transfer characteristic of one possible LCLV device , as compared to that of a standard sigmoid 's , is shown in figure 2 . The neural network learning rule needs to compensate for non-ideal thresholding functions of practical devices as this one . Preliminary simulation results with the LCLV transfer curve show that the performance of the neural network degrades as compared to that with standard-sigmoid thresholding . 3.4 Weight Discretization Analog optical implementations incur inevitable penalties regarding the precision of computation . A principal focus of the research is the development of training methods for neural networks that compensate for this imprecision , while preserving the performance of the system . A method for discretizing weights and determining the degree of discretization with respect to performance has been developed -LSB- 8 -RSB- . Computer simulations based on this weight discretization method have shown very promising results in which neural networks with only a small number of discretization levels show no considerable loss in performance compared to their counterparts with continuous weights . This method of weight discretization shall be applied and customized to the ONN described here . 4 Summary The design of a large , versatile adaptive multilayer optical neural network using available opto-electronic hardware , has been presented . It exhibits some of the major benefits of using optics , namely , massive parallelism and free-space interconnections with negligible beam interference . The system with close to seventy thousand interconnections is large compared to other SLM based systems . It is versatile , because it is application independent ; only limited in maximum interconnection capability , which is easily upgradable by using larger SLMs . It is adaptive as it is application independent with modifiable weights to enable on-line learning . Above all , it is the first multilayer NN implementation with all-optical feed-forward propagation . Saxena & Fiesler An Adaptive Multilayer Optical NN Design IDIAP TR-94-04 6 2 4 6 8 10 Write Light Intensity 0.10.20.30.40.50.6 Read Light Intensity Measured LCLV Transfer Curve -6 -4 -2 2 4 6 Input 0.2 0.4 0.6 0.8 1 Output Standard-Sigmoid Figure 2 : Transfer Curve of a Standard Sigmoid used in NN Computer Simulations and that of a typical LCLV . Saxena & Fiesler An Adaptive Multilayer Optical NN Design IDIAP TR-94-04 7 The knowledge gained by the implementation of this design shall pave the way towards larger multilayer ONNs by device optimisation and further refinement of the learning algorithm . 5 Acknowledgements This publication is an updated version of the original research proposal to the Swiss \ Fond National '' . We would like to thank Neil Collings for his contribution towards the proposal , the design , and the project 's progress in general . We are also grateful for the support from Daniel Osherson and Ren?e Dandliker . This work is partially supported by the Fond National Suisse de la Recherche Scientifique , project number 21-36497 .92 . References -LSB- 1 -RSB- Kelvin Wagner and Demetri Psaltis , \ Multilayer Optical Learning Networks '' , Applied Optics , Vol . 26 , No. 23 , pp. 5061 -LCB- 5076 , December 1987 . -LSB- 2 -RSB- D. Psaltis and Y. Quio , \ Optical Neural Networks '' , Optics and Photonics News , pp. 17 -LCB- 21 , December 1990 . -LSB- 3 -RSB- J. Ohta et al. , \ Optical Neurochip Based on a Three-layered Feedforward Model '' , Optics Letters , Vol . 15 , 1362 -LCB- 1364 , 1990 . -LSB- 4 -RSB- J.-S . Jang , S.-G . Shin , S.-W . Yuk , et . al. , \ Dynamic optical interconnections using holographic lenslet arrays for adaptive neural networks '' , Optical Engineering , Vol . 32 , No. 1 , pp. 80 -LCB- 87 , January 1993 . -LSB- 5 -RSB- K. J. Weible , G. Pedrini , W. Xue , and R. Thalmann , \ Optical Implementation of a Neural Network Associative Memory Using Diffraction Gratings '' , Japanese Journal of Applied Physics , Vol . 29 , No. 7 , pp . L1301 -LCB- L1303 , July 1990 . -LSB- 6 -RSB- K. J. Weible , N. Collings , and A. Pourzand , \ Initial Results of a Fully Interconnected Neural Network with Modifiable Interconnects '' , European Optical Society : Topical Meetings Digest series , Vol . 1 , 8th : Workshop on Optics in Computing , Paris , 8th : -LCB- 9th : September 1992 . -LSB- 7 -RSB- E. Fiesler , \ Neural Network Classification and Formalization '' , Computer Standards & Interfaces , Vol . 16 , special issue on Neural Network Standards , John Fulcher , editor , North-Holland/Elsevier Science Publishers B. V. , Amsterdam , The Netherlands , 1994 , in press . A preprint is available by anonymous ftp : ftp Maya.IDIAP.CH -LRB- or : ftp 192.33.221.1 -RRB- ; directory : pub/papers/neural ; file : fiesler.formalization.ps.Z -LRB- or fiesler.formalization.ps -RRB- . -LSB- 8 -RSB- E. Fiesler , A. Choudry , and H. J. Caulfield , \ A Universal Weight Discretization Paradigm for Backward Error Propagation Neural Networks '' , accepted for publication by IEEE Transactions on Systems , Saxena & Fiesler An Adaptive Multilayer Optical NN Design IDIAP TR-94-04 8 Man and Cybernetics . See also : E. Fiesler , et al. \ A Weight Discretization Paradigm for Optical Neural Networks . '' Proceedings of the International Congress on Optical Science and Engineering , volume SPIE-1281 , pages 164 -LCB- 173 . The International Society for Optical Engineering Proceedings , Bellingham , Washington , U.S.A. , ISBN 0-8194-0328-8 . 1990 .

O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O

learning
liquid crystal light valve
optical neural network

optical computing
optical multilayer neural network
spatial light modulator