This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Array Assignments; More Parallelism CS 536 Notes, Lecture 12, Mon Nov 22, 2010 A. Why Array assignments arent like assignments to plain variables because the actual item to change cant be determined until runtime. We can handle this by extending our notion of assignment and/or substitution. Going back to parallel programs, wed like to loosen the restrictions imposed on disjoint parallel programs. B. Outcomes After this lecture, you should Know how to perform textual substitution to replace an array element. Know how to calculate the wp of an array element assignment. Know how to combine correctness proofs for threads with disjoint programs and conditions. Know how auxiliary variables allow us to say something about coordinating the activities of disjoint threads. C. Array Assignments An array assignment b[ e ]:= t (where e and t are expressions) is different from a plain variable assignment because the exact element being changed may not be known at program annotation time. There are two alternatives for handling array assignments The one well use involves extending the notion of textual substitution: { P [ t / b[ e ] } b[ e ]:= t { P } The Dijkstra/Gries technique is to introduce a new kind of expression and view the array assignment b[ e ]:= t as short for b:= this new kind of expression. If we have time later (we probably wont), well study this. D. Substitution for Array Elements Given an array assignment b[ e ]:= t and a predicate P or expression s , what should P [ t / b[ e ] ] or s [ t / b[ e ] ] be? The important cases involve variables: For any simple variable u , ( u )[ t / b[ e ] ] is u . So, e.g., ( x+y )[ 1 / b[0] ] is ( x )[ 1 / b[0] ]+ ( y )[ 1 / b[0] ] is x+y . Substitution into an array expression is the other basic case. If b and c are different array names then ( c[j] )[ t / b[ e ] ] is c[j] . If the index for c is a more complicated expression, we need to check for substitutions inside of it: ( c[ e ] ) [ t / b[ e ] ] is c[ ( e )[ t / b[ e ] ] ] . Illinois Institute of Technology Notes for Lecture 12 CS 536: Science of Programming  1 of 9  James Sasaki, 2010 E.g., ( c[b[n]] ) [ 2 / b[n] ] should have the same value as c[2] (though depending on how we define the substitution rules, they might be syntactically different). The most interesting case is when the the array names match, as in ( b[i] )[ t / b[ e ] ]. If i = e , then ( b[i] )[ t / b[ e ] ] should have the same value as t . If i e , then ( b[i] )[ t / b[ e ] ] should have the same value as b[i] . We can summarize this by defining ( b[i] )[ t / b[e] ] to be the conditional expression (if i = e then t else b[i] fi) ....
View
Full
Document
This note was uploaded on 04/17/2011 for the course CS 536 taught by Professor Cs536 during the Fall '08 term at Illinois Tech.
 Fall '08
 cs536

Click to edit the document details