<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% flag to use fancy fonts / graphics
\newif\ifjnf\jnftrue

\documentclass[11pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{cmtt}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{stmaryrd}
\usepackage{url}
\usepackage[margin=1in]{geometry}

\usepackage{csnotes}
\newcommand{\lam}[2]{\ensuremath{\lambda #1.\,#2}}
\newcommand{\subst}[3]{\ensuremath{#1[#2/#3]}}

\begin{document}

\header{27 September 2011}{Shrutarshi Basu}

\section{The $\pi$-calculus}
\begin{eqnarray*}
\pi &amp; ::= &amp; \tau \mid \bar{x}\langle y \rangle \mid x(y) \mid [x = y] \pi \\
M, N &amp; ::= &amp; 0 \mid \pi .P \mid M + N \\
P &amp; ::= &amp; M \mid P_1|P_2 \mid \nu x P \mid !P\\
\end{eqnarray*}
Polyadic encoding and recursion were also covered in the previous lecture.

\section{Encoding Booleans}

\begin{eqnarray*}
  True (l) &amp; \triangleq &amp; l (t,f). \bar{t} \\
  False (l) &amp; \triangleq &amp; l(t,f). \bar{f}\\
  Cond(P,Q)(l) &amp; \triangleq &amp; \nu t,f (\bar{l}\langle t,f \rangle.(t.P + f.Q))\\
\end{eqnarray*}

\section{Encoding Lists}
\begin{eqnarray*}
  Nil (k) &amp; \triangleq &amp; k(n,c).\bar{k}\\
  Cons(V,L)(k) &amp; \triangleq &amp; \nu v,l (k(n,c).\bar{c}\langle v, l \rangle \mid
                              V\langle v \rangle \mid L\langle l \rangle) \\
  IsNil(L)(r) &amp; \triangleq &amp; \nu l,n,c(L\langle l \rangle \mid \bar{l}\langle n,v
  \rangle . (n.True\langle r \rangle + c(n,t).False\langle r \rangle))
\end{eqnarray*}

Introduce a $case$ form:
\begin{eqnarray*}
  \text{case $l$ of} \\
  Nil? &amp; \Rightarrow P \\
  Cons? &amp; \Rightarrow Q
\end{eqnarray*}

\subsection{Destructive List Copy}
\begin{eqnarray*}
  Copy\langle l,m \rangle &amp; \triangleq &amp; \text{case $l$ of}\\
  &amp; &amp; Nil? \Rightarrow Nil \langle m \rangle \\
  &amp; &amp; Cons?(h,t) \Rightarrow \nu m'(m(n,c).\bar{c}\langle n,m' \rangle
  \mid Copy\langle r,m' \rangle)
\end{eqnarray*}

\subsection{Destructive List Join}
\begin{eqnarray*}
  Join\langle k,l,m \rangle &amp; \triangleq &amp; \text{case $k$ of}\\
  &amp; &amp; Nil? \Rightarrow Copy \langle l,m \rangle \\
  &amp; &amp; Cons?(h,t) \Rightarrow \nu m'(m(n,c).\bar{c}\langle n,m' \rangle
  \mid Join\langle t,l,m' \rangle)
\end{eqnarray*}

A $Double$ operation cannot be defined as follows because $Join$ is destructive

\begin{eqnarray*}
  Double (l,m) &amp; \triangleq &amp; Join(l,lm)
\end{eqnarray*}

\section{Encoding Persistent Datatypes}
We put a ! in front of processes to turn them into servers create arbitrary
numbers of the original process. This prevents their destruction after sending
or receiving a message. This is generally used on ``connectors'' -- the
processes that acts as ``cons cell'' equivalents. The List encoding can be
rewritten as:

\begin{eqnarray*}
  Nil (k) &amp; \triangleq &amp; !k(n,c).\bar{k}\\
  Cons(V,L)(k) &amp; \triangleq &amp; \nu v,l (!k(n,c).\bar{c}\langle v, l \rangle \mid
                              V\langle v \rangle \mid L\langle l \rangle) \\
  IsNil(L)(r) &amp; \triangleq &amp; \nu l,n,c(L\langle l \rangle \mid \bar{l}\langle n,v
  \rangle . (n.True\langle r \rangle + c(n,t).False\langle r \rangle))
\end{eqnarray*}

\section{Reference Cells for Mutable Data}

\begin{eqnarray*}
  NullRef(r) &amp; \triangleq &amp; r(g,s,t,i).(s(v).Ref\langle v,r \rangle +
  t.NullRef\langle r \rangle + i(b).True\langle b \rangle)\\
  Ref(v,r) &amp; \triangleq &amp; r(g,s,t,i).(\bar{g}(v) + s(v').Ref\langle v',r \rangle
  + t.NullRef\langle r \rangle + i(b).False\langle b \rangle)
\end{eqnarray*}

\section{Encoding the $\lambda$-calculus}
We can express the syntax of the pure untyped $\lambda$-calculus as:
\[
e\ \ ::=\ \ x \mid e_1\,e_2 \mid \lam xe
\]

The semantics can be expressed as:

\begin{alignat*}{2}
  \frac{e_1 \rightarrow e_1'}{e_1e_2 \rightarrow e_1'e_2} &amp;\quad
  \frac{}{(\lam x{e_1})e_2 \rightarrow \subst{e_1}{e_2}{x}}
\end{alignat*}

The above semantics can be encoded in the $\pi$-calculus as:


\begin{eqnarray*}
  \llbracket x \rrbracket (u) &amp; \triangleq &amp; \bar{x}\langle u \rangle \\
  \llbracket \lam xe \rrbracket (u) &amp; \triangleq &amp; u(x,y).\llbracket e
  \rrbracket \langle v \rangle\\
  \llbracket e_1,e_2 \rrbracket (u) &amp; \triangleq &amp; \nu y (\llbracket e_1
  \rrbracket \langle y \rangle \mid \nu x ( \bar{y} \langle x,u \rangle \mid
  !x(w).\llbracket e_2 \rrbracket \langle w \rangle))
\end{eqnarray*}


\end{document}
</pre></body></html>