POPL Lecture notes: PARLANG – a parallel interlude
Table of Contents
- 1. Introduction
- 2. Abstract Syntax
- 3. Stores
- 4. PARLANG abstract machine configurations
- 5. Rewrite Rules
- 6. Reduction
- 7. Lexicographic ordering
- 8. Normal forms, termination and non-confluence
- 8.1. Lemma (Termination): The PARLANG reduction system \(\goesto{}\) is terminating.
- 8.2. Exercise (non-confluence)
- 8.3. Derived reduction relation \(\xto{}{S}\)
- 8.4. Lemma (Progress): Either \(s=\textbf{done}\) or \(s\xto{}{S}\)
- 8.5. Corollary (Unique Normal Form): Every statement \(s\) simplifies under \(\xto{}{S}\) to \(\textbf{done}\) and to no other statement.
- 9. References and online resources
Changelog
UNNUMBERED: notoc
- Added definition of lexicographic order. Added proofs of termination and unique normal form for statements.
1 Introduction
The purpose of this short excursion is to investigate the behaviour of PARLANG, small parallel language, while we warm up for studying the confluence property for λ calculus. The language is a small, but with sufficiently interesting behaviour that allows us to conclude that it is a language that does not exhibit confluence. Recall that confluence is a property that says that if an expression simplifies to two expressions, then those two expressions further simplify to some common third expression. In PARLANG, a program's execution may result in multiple, possible answers. Answers depend on which of the permitted orders of execution are taken by the system.
In languages like PARLANG, non-confluence is a feature of the semantics. It is used to model phenomena like race conditions.
2 Abstract Syntax
The language consists of statements, variables and numbers:
\begin{align*} s ::= & & \scriptstyle{STMT} & \qquad \mbox{Statement}\\ & \textbf{done} & \scriptstyle{DONE} & \qquad \mbox{Done}\\ & x:=n & \scriptstyle{SET} & \qquad \mbox{Assignment}\\ & s; s & \scriptstyle{SEQ} & \qquad \mbox{Sequential}\\ & s | s & \scriptstyle{PAR} & \qquad \mbox{Parallel}\\ \\ x ::= & & \scriptstyle{IDENT} & \qquad \mbox{Identifiers}\\ \\ n ::= & & \scriptstyle{NUM} & \qquad \mbox{Numbers}\\ \\ \end{align*}
The language is small; there is no lexical scoping, if
,
functions, or primitive operations on numbers.
3 Stores
Stores map identifiers to values.
\begin{align*} G : \id{IDENT} \rightarrow \id{NUM} & \qquad \qquad \scriptstyle{STORE}\\ \end{align*}4 PARLANG abstract machine configurations
In the abstract PARLANG machine, a program is `executed' in the context of a store. A store is a map from identifiers to values.
A configuration is a pair \(G,s\) where \(G\) is a store and \(s\) is a statement.
5 Rewrite Rules
6 Reduction
7 Lexicographic ordering
Let \((A, <)\) be a (strict) partial order. A relation \((A^*, \sqsubset)\) is a (strict) lexicographic order over \((A,<)\) defined as \(a\sqsubset b\) iff
- \(a\) is a proper prefix of \(b\), OR
- there exists elements \(x,y\in A\) and strings \(p,q,r\in A^*\)
such that
- \(a=pxq\)
- \(b=pyr\)
- \(x < y\)
8 Normal forms, termination and non-confluence
8.1 Lemma (Termination): The PARLANG reduction system \(\goesto{}\) is terminating.
8.1.1 Proof
For a statement \(s\), define the following:
- 1. \(\id{parsym}(s)\): the number of `|' symbols in \(s\).
- 2. \(\id{seqsym}(s)\): the number of `;' symbols in \(s\).
- 3. \(\id{setsym}(s)\): the number of `:=' symbols in \(s\).
- 4. \(\id{donesym}(s)\): the number of \textbf{done} symbols in \(s\).
For any \(s\in \id{Stmt}\), let \(|s|: \N^4\) be defined as
\[|s| = \pair{\id{parsym}(s), \id{seqsym}(s), \id{setsym}, \id{donesym}(s)}\]
Examples:
- 1. \(|(x:=5 | \textbf{done})| = [1, 0, 1, 0]\)
- 2. \(|(\textbf{done} ; \textbf{done})| = [0, 0, 0, 2]\)
- 3. \(|((x:=4; \textbf{done}) | (x:=3 | y:=2))| = [1, 1, 3, 1]\)
Now, let \((\N^4, \sqsubset)\) be the subset of the lexicographic ordering over the total ordering \((\N, <)\). Clearly, \((\N^4, \sqsubset)\) is a strict well-ordering (a strict total order with every subset having a least element) and hence well-founded.
To show that \(\goesto{}\) terminates, we show the following:
\[ \text{if}\ (G,s) \goesto{} (G', s'), \text{then}\ |s'| \sqsubset |s| \]
In each case, we verify that a reduction reduces the size of the statement.
Case REWRITE: Then \((G,s)\rewritesto{} (G',s')\) for some stores \(G,G'\).
- 1. case ASSGN: \(s=\ (x:=n)\): Then \(s' = \textbf{done}\). and \([0,0,0,1] = |s'| \sqsubset |s| = [0,0,1,0]\).
- 2. case SEQ-DONE: \(s=\textbf{done}; s'\). If \(s=[i,j,k,l]\) where \(l>0\) and \(j>0\), then \(|s'|=(i, j-1, k, l-1)\). Clearly, \(|s'| \sqsubset |s|\).
- 3. cases PAR-1 and PAR-2: Exercise.
Case SEQ-COMP: Left as an exercise.
QED.
8.2 Exercise (non-confluence)
Show that \(\set{x:1} (x:=3\ | \ x:=4)\) simplifies to any of the following: \(\set{x:3}, \textbf{done}\) or \(\set{x:4}, \textbf{done}\).
8.3 Derived reduction relation \(\xto{}{S}\)
8.3.1 Rewrite rules
8.3.2 Reduction rules
\(\xto{}{S}\) is terminating since \(\goesto{}\) is.
Note that \(\textbf{done}\) is a normal form. We prove that for any statement \(s\), either \(s = \textbf{done}\), or \(s\xto{}{S}s'\) for some \(s'\). Since the reduction relation is terminating, it follows that every statement \(s\) simplifies to the normal form \(\textbf{done}\).
8.4 Lemma (Progress): Either \(s=\textbf{done}\) or \(s\xto{}{S}\)
8.4.1 Proof
The proof is by induction on the structure of \(s\):
- 1. \(\textbf{done}\), so the proposition is trivially true
- 2. \(s=(x:=n)\): Then we have
- 2.1: \(s\rewritesto{} \textbf{done}\) (using \(\id{ASSIGN'}\))
- 2.2: \(s\xto{}{S} \textbf{done}\) (from 2.1 using \(\id{REWRITE'}\))
- 3. \(s=(s_1|s_2)\): Then we have the deduction
- 3.1: \(s \rewritesto{} (s_1;s_2)\) (using \(\id{PAR-1'}\))
- 3.2: \(s\xto{}{S} (s_1;s_2)\) (from 3.1 using \(\id{REWRITE'}\))
- 4. \(s=(s_1;s_2)\): We apply the induction hypothesis on
\(s_1\). This yields two cases:
- a. \(s_1=\textbf{done}\): Then we have the deduction
- 4.a.1: \(s\rewritesto{} s_2\) (using \(\id{DONE'}\))
- 4.a.2: \(s\xto{}{S}s_2\) (from 4.a.1 using \(\id{REWRITE'}\))
- b. \(s_1\xto{}{S}\): Then, we have the deduction
- 4.b.1: \(s_1\xto{}{S}s'_1\) for some \(s'_1\)
- 4.b.2: \(s_1;s_2\xto{}{S}(s'_1;s_2)\) (from 4.b.1 using \(\id{SEQ-COMP'}\))
- a. \(s_1=\textbf{done}\): Then we have the deduction
QED.
8.5 Corollary (Unique Normal Form): Every statement \(s\) simplifies under \(\xto{}{S}\) to \(\textbf{done}\) and to no other statement.
8.5.1 Proof
This is a direct consequence of the Progress Lemma and the termination of \(\xto{}{S}\).
9 References and online resources
- Spacek and Eremondi course slides on Pi calculus
- The π calculus, used to model concurrency and communication is another example of a language that is not confluent.