1.6 Behavioral Equivalence. 2 Two very important concepts in the study and analysis of programs –Equivalence between programs –Congruence between statements.

Slides:



Advertisements
Similar presentations
Example of Constructing the DAG (1)t 1 := 4 * iStep (1):create node 4 and i 0 Step (2):create node Step (3):attach identifier t 1 (2)t 2 := a[t 1 ]Step.
Advertisements

Theory of Computing Lecture 23 MAS 714 Hartmut Klauck.
1 Turing Machines and Equivalent Models Section 13.2 The Church-Turing Thesis.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Partial Order Reduction: Main Idea
Models of Concurrency Manna, Pnueli.
Functional Verification III Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture Notes 23.
Cook’s Theorem The Foundation of NP-Completeness.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
1 Partial Order Reduction. 2 Basic idea P1P1 P2P2 P3P3 a1a1 a2a2 a3a3 a1a1 a1a1 a2a2 a2a2 a2a2 a2a2 a3a3 a3a3 a3a3 a3a3 a1a1 a1a1 3 independent processes.
Chapter 5 ( ) of Programming Languages by Ravi Sethi
Discrete Mathematics Lecture 5 Alexander Bukharovich New York University.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Computability and Complexity 9-1 Computability and Complexity Andrei Bulatov Logic Reminder (Cnt’d)
Prof. Busch - LSU1 Decidable Languages. Prof. Busch - LSU2 Recall that: A language is Turing-Acceptable if there is a Turing machine that accepts Also.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
1 Module 9 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.
Discrete Mathematics Lecture 4 Harper Langston New York University.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
Axiomatic Semantics Dr. M Al-Mulhem ICS
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Data Flow Analysis Compiler Design Nov. 8, 2005.
1 Module 10 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.
Propositional Equivalence Goal: Show how propositional equivalences are established & introduce the most important such equivalences.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Fundamentals of Python: From First Programs Through Data Structures
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Fundamentals of Python: First Programs
Advanced Topics in Software Engineering Marjan Sirjani Tehran University Faculty of Engineering ECE Department Tehran,
Zvi Kohavi and Niraj K. Jha 1 Memory, Definiteness, and Information Losslessness of Finite Automata.
Software Verification 2 Automated Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität and Fraunhofer Institut für.
1 2. Independence and Bernoulli Trials Independence: Events A and B are independent if It is easy to show that A, B independent implies are all independent.
Copyright © Cengage Learning. All rights reserved. CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF.
Logic Circuits Chapter 2. Overview  Many important functions computed with straight-line programs No loops nor branches Conveniently described with circuits.
Boolean Algebra and Computer Logic Mathematical Structures for Computer Science Chapter 7.1 – 7.2 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Boolean.
Advanced Topics in Software Engineering Marjan Sirjani Tehran University Faculty of Engineering ECE Department Tehran,
Algorithm Design.
Model 3: Message-Passing Text We saw –Diagrams –Shared-variables text Now –Message-passing text (like CSP)
Detecting Equality of Variables in Programs Bowen Alpern, Mark N. Wegman, F. Kenneth Zadeck Presented by: Abdulrahman Mahmoud.
Chapter 3 Part II Describing Syntax and Semantics.
Chapter 4: Elementary Number Theory and Methods of Proof 4.8 Application: Algorithms 1 Begin at the beginning…and go on till you come to the end: then.
VHDL Discussion Subprograms IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology 1.
1 Fault tolerance in distributed systems n Motivation n robust and stabilizing algorithms n failure models n robust algorithms u decision problems u impossibility.
Classical Control in Quantum Programs Dominique Unruh IAKS, Universität Karlsruhe Founded by the European Project ProSecCo IST
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Sets and Basic Operations on Sets Notation A set will usually be denoted by a capital letter, such as, A,B,X, Y,..., whereas lower-case letters, a, b,
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Process Algebra (2IF45) Basic Process Algebra Dr. Suzana Andova.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Syntax Analysis Or Parsing. A.K.A. Syntax Analysis –Recognize sentences in a language. –Discover the structure of a document/program. –Construct (implicitly.
Chapter 5 Inverse Functions and Applications Section 5.1.
Formal methods: Lecture
Propositional Equivalence
Data Structures and Algorithms
GC211Data Structure Lecture2 Sara Alhajjam.
Copyright © Cengage Learning. All rights reserved.
A Survey of Program Slicing Techniques: Section 4
VHDL Discussion Subprograms
The Programming Language L
VHDL Discussion Subprograms
The structure of programming
Instructor: Aaron Roth
The Programming Language L
Presentation transcript:

1.6 Behavioral Equivalence

2 Two very important concepts in the study and analysis of programs –Equivalence between programs –Congruence between statements –Replacing statements and programs

3 Consider the two programs: P1::[ out x:integer where x=0 l0: x:=1 :l0’ ] P2::[ out x:integer where x=0 local t:integer where t=0 l0: t:=1 :l0’ l1: x:=t :l1’ ]

4 Computation generated by P1 –,,, … Computation generated by P2 –,,,,… Computations contain too much distinguishing information, irrelevant to the correctness of the program, like –Control variable –Local variables

5 Observable variables: O a subset of state variables –Usually input or output variables –Control variables are never observable Label renaming =>equivalent programs

6 We define the observable state corresponding to s, denoted by s|O, to be the restriction of s to just the observable variables O. Thus, s|O is an interpretation of O that coincides with s on all the variables in O.

7 Given a computation σ :s0, s1, … We define the observable behavior corresponding to َ to be the sequence َ σ o : s0 |O, s1 |O, …

8 For P1 and P2, and O={x}, observable behaviors: σ 1 O :,,, … σ 2 O :,,,, …

9 Reduced behavior The reduced behavior σ r –relative to O, –corresponding to a computation σ, is the sequence obtained from σ by the following transformations : Replace each state s i by its observable part s i |O Omit from the sequence each observable state that is identical to its predecessor but not identical to all of its successors. –Not to delete the infinite suffix.

10 Applying these transformations to the computations σ 1 and σ 2 or just the second transformation to σ 2 O σ 1 r :,,, … σ 2 r :,,, …

11 Equivalence of transition systems For a basic transition system P, we denote by R(P) the set of all reduced behaviors generated by P. Let P1 and P2 be two basic transition systems and O subsetof Π1 intersect Π2 be a set of variables (observable variables for both systems). The systems P1 and P2 are defined to be equivalent (relative to O), denoted by P1~P2, if R(P1)=R(P2).

12 Which is equivalent to which? Q1::[out x: integer where x=0; x:=2] Q2::[out x: integer where x=0; x:=1; x:=x+1] Q3::[out x: integer where x=0; [local t: integer; t:=1; x:=t+1]] Observable set?

13 Congruence between statements –To explain the meaning of a statement S by another more familiar statement S’, that is congruent to S (perform the same task as S), but may be more efficient.

14 Congruence of statements Consider the two statements: T1::[x:=1;x:=2] T2::[x:=1;x:=x+1] Viewing them as the bodies of programs, they are equivalent: P1::[out x: integer where x=0;T1] P2::[out x: integer where x=0;T2]

15 Our expectation about equivalent statements is that they are completely interchangeable: the behavior of a program containing T1 will not change when we replace an occurrence of T1 with T2.

16 Consider Q1 and Q2: Q1:: [out x: integer where x=0;[T1 || x:=0]] Q2:: [out x: integer where x=0;[T2 || x:=0]] Are they equivalent? Obtain the set of reduced behaviors of Q1 and Q2.

17 Let P[S] be a program context, which is a program in which statement variable S appears as one of the statements. For example: Q[S]:: [out x: integer where x=0;[S|| x:=0]] Let programs P[S1] and P[S2] be the programs obtained by replacing statement variable S with the concrete statements S1 and S2, respectively. Statements S1 and S2 are defined to be congruent, denoted by S1~S2, if P[S1]~P[S2] for every program context P[S].

18 examples Commutativity –Selection and cooperation constructions are commutative. [S1 or S2] ~ [S2 or S1] [S1 || S2] ~[S2 || S1] Associativity –Concatenation, selection, and cooperation constructions are all associative. [S1;[S2;S3]] ~ [[S1;S2];S3]~[S1;S2;S3] For or and ||

19 S~ [S; skip] What about: S1 :: [await x] S2 :: [skip; m: await x] ? Consider: P[S]:: [out x: boolean where x=F l0: [S or [await !x]]; l1: x:=T :l1’]

20 P[S2] may deadlock, while P[S1] may not.

21 await c ~ while !c do skip Implementing await by busy waiting Problem 1.3

22 Implementation versus emulation Replacement of two programs may be desirable, for example in the case that one is expressed in terms of high-level constructs that are not directly available on a considered machine. There are two possible relations; –Emulation –implementation

23 P2 emulates P1 if they are equivalent, i.e., if their sets of reduced behaviors are equal (a symmetric relation). P2 implements P1 if the set of reduced behaviors of P2 is a subset of the set of reduced behaviors of P1.

24 Example: P1::[ out x, y: integer where x=0, y=0 loop forever do [x:=x+1 or y:=y+1]] P2::[ out x, y: integer where x=0, y=0 loop forever do [x:=x+1 ; y:=y+1]]

25 Emulation and implementation relations between statements: –The statement S2 emulates statement S1 if P[S2] emulates P[S1] for every program context P[S]. –S2 emulates S1 iff S2 is congruent to S1. –The statement S2 implements statement S1 if P[S2] implements P[S1] for every program context P[S].

26 What are the relations? –While !c do skip ?? await c –x:=x+1 ?? [[x:=x+1] or [y:=y+1]] –S2= await x ?? S1=[await x] or [await y] –S3=await (x or y) ?? S1=[await x] or [await y]

27 An example to compare S1 and S2 and S3: [local x,y : boolean where x=F, y=T out z: integer where z=0 S; z:=1]

Grouped Statements In our text language, an atomic step (corresponding to a single transition taken in a computation), consists of the execution of at most one statement of the program.

29 We define a class of statements as elementary statements. These statements can be grouped together. The elementary statements: –Skip, assignment, and await statements –If S, S1, …, Sk are elementary statements, then so are: When c do S If c then S1 else S2 [S1 or … or Sk] [S1; …; Sk] –Any statement containing: cooperation or a while statement is not elementary.

30 If S is an elementary statement, then is a grouped statement. Example: Execution of this grouped statement calls for the uninterrupted and successful execution of the three statements participating in the group in succession. This grouped statement is congruent to the statement await y=1 This interpretation implies that execution of a grouped statement cannot be started unless its successful termination is guaranteed.

31 The transition associated with a grouped statement Product of transitions –Let and be two transitions. –Product of and, denoted by o, is s”

Semaphore Statement

Region statement

Mode 3: Message-Passing Text

Model 4: Petri Nets