281 108 26MB
English Pages 180 Year 1985
Waterloo BASIC. provides a modern programming
Waterloo'BAslC has been installed at hund eds of
environment with structured programming state
academic and corporate locations around the \l\forld
since 1980. WATCOM's comprehensive support
ments, long variable names, functions, and proce dures. Programming is further simplified by Waterloo
services for Waterloo BASIC include software main
BASIC's power, which includes commercial format
tenance, and our telephone Hotline, Newsletter,
ting, internal and file sorting, indexed files, and a full
and product bulletins. Our comprehensive text and
complement of string and matrix functions.
reference manual for student or general use makes Waterloo BASIC easy to use. Powerful, simple, complete. Waterloo BASIC is
Waterloo BASIC is an incremental compiler which
the right choice.
detects errors as lines are entered. Corrections can
With more than 200,000 licenses \MJrldwide, WATCOM is a leading developer of software tools. WATCOM means compilers and interpreters. Plus document composition and data management. All WATCOM products are engineered for optimum human efficiency and productMty. But we're more thanjust software. WATCOM's people have been on the leading edge of software research and development for more than t\MJ decades. Our commitment
r ;s,-;-�tto�k;-�ight;,�i�oftware.I I I I I
:
Send me more information on:
D Waterloo BASIC D WATCOM Software Catalogue.
Name: Company: 11tre:
us to produce software that meets your exacting require ments. And, our comprehensive support services and innovative licensing will help you get the most out of your software investment. Make the right choice. Call or write WATCOM today and we'll tell you all about our people-efficient products and services.
- - �ACM� II
,/°'
�������
/ /
to innCM1tion is a continuing tradition at WATCOM enabling
I
I I I I
:
I I Address: I I I a� I I State: I Zip: L-------------------�
/
//
I
/
••�.===. .===.
a=:=-=� ==
==-====-= -
------
The right choice In software.
WATCOM PRODUCTS INC. 415 Phillip Street Waterloo, Ontario, Canada N2L3X2
(519) 886-3700
Telex 06-955458
*IBM VM/SP CMS and MVS/TSO are registered trademarks of International Business Ma'chines Corporation.
I
MSD Bedford Laboratories
llu.l Quality People Make The Difference -
When you put a top-notch professional staff to work in one m i l lion square-foot, state-of-the-art fac i l ities, the end result is a distinguished, enviable record in technological breakthroughs and new-product devel opment. Raytheon's strong record of acco mplishment provides positive proof that our people continue to meet and exceed the complex demands of our cus tomers. Engineers and Computer Scientists working in our Software Laborat�ry are heavily involved in a variety of proiects, inc l uding com m and and contro l , missile guidance, real-time executive control , data collection/ reduction, s i m u l ation, signal processors, d iagnostics, software tools , UNIX;M CAD/CA M , CAD V SLI and sup port software development. Dlgltal Slmulatlon/Test (CAD) Mechanlcal CAD Analog Slmulatlon (CAD) Software Tools Development Systems Development (UNIX™) Diagnostic Appllcatlons Software Real· T ime Appllcatlons Software Appllcatlons Software Software Requirements Analysls Test DeslgnNalldatlon Communications Software Dlsplay and Command Software L200 Test Software Microcode Software Embedded Microprocessor Software UNIX'M is a registered trademark of Bell Labs.
Raytheon'sBedford Laboratories is located in one of suburban Boston's most desirable communities convenient to the city' s incomparable ed ucational, cultural and entertainment resources, as well as the innumerable four season, recreational activities of nearby New Hampshire, M aine, Vermont and Cape Cod. ABS degree in an engineering discipline is necessary. Both experienced engineers and recent college graduates will be considered. Raytheon offers an excellent salary/company-paid benefits program , including Investment Savings and Stock Ownership Plans. Please send resume with salary requirements to: Pat A. Gillis, Raytheon Company, Missile Systems Division, Hartwell Road , Bedford , MA 01730. An Equal Opportunity Employer. U . S . Citizenship required.
Quality Starts with Fundamentals
Raytheon
A-1
HOUSTON ASTROHALL MARCH 24-26, 1986
If it has anything to do with running an office or business more efficiently, OAC '86 will have it! Exhibitors and attendees have come to recognize OAC as the "one stop shopping center" for the latest and the best in the ever-widening scope of business automation and communication. For three days in March of '86, the Houston Astrohall will be converted to a giant melting pot with every business related product and service. A unique exhibit, "The Office of the Future" will demonstrate how various products and services can be integrated in one business situation, and will be coordinated with the Houston Design Center. "Integrated Systems: Merging Islands of Technology;• the theme of OAC '86, will focus on the tremendous growth and diversity of business automation and communication. The full Conference Program will include six major tracks of discussion: Microcomputers, Intercon nection, Strategic Islands, The Future, Management and Organization Issues. To learn about exhibiting at or attending OAC '86, send in the coupon below or call the OAC '86 hotline: 800-0AC-1986. I want to know more about OAC '86. Please send me: D Information on exhibiting at OAC '86. D Information on attending OAC '86. NAME: T I T LE : _____ COMPANY: _______ ADDRESS: CITY:
_________________ �
STATE:
__
ZIP:
�#a � �-----
1
9
MAIL TO: OAC '86, AFIPS, 1899 PRESTON WHITE DRIVE, RESTON, VA 22091
8
6
UF
COMMUNICATIONS OFTHEacm
l\(ol�!!f::I
The cover i l l u strat i o n . w h i ch i s b ased o n A l a i n Colmerauer's article i n t h i s i ssue. exem p l i fies Prolog's use of trees as i t s basic dat a struct ure. Jn Prolog a fact is represented by a tree draw n upsi de dow n . where each .. .. leaf and node i s l abeled w i t h an atom of i n format i on. Cover concept is by A ngel i c a Design .,..,....,.. Group an d i l l ustrat i o n by Jo A n n e Scri b n er.
A Publication of the Association for
Computing Machinery
December 1985
Volume 28
Number 12
ARTICLES 1296
Prolog in 10 Figures
Ala in Colmerauer
The theoretical model underlying logic progm111111i11g i11 Prolog is presented i11
1311
Describing Prolog by Its Interpretation and Compilation
l0 sequential figures.
Jacques Cohen
Cornpilation and interpretation in Prolog-posed i11 the context of their parallels i11 other languages-illustrate the advantages Prolog presents i11 the area of sy111bolic processing.
REPORTS 1326
Software Aspects of Strategic Defense Systems
David Lorge Parnas
A former member of an SDIO advisory panel explains why lze believes we can never be sure SDI software will work.
COMPUTING PRACTICES 1336
Data Compression on a Database System
Gordon V. Cormack
General data-cornpression and expansion routines added lo the IMS system demonstrate how a wide variety of data can be compressed using a single, fixed co111pression routine with almost no working storage.
RESEARCH CONTRIBUTIONS 1344
Selecting MIS Projects by Steering Committee
J. D. McKeen and Tor Guimaraes
Using a steering cornmillee lo approve MIS projects alters a very political process b11 changing the locus of authority and
often the personnel involved, resulting i11 a changed portfolio of projects.
DEPARTMENTS 1263
Authors
1361
Calls for Papers
1265
ACM President's Letter
1363
ACM News
1271
ACM Forum
1365
Report of the ACM Nominating Committee
1275
From Washington
1277
Annual Report of the Association for Computing Machinery
1366
General News and Notes
for the Period Ending June 30, 1985
1370
SIG Reference Guide
Abstracts from Other ACM Publications
1372
Algorithm Index for 1985
1355
Professional Activities
1373
CACM Index for 1985
1357
Calendar of Events
1353
on Candidates for the 1986 ACM Election
*Programming Pearls will return in January.
Submission Information
0 Yes 0
No.
-----Chapter Name
Show It! New or current ACMer? You're a member of the most prestigious computing society. . . show it1 Demonstrate you r pride in your ACM affiliation by ordering an ACM Membership Certificate, the handsome meta l l ic ACM Pioneer Poster Series- Blaise Pasca l , Ada Lovelace and Charles Babbage (who are pictured o n this ap plication )-as well as other accessories and gifts. Wri te headquarters: ACM, Att: Member Services, 11 West
42nd Street, New York, NY 10036, for ACM's "Show It Merchandise Flyer. "
On November 18 , 1985 , at SIGAda in Boston, ALSYS opened the doors to Ada . . . With Ada compilers for 15 computer models
Apollo Domain DN300, DN320, DN330, DN400, DN460, DN550, DN600, DN660. SUN Workstations 2/50, 2/100, 21120, 2/160, 2/170. Hewlett-Packard 9000, Series 200, 300.
With an Ada cross-compiler
DEC VAX 11/730, 11/750, 11/780, 11/785, and MicroVAX I Cross-Compiler to Altos ACS 68000 .
With Ada training products
You Know Fortran-Ada is Simple
(12 Lesson Computer-Aided Instruction for those
who know Fortran. ) Lessons o n Ada
With Ada programming tools
AdaQuery (Complete, searchable on-line Ada Language Refer ence Manual . ) AdaViewer (Unique viewing tool for Ada programmers . )
With more compilers in development
IBM-370 Compiler under development at Alsys Ltd . , U . K. Hewlett-Packard 1000 Series A900 Compiler under de velopment at Alsys Ltd ., U . K . IBM-PC/AT and IBM-PC/XT Compilers under develop ment at Alsys, I nc . , U . S .
(2-Volume, 27 lesson CAI course running on IBM PC and VAX. l Ichbiah, Barnes and Firth o n Ada (27 video tape overview of Ada by language designers . )
0 Ada is a registered trademark of the U.S. Government IAJPO I .
ACM Conference on the
J a n u ary 9- 1 0 , 1 986 Hyatt R i ckeys, Palo A lto , Cal iforn i a This i s the fi rst i n a series of ACM sponsored conferences foc u s i n g o n the " H istory of Computi n g . "
The H i story of Personal Workstations Conference w i l l expl ore the m aj o r events that
i nfluenced and led to one of the m ost fu nd amental aspects of modern computing - the p e r s o n a l workstatio n .
The Conference w i l l bring together, for the fi rst time, those pioneers i n the c o m puter field
whose vision and work shaped the con cepts beh i n d m odern personal workstations. The, H i story of Personal Workstations Conference i s being sponsored by the Associati o n for C o m p u t i n g Machin ery t h ro u g h its Pacif ic Reg i o n and hosted b y the Xerox Palo A l t o Research Center.
T h e C onference
will explore i m portant areas such as com puter networks, d istri buted com puti n g , spec i a l ized workstat i o n environments, and program m i n g environ ments that have shaped t h e h istory o f , and l e d t o , the m odern workstat i o n .
P i o neeri n g researchers i n these areas wi l l present the vision they had at the start of their
work, reflect o n the i m pact their work has had, and d i scuss the potential for i m pact i n the f u t u re . The History o f Personal Workstations Conference represents a u n i q u e opport u n ity t o u nd erstand the events that have led to m odern d istrib u ted computing and personal workstati ons.
Bri n g i n g together the architects
and pioneers of the fu nd amental i d eas beh ind m odern workstati o n s s h o u l d be a m e morable experience.
Advance Prog ram Th u r s d a y , J a n u a ry 9, 1 986
Banquet
Open ing Session 9:00- 1 0: 1 5
The D y n a book - P a s t , P re s e n t , a n d F u t u re Alan Kay
Welcome Willia m Sp encer
7:30-1 0:00
Apple Computer, Inc.
Xerox Palo Alto Research Center K e y note A d d ress G o rdon Bell
F ri d a y , J a n u a r y 1 0 , 1 9 8 6
Session 2
Pe rso n a l D i s t ri b u ted C o m p u t i n g : T h e A l to a n d Et h e rnet H a rd w a re Chuck Thacker
Encore Com puter Corp.
1 0:45- 1 1 :45
A Pe r s o n a l V i e w of Pe rs o n a l Wo rkstati o n s : Some F i rsts in the F i f t i e s Douglas Ross SofTech/MIT
Lunch
1 1 :45-1 :00
Session 3
1 :00-3:00
Some Ea r l y H i sto ry Seen f ro m a W a s h i n gton P o i n t of V i e w J , C , R , Lic klider M IT Laboratory for Computer Science The A rp a n et a n d Compute r Net w o rks Larry Roberts
Net Express
Session 4
3:30-5:30
T h e F i rst S c i e n t i f i c Wo rkstat i o n Glen Culler
C u l ler Scientific Systems Corp.
T h e A u g m e n ted K n o w l edge Wo r k s h o p D o u g Englebart
MacDonnell Doug las Reception
8
Sponsor:
6:00- 7:30
Session 5
8:30 - 1 0:30
Dig ital E q u i ptment Corp. Systems Research Center
P e rs o n a l D i st ri b u ted Co m p u t i n g : T h e A l to a n d Et h e rnet Softw a re Butler Lampson
D i g ital Equi ptment Corp. Systems Research Center
Session 6
1 1 :00- 1 2:00
The L I N C w a s Ea r l y a n d S m a l l Wesley Clark
Sutherland and Sproull Lunch
1 2:00- 1 :00
Session 7
1 :00-2:00
F ro m t h e H a n d C a l c ' u l ato r to t h e M o d e r n E n g i n e e r i n g Wo r k s t a t i o n Chuck House
Hewlett-Packard Session 8
2:30-4:30
A H i sto ry of t h e P ro m i s Te c h n o l o g y J a n Schultz
Promis I nformation Systems
U se r T e c h n o l o g,y - - F ro m P o i n t i n g to P o n d e ri n g Stuart Card and Thomas Moran
Xerox Palo Alto Research Center
ACM Pacific R e g i o n
Host: X e ro x Palo A l to
Research Center
Advance Reg istr:ation The advance registration fee for the conference i n c l udes a copy of the proceed i ngs, l u n c h e o n s o n T h u rsday and Friday, refreshments d u ri n g breaks, and the reception and banquet o n T h u rsday even i n g . Student registration fees d o not i n clude l u ncheons o r the banquet alth o u g h some tickets fodhese f u nctions may be available o n -site. O n -site registrations w i l l be accepted between 7:00- 1 0:00 p . m . o n Wednesday, J a n uary 8, 1 986 at the conference hotel and a l l day T h u rsday start i n g at 8:00 am. space i s l i m ited.
It s h o u l d be n oted , ,h owever, t h at m eeting
Therefore, a d va nce registration i s strongly rec o m m e n de d .
A d v a n ce Regist ration Form
Please make checks o r money orders payable ( i n U.S. cu rrency) t o ACM History o f Perso nal Workstations , Conference. Co mplete and return this form along with your payment to: ACM History of Personal Workstations Conference c/o Gloria Warner Xerox Palo Alto Research Center 3333 Coyote Hill Road Palo Alto, CA 94304
Advance Registration (Before December 1 5) $220 0 $260 0 $1 00 0
ACM Mem ber: Non-Member: Ful l-time Student:
A2
Late/On -Site Reg istration $280 0 $320 0 $ l 00 0
Name: ------ Aff i l i ation: Address: Phone:
-------
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
------
ACM Mem ber Nu m ber:
------
0 Do not include my name on the Conference mailing l ist (wh ich may be sold by ACM)
Hotel Reservations The ACM Conference o n the H istory of Personal Wo rkstations w i l l be held at Hyatt R i c keys, 421 9 El Cam i n o Real, Palo A lto, Californ i a 94306, Telephone: has been reserved for conference attendees. using the attached form .
41 5-493-8000, Telex:
334477.
A block of rooms
Pl ease make room reservati o n s p r i o r t o D e c e m b e r 8 t h by
If you co ntact the hotel by phone or Telex, mention that your reservat i o n is
associ ated with the ACM H istory of Perso nal Workstations Conference to receive the speci a l co nference rate.
Hotel R e s e rvation Fo rm ACM Conference on the History of Personal Workstations Return this form ( b efo re D e c e m b e r 8th) to: To g uarantee reservation for late arrival:
Hyatt Rickeys 421 9 El Camino Real Palo Alto, California 94306
0 check enclosed , or
Attn: Reservations
Name:
0 credit card
MC/Visa/ A mEx No. ------Exp, Date
-------
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Add ress:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Departure Date:
Arrival Date:
Ti me:
Single ($97 /night): 0
Double or Twin ($1 1 2/night): 0
____
Time:
_ _ _
Reservations held u ntil 6 p . m . unless payment guaranteed
General and Program Chair:
Conference Organ ization
Alan Perlis Computer Science Dept. Yale University 2 1 58 Yale Station New Haven , CT 06520
For more information contact the Local Arrang ements Chair:
John R. White Xerox P alo Alto Research Center 3333 Coyote Hill Road P alo Alto, CA 94304 (41 5) 494-4464
Here's one reason why you need more life insurance ... and three reasons why it should be our group insurance.
Family responsibilities increase and change-a new baby, a job change, a new home. Your family could have a lot to lose unless your insurance keeps pace with these changes. Now here's why you need our group term life insurance. First, it's low-cost. Unlike everything else, life rates have gone down over the past 20 years. And, because of our buying power, our group rates are low. Second, you will continue to receive this protection even if you change jobs, as long as you remain a member and pay the premiums when due. Third, our wide range of coverage allows you to choose the insurance that's right for you. And you can protect yourself and your enti re family. It's insurance as you need it. So check your current insurance portfolio. Then call or write the Administrator for the extra protection you need. UP TO $ 1 9 5,000 IN TERM LIFE INSURANCE PROTECTION IS AVAILABLE TO ACM MEMBERS. Plus these other group i ns u ra nc e plans:
Major Medical Expense I n s u rance • Excess Major Medical Disabi l ity I ncome • H i gh-Li m i t Accident I ns u rance
Contact Administrator, ACM Group Insurance Program
Smit h-Sternau Organization, I nc 1 255 23rd Street, N.W. Washington, D.C. 20037
800 424· 9883 Toll Fraa in Washington. O.C. area. 202 296-8030
Wright State U n iversity
The N C R D isti n g u i shed Professor i n Computer Science a n d Eng i neering The Position
Wright State University invites applications and nominations for the NCR Distinguished Professor in Computer Science and Engineering. Applicants must possess an outstanding research record in computer science and/or computer engineering. The recipient will be expected to provide strong research leadership in a program committed to excellence and prominence in the discipline. He/she can expect a competitive salary for a distinguished professorsh i p , p lus discretionary funds commensurate with responsibilities. The Department
Departmental strengths include a large and cooperative faculty, extensive laboratory facilities, excellent potential for industrial/military support, graduate and undergraduate programs in both computer science and computer engineering, and a large population of graduate as well as undergraduate students. The Environment
The state-assisted university is located in a high technology environment among industrial/military research and development facilities. A state-supported
A·12
research park to foster both basic and applied industrial/military/university research is also under development and is progressing impressively. The university has identified computer science and engineering as an area of high priority for continued developmental funding. To Apply
Please submit resumes or nominations to: Larry A. Crum, Chair Department of Computer Science Wright State U niversity Dayton, Ohio 45435 51 3/873-2491 Reviewing will begin October 1 , 1 985 and continue monthly until the position is filled or until September 1 , 1 986. An equal opportunity/affirmative action employer.
WRIGHT STAlE
Wright State U niversity Dayton, Ohio 45435
The 1 985 Guide will be available Spring 1 986. ACM Guide to Computing Literature is an annual com
authors in computing and related fields. It includes items
Computing Reviews, papers from ACM journals
prehensive index to the world's computing literature. Speci
reviewed in
fically designed for researchers, librarians, and educators,
and thousands of citations from other societies, academic
the
and professional publishers, and government agencies.
ACM Guide to Computing Literature
makes it easy to
retrieve information because of its thorou gh cross-referenc ing system . T h e new 1 984
Guide
is t h e third volume in the
Guide
series to offer g reatly improved subject access to the
A complete set of Guides ( 1 960- 1 984) is a necessity for
anyone interested in computing research and in doing a literature search. Past and future
Guides
provide a useful
database through the new ACM Computing Classification
and continuous record for computing l iterature and increase
System. This System contains over 1 OOO specific categories
the value of the volumes you may already own.
and subject descriptors hierarch ically organized for quick
Future volumes can be added to your collection of Guides
and accurate retrieval of appropriate citations.
by checking the Standing Order Subscription option. Shortly
includes complete references to a full range of publ ications
payment is received by the ACM Order Department, the
published that year.
publication will be shipped. You will then receive an invoice
Each volume of the ACM
Guide to Computing Literature
The most recent Guide (over 1 1 00 pages) contains re
ferences to more than 1 7 ,000 entries from books, journals, proceedings, reports, and theses as well as a listing of 1 8,000
before the
Guide
is printed, an invoice will be mailed. When
automatically for each succeeding vol ume. So, to avoid searching and sorting through stacks of liter
ature, order the ACM
Guide to Computing Literature
today!
�
lijtjQld@lilll&!fiG:-lMl:Viil;[tJ'!t;!'-f.11it+tJIM;itMIJZ How the Guide is Organized: Each citation is assigned an iden tification number and is then i ndexed by source, author(s), keywords(s), subject categories and Computing Reviews reviewer ( if reviewed). Even if you have only incomplete bibliographic infor mation, the cross-referencing system allows you to find your citation. Bibliographic Index: Bibliographic source ( Publ ishers full addres ses are listed in the Source Index in each volume of ACM Guide to Computing Literature) and citation data a re displayed in sections: books, journals, proceedings, reports, and theses. Each item is flagged by a unique identification n u m ber to which all other in dexes point. (If the item has been reviewed in Computing Reviews, the identification n u m ber used is taken from the review itself.)
KEYWORD INDEX
Titles containing a given keyword are listed. The identification number points to the full citation.
I Keyword ""-
Opt i m iz i n g * pcrrormancc in a Modula-2 c o m p i k r for � m a l l compulcrs.
CATEGORY INDEX Every item is indexed according to the unique new computing classification system
M . W.
C.
Dore.
J . Software e n g i neering in an Ada e n v i ronment .
Publishers. I nc . . New Yor k . N Y. 1 984 .
ISBN 01 01010 1 01 .
L__ �
Total Pages
International Standard Book Number
Date of Publication
� / �
Co111p111. /111pi al lows t he ·erasure of t he tree n0 from
t rees to l he
rad ishcs vcn t
radi
T h i s is t h e accumulated s e t of all new rules obtained from each original rule by .assigning all possible trees to the rule's variables while satisfying the rule's constraint C. These new rules are thus of one of the two forms: appetizer ---> ;
�IJ� ; {x = 3.1. 2 . nil} in the play. The sentence is first insertion [e,f.x,f.y) --> {x = 3 . 2.1.nil} insertion [e,x,y); decomposed into five parts, which are given in Figure 9a. 9e Each part is made up of one or a permutation ["beautiful marquise " . " your beautiful eyes" . " make me"."die"."of love " . n i l , x)? few inseparable words. Starting from an initial sequence with these five components, we can produce all possible variants by generating all the permutations of the sequence. We first have to choose a way of coding a sequence by a tree. 1 1 Since it is necessary to have a notation for the empty sequence, the sequence 3, 7, 2 is repre sented by the tree in Figure 9b. Also, since each node is labeled with a single character, a dot, readability is improved by using infix notation, u.v. , instead of pre fix notation, .(u, v). To further simplify, we omit parentheses whenever left-right association is implied. To assert that sequence 11 is a permutation of sequence x we write permutation (x, y). The first rule of Figure 9c states that the sequence of length zero, that is, the empty sequence, has only one permutation-itself. The second rule specifies that, in order to permute a nonempty sequence, that is, a sequence of length 11 + 1 , we remove its first element e and obtain a sequence x of length 1 1 ; we then compute any What are all permutations x of the sequence 1 , 2, 3? permutation y of this sequence x, insert the element e in any and position of the sequence, and produce the desired sequence z. To insert an element e in a sequence x and obtain a What are the values of the variables a, b, c, and d so that 2, sequence y, we introduce the term insertion(e, x, y). We 4, c, d is a permutation of 3, a, 1 , b? either insert e before x (third rule of Figure 9c) or we insert e Finally in Figure 9e (a magnetized version is shown on the in the sequence that has its first element removed (fourth following two pages), we ask the question producing the 1 20 rule of Figure 9c). These four rules of Figure 9c constitute stylistic variants that the "bourgeois gentilhomme" might the entire permutation program. have said! Figure 9d presents the computer's answers to two ques tions: =
=
=
=
{11•"be•utdu1 -rqu•H". "your t>oo•ullful •Y•• " , ".,.k• ,.,,- , " d 1 • " . "of
{••"your beaut1Cul •r•s"."beautlful ..rquu1·. -.,.k. ,.." . "d1e"."ot
lov•" .n • l l lov•" . n 1 l )
=
[.-"beautiful ..rqu11•", "yo11r i:..a u t d u l eyu · . -...k, - · . · o r
lo111","di1" . n 1 I }
{••"your bN11t1tul 1yu"."be.out ttul -rqu 1 u " . n 1 ! )
(a•"b wi t hout-repet i t ion ( S . E. N .D.M.O.B. Y n i l ) adm issible ( r l . 0 , 0.M,O) adm issible (r2.S.M.0. r 1 ) a d m issible (r3 . E . 0.N.r2) ad missible (r4.N.R.E.r3) adm issible (0.0,£.Y.r4). (S ;< 0 . M ;< OJ:
SEND + MOBE MONEY
lOc
lOd
wit hout-repe t i t ion ( n i l ) ---> : w i t ho u t -repet i t ion (u.v) -> o u t -of (11.v) w i t hout-repe t i t ion (v): o u t -of ( u . n il) -> : out-of (u. v.w) -> out-of (11. w). (11 # v):
a d m i ss i ble ( 0 . 11 1 . 112 .113.r) ---> plus ( 0 . 1 1 1 .0.u2 .r.113 ) : admissi ble ( 1 .11 1 .112.113.r) ---> plus ( 0 . 1 1 1 .0.112.x) plus-one (x,r. 1 1 3 ) ;
lOe
so l u t i on (x. If, : j ? (x = 9 . 5 . 6 . i. y = 1 .0 . 8 . 5 . z
=
1 . 0.6. 5 . 2 )
The purpose o f this example is to solve a classical cryptarithmetic puzzle: Assign eight different digits to the eight letters S, E, N, D, M, 0, R, Y, such that the sum SEND + MORE = MONEY becomes valid. To do so, we introduce, in Figure 1 Oa ' , the four carryovers r1 , r2, r3, and r4, which can be null and which have to be added to each column of the sum . The program consists of the three parts shown in Fig ures 1 Ob, 1 Oc, and 1 Od. The table of sums up to 20 is programmed in Figure 1 Od: Any elementary-school stu dent knows this table by heart, but the machine has to compute it over and over again since it only knows how to add 1 to a number. We use plus(x, y, z) to mean x + y = z . Each number is represented by two digits with a dot between them (we use infix notation as in Figure 9). Fig-
+
9567 1 085 10652
plus (O.O,x.x) ---> less-than-twenty ( x ) ; plus ( x ' , 11 .z ' ) ---> plus-one (x.x' J plus (x,11.z) plus-01ie (z.z ' ) :
less-than-twenty ( 0 . 0 ) -+ : less-than-twenty (11) ---> plus-one (x.y ) : ·
p l u s-one p l u s-one p l us-one p l u s-one p l us-one p l u s-one pl us-one p l u s-one p l u s-one p l us-one p l us-one pl us-one p l us-one pl us-one p l u s-one p l u s-one pl us-one p l u s-one plus-one
(0.0. (0 . 1 . (0.2. (0.3. (0.4. (0.5. (0.6, (0.7. (0.8. (0.9. ( 1 .0 . (1.1. ( 1 .2 . ( 1 .3 , ( 1 .4. ( 1 .5. ( 1 .6. ( 1 .7. ( 1 .8 .
0. 1 ) ---> 0 . 2 ) ---> 0 . 3 ) ---> 0 . 4 ) ---> 0 . 5 ) ---> 0 . 6 ) ---> 0. 7 ) ---> 0 . 8 ) ---> 0 . 9 ) ---> 1 .0 ) ---> 1 . 1 ) ---> 1 . 2 ) ---> 1 . 3 ) ---> 1 .4 ) ---> 1 . 5 ) ---> 1 .6 ) ---> 1 . 7 ) ---> 1 . 8 ) ---> 1 .9 ) --->
: : : : : : : : : : : : : : : : : : :
ure 1 Oc presents the definition of a sequence without repetition (note that the last rule of Figure 1 Oc contains a nonempty constraint). In Figure 1 Ob, it is stated that to compute a solution it is necessary to assign distinct val ues to the letters S, E, N, D, M, 0, R, Y, and that, in each column of the sum , a property called admissible, has to be satisfied between the carryover, the three letters of the column, and the preceding carryover. Of course, this property admissible is defined using the property plus and the property plus-one. Since the numbers SEND, MORE, and MONEY should not begin with the digit 0, an inequal ity constraint is added to the first rule of Figure 1 Ob. In Figure 1 Oe, we challenge the computer to provide us with the three mystery numbers.
FIGURE 10. Send More Money
1310
Communications of the ACM
December 1 985
Volume 28
Number 1 2
ARTICLES
DESCRIBING PROLOG BY ITS INTERPRETATION AND COMPILATION Since its conceptio n, Prolog has fol lowed a developm e n ta l course similar to the early evo l u tion of LISP. Although the version of Prolog described here typifies that c u rren tly in use, it should be cons idered with in the fra m ework of l a nguage evo l u tion. JACQUES COHEN
Pro log is a language developed about 1 0 years ago by Alain Colmera u e r and h i s coworkers at t h e A r t i fi c i a l I n t e l l igence Group (GIA-G ro upe d ' I n t e l l igence Art i fi c i e l l e ) i n M a rse i l l e s , F r a n c e . I t i s a logic progra m m i n g l anguage i n t h e sense t h a t i t s s t a t ements a r e i n te rpreted as sentences of a l ogic. D u ri ng the last decade. Prolog has a t t racted t h e at t e n t ion of a fai r l y l a rge n u mber of E u ropean comput e r sci e n tists who formed research groups act ively engaged i n refin i ng the l anguage and developing new appl ications. The adoption of Prolog as the core l a nguage for the J apanese F i ft h Generation project has i ncreased i n terest i n t h e l a nguage b y American compu t e r scientists from b o t h u niversit i es and i ndust ry. There is a growi ng l i t erat u re on the subj ect of P ro log, and presen t l y several j o u rnals regu larly publish a r t icles i n t h is a rea [ 34 ] . Since 1 98 1 , E u ropean groups have a lso h e l d yearly symposia on l ogic program m i ng ( 3 2 . 40, 41 J . More rece n t l y , a n n u a l conferences h a v e also b e e n h e l d i n t h e U n i ted Sta t es [20. 2 1 ] . A brief review of t h e available l i t erat u re appea rs i n t h e references. In addit ion t o C o lmeraue r's a r ti c l e t h a t appears i n t h i s issue o f CACM, t here a re a few excellent articles t h a t are h ighly recommended as i n t roductions t o Prolog. Kowa lsk i 's a r t i cl es [ 2 3 , 2 5 ] st ress t he relat ion ship between Prolog- l i k e l a nguages and classical l ogic. Two i n t roductory art icles b y Genesere t h and Davis h ave appeared more rece n t l y ( 1 3 . 1 6] . The t heore tical foundations of logic progra m m i ng a re covered i n Lloyd's book [ 2 7 ] . and a h istorical acco u n t o f t h e evo l u t ion of Prolog is d escribed b y Robi nson (37] . In a n effort to teach P ro log t o persons w h o were a l ready fluent i n a progra m m i n g l anguage (say, Pascal or LISP), we fou nd t h a t l ea rn i ng t he l anguage co u l d be accelerated by d rawir.g para ll e ls between P rolog pro gra ms and programs w r i t t e n in o t h e r l a nguages. We a lso fou n d t ha t expla i n i ng the progra mming m a c h i nery This work w a s par t l v supported
bv NSF Grant
DCR-85 0088 1 .
(c 1 985 ACM 000 1 -0782/85/ 1 200- 1 3 1 1 75�
December 1 985
Volume 28
Number 1 2
needed to i n t e rpret Pro log programs was a n i ncen t i ve to learning more abou t t h e new la nguage. I t was t h is experience that compe l led us t o write this a r t i c l e , w h i c h i s d i re c t e d t o progra m m e rs who are a t e a s e w i t h recu rsion and l in k ed data s t r u c t u res ( s u c h as l ists). W e believe t h a t t h e most i n teres t i ng exa mples of t h e u s e of Prolog a re i n symbolic processi ng. and we w i l l i l l us t r a t e t h e advan t ages of t h e l a nguage i n t h a t con t e x t . This a r t icle comb i nes t h e feat u res of a t u torial a n d a s u rvey. More specifica lly . i t s objectives a re
1. 2. 3. 4. 5.
t o describe t h e nucleus of a n i n terpreter t h a t can be used i n r u n n i ng s imple programs. to present examples t ha t make P rolog u n iq u e among e x i s t i ng l a nguages, t o show how Prolog programs can be compil e d , to d iscuss recent e x tensions, and t o provide a gu ide t o the cu rrent l i t e ra t u re.
If t h is sel f-contained present a t ion fulfills the above ob j ec t i ves, it should enable the reader to fol low the s t a t e of- t h e-art l i t erat u re on t h e subject. The reader is re ferred t o t he b i b l i ography in [34] for refere nces to ap plications u s i ng Prolog. A common misconcept ion about P rolog is t h a t i ts m a i n applica t ion js to prove t h eorems i n predicate cal c u l us. Reca l l that LISP is a genera l -pu rpose program m i ng l anguage based on C h u rc h 's l a mbda calculus. By the same token, P rolog i s a program m i ng l a nguage based on predicate cal c u lus. I t s fou nd a ti ons rest i ndeed on Robinson's a u to m a t i c t h eorem-provi ng t heory [35. 3 6 ] . B u t . since i t s conception, Prolog has been evolving i n a manner not u n l i k e the early evo l u t i o n of LISP. Act u a l l y . both languages are s t i l l evolving' We ask the reader t o consider t his a r t icle w i t h i n t h e frame work of language evol u t ion. The version of Prolog de scribed i n this a rt i cle is t ypical of t h a t in cu rre n t use. (See the box i l l us t ra t i ng t he main syntactic d i fferences between t he Marse i lles P rolog in C o lmerauer's a r t icle ( p . 1 296) and t h e E d i n b u rgh Prolog u sed in t h is a r t icle.)
Co111mu11icatio11s of tile ACM
131 1
Articles
The fol lowing i l l u s t ra t es t h rough e xa m ples t h e m a i n syn t a c t i c d i fferences between the M arse i l les ( M ) Prolog in Col merauer's a r t i c l e (p. ] 296) and the Edi n b u rgh (E ) Prolog used in t h is a rt i cl e .
Varia bles
(MJ ( E)
Constants
(E)
Rules Lists
[M)
(M) [E)
[M) [ E)
x
a
x A
� xl" Xpri111e X l b
1 23 a/Jc"
goal a can be satisfied if goals b, c, a n d d c a n b e satisfied.
1 23 a/Jc
a --> /J c: a a. - b. c.
ll :
a . /u . n i l
[ a.b.XJ
--+
;
x.y
[X I YJ
• Single letters followed b y a prime or by digits. " Identifiers starting with an uppercase letter. c I ntegers or a sequerice having more than two letters.
DEFIN ITION
One concrete syntax fo r P rolog r u l es is given by
( rule) ( clause) ( head ) ( tail) ( un it clause )
( clause ) . ! ( un it clause ) . ( head ) : - ( tail ) ( l itera l ) ( l itera l ) ! , ( literal ) ! ( litera l )
w h e r e t h e c u r l y b races d e n o t e a n y n u mber of repet i t ions ( i n c l u d i n g none) o f t h e sequ ence e nclosed by t h e brackets. A P ro log progra m is a sequence of ru les t h a t c a n b e viewed i n i t i a l l y a s pa ra meterless procedu res t h a t call o t h e r procedu res. For t h e l i m e bei ng. let us consider t he simplest case, w he re a ( literal ) i s a si ngle l e t ter. for example. cons i de r t h e fol lo w i ng Prolog pro gram i n which ru les are n u m b e red for fut u re refe re nce:
a a b e. f. a
1. 2. 3. 4. 5. 6.
- b. c. d. - e, f. :- f.
:- f.
In t h e first r u l e . a is t h e ( head ) , and b, c, d i s t h e ( tail ) . The fou r t h and fi ft h r u l es are u n i t clauses. W e ass u m e t h e r u l es are stored i n a d a t a base so t h a t t h ey can b e accessed e fficien t l y . The execu t i on of a P rolog progra m is t ri ggered b y a q u ery. which is syntac t i ca l l y e q u i v a l e n t to a ( tail ) . For example. a, e . is a q uery. The resu l t o f q u e ryi ng t h e program i s a yes or no a nswer i nd i ca t i ng t h e s uccess or fa i l u re of t h e q u ery. There are t h ree ways of i n terpre t i ng t he semant ics of Prolog r u l es and q u e r i es. The fi rst i s based on l ogic, i n t h i s pa r t i c u l a r case, o n Boolean algebra. The l i t erals a re Boolean variables, and t h e ru l es e xp ress form u las. For example, t h e fi rst r u l e is i n t e rpreted as
a is true if b and c and d are true or
b
1312
/\
c
/\
d � a.
Communications of the ACM
A u n i t cla use such as e means e = true. The P rolog program is vi ewed as t h e con j u nction of for m u l as i t defi nes. T h e q u e ry su cceeds i f i l a n d t h e program are s i m u l t aneously sat isfiable. J n a second i n t e rpretat ion of a Prolog rule, we assume t hat a ( literal ) is a goa l t o be sa t i sfi ed. For example, t h e fi rst rule slates t h a t
The u n i t clause states t h a t t h e d e fi n e d goa l can be sa t isfied. As before. t h e progra m defi nes a con j u nc t i o n of goals to be sat isfied. The q uery succeeds i f t h e goals can be satisfied using t h e ru les o f t h e progra m . F i n a l l y . i n a t h i rd i n t e rpret a t i on we invoke t h e s i m i l a r i t y between P ro log ru les and con t e x t - free gram m a r r u l es. A Prolog progra m is associ a ted w i t h a conlext free gra mmar i n w h i ch a ( litera l ) i s a nonl erm i n a l and a ( rule) corresponds t o a gram m a r r u l e i n wh ich t h e ( head ) rew rites i n t o t he ( tail ) : a u n i t c l a use is vi ewed as a gra mmar r u l e in w h i ch a nonterm i n a l rewrites i n t o t h e e m p t y symbol f . U n d e r t h is i nt e rpreta t i on. a q u e ry succeeds i f it can be rewri t t e n i n lo t he empty s t ri ng. or. eq u i valently. can be erased. A l t hough t h e above t h ree i n t erpretat ions are all h e l p fu l i n expl a i n i ng t h e semant ics of t h i s s i m p l i fied ver sion of Prolog. t h e logic i n te rpret a t i on w i l l be u sed i n t h e re m a i nd e r o f t h is art icle. I NTERPRETATION
We will fi rst s how h ow a n i n t erpreter can be i mple mented fo r t h e s i m p l i fied P rolog of the previous sec t i o n . The rules w i l l be stored seq u e n t i a l l y in a d a t a base i mplemented as a one-dimensional array Rule [ 1 . . n ] and con t a i n i ng poi n te rs t o a speci a l type o f l i near l ist. Such a lis t is a record w i t h two fi elds. t h e fi rst storing a letter. and t h e second being e i t h e r n il or a poi n t e r to a l i near l i s t . Let t h e fu nction cons be t he const ructor of a l ist elemen t , a n d assume t h a t i t s fi elds are accessible via t h e fu nctions head a n d tail. The first ru le is stored i n t h e dat abase b y
Rule[ 1 ]
:=
co11s( 'a' . co11s('b' . cons('c'. cons('d'. nil)))).
The fi ft h rule defi n i n g a u n i t cla use i s stored as
Rule[S]
:=
co11s('e'. n il) .
S i m i l a r assignments are used to store t h e re m a i n i ng r u l es. We are now ready to present a p rocedu re solve t h a t h a s a s a pa ra meter a poi n t e r t o a l i near l ist and i s capable of determ i n ing w h e t h e r or n o t a q uery i s suc cessfu l . The q u ery i tself is the l ist with which solve i s fi rst ca l led. The proced u re uses t w o a u x i l i a r y proce d u res match and append ; 1 11 atch (A . B) simply tests if t h e a l p h a n u meric A equals t h e a l p h a n u m e ri c B ; appe11d(L 1 . L2) produ ces t h e l ist represen t i ng t h e conca t e n a t ion o f L 1 w i t h L 2 ( t h i s i s equivalent t o t he fa m i l i a r append fu nction in LISP: it basica l l y copies L1 a nd ma k es its last element poi n t to L2). The procedu re solve . w r i t t e n i n a Pasca l - l i k e l a n guage. a ppears i n Figu re l . The proced u re performs a
December 1 985
Volume 28
Number 1 2
Articles
solve (L: pLIST); begin local i : i n teger; if L ¥- n il
procedure
then for
i
if
:= 1 t o n do match (head(Rule [ i ] ) , head(L))then solve(append(ta i /(Ru/ e[i]), ta ii (L )));
else write('yes') end:
FIGURE 1 . An Initial Version of the Interpreter
depth first search of t h e p roblem space where t h e local variable is used for con t i n u i n g t he search i n case of a fa i l u re . 1 The head of t h e list of goa ls L is ma tched w i t h t h e h e a d of e a c h rule. I f a m a t c h is fou n d . t h e p roce d u re is ca l l ed rec u rsively w i t h a new list of goa l s formed by a d d i ng ( t h rough a c a l l of append) t h e ele ments of the tail of the matching ru le t o the goals t h a t re main to be sat isfied. W h e n t h e l i s t of goa ls is n il, a l l goa ls have been sat isfied. and a success message is is sued. If t h e a t te m p t s t o match fa i l . t h e sea rch is cont i n ued i n t h e p revious recu rsion level u n t i l t he zero t h level i s reached i n wh ich case no more solu tions a re possible. for example t he q u e ry a, e. is expressed by
solve(co11s('a'. cons('e'. nil))) and yields two sol u t ions. If we were to pri nt the suc cessfu l sequ ence of the list of goa ls. we would o b t a i n sol u t ion 1 : so l u tion 2:
a, e a, e
= =
e , f, e = f, e = e = nil; f, e = e = n il.
The e n t i re search space is shown i n Figu re 2 (p. 1 3 14) i n t he form of a t ree. I n nondet e r m i n ist i c algorit hms. t hat t ree is called the t ree of choices [ 7 ] . I ts l ea ves a re nodes represen t i ng fa i l u res or successes. The i n t ernal nodes are labeled with the list of goals that remain t o be sa t i sfi ed. N o t e t h a t . i f t h e t ree of choices is fi n i t e , t h e order of t h e goals i n t h e l ist of goa ls is i rrelevant i nsofar as the presence and n u m be r of sol u t ions are concerned. Thus. the order of t he parameters of append in Figure 1 cou l d be switched. and t he two exis t i ng sol u t ions wou ld still be fou nd. Note that if t h e last ru le were replaced by
a
:-
f, a .
t h e t ree of choices w o u l d be i n fi n i t e and sol u t ions s i m i lar to t h e fi rst sol u t ion w o u l d be fou nd repeat e d l y . T h e proced u re solve i n Figure 1 c a n h a n d l e t h ese s i t u a t ions by ge nera t i ng an i n fi n i t e sequence of sol u t ions. H ow ever. had t h e a bove rule a ppea red as t h e fi rst one, t h e procedure solve w o u l d a l s o l oop, but w i t h o u t y i e l d i ng any sol u t i ons. This last example shows h ow i m po r t a n t t h e ordering of t h e ru les i s t o t he ou t come of a q ue ry. Let us now t e m po rari l y i nt e r r up t our description of Prolog interpretation t o show how paramet e rs a re i n t ro d u ced into Prolog r u l es. These parameters a l l ow a 1 t\ l a i n Colmcraucr'!; clock variable corresponds l o l h c recursion level in our
procedure ::11/i.'t'.
December 1 985
Volume 28
Number 1 2
m uch more ge nera l pattern matching mechanism t o take place. extending t h e match fu nction u sed i n t h i s section. It is t h e comb i n a t ion of t h e control mechanism using back t racking and the powerfu l pa t t e rn match i ng capa b i l i t ies t ha t a l l ows t h e langu age to reach i t s fu l l expressive power. The i n t roduction of paramet ers in P ro log ru les corre sponds t o extending t h e Boolean algebra i n t erpret a t i o n to cover a speci a l form of pred icate ca l c u l u s called Horn clauses. Basica l l y . P(X. Y, . . . ) is t ru e if t he re are v a l u es for X, Y, . . . t ha t render P t ru e . The task of t h e Prolog i n terpre t e r is t o a t t e mp t t o fi nd t hese valu es. In the next section. we will d iscuss one of the most usefu l proced u res i n P ro log, namely. t h e append proce d u re. Following t h a t we w i l l aga i n ret u rn to Prolog i n t erpret a t ion i n t h e more general case of procedu res con t a i n i n g pa ra m e t e rs. E X A M PLES
This section demonst rates the t ransformation of a func t ional specification of a p rocedu re into i ts P ro log coun terpart. Consider t h e LISP- l i k e fu nction append t h a t conca t enates two l ists. L1 and L2: fu nction i f L1
=
append(L1 , L 2 : pLIST) : pLIST: nil then append := L2 . else append : = cons(head(L1), append(tail( L 1 ) , L2)):
I n the above L1 and L2 are poi nt ers to l ists: a list is a record cont a i n i n g t he two fi elds head and tail, which t h e mselves con t a i n poi nters to o t h e r lists or to a toms. The tail m ust poi n t t o a l ist or t o the special atom nil. The fu nction cons(H, T) c reates t h e list whose head and tail are. respectively. H a nd T. Let us t ra nsform t he fu nction append i n t o a p rocedu re having a n explicit t h i rd para meter L3 t h a t w i l l conta i n t h e desi red resu l t . T h e l oca l variable T is used t o store int ermed i a t e res u l ts.
append( L 1 . L2: pLIST; T: pLIST : L1 = nil then L3 := L2
procedure
var
L3 : pUST);
begin local if
else begin
append(tail( L 1 ) , L2, T); L3 : = cons (head(L 1 ) , T) end end;
The former procedure can be t ransformed i n t o a Boolean fu nction t ha t . i n addition to b u i l d i n g L3, ch ecks if append p roduces t h e correct res u l t .
append(L1 , L2 : pLIST: v a r L3 : pUST) : H J . T1 . T: pUST; i f L1 = n il then
fu nction
Boolea n :
begin local begin
L3 := L2: append : =
true
end else if
! There exists a 1 1 HJ and a TJ such that HJ = head (L1) and TJ = tail ( L 1 ) 1
Communications of the ACM
1313
Articles
�([)
d e
� I (J) 3
2
c
d
4
5
4
3
2
e
� \ G) 2
6
5
2
3
fa i l u re
4
5
I
([)
e
2
3
5
� 2
6
3
4
5
4
5
6
\
0
� 2
6
0
e
�
4
� \
6
d
3
e
2
(backtrack)
3
4
4
5
\
success
5
\
success
�
6
3
6
11il
6
n il
R ules: 4.
1. a : - b, c, d. 2. a : - e, f. 3. b : f.
5.
-
Query:
6.
e. f. a
:- f. 0
a, e.
denotes the head of the list of goals.
FIGURE 2. The Search Space (also called the tree of choices)
then begin
append : = append(T l , L2, T): L3 := cons (H1 , T) end else
append :=
false
end;
The Boolean in the second conditional has been pre sented informally. but it could actually have been pro grammed in detail. Note t hat t h e assignments in the above program are execu ted at most once for each re cursive cal l. The function ret urns false if L1 is not a list (e.g., i f L1 = cons (a, b) for some atom b ,e nil). We are now ready to transform t h e last function into
1314
Communications of the ACM
a Prolog-like coun terpart in which rules of assignments and conditionals are subsumed by a general pattern match ing operation called unificat ion and specified by the equ ality sign. The statement E l = E2 succeeds i f E l and E 2 can b e matched. I n addition, some of t h e vari ables in E1 and E2 may be bound if necessary. We obtain
append(L1 , L2, L3)
i s true if
L1
=
n il
and
L3
= L2
L1
=
otherwise
append(L1 , L2, L3)
i s t r ue if
cons(H l , Tl)
and
append(T 1 , L2, T)
December 1 985
Volume 28 Number 1 2
A rticles
a nd o t h e r w ise
L3 = cons (H 1 , T) append i s false.
The reader ca n now compare t h e above res u l t s wi t h t h e previous description o f t h e subset o f P rolog. This comparison y i elds t he Prolog progra m
append(L 1 . L2. L3) :- L1 = nil, L3 = L2. append(L1 , L2, L3) : - L1 = cons(H 1 , T1). append(T1 , L2, T), L3 = cons (H1 , T). I n t h is case, t h e e q u a l i t y s ign is a n operator t h a t commands a u n i fication between i t s l e ft a n d righ t opera nds. T h is cou l d a lso be done u s i ng t h e u n i t cla use unify(X, X) and subst i t u ti n g L 1 = nil b y unify (L J , nil), and so on. Replacing L 1 and L3 with t he i r respective values i n t h e righ t - h a n d side of a cla use. w e obtain
append(nil, L2, L2). append(cons(H 1 , T 1 ) . L2, cons(H1 , T)) : - append(T1 , L2, T). The explicit calls to unify h ave now been replaced by i mp l i c i t ca l l s that w i l l be t riggered b y the P rolog i nter pre t e r when i t t ries t o match a goa l with the head of a ru l e . Not ice t h a t a ( litera l ) now becomes a fu nct ion name fol lowed b y a l is t of para m e t e rs each of w h i ch is syntactica l l y s i m i l a r to a ( litera l ) . T h e E d i n b u rgh Prolog represe n t a tion of cons(H, T ) i s (H I T], a n d n i l i s [ J . The M a rseil les cou n t e rparts are H. T and nil. I n t h e E d i n b u rgh d i a l ec t . append is prese n t ed by
append([ ], L2, L2). append(( H J I T1], L2, [Hl I T]) : - append(Tl , L2, T). The t ransformat ions above have been presented in an i nformal manner w i t h the pri m a ry goa l of showing t h e relationship between well-k nown l a nguages (Pascal , LISP) a n d P rolog. T h e pot e n t i a l P rolog user is u rgPd t o a t t empt progra m m i n g d i rect l y i n Prolog instead of fol lowing the above st eps. The q uery append(cons(a, cons(b, nil)), cons(c, nil). Z ) y i e lds
Z = cons(a, cons(b, cons(c, nil))) . I n E d i n b u rgh P ro log, t he above q u e ry is stated as append((a, b], (c), Z). a n d t h e resu l t becomes
Z = [a, b, c] A remarkable d i fference between t h e origi n a l Pascal like version and the P ro log version of append is t h e a b i l i t y of t h e l a t t e r t o determine ( u n k nown) l ists t h a t , w h e n appended, y i e l d a given l ist as a resu l t . F o r exam ple. t he query append(X, Y, (a]) y i el ds
X = (] X = [a]
Y = [a] Y= []
The above capabi l i t y is d u e t o t h e gen e ra l i t y of t h e search a n d pat t e rn match i ng me c hanism of P ro log. A n often asked question is. l s the generality usefu/ 7 The a nswer is definitely yes ' A few exa mples w i l l provide support ing evide nce.
December
1 985
Vol u m e
28
Number
12
The fi rst appears i n Wa rren (45] and i s a procedu re for determ i n i ng a l ist LLL. w h i c h is t h e conca t e n a t i o n of L w i t h L t h e res u l t i tself being aga i n concatenated w i t h L.
triple(L, LLL) : - appe11d(L, LL, LLL) , append(L, L, LL) . Note t h a t t he fi rst append is exec u t ed even t hough LL has not yet been bound. T h is a m o u n ts t o copying t h e l is t L a nd h a v i ng t h e variable L L a s i t s last element. After t h e second append is fi nished. LL is b o u n d , a n d t h e l ist LLL becomes fu l l y k nown. T h is propert y of post poni ng b i n ding t i mes c a n be very usefu l . F o r example, a d i c t ionary may con t a i n e n t r i es whose val ues are u n k nown. Ide n t i ca l e n t ries w i l l have values t h a t a re bound among t h emselves. If a n d when a v a l u e is ac t u a l l y determined. all com m u n a l l y u nbound variables a re bound to t h a t value. T h is s i t u a t ion occu rs, for ex ample. i n compi l i ng. when several gotos are d i rected t o t h e s a m e fo rward l a b e l t ha t has not y e t b e e n reached a t a given stage o f t h e processi ng. Another i n t eres t i ng example is su blist(X, Y), w h i c h i s t ru e w h e n X is a s u b l i s t of Y . L e t U a n d W be t h e lists a t t h e left a n d right of t h e s u b l i s t X. Then t h e program becomes sublist ( X . Y) : - append(Z, W, Y). append(U, X, Z).
where the va riables represent t he s u b l ists i nd i ca t ed below: y
u
x
w
An addit ional example is t h e b u b b l esort program credited to van E m de n i n [ 6 ] . The spec ification of t wo adjacent elements A and B i n a l i st L is done by a call :
append(_, (A , B I -], L) The underscore stands for a variable whose name is i nelevant to t he compu t a t i o n , and the notation (A, B I C] stands fo r cons(A, cons(B, C)) . (Note t h a t t h e u nderscores correspond to d i ffe rent variables.) The r u l es to b u bble sort t hen become
bsort(L, S) : - append(U, [A , B I X], L), B < A, append(U, [B, A I X] , M), bsort(M, S) , bsort(L, L). The fi rst append generates a l l pai rs of adjacent ele ments in L. The l i t e ra l B < A i s a b u i l t - i n pred icate t h a t tests whet her B is l e x i cograph i c a l l y s m a l l e r t h a n A . (Note t h a t b o t h A a n d B m u s t be b o u n d , o t he rwise a fa i l u re occu rs' There w i l l be more d iscussion of t h is l i m i t a t i o n later in t h is a r t icle.) The second append re const ructs the mod i fied l i s t , which becomes t h e a rguCo111 m 11 11icatio11s of t / J e ACM
1315
Articles
ment in a recursive call to bsort. If t he fi rst clause is no longer applicable. t h e n a l l pai rs of adj acent e l ements are i n order. a nd the second clause then provides the desi red resu l t . This version of b u b blesort i s space and t i m e i ne ffici e n t s i n ce U, the i n i t i a l segm e n t of the l is t , is copied t w i c e a t e a c h l e v e l of recu rsi on.2 However. the b revi t y of t h e program i s i ndicat ive of t h e savings t h a t ca n be accrued i n progra m m i ng a n d debuggi ng. In a fi nal example a lso cred ited to van E m d e n ( 6 ) , t h e program plays t he cl assical game of N i m . A l i s t s u c h a s
[s(s(O)). s(O). s(s(s (O)))] represe nts a current list of p i l es of m atches: 0 i ndicates no ma tches. s (O) one match. a n d so on. The object i ve of the ga me is to make a move-remove one or more matches from one of t h e piles-such t h a t . after a lter nate moves the opponent is u nable t o remove any matches. The program is presen t ed i n Figure 3 . The cla uses us and move s t a t e t h a t a m o v e should produce t h e list Y b y selec t i ng a p i l e X1 from X, t a ki ng some matc hes from X1 to form X2, a n d repl a c i ng X 1 wi t h X2 t o fo rm Y . The n u m ber o f m a t c h es removed s h o u l d be such t h a t the oppo n e n t w i l l be u nable t o w i n t h e ga me b y remov i ng matches from l is t Y . T h e proce d u re 1101 can be considered as a b u i l t - i n predica t e t h a t succeeds i f its a rgument fai ls a n d v i c e versa. Each ca l l of t h e proce d u re takesome a t te mpts t o remove one or more m a t c h es from t h e origi n a l stack of matches. The progra m cou ld be fu r t h e r s i m p l i fied n o t i n g t h a t 1.
2.
t h e proce d u re them is i d e n t i ca l t o us a nd c a n t h e re fore be e l i m i nated: by using l ists of l ists s u c h as [(1 , . . . , 1 ] , [ 1 , . . . , 1 ], . , [1 , . . . , 1 )], t h e proce d u re takesome cou l d be replaced b y a ca ll to append(X2, [- 1 -J. X1) t h a t re moves one or more ls from a given s u b l i s t . 3
We u rge readers t o est i m a t e t h e s i z e of a corresponding program wri t t e n i n the langu age of their choice. The genera l i t y and succinct ness a c h i eved i n Prolog programs vis-a-vis t h ose wri t te n i n con v e n t i o n a l l a n guages is d u e t o t w o factors: 1. 2
t he centra l role played by u n i fication t h a t combi nes t h e effect of both con d i t ionals and assign m e n ts. and
Bsort could be mod i fied to avoid t h i s copying.
3 \ ( tail )
where t h e rew r i t i ng a rrow "-->" replaces t h e sign " : -". Prolog i n te rprete rs t ra nslate DCGs i n t o Prolog rules (co n t a i n i ng additional parameters) t h a t are used i n parsing t h e stri ngs generated by t h e context-free rule defi n ing t h e nonterm i n a l ( head ) a n d having ( tail) as the righ t - h a nd side. In t h e case o f OCGs, [ ( term inal ) ] is a valid term appearing i n a tail. ll denotes a n element of t h e term i na l vocabulary. A n example will i l l ustrate t h e use of DCGs. A Prolog parser using the gra m m a r ru les
E XTENSIONS
In t h i s sec t ion. some of t h e extensions l h a l h a ve been and are prese n t l y being proposed l o i ncrease the capa b i l it ies or the effici ency o f Prolog programs are summa rized. The OCG sect ion cons i ders a special t ype of P rolog rule that has been i ncorporated i n to most P ro log i n t erpret ers. These rules have a proven record of use ful ness in compi l i ng and in n a t u r a l - l a nguage pro cessi ng. The other extensions can be class i fied accord i ng to the cha nges t h e y i n t roduce in our version of t h e proce d u re solve of Figure 4 . T h e ext ension to h a n d l e i nfi n i t e t rees genera l i zes t h e un ify fu nction to consider c i rc u l a r struct u res as well as t rees. S i m i l a r l y , the use of diseq u a l i l i es, in a d d i t ion to equalit i es. can a lso be viewed as an ext ension a i med at i mproving u n ify. The goa l -freezing technique extends Prolog by changing the order i n w h i c h goals a re placed i n t h e l ist of goa ls prior to recursively call i ng solve. The potent i a l for pa ra l l e l execu tion of Prolog progra ms, a nd extensions based on t h e use of more general cla uses, for example, t hose contai n ing more t h a n one l i teral in t h e head of a clause. a re d iscussed in t h e l ast two sections.
::=
S ---> a S b s -c is gi ven by t h e DCG s--> [a], s, [b). s - -> [c]. If we wished l o determine t h e value of n for an i np u t s t r i n g o f t h e form a "cb11, we would i n t roduce a n a t t ri bute t hat counts 11 u s i n g t h e t e rm succ ( for su ccessor). The OCG becomes s (succ(X)) --> [a], s(X) , [b ) . s (O) - -> [c] . This yie l ds succ(succ(O)) when parsing t h e s t ri ng aacbb. The abi l i t y of Prolog to have parameters t h a t are both i nput a nd output enables us to genera t e aacbb when n is given as succ(succ(O) ) . A n addi tional fea t u re of DCGs i s t h a t P rolog l it e ra ls (enclosed w i t h i n curly b races) can be i n t e rspe rsed i n t h e righ t-hand s i de of gra mmar ru les t h us a l lowing ac t ions lo be execu ted w h i l e pars i ng is being done. I n fi ni te Trees
Al t h e begi n n i ng of t h is article. we ment i oned t h a t most Prolog i n t e rpreters do n o l prevent t h e construc t ion of ci rcu l a r struct u res; s i nce t h e cost o f t h is preven t ion is h igh (see occu r check) . Colmerauer has advocated the use of more genera l u ni ficat ion capable of dea l i ng w i t h terms co ntai n i ng variables t h a t ca n be bound t o suble rms of t h e gi ven term. These circular structures are called i n fi n i t e t rees and have a n i nteresti ng prop erly: They can be decomposed i n lo a fi nite sel o f ( i n fi nite) subl rees. Ass u m i ng t h a t t h e u n i t cla u se e q (Z, Z ) is in the dat abase. the query
�
eq(X, f(X, Y)). eq(Y. g(t(Y) . X)). prod uces t h e i n fi nite tree X: f
u �
OY: g December 1 985
Volume 28
Number 1 2
A rticles
Colmerauer's view is t h a t t h e u nifica t i o n algorithm overhead needed to handle t h ese structu res is smaller t h a n t h a t req u i red by the occur check and, more i mpor tant. i n fi n i t e t rees are nat u ral representat ions for graphs, gram ma rs. and flowcharts and t h e refore should not be avoi ded. The t heoret ical fou ndations for h i s gen eralized u n i fication appear in [9]. His paper a lso pre sents exampl es o f the use of i n fi n i t e t rees i n t h e synthe sis and m i n i mization of fin i t e state a u tomatons. G i a n nesini and t h e a ut hor have u t i l ized i n fi n i t e t rees i n parser ge neration [ 1 7 ] . The use o f t h e exte nded u n i fica tion algo r i t h m requ ires t hat a special printing program be available t o output i n fi n i t e t rees ( 3 3 ] . A n i n teresting charact eristic of t h i s progra m is t h a t it can e l i m i nate common subtrees t h us producing a m in i m a l i nfi nite t ree. For example. t h e minimal t ree corresponding to eq(X, f( f( f(X)))) is X = f(X). T h is capa b i l i t y of t h e print ing rou t i n e is usefu l in determ i n i ng m i n imal fi n i t e state a u t omatons ( 9 ] and in opt i m izing code ( 1 7 ] . Goal Freezing
Another very usefu l extension oft e n i ncorporated i n to i nt e rpret e rs is t h e notion of coro u t i n i ng, or lazy evalua tion. The b u i l t - i n proce d u re freeze(X, P) t ests whether t h e variable X has been bound. I f so, P i s executed: oth e rw ise t h e pa i r ( X. P) is placed i n a " freezer." As soon as X becomes bound, P is p l aced a t the head o f t h e l ist o f goals for i m mediate execution. We n o w show h ow freeze can be easi l y implemented by expressi n g t h e procedure solve i n Prolog i tself' A l t h ough t h is metal evel progr a m m i ng will o f cou rse considerably slow down t h e execution, t h i s capa b i l i t y can and has been used for fast prototyping extensions t o the l anguage. The Prolog procedure solve uses the b u i l t - i n predicate clause(Goal, Tail), which determines the ( fi rst) head o f a Prolog rule that u n i fies w i t h Goal and b inds Tail t o t h e t a i l o f t h a t r u l e . I n t h e case o f u n i t cla uses, Tail i s bound to t h e constant true. (It would not be d i ffic u l t to i ncorporate t his predicate i nto t h e i n te rpreter discussed earl ier.) The metalevel i n terpreter becomes solve(true). solve([Goal I Restgoal]) : - solve( Goal), solve(Restgoal). solve(Goal) : - c/ause(Goal, Tail), solve(Tail). To i ncorporate freeze, t wo addit io n a l paramete rs a re n eeded: t h e l ist represent i ng a cu rrent Freezer and an other l ist repres e n t i ng its modified cou n t e rpart, the NewFreezer. Both l ists contain p a i rs (variable-goal) i n which variable i s a n u nbound (dr frozen) variable and t h e goal is a term to be act i vated as a procedure as soon as t h e variable becomes bound (or u n frozen). Immedi ately a fter cla use matches a Goal i n t h e database ( i . e . , a fter u n i fi ca t ion occ u rs), t h e defrost predicate is u s e d t o check whether a n y variable h a s t hawed, i n w h i c h case the corresponding proced u re is i m mediately solved a ft e r updating t h e Freezer. Details a r e given i n Figure 6 . T h e b u i l t -in predicates v a r and nonvar a r e used to check whether variables are bound. I n an efficient implementation of freeze, variables have an additional fi eld that con t a i ns n il i f the variable is bound: ot herwise i t con t a i ns a poi n te r to the goa l t h a t
Dece111ber 1 985
Vu/11111e 28
Nu mber 1 2
solve(true, Freezer, Freezer). solve([Goal I Restgoal], Freezer, NewFreezer) : solve(Goal, Freezer, TempFreezer) , solve(Restgoal, TempFreezer, New Freezer) . solve(Goal, Freezer, NewFreezer) : clause(Goal, Tail), defrost(Freezer, TempFreezer), solve(Tail, TempFreezer, NewFreezer) . solve(freeze(X, Goal). Freezer, [[X I Goal] I Freezer]): var(X) : solve(freeze(X, Goal), Freezer, NewFreezer) : nonva r(X), solve(Goal, Freezer, NewFreezer) . defrost([ ], [ ]). defrost([[X I Goal] I Freezer], [[X I Goal] I NewFreezer]): var(X), defrost(Freezer, New Freezer). defrost([[X I Goal] I Freezer], NewFreezer) : nonvar(X), defrost(Freezer, TempFreezer), solve(Goal, TempFreezer, NewFreezer). FIGURE 6. Steps in the Unification Algorithm
has to be executed when t h e variable becomes bound. The u n i fication algori t h m i nspects the variable's field and. i f applicable. t riggers t h e goal execution. Also no t i ce t h at. in the backtracking mode, t hawed procedu res should be refrozen. The predicate freeze h as applica tions i n t ree and graph m a n i p u l a t i o n . Disequalities
We begi n here by showing an example o f the use of freeze i n "si m u la t i ng" another usefu l P rolog extension: dif(X, Y) or X #- Y. T h is appare n t l y i n nocuous b u i l t - i n predicate is available i n m o s t i n t e rpreters: h owever. with the e xcept i o n of the Prolog I I i nterpreter ( 1 1 ] . t h e predicate is applicable o n l y when b o t h X and Y a re bound' If one or both of t h e variables are u nbound, t h e i n te rpreters preci pitously enter t h e backt rack m ode by assu ming a fa i l u re. This is, of cou rse, logica l l y unsound. The more ge neral pred icate dif cou l d be program med using the clause dif(X, Y) : - freeze(X, freeze(Y, different(X, Y))). in which t h e b u i l t - i n predicate different(X, Y) would t est whether or not the bo und variable X is d i fferent from t h e bound variable Y. Act u a l l y , t h e procedu re different would have to be m uch more complex to achieve some of t he ge nera l i t y o f dif in Prolog II. Consider, for exam ple, t h e qu ery dif(X, Y). X
=
f(a, BJ, Y
=
f(A, b) .
The predicate different may prematu rely fai l i f i t does not check t hat X and Y are bound to terms contai n i ng new variables. The P rolog i n t e rpreter would have to ensure that dif(A, a) or dif(B, b). F u r t h e rmore, i t should t rigger a fai l u re when processi ng the query
Com111u11icatio11s of the ACM
1321
Articles
dif(X, Y). X
=
Y
Alt hough t h e above cou l d be done w i t h special freezes (42 ] . Colmerauer's approach is cleaner i n t he sense t ha t i t s general u n i fication incorporates lists of equalities and d isequ a l i ties t hat a re kept in the environ m e n t . The a v a i l a b i l i t y of a general dif can r e n d e r programs more efficient. For example, in coloring maps we m a y u s e t h e rules color(red) . color(white). color(blue) . validco/ors(node(N 1 , C l ) . node(N2, C2)) :- dif(Cl , C2), co/or(Cl ) . color(C2 ) . T h e proce d u re validcolors asserts t hat t wo a d j acent "nodes" must be colored d i fferently. Note that dif is called when Cl and C2 a re unbound a n d i t is i nvoked as soon as Cl and C2 become bound. Jn Colmerauer's approach, i t is the generalize d unifi cation a lgori t h m , capable of h a nd l i ng i n fi n i t e t rees, t h a t i s a lso capable of deci d i ng w h e t h e r t h e s e t of con straints is satis fiable or not. The backtrac k i ng mode is triggered only in the case of unsatisfiability. A logical extension of t h is p h i losophy is p resently being pursued by t h e M a rseil les' group. Why not make similar back t racking decisions for other i nequalities (i.e., =:: :::: . . . )? Indeed, t h e simplex met hod is now b e i ng i ncorporated into a Prolog interpreter deal ing with rational n u mbers and that is a lso able to decide the unsatisfiability of a system of linear i nequations.
A language called Concurrent Prolog h as been pro posed by Shapiro ( 39] and is being used to develop parallel algorithms in systems program ming and i n graph m a n ipulat i o ns. I t ass um es t h a t both And- and Or-pa rallel ism are available. Concurre n t Prolog uses the speci a l punct u a t i o n m a rks " ? " a n d " I ". The q u estion mark i s a shorthand notation for freezes. For example. the l iteral p(X?, Y) can be viewed as a form of freeze(X, p(X, Y)) . T h e vertical b a r is called com m it a n d usually a ppears o nce i n t h e t a i l of c l a u ses defi n i n g a given procedure.5 Consider. for example, a : - b, c l d. e. a : - PI q . The li t erals b, c , and d, e are executed u s i n g A n d parallelism. However. t h e comp utation using O r parallelism for t h e t w o cla uses defi ning a con t i n u es only w i t h t h e clause t h a t first reaches t h e commit sign. For example, i f the computa tion of b, c proceeds faster t h a n p, t he n the second clause is abandoned, and exe cution continues with d, e only. Other E xtensions
Many other exte nsions a re consta n t l y being proposed, and they range from polymorphic type checking to ex tending t h e generali t y of Prolog rules. I n the logic i n ter pretation of a Prolog program . we saw t h a t a : - b,
c,
d.
could b e i nt e rpreted as t h e Boolean for m u l a Parallelism
W he reas fo r most la nguages it is fai rl y d i fficult t o write p rograms t h a t a u tomatically t a k e advantage of opera tions and instructions that can be executed in parallel, Prolog offers an a b undance of opport u n i t i es for paral lelization. There a re a t least t h ree possibili ties for per forming Prolog operations i n pa rallel: 1 . Unification. Since t h is is one of t h e most frequent operations i n r u n n i ng Prolog p rograms, i t would seem worth w h i l e to search for e fficient parallel u ni fication algorit h ms. Some work has a l ready been done in t his a rea ( 1 4 . 4 7 ] . However, the res u l ts h a ve not been en cou ragi ng. 2 . A nd-parallelism. This consists of s i m u l taneously execut i ng each proce d u re in the tail of a clause. For example. in a (X, Y, U) : - b(X, Z). c (X, Y). d(T, U). an a t tempt is made to con t i n u e the execut ion i n paral lel for t h e cla uses defi ning b, c, and d. The first two share the common variable X; t he refore, i f u n i fication fa ils i n one but not i n t h e ot her, or i f the u n i fication yields d i fferent b i n d i ngs, then some of t h e l abor done in parallel is lost. However, the last clause in the t a i l c a n be executed i n dependently since i t does not share variables with t h e other two. 3. Or-parallelism. When a given predicate is defi ned by several rules. it is possible to attempt t o apply t h e rules s i m u lt aneously ( 1 2 ] .
1322
Communications of the ACM
b f\ c f\ d � a or a V bV cV d The a bove for m ulas have j ust one posi t i ve l i teral and correspond to clauses having j ust one head. These are called Horn clauses. and Prolog's fou n d a t ions rest on prov i ng t heorems t h a t are e xp ressible by Horn clauses (4 3 ] . Several researchers have suggested e x te nsions for deali ng w i t h more gen e ra l cla u ses ( 2 1 ] and for develop i ng semantics for negation t ha t are more general t h a n t h a t o f "negation by fai l u re" ( 2 7 ] . Experience has s hown t h a t t h e most general extension, that is, t o the general predicate calculus, poses d i ffic u l t combinatorial search problems. I t is conceivable that other restricted forms of t h e predicate calcul u s m a y prove t o be practi cal. FINAL REMARKS
P rolog has not yet h a d t i m e to fully mature. Yet, i ts you t h should be viewed posit ively since i t encou rages experi mentation. For t h is reason , efforts toward stan dardization have been considere d premat u re b y a fai r number o f i ts practit ioners. Prolog programs are usually significantly shorter t h a n programs written i n o t h e r l anguages (typically 5-1 0 t imes s horter). However, t h e re have not yet been e x If a comm i t sign does not appear i n a rule. i t s i m pl icit presence i s assumed as t he first element of the t a i l .
5
December 1 985
Volume 28 Number 1 2
Articles
t remely la rge programs written in P rolog. To develop t h ese la rge progra ms. one would need a special envi ronment w i t h adequate compilers. deb uggers. t ype checkers, editors, p rofil e rs, etc. Prolog does not yet have such a n enviro n m e n t . but t h e d i rection t a k e n in developing LISP workstat ions should serve as a guide in prod ucing Prolog counterparts. The nonexistence of block s t ructure, scopi ng. and type ch eck ing of va riables may deter potential users from wri t i ng very la rge Prolog programs. Also lacking is a methodology for documentation, development of suit able notation for a voiding an ever-i ncreasing n u mber of parameters and fo r specifying pa rallelism. These, we believe. can only be achi eved t h rough experimentation. We a lso believe t hat t h ere are a consi de rable n u mber of people who are adept i n the la nguage, who. i n d u e time. will p rovide solut ions to t h ese problems. A u n ique property of some P rolog programs is t heir ability to perform inverse compu tations. For example. i f p ( X , Y ) defi nes a procedure p t a k i ng a n i nput X and prod ucing an output Y i t can ( i n certain cases) deter m i ne which input X p roduces Y. Therefore, i f p is a d i fferentiation p rogram it can also pe rform integration. This is easier said t h a n done, since t h e use of i m p u re fea t u res may result in operations t h a t a re not correctly bac k t ra c k a b l e .
The i nverse computation of parsing is string ge nera tion. and pa rsers are now available to perform both operations. T h is genera tion is only a ppl icable when dealing with gram mars for n a t u ra l languages for w h i c h t h e generated sentences a re s m a l l . A compiler carefu l ly written in Prolog ca n also be useful i n decompili ng. The difficult ies e ncou nt e red i n doing t h e inverse opera tions are frequently clue to t he use of the cut and of assign m e n ts. It is li kely t h a t by using dif a n d by making certain assignments back t rack able, decompi lation and other i nverse computations would be atta inable. Problems a k i n to i n ve rse computa tion have a lso been programmed in P rolog. Among them is t h e synt hesis of au toma tons given samples of input stri ngs that t h ey should accept or refuse (9, 3 8 ] . A fairly common classi fication of p rogram m i n g l a n guages divides t h e m i n t o i m perative. functional, and decl a ra tive. Most existing progra m m i ng la nguages are i mpera tive. pure LISP is fu nctional, and p u re P rolog is declarat ive. Since t hese types of languages have useful fea t u res. it is tempt i ng to graft fea tures of one of t hese t ypes of la nguage onto another. However. to achieve orthogonality t his blending task may require consider able effort. S u m ma rized below are some of t h e fea t u res w hose combination render P rolog u n ique among other lan guages. 1.
P rocedu res m a y cont a i n parameters t hat a r e both input and o u t p u t :
2.
procedu res may ret u rn results contai n i ng u nbound v a riables:
3.
back t racking is built i n . t h e refore allowing the determination of m u l t iple solu tions to a given problem:
December 1 985
Volume 28
Number 1 2
4.
5.
general pattern matching capabilit ies operate in co n j u nction with a goal-seeking search mecha nism: progra m and data are prese nted i n similar forms.
We believe. however. that the above listing of t h e fea t u res of Prolog does not fu lly convey t h e subjective advant ages of the la nguage. In our view. t h e re are at least t h ree such advant ages: 1.
2.
3.
Having its fo u ndat ions i n logic. P rolog e ncourages the programmer to describe probl ems in a logical manner that faci litates check i ng for correctness and conseq uently reduces t h e debugging effort. The algori t h ms needed to inte rp ret P rolog programs a re pa rticularly amenable to parallel processi ng. The concise ness of Prolog programs, w i t h the re s u l t i ng decrease i n development time. makes i t a n ideal la nguage for prototyping.
Another i m portant characteristic of P rolog t hat de serves extension. and is now being extended. is the ability to postpone variable bindi ngs as much as is deemed necessa ry. failure and back t racking should be triggered only when t h e interpreter is confro n t ed w i t h a logica lly u nsat isfiable s e t of const raints. Jn t h i s re s pe c t . P ro l og's not i o n o f v a r i a b l es will a pproach t h a t used in mathematics. The price to be pa id for the advan tages o ffered by the la nguage amounts to t h e i ncreasing dema nds for larger memories and faster C PUs. The h istory of programmi ng-la nguage evol u l ion has demonstrated that. with the consistent trend towa rd less expensive and faster computers w i t h l a rger memories. t h i s p rice becomes not only acceptable but a lso advantageous since the savi ngs achi eved by progra m conciseness and by a reduced progra m mi ng effort largely compensat e for t h e space and execution t i m e overheads. f u rt h e r more. t h e q uest for increased efficiency of P rolog pro grams will enco u rage new and i m portant research i n t h e a reas o f optimiza t ion a n d parallelism. I owe my P rolog education to t h e membe rs of GIA (Groupe d'Intell igence A rt i ficielle) of Marseilles. f rance. It took a few s u mmers t h ere to con vince me t hat the elega nce and si mplicity of P rolog could make a d ramatic cha nge in t h e craft of p rogra m mi ng. The revelation I had learning P rolog was compa rable to my i n i t ial encounter with recursion i n LISP and a lso with my first at tempts to code digital com put ers back in t h e late 1 950s. W i t h m i n i m a l equipment. the members of GIA dem onstrated t h e i m portance of t h e concepts they had cre ated. My th anks go to Alain Colmerauer. Henri K a nou i . francis Giann esini. Bob Pasero. and Michel van Caneghem for sharing t heir e n t h usiasm a n d knowl edge of the new language. Thanks are a lso d u e t o many GIA graduate students with whom I interacted. Among t h ese I owe special t ha nks to Robert Kong. now at Brandeis University. who p rovided substa ntial help in the prepa ration of this art icle. Also a t Brandeis U ni ve r sity. I am fort unate to have a receptive group of coAcknowledgments.
Communications of the ACM
1323
A rt icles
workers a nd students wit h whom I continue to learn and experiment with new fea t u res o f Prolog. In pa rticu lar. I wish to t h a n k M i tchell Wand for his valuable comments and T i m Hickey for developing new tech niq ues for using and i m plement ing the predicate freeze a nd for participat i ng act i vely i n t h e m u l t iple revisions of the art icle. Finally, I wish to express m y gra t i tude to Randy Goebel of t h e U n ivers i t y o f Waterloo. He was an outstandingly hel pful referee who provided n u merous deta iled suggestions for i mprovi ng the original manu scri pt. GUIDE T O CURRENT LITERATURE Journals: /011 nrn l of Logic Progra 111111i11g. North-Holland. Amsterdam. (first issue- 1 984) . New Ce11eratio11 Co111p11ti11g, Springer-Verlag. New York (first issue- 1 983).
Newsletter: Logic Programming Newsletter. Dept. of Informatics. Univ. of Lisbon. Portugal (first issue- 1 981 ) .
Proceedings: See references 1 2 0 1 . 1 2 1 1 . 1 3 2 1 . 1401. a n d 141 I. Books: See references 1 2 1- 1 6 1 . 1 1 5 1 . [ 1 8 J . l 1 9 I . [ 2 2 1 . [ 24 1 . [261. and [ 2 7 1 . Bibliography: See reference [ 34 I. REFERENCES References [ 3 1 - [ 5 1 . l l O l . [ 1 5 1 . 1 1 8 1 . [ 1 9 1 . 1 2 2 1 . [ 2 4 ] . and [ 26] are not cited
in text. 1 . Bru ynooghe. M. A note on garbage-collection i n Prolog i n terpreters. In t111ple111entation of Protog. E l l is Horwood Series in Artificial Intelli gence. J A. Campbell. Ed. Wiley. New York . 1 984. pp. 258-267. 2. Campbell. J.A . . Ed. /111p/e111e11tatio11 of Prolog. Ellis Horwood Series in Artificial Intell igence. Wiley. New York . 1 984. 3. Clark. K . L. . and McCabe. f.G. Micro-Prolog: Progra111111ing in Logic. Prentice-Hall. Englewood Cliffs. N.) .. 1 984. 4. Clark. K.L .. and Ta rnlund. S.A . . Eds. Logic Progra111111ing. Academic Press. New York. 1 982. 5. Clocksin. W.F . . mid Mellish. C.S. Progra111111i11g in Prolog. 2nd ed. Spri nger-Verlag. New York. 1 9 84 . 6 . Coel ho. H . . Cotta. J . C . . a n d Pereira. L . M . H o w lo solve i i i n Prolog. Laboratorio Nacional de Engenharia Civil. Lisbon. Portugal. 1 980. . 7. Cohen. J. Nondeterministic algorithms. Co111p11t. S11rv. 1 1 . 2 ( June
1 979). 79-94.
8. Colmerauer. A. Les grammai res de metamorphose. Groupe d ' l ntelli gence Artificielle. Univ. of M a rsei l l es-Lu miny. France. 1 975. (Ap pears as Metamorphosis grammars. I n Natural La11g11age Commw1ica tion with Co111p11tcr;. L.. Bale. Ed. Spri nger-Verlag. New York. 1 978. pp. 1 33-1 89.) 9. Colmerauer. 1\. Prolog and infi n i t e t rees. In Logic Programm ing. K . L. Clark and S.A. Ta rnlund. Eds. Academic Press. New York. 1 982. pp.
23 1 -2 5 1 . 1 0. Colmerauer. A . Equations a n d i nequ a l i t ies on finite a n d i nfinite 11.
12. 13. 14. 15. 1 6.
17.
trees. Groupe d'lntelligence Artificielle. U n iversite A i x-Marseille II. France. 1 984. Colmerauer. A . . Kanou i . H . . and van Caneghem. M . Prolog 11. Groupe d ' l n t e l l igence Artificielle. U n iversity of Marseilles-Luminy. France. 1 982. Conery. J .S. The and/or process model for para l l e l i n terpretation of logic programs. Tech. Rep . . Univ. of California. Irvine. May 1 980. Davis. R.E. Logic program m i ng and Prolog: A tutorial. IEEE Softw. 2, 5 (Sept. 1 985). 53-62. Dwork. C . . Kanell aris. P.C . . and Mitchell. J.C. On the seq uential nature of unification. f. Logic Program. 1 ( 1 984). 3 5 - 5 0 . Gallaire. H .. and M i nker. J .. Eds. Logic and Data Bases. Plenum. New York. 1 977. Genesereth. M.R . . and Gi nsberg. M.L. Logic progra mming. Com11111n. ACM 28. 9 (Sept. 1 985). 933-941. Giannesi n i . F . . and Cohen. J . Parser generation and grammar manip ulat ions using Prolog's infi nite trees. /. Logic Program. (Oct. 1 984).
253-265.
18. Giannesin i . F. . Kanoui. H . . Pasero. R .. and van Caneghem. M . Prolog (in French). lnterEditions. Paris. 1 985 (a forthcoming English version will be published by Addison-Wesley. Reading. Mass.). 1 9. Hogger. C.J. ln trod11ction to Logic Program111 ing. Academic Press. New York. 1 984. 20. IEEE. Proceedings of the lntemational Symposi11m on Logic Program ming. IEEE. Atlantic City. N.J .. F eb . 1 9 84 . 2 1 . IEEE. Proceedings of the Symposi11m on Logic Progra111mi11g. I EEE. Boston. Mass. . J u l y 1 985.
1324
Communications of the ACM
22. Kluzniak. F .. and Szpakowicz. S. Prolog for Programmers. Academic Press. New York . 1 985. 23. Kowalsk i . R.A. Algorithm = logic + control. Commun. ACM 22. 7 ( J uly 1 979). 424-436. 24. Kowalski. R.A. Logic for Problem Solving. Elsevier North-Holland. New York. 1 979. 25. Kowalski. R.A. Logic as a computer la nguage. In Logic Program111ing, K . L.. Clark and S.A. Ta rnlund. Eds. Academic Press. New York. 1 982. pp. 3-1 6. 26. Li. D. A Prolog Data Base System. Research Studies Press, Wiley. New York. 1 984. 27. Lloyd. J . W. Fa11ndations of Logic Program ming. Springer-Verlag. New York . ·1984. 28. M a rt e l l i . A . . and Montanari. U. An efficient un ification algori t h m . ACM Trans. Program. Lang. Syst. 4. 2 (Apr. 1 982). 258-282. 29. Mellish. C . . and Hardy. S. I ntegra t i ng Prolog i n the poplog environ ment. In /mple111entation of Prolog. E l l is Horwood Series i n Artificial Intelligence. J.A. Campbell. Ed. Wiley. New York. 1 984. 30. Mellish. C.S. Some global optimizations for a Prolog compiler. /. Logic Program. 2. 1 (Apr. 1 985). 43-66. 31. Pereira. r.C . . and Warren. D.H. Defi n i te clause grammars for lan guage analysis. Artif. tntell. 1 3 ( 1 980). 231 -278. 32. Pereira. L. M . . et al. Eds. Proceedings Logic Progra111ming Workshop. Algarve. Portugal. J u l y 1 983. 33. Pique. J.f. Drawing t rees and their equations i n Prolog. In Proceed ings of t/1e Second International Logic Programming Conference. UPMAIL. Univ. of Uppsala. Sweden. J u l y 1 984. pp. 23-33. 34. Poe. M.D . Nasr. R . . Potter. J . . and S l i n n . ) . A Kwic bibliography on Prolog and logic progra m m i ng. f. Logic Progra111. 1 ( 1 984). 81-1 42. 35. Robinson. J . A . A machi ne-oriented logic based on the resolut ion principle. /. ACM 1 2. 1 (Jan. 1 965). 23-4 1 . 36. Robinson. J . A . Computational logic: T h e unification computation. Mach. tntell. 6 ( 1 9 7 1 ) . 63-72. 37. Robinson. J.A. Logic progra mmi ng-Past, present and future. New Ce11eration Com1111t. 1 (1 983). 1 07-1 24. 38. Shapiro. E. Algorit h m i c program debugging. P h . D. dissertation. Yale Univ . . MIT Press. Cambridge. Mass. . 1 982. 39. Shapiro. E. Systems progra m m i ng i n concurrent Prolog. !COT Tech. Rep .. Nov. 1 983. 40. Univ. of Uppsala. Proceedings of the 2nd Jntemational Logic Program ming ConferC11 c e. UP-MAIL. Univ. of Uppsala. Sweden . J u l y 1 984. . 41. va n Caneghem. M . . Ed. Proceedings of the 1st lnternat1011nl Logic Pro gramm ing Conference. Faculte des Sciences de Luminy. Marseilles. France. Sept. 1 982. 42. van Caneghem. M . L'anatomie de Prolog I I ( i n Prench). Ph.D. disser tation. U niversite d'Aix-Marseille II. Prance. Oct. 1984. 43. van Emden. M.H . . and Kowalski. R.A. The semantics of predicate logic as a programming language. /. ACM 23. 4 (Oct. 1 976). 733-742. 44. Warren. D.H.D. Applied logic-Its use and implementation as a pro gramming tool. Ph.D. dissertation. Univ. of Edinburgh. 1 977 (also appeared as Tech. Note 290. SRI International. Menlo Park. Calif ..
1 983).
45. Warren. D.H.D. Logic programming and compiler writing. Softw. Pract. Exper. 10 (Feb. 1 980). 97-1 25 . 46. Warren. D . H . D . A n abstract Prolog instruction s e t . Tech. Note 309. SRI International. Menlo Park. Calif. . Oct. 1 983. 47. Yasuura. H . O n t h e parallel computational complexity of u n i fica tion. In Proceedi11gs of the /11tematio11al Conference 011 Fifth Ce11eratio11 Co111p11ti11g Systems (Tokyo. Japa .n, Nov. 6-9). 1 984. pp. 235-243.
CR Categories and Subject Descriptors: 0.3. 1 : [ Programming Lan guages] : Formal Defi n i t ions and Theory-semantics, syntax; D. 3 . 2 [ Pro gramming Languages]: Language Classification-very h igh-level lan g11ages. Prolog: D. 3.4 [Programming Languages]: P rocessors-com p ilers , interpreters; 1.2.3 [ Artificial Intelligence]: Deduction and Theorem Prov ing- logic programming, metatheory: 1.2.5 [Artificial Intelligence]: Pro gramming Languages and Software General Terms: Languages
Additional Key Words and Phrases: nondeterminism. u n i fication A u t hor's Present Address: Jacques Cohen, Computer Science Dept . . Ford Hall. Brandeis University. Waltham. MA 02254: CSNET address: jc.brandeis@csnel-relay. Permission to copy without fee all or part of this material is granted provided t hat the copies are not made or distributed for direct commer cial advantage. the ACM copyright notice and the title of the publication and its date appear. and notice is given that copying is b y permission of the Association for Compu t i n g Machi nery. To copy otherwise. or lo republish. requi res a fee and/or specific permission.
December 1 985
Volume 28 Number 1 2
Journals you read cover to cover From com p uting applications to computing theory, from m atters of practical i mportance to those of scientific research, ACM jou rnals offer you high quality informative articles. Each undergoes a thorough review to insure its accuracy, topicality, and pertinence. Every journal is spe cially tailored to serve the specific needs of the computing com m u nity.
source for comprehensive su rveys, tutorials, and overview articles on topics of cu rrent and emerging importance. The Journal of the Association for Computing Machinery presents fundamental ideas that are of lasting value to the understanding of computation. ACM also publishes u nique reference sources. Com puting Reviews contains original reviews and abstracts of cu rrent books and journals. The ACM Guide to Comput ing Literature is an i mportant bibliographic g u ide to computing literature (available annually on Standing Order Subscription). Collected Algorithms from ACM is a collec tion of ACM algorithms avai lable in printed version, on microfiche, or on machine-readable tape.
While Communications of the ACM has made its mark publishing landmark research papers in computer sci ence, today the magazine is moving into a broader overview role. The editorial aim is to publish broad-gauge, high quality, highly readable articles on key issues and major technical developments in the field. The various transactions (ACM Transactions on Mathematica/ Soft ware, ACM Transactions on Database Systems, ACM Transactions on Graphics, ACM Transactions on Pro gramming Languages and Systems, ACM Transactions on Office Information Systems, and ACM Transactions on Computer Systems) cover burgeoning areas of computer
research and applications. Computing Surveys is your - - - - - - - -
�
D D
Please send me a free ACM Publ ications Catalog. Please send me subscription information for the following journal(s):
_
_
_ _
_ _
ACM Transactions on:
Communications of the ACM Journal of the ACM
_ _
Computing Reviews Computing Surveys
D Member No. D I am not an ACM
Programming Languages & Systems
_
Office Information Systems
_
Literature
Mathematical Software Database Systems
_ _
Collected Algorithms from ACM ACM Guide to Computing
Graphics Computer Systems
Expiration Date _ _ _ _ _
member, please send me membership information.
Address_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ City ______ State ____ Zip _
Mail to: Publications Department, ACM,
11
�
- - - - - - - - - -
For further information about ACM journals, send for your free ACM
Publications Catalog today!
West 42nd Street, New York, NY
1 0036.
- - -
REPORTS
SOFTWARE ASPECTS OF STRATEGIC DEFENSE SYSTEMS A form er member of the SDIO Panel o n Computing i n Support of Ba ttle Ma n age m e n t expla in s why h e believes the "star w a rs " effort will n o t a c h ieve its stated goals.
DAVID LORGE PARNAS
On 28 June 1 985, David Lorge Parnas, a respected computer scientist who has consulted extensively on United States defense projects, resigned from the Panel on Computing in Support of Battle Management, conve11ed by the Strategic Defense 111 itiative Organizatio11 (SDIO). With h is letter of resig11atio11, he subm itted eight short essays explaining why he believed the software required by the Strategic Defense In itiative would 11ot be tru stworthy. Excerpts from Dr. Par nas 's letter and the accompanying papers have appeared widely in the press. The Editors of A merican Scientist be lieved that it would be useful lo the scientific comm un ity to publish these essays in their entirety to stimulate scien tific discussio11 of the feasibility of the project. As part of the activity of the Forum 011 Risks to the Public in the use of computer systems the Editors of Com m u n ications are pleased to reprint these essays. '
This report comprises eight short papers t h a t were com pleted w h i l e I was a member of the Panel on Comput i ng in Su pport of Battle Managemen t, convened b y the St rat egic Defense I n i t i a t ive Organization (SDIO). SDIO is part of t h e Office of the U.S. Secretary of Defense. The panel was asked to identify t h e computer science problems t h a t would have to be solved before an effec tive antiballistic missile (ABM) system cou ld be de ployed. It is clear to everyone that computers must play a critical role in t h e systems t h a t SDIO is consideri ng. The essays t h a t cons t i t u t e t h is report were written to organize my t h oughts on t h ese topics and were submit ted to SDIO w i t h m y resignation from t h e panel. • Reprinted by permission o f A111erica11
Scie11tist. journal o[ Sigma X i :
Software Aspects o[ S t ra t egic Oefense Systems, David Lorge Parnas. Vol. 7 3 . No. 5 . pp. 432-440.