11.6.2015 Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.

Slides:



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

Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Nov 10, Fall 2009IAT 8001 Binary Search Sorting. Nov 10, Fall 2009IAT 8002 Search  Often want to search for an item in a list  In an unsorted list,
Qualitätssicherung von Software (SWQS) Prof. Dr. Holger Schlingloff Humboldt-Universität zu Berlin und Fraunhofer FOKUS : Modellprüfung II - BDDs.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Information Security of Embedded Systems : Public Key Cryptosystems, Communication Prof. Dr. Holger Schlingloff Institut für Informatik und Fraunhofer.
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
Fall 2008 Insertion Sort – review of loop invariants.
VS 3 : Verification and Synthesis using SMT Solvers SMT Solvers for Program Verification Saurabh Srivastava * Sumit Gulwani ** Jeffrey S. Foster * * University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 11 Sorting and Searching.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
1.7 Arrays academy.zariba.com 1. Lecture Content 1.Basic Operations with Arrays 2.Console Input & Output of Arrays 3.Iterating Over Arrays 4.List 5.Cloning.
Lecture 2 MAS 714 Hartmut Klauck
Algorithmics - Lecture 21 LECTURE 2: Algorithms description - examples -
1 Data Structures and Algorithms Sorting. 2  Sorting is the process of arranging a list of items into a particular order  There must be some value on.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Reading and Writing Mathematical Proofs
Software Verification 2 Automated Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität and Fraunhofer Institut für.
Software Verification 2 Automated Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität and Fraunhofer Institut für.
Jessie Zhao Course page: 1.
26 Sep 2014Lecture 3 1. Last lecture: Experimental observation & prediction Cost models: Counting the number of executions of Every single kind of command.
MS 101: Algorithms Instructor Neelima Gupta
Searching. The process used to find the location of a target among a list of objects Searching an array finds the index of first element in an array containing.
Examples using Arrays. Summing Squares Problem: To compute the sum of the squares of N numbers N is given N values are also given These should be read.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 11 Sorting and Searching.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Software Verification 2 Automated Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität and Fraunhofer Institut für.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
Algorithmics - Lecture 61 LECTURE 6: Analysis of sorting methods.
Selection Sort main( ) { int a[ ] = { 17, 6, 13,12, 2 } ; int i, j, t ; for ( i = 0 ; i
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Dr. Naveed Riaz Design and Analysis of Algorithms 1 1 Formal Methods in Software Engineering Lecture # 26.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Software Verification 2 Automated Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität and Fraunhofer Institut für.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Dr. Sajib Datta CSE 1320 Arrays, Search and Sort.
1 Computer Algorithms Tutorial 2 Mathematical Induction Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Software Verification 2 Automated Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität and Fraunhofer Institut für.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
Data Structures I (CPCS-204) Week # 5: Recursion Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Unit – 5: Backtracking For detail discussion, students are advised to refer the class discussion.
ALGORITHMS PROVING ALGORITHMS (PROGRAMS) CORRECT WITH AND WITHOUT INDUCTION.
SS 2017 Software Verification Bounded Model Checking, Outlook
Software Verification 2 Automated Verification
SS 2017 Software Verification Software Model Checking 2 - Parallelism
CS 3343: Analysis of Algorithms
SS 2018 Software Verification LTL Satisfiability applied
SS 2017 Software Verification CTL model checking, BDDs
SS 2017 Software Verification Tableaus, CTL model checking
Software Verification 2 Automated Verification
Axiomatic Verification II
Software Verification 2 Automated Verification
Axiomatic Verification II
§2 Basic Computability Theory
Presentation transcript:

Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut für offene Kommunikationssysteme FOKUS

Folie 2 H. Schlingloff, Software-Verifikation I Invariably: Starter Questions … What is an invariant? How is it used in verification? Is the set of invariants of a loop recursive? … or recursively enumerable? Is there any decidable invariant? How to construct an invariant for a given loop? E.g. {i=0; while (i<n) {i++}} E.g. {i=0; while (i<n) {i++; j--}} E.g. {i=0; while (i<n) {i++; j+=i}}

Folie 3 H. Schlingloff, Software-Verifikation I While [] -Programs While-Programs are Turing-complete, but not very convenient to use Missing: arrays, pointers, data structures, functions & procedures, modules, inheritance, … Today: arrays and search Introduce array type X[n], where X is any type and n is any integer set V [] of indexed program variables: if i is a program variable of type Int and a is an array variable of type X[n], then a[i] is an indexed program variable of type X while [] Prog: Indexed program variables can be used in terms and expressions wherever “normal” program variables are allowed Semantics: An array variable a: X[n] is evaluated as a partial function V( a ): Int  X  {undef} V( a )(x) = undef if x < 0 or x ≥ n V( a[i] ) = V( a ) (V( i ))

Folie 4 H. Schlingloff, Software-Verifikation I Example: Binary Search Input: a sorted array x:Int[n] (i.e.,  i (x[i-1]<x[i]) ) and a value a to search for Result: index i s.t. x[j] =a for i<=j<n  : i=0; k=n; while (i<k) { s=(i+k-1)/2; // integer division if (a>x[s]) i=s+1 else k=s }  : i=0; k=n; while (i<k) { s=(i+k-1)/2; // integer division if (a>x[s]) i=s+1 else k=s } Correctness: Show {n>=0   i(0<i<n  (x[i-1]<x[i])}  {0 =a} >=a<a x: i >=a<a x: iks

Folie 5 H. Schlingloff, Software-Verifikation I Invariant for Binary Search x is sorted   0 :  i(0<i<n  (x[i-1]<x[i]) i is changed such that   1 : 0<=i<=n   j(0<=j<i  x[j]<a) k is changed such that   2 : 0 =a) additionally   3 : i<=k Let  =  0   1   2   3

Folie 6 H. Schlingloff, Software-Verifikation I Hoare Proof for Binary Search {n>=0   i(0<i<n  (x[i-1]<x[i])} i=0; k=n; {  } while (i<k) { {   i<k} s=(i+k-1)/2; //integer division if (a>x[s]) i=s+1 else k=s {  } } {   i>=k} {i=k  0 =a)} {0 =a)}

Folie 7 H. Schlingloff, Software-Verifikation I  : 0 =a) {   i<k} s=(i+k-1)/2; {   i<k  s==(i+k-1)/2} if (a>x[s]) i=s+1 else k=s {  } holds since {   i x[s]} {  [i:=s+1]} i=s+1 {  } {   i<k  s==(i+k-1)/2  a<=x[s]} {  [k:=s]} k=s {  } proof: see next

Folie 8 H. Schlingloff, Software-Verifikation I  : 0 =a) Show:   i<k  s=(i+k-1)/2  x[s]<a   [i:=s+1]   i<k  s=(i+k-1)/2  x[s]<a  0<= s+1 <= k <= n   j(0<=j< s +1  x[j]<a)   i<k  s=(i+k-1)/2  x[s]<a  (i+k+1)/2 <= k   j(0<=j<= (i+k-1)/2  x[j]<a) holds since i<k  i+k<k+k  i+k+1<=2*k  (i+k+1)/2<=k x[s]<a  j=s  x[j]<a  0  x[s]<a  j<s  x[j]<a

Folie 9 H. Schlingloff, Software-Verifikation I Haha Binary Search in Haha

Folie 10 H. Schlingloff, Software-Verifikation I Last Example: Bubblesort Given an array x [0..n-1] of integers, the task is to sort x Bubblesort repeatedly exchanges “unordered” elements in x, e.g.:  6 – 3 – 8 – 4 – 1  3 – 6 – 8 – 4 – 1  3 – 6 – 4 – 8 – 1  3 – 6 – 4 – 1 – 8  3 – 4 – 6 – 1 – 8  3 – 4 – 1 – 6 – 8  3 – 1 – 4 – 6 – 8  etc.

Folie 11 H. Schlingloff, Software-Verifikation I Bubblesort Algorithm  :  : i=n;  : while (i>1) {  : i=i-1; k=0;  : while (k!=i){  : k++;  : if (x[k-1]>x[k]) swap(x[k-1], x[k])  : }  : }  :

Folie 12 H. Schlingloff, Software-Verifikation I Specification of Sortedness x is sorted  sorted(x):  i(0<i<n  x[i-1] <= x[i]) x is a permutation of the input array ? For sake of simplicity:  assume all elements in x are pairwise unequal: diff(x):  i,j(0<=i != j<n  (x[i]!=x[j])}  in this case, x is a permutation of y iff perm(x,y):  a(  i x[i]==a   i y[i]==a) Specification {x==y  diff(x)}  {sorted(x)  perm(x,y)}

Folie 13 H. Schlingloff, Software-Verifikation I Invariant for Bubblesort Invariant for loop at  : after first iteration: x[n-1] at correct position after second iteration: x[n-1] and x[n-2] at correct position after third iteration: x[n-1].. x[n-3] at correct position... ordered(x, i):1<=i<=n   j(i<=j<n  x[j-1] < x[j])   j(0<=j<i <n  x[j] <= x[i]) then we have:  ordered(x, n)  T  ordered(x, 1)  sorted(x) I  : diff(x)  perm(x,y)  ordered(x,i)

Folie 14 H. Schlingloff, Software-Verifikation I Proof of Outer Loop x==y  diff(x)  perm(x,y)  : x==y  diff(x)   : x==y  diff(x)  i==n x==y  diff(x)  i==n  diff(x)  perm(x,y)  ordered(x,i)  : x==y  diff(x)   : I   : I    : I   (i 1)   : I  perm(x,y)  ordered(x,i)  (i<=1)  perm(x,y)  sorted(x)  : I    : sorted(x)  perm(x,y)  : x==y  diff(x)   : perm(x,y)  sorted(x) that is, {x==y  diff(x)}  {sorted(x)  perm(x,y)}

Folie 15 H. Schlingloff, Software-Verifikation I Inner Invariant It remains to show:  : I   (i>1)   : I  Invariant for loop at  : perm(x,y)  ordered(x,i+1) remains stable goal of the inner loop: maximal element from x[0]...x[i-1] is moved to x[i-1] after each step: 0 =x[j]) I  : perm(x,y)  ordered(x,i+1)  0 =x[j])

Folie 16 H. Schlingloff, Software-Verifikation I Proof of Inner Invariant  : I   (i>1)   : perm(x,y)  ordered(x,i+1)  k==0 perm(x,y)  ordered(x,i+1)  k==0  I   : I   (i>1)   : I   : I    : I   (k==i), provided that  : I   (k!=i)   : I  I   (k==i)  perm(x,y)  ordered(x,i+1)   j(0 =x[j])  : I   (i>1)   : I  it remains to show:  : I   (k!=i)   : I  perm(x,y) remains unchanged ordered(x,i+1) is not modified  : 0 =x[j])  k!=i   : 0 =x[j])  : I   (k!=i)   : 0 =x[j])