Mathematical Structures for Computer Science Chapter 1

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Program verification: flowchart programs Book: chapter 7.
Verification with Array Variables Book: Chapter 7.2.
Program verification: flowchart programs Book: chapter 7.
In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows.
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Dynamic semantics Precisely specify the meanings of programs. Why? –programmers need to understand the meanings of programs they read –programmers need.
Simple Example {i = 0} j := i * i {j < 100} Can we ‘verify’ this triple? Only if we know the semantics of assignment.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
1 Discrete Structures Lecture 29 Predicates and Programming Read Ch
Predicate Transformers
Announcements We are done with homeworks Second coding exam this week, in recitation –Times will be posted later today –If in doubt, show up for your regular.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CS 355 – Programming Languages
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Axiomatic Semantics Dr. M Al-Mulhem ICS
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Describing Syntax and Semantics
Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic.
Chapter 1: The Foundations: Logic and Proofs
Formal Logic Mathematical Structures for Computer Science Chapter Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic.
Reading and Writing Mathematical Proofs
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
MATH 224 – Discrete Mathematics
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
PREDICATES AND QUANTIFIERS COSC-1321 Discrete Structures 1.
Spring 2017 Program Analysis and Verification
Formal Methods in Software Engineering 1
B (The language of B-Method )
Lecture 5 Floyd-Hoare Style Verification
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Semantics In Text: Chapter 3.
Axiomatic Verification I
Predicate Transformers
Formal Methods in software development
Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP:
Axiomatic Verification I
Copyright © Cengage Learning. All rights reserved.
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
Copyright © Cengage Learning. All rights reserved.
CIS 720 Lecture 3.
CIS 720 Lecture 3.
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Mathematical Structures for Computer Science Chapter 1 Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Formal Logic

Proof of Correctness Program verification attempts to ensure that a computer program is correct. A program is correct if it behaves in accordance with its specifications. This does not necessarily mean that the program solves the problem that it was intended to solve; the program’s specifications may be at odds with or not address all aspects of a client’s requirements. Program validation attempts to ensure that the program indeed meets the client’s original requirements. Program testing seeks to show that particular input values produce acceptable output values. Proof of correctness uses the techniques of a formal logic system to prove that if the input variables satisfy certain specified predicates or properties, the output variables produced by executing the program satisfy other specified properties. Section 1.6 Proof of Correctness

Assertions Let us denote by X an arbitrary collection of input values to some program or program segment P. The actions of P transform X into a corresponding group of output values Y. The notation Y = P(X) suggests that the Y values depend on the X values through the actions of program P. A predicate Q(X) describes conditions that the input values are supposed to satisfy. Q is the precondition. A predicate R describes conditions that the output values are supposed to satisfy. These conditions will often involve the input values, so R has the form R(X, Y) or R[X, P(X)]. R is the postcondition. Section 1.6 Proof of Correctness

Assertions For example, if a program is supposed to find the square root of a positive number, then X consists of one input value, x, and Q(x) might be “x > 0.” If y is the single output value, then y is supposed to be the square root of x, so R(x, y) would be “y2 = x.” Program P is correct if the following implication is valid: ("X)(Q(X)  R[X, P(X)]) For the square root case, it is: ("x)(x > 0  [P(x)]2 = x ) The traditional program correctness notation (called a Hoare triple) is: {Q}P{R} Section 1.6 Proof of Correctness

Assertions A program or program segment is broken down into individual statements si, with predicates inserted between statements as well as at the beginning and end. These predicates are also called assertions because they assert what is supposed to be true about the program variables at that point in the program. {Q} s0 {R1} s1 {R2} sn1 . {R} Where Q, R1, R2, ... , Rn = R are assertions. The intermediate assertions are often obtained by working backward from the output assertion R. Section 1.6 Proof of Correctness

Assertions P is provably correct if each of the following implications holds: {Q}s0{Rl} {Rl}sl{R2} {R2}s2{R3} . {Rn1}sn1{R} A proof of correctness for P consists of producing this sequence of valid implications. Some new rules of inference can be used, based on the nature of the program statement si. Section 1.6 Proof of Correctness

Assignment Rule Suppose that statement si is an assignment statement of the form x = e for some expression e. The Hoare triple to prove correctness of this one statement has the form: {Ri} x = e {Ri + l}. For this triple to be valid, the assertions Ri and Ri +1 must be related in a particular way. The appropriate rule of inference for assignment statements is the assignment rule. It says that if the precondition and postcondition are appropriately related, the Hoare triple can be inserted at any time in a proof sequence without having to be inferred from something earlier in the proof sequence. It has the following conditions: si has the form x = e. Ri is Ri + 1 with e substituted everywhere for x. Section 1.6 Proof of Correctness

Assignment Rule For example, the Hoare triple: {x  1 > 0} x = x  1 {x > 0} is valid by the assignment rule. The postcondition is: x > 0 Substituting x  1 for x throughout the postcondition results in: x – 1 > 0 or x > 1 which is the precondition. Section 1.6 Proof of Correctness

Conditional Rule A conditional statement is a program statement of the form: if condition B then P1 else P2 end if A conditional rule of inference determines when a Hoare triple can be inserted in a proof sequence if si is a conditional statement. The Hoare triple is inferred from two other Hoare triples: {Q /\ B} P1 {R} if B is true {Q /\ B} P2 {R} if B is false This simply says that each branch of the conditional statement must be proved correct. Section 1.6 Proof of Correctness

Conditional Rule For example: We must prove: {n = 5} if n >= 10 then y = 100 else y = n + 1 end if {y = 6} We must prove: {n = 5 and n >= 10} y = 100 {y = 6} {n = 5 and n < 10} y = n + 1 {y = 6} Using the assignment rule we get: {n = 5} y = n + 1 {y = 6} {n = 5 and n < 10} y = n + 1 {y = 6} The conditional rule allows us to conclude that the program segment is correct. Section 1.6 Proof of Correctness