\documentclass[11pt]{article}
\usepackage{palatino}
\usepackage{latexsym}
\usepackage{verbatim}
\usepackage{alltt}
\usepackage{amsmath,proof,amsthm,amssymb,enumerate,mathabx}
\usepackage{china2e} % to get \Integer, \Natural
\usepackage{math-cmds}
\usepackage{listings}

% FIXME be more precise about parens in question 2

\newcommand{\question}[2]
  {\bigskip \noindent
   {\bf Question #1} (#2 points).}

\newcommand{\extracreditquestion}[1]
  {\bigskip \noindent
   {\bf Question #1} (EXTRA CREDIT).}

\newcommand{\definition}[2]
  {\bigskip
   \begin{tabular}{p{1.5in}p{4.0in}}
        \textbf{#1} & #2 \\
        \end{tabular}
  }

\def\prop{\textsf{\,\,prop}}
\def\thm{\textsf{\,\,thm}}
\def\implies{\Rightarrow}

\newcommand{\parg}[1] % program argument
  {\ldbrack #1 \rdbrack}
  
\newcommand{\join}{\sqcup}
\newcommand{\meet}{\sqcap}
\newcommand{\alap}{\sqsubseteq}



\title{Assignment 3 (Written):\\
Dataflow Analysis}
\author{15-819O: Program Analysis\\
        Jonathan Aldrich\\
		{\tt jonathan.aldrich@cs.cmu.edu}}
\date{Due: Monday, February 11, 2013 (11:59 pm) \\[1em]
100 points total
}

\begin{document}
\begin{sloppypar}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}

\newcommand{\pfalse}{\mbox{false}}
\newcommand{\ptrue}{\mbox{true}}
\newcommand{\pand}{\mbox{and}}
\newcommand{\por}{\mbox{or}}
\newcommand{\pskip}{\mbox{skip}}
\newcommand{\pif}{\mbox{if}}
\newcommand{\pthen}{\mbox{then}}
\newcommand{\pelse}{\mbox{else}}
\newcommand{\pdo}{\mbox{do}}
\newcommand{\pwhile}{\mbox{while}}




\maketitle

Turn in a PDF file electronically via Blackboard for Assignment 3.  The file should contain the answers to the questions below.  At the top of the document, state your name and andrew ID.

\vspace{1ex}\noindent\textbf{Assignment Objectives:}
\begin{itemize}
\item Prove a simple dataflow analysis correct, and demonstrate the problem with an incorrect dataflow analysis.
\end{itemize}


\clearpage

\section{Local Soundness (25 points)}

Consider the following hypothetical flow function for sign analysis:

\[
f\parg{x := y + z}(\sigma) = [x \mapsto +] \sigma
\]

This flow function is ``obviously'' incorrect.  However, to prove that
it is incorrect, you must show that it violates the criterion of local
soundness defined in class.  That is, you must find a program configuration
 $E,n$ and an instruction $I$ such that $P \vdash E,n \leadsto E',n'$ (where $P(n)=I$) 
and $\alpha(E', n') \not\alap f\parg{I}(\sigma)$
with $\sigma = \alpha(E,n)$.  For simplification, we will ignore $n$ as an argument to $\alpha$ as it is not relevant for this analysis.
You may assume the less
precise lattice from Question 2 in the first assignment.

\question{1.1}{5}
\begin{quote}
Define $\alpha(E)$ for sign analysis.
\end{quote}

\question{1.2}{5}
\begin{quote}
Find a pair of $E$ and $I$ that illustrates the local unsoundness.
What are $E$ and $I$?
\end{quote}

\question{1.3}{2}
\begin{quote}
What is $\sigma=\alpha(E)$?
\end{quote}

\question{1.4}{3}
\begin{quote}
If $P \vdash E,n \leadsto E',n'$, what is $E',n'$?
\end{quote}

\question{1.5}{2}
\begin{quote}
What is $\alpha(E')$?
\end{quote}

\question{1.6}{4}
\begin{quote}
What is $\sigma'=f\parg{I}(\sigma)$?
\end{quote}

\question{1.7}{4}
\begin{quote}
Show that $\alpha(E') \not\sqsubseteq \sigma'$
\end{quote}

\clearpage

\section{Analysis Correctness (75 points)}

\question{2}{20}

\begin{quote}
Define a correct flow sign analysis function for addition.  Also
define flow functions for copy, constant assignment, and (unconditional) jump.  Your definitions should assume ideal integer arithmetic.
They should be precise.
\end{quote}

\question{3}{20}

\begin{quote}
Show (i.e. prove) that your flow functions are monotonic.
\end{quote}


\question{4}{5}

\begin{quote}
Give the height of the dataflow lattice that maps each variable to one
of the simple lattice elements from question 2 in the first
assignment.  The height should be expressed in terms of $|\textit{Var}|$, the
number of variables in scope.  Briefly justify your answer.

Note that together with the monotonicity of your flow functions,
termination of your analysis is guaranteed.
\end{quote}


\question{5}{30}

\begin{quote}
Prove that your flow functions are locally sound with respect to
the semantics given in class.
\end{quote}







\end{sloppypar}
\end{document}
