You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 \geq0$.
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}
42
48
\end{examplebox}
43
49
44
50
\begin{examplebox}{Now it all adds up!}
@@ -52,6 +58,40 @@ \subsubsection{Properties}
52
58
}{3 + (2 + 1)}{6}\]
53
59
\end{examplebox}
54
60
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}{}\]
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
+
55
95
\begin{exambox}{1a}{2021/22}
56
96
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):
57
97
\[C ::= exit \ | \ x := E \ | \ goto(i) \ | \ goto(B, i, j)\]
0 commit comments