\section{AffApproxes with round-off error}

In Section 6, we saw how to do calculations with AffApproxes.  Here, we incorporate round-off error into
these calculations.

\demo{Conventions {\rm FIXME:8.1}}
An AffApprox $x$ is a five-tuple
$(x.f; x.f_0,x.f_1,x.f_2; x.{\rm err})$
consisting of four complex numbers $(x.f, x.f_0,x.f_1, x.f_2)$ and one real number $x.{\rm err}.$  In Section FIXME:6, the
real number was denoted $x.e,$ but it seems preferable to use $x.{\rm err}$ here.  Recall (Definition FIXME:6.4)
that an AffApprox $x$ represents the set $S(x)$ of functions from $A = \{(z_0,z_1,z_2) \in {\bf C}^3 : |z_k| \le 1 \
{\rm for} \ k \in \{0,1,2\}\}$ to ${\bf C}$ that are $x.{\rm err}$-well-approximated by the affine function
$x.f + x.f_0 z_0 + x.f_1 z_1 + x.f_2 z_2.$
\enddemo

{\it Remark} FIXME:8.2.
A review of Definition FIXME:7.2 (XComplexes and AComplexes; loosely, exact and approximate complex numbers) might be helpful at this time.

One approach to round-off error for AffApproxes would be to replace the four complex numbers in the definition of AffApprox by four AComplex numbers complete with their round-off errors, and similarly for the one real number.  We will not do this because it would necessitate keeping track of five separate round-off-error terms when we do AffApprox calculations.

Instead, we will
replace the four complex numbers by four XComplexes and push all the round-off error into the $.{\rm err}$ term.
Thus, the definition of AffApprox remains
essentially the same as in Section FIXME:6.
We note that, in doing an AffApprox calculation, our subsidiary calculations will generally be on XComplex numbers and produce an AComplex number whose $.e$ term will be plucked off and forced into the $.{\rm err}$ term of the final AffApprox.

\demo{Conventions {\rm FIXME:8.3}}
i)  In what follows, we will use Basic Properties FIXME:7.0 and Lemmas FIXME:7.0 and FIXME:7.1.  Also, the propositions in Section 6
will be utilized;  as such, the numbering of the propositions is the same in Sections FIXME:6 and FIXME:8 (for example,
Proposition FIXME:6.7 corresponds to Proposition FIXME:8.7).
\vglue4pt
ii)  Some notational simplifications will be introduced: ${\rm dist}(x)$ before Proposition FIXME:8.6, $ax$ before Propositions FIXME:8.8, 8.9, 8.11
(the middle usage of $ax$ differs slightly from the other two), and $ay$ before Propositions FIXME:8.8, 8.9.
\vglue4pt
iii)  We will try to keep our notation fairly consistent with that of the {\it verify} computer program, and this will produce some mildly peculiar notation.  In particular, in the operations pertaining to Propositions FIXME:8.2 and beyond, the resultant AffApproxes will be denoted $(r\_f.z; r\_f_1.z, r\_f_2.z,
r\_f_3.z; r\_{\rm error})$
where the first four terms are XComplexes and the last term is a double (technically, $r\_f.z$ is the XComplex part of the AComplex  $r\_f$ and similarly for the $r\_f_k.z$ terms).  One break with the notation of the programs though is that AffApproxes are called (in the programs) ACJ's, which stands for ``Approximate Complex 1-Jets."
\vglue4pt
iv) The propositions that follow include in their statements the definitions of the various operations on AffApproxes (see Remark
FIXME:6.6iii)).
\vglue4pt
v)  We remind the reader (see Section FIXME:7.4) that all machine operations act on machine numbers, and that the
various variables appearing in the propositions are assumed to be doubles.
\enddemo

$-X$:

\nonumproclaim{Proposition FIXME:8.1}
If $x$ is an AffApprox
then $S(-x) = -(S(x))$ where
$$-x \equiv (-x.f; -x.f_0,-x.f_1,-x.f_2; x.{\rm err}).$$ \endproclaim

$X+Y$:
We analyze the addition of the  {\rm AffApproxes}
 $x = (x.f; x.f_0,x.f_1, x.f_2; x.{\rm err})$  and
$y = (y.f; y.f_0,y.f_1,y.f_2; y.{\rm err}).$  To get the first term in $x+y$ we add the XComplex numbers $x.f$ and $y.f;$ which
produce the AComplex number $r\_f = x.f + y.f$ (see Proposition FIXME:7.4), and then we pluck off the XComplex part,
which we denote $r\_f.z.$  The round-off error part $r\_f.e$ will be foisted into the overall error term $r\_{\rm error}$
for $x+y.$ Similarly for the next three terms in $x + y.$

Abstractly, the overall error term $r\_{\rm error}$ comes from adding the round-off error contributions $r\_f.e,\  r\_f_0.e,\  r\_f_1.e,
\ r\_f_2.e$ and the AffApprox error contributions $x.{\rm err},\  y.{\rm err}$.  Of course, we have to produce a machine version.

\nonumproclaim{Proposition FIXME:8.2} If $x$ and $y$ are
{\rm AffApproxes, }
then $S(x + y) \supseteq S(x) + S(y)${\rm ,} where
$$x + y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f &=& x.f + y.f,\\
r\_f_k &=& x.f_k + y.f_k,\\
r\_{\rm error}& =& (1 + 3EPS)\\
&&\otimes\ ((x.{\rm err} \oplus y.{\rm err}) \oplus ((r\_f.e \oplus
r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))).
\end{eqnarray*}
\endproclaim

\demo{Proof}
The error is given by
\begin{eqnarray*}
&&\hskip-24pt (x.{\rm err} + y.{\rm err})  +\ ((r\_f.e + r\_f_0.e) + (r\_f_1.e + r\_f_2.e))\\
&\le& (1+EPS/2) (x.{\rm err} \oplus
y.{\rm err}) \\
&&+\ (1+EPS/2)((r\_f.e \oplus r\_f_0.e) + (r\_f_1.e \oplus r\_f_2.e))\\
&\le& (1+EPS/2)^3 ((x.{\rm err} \oplus
y.{\rm err}) \oplus ((r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e)))\\
&\le& (1 + 3EPS) \otimes ((x.{\rm
err} \oplus y.{\rm err}) \oplus ((r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))).
\end{eqnarray*}
 To get the last line
we used Lemma FIXME:7.1. \enddemo

$X - Y$:

\nonumproclaim{Proposition FIXME:8.3:} If $x$ and $y$ are {\rm AffApproxes,} then $S(x - y) \supseteq S(x) - S(y)${\rm ,}
 where
$$x - y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f& =& x.f - y.f,\\
r\_f_k &= &x.f_k - y.f_k,\\
r\_{\rm error} &=& (1 + 3EPS)\\
&& \otimes\ ((x.{\rm err} \oplus y.{\rm err}) \oplus ((r\_f.e
\oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))).
\end{eqnarray*}
\endproclaim

$X + D$:
Here, we add the AffApprox $x = (x.f; x.f_0,x.f_1,x.f_2; x.{\rm err})$  to the double $y$.  The only terms that change are the first and the last.

\nonumproclaim{Proposition FIXME:8.4}\hskip-8pt If $x$ is an
{\rm AffApprox}  and $y$ is a double{\rm ,}
then $S(x + y) \supseteq S(x) + S(y)${\rm ,} where
$$x + y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f& =& x.f + y,\\
r\_f_k &=& x.f_k,\\
r\_{\rm error}& = &(1 + EPS) \otimes (x.{\rm err} \oplus r\_f.e).\end{eqnarray*}
\endproclaim

\demo{Proof}
The error is given by
$$x.{\rm err} + r\_f.e \le (1 + EPS) \otimes (x.{\rm err} \oplus r\_f.e)$$
by Lemma FIXME:7.0. \enddemo

$X - D$:
\nonumproclaim{Proposition FIXME:8.5}\hskip-8pt If $x$ is an
{\rm AffApprox}  and $y$ is a double{\rm ,}
then $S(x - y) \supseteq S(x) - S(y)${\rm ,} where
$$x - y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f &= &x.f - y,\\
r\_f_k &=& x.f_k,\\
r\_{\rm error}& =& (1 + EPS) \otimes (x.{\rm err} \oplus r\_f.e).\end{eqnarray*}
\endproclaim

$X \times Y$:
We multiply the AffApproxes $x$ and $y$ while pushing all error into the $.{\rm err}$ term.

We will use the functions (see Formulas FIXME:7.0 and 7.1, at the end of Section~7) ${\rm absUB}= (1 + 2EPS) \otimes
{\rm hypot}_o(x.re,x.im)$ and
${\rm absLB}(x) = (1 - 2EPS) \otimes {\rm hypot}_o(x.re,x.im)$.

When $x$ is an AffApprox, we define ${\rm dist}(x)$ to be $$(1 + 2EPS) \otimes ({\rm absUB}(x.f_0) \oplus ({\rm absUB}(x.f_1) \oplus {\rm absUB}(x.f_2))).$$  This is the machine representation of the sum of the absolute values of the linear terms in the AffApprox $x$
(the proof is straightforward).

\nonumproclaim{Proposition FIXME:8.6} If $x$ and $y$ are
{\rm AffApproxes,}
then $S(x \times y) \supseteq S(x) \times S(y)${\rm ,} where
$$x \times y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f &=& x.f \times y.f,\\
r\_f_k &=& x.f \times y.f_k + x.f_k \times y.f,\\
r\_{\rm error} &=&
(1 + 3EPS) \otimes (A \oplus (B \oplus C)),\end{eqnarray*}
and
\begin{eqnarray*}
A &=& ({\rm dist}(x) \oplus x.{\rm err})\otimes ({\rm dist}(y) \oplus y.{\rm err}),
\\
B& =& {\rm absUB}(x.f) \otimes
y.{\rm err} \oplus {\rm absUB}(y.f) \otimes x.{\rm err},\\
C& =& (r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus
r\_f_2.e).\end{eqnarray*}
\endproclaim

\demo{Proof}
We add the non-round-off error term for $x \times y$ to the various round-off error terms that accumulated.
\begin{eqnarray*}
&&\hskip-48pt (({\rm dist}(x) + x.{\rm err}) \times\ ({\rm dist}(y) + y.{\rm err})) +
 (({\rm absUB}(x.f) \times y.{\rm err}
\\
&& +\
{\rm absUB}(y.f) \times x.{\rm err}) +
 (r\_f.e + r\_f_0.e) + (r\_f_1.e + r\_f_2.e))
\\
&\le&
(1+EPS/2)^3[({\rm dist}(x) \oplus x.{\rm err})\otimes ({\rm dist}(y) \oplus y.{\rm err})]\\
&& +\
 (1+EPS/2)^2\{({\rm absUB}(x.f) \otimes y.{\rm err}
\\
& &\oplus\
{\rm absUB}(y.f) \otimes x.{\rm err}) +
((r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))\}
\\
&\le& (1+EPS/2)^3 A + (1+EPS/2)^3 (B \oplus C) \\
&\le& (1+3EPS) \otimes (A \oplus (B \oplus C) ). \\
\noalign{\vskip-36pt}
\end{eqnarray*}
\enddemo

$X \times D$:

\nonumproclaim{Proposition FIXME:8.7} \hskip-8pt If $x$ is an
AffApprox  and $y$ is a double{\rm ,}
then $S(x \times y) \supseteq S(x) \times S(y)${\rm ,} where
$$x \times y = (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f& =& x.f \times y,\\
r\_f_k &=& x.f_k \times y,\\
r\_{\rm error} &=& (1+3EPS)\\
&& \otimes\ ( (x.{\rm err} \otimes |y|) \oplus
( (r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e)) ).
\end{eqnarray*}
\endproclaim

$X/Y$:
For convenience, let  $ax = {\rm absUB}(x.f),\ ay = {\rm absLB}(y.f).$

\nonumproclaim{Proposition FIXME:8.8} If $x$ and $y$ are
{\rm AffApproxes}  with $D > 0$ {\rm (}\/see below{\rm ),} then
$S(x / y) \supseteq S(x) / S(y)${\rm ,} where
$$x / y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f &=& x.f / y.f,
\\
r\_f_k& =& (x.f_k \times y.f - x.f \times y.f_k)/ (y.f \times y.f),\\
r.{\rm error} & =& (1 + 3EPS) \otimes (
((1 + 3EPS) \otimes A \ominus (1 - 3EPS) \otimes B )\oplus C ),\end{eqnarray*}
and
\begin{eqnarray*}
A &=& (ax \oplus ({\rm dist}(x) \oplus x.{\rm err})) \oslash D,\\
B &=& (ax \oslash ay \oplus {\rm dist}(x) \oslash ay)
\oplus  (({\rm dist}(y) \otimes ax) \oslash (ay \otimes ay)),\\
C &=& (r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus
r\_f_2.e),\\
D &=& ay \ominus (1 + EPS) \otimes ({\rm dist}(y) \oplus y.{\rm err}).
\end{eqnarray*}
\endproclaim

\demo{Proof}
As usual, we add the round-off errors to the old AffApprox error,
taking into account round-off error, working on it bit by bit.
\begin{eqnarray*}
 &&\hskip-16pt (ax + {\rm dist}(x) + x.{\rm err})/(ay - ({\rm dist}(y) + y.{\rm err}))\\
&&  \le (1 + EPS/2)^2 \\
&&\quad \times \ (ax \oplus ({\rm dist}(x)
\oplus x.{\rm err}))/
         (ay - (1 + EPS) \otimes ({\rm dist}(y) \oplus y.{\rm err}))\\
&&  \le (1 + EPS/2)^2 (ax \oplus ({\rm dist}(x) \oplus
x.{\rm err}))/
         \Big(\left({1 \over 1 + EPS/2}\right) \\
&&\quad\times \ (ay \ominus (1 + EPS) \otimes ({\rm dist}(y) \oplus y.{\rm err}))\Big)\\
&& \le (1 + EPS/2)^4 (ax
\oplus ({\rm dist}(x) \oplus x.{\rm err}))\\
&&\quad \oslash
         (ay \ominus (1 + EPS) \otimes ({\rm dist}(y) \oplus y.{\rm err}))\\
&& \le   (1 + 3EPS) \otimes A.
\end{eqnarray*}

The next term, being subtracted, requires opposite inequalities.
\begin{eqnarray*}
&&(ax/ay + {\rm dist}(x)/ay) + {\rm dist}(y) \times ax / (ay \times ay)\\
&&\quad \ge (1-EPS/2)(ax \oslash ay + {\rm
dist}(x)
\oslash ay) \\
&&\qquad +  (1-EPS/2) ({\rm dist}(y) \otimes ax )/ ({1 \over 1 - EPS/2})(ay \otimes ay)\\
&&\quad \ge ((1-EPS/2)^4 ((ax
\oslash ay \oplus {\rm dist}(x) \oslash ay) \oplus  (({\rm dist}(y) \otimes ax) \oslash (ay \otimes ay)))\\
&&\quad \ge (1 +
EPS/2)(1 - 3EPS) (B)  \ge (1 - 3EPS) \otimes B.\end{eqnarray*}

Finally, we do the round-off terms
$$((r\_f.e + r\_f_0.e) + (r\_f_1.e + r\_f_2.e)) \le (1 + EPS/2)^2 C $$
and we put these three pieces together:
\begin{eqnarray*}
&&
(ax + {\rm dist}(x) + x.{\rm err})/(ay - ({\rm dist}(y) + y.{\rm err}))
\\
&&\qquad  -
((ax/ay + {\rm dist}(x)/ay) + {\rm dist}(y) \times ax / (ay \times ay))\\
&&\qquad
+ ((r\_f.e + r\_f_0.e) + (r\_f_1.e + r\_f_2.e))
\\
&&\quad \le
(1 + 3EPS) \otimes A - (1 - 3EPS) \otimes B + (1 + EPS/2)^2 C\\
&&\quad \le (1+EPS/2)^2 (
((1 + 3EPS) \otimes A \ominus (1 - 3EPS) \otimes B)
 + C
) \\
&&\quad \le (1+3EPS) \otimes (
((1 + 3EPS) \otimes A \ominus (1 - 3EPS) \otimes B)
 \oplus C
) . \\
\noalign{\vskip-36pt}
\end{eqnarray*}
\enddemo

$D/X$:
We   divide a double $x$ by an AffApprox $y$.
For convenience, let $ax = |x|,\ ay = {\rm absLB}(y.f).\ $  Having done division out in the previous proposition, we will skip the proof of Proposition FIXME:8.9.  See the {\it Annals}
web site for the proof.

\nonumproclaim{Proposition FIXME:8.9} If $x$ is a double and $y$ is an
{\rm AffApprox}  with $D > 0$ {\rm (}\/see below{\rm ),}
 then $S(x / y) \supseteq S(x) / S(y)${\rm ,} where
$$x / y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error})$$
with
 \begin{eqnarray*}
r\_f&\hskip-8pt =\hskip-8pt& x / y.f,\\
r\_f_k&\hskip-8pt =\hskip-8pt& -(x \times y.f_k)/ (y.f \times y.f),\\
r\_{\rm error}&\hskip-8pt =\hskip-8pt& (1+3EPS) \otimes (
((1 + 2EPS) \otimes (ax  \oslash D) \ominus (1 - 3EPS) \otimes B)
\oplus C),\\
 B&\hskip-8pt =\hskip-8pt& ax \oslash ay  \oplus ({\rm dist}(y) \otimes ax \oslash (ay \otimes ay)),\\
C& \hskip-8pt=\hskip-8pt& (r\_f.e \oplus r\_f_0.e)
\oplus (r\_f_1.e \oplus r\_f_2.e),\\
D &\hskip-8pt=\hskip-8pt& ay \ominus (1 + EPS) \otimes ({\rm dist}(y) \oplus y.{\rm err}).
\end{eqnarray*}
\endproclaim

$X/D$:
We   divide an AffApprox $x$ by a nonzero double $y$ (the computer will object if $y = 0$).  The proof is easy  and
so we delete it.

\nonumproclaim{Proposition FIXME:8.10}
If $x$ is an {\rm AffApprox}  and $y$ is a nonzero double{\rm ,} then
$S(x / y) \supseteq S(x) / S(y)${\rm ,} where
$$x / y \equiv (r\_f.z; r\_f_0.z, r\_f_1.z, r\_f_2.z; r\_{\rm error}),$$
with
\begin{eqnarray*}
r\_f &\hskip-8pt=\hskip-8pt& x.f / y\\
r\_f_k &\hskip-8pt=\hskip-8pt& x.f_k / y\\
r\_{\rm error} &\hskip-8pt = \hskip-8pt&
(1+3EPS) \otimes (
(x.{\rm err}\oslash |y|)
\oplus
[(r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e)]
                                               ).\end{eqnarray*}
\endproclaim

$\sqrt X$:
Here, $x$ is an AffApprox and we let $ax = {\rm absUB}(x.f)$.  There are two cases to consider depending on whether or not
$D = ax \ominus (1 + EPS) \otimes ({\rm dist}(x) \oplus x.{\rm err})$ is or is not greater than zero.

\nonumproclaim{Proposition FIXME:8.11{\rm a}} If $x$ is an {\rm AffApprox}
and
$ D = ax \ominus (1 + EPS) \otimes ({\rm dist}(x) \oplus x.{\rm err})$ is not greater than zero{\rm ,} then
$S(\sqrt x) \supseteq \sqrt {S(x)}${\rm ,} where
we use the crude overestimate $$\sqrt x \equiv \left(0;0,0,0;(1 + 2EPS) \otimes
\root o \of {(ax \oplus (x\,{\rm dist} \oplus x.{\rm err}))} \right).$$
\endproclaim

\demo{Proof}
\begin{eqnarray*}\sqrt {ax + x\,{\rm dist} + x.{\rm err}}&\le &(1 + EPS/2) \sqrt { (ax \oplus (x\,{\rm dist} \oplus x.{\rm err}))}\\
&\le  &(1 + 2EPS) \otimes \root o \of { (ax \oplus (x\,{\rm dist} \oplus x.{\rm err}))}.
\\
\noalign{\vskip-36pt}
\end{eqnarray*}
\enddemo

\nonumproclaim{Proposition FIXME:8.11{\rm b}} If
$x$  is an {\rm AffApprox} and
$ D = ax \ominus (1 + EPS) \otimes ({\rm dist}(x) \oplus x.{\rm err})$ is greater than zero{\rm ,}
then $S(\sqrt x) \supseteq \sqrt {S(x)}${\rm ,} where
 $$\sqrt{x} \equiv (r\_f.z; r\_f_0.z,r\_f_1.z,r\_f_2.z; r\_{\rm error})$$
with
\begin{eqnarray*}
r\_f& = &\sqrt {x.f},\\
t &=& r\_f + r\_f,\\
r\_f_k& = &{\rm AComplex} (x.f_k.re,x.f_k.im;0) / t.
\end{eqnarray*}
{\rm (}\/Simply put{\rm ,} $r\_f_k = x.f_k / (2\sqrt{x.f})$. The reason we have to fuss to define $r\_f_k$ is
 because
$\sqrt{x.f}$ is an {\rm AComplex.)}
\begin{eqnarray*}
  r\_{\rm error}& \hskip-8pt =\hskip-8pt &
(1+3EPS)\\ &\hskip-8pt\hskip-8pt& \otimes\hskip-1pt \left\{\hskip-1pt
(1+EPS) \otimes \root o \of {ax}\ominus
(1 - 3EPS) \otimes [{\rm dist}(x)\oslash(2 \times \root o \of {ax})
\oplus \root o \of {D} ]\right\}
\\
&\hskip-8pt\hskip-8pt&  \oplus
((r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))
.\end{eqnarray*}
\endproclaim

\demo{Proof}
Let us work on the pieces.
$$\sqrt {ax} \le (1 + EPS) \otimes \root o \of {ax}.$$

Next,
\begin{eqnarray*}
&&{\rm dist}(x)/(2 \sqrt {ax}) + \sqrt {ax - ({\rm dist}(x) + x.{\rm err})}\\
&&\quad
\ge  (1 - EPS/2)^2 {\rm dist}(x) \oslash (2 \root o \of {ax})
\\
&&\qquad + (1 - EPS/2)^{1/2}\sqrt {ax \ominus (1+EPS) \otimes ({\rm dist}(x) \oplus x.{\rm err})}
                                              \\
&&\quad \ge(1 - EPS/2)^3 \left[{\rm dist}(x) \oslash (2 \root o \of {ax}) \oplus \root o \of {D}\
\right]\\
&&\quad \ge (1 + EPS/2) (1 - 3EPS) \left[{\rm dist}(x) \oslash (2 \root o \of {ax}) \oplus \root o \of {D}\ \right]\\
&&\quad \ge (1 -
3EPS) \otimes \left[{\rm dist}(x) \oslash (2 \root o \of {ax}) \oplus \root o \of {D}\ \right].
\end{eqnarray*}

Adding in the usual term, we get as our error bound
\begin{eqnarray*}
&&\sqrt {ax} - ({\rm dist}(x)/(2 \sqrt {ax}) + \sqrt {ax - ({\rm dist}(x) + x.{\rm err})}\ )\\
&&\qquad+\ ((r\_f.e + r\_f_0.e) + (r\_f_1.e + r\_f_2.e))\\
&&\quad \le (1 + EPS) \otimes \root o \of {ax}
- (1 - 3EPS) \otimes [{\rm dist}(x) \oslash (2 \root o \of {ax}) \oplus
\root o \of {D}\ ]
\\
&&\qquad+\ (1 + EPS/2)^2 ((r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))
      \\
&&\quad \le (1 + EPS/2)^3 \big(\{(1 + EPS) \otimes \root o \of {ax} \\
&&\qquad
\ominus\ (1 - 3EPS) \otimes [{\rm dist}(x) \oslash (2 \root o \of {ax}) \oplus \root o \of {D}\ ]\}
\\
&&\qquad \oplus\ ((r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))\big)
 \\
&&\quad \le (1 + 3EPS) \otimes (
\{(1 + EPS) \otimes \root o \of {ax}
\\
&&\qquad\ominus\ (1 - 3EPS) \otimes [{\rm dist}(x) \oslash (2 \root o \of {ax})\oplus \root o \of {D}\ ]\}
\\
&&\qquad \oplus ((r\_f.e \oplus r\_f_0.e) \oplus (r\_f_1.e \oplus r\_f_2.e))
                                                ).\\
\noalign{\vskip-36pt}
\end{eqnarray*}
\enddemo


\chapter{Meta-heuristics}

\section{Tabu-Search}
Tabu Search (TS) has been developed by Fred Glover \cite{Glover1998}. TS is a heuristic that combines a local search process with a number of anti-cycling rules which prevent the search from getting trapped in a local minimum. Tabu Search is very similar to a local search algorithm that proceeds iteratively from one solution to another through the \texttt{best\_two\_opt} \ref{sec:best_2_opt} method. It also uses a special memory structure, called a tabu list, that determines which subsequent solution will be chosen and therefore to organize the way space is explored. The algorithm starts with a random solution. By applying the \texttt{best\_two\_opt}, as long as a new improvement solution is found, it updates the current solution to it. When it comes to a local minimum (i.e. there are non-improvement solutions around two optimality) the use of the tabu list comes into play.\\
Pejorative moves are now allowed and the algorithm chooses the lowest cost one and adds this move to the tabu list, updates the current solution and starts again with the \texttt{best\_two\_opt}.
During the next iteration, while searching for the new solution, check that the move to obtain it does not belong to the list. If it does not appear, then the move is lawful and continues with the next steps of the algorithm. Conversely, if the move is tabu (i.e. not allowed, prohibited), the solution is discarded and another is chosen, until a lawful move is found. The algorithm will continue to choose licit pejorative moves until an improvement one, that does not belong to the list, is found. In this case the algorithm starts again.\\
As will be discussed later, the tabu list has a maximum size of elements. Consequently, when a new element has to be inserted and the list is full, the "oldest" element (i.e. the one that has been inserted longer) of the list will be replaced with it.\\
This strategy allows research to move along the "hills" that the costs of the various solutions form in the solution space. It is an excellent method to escape from the local minimum by maintaining a search based on the \texttt{best\_two\_opt} (Figure \ref{fig:tabu_search_perform_time}).\\
Looking at the implementation details there are many aspects that must be carefully evaluated:

\begin{itemize}
\item Type of structure for tabu list
\item Size of tabu list
\item Termination criterion
\end{itemize}

First of all, the type of structure used for the tabu list. We have decided to propose two different solutions, as each of them has its potential and its defects. The first, more classic, involves the use of a fixed-size circular array to store prohibited moves (so for each \texttt{best\_two\_opt} move, the two relative edges are inserted into the array). The second, however, uses a linked list in which each element is formed by a variable for the edge and a pointer \textit{next} to the next element.
One of the main differences is the allocation of memory, as the linked list dynamically manages its size and therefore aims to optimize space but, on the other hand, the removal of the oldest inserted element requires complete scrolling of the list. Instead, in the circular array the insertion and the deletion of an element is $O(1)$, but on the other hand it has a fixed tabu list dimension.
Fig.s \ref{fig:tabu_search_diff_perform_time} and \ref{fig:tabu_search_diff_perform_lb} show the performance profiles related to the tabu search with the two different data structures (tabu\_search names is related to linked list version). As anticipated, the version with array proves to be the fastest in terms of time, maintaining almost the same quality as the lower bound. \\
\begin{figure}[!h]
	\centering
	\begin{subfigure}{0.49\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/Ltabu_LA_time.png}
		\caption{Performance profile considering the execution time}
		\label{fig:tabu_search_diff_perform_time}
	\end{subfigure}
	\hfill
	\begin{subfigure}{0.49\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/Ltabu_LA_lb.png}
		\caption{Performance profile considering the solution cost}
		\label{fig:tabu_search_diff_perform_lb}
	\end{subfigure}
\caption{\texttt{tabu\_search} use linked list as data structure to store the tabu list instead of array.}
\label{fig:tabu_search_diff_perform}
\end{figure}
Another aspect to consider is the size of the tabu list. An "infinite" dimension would risk bringing the algorithm to a standstill in which it can no longer make any move since all those around two optimality have been prohibited. Conversely, too small a size could cause a return to the local minimum from which one was running away. A lot of studies and research have been done for this specific aspect \cite{Nababan_2019, Tsubakitani1998} and a better overall result than others has not been found, changing the typology of the problem also varies the best size of the list. A dynamic size list would seem to be the winning choice as a balance between computational time and the optimal cost. In our project, instead, two tests with a static dimension list are performed:
\begin{enumerate}
\item A size equal to (fig. \ref{fig:tabu_search_n2}):
	\begin{equation}
		\frac{|V|}{2}
	\end{equation}
\item A size equal to (fig. \ref{fig:tabu_search_r3}):
	\begin{equation} \label{tabu_list_size_r3}
		\frac{|V|}{\sqrt{3} * \frac{\ln{|V|}}{\ln{10}}}
	\end{equation}
\end{enumerate}
\begin{figure}[!h]
	\begin{subfigure}{\columnwidth}
		\centering
		\includegraphics[width=.6\columnwidth]{../res/lb_tabu_search_n_greedy_d2103_old.png}
		\caption{Linear tabu list size in the number of nodes.}
		\label{fig:tabu_search_n2}
	\end{subfigure}
	\begin{subfigure}{\columnwidth}
		\centering
		\includegraphics[width=0.6\columnwidth]{../res/lb_ts_test_d2103_5000.png}
		\caption{Logarithmic tabu list size in the number of nodes.}
		\label{fig:tabu_search_r3}
	\end{subfigure}
	\caption{Solution cost profiles considering the execution time.}
	\label{fig:tabu_search_perform_time}
\end{figure}
Finally, the termination criterion can be based on a maximum number of iterations of the algorithm in which the solution no longer improves or on a time limit.\\
Fig. \ref{fig:tabu_search_perform_time} shows the trend of the lower bounds found over time. %versione 2
The linear version gets good results for small problems, but from the figure, it is clear that as the number of nodes increases, the list becomes too large and, therefore, also the number of pejorative moves, which causes the lower bound to no longer be able to improve.
Instead, a logarithmic tabu list size manages both small and large problems and improves the lower bound in both types of them.

\section{Simulated-Annealing}
The goal is to find a point in the space at which a real valued energy function (or cost function) is minimized. Simulated annealing is a minimization technique which has given good results in avoiding local minima. This research is based on a \texttt{random\_two\_opt} (similar to sec. \ref{sec:best_2_opt} but choose a random one instead of looking for the best one). Moreover, it follows the idea of taking a random walk through the space at successively lower temperatures, where the probability of taking a step is given by a Boltzmann distribution:
\begin{equation}
	P(\Delta E)= \begin{cases}
	e^{-\frac{ E_{i+1} - E_{i}}{kT}} & \text{if } E_{i+1} > E_{i} \\
	1 & \text{otherwise}
	\end{cases}
\end{equation}
where $ E_{i} $ is the energy at time $ i $, $ T $ is the temperature, $k$ is the Boltzmann constant and $\Delta E =  E_{i+1} - E_{i}$. \\
\begin{figure}[!h]
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_100_a280_500.png}
		\caption{Initial temperature of $100$\%.}
		\label{fig:sim_ann_100}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_50_a280_500.png}
		\caption{Initial temperature of $50$\%.}
		\label{fig:sim_ann_50}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_10_a280_500.png}
		\caption{Initial temperature of $10$\%.}
		\label{fig:sim_ann_10}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_01_a280_500.png}
		\caption{Initial temperature of $1$\%.}
		\label{fig:sim_ann_1}
	\end{subfigure}
	\caption{Solution cost profile considering the execution time, with time limit of $500$ sec. and different initial temperatures, of the instance \textit{a280.tsp}.}
	\label{fig:sim_ann_temperature}
\end{figure}
A step will occur if the new energy is lower. If the new energy is higher, the transition can still occur, and its likelihood is proportional to the temperature $T$ and inversely proportional to the energy difference $\Delta E$.
The temperature $T$ is initially set to a high value (\texttt{INT\_MAX} of \textit{limits.h} C class), and a random walk is carried out at that temperature. Then, the temperature is lowered very slightly according to a cooling schedule.
The cooling schedule chosen is based on the time limit given to the algorithm, at each interaction the temperature is scaled as a percentage based on the percentage of time spent on the time limit to perform that iteration. This avoids estimating a fixed value with which to decrease the temperature at each iteration, as the time required for an iteration can vary greatly based on the probability value found (when successful, the computational time increases drastically compared to when probability fails).\\
Furthermore, if the temperature decreases sufficiently slowly, the probability of finding the global minimum tends to 1, thanks to all simulated annealing proofs of convergence in the literature which is based on homogeneous Markov chain theory and the condition of reversibility \cite{Henderson}. Since only improvement steps are accepted at zero temperature, various \texttt{random\_two\_opt} are performed before concluding the algorithm in order to optimize the achieved solution as much as possible.\\
The slight probability of taking a step that gives higher energy is what allows simulated annealing to frequently get out of local minima.

Several single tests were performed for this algorithm focusing on the type of dataset used and the initial temperature. The tests in fig. \ref{fig:sim_ann_temperature} and \ref{fig:sim_ann_dataset} start from an initial tour given by the execution of the Greedy algorithm (\ref{sec:greedy}), while for those in fig. \ref{fig:sim_ann_heavy} an algorithm \texttt{n\_grasp} \ref{sec:grasp} (with n = 2) was used.
First of all, in fig. \ref{fig:sim_ann_temperature} the different performance profiles are highlighted, based on lower bound and execution time, as the initial temperature varies. It is noted that, starting from a good initial solution, the higher the temperature, the more the simulating annealing will tend to worsen it, accepting pejorative moves with a high probability. However, as the figure shows, this does not bring any advantage compared to starting with a temperature of already 10\%. The theory shows that a very slow descent of the temperature will lead the algorithm to avoid local minimums with probability almost $1$, but already with $500$ seconds it cannot reach the global minimum, indeed, the one with an initial temperature of 10\% succeeds find a lower value.
The case \ref{fig:sim_ann_1} works better than all the others with that dataset as it accepts few pejorative moves (initial ascent of the graph) and spends more time looking for the improvement ones, in fact it is the only one that improves the initial solution given from Greedy.\\
If the initial solution were already in the valley towards a local minimum, the algorithm \ref{fig:sim_ann_1} would hardly be able to get out of it, but instead, if it were in a valley towards the global one then it would almost certainly find the best lower bound. Conversely, it can be said for the \ref{fig:sim_ann_100} algorithm that in the first case it would easily get out of it but most likely it would leave the valley also in the second case.\\
Surely the right initial temperature value is based on the problem.
\begin{figure}[!h]
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_100_att48.png}
		\caption{Instance att48.tsp.}
		\label{fig:sim_ann_att48}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_100_a280.png}
		\caption{Instance \textit{a280.tsp}.}
		\label{fig:sim_ann_a280}
	\end{subfigure}
	\caption{Two examples of solution cost profile considering the execution time with initial temperature of 100\% of different instances.}
	\label{fig:sim_ann_dataset}
\end{figure}

\begin{figure}[!h]
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_n_grasp_01_d18512_25200.png}
		\caption{Initial temperature of $1$\% and time limit \protect\\ of $25200$ sec.}
		\label{fig:sim_ann_1_d18512}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_simulating_annealing_ngrasp_10_d18512_36000.png}
		\caption{Initial temperature of 10\% and time limit \protect\\ of $36000$ sec.}
		\label{fig:sim_ann_10_d18512}
	\end{subfigure}
	\caption{Solution cost profile considering the execution time of heavy instance \textit{d18512.tsp} with different initial temperatures and execution times.}
	\label{fig:sim_ann_heavy}
\end{figure}
There are two other important considerations shown in fig.s \ref{fig:sim_ann_dataset} and \ref{fig:sim_ann_heavy}. The first concerns the search method used, it is clearly seen that \texttt{random\_two\_opt} brings a lot of variability in datasets with few nodes (\ref{fig:sim_ann_att48}), as it is also performed more quickly and therefore more times, while for heavy datasets (\ref{fig:sim_ann_heavy}) the time required for a single \texttt{random\_two\_opt} is very high and the variability is very low. \\
The second consideration concerns only fig. \ref{fig:sim_ann_heavy}, where simulating annealing was tested with the largest dataset of this project. Despite having been performed for many hours and with very low temperatures, it almost never managed to improve the solution, worsening it over time until it ended at the highest lower bound among those found. Due to the high cost of time to execute the \texttt{random\_two\_opt} the algorithm did only a few steps and probably with larger jumps it would have been better, but surely it would have taken a lot of hours to find a good solution to this dataset.

\section{Variable Neighborhood Search (VNS)}

This metaheuristic moves from a solution to another iterating two phases:
\begin{enumerate}
	\item Optimization
	\item Perturbation
\end{enumerate}

\begin{figure}[!h]
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_vns_n_greedy_10_5_d2103.png}
		\caption{n=5}
		\label{fig:lb_vns_n_greedy_10_95_03_02_5_d2103}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_vns_n_greedy_10_10_d2103.png}
		\caption{n=10}
		\label{fig:lb_vns_n_greedy_10_95_03_02_10_d2103}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/lb_vns_n_greedy_10_20_d2103.png}
		\caption{n=20}
		\label{fig:lb_vns_n_greedy_10_95_03_02_20_d2103}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/d2103_16.png}
		\caption{The graph of the solution returned by VNS (n=5).}
		\label{fig:d2103_16}
	\end{subfigure}
	\caption{The profile of the cost of the solution (versus time domain) returned by \texttt{best\_two\_opt} in each step of the VNS, changing the value of n of \texttt{random\_n\_opt}.}
	\label{fig:lb_vns}
\end{figure}
The first is done iterating a refining heuristic until a local minimum is found, in this specific case it has been used the \texttt{best\_two\_opt} algorithm, which is explained in cap \ref{sec:best_2_opt}. After the optimization, a perturbation is applied to leave the local minima, here \texttt{random\_n\_opt}. This algorithm generate a new solution that differ n edges from the first (check at the end of this section for details).
The two phases are iterated until the max number of iterations or time limit occur.\\
Note that the implemented VNS is not optimized to work with multiple thread.\\
In fig \ref{fig:lb_vns} is shown the cost of the solution in each \texttt{2\_opt} step of the VNS using different $ n $ for \texttt{random\_n\_opt}. It is interesting to note that most of the time is required for the first descent and after that the first local minimum is found, the best lower bound does not decrease so much. The calculated tour is plotted in fig \ref{fig:d2103_16}, note that the improvement introduced by VNS w.r.t \texttt{n\_greedy\_best\_two\_opt} is very small.\\
The performance profiles in fig \ref{fig:Lsubtour_hardfixing_vns_time} and \ref{fig:Lsubtour_hardfixing_vns_lb} show that there is no significant difference in using \texttt{n\_greedy}, \texttt{n\_grasp} or a single grasp (\texttt{vsn}) as warm start.

\begin{figure}[!h]
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/Lvns_LA_time.png}
		\caption{Performance profile considering the execution time}
		\label{fig:Lsubtour_hardfixing_vns_time}
	\end{subfigure}
\hfill
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/Lvns_LA_lb.png}
		\caption{Performance profile considering the solution cost.}
		\label{fig:Lsubtour_hardfixing_vns_lb}
	\end{subfigure}
\caption{\texttt{vns} method use \texttt{n\_grasp} with $ n=1 $ as warm start, instead in \texttt{vns\_n\_greedy} and \texttt{vns\_n\_grasp} $ n=10 $. No significant differences to note in terms of execution times and solutions cost between the methods.}
\label{fig:Lvns_pp}
\end{figure}

\section{Genetic Algorithm}
The genetic algorithm (GA) is the last meta-heuristic technique proposed. Its behaviour derives from an evolutionary biology metaphor. A population of individuals (solutions) is randomly created. The individual solutions represent one tour each. These solution are then exposed to simulated evolution.
For a complete explanation of the simple genetic algorithm, see \cite{phdthesis}.\\
A particular genetic algorithm has been implemented in this paper: it is based almost exclusively on the "Powerful Genetic Algorithm Using Edge Assembly Crossover" created by Yuichi Nagata and Shigenobu Kobayashi \cite{Nagata2013, Honda2013}, except for a subsection that has been completely designed by us.\\ A description of the algorithm will be presented and some paragraphs, which are contained in their paper \cite{Nagata2013}, will be reported here thanks to their clear description. In addition, the differences from his algorithm and our implementation choices will be explained.\\
The search process of the GA consists of two stages: \\
\begin{itemize}
\item \texttt{GA-EAX/Stage I}: a localized version of Edge Assembly Crossover (EAX) as the crossover operator from the start of the search until non-improvement in the best solution is found over a period of generations or because of time limit.
\item  \texttt{GA-EAX/Stage II}: after that, switch to a global version of EAX and use it until the end of the search. Stage II is also terminated by the same condition of previous one.
\end{itemize}
For this project only Stage I is developed but the global version does not add any difficulties in the code. Algorithm \ref{alg:gagen} describes in a compact way the various steps of the entire search.\\

\begin{algorithm}
\caption{GA General}\label{alg:gagen}
\begin{algorithmic}[1]
\Procedure{Procedure GA()}{}
\State $\textit{\{x\textsubscript{$1$},...,x\textsubscript{N\textsubscript{pop}}\}} := \texttt{INIT\_POPULATION()}$
\While{\textit{termination condition is satisfied}}
	\State $\textit{r($\cdot$)} := \texttt{SHUFFLE\_INDIVIDUALS()} \textit{$\equiv$ a random permutation of $1$,...,N\textsubscript{pop} } $
	\For{\texttt{$i := 1$ to N\textsubscript{pop}}}
		\State $p_A := \textit{x\textsubscript{r($i$)}} , \textit{p\textsubscript{B}} := \textit{x\textsubscript{r($i+1$)}} $
		\State $\textit{\{y\textsubscript{$1$},...,y\textsubscript{N\textsubscript{kids}}\}} := \texttt{EAX\_SINGLE(p\textsubscript{A}, p\textsubscript{B})}$
		\State $x_{r(i)} :=$ \texttt{SURVIVAL\_SELECTION(y\textsubscript1,...,y\textsubscript{N\textsubscript{kids}}, p\textsubscript{A})}
	\EndFor
	\State $\textit{best\_individual} := \textit{best individual of actual population}$
\EndWhile
\State \textbf{return} $best\_individual$
\EndProcedure
\end{algorithmic}
\end{algorithm}

\subsection{EAX\_SINGLE}
The recombination operator EAX uses the edges from the two parents to construct disjoint subtours.
Then, using a more general version of the \texttt{patching} algorithm \ref{section:patching}, the subtours are connected in a greedy fashion to produce the offspring tour. Thus, the EAX operator considers local information which is exploited in determining which edges to use to connect subtours.\\
Another important trait of the EAX operator is that it will introduce new edges into the offspring when connecting subtours. Edges not in the parents, or perhaps not even in the population, are introduced into offspring.
The argument as to why good new edges must be introduced during recombination is simple. As point out in \cite{Mathias92geneticoperators}, the complete graph of all possible edges for a sTSP has $(N^2-N)/2$ edges, where $N$ is the number of nodes. Each tour samples $N$ of these edges, so a population must be of size at least $(N-1)/2$ in order to sample each edge exactly once.
Assume population size is proportional to the number of the nodes. Then each edge occurs twice in expectation in an initial random population. Selection can therefore quickly eliminate edges from the population. Good edges can also be lost if they occur in poor tours. Thus it is important for operators to intelligently introduce new good edges. This feature is part of the construction of EAX and therefore, may contribute to its effectiveness.

\begin{figure}[h]
	\centering
	\includegraphics[width=1.0\columnwidth]{img/GA_steps}
	\caption{Example of the \texttt{EAX\_SINGLE} method steps (image taken from \cite{Nagata2013}).}
	\label{fig:GA_steps}
\end{figure}

Focusing on details of the EAX procedure:\\
Once two parents have been selected for crossover, the EAX operator merges these two individuals into a single graph denoted by R (Step 1 of Image \ref{fig:GA_steps}, graph R is named G\textsubscript{AB}). The two parents are denoted by A and B, respectively. Each edge in R is annotated with the parent to which it belongs. R may contain two instances of the same edge, if both parents contain the edge (that is why a more general version of \texttt{patching} is used).\\
R is next divided into a set of disjoint subtours. Let v\textsubscript{i} represent a vertex from R and let (v\textsubscript{i},  v\textsubscript{j}), i $\neq$ j, represent an edge. Suppose (v\textsubscript{i},  v\textsubscript{j}) represents an edge randomly chosen from parent A.\\
Choose one vertex (either v\textsubscript{i} or v\textsubscript{j}) as the origin. If v\textsubscript{i} is the origin, then choose an edge which leads from the second vertex, v\textsubscript{j} , to any other vertex in R. However, this edge must come from parent B. If more than one such edge exists, a random selection is made. The algorithm continues to traverse R, at each step alternately picking edges from parent A and parent B.\\
After each edge is traversed, the algorithm checks to see if adding this new edge to the set of previously selected edges will result in an AB-cycle. An AB-cycle is a even-length sub-cycle of R with edges that alternately come from A and B. An AB-cycle may repeat nodes, but not edges. While there can be two edges between a pair of nodes, they are uniquely identified as an A or B edge, and thus distinct.\\
Once an AB-cycle has been found it is stored and the edges making up that cycle are removed from R. The algorithm repeats this procedure until R contains no more edges, having been completely decomposed into a set of AB-cycles (Step 2 of Image \ref{fig:GA_steps}). \\
The first several edges used in the construction of the AB-cycle may not appear in the final AB-cycle.
This occurs when the final edge connects back onto the subgraph at some node x other than the origin node, and the induced subcycle is an AB-cycle. In this case the remaining edges are however removed from R graph but is kept aside in the path being traced, to eventually be used later in forming another cycle. Nagata and Kobayashi choose an edge incident with x from R to begin construction of the next AB-cycle instead in our algorithm we preferred to take an edge incident to any node remaining in the traced path (other technique prefers to select the starting location of a new AB-cycle at random from R).
For the symmetric TSP problem, R is undirected and therefore, the set of AB-cycles is not uniquely determined by the algorithm. Furthermore, a number of "ineffective" AB-cycles may be formed by the algorithm. All AB-cycles that have less than 4 different nodes inside them belong to this group. Any ineffective AB-cycles are found and removed from R and also removed from consideration by the remaining phases of the algorithm.
\\
After construction of the set of AB-cycles, a subset of AB-cycles is chosen to be used in the generation of an intermediate child. This subset is called an E-set (Step 3 of Image \ref{fig:GA_steps}). For selecting AB-cycles for inclusion into the E-set, we choose an our method different from those defined by Nagata and Kobayashi. Given the small size of the problems we tested compared to those of the TSP Art of Nagata, the number of subtours in the E-set is not very large and therefore, instead of sampling by random selection some of them, we scroll through them all and create one intermediate child for each.
\\
Construction of an intermediate child, C, begins with a copy of parent A. Then each edge of each subtour in the E-set is examined, with the following actions taken on C. If the edge from the E-set is a member of parent A, the edge is deleted from C. If the edge is a member of parent B, the edge is added to C. The result is a set of disjoint subtours which comprise the intermediate child (Step 4 of Image \ref{fig:GA_steps}). Fig. \ref{fig:ga_eax_att12} show some steps performed on \textit{att12.tsp} instance. \\
The last stage of the EAX operator involves transformation of the intermediate child into a single legal tour using a general \texttt{patching} algorithm (Step 5 of Image \ref{fig:GA_steps}). The difference between this general algorithm and the one presented in \ref{section:patching} is in the possibility of having double edges, after performing Step 4. This implies that one of the subtours can only be made up of two nodes and two same edges, one of parent A and one of B. Similar situation with three nodes and six edges (three doubles). In previous problems this situation never happened and therefore we generalized the Patching algorithm to include this variant.\\
The pseudocode of the \texttt{EAX\_SINGLE} method is identical to that explained in Algorithm 1 of Paper \cite{Honda2013}.

\begin{figure}[!h]
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_gen_A.png}
		\caption{Tour represented Parent A.}
		\label{fig:ga_gen_A}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_gen_B.png}
		\caption{Tour represented Parent B.}
		\label{fig:ga_gen_B}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_rm_A.png}
		\caption{Tour \texttt{y} obtained after removing the sides \\ belonging to both the chosen E-set and Parent A, \\starting from Tour Parent A.}
		\label{fig:ga_rm_A}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_add_B.png}
		\caption{Two subtours obtained after adding the sides belonging to both the chosen E-set and Parent B. A \texttt{patching} will then be applied, starting from this.}
		\label{fig:ga_add_B}
	\end{subfigure}
	\caption{\texttt{EAX\_SINGLE} procedure steps.}
	\label{fig:ga_eax_att12}
\end{figure}

\subsection{Evaluate AB-Cycles}
This method was completely designed by us from scratch. It refers to how to find a cycle that respects the conditions of the \texttt{EAX\_SINGLE} procedure inside the nodes and edges traced so far by the current AB-Cycle. An explanation of this procedure is not given in the papers \cite{Nagata2013, Honda2013} and it is not even that simple. We initially thought of using a greedy graph search algorithm, such as Depth First Traversal (DFT) or Breadth First Search (BFS), but these algorithms do not include the presence of double edges between two nodes and are based on visiting the nodes and not edges and also once found any cycle they stop and do not provide the possibility to continue the search if the cycle does not meet certain conditions. So we have developed an ad hoc algorithm for this type of search that transforms the graph into a tree considering double edges and the possibility to continue the search if a cycle is found that does not respect the conditions required by the \texttt{EAX\_SINGLE}. This algorithm has a recursive structure and uses linked lists that allow a dynamic allocation to save all the necessary information, it was also built trying to free up memory as much as possible in order to avoid overflow as the generations increase. Furthermore, the possibility of finding all the cycles within the graph and not only one is managed, but, as required by the EAX, when an acceptable solution is found, the search ends.
% spiegare un attimo come funziona? quindi le diramazioni rappresentano ognuna un percorso possibile, in questo modo vengono considerati tutti i possibili cammini all'interno del grafo.

\subsection{SURVIVAL\_SELECTION}
For the survival selection method, some parameters are defined:
\begin{itemize}
\item N\textsubscript{pop}
\item N\textsubscript{kids}
\item Edge Frequency Table F($e$)
\end{itemize}
N\textsubscript{pop} and N\textsubscript{kids} be the population size and the number of offspring solutions generated from a single pair of parents, p\textsubscript{A} and p\textsubscript{B}, respectively, with the chosen value of 10 for both, differently from the default configuration of \texttt{GA-EAX/Stage I} \cite{Nagata2013} (low values is used due to the complexity of the algorithm). N\textsubscript{kids} represents an upper bound to the number of offspring solutions but fewer of them could be generated.\\
The edge frequency table F($e$) is a table that records the frequencies of each edge $e \in E$ included in the population, where $E$ is the edge set of the complete graph of a given TSP instance. The values of F($e$) are initialized and are used in the evaluation function for selecting offspring solutions. This evaluation function is based on the edge entropy measure computed from F($e$) and is used for maintaining the population diversity in a positive manner. \\
To keep the table updated: let $y\ssymbol{1}$ be the selected individual among the generated offsprings, which replaces the population member chosen as parent p\textsubscript{A}. The values of F($e$) are updated as follows:

\begin{equation}\begin{array}{ll}
F(e) \leftarrow F(e)-1 & \forall e \in E\textsubscript{remove} \\
F(e) \leftarrow F(e)+1 & \forall e \in E\textsubscript{add}
\end{array}\end{equation}

where E\textsubscript{remove} is a set of the edges that are included in p\textsubscript{A} but not included in $y\ssymbol{1}$, E\textsubscript{add} is a set of the edges that are included in $y\ssymbol{1}$ but not included in p\textsubscript{A}. \\

The offspring $y\ssymbol{1}$ is selected, taking account of the balance between the amount of the improvement and loss of the population diversity. Let L be the average tour length of the population and H the edge entropy of the population defined as follows:

\begin{equation}
H=-\sum_{e \in E} F(e) / N_{\mathrm{pop}}\left(\log \left(F(e) / N_{\mathrm{pop}}\right)\right)
\end{equation}

$\Delta$L(y) and $\Delta$H(y) denote the differences in L and H, respectively, when x\textsubscript{i}(p\textsubscript{A}) is replaced with $y\ssymbol{1}$. The offspring $y\ssymbol{1}$ is selected so that the following evaluation function is maximized.

\begin{equation}\text { Eval\textsubscript{Ent}}(y):=\left\{\begin{array}{ll}
\frac{\Delta L(y)}{\Delta H(y)} & (\Delta L<0, \Delta H<0) \\
-\frac{\Delta L(y)}{\epsilon} & (\Delta L<0, \Delta H \geq 0) \\
-\Delta L(y), & (\Delta L \geq 0)
\end{array}\right.\end{equation}

where $y$ is an offspring solution and $\epsilon$ is a sufficiently small positive number (our chosen value $0.1$).\\
% versione 2
\subsection{Test}
For all tests, each individual of the initial population is created from one of the following heuristics at random: \texttt{heuristic\_insertion}, \texttt{n\_grasp\_10\_33\_33\_33}, \texttt{n\_grasp\_10\_95\_03\_02}, \texttt{n\_greedy\_10} and \texttt{n\_greedy\_100}. This allows the algorithm much more initial variance than a population created by the same heuristic. Furthermore, a \texttt{two\_opt} is executed for each child created, in order to optimize it without losing its characteristics (as happens if \texttt{best\_two\_opt}  is used instead).\\
The figure \ref{fig:ga_50_10} contains two tests performed by varying the termination condition relative to the maximum number of iterations without improvement of the lower bound. If a maximum value of 50 generations without improvement is set, the figures \ref{fig:ga_50_att48} and \ref{fig:ga_50_bier127} show how the lower bound tends to stabilize towards the end of the execution but continuing for a long time.
Instead, figures \ref{fig:ga_10_att48} and \ref{fig:ga_10_bier127} with only 10 generations without improvement get the same lower bound but in the first case, in a quarter of the time and in the second, about half. Figure \ref{fig:ga_10_50} confirms what has just been said.\\
The potential of this algorithm lies in finding the best lower bound where many other algorithms would never be able to arrive, but its complexity entails an enormous time in our computers.
Thus, to make the genetic algorithm comparable with the other meta heuristics, the value chosen is 10 generations (a lower value would lead the algorithm to find a worse lower bound for the same time).\\
In the case that the best possible lower bound is sought, it is advisable to increase this value or even remove it and look for an initial population as variable as possible.
This way the algorithm will have a slower lower bound improvement but will probably have enough variability to avoid local minima. \\

\begin{figure}[!h]
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_50_att48.png}
		\caption{Max generations 50, instance \textit{att48.tsp}.}
		\label{fig:ga_50_att48}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_50_bier127.png}
		\caption{Max generations 50, instance \textit{bier127.tsp}.}
		\label{fig:ga_50_bier127}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_10_att48.png}
		\caption{Max generations 10, instance \textit{att48.tsp}.}
		\label{fig:ga_10_att48}
	\end{subfigure}
	\begin{subfigure}{.5\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_10_bier127.png}
		\caption{Max generations 10, instance \textit{bier127.tsp}}
		\label{fig:ga_10_bier127}
	\end{subfigure}
	\caption{Solution cost profile considering the execution time, with time limit of $600$ sec. and different maximum number of generations without improvement.}
	\label{fig:ga_50_10}
\end{figure}

\begin{figure}[!h]
	\centering
	\begin{subfigure}{0.7\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_10_50_time.png}
		\caption{Solution time domain.}
		\label{fig:ga_10_50_time}
	\end{subfigure}
	\begin{subfigure}{0.7\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/ga_10_50_lb.png}
		\caption{Solution cost domain.}
		\label{fig:ga_10_50_lb}
	\end{subfigure}
	\caption{Performance profile of genetic algorithm with maximum number of generations without improvement of 50 and 10.}
	\label{fig:ga_10_50}
\end{figure}

Finally, figure \ref{fig:meta_heur} reports the performance profiles of three of the four different meta heuristics. Simulating annealing is missing because, as it has been developed, it has no termination conditions except for the time limit. Consequently a comparison on time would have no meaning while a comparison on the lower bound would be possible if the other termination conditions were removed from the other algorithms.\\

\begin{figure}[!h]
	\centering
	\begin{subfigure}{\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/metaheur_time_L_2ga_new.png}
		\caption{Solution time domain.}
		\label{fig:meta_heur_time}
	\end{subfigure}
	\begin{subfigure}{\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{../res/metaheur_lb_L_2ga_new.png}
		\caption{Solution cost domain.}
		\label{fig:meta_heur_lb}
	\end{subfigure}
	\caption{Performance profile of meta-heuristics.}
	\label{fig:meta_heur}
\end{figure}


\section{The \pushheap algorithm}
\Label{sec:pushheap}

The \pushheap algorithm assumes that the first $n-1$ elements of an array
of length~$n$ form already a heap and adds to it the element \inl{a[n-1]}.

Whereas in the \cxx Standard Library \cite[\S 28.7.7.1]{cxx-17-draft}
\pushheap works on a range of random access iterators,
our version operates on an array of \valuetype.
We therefore use the following signature for \pushheap

\begin{lstlisting}[style = acsl-block]

    void push_heap(value_type* a, size_type n);
\end{lstlisting}

The \pushheap algorithm expects that \inl{n} is greater or equal than~1.
It also assumes that the array\\
\inl{a[0..n-2]} forms a heap.
The algorithms then \emph{rearranges} the array \inl{a[0..n-1]} such that the
resulting array is a heap.
In this sense the algorithm \emph{pushes} the element \inl{a[n-1]} on the given heap.

\subsection{Formal specification of \pushheap}

The following listing shows our specification of \pushheap.
Note that the post condition \inl{reorder} states
that \pushheap is not allowed to change the number of occurrences
of an array element.
Without this post condition,
an implementation that assigns \inl{0} to each array element
would satisfy the post condition \inl{heap}---surely
not what a user of the algorithm has in mind.

\input{Listings/push_heap.h.tex}

Pushing an element on a heap usually \emph{rearranges} several elements of the array
(cf.\xspace Figures~\ref{fig:pushheap-pre} and~\ref{fig:pushheap-post}).
We therefore must be able express that \pushheap only reorders
the elements of the array.
We re-use the predicate \logicref{MultisetReorder} to formally describe this property.

\subsection{Implementation of \pushheap}

The following two figures illustrate how \pushheap affects an array,
which is shown as a tree with blue and grey nodes, representing
heap and non-heap nodes, respectively.
Figure~\ref{fig:pushheap-pre} shows the heap from
Figure~\ref{fig:heap-tree} together with the additional element~\inl{12} that
is to be pushed on the heap.
To be quite clear about it: the new element~\inl{12} is the last element of the
array and not yet part of the heap.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.70\linewidth]{Figures/push_heap_pre.pdf}
\caption{\Label{fig:pushheap-pre}Example heap before the call of \pushheap}
\end{figure}

\FloatBarrier

Figure~\ref{fig:pushheap-post} shows the array
after the call of \pushheap.
We can see that now all nodes are colored in blue, i.e., they are part of the heap.
The dashed nodes highlight which heap nodes have changed during the function call.
The element to be pushed into the heap is now at its correct position.
The arrows indicate the \emph{cyclic reordering} of array elements to achieve the
desired result.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.70\linewidth]{Figures/push_heap_post.pdf}
\caption{\Label{fig:pushheap-post}Example heap after the call of \pushheap}
\end{figure}

\FloatBarrier

Verifying our implementation of \implref{pushheap} is a non-trivial undertaking.
In order to better structure our discussion we refer to the central
loop of the algorithm as the \emph{main act} and the parts before and after
it as \emph{prologue} and \emph{epilogue}.

We can establish the \inl{heap} property of \specref{pushheap}
already in the prologue.
The \inl{reorder} property, however, only holds at the function boundaries
and is violated while \pushheap manipulates the array.
To be more precise:
We loose the \inl{reorder} property in the prologue and
formally capture and maintain a slightly more general property
in the main act.
From this we will recover the \inl{reorder} property in the epilogue.

We will illustrate the changes to the underlying array after each stage
by figures of the array in tree form,
based on the \pushheap example from Figure~\ref{fig:pushheap-pre}.

\input{Listings/push_heap.c.tex}

\subsubsection{Prologue}
\Label{sec:push-heap-prologue}

In the prologue we check whether the initial heap is nonempty,
initialize some variables,
\emph{and} also check by comparing with the parent node
whether \inl{a[c]}, which is the value to be pushed on the heap and which
is the last element of the array, is by chance already at the right place.
If not we set aside this value in the variable \inl{v} and
assign the parent value \inl{a[p]} to \inl{a[c]}.
Note that this assignment only occurs if the respective values
differ.
This allows us to formally describe the effect of the assignment using the predicate
\logicref{ArrayUpdate}.
%
Figure~\ref{fig:pushheap-prologue} highlights the main effects of the prologue.
Here and in the following figures we highlight the currently active node.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.70\linewidth]{Figures/push_heap_prologue.pdf}
\caption{\Label{fig:pushheap-prologue}Heap after the prologue of \pushheap}
\end{figure}

At this point we have achieved several things.
\begin{enumerate}
\item The array \inl{a[0..n-1]} is now a heap.
\item Regarding their respective number of occurences in the array \inl{a[0..n-1]}
\begin{itemize}
\item the original value \inl{a[c]} occurs one time less
\item the original value \inl{a[p]} occurs one time more
\item whereas all other values have not changed their number of occurences.
\end{itemize}
\end{enumerate}

The first observation is expressed in the assertion \inl{heap}
whereas the small fluctuation of array elements described in
the second observation is expressed by using the predicate \logicref{MultisetParity}
in the assertion \inl{reorder}.

\subsubsection{Main act}
\Label{sec:push-heap-main-act}

In the main act, we start at the parent location, which is now stored
in the variable \inl{c} (\emph{child}).
Compared to the pre-state of \pushheap
at the beginning of the main act the array \inl{a[0..n-1]}
\begin{itemize}
\item contains the value \inl{v} one time less
\item contains the value \inl{a[c]} one time more
\item whereas all other values have not changed their number of occurences.
\end{itemize}

Now, as long as the index~\inl{c} is not yet the root of the heap
and its consequently existing parent value \inl{a[p]} is less than \inl{v},
we haven't found yet an index \inl{c} where we could insert \inl{v} without
violating the heap property.

In the loop body we proceed as follows.

\begin{itemize}
\item
If \inl{a[c]} is less than \inl{a[p]} we copy the latter value on the former.
Note that this assignment preserves the heap property of the array.
The value \inl{a[p]} now occurs one time more than in the pre-state whereas
the now overwritten value \inl{a[c]} occurs as often as in the pre-state.
The value \inl{v} continues to occur one time less.
%
We then proceed to the next iteration by setting \inl{c} to \inl{p}.

The verification of tracking the number of occurences happens
in smaller steps than just described.
It relies on the predicates \logicref{ArrayUpdate} and \logicref{MultisetUpdate}
which we can apply in this guarded assignment.
Lemma \logicref{MultisetParityCombined} also plays an important role here.

\item
Otherwise, since \inl{c} is a child of \inl{p},  we can conclude that
\inl{a[c]} equals \inl{a[p]} and we continue with the next iteration
after setting \inl{c} to \inl{p}.
\end{itemize}

This means that at the begin of the next iteration again
the following conditions hold.
Compared to the pre-state of \pushheap the array \inl{a[0..n-1]}

\begin{itemize}
\item contains the value \inl{v} one time less
\item contains the value \inl{a[c]} one time more
\item whereas all other values have not changed their number of occurences.
\end{itemize}

Figure~\ref{fig:pushheap-main-act} shows the our example heap after the main act.
For this particular heap, only one iteration is performed until a node is reached
whose parent value \inl{a[p]} is greater or equal than \inl{v}.
Note that assignments which have previously occurred are marked with dashed arrows.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.70\linewidth]{Figures/push_heap_main_act.pdf}
\caption{\Label{fig:pushheap-main-act}Heap after the main act of \pushheap}
\end{figure}

\FloatBarrier
\clearpage

\subsubsection{Epilogue}
\Label{sec:push-heap-epilogue}

At this point, we have arrived at an index \inl{c} where
the assignment of the value \inl{v} preserves the heap property.
We express this formally using the predicate \logicref{HeapCompatible}.

Moreover, this assignment also corrects the imbalance in the number of
occurences of the values \inl{a[c]} and \inl{v} and consequently
establishes the desired property \inl{reorder} of \pushheap.
The verification that this correction leads to a proper reordering relies
on lemma \logicref{MultisetParityMultisetReorder}.

Figure~\ref{fig:pushheap-epilogue} shows the final assignment and highlights the
completion of the cycle depicted in Figure~\ref{fig:pushheap-prologue}.
The figure also makes clear that the value \inl{v} acts like an additional
element in this assignment cycle.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.70\linewidth]{Figures/push_heap_epilogue.pdf}
\caption{\Label{fig:pushheap-epilogue}Heap after the epilogue of \pushheap}
\end{figure}

\clearpage


% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí
\setcounter{chapter}{7}
\chapter{Aperture and Depth of Field}
%
In this experiment you will learn about the effect of aperture on depth of field.
%
\section{Preliminary}
%
Given an object in position $x_{\text{O}}$ and a convex lens in position $x_{\text{L}}$ with focal length $f$, a perfectly sharp image will form in position $x_{\text{I}}$. As was found in the previous experiment, the three positions and the focal length are related via:
\begin{equation}
    \frac{1}{d_{\text{O}}} + \frac{1}{d_{\text{I}}} = \frac{1}{\vert x_{\text{O}} - x_{\text{L}} \vert} + \frac{1}{\vert x_{\text{I}} - x_{\text{L}} \vert} = \frac{1}{f}
\end{equation}
Indeed, there is some wiggle room around the position of the perfectly sharp image where the image is still relatively in focus. The \textbf{depth of field} is defined as the range of positions where a real image from a convex lens is reasonably focused, according to some specific criterion. In this experiment you will use the following criterion: can two distinct lines in an image be distinguished?
%
\subsection{Near Limit}
%
The \textbf{near limit} $D_{\text{N}}$ is the distance between the object and the lens when the lens is as \textbf{near} to the object as possible and features in the image are close to being blurred.
%
\subsection{Far Limit}
%
The \textbf{far limit} $D_{\text{F}}$ is the distance between the object and the lens when the lens is as \textbf{far} from the object as possible and features in the image are close to being blurred.
%
\subsection{Depth of Field}
%
The near and far limits tell you how close or how far away the object can be while still being relatively in focus. The size of this region in space is known as the \textbf{depth of field}. Given the values of the near limit $D_{\text{N}}$ and the far limit $D_\text{{F}}$, you can find the depth of field via:
\begin{equation}
    \text{depth of field} = D_{\text{F}} - D_{\text{N}}
    \label{eq.09.dof}
\end{equation}
It turns out that the value of the near limit, the far limit, and the depth of field can all be changed by using different apertures. An \textbf{aperture} is a space opening between the lens and the image. For example, the pupil of the eye serves as the aperture for the eye. As the pupil changes size, the eye's depth of field changes: near objects can come to sharp focus or vice versa.
%
\subsection{f-Numbers}
%
The f-number $N_{\text{f}}$ is a value used to describe an aperture of a lens:
\begin{equation}
    N_{\text{f}} = \frac{f}{d}
\end{equation}
Here $f$ is the focal length of the lens, and $d$ is the diameter of the aperture.

In photography, it is common to find combinations of lens ($f$) and aperture ($d$) that produce certain values of f-number. More information about f-numbers can be found in Wikipedia:
\begin{center}
    \url{https://en.wikipedia.org/wiki/F-number}
\end{center}
In this experiment you will have five different apertures available. Each aperture is labeled with a number from 1 to 5, and has a different diameter. Hence, each aperture will have a different f-number. You can check that the following ratios are fixed:
\begin{equation}
    \frac{N_{4}}{N_{5}} = \frac{N_{3}}{N_{4}} = \frac{N_{2}}{N_{3}} = \frac{N_{1}}{N_{2}} = \sqrt{2} \approx 1.4142\ldots
\end{equation}
Here $N_{5}$ is the f-number for the aperture labeled with 5, and so on.
%
\section{Experiment}
%
You used the 20 cm double convex lens and five different apertures. For each aperture you measured the diameter. You also found the near and far limits for each aperture.
%
\section{Analysis}
%
Instead of measuring the near and far limits directly, you measured the positions of the object and lens. The near and far limits can be found in the same way that the object distance is calculated:
\begin{equation}
    \vert x_{\text{O}} - x_{\text{L}} \vert
\end{equation}
Once the near and far limits are obtained, you can find the depth of field using Equation (\ref{eq.09.dof}).
%
% \newpage
% \section{Your Report}
% %
% Your report should include the following:
% \begin{itemize}
%     \item A table like Table \ref{table.09.fnumbers} with the diameter measurements and the values of the f-Number determined.
%     \item A table like Table \ref{table.09.ratios} with the ratios of consecutive f-numbers. Include the percent difference found by comparing each ratio with the expected value $\sqrt{2} \approx 1.4142$.
%     \item A table like Table \ref{table.09.results} with the rest of the results: include the near and far limits, and also the depth of field for each aperture.
%     \item A scatter chart with depth of field in the vertical axis, and aperture diameter in the horizontal axis. Make sure you label each axis.
% \end{itemize}
% You should answer the following questions:
% \begin{enumerate}
%     \item Which aperture has the largest near limit?
%     \item Which aperture has the largest far limit?
%     \item Which aperture has the largest depth of field?
%     \item Looking at your chart of depth of field versus diameter, what happens to the values of depth of field as you make the diameter smaller?
% \end{enumerate}
%
\newpage
\section{Tables}
%
\begin{table}[ht]
    \begin{center}
        \begin{tabular}{l|r|r}
            \textbf{Aperture Label} & \textbf{Diameter} (cm) & \textbf{f-Number} \\
            \hline
            5 & & \\
            4 & & \\
            3 & & \\
            2 & & \\
            1 & & \\
            \hline
        \end{tabular}
    \end{center}
    \caption{f-Numbers for apertures with 20 cm double convex lens}
    \label{table.09.fnumbers}
\end{table}
%
\begin{table}[ht]
    \begin{center}
        \begin{tabular}{l|r|r|r}
            \textbf{Ratio} & \textbf{Observed Value} & \textbf{Expected Value} & \textbf{P.D.} (\%) \\
            \hline
            $N_{4} / N_{5}$ & & 1.4142 & \\
            $N_{3} / N_{4}$ & & 1.4142 & \\
            $N_{2} / N_{3}$ & & 1.4142 & \\
            $N_{1} / N_{2}$ & & 1.4142 & \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Ratios of consecutive f-numbers}
    \label{table.09.ratios}
\end{table}
%
\begin{table}[ht]
    \begin{center}
        \begin{tabular}{l|r|r|r}
            \textbf{Aperture Label} & $D_{\text{N}}$ (cm) & $D_{\text{F}}$ (cm) & $D_{\text{F}} - D_{\text{N}}$ (cm) \\
            \hline
            5 & & & \\
            4 & & & \\
            3 & & & \\
            2 & & & \\
            1 & & & \\
            \hline
        \end{tabular}
    \end{center}
    \caption{Results}
    \label{table.09.results}
\end{table}
%