%%% This is the scribe notes template for CS611
%%% There are several comments preceded by CS611: and boxed in %%%%'s
%%% which indicate where macros should be altered to set up the header
%%% for the paper.  Your Notes should go at the comment SCRIBE NOTES GO HERE!.

%%% In the various .sty files that accompany this .tex file you will
%%% find LaTeX macros that make it easier to typeset inference rules
%%% and programming language constructs.  You must make sure that the
%%% file proof.sty is in a path searched by LaTeX when you try to
%%% use this file.  Take a look to see what macros are available--it
%%% will save you time and make the notes look better.  Feel free to
%%% extend the set of macros--post them to the newsgroup and contact
%%% the course staff if you come up with some good ones so they can be
%%% added to the template.

%%% This template includes examples of how to use some of the macros
%%% to give you an idea of how they work.  (Delete the examples when
%%% you do your scribing.)

\documentclass{article} \usepackage{611-lecture}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% CS611: Please fill in these macros as appropriate:
\lecture{5}                            %% Lecture number
\title{IMP: Big-Step \& Small-Step Semantics}   %% Title of lecture
\author{Kevin Markman and Jon Guarino} %% name of scribe
\date{07 September, 2005}              %% Date of lecture, e.g., 1 January 2001
\lecturer{Radu Rugina}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% See 611.sty for a variety of macros that will be helpful in
% typesetting the lecture. Here are a few of particular interest:
%
% "x"	 	x in keyword font (e.g., "if", "#t")
% _x_	 	x in italics
% \nm{n}   	n in slanted font (used for abbreviations)
% <e> 	 	e in angle brackets
% \lt 	 	less-than sign
% \gt 	 	greater-than sign
% \SB{x}	x in semantic brackets
% \Tr x{y} 	x[[y]] with x in calligraphic font
%          	(if x is more than a single character, use \Tr{x}{y})

\begin{document}

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% CS611: SCRIBE NOTES GO HERE!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Today's lecture presented a simple imperative language, IMP, and
gave the small-step and big-step rules for evaluation. These notes provide the following:

\begin{itemize} % use enumerate for numbered list
\item The IMP language syntax
\item A small-step semantics for IMP
\item A big-step semantics for IMP
\item Some notes on why both can be useful
\end{itemize}

\section{Syntax}

There are three types of statements in IMP:

\begin{itemize}
\item Arithemetic expressions: \nm{AExp}
\item Boolean expressions: \nm{BExp}
\item Commands: \nm{Com}
\end{itemize}

A program in the IMP language is a command, $c \in Com$.
Suppose $n$ denotes an integer literal, $x$ denotes a variable name,
$a_i$ denotes an arithmetic expression, $b_i$ denotes a boolean
expressions, and $c_i$ represents a command. The grammar follows:

\begin{eqnarray*}
\nm{AExp} & ::= & n \bnf x \bnf ("a_0~\oplus~a_1") \\
\nm{BExp} & ::= & \TRUE \bnf \FALSE \bnf ("a_0~\odot~a_1") \bnf
        ("b_0~\oslash~b_1") \\
\nm{Com} & ::= & \SKIP \bnf x:=a \bnf ("c_0~;~c_1") \bnf
        (\IF~b~\THEN~c_1~\ELSE~c_2) \bnf (\WHILE~b~\DO~c~) \\
\nm{$\oplus$} & ::= & "+" \bnf "*" \bnf - \\
\nm{$\odot$} & ::= & \leq \bnf = \\
\nm{$\oslash$} & ::= & \vee \bnf \wedge \\
\end{eqnarray*}

\subsection{Configurations}

Configurations are pairs, $<c,\sigma>$, where:
\begin{itemize}
\item $c \in Com$ is a command
\item $\sigma$ is a store (also known as a state or environment) \\
$\sigma \in (\sum = Var \rightarrow \mathbb{Z})$ where $\sum$ is all
possible stores
\end{itemize}

\section{Structural Operational Semantics: Small-Step Semantics}

We can evaluate a configuration ``one step at a time'' until we reach
the final configuration, $<\SKIP,\sigma>$:

\[<c,\sigma>\rightarrow<c',\sigma'>\]
\[<c,\sigma_0>\rightarrow<c_1,\sigma_1>\rightarrow...\rightarrow
<c_k,\sigma_k>\rightarrow<\SKIP,\sigma> \]
\begin{flushleft}
We can represent this more tersly using closure:
\end{flushleft}
\[<c,\sigma_0>\rightarrow^{*}<\SKIP,\sigma>\]

\begin{flushleft}
To be proper, we should define the $\rightarrow$ operator for
commands\footnotemark, arithmetic expressions, and boolean expressions:
\end{flushleft}
\footnotetext{Winskel uses $\rightarrow_1$ instead of $\rightarrow$ to
 emphasize that only a single step is performed}

\begin{eqnarray*}
\rightarrow & \in & (Com\times\sum)\rightarrow(Com\times\sum) \\
\rightarrow_a & \in & (AExp\times\sum)\rightarrow AExp \\
\rightarrow_b & \in & (BExp,\times\sum)\rightarrow BExp
\end{eqnarray*}

\begin{flushleft}
We will use $\rightarrow$ as shorthand for all three operations.
\end{flushleft}

\subsection{Arithmetic \& Boolean Expressions}
\begin{itemize}
\item
Constants:
\noindent
\begin{tabular}{ccc}
no rule (already fully reduced)
\end{tabular}
\item
Variables:
\begin{tabular}{ccc}
\infer{<x,\sigma>\rightarrow\sigma(x)}{}
\end{tabular}
\item
Operations:
\begin{tabular}{ccc}
\infer{<a_0 \oplus a_1,\sigma>\rightarrow
a'_0 \oplus a_1}{<a_0,\sigma>\rightarrow a'_0} &
\infer{<n \oplus a_1,\sigma>\rightarrow n \oplus
a'_1}{<a_1,\sigma>\rightarrow a'_1} &
\infer{<n_0 \oplus n_1,\sigma>\rightarrow n}{}
where $n=n_0 \oplus n_1$
\end{tabular}
\item
Corresponding rules of the above form exist for boolean expressions
using $\odot$ and $\oslash$ operators
\end{itemize}

\subsection{Commands}
\begin{itemize}
\item
Skip:
\begin{tabular}{ccc}
no rule ($<\SKIP,\sigma>$ is a final configuration)
\end{tabular}
\item
Assignments:
\begin{tabular}{cc}
\infer{<x:=a,\sigma>\rightarrow<x:=a',\sigma>}
{<a,\sigma>\rightarrow a'} &
\infer{<x:=n,\sigma>\rightarrow<\SKIP,\sigma[x\mapsto n]>}{}
\end{tabular}
\item
Sequences:
\begin{tabular}{cc}
\infer{<c_0;c_1,\sigma>\rightarrow<c_0';c_1,\sigma'>}
{<c_0,\sigma>\rightarrow<c_0',\sigma'>} &
\infer{<\SKIP;c_1,\sigma>\rightarrow<c_1,\sigma>}{}
\end{tabular}
\item
If Statements:
\begin{tabular}{l}
\infer{<$\IF~b~\THEN~c_0~\ELSE~c_1$,\sigma>\rightarrow
 <$\IF~b'~\THEN~c_0~\ELSE~c_1$,\sigma>}{<b,\sigma>\rightarrow b'}\\
\\
\infer{<\IF~\TRUE~\THEN~c_0~\ELSE~c_1,\sigma>\rightarrow<c_0,\sigma>}{}\\
\\
\infer{<\IF~\FALSE~\THEN~c_0~\ELSE~c_1,\sigma>\rightarrow<c_1,\sigma>}{}
\end{tabular}
\item
While Statements:
\begin{tabular}{c}
\infer{<\WHILE~b~\DO~c,\sigma>\rightarrow<\IF~b~\THEN~(c;\WHILE~b~\DO~c)
\ELSE~\SKIP,\sigma>}{}
\end{tabular}
\end{itemize}

\section{Structural Operational Semantics: Big-Step Semantics}

As an alternative to ``one step at a time'' evaluation, we now consider
a step in evaluation to mean the entire transition from an expression
and state to a final value.  For example:

\begin{tabular}{ll}
\\ $<c,\sigma>\stepsto\sigma'$ & (steps to the final store of
 its final configuration)\\
$<a,\sigma>\stepsto n$ & (steps to its final integer value)\\
$<b,\sigma>\stepsto t$ & (steps to t where $t \in  \{\TRUE,\FALSE\}$)\\
\end{tabular}

\begin{flushleft}
The rules for specific commands are as follows.
\end{flushleft}

\begin{itemize}
\item
Skip:
\begin{tabular}{c}
\infer{<\SKIP,\sigma>\stepsto\sigma}{}
\end{tabular}
\item
Assignments:
\begin{tabular}{c}
\infer{<x:=a,\sigma>\stepsto\sigma[x\mapsto n]}
 {<a,\sigma>\stepsto n}
\end{tabular}
\item
Sequences:
\begin{tabular}{c}
\infer{<c_0;c_1,\sigma>\stepsto\sigma'}
 {<c_0,\sigma>\stepsto\sigma''~~~<c_1,\sigma''>\stepsto\sigma'}
\end{tabular}
\item
If Statements:
\begin{tabular}{cc}
\infer{<\IF~b~\THEN~c_0~\ELSE~c_1,\sigma>\stepsto\sigma'}
 {<b,\sigma>\stepsto\TRUE~~~<c_0,\sigma>\stepsto\sigma'} &
\infer{<\IF~b~\THEN~c_0~\ELSE~c_1,\sigma>\stepsto\sigma'}
 {<b,\sigma>\stepsto\FALSE~~~<c_1,\sigma>\stepsto\sigma'}
\end{tabular}
\item
While Statements:
\begin{tabular}{cc}
\infer{<\WHILE~b~\DO~c,\sigma>\stepsto\sigma}
 {<b,\sigma>\stepsto\FALSE} &
\infer{<\WHILE~b~\DO~c,\sigma>\stepsto\sigma'}
 {<b,\sigma>\stepsto\TRUE~~~<c,\sigma>\stepsto\sigma''
 ~~~<\WHILE~b~\DO~c,\sigma''>\stepsto\sigma'}
\end{tabular}
\end{itemize}

\section{Big-Step vs. Small-Step SOS}
\subsection{Small-Step}
\begin{itemize}
\item
can model more complex features, like programs which
run forever and concurrency
\item
Although ``one step at a time'' evaluation is useful for
proving certain properties, in many cases it is unnecessary
extra work.
\end{itemize}
\subsection{Big-Step}
\begin{itemize}
\item
large steps in reasoning make it easier to prove things
\item
more closely models an actual recursive interpreter
\end{itemize}
\begin{itemize}
\item
Because evaluation skips over intermediate steps, all
programs without final configurations (infinite loops,
errors/stuck configs) look the same.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
