Skip to content

Commit e923eb7

Browse files
committed
50003: Fixed totality example and added short circuiting example
1 parent f4c0cb7 commit e923eb7

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed
Binary file not shown.

50003 - Models of Computation/while_language/while_language.tex

+46-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@ \subsubsection{Properties}
3333
\end{tcbraster}
3434

3535
\begin{examplebox}{Break it!}
36-
How could we break the totality of SimpleExp?
37-
\tcblower
38-
\[\bigstepdef{B-NON-TOTAL}{}{true}{true}{}\]
39-
We can break \textit{totality} by introducing a rule that can always match its output.
40-
\\
41-
\\ The B-NON-TOTAL rule can be applied indefinitely (possible evaluation path that never finishes).
36+
We introduce a subtraction operator with big step rule:
37+
\[\bigstepdef{B-SUB}{E_1 \Downarrow n_1 \qquad E_2 \Downarrow n_2}{E_1 - E_2}{n_3}{n_3 = n_1 - n_2}\]
38+
What properties of simpleExp does this break? How could this be resolved.
39+
\tcblower
40+
It breaks totality as we specify $n \in \mathbb{N}$, hence $n \geq 0$.
41+
\[\text{for example } \quad \bigstep{?}{\bigstep{B-NUM}{}{3}{3} \qquad \bigstep{B-NUM}{}{4}{4}}{3 - 4}{?}\]
42+
We could fix this by:
43+
\begin{itemize}
44+
\item Changing the set of $n$ to include negative numbers
45+
\item Use saturating arithmetic, and fix negative subtraction to zero by modifying the B-SUB rule to have $n_3 = n_1 - n_2 \text{ where } n_1 \geq n_2$, and introducing a new saturated arithmetic rule for $n_1 < n_2$.
46+
\item Add a new result value to represent a non-number/underflow. $n \in \mathbb{N} \cup \{ Nan \}$ and set negative results to $NaN$
47+
\end{itemize}
4248
\end{examplebox}
4349

4450
\begin{examplebox}{Now it all adds up!}
@@ -52,6 +58,40 @@ \subsubsection{Properties}
5258
}{3 + (2 + 1)}{6}\]
5359
\end{examplebox}
5460

61+
\begin{examplebox}{C Semantics \& Short Circuiting in Big-Step}
62+
In this module short-circuiting and side-effects have been kept separate, however this typically not the case (expressions with assignment, using results of functions in expressions).
63+
\begin{minted}{C}
64+
int main() {
65+
bool a = false;
66+
bool b = true || (a = true);
67+
// a is false, b is true
68+
}
69+
\end{minted}
70+
Create basic big-step operational semantics rules for an extension to SimpleExp boolean expressions that contains:
71+
\begin{itemize}
72+
\item Assignments in expressions $B ::= x \ | \ B \lor B \ | \ B \land B \ | \ \neg B \ | \ x : = B$ where $x$ is a variable identifier $x \in Var$, assignment evaluates to the assigned value.
73+
\item A variable store $s$ ($Var \rightharpoonup \{true, false \}$), much like the While language.
74+
\item A big-step derivation rule of form $\langle B, s \rangle \Downarrow_b \langle s', b \rangle$ (program and store $\to$ final store and expression value).
75+
\end{itemize}
76+
We want determinacy and totality to be preserved, provide a suggestion of a rule that could be added to your solution to break either.
77+
\tcblower
78+
\[\bigstepdef{B-BOOL}{}{\langle b, s \rangle}{\langle s, b \rangle}{} \qquad \bigstepdef{B-NEG-FALSE}{\langle B, s \rangle \Downarrow_b \langle s', false \rangle}{\langle \neg B, s \rangle}{\langle s', true \rangle}{} \qquad \bigstepdef{B-NEG-TRUE}{\langle B, s \rangle \Downarrow_b \langle s', true \rangle}{\langle \neg B, s \rangle}{\langle s', false \rangle}{}\]
79+
\[\bigstepdef{OR-SC}{\langle B_1, s \rangle \Downarrow_b \langle s', true \rangle}{\langle B_1 \lor B_2, s \rangle \lor }{\langle s', true \rangle}{} \qquad \bigstepdef{OR-EXH}{\langle B_1 , s \rangle \Downarrow_b \langle s'', false \rangle \qquad \langle B_2, s'' \rangle \Downarrow_b \langle s', b \rangle}{\langle B_1 \lor B_2, s \rangle}{\langle s', b \rangle}{}\]
80+
\[\bigstepdef{AND-SC}{\langle B_1, s \rangle \Downarrow_b \langle s', false \rangle}{\langle B_1 \land B_2, s \rangle}{\langle s', false \rangle}{} \qquad \bigstepdef{AND-EXH}{\langle B_1, s \rangle \Downarrow_b \langle s'', true \rangle \qquad \langle B_2, s'' \rangle \Downarrow_b \langle s', b \rangle}{\langle B_1 \land B_2, s \rangle}{\langle s', b \rangle}{}\]
81+
\[\bigstepdef{ASSIGN}{\langle B, s \rangle \Downarrow_b \langle s'', b \rangle \qquad s' = [x \mapsto b]}{\langle x := B, s \rangle}{\langle s', b \rangle}{}\]
82+
Hence we can now create derivations such as:
83+
\begin{minted}{C}
84+
bool x;
85+
(x = true) || (x = false);
86+
\end{minted}
87+
\[\bigstepdef{OR-SC}{
88+
\bigstepdef{ASSIGN}{
89+
\bigstepdef{B-BOOL}{}{true}{true}{} \qquad (x \mapsto true) = ()[x \mapsto true]
90+
}{\langle x := true, () \rangle}{\langle (x \mapsto true), true \rangle}{}
91+
}{\langle (x := true) \lor (x := false), () \rangle}{\langle (x \mapsto true), true \rangle}{}\]
92+
We can break determinacy by adding short-circuiting rules for the right hand side (e.g $b \lor true \Downarrow true$) of $\lor$ and $\land$.
93+
\end{examplebox}
94+
5595
\begin{exambox}{1a}{2021/22}
5696
Consider the language $GOTO$, comprising of the standard expressions $E$, boolean expressions $B$ and the following commands (where $i,j \in \mathbb{N}$ are natural numbers):
5797
\[C ::= exit \ | \ x := E \ | \ goto(i) \ | \ goto(B, i, j)\]

0 commit comments

Comments
 (0)