1.6 Behavioral Equivalence - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

1.6 Behavioral Equivalence

Description:

Concatenation, selection, and cooperation constructions are all associative. ... consists of the execution of at most one statement of the program. 29 ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 35
Provided by: eceU3
Category:

less

Transcript and Presenter's Notes

Title: 1.6 Behavioral Equivalence


1
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 xinteger where x0
  • l0 x1 l0
  • P2 out xinteger where x0
  • local tinteger where t0
  • l0 t1 l0
  • l1 xt l1

4
  • Computation generated by P1
  • ltl0,0gt,ltl0,1gt,ltl0,1gt,
  • Computation generated by P2
  • ltl0,0,0gt,ltl1,0,1gt,ltl1,1,1gt,ltl1,1,1gt,
  • 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 gtequivalent programs

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

7
  • Given a computation
  • s s0, s1,
  • We define the observable behavior corresponding
    to ? s to be the sequence
  • ? s o s0 O, s1 O,

8
  • Computation generated by P1
  • ltl0,0gt,ltl0,1gt,ltl0,1gt,
  • Computation generated by P2
  • ltl0,0,0gt,ltl1,0,1gt,ltl1,1,1gt,ltl1,1,1gt,
  • For P1 and P2, and Ox, observable behaviors
  • s1O lt0gt, lt1gt, lt1gt,
  • s2O lt0gt, lt0gt, lt1gt, lt1gt,

9
Reduced behavior
  • The reduced behavior sr
  • relative to O,
  • corresponding to a computation s,
  • is the sequence obtained from s by the following
    transformations
  • Replace each state si by its observable part siO
  • 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 s1 and s2
  • or just the second transformation to s2O
  • s1r lt0gt, lt1gt, lt1gt,
  • s2r lt0gt, lt1gt, lt1gt,

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 P1P2,
  • if R(P1)R(P2).

12
  • Which is equivalent to which?
  • Q1out x integer where x0 x2
  • Q2out x integer where x0 x1 xx1
  • Q3out x integer where x0 local t integer
    t1 xt1
  • 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
  • T1x1x2
  • T2x1xx1
  • Viewing them as the bodies of programs, they are
    equivalent
  • P1out x integer where x0T1
  • P2out x integer where x0T2

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 x0T1 x0
  • Q2 out x integer where x0T2 x0
  • Are they equivalent?
  • Obtain the set of reduced behaviors of Q1 and
    Q2.

17
  • Let PS be a program context, which is a program
    in which statement variable S appears as one of
    the statements.
  • For example
  • QS out x integer where x0S x0
  • Let programs PS1 and PS2 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 S1S2, if PS1PS2 for every
    program context PS.

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.
  • S1S2S3 S1S2S3S1S2S3
  • For or and

19
  • S S skip
  • What about
  • S1 await x
  • S2 skip m await x ?
  • Consider
  • PS out x boolean where xF
  • l0 S or await !x l1 xT l1

20
  • PS2 may deadlock, while PS1 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 x0, y0
  • loop forever do
  • xx1 or
    yy1
  • P2 out x, y integer where x0, y0
  • loop forever do
  • xx1
    yy1

25
  • Emulation and implementation relations between
    statements
  • The statement S2 emulates statement S1 if PS2
    emulates PS1 for every program context PS.
  • S2 emulates S1 iff S2 is congruent to S1.
  • The statement S2 implements statement S1 if PS2
    implements PS1 for every program context PS.

26
  • What are the relations?
  • While !c do skip ?? await c
  • xx1 ?? xx1 or yy1
  • S2 await x ?? S1await x or
    await y
  • S3await (x or y) ?? S1await x or await y

27
  • An example to compare S1 and S2 and S3
  • local x,y boolean where xF, yT
  • out z integer where z0
  • S z1

28
1.7 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 ltSgt is a
    grouped statement.
  • Example ltyy-1 await y0 y1gt
  • 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 y1
  • 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 t1 and t2 be two transitions.
  • Product of t1 and t2 , denoted by t1o t2 , is
  • s ? t1 o t2 iff there exists an s
  • such that s ? t1(s) and s ? t2(s)
  • Thus, the (t1o t2)-successors of s can be
    obtained by the application of t1 to s, followed
    by the application of t2 to the resulting states.

32
  • Assume that
  • ?t1 C1 /\ (y e1) and ?t2 C2 /\ (y e2)
  • Where we assume that ?t1 and ?t2 have the same
    set of modifiable variables.
  • ?t1 0 t2
  • ?t1 o ?t2 C1 /\ C2e1/y /\
    (ye2e1/y)

33
  • Example
  • ?t1 (xgty) /\ (x x-y) /\ (y y)
  • ?t2 (xlty) /\ (x x) /\ (y y-x)
  • What is the transition relation for the product?

34
  • Transitions for ltSgt page 54.
  • Example page 55
Write a Comment
User Comments (0)
About PowerShow.com