Crossbar Based Model Provides Viable Platform for PRAM Simulation Peter J. Looges Stephan Olariu ? Department of Computer Science Old Dominion University Norfolk , VA 23529 Abstract The Parallel Random Access Machine or PRAM model , has been a much employed parallel algorithm development tool for a number of years . As such , many important problems have been solved on this model . Accordingly , considerable attention has been given to the process of simulating PRAM models on more realistic architectures . The purpose of this paper is to present an efficient simulation of the Concurrent Read Exclusive Write and Common Concurrent Read Concurrent Write PRAM models by the enhanced linear array with global buses -LRB- ELAGB -RRB- . The ELAGB is a linear array enhanced by a Crossbar network . The buses of the network are assumed to have a bus delay of d -LRB- n -RRB- . Recent implementations of the crossbar network in CMOS VLSI technology support the viability of the ELAGB model . It is the communication flexibility of the crossbar network which supports the PRAM simulations in a very straightforward manner without the complex interconnection systems or high overhead algorithms of many prior simulations . 1 . Introduction Shared memory model SIMD computers have received considerable algorithmic attention in many areas of computation , see -LSB- A89 -RSB- for an overview . The simulation of PRAM models has accordingly received considerable attention . This simulation may be separated into two categories , the simulation of common memory through a network and the use of an interconnection unit between the processors and memory -LSB- ALG91 , AHM87 , R87 -RSB- . We shall employ the first strategy to simulate the common memory . We are interested in two shared memory models , the Concurrent Read Exclusive Write or CREW and the Common Concurrent Read Concurrent Write or Common CRCW . While arithmetic and logic operations typically pose no problems , the concurrent read and write operations often cause additional complexity when simulating these models on actual architectures . Thus any system which efficiently handles this concurrency can inherit a vast quantity of algorithms which are already ? Support by the National Science Foundation under grant CCR-8909966 is gratefully acknowlwdged . developed . The crossbar based , enhanced linear array with global buses -LRB- ELAGB -RRB- is such a model . It has been shown that in addition to inheriting a number of algorithms , the model also inherits the corresponding lower bounds . The remainder of the paper is organized as follows : Section 2 reviews the main features of the crossbar based enhanced linear array with global buses ; Section 3 examines the enhanced linear array with global buses as a platform to simulate the Concurrent Read Exclusive Write and Common Concurrent Read Concurrent Write Parallel Random Access Machine models ; Section 4 summarizes the results . 2 . The Enhanced Linear Array with Global Buses A parallel array architecture is a set of processing elements connected via some type of interconnection network -LSB- S84 -RSB- . Many different interconnection topologies have been proposed and implemented in recent years . These include the n-cube -LSB- C90 , NCUBE , VB81 -RSB- , the perfect shuffle -LSB- S71 -RSB- , the mesh of trees -LSB- L81 , L83 , NMB83 -RSB- , the multi-dimensional mesh array -LSB- A88 , BBK68 -RSB- , the mesh with multiple broadcast -LSB- DAP1 , CCC90 , PR87 , ML89 -RSB- , and parallel arrays with reconfigurable bus systems -LSB- LM89 -RSB- . The most basic type of processing element interconnection scheme is that of a linear array . In this scheme , a processing element is connected to at most two other processing elements . The main advantage of this scheme is its simplicity and regularity , which in turn reduces cost . Large linear arrays can easily be constructed by fusing together a series of smaller arrays . Linear arrays have been shown to be useful in low level image processing , graph algorithms , and some numerical computation -LRB- see -LSB- DV87 , KY82 , K84 , RV83 -RSB- for further details -RRB- . While the linear array has definite advantages from the cost and engineering standpoints , there are some very significant drawbacks . Primary is long distance communication . Standard linear arrays are characterized by large communication latency in addition to a small communication bandwidth -LSB- DV87 -RSB- . This implies that communication time between two processing elements could be of the order of the size of the array . For communication intensive algorithms this would be an excessive and intolerable cost . The more complex array topologies solve the communication cost problem , but at the expense of complexity and higher engineering costs . 2.1 The Crossbar Background The crossbar interconnection network was first applied to the telephone system as a non-blocking switch system in the 1930 's . As the telephone system grew , the network 's size caused it to become infeasible with prevailing technology . This lead to more complex non-blocking systems which employed fewer switches and less space -LSB- C53 -RSB- . Advances in integrated circuit and VLSI technology are once again allowing the crossbar network to be a feasible interconnection network . Of particular interest is the work of Choi and Adams -LSB- CA92 -RSB- where they showed that a 256 % 256 crossbar network can be implemented on a chip of 1cm2 using current CMOS VLSI technology , with each input/output line running at 100 Mbps . This circuit definitely has potential for multiprocessor systems . Additional works focusing on the potential of actual construction of the system serve to establish a firm foundation for a crossbar based multiprocessor architecture -LSB- CL88 , G84 , GV90 -RSB- . For other variations of the cross bar network the reader is referred to -LSB- LVA82 , VC92 , W92 -RSB- . The model to be presented here considers the crossbar network as a system of global buses that provide a powerful enhancement to a linear array of processing elements . We depart from the models noted above in that we do not view the crossbar network as a point-to-point communication system . In our model , a processing element will place a value at a precise location in the communication network , normally based on its own ID . Other processing elements will read values from buses in the network . Under this model , the sender is not concerned with the receiver -LRB- s -RRB- and the receiver -LRB- s -RRB- are not concerned with the sender . This allows the communication system to become a participating portion of many computations . It also removes the need for a message routing system and related costs . This specific utilization of the crossbar interconnection network was first detailed in -LSB- L92 -RSB- . An examination of the current technology which supports the feasibility of the model may be found in -LSB- L92a -RSB- . For completeness the following explanation of the model is provided . 2.2 Our Computational Model We shall now formally define the ELAGB model . We begin with a linear array of n processing elements -LRB- PEs -RRB- . Each processing element is connected to a vertical bus -LRB- VB -RRB- , thus PEi connects to VBi . Each vertical bus has n horizontal buses connected to it by n interconnection points . Figure 1 is an example of an n processing element version of this architecture . The interconnection point at the intersection of VBi and HBj -LRB- 1 ? i ? n -RRB- , -LRB- 1 ? j ? n -RRB- , referred to as IPi , j , can only set or break the connection between VBi and HBj . Figure 1 . The Enhanced Linear Array with Global Buses Thus , we propose a linear array of processing elements communicating via a crossbar network . For clarity and to better reflect the functioning of the system , we refer to this model as the enhanced linear array with global buses or ELAGB . This is directly derived from the ability to dynamically communicate to suit computational needs . Since multiple buses may be utilized at any step , the bus delay , d -LRB- n -RRB- , caused by the length of both the horizontal and vertical buses must be considered to be that of the longest path in all cases . Following from the experience with YUPPIE -LSB- ML89 -RSB- , we consider d -LRB- n -RRB- to be a constant for the purposes of this work . Additional details of the model may be found in -LSB- L92 , L92a -RSB- . 3 . PRAM Simulation 3.1 CREW-PRAMs The CREW-PRAM model permits multiple processors to concurrently read a memory location , but only one processor may write to a particular memory location at any one time . For further reference a CREW -LRB- n , m -RRB- will designate a CREW-PRAM with n processors and m memory locations . The processors and memory locations will be denoted as P1 , P2 , ... Pn and M1 , M2 , Mm respectively . An ELAGB -LRB- n , b -RRB- will refer to an enhanced linear array with global buses with n processing elements and b horizontal buses . The processing elements and horizontal buses will be denoted as PE1 , PE2 , ... , PEn and HB1 , HB2 , ... , HBb , respectively . We now consider a problem P which requires O -LRB- t -RRB- time on a CREW -LRB- n , m -RRB- . In our simulation scheme , we begin with an ELAGB -LRB- n + m , n + m -RRB- . Therefore , every processing element PEi -LRB- 1 9 i 9 n -RRB- of the ELAGB is responsible for simulating the actions of Pi -LRB- 1 9 i 9 n -RRB- . For this purpose , we assume without loss of generality that any arithmetic/logical operation that Pi caries out in unit time can be carried out in unit time by PEi . When Pi -LRB- 1 9 i 9 n -RRB- writes to Mj -LRB- 1 9 i 9 m -RRB- , PEi accomplishes the write by placing the value to be written onto HBj + n and PEj + n then writes the value to its memory . No collisions occur because of the exclusive write constraint of the PRAM model , thus all processing elements can write to a horizontal bus and then accomplish the store in parallel . Similarly , to accomplish a read operation , each processing element places the value in its memory onto its own horizontal bus , then any number of processing elements can read any horizontal bus . Thus the ELAGB with n + m processing elements solves problem P in O -LRB- t -RRB- steps . In fact , we can do slightly better . Only max -LRB- n , m -RRB- processing elements are needed . Since each processing element can maintain its own local memory , the first m processing elements are responsible to service the m memory locations . While the first n processing elements will function as the n processors of the CREW-PRAM . This allows reads and writes to be more straightforward . When Pi writes to Mj , PEi accomplishes the write by placing the value to be written onto HBj and PEj then writes the value to its memory . We have shown the following result : Theorem 1 . Any problem P which a CREW -LRB- n , m -RRB- can solve in O -LRB- t -RRB- time , the ELAGB -LRB- max -LRB- n , m -RRB- , max -LRB- n , m -RRB- -RRB- can also solve in O -LRB- t -RRB- time . ? It must be noted that the simulation result of Theorem 1 is perfectly general . However , in practice it is only useful for m?O -LRB- n -RRB- . As it turns out , the vast majority of CREW-PRAM algorithms satisfies this property . 3.2 CRCW-PRAMs The CRCW-PRAM model allows multiple processors to either read or write to a single memory location . While multiple processors reading the same memory location cause no algorithmic difficulty , multiple processors writing to a single location require a specific contention resolution method . A number of resolution methods have been proposed , including : ? allow the processor with the minimum -LRB- maximum -RRB- identification number to succeed ; ? allow the processor holding the minimum -LRB- maximum -RRB- value to succeed ; ? allow any processor to succeed randomly ; ? allow any processor to succeed only if all processors are trying to write the same value , otherwise the result is undetermined . We adopt the latter resolution method , which is often referred to as Common Concurrent Write . While all methods are interesting in their own right , this method lends itself best to the enhanced linear array with global buses . The first two methods require some type of additional consideration to arrive at the maximum -LRB- minimum -RRB- decision . This implies some degree of extra overhead which we desire to avoid . We now utilize a stronger version of the ELAGB model . This model allows concurrent writes to the same horizontal bus , just as the Common CRCW allows simultaneous writes . The bus structure allows use of the same common contention resolution method that we are assuming for the CRCW model . For clarity purposes , we will refer to this version of the ELAGB as the Common ELAGB . Consider a problem P which requires t steps on a common CRCW-PRAM with n processors and m memory locations . These steps will fall in to one of the following categories : 1 . Pi accomplishes some arithmetic or logical operation , i ? -LCB- 1 ... n -RCB- ; 2 . Pi reads from Mj , i ? -LCB- 1 ... n -RCB- , j ? -LCB- 1 ... m -RCB- ; 3 . Pi writes to Mj , i ? -LCB- 1 ... n -RCB- , j ? -LCB- 1 ... m -RCB- . A processing element of a Common ELAGB can perform any arithmetic or logical operation just as the common CRCW . For PEi to read Mj two steps are required to occur : 1 . PEj places the value it holds on HBj ; 2 . PEi reads HBj . A processor PEi will write to Mj in a similar manner : 1 . PEi places the value to be written onto HBj ; 2 . PEj reads HBj and stores the value . The read and write operations detailed above , again show how a single processing element accomplishes the task , but do not directly address how concurrency affects the model . Concurrent reads are accomplished in a straightforward manner , and as noted above any number of processing elements can read from the same horizontal bus . Recall the concurrent write resolution method , if a subset of the processing elements attempt to write to Mj , the write only succeeds if all processing elements attempt to write the same value , otherwise an undetermined result occurs . Concurrent write on the ELAGB is accomplished in a similar manner to the concurrent read , in that , all processing elements which want to write to Mj place the value to be written onto HBj . Then PEj reads HBj and stores the value . If all processing elements did not place the same value on the horizontal bus , the stored result is undetermined . It should be obvious that if multiple values are placed on the same bus , a collision will occur . This collision will be destructive if different values have been placed on the same bus , thus causing an undetermined result . All that remains is to address the number of horizontal buses required to handle all communication without conflict and maintain all the power of the CRCW-PRAM . Since the CRCW - PRAM model employs communication through the shared memory , sufficient buses must be available to handle all memory accesses . Thus m horizontal buses will be required to fully model the CRCW-PRAM . We have shown the following result : Theorem 2 . A Common ELAGB -LRB- max -LRB- n , m -RRB- , max -LRB- n , m -RRB- -RRB- can solve a problem P in O -LRB- t -RRB- steps if the CRCW -LRB- n , m -RRB- solves P in O -LRB- t -RRB- steps . ? 4 . Conclusion The massive flexibility of communication in the enhanced linear array with global buses allows it to fully simulate any operation which the CREW-PRAM can accomplish in same time with the same number of processing elements . Conversely , any operation that the enhanced linear array with global buses can accomplish without allowing multiple processing elements to write to the same horizontal bus , the CREW-PRAM can accomplish in comparable time with a similar number of processors . As shown in -LSB- LO92 -RSB- this allows one to transfer known lower bounds for the CREW - PRAM to the ELAGB . While the results noted here employ a linear number of processing elements , the space required by the interconnection network must be addressed . It can be easily shown that any given interconnection point requires few transistors in comparison to a processing element -LSB- CL88 -RSB- . Thus while the enhanced linear array with global buses requires more space than a simple linear array , it will require considerably less physical space than a Parallel Array with Reconfigurable Bus System or PARBS which requires O -LRB- n2 -RRB- processing elements to accomplish efficient results . 5 . References -LSB- A89 -RSB- S. G. Akl . Design and Analysis of Parallel Computer Algorithms . Prentice-Hall , Inc. , 1989 . -LSB- ALG91 -RSB- S.G. Akl , L. Fava Lindon and G.R. Gunther , Broadcasting with selective reduction on an optimal PRAM circuit , Technique et Science Informatiques , vol 10 , No. 4 , 1991 , pp. 261 - 268 . -LSB- AHM87 -RSB- H. Alt , T. Hagerup , K. Mehlhorn and F.P. Preparata , Deterministic simulation of idealized parallel computers on more realistic ones , Siam Journal on Computing , 16 -LRB- 5 -RRB- , Oct. 87 , pp . 808-835 . -LSB- A88 -RSB- M. J. Atallah . On Multidimentional Arrays of Processors . IEEE Transactions on Computers , 37 -LRB- 10 -RRB- , October 1988 . -LSB- BBK68 -RSB- G.H. Barnes , R. Brown , M. Kato , D. Kuck , D. Slotnick , and R. Stokes . The ILLIAC IV computer . IEEE Transactions on Computers , C-17 , 1968 . -LSB- C53 -RSB- C. Clos , A study of non-blocking switching networks , The Bell System Technical Journal , Mar. 1953 , pp406-424 . -LSB- C90 -RSB- S.-K . Chen . n + Cube : The Extra-Dimensional n-Cube . 1990 International Conference on Parallel Processing -RSB- , pp 583 -- 584 , 1990 . -LSB- CCC90 -RSB- Y-C Chen , W-T Chen , G-H Chen , and J-P Sheu . Designing efficient parallel algorithms on mesh-connected computers with multiple broadcasting . IEEE Transactions on Parallel and Distributed Systems , 1 -LRB- 2 -RRB- , April 1990 . -LSB- CA92 -RSB- K. Choi and W.S. Adams , VLSI Implementation of a 256 x 256 Crossbar Interconnection Network . Proc . 6th Int ' l Parallel Processing Symposium , 1992 , pp. 289-293 . -LSB- CDR86 -RSB- S. A. Cook , C. Dwork , and R. Reischuck , Upper and lower time bounds for parallel random access machines without simultaneous writes . SIAM Journal on Computing , 15 , pp87-97 , 1986 . -LSB- CL88 -RSB- C. Chin and W. Lin . A massively Parallel Processing System Based on A Hyper-Crossbar Network . 2nd Symposium on the Frontiers of Massively Parallel Computation , pages 463 -- 466 , October 1988 . -LSB- DAP1 -RSB- Active Memory Technology , Irvine , Ca . DAP Series : FORTRAN-PLUS Language -LRB- man002 .03 -RRB- , 1988 . -LSB- DV87 -RSB- K. A. Doshi and P. J. Varman . Optimal graph algorithms on a fixed-size linear array . IEEE Transactions on Computers , C-36 -LRB- 4 -RRB- , April 1987 . -LSB- G84 -RSB- C. J. Georgiou , Fault-tolerant crosspoint switching networks , Proc . 14th Int ' l Symposium on Fault-Tolerant Computing , pp 240-245 , Jul. 1984 . -LSB- GV90 -RSB- J. Ghosh and A. Varma , Reliable design of multichip non-blocking crossbars , 1990 IEEE Int ' l Conf . on Computers and Processors , pp 70-73 , Sep. 1990 . -LSB- KY82 -RSB- A.V. Kulkarni and D.W.L. Yen . Systolic processing and an implementation for signal and image processing . IEEE Transactions on Computing , C-31 , October 1982 . -LSB- K84 -RSB- H.T. Kung . Systolic algorithms for the CMU WARP processor . in Proceedings of 7th International Conference on Pattern Recognition , July 1984 . -LSB- L81 -RSB- F.T. Leighton . New lower bound techniques for VLSI . Proceedings of 22nd Annual IEEE Symposium Foundations of Computer Science , October 1981 . -LSB- L83 -RSB- F.T. Leighton . Parallel computation using meshes of trees . Proceedings 1983 international workshop on graph theoretic concepts in Computer Science -RSB- , 1983 . -LSB- L92 -RSB- P.J. Looges , High Performance Issues on Parallel Architectures , Doctoral Dissertation , Old Dominion University , Aug. 1992 . -LSB- L92a -RSB- P.J. Looges , Application of the Crossbar Interconnection Network to Multiprocessor Communication , Old Dominion University Technical Report # 92-25 , Oct. 1992 . -LSB- LO92 -RSB- P.J. Looges and S. Olariu , Lower Bounds for the Enhanced Linear Array with Global Buses , Old Dominion University Technical Report # 92-20 , Nov. 1992 . -LSB- LM89 -RSB- H. Li and M. Maresca . Polymorphic-torus network . IEEE Transactions on Computers , 38 -LRB- 9 -RRB- , September 1989 . -LSB- LVA82 -RSB- T. Lang , M. Valero and I. Alegre , Bandwidth of crossbar and multiple bus connections for multiprocessors . IEEE Transactions on Computers , vol . C-31 , pp. 1227-1234 , Dec. 1982 . -LSB- ML89 -RSB- M. Maresca and H. Li . Connection autonomy in SIMD computers : A VLSI implementation . Journal of Parallel and Distributed Computing , 7 , 1989 , pp 302-320 . -LSB- NMB83 -RSB- D. Nath , S.N. Maheshwari , and C.P. Bhatt . Efficient VLSI networks for parallel processing based on orthagonal trees . IEEE Transactions on Computing , C-32 , June 1983 . -LSB- NCUBE -RSB- nCUBE , Beaverton , Oregon . nCUBE 2 Supercomputers : Systems Technical Overview , 1990 . -LSB- PR87 -RSB- V.K. P. Kumar and C.S. Raghavendra . Array processor with multiple broadcasting . Journal of Parallel and Distributed Computing , 4 , 1987 . -LSB- R87 -RSB- A.G. Ranade , How to emulate shared memory , Proc . of 28th annual Symposium on Foundation of Computer Science , Oct. 1987 , pp185-194 . -LSB- RV83 -RSB- I.V. Ramakrishnan and P.J. Varman . Modular matrix multiplication on a linear array . IEEE Transactions on Computing , C-32 , October 1983 . -LSB- S84 -RSB- C.L. Seitz . Concurrent VLSI architectures . IEEE Transactions on Computing , C-33 , December 1984 . -LSB- S71 -RSB- H.S. Stone . Parallel processing with the perfect shuffle . IEEE Transactions on Computing , C-20 , Feburary 1971 . -LSB- VB81 -RSB- L.G. Valiant and G.J. Brebner . Univeral schemes for parallel computation . Proceedings of 13 ACM Symposium of Theory of computing 1981 . -LSB- VC92 -RSB- A. Varma and S. Chalasani . Fault-tolerance analysis of one-sided crosspoint switching networks . IEEE Transactions on Computers , vol . 41 , pp. 143-158 , Feb. 1992 . -LSB- W92 -RSB- B. Wilkinson , On crossbar switch and multiple bus interconnection networks with overlapping connectivity . IEEE Transactions on Computers , vol . 41 , pp. 738-746 , Jun. 1992 .

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 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 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 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 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 B O O O O O O O O O O B 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 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 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 B 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 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 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 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 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 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 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 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 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 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 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 B 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 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 B I 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 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 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

crossbar
parallel algorithms
parallel architectures
shared memory model
simulation


Extracting

Determinacy

in

Logic

Programs

Steven

Dawson

C.R.

Ramakrishnan

I.V.

Ramakrishnan

Department

of

Computer

Science

SUNY

at

Stony

Brook

Stony

Brook

NY

R.

C.

Sekar

Bellcore

South

Street

Morristown

NJ

E-mail

fsdawson

cram

ramg@cs.sunysb.edu,

sekar@thumper.bellcore.com

Abstract

Unnecessary

backtracking

is

a

principal

source

of

inefficiency

in

Prolog

execution

In

order

to

avoid

the

overhead

of

the

general

backtracking

mechanism

determinate

programs

should

be

executed

deterministically

Achieving

this

requires

an

automatic

means

of

extracting

determinacy

We

present

a

method

in

which

determinacy

is

inferred

from

the

success

conditions

and

the

calling

contexts

of

predicates

Unlike

previous

approaches

that

rely

on

cuts

or

use

a

limited

notion

of

test

predicates

we

propagate

the

conditions

to

detect

determinacy

enabling

us

to

handle

a

much

larger

class

of

programs

Since

the

conditions

are

propagated

explicitly

the

power

of

the

method

can

be

readily

increased

by

increasing

the

expressiveness

of

these

conditions

Moreover

our

approach

provides

a

uniform

treatment

of

calling

contexts

and

success

conditions

and

clearly

spells

out

their

roles

in

inferring

determinacy

We

also

describe

how

determinacy

information

can

be

combined

with

state-of-the-art

indexing

techniques

to

efficiently

realize

the

benefits

of

determinism

Introduction

The

exploitation

of

determinacy

in

logic

programs

has

been

a

major

focus

of

efforts

to

increase

the

efficiency

of

Prolog

execution

A

primary

source

of

inefficiency

in

Prolog

is

unnecessary

backtracking

Though

the

general

backtracking

mechanism

is

useful

to

programs

that

require

it

it

incurs

too

much

overhead

for

programs

that

essentially

compute

functions

Introducing

cuts

reduces

this

overhead

but

cut

is

non-declarative

and

merely

removes

choice

points

that

were

unnecessary

in

the

first

place

An

automatic

means

of

exploiting

determinacy

is

an

ideal

way

to

reduce

backtracking

while

preserving

the

declarative

nature

of

Prolog

Such

an

automatic

mechanism

must

-LRB-

-RRB-

detect

determinacy

of

predicates

i.e.

identify

places

in

the

program

where

backtracking

is

unnecessary

and

-LRB-

-RRB-

prevent

placement

of

choice

points

at

these

places

This

paper

presents

a

method

that

detects

determinacy

and

makes

this

determinacy

explicit

for

the

compiler

Many

approaches

to

exploiting

determinacy

rely

on

the

presence

of

cuts

-LSB-

-RSB-

Others

-LSB-

-RSB-

use

a

limited

notion

of

test

predicates

and

furthermore

do

not

propagate

determinacy

information

Hence

they

are

unable

to

extract

hidden

or

latent

determinacy

Sato

and

Tamaki

-LSB-

-RSB-

addressed

a

notion

of

determinacy

similar

to

ours

and

described

a

technique

for

detecting

it

Their

method

propagates

determinacy

information

implicitly

and

deals

only

with

programs

where

determinacy

arises

from

a

restricted

form

of

structural

equality

They

did

not

address

classes

of

programs

where

determinacy

arises

from

other

sources

for

instance

inequalities

or

arithmetic

constraints

In

contrast

the

method

we

present

here

can

handle

such

programs

and

can

be

further

generalized

We

compare

our

method

to

related

work

in

greater

detail

in

Section

Overview

of

the

method

A

natural

way

to

infer

determinacy

of

a

predicate

is

to

determine

the

conditions

under

which

its

clauses

are

satisfied

If

the

conditions

associated

with

the

clauses

of

a

predicate

are

mutually

exclusive

then

we

can

conclude

that

the

predicate

is

determinate

Hence

these

conditions

should

be

expressed

in

a

form

that

can

be

readily

tested

for

mutual

exclusion

The

conditions

for

success

of

clauses

can

be

inferred

from

those

for

the

predicates

used

in

the

clause

In

addition

to

conditions

for

success

of

a

predicate

its

calling

context

i.e.

the

conditions

under

which

it

is

called

is

important

for

detecting

determinacy

Calling

context

is

useful

in

identifying

determinacy

when

a

program

uses

a

nondeterminate

predicate

in

a

restricted

way

such

that

its

evaluation

is

deterministic

In

our

method

we

analyze

the

program

to

infer

success

conditions

and

calling

context

of

a

predicate

Success

information

originates

from

facts

and

base

predicates

and

percolates

up

whereas

context

information

flows

down

from

the

top

As

it

turns

out

we

can

define

new

predicates

such

that

success

conditions

of

these

predicates

correspond

to

the

calling

context

of

the

original

predicates

With

this

transformation

we

obtain

both

types

of

conditions

through

a

single

analysis

Our

approach

is

to

represent

success

conditions

of

a

predicate

by

constraints

on

its

arguments

The

constraints

for

each

predicate

can

be

inferred

from

those

on

the

predicates

used

in

its

definition

We

initially

define

sound

constraints

on

predefined

predicates

and

propagate

them

bottom

up

using

a

sound

inference

technique

Greater

accuracy

in

detecting

determinacy

requires

stronger

constraints

At

the

same

time

the

set

of

constraints

should

be

manageably

small

for

efficient

analysis

Hence

we

need

to

handle

constraints

with

considerable

expressive

power

For

instance

rather

than

representing

only

the

range

of

values

each

variable

can

take

constraints

should

be

able

to

express

relationships

among

variables

Abstract

interpretation

approaches

-LRB-

such

as

-LSB-

-RSB-

-RRB-

do

not

represent

such

relationships

explicitly

and

thus

do

not

directly

accommodate

our

formulation

As

mentioned

above

we

derive

necessary

conditions

for

success

of

a

rule

from

the

success

and

context

conditions

of

predicates

used

in

that

rule

With

an

appropriate

indexing

scheme

these

conditions

can

be

tested

and

the

unsuccessful

branches

can

be

pruned

thus

reducing

backtracking

Such

testing

and

clause

selection

can

be

performed

efficiently

using

powerful

indexing

techniques

developed

recently

-LSB-

-RSB-

enabling

determinate

programs

to

be

evaluated

without

the

overhead

of

backtracking

The

main

contributions

of

the

present

work

are

ffl

a

general

method

to

identify

determinacy

ffl

a

uniform

analysis

that

reveals

the

interaction

between

top-down

and

bottom-up

information

needed

to

detect

determinacy

ffl

a

practical

means

for

exploiting

determinacy

Organization

The

rest

of

the

paper

is

organized

as

follows

In

Section

determinacy

analysis

is

described

in

terms

of

a

program

transformation

and

success

condition

analysis

The

latter

is

presented

in

Section

Section

illustrates

the

generality

of

the

method

by

its

applications

to

programs

requiring

more

than

simple

structural

constraints

for

extraction

of

determinacy

Section

describes

how

the

results

of

the

analysis

can

be

used

in

conjunction

with

indexing

techniques

to

increase

determinism

Section

discusses

the

relationship

to

other

work

and

concluding

remarks

appear

in

Section

Determinacy

Analysis

Determinacy

analysis

consists

of

obtaining

success

conditions

and

calling

contexts

of

predicates

and

using

them

to

derive

a

necessary

condition

for

each

clause

in

the

program

We

define

a

transformation

that

reduces

the

problem

of

finding

calling

contexts

to

finding

success

conditions

in

the

transformed

rules

Success

conditions

can

be

derived

using

the

method

developed

in

Section

We

establish

the

soundness

of

the

analysis

method

assuming

that

the

success

conditions

are

sound

Notation

The

symbols

of

our

language

are

drawn

from

three

mutually

exclusive

sets

variables

denoted

by

X

Y

Z

function

symbols

denoted

by

a

b

c

predicate

symbols

denoted

by

p

q

r

s

The

symbols

may

appear

with

or

without

subscripts

Constants

are

function

symbols

For

convenience

we

use

the

standard

notation

for

lists

-LSB-

H

jT

-RSB-

for

a

list

with

head

H

and

tail

T

and

-LSB-

-RSB-

for

the

empty

list

A

term

is

a

variable

constant

unknown

-LRB-

-RRB-

or

a

compound

term

a

-LRB-

tn

-RRB-

where

a

is

a

n-ary

function

symbol

and

each

ti

is

a

term

Lists

of

variables

are

denoted

by

symbols

X

Y

Z

A

program

is

denoted

by

symbols

P

P

Q

etc.

Each

clause

in

a

program

is

of

the

form

p

-LRB-

X

-RRB-

-LRB-

-RRB-

qn

-LRB-

Xn

-RRB-

Note

that

this

form

does

not

restrict

the

set

of

programs

we

consider

since

all

programs

can

be

readily

transformed

into

this

form

We

consider

purely

declarative

negation-free

programs

without

control

features

-LRB-

such

as

cut

-RRB-

or

side

effects

In

the

following

discussion

clauses

are

labeled

by

symbols

such

as

-LRB-

-RRB-

-LRB-

-RRB-

etc.

the

labels

themselves

are

not

a

part

of

the

program

Preliminaries

To

illustrate

how

success

conditions

and

calling

contexts

are

used

in

inferring

determinacy

we

consider

the

following

clause

-LRB-

-RRB-

p

-LRB-

X

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

Let

-LRB-

-RRB-

be

some

necessary

condition

for

success

of

-LRB-

-RRB-

Then

the

clause

-LRB-

-RRB-

p

-LRB-

X

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

is

-LRB-

logically

-RRB-

equivalent

to

clause

Corresponding

necessary

conditions

for

other

predicates

on

the

rhs

-LRB-

e.g.

-RRB-

can

be

introduced

similarly

Evaluating

p

through

clause

-LRB-

-RRB-

places

fewer

calls

to

than

evaluating

p

through

-LRB-

-RRB-

Let

p

be

a

property

of

predicate

p

such

that

p

-LRB-

X

-RRB-

is

true

whenever

p

-LRB-

X

-RRB-

is

called

all

possible

calling

contexts

of

p

are

represented

in

p

Then

the

clause

-LRB-

-RRB-

p

-LRB-

X

-RRB-

p

-LRB-

X

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

is

also

equivalent

to

clause

If

the

newly

introduced

goals

are

simple

conditions

on

the

arguments

these

tests

can

be

moved

to

the

head

of

the

clause

When

the

necessary

conditions

are

strong

enough

many

of

the

calls

-LRB-

that

would

have

otherwise

resulted

in

failure

-RRB-

to

the

original

predicates

on

the

rhs

are

avoided

increasing

determinism

at

run

time

Further

if

the

conditions

placed

on

the

clauses

of

a

predicate

are

non-unifiable

then

we

know

that

at

most

one

clause

is

applicable

when

the

input

is

Provided

that

the

conditions

are

simple

we

can

find

that

unique

clause

at

the

time

of

call

and

hence

not

only

avoid

backtracking

but

avoid

even

placing

choice

points

As

previously

mentioned

the

context

information

helps

in

clauses

that

are

not

determinate

in

themselves

but

are

used

in

the

program

in

a

restricted

way

such

that

they

become

determinate

For

instance

let

a

predicate

p

be

defined

by

two

rules

and

let

and

be

the

necessary

success

conditions

on

the

rhs

of

each

of

the

two

rules

If

and

are

non-unifiable

we

can

detect

that

p

is

determinate

whenever

the

input

is

ground

On

the

other

hand

let

and

unify

to

This

means

that

predicate

p

is

by

itself

nondeterminate

But

the

program

is

still

determinate

if

is

always

invalid

in

every

calling

context

of

p

i.e.

and

p

are

non-unifiable

Thus

we

can

vastly

increase

the

strength

of

our

method

to

estimate

determinacy

at

compile

time

by

use

of

both

success

and

context

information

We

first

describe

how

by

transforming

the

program

the

calling

contexts

can

be

obtained

from

success

information

of

the

transformed

program

The

method

for

deriving

success

information

is

described

in

Section

Both

success

and

call

information

can

thus

be

obtained

by

bottom-up

analysis

of

the

transformed

Derived

Program

From

a

given

program

P

we

obtain

a

derived

program

P

such

that

for

each

predicate

p

in

the

original

program

we

have

in

P

predicates

which

computes

a

necessary

condition

for

success

of

p

and

which

succeeds

whenever

p

is

called

from

a

clause

that

itself

succeeds

in

P

The

construction

of

P

from

P

is

formally

defined

below

ground

means

sufficiently

instantiated

to

enable

condition

testing

transformation

is

similar

in

spirit

to

the

Magic

transformation

in

the

sense

that

it

makes

top-down

information

amenable

to

bottom-up

interpretation

Definition

The

derived

program

from

P

denoted

by

P

is

the

smallest

program

such

that

For

each

user

callable

predicate

r

-LRB-

Y

-RRB-

in

P

-LRB-

Y

-RRB-

-LRB-

Y

-RRB-

is

a

clause

in

P

For

each

clause

of

the

form

p

-LRB-

X

-RRB-

-LRB-

-RRB-

qn

-LRB-

Xn

-RRB-

in

P

ffl

-LRB-

X

-RRB-

-LRB-

-RRB-

-LRB-

Xn

-RRB-

is

in

P

ffl

-LRB-

Xi

-RRB-

-LRB-

X

-RRB-

-LRB-

-RRB-

-LRB-

Xn

-RRB-

is

in

P

for

each

user-defined

predicate

qi

i

n

The

Prolog

program

in

Figure

is

a

parser

for

the

LL

-LRB-

-RRB-

language

-LRB-

aa

-RRB-

n

-LRB-

ab

-RRB-

n

n

The

corresponding

derived

program

is

given

in

Figure

p

-LRB-

-RRB-

-LSB-

-RSB-

s

-LRB-

-RRB-

s

-LRB-

-RRB-

-LSB-

a

a

-RSB-

q

-LRB-

-RRB-

s

-LRB-

-RRB-

q

-LRB-

-RRB-

s

-LRB-

-RRB-

r

-LRB-

-RRB-

r

-LRB-

-RRB-

-LSB-

a

b

-RSB-

Figure

Parser

for

a

simple

context-free

grammar

-LRB-

-RRB-

-LSB-

-RSB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LSB-

a

a

-RSB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LSB-

-RSB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LSB-

a

a

-RSB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LSB-

a

b

-RSB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

Figure

Derived

program

for

CFG

parser

Lemma

a.

Each

predicate

in

P

defines

a

necessary

condition

for

success

of

the

corresponding

predicate

p

in

P.

b.

Each

predicate

in

P

defines

a

condition

that

is

valid

whenever

p

is

called

from

a

clause

that

succeeds

in

P.

Proof

a

The

subset

of

clauses

in

P

that

define

for

each

p

in

P

is

nothing

but

what

we

obtain

by

renaming

each

p

by

in

P

Each

is

equivalent

to

p

and

hence

defines

the

necessary

-LRB-

and

sufficient

-RRB-

condition

for

success

of

p.

b.

Follows

directly

from

part

-LRB-

a

-RRB-

above

and

operational

semantics

of

Prolog

Determinacy

using

Success

Conditions

We

now

describe

a

sound

method

to

obtain

determinacy

information

from

success

conditions

and

calling

contexts

Recall

that

is

a

predicate

that

defines

a

necessary

condition

for

success

of

p

and

is

a

predicate

that

succeeds

whenever

p

is

called

from

a

successful

clause

Let

p

denote

a

constraint

on

the

variables

of

p

that

is

satisfied

whenever

p

succeeds

Hence

-LRB-

-RRB-

and

-LRB-

-RRB-

are

constraints

that

are

satisfied

whenever

p

succeeds

and

p

is

called

from

a

successful

context

respectively

Definition

-LRB-

Clause

Condition

-RRB-

Let

be

a

clause

of

the

form

p

-LRB-

X

-RRB-

-LRB-

-RRB-

qn

-LRB-

Xn

-RRB-

Then

the

clause

condition

of

is

the

condition

defined

as

-LRB-

-RRB-

-LRB-

ri

j

-LRB-

-RRB-

-RRB-

The

condition

defines

a

necessary

condition

that

succeeds

when

p

is

invoked

from

a

successful

context

That

is

if

is

not

satisfied

then

either

the

clause

fails

-LRB-

one

of

-LRB-

-RRB-

is

false

-RRB-

or

the

clause

from

which

p

was

invoked

in

the

first

place

fails

-LRB-

-LRB-

-RRB-

is

false

-RRB-

Hence

the

condition

can

be

tested

before

attempting

to

satisfy

the

clause

without

affecting

the

success

or

failure

of

the

program

This

is

stated

formally

as

follows

Lemma

Let

the

program

Q

be

derived

from

program

P

such

that

from

a

clause

in

P

of

the

form

p

-LRB-

X

-RRB-

-LRB-

-RRB-

qn

-LRB-

Xn

-RRB-

we

derive

the

following

clause

in

Q

p

-LRB-

X

-RRB-

-LRB-

-RRB-

qn

-LRB-

Xn

-RRB-

where

is

the

clause

condition

of

The

programs

P

and

Q

are

logically

equivalent

Since

clause

conditions

contain

only

tests

and

perform

no

unification

they

can

be

tested

before

the

corresponding

clauses

are

invoked

If

the

clause

conditions

of

a

predicate

are

pairwise

nonunifiable

then

we

can

conclude

that

the

predicate

is

determinate

when

the

input

arguments

are

ground

In

such

a

predicate

using

the

clause

conditions

we

can

select

the

unique

clause

that

is

applicable

at

each

call

to

the

predicate

This

selection

can

be

done

using

an

indexing

technique

and

is

described

in

Section

We

described

the

determinacy

analysis

assuming

that

success

conditions

for

predicates

can

be

inferred

Unfortunately

finding

the

strongest

success

condition

for

every

predicate

is

undecidable

since

this

reduces

directly

to

the

halting

problem

In

the

next

section

we

develop

an

analysis

technique

to

find

success

conditions

based

on

those

on

the

predefined

predicates

such

that

the

conditions

are

weak

enough

to

guarantee

termination

Success

Condition

Analysis

In

this

section

we

present

a

general

analysis

method

to

determine

necessary

conditions

for

satisfaction

of

each

predicate

in

the

program

For

each

predicate

p

in

the

program

the

analysis

determines

a

constraint

p

such

that

p

-LRB-

X

-RRB-

implies

p

-LRB-

X

-RRB-

When

there

is

no

ambiguity

p

is

used

in

place

of

p

-LRB-

X

-RRB-

For

purposes

of

description

we

first

consider

constraints

that

deal

with

structural

equality

alone

That

is

every

atom

of

the

constraint

is

of

the

form

-LRB-

X

t

-RRB-

where

X

is

a

variable

and

t

is

a

term

composed

only

of

uninterpreted

function

symbols

and

variables

We

later

show

how

we

can

generalize

the

analysis

by

enriching

the

form

of

constraints

for

instance

by

including

inequalities

Formally

the

set

of

all

constraints

we

consider

is

defined

as

the

smallest

set

such

that

True

and

F

alse

-LRB-

X

t

-RRB-

for

every

variable

X

and

every

term

t

in

the

program

OE

if

OE

OE

if

OE

Every

substitution

oe

satisfies

True

and

no

substitution

satisfies

F

alse

We

define

an

order

-RRB-

defined

on

such

that

OE

-RRB-

iff

for

every

substitution

oe

on

the

variables

of

OE

and

whenever

oe

satisfies

OE

it

also

satisfies

It

can

be

shown

that

h

-RRB-

i

is

a

lattice

with

F

alse

as

the

least

and

True

as

the

greatest

element

In

this

analysis

the

idea

is

to

associate

a

formula

p

with

each

predicate

p

in

the

program

such

that

p

represents

a

necessary

condition

for

success

of

p

We

formalize

the

notion

of

necessary

condition

as

follows

Definition

-LRB-

Necessary

Condition

-RRB-

A

formula

OE

-LRB-

X

-RRB-

is

a

necessary

condition

of

predicate

p

-LRB-

Y

-RRB-

if

for

every

substitution

oe

for

which

-LSB-

p

-LRB-

Y

-RRB-

-RSB-

oe

succeeds

the

formula

-LSB-

OE

-LRB-

X

-RRB-

-RSB-

oe

True

We

now

derive

equations

to

compute

p

for

each

predicate

p

The

only

predefined

predicate

is

the

equality

predicate

We

define

-LRB-

X

t

-RRB-

as

the

constraint

-LRB-

X

approxk

-LRB-

t

-RRB-

-RRB-

where

approxk

-LRB-

which

corresponds

to

the

depth-k

approximation

of

-LSB-

-RSB-

-RRB-

is

defined

as

-LRB-

t

-RRB-

approxi

-LRB-

X

-RRB-

X

approxi

-LRB-

a

-LRB-

tn

-RRB-

-RRB-

a

-LRB-

approxi

-LRB-

-RRB-

approxi

-LRB-

tn

-RRB-

-RRB-

Clearly

-LRB-

X

t

-RRB-

is

a

necessary

condition

for

success

of

-LRB-

X

t

-RRB-

A

user

defined

predicate

p

is

assumed

to

be

defined

clauses

of

the

following

form

-LRB-

X

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

pn

-LRB-

X

-RRB-

-LRB-

-RRB-

qnrn

-LRB-

Xnrn

-RRB-

-LRB-

-RRB-

Observe

that

p

succeeds

only

if

one

of

its

clauses

succeeds

and

a

clause

succeeds

only

if

each

of

the

goals

on

its

rhs

succeed

This

leads

to

the

following

rules

that

define

necessary

conditions

for

satisfaction

of

each

predicate

p

pj

SX

-LRB-

rj

k

-LRB-

qjk

-RRB-

-RRB-

p

n

j

pj

The

function

SX

simplifies

a

given

constraint

and

projects

those

that

involve

X

the

head

variables

of

p.

Note

that

in

the

degenerate

case

V

is

true

and

W

is

false

The

above

rules

can

be

directly

used

to

compute

p

if

p

is

nonrecursive

If

p

is

recursively

defined

then

p

is

computed

by

the

following

fix-point

iteration

procedure

p

F

alse

pj

i

SX

-LRB-

rj

k

-LRB-

qjk

-RRB-

i

-RRB-

p

i

n

j

pj

i

For

a

nonrecursive

predicate

q

-LRB-

and

hence

all

pre-defined

predicates

-RRB-

q

i

is

defined

to

be

q

for

all

i

For

a

recursive

predicate

p

the

limit

of

the

sequence

p

p

is

defined

to

be

p

The

simplification

function

SX

can

be

viewed

as

first

finding

the

canonical

form

for

a

formula

and

then

projecting

away

conditions

on

variables

not

in

X

A

formula

is

said

to

be

in

canonical

form

if

it

is

in

DNF

each

atom

is

of

the

form

-LRB-

X

t

-RRB-

and

each

disjunct

is

such

that

each

variable

is

in

a

sense

uniquely

and

maximally

defined

This

is

defined

formally

below

Definition

A

formula

OE

is

in

canonical

form

if

it

is

True

F

alse

or

OE

ni

where

OEi

rij

-LRB-

Xij

tij

-RRB-

and

No

OEi

is

subsumed

by

OEj

for

any

j

i.e

i

j

n

j

such

that

OEi

-LSB-

oe

-RSB-

-RRB-

OEj

-LSB-

oe

-RSB-

i

n

j

k

ri

Xij

is

not

in

tik

and

In

every

OEi

all

Xij

's

are

distinct

For

example

of

the

three

constraints

and

defined

as

-LRB-

-LRB-

X

-LSB-

-RSB-

-RRB-

-LRB-

Y

-LSB-

a

-RSB-

-RRB-

-RRB-

-LRB-

-LRB-

X

-LSB-

ajZ

-RSB-

-RRB-

-LRB-

Y

-LSB-

bjZ

-RSB-

-RRB-

-RRB-

-LRB-

-LRB-

X

-LSB-

-RSB-

-RRB-

-LRB-

Y

-LSB-

ajX

-RSB-

-RRB-

-RRB-

-LRB-

-LRB-

X

-LSB-

ajZ

-RSB-

-RRB-

-LRB-

Y

-LSB-

bjZ

-RSB-

-RRB-

-RRB-

-LRB-

-LRB-

X

-LSB-

a

-RSB-

-RRB-

-LRB-

Y

-LSB-

b

-RSB-

-RRB-

-RRB-

-LRB-

-LRB-

X

-LSB-

ajZ

-RSB-

-RRB-

-LRB-

Y

-LSB-

bjZ

-RSB-

-RRB-

-RRB-

is

in

canonical

form

is

not

in

canonical

form

due

to

rule

rule

is

also

not

in

canonical

form

since

the

second

disjunct

subsumes

the

first

It

can

be

shown

that

for

each

formula

OE

there

is

a

unique

canonical

form

C

-LRB-

y

-RRB-

such

that

y

C

-LRB-

y

-RRB-

C

-LRB-

y

-RRB-

is

known

as

the

canonical

form

of

y.

For

instance

is

the

canonical

form

for

Further

it

can

be

shown

that

there

is

an

effective

procedure

to

compute

the

canonical

form

Existence

and

computability

of

canonical

forms

mean

that

equality

checking

is

decidable

A

procedure

to

find

the

canonical

form

of

a

formula

can

be

based

on

unification

algorithms

-LSB-

-RSB-

First

we

compute

the

DNF

of

the

given

formula

Each

conjunction

in

this

formula

is

of

the

form

-LRB-

Yi

ti

-RRB-

We

use

the

unification

algorithms

to

compute

the

most

general

unifiers

of

the

equations

Yn

tn

The

substitutions

obtained

for

each

variable

Yn

as

well

as

those

obtained

for

variables

in

tn

are

simplified

as

follows

Let

t

be

the

substitution

obtained

for

a

variable

X

If

t

contains

a

variable

X

such

that

the

mgu

specifies

as

substitution

for

X

then

we

substitute

in

place

of

X

in

t

We

continue

this

process

until

t

contains

no

variable

for

which

a

-LRB-

nonvariable

-RRB-

substitution

is

given

by

the

mgu

It

is

easy

to

see

that

this

procedure

terminates

whenever

the

unification

algorithm

succeeds

Definition

The

function

S

is

defined

as

SY

-LRB-

OE

-RRB-

Y

-LRB-

C

-LRB-

OE

-RRB-

-RRB-

The

projection

function

is

defined

by

Y

-LRB-

n

i

OEi

-RRB-

n

i

-LRB-

Y

-LRB-

OEi

-RRB-

-RRB-

Y

-LRB-

m

j

-LRB-

X

ij

-RRB-

-RRB-

m

j

-LRB-

Y

-LRB-

X

ij

-RRB-

-RRB-

-RRB-

Y

-LRB-

X

ij

-RRB-

-RRB-

-LRB-

X

ij

Y

-LRB-

-RRB-

-RRB-

if

X

ij

Y

True

otherwise

Y

-LRB-

-RRB-

approxk

-LRB-

-RRB-

For

example

fXg

-LRB-

-RRB-

-LRB-

-LRB-

X

-LSB-

-RSB-

-RRB-

-LRB-

X

-LSB-

aj

-RSB-

-RRB-

-RRB-

We

state

without

proof

that

SY

-LRB-

OE

-RRB-

is

the

strongest

condition

that

OE

imposes

on

the

variables

in

Y

This

means

that

S

loses

no

information

Lemma

The

projection

function

has

the

following

properties

a.

is

monotonic

b.

OE

-RRB-

-LRB-

OE

-RRB-

c.

range

-LRB-

-RRB-

is

finite

Proof

-LRB-

Sketch

-RRB-

The

proofs

for

-LRB-

a

-RRB-

and

-LRB-

b

-RRB-

are

by

induction

on

the

construction

of

formula

OE

In

the

base

case

approxk

-LRB-

t

-RRB-

is

clearly

monotonic

and

size

decreasing

i.e.

t

-RRB-

approxk

-LRB-

t

-RRB-

The

rest

of

the

proof

follows

from

definition

of

-RRB-

over

formulae

For

-LRB-

c

-RRB-

due

to

the

third

rule

in

the

definition

of

the

range

of

is

made

of

formulae

such

that

the

terms

on

rhs

of

constraints

are

of

bounded

depth

It

can

be

seen

that

there

are

only

a

finite

number

of

terms

that

can

be

made

up

of

such

constraints

Hence

the

range

of

is

finite

Note

that

for

finiteness

we

need

to

limit

the

number

of

distinct

terms

t

This

can

be

accomplished

by

means

other

than

the

use

of

approxk

as

discussed

later

Since

S

is

defined

as

a

projection

of

the

canonical

form

of

a

formula

and

since

taking

the

canonical

form

is

lossless

the

following

corollary

results

Corollary

The

simplification

function

S

has

the

following

properties

a.

S

is

monotonic

b.

OE

-RRB-

S

-LRB-

OE

-RRB-

c.

range

-LRB-

S

-RRB-

is

finite

Termination

We

show

that

p

can

be

effectively

computed

for

every

predicate

p

The

formula

p

is

defined

using

and

S

and

the

fact

that

all

of

them

are

monotonic

means

that

the

sequence

p

p

is

a

monotonically

ascending

chain

The

range

of

S

is

finite

implies

that

the

above

chain

must

converge

after

a

finite

number

of

steps

Furthermore

since

equality

checking

in

is

decidable

we

can

detect

when

p

i

p

i

and

hence

effectively

compute

the

limit

of

the

chain

Lemma

For

every

predicate

p

in

the

program

p

i

-RRB-

p

i

Proof

The

proof

is

by

induction

on

i.

For

the

base

case

p

-RRB-

p

for

every

predicate

p.

For

nonrecursive

predicates

p

p

p

and

hence

p

-RRB-

p

For

recursive

predicates

p

F

alse

and

F

alse

-RRB-

OE

for

every

OE

Hence

p

-RRB-

p

For

the

induction

step

assume

that

p

i

-RRB-

p

i

for

all

i

m.

Let

l

denote

the

formula

Wnj

S

-LRB-

Vrjk

-LRB-

qjk

-RRB-

l

-RRB-

Note

that

m

is

obtained

from

m

by

replacing

q

m

by

q

m

Since

S

and

are

monotonic

in

and

q

m

-RRB-

q

m

-LRB-

by

induction

hypothesis

-RRB-

p

m

m

-RRB-

m

p

m.

Theorem

For

every

predicate

p

in

the

program

p

can

be

effectively

computed

Proof

The

range

of

S

is

finite

the

closure

of

a

finite

set

of

points

under

and

is

finite

Hence

the

chain

p

p

reaches

a

limit

after

a

finite

number

of

steps

Furthermore

since

equality

checking

in

is

decidable

we

can

compute

the

smallest

i

for

which

p

i

p

i

and

hence

effectively

compute

the

limit

Soundness

We

now

show

that

for

each

predicate

p

in

the

program

p

is

a

necessary

for

p

We

first

consider

only

nonrecursive

programs

Nonrecursive

Programs

Lemma

Let

p

be

a

predicate

as

defined

before

-LRB-

Equation

on

page

-RRB-

and

-LRB-

qjk

-RRB-

be

a

necessary

condition

for

each

qjk

Then

p

Wnj

S

-LRB-

Vrjk

-LRB-

qjk

-RRB-

-RRB-

is

a

necessary

condition

for

p.

Proof

-LRB-

Sketch

-RRB-

If

-LRB-

Y

-RRB-

and

-LRB-

Z

-RRB-

are

necessary

conditions

for

-LRB-

Y

-RRB-

and

-LRB-

Z

-RRB-

respectively

then

clearly

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

is

a

necessary

condition

for

the

goal

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

to

succeed

It

is

easy

to

see

that

Vrjk

qjk

-LRB-

Xjk

-RRB-

is

a

necessary

condition

for

the

goal

-LRB-

-RRB-

qjrj

-LRB-

Xjrj

-RRB-

From

OE

-RRB-

S

-LRB-

OE

-RRB-

S

-LRB-

OE

-RRB-

is

a

necessary

condition

for

OE

Hence

S

-LRB-

Vrjk

qjk

-LRB-

Xjk

-RRB-

-RRB-

is

a

necessary

condition

for

the

goal

-LRB-

-RRB-

qjrj

-LRB-

Xjrj

-RRB-

Furthermore

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

is

a

necessary

condition

for

the

goal

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

to

succeed

whenever

-LRB-

Y

-RRB-

and

-LRB-

Z

-RRB-

are

necessary

conditions

for

-LRB-

Y

-RRB-

and

-LRB-

Z

-RRB-

respectively

It

follows

that

Wnj

S

-LRB-

Vrjk

-LRB-

qjk

-RRB-

-RRB-

is

a

necessary

condition

for

predicate

p.

Theorem

For

each

predicate

p

in

a

nonrecursive

program

p

is

a

necessary

condition

for

p.

Proof

Since

the

program

is

nonrecursive

the

call

graph

is

a

dag

Let

the

predicates

be

assigned

a

level

number

lp

such

that

lp

for

each

base

predicate

p

i.e.

those

that

do

not

call

any

other

predicate

For

all

other

predicates

lp

i

if

max

-LRB-

lq

-RRB-

i

where

max

is

taken

over

all

predicates

q

called

by

p

The

theorem

is

proved

by

induction

on

level

number

Base

case

All

level

predicates

are

predefined

or

are

trivially

true

But

the

only

predefined

predicate

is

and

-LRB-

X

Y

-RRB-

defined

as

-LRB-

approxk

-LRB-

X

-RRB-

approxk

-LRB-

Y

-RRB-

-RRB-

is

clearly

a

sound

necessary

condition

for

satisfaction

of

-LRB-

X

Y

-RRB-

Induction

Step

Assume

that

q

is

a

necessary

condition

for

all

predicates

q

of

level

m.

For

a

level

m

predicate

say

p

all

calls

are

to

predicates

qj

such

that

lqj

m.

By

induction

hypothesis

qj

is

a

necessary

condition

for

each

qj

Hence

from

lemma

p

is

a

necessary

condition

for

p.

Recursive

Programs

Theorem

If

p

is

a

fix

point

for

p

then

p

is

a

necessary

condition

for

p.

Proof

Let

p

q

be

the

fix

points

for

p

q

For

each

predicate

p

define

as

follows

For

each

rule

that

defines

p

of

the

form

p

-LRB-

X

-RRB-

Body

define

-LRB-

X

-RRB-

p

-LRB-

Body

-RRB-

and

for

i

pi

-LRB-

X

-RRB-

i

-LRB-

Body

-RRB-

where

i

-LRB-

s

-RRB-

replaces

each

occurrence

of

any

predicate

symbol

q

in

s

by

qi

that

the

strongest

necessary

condition

corresponds

to

the

least

fix

point

Since

p

is

in

the

rhs

of

every

rule

for

p

is

a

necessary

condition

for

Note

that

pi

is

nonrecursive

for

i

By

taking

the

necessary

condition

for

as

p

-LRB-

which

is

certainly

safe

-RRB-

we

get

the

necessary

condition

for

as

p

since

p

is

a

fix

point

By

induction

we

obtain

p

as

a

necessary

condition

for

pi

for

all

i.

Now

it

is

easy

to

see

that

the

behavior

of

p

and

pi

is

identical

for

all

execution

sequences

of

length

i.

Given

any

execution

sequence

of

p

say

of

length

n

behavior

of

p

is

identical

to

that

of

pn

and

p

is

a

necessary

condition

for

pn

Hence

p

is

a

necessary

condition

for

p

Since

any

fix

point

is

seen

to

be

a

necessary

condition

the

following

corollary

results

Corollary

The

fix-point

iteration

procedure

correctly

computes

p

for

recursive

predicates

p.

An

Example

We

illustrate

the

analysis

method

through

the

example

program

in

Figure

using

a

abstraction

In

an

implementation

of

the

fix-point

computation

we

would

proceed

bottom-up

through

the

call

graph

computing

fix

points

for

the

strongly

connected

components

But

for

the

purposes

of

illustration

we

consider

the

fix-point

iterations

performed

over

the

whole

program

Note

that

q

false

for

every

predicate

q

in

the

derived

program

For

brevity

only

the

conditions

that

have

changed

at

each

iteration

are

given

The

fix

point

is

reached

after

the

tenth

iteration

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

b

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

b

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

-RSB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

a

b

j

-RSB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-LSB-

a

b

j

-RSB-

-RRB-

-LRB-

-LSB-

a

b

j

-RSB-

-LSB-

a

b

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

b

j

-RSB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

a

j

-RSB-

-LSB-

a

b

j

-RSB-

-RRB-

-LRB-

-LSB-

a

b

j

-RSB-

-LSB-

a

b

j

-RSB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

a

b

j

-RSB-

-LSB-

a

b

j

-RSB-

-RRB-

Generality

of

the

Method

The

extent

to

which

determinacy

is

revealed

depends

on

the

tightness

of

the

success

conditions

we

derive

These

in

turn

are

directly

dependent

on

the

conditions

we

associate

with

the

base

predicates

The

stronger

the

conditions

on

the

base

predicates

the

greater

is

the

power

of

the

method

In

order

to

utilize

these

stronger

conditions

the

inference

mechanism

should

lose

as

little

information

as

possible

Hence

by

strengthening

the

base

conditions

and

the

inferencing

mechanism

we

can

enlarge

the

class

of

programs

on

which

determinacy

can

be

inferred

by

our

method

p

-LRB-

-RRB-

-LSB-

-RSB-

s

-LRB-

-RRB-

s

-LRB-

-RRB-

append

-LRB-

-LSB-

a

-RSB-

-LSB-

a

-RSB-

-RRB-

append

-LRB-

-LSB-

a

-RSB-

-LSB-

b

-RSB-

-RRB-

s

-LRB-

-RRB-

s

-LRB-

-RRB-

append

-LRB-

-LSB-

c

-RSB-

-LSB-

a

-RSB-

-RRB-

append

-LRB-

-LSB-

c

-RSB-

-LSB-

b

-RSB-

-RRB-

s

-LRB-

-RRB-

s

-LRB-

-RRB-

append

-LRB-

-RRB-

-LSB-

-RSB-

append

-LRB-

-RRB-

-LSB-

-RSB-

-LSB-

-RSB-

append

-LRB-

-RRB-

Figure

Parser

for

a

context

sensitive

grammar

The

generality

of

the

method

is

illustrated

through

two

examples

in

which

depth-k

abstraction

reveals

no

determinacy

Proofs

of

soundness

and

termination

can

be

obtained

along

the

same

lines

as

those

presented

for

structural

equality

constraints

and

are

omitted

Parser

for

a

Context

Sensitive

Grammar

The

program

in

Figure

is

a

parser

for

the

language

fwwRbnanjw

-LRB-

a

c

-RRB-

n

n

g

We

analyze

this

program

using

a

generalization

of

the

structural

constraints

used

to

illustrate

the

method

in

Section

The

necessary

condition

for

equality

between

two

terms

is

that

the

labels

in

some

k

fixed

positions

in

the

terms

are

equal

By

fixed

we

mean

positions

that

are

defined

in

the

term

either

with

respect

to

the

root

or

its

rightmost

-LRB-

leftmost

-RRB-

leaf

Note

that

the

depth-k

abstraction

is

a

special

case

of

this

condition

In

the

discussion

that

follows

a

list

is

represented

as

-LSB-

-RSB-

where

bi

's

are

at

fixed

positions

relative

to

the

root

and

ei

's

are

fixed

relative

to

the

tail

We

omit

the

correctness

proofs

for

this

method

From

X

-LSB-

ajY

-RSB-

deriving

hd

-LRB-

X

-RRB-

a

is

a

weak

necessary

condition

Intuitively

we

can

obtain

stronger

necessary

conditions

from

the

fact

that

not

only

is

X

's

head

a

X

and

Y

have

the

same

last

element

The

above

abstraction

permits

us

to

represent

and

propagate

this

condition

The

derived

program

is

omitted

Of

particular

interest

to

the

analysis

of

this

program

are

the

necessary

conditions

for

-LRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-LRB-

-LSB-

-RSB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-LSB-

-RSB-

-RRB-

-RRB-

-LRB-

-LSB-

-RSB-

-LRB-

-LSB-

-RSB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-LSB-

-RSB-

-RRB-

-RRB-

It

is

with

this

stronger

condition

for

equality

that

we

can

derive

that

the

second

and

third

arguments

of

append

have

the

same

tail

and

hence

detect

determinacy

of

the

predicate

s

The

clause

conditions

obtained

for

the

three

rules

defining

s

are

-LRB-

-LSB-

a

a

-RSB-

-RRB-

-LRB-

-LRB-

-LSB-

a

b

-RSB-

-RRB-

-LRB-

-LSB-

c

b

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-RRB-

-LRB-

-LSB-

c

a

-RSB-

-RRB-

-LRB-

-LRB-

-LSB-

a

b

-RSB-

-RRB-

-LRB-

-LSB-

c

b

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-RRB-

-LRB-

-RRB-

-LRB-

-LRB-

-LSB-

a

b

-RSB-

-RRB-

-LRB-

-LSB-

c

b

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-RRB-

Clearly

the

three

conditions

are

mutually

exclusive

and

hence

we

conclude

that

the

predicate

s

is

determinate

Quicksort

That

the

power

of

our

method

is

not

limited

to

structural

equality

is

illustrated

through

this

example

We

show

how

arithmetic

conditions

can

be

handled

by

the

method

The

basic

idea

is

that

the

properties

of

arithmetic

operators

should

be

abstracted

as

a

finite

set

of

necessary

conditions

For

example

a

necessary

condition

for

X

Y

Z

is

that

-LRB-

-LRB-

Y

-RRB-

-LRB-

X

Z

-RRB-

-RRB-

Another

way

to

abstract

these

operators

is

to

define

them

precisely

up

to

a

certain

point

and

with

inequalities

beyond

that

ceiling

For

example

the

following

formula

defines

a

part

of

the

necessary

condition

for

X

Y

Z

when

arithmetic

is

interpreted

exactly

for

numbers

from

to

and

approximated

outside

this

range

-LRB-

-LRB-

-LRB-

Y

-RRB-

-LRB-

X

Z

-RRB-

-RRB-

-LRB-

-LRB-

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

-RRB-

-RRB-

-LRB-

X

-RRB-

-RRB-

-LRB-

-LRB-

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

-RRB-

-RRB-

-LRB-

X

-RRB-

-RRB-

-LRB-

-LRB-

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

-RRB-

-RRB-

-LRB-

X

-RRB-

-RRB-

-LRB-

-LRB-

-LRB-

Y

-RRB-

-LRB-

Z

-RRB-

-RRB-

-RRB-

-LRB-

X

-RRB-

-RRB-

-RRB-

It

is

clear

that

reasoning

with

such

formulae

is

tractable

It

should

be

noted

here

that

the

simplification

of

formulas

done

on

this

domain

can

be

considered

as

semantic

inference

whereas

the

simplification

in

the

case

of

structural

equality

was

defined

syntactically

The

Quicksort

program

fragment

in

Figure

employs

a

simple

sorting

routine

for

short

lists

This

technique

is

often

used

in

practice

to

improve

the

performance

of

Quicksort

Unfortunately

execution

of

this

program

would

result

in

the

placing

of

a

choice

point

for

each

call

to

quicksort

since

the

clause

that

applies

can

not

be

determined

until

after

a

call

to

length

Our

analysis

method

is

powerful

enough

to

infer

the

determinacy

of

quicksort

quicksort

-LRB-

-RRB-

length

-LRB-

-RRB-

simplesort

-LRB-

-RRB-

quicksort

-LRB-

-RRB-

-LSB-

-RSB-

length

-LRB-

-RRB-

-LSB-

-RSB-

partition

-LRB-

-RRB-

quicksort

-LRB-

-RRB-

quicksort

-LRB-

-RRB-

length

-LRB-

-RRB-

-LSB-

-RSB-

length

-LRB-

-RRB-

-LSB-

-RSB-

length

-LRB-

-RRB-

is

Figure

Quicksort

program

fragment

The

analysis

of

this

program

is

illustrated

using

a

approximation

combined

with

the

inference

rule

for

addition

noted

above

We

focus

here

on

the

computation

of

conditions

for

the

satisfaction

of

length

since

it

is

those

conditions

that

enable

the

program

to

be

recognized

as

determinate

The

success

condition

obtained

for

length

is

-LRB-

length

-RRB-

-LRB-

-RRB-

-LRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-RRB-

-LRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-RRB-

-LRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-RRB-

-LRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-RRB-

-RRB-

-LRB-

-LRB-

-LSB-

j

-RSB-

-RRB-

-LRB-

-RRB-

-RRB-

ffifl

fflfi

ffifl

fflfi

ffifl

ffl

ffifl

ffl

ffifl

ffl

OEAE

Oo

OEAE

Oo

-LSB-

j

-RSB-

-LRB-

-RRB-

a

-LRB-

-RRB-

b

-LRB-

-RRB-

a

-LRB-

-RRB-

chd

-LRB-

-RRB-

a

-LSB-

-RSB-

-LRB-

-RRB-

b

Figure

Discrimination

Net

for

the

CSG

parser

The

following

are

the

clause

conditions

obtained

for

quicksort

For

clarity

we

show

only

the

part

of

the

conditions

that

deals

with

since

these

are

the

conditions

that

lead

to

determinacy

-LRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-LRB-

-LSB-

-RSB-

-RRB-

-RRB-

-LRB-

-LSB-

j

-RSB-

-RRB-

From

Determinacy

to

Determinism

In

order

to

realize

the

practical

benefits

from

the

detected

determinacy

it

is

crucial

to

discriminate

among

the

clauses

of

a

predicate

based

on

the

clause

conditions

Techniques

have

been

recently

developed

-LSB-

-RSB-

that

can

index

clause

heads

based

on

all

the

information

appearing

in

the

head

We

can

therefore

build

a

discrimination

net

based

on

these

techniques

It

should

be

noted

that

these

conditions

may

involve

testing

variables

and

terms

that

are

not

ground

For

instance

a

clause

may

have

-LRB-

X

-LSB-

-RSB-

-RRB-

as

a

clause

condition

but

X

may

be

non-ground

at

the

time

of

call

The

indexing

technique

in

-LSB-

-RSB-

naturally

handles

non-ground

input

terms

Hence

mode

analysis

is

not

necessary

for

the

success

of

our

technique

but

is

useful

in

optimizing

the

indexing

code

The

discrimination

net

identifies

a

set

of

clauses

such

that

their

clause

conditions

are

satisfied

by

the

input

goal

The

smaller

the

set

the

fewer

the

unnecessary

backtracks

Clearly

when

the

set

has

only

one

clause

we

need

not

place

any

choice

points

Thus

not

only

do

we

avoid

backtracking

we

avoid

even

laying

down

choice

points

As

an

example

the

discrimination

net

for

the

predicate

s

in

Figure

is

given

in

Figure

For

clarity

we

have

shown

only

the

case

when

the

first

argument

of

s

is

ground

The

indexing

technique

enables

us

to

uniquely

pick

one

of

the

three

clauses

with

one

scan

of

the

goal

Note

that

the

testable

conditions

here

are

checking

the

last

element

-LRB-

-RRB-

the

first

element

-LRB-

-RRB-

and

emptiness

of

the

list

and

these

appear

as

primitives

in

our

discrimination

net

If

the

clause

conditions

contain

tests

that

are

not

present

as

primitives

in

the

indexing

scheme

the

conditions

are

weakened

to

those

that

the

indexing

scheme

can

handle

Hence

by

adding

more

expressive

primitives

to

the

indexing

scheme

the

full

power

of

our

method

can

be

exploited

Related

Work

Other

approaches

to

extracting

determinacy

in

logic

programs

have

been

described

by

Van

Roy

Demoen

and

Willems

-LSB-

-RSB-

Hickey

and

Mudambi

-LSB-

-RSB-

and

Zhou

Takagi

and

Ushijima

-LSB-

-RSB-

While

all

three

approaches

address

the

problem

of

avoiding

backtracking

when

predicates

are

determinate

the

class

of

programs

in

which

they

can

infer

determinacy

is

restricted

In

particular

of

these

methods

is

able

to

infer

determinacy

in

the

examples

we

give

due

to

the

lack

of

a

mechanism

for

propagating

determinacy

information

-LRB-

other

than

mode

information

-RRB-

Even

in

the

following

simple

example

which

is

based

on

one

in

-LSB-

-RSB-

the

ability

to

propagate

constraints

is

necessary

for

inferring

determinacy

p

-LRB-

X

Y

-RRB-

less

-LRB-

X

Y

-RRB-

q

-LRB-

X

Y

-RRB-

p

-LRB-

X

Y

-RRB-

geq

-LRB-

X

Y

-RRB-

r

-LRB-

X

Y

-RRB-

less

-LRB-

a

-LRB-

-RRB-

a

-LRB-

-RRB-

-RRB-

geq

-LRB-

a

-LRB-

-RRB-

a

-LRB-

-RRB-

-RRB-

In

contrast

to

the

above

approaches

our

method

of

propagating

constraints

makes

the

inference

of

p

's

determinacy

straightforward

The

method

proposed

by

Sato

and

Tamaki

-LSB-

-RSB-

does

propagate

information

leading

to

determinacy

detection

However

in

their

approach

propagation

is

implicit

Moreover

the

information

that

is

propagated

is

fixed

to

a

restricted

form

-LRB-

depth-k

-RRB-

of

structural

equality

between

terms

Thus

their

method

is

unable

to

detect

determinacy

in

the

CSG

and

Quicksort

programs

or

even

in

the

above

example

Their

approach

is

based

on

an

item-set

construction

similar

to

that

used

for

LR

parsers

and

it

is

not

clear

whether

this

method

can

be

adapted

to

propagate

more

general

types

of

constraints

Finally

we

note

that

a

method

involving

constraint

propagation

was

proposed

by

Srivastava

and

Ramakrishnan

-LSB-

-RSB-

for

optimization

of

constraint

query

languages

using

bottom-up

evaluation

The

constraints

that

are

propagated

are

arithmetic

constraints

explicit

in

the

program

However

the

notion

of

abstraction

that

is

crucial

for

termination

is

absent

from

their

approach

Conclusions

and

Future

Directions

We

have

presented

a

powerful

method

for

extracting

determinacy

in

logic

programs

The

method

is

general

in

that

the

class

of

programs

in

which

determinacy

is

inferred

can

be

easily

expanded

In

order

to

further

increase

the

scope

of

our

work

a

number

of

important

issues

must

be

addressed

We

need

to

investigate

how

our

method

extends

to

programs

that

use

negation

non-logical

features

-LRB-

such

as

var

tests

-RRB-

and

cuts

The

effect

of

operations

such

as

assert

and

retract

on

the

method

also

needs

to

be

explored

Since

the

strength

of

the

constraints

placed

on

base

predicates

determines

the

extent

to

which

determinacy

can

be

extracted

an

issue

of

practical

importance

is

the

choice

of

base

constraints

Thus

we

must

develop

heuristics

for

choosing

these

constraints

based

on

the

program

to

be

analyzed

Furthermore

since

the

propagation

of

strong

constraints

requires

a

strong

inference

mechanism

there

is

a

trade-off

between

the

effort

required

to

analyze

the

program

and

the

amount

of

determinacy

that

can

be

extracted

We

believe

that

an

implementation

of

our

method

that

addresses

the

above

issues

will

go

a

long

way

toward

making

the

execution

of

logic

programs

more

efficient

References

-LSB-

-RSB-

U.

Montanari

A.

Moartelli

An

efficient

unification

algorithm

ACM

TOPLAS

-LRB-

-RRB-

-LCB-

April

-LSB-

-RSB-

Maurice

Bruyhooghe

A

practical

framework

for

the

abstract

interpretation

of

logic

programs

Journal

of

Logic

Programming

-LCB-

-LSB-

-RSB-

Ta

Chen

I.

V.

Ramakrishnan

and

R.

Ramesh

Multistage

indexing

algorithms

for

speeding

Prolog

execution

In

Logic

Programming

Proceedings

of

the

Joint

International

Conference

and

Symposium

pages

-LCB-

-LSB-

-RSB-

Timothy

Hickey

and

Shyam

Mudambi

Global

compilation

of

Prolog

Journal

of

Logic

Programming

-LCB-

-LSB-

-RSB-

B.

Le

Charlier

K.

Musumbu

and

P.

Van

Hentenryck

A

generic

abstract

interpretation

algorithm

and

its

complexity

analysis

In

Logic

Programming

Proceedings

of

the

Eighth

International

Conference

pages

-LCB-

-LSB-

-RSB-

C.

S.

Mellish

Some

global

optimizations

for

a

Prolog

compiler

Journal

of

Logic

Programming

-LRB-

-RRB-

-LCB-

-LSB-

-RSB-

C.

S.

Mellish

Abstract

interpretation

of

Prolog

programs

In

S.

Abramski

and

C.

Hankin

editors

Abstract

Interpretation

of

Declarative

Languages

chapter

pages

-LCB-

Ellis

Horwood

-LSB-

-RSB-

M.

S.

Peterson

and

M.

N.

Wegman

Linear

Unification

Journal

of

Computer

System

Science

-LRB-

-RRB-

-LCB-

April

-LSB-

-RSB-

R.

Ramesh

Automata

Driven

Matching

and

Unification

PhD

thesis

SUNY

Stony

Brook

-LSB-

-RSB-

R.

Ramesh

I.

V.

Ramakrishnan

and

D.

S.

Warren

Automata-driven

indexing

of

Prolog

clauses

In

Seventh

ACM

Symposium

on

Principles

of

Programming

Languages

pages

-LCB-

-LSB-

-RSB-

Divesh

Srivastava

and

Raghu

Ramakrishnan

Pushing

constraint

selections

In

Eleventh

Principles

of

Database

Systems

pages

-LCB-

San

Diego

CA

June

ACM

-LSB-

-RSB-

Taisuke

Sato

and

Hisao

Tamaki

Enumeration

of

success

patterns

in

logic

programs

Theoretical

Computer

Science

-LCB-

-LSB-

-RSB-

H.

Sawamura

and

T.

Takeshima

Recursive

unsolvability

of

determinacy

solvable

cases

of

determinacy

and

their

applications

to

Prolog

optimization

In

Proceedings

of

the

Symposium

on

Logic

Programming

pages

-LCB-

IEEE

-LSB-

-RSB-

Peter

Van

Roy

Bart

Demoen

and

Yves

D.

Willems

Improving

the

execution

speed

of

compiled

Prolog

with

modes

clause

selection

and

determinism

In

Proceedings

of

TAPSOFT

pages

-LCB-

March

-LSB-

-RSB-

Neng-Fa

Zhou

Toshihisa

Takagi

and

Kazuo

Ushijima

A

matching

tree

oriented

abstract

machine

for

Prolog

In

Logic

Programming

Proceedings

of

the

Seventh

International

Conference

pages

-LCB-