Proving termination conditions Name Country, City, University Omer Subasi Turkey, Istanbul, Koc University Anton Dergunov

Slides:



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

Introduction to Recursion and Recursive Algorithms
Semantics Static semantics Dynamic semantics attribute grammars
Reasoning About Code; Hoare Logic, continued
11111 Functional Program Verification CS 4311 A. M. Stavely, Toward Zero Defect Programming, Addison-Wesley, Y. Cheon and M. Vela, A Tutorial on.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
© M. Winter COSC 4P41 – Functional Programming Testing vs Proving Testing –uses a set of “typical” examples, –symbolic testing, –may find errors,
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.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CS 355 – Programming Languages
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Proving the Correctness of Algorithms Algorithm Design and Analysis Week 2
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Firewall Policy Queries Author: Alex X. Liu, Mohamed G. Gouda Publisher: IEEE Transaction on Parallel and Distributed Systems 2009 Presenter: Chen-Yu Chang.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
© Love Ekenberg The Algorithm Concept, Big O Notation, and Program Verification Love Ekenberg.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
4/17/2017 Section 3.6 Program Correctness ch3.6.
Chapter 11: Limitations of Algorithmic Power
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Describing Syntax and Semantics
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Proving Program Correctness The Axiomatic Approach.
Induction and recursion
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
CS 363 Comparative Programming Languages Semantics.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Algorithm Design.
Recursive Algorithms &
Reasoning about programs March CSE 403, Winter 2011, Brun.
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.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
1 Proving program termination Lecture 5 · February 4 th, 2008 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A.
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Chapter 3 of Programming Languages by Ravi Sethi
Reasoning about code CSE 331 University of Washington.
Formal Methods in Software Engineering 1
Lecture 5 Floyd-Hoare Style Verification
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Over-Approximating Boolean Programs with Unbounded Thread Creation
Semantics In Text: Chapter 3.
Predicate Transformers
Functional Program Verification
Programming Languages and Compilers (CS 421)
Presentation transcript:

Proving termination conditions Name Country, City, University Omer Subasi Turkey, Istanbul, Koc University Anton Dergunov Russia, Nizhny Novgorod, UNN Krasnoshtan Dmytro Ukraine, Kiev, KPI Georgiy Savchenko Russia, Krasnoyarsk, Siberian federal university Pavel Ajtkulov Russian, Izhevsk, Udmurt State University Mentor: Dr. Ben Livshits & Dr. Stephan Tobies

The Project The aim: – Investigate state of the art approaches for termination proof; – Prove termination of sample algorithms. We focused on the following cases: – Nested loops; – Recursion; – Linked list data structures. 2

Termination A program is terminating if all its executions of all its executions are finite. A program is non-terminating it there exits at least one infinite execution. 3

Motivation Functional correctness + termination proof = Total correctness The halting problem: termination is undecidable (Alan Turing). Does not mean we can’t not prove termination in every case. We can prove termination via introducing termination metrics (ranking functions). 4

Termination proof in Dafny Dafny is a programming language and verifier that enables to prove terminations of algorithms. Dafny provides annotations to specify termination metrics Many verifiers do not support termination proofs us/projects/dafny/ 5

Dafny Approach-Formalism Let U be a non-empty set of disjoint union of algebraic datatypes, tuples and variables. Algebraic datatypes: sets, sequences, lists. Let S be set of states of program. Let (Y,>=) be a well-ordered set. For instance, ℕ is a well-ordered set. 6

Formalism Cont. Define metric φ:UxS  Y such that – For ∀ transition (s,s’), φ(u,s)> φ(u,s’) – For ∀ state s, ∀ u in U, φ(u,s)>=0 – ∃ δ>0 such that for ∀ transition (s,s’) and ∀ u in U, φ(u,s)> φ(u,s’)+δ Usually this mapping is called progress measure or ranking function 7

Node #1 ReachableNodes: {1, 2, 3, 4, 5} Node #3 ReachableNodes: {3} Node #2 ReachableNodes: {2, 4, 5} Node #4 ReachableNodes: {4} Node #5 ReachableNodes: {5} method Find(x: int): returns (found:bool) decreases ReachableNodes; { if (x == data) {found := true;} else if (left != null && x < data) {found := left.Find(x);} else if (right != null && x > data) {found := right.Find(x);} else {found := false;} }

Other Approaches Compose termination arguments since constructing a ranking function can be difficult Decompose the termination check into easier ones Terminator us/um/cambridge/projects/terminator/ development of automatic methods for proving program termination and general liveness propertieshttp://research.microsoft.com/en- us/um/cambridge/projects/terminator/ 9

Our Contribution Proved termination of several Dafny programs: – QuickSort – MergeSort – Insertion sort – Insertion and search for binary search tree We have investigated state of art for termination proof. Idea: reusing termination metric to prove computational complexity of algorithms. 10

What we have learned More in-depth understanding of formal verification. Got information about proving termination properties. Got additional insights how complexity analysis can be implemented by reusing termination metric. What remains to be done 11

Thank you! Questions? 12

Possible tools partial correctness + termination = total correctness partial correctness + time > total correctness VCC provides only partial correctness Other tools: -Code contracts -Dafny -f* -spec# 13

Why dafny It is imperative, sequential, supports generic classes and dynamic allocation, and builds in specification constructs. Also -Updatable ghost variables -Recursive functions -Proof of total correctness -Types like algebraic datatypes (sets, sequences) 14

Principles of termination by Byron Cook A program is terminating if all its executions are finite. A program is non-terminating it there exits at least one infinite execution. When trying to prove termination, one tries to prove program’s transition relation is well-founded. Turing’s suggestion for proving well-foundedness: Find a map form (R,S) to a well-ordered set and then prove this map is a homomorphism. These maps are typically ranking functions. Constructing a ranking function can be difficult: Compose termination arguments. Another idea: Decompose the termination check into easier ones. 15

Notation {P}C{Q} : partial correctness [P]C[Q] : total correctness Problems with: -While loop ( for is alias in C-like languages) -Recursion -Function invocation 16

Total Correctness Specification A total correctness specification [P]C[Q] true if -Whenever C is executed in a state satisfying P, then the execution of C terminates -After C terminates Q holds With the exception of the WHILE, FOR loops, recursion and function invocation, all the axioms and rules described so far are sound for total correctness as well as partial correctness 17

Rules for Non-Looping Command Replace { and } by [ and ], respectively, in: - Assignment axiom - Consequence rules - Conditional rules - Sequencing rule - Block rule 18

Total Correctness Assignment Axiom - Assignment axiom for total correctness: Ⱶ [P [E/V ]] V := E [P ] -Note that the assignment axiom for total correctness states that assignment commands always terminate -So all function applications in expressions must terminate -This might not be the case if functions could be defined recursively EXAMPLE: X := fact(-1), where fact(n) = if n = 0 then 1 else n * fact(n - 1) 19

WHILE Rule for Total Correctnes -WHILE commands are the only commands that can cause non-termination -The idea behind the WHILE rule for total correctness is: 1) to prove WHILE S DO C terminates 2) show that some non-negative quantity decreases on each iteration of C 3) this decreasing quantity is called a variant 20

WHILE Rule for Total Correctness 21

Derived rules Multiple step rules for total correctness can be derived in the same way as for partial correctness -The rules are the same up to the brackets used -Same derivations with total correctness rules replacing partial correctness ones 22

Example 3: ghost data class ListNode { var data: int; var next: ListNode; ghost var reachableNodes: set ; //... function sum(): int reads *; decreases reachableNodes; { if next == null then data else data + next.Sum() } 23

Example 1: no termination proof is required method processArray(numbers: array ) requires numbers != null; { var i := 0; var sum := 0; while (i < numbers.Length) { sum := sum + numbers[i]; i := i + 1; } 24

Dafny programs that we have proved Termination of: QuickSort MergeSort Insertion and search for binary search tree TODO: outline the most interesting aspects of these programs 25