Docsity

Homework 1 for CMSC 631, Fall 2006: Monotonic Functions and Lattices in Computer Science -, Assignments of Computer Science

Toggle sidebar
bg1
CMSC 631, Fall 2006
Homework 1
Due Wednesday, Sept. 20, in class
1. Let Sbe a finite set, and let Lbe the lattice of subsets of S, with order ⊆. Show that any function
f(x) constructed from union, intersection, and constant sets is monotonic. Here, I mean that f(x) = e
where ecan be specified by the grammar
e::= x|S0|e∪e|e∩e
where S0is any subset of S. Your proof should be by induction on the structure of e.
2. Suppose that we extend the grammar for efrom problem 1 to include the complement operator !e,
where !T=S−Tfor some set T. Is fstill guaranteed to be monotonic? If it is, justify your answer. If
it’s not, provide a counterexample. In addition, explain why a transfer function defined by Out(stmt)
= Gen(stmt) ∪(In(stmt) - Kill(stmt)), which seems to include negation, is monotonic.
3. Let Abe a lattice, with order ≤. Define A→Ato be the set of all functions from Ato A, and define
f≤0giff f(x)≤g(x) for all x∈A.
•Show that A→Awith order ≤0is also a lattice. That is, show that for all f, g ∈A→A,ftg
and fugalways exist.
•Suppose lattice Ahas height hand that Ais finite with nelements. What is the height of the
lattice (A→A, ≤0)? (When counting height, count “edges” rather than “nodes,” e.g., if Awere
the lattice {a, b}with a < b, then its height would be 1.)
4. A programming language ensures definite initialization when no program in the language is able to
read a variable before it is initialized (written). Your task is to ensure that this property holds by
designing a dataflow analysis on a simplification of the 3-address code language from project 1 (doesn’t
include arrays):
lab stmt ::= stmt
|identifier :stmt
stmt ::= id:=arg1binop arg2;
|id:=arg;
|goto label;
|if arg1relop arg2goto label;
binop ::= +|-|*|/
relop ::= == |!= |<|>|>= |<=
id ::= identifier
label ::= identifier
arg ::= identifier |constant
Write down the following about your analysis:
(a) State precisely what your analysis aims to do. Explain how this will be used to ensure definite
initialization.
(b) Give the direction of your analysis.
(c) Define the lattice, and define the meet operation.
(d) State how you would initialize the dataflow facts at each program point, including the entry or
exit nodes, as appropriate.
(e) Give the transfer functions (e.g., in terms of Gen and Kill functions) for each three-address code
statement.

Partial preview of the text

Download Homework 1 for CMSC 631, Fall 2006: Monotonic Functions and Lattices in Computer Science - and more Assignments Computer Science in PDF only on Docsity!

CMSC 631, Fall 2006

Homework 1

Due Wednesday, Sept. 20, in class

  1. Let S be a finite set, and let L be the lattice of subsets of S, with order ⊆. Show that any function f (x) constructed from union, intersection, and constant sets is monotonic. Here, I mean that f (x) = e where e can be specified by the grammar

e ::= x | S′^ | e ∪ e | e ∩ e where S′^ is any subset of S. Your proof should be by induction on the structure of e.

  1. Suppose that we extend the grammar for e from problem 1 to include the complement operator !e, where !T = S − T for some set T. Is f still guaranteed to be monotonic? If it is, justify your answer. If it’s not, provide a counterexample. In addition, explain why a transfer function defined by Out(stmt) = Gen(stmt) ∪ (In(stmt) - Kill(stmt)), which seems to include negation, is monotonic.
  2. Let A be a lattice, with order ≤. Define A → A to be the set of all functions from A to A, and define f ≤′^ g iff f (x) ≤ g(x) for all x ∈ A. - Show that A → A with order ≤′^ is also a lattice. That is, show that for all f, g ∈ A → A, f t g and f u g always exist. - Suppose lattice A has height h and that A is finite with n elements. What is the height of the lattice (A → A, ≤′)? (When counting height, count “edges” rather than “nodes,” e.g., if A were the lattice {a, b} with a < b, then its height would be 1.)
  3. A programming language ensures definite initialization when no program in the language is able to read a variable before it is initialized (written). Your task is to ensure that this property holds by designing a dataflow analysis on a simplification of the 3-address code language from project 1 (doesn’t include arrays): lab stmt ::= stmt | identifier : stmt stmt ::= id:=arg 1 binop arg 2 ; | id:=arg; | goto label; | if arg 1 relop arg 2 goto label; binop ::= + | - | * | / relop ::= == | != | < | > | >= | <= id ::= identifier label ::= identifier arg ::= identifier | constant Write down the following about your analysis:

(a) State precisely what your analysis aims to do. Explain how this will be used to ensure definite initialization. (b) Give the direction of your analysis. (c) Define the lattice, and define the meet operation. (d) State how you would initialize the dataflow facts at each program point, including the entry or exit nodes, as appropriate. (e) Give the transfer functions (e.g., in terms of Gen and Kill functions) for each three-address code statement.