% 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{mathpartir}
\usepackage{url}
\usepackage[margin=1in]{geometry}

\usepackage{csnotes}

% local definitions for this lecture
\newcommand{\lam}[2]{\ensuremath{\lambda #1.\,#2}}
\newcommand{\definedas}{\ensuremath{\triangleq}}
\newcommand{\orcdef}{\ensuremath{=_{df}}}
\newcommand{\subst}[3]{\ensuremath{#1[#2/#3]}}
\newtheorem{question}{Question}
\newtheorem{comment}{Comment}
\newtheorem{thm}{Theorem}
\newcommand{\trans}[2]{\stackrel{#1,#2}{\rightarrow}}


\makeatletter
  \newcommand{\addToLabel}[1]{%
    \protected@edef\@currentlabel{\@currentlabel#1}%
  }
\makeatother

\newcounter{rule}
\renewcommand{\therule}{}
\newcommand{\rulename}[1]{{\textsc{#1}}}


\newcommand{\infrule}[4][]{%
  \ensuremath{
  \refstepcounter{rule}%
  \addToLabel{\rulename{#1}}%
   \raisebox{1.7ex}{\rulename{#1}\:}
\begin{array}[b]{@{}l@{}}%
   \begin{array}[b]{c}
   #2\raisebox{0ex}[2.1ex][1.1ex]{\strut}\\
   \hline
   \raisebox{0ex}[2.1ex]{\strut}#3%
   \end{array}%
   \raisebox{1.7ex}{\:#4}
  \end{array}}}
\newcommand{\elidedprooftree}[1][]{\ensuremath{\vdots{}^{#1}}}

\begin{document}

\header{08 November 2011}{Mark Reitblatt}

\section{Orc}

Orc is all about ``orchestration''. It's basically the communciation, distribution skeleton of a program. Web scripting, workflow applications etc. Orc is the glue for building these orchestration tasks. Orc's key abstraction is a site, something you can call and that publishes results. Services are implemented as sites.


Orc is a simple language. It consists of
\begin{itemize}
\item Site calls $M(v)$
\item Symmetric parallel composition $f|g$
\item Sequential composition with respect to a variable $x$: $f >x> g$.  $f$ executes after $g$ publishes a value, with $x$ bound to that value. If $g$ publishes more than one value, $f$ is run multiple times, once for each value published.
\item Asymmetric parallel composition with respect to $x$: $f<x<g$   Subcomputations of $f$ that don't depend upon $x$ execute in parallel with $g$, while computations dependent upon $x$ block until $g$ publishes a value which is in turn bound to $x$. $f$ is run at most once.
\item Definitions $D(x) \orcdef g$
\end{itemize}

\paragraph{Site calls}
Site calls perform a computation and publish at most one result.

\paragraph{Symmetric parallel composition}
To evaluate $f|g$, evaluate $f$ and $g$ in parallel. $f|g|$ publishes $v$ iff $f$ or $g$ publishes $v$.

\paragraph{Sequential composition}
To evaluate $f>x>g$, begin by evaluating $f$. For each $v$ published by $f$, evaluate $[v/x]g$ in parallel. $f>x>g$ publishes $w$ iff some $[v/x]g$ publishes $w$.

\paragraph{Asymmetric parallel composition}
To evaluate $f<x<g$, evaluate $f$ and $g$ in parallel. $f$ may block waiting for data from $g$ ($x$). If $g$ publishes $v$, kill $g$ and continue evaluating $[v/x]f$.

\begin{question} Is $<x<$ necessary? Can it be encoded using $\mid$ and $>x>$? \end{question}

\begin{comment} From Owen: Seems like it was inspired by Bash, I would really like to use a language like this to write in a command line script.\end{comment}

\subsection{Examples}
 \begin{itemize}
   \item $fork-join$ $=$ $(let(x,y) <x< M) <y< N$
    \item $sync = fork-join >x> (f|g)$
    \item $delay = (Rtimer(1) >> let(x))<x< M$ % Explain $<<$ syntax
    \item $priority = let(x) <x< (N|delay)$
 \end{itemize}

\section{Timed Trace semantics}

Originally, Orc was given an asynchronous, then a ``synchronous-but-untimed'' semantics. Here we will use a ``relative-time'' semantics which describe delays from site calls.

\[(Rtimer(s)>> let(v))|(Rtimer(3)>>let(w))\]

The operational semantics are based on a labelled transition system $f\trans{t,a}f'$ with time-event pairs $t,a$ for labels.


\[  f\trans{t,a} f'\]



Expression $f$ {\textbf may} engage in event $a$ after $t$ units of time, without engaging in other events, resulting in expression $f'$

\subsection{Rules}

\paragraph{Sites}
\[ let(v)\trans{0}{!v} 0\]

Immediately publish value $v$ and transition to an expression 0 that engages in no other events.

\[Rtimer(t) \trans{t}{!} 0\]

Publish a signal after $t$ time units.

\paragraph{Combinators}

\[\infrule{f\rightarrow^{t,a} f'}{f | g \rightarrow^{t,a} f' | g}{}\]

Works in asynchronous system, but NOT with time. Consider $Rtimer(8) |Rtimer(3)$.

To fix this, we introduce ``Time Shifting'', $f^t$. Evaluate for $t$ time units without an event. For example, $Rtimer(5)^3 \equiv Rtimer(2)$. But, it may not alwats be possible: $Rtimer(5)^7 \equiv \bot$.

- $Rtimer(2)^5 \equiv \bot$

\[\infrule{f\rightarrow^{t,a} f'}
{f | g \rightarrow^{t,a} f' | g^t}{}\]


Only if $g^t$ is not $\bot$. 

Rest of the semantics similarly extend the asynchronous semantics.

\begin{mathpar}
\infrule{[E(x) \definedas f] \in \mathcal{D}}{E(p) \trans{0}{\tau} [p/x].f}{Def}

\infrule{k\in \Sigma(M,m)}{M(m)\trans{0}{\tau} ?k}{Call}

\infrule{(t,m)\in k}{?k\trans{t}{!m} 0}{Return}

\infrule{f\trans{t}{a} f'}{f|g\trans{t}{a} f'|g^t}{Sym1}

\infrule{f \trans{t}{a} g'}{f | g\trans{t}{a} f^t|g'}{Sym2}

\infrule{f\trans{t}{a}f' \qquad a\neq !m}{f >x> g\trans{t}{a} f' >x>g}{Seq1N}

\infrule{f \trans{t}{!m} f'}{f >x>g \trans{t}{\tau} (f' >x> g) | [m/x].g}{Seq1V}

\infrule{f\trans{t}{a} f'}{ f<x<g \trans{t}{a} f'<x< g^t}{Asym1}

\infrule{f \trans{t}{!m} g'}{f <x< g \trans{t}{\tau} [m/x].f^t}{Asym2V}

\infrule{g\trans{t}{a} g'\qquad a\neq !m}{f <x< g \trans{t}{a} f^t <x< g'}{Asym2N}
\end{mathpar}



\subsection{Denotational Semantics}

An {\textbf execution} is a finite sequence of time-event pairs that $f$ engages in. A {\textbf trace} is an execution without internal events. $<f> =$ traces of $f$ defined operationally.

Trace sets form a {\textbf denotation}, $\mu(f)$. 

\begin{thm}
Operational and denotation semantics are equivalent: $<f>=\mu(f)$.
\end{thm}

This allows for compositional reasoning.



\end{document}

