Section 1: Code Reasoning

Slides:



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

ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Reasoning About Code; Hoare Logic, continued
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Pre and Post Condition Rules Definition : If R and S are two assertions, then R is said to be stronger than S if R -> S (R implies S). –Example : the assertion.
1 University of Toronto Department of Computer Science © 2001, Steve Easterbrook Lecture 10: Formal Verification Formal Methods Basics of Logic first order.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
Partial correctness © Marcelo d’Amorim 2010.
Axiomatic Semantics The meaning of a program is defined by a formal system that allows one to deduce true properties of that program. No specific meaning.
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.
Simple Example {i = 0} j := i * i {j < 100} Can we ‘verify’ this triple? Only if we know the semantics of assignment.
1 Discrete Structures Lecture 29 Predicates and Programming Read Ch
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Predicate Transformers
Program Proving Notes Ellen L. Walker.
CSE 331 Software Design & Implementation Dan Grossman Winter 2014 Lecture 2 – Reasoning About Code With Logic 1CSE 331 Winter 2014.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CSE Winter 2008 Introduction to Program Verification symbolic execution continued.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION WORKSHEET A Autumn 2011 Today’s Process If you haven’t completed the solution sheet for Worksheet A, please leave.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
Axiomatic Semantics Dr. M Al-Mulhem ICS
ECI 2007: Specification and Verification of Object- Oriented Programs Lecture 1.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
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
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Section 1: Debugging + Code Reasoning Alex Mariakakis (staff-wide)
1 cs205: engineering software university of virginia fall 2006 Avoiding Software Disasters.
SECTION 2: CODE REASONING + PROGRAMMING TOOLS slides borrowed and adapted from Alex Mariakis and CSE 390a.
Reasoning about programs March CSE 403, Winter 2011, Brun.
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.
SECTION 1: CODE REASONING + VERSION CONTROL slides borrowed and adapted from Alex Mariakis and CSE 390a Justin Bare & Deric Pang.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 2 Formal Reasoning.
Hoare Logic LN chapter 5, 6 but without 6.8, 6.12, 6.13 (to be discussed later) Hoare Logic is used to reason about the correctness of programs. In the.
11/22/2016IT 3271 A formal system:Axioms and Rules, for inferring valid specification x := m; y := n; while ¬(x=y) do if x>y then x := x-y else y := y-x.
Rule of Sequential Composition
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
CSE 331 Software Design & Implementation
Formal Methods in Software Engineering 1
CSE 331 Software Design and Implementation
SECTION 1: CODE REASONING + VERSION CONTROL
Hoare-style program verification
Mathematical Structures for Computer Science Chapter 1
CSE 331 Software Design and Implementation
Reasoning About Code; Hoare Logic
Lecture 5 Floyd-Hoare Style Verification
Reasoning about Loops, Conclusion
Programming Languages and Compilers (CS 421)
CSE 331 Software Design and Implementation
Semantics In Text: Chapter 3.
Axiomatic Verification I
Formal Methods in software development
Predicate Transformers
Formal Methods in software development
IMPORTANT NOTE Some parts of these section slides deal with null ints. This was a mistake, as primitives cannot be null. These issues have been corrected.
Axiomatic Verification I
The Zoo of Software Security Techniques
Predicate Transforms I
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
50.530: Software Engineering
COP4020 Programming Languages
Presentation transcript:

Section 1: Code Reasoning cse331-staff@cs.washington.edu

Today’s Goals Review of code reasoning Practice forward and backward reasoning on straight-line and if-statement code Practice identifying the strongest assertion

Before we begin . . . “=” vs. “==” Read the lecture notes

Reasoning About Code Two purposes Prove our code is correct Understand why code is correct Forward reasoning: determine what follows from initial conditions Backward reasoning: determine sufficient conditions to obtain a certain result

Worksheet Problems 1 through 4 15 Minutes – get as far as you can You can collaborate with other students Grab a TA if you feel stuck

Forward Reasoning {x >= 0, y >= 0} y = 16; x = x + y x = sqrt(x) y = y - x {x >= 0, y = 16} {x >= 16, y = 16} {x >= 4, y = 16} {x >= 4, y <= 12}

Forward Reasoning {true} if (x > 0) { abs = x } else { abs = -x {x > 0, abs = x OR x <= 0, abs = -x} {abs = |x|}

Backward Reasoning {x + 3b - 4 > 0} a = x + b; c = 2b - 4 x = a + c {a + 2b – 4 > 0} {a + c > 0} {x > 0}

Backward Reasoning {y > 15 || (y <= 5 && y + z > 17)} if (y > 5) { x = y + 2 } else { x = y + z; {y > 15} {x > 17} {y + z > 17} {x > 17} {x > 17}

Implication Hoare triples are just an extension of logical implication Hoare triple: {P} S {Q} P → Q after statement S P Q P → Q T F T F Everything implies true False implies everything

Weaker vs. Stronger If P1 → P2, then P1 is stronger than P2 P2 is weaker than P1 Weaker statements are more general Stronger statements are more restrictive

Worksheet Problem 5

Worksheet “y > 23” “y >= 23” “y = 23” “y >= 23” “I attend quiz sections.” “I attend quiz sections on Thursdays.” “y > 23” “y >= 23” “y = 23” “y >= 23” “y < 0.00023” “y < 0.23” “y is prime” “y <= 17”

Worksheet “y > 23” “y >= 23” “y = 23” “y >= 23” “I attend quiz sections.” “I attend quiz sections on Thursdays.” “y > 23” “y >= 23” “y = 23” “y >= 23” “y < 0.00023” “y < 0.23” “y is prime” “y <= 17”

Worksheet “y > 23” “y >= 23” “y = 23” “y >= 23” “I attend quiz sections.” “I attend quiz sections on Thursdays.” “y > 23” “y >= 23” “y = 23” “y >= 23” “y < 0.00023” “y < 0.23” “y is prime” “y <= 17”

Worksheet “y > 23” “y >= 23” “y = 23” “y >= 23” “I attend quiz sections.” “I attend quiz sections on Thursdays.” “y > 23” “y >= 23” “y = 23” “y >= 23” “y < 0.00023” “y < 0.23” “y is prime” “y <= 17”

Worksheet “y > 23” “y >= 23” “y = 23” “y >= 23” “I attend quiz sections.” “I attend quiz sections on Thursdays.” “y > 23” “y >= 23” “y = 23” “y >= 23” “y < 0.00023” “y < 0.23” “y is prime” “y <= 17”

Worksheet “y > 23” “y >= 23” “y = 23” “y >= 23” “I attend quiz sections.” “I attend quiz sections on Thursdays.” “y > 23” “y >= 23” “y = 23” “y >= 23” “y < 0.00023” “y < 0.23” “y is prime” “y <= 17” -- ?

Weakest Precondition The most lenient assumptions such that a postcondition will be satisfied If P* is the weakest precondition for {P} S {Q}, then P → P* for all P that make the Hoare triple valid Notation: WP = wp(S, Q)

Weakest Precondition wp(x = y*y, x > 4)

Weakest Precondition wp(x = y*y, x > 4) |y| > 2

Weakest Precondition wp(x = y*y, x > 4) |y| > 2 wp(y = x+1;z = y-3, z = 10)

Weakest Precondition wp(x = y*y, x > 4) wp(y = x+1;z = y-3, z = 10) wp(y = x+1, wp(z = y-3, z = 10)) wp(y = x+1, y-3 = 10) wp(y = x+1, y = 13) x = 12

Questions