Docsity

Operational Semantics of Sequential and Parallel Composition in Programming - Prof. James , Study notes of Computer Science

Toggle sidebar
bg1
Science!of!Programming
Notes!#11!—!Disjoint!Parallel!Programs
Dr.!Jim!Sasaki
Today:
1. Parallel Programs
2. Disjoint!Parallel!Programs
Today’s!Goals
•Disjoint parallel programs
•Cover some disjoint parallel program rules
1. Basic Definitions for Parallel Programs (Chapter 4)
1.1 Basic syntax of parallel programs
•Syntax rule for parallel statements: S ::=![S!||!S!||!…!||!S].
•[S"!||!S#!||!…!||!Sn] is the parallel composition of the n statements S",
S#, …, Sn in parallel. E.g., [x!:=!x+1!||!x!:=!x*2].
Science!of!Programming Spring’09 Notes!#11
Ill.!Inst.!Tech.!CS 1!of!35 Tue,!Apr!7,!2009
•S", S#, …, Sn are the threads of the composed statement.
•Syntactic restriction: Parallel statements cannot be nested: The
threads cannot contain parallel statements.
-On the other hand, statements like [S"||S#]; while B do [S$!||!S%]
od are okay.
1.2 Execution of parallel programs
•We run sequential programs in parallel by interleaving their execu-
tion — execute S" for a while, then execute S# for a while, etc.
•Execution can end in different states depending on how the interleav-
ing is done.
•E.g., evaluate [x!:=!x+1!||!x!:=!x*2] by
(1) Evaluating x!:=!x+1 and then x!:=!x*2 or
(2) Evaluating x!:=!x*2 and then x!:=!x+1.
•Interference!causes!the!parallel!composition!of!n!threads!to!have!
properties!very!different!from!the!properties!of!the!individual!threads.
Science!of!Programming Spring’09 Notes!#11
Ill.!Inst.!Tech.!CS 2!of!35 Tue,!Apr!7,!2009
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Operational Semantics of Sequential and Parallel Composition in Programming - Prof. James and more Study notes Computer Science in PDF only on Docsity!

Science!of!Programming

Notes!#11!—!Disjoint!Parallel!Programs

Dr.!Jim!Sasaki

Today:

  1. Parallel Programs
  2. Disjoint!Parallel!Programs Today’s!Goals
  • Disjoint parallel programs
  • Cover some disjoint parallel program rules

1. Basic Definitions for Parallel Programs (Chapter 4)

1.1 Basic syntax of parallel programs

  • Syntax rule for parallel statements:^ S^ ::=![ S !||! S !||!…!||! S ].
    • [ S "!||! S #!||!…!||! Sn ] is the parallel composition of the n statements S ", S #, …, Sn in parallel. E.g., [ x !:=! x +1!||! x !:=! x *2]. Ill.!Inst.!Tech.!CS 1 !of! 35 Tue,!Apr!7,! 2009
  • S ", S #, …, Sn are the threads of the composed statement.
  • Syntactic restriction: Parallel statements cannot be nested: The threads cannot contain parallel statements.
  • On the other hand, statements like [ S "|| S #];^ while^ B^ do^ [ S $!||! S %] od are okay. 1.2 Execution of parallel programs
  • We run sequential programs in parallel by^ interleaving^ their execu- tion — execute S " for a while, then execute S # for a while, etc.
  • Execution can end in different states depending on how the interleav- ing is done.
  • E.g., evaluate [ x !:=! x +1!||! x !:=! x *2] by (1) Evaluating x !:=! x +1 and then x !:=! x *2 or (2) Evaluating x !:=! x *2 and then x !:=! x +1.
  • Interference !causes!the!parallel!composition!of! n !threads!to!have! properties!very!different!from!the!properties!of!the!individual!threads. Science!of!Programming Spring’09 Notes!#1 1
  • Example:
    • !!{ x !=! 5 }! x !:=! x +1!{ x !=! 6 }!and!!!{ x !=! 5 }! x !:=! x *2!{ x !=! 10 }
    • But!!!{ x !=! 5 }![ x !:=! x +1!||! x !:=! x *2]!{ x !=! 11 !!! x !=! 12 }.
  • The problem with reasoning about parallel programs is that different threads can interfere with each other.
  • Full interference is tricky, so we’re going to work our way up to it. 1.3 Disjoint parallel programs
  • In this chapter, we’ll avoid interference by looking at the simplest case, where the threads can’t affect each other.
  • This models computations with n processors that share readable memory but not writable memory.
  • Not a thrilling version of parallelism, but it will help us define the basic machinery we’ll be using.
  • Definition : The threads^ S ",^ S #, …,^ Sn are^ pairwise disjoint^ if no pro- gram can change the variables used by any other: change( Si ) " Ill.!Inst.!Tech.!CS 3 !of! 35 Tue,!Apr!7,! 2009 vars( Sj )!=!# for all 1!"! i !#! j !"! n.
  • vars( S )!=!set of variables that appear in statement S [page 49].
  • change( S )!=!set of variables on left-hand side of assignments in statement S.
  • Execution order isn’t taken into account.
  • E.g., change( if^ b^ then^ x !:=!^1 else^ y !:=!^1 fi )!=!{ x ,^ y }
  • Examples:
  • a !:=! x +1 and y !:=! x +2 are disjoint.
  • a !:=! x^ and^ x !:=! c^ are not disjoint.
  • a !:=! x^ and^ x !:=! x +1 are not disjoint.
  • x !:=! a +1 and x !:=! b *2 are not disjoint.
  • In general
  • A^ variable can be read by multiple^ S &^ (but only if no^ Sj writes to it).
  • If S & writes to variable u , then S & can read u , and no other Sj can read or write u. Science!of!Programming Spring’09 Notes!#1 1
  • Consider^ S^ '^ S ;^ E^ '^ E ;^ S.
  • We say that # S ,!$$ evaluates to # S ',!$'$ in k steps (and write # S ,!$$!% k

S ',!$'$) if there’s a sequence with exactly k arrows that leads from # S ,!

$$ to # S ',!$'$.

  • (For the special case^ k^ = 0,^ # S ,!$$!%)^ # S ,!$$.)
  • We say that # S ,!$$ evaluates to # S ',!$'$ (in some number of steps) (and write # S ,!$$!%* # S ',!$'$) if # S ,!$$!% k^ # S ',!$'$ for some k.
  • Another way to say this is that^ % k^ is the^ k -fold composition of^ * with itself and that %* is the reflexive transitive closure of %.
  • The^ evaluation graph^ for^ # S ,!$$^ is the directed graph of configura- tions and evaluation arrows leading from # S ,!$$.
  • For a deterministic sequential program, if you start in an arbitrary configuration # S ,!$$, the evaluation graph is either:
  • A finite path ending in a unique terminal configuration # E ,!&$.
  • An infinite path. Ill.!Inst.!Tech.!CS 7 !of! 35 Tue,!Apr!7,! 2009
  • A^ finite path that leads to a finite-length cycle.
  • Program^ S^ diverges^ at state^ $^ if the sequence of configurations start- ing with # S ,!$$ doesn’t terminate.
  • (May hear diverge “on”, “in”, “from”, …^ $).
  • The textbook’s formal definition of the meaning function M for states is M! S "($)!=!{& | # S ,!$$!%* # E ,!&$}.
  • For deterministic sequential programs, either M! S "($)!=!# or!{&} where # S ,!$$!%* # E ,!&$.
  • I. e ., evaluation of^ S^ in state^ $^ either goes forever or it takes some number (!$!0) of steps and terminates in state!&.
  • M tot! S "($)!=! M! S "($) ( {) | if S diverges at $}. 2.2 Operational semantics rules for sequential programs
  • The operational semantics rules mimic machine computation. (Ours is a pretty abstract operational semantics.) Science!of!Programming Spring’09 Notes!#1 1

Operational Semantics of skip

  • skip ,!$$!% # E ,!$$

    • Executing a^ skip^ completes and doesn’t change the state. Operational Semantics of Assignment
  • u !:=! t ,!$$!%^ # E ,!$[ u !:=!$( t )]$

  • To execute an assignment, evaluate the r.h.s. expression t and make its value the new value of the l.h.s. variable! u.
  • No matter how large an expression^ t^ is, execution of^ u !:=! t^ is modeled as taking only one step; evaluation steps don’t model physical execution time very well. Operational Semantics of if-then and if-else
  • if^ B^ then^ S "^ else^ S #^ fi ,!$$!%^ # Si ,!$$!where^ i !=!1 if^ $^!^ B^ and^ i !=!2 if^ $

! ¬ B.

  • To execute a conditional statement for one step, evaluate the test and jump to the appropriate branch. Ill.!Inst.!Tech.!CS 9 !of! 35 Tue,!Apr!7,! 2009 Operational Semantics of while loops
  • while B do S " od ,!$$!% # E ,!$$ if $! ¬ B

  • If the while loop test fails, we’re done.
  • while^ B^ do^ S "^ od ,!$$!%^ # S ";^ while^ …,!$$^ if^ $^!^ B

  • If the^ while^ loop test succeeds, jump to the loop body (and after the loop body, follow with the loop).
  • For example,^ # while^ B^ do^ S #;^ x !:=! x +1^ od ,!$$ % # S #; x !:=! x +1; while B do S #; x !:=! x +1 od ,!$$ if $! B Operational Semantics of Sequential Composition
  • There’s one rule that has a different form: Instead of being an axiomatic rule that tells you how to take a configuration and write an arrow and configuration next to it, it’s a deduction rule:

S ",!$$ * # S "',!&$

––––––––––––––––––––––––––––––

S "; S #,!$$ * # S "'; S #,!&$

Science!of!Programming Spring’09 Notes!#1 1

  • Example 2: Let W ' while i !>! 0 do i !:=! i -1; s !:=! s + i od and let S ' s !:=!0; i !:=! n +1; W. Let’s evaluate W in a state $ where $( n ) is 2: # S ,!$$!' # s !:=!0; i !:=! n +1; W ,!$$ %% # W ,!$[ s !:=!0][ i !:=!3]$ ' # while i !>! 0 do i !:=! i -1; s !:=! s + i od ,!$[ s !:=!0][ i !:=!3]$ % # i !:=! i -1; s !:=! s + i ; W ,!$[ s !:=!0][ i !:=!3]$ %, # W ,!$[ n !:=!2][ i !:=!2][ s !:=!2]$ % # i !:=! i -1; s !:=! s + i ; W ,!$[ i !:=!2][ s !:=!2]$ %, # W ,!$[ i !:=!1][ s !:=!3]$ % # i !:=! i -1; s !:=! s + i ; W ,!$[ i !:=!1][ s !:=!3]$ %% # W ,!$[ i !:=!0][ s !:=!3]$ % # E ,!$[ i !:=!1][ s !:=!3]$

3. Semantics of Disjoint Parallel Programs

3.1 Operational semantics of parallel programs

  • To execute the sequential composition S " ;!… ;! Sn for one step, we execute S " for one step. To execute the parallel composition [ S "!||!…!||! Ill.!Inst.!Tech.!CS 13 !of! 35 Tue,!Apr!7,! 2009 Sn ], we can pick any one of the threads and evaluate it for one step. Note the evaluation graph for # S ,!$$ can have n out-arrows. Operational Semantics of Parallel Composition
  • If^ S^ '![ S "!||!…!||! Sn ], then for each^ k !=!1, 2, …,^ n ,

Sk ,!$$!% # Tk ,!&$

–––––––––––––––––––

S ,!$$!% # T ' k ,!&$

where T ' k ' [ S "!||!…!||! Sk -1!||! Tk !||! Sk +1…!||! Sn ].

  • With sequential composition, we treat^ E^ ; … ;^ E^ as equivalent to^ E. With parallel composition, we treat [ E !||!…!||! E !||! E ] as equivalent to E.
  • Example:
  • Let^ S^ '^ [ x !:=! a +1!||! y !:=! a *2] and^ $( a ) =!+, then one execution path is

S ,!$$ % #[ E !||! y !:=! a *2],!$"$ % #[ E !||! E ],!$""$ = # E ,!$""$

where $" = $[ x !:=!++1] and $"" = $[ x !:=!++1][ y !:=! 2 +] Science!of!Programming Spring’09 Notes!#1 1

(For the $ subscript, I used a sequence that indicates the path through the evaluation graph; it can come in handy for compli- cated graphs.)

  • We could’ve chosen to evaluate the right-hand thread first, then

    S ,!$$ = #[ x !:=! a +1!||! y !:=! a *2],!$$ % #[ x !:=! a +1!||! E ],!$#$ %!# E ,!$#"$

    where $# = $[ x !:=! 2 +] and $#" = $[ y !:=! 2 +] [ x !:=!++1]
  • As these are the only possible execution paths, we have by defini- tion that M! S "($) = {$"", $#"}. But interestingly, $"" = $#" because they do exactly the same updates, just in different orders.
  • Let - = $"" = $#", so we now find M! S "($) = {$"", $#"} = {&}.
  • Here's the evaluation graph for our program: Ill.!Inst.!Tech.!CS 15 !of! 35 Tue,!Apr!7,! 2009 ![ E !||! y !:=! a !2],!"[ x !:=!!+1]" ![ x !:=! a +1!||! E ],!"[ y !:=! 2 !]" ![ x !:=! a +1!||! y !:=! a !2],!"" ![ E !||! E ],!#" where! = "( a ) and # = "[ x !:=!!+1][ y !:=! 2 !] = "[ y !:=! 2 !][ x !:=!!+1] 3.2 Total correctness for disjoint parallel programs
  • For total correctness, we have to look at divergence.
  • S can diverge at $ if the evaluation graph for # S ,!$$ has an infinite path or it has a (finite) cycle. (May hear diverge “on”, “in”, “from”, … $).
  • M tot! S "($)!=! M! S "($) ( {) | if S can diverge at $}.
  • For parallel programs in general (and for nondeterministic programs) Science!of!Programming Spring’09 Notes!#1 1

(not just parallel programs) is confluent if execution doesn't have side effects. For example, evaluation of everyday arithmetic expressions is confluent: 2%3 + 4%5 = 26 regardless of whether you calculate 2% 3 or 4%5 first. Evaluation of C expressions with assignment operators is not confluent: x + (x = 2) could differ depending on whether you evaluate left-to-right or right-to-left. 3.4!Unique!Result!of!Disjoint!Parallel!Program

  • Because!execution!of!disjoint!parallel!programs!is!confluent,!if!execu- tion!terminates,!it!terminates!in!a!unique!state.
    • Theorem (Unique Result) :!If! S !is!a!disjoint!parallel!program!then! either! M! S "($)!=!#!or!for!some!&,! M! S "($)!=!{&}. (I.e., it will have < Ill.!Inst.!Tech.!CS 19 !of! 35 Tue,!Apr!7,! 2009 2 states.) Similarly,! M tot! S "($)!either!=!{)}! or!some!{&}.
    • Proof:!If!# S ,!$$!%!# E ,!&"$!and!# S ,!$$!%!

      E ,!&#$,!then!by!confluence!there!must!be!

      some!configuration!# S ',!&$!such!that!

      E ,!&"$!%!# S ',!&$!and!# E ,!&#$!%!# S ',!&$.!!

      Since!no!semantics!rule!take!# E ,!…$!%!any- thing,!the!%*!relations!must!both!involve! zero!steps,!so! S '!'! E !and!&!=!&"!=!&#.

4 Sequentialization Proof!Rule!for!Disjoint!Parallel!Programs

4.1!Introduction

  • We’ll!have!^3 !rules!for!proving!disjoint!parallel!programs!correct:!a!se- quential!rule!and!two!parallel!rules.
  • The!sequential!rule!will!be!powerful!but!burdensome,!the!disjoint!par- allelism!rule!will!be!easy!to!use!but!weak,!and!the!auxiliary!variable!

! E ,!!""! E ,!!#"

! S ,!""

! E ,!!"

where! = !" = !# Science!of!Programming Spring’09 Notes!#1 1

rule!will!be!powerful,!less!burdensome,!but!a!bit!subtle!in!its!justifica- tion. 4.2!Sequentialization

  • Definition : The! sequentialization !of!the!parallel!statement![ S "!||!…!||! Sn ] is the!sequence!of!statements! S ";!!…;! Sn.
  • In!the! sequentialized !execution!of![ S "!||!…!||! Sn ],!we!evaluate! S "!com- pletely,!then! S #!completely,!and!so!on: #[ S "!||!…!||! Sn ],!$$ %!#[ E !||! S #!||!…!||! Sn ],!$"$ %!#[ E !||! E !||! S $!||!…!||! Sn ],!$#$ %… %!#[ E !||! E !||!…!||! E ],!$ n +1$
  • Sequentialized!execution!follows!the!same!state!transformations! you’d!see!when!executing!the!sequential!program! S "!;! S #!;!…!;! Sn : Ill.!Inst.!Tech.!CS 21 !of! 35 Tue,!Apr!7,! 2009

S ";!…;! Sn ,!$$

%!# S #;!…;! Sn ,!$"$ %!# S $;!…;! Sn ,!$#$ %… %!# E ,!$ n +1$

  • Example:!Compare Sequentialized Sequence #[ a !:=! 0 !||! b !:=!1],!.$ !!!!%!#[ E !||! b !:=!0],!$[ a !:=!0]$ !!!!%!#[ E !||! E ],!$[ a !:=!0][ b !:=!1]$

a !:=!0;! b !:=!1,!$$

!!!!%!# b !:=!0,!$[ a !:=!0]$ !!!!%!# E ,!$[ a !:=!0][ b !:=!1]$

  • Since it doesn't matter how!we!interleave!evaluation!of!pairwise dis- joint!parallel!threads, we know their total effect will be the same as if we had evaluated them sequentially.
  • Therefore, any!preconditions!and!postconditions!that!work!for!the!se- quential!program!should!also work!for!the!parallel!program. Science!of!Programming Spring’09 Notes!#1 1

{ true }![ a !:=! x +1!||! b !:=! x +2]!{ a +1!=! b }”

  • This can be condensed into a proof outline: { true } [!{ true } a !:=! x +1 { a !=! x +1} ||!{ true } b !:=! x +2 { b !=! x +2}!] { a !=! x +1 , b !=! x +2} { a +1!=! b } 5.2 Disjoint parallel programs with disjoint conditions
  • We can’t join the conditions of arbitrary parallel disjoint program threads. An example: { x !=!0} [!{ x !=!0} x !:=!1 { x !=!1} ||!{ x !=!0} y !:=!0 { x !=! y }!] { x !=! 1 , x !=! y } - Bad! Can’t combine the postconditions! { x !=! y !=!1}
  • We can’t combine the postconditions because the first thread invali- Ill.!Inst.!Tech.!CS 25 !of! 35 Tue,!Apr!7,! 2009 dates the x !=!0 precondition that the second thread relies on.
  • Avoiding this invalidation will allow us to combine the conditions.
  • Definition :!{ p "}! S "!{ q "}!and!{ p #}! S #!{ q #}!have! disjoint! conditions !if!nei- ther!program!can!affect!the!other’s!conditions:
  • Change ( S ")!"! Free ( p #,! q #)!=!#!and! Change ( S #)!"! Free ( p ",! q ")!=!#.
  • Examples of disjoint / nondisjoint conditions:
  • Nondisjoint: { true }! x !:=! 1 !{ x !=! 1 }!and!{ x !=! 0 }! y !:=! 0 !{ x !=! y }
  • { x } " { x , y } # # and { y } " { x } = #
  • Disjoint: { z !=!0}! x !:=! z +1!{ x " z }!and!{ z !=!0}! y !:=! z !{ z !=! y }
  • { x }^ "^ { y ,^ z } =^ #^ and { y }^ "^ { x ,^ z } =^ #
  • If!two!triples!have!disjoint!programs!and!conditions,!then!neither!can! modify!information!used!by!the!programs!or!conditions!of!the!other.
  • Example:!{ x !=!^0 }! x !:=! x +2;! x !:=! x *3!{ x !=!6}!and!{ p #}! S #!{ q #}!(where S# doesn’t modify x and where x !doesn’t!appear in S # or (free) in p " or p #.!No!matter!how!we!interleave!execution!of!the!two!threads,!no! Science!of!Programming Spring’09 Notes!#1 1

statement!of! S #!ever!modifies! x : { x !=! 0 }!Run!some!part!of! S #; { x !=! 0 }! x !:=! x +2; { x !=! 2 }!Run!some!more!of! S #; { x !=! 2 }! x !:=! x * { x !=!6}!Finish!running! S # { x !=! 6 } Rule!9:!Disjoint!Parallelism { p "}! S "!{ q "}!!!!!{ p #}! S #!{ q #}!!!!!…!!!!!{ pn }! Sn !{ qn } ––––––––––––––––––––––––––––––––––––––––––––––– { p "!,! p #!,!…!,! pn }![ S "!||!…!||! Sn ]!{ q "!,! q #!,!…!,! qn } where!the!{ pi }! Si !{ qi }!have!pairwise!disjoint!programs!and!conditions.

  • Example: Recall the proof outline we wanted earlier { true } { true !,! true } [!{ true }! a !:=! x +1!{ a !=! x +1} Ill.!Inst.!Tech.!CS 27 !of! 35 Tue,!Apr!7,! 2009 ||!{ true }! b !:=! x +2!{ b !=! x +2}!] { a !=! x +1!,! b !=! x +2} { a +1!=! b }
  • This is now a valid outline that stands for the following proof:
  1. { x +1!=! x +1}! a !:=! x +1!{ a !=! x +1} by!assignment
  2. true % x +1!=! x +1 by predicate logic
  3. { true }! a !:=! x +1!{ a !=! x +1} by precond. strength. 2, 1
  4. a{ x +2!=! x +2}! b !:=! x +2!{ b !=! x +2} by assignment
  5. true % x +2!=! x +2 by predicate logic
  6. { true }! b !:=! x +2!{ b !=! x +2} by precond. strength. 5, 4
  7. { true !,! true }![ a !:=! x +1!||! b !:=! x +2]!{ a !=! x +1!,! b !=! x +2} by!disjoint!parallelism 3, 6
  8. true !%! true !,! true by predicate logic
  9. a !=! x +1!,! b !=! x +2!%! a +1!=! b by predicate logic 10.{ true }![ a !:=! x +1!||! b !:=! x +2]!{ a +1!=! b } by!consequence 8, 7, 9 Science!of!Programming Spring’09 Notes!#1 1

{ x !=! x '!,! y !=! y '!,! x - y !=! x '- y '} { x !=! x '!,! y !=! y '} [!{ x !=! x '}! x !:=! x +1!{ x -1!=! x '} ||!{ y !=! y '}! y !:=! y +1!{ y -1!=! y '}!] { x -1!=! x '!,! y -1!=! y '} { x - y !=! x '- y '}

  • Hmm.!!It!would!be!nice!to!get!something!like { x - y !=! d }![ x !:=! x +1!||! y !:=! y +1]!{ x - y !=! d }
  • We!can’t!use!{ x - y !=! d }! x !:=! x + 1 !{…}!because!that!interferes!with! y !:=! y + 1 .!! Symmetrically,!we!can’t!use!{ x - y !=! d }! y !:=! y +1!{…}!because!that!inter- feres!with! x !:=! x +1.
  • How!about!these!triples? { x !=! x ',! d !=! x '- y '}! x !:=! x +1!{ x -1!=! x ',! d !=! x '- y '} { y !=! y '}! y !:=! y +1!{ y -1!=! y '}
  • If!we!combine!them!using!disjoint!parallelism,!we!can!get Ill.!Inst.!Tech.!CS 31 !of! 35 Tue,!Apr!7,! 2009 { x !=! x '!,! d !=! x '- y '!,! y !=! y '} [!{ x !=! x ',! d !=! x '- y '}! x !:=! x +1!{ x -1!=! x ',! d !=! x '- y '} ||!{ y !=! y '}! y !:=! y +1!{ y -1!=! y '}!] { x -1!=! x '!,! d !=! x '- y '!,! y -1!=! y '} { x - y !=! d }
  • But!it’s! not !the!case!that!( x - y !=! d )!%!( x !=! x '!,! d !=! x '- y '!,! y !=! y '),!so!we! can’t!“strengthen”!the!precondition!to! x - y !=! d.
  • We! can !show!{ x - y !=! d }! x '!:=! x ;! y '!:=! y !{ x !=! x '!,! d !=! x '- y '!,! y !=! y '},!so!we! can !prove!{ x - y !=! d }! x '!=! x ;! y '!=! y ;![ x !:=! x +1!||! y !:=! y +1]!{ x - y !=! d }.
  • Is!there!any!way!we!can!(semantically)!justify!throwing!away!the!as- signments!to! x '!and! y '?
    • Then!we!could!get!{ x - y !=! d }![ x !:=! x +1!||! y !:=! y +1]!{ x - y !=! d }
    • The!assignments!to! x '!and! y '!are!“auxiliary”!variables
      • They!don’t!affect!the!“actual”!computations,!they!just!support! the!proof!of!correctness. Science!of!Programming Spring’09 Notes!#1 1
  • So,!any!actual!calculations!involving! x '!and! y '!are!dispensable.! 6.3!What!makes!a!variable!auxiliary?!!
  • Intuitively,!a!variable!is!auxiliary!if!its!value!does!not!influence!the! values!of!any!variables!whose!values!we!are!actually!interested!in.
  • Purely! logical! variables !are!variables!that!don’t!appear!in!the!pro- gram!text!at!all,!just!in!the!conditions.
  • Purely!logical!variables!are!certainly!auxiliary.
  • Easy-to-determine!criterion,!but!limiting.
  • Write-only! variables !are!variables!that!appear!only!on!the!left-hand! side!of!assignments,!nowhere!else.
  • If!the!program!assigns!a!value!to!a!variable!but!never!looks!up!that! value!later!on,!the!variable!can’t!affect!the!value!of!any!computation! at!all,!much!less!the!ones!we!might!be!interested!in.
  • Another!easy-to-recognize!property,!but!it’s!still!limiting. E.g., if! x '! and! y '!are!auxiliary,!then!should! z !:=! x '+ y '!make z !auxiliary? Ill.!Inst.!Tech.!CS 33 !of! 35 Tue,!Apr!7,! 2009
  • Textbook’s! definition! of! auxiliary! variables :!A!set!of!variables! A is!a! set!of!auxiliary!variables!if!every!variable!in! A !only!appears!in!assign- ments!to!variables!in! A. (Other!variables!are!“program”!variables.)
  • No!variable!in! A !can!appear!in!an! if !test!or! while !test.
  • For!every!assignment! u !:=! t !in!the!program,!if! t !uses!any!variable! from! A ,!then! u !must!be!in! A .!(I. e .,! vars ( t )!"! A !#!#!%! u !.! A .)
  • OK:!program!variable!:=!program!variable
  • OK:!auxiliary!variable!:=!program!variable!+!auxiliary!vari- able
  • Not OK:!program!variable!:=!auxiliary!variable.
  • Example 1:!Take!the!program! x !:=! y ;^! y !:=! v + w ;! if! w !$!^0! then! x !:=! x +1! fi .!
  • The!set! A "!=!{ x }!is!a!set!of!auxiliary!variables.
  • x !doesn’t!appear!in!the! if !test.
  • The!only!assignment!that!has! x !on!the! right-hand !side!is! x !:=! x +^1 ,! and!the!left-hand!side!variable!(i. e .,! x )!is!in!{ x }. Science!of!Programming Spring’09 Notes!#1 1