equal
deleted
inserted
replaced
767 |
767 |
768 \ifsem |
768 \ifsem |
769 \subsection{Exercises} |
769 \subsection{Exercises} |
770 |
770 |
771 \begin{exercise} |
771 \begin{exercise} |
|
772 In \autoref{sec:AExp} we defined a recursive evaluation function |
|
773 @{text "aval :: aexp \<Rightarrow> state \<Rightarrow> val"}. |
|
774 Define an inductive evaluation predicate |
|
775 @{text "aval_rel :: aexp \<Rightarrow> state \<Rightarrow> val \<Rightarrow> bool"} |
|
776 and prove that it agrees with the recursive function: |
|
777 @{prop "aval_rel a s v \<Longrightarrow> aval a s = v"}, |
|
778 @{prop "aval a s = v \<Longrightarrow> aval_rel a s v"} and thus |
|
779 \noquotes{@{prop [source] "aval_rel a s v \<longleftrightarrow> aval a s = v"}}. |
|
780 \end{exercise} |
|
781 |
|
782 \begin{exercise} |
772 Consider the stack machine from \autoref{sec:aexp_comp}. |
783 Consider the stack machine from \autoref{sec:aexp_comp}. |
773 A \concept{stack underflow} occurs when executing an instruction |
784 A \concept{stack underflow} occurs when executing an instruction |
774 on a stack containing too few values, e.g., executing an @{text ADD} |
785 on a stack containing too few values, e.g., executing an @{text ADD} |
775 instruction on a stack of size less than two. Define an inductive predicate |
786 instruction on a stack of size less than two. Define an inductive predicate |
776 @{text "ok :: nat \<Rightarrow> instr list \<Rightarrow> nat \<Rightarrow> bool"} |
787 @{text "ok :: nat \<Rightarrow> instr list \<Rightarrow> nat \<Rightarrow> bool"} |