CBMS-NSF REGIONAL CONFERENCE SERIES IN APPLIED MATHEMATICS A series of lectures on topics of current research interest ...
44 downloads
1204 Views
2MB Size
Report
This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Report copyright / DMCA form
CBMS-NSF REGIONAL CONFERENCE SERIES IN APPLIED MATHEMATICS A series of lectures on topics of current research interest in applied mathematics under the direction of the Conference Board of the Mathematical Sciences, supported by the National Science Foundation and published by SIAM. GARRETT BIRKHOFF, The Numerical Solution of Elliptic Equations D. V. LINDLEY, Bayesian Statistics, A Review R. S. VARGA, Functional Analysis and Approximation Theory in Numerical Analysis R. R. BAHADUR, Some Limit Theorems in Statistics PATRICK BILLINGSLEY, Weak Convergence of Measures: Applications in Probability J. L. LIONS, Some Aspects of the Optimal Control of Distributed Parameter Systems ROGER PENROSE, Techniques of Differential Topology in Relativity HERMAN CHERNOFF, Sequential Analysis and Optimal Design i. DURBIN, Distribution Theory for Tests Based on the Sample Distribution Function SOL I. RUBINOW, Mathematical Problems in the Biological Sciences P. D. LAX, Hyperbolic Systems of Conservation Laws and the Mathematical Theory of Shock Waves I. J. SCHOENBERG, Cardinal Spline Interpolation IVAN SINGER, The Theory of Best Approximation and Functional Analysis WERNER C. RHEINBOLDT, Methods of Solving Systems of Nonlinear Equations HANS F. WEINBERGER, Variational Methods for Eigenvalue Approximation R. TYRRELL ROCKAFELLAR, Conjugate Duality and Optimization SIR JAMES LIGHTHILL, Mathematical Biofluiddynamics GERARD SALTON, Theory of Indexing CATHLEEN S. MORAWETZ, Notes on Time Decay and Scattering for Some Hyperbolic Problems F. HOPPENSTEADT, Mathematical Theories of Populations: Demographics, Genetics and Epidemics RICHARD ASKEY, Orthogonal Polynomials and Special Functions L. E. PAYNE, Improperly Posed Problems in Partial Differential Equations S. ROSEN, Lectures on the Measurement and Evaluation of the Performance of Computing Systems HERBERT B. KELLER, Numerical Solution of Two Point Boundary Value Problems ]. P. LASALLE, The Stability of Dynamical Systems - Z. ARTSTEIN, Appendix A: Limiting Equations and Stability of Nonautonomous Ordinary Differential Equations D. GOTTLIEB AND S. A. ORSZAG, Numerical Analysis of Spectral Methods: Theory and Applications PETER J. HUBER, Robust Statistical Procedures HERBERT SOLOMON, Geometric Probability FRED S. ROBERTS, Graph Theory and Its Applications to Problems of Society JURIS HARTMANIS, Feasible Computations and Provable Complexity Properties ZOHAR MANNA, Lectures on the Logic of Computer Programming ELLIS L. JOHNSON, Integer Programming: Facets, Subadditivity, and Duality for Group and Semi-Group Problems SHMUEL WINOGRAD, Arithmetic Complexity of Computations (continued on inside back cover)
Lectures on the Logic of Computer Programming
ZOHAR MANNA Stanford University and Weizmann Institute of Science
SOCIETY for INDUSTRIAL and APPLIED MATHEMATICS
1980
PHILADELPHIA, PENNSYLVANIA 19103
Copyright © 1980 by the Society for Industrial and Applied Mathematics. 1098765432 Library of Congress Catalog Card Number: 79-93153. ISBN: 0-89871-164-9
Copyright © 1980 by the Society for Industrial and Applied Mathematics. 1098765432 Library of Congress Catalog Card Number: 79-93153. ISBN: 0-89871-164-9
Contents Introduction
1
Chapter 1 PARTIAL CORRECTNESS A. Invariant method B. Subgoal method C. Subgoal method versus invariant method
3 5 6
Chapter 2 TERMINATION A. Well-founded ordering method B. The multiset ordering
9 10
Chapter 3 TOTAL CORRECTNESS A. Intermittent method
15
Chapter 4 SYSTEMATIC PROGRAM ANNOTATION A. Range of individual variables B. Relation between variables C. Control invariants D. Debugging E. Termination and run-time analysis
20 20 21 22 23
Chapter 5 SYNTHESIS OF PROGRAMS A. The weakest precondition operator B. Transformation rules C. Simultaneous-goal principle D. Conditional-formation principle E. Recursion-formation principle F. Generalization G. Program modification H. Comparison with structured programming
25 27 28 30 31 34 36 36
iii
iv
CONTENTS
Chapter 6 TERMINATION OF PRODUCTION SYSTEMS A. Example 1: Associativity B. Example 2: Distribution system C. Example 3: Differentiation system D. Nested multisets
41 42 44 45
References
49
Introduction Techniques derived from mathematical logic have been applied to many aspects of the programming process. The following lecture notes deal with six of these aspects: partial correctness of programs: proving that a given program produces the intended results whenever it halts. termination of programs: proving that a given program will eventually halt. total correctness of programs: proving both that a given program is partially correct and that it terminates. systematic program annotation: describing the intermediate behavior of a given program. synthesis of programs: constructing a program to meet given specifications. termination of production systems: proving that a system of rewriting rules always halts.
l
This page intentionally left blank
CHAPTER 1
Partial Correctness We use the following conventions: Let P be a program; x be all the variables in P; x0 be the initial values of x (when computation starts); xh be the final values of x (upon termination of computation). Let L0, LI, ..., Lh be a designated set of labels (cutpoints) in P, where L0 is the entrance and Lh is the exit. (It is assumed that each loop passes through at least one of the designated labels.) A path a between L, and L/
is said to be basic if there are no designated labels between L, and L/. Let t a ( x ) be the condition for path a to be traversed; ga(x) be a function expressing the change in values along path a Thus
Let : for every x0 such that 3>(x0) holds, the computation reaches the exit Lh. P is totally correct w.r.t. and ^, find a set of predicates qo(xo, x), q\(xQ, x), - • •, qh(xo, x), corresponding to the labels L0, LI, • • • , Lh, such that the 3
4
CHAPTER 1
following verification conditions are satisfied for all x, x0, and xh (universally quantified): (11) 4>(f0) ^ qo(xo, *o) (the input specification implies the initial predicate), (12) qh(xo,Xh) ^ ^(xo^h) (the final predicate implies the output specification), and for each basic path a from L, to L/ (13) t a ( x ) and qi(x0, x) => g/Cc0, g«(*)) (the predicate before the path implies the predicate after, whenever the path can be taken). Verification conditions (II) and (13) imply that for each /, qi(xQ, x) is an invariant assertion at L,, i.e., each time we pass through L,, qi(x0, x) is true for the initial value x0 and for the current value of x. In particular, qh(xo, x) is an invariant assertion at L/,, which, by verification condition (12), implies the partial correctness of the program. In practice, we usually take qo(xo, *o) to be Q>(XO) and qh(xo, x) to be ^(jc0, jc). Then, (II) and (12) are guaranteed to hold. Example: integer square-root program. The following program computes b — [VaJ for every nonnegatiye integer a; that is, the final value of b is the largest integer k such that k ^ Va, i.e., b2 ^ a < (b +1)2. input (a) L0: (6,c,d)«-(0,l,l) LI: if c > a then LI,: output (b) else (ft,rf)