\documentclass[12pt]{amsart}
\input{defalgo.tex}
\usepackage{program}
\usepackage{epsfig}
\input{defproof}

\begin{document}

\section{Job scheduling}
The jobs are defined as a sequence of triples:
\begin{tabular}{|l|l|l|l|}\hline
$i$ & $p_i$ & $d_i$ & $t_i$ \\ \hline
1 & 5 & 1 & 1 \\
2 & 10 & 2 & 3 \\
3 & 6 & 2 & 1 \\
4 & 3 & 1 & 1 \\ \hline

\end{tabular}
\begin{center}
\epsfig{file=j0.ps,width=16cm}
\end{center}

The $l$ is the lower bound for each node, also called estimated cost:
\[ l(X) = \sum_{q(x)}p_i,\mathrm{\ where\ } q(x)= i\not\in S_x \land i\lt max(S_x)\]

The upper bound for each node is
\[ u(X) = \sum_{q(x)}p_i,\mathrm{\ where\ } q(x)= i\not\in S_x\]
  
\pagebreak
\section{PRAM search}
Given an \[X\in\Int\] and
\[S.0..M-1 \in \Int\text{ where }\forall i,j:\lelt{0}{i}{j}\lt M:S.i\lt S.j\]
one is required to calculate $present$ such that
\[present\leq \exists i:0\le i\lt M: X = S.i  \]

Determining $present$ is then relaxed to finding an $i$
\[R\leq\lelt{0}{i}{M}\land \lelt{S.i}{X}{S.i+1} \]
assuming that $S.M$ is defined to be greater than $X$. 

Dijkstra's program has the form

\begin{program}
\hspace*{0.5cm}\tab
  \bb\tab\Var i\in \Int
     ; S.M:= X+1
     ; establish\ R
     ; present:= (S.i=X)
  \untab\eb
\end{program}

\[P\leq\lelt{0}{i}{j}\le M\land \lelt{S.i}{X}{S.j} \]

\[\invariant P\]

A progress condition:
\[(j-i)\gt(j-i)'\]
A fixed point:
\[(j-i)=1\] 

``establish R'' is

\begin{program}
\hspace*{0.5cm}\tab
  \bb\tab\Var j\in \Int
     ;i,j:= 0,M
     ; \{P\}
     \bloop  
        j-i\neq 1\athen shrink(S,j,i) \{P\}
     \eloop \{R\}
   \untab\eb \{R\}
\end{program}

Shrinking $(j-i)$ can be done by either:
\begin{itemize}

\item increasing $i$ to some $h$,
if $S.h\le X$;
\item  or decreasing $j$ to $h$, if $S.h\lt X$;
\item or both
simultaneously, why not? 
\end{itemize}

\begin{program}
\hspace*{0.5cm}\tab
  sh\tab rink(S,X,i,j)\ \progis
  \bb\tab \Var h\in \Int
     ; h:=(i+j)/2
     ;\tab \ifbb S.h\le X\athen i:=h
       \ifassync X\lt S.h \athen j:=h
      \ifeb
  \untab\eb
\end{program}

Program correctnes?
\begin{itemize}
\item $P$ is true initially;
\item $P$ holds after every transition;
\item $(j-i)>0$ and decreases with every transition;
\item $(j-i)=1$ $X=S.i$ or $X<S.0$ and these conditions exclude each other. 
\end{itemize}

\pagebreak

\section{(p+1)-ary search}
The program becomes

\begin{program}
\hspace*{0.5cm}\tab
  \bb\tab\Var i\in \Int
     ; establish\ R
     ; \tab\parbb{i}{\lelt{i}{k}{min(i+p,M)}}
        q:=(X=S.k)
	\pareb\untab
  \untab\eb
\end{program}

The loop invariant  is the same. The fixed point now is reached when $(j-i)$
is less than or equal to $p$. 
 
``establish R'' is then refined to

\begin{program}
\hspace*{0.5cm}\tab
  \bb\tab\Var j\in \Int
     ;i,j:= 0,M
     ; \{P\}
     \bloop  
        j-i\gt p\athen pshrink(S,j,i,p) \{P\}
     \eloop \{R\}
   \untab\eb \{R\}
\end{program}

This is performed by a parallel test.

\begin{program}
\hspace*{0.5cm}\tab
  psh\tab rink(S,X,i,j)\ \progis
  \bb\tab \Var h\in \Int
     ; nel:=(i+j)/(p+1)
     ; \tab\parbb{k}{\lele{1}{k}{p}}
            \Var h,hb\in \Int
            ; h,hb := i+(nel*k),i+(nel*(k-1))
            ;\tab\ifbb k=p \land X\ge S.h\athen i:=h
	    \ifassync S.hb\le X \land X\lt S.h\athen i,j:=hb,h
            \ifeb\untab
            \pareb\untab
     
  \untab\eb
\end{program}
\pagebreak

\section{Sequence sums}
Given
\[s_i=0,\text{ for } i\le 0\]
\[a_{1..m}, b_{1..m}\]
calculate
\[s_i=(a_i * s_{i-1})+b_i\]

$s_i$ is reduced to:

\[\sum_{1\le i\lt n} ((\prod\ltle{i}{j}{n} a_j) * b_i )\]


\begin{program}
\hspace*{0.5cm}\tab
; scanl(a,1,n,s)
; \tab\parbb{i}{\le\le{1}{i}{n}}
	s.h:=s.h*(b.i/a.i)
 \pareb\untab
; scanl(s,1,n,s);
\end{program}

\end{document}
