% $Id: chaotic-iteration-example.tex,v 1.10 2024/02/18 04:07:17 leavens Exp leavens $
\documentclass{article}
\input{macros}
\input{use-full-page}
\newcommand{\DO}{\ANALYSIS{DO}}
\newcommand{\INT}{\mbox{\textrm{Int}}}
\newcommand{\STEPSYM}{\textrm{:=}}
\newcommand{\STEPREASON}[1]{\REASON{\STEPSYM}{#1}}
\begin{document}
\title{Chaotic Iteration for the Depends On Analysis}
\author{Gary T. Leavens}
\maketitle
\begin{abstract}
An example of computing the ``Depends On'' analysis discussed in class.
\end{abstract}

\section{The Depends On Analysis}

\subsection{Definitions}

We say that a variable
$y$ \emph{may have influenced the value of a variable} $x$ 
if changing the value of $y$ might change the value of $x$ in some execution.
In this case we say that \emph{$x$ may depend on $y$}.

(This dependency information could, for example, be used to help an
optimizing compiler decide if two statements could be reordered
or run in parallel.)

As discussed in class, the ``Depends On'' (DO) analysis concerns the
question of what variables a variable may depend on at each program point.

\subsubsection{Example Program}
\label{sec:exampleprog}

In class we discussed the following example program to illustrate the analysis.

\begin{program*}
\ASSIGN{i}{n};
\ASSIGN{j}{i};
if \EXP{i > 0} then \ASSIGN{m}{j+1} else \ASSIGN{m}{j-1};
\ASSIGN{j}{m-i};
\ASSIGN{k}{j}
\end{program*}

In this example, at the exit to block 1, \texttt{i} depends on
\texttt{n}. 
At the exit from block 2, \texttt{j} depends on both \texttt{i} and \texttt{n},
and \texttt{i} still depends on \texttt{n}.
At exit from block 3, the same dependencies hold as on exit from block 2.
At exit from block 4, in addition to the dependencies that hold on
exit from block 3, \texttt{m} depends on \texttt{j}, \texttt{i}, and
\texttt{n}, and the same holds on exit from block 5.
At exit from block 6, all the dependencies that hold on exits from
blocks 4 and 5 hold, except that \texttt{j} depends on
\texttt{m}, \texttt{i}, \texttt{j}, and \texttt{n}.
At exit from block 7, all the dependencies that hold on exits from
block 6, and in addition, \texttt{k} depends on \texttt{j},
\texttt{m}, \texttt{i}, and \texttt{n}.

\subsection{Mathematical Treatment}

The analysis is a forward ``may'' analysis.

\subsubsection{Property Space}

We use as a property space
(finite) binary relations between variable names
(although one could also use an isomorphic property space,
such as finite mappings from variable names to sets of
variable names).  That is, we use as the property space:

\begin{displaymath}
(L, \bigsqcup) = (\POWERSET{\ProgVar \times \ProgVar}, \bigcup).
\end{displaymath}

Since $L$ is a finite set, the ordering induced by $\bigcup$ is a
complete partial order.
That is, this property space has the ascending chain property.

\subsubsection{Dataflow Equations}

We can define the DO analysis as a set of dataflow equations
in the usual way by first defining the $\KILL{DO}$ and $\GEN{DO}$
functions.
The $\GEN{DO}$ function is explicitly passed the binary relation
on variables that holds on entry to the elementary block;
this makes the result of $\GEN{DO}$ explictly depend on
the entry information passed (in argument $R$),
avoiding an implicit (and obscure) dependence on
the entry information for the block.
Also note that the transitive closure of the relation passed to
$\GEN{DO}$, notated $R^{+}$ is used in the definition of the
$\GEN{DO}$ function for assignments.\footnote{Using
the transitive closure is a difference from what we did in class, but
seems necessary to obtain the right results.}
\begin{tabbing}
$\KILL{DO}: \ProgBlock \rightarrow L$ \\
$\KILL{DO}(\LASSIGN{x}{a}{\ell}) = \{(x,z) \mid z \in \ProgVar \}$ \\
$\KILL{DO}(\LSKIP{\ell}) = \emptyset$ \\
$\KILL{DO}(\LEXP{b}{\ell}) = \emptyset$ \\
~ \\
$\GEN{DO}: L \rightarrow \ProgBlock \rightarrow L$ \\
$\GEN{DO}(R)(\LASSIGN{x}{a}{\ell}) = \{(x, y) \mid y \in FV(a)\} \cup \{(x,z) \mid y \in FV(a), (y,z) \in R^{+}\}$ \\
$\GEN{DO}(R)(\LSKIP{\ell}) = \emptyset$ \\
$\GEN{DO}(R)(\LEXP{b}{\ell}) = \emptyset$
\end{tabbing}

Using the above definitions, we can define the analysis schematically
as follows. (Note that $s_1 \setminus s_2$ means the subtraction of
$s_2$ from $s_1$, that is: $s_1 \setminus s_2 = \{w \mid w \in s_1, w \not\in s_2\}$.)
\begin{tabbing}
$\ENTRY{\ANALYSIS{DO}}(\ell) = 
\left\{
\begin{array}{ll}
\emptyset, & \mbox{if $\ell = \INIT(\Prog)$} \\
\bigcup \{\EXIT{\ANALYSIS{DO}}(\ell') \mid (\ell',\ell) \in \FLOW(\Prog)\}, & \mbox{otherwise}
\end{array}
\right.$ \\
$\EXIT{\ANALYSIS{DO}}(\ell) = (\ENTRY{\ANALYSIS{DO}}(\ell) 
                               \setminus \KILL{DO}(B^{\ell}))
                              \cup
                              \GEN{DO}(\ENTRY{\ANALYSIS{DO}}(\ell))(B^{\ell})$ \\
~~~~~~~~~ where $B^{\ell} \in \BLOCKS(\Prog)$
\end{tabbing}

\subsubsection{Functional Representing the Dataflow Equations for the
  Example Program}

In the example program shown in Sec.~\ref{sec:exampleprog}, there are
7 elementary blocks, and since there are entry and exit points for each of
these blocks, the functional encoding the dataflow
equations will have 14 components. So we define for
the example program $F(\vec{DO}) = (F_1(\vec{DO}),\ldots,F_{14}(\vec{DO}))$
where $\vec{DO}$ is a 14-tuple of elements of $L$. The components of
$F$ are defined in \figref{fig:functional}.

\begin{figure}[pbt]
\newcommand{\EESEP}{\\[1.35ex]}
\newcommand{\NFSEP}{\\[1.9ex]}

\begin{tabular}{lcl}
\textit{entry 1:} & & \\
$F_1(DO_1,\ldots,DO_{14})$ & = & $\emptyset$ \EESEP
\textit{exit 1:} & & \\
$F_2(DO_1,\ldots,DO_{14})$
  & = & $(DO_1 \setminus \KILL{DO}(\LASSIGN{\texttt{i}}{\texttt{n}}{1})
                              \cup
                              \GEN{DO}(DO_1)(\LASSIGN{\texttt{i}}{\texttt{n}}{1})$
                              \\
  & = & $(DO_1 \setminus (\{\texttt{i}\} \times \ProgVar)) \cup \{(\texttt{i},\texttt{n})\}$ \NFSEP
\textit{entry 2:} & & \\
$F_3(DO_1,\ldots,DO_{14})$ & = & $DO_2$ \EESEP
\textit{exit 2:} & & \\
$F_4(DO_1,\ldots,DO_{14})$
  & = & $(DO_3 \setminus \KILL{DO}(\LASSIGN{\texttt{j}}{\texttt{i}}{2})
                              \cup
                              \GEN{DO}(DO_3)(\LASSIGN{\texttt{j}}{\texttt{i}}{2})$
                              \\
  & = & $(DO_3 \setminus (\{\texttt{j}\} \times \ProgVar)) \cup
                              \{(\texttt{j},\texttt{i})\}
                               \cup \{(\texttt{j},z) \mid (\texttt{i},z) \in DO_3^{+}\}$ \NFSEP
\textit{entry 3:} & & \\
$F_5(DO_1,\ldots,DO_{14})$ & = & $DO_4$ \EESEP
\textit{exit 3:} & & \\
$F_6(DO_1,\ldots,DO_{14})$ & = & $(DO_5 \setminus \KILL{DO}(\LEXP{\texttt{i > 0}}{3})
                              \cup
                              \GEN{DO}(DO_5)(\LEXP{\texttt{i > 0}}{3})$
                              \\
                         & = & $DO_5$ \NFSEP
\textit{entry 4:} & & \\
$F_7(DO_1,\ldots,DO_{14})$ & = & $DO_6$ \EESEP
\textit{exit 4:} & & \\
$F_8(DO_1,\ldots,DO_{14})$
  & = & $(DO_7 \setminus \KILL{DO}(\LASSIGN{\texttt{m}}{\texttt{j+1}}{4})
                              \cup
                              \GEN{DO}(DO_7)(\LASSIGN{\texttt{m}}{\texttt{j+1}}{4})$
                              \\
  & = & $(DO_7 \setminus (\{\texttt{m}\} \times \ProgVar)) \cup
                              \{(\texttt{m},\texttt{j})\}
                               \cup \{(\texttt{m},z) \mid (\texttt{j},z) \in DO_7^{+}\}$ \NFSEP
\textit{entry 5:} & & \\
$F_9(DO_1,\ldots,DO_{14})$ & = & $DO_6$ \EESEP
\textit{exit 5:} & & \\
$F_{10}(DO_1,\ldots,DO_{14})$
  & = & $(DO_9 \setminus \KILL{DO}(\LASSIGN{\texttt{m}}{\texttt{j-1}}{5})
                              \cup
                              \GEN{DO}(DO_9)(\LASSIGN{\texttt{m}}{\texttt{j-1}}{5})$
                              \\
  & = & $(DO_9 \setminus (\{\texttt{m}\} \times \ProgVar)) \cup
                              \{(\texttt{m},\texttt{j})\}
                               \cup \{(\texttt{m},z) \mid (\texttt{j},z) \in DO_9^{+}\}$ \NFSEP
\textit{entry 6:} & & \\
$F_{11}(DO_1,\ldots,DO_{14})$ & = & $DO_8 \cup DO_{10}$ \EESEP
\textit{exit 6:} & & \\
$F_{12}(DO_1,\ldots,DO_{14})$
  & = & $(DO_{11} \setminus \KILL{DO}(\LASSIGN{\texttt{m}}{\texttt{j-i}}{6})
                              \cup
                              \GEN{DO}(DO_{11})(\LASSIGN{\texttt{m}}{\texttt{j-i}}{6})$
                              \\
  & = & $(DO_{11} \setminus (\{\texttt{m}\} \times \ProgVar))
                              \cup
                              \{(\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}$ \\
  &  & ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                              $\cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
                                                          (y,z) \in DO_{11}^{+}\}$ \NFSEP
\textit{entry 7:} & & \\
$F_{13}(DO_1,\ldots,DO_{14})$ & = & $DO_{12}$ \EESEP
\textit{exit 7:} & & \\
$F_{14}(DO_1,\ldots,DO_{14})$
  & = & $(DO_{13} \setminus \KILL{DO}(\LASSIGN{\texttt{k}}{\texttt{j}}{7})
                              \cup
                              \GEN{DO}(DO_{13})(\LASSIGN{\texttt{k}}{\texttt{j}}{7})$
                              \\
  & = & $(DO_{13} \setminus (\{\texttt{k}\} \times \ProgVar)) \cup
                              \{(\texttt{m},\texttt{j})\}
                               \cup \{(\texttt{k},z) \mid (\texttt{j},z) \in DO_{13}^{+}\}$
\end{tabular}
\caption{Formulation of the dataflow equations for the example
  program.}
\label{fig:functional}
\end{figure}

\subsection{Solution for the Example Program}

In this section we use Chaotic Iteration to find the least solution
(in the pointwise subset ordering on 14-tuples, $\sqsubseteq$).
We want the least solution, because that is the most precise
solution available (as is true for all ``may'' analyses).

So to use Chaotic iteration, let each $DO_i$ be $\emptyset$
(for $i \in \{1,\ldots,14\}$).  Possible steps of the Chaotic
Iteration for this example follow, starting from the beginning of the
example program (since this is a forward analysis), but noting that no
changes can be made to $DO_1$, due to the definition of $F_1$.

To take a step with the exit of block 1, we use the following lemma.

\begin{lemma}\label{lem:exit1}
  Let the $F_2$ be as in \figref{fig:functional} and let each $DO_i = \emptyset$.
  Then $F_2(DO_1,\ldots,DO_{14}) = \{(\texttt{i},\texttt{n})\}$.
\end{lemma}

\PROOF
Assume that the $F_2$ is as in \figref{fig:functional} and that the
$DO_i$ are all empty.
We calculate as follows.
\begin{calculation}
  \FORMULA{F_2(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_2$}
  \FORMULA{(DO_1 \setminus (\{\texttt{i}\} \times \ProgVar)) \cup \{(\texttt{i},\texttt{n})\}}
\EQREASON{assumption $DO_1 = \emptyset$}
  \FORMULA{(\emptyset \setminus (\{\texttt{i}\} \times \ProgVar)) \cup \{(\texttt{i},\texttt{n})\}}
\EQREASON{set theory}
  \QEDFORMULA{\{(\texttt{i},\texttt{n})\}}
\end{calculation}

\clearpage
Thus we can take the following step.

\begin{calculation}
  \FORMULA{DO_2}
\STEPREASON{Lemma~\ref{lem:exit1},
    $F_2(DO_1,\ldots,DO_{14}) \neq \emptyset = DO_2$, so can take this step}
  \LASTFORMULA{\{(\texttt{i},\texttt{n})\}}
\end{calculation}

The previous step allows a step at the entry of block 2.

\begin{lemma}\label{lem:entry2}
  Let $F_3$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_3(DO_1,\ldots,DO_{14}) = \{(\texttt{i},\texttt{n})\}$.
\end{lemma}

\PROOF
\begin{calculation}
  \FORMULA{F_3(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_3$}
  \FORMULA{DO_2}
\EQREASON{assumption the value of $DO_2$ is $\{(\texttt{i},\texttt{n})\}$.}
  \QEDFORMULA{\{(\texttt{i},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_3}
\STEPREASON{Lemma~\ref{lem:entry2},
    $F_3(DO_1,\ldots,DO_{14}) = \{(\texttt{i},\texttt{n})\}$, so can take this step}
  \LASTFORMULA{\{(\texttt{i},\texttt{n})\}}
\end{calculation}

The next step is justified by the following lemma.

\begin{lemma}\label{lem:exit2}
  Let $F_4$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_4(DO_1,\ldots,DO_{14})  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.
\end{lemma}

\PROOF
Assume that the $F_4$ is as in \figref{fig:functional} and that the
$DO_i$ are as above.
We calculate as follows.
\begin{calculation}
  \FORMULA{F_4(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_4$}
  \FORMULA{(DO_3 \setminus (\{\texttt{j}\} \times \ProgVar)) 
    \cup \{(\texttt{j},\texttt{i})\}
    \cup \{(\texttt{j},z) \mid (\texttt{i},z) \in DO_3\}}
\EQREASON{assumption $DO_3 = \{(\texttt{i},\texttt{n})\}$}
  \FORMULA{(\{(\texttt{i},\texttt{n})\} \setminus (\{\texttt{j}\} \times \ProgVar)) \cup \{(\texttt{j},\texttt{i})\}
    \cup \{(\texttt{j},z) \mid (\texttt{i},z) \in \{(\texttt{i},\texttt{n})\}\}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{j},\texttt{i})\} \cup \{(\texttt{i},\texttt{n})\}}
\EQREASON{set theory}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_4}
\STEPREASON{Lemma~\ref{lem:exit2},
  $F_4(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
    \neq \emptyset = DO_4$, so can take this step}
  \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

The previous step allows a step at the entry of block 3.

\begin{lemma}\label{lem:entry3}
  Let $F_5$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_5(DO_1,\ldots,DO_{14})
   = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.
\end{lemma}

\PROOF
\begin{calculation}
  \FORMULA{F_5(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_5$}
  \FORMULA{DO_4}
\EQREASON{assumption the value of $DO_4$
    is $\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_5}
\STEPREASON{Lemma~\ref{lem:exit2},
  $F_5(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
    \neq \emptyset = DO_5$, so can take this step}
  \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

The previous step allows a step at the exit of block 3.

\begin{lemma}\label{lem:exit3}
  Let the $F_i$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_6(DO_1,\ldots,DO_{14})
   = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.
\end{lemma}

\PROOF
\begin{calculation}
  \FORMULA{F_6(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_6$}
  \FORMULA{DO_5}
\EQREASON{assumption the value of $DO_5$
    is $\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_6}
\STEPREASON{Lemma~\ref{lem:exit3},
  $F_6(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
    \neq \emptyset = DO_6$, so can take this step}
  \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

The previous step allows a step at the entry of block 4.

\begin{lemma}\label{lem:entry4}
  Let the $F_i$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_7(DO_1,\ldots,DO_{14})
        = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.
\end{lemma}

\PROOF
\begin{calculation}
  \FORMULA{F_7(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_7$}
  \FORMULA{DO_6}
\EQREASON{assumption the value of $DO_6$ is $\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_7}
\STEPREASON{Lemma~\ref{lem:exit4},
  $F_7(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
    \neq \emptyset = DO_7$, so can take this step}
  \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

The next step, for the exit of block 4, is justified by the following lemma.

\begin{lemma}\label{lem:exit4}
  Let the $F_i$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_8(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}$.
\end{lemma}

\PROOF
Assume that the $F_i$ are as in \figref{fig:functional} and that the
$DO_i$ are as above.
We calculate as follows.
\begin{calculation}
  \FORMULA{F_8(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_8$}
  \FORMULA{(DO_7 \setminus (\{\texttt{m}\} \times \ProgVar))
              \cup \{(\texttt{m},\texttt{j})\}
              \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
                                         (y,z) \in DO_7^{+}}
\EQREASON{assumption $DO_7 = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$}
  \FORMULA{(\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
             \setminus (\{\texttt{m}\} \times \ProgVar))
            \cup \{(\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
            \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
            (y,z) \in
              (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\})^{+}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
            \cup \{(\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
            \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
            (y,z) \in
              (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\})^{+}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
            \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
            (y,z) \in
              (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\})^{+}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
             \cup \{(\texttt{m},\texttt{i}),(\texttt{m},\texttt{n})\}}
\EQREASON{set theory}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
             (\texttt{m},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_8}
\STEPREASON{Lemma~\ref{lem:exit4},
  $F_8(DO_1,\ldots,DO_{14})
    = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
             (\texttt{m},\texttt{n})\}
      \neq \emptyset = DO_8$, so can take this step}
  \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
             (\texttt{m},\texttt{n})\}}
\end{calculation}

Similarly, a step for the entry of block 5 can be taken, which is
justified by the following lemma.

\begin{lemma}\label{lem:entry5}
  Let the $F_i$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_9(DO_1,\ldots,DO_{14})
        = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.
\end{lemma}

\PROOF
\begin{calculation}
  \FORMULA{F_9(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_9$}
  \FORMULA{DO_6}
\EQREASON{assumption the value of $DO_6$ is
    $\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$.}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_9}
\STEPREASON{Lemma~\ref{lem:entry5},
  $F_9(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$,
  so can take this step}
 \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}}
\end{calculation}

The previous step allows a step at the exit of block 5.

\begin{lemma}\label{lem:exit5}
  Let the $F_i$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_{10}(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}$.
\end{lemma}

\PROOF
Assume that the $F_i$ are as in \figref{fig:functional} and that the
$DO_i$ are as above.
We calculate as follows.
\begin{calculation}
  \FORMULA{F_{10}(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_{10}$}
  \FORMULA{(DO_9 \setminus (\{\texttt{m}\} \times \ProgVar))
             \cup \{(\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
             \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
                                         (y,z) \in DO_9^{+}}
\EQREASON{assumption $DO_9 = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}$}
  \FORMULA{(\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
             \setminus (\{\texttt{m}\} \times \ProgVar))
            \cup \{(\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
            \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
            (y,z) \in
              (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\})^{+}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\}
            \cup \{(\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
            \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
            (y,z) \in
              (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\})^{+}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
            \cup \{(\texttt{m},z) \mid y \in \{\texttt{j},\texttt{i}\},
            (y,z) \in
              (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n})\})^{+}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i})\}
             \cup \{(\texttt{m},\texttt{i}),(\texttt{m},\texttt{n})\}}
\EQREASON{set theory}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
             (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
             (\texttt{m},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_{10}}
\STEPREASON{Lemma~\ref{lem:exit5},
  $F_{10}(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}$,
  so can take this step}
 \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}}
\end{calculation}

The above steps allow the iteration to take a step at the entry to
block 6.

\begin{lemma}\label{lem:entry6}
  Let the $F_i$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_{11}(DO_1,\ldots,DO_{14})
        = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}$.
\end{lemma}

\PROOF
\begin{calculation}
  \FORMULA{F_{11}(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_{11}$}
  \FORMULA{DO_8 \cup DO_{10}}
\EQREASON{assumption the values of $DO_{8}$ and $DO_{10}$}
\FORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
           (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
           (\texttt{m},\texttt{n})\}
         \cup \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
                  (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
                 (\texttt{m},\texttt{n})\}}
\EQREASON{set theory}
  \QEDFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_{11}}
\STEPREASON{Lemma~\ref{lem:entry6},
  $F_{11}(DO_1,\ldots,DO_{14})
  = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}$,
  so can take this step}
 \LASTFORMULA{\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}}
\end{calculation}

The previous step allows a step at the exit of block 6.

\begin{lemma}\label{lem:exit6}
  Let the $F_i$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_{12}(DO_1,\ldots,DO_{14})
  = \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
             (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
             (\texttt{j},\texttt{n})\}$.
\end{lemma}

\PROOF
Assume that the $F_i$ are as in \figref{fig:functional} and that the
$DO_i$ are as above.
We calculate as follows.
\begin{calculation}
  \FORMULA{F_{12}(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_{12}$}
  \FORMULA{(DO_{11} \setminus (\{\texttt{j}\} \times \ProgVar))
             \cup \{(\texttt{j},\texttt{m}),(\texttt{j},\texttt{i})\}
             \cup \{(\texttt{j},z) \mid y \in \{\texttt{m},\texttt{i}\},
                                         (y,z) \in DO_{11}^{+}}
\EQREASON{assumption $DO_{11} = \{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
      (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
      (\texttt{m},\texttt{n})\}$}
  \FORMULA{\begin{array}{l}
          (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
              (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
              (\texttt{m},\texttt{n})\}
          \setminus (\{\texttt{j}\} \times \ProgVar)) \\
           {} \cup \{(\texttt{j},\texttt{m}),(\texttt{j},\texttt{i})\}
            \cup \{(\texttt{j},z) \mid y \in \{\texttt{m},\texttt{i}\},
                     (y,z) \in (\{(\texttt{j},\texttt{i}),
                        (\texttt{i},\texttt{n}),
                        (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
                        (\texttt{m},\texttt{n})\})^{+}
          \end{array}}
\EQREASON{set theory}
  \FORMULA{\begin{array}{l}
      \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{m},\texttt{n})\} \\
       {} \cup \{(\texttt{j},\texttt{m}),(\texttt{j},\texttt{i})\}
          \cup \{(\texttt{j},z) \mid y \in \{\texttt{m},\texttt{i}\},
                  (y,z) \in (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
                               (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
                               (\texttt{m},\texttt{n})\})^{+}

          \end{array}}
\EQREASON{set theory}
  \FORMULA{\begin{array}{l}
      \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
             (\texttt{j},\texttt{i})\} \\
      {} \cup \{(\texttt{j},z) \mid y \in \{\texttt{m},\texttt{i}\},
                   (y,z) \in (\{(\texttt{j},\texttt{i}),(\texttt{i},\texttt{n}),
                                (\texttt{m},\texttt{j}),(\texttt{m},\texttt{i}),
                                (\texttt{m},\texttt{n})\})^{+}
         \end{array}}
\EQREASON{set theory}
  \FORMULA{\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
             (\texttt{j},\texttt{i})\}
            \cup \{(\texttt{j},\texttt{j}),(\texttt{j},\texttt{i}),
                   (\texttt{j},\texttt{n})\}}
\EQREASON{set theory}
  \QEDFORMULA{\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
             (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
             (\texttt{j},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_{12}}
\STEPREASON{Lemma~\ref{lem:exit5},
  $F_{12}(DO_1,\ldots,DO_{14})
  = \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
             (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
             (\texttt{j},\texttt{n})\}$,
  so can take this step}
 \LASTFORMULA{\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
             (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
             (\texttt{j},\texttt{n})\}}
\end{calculation}

The previous step allows a step at the entry of block 7.

\begin{lemma}\label{lem:entry7}
  Let $F_{13}$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_{13}(DO_1,\ldots,DO_{14})
  = \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
      (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
      (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
      (\texttt{j},\texttt{n})\}$.
\end{lemma}

\PROOF
\begin{calculation}
  \FORMULA{F_{13}(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_{13}$}
  \FORMULA{DO_{12}}
\EQREASON{assumption the value of $DO_{12}$ is $\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
             (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
             (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
             (\texttt{j},\texttt{n})\}$.}
  \QEDFORMULA{\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_{13}}
\STEPREASON{Lemma~\ref{lem:entry7},
    $F_{13}(DO_1,\ldots,DO_{14}) = \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\}$, so can take this step}
  \LASTFORMULA{\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\}}
\end{calculation}

The next step is justified by the following lemma.

\begin{lemma}\label{lem:exit7}
  Let $F_{14}$ be as in \figref{fig:functional} and let the $DO_i$ be as above.
  Then $F_{14}(DO_1,\ldots,DO_{14})
            = \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n}),(\texttt{k},\texttt{j}),
                (\texttt{k},\texttt{m}),(\texttt{k},\texttt{i}),
                (\texttt{k},\texttt{n})\}$.
\end{lemma}

\PROOF
Assume that the $F_{14}$ is as in \figref{fig:functional} and that the
$DO_i$ are as above.
We calculate as follows.
\begin{calculation}
  \FORMULA{F_{14}(DO_1,\ldots,DO_{14})}
\EQREASON{definition of $F_{14}$}
  \FORMULA{(DO_{13} \setminus (\{\texttt{k}\} \times \ProgVar)) 
    \cup \{(\texttt{k},\texttt{j})\}
    \cup \{(\texttt{k},z) \mid (\texttt{j},z) \in DO_{13}^{+}\}}
\EQREASON{assumption $DO_{13} = \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\}$}
     \FORMULA{\begin{array}{l}
    (\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\} \setminus
         \setminus (\{\texttt{k}\} \times \ProgVar)) \\
    {} \cup \{(\texttt{k},\texttt{j})\}
       \cup \{(\texttt{k},z) \mid (\texttt{j},z)
         \in (\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\})^{+}
             \end{array}}
\EQREASON{set theory}
   \FORMULA{\begin{array}{l}
    \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\}
      \cup \{(\texttt{k},\texttt{j})\} \\
     {} \cup \{(\texttt{k},z) \mid (\texttt{j},z)
         \in (\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\})^{+}
             \end{array}}
\EQREASON{set theory}
   \FORMULA{\begin{array}{l}
    \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n}),(\texttt{k},\texttt{j})\} \\
     {} \cup \{(\texttt{k},z) \mid (\texttt{j},z)
         \in (\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n})\})^{+}
             \end{array}}
\EQREASON{set theory}
   \FORMULA{\begin{array}{l}
    \{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n}),(\texttt{k},\texttt{j})\} \\
      {} \cup \{(\texttt{k},\texttt{m}),(\texttt{k},\texttt{i}),
                (\texttt{k},\texttt{j}),(\texttt{k},\texttt{n})\}
             \end{array}}
\EQREASON{set theory}
  \QEDFORMULA{\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n}),(\texttt{k},\texttt{j}),
                (\texttt{k},\texttt{m}),(\texttt{k},\texttt{i}),
                (\texttt{k},\texttt{n})\}}
\end{calculation}

\begin{calculation}
  \FORMULA{DO_{14}}
\STEPREASON{Lemma~\ref{lem:exit7},
  $F_{14}(DO_1,\ldots,DO_{14}) \neq \emptyset = DO_{14}$, so can take this step}
  \LASTFORMULA{\{(\texttt{i},\texttt{n}),(\texttt{m},\texttt{j}),
                (\texttt{m},\texttt{i}),(\texttt{j},\texttt{m}),
                (\texttt{j},\texttt{i}),(\texttt{j},\texttt{j}),
                (\texttt{j},\texttt{n}),(\texttt{k},\texttt{j}),
                (\texttt{k},\texttt{m}),(\texttt{k},\texttt{i}),
                (\texttt{k},\texttt{n})\}}
\end{calculation}

After these steps, no more steps are possible, because the example
program has no loops.  So the values of the $DO_i$ constitute the
least solution to the equations.

%\bibliographystyle{plain}
%\bibliography{all}

\end{document}
