Algorithm = Logic + Control Robert Kowalski Imperial College, London

Algorithm = Logic + Control Robert Kowalski Imperial College, London

S. 1 Programming J. J. Horning Languages Editor Algorithm = Logic + Control Robert Kowalski Imperial College, London An algorithm can be regarded as consisting of a . logic component, which specifies the knowledge to be used in solving problems, and a control component, which determines the problem-solving strategies by means of which that knowledge is used. The logic component determines the meaning of the algorithm whereas the control component only affects its effkiency. The effkiency of an algorithm can often be improved by improving the control component without changing the logic of the algorithm. We argue that computer programs would be more often correct and more easily improved and modified if their logic and control aspects were identified and separated in the program text. Key Words and Phrases: control language, logic programming, nonprocedural language, programming methodology, program specification, relational data structures CR Categories: 3.64, 4.20, 4.30, 5.21, 5.24 Introduction Predicate logic is a high level, human-oriented lanl guage for describing problems and problem-solving methods to computers. In this paper, we are concerned not with the use of predicate logic as a programming language in its own right, but with its use as a tool for the analysis of algorithms. Our main aim will be to study ways in which logical analysis can contribute to improv- ing the structure and efficiency of algorithms. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct Eommer&al advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. This research was supported- - by- a grant from the Science Research Council. Author’s address: R.A. Kowalski, Dept. of Computing and Con* trol, Imperial College of Science and Technology, 180 Queens Gate, London SW7 2BZ, England. 0 1979 ACM OOOl-0782/79/0700-0424 $00.75. Communications July 1979 of Volume 22 the ACM Number 7 The notion that computation = controlled deduction presses the knowledge which can be used in solving was first proposed by Pay Hayes [19] and more recently problems and the control component determines the way by Bibel [2] and Vaughn-Pratt [31]. A similar thesis that in which that knowledge can be used. The distinction database systems should be regarded as consisting of a between logic and control is not wholly unambiguous. relational component, which defines the logic of the data, The same algorithm A can often be analyzed in different and a control component, which stores and retrieves it, ways. has been successfully argued by Codd [10]. Hewitt's A = L~ + C~. argument [20] for the programming language PLAN- A = Lz + C2. NER, though generally regarded as an argument against logic, can also be regarded as an argument for the thesis One analysis might include in the logic component what that algorithms be regarded as consisting of both logic another analysis includes in the control component. In and control components. In this paper we shall explore general, we prefer an analysis which places the greatest some of the useful consequences of that thesis. burden for achieving efficiency on the control compo- We represent the analysis of an algorithm A into a nent. Such an analysis has two advantages: (1) the logic logic component L, which defines the logic of the algo- component can afford to be a clearer and more obviously rithm, and a control component C, which specifies the correct statement of the problem and the knowledge manner in which the definitions are used, symbolically which can be used in its solution and (2) the control by the equation component assumes greater responsibility for the effi- ciency of the algorithm, which consequently can be more A=L+C. readily improved by upgrading the efficiency of the control. Algorithms for computing factorials are a simple exam- It is the intention that this paper should be self- ple. The definition of factorial constitutes the logic com- contained. The first part, accordingly, introduces the ponent of the algorithms: clausal form of predicate logic and defines the top-down 1 is the factorial of 0; and bottom-up interpretations of Horn clauses. The body u is the factorial of x + 1 ~ v is the factorial of x and u is v times of the paper investigates the following decomposition of x+l. algorithms into their various components. The definition can be used bottom-up to derive a se- quence of assertions about factorial or it can be used top- down to reduce the problem of computing the factorial cLOgic ./ //•ithm\ of x + 1 to the subproblems of computing the factorial of x and multiplying the result by x + 1. Different ways of using the same definition give rise to different algo- Abstract Oefinitk)ns of ~,~Control component rithms. Bottom-up use of the definition behaves like procedure data -structures definitions represented by // ~ iteration. Top-down use behaves like recursive evalua- tion. Direction Strategy for Strategy for Scheme for (e.g. top-down execution of investigating storing data The manner in which the logic component is used to or bottorn-up) i)rocedure alternative represented calls (e.g. procedures relationally solve problems constitutes the control component. As a sequential or first approximation, we restrict the control component C parallel ) to general-purpose problem-solving strategies which do We study the affect of altering each of the above com- not affect the meaning of the algorithm as it is deter- ponents of an algorithm. The final section of the paper mined by the logic component L. Thus different algo- introduces a graphical notation for expressing, more rithms A1 and Az, obtained by applying different meth- formally than in the rest of the paper, certain kinds of ods of control Cx and C2 to the same logic definitions L, control information. Much of the material in this paper are equivalent in the sense that they solve the same has been abstracted from lecture notes [23] prepared for problems with the same results. Symbolically, if A1 = the advanced summer school on foundations of comput- L + C1 and Az = L + C2, then A1 and Az are equivalent. ing held at the Mathematical Centre in Amsterdam in The relationship of equivalence between algorithms, be- May 1974. cause they have the same logic, is the basis for using logical analysis to improve the efficiency of an algorithm Notation by retaining its logic but improving the way it is used. In particular, replacing bottom-up by top-down control We use the clausal form of predicate logic. Simple often (but not always) improves efficiency, whereas re- assertions are expressed by clauses: placing top-down sequential solution of subproblems by Father (Zeus, Ares) ~-- top-down parallel solution seems never to decrease effi- Mother (Hera, Ares) Father (Ares, Harmonia) ~- ciency. Mother (Semele, Dionisius) Both the logic and the control components of an Father (Zeus, Dionisius) algorithm affect efficiency. The logic component ex- etc. 425 Communications July 1979 of Volume 22 the ACM Number 7 Here Father (x, y) states that x is the father of y and .... An are conditions of the clause and the atoms B1 .... , Mother (x, y) states that x is the mother ofy. Bm are alternative conclusions of the clause. If the clause Clauses can also express general conditional propo- contains the variables Xl ..... Xk then interpret it as stating sitions: that Female (x) *- Mother (x, y) for all xl ..... xk Male (x) ,--- Father (x, y) B1 or ... or Bm if A1 and ... and An. Parent (x, y) ~ Mother (x, y) Parent (x, y) ~-- Father (x, y). If n = 0, then interpret it as stating unconditionally that for all x~, .... xk These state that B~ or ... or Bin. x is female/fx is mother of y, If m = 0, then interpret it as stating that x is male/fx is father of y, x is parent ofy tfx is mother of y, and for no x~, ..., xk x is parent ofy tfx is father ofy. A ~ and ... and A n. The arrow ~ is the logical connective "if"; "x" and "y" If m = n = O, then interpret the clause as a sentence are variables representing any individuals; "Zeus," which is always false. "Ares," etc. are constant symbols representing particular An atom (or atomic formula) is an expression of the individuals; "Father," "Mother," "Female," etc. are form predicate symbols representing relations among individ- P (h ..... tn) uals. Variables in different clauses are distinct even if they have the same names. where P is an n-place predicate symbol and t~, ..., t,, are A clause can have several joint conditions or several terms. Interpret the atom as asserting that the relation alternative conclusions. Thus called P holds among the individuals called t~..... tn. A term is a variable, a constant symbol, or an expres- Grandparent (x, y) ,--- Parent (x, z), Parent (z, y) Male (x), Female (x) ~-- Parent (x, y) sion of the form Ancestor (x, y) ,--- Parent (x, y) f (h ..... tn) Ancestor (x, y) ~ Ancestor (x, z), Ancestor (z, y) where f is an n-place function symbol and tl ..... tn are where x, y, and z are variables, state that for all x, y, and terms. g The sets of predicate symbols, function symbols, con- x is grandparent ofy/f x is parent of z and z is parent of y; stant symbols, and variables are any mutually disjoint x is male or x is female tfx is parent of y; sets.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us