Characterization and Elimination of Redundancy in Recursive Programs

0 downloads 278 Views 1MB Size Report
common generator redundancy, lprovided that the frontier condition holds for the set of functions. {gi!O
CHARACTERIZATION

AND

ELIMINATION

Norman Harvard

Many Abstract. by interpretations procedure Q

well-known of the

f(x)

functions recursion

are schema

OF REDUNDANCY

H.

computed

;

Cohen

However,

many

of

because

they

lead

is,

cause

they

times

then

return

a(x)

else .—

return

b(x,f(cl(x)),

these

with

))

by

f

with

identical

of

known

In

each

to

computes certain

the

be

to

equal

case

there

f(x)

without

for is

are

redundant

be

inefficient

computation.

called

That

recursively

several

arguments.

set

of

transformed about

by f(x)

~rocedure

We

a,

The

which that and

resulting

Figure and

the

results

in

specified

global

transformed

ability program

programs,

of these improvement

locations;

for

criterion redundancy.

the

to present the

establishing

an

the

1,

y+z,

J4 =

Cl(x)

we

obtain

given a Xth element

non-

of

the

;

or

x.1

Q&;return

1

else

f(x-1)

return

computation

f(2)

is

+

f(x-2)

f(3) three

calls

on

f(5) is

is

times. f

pictured

computed

two

In

with

all,

only

in times,

there distinct

six

values. interpretations

certain

procedure is

for

that

computed

fifteen

For

in

without requirements

discuss

transformations system, and

X, returns

Note

1-1.

are

are all valueless intermediate and

each case recursion can be eliminated of a stack. We compare the storage

schema =

which

transformations

programs which leave

the a(x)

= which,

x.O

❑erging

computation. recursive

These procedures

interpret

and b(x,y,z) function,

f’(x)

U

assumptions.

p,

we

(x=O~x=l),

The

program provided

redundancy, assumptions

if ::

integer series:

argument

eKist f,

yield

partially

which,

when

a non-redundant

equivalent

to

of applied program

f.

The

9n , to

the

which

applicability

use

applicautomatic a general

existence

of

INTRODUCTION

Functions

often are

which

definitions recursion

Pn:

to

c2(x) = x-2, following

Ci are satisfied. The transformed programs avoid redundancy by saving exactly those intermediate results which will be needed again later in the

1.

f

p(x)

negative Fibonacci

calls

functions.

formed tree for

each

a

multiple values.

these

acyclic graphs the computation

additional

the

definitions

to

instance:,

letting

redundancy depend on Ci. We explore four

about

assumptions

are

lead

argument

and nature of of the functions

analyze directed the nodes of

redundant

define

they

because

existence properties

of

these

identical

For . . ..f(cn(x)

interpretations

computations

final

PROGRAMS*

p(x)

Some of

sets

RECURSIVE

University

x-1, the

on

IN

schema

P rocedure U p(x) MQQ

else

gn, f(x)

contract

under

by

;

return return

fellowship Navy

defined

and Naval

Figure

a(x) b(x,f(cl

suPPorted

*-Research

recursive of the

elegant have interpretations

(x)),.

by by

U.S.

Electronic

an

..,f(cn(x)

IBM Department Systems

)) research of

1-1.

A

the

interpretation call on

f,

value

that

for

recursive

Command

represented

NOO039-78-G-0020.

143

tree

of

computation

.

of’

and call.

cal 1s by

that

representation

f(5) ~2.

is

the

of

the Fibonacci under represents Each node labelled

The arising node.

sons

with of

directly

the

a node from

argument represent the

call

a

of

these

of

two

transformations

the

functions

frontier predicate

ci~

condition p and

the

such

following

to

each

relating function

the

interpretation,

the on condition

depends descent

a -I defined

global

transformations,

In

one.

BACK2 the

a weaker

under these

placing

Dlaces o; f(x-2)

present

applicable the previous

and

procedure of

produce

determine

checking

f

Strategv The

BACKI,

side-effect

which about

;

variables variables

by

for

[19701, among

;

BACK2

@lcJ The

times.

identified has

reuse we will

begin

o,ther

calls

location value

to

of unbounded

Hewitt 5 that

some

us

amount all

interpretations

calls only references

programming

recursive

BACKI else

allows

recursive and necessary, at

for

knowledge

makes

dynamic

fixed

require

are

Sophisticated

results

begin BACKO

are

inherently

interpretations

to

then

there

a

sufficient

these

which

fix.owx.l

cases be

of storage (Paterson and We show in Section [19711).

are procedure

all, to

Strong

interpretation

f2(x)

not

shown

general,

redundant.) Drocedure

but be

the be

Descent

Conditions We

partition @

subsets, cases, is

values

%

consists

in

the

refer

functions

of

%

in

domain

We shall

domain

.%? .

those

true;

values

the and

the

%

the

of

f c

(In

we consider c(x)=d(x)

very

require

the

m and all and

all

n

existence

such

x in g(gi-l(x))

that

for

which

and

d

strong in

x

notation

otherwise.)

condition

asserts on f%? for some on the existence for

that

c

we

%’.

Section

requirement

5

that and

d commute

The

Condition

Frontier The

and

%,

and

the toward

S be

a

means

set

of

functions

will

functions.)

The

frontier

requirement

that

for

1)

a(h(x))

2)

if

be all

(and

x

thus

f(h(x))

is

and descent we

%

h(x))

is

calls

The resulting descent L@.

the

for

Fibonacci

descent

by the

same

are roots nodes by

the

for

and

d,

into

merging

graph will Figure

dag

c

tree

a

nodes argument

of identical merging those be called a shows a 1-3

descent

tree

of

1-1.

@GJ%Q ,...,, .... >

say as

(b(x, b(c(x), o(c(c(x )):', a(d(c(x)))), b(d(x), / (b)

‘=.

b(c(x), o(c(c(x))),

all

& c

in

dc

d

cd

d

the

computation

,,-

Figure of

descent is the h

;=

cc

these of S

o(c(d(x ))), o(d(d(x))))~

b[d(x), o(c(d(x))), o(d(d[x))))

a(d~a

(c)

to @

values Formally,

then

Figure tree

about

with

subtrees.) compressed

more

defined,

defined

is

in

descent

(dag)

to

map

and

f

the

subtrees,

weak (We

(Typically,

in

do

descent

is between

for

a descent

assumptions

two such nodes and we merge the

‘a)

and

cases.

compositions condition

(Any

Figure

descent

functions

depicted

is

where

graph

descent

surprisingly,

‘Ieasierft functions.

comrn’ess

i=O

become

descent

certain

may

compressed

we

if

.$%?.

condition boundary

is

for x

weaker

frontier !Inicett

1-1

f(5),

correspond

value.

integers

relatively

Not

of

acyclic

which

that

m and n, but of g. The

transformations

that

monotonically let

gi(x)

Figure

we make we

directed

IS hold 2

3

g and d(x).gn(x)

on

If

descent

condition Section

the

%?.)

purpose of the that there is a

assure

is

on

our

a

conventions in

computation

then

descent

and

tree

function.

p

false.

is

these

The

those

the

Ci

progressively

conditions, intricate.

is

as

c(d(x)).d(c(x))

consider

which

This weaker cn(x)=dm(x) that In Section 4 our Cn(x)=dm(x) that

implies on

condition

p

of a function

(The

for

of

1-2. the

base

cases,

descent 4?. In

condition c(d(x)).d(c(x)) c(d(x))=d(c(x)) not insist

f

two

the

A descent condition relationships on %. In Section

c(x)=gm(x)

iZ?.

of

general,

for I

Suggest Documents