\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[mathcal]{euscript}

\usepackage{url}

\newcommand{\Fcal}{\mathcal{F}}
\newcommand{\Lcal}{\mathcal{L}}
\newcommand{\Tcal}{\mathcal{T}}
\newcommand{\Bcal}{\mathcal{B}}

\newcommand{\real}{\mathbb{R}}
\newcommand{\cplx}{\mathbb{C}}

\title{Condensed notes for \url{probability.net}}
\author{Nazarov Ivan}

\date{\today}

\begin{document}

\maketitle

\paragraph{tut 11} % (fold)
\label{par:tut_11}

Complex measures form a normed $\cplx$-vector space $M_1(\Omega, \Fcal)$ and their
total variation is always a finite measure;
%
$L^1_\cplx(\mu) \equiv L^1_\cplx(|\mu|)$;
%
the norm is $\|\mu\| = |\mu|(\Omega)$;
%
real valued bounded linear functionals on complex measures give signed measures;
%
their real~/~imaginary total variation can be used to decompose the complex measure
into a $\cplx$-linear combination;
%
reverse triangle inequality: there is $S \subseteq \{1,\, \ldots,\,N\}$ such that
$\sum_{i=1}^N |z_i| \leq \pi |\sum_{i \in S} z_i|$.

% paragraph tut_11 (end)

\paragraph{tut 12} % (fold)
\label{par:tut_12}

Absolute continuity of measures has a $\varepsilon - \delta$ continuity set-theoretic
equivalent;
%
if for a finite measure $\mu$ and $f \in L^1_\cplx(\Omega, \Fcal, \mu)$, we have
$\tfrac1{d\mu(E)} \int_E f d\mu \in S$ for $S$ closed in $\cplx$, then $f \in S$
$\mu$-as;
%
Radon-Nikodym derivative $h$ of a complex~/~signed~/~finite measure $\nu$ on
$(\Omega, \Fcal)$ wrt. $\sigma$-finite measure $\mu$ is an element of $L^1_\cplx(\mu)$
and respects the co-domain of $\nu$;
%
the same holds for a pair of $\sigma$-finite measures, but $h\colon \Omega \to [0, +\infty]$;
%
derivative of a complex measure wrt. its total variation exists and its modulus~/~absolute
value is $1$ almost surely;
%
set convergence holds for complex measures (via DCT);
%
for any measure $\mu$ if $d\nu = f d\mu$ for some complex $\mu$-integrable $f$, then
$\nu$ is a complex measure, $d|\nu| = |f| d\mu$ and for any bounded measurable $g$ or
$g \in L^1_\cplx(\nu)$ we have $\int g d\nu = \int g f d\mu$;
%
Complex Lebesgue integral is defined as $\int f d\mu = \int f h d|\mu|$,
$d\mu = h d|\mu|$;
%
Complex Lebesgue is bilinear wrt. function and measure arguments;
%
ordinary Lebesgue is also monotone wrt. measures and linear wrt. nonnegative finite
linear combinations of measures;
%
Complex integral can be decomposed into a linear combination of ordinary Lebesgue
integrals wrt. finite measures based on total-variation (unique for any given complex
measure);
%
Basically all commons sense operations and manipulations with complex integrands
and complex measures are legal.

% paragraph tut_12 (end)

\paragraph{tut 13} % (fold)
\label{par:tut_13}

Simple $\cplx$-valued functions that are also in $L^p_\cplx(\Omega, \Fcal, \mu)$ are
dense in $L^p_\cplx(\mu)$;
%
for any finite measure $\mu$ on metrizable space $(\Omega, \Tcal)$
(metrizability -- to get open neighborhoods of closed sets) for any measurable
$E \in \Bcal(\Omega)$ and $\varepsilon > 0$ there are $F$ -- closed and $U$ -- open,
$F \subseteq E \subseteq U$ with $\mu(U \setminus F) \leq \varepsilon$;
%
bounded continuous functions $C_\cplx^b(\Omega, \Tcal)$ on metrizable spaces
(or T4 for Urhyson lemma) approximate measurable indicator functions;
%
bounded continuous functions on metrizable spaces (T4 not enough due to measure!)
are dense in $L^p_\cplx(\Omega, \Bcal(\Omega), \mu)$ for $\mu$ finite measure and
$p < +\infty$;
%
Portmanteau lemma: complex measures on metrizable space coincide if their integrals
are equal for all continuous bounded real-valued functions;
%
locally finite borel measure: every point has an open neighborhood with finite measure;
%
compact sets have finite measure for any locally finite measure;
%
metrizable compact ($\sigma$-compact) topological space is separable;
%
in a metrizable topological space separability is equivalent to a countable base;
%
in a topological space with a locally finite borel measure a subset of a base with finite
measure is still a topological base;
%
on a metrizable $\sigma$-compact topological space any locally finite measure is
inner and outer regular;
%
strongly $\sigma$-compact topological space is the same as $\sigma$-compact and
locally compact;
%
in a metrizable locally compact space for any $K$ -- compact, $U$ -- open, $K \subseteq U$,
there is a continuous function $\phi$ with compact support ($[\{\phi \neq 0\}]$
-- compact in $\Omega$) such that $1_K \leq \phi \leq 1_U$;
%
on a metrizable strongly $\sigma$-compact topological space continuous functions
with compact support are dense in $L^p_\cplx(\Omega, \Bcal(\Omega), \mu)$.

Locally compact -- every open neighborhood has a compact closure;
%
$\sigma$-compact -- there exists an increasing family of compact sets that covers $\Omega$;
%
strongly $\sigma$-compact -- there is an increasing sequence of open sets with compact
closure that covers $\Omega$;

for $
  H\vert_X
    = \{A\cap X\colon A \in H\}
$ we have $
  T_X
    = T(H) \vert_X
    = T(H \vert_X)
$;
%
$H$ is a topological base on $\Omega$ if $H$ cover $\Omega$ and $x \in U \cap V$ implies $
  \exists W \in H
  \,\colon\, x \in W \subseteq U \cap V
$;
%
$
\mathcal{T}(H)
  = \{
    \cup_{V \in \Gamma} V
    \colon \Gamma \subseteq H
  \}
  = \{
    U \subseteq \Omega
    \colon \forall x\in U\, \exists W\in H
    \colon x \in W \subseteq U
  \}
$.

% paragraph tut_13 (end)

\paragraph{tut 14} % (fold)
\label{par:tut_14}

Total variation (tv) of a $b\colon \real^+ \to \cplx$ map is non-decreasing, preserves
right~/~left continuity if any, and
$|b|(t) - |b|(s) = \sup_{t_i \in [s, t]} \sum_i |b(t_i) - b(t_{i-1})|$;
%
tv of a nonnegative non-decreasing map is the map itself;
%
tv of a map is sub-additive and preserves order;
%
nondecreasing nonnegative $\real$-valued maps (of finite variation) make Stieltjes
measures, complex maps of bounded variation --- complex Stieltjes measures,
$db((s,t]) = b(t) - b(s)$, $db(\{0\}) = b(0)$;
%
tv of a complex Stieltjes measure is the Stieltjes measure of the tv, i.e. $|db| = d|b|$;
%
total variations can be used to linearly decompose maps of finite variation;
%
for measures on $\real^+$ to be ordered it is sufficient for them to be ordered on
half-intervals and at zero;
%
tv of a right~/~left continuous map can be computed on partitions
$t_k = \tfrac{k t}{2^n}$, $k=0,\, \ldots,\,2^n$;
%
cadlag complex maps are bounded on bounded sets: for some $M\geq 0$
$|b(t-) \vee b(t)| \leq M$ for all $t \in [0, T]$.

% paragraph tut_14 (end)

\paragraph{tut 15} % (fold)
\label{par:tut_15}

Stieltjes (local) $L^1$-space $L^1_\cplx(b)$ ($L^{1,loc}_\cplx(b)$) for right continuous
({\bf rc}) $b\colon \real^+ \to \cplx$ of finite variation is
$L_\cplx^1(\real^+, \Bcal(\real^+), d|b|)$ ($L_\cplx^1(d|b|^{[0,t]})$);
%
for an {\bf rc} nonnegative nondecreasing $a$ and $f \in L^1_\cplx(a)$ (or $f \geq 0$ in
$L^{1,loc}_\real(a)$) we have $f.a(t) = \int_0^t f da$ {\bf rc} map of bounded (finite)
variation and $d(f.a) = f da$;
%
for {\bf rc} nonnegative nondecreasing $a$ and $f \in L^1_\cplx(a)$ we have
$|f.a| = |f|.a$ with $\Delta f.a = f\Delta a$, $\Delta a = a(t) - a(t-)$;
%
for $a\colon \real^+ \to \real^+$ {\bf rc} nonnegative nondecreasing and
$b\colon \real^+ \to \cplx$ {\bf rc} of finite variation there is $f \in L^1_\cplx(a)$
$da$-as unique such that $b = f.a$ and $f$ preserves the co-domain of $b$;
%
for $b\colon \real^+ \to \cplx$ {\bf rc} of finite variation there exists
$h \in L^{1,loc}_\cplx(b)$ with $|h|=1$ and $b = h.|b|$ and for $f \in L^1_\cplx(b)$
the Stieltjes integral of $f$ is $f.b = (f h).|b|$, $|f.b| = |f|.|b|$ and
$\Delta f.b = f \Delta b$;
%
for $g \in L^{1,loc}_\cplx(b)$ we have $f.(g.b) = (fg).b$ for any
$f \in L^{1,loc}_\cplx(g.b) \Leftrightarrow fg \in L^{1,loc}_\cplx(b)$ or bounded;
%
$f.b$ is bilinear for $f \in L^{1,loc}_\cplx(b)$ and $b\colon \real^+ \to \cplx$
is {\bf rc} of finite variation;
%
$f.b = f.|b_1|^+ - f.|b_1|^- + i(f.|b_2|^+ - f.|b_2|^-)$ for $b_1 = \Re(b)$, $b_2 = \Im(b)$;
%
for $a\colon \real^+ \to \real^+$ {\bf rc} nonnegative and non decreasing the inverse
$c_a(t) = \inf\{s \geq 0 \mid t < a(s) \}$ is nonnegative, nondecreasing and right
continuous, sort of generalized inverse, and $f.a(t) = ((f \circ c_a).s)(a(t))$ for
$f \in L^{1,loc}_\cplx(a)$ and also $a = c_{c_a}$;
%
nondecreasing maps are always measurable.

% paragraph tut_15 (end)

\paragraph{tut 16} % (fold)
\label{par:tut_16}

Recall:
$\limsup_{x\to x_0} = \inf_{U\ni x_0} \sup_{x\in U}$,
$A_n~\text{i.o.} = \cap_{n\geq 0} \cup_{k\geq n} A_k$,
$A_n~\text{ev.} = \cup_{n\geq 0} \cap_{k\geq n} A_k$;
%
lsc functions ($\{\lambda < f\}$ -- open in $\Omega$) are closed under addition,
scaling by nonnegative values, and arbitrary suprema;
%
lsc = - usc;
%
$1_U$, $U$ open, is lsc;
%
$1_F$, $F$ -- closed, is usc;
%
all usc~/~lsc maps are measurable wrt. Borel $\sigma$-algebra;
%
on a metrizable $\sigma$-compact space with a locally finite measure $\mu$ for any
$f \in L^1_\real(\Omega, \Fcal, \mu)$ and any $\varepsilon > 0$ there are lsc $v$ and
usc $u$ ($\mu$-as having counterparts in $L^1_\real(\mu)$) such that $u \leq f \leq v$
and $\int (v - u) d\mu \leq \varepsilon$ (Viteli-Caratheodory);
%
a connected topological space has $\emptyset$ and $\Omega$ as the {\bf only} closed
and open;
%
a space is connected iff whenever $\Omega = A \uplus B$ then either $A$ or $B$ is
$\emptyset$;
%
an interval is a subset $G$ of $\real$ such that for all $a \leq b \in G$ we have
$[a, b] \subseteq G$;
%
$G$ is an intervals iff $G$ is either $(a, b]$, $(a, b)$, $[a, b)$, or $[a, b]$;
%
a subset of $\real$ is an interval iff it is connected;
%
images of connected subsets via a continuous map are connected;
%
if $\Omega$ is connected and $f$ continuous, then $[a, b] \subseteq f(\Omega)$ implies
that for any $c \in [a, b]$ there is $z \in \Omega$ with $c = f(z)$;
%
if $a < b$, and $f$ is differentiable everywhere at $[a, b]$ with
$\int_a^b | f'(x)| dx < + \infty$, then $f(b) - f(a) = \int_a^b f'(s) ds$;
%
on $(\real^n, \Bcal(\real^n))$ for any $\alpha > 0$ we have
$dx({k_\alpha \in B})
  = \alpha^{-n} dx(B)
  = \lvert J_{k_\alpha} \rvert^{-1} dx(B)$;
%
for complex measure $\mu$ on $(\real^n, \Bcal(\real^n))$ the maximal function
$M\mu(x) = \sup_{\varepsilon>0}
  \tfrac{|\mu|(B(x,\varepsilon))}
        {dx(B(x,\varepsilon))}$
is nonnegative and lsc;
%
(constructive) for a collection $(B(x_i,\varepsilon_i))_{i=1}^n$, $\varepsilon_i > 0$
there exists an $S \subseteq \{1,\,\ldots,\,n\}$ such that
$\cup_{i=1}^n B(x_i,\varepsilon_i))_{i=1}^n
  \subseteq \cup_{i\in S} B(x_i, 3\varepsilon_i)$
and $(B(x_i,\varepsilon_i))_{i\in S}$ are pairwise disjoint;
%
for a complex measure $\mu$ and any $\lambda > 0$ we have
$dx(\{\lambda < M\mu\}) \leq \tfrac{3^n}{\lambda} \|\mu\|$;
%
the maximal function of $f \in L^1_\cplx(\real^n, \Bcal(\real^n), dx)$ is
$M f = M \mu$ for $d\mu = f dx$;
%
for any $f \in L^1_\cplx(dx)$ we have
$\bigl\{
  \lim_{\varepsilon \downarrow 0}
    \tfrac{\int_{B(x, \varepsilon)} |f(x) - f(y)| dy}
          {dx(B(x, \varepsilon)))}
  = 0\bigr\}$ $dx$-a.s.

% paragraph tut_16 (end)

\paragraph{tut 17} % (fold)
\label{par:tut_17}

The space of $n\times n$ matrices $M_n(K)$, $K = \real$ or $\cplx$, is the same as
the space $M'_n(K)$ of all finite products of diagonal scaling ($H_\alpha e_1 = \alpha e_1$,
$H_\alpha e_i = e_i$, $\alpha \in K$), row swapping $P_{ij}$ ($P_{ij} e_i = e_j$,
$P_{ij} e_j = e_i$, and $P_{ij} e_l = e_l$) and pivoting ($U e_1 = e_1 + e_2$, $U e_j = e_j$)
matrices;
%
if matrices with $1$ in the top left corner is in $M'_n(K)$, then $M_n(K)\subseteq M'_n(K)$;
%
if matrices with $e_1$ in its first column is in $M'_n(K)$, then all matrices with
$1$ in the top left corner are in $M'_n(K)$;
%
the distribution of $X\colon (\Omega, \Fcal) \to (\Omega', \Fcal')$ under $\mu$ (possibly
complex), or the {\bf image measure} of $\mu$ under $X$, or the {\bf pushforward} of
$\mu$, $X_\sharp\mu$, is $X(\mu)(E) = \mu^X(E) = \mu(\{X \in E\}) = \mu(X^{-1}(E))$,
and we have $Y(X(\mu)) = Y(\mu^X)$;
%
$|\mu^X| \leq |\mu|^X$;
%
a complex measure $\mu$ on $(\real^n, \Bcal(\real^n))$ is translation invariant iff
$\tau_\alpha(\mu) = \mu$ for $\tau_\alpha(x) = \alpha + x$;
%
$\tau_\alpha(dx) = dx$, $k_\alpha(dx) = \alpha^{-n} dx$ for $x\mapsto k_\alpha(x) =
\alpha x$, $a > 0$;
%
for $X\colon (\Omega, \Fcal) \to (\Omega', \Fcal')$ we have $\int_{\Omega} (f \circ X)
d\mu = \int_{\Omega'} f dX(\mu)$ for measure $\mu$ and measurable $f\colon \Omega' \to
[0, +\infty]$ or $f\in L^1_\cplx(\Omega', \Fcal', X(\mu))$ (iff $f\circ X \in
L^1_\cplx(\Omega, \Fcal, \mu)$), or for a complex measure $\mu$ and integrable
$f$ (the STM);
%
the \textbf{s}tandard \textbf{m}achine \textbf{a}rgument: indicator $\to$ simple
(linearity) $\to$ nonnegative (mct$\uparrow$, or dct$\to$+majorant) $\to$ general
integrable, if the measurable sets are involved, then use Dynkin's lemma: if a
$\lambda$-system includes a $\pi$-system, then it includes the $\sigma$-algebra
of the latter;
%
if $\mu$ is a translation-invariant measure $(\real^n, \Bcal(\real^n))$, then there
is a unique $\alpha \geq 0$, such that $\mu = \alpha dx$ (due to translation invariance
the scaling in front of $\mu$ becomes the Lebesgue measure);
%
$T\colon \real^n \to \real^n$ is a linear bijection iff it has a non-singular matrix
representation in, e.g., canonical bases in domain and image spaces;
%
the linearity of $T$ makes the image measure $\mu = T(dx)$ translation invariant in
$\real^n$ with $\mu = \Delta(T) dx$;
%
the matrix of $T$ being composed of invertible simple matrices makes $\Delta(T) \neq
0$ and $\Delta(T_1 \circ T_2) = \Delta(T_1) \Delta(T_2)$;
%
ultimately $\Delta(T) = \lvert \det T^{-1} \rvert = \lvert \det T \rvert^{-1}$ due
to the determinant of a product being equal to the product of determinants;
%
$dx(T(B)) = \lvert \det T\rvert dx(B)$;
%
any linear subspace $V$ of $\real^n$ is closed and $dx(V) = 0$ when $\dim V \leq n-1$;

% paragraph tut_17 (end)

\paragraph{tut 18} % (fold)
\label{par:tut_18}

The norm topology of the $K$-normed vector space is the metric topology induced by
the norm metric;
%
if $E$ and $F$ are $K$-normed spaces and $l\colon E \to F$ is a linear map, then
$l$ is continuous iff $l$ is continuous at $0$, iff there is $M\geq 0$ such that
$\|l(x)\| \leq M \|x\|$ for all $x\in E$, iff
$\|l\| = \sup\{\|l(x)\|\colon x\in E,\, \|x\|=1\} < +\infty$;
%
the norm $\|l\|$ of a linear map $l$ is $\sup\{\|l(x)\|\colon x\in E,\, \|x\| \leq 1\}$,
$\sup\{\tfrac{\|l(x)\|}{\|x\|} \colon x\in E,\, x\neq 0\}$, and
$\inf\{M\geq 0\colon \|l(x)\| \leq M \|x\|\,\,\forall{x\in E} \}$;
%
for all $x\in E$ we have $\|l(x)\| \leq \|l\| \|x\|$, and $(\Lcal_K(E, F), \|\cdot\|)$
is a $K$-normed space.

For $E, F$ be $\real$-normed spaces and an open $U\subseteq E$, the map $\phi\colon E\to F$
is differentiable at $a\in U$ iff there is $d\phi(a) \in \Lcal_\real(E, F)$ so that for any
$\varepsilon > 0$ there is $\delta > 0$ such that for all $h\in E$ with $\|h\| \leq \delta$
and $a + h \in U$ we have $\|\phi(a+h) - \phi(a) - l(h) \| \leq \varepsilon \|h\|$;
%
the linear map $d\phi(a)$ is unique, and the map $\phi$ is differentiable on $U$ if
it is differentiable at every $a\in U$;
%
$\phi\colon U \to F$ is $C^1$ if it is differentiable on $U$ and
$d\phi\colon U \to (\Lcal_\real(E, F), \|\cdot\|)$ is continuous;
%
for $\real$-normed spaces $E, F, G$ with $U$ -- open in $E$, $V$ -- open in $F$, if
maps $\phi\colon U\to F$ and $\psi\colon V\to G$ are differentiable at $a\in U$ and
$\phi(a)\in V$ with $\phi(U) \subseteq V$, then the map $\psi\circ \phi$ is differentiable
at $a$ and $d(\psi\circ\phi)(a) = d\psi(\phi(a)) \circ d\phi(a)$;
%
norms on finite product spaces are topologically equivalent;
%
if norms $\|\cdot\|$ and $N_E(\cdot)$ induce the same topology, then the
$id_E\colon (E, \|\cdot\|) \to (E, N_E(\cdot))$ is continuous, and the norms are equivalent:
there exist $m_E, M_E > 0$ such that $m_E\|\cdot\| \leq N_E(\cdot) \leq M_E \|\cdot\|$;
%
if maps are differentiable at $a$ so are their linear combinations;
%
the differential does not depend on the choice of norms in finite dimensional spaces;
%
if $\phi\colon U\to F$ and $\psi\colon V\to G$ are $C^1$, then so their composition is
$C^1$ as well;
%
if $E$ is an $\real$-normed space, $f\colon [a, b] \to E$ and $g\colon [a, b] \to \real$
are differentiable at every $(a, b)$ with $\|f'(t)\| \leq g'(t)$, then
$\|f(b) - f(a)\| \leq g(b) - g(b)$;
%
$\Rightarrow$ if $\phi\subseteq \real^n \to E$, $\real$-normed, is differentiable at
$a\in U$ then all $\tfrac{\partial \phi}{\partial x_i}(a)$ exist at $a$, furthermore
$d\phi(a)(h) = \sum_i \tfrac{\partial \phi}{\partial x_i}(a) h_i$;
%
if $d\phi$ exists on $U$ and is continuous at $a$, then
$\tfrac{\partial \phi}{\partial x_i}(\cdot)$ are continuous at $a$;
%
$\Leftarrow$ if $\phi$ has all $\tfrac{\partial \phi}{\partial x_i}(\cdot)$ on $U$ and
they are continuous at $a\in U$, then $\phi$ is differentiable at $a$ (only existence!);
%
if $\tfrac{\partial \phi}{\partial x_i}(\cdot)$ are continuous on $U$ then so is $d\phi$
on $U$;
%
finally $\phi\colon U\to E$ is $C^1$ on $U$ iff each
$a\to \tfrac{\partial \phi}{\partial x_i}(a)$ is $U$-$E$ continuous;
%
$l\in \Lcal(E, F)$ is $C^1$ and $d(l\big\vert_U)(a) = l$ for any $a\in U$ -- open in $E$;
%
$\phi\colon U \to F = \prod_{i=1}^p F_p$ is differentiable at $a$ iff each
$\phi_i\colon U\to F_i$ is, $\phi$ is $C^1$ on $U$ iff each $\phi_i$ is $C_1$ on $U$,
and $d\phi(a) = (d\phi_i(a))_{i=1}^n \in \Lcal(E, F)$;
%
if $\phi\colon U \to \real^n$ then
$d\phi(a) = (\tfrac{\phi_c}{\partial x_r})_{r,c}^{n,n} \in \real^{n\times n}$;
%
the Jacobian of $\phi$ is $J(\phi)(a) = \det d\phi(a)$ --- the determinant of the
partial derivative matrix.

For $\Omega$ and $\Omega'$ open in $\real^n$ a bijection $\phi\colon \Omega \to \Omega'$
is a $C^1$-diffeomorphism between $\Omega$ and $\Omega'$ iff $\phi\colon \Omega \to \real^n$
and $\phi^{-1}\colon \Omega' \to \real^n$ are both $C^1$;
%
if $\phi$ is a $C^1$-diffeomorphism ($\psi = \phi^{-1}$) then
$d\phi(\psi(x)) \circ d\psi(x) = id_{\real^n}$ and
$d\psi(\phi(x)) \circ d\phi(x) = id_{\real^n}$ and
$J(\phi) = \tfrac1{J(\psi) \circ \phi} \neq 0$;
%
if $d\phi(a) = id_{\real^n}$, then for all $x\in \Omega'$
$\lim_{\varepsilon\downarrow 0}
  \tfrac{\phi(dx\big\vert_{\Omega})(B(x, \varepsilon))}
        {dx\big\vert_{\Omega'}(B(x, \varepsilon))} = 1$;
%
the matrix $A = d\phi(x)$ is non-singular, and $\tilde{\phi} = \phi \circ A$ is $C^1$
diffeomorphism between $\Omega'' = A^{-1}(\Omega)$ and $\Omega'$ with
$\tilde{\psi} = A^{-1} \circ \psi$ and
$d\tilde{\phi}(x) = id_{\real^n} \in \Lcal(\real^n, \real^n)$;
%
hence
$\lim_{\varepsilon\downarrow 0}
  \tfrac{\phi(dx\big\vert_{\Omega})(B(x, \varepsilon))}
        {dx\big\vert_{\Omega'}(B(x, \varepsilon))}
  = \lvert \det J(\psi)(x) \rvert$ for all $x\in \Omega'$;
%
finally $\phi(dx\big\vert_{\Omega}) \ll dx\big\vert_{\Omega'}$ for a $C^1$-diffeomorphism
$\phi$ between $\Omega$ and $\Omega'$ and the Radon-Nikodym derivative is
$a \to \lvert \det J(\psi)(a) \rvert$;
%
the Jacobian formula is
$\int_\Omega (f\circ \phi) dx\big\vert_{\Omega}
  = \int_{\Omega'} f \, \phi(dx\big\vert_{\Omega})
  = \int_{\Omega'} f \lvert J(\phi^{-1})\rvert dx\big\vert_{\Omega'}$
and
$\int_{\Omega'} f dx\big\vert_{\Omega'}
  = \int_{\Omega} (f\circ \phi) \, \phi^{-1}(dx\big\vert_{\Omega})
  = \int_{\Omega} (f\circ \phi) \lvert J(\phi)\rvert dx\big\vert_{\Omega}$
-- true for nonnegative $f$, $f\in \Lcal_\cplx^1(\Omega', \Bcal(\Omega'), dx)$
iff $(f \circ \phi) \lvert J(\phi) \rvert \in \Lcal_\cplx^1(\Omega, \Bcal(\Omega), dx)$,
and $f \circ \phi \in \Lcal_\cplx^1(\Omega, \Bcal(\Omega), dx)$
iff $f \lvert J(\phi^{-1}) \rvert \in \Lcal_\cplx^1(\Omega', \Bcal(\Omega'), dx)$;
%
{\bf pushforward}: $\phi_\sharp dx_\Omega = \lvert \det J(\phi^{-1}) \rvert dx_{\Omega'}$;
%
the integral w.r.t. measure $\mu$ of a {\bf pullback} of $f\colon \Omega'\to \real$ by
$\phi\colon \Omega\to\Omega'$ is the integral of $f$ w.r.t the {\bf pushforward}
of $\mu$ by $\phi$: $\int_\Omega f\circ \phi d\mu = \int_{\Omega'} f d\phi_\sharp\mu$.
% paragraph tut_18 (end)

\paragraph{tut 19} % (fold)
\label{par:tut_19}

% paragraph tut_19 (end)

\paragraph{tut 20} % (fold)
\label{par:tut_20}

% paragraph tut_20 (end)
\end{document}


\chapter{Results} \label{sec:results}
\epigraphhead[30]{\epigraph{%
\textit{"Even if rounding error vanished, numerical analysis would remain. Approximating numbers, the task of floating-point arithmetic, is indeed a rather small topic and may even be a tedious one."}}%
{\textsc{Lloyd N. Trefethen (1955)}}%
}

\section{Planar maneuvers} \label{sec:resplanar}

For the planar maneuvers, we will skip the semimajor-axis only case as explained in the previous chapter since we were not able to find a validation example, and only briefly comment the numerical results of the other two maneuvers. More details will be given for the more complicated combined maneuvers.

\subsection{Eccentricity change} \label{sec:resecc}

For the two cases in consideration (the one described in the previous chapter and the one corresponding to a reverse change in eccentricity) we were able to recover the expected results from \cite{pollard1997simplified} with a relative error of $10^{-4}$. This can be regarded as a nice result, given that the actual values were not present in the original paper and had to be computed or interpreted from the plots.

The same relative and absolute errors of $10^{-4}$ are obtained for the expected eccentricity after integrating the equations of motion, either with a positive or a negative change in eccentricity. This validates our intuition of reversing the direction of the thrust depending on the sign of $\Delta e$.

\subsection{Argument of periapsis adjustment}

For the only validation example studied in this case, we were able to match the results in \cite{ruggiero2011low} within a relative tolerance of $10^{-2}$. We observe a moderate accuracy in this case due to the fact that the time of flight given by the original paper is approximate and because of the intermediate computations needed to obtain the orbital parameters of the GTO orbit from the information given in the Soyuz User Manual. On the other hand, we did not find any validation example that did take into account the natural apsidal rotation of the orbit, so we openly question the applicability of this example. In any case, the function as it is implemented now, albeit not validated, accepts a precomputed value of $\dot{\omega}$.

Regarding the integration of the trajectory we obtained better results and managed to approximate the final argument of periapsis with a relative error of $10^{-4}$.

\section{Non planar maneuvers} \label{sec:resnonplanar}

\subsection{Combined semimajor axis and inclination change} \label{sec:resedelbaum}

For all the evaluated cases we were able to recover the original results of \cite{kechichian1997reformulation}, with a varying degree of accuracy. For both the expected time of flight $t_f$ and cost $\Delta V$, a relative error of $10^{-5}$ was achieved for the first case, $10^{-3}$ for the second and $10^{-2}$ for the singular case. With the figures given in the original paper, we are unable to assess if the loss of accuracy is due to problems in our algorithm or simply the fact that not all decimal places are included in the text. For the sake of completeness, our results to machine precision are summarized in table~\ref{tab:aincanares}.

Regarding the numerical validation, after integrating the equations of motion for a time $t = t_f$ for the two non singular cases we recover the expected values for final semimajor axis $a$ and inclination $i$ with a relative error of $10^{-5}$ for the former and an absolute error of $10^{-3}$ for the latter. Notice that the relative error makes no sense if we are comparing to zero. The eccentricity does not experiment significant growth and stays equal to zero with an absolute tolerance of $10^{-2}$.

For completeness, we also include the plots of the time history for the semimajor axis, inclination and velocity for the two non singular cases (figures \ref{fig:aincnumres28} and \ref{fig:aincnumres90}), recording the evolution during the integration of the equations of motion. We notice how the semimajor axis significantly increases for the second case, and how most of the inclination change takes place at that moment.

\begin{figure}%[h]
\begin{subfigure}[b]{0.5\textwidth}
\centering
\resizebox{1.0\textwidth}{!}{
\input{figures/edelbaum/edelbaum_28_a.pgf}
}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}
\centering
\resizebox{1.0\textwidth}{!}{
\input{figures/edelbaum/edelbaum_28_v_inc.pgf}
}
\end{subfigure}
\caption{Evolution of the combined $a$ and $i$ transfer orbit for the case $i_0 = 28.5~\text{deg}$}
\label{fig:aincnumres28}
\end{figure}

\begin{figure}%[h]
\begin{subfigure}[b]{0.5\textwidth}
\centering
\resizebox{1.0\textwidth}{!}{
\input{figures/edelbaum/edelbaum_90_a.pgf}
}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}
\centering
\resizebox{1.0\textwidth}{!}{
\input{figures/edelbaum/edelbaum_90_v_inc.pgf}
}
\end{subfigure}
\caption{Evolution of the combined $a$ and $i$ transfer orbit for the case $i_0 = 90~\text{deg}$}
\label{fig:aincnumres90}
\end{figure}

To observe the differences between the numerical and the analytical solution, in figure~\ref{fig:aincdiffinc90} we have plotted the difference between the analytical evolution of the inclination and the numerical solution. While this difference is small compared to the absolute value of the inclination, we notice and oscillatory behavior that is due to the differences within each revolution. In fact, we notice that the frequency of the oscillations decreases as the orbit gets larger, and then rises again.

\begin{figure}%[h]
\centering
\resizebox{1.0\textwidth}{!}{
\input{figures/edelbaum/edelbaum_diff_inc_90.pgf}
}
\caption{Difference between analytical and numerical value for the inclination in the combined $a$ and $i$ transfer orbit for the case $i_0 = 90~\text{deg}$}
\label{fig:aincdiffinc90}
\end{figure}

% Please add the following required packages to your document preamble:
% \usepackage{multirow}
\begin{table}%[b]
\centering
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{} & \multicolumn{3}{l|}{\textbf{Time of flight $t_f$}}   & \multicolumn{3}{l|}{\textbf{Cost $\Delta V$}}      \\ \cline{2-7}
                  & Expected    & Computed        & $\varepsilon$       & Expected  & Computed        & $\varepsilon$       \\ \hline
\textbf{Case 1}   & $191.26295$ & $191.262282913$ & $0.35 \cdot 10^{-5}$ & $5.78378$ & $5.7837714353$  & $0.15 \cdot 10^{-5}$ \\ \hline
\textbf{Case 2}   & $335.0$     & $335.033933749$ & $0.10 \cdot 10^{-3}$ & $10.13$   & $10.1314261566$ & $0.14 \cdot 10^{-3}$ \\ \hline
\textbf{Case 3}   & $351.0$     & $351.211665646$ & $0.60 \cdot 10^{-3}$ & $10.61$   & $10.6206407691$ & $0.10 \cdot 10^{-2}$ \\ \hline
\end{tabular}
\caption{Analytical results of the combined semimajor axis and inclination change.}
\label{tab:aincanares}
\end{table}

\subsection{Combined eccentricity and inclination change}

For each of the data points extracted from the plots in \cite{pollard2000simplified}, we were able to recover the expected values of yaw angle $\beta$ and cost $\Delta V$ with a relative error of $10^{-2}$. This case is even more challenging since the precision of the extracted data is limited by the resolution of the plots, even with the help of an automated software. Again, for improving the accuracy more numerical test cases would be needed.

The results of the integration of the third case ($e_0 = 0.4, i_f = 20.0~\text{deg}$) display similar accuracy: the expected final eccentricity and inclination are recovered with a relative error of $10^{-2}$ and $10^{-1}$ respectively. These tolerances are the worst for all the guidance laws in study, although still acceptable. The reverse change in eccentricity has been studied as well to test the algorithm against an initial circular orbit, yielding the same results.

We reproduce here the charts that can be found in \cite{pollard2000simplified} using our own formulas, where it can be seen that the general trend of the plots is respected (figure~\ref{fig:eccincnumcharts}).

\begin{figure}%[h]
\begin{subfigure}[b]{0.5\textwidth}
\centering
\resizebox{1.0\textwidth}{!}{
\input{figures/combined_ei/chart_beta.pgf}
}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}
\centering
\resizebox{1.0\textwidth}{!}{
\input{figures/combined_ei/chart_dV.pgf}
}
\end{subfigure}
\caption{Charts of yaw angle and velocity requirements in terms of inclination and eccentricity as found in  \cite{pollard2000simplified}.}
\label{fig:eccincnumcharts}
\end{figure}

On the other hand, we also represent the evolution of the eccentricity during the integration of the equations of motion versus the theoretical trend, given by:

\[
e = \sin{\left( \pm \frac{3}{2} f \cos{|\beta|} \sqrt{\frac{a}{\mu}} t + \arcsin{e_0} \right)}
\]

\begin{figure}[b]
\centering
\resizebox{0.8\textwidth}{!}{
\input{figures/combined_ei/eccentricity.pgf}
}
\caption{Evolution of the eccentricity in the combined $e$ and $i$ transfer orbit.}
\label{fig:eccincecc}
\end{figure}

The discrepancy in the final part of the transfer corresponds with the numerical tolerance achieved for the integration.


\documentclass[11pt,fancychapters]{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{cite}
\usepackage{color}
\usepackage{xcolor}
\usepackage{empheq}
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{minted}
\usepackage{acro}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{subcaption}
\usepackage{cancel}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tcolorbox}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{parskip}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{pgfplots}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }
\pgfplotsset{width=8cm,compat=1.9}
\newcommand{\dbar}{{d\mkern-7mu\mathchar'26\mkern-2mu}}
\newcommand{\boxedeq}[2]{\begin{empheq}[box={\fboxsep=6pt\fbox}]{align}\label{#1}#2\end{empheq}}
\def\*#1{\mathbf{#1}}
\def\ab{ab}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}
\geometry{top=1.3in,bottom=1.3in}

\begin{document}
\centerline{\huge{2D Project --- 50.004 Introduction to Algorithms}}

\begin{table}[ht]
\centering
\footnotesize
 \begin{tabular}{c c c c c c}
V S Ragul Balaji&James Raphael Tiovalen&Anirudh Shrinivason&Jia Shuyi&Gerald Hoo&Shoham Chakraborty
 \end{tabular}
\end{table}

\section{Part A --- Deterministic Graph-Based Algorithm}
\subsection{Overview of Algorithm}

A solver for a 2-SAT problem can follow many methods. For a 2-SAT problem to be SATISFIABLE in Conjunctive Normal Form (CNF), every clause must be \texttt{true}. Since there are only 2 literals in each clause in a 2-SAT problem, within a single clause, we notice that we can form two implications, thus converting it into an Implicative Normal Form (INF). This sets one of the literals within the clause to be \texttt{false} and for the entire clause to be \texttt{true}, we need the other literal to be \texttt{true}. In other words, we are forbidding the four possible joint assignments of a pair of literals. This defines certain constraints between the variables, which can be propagated throughout the whole implication graph. Each pair of constraints can be considered to be an edge between the variables in an implication graph for the boolean satisfiability problem.\newline

To create the implication graph, we first implement a directed graph using an adjacency list. In the \texttt{Graph} class defined in the \texttt{dfs/kosaraju.py} file, we create the adjacency list by defining the graph's vertices, as well as a function to add edges. Since each variable produces two literals (the variable itself and its negation), we create $2n$ vertices, where $n$ is the number of variables. These vertices are added as the keys of the dictionary $G$ defined in the \texttt{Graph} class. The values for each key would be a list containing consecutive outgoing edges from the vertex defined in the key. This keeps the connection between each individual vertex to the other vertices.

\vspace{4mm}

\begin{figure}[h]\label{fig}
\centering
\includegraphics[width=.9\textwidth]{diagrams/example_cnf_solved.png}
\caption{Guided example of solving 2SAT by hand in polynomial time}
\label{fig:example_problem}
\end{figure}

\vspace{4mm}

In Figure~\ref{fig:example_problem}, we demonstrate this process using an example. This example is also defined in the \texttt{cnf/example.cnf} file. Steps 3 and 4 in Figure~\ref{fig:example_problem} are defined in lines 110-111 in the \texttt{kosaraju.py} file. Using the implication graph, we find the Strongly-Connected Components (SCCs) of the graph and group vertices that are along the same path using Kosaraju's Algorithm. We first create a stack and a depth-first search (DFS) is implemented to traverse through the graph. Adjacent vertices are pushed to the stack. The same procedure is executed on the inverse of the graph, where the direction of all of the edges is reversed. After that, while the stack is not empty, we pop each vertex from the stack. Using this algorithm, we can find all the SCCs of the graph.\newline

Next, we can check for contradiction in each of the SCC. If a variable and its corresponding negation is in the same SCC, the whole 2-SAT formula is deemed to be UNSATISFIABLE, as it is impossible to assign two literals to the same variable. This is because within a single SCC, you can traverse from any vertex to any other vertex. Otherwise, the formula is deemed as SATISFIABLE.\newline

If the formula is SATISFIABLE, we can output a possible solution for the formula. We can do this by grouping the SCCs together and connect them using a directed acyclic graph. Using the graph in Figure~\ref{fig:example_problem} as an example, going in topological order, assign $0$ to the first group of SCC (which is the left SCC in this specific case) and assign $1$ to the second group of SCC (the one highlighted by the red rectangle). We would then get the corresponding output of the variables by equating the literals in any SCC to the assigned value.

\subsection{Time Complexity Analysis}

In general, we know that 2-SAT is in P and is tractable due to the mechanism of forcing the other literal to be \texttt{true} in a single clause by assigning a literal within that same clause as \texttt{true}. When we pick an assignment, 3 cases could happen:

\begin{enumerate}
    \item We reach a contradiction. In this case, it means that there can only be a satisfying assignment if we use the other truth value for that specific variable. Thus, we can simplify the formula using this new assigned value for that variable and repeat the process.
    \item The ``forcing" of the value assignment for a specific variable does not affect other variables and clauses. In this case, adopt these truth values, eliminate the clauses that they satisfy and continue the process.
    \item We find a satisfying assignment.
\end{enumerate}

In Cases 1 and 2, we have spent at most $O(n^2)$ time and have reduced the length of the formula by $\geq 1$. Thus, in total, we have spent at most $O(n^3)$ time.\newline

In fact, our specific implementation method of using a DFS traversal on an implication graph using Kosaraju's Algorithm would take even less time:

\begin{enumerate}
    \item To create the implication graph, we set up the vertices and edges in $O(V + E)$ time, where $V$ is the number of vertices and $E$ is the number of edges in the graph.
    \item We implement DFS to traverse through the implication graph using Kosaraju's Algorithm in $O(V + E)$ time.
    \item We set up the inverse/transpose implication graph in $O(V + E)$ time.
    \item We implement the DFS again through the inverse implication graph in $O(V + E)$ time.
\end{enumerate}

Thus, this reduction of the 2-SAT problem to finding SCCs implemented in our deterministic algorithm would cause the algorithm to take only linear time.\newline

Meanwhile, $k$-SAT problems for $k \geq 3$ would be NP-complete (as shown by the Cook-Levin Theorem) and thus, the time taken would have non-polynomial asymptotics. This is because the size of the CNF formula is exponential in the size of the original boolean formula for $k \geq 3$.\newline

A possible improvement that could be made would be to implement Tarjan's Algorithm to conduct the search for the Strongly-Connected Components. While both Kosaraju's Algorithm and Tarjan's Algorithm would take $O(V+E)$ time, Tarjan's Algorithm has a lower constant factor to the runtime since it would need to go through the whole graph and execute DFS only once (instead of two times for Kosaraju's Algorithm, once for the normal graph and another instance of the DFS traversal for the inverse graph).

\newpage

\section{Part B --- Randomised Algorithm}
\subsection{Overview of Algorithm}
\begin{algorithm}[H]
	\caption*{\textbf{function} RANDOM\_WALK($\mathbb{F}, L$)}
	// $\mathbb{F}: \textit{a list of clauses}$\\
	// $L: \textit{a list of all variables used in } \mathbb{F}$
	\begin{algorithmic}[1]
	\State Store all variables as keys in a dictionary $\mathbb{D}$ with initial values \textbf{false}
	\For {$i \gets 1 \text{ to } 100\times(L.\textit{length})^2$}
	    \State Using $\mathbb{D}$, assign boolean values to $\mathbb{F}$
	    \State $\mathbb{C}\gets $ all invalid clauses in $\mathbb{F}$
	    \If {$\mathbb{C}.length \ne 0$}
	        \State $V\gets$ a random variable from a random clause in $\mathbb{C}$
	        \State $V\gets \neg V$
	        \State Update $\mathbb{D}$ with $V$
	   \Else
	        \State \textbf{return} SATISFIABLE
	   \EndIf
	\EndFor
	\State \textbf{return} UNSATISFIABLE
	\end{algorithmic}
\end{algorithm}

First, we arbitrarily assign Boolean value \texttt{false} to all $n$ variables. In each of the $100n^2$ steps, we randomly choose a variable from a randomly selected invalid clause (that is, the clause evaluates to \texttt{false}) and negate its assignment. We then check if the resultant formula is satisfied or not. If no solution is found after $100n^2$ steps, we return UNSATISFIABLE. If at any point during the $100n^2$ steps the formula is satisfied, we return SATISFIABLE.
\subsection{Time Complexity Analysis}
Let $X_i$ be the number of correct assignments at step $i$. Assuming worst-case initialization, all variables are assigned incorrectly, we have $X_0 = 0$. This forces $X_1 = 1$, since flipping any variable would give us a correct assignment.\newline

For $1\le i \le n-1$, the probability for $X_i$ transiting to $X_{i+1}$ is at least $\frac{1}{2}$ while that to $X_{i-1}$ is at most $\frac{1}{2}$. This can be easily seen from the table below:

\begin{table}[H]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{2}{|l|}{Wrong Clause $A+B$}            & $A$           & $B$          \\ \hline
\multicolumn{2}{|l|}{Actual Value}                  & T           & T          \\ \hline
\multicolumn{2}{|l|}{Both Wrong Assignment}         & F           & F          \\ \hline
\multicolumn{2}{|l|}{One Wrong Assignment}          & F           & T          \\ \hline
\multirow{2}{*}{$P(X_i \text{ to } X_{i+1})$} & Both Wrong & \multicolumn{2}{l|}{1}   \\ \cline{2-4}
                                       & One Wrong  & \multicolumn{2}{l|}{0.5} \\ \hline
\multirow{2}{*}{$P(X_i \text{ to } X_{i-1})$} & Both Wrong & \multicolumn{2}{l|}{0}   \\ \cline{2-4}
                                       & One Wrong  & \multicolumn{2}{l|}{0.5} \\ \hline
\end{tabular}
\end{table}
Let us suppose the worst case – that the probability $X_i$ goes up is $\frac{1}{2}$, and down is $\frac{1}{2}$. This process is similar to a random walk.\newline

Let $h_i$ be the expected number of steps to reach $n$ on our random walk when we start at step $i$. We have
\begin{equation}\label{eqn2.1}
    h_i = \frac{h_{i-1}}{2} + \frac{h_{i+1}}{2} + 1 \quad \Rightarrow \quad h_i - h_{i+1} = h_{i-1} -h_i + 2.
\end{equation}
Using the base case $h_0 = h_1 + 1$, the next 2 steps are
\begin{align}
    h_1 - h_2 &= h_0 - h_1 + 2 = h_1 + 1 - h_1 + 2 = 3,\label{h1h2} \\
    h_2 - h_3 &= h_1 - h_2 + 2 = 3 +2 = 5,\label{h2h3}
\end{align}
where Eqn.~(\ref{h1h2}) is substituted into Eqn.~(\ref{h2h3}). By careful observation, we formulate the following expression:
\begin{equation}\label{mi}
    h_i - h_{i+1} = 2i+1.
\end{equation}
As shown above, this expression holds for $i=1$. Assume the expression is \texttt{true} for $h_k - h_{k+1} = 2k+1$ for some positive integer $k$, we want to prove that the expression holds for $i = k + 1$.
\begin{align*}
    h_{k+1} - h_{k+2} &= h_k - h_{k+1} + 2 \qquad \text{By Eqn.~(\ref{eqn2.1})}\\
    &= 2k+1+2\\
    &= 2(k+1) + 1.
\end{align*}
Thus, by mathematical induction, Eqn.~(\ref{mi}) is true for all $k \in \mathbb{Z}^+$. Using Eqn.~(\ref{mi}), we sum all the steps from $i = 0$ to $i = n$:
\begin{align*}
    h_0 &= h_n + \sum^{n-1}_{i=0}\left(h_i - h_{i+1}\right)\\
    &= \sum^{n-1}_{i=0}(2i+1)\\
    &= n+2\left(\frac{n^2-n}{2}\right)\\
    &= n^2,
\end{align*}
where $h_n = 0$.\newline

Therefore, the average time complexity of the randomised algorithm is $O(n^2)$. In other words, we will find a solution in $n^2$ steps \textbf{on average}. If we decide to run the algorithm for $2n^2$ steps, the probability of not finding a solution is at most $\frac{1}{2}$. Thus, if we run the algorithm for $100n^2$ steps (as it is in the pseudo-code), the probability of not finding a solution is $\left(\frac{1}{2}\right)^{50} = 2^{-50}$.

\newpage
\section{Performance Comparison}

\begin{figure}[h]
\centering
\includegraphics[width=.95\textwidth]{diagrams/test0.png}
\caption{Benchmarking script used to compare the speed of the two implementation in Part A and Part B. Kosaraju's Algorithm runs faster than the randomised algorithm as predicted by the algorithmic analysis. }
\end{figure}

\vspace{4mm}

Even though the probability of not finding a solution is very small ($2^{-50}$ for $100n^2$ steps), the randomised algorithm is not a practical substitute for the deterministic one since it takes longer time than the deterministic algorithm. There is also some chance that a solution is not found and hence an incorrect conclusion/statement of the problem's satisfiability could be made. The randomised algorithm is also dependent on the size of the variables.\newline

However, we should not dismiss the usefulness of the idea of randomised local search entirely. We should be aware that the strategy of using randomised local search is useful to improve over naive brute-force search for NP-complete $k$-SAT problems, such as the $3$-SAT problem. In fact, for a 3-SAT problem, the naive brute-force method would take $O(2^n)$ time, while a version of the randomised local search with a clever twist (such as Sch\"{o}ning's stochastic local search algorithm) would take $O\left(\frac{4}{3}^n\right)$ time, which is significantly better than $O(2^n)$.

\end{document}


\section{EIS: using \texttt{glimmer-tests}}
\texttt{glimmer-tests} provides more example configurations, that include both the EISMINT
and EIS climate drivers. If you have not already done so, download
\texttt{glimmer-tests} via the nescforge page or CVS, and do the usual
\begin{verbatim}
    ./configure -with-glimmer-prefix=/path/to/GLIMMER/installation
    (e.g. /usr/local/GLIMMER)
\end{verbatim}
(if you updated GLIMMER via CVS, you need to do \texttt{./bootstrap} first.)\\
\texttt{glimmer-tests} is not (yet) a test suite, but will exemplarily show
what GLIMMER can do (see the \texttt{glimmer-tests} README file for detailed
information on the tests).

Basically \texttt{glimmer-tests} runs GLIMMER using the EISMINT 1 and 2 (and 3)
climate driver (fixed and moving margin type ice sheets with no external mass
balance forcing), as well as the Edinburgh Ice Sheet (EIS) climate driver,
using mass balance parameterisation via ELA and temperature forcing. There are
a couple of other tests running besides this, e.g. some benchmarks. If you want
to run all the examples, simply do a \texttt{make} in the
\texttt{glimmer-tests} directory, but be aware that running all tests will take a good
12+ hours on a single CPU 3 GHZ machine. If you're too impatient for this,
simply do a \texttt{make} in one of the subdirectories, e.g. EISMINT1 and GLIDE
will be launched using the EISMINT climate driver, which should deliver you a
number of netcdf files with the model results, eg. \texttt{e1.fm.1.nc}
containing the EISMINT1 fixed margin results 1, etc. Again, to visualise the
results use a viewer like ncview.

If you want a more sophisticated results, try \texttt{make} in the \texttt{eis}
directory, which will repeat the results of \cite{Hagdorn2003} reconstructing
the Fennoscandian ice sheet during the last glacial maximum, using the EIS
driver.

\subsection{A short introduction to the EIS driver parameterisation}

Again, check the config file \texttt{fenscan.config} to see the basic
parameters for this model run. Have a look at the \texttt{mb2.data} (mass
balance forcing via ELA), \texttt{temp-exp.model} (exponential type temperature
forcing) and \texttt{specmap.data} (sealevel change) data files and compare
them to the EIS driver documentation (section \ref{driver:eis}) to get an idea of how things are done.

The first column in every data file is the model time at which the new
parameter values are applied. For the temperature model, the records in the
\texttt{temp-exp.model} file
\begin{verbatim}
...
 -97000.000000  -17.858964  23.158964   -0.051329
 -96000.000000  -20.074036  24.674036   -0.051329
...
\end{verbatim}

correspond to the timesteps -97000 and -96000 (first column - model usually
ends at time 0) where the parameters a0 (2nd column), a1 (3rd column) and a2
(last column) of the exponential temperature model $T(t)=a_0+a_1\exp\left(a_2(\lambda-\lambda_0)\right)$
(page \pageref{driver:eis})
are updated to reflect an approximate change in temperature of -2 degrees
Celsius.

For EIS, the mass balance is parameterised via the ELA, according to
$$z_{\text{ELA}} = a + b\lambda + c\lambda^2 + \Delta z_{\text{ELA}},$$
given the parameters in the according config file section:
\begin{verbatim}
...
[EIS ELA]
ela_file = mb2.data
bmax_mar = 4.
ela_a = 14430.069930
ela_b =-371.765734
ela_c = 2.534965
...
\end{verbatim}
Factors a, b and c are specified together with the maximum mass balance of 4. The
latitude $\lambda$ in degrees North is read from the input topography grid. In
order to do the ELA forcing over time, the parameter $\Delta z_{ELA}$ is varied
over time using the ela file \texttt{mb2.data}:
\begin{verbatim}
...
 -109000 225
 -105000 350
...
\end{verbatim}

Similar to the temperature forcing, $\Delta z_{ELA}$ (column 2) is changed at
timestep -10900 (column 1), to reflect an ELA 225m above the altitude value
calculated using the factors a, b, c and the latitude $\lambda$. At timestep
-10500, ELA is rising to 350m above the calculated value.

Where a globally changing $\Delta z_{ELA}$ is insufficient to reflect
disparities in ELA, there are two options to fine tune ELA behaviour. First,
continentality can be used to introduce a dependency of mass balance with
distance to oceans. The according settings are supplied using the \texttt{[EIS CONY]}
section of the config file (see section \ref{driver:eis}).
In short, an index is calculated for every grid cell reflecting
the ratio of below sealevel cells to land cells within a certain \texttt{range} (defaults to 600km).
Maximum mass balance values are then scaled between the values given in the \texttt{[EIS ELA]} section
for \texttt{bmax\_mar} (marine conditions, all cells within \texttt{range} are below sea level) and
\texttt{bmax\_cont} (continenal conditions, all cells within \texttt{range} are above sea level).
Alternatively, continentality values between 0 and 1 can be input using a file. Set the according
flag \texttt{file} to 1 and specify the file containing the cony data using a \texttt{[CF input]} section
in the configuration file (see example for ELA file below).
.

In case a more detailed spatial distribution of ELA altitudes is needed, e.g.
to reflect special orographic effects, a map of $\Delta z_{ELA}$ can be input
to the model using a netcdf file, containing a variable 'ela' on a grid
the same size and coordinates as the input topography grid the model is running
on. This ela file is coupled using a \texttt{[CF input]} section in the
configuration file
\begin{verbatim}
[CF input]
name: ela_1k.nc
\end{verbatim}
resulting in a spatial distribution of $\Delta z_{ELA}$ being applied to the
model. The variation of ELA over time using a global $\Delta z_{ELA}$ is still
applied on top of this ELA forcing file.

\textcolor[rgb]{1.00,0.00,0.00}{\emph{Note: (Maybe an example
containing an ELA forcing file should be added to GLIMMER test/examples?)}}
\\
Sealevel changes are forced upon the model in an according way using the
\texttt{specmap.data} file.


\documentclass[12pt]{cdblatex}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% ============================================================================================
\section*{Example 11 The RNC connection.}

\CdbSetup{action=hide}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u#}::Indices(position=independent).

   D{#}::PartialDerivative.
   \nabla{#}::Derivative.

   g_{a b}::Metric.
   g^{a b}::InverseMetric.

   \delta{#}::KroneckerDelta.

   R_{a b c d}::RiemannTensor.

   def truncate (obj,n):

       ans = Ex("0")

       for i in range (0,n+1):
          foo := @(obj).
          bah  = Ex("xnum = " + str(i))
          distribute  (foo)
          keep_weight (foo, bah)
          ans = ans + foo

       return ans

   def check (objA,objB):

       tmp := @(objA) - @(objB).

       distribute     (tmp)
       sort_product   (tmp)
       rename_dummies (tmp)
       canonicalise   (tmp)

       return tmp

   import cdblib

   # ---------------------------------------------
   check000A = truncate ( cdblib.get ('check000','expected/example-11.json'), 3)
   check001A = truncate ( cdblib.get ('check001','expected/example-11.json'), 3)
   check002A = truncate ( cdblib.get ('check002','expected/example-11.json'), 3)

   # ---------------------------------------------
   check000B = truncate ( cdblib.get ('check000','output/example-11.json'), 3)
   check001B = truncate ( cdblib.get ('check001','output/example-11.json'), 3)
   check002B = truncate ( cdblib.get ('check002','output/example-11.json'), 3)

   # ---------------------------------------------
   diff000 = check (check000A,check000B)   # cdb (ex-11.diff000,diff000)
   diff001 = check (check001A,check001B)   # cdb (ex-11.diff001,diff001)
   diff002 = check (check002A,check002B)   # cdb (ex-11.diff002,diff002)

\end{cadabra}

% \clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-11.diff000}}
   \Dmath*{\cdb*{ex-11.diff001}}
   \Dmath*{\cdb*{ex-11.diff002}}
\end{dgroup*}

\end{document}


\section{The Riemann integral}


\documentclass{article}
\usepackage[left=6.3em,right=7em,top=7em]{geometry}
\usepackage{amsmath}
\usepackage{bcprules}
\usepackage{amssymb}
\usepackage{stmaryrd}
\usepackage{multicol}
\begin{document}
\section{source language $\mathcal{T}$}
\begin{flalign*}
    \mathtt{n} ::=&\quad n \in \mathcal{N} \\
    \mathtt{e} ::=&\qquad \mathtt{n} \mid \mathtt{true} \mid \mathtt{false} \mid \mathtt{()} \mid \mathtt{x} \\
         &\quad \mid \mathtt{e+e} \mid \mathtt{e-e} \mid \mathtt{e*e} \mid \mathtt{e/e}\\
         &\quad \mid \mathtt{e=e} \mid \mathtt{e<e} \mid \mathtt{e>=e} \mid \mathtt{not\ e}\\
         &\quad \mid \mathtt{if}\ \mathtt{e}\ \mathtt{then}\ \mathtt{e}\ \mathtt{else}\ \mathtt{e}\\
         &\quad \mid \mathtt{let\ x=e\ in\ e} \mid \mathtt{let\ rec\ x\ x=e\ in\ e} \mid \mathtt{fun\ x \rightarrow e} \mid \mathtt{e\ e}
\end{flalign*}

\section{Virtual Machine specificatoin}
\subsection{closure representation}
\[Q = \left\langle I, C, F, \mathit{Um} \right\rangle\]
$I$ is instruction sequense, $C$ is constant table, $F$ is closure table
and $\mathit{Um}$ is just an information, to create upvalues, composed of index and \textit{meta} index, which of the former represents current register value and the latter does the upvalue index.

\subsection{machine state}
\[S = \left\langle Q, \mathtt{pc}, U, R \right\rangle\]
\texttt{pc} is program counter which points nth instruction of $I$, $U$ is upvalues table and $R$ is register list.

\subsection{values}
\begin{flalign*}
    \mathtt{v} ::=\quad \mathtt{null} \mid \mathtt{()} \mid \mathtt{i} \in \mathcal{N} \mid \mathtt{true} \mid \mathtt{false} \mid \mathtt{clos}\left(Q, U\right)
\end{flalign*}

\subsection{Instructions}
\begin{minipage}{\textwidth}
    \begin{multicols}{2}
        \begin{itemize}
            \item \texttt{Load(a, kx)}

                set \texttt{C[kx]} to \texttt{R[a]}
            \item \texttt{SetBool(a, x, p)}

                set boolean \texttt{x > 0} to \texttt{R[a]};
                if \texttt{p = 1} then \texttt{pc++}
            \item \texttt{Unit(a)}

                set \texttt{()} to \texttt{R[a]}
            \item \texttt{Clos(a, cx, p)}

                create $U'$ = $U\ @\ \left\{u \mid i_u \in \mathit{Um} \wedge u = R[i_u]\right\}$
                and set $\left\langle \mathtt{F[cx]}, 0, U', R'\right\rangle$ with environment to \texttt{R[a]}
                if \texttt{p=1} then the closure is recursive
            \item \texttt{Upval(a, ux)}

                set \texttt{U[rx]} to \texttt{R[a]}
            \item \texttt{Add(a, b, c)}

                set \texttt{R[b] + R[c]} to \texttt{R[a]}
            \item \texttt{Sub(a, b, c)}

                set \texttt{R[b] - R[c]} to \texttt{R[a]}
            \item \texttt{Mul(a, b, c)}

                set \texttt{R[b] * R[c]} to \texttt{R[a]}
            \item \texttt{Div(a, b, c)}

                set \texttt{R[b] / R[c]} to \texttt{R[a]}
            \item \texttt{Eq(a, b)}

                if \texttt{R[a] == R[b]} then \texttt{pc++}
            \item \texttt{Lt(a, b)}

                if \texttt{R[a] < R[b]} then \texttt{pc++}
            \item \texttt{Ge(a, b)}

                if \texttt{R[a] >= R[b]} then \texttt{pc++}
        \end{itemize}
    \end{multicols}
\end{minipage}
\begin{minipage}{\textwidth}
    \begin{multicols}{2}
        \begin{itemize}
            \item \texttt{Test(a, p)}

                if \texttt{p > 0 \&\& R[a] || p <= 0 \&\& !R[a]} then \texttt{pc++}

            \item \texttt{Jump(x)}

                \texttt{pc += x}
            \item \texttt{Move(a, b)}

                set \texttt{R[b]} to \texttt{R[a]}
            \item \texttt{Call(a, b)}

                call closure \texttt{R[a]} with argument \texttt{R[b]} and set return value to \texttt{R[a]}
            \item \texttt{Return(a)}

                exit closure evaluation and return \texttt{R[a]}
            \item \texttt{TailCall(a, b)}

                call closure \texttt{R[a]} with argument \texttt{R[b]} and exit closure evaluation and return \texttt{R[a]}
        \end{itemize}
    \end{multicols}
\end{minipage}

\section{compilation: translate source language program to VM initial state (input bytecode)}
Compilation is represented as equation: \[\llceil\mathcal{T}, \Sigma, Q\rrceil = Q', \Sigma' .\]
$\Sigma$ is an environment from source language variable to register index.
$Q_{\mathit{init}}$ generates initial compilation state: \[Q_{\mathit{init}}\left(e\right) = \llceil e, [], \left\langle [], [], [], []\right\rangle \rrceil .\]

\subsection{auxiliary funcion}
We define two auxiliary functions; \textit{mtch} is to get last used register and rest instructions by pattern match,

\begin{center}
    \begin{minipage}{.5\textwidth}
        \begin{flalign*}
            &\mathit{mtch}\left(I; \mathtt{Return\left(a\right)}\right) &&=& \left(\mathtt{a}, I\right)\\
            &\mathit{mtch}\left(I; \mathtt{TailCall\left(a, b\right)}\right) &&=& \left(\mathtt{a}, I; \mathtt{Call\left(a, b\right)}\right)\\
            &\mathit{mtch}\left(\textunderscore\right) &&=& \mathrm{undefined}
        \end{flalign*}
    \end{minipage}
\end{center}
\textit{FV} is to get free variables.
\begin{center}
    \begin{minipage}{.5\textwidth}
        \begin{flalign*}
            &FV\left(\mathtt{n}\right) \mid FV\left(\mathtt{true}\right) \mid FV\left(\mathtt{false}\right) \mid FV\left(\mathtt{()}\right) &&=& \left\{\right\}\\
            &FV(\mathtt{x}) &&=& \left\{\mathtt{x}\right\}\\
            &FV(\mathtt{not\ e}) &&=& FV(\mathtt{e})\\
            &FV(\mathtt{e1 ? e2}) \mid FV\left(\mathtt{e1\ e2}\right) &&=& FV(\mathtt{e1}) \cup FV(\mathtt{e2})\\
            &FV(\mathtt{if\ e1\ then\ e2\ else\ e3}) &&=& FV(\mathtt{e1}) \cup FV(\mathtt{e2}) \cup FV(\mathtt{e3})\\
            &FV\left(\mathtt{fun\ x\rightarrow e}\right) &&=& FV\left(\mathtt{e}\right) \textbackslash \left\{\mathtt{x}\right\}\\
            &FV\left(\mathtt{let\ x\ =\ e1\ in\ e2}\right) &&=& FV(\mathtt{e1}) \cup \left(FV\left(\mathtt{e2}\right) \textbackslash \left\{\mathtt{x}\right\}\right)\\
            &FV\left(\mathtt{let\ rec\ f\ x=\ e1\ in\ e2}\right) &&=& \left(FV\left(\mathtt{e1}\right) \textbackslash \left\{\mathtt{x}\right\} \cup FV\left(\mathtt{e2}\right)\right) \textbackslash \left\{\mathtt{f}\right\}
        \end{flalign*}
    \end{minipage}
\end{center}

\subsection{compilation rules}

\infrule[Int]{%
    \mathtt{a}\ \mathrm{and}\ \mathtt{kx}\ \mathrm{are\ fresh}
}{
    \llceil\mathtt{n}, \Sigma, \left\langle I, C, F, \mathit{Um}\right\rangle \rrceil =%
    \left\langle
        I; \mathtt{Load(a, kx)}; \mathtt{Return(a)}, C; \mathtt{kx} = \mathtt{n}, F, \mathit{Um}
    \right\rangle, \Sigma'
}

\infax[Unit]{
    \llceil\mathtt{()}, \Sigma, \left\langle I, C, F, \mathit{Um}\right\rangle \rrceil =
    \left\langle
        I; \mathtt{Unit(a)}; \mathtt{Return(a)}, C, F, \mathit{Um}
    \right\rangle, \Sigma'
}

\infax[True]{
    \llceil\mathtt{true}, \Sigma, \left\langle I, C, F, \mathit{Um}\right\rangle \rrceil =
    \left\langle
        I; \mathtt{SetBool(a, 1)}; \mathtt{Return(a)}, C, F, \mathit{Um}
    \right\rangle, \Sigma'
}

\infax[False]{
    \llceil\mathtt{false}, \Sigma, \left\langle I, C, F, \mathit{Um}\right\rangle \rrceil =
    \left\langle
        I; \mathtt{SetBool(a, 0)}; \mathtt{Return(a)}, C, F, \mathit{Um}
    \right\rangle, \Sigma'
}

\infrule[Add]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_\mathtt{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1 + e2}, \Sigma, Q\rrceil = \langle I''; \mathtt{Add(a, r_{e1}, r_{e2})}; \mathtt{Return(a)}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[Sub]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1 - e2}, \Sigma, Q\rrceil = \langle I''; \mathtt{Sub(a, r_{e1}, r_{e2})}; \mathtt{Return(a)}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[Mul]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1 * e2}, \Sigma, Q\rrceil = \langle I''; \mathtt{Mul(a, r_{e1}, r_{e2})}; \mathtt{Return(a)}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[Div]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1 / e2}, \Sigma, Q\rrceil = \langle I''; \mathtt{Div(a, r_{e1}, r_{e2})}; \mathtt{Return(a)}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[Eq]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1 = e2}, \Sigma, Q\rrceil =
    \langle I''; \mathtt{Eq(r_{e1}, r_{e2})}; \mathtt{SetBool(a, 1)}; \mathtt{SetBool(a, 0)}; \mathtt{Return(a)}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[Lt]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1 < e2}, \Sigma, Q\rrceil =
    \langle I''; \mathtt{Lt(r_{e1}, r_{e2})}; \mathtt{SetBool(a, 1)}; \mathtt{SetBool(a, 0)}; \mathtt{Return(a)}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[Ge]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1 >= e2}, \Sigma, Q\rrceil =
    \langle I''; \mathtt{Ge(r_{e1}, r_{e2})}; \mathtt{SetBool(a, 1)}; \mathtt{SetBool(a, 0)}; \mathtt{Return(a)}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[Not]{
        \mathtt{a}\ \mathrm{is\ fresh}
    \andalso Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e}, \Sigma, Q\rrceil = \langle I_\mathtt{e}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e}\right) = \left(\mathtt{r_e}, I'\right)
}{
    \llceil \mathtt{not\ e}, \Sigma, Q\rrceil = \langle I'; \mathtt{Test(r_{e}, 0)}; \mathtt{SetBool(a, 1)}; \mathtt{SetBool(a, 0)}; \mathtt{Return(a)}, C', F', \mathit{Um}'\rangle, \Sigma'
}

\infrule[Fun]{
        \mathtt{a}\ \mathrm{and}\ \mathtt{cx}\ \mathrm{are\ fresh}
    \andalso Q = \left\langle I, C, F, \mathit{Um}\right\rangle
    \andalso fv = FV\left(\mathtt{fun\ x\rightarrow e}\right)
    \andalso \Sigma_0 = \left\{\left(\mathtt{x} = \mathtt{i_r}\right) \mid \left(\mathtt{x} = \mathtt{i_r}\right) \in \Sigma \wedge \mathtt{x} \in fv \right\}
    \andalso\\
        \Sigma' = \left\{ \left(\mathtt{x} = \mathtt{-\left(i + 1\right)}\right) \mid \left(\mathtt{x} = \mathtt{i_r}\right)\ \mathrm{as}\ \mathit{xi} \in \Sigma_0 \wedge \mathit{xi}\ \mathrm{is}\ i\mathrm{th\ element\ of}\ \Sigma_0 \right\}
    \andalso \mathit{Um}' = \left\{ \mathtt{i} \mid \left(\textunderscore = \mathtt{i}\right) \in \Sigma' \right\}
    \andalso\\
        Q_{\mathit{init}}\left(\mathtt{e}\right) = \llceil \mathtt{e}, \Sigma_\mathtt{e}, \left\langle I_\mathtt{e}, C_\mathtt{e}, F_\mathtt{e}, \textunderscore\right\rangle \rrceil
    \andalso \Sigma_\mathtt{e}' = \Sigma_\mathtt{e}; \mathtt{x} = 0
    \andalso \llceil \mathtt{e}, \Sigma_\mathtt{e}', \langle I_\mathtt{e}, C_\mathtt{e}, F_\mathtt{e}, \mathit{Um}' \rangle \rrceil%
        = \left\langle I_\mathtt{e}', C_\mathtt{e}', F_\mathtt{e}', \textunderscore\right\rangle, \Sigma_\mathtt{e}''
    \andalso\\
        \mathit{Clos} = \left\langle I_\mathtt{e}', C_\mathtt{e}', F_\mathtt{e}', \mathit{Um} @ \mathit{Um}' \right\rangle
}{
    \llceil \mathtt{fun\ x \rightarrow e}, \Sigma, Q\rrceil = \langle I; \mathtt{Clos(a, cx, 0)}; \mathtt{Return(a)}, C, F; \mathtt{cx} = \mathit{Clos}, \mathit{Um} \rangle, \Sigma
}

\infrule[Call]{
        Q = \left\langle I,C, F, \mathit{Um} \right\rangle
    \andalso \llceil \mathtt{e1}, \Sigma, Q\rrceil = \langle I_\mathtt{e1}, C', F', \mathit{Um}'\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e2}, \Sigma', \langle I', C', F', \mathit{Um}'\rangle \rrceil = \langle I_\mathtt{e2}, C'', F'', \mathit{Um}''\rangle, \Sigma''
    \andalso \mathit{mtch}\left(I_\mathtt{e2}\right) = \left(\mathtt{r_{e2}}, I''\right)
}{
    \llceil \mathtt{e1\ e2}, \Sigma, Q\rrceil = \langle I''; \mathtt{TailCall(r_{e1}, r_{e2})}, C'', F'', \mathit{Um}''\rangle, \Sigma''
}

\infrule[VarLocal]{
    \Sigma[\mathtt{x}] = \mathtt{i} \wedge \mathtt{i}\geq \mathtt{0}
}{
    \llceil \mathtt{x}, \Sigma, \left\langle I, C, F, \mathit{Um}\right\rangle \rrceil =
    \left\langle
        I; \mathtt{Move(a, i)}; \mathtt{Return(a)}, C, F, \mathit{Um}
    \right\rangle, \Sigma'
}

\infrule[VarUpval]{
    \Sigma[\mathtt{x}] = \mathtt{i} \wedge \mathtt{i < 0}
}{
    \llceil \mathtt{x}, \Sigma, \left\langle I, C, F, \mathit{Um}\right\rangle \rrceil =
    \left\langle
        I; \mathtt{Upval(a, -i - 1)}; \mathtt{Return(a)}, C, F, \mathit{Um}
    \right\rangle, \Sigma'
}

\infrule[Let]{
        \mathtt{a}\ \mathrm{and}\ \mathtt{b}\ \mathrm{are\ fresh}
    \andalso Q = \left\langle I, C, F, \mathit{Um} \right\rangle
    \andalso\\
        \llceil \mathtt{e_1}, \Sigma, Q\rrceil = \left\langle I_\mathtt{e1}, C', F', \mathit{Um}'\right\rangle, \Sigma'
    \andalso \mathit{mtch}\left(I_\mathtt{e1}\right) = \left(\mathtt{r_{e1}}, I'\right)
    \andalso\\
        \llceil \mathtt{e_2}, \Sigma'; \mathtt{x}=\mathtt{a}, \left\langle I'; \mathtt{Move(b, a)}, C', F', \mathit{Um}'\right\rangle\rrceil = Q', \Sigma''
}{
    \llceil \mathtt{let\ x=e_1\ in\ e_2}, \Sigma, Q\rrceil = Q', \Sigma''
}

\infrule[LetRecFun]{
        \mathtt{a}\ \mathrm{and}\ \mathtt{cx}\ \mathrm{are\ fresh}
    \andalso Q = \left\langle I, C, F, \mathit{Um} \right\rangle
    \andalso\\
        fv = \left(FV\left(\mathtt{e_1}\right) \textbackslash \left\{\mathtt{x}\right\} \cap FV\left(\mathtt{e_2}\right)\right) \textbackslash \left\{f\right\}
    \andalso \Sigma_0 = \left\{\left(\mathtt{x=i_r}\right) \mid \left(\mathtt{x=i_r}\right) \in \Sigma \wedge \mathtt{x}\in fv\right\} \cap \left\{\mathtt{\left(f = a\right)}\right\}
    \andalso\\
    \Sigma' = \left\{ \left(\mathtt{x} = \mathtt{-\left(i + 1\right)}\right) \mid \left(\mathtt{x} = \mathtt{i_r}\right)\ \mathrm{as}\ \mathit{xi} \in \Sigma_0 \wedge \mathit{xi}\ \mathrm{is}\ i\mathrm{th\ element\ of}\ \Sigma_0 \right\}
    \andalso\\
        \mathit{Um}' = \left\{\mathtt{i} \mid \left(\mathtt{\textunderscore = i}\right) \in \Sigma'\right\}
    \andalso Q_\mathit{init}(\mathtt{e_1}) = \llceil \mathtt{e1}, \Sigma_\mathtt{e1}, \left\langle I_\mathtt{e1}, C_\mathtt{e1}, F_\mathtt{e1}, \textunderscore\right\rangle \rrceil
    \andalso \Sigma_\mathtt{e1}' = \Sigma_\mathtt{e1}; \mathtt{x} = \mathtt{0}
    \andalso\\
    \llceil \mathtt{e1}, \Sigma_\mathtt{e1}', \left\langle I_\mathtt{e1}, C_\mathtt{e1}, F_\mathtt{e1}, \mathit{Um}' \right\rangle \rrceil = \left\langle I_\mathtt{e1}', C_\mathtt{e1}', F_\mathtt{e1}', \textunderscore\right\rangle, \Sigma_\mathtt{e1}''
    \andalso \mathit{Clos}=\left\langle I_\mathtt{e1},', C_\mathtt{e1}', F_\mathtt{e1}', \mathit{Um} @ \mathit{Um'}\right\rangle
    \andalso\\
        I' = I; \mathtt{Clos(a, cx, 1)}
    \andalso F' = F; \mathtt{cx}=\mathit{Clos}
    \andalso \Sigma' = \Sigma; \mathtt{f=a}
    \andalso \llceil \mathtt{e2}, \Sigma', \left\langle I', C, F', Um \right\rangle \rrceil = Q', \Sigma''
}{
    \llceil \mathtt{let\ rec\ f\ x=e1\ in\ e2}, \Sigma, Q\rrceil = Q', \Sigma''
}

% \section{Evaluation: VM state transition rules}

\end{document}


\section{Feasible Generalised Least Squares (FGLS)}


\subsection{Bayesian splines}


\listfiles
\documentclass{article}
\author{Arya Stark}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{listings}
\usepackage{float}
\usepackage{tikz}
\usepackage{tikz,fullpage}
\usepackage{tkz-graph}
\usepackage[position=top]{subfig}
\usepackage{graphicx}

\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclareMathOperator{\cl}{cl}
\DeclareMathOperator{\E}{E}
\def\Z{\mathbb{Z}}
\def\N{\mathbb{N}}
\def\R{\mathbb{R}}
\def\Q{\mathbb{Q}}
\def\K{\mathbb{K}}
\def\T{\mathbb{T}}
\def\B{\mathcal{B}}
\def\XX{\mathfrak{X}}
\def\YY{\mathfrak{Y}}
\def\AA{\mathfrak{A}}
\def\ZZ{\mathfrak{Z}}
\def\BB{\mathcal{B}}
\def\UU{\mathcal{U}}
\def\MM{\mathcal{M}}
\def\M{\mathfrak{M}}
\def\l{\lambda}
\def\L{\Lambda}
\def\<{\langle}
\def\>{\rangle}

\usepackage[a4paper,margin=1in]{geometry}

\setlength{\parindent}{0cm}
\setlength{\parskip}{1em}

\title{Virtual Channels and Rebalancing in State Channel Networks}
\date{}

\begin{document}
\maketitle

\section*{Introduction}

This research note was written because there are some unsolved problems in designing state channel networks that are not well-known or being worked on. These problems reveal themselves when we consider how to build channel networks capable of expressing agents' preferences over network topology (payment capacity) and capital costs, expectation of other participants' future liveness, and minimizing blockchain fees.

\section*{Relevant Prerequisite Literature}

This section goes through relevant existing literature. Note that even if you know all this, many definitions will be used in later sections.

\subsection*{Ball-and-bead model of PCN}

In this model, edges represent two-party channel between the endpoints, and a party's balance within the channel is represented by beads near to them.

\begin{center}
\includegraphics[scale=0.4]{beads.png}
\includegraphics[scale=0.4]{beads2.png}
\end{center}

This shows Alice sending Bob 2 beads via Hub. The remaining capacity along this path is $\min(2,1) = 1$.

\subsection*{Rebalancing}

We say that two payment channel networks are value-equivalent if the set of agents is the same and each agent owns the amount of beads summed over all their channels. A channel network is rebalanced when it transitions into a value-equivalent state. This transition can include on-chain transactions or not. In the following on-chain rebalance, Bob increases the capacity of the Bob $\to$ Alice link.

\begin{center}
\includegraphics[scale=0.4]{on-chain-rebalancing-1.png}
\includegraphics[scale=0.4]{on-chain-rebalancing-2.png}
\end{center}

The following is an example of a rebalance that does not require on-chain transactions.

\begin{center}
\includegraphics[scale=0.4]{off-chain-rebalancing-1.png}
\includegraphics[scale=0.4]{off-chain-rebalancing-2.png}
\end{center}

Are off-chain rebalances sufficient? In general, no.

% TBW: define a $a,b$-flow, apply max-flow-min-cut theorem, etc.

% Note some assumptions implicitly made when applying this theorem: the max flow might requrie very global knowledge to compute.

% Fun exercise! A self-payment is a special type of off-chain rebalance. Show that any rebalance can be expressed as a series of self-payments.

\subsection*{Time-based lockup}

There are multiple ways that intermediaries can structure agreements-to-route; we go through two extremal points here. They can agree to route a single payment. When that payment completes successfully, the balances change and they are free of any further commitments. The second way is to agree to lock up funds for a certain period of time, creating a ``virtual channel". The balances in the virtual channel can be updated instantly and many times without the intermediary's participation or knowledge. At the end of the lockup time, the final balances in the virtual channel are agreed to and we update the direct channel balances as though a single set of routed balance updates (routed payments) was made.

\subsection*{Ejection}

There is an upper bound on the fee that the intermediary can charge, since any virtual channel can be transformed into a direct channel (i.e. it can be ``ejected") by some on-chain transactions, without disrupting the internal state of the virtual channel. Here is an example. Suppose we have this system of direct channels. (Note: we switch to labelling edges by their endpoint balances rather than using beads, due to limitations of latex).

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{H}
        \Vertex[x=4,y=0]{B}
        \Edge[label=$1/1$](A)(H)
        \Edge[label=$1/1$](H)(B)
    \end{tikzpicture}
\end{figure}

Here, a virtual channel between A and B can be formed, with balance one bead for each of them, locking up two beads from H. The channel could be ejected by an on-chain transaction that transfers one bead out of the A-H channel and H-B channel and atomically updating the internal states of them.

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$0/1$](A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[style={bend left},label=$1/1$](A)(C)
    \end{tikzpicture}
\end{figure}

\subsection*{Intermediation Fees}

For this reason, thinking of lockups as either completely ``per-payment" or ``time-based" is not strictly accurate; the costs an intermediary would incur in a channel network is both the cost of re-configuring the capacity graph as well as time-based opportunity cost of having their capital in excess of payments they would want to make anyway in the network (e.g. instead of staking), however both can be avoided by on-chain transactions; the instances where on-chain transactions are avoided and off-chain fees paid instead are therefore some complex subset of transactions in general.

Here is a crude fee scheme that captures some of it this: an intermediary charges some large fee $F_1$ to intermediate a virtual channel, and assumes the responsibility of ejecting the channel; if the virtual channel participants have no further use for it, they negotiate a payment of $F_2$ from the intermediary to close the virtual channel offline. If the on-chain fee is $T$, we should have $0 < F_1 - F_2 < T < F_1$. On/off-chain rebalancing is handeled by an independent protocol.

Another design: timeout by default, but eject if agreed to.

\subsection*{State Channels}

By allowing beads to be locked into complex applications (e.g. chess, prediction markets) instead of just payments, the need for virtual channels as well as for ejection is even more apparent. Beads can be freed up and re-used within a virtual channel. The time bound for an application might be long or unknown (e.g., we lock beads up in a bet of whether any US Libertarian Party ever wins a House seat in the next 10 years),

\subsection*{Multipath}

TBW

\subsection*{N-Party}

TBW

\subsection*{Subchannels}

TBW

\subsection*{Plasma}

Plasma can be used to fund channels. If all channels are funded by plasma, then rebalancing is a plasma transaction in the normal case, i.e., the entire network can be rebalanced arbitrarily in a single ethereum transaction. I claim that a super-optimized channel network that does not support funding via plasma will be much more expensive than a very suboptimal one that supports funding via plasma.

\section*{Ejection Test Cases}

We present some ejection test cases and for each one, we show that it could be the optimal way of ejecting the channel given certain assumptions about the participants' preferences over the capacity graph, on-chain fees, and expectation of other participants' future liveness.

\subsection*{Symmetric}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$1/1$](A)(B)
        \Edge[label=$1/1$](B)(C)
        \Edge[style={bend left}](A)(C)
    \end{tikzpicture}
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$0/1$](A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[style={bend left},label=$1/1$](A)(C)
    \end{tikzpicture}
\end{figure}

Reviewed previously.

\subsection*{Asymetric}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$1/1$](A)(B)
        \Edge[label=$1/1$](B)(C)
        \Edge[style={bend left}](A)(C)
    \end{tikzpicture}
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$0/2$](A)(B)
        \Edge(B)(C)
        \Edge[style={bend left},label=$1/1$](A)(C)
    \end{tikzpicture}
\end{figure}

What are the differences between the the assymetric and symmetric ways of ejecting? The symmetric manner might be preferred because it minimal in the number of transactions (1 vs 2). Even if we assume some mechanism to batch two sub-transactions under one (e.g. account abstraction), it is minimal in the number of ERCECOVERS (3 vs 2). On the other hand, the symmetric manner might be preferred for the more ``balanced" resulting capacity graph.

\subsection*{Symmetric Unidirectional}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$2/0$](A)(B)
        \Edge[label=$2/0$](B)(C)
        \Edge[style={bend left}](A)(C)
    \end{tikzpicture}
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$0/1$](A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[style={bend left},label=$2/0$](A)(C)
    \end{tikzpicture}
\end{figure}

\subsection*{Asymmetric Unidirectional 1}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$1/0$](A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[style={bend left}](A)(C)
    \end{tikzpicture}
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$0/1$](A)(B)
        \Edge(B)(C)
        \Edge[style={bend left},label=$1/0$](A)(C)
    \end{tikzpicture}
\end{figure}

\subsection*{Asymmetric Unidirectional 2}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge[label=$1/0$](A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[style={bend left}](A)(C)
    \end{tikzpicture}
    \begin{tikzpicture}[scale=2.75]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Edge(A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[style={bend left},label=$1/0$](A)(C)
    \end{tikzpicture}
\end{figure}

\subsection*{Long-Chain Large-Radius}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Vertex[x=6,y=0]{D}
        \Vertex[x=8,y=0]{E}
        \Vertex[x=10,y=0]{F}
        \Edge[label=$1/0$](A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[label=$1/0$](C)(D)
        \Edge[label=$1/0$](D)(E)
        \Edge[label=$1/0$](E)(F)
        \Edge[style={bend left}](A)(F)
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Vertex[x=6,y=0]{D}
        \Vertex[x=8,y=0]{E}
        \Vertex[x=10,y=0]{F}
        \Edge[label=$0/1$](A)(B)
        \Edge[label=$0/1$](B)(C)
        \Edge[label=$0/1$](C)(D)
        \Edge(D)(E)
        \Edge[label=$1/0$](E)(F)
        \Edge[style={bend left},label=$1/0$](A)(F)
    \end{tikzpicture}
\end{figure}

\subsection*{Long-Chain Short-Radius}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Vertex[x=6,y=0]{D}
        \Vertex[x=8,y=0]{E}
        \Vertex[x=10,y=0]{F}
        \Edge[label=$1/0$](A)(B)
        \Edge[label=$1/0$](B)(C)
        \Edge[label=$1/0$](C)(D)
        \Edge[label=$1/0$](D)(E)
        \Edge[label=$1/0$](E)(F)
        \Edge[style={bend left}](C)(E)
    \end{tikzpicture}
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=0]{A}
        \Vertex[x=2,y=0]{B}
        \Vertex[x=4,y=0]{C}
        \Vertex[x=6,y=0]{D}
        \Vertex[x=8,y=0]{E}
        \Vertex[x=10,y=0]{F}
        \Edge[label=$0/1$](A)(B)
        \Edge[label=$0/1$](B)(C)
        \Edge[label=$0/1$](C)(D)
        \Edge(D)(E)
        \Edge[label=$1/0$](E)(F)
        \Edge[style={bend left},label=$1/0$](C)(E)
    \end{tikzpicture}
\end{figure}

\subsection*{Multipath}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=2,y=0]{D}
        \Vertex[x=0,y=1]{A}
        \Vertex[x=4,y=1]{E}
        \Vertex[x=1,y=2]{B}
        \Vertex[x=3,y=2]{C}
        \Edge(A)(E)
        \Edge(A)(B)
        \Edge(B)(C)
        \Edge(C)(E)
        \Edge(A)(D)
        \Edge(D)(E)
    \end{tikzpicture}
\end{figure}

Balances and ejection to be filled in.

\subsection*{Thanos Star}

New notation: a square node is not a participant, but it means that its neighbours are all connected in a direct channel.

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=2.5]{A}
        \Vertex[x=3,y=0]{B}
        \Vertex[x=3,y=1]{C}
        \Vertex[x=3,y=2]{D}
        \Vertex[x=3,y=3]{E}
        \Vertex[x=3,y=4]{F}
        \Vertex[x=3,y=5]{G}
        \begin{scope}[VertexStyle/.append style = {rectangle}]
        \Vertex[x=6,y=2.5,style={color=red}]{H}
        \end{scope}
        \Edge[label=$1/1$](A)(B)
        \Edge[label=$1/1$](A)(C)
        \Edge[label=$1/1$](A)(D)
        \Edge[label=$1/1$](A)(E)
        \Edge[label=$1/1$](A)(F)
        \Edge[label=$1/1$](A)(G)
        \Edge(H)(B)
        \Edge(H)(C)
        \Edge(H)(D)
        \Edge(H)(E)
        \Edge(H)(F)
        \Edge(H)(G)
    \end{tikzpicture}
\end{figure}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \SetVertexSimple
        \Vertex[x=0,y=2.5]{A}
        \Vertex[x=3,y=0]{B}
        \Vertex[x=3,y=1]{C}
        \Vertex[x=3,y=2]{D}
        \Vertex[x=3,y=3]{E}
        \Vertex[x=3,y=4]{F}
        \Vertex[x=3,y=5]{G}
        \begin{scope}[VertexStyle/.append style = {rectangle}]
        \Vertex[x=6,y=2.5,style={color=red}]{H}
        \end{scope}
        \Edge(A)(B)
        \Edge(A)(C)
        \Edge(A)(D)
        \Edge[label=$2/0$](A)(E)
        \Edge[label=$2/0$](A)(F)
        \Edge[label=$2/0$](A)(G)
        \Edge[label=$1$](H)(B)
        \Edge[label=$1$](H)(C)
        \Edge[label=$1$](H)(D)
        \Edge[label=$1$](H)(E)
        \Edge[label=$1$](H)(F)
        \Edge[label=$1$](H)(G)
    \end{tikzpicture}
\end{figure}

A 6-party virtual channel gets ejected into a 6-party direct channel. This manner of ejecting is minimal in number of transactions.

\section*{Other test cases}

\subsection*{Under-Capacity Three Party Channel}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=1.5]
        \GraphInit[vstyle=Normal]
        \Vertex[x=0,y=0]{A}
        \Vertex[x=0,y=2]{B}
        \Vertex[x=3,y=1]{H}
        \Vertex[x=6,y=1]{C}
        \Edge[label=$1/0$](A)(H)
        \Edge[label=$1/0$](B)(H)
        \Edge[label=$1/0$](H)(C)
    \end{tikzpicture}
\end{figure}

If A,B,C form a virtual channel through H, they end up in a three-party virtual channel where A can send C one bead, and B can send C one bead, but the two cannot happen at the same time. The challenge is that it is inappropirate to represent this as a three-party channel where A and B's balances are both one.

\subsection*{Self Lock-in}

TBW

channel factories: more attack surface, but root nonce => same cost of attack

channels-on-plasma spectrum

\end{document}


\section{Single Variable Calculus}
\noindent

% Derivatives and Integrals
\input{./backgroundReview/singleVariableCalc/derivativesIntegrals.tex}
% Taylor Series
\input{./backgroundReview/singleVariableCalc/taylorSeries.tex}


\title{LMMP: Stereo Module Testing Plan}
\author{
        Ara V. Nefian \and Michael Broxton
}
\date{\today}

\documentclass[12pt]{article}

\begin{document}
\maketitle

This document describes a testing plan for the LMMP stereo module.
{\underline {\bf Accuracy measures}}

\begin{itemize}
\item {\bf Option 1:} Short term, if ground truth data (Apollo Panoramic images) is available (Feb 15). Let the predicted horizontal and vertical
      disparity map for the $k$th image be denoted as ${\bf P}_{k, h}(i,j)$ and ${\bf P}_{k, v}(i,j)$  respectively with the corresponding ground truth dispariy map ${\bf T}_{k, h}(i,j)$ and ${\bf T}_{k, v}(i,j)$ for all pixels $(i,j)$.

The ${\bf average}$ ${\bf error}$ is
      ${\bf E} =\frac{1}{K}\sum_k\frac{\sum_{ij} (P_{k,v}(i,j)-T_{k,v}(i,j))^2 + (P_{k,h}(i,j)-T_{k,h}(i,j))^2}{N_{k,pred}} $ where $N_{k,pred}$
      is the number of pixels for which the disparity map was computed in the $k$th image, and $K$ is the total number of images for
      which we have ground truth.

      The ${\bf average}$ ${\bf coverage}$ ${\bf C}$ measures the number of pixels for which the disparity is determined:
${\bf C} = \frac{1}{K}\sum_k\frac{N_{k,pred}}{N_{k,true}}$, where $N_{k, true}$ is the resolution of the ground truth images.

     The goal is to have a small average error ${\bf E}$ and large avearge coverage ${\bf C}$ measures.

\item {\bf Option 2:} Very short term, before the ground truth data is made available (Jan 15th).
                    Compute the ${\bf E}$ measure using existing synthetic ground truth data, and the ${\bf C}$
                    measure using the MOC and Apollo Metric data.

\item {\bf Option 3:} On the longer term the ${\bf E}$ measure will be weighted by the confidence score of the Bayesian subpixel correlator.

       ${\bf \tilde E} =\frac{1}{K}\sum_k\frac{\sum_{ij} ((P_{k,v}(i,j)-T_{k,v}(i,j))^2 + (P_{k,h}(i,j)-T_{k,h}(i,j))^2)\frac{p_{ij}}{\sum_{ij}p_{ij}}}{N_{k,pred}} $
\end{itemize}

{\underline {\bf Performance measures}}
 Very short term (Jan 15th). Compute the number of additions, multiplications log and exp operations per pixel and run time required to generate the dense disparity map.
%\begin{abstract}
%This is the paper's abstract \ldots
%\end{abstract}

%\section{Introduction}
%This is time for all good men to come to the aid of their party!

%\paragraph{Outline}
%The remainder of this article is organized as follows.
%Section~\ref{previous work} gives account of previous work.
%Our new and exciting results are described in Section~\ref{results}.
%Finally, Section~\ref{conclusions} gives the conclusions.

%\section{Previous work}\label{previous work}
%A much longer \LaTeXe{} example was written by Gil~\cite{Gil:02}.

%\section{Results}\label{results}
%In this section we describe the results.

%\section{Conclusions}\label{conclusions}
%We worked hard, and achieved very little.

\bibliographystyle{abbrv}
\bibliography{simple}

\end{document}
This is never printed