Formal Methods in Software Development Computer Programs/Systems Are Subject to Exact Reasoning

Formal Methods in Software Development Computer Programs/Systems Are Subject to Exact Reasoning

Core Claim Formal Methods in Software Development Computer programs/systems are subject to exact reasoning. Wolfgang Schreiner Computer programming is an exact science in that all the properties [email protected] of a program and all the consequences of executing it in any given environment can, in principle, be found out from the text of the Research Institute for Symbolic Computation (RISC) program itself by means of purely deductic reasoning. Johannes Kepler University, Linz, Austria C.A.R. Hoare, “An Axiomatic Basis for Computer Programming”, http://www.risc.uni-linz.ac.at 1969. A strong claim; not everyone might agree to it (we will rephrase it later). Wolfgang Schreiner http://www.risc.uni-linz.ac.at 1/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 2/18 Example Demonstration static int sum(int[] a) class Swap { { // swap a[i] and a[j] int n = a.length; static void swap(int[] a, int i, int j) int s = 0; { {n = length(a) ∧ s =0} int t = a[i]; for (int i=0; i<n; i++) a[i] = a[j]; { a[j] = t; − i 1 < } {n = length(a) ∧ s = Pj=0 a[j] ∧ 0 ≤ i n} s = s+a[i]; } // swap the first two elements of a n−1 static void swapFirst(int[] a) {n = length(a) ∧ s = Pj=0 a[j]} return s; { swap(a, 0, 1); } } } We will investigate what can go wrong. Wolfgang Schreiner http://www.risc.uni-linz.ac.at 3/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 4/18 Demonstration (Contd) Aspects This reasoning has various aspects: class Main static void init(int[] a, int n) { { Specification. State the properties that a program shall have. public static void main(String[] args) for (int i=0; i<n; i++) Verification. Argue why a particular program satisfies a given { a[i] = i; int n = parseInt(args[0]); } specification (in every execution). int[] a = new int[n]; Falsification. Detect that a program violates a specification (in some init(a, n); static void print(int[] a, int n) print(a, n); { execution). Swap.swapFirst(a); for (int i=0; i<n; i++) print(a, n); { Transformation. Transform a program that it preserves its behavior } System.out.print(a[i]); (but e.g. improves its execution time). System.out.print(’ ’); static int parseInt(String s) } Derivation. Construct a program in such a way that it is guaranteed { System.out.println(""); to satisfy a given specification. return Integer.parseInt(s); } } } This course deals with specification and verification/falsification. Wolfgang Schreiner http://www.risc.uni-linz.ac.at 5/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 6/18 Properties of Reasoning Alternatives to Reasoning Principal advantage: clarity and generality. Inspection. Let multiple people look at program and discuss it. The subjects of discussion are well defined. Actually, this is reasoning (but without a formal basis). There are clear rules for the correctness of the arguments. Advantages: reduces programmer’s “system blindness”. The arguments may apply to infinitely many situations. Disadvantage: without a formal basis, it is unclear what rules guide Example: {x ≥ 0}x = x+1{x > 0} the discussion. (for all x, to show that x is greater than zero after the execution of Testing. Run the program with sample inputs and observe the the assignment statement, it suffices to show that x is greater than or external effects (see what happens). equal to zero before). Advantage: the program is shown to work in certain situations. Principal disadvantage: abstraction. Disadvantage: you never know what happens with other inputs. We reason about models of the real world. In concurrent programs, you even do not now whether the same Questionable whether the model adequately describes the real world. behavior is always exhibited with the same input. Example: the machine code generated by the compiler for x = x+1 Simulation/Visualization. Similar to testing, but also observe the may be wrong, or the processor may have an error in the internal behavior of the program. implementation of the + operation, or ... Advantage: consideration not limited to external effects. All reasoning is relative to the assumptions of the model. Disadvantages: same as for testing. Wolfgang Schreiner http://www.risc.uni-linz.ac.at 7/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 8/18 The Power and Limits of Reasoning Core Claim Rephrased Assume a correct proof that program P satisfies specification S. True interpretation of Hoare’s statement: We have shown Computer programming is an exact science in that all the properties that every model execution of P satisfies S, of a model program and all the consequences of executing it in any which is also true for all real executions of P if the model is adequate. given model environment can, in principle, be found out from the text We have not shown of the program itself by means of purely deductic reasoning. that any real execution of P satisfies S, Beware of bugs in the above code; I have only proved it correct, not tried it. Donald E. Knuth, 1977. Still a strong claim, but now everyone should be able to agree to it. that S captures your expectation of a real world behavior. On the other hand, with a successful test run we demonstrate that some real execution of P satisfies an expectation, we cannot show that this is true for all real executions of P. Program testing can be used to show the presence of bugs, but never to show their absence! E.W.Dijkstra, 1972. Reasoning and testing have both their place. Wolfgang Schreiner http://www.risc.uni-linz.ac.at 9/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 10/18 The Role of Reasoning The Role of Reasoning Often: Post Factum Better: Pre Factum So the main role of reasoning is on program/system designs: Design a principal solution to a given problem. Argue about the correctness of the design. Specification Specification Thus find design errors; repeat process until you are satisfied. The main role of testing is on program/system implementations: Reasoning Reasoning Map the design to real computers using real programming languages. Model Model Run the implementation on sample inputs and check its behavior. System System Thus find implementation errors; repeat process until you are satisfied. Modeling Implementing This is a big difference from “proving that a program is correct”. Real Real System System Write a specification, design a model system, reason about its correctness, then implement the design, then test the implementation. Wolfgang Schreiner http://www.risc.uni-linz.ac.at 11/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 12/18 The Role of Reasoning The Origins: Sequential Programs Apparently, there are various approaches/tools that seem to apply A personal selection. reasoning to real systems . Robert W. Floyd, 1967: Assigning Meaning to Programs. Typical goal: prevent runtime errors. C.A.R. Hoare, 1969: An Axiomatic Basis for Computer Division by zero, array index out of bounds, null pointer dereferences, Programming. memory corruptions (buffer overflows). Tool that takes program as input and detects program errors. C.A.R. Hoare, 1972: Proof of Correctness of Data Representations. Actually: operate on automatically constructed models. Edsger W. Dijkstra, 1975: Guarded Commands, Nondeterminacy Focus is on falsification (finding errors). and Formal Derivation of Programs. Investigate whether “bad” states might occur in model. Edsger W. Dijkstra, 1976: A Discipline of Programming. Detected/assumed error in model may imply error in real system. Luckham et al, 1979: Stanford PASCAL Verifier - User Manual. Application to mission-critical/important pieces of software. Airplane control software. David Gries, 1981: The Science of Programming. MS Windows device driver. Axiomatic program semantics, program verification. We alwas reason about models. Wolfgang Schreiner http://www.risc.uni-linz.ac.at 13/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 14/18 The Origins: Concurrent Programs Later History A personal selection. In the 1980s, program verification was considered “dead” by many. Little automation, much manual effort by programmer. Dijkstra, 1968: Cooperating Sequential Processes. Handling of toy programs only. Ashcorft and Manna, 1971: Formalization of Properties of Parallel In the 1990s, model checkers became successful. Programs. Fully automatically check (finite state) models. Owicki, Gries, 1976: An Axiomatic Proof Technique for Parallel Verification of hardware and of communication protocols. Systems with state spaces of size 10100 and beyond. Programs. Since the late 1990s, interest in software verification revived. C.A.R. Hoare, 1978: Communicating Sequential Processes. Model checking/proving of critical pieces of software. Armin Pnueli, 1979: The Temporal Logic of Programs. Focus often more on falsification than on verification. Leslie Lamport, 1980: The “Hoare Logic” of Concurrent Programs. New applications such as proof-carrying-code (PCC). Robin Milner, 1982: A Calculus of Communicating Systems. Ship machine code together with proof that code satisfies certain safety/security properties. Axiomatic semantics, process calculus/algebra, temporal logic. New issues such as security considered. Formal methods are a hot topic today (also in industry). Wolfgang Schreiner http://www.risc.uni-linz.ac.at 15/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 16/18 Languages and Systems Course Outline Specification Languages Specifying and verifying sequential programs. Hoare style: VDM (Vienna Development Method), SPARK (SPADE Hoare calculus and predicate transformers. Ada Kernel), Larch/C++, OCL (Object Constraint Language for PVS specification and verification system. UML), JML (Java Modeling Language), ... Specifying and verifying Java programs. Algebraic/axiomatic: OBJ, ACT One, CafeOBJ, Larch, CASL, . Java modeling language (JML). State-oriented: Z, ASM (Abstract State Machines), ... Extended static checking of Java programs (ESC/Java2). Concurrent: Unity, Estelle, Lotos, TLA, ..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 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