Tuesday, September 2, 2025
What questions do you have? What questions does your neighbor have?
\[ \begin{array}{rrrl} \text{statements} & s& \mathrel{::=}& \texttt{;} \mid x \mathrel{\texttt{=}}e \mid s_1 \mathbin{\texttt{;}} s_2 \mid\mathbf{if}\;\texttt{(}e\texttt{)}\;s_1\;\mathbf{else}\;s_2 \mid\mathbf{while}\;\texttt{(}e\texttt{)}\;s_1 \end{array} \]
\[ \fbox{$\rho \vdash s \Downarrow\rho'$} \]
\[ \begin{array}{rrrl} \text{stores} & \rho& \mathrel{::=}& \circ \mid\rho,x \mapsto v \end{array} \]
Define a judgment form \(\rho \vdash s \Downarrow\rho'\) that says, “In store \(\rho\), statement \(s\) executes to yield store \(\rho'\).”
\[ \fbox{$\rho \vdash s \Downarrow\rho'$} \]
\(\inferrule[EvalSkip]{ \phantom{\Downarrow} }{ \rho \vdash \texttt{;} \Downarrow\rho }\)
\(\inferrule[EvalAssign]{ \rho \vdash e \Downarrow v }{ \rho \vdash x \mathrel{\texttt{=}}e \Downarrow \rho(x \leftarrow v) }\)
\(\inferrule[EvalSeq]{ \rho \vdash s_1 \Downarrow\rho' \and \rho' \vdash s_2 \Downarrow\rho'' }{ \rho \vdash s_1 \mathbin{\texttt{;}} s_2 \Downarrow \rho'' }\)
\(\inferrule[EvalIfTrue]{ \rho \vdash e \Downarrow\mathbf{true} \and \rho \vdash s_1 \Downarrow\rho' }{ \rho \vdash \mathbf{if}\;\texttt{(}e\texttt{)}\;s_1\;\mathbf{else}\;s_2 \Downarrow \rho' }\)
\(\inferrule[EvalIfFalse]{ \rho \vdash e \Downarrow\mathbf{false} \and \rho \vdash s_2 \Downarrow\rho' }{ \rho \vdash \mathbf{if}\;\texttt{(}e\texttt{)}\;s_1\;\mathbf{else}\;s_2 \Downarrow \rho' }\)
\(\inferrule[EvalWhileFalse]{ \rho \vdash e \Downarrow\mathbf{false} }{ \rho \vdash \mathbf{while}\;\texttt{(}e\texttt{)}\;s_1 \Downarrow \rho }\)
\(\inferrule[EvalWhileTrue]{ \rho \vdash e \Downarrow\mathbf{true} \and \rho \vdash s_1 \mathbin{\texttt{;}} \mathbf{while}\;\texttt{(}e\texttt{)}\;s_1 \Downarrow \rho' }{ \rho \vdash \mathbf{while}\;\texttt{(}e\texttt{)}\;s_1 \Downarrow \rho' }\)
Theorem 1 (Evenness Invariant, Operationally) For any expression \(e\) and store \(\rho\) such that \(\rho(\texttt{i})\) is even, if \[ \mathcal{E} :: \rho \vdash \mathbf{while}\;\texttt{(}e\texttt{)}\; \texttt{i} \mathrel{\texttt{=}} \texttt{i} \mathbin{\texttt{+}} \texttt{2} \Downarrow\rho' \] then \(\rho'(\texttt{i})\) is even.
Proof. By induction on derivation \(\mathcal{E}\).
Proof. By induction on derivation \(\mathcal{E}\).
| \(\rho' = \rho\) | by assumption |
| \(\rho'(\texttt{i})\) is even | by assumption |
| \(\mathcal{E_{11}} :: \rho \vdash \texttt{i} \mathrel{\texttt{=}} \texttt{i} \mathbin{\texttt{+}} \texttt{2} \Downarrow\rho''\) and \(\mathcal{E_{12}} :: \rho'' \vdash \mathbf{while}\;\texttt{(}e\texttt{)}\; \texttt{i} \mathrel{\texttt{=}} \texttt{i} \mathbin{\texttt{+}} \texttt{2} \Downarrow \rho' \) | for some store \(\rho''\) by inversion on \(\mathcal{E_1}\) |
| \(\mathcal{E_{111}} :: \rho \vdash \texttt{i} \mathbin{\texttt{+}} \texttt{2} \Downarrow v' \) | for some value \(v'\) s.t. \(\rho''(\texttt{i}) = v'\) by inversion on \(\mathcal{E_{11}}\) |
| \(\rho \vdash \texttt{i} \Downarrow \rho(\texttt{i}) \) and \(\rho \vdash \texttt{2} \Downarrow 2 \) s.t. \(v' = \rho(\texttt{i}) + 2\) | by inversion on \(\mathcal{E_{111}}\) |
| \(v'\) is even | by arithmetic |
| \(\rho''(\texttt{i})\) is even | since \(\rho''(\texttt{i}) = v'\) |
| \(\rho'(\texttt{i})\) is even | by the i.h. on \(\mathcal{E_{12}}\) |
Define a judgment form \(\langle \rho, s \rangle \rightarrow\langle \rho', s' \rangle\) that says, “In store \(\rho\), statement \(s\) reduces to statement \(s'\) in store \(\rho'\) in one step.”
Prove an equivalence between big-step evaluation and small-step reduction. You will first need to define iterating the small-step relation to state the theorem. Then, you will need to come up with a lemma that relates single-step reduction with evaluation.