CSE 3341.03 Winter 2008 Introduction to Program Verification refining an interface.

Slides:



Advertisements
Similar presentations
A Framework for describing recursive data structures Kenneth Roe Scott Smith.
Advertisements

CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
Chao Liu, Chen Chen, Jiawei Han, Philip S. Yu
Pointers.
Linked Lists.
Data Structures ADT List
AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
Linked List 1. Introduction to Linked List 2. Node Class 3. Linked List 4. The Bag Class with Linked List.
TA C252 Computer Programming 13/8/03Sundar B. BITS, Pilani.1 Todays Agenda 1. Data Abstraction 2. Linear Data.
FIFO Queues CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
CSE Lecture 12 – Linked Lists …
1 Symbol Tables Chapter Sedgewick. 2 Symbol Tables Searching Searching is a fundamental element of many computational tasks looking up a name.
Review Pseudo Code Basic elements of Pseudo code
Copyright 2008 by Pearson Education 1 Nested loops reading: 2.3 self-check: exercises: videos: Ch. 2 #4.
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 10 SHARED MEMORY.
Techniques for proving programs with pointers A. Tikhomirov.
Compiler construction in4020 – lecture 2 Koen Langendoen Delft University of Technology The Netherlands.
The University of Adelaide, School of Computer Science
Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
50.530: Software Engineering Sun Jun SUTD. Week 10: Invariant Generation.
Chapter 17 Templates. Generic Algorithms Algorithms in which the actions or steps are defined, but the data types of the items being manipulated are not.
CSCI 160 Midterm Review Rasanjalee DM.
Ch 8. Characters and Strings Timothy Budd 2 Characters and Literals Strings Char in C++ is normally an 8-bit quantity, whereas in Java it is a 16-bit.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
CSE Winter 2008 Introduction to Program Verification symbolic execution continued.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Polymorphism Chapter six of: Szyperski, Clemens et al. Component Software - Beyond Object-Oriented Programming. Second Edition.
Priority Queues, Heaps & Leftist Trees
19-Aug-15 Simple Recursive Algorithms. 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking.
Component-Based Software Engineering Components and Interfaces Paul Krause.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
SAK 3117 Data Structures Chapter 3: STACKS. Objective To introduce: Stack concepts Stack operations Stack applications CONTENT 3.1 Introduction 3.2 Stack.
Effective Java: Generics Last Updated: Spring 2009.
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
AP Comp Sci A Chapter 12 - Arrays. Ch 12 Goals: Goals: Declare and create arrays Declare and create arrays Access elements in arrays Access elements in.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
30 May Stacks (5.1) CSE 2011 Winter Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
CSE Winter 2008 Introduction to Program Verification January 15 tautology checking.
Tail Recursion l The case in which a function contains only a single recursive call and it is the last statement to be executed in the function. l Tail.
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
ITI Introduction to Computing II Lab-5 Dewan Tanvir Ahmed University of Ottawa.
Dynamic Programming & Memoization. When to use? Problem has a recursive formulation Solutions are “ordered” –Earlier vs. later recursions.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
CS 46B: Introduction to Data Structures July 23 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
There’s a particular style to it… Rob Hatton
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
BlueJ Tester By Pepper.
Decisions Chapter 4.
CSE 501N Fall ‘09 08: Control Flow
Introduction to C++ Programming
Chapter 1: Computer Systems
BlueJ Tester By Pepper.
C Programming Getting started Variables Basic C operators Conditionals
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Lecture No.02 Data Structures Dr. Sohail Aslam
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

CSE Winter 2008 Introduction to Program Verification refining an interface

Exercise 7.2, 7.3(b) why all the complexity in the switch statement? language supports optimization -> complexity -> confusing logic -> harder to understand and verify is the complexity necessary? no: push it into an optimizing compiler

simpler switch to get the best of both worlds: we could code the switch statement in an unoptimized form with redundant statements so every case ends in a break annotate this with simpler conjunction of implications translate it into an optimized form, using break to eliminate the redundancies

7.2 Interfaces /* * If the object doesn't exist, add the object and return null, otherwise replace the * first object that matches and return the old object. object The object to add. Set#get */ public Object put(Object object);

Exercise 7.6 get(Object) = null and put(Object) = null and S = oldS union {Object} or remove(get(Object)) and put(Object) = get(Object)

7.3 refining an interface an easy case: the refinement extends the pre-condition (allowing more initial states) the new post-condition is a special case of the old.

proof obligations for refined interface verify that Pre implies Pre new and Post new implies Post

more complex refinement what needs to be verified? new code

refinement example TextModel, p write inserts a character into or at the end of a text array BetterTextModel, p write inserts a character into or after the end of a text array, filling any gap with blanks

TextModel interface interface TextModel { void write (int pos, char ch); // insert char ch at position pos within the existing text. // pre-condition: //{ len = 'this.length'(nil) and txt = ‘this.text’(nil) and (0<= i < len implies 'this.read'(i) = array(txt,i)) and len < 'this.max'(nil)' and 0 <= pos <= len } // post-condition: //{ 'this.length'(nil) = len + 1 and (0 <= i < pos implies 'this.read'(i) = array(txt,i)) and 'this.read'(pos) = ch and pos < i < 'this.length'(nil) implies 'this.read'(i) = array(txt, i-1) }

BetterTextModel interface BetterTextModel { // pre-condition: //{ len = 'this.length'(nil) and txt = ‘this.text’(nil) and (0<= i < len implies 'this.read'(i) = array(txt,i)) and len < 'this.max'(nil) and 0 <= pos <= 'this.max'(nil) } // post-condition: //{ 'this.length'(nil) = max(len, pos) + 1 and (0 <= i < min(pos, len) implies array(txt, i) = 'this.read'(i)) and 'this.read'(pos) = ch and (pos < i < 'this.length'(nil) implies 'this.read'(i) = array(txt, i-1)) and (len < i < pos implies 'this.read'(i) = " ") }

Exercise 7.8 Given that the TextModel pre-condition holds, what is the (descriptive) post- condition when BetterTextModel's write(pos, ch) method is executed? min(pos, len) = pos and max(len, pos) = len and.. BetterTextModel's post-condition..

Well-behaved expressions BetterTextModel requires that the array length len < this.max problem: what ensures that this.max ≤ available addressable memory? very simple example (p. 14): int n1 = Integer.MAX_VALUE; int n2; n2 = n1 + 1; //{ n2 = n1 + 1}

assume all expressions are well-behaved given the code int n1; int n2; n2 = n1 + n2; //{ n2 = n1 + n2} we can only assume that n1 + n2 are "well- behaved", i. e. n1+ n2 ≤ Integer.MAX_VALUE so that the post-condition //{ n2 = n1 + n2} holds

partial functions another source of qualifications or restrictions: partial functions restricting variables to the domain of a function requires a pre-condition to be satisfied before the function is called. if we don’t want to have the code check every division operation (or top(stack) or rest(list) or a[i]) to see if the function is defined, we need a proof that the variable is "in bounds"