CIS 540 Principles of Embedded Computation Spring 2016 Instructor: Rajeev Alur

Slides:



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

CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Reasoning About Code; Hoare Logic, continued
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
1 Chapter Six Algorithms. 2 Algorithms An algorithm is an abstract strategy for solving a problem and is often expressed in English A function is the.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 13.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
ISBN Chapter 3 Describing Syntax and Semantics.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Lecture 2: Reasoning with Distributed Programs Anish Arora CSE 6333.
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
Induction Sections 41. and 4.2 of Rosen Fall 2008 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
Model Checking. Used in studying behaviors of reactive systems Typically involves three steps: Create a finite state model (FSM) of the system design.
Discrete Structures Chapter 2 Part B Mathematical Induction
Describing Syntax and Semantics
School of Computer ScienceG53FSP Formal Specification1 Dr. Rong Qu Introduction to Formal Specification
Chapter 4: A Universal Program 1. Coding programs Example : For our programs P we have variables that are arranged in a certain order: Y 1 X 1 Z 1 X 2.
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Instructor: Rajeev Alur
Reading and Writing Mathematical Proofs
Benjamin Gamble. What is Time?  Can mean many different things to a computer Dynamic Equation Variable System State 2.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
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.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Incremental formal verification of hardware Hana Chockler Alexander Ivrii Arie Matsliah Shiri Moran Ziv Nevo IBM Research - Haifa.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Recursive Algorithms &
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Program correctness The State-transition model A global states S  s 0 x s 1 x … x s m {s k = set of local states of process k} S0  S1  S2  Each state.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
More on Correctness. Prime Factorization Problem: Write a program that computes all the prime factors of a given number Solution (Idea): Factors are less.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
This Week Lecture on relational semantics Exercises on logic and relations Labs on using Isabelle to do proofs.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
From Natural Language to LTL: Difficulties Capturing Natural Language Specification in Formal Languages for Automatic Analysis Elsa L Gunter NJIT.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Application: Algorithms Lecture 19 Section 3.8 Tue, Feb 20, 2007.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Advanced Algorithms Analysis and Design
Model Checking Rajeev Alur.
Instructor: Rajeev Alur
CSE 311 Foundations of Computing I
Lectures on Network Flows
Autonomous Cyber-Physical Systems: Basics of Verification
Autonomous Cyber-Physical Systems: Dynamical Systems
ITEC452 Distributed Computing Lecture 5 Program Correctness
Advanced Analysis of Algorithms
Program correctness Axiomatic semantics
Presentation transcript:

CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur

Requirements  Requirement: Desirable property of the executions of the system  Informal: Either implicit, or stated in English in documents  Formal: Stated explicitly in a mathematically precise manner  High assurance / safety-critical systems: Formal requirements  Model/design/system meets the requirements if every execution satisfies all the requirements  Clear separation between requirements (what needs to be implemented) and system (how it is implemented)  Verification problem: Given a requirement  and a system/model C, prove/disprove that the system C satisfies the requirement  CIS 540 Spring 2016; Lecture Feb 3

Safety Requirements  A safety requirement states that a system always stays within “good’ states (i.e. a nothing bad ever happens)  Leader election: it is never the case that two nodes consider them to be leaders  Collision avoidance: Distance between two cars is always greater than some minimum threshold  Different class of requirements: Liveness  System eventually attains its goal  Leader election: Each node eventually makes a decision  Cruise controller: Actual speed eventually equals desired speed  Formalization and analysis techniques for safety and liveness differ significantly, so let us first focus on safety CIS 540 Spring 2016; Lecture Feb 3

Transition Systems States+ Transitions between states+ Initial states CIS 540 Spring 2016; Lecture Feb 3

Definition of Transition System  Syntax: a transition system T has 1.a set S of (typed) state variables 2.Initialization Init for state variables 3.Transition description Trans given by code to update state vars  Semantics: 1.Set Q S of states 2.Set [Init] of initial states (this is a subset of Q S ) 3.Set [Trans] of transitions, subset of Q S x Q S  Synchronous reactive components, programs, and more generally systems, all have an underlying transition system CIS 540 Spring 2016; Lecture Feb 3

Transition System for Switch Example offon int x:=0 (press=0) ? (press=1) ? (press=0 & x<10)  x:=x+1 (press=1 | x>=10)  x:=0 State variables: {off, on} mode, int x (off,0) (off, 17) (on, 2) (on, 56) Initialization: mode = off; x = 0 Transitions: (off,n) -> (off,n); (off,n) -> (on,n); (on,n) -> (on,n+1) if n<10; (on,n) -> (off,0) (on, 3) (on, 0) (on, 17) Input/output variables become local Values for input vars chosen nondeterministically CIS 540 Spring 2016; Lecture Feb 3

Euclid’s GCD Algorithm Classical program to compute greatest common divisor of (non-negative) input numbers m and n loopstop nat x:=m; y:=n (x>0 & y>0)  if (x>y) then x:=x-y else y:=y-x ~ (x>0 & y>0)  if (x=0) then x:=y CIS 540 Spring 2016; Lecture Feb 3

Reachable States offon int x:=0 (press=0) ? (press=1) ? (press=0 & x<10)  x:=x+1 (press=1 | x>=10)  x:=0 (off, 17) (on, 1) (on, 56) (on, 10) (off,0) (on, 0) (on, 17) CIS 540 Spring 2016; Lecture Feb 3

Reachable States of Transition Systems A state s of a transition system is reachable if there is an execution starting in an initial state and ending in the state s CIS 540 Spring 2016; Lecture Feb 3

Invariants (off, 17) (on, 1) (on, 56) (on, 10) (off,0) (on, 0) (on, 17) (off, 10)  Property of a transition system: Boolean-valued expression  over state variables  Property  is an invariant of T if every reachable state satisfies   Examples of invariants: (x x=0 )  Examples of properties that are not invariants: (x < 10); (mode=off) CIS 540 Spring 2016; Lecture Feb 3

Invariants  Express desired safety requirement as property  of state variables  If  is an invariant then the system is safe  If  is not an invariant, then some state satisfying ~  is reachable (execution leading to such a state is counterexample)  Leader election: (r n = N -> id n = max P), where P is set of identifiers of all nodes  Euclid’s GCD Program: (mode=stop -> x = gcd(m,n)) CIS 540 Spring 2016; Lecture Feb 3

Formal Verification Model/Program Requirement yes/proof no/bug Verifier Grand challenge: Automate verification as much as possible ! CIS 540 Spring 2016; Lecture Feb 3

Analysis Techniques  Dynamic Analysis (runtime)  Execute the system, possibly multiple times with different inputs  Check if every execution meets the desired requirement  Static Analysis (design time)  Analyze the source code or the model for possible bugs  Trade-offs  Dynamic analysis is incomplete, but accurate (checks real system, and bugs discovered are real bugs  Static analysis can catch design bugs early !  Many static analysis techniques are not scalable (solution: analyze approximate versions, can lead to false warnings) CIS 540 Spring 2016; Lecture Feb 3

Invariant Verification  Simulation  Simulate the model, possibly multiple times with different inputs  Easy to implement, scalable, but no correctness guarantees  Proof based  Construct a proof that system satisfies the invariant  Requires manual effort (partial automation possible)  State-space analysis (model checking)  Algorithm explores “all” reachable states to check invariants  Not scalable, but current tools can analyze many real-world designs (relies on many interesting theoretical advances) CIS 540 Spring 2016; Lecture Feb 3

Proving Invariants  Given a transition system (S, Init, Trans) and a property , prove that all reachable states of T satisfy   Inductive definition of reachable states  All initial states are reachable using 0 transitions  If a state s is reachable in k transitions and (s,t) is a transition, then the state t is reachable in (k+1) transitions  Reachable = Reachable in n transitions, for some n  Prove: for all n, states reachable in n transitions satisfy   Base case: Show that all initial states satisfy   Inductive case: Assume that a state s satisfies  Show that if (s,t) is a transition then t must satisfy  CIS 540 Spring 2016; Lecture Feb 3

Recap: Inductive Proofs  To show that a statement P holds for all numbers n,  Base case: Prove that P holds for n=0  Assume that P holds for an arbitrary number k  Prove (using the assumption) that the statement holds for k+1  Example statement: For all n, ( … + n) = n(n+1)/2 CIS 540 Spring 2016; Lecture Feb 3

Inductive Invariant  A property  is an inductive invariant of transition system T if 1.Every initial state of T satisfies  2.If a state satisfies  and (s,t) is a transition of T, then t must satisfy   If  is an inductive invariant, then all reachable states of T must satisfy , and thus, it is an invariant CIS 540 Spring 2016; Lecture Feb 3

Proving Inductive Invariant Example (1)  Consider transition system T given by  State variable int x, initialized to 0  Transition description given by “if (x < m) then x:=x+1”  Is the property  : (0 <= x <= m) an inductive invariant of T ?  Base case: Consider initial state (x=0). Check that it satisfies   Inductive case:  Consider an arbitrary state s, suppose s(x) = a  Assume that s satisfies , that is, assume 0 <= a <=m  Consider the state t obtained by executing a transition from s  If a < m then t(x) = a+1, else t(x) = a  In either case, 0 <= t(x) <= m  So t satisfies the property , and the proof is complete CIS 540 Spring 2016; Lecture Feb 3

Proving Inductive Invariant Example (2)  Consider transition system T given by  State variables int x, y; x is initially 0, y is initially m  Transition description given by “if (x < m) then {x:=x+1; y:=y-1}”  Is the property  : (0 <= y <= m) an inductive invariant of T ?  Base case: Consider initial state (x=0,y=m). Check that it satisfies   Inductive case:  Consider an arbitrary state s with x=a and y=b  Assume that s satisfies , that is, assume 0 <= b <=m  Consider the state t obtained by executing a transition from s  If a < m then t(y) = b-1, else t(y) = b  Can we conclude that 0 <= t(y) <= m ?  No! The proof fails! In fact,  is not an inductive invariant of T! CIS 540 Spring 2016; Lecture Feb 3

Why did the proof fail?  Consider the state s with x=0 and y=0  State s satisfies  : (0<=y <=m)  Executing a transition from s leads to state t with x=1 and y=-1  State t does not satisfy  !  The state s in above argument is not reachable!  Cause of failure: The property  did not capture corelation between the variables x and y  Solution: Inductive Strengthening!  Consider property  : (0 <= y <= m) & (x+y = m)  The property  implies property   While  is not inductive invariant,  is!  It follows that all reachable states must satisfy  CIS 540 Spring 2016; Lecture Feb 3

Proving Inductive Invariant Example (3)  Consider transition system T given by  State variables int x, y; x is initially 0, y is initially m  Transition description given by “if (x < m) then {x:=x+1; y:=y-1}”  Property  : (0 <= y <= m) & (x+y = m)  Base case: Consider initial state (x=0,y=m). Check that it satisfies   Inductive case:  Consider an arbitrary state s with x=a and y=b  Assume that s satisfies , that is, assume 0 <= b <=m and a+b =m  Consider the state t obtained by executing a transition from s  If a < m then t(x) = a+1 and t(y) = b-1, else t(x)=a and t(y)=b  But if a 0, and thus b-1 >=0  In either case, the condition (0<= t(y) <=m & t(x)+t(y)=m) holds!  Conclusion: Property  is an inductive invariant! CIS 540 Spring 2016; Lecture Feb 3