• Aucun résultat trouvé

A Complexity Calculus for Recursive Tree Algorithms

N/A
N/A
Protected

Academic year: 2022

Partager "A Complexity Calculus for Recursive Tree Algorithms"

Copied!
50
0
0

Texte intégral

(1)

P UBLICATIONS DU D ÉPARTEMENT DE MATHÉMATIQUES DE L YON

P HILIPPE F LAJOLET J EAN -M ARC S TEYAERT

A Complexity Calculus for Recursive Tree Algorithms

Publications du Département de Mathématiques de Lyon, 1984, fascicule 6B

« Théorie des langages et complexité des algorithmes », , p. 39-88

<http://www.numdam.org/item?id=PDML_1984___6B_A3_0>

© Université de Lyon, 1984, tous droits réservés.

L’accès aux archives de la série « Publications du Département de mathématiques de Lyon » im- plique l’accord avec les conditions générales d’utilisation (http://www.numdam.org/conditions).

Toute utilisation commerciale ou impression systématique est constitutive d’une infraction pé-

(2)

A C O M P L E X I T Y C A L C U L U S FOR R E C U R S I V E T R E E A L G O R I T H M S

by Philippe F L A J O L E T ( I . N . R . I . A . - Rocquencourt - France) and Jean-Marc S T E Y A E R T ( C e n t r e de Math. A p p l . -

Ecole Polytechnique - Palaiseau - France)

ABSTRACT :

We study a restricted programming language over tree structures. For this language, we give systematic translation rules which map programs into complexity descriptors. The descriptors are in the form of generating functions of average costs. Such a direct approach avoids the recourse to recurrences ; it therefore simplifies the task of analyzing algorithms in the class considered and permits analysis of structurally complex programs. It also allows for a clear discussion of analytic properties of complexity desciptors whose singularities are related to the asymptotic behavior of average costs. Algorithms that are analyzed in this way include : formal differentiation, tree matching, tree compatibility and

simplification of expressions in a diversity of contexts. Some general results relating (average case) complexity properties to structural properties of programs in the class can also be derived in this framework.

RESUME :

L'objet de cet article est l'étude d'un langage de programmation restreint pour les structures arborescentes. On donne pour ce langage des règles de traduction systématiques qui associent aux programmes des des- cripteurs de complexité représentant les coûts moyens sous forme de série génératrice. Une telle approche directe évite le recours aux récurrences et permet ainsi l'analyse de programmes structurellement complexes. Ceci nécessite l'examen des propriétés analytiques des descripteurs de complexité dont les singularités déterminent le comportement asymptotique du coût moyen.

Divers algorithmes sont étudiés de cette manière : dérivation formelle, re- cherche de motifs, compatibilité, simplification d'expressions. Quelques résultats généraux reliant les coûts moyens à la structure des programmes de la classe définie sont également donnés dans ce cadre.

39

(3)

1. I N T R O D U C T I O N

A Large number of a l g o r i t h m s of both practical and t h e o r e t i c a l interest c o n s i d e r e d in the literature are realized by c o m b i n a t i o n s of recursive descent p r o c e d u r e s over recursively d e f i n e d d a t a s t r u c t u r e s ,

As is also the case for l o o p - p r o g r a m s , such a l g o r i t h m s have the i n t e r e s t i n g p r o p e r t y that t e r m i n a t i o n is a priori g u a r a n t e e d by their s t r u c t u r e , so

* h a t no u n d e c i d a b i l i t y q u e s t i o n a r i s e s to limit the p o s s i b i l i t y of a n a l y ­ zing p r o g r a m b e h a v i o r - We m e n t i o n the following classes :

(i) Tree a l g o r i t h m s : forma' d i f f e r e n t i a t i o n (in formal m a n i p u l a t i o n s y s t e m s ) , tree m a t c h i n g (as o c c u r s in compiler o p t i m i z a t i o n ) , r e d u c t i o n a l g o r i t h m s (in t h e o r e m proving or s y m b o l i c e x e c u t i o n ) . (ii) C o m p a r i s o n searching and sorting : b i n a r y search (for m a i n t a i n i n g

d i c t i o n a r i e s ) , h e a p - l i k e s o r t i n g , tree s o r t i n g , q u i c k s o r t a n d a number of their v a r i a n t s .

(iii) Digital search : with a l g o r i t h m s for i n s e r t i n g , d e l e t i n g and q u e r y i n g tables that m a i n t a i n digital keys (strings over some fixed a l p h a b e t ) ; v a r i o u s s e t - t h e o r e t i c o p e r a t i o n s such as u n i o n a n d i n t e r s e c t i o n can also be p e r f o r m e d e f f i c i e n t l y .

The p e r f o r m a n c e s of a number of such a l q o r i t h m s have a l r e a d y b e e n a n a l y z e d and ( i i ) , (iii) represent a n o n n e g l i g i b l e f r a c t i o n of

[ K n 7 3 ] . A few a n a l y s e s p e r t a i n i n g to (i) are also d i s c u s s e d in [ K n 6 8 ] . Existing a n a l y s e s e s s e n t i a l l y obey the following p a r a d i g m .

For an a l g o r i t h m A over a set of inputs I ( v i z . t r e e s , p e r m u t a t i o n s , digital sets ), with In the subset of inputs of size n , we consider the q u a n t i t i e s :

i = c a r d lp x an = X! t i m e ^ [e]

(4)

To d e t e r m i n e these q u a n t i t i e s , i.e., " a n a l y z e " the a l g o r i t h m , one u s u a l l y sets up recurrence relations b a s e d o n the o n e hand o n a c o m b i n a t o r i a l d e c o m p o s i t i o n of the s t r u c t u r e into smaller components :

i = Ф <{i.}. )

n J j <n

a n d , o n the other h a n d , o n tracing back the c o m p l e x i t y of the algorithms o n s u b s t r u c t u r e s a n d s u b r o u t i n e s . For i n s t a n c e , in the case of two

m u t u a l l y d e p e n d e n t s u b r o u t i n e s . А , В e q u a t i o n s w o u l d have the form :

та = ^ Ц т а Л . , ( х Ь Л .

:

« П Л . )

тап A J J 4n )/]<n 1 ,jj rj < n i bn = *B< { T 3 J } J N ; { T b j } j <n ; { i j } j <n >

One then a t t e m p t s to solve these recurrence r e l a t i o n s , relying o n classical t e c h n i q u e s from the calculus of finite d i f f e r e n c e s , the alqebra of formal power series or a n a l y s i s .

Such p e r f o r m a n c e a n a l y s e s are b a s i c a l l y o n e - s h o t . A new set of e q u a t i o n s has to be set up for each new a l g o r i t h m c o n s i d e r e d a n d often a d hoc s o l u t i o n m e t h o d s have to be f o u n d in each p a r t i c u l a r c a s e . E x p e r i e n c e , h o w e v e r , s h o w s that most " r e a s o n a b l e " a l g o r i t h m s u l t i m a t e l y exhibit r e l a t i ­ vely simple b e h a v i o r s (expressible in terms of s t a n d a r d f u n c t i o n s ) , and the set of a p p l i c a b l e t e c h n i q u e s seems much more r e s t r i c t e d than appears at first g l a n c e .

This paper p r o p o s e s to d e v e l o p a n a l t e r n a t i v e framework to the a n a l y s i s of such a l g o r i t h m s , trying to capture m a n y of the regularities e n c o u n t e r e d in the r e c u r r e n c e a p p r o a c h . It starts with the o b s e r v a t i o n that g e n e r a t i n g f u n c t i o n s for input counts ( in> a n d c u m u l a t e d complexity counts ( т ар) d e f i n e d by

i (z) = I inzn a n d xa(z) = I та z n

s a t i s f y e q u a t i o n s w h o s e shapes reflect the structural d e f i n i t i o n s of

inputs a n d p r o g r a m s (such a r e l a t i o n also e x i s t s b e t w e e n programs and r e c u r ­ rences but is of a m u c h less simple f o r m ) . This o b s e r v a t i o n can be d e v e l o p e d into a system of t r a n s l a t i o n rules that allow a s y s t e m a t i c t r a n s l a t i o n from p r o g r a m texts into c o m p l e x i t y d e s c r i p t o r s (the g e n e r a t i n g functions of the c u m u l a t e d c o m p l e x i t i e s т ар) . More p r e c i s e l y , each t r a n s l a t i o n rule s p e c i f i e s in a p a r t i c u l a r context how the c o m p l e x i t y descriptor of a larger p r o g r a m can be d e t e r m i n e d from the c o m p l e x i t y d e s c r i p t o r s of its simpler c o m p o n e n t s .

41

(5)

The system of rules thus forms the a l g e b r a i c part of a c o m p l e x i t y caIculus for the class of p r o g r a m s c o n s i d e r e d - The next s t a g e , which involves complex a n a l y s i s , is to recover proper i n f o r m a t i o n o n p r o g r a m c o m p l e x i t y form these c o m p l e x i t y d e s c r i p t o r s - We use here the e x i s t e n c e of r e l a t i o n s b e t w e e n the nature of a f u n c t i o n a r o u n d its s i n g u l a r i t i e s in the c o m p l e x plane and the a s y m p t o t i c behavior of its Taylor c o e f f i c i e n t s . By tracing singular parts of c o m p l e x i t y d e s c r i p t o r s , we are thus able to d r a w , in a s y s t e m a t i c w a y , p r e c i s e c o n c l u s i o n s o n the costs of a l g o r i t h m s .

We p r o p o s e here to illustrace this a p p r o a c h by s t u d y i n o a r e s t r i c t e d p r o g r a m m i n g language over tree s t r u c t u r e s . This language P L - t r e e o p e r a t e s o n tree s t r u c t u r e s as appear in c o m p i l i n g , formal m a n i p u l a t i o n s y s t e m s , t h e o r e m p r o v i n g , a u t o m a t i c i n f e r e n c e , i.e., e s s e n t i a l l y term trees (in s i n g l e - t y p e d or h e t e r e g e n e o u s a l g e b r a s ) . It a l l o w s for b a s i c r e c u r s i v e d e s c e n t m e c h a n i s m s p o s s i b l y g u i d e d by the i n f o r m a t i o n s c o n t a i n e d in nodes of the t r e e s . The language is powerful e n o u g h to include p r o g r a m s for formal d i f f e r e n t i a t i o n , tree m a c h i n g , tree e n b e d d i n g , r e d u c t i o n of e x p r e s s i o n s for w h i c h p r e c i s e p e r f o r m a n c e e s t i m a t e s are g i v e n .

A m o n g s t the works that bear relations to our a p p r o a c h we m e n t i o n : (i) i n v e s t i g a t i o n of relations b e t w e e n structural p r o p e r t i e s of c o m b i n a ­

torial o b j e c t s and c o r r e s p o n d i n g g e n e r a t i n g f u n c t i o n s is an i m p o r t a n t t r e n d in c o m b i n a t o r i a l a n a l y s i s : one can refer to w o r k s by R o t a , F o a t a , S c h ü t z e n b e r g e r [Ro75][FS70] a n d the very s y s t e m a t i c t r e a t m e n t in J a c k s o n a n d G o u l d e n [ J G 8 1 ] .

(ii) W e g b r e i t [W76] a n d Ramshaw [R79] have p r o p o s e d c o m p l e x i t y a s s e r t i o n s systems that are a n a l o g u e s of the Floyd-Hoare a s s e r t i o n s in formal s e m a n t i c s ; these systems can be used to e x p r e s s c o m p u t a t i o n a l p r o p e r t i e s of p r o g r a m s but seem too general to allow a u t o m a t i c p e r f o r m a n c e a n a l y s t s of s p e c i f i c c l a s s e s . Closer to our o b j e c t i v e is W e g b r e i t ' s system [W75] for a u t o m a t i n g the a n a l y s i s of a set of L I S P - l i k e p r o c e d u r e s o n l i s t s . It i s , h o w e v e r , b a s e d o n recurrence relations a n d , as s u c h , has to rely in its r e s o l u t i o n part o n s t r i n ­

(6)

(iii) We finally exploit i n f o r m a t i o n s o n functions a r o u n d their singularities to d e r i v e the a s y m p t o t i c s of their c o e f f i c i e n t s - This is related to the D a r b o u x - P o l y a m e t h o d [He74], e s o e c i a l l y to d e v e l o p m e n t s in a paper by Meir a n d M o o n [MM78] , as well as the use of p a r t i c u l a r contour i n t e g r a t i o n by O d l y z k o [082] a n d [ F 0 8 2 ] [ S F 8 2 ] .

The p l a n of the paper is as follows :

S e c t i o n 2 s t a r t s with a d e s c r i p t i o n of the p r o g r a m m i n g constructs of P L . t r e e (Section 2 . 1 . ) , together with a s s o c i a t e d c o m p l e x i t y rules (Section 2.2.) ; proof t e c h n i q u e s for these a l g e b r a i c c o m p l e x i t y rules are d i s c u s s e d in S e c t i o n 2 . 3 . , a n d the set of a n a l y t i c tools n e e d e d to interpret c o m p l e ­ xity d e s c r i p t o r s a p p e a r s in S e c t i o n 2.4.

We then work out several a n a l y s e s in detail :

Firstly the classical a l g o r i t h m for s y m b o l i c d i f f e r e n t i a t i o n (Section 3 ) ; secondly a tree c o m p a t i b i l i t y a l g o r i t h m (Section 4) closely related to the

" g e n e r a l i z a t i o n p r o b l e m " in s y m b o l i c m a n i p u l a t i o n . In S e c t i o n 5, we conclude with two further e x a m p l e s : tree matching r e v i s i t e d with results c o m p l e m e n ­ ting t h o s e o f [SF82] a n d a simple case of a top d o w n recursive s i m p l i f i e r .

2 - COMPLEXITY D E S C R I P T O R S AND COMPLEXITY RULES

In this s e c t i o n , we first d e s c r i b e informally the m a i n features of the p r o g r a m m i n g language (PL-tree) to which our rules a p p l y . We then state the m a i n rules that allow c a l c u l a t i o n of c o m p l e x i t y d e s c r i p t o r s a s s o c i a t e d to p r o g r a m s ; these rules also serve indirectly as a s p e c i f i c a t i o n of the a l l o w a b l e constructs of P L - t r e e - L a s t l y , we present some a n a l y t i c t r a n s l a t i o n

lemmas that make it p o s s i b l e to extract i n f o r m a t i o n o n the a s y m p t o t i c

time complexity of p r o g r a m s from the e q u a t i o n s s a t i s f i e d by their complexity d e s c r i p t o r s as d e r i v e d through the complexity r u l e s .

43

(7)

2.1. - A P r o g r a m m i n g L a n g u a g e o n Trees

The basic data type underlying PL-tree is a set of term trees

o r e x p r e s s i o n trees : a fixed a l p h a b e t of o p e r a t o r s y m b o l s ft is g i v e n ; to each o p e r a t o r GO C ft is a s s o c i a t e d its a r i t y (or d e g r e e ) - 6 G o ) - ; this d e f i n e s in a s t a n d a r d way the set of term trees c o n s t r u c t e d o n ft : a tree T with root oo can b e w r i t t e n in functional form as

T = c o ( T , , . . . , T6 ( a j ) )

where the T^'s are t h e m s e l v e s trees built o n ft . The set T of all trees built o n ft thus s a t i s f i e s f o r m a l l y the e q u a t i o n :

T =. I 03 (T,T,...,T ) (1)

0)

€ ft

in which the number of T's a p p e a r i n g in (D(T, . . . J ) is equal to the a r i t y of a). E q u a t i o n (1) will also be w r i t t e n for short as

T = ft (T)

Our a n a l y s e s are relative to p r o g r a m s o p e r a t i n g o n data types T j , T2 , — (i ncludi ng T i tself) w h i c h are s u b t y o e s o f T a n d are d e f i n e d by some ftj_ c ft :

T. = ft4 ( T . ) (2)

1 L

E l e m e n t s of T are commonly w r i t t e n in f u n c t i o n a l form as above a n d can be r e p r e s e n t e d as trees as s h o w n in Figure 1.

We shall d e n o t e the size of a tree T - i.e. its total number of nodes or e q u i v a l e n t l y of symbols - by ITI.

+

f A ' A

(8)

P L - t r e e i s a l a n q u a q e o f a p r o c e d u r a l type w h i c h does not allow e x p l i c i t a s s i g n m e n t of v a r i a b l e s . From d e v e l o p m e n t s that follow it will b e clear that it is not u n i v e r s a l . Such a c o n s t r a i n t has to be out o n the

language s i n c e , as is well k n o w n , c o m p l e x i t y p r o p e r t i e s of u n i v e r s a l p r o ­ g r a m m i n g languages are h i g h l y u n d e c i d a b l e . Yet P L - t r e e a l l o w s p r o g r a m m i n g of a large number of r e c u r s i v e p r o c e d u r e s of g e n e r a l interest as it has b e e n m e n t i o n n e d p r e v i o u s l y .

W i t h o u t going i n t o a formal s p e c i f i c a t i o n of the l a n g u a g e , that w o u l d take us too far a w a y , w e b r i e f l y d i s c u s s its m a i n c h a r a c t e r i s t i c s :

(i) B a s i c d a t a types :

The b a s i c type is the set of trees d e f i n e d in (1) together w i t h s u b ­ types of the form ( 2 ) . Integers are a l l o w e d in a r e s t r i c t e d form in the control of loops a n d in tests o n node d e g r e e s , but cannot b e a s s i g n e d freely to v a r i a b l e s or p r o c e d u r e r e s u l t s .

B o o l e a n s may only a p p e a r as the result of e l e m e n t a r y tests or as the result of b o o l e a n p r o c e d u r e s (functions) to be u s e d in c o n d i t i o n a l i n s t r u c t i o n s .

(i i) P r i m i t i v e o p e r a t o r s :

The m a i n o p e r a t i o n s are the o n e s d e a l i n g w i t h trees ; for a tree X : - r o o t ( X ) is the label of the root of X , thus a n element of ft.

- d e g ( X ) is the a r i t y of the root of X ^ i . e . 6 ( r o o t ( X ) ^ .

- for an integer i, X [ i ] d e n o t e s the i-th root s u b t r e e of X so that X = r o o t ( X ) ( \ [ 1 ] , . . , x [ d e g ( X ) ] y *

E l e m e n t a r y tests allow c o m p a r i s o n of the root of a tree to some e l e m e n t in ft a n d of its d e g r e e to some fixed i n t e g e r .

R e s u l t s of tests a n d b o o l e a n f u n c t i o n s c a n a l s o b e c o m b i n e d using the s t a n d a r d b o o l e a n c o n n e c t i v e s ,

(iii) The p r e s e n t a t i o n of the syntax is P a s c a l - o r i e n t e d .

P r o c e d u r e a n d p r o g r a m d e f i n i t i o n s allow usual s e q u e n t i a l c o m p o s i t i o n of i n s t r u c t i o n s d e n o t e d b y

P r o c e d u r e calls a r e w r i t t e n a s usual : A (Yj,..,Y ) d e n o t e s a p p l i c a t i o n of p r o c e d u r e A to a r g u m e n t s Yj rv 2' Y m' with a r g u m e n t s b e i n g p a s s e d by r e f e r e n c e .

P r o c e d u r e d e f i n i t i o n s obey the format :

p r o c e d u r e A (Xj : T j ; X2 : ^2 ' — * : — e n d p r o c ; f u n c t i o n A (Xj : T ; X ^ : ; ) : endfct ;

in the case of a pure p r o c e d u r e w i t h o u t result a n d of a b o o l e a n f u n c t i o n r e s p e c t i v e l y .

45

(9)

The control s t r u c t u r e s are : c o n d i t i o n a l s :

if < b o o l e a n e x p r e s s i o n > then < i n s t r u c t i o n > else < i n s t r u c t i o n > fi i t e r a t i o n :

with Q a p r e d i c a t e over ]Nm x ftm it reads :

for (i-|,..,im) with Q ( i - | / — , im, r o o t ( X < | ) , — , r o o t ( Xm) ) do B ( Y1, . . . , Yp, X1[ i1] , . . . , Xm [ im] ) o d .

This c o n s t r u c t means that the body of the f o r - l o o p will be e x e c u t e d for all v a l u e s of indices i , 1 < j < m and 1 < i < d e g ( X j ) , w h i c h s a t i s f y p r e d i c a t e Q, w h e r e Q may d e p e n d o n the root labels of its a r g u m e n t s .

c o n d i t i o n a l i t e r a t i o n :

w i t h a r g u m e n t s X i , X £ , , Xm satisfying deg(X>|) = d e q ( X 2 ) = ...= d e g ( Xm) , it reads :

for i 1 t £ d e g ( X ^ ) whi le Q ( X1 [ i ] , . . . , Xm [i ]) do B ( X ^ i ] ...,X [i]) o d

With this m e c h a n i s m , r o o t - s u b t r e e s of a m - t u p l e s of trees can b e s e a r c h e d until a c o n d i t i o n t e r m i n a t i n g the loop is m e t .

Notice t h a t , in these i t e r a t i o n s , the v a l u e s of the indices are u n d e f i n e d o u t s i d e the loop.

(iv) Special f e a t u r e s :

These are the w r i t e , a s s i g n a n d nil c o n s t r u c t s :

- wri te (<info>) : where info is a string p o s s i b l y made of e l e m e n t s of ft, can b e u s e d to t r a n s f e r i n f o r m a t i o n o n a w r i t e - o n l y o u t p u t file ; in p a r t i c u l a r , this feature a l l o w s p r o g r a m s to o p e r a t e as tree t r a n s d u c e r s , the results b e i n g o u t p u t for instance in polish prefix n o t a t i o n (trivial m o d i f i c a t i o n s w o u l d make it p o s s i b l e to p r o d u c e linked t r e e - s t r u c t u r e s as o u t p u t s ) .

" a s s i g n (<boolean e x p r e s s i o n > ) : each b o o l e a n f u n c t i o n is a s s u m e d to have a special result register ; the a s s i g n construct can be p u a r o u n d

(10)

(v) m a c r o i n s t r u c t i o n s :

It is c o n v e n i e n t to a v o i d Long s e q u e n c e s of n e s t e d conditional s t a t e m e n t s w e shall t h e r e f o r e use in some cases the f o l l o w i n g m a c r o i n s t r u c t i o n :

case root(X) of_

a) 1 : < i n s t r u c t i o n >

OJ : < i n s t r u c t i o n >

fo

w h i c h is easily t r a n s l a t e d in terms of if t h e n e l s e . For c o m p l e x i t y e s t i m a t e s , we shall consider that this switch p e r f o r m s a single test

(this c o n v e n t i o n could c l e a r l y b e c h a n g e d w i t h o u t d e e p l y a f f e c t i n g our r e s u l t s ) .

In Figure 2, we g i v e a n e x a m p l e of p r o g r a m in P L - t r e e , w h i c h tests two trees for e q u a l i t y , using a recursive search in p r e o r d e r .

f u n c t i o n equal (X,Y : T) :

if root(X) # root(Y) t h e n a s s i g n (false) e l s e a s s i g n (true) ;

for i<- 1 to d e g ( X )

w h i l e a s s i g n (equal (X[i],Y[i])) do niI o d

e n d equal .

Figure 2 : The f u n c t i o n equal which tests two trees for e q u a l i t y .

47

(11)

2.2. - C o m p l e x i t y Rules

We d e f i n e here input d e s c r i p t o r s a n d c o m p l e x i t y d e s c r i p t o r s

a s s o c i a t e d to P L - t r e e data s t r u c t u r e s and p r o g r a m s We later give a set o f rules that can b e u s e d to i n d u c t i v e l y d e t e r m i n e t h e c o m p l e x i t y d e s c r i p t o r s of p r o g r a m s a n d p r o c e d u r e s from their simpler c o m p o n e n t s .

Let U c T ™ k e a set of m - t u p l e s of t r e e s .

The g e n e r a t i n g f u n c t i o n -or c h a r a c t e r i s t i c f u n c t i o n - of U is the s e r i e s

Xu (x ,x^,...,x ) = Y* C x ?1 x ?2. .xP m (3) 1 2 m L-J n ^ n - ^ . - . n - 1 * • • •xm

n1 , n2 /. , nm 1' 2' m

w h e r e

X, n2 nm = C a r d { ( X r X

2

X

m

) U

'

'X1 ' = n

1

I X

- '

= n

4 «

(4)

Let furthermore Q b e a p r e d i c a t e over T™ ; w e a l s o i n t r o d u c e t h e c o n d i t i o n a l c h a r a c t e r i s t i c f u n c t i o n of U w i t h c o n d i t i o n Q as :

xu (x<|,x-2'-•-'x m I ^ = X ( U A Q ) ( X ^ X ^ , . . ) , (5)

w h e r e U A Q ist t h e c o n j o n c t i o n (intersection) of U a n d Q ; In the s e q u e l , w e r e p e a t e d l y make u s e of the n o t a t i o n [ xJ1 x ? ... x ^ ] f ( xvx2 xm)

to d e n o t e t h e Taylor c o e f f i c i e n t of x "1 x ^2 ... x ^m "in f (x<|,x2,.. .,xm) - W i t h this n o t a t i o n , w e s e e that (5) is e q u i v a l e n t to :

K1 x 2 2 •••xmm] XU <*1'*2 xm lQ > =

c a r d | ( X1, X2, . - . , Xm) € U / |X-|I = n ^ . - . J X j = nm , Q ( XV. . .,Xm) Î

(12)

S i m i l a r l y , let A(X<| : T ^ X z : T"2, . . . , Xm : Tm) be a p r o c e d u r e d e f i n e d o n m a r g u m e n t s of respective types T<\ , T2, . . . Tm. A s s u m e also that a s t a n d a r d c o m p l e x i t y m e a s u r e T is d e f i n e d for p r o g r a m s in P L - t r e e , with

T A(X-j,X2, - - .,Xm)

r e p r e s e n t i n g the cost of running p r o c e d u r e A o n a r g u m e n t s X ^ , X 2 , - . - , Xm. The c o m p l e x i t y d e s c r i p t o r of A is d e f i n e d as the series

T a(x<|,x2, - - - xm) w h o s e general c o e f f i c i e n t is

[ x ?1 x £2 . . . x M Ta(X l, X 2, . . . , x| n) = I TA ( X1, X2, . . . , Xm) (6)

J I Xql = n q , . . . , I Xml = nm

a n d r e p r e s e n t s the c u m u l a t i v e cost of running a l g o r i t h m A over all inputs ( X1, X2, • - . , Xn) of size ( n i, n 2 ,- - - nm) -

For Q a p r e d i c a t e o n Ti x T2 x. . . x Tm , the c o n d i t i o n a l c o m p l e x i t y d e s c r i p t o r of A (under condition**) is similarly d e f i n e d as the series

x a ( x i, X 2 ,- --xml Q) w i t h

[ x!J1 x^ 2 .. .xnm 1 T a( xvx2, - . . , xml Q ) =

I T A( X1, X2, . . . , Xm) .

IX-)I = n1, . . . , I Xml = nm Q ( X * , • • •, X.)

Ir ' m

Thus t a ( x i, X 2 ,- - - xm I Q) d e s c r i b e s the c o m p l e x i t y of A w h e n a p p l i e d to a r g u m e n t s sati'sfy/r'ngcondition Q-

In the f o l l o w i n g w e shall use e x t e n s i v e l y a vector n o t a t i o n to d e n o t e m - t u p l e s of v a r i a b l e s a n d c a r t e s i a n p r o d u c t s :

X , x a n d n will d e n o t e respectively

( X1, X2, . . . , Xm) , ( x1, x2, . . . , xf T |) a n d ( n1 , n?, . - - , nm) - T will d e n o t e 7\j x 7"2 x..x Tf f l .

In p a r t i c u l a r , w e shall w r i t e X € T i n s t e a d of ( X1, X2, . . . , Xm) e x T2 x..x Tm a n d

|X| = n i n s t e a d of IXiI = for I < i < m .

49

(13)

It also proves convenient to use X [i ] to d e n o t e

<X-| [i-,], X2 h^L- - rx nm3 ) and ^ to d e n o t e "m x m n

(thus x ~ = x^ X 2- - - xm) ; hov;ever, for the sake of n o t a t i o n a l s i m p l i c i t y , we shall o f t e n use x instead of xl w h e n no a m b i g u i t y a r i s e s , so that :

[?xj f (x) =

[¿4

f < x ) .

(14)

From the d e f i n i t i o n s follow a few b a s i c facts w h i c h we now list : (i) If Q(X) = Qi (X) v G*2 (X ) w h e r e Qi 3nd Q2 are disjoint p r e d i c a t e s

(i-e- Q1 A Q2 e false) :

xq(x) = X Q i (x) + X Q 2 <x>

x a ( x j Q) = Ta(x^I Q1) + x a ( x j Q2) . (8) If Q(X) = C L W - ) A G U ( X J A . . A Q (X ) t h e n

I I c c m m

xq(x> = XQ^x-,) . x q 2( x2}- •xqm(xm) '

with x t r u e = 1 a n d x f a l s e = 0 (9) (ii) Let t ( x ) , t-j(x) d e n o t e the c h a r a c t e r i s t i c f u n c t i o n s of types

T , 1\ (since they will be of constant use w e omit there the p r e f i x x > • Let <X>(u) «D^u) r e s p e c t i v e l y ) be the power s e r i e s d e f i n e d from Q

(ft-i resp.) by

[un] <D (u) = card jooEft Ideg(o)) = n j , (10)

with a s i m i l a r d e f i n i t i o n for the fl^'s. T h e n t(z) s a t i s f i e s the e q u a t i o n ( D W I 7 8 ] , [G65],[SF82],[F082] ) :

t(x) = x <D^t(x)^ (11)

a n d s i m i l a r l y for t^- From (9) f o l l o w s in p a r t i c u l a r that the c h a r a c t e ­ ristic f u n c t i o n of the type x x..x 7"m is

t-(x) t^(x) t ( x ) .

I c m

(iii) If the p r o c e d u r e A(X : T ) d e p e n d s e f f e c t i v e l y o n only p a r g u m e n t s w h e r e p < m - s a y X1, X 2" • • -'x 0 ~ ' U c a n b e w r i tt e n a s :

A(X^,«--,X^) = B(X«|,a..,X ) a n d we have

xa(x) = x b ( xl y, . . . , x ). n f xi) . (12) p < i < m

51

(15)

This Last e q u a t i o n is easily r e l a t i v i z e d to s o m e p r e d i c a t e GL x G> x ... x Q over L x x..x I :

1 2 m 1 d m

Ta ( x I Gl x G> x...x Q ) = xb(x I GL x...x Q ) . TT x Q . < x . ) (12')

~ 1 2 m — 1 p i i

p<i <m

(iv) G i v e n a p r o c e d u r e A (X : 7) a n d its c o m p l e x i t y d e s c r i p t o r x a ( x ) , the series x a ( z , z , ,z) is o f t e n w r i t t e n for short as x a ( z ) .

Its n-th Taylor coefficient s a t i s f i e s

[zn] xa ( z ) = I T A ( Xr. . . , Xm) ( 1 3 )

| X1l + . . . + l Xml = n

w h i c h t h e r e f o r e r e p r e s e n t s the c u m u l a t e d cost of p r o c e d u r e A o n all m - t u p l e s of inputs of total size n .

We can now p r o c e e d with the s t a t e m e n t of c o m p l e x i t y r u l e s . Each rule a p p l i e s to a construct in the language of the form

A = C (B^Bz,...)

a n d e x p r e s s e s the c o m p l e x i t y d e s c r i p t o r xa of A in terms of the c o m p l e x i t y d e s c r i p t o r s xb-j of the p r o g r a m s e g m e n t s B-j a n d the c h a r a c t e r i s t i c functions of the u n d e r l y i n g d a t a t y p e s :

xa(x) = r ^ x b i ( x ) , x b 2 < > 0 , — , ^SZ?^

O c c a s i o n a l l y (in the case of b o o l e a n c o n s t r u c t s ) , r may also involve the c h a r a c t e r i s t i c functions of some i n t e r v e n i n g b o o l e a n p r o c e d u r e s .

(16)

Rules are relative to an a d d i t i v e ( w . r . t . c o m p o s i t i o n of i n s t r u c t i o n s ) c o m p l e x i t y m e a s u r e c o r r e s p o n d i n g to e x e c u t i o n time o n an a b s t r a c t m a c h i n e m o d e l , w h o s e p r o p e r t i e s are s u m m a r i z e d in Figure 3.

T h e r e is n a t u r a l l y c o n s i d e r a b l e a r b i t r a n n e s s i n the choices made in this table : our p u r p o s e has o n l y b e e n to have rules that are reasonably s i m p l e to state ; from the d e v e l o p m e n t s that follow it s h o u l d be clear that a d e q u a t e time c o n s t a n t s in p r o c e d u r e c a l l s , t e s t s , b r a n c h i n g . . . c o u l d be i n t r o d u c e d to reftect more closely the time constants of any p a r t i c u l a r m a c h i n e m o d e l .

C o n s t r u c t R e s u l t i n g c o m p l e x i t y

A s B ; C T A = T B + T C A s B ( X [ i ] ) T A = T B (X [i])

f TA = TQ + TB if Q

A = i± Q th en B else c f i I TA = TQ + TC i f Q

A H for i with Q do B o d . . , o l

~ — — TA is the sum of TB ' s c o r r e s p o n d i n g to a r g u m e n t s which satisfy p r e d i c a t e Q a n d of T Q ' S .

A = for i w h i l e Q do B o d TA is the sum of T Q ' S an TB ' s c o r r e s - p o n d i n g to e x e c u t i o n s of Q a n d B w h i l e c o n d i t i o n Q is s a t i s f i e d a n d , of the first e x e c u t i o n of Q w h i c h returns false.

Q s a b o o l e a n c o m b i n a t i o n of T Q = 1 a t o m i c p r e d i c a t e s o n root labels

a n d degrees

a s s i g n , nil x a s s i g n = xniI = 0

Figure 3 : A s u m m a r y of the d e f i n i t i o n s of the a d d i t i v e m e a s u r e c o n s i d e r e d .

5 3

(17)

R u l e 1 [Composition]

W h e n

A(X) = B(X) ; C(X)

w h e r e X^ is of type T , o n e has for any p r e d i c a t e Q on T : x a ( x I Q) = x b ( x I Q ) + t c ( x I Q ) .

r^> <~->

R u l e 2 [Conditionals]

W h e n

A (X ? s 11 Q (X ? the n B (X ? else C(X) jM o n e has

x a ( x ) = x q ( x ) + x b ^ x I Q ( X ) ) + x c ^ x I-Q(X))

These two rules follow d i r e c t l y from the a d d i t i v e character of the time c o m p l e x i t y m e a s u r e .

Rule 3 [Subtree d e s c e n t ] W h e n

A(X) s B [i-, ], -. . , X [ ip] )

for s o m e ij all d i f f e r e n t , w h e r e X is of type T , o n e has : x a ( x ) = x t b ( x , x , .. .,x) * (^t(x)^

w h e r e

a)

e

Πp < 6 (w)

A v a r i a n t of Rule 3 is of special interest w h e n we insist that the rootsubtrees be identical ; we state it in a special c a s e .

Let E qw be the p r e d i c a t e over T d e f i n e d by :

Eq a ) (X) s J root (X) = to a n d Vj X [j ] = X [ 1] J .

(18)

We t h e n have :

Rule 3 eg [Subtree d e s c e n t with E q u a l i t y ] W h e n

A(X) • B-( X ti])

w h e r e X is of type T a n d i < 6(03), o n e has under c o n d i t i o n E q ^ :

Ta ( x I E qw) = x x b ( x6 ( a ) )) . Rule 4 [Iteration]

W h e n

A(X) s for i with o/ i , root (xA do B ( X [ i ] ) Q d

with X of type T o n e has

w h e r e

a n d

a_<6) = c a r d <<i,u>) I V j 6- = 6 <u. ) & Q(i,cu)f •

Two s u b c a s e s of Rule 4 are of s p e c i a l i n t e r e s t so that w e s t a t e t h e m a s d e r i v e d rules :

Rule 4 dis [Distributive d e s c e n t ] W h e n

A(X) s for i do B(X [i ]) o d w i t h X of t y p e T , o n e has :

xa(x) = x ib(x)

n

<x>. ( t . (x.) )

i < j < m

t

<X>!, $! d e n o t e the d e r i v a t i v e s of <X> a n d .

5 6

(19)

Let Eqrt b e t h e p r e d i c a t e over "/^defined b y

Eqrt(X) = Vi 1<i<m root(X<|) = root(X-j) The s e c o n d d e r i v e d rule states a s f o l l o w s :

Rule 4 sim [simultanious d e s c e n t ] W h e n

A(X) = for i 1 to d e g ( X ^ do

B ( X1[ i ] , X2[ i ] , . . . , Xm[ i ] ) o d where X is of type Tmo n e h a s under c o n d i t i o n

Eqrt :

xa(x, I Eqrt) = £ Tb(x^) O'l n t ( xj)) -

A v a r i a n t of Rule 4 is also of interest w h e n t h e descent a f f e c t s a subset of t h e input a r g u m e n t s :

Rule 4 p d s [Partial d e s c e n t ] W h e n

A ( X , Y ) s for i + 1 to d e g ( Y ) do B ( X , Y [ i ] ) o d where Y is in T , o n e h a s

xa(x,y) = y x b( x , y ) O ' ^ t ( y ) ^ .

Rule 5 [Conditional i t e r a t i o n ] When

A(X) = f o £ 1 4 - 1 to d e g ' C X ^ w h i l e Q(X,[i]) do B C X j j ] ) o d where X is in T , o n e has under c o n d i t i o n Eqrt :

(20)

where

F(u) = I u6 ( a 3 ) , I = Q n-

a>ei J

3

As a final r u l e , we give the c o m p l e x i t y d e s c r i p t o r of the p r o c e d u r e that copies a tree o n the o u t p u t f i l e :

Rule 6 [Copy]

With X in T one has : xcopy (x) = x t1( x ) .

This rule a c t u a l l y f o l l o w s from the p r e c e d i n g o n e s as we shall sea later.

We now t u r n to e q u a t i o n s for c h a r a c t e r i s t i c f u n c t i o n s of b o o l e a n p r o c e d u r e s . The b a s i c remark is that the result of a b o o l e a n f u n c t i o n

is p r e c i s e l y that of the last " a s s i g n " - i n s t r u c t i o n e x e c u t e d ; the s i t u a t i o n is t h e r e f o r e more i n t r i c a t e for c h a r a c t e r i s t i c f u n c t i o n s t h a n for c o m p l e ­ xity d e s c r i p t o r s ; however some schemes are q u i t e o f t e n e n c o u n t e r e d for w h i c h w e give the following rules :

Rule 7 [Characteristic functions]

(i) W h e n

a(X) s j_f Q(X) then a s s i g n ( b ( X ) ) e l s e a s s i g n ( c ( X ) J fj_

w h e r e X is of type T , o n e has :

xa(x) = xb(x, I Q) + x c C x J ^ Q ) . (ii) W h e n

A(X) = j[or i + 1 t_o deg ( X ^

while a s s i g n ^Q(Xji])J do B(X[i]> o d

w h e r e is in T a n d B is a pure p r o c e d u r e (without b o o l e a n result) o n e has under c o n d i t i o n Eqrt :

x a ( x j Eqrt) = X/(F(xq(x,)) - F ( 0 ) ) w h e r e

• F(u) = I u6 (u) , I = n fij -

0) 6 I

58

(21)

This Last a s s e r t i o n e x p r e s s e s the fact that p r e d i c a t e Q holds true for all m - t u p l e s xti] , 1 < i < d e g ( X - ) .

2.3. - Proof t e c h n i q u e s

C o u n t i n g m u l t i s e t s is the m a i n tool for p r o v i n g c o m p l e x i t y r u l e s . To introduce the m e t h o d let us start with the p r o b l e m of c o u n t i n g trees in a family T d e f i n e d by a set Q of o p e r a t o r s :

T = I ( T , T , . . . , T ) ,

a) € tt or in other w o r d s :

T =

I I I

c t T , , Tp) . (14)

" » ° « < . " , I T 1 - ' T P ' T P

The g e n e r a t i n g f u n c t i o n t(x) of T can also b e w r i t t e n as :

t(x) =

I

X | T | ; (15)

T € T

so that it can be f o r m a l l y d e r i v e d from the m u l t i s e t T by replacing each node (or symbol) of a T € T by an x, taking j u x t a p o s i t i o n of v a r i a b l e s as p r o d u c t s .

A p p l y i n g this t r a n s f o r m a t i o n to e q u a t i o n (14) w e thus o b t a i n :

v / \6<a>) t(x) = / x f t ( x ) J

/ \ n

= x I sn ( t(z> j (16)

w h e r e sn is the number of o p e r a t o r s of arity n in Q .

This s y m b o l i c way of d e r i v i n g g e n e r a t i n g f u n c t i o n s is i n s p i r e d by w o r k s of S c h u t z e n b e r g e r tFS 7 0 ] . It can b e e x t e n d e d to count m u l t i s e t s of trees as s h o w n in [G65] [SF 82] a n d in parallel d e v e l o p m e n t s of [BR 8 2 ] . It m a k e s it p o s s i b l e to translate "at s i g h t " inductive '

(22)

G i v e n a p r o c e d u r e A ( X : T) w e consider the m u l t i s e t a s s o c i a t e d to the cost m e a s u r e :

T A = Y TA ( X ) - X . (17)

x e r

(a) The proof of Rule 3 [subtree descent] can b e d e r i v e d a s f o l l o w s ; by d e f i n i t i o n w e have o n m u l t i s e t s :

T A = I x B ( X [ i1] , . . . , X[ip]> - X X € T

I I TB(X I, . . . , X ) . a) (V- " 'XS ( a > ) }

I ai j i B , T5(A3>" P J (19) 0)

6(a))>p

where the b r a c k e t s indicate the a r g u m e n t s of x B s h o u l d b e d i s t r i b u t e d in the p o s i t i o n s i^ to i . A p p l y i n g the t r a n s l a t i o n s c h e m e o n (19) w e o b t a i n :

„ / \6(o))-p

xa(x) = I x xb(x,...,x) ( t ( x ) j (20) 6(o))>p

from w h i c h the rule f o l l o w s .

(b) The p r o o f s of rules 1-2-4-5-7 are q u i t e s i m i l a r , a l t h o u g h m u l t i v a r i a t e series are u s e d ; consider for i n s t a n c e Rule 5 [Conditional i t e r a t i o n ] ; by d e f i n i t i o n :

60

(23)

rA( I Eqrt) = \ 7

^ I 1 T Q (X [ 1 ] ) . ^ X

+ I I { ^B(^fP ~1]) + T Q C X t p ] ) ^ .X 1<p<6(o)) A \ Q ( X j i ] )

X ^1 #< P \

I tb(x,[5CO>>]) - X (21)

*\Q(X,[i]) | 1 < i <5 (oj)

where £ m e a n s that the s u m m a t i o n is t a k e n over t h e m - t u p l e s

<X. [ 1 ] , . . . Xj [6<w>]> € T ?( ( A i ) , 1 < j < m , a n d Xj = O J ^ Xj [1],...,Xj [6(o))]^ .

A p p l y i n g the t r a n s l a t i o n s c h e m e , we a s s o c i a t e to trees in Tj the v a r i a b l e xj , 1 < j <m a n d w e o b t a i n :

Ta ( x ) = I x„...x I Xq ( x )p~1 ( r b U l Q ) + x q ( x ) ) a) 1 m 1 < p < 5 ( w ) ~ V ~ 1

. n 7

t

. (x .)V

( w )

"

p

1<j<m V

J 3 /

p - 1 6 ( w ) - p

=

,* (

T b (

*

, Q ) + T

q<x)J I I *

q (

£? (

T T t

j

( x

j

)

) "

( 2 2 )

03 p

The last s u m being a g e o m e t r i c p r o g r e s s i o n , w e o b t a i n the final form of t h e r u l e .

Rule 6 c o u l d b e a l s o D r o v e d a l o n g these l i n e s b u t we c a n o b t a i n

i t t h r o u g h the o t h e r r u l e s b y e x p r e s s i n g the p r o c e d u r e c o o y r e c u r s i v e l y as :

p r o c e d u r e copy (X : T) : w r i t e (root(X)) ;

for i«-1 to deg(X) do cooy ( X [ i ] ) o d end c o p ^ .

(24)

2.4. - A n a l y t i c t r a n s l a t i o n m e t h o d s

It s h o u l d b e clear at this s t a g e , that g i v e n a p r o g r a m (viz. a set of p r o c e d u r e s ) in P L - t r e e , o n e is able to d e r i v e , u s i n g the p r e c e d i n g r u l e s , a system of e q u a t i o n s which d e t e r m i n e s v a r i o u s

g e n e r a t i n g functions a s s o c i a t e d to the p r o g r a m a n d which u l t i m a t e l y d e f i n e the c o m p l e x i t y d e s c r i p t o r . In this p a r a g r a p h , we are i n t e r e s t e d in

d e t e r m i n i n g the b e h a v i o u r of the a v e r a g e c o s t , a s y m p t o t i c a l l y w h e n the size of the data gets large.

Most complexity d e s c r i p t o r s a s s o c i a t e d to s i m n l e p r o g r a m s s a t i s f y a system of e q u a t i o n s of the form :

W h e r e the h's a n d H's are k n o w n f u n c t i o n s ; this is u s u a l l y

a c h i e v e d after some a l g e b r a i c t r a n s f o r m a t i o n s , by e l i m i n a t i n g c o n d i t i o n s from conditional c o m p l e x i t y d e s c r i p t o r s .

A special case of interest is w h e n the s y s t e m can be w r i t t e n in the form

f^xj) = X i H- ( f O c ) ) (25)

It is then p o s s i b l e to solve it a l g e b r a i c a l l y a n d to recover the c o e f f i c i e n t s of the Taylor e x p a n s i o n s of the f's using the L a g r a n g e - G o o d i n v e r s i o n t h e o r e m for implicit f u n c t i o n s [G 60] ; h o w e v e r the e x p r e s s i o n s thus o b t a i n e d are usually too complex to allow a y m p t o t i c a n a l y s i s . We t h e r e f o r e t u r n to a more d i r e c t a p p r o a c h that f o l l o w s the

lines of [MM 7 8 ] , [0 3 2 J , [SF 8 2 ] , [F0 82] : this a p p r o a c h is b a s e d o n the e x i s t e n c e of relations b e t w e e n the a s y m p t o t i c s of Taylor c o e f f i c i e n t s of a f u n c t i o n a n d the b e h a v i o u r of that f u n c t i o n a r o u n d its m a i n s i n g u l a r i t y .

62

(25)

More p r e c i s e l y , the c u m u l a t e d costs relative to total input size n have a g e n e r a t i n g f u n c t i o n which is o b t a i n e d by replacing in (24) all o c c u r r e n c e s of x-j's by z ; so that the s y s t e m (24) b e c o m e s :

|9 i. ( z ) = K . ( z , fl(k<z>)) • ( 2 6 )

In (26) o n e of the f u n c t i o n s ( z ) , call it c ( z ) , is the

complexity d e s c r i p t o r of the a l g o r i t h m c o n s i d e r e d ; in order to d e t e r m i n e the a s y m p t o t i c b e h a v i o u r . o f the c o e f f i c i e n t s cn of c(z) w e study "its s i n g u l a r i t i e s . The m e t h o d relies o n two remarks :

(i) let P b e the radius of c o n v e r g e n c e (r.d.c.) of c(z) ; t h e n the e x p o n e n t i a l order of growth of cn is P"~N , that is

V e > 0 [ P "1d + e ) ] "n < cn < V1d + e ) ] ~n i - o a . e

(ii) If z = P is the unique s i n g u l a r i t y of c(z) of m o d u l u s P , the b e h a v i o u r of

rn = cNPN is d e t e r m i n e d by the local e x p a n s i o n of c(z) at z = P .

T h e major fact c o n c e r n i n g a l g o r i t h m s w r i t t e n in P L - t r e e is that in most cases c(z) b e h a v e s as ^1 - £ ^ "a ; more p r e c i s e l y , at z = P ,

c(z) can b e w r i t t e q :

c(z) = ^1 - 1 u(z) + v(z) (27) where u a n d v are regular at z = P , a n d A € ID \ {0,-1,-2 — } .

P r o p e r t y (27) a l l o w s us to s t a t e , b y the Darboux theorem [H 7 4 ] , [D 1878] that :

cn = - u (P) p - n H ^ L . (1 + 0

(J))

< 2 8 )

r ( A ) V X JJ

where r is the Euler g a m m a f u n c t i o n .

Let us i l l u s t r a t e this m e t h o d by d e r i v i n g the a s y m p t o t i c number of term trees d e f i n e d o n a f i x e d set of o p e r a t o r s ft. Let <£(u)

(26)

We know by (11) that the g e n e r a t i n g f u n c t i o n t(z) s a t i s f i e s : t(z) = z « (t ( z )) -

Let us further a s s u m e that the c o n d i t i o n s (C) below h o l d : (i) the sp a r e b o u n d e d by some fixed M

(ii) g c d j n l sn * 0 = lj

( C o n d i t i o n (ii) can easily be d i s p e n s e d w i t h ) .

S u m m a r i z i n g e x t e n s i v e d i s c u s s i o n s of [MM 7 8 ] [ S F 8 2 ] w e have : (a) t(z) is a n a l y t i c for all z, |z| < p , e x c e n t z=p w h e r e

p = — ! — < 1 (29)

<&'(T)

a n d x is t h e root of s m a l l e s t m o d u l u s of the e q u a t i o n :

T 41 ( T ) = <2>(T) ; (30)

T is a l w a y s a real p o s i t i v e number

(b) at z = p , t(z) has a n e x p a n s i o n of t h e form :

) • j , 6n ( i - | ) " ' 2 « 1 >

/ 2d>(T) w h e r e v = -/

V <3>"(T)

S i m i l a r l y , the e n u m e r a t i n g s e r i e s for t h e f a m i l y of

k- tuples of trees in T is t ^ ( z ) , w h o s e radius of c o n v e r g e n c e is still p , a n d at z=p s a t i s f i e s :

1/2

tk( z ) =

(

1

- I

) u k ( z ) + vk( z) (32)

w h e r e u|< a n d a r e regular a n d

u.(p) = - k T H

JM^I

k K * " (T )

64

(27)

From t h e above d i s c u s s i o n f o l l o w s that t h e c o n d i t i o n s for t h e Darboux theorem to a p p l y a r e s a t i s f i e d a n d w e c a n state :

P r o p o s i t i o n 1 : Let T b e a f a m i l y of trees s a t i s f y i n g c o n d i t i o n s ( C ) . Let tn ^ t ^ k ) ^ b e t h e number of trees (k-tuples of trees) of size n ; then : I

tn • (1*0 (1))

+(k)- u k-1 / * < T ) _N _ 3 , -

*n "

kT

V^^"

P

"

(1+0

^

)>

wh e r e p = — — a n d TG' ( T ) = <I>(T) .

• ' ( T )

Local e x p a n s i o n s of input a n d program d e s c r i p t o r s a r o u n d their singularities will b e s y s t e m a t i c a l l y u s e d to d e r i v e t h e a s y m p t o t i c b e h a v i o u r of p r o c e d u r e c o s t s , as g i v e n by t h e c o m p l e x i t y rules of § 2 . 2 . Let us

give o n e e x a m p l e of this s i t u a t i o n (we c o n t i n u e to a s s u m e here that the family of inputs T s a t i s f i e s c o n d i t i o n s ( O )

P r o p o s i t i o n 2 : Let B b e a p r o c e d u r e o n trees of type T a n d A b e the iterate of B o n s u b t r e e s , d e f i n e d b y :

A(X) = B ( X ) ; for_ i + 1 to deg(X) do A ( X [ i ] ) o d

Assuming xb(z) h a s a unique a l g e b r a i c s i n g u l a r i t y t o n its circle of c o n v e r g e n c e , a n d

b ~ c . na n

for some constants c a n d a < _ then

- .

r

(°-')

z

°

4

xa ~ c8 ^ H n n

(28)

w h e r e 9 is a c o n s t a n t d e p e n d i n g o n l y o n T, a n d r is the Euler g a m m a f u n c t i o n „

Proof : By Rules 1 a n d 4 d i s we have :

xa(z) = xb(z) + z xa(z) ® 1 (t(z) ) , h e n c e

a(z) = T b ( 2 ) (33>

1-z <&' (t(z>)

From e q u a t i o n (11) w e get b y d e r i v a t i o n :

1 - z * ' (t<z>> = (34) zt'(z)

S i n c e x bn is e q u i v a l e n t to c na, *rb(z) has radius of c o n v e r g e n c e p , a n d from the h y p o t h e s i s a d m i t s at z=p (its s i n g u l a r i t y ) the e x p a n s i o n :

T b ( z ) = ( t - ~ j " 6 M,(z) • ^(z) (35)

w h e r e a n d v.] are regular at z=p . R e w r i t i n g (31) as :

z U

t(z) = (1 - - ) ^ 2 u( z ) + v ( z ) , p

w e o b t a i n the e x p a n s i o n for t'(z) at z=p :

t'(z) =

- _L

^1 -^y'1

[u<z)

- 2 ^ 1 --^

u'(z)j

+ v ' ( z ) . (36) T h e n xa(z) has radius of c o n v e r g e n c e p a n d at z=p w e c o n c l u d e from (33)

(34) (55) (36) that it s a t i s f i e s :

xa(z) = - ±J& u2( z ) + v2( z ) (37)

w h e r e U2 a n d V £ are regular a n d 6 = ) - \ if 0 ^ 0

1 1

1 (3 + JL o t h e r w i s e

I

2

F u r t h e r m o r e w h e n & > 0

u9( p ) = -u-(p) - 1

1 1 2 t

w h e r e y and t are d e f i n e d in e q u a t i o n s (30) a n d ( 3 1 ) .

66

(29)

By p r o p o s i t i o n 1 a n d the Darboux theorem it is easy to see that a = 0 +

-1 .

Applying a g a i n D a r b o u x1 theorem to (37) leads to the a s y m p t o t i c value of the a v e r a g e cost of p r o c e d u r e A.

(30)

3. D I F F E R E N T I A T I O N A L G O R I T H M S

In this s e c t i o n w e study a class of a l g o r i t h m s w h i c h p e r f o r m formal d i f f e r e n t i a t i o n o n e x p r e s s i o n s r e p r e s e n t e d by trees ; in a m o r e a l g e b r a i c setting these a l g o r i t h m s can also b e s e e n as t o p - d o w n f i n i t e state t r a n s d u c e r s [Th 73]and illustrate a natural class of c o m p u t a t i o n s o n t r e e s , Let us start w i t h some d e f i n i t i o n s .

Let 0, be a n a r b i t r a r y finite set of o p e r a t o r s (including p o s s i b l y +, -, \Tr l o g , s i n , . . . ) , v a r i a b l e s (x,y...) a n d c o n s t a n t s ( a , b , c , . . . ) . A set of d i f f e r e n t i a t i o n rules D over the f a m i l y T o f t e r m s c o n s t r u c t e d o n Q, is d e f i n e d by local t r a n s f o r m a t i o n s o n ^ t e r m s : a term

X = u) (X [1],...,X M)

with leading o p e r a t o r GO of a r i t y m is t r a n s f o r m e d into a term DX = X (Xfi,,], , X [ ip] , D X t l l , . . . , D X tml)

w h e r e as usual the X [ i j ] ' s are root s u b t r e e s of X a n d DX [i ] d e n o t e s the d e r i v a t i v e of X [ijaccording to the set of d e r i v a t i o n r u l e s . In the d e r i v e d e x p r e s s i o n , A wi 11 be c a l l e d the header ; let e ^ , 6^ , i > 1 be n u l l a r y s y m b o l s not in .Q ; the header A of DX is a tree over

R1 = fi U jei I 1 < i < m | U j^i I 1 < i ^ m |

w h e r e 6-j1 s occur e x a c t l y o n c e : the term DX is thus o b t a i n e d by

s u b s t i t u t i n g X [ i ] ' s to e.'s a n d DX[i]'s to S i ' s . The fact that 6^'s o c c u r e x a c t l y o n c e is an important f e a t u r e of d i f f e r e n t i a t i o n ; thus in D X , d e r i v e d s u b e x p r e s s i o n s DX[i] , 1 < i < m , o c c u r o n c e , w h e r e a s c o p i e d s u b e x p r e s s i o n s X [ i ] ' s , 1 < i < m , may occur several t i m e s .

N o t a t i o n s : Let co € Q be an o p e r a t o r , with arity <5(OJ) = m . Let A ( e1. . , £ ^ , 6 ^ . .,6m> be the header of D

( w ( x

1

,

.. . , Xm> )

The size h(oo) of the h e a d e r A a s s o c i a t e d to co is the n u m b e r of nodes of A b e l o n g i n g to R ( e ^fs a n d Si's are not c o u n t e d ) . For 1^i^m, ot(aj).j is the number of times s u b e x p r e s s i o n X [i ] is c o p i e d ( s u b s t i t u t e d to

e^) in the d e r i v e d e x p r e s s i o n , i.e. the number of o c c u r r e n c e s of $i in A ; the total number a(oo) of c o p i e d s u b e x p r e s s i o n s is a(w) = a(a))-j + ...+ 01(00)^.

68

(31)

Fiqure 4 g i v e s a n e x a m p l e of d i f f e r e n t i a t i o n r u l e s .

M u l t i p l i c a t i o n :

D * C X , Y ) = + (* ( X , D Y ) , * ( D X , Y ) ) ;

The header is + ( * ( . , . ) , * ( . , . ) ) so that h(*) = 3 , a(*) = 1 + 1 = 2

S q u a r e root :

D v T (X) = v ( D X , * (2 , \ T( X ) ) ) ;

the header is * (. , * (2 , \/ (.))) so that h(\/) = 5 ,

a(V)

= 1

Inverse :

D i n v ( X ) = o p ( T ( D X , * ( X , X ) ) ) ;

the header is o p ( T ( . , * ( . ,.))) so that h(inv) = 3 a ( i n v ) = 2

Figure 4 : Some usual d i f f e r e n t i a t i o n r u l e s .

(ei's a n d 6i's have b e e n m a r k e d by dots in h e a d e r s ) .

The rules of some d i f f e r e n t i a t i o n s y s t e m D t r a n s l a t e at sight into a n a l g o r i t h m w r i t t e n in P L - t r e e a p p l i e d to inputs of type

T , w h e r e T = Q ( T ) ( s e e , e - q . , [ K n 6 3 ] p . 3 3 8 ) . The general form of the a l g o r i t h m is g i v e n in Figure 5 a ; the s e q u e n c e of i n s t r u c t i o n s c o r r e s ­ p o n d i n g to each b r a n c h of the case s h o u l d be m a c r o e x n a n d e d as is shown

in P?nnre 5-b o n a n e x a m p l e .

(32)

p r o c e d u r e diff (X : T ) = case root(X) £ f

0)^1 " g e n e r a t e Xw CXC i 11 , .-,X[ ip],dif f CXC1]"), - -, d i f f(x[ p ] ) >

w o : g e n e r a t e X ( )

a) : g e n e r a t e X ( ) n ^ n esac

e n d diff .

Figure 5-a : General form of the d i f f e r e n t i a t i o n a l g o r i t h m

* : w r i t e ('+') ; w r i t e ('*') ; c o p y M x M l ) ; diff (x[2l) ; w r i t e ('*•') ; diff ( x t i l ) ; copy ( x[ 2 ] ) .

inv : w r i t e C o p ' ) ; w r i t e < • * • ) ; diff <X[1]> ; w r i t e ('*') ; copy (X[1]> ; copy < X [ 1 ] ) .

Figure 5-b : M a c r o e x p a n s i o n of g e n e r a t e for two usual o p e r a t o r s .

The c o m p l e x i t y d e s c r i p t o r of p r o c e d u r e diff is t h e r e f o r e by Rule 2 [conditionals]

x d i f f ( z ) = t(z) + J x g e n e r ( z I root(X) =o>) (38) 0)

By R u l e s 1-3 a n d 6 one gets :

6(d)) xgener (z I root (X)=o)) = h&o) z(t(z))

+ a ( o » z2t ' ( z ) ( t ( z ) )5 < w )~1

+ 6(a)) z xdiff (z)(t(z)) (3 9)

w h e r e the first term c o r r e s p o n d s to wri te i n s t r u c t i o n s , the s e c o n d to copy i n s t r u c t i o n s a n d the t h i r d one to recursive calls w i t h s u b t r e e d e s c e n t .

70

(33)

C o m b i n i n g (38) a n d (39) w e f i n a l l y g e t that : t d i f f ( z ) = t(z) + zH(t(z)) + z2t ' ( z ) A (t(z))

+ zxdiff(z) <X>'(t(z)) (40) where H ( u ) = £ h C O u l 5 ( u ) )

w

a n d A ( u ) = I a (w) u 6 ( a ) )"1 . w '•

S o l v i n g this linear e q u a t i o n in tdiff(z) w e o b t a i n the e x p l i c i t form :

. t ( z ) + z H (t(z)) + z2t ' ( z ) A ( t ( z ) ) , , „x

Tdiff(z) = (41) 1 - z<3>'(t(z))

a n d by (35)

xdiff(z) = t.( z ) + i l l i i l H( t ( z ) ) + z f2( z ) A( t( z) ) < « >

t(z) t(z) S i n c e b y the L a g r a n g e i n v e r s i o n t h e o r e m w e have explicit e x p r e s s i o n s for t h e c o e f f i c i e n t s of t(z) a n d t'(z) it w o u l d be p o s s i b l e to provide e x p l i c i t b u t a k w a r d e x p r e s s i o n s for the coefficient of xdiff ; the formulae o b t a i n e d in this w a y a r e q u i t e intricate so that it w o u l d be h a r d -if not i m p o s s i b l e - to derive a n a s y m p t o t i c e s t i m a t e for t h e a v e r a g e cost of the a l g o r i t h m .

We thus t u r n to the a n a l y t i c study of T d i f f ( z ) .

Since ft is f i n i t e , H ( u ) a n d A(u) a r e p o l y n o m i a l s a n d o n e c a n

conclude that xdiff(z) h a s radius of convergence P - Furthermore for I z| = o its s i n g u l a r i t i e s are p r e c i s e l y those of t(z) a n d t ' ( z ) . lie can thus

o b t a i n a local e x p a n s i o n of x d i f f ( z ) at z=p by simply r e p l a c i n g t(z) a n d t'(z) b y t + - ~^j~2 and T' + Y' (1 " f respectively in

e q u a t i o n (42) : ^

(34)

U s i n g the Da'rboux t h e o r e m we conclude that

T d i f fn = [ znl x d i f f ( z ) = - £ l cx y '2 p ~n ( 1 + 0 ( n ~1 / 2) ) .

x

From (28) w e have for the a v e r a g e cost :

x d i f fn P2 0^ / 2 n ^M(T) 3 / 2 / n/ - 1 / 2 - \ \

T d i f fn = Q = a Y , 2V n ( l + 0 ( n ))

tn T f » ( T ) \ \ //

T h e o r e m 1 :

The a v e r a g e cost of a d i f f e r e n t i a t i o n a l g o r i t h m t s of the form :

Td i f fn = c n3 /2 + 0(n)

w h e r e c is a c o n s t a n t w h i c h d e p e n d s only o n the family of trees a n d the set of r u l e s .

The b e h a v i o r of the a v e r a g e cost (0(n3/2)) is to be c o m p a r e d to the w o r s t case ( 0 ( n2) ) a n d the best case ( 0 ( n ) ) . It is important to n o t i c e that the n o n linear cost is due tn the conies of s u b t r e e s the a l g o r i t h m

p e r f o r m s . If we allow p o i n t e r s so that c o m m o n s u b e x p r e s s i o n s c o u l d be s h a r e d , we c o u l d simply a t t a c h the s u b t r e e s of the a r g u m e n t to the h e a d e r s w i t h unit cost (independently of the size of the s u b t r e e ) .

E q u a t i o n (41) w o u l d t h e n be c h a n g e d to

x d i f f ( z ) = t'(z) + Z t > ( 2 ) ^ H ( t ( z ) ) + A ( t ( z ) ) ) (43)

t(z) \ 7

w h o s e a n a l y s i s y i e l d s a linear a v e r a g e cost c o n s i s t e n t with the linear w o r s t case b e h a v i o u r .

72

(35)

4 - T R E E C O M P A T I B I L I T Y

In this s e c t i o n we study a n a l g o r i t h m w h i c h returns the g r e a t e s t commun part of two trees in a family T ; this a l g o r i t h m can a p p e a r as the first part of g e n e r a l i z a t i o n a l g o r i t h m s . The interest relies now o n the fact that the p r o c e d u r e has two a r g u m e n t s as one can see o n

Figure 6.

p r o c e d u r e comoat (X , Y : T )

if root(X) * root(Y) t h e n w r i t e C .1) else b e g i n w r i t e (root(X)) ;

for i<-1 to deg(X) do dbmpat ( X [ i ] , Y[i]) e n d f i

e n d c o m p a t .

- Figure 6 -

A l g o r i t h m for t r e e - c o m p a t i b i l i t y

The c o m p l e x i t y d e s c r i p t o r of p r o c e d u r e compat s a t i s f i e s the f o l l o w i n g e q u a t i o n s ; by rule 2 we d e c o m p o s e Tcompat in :

x c o m p a t (x,y) = t(x) t(y) + x t h e n (x,y I root(X) ± root(Y))

+ xelse (x,y I root(X) = r o o t ( Y ) ) . (44) w h e r e the unit cost of the test in taken into account by the term t(x) t ( y ) .

Now

T t h e n (x,y I root(X) t root(Y)) = t(x).t(y) - x y $ ( t ( x ) t(y)) (45) since this q u a n t i t y is the c h a r a c t e r i s t i c f u n c t i o n of pairs ( X , Y ) € T ^ whose roots are d i f f e r e n t .

By R u l e s 1 a n d 4 s i m one i m m e d i a t e l y o b t a i n s : xelse (x,y I root(X) = root (Y)) =

xy $ ( t ( x ) t(y))

+ xy T C o m p a t ( x , y ) <£' (t (x) t (y)) - (46) C o m b i n i n g e q u a t i o n s ( 4 4 ) , ( 4 5 ) , (46) a n d s o l v i n g the linear

Références

Documents relatifs

Apparus sur le marché au cours de l'année passée, ces produits ont retenu notre attention pour leurs performances techniques et environnementales, leurs qualités esthétiques....

machine contenant des bouts de programme qui doivent être liés entre eux et à d’autres programmes objets pour obtenir un programme exécutable.. ♦ Le programme exécutable,

Next, we address the question of effectively recognizing Garside families and we describe and analyse algorithms doing it: in Section 2, we consider the case when the ambient

The proof of the main theorem needs a diÆcult combinatorial result (proposition.. 18) which has some interest

In this paper we focus on Upper Confidence Bound (UCB) bandit algorithms [ACBF02] applied to tree search, such as UCT (Upper Confidence Bounds applied to Trees) [KS06]. A reward

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des

As a second example, which will be detailed in the sequel, consider the computation of the complex roots of a separable polynomial f of degree n over the complex numbers: once

To do so, we actually relate (polynomial-time) computable functions over the reals to (polynomial-time) computable functions over the integers, and provide some statements that allow