\documentclass[a4paper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{theorem}
\usepackage{listings}
\usepackage{url}
\usepackage{pdfsync}

%%% Settings for listings
\lstset{basicstyle=\ttfamily\small,xleftmargin=\parindent,language=Haskell}

\newcommand{\cc}[1]{\lstinline{#1}}

%%% Theorems
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}

{\theorembodyfont{\rmfamily}
  \newtheorem{exercise}[theorem]{Exercise}
  \newtheorem{definition}[theorem]{Definition}
}

\newenvironment{proof}{\par\noindent\textit{Proof.}}{\hfill$\Box$\par\medskip}

%%% Macros

\newcommand{\RR}{\mathbb{R}}

\newcommand{\set}[1]{\{#1\}}
\newcommand{\such}{\mid}
\newcommand{\tpl}[1]{\mathcal{O}(#1)}
\newcommand{\cont}[1]{\mathcal{C}(#1)}
\newcommand{\scr}[1]{\mathcal{#1}}
\newcommand{\two}{\mathsf{2}}
\newcommand{\Bool}{\mathtt{Bool}}

\newcommand{\R}[1]{\mathtt{#1}}
\newcommand{\rz}{\Vdash}

\newcommand{\bind}{\mathbin{\text{\texttt{\char62\char62\char61}}}}

%%% Quantifiers

%%% quantifiers
\newcommand{\all}[3]{\forall\, #1 \,{\in}\, #2\,.\left(#3\right)}
\newcommand{\some}[3]{\exists\, #1 \,{\in}\, #2\,.\left(#3\right)}
\newcommand{\exactlyone}[3]{\exists!\, #1 \,{\in}\, #2\,.\left(#3\right)}
\newcommand{\lam}[3]{\lambda #1 \,{\in}\, #2\,.\left(#3\right)}
\newcommand{\uall}[2]{\forall\, #1\,.\left(#2\right)}
\newcommand{\usome}[2]{\exists\, #1\,.\left(#2\right)}
\newcommand{\uexactlyone}[3]{\exists!\, #1\,.\left(#2\right)}
\newcommand{\ulam}[2]{\lambda #1 .\left(#2\right)}
\newcommand{\xall}[3]{\forall\, #1 \,{\in}\, #2\,.\,#3}
\newcommand{\xsome}[3]{\exists\, #1 \,{\in}\, #2\,.\,#3}
\newcommand{\xexactlyone}[3]{\exists!\, #1 \,{\in}\, #2\,.\,#3}
\newcommand{\xuall}[2]{\forall\, #1\,.\,#2}
\newcommand{\xusome}[2]{\exists\, #1\,.\,#2}
\newcommand{\xuexactlyone}[2]{\exists!\, #1,.\,#2}
\newcommand{\xlam}[3]{\lambda #1 \,{\in}\, #2\,.\,#3}
\newcommand{\xulam}[2]{\lambda #1 .\,#2}
\newcommand{\tlam}[3]{\lambda #1 \,{:}\, #2\,.\,\left(#3\right)}
\newcommand{\xtlam}[3]{\lambda #1 \,{:}\, #2\,.\,#3}

\begin{document}

\title{Computation over compact and overt spaces}
\author{Andrej Bauer}

\maketitle

\begin{abstract}
    These are lecture notes for the graduate course ``Topology in computer
    science'' which I gave with Neža Mramor-Kosta in the Fall of~2009 at the
    Faculty of computer science, University of Ljubljana.
\end{abstract}

\section{Introduction}
\label{sec:introduction}

When students first see the definition of compact spaces it usually looks very
mysterious to them. Where does the Heine-Borel property come from? Why would
anyone consider finite subcovers of arbitrary open covers? In these notes we
review the basic definitions and try to motivate them from the point of view
of computation.

We assume basic familiarity with topology and a certain degree of programming
skill. The code examples are written in Haskell, but could be translated to
any other programming language that supports higher-order functions.

These notes do not contain any original material. All is ``standard''
knowledge in topology and computation, although some parts are not well known.
A good starting point for background reading are Martín Escardó's
notes~\cite{escardo04:_synth}.

\section{Open sets as semidecidable properties}
\label{sec:opens-semidecidable}

An open subset of a topological space may be thought of as a property that can
be verified in finite time. To illustrate this, suppose we a real number $a$
is given to us in a physically realistic way. That is, $a$ is not given with
infinite precision all at once, but rather as a sequence of rational
approximations with error bounds. The approximations and the error bounds
might come from a sequence of ever more precise (and ever more expensive)
measurements, or from a computer program that computes~$a$ to any desired
precision.

We may want to know whether $a$ has a given property, or equivalently
whether it is an element of a given set $S \subseteq \RR$. We
distinguish between
%
\begin{itemize}
\item \emph{deciding} whether $a \in S$: we do not know whether $a \in
  S$ or $a \not\in S$ and would like to know which is the case.
\item \emph{verifying} that $a \in S$: we seek evidence that $a \in S$
  (and if $a \not\in S$ then we do not care what happens, and in
  particular we do not have to provide evidence that $a \not\in S$).
\end{itemize}
%
Deciding whether $a \in S$ provides one bit of information: we find out either
$a \in S$ or $a \not\in S$. Verifying that $a \in S$ provides \emph{less} than
that: if $a \in S$ we eventually get the evidence, but if $a \not\in S$ we
just wait forever hoping that perhaps the evidence of $a \in S$ will appear.

Can we decide whether $a > 0$? No, not for all $a$. The problematic case is $a
= 0$ because we will never be able to tell that $a > 0$ does not hold just by
looking at an approximation $a'$ with a positive error bound $\epsilon > 0$.

Can we verify that $a > 0$? Yes. If it is the case that $a > 0$ then
eventually we will see an approximation $a'$ with a good enough error bound
$\epsilon > 0$ such that $0 < a' - \epsilon < a$. If $a < 0$ then we do not
care what happens. (If you are thinking that we can decide whether $a > 0$ in
all cases but $a = 0$ then you are right. Of course, we are now talking about
a different topological space $\RR \setminus \set{0}$.)

A moment's thought shows that we can verify $a \in S$ when $S$ has the
following property: if $b \in S$ then also all points close enough to~$b$ are
in $S$. But that's precisely the definition of open sets. So we adopt the
slogan
%
\begin{quote}
  \emph{``Verifiable properties correspond to open sets.''}
\end{quote}
%
The word ``verifiable'' should be understood either as ``evidence can be
computed in finite time'' or ``an experiment confirming it can be performed''.

Now suppose $f : X \to Y$ is a map between topological spaces and $U \subseteq
Y$ is open (verifiable). Imagine we can implement $f$ on a computer or as a
physical process. For every $x \in X$, $x \in f^{-1}(U)$ is equivalent to
$f(x) \in U$. This means that $x \in f^{-1}(U)$ is verifiable: just verify
$f(x) \in U$ instead. In other words, the inverse image $f^{-1}(U)$ is open if
$U$ is open, which is the definition of continuity of~$f$. This is summarized
by our second slogan
%
\begin{quote}
  \emph{``Computable functions are continuous.''}
\end{quote}

\begin{exercise}
  Show that verifiable properties are closed under finite intersections. Are
  they closed under infinite unions?
\end{exercise}

\section{Compactness}
\label{sec:compactness}

The standard definition of compactness is as follows.

\begin{definition}
  A topological space~$X$ is \emph{compact} when every open cover of~$X$ has a
  finite subcover.
\end{definition}

Our aim is to give the concept of compactness a computational interpretation,
just like we did for open sets and continuous maps above. We first rephrase
this definition in terms of directed open covers. A family $\mathcal{S} =
\set{S_i \such i \in I}$ of sets is \emph{directed} when $I$ is non-empty and
for all $i, j \in I$ there is $k \in I$ such that $S_i \subseteq S_k$ and $S_j
\subseteq S_k$.

\begin{exercise}
  Suppose $\mathcal{S} = \set{S_i \such i \in I}$ is a directed family of
  sets. Show that for any finite number of members $S_{i_1}, \ldots, S_{i_n}
  \in \mathcal{S}$, there is some $S_j \in \mathcal{S}$ which contains them
  all.
\end{exercise}

\begin{exercise} Suppose $\mathcal{S} = \set{S_i \such i \in I}$ is an
  arbitrary family of sets. Show that the family formed by taking all finite
  unions of the $S_i$'s, including the empty one,
  %
  \begin{equation*}
    \mathcal{T} =
    \set{U_{i_1} \cup \cdots \cup U_{i_n} \such n \geq 0 \land i_1, \ldots, i_n \in I}
  \end{equation*}
  %
  is directed and that $\bigcup \mathcal{S} = \bigcup \mathcal{T}$.
\end{exercise}

\begin{proposition}
  \label{proposition:compact-directed-cover} A topological space~$X$ is
  \emph{compact} if, and only if, every directed open cover of~$X$ contains
  $X$ as a member.
\end{proposition}

\begin{proof} Suppose $X$ is compact and let $\set{U_i \such i \in I}$ is a
  directed open cover. There exist $i_1, \ldots, i_n \in I$ such that
  $\set{U_{i_1}, \ldots, U_{i_n}}$ already cover~$X$. By directedness there
  exists $j \in I$ such that $U_j$ contains $U_{i_1}, \ldots, U_{i_n}$, but
  then $U_j = X$.

  Conversely, suppose every directed open cover of~$X$ contains $X$ as a
  member, and let $\set{U_i \such i \in U}$ be any open cover of~$X$. We form
  a new cover which consists of all finite unions of $U_i$'s, including the
  empty union:
  %
  \begin{equation*}
    \set{U_{i_1} \cup \cdots \cup U_{i_n} \such n \geq 0 \land i_1, \ldots, i_n \in I}.
  \end{equation*}
  %
  This is a directed open cover of~$X$, hence it has a member $U_{i_1} \cup
  \cdots \cup U_{i_n}$ which is equal to~$X$. Thus the original open cover has
  the finite subcover $\set{U_{i_1}, \ldots, U_{i_n}}$.
\end{proof}

Let $X$ be a topological space and $\tpl{X} = \set{U \subseteq X \such
  \text{$U$ is open}}$ its topology. The set $\tpl{X}$ can be considered as a
topological space, too! Say that $\scr{U} \subseteq \tpl{X}$ is \emph{Scott
  open} when
%
\begin{enumerate}
\item it is an \emph{upper set:} if $U \in \scr{U}$ and $U \subseteq V \in
  \tpl{X}$ then $V \in \scr{U}$,
\item it is \emph{inaccessible by directed families}: if $\set{U_i \such i \in
    I}$ is a directed family of open sets in~$X$ and $\bigcup_{i \in I} U_i
  \in \scr{U}$ then there is $i \in I$ such that $U_i \in \scr{U}$.
\end{enumerate}

\begin{exercise}
  Verify that the family of all Scott open sets forms a topology on $\tpl{X}$.
\end{exercise}

We call the family of all Scott open subsets of~$\tpl{X}$ the \emph{Scott
  topology}. Henceforth, whenever $\tpl{X}$ is viewed as a topological space
we mean the Scott topology.

\begin{proposition}
  \label{proposition:compact-top-open}
  A topological space~$X$ is compact if, and only if, $\set{X}$ is a Scott
  open subset of $\tpl{X}$.
\end{proposition}

\begin{proof}
  This is just Proposition~\ref{proposition:compact-directed-cover} rephrased
  in terms of Scott open sets.
\end{proof}

\begin{exercise}
  Write down enough details of the proof of
  Proposition~\ref{proposition:compact-top-open} to convince yourself that it
  holds.
\end{exercise}

The last proposition allows us to rephrase compactness in terms of verifiable
properties: a space is compact when ``holds for all $x \in X$'' is a
verifiable property of verifiable properties. Admittedly, is a bit confusing,
so we seek another characterization.

A third way to characterize compact spaces involves the \emph{Sierpinski
  space} $\Sigma = \set{\bot, \top}$ which has two points and the open sets
$\emptyset$, $\set{\top}$ and $\set{\bot, \top}$.

\begin{exercise}
  Find all the ways to equip the set $\set{\bot, \top}$ with a topology. How
  many non-homeomorphic ones are there?
\end{exercise}

\begin{exercise}
  Show that $\Sigma$ is homeomorphic to the topological space
  $\tpl{\set{\star}}$, where $\set{\star}$ is a singleton space.
\end{exercise}

\begin{exercise}
  How many maps $\Sigma \to \Sigma$ are there? How many are continuous?
\end{exercise}

\begin{proposition}
  \label{proposition:map-sigma-continuous}
  A map $f : X \to \Sigma$ is continuous if, and only if, $f^{-1}(\set{\top})$
  is open in~$X$.
\end{proposition}

\begin{proof}
  $\Sigma$ only has three open sets. The inverse images $f^{-1}(\emptyset) =
  \emptyset$ and $f^{-1}(\Sigma) = X$ of two of them are always open, which
  leaves us with checking just the third one, $f^{-1}(\set{\top})$.
\end{proof}

The previous proposition tells us that there is a bijection between $\tpl{X}$
and continuous maps $X \to \Sigma$. In one direction the bijection maps an
open subset $U \subseteq X$ to its \emph{characteristic map} $\chi_U : X \to
\Sigma$, defined by
%
\begin{equation*} \chi_U(x) =
  \begin{cases} \top & \text{if $x \in U$,}\\ \bot & \text{otherwise.}
  \end{cases}
\end{equation*}
%
In the other direction a continuous map $f : X \to \Sigma$ corresponds to the
open subset $f^{-1}(\set{\top})$.

\begin{proposition}
  \label{proposition:compact-iff-forall-continuous}
  A topological space $X$ is compact if, and only if, the map $\forall_X :
  \tpl{X} \to \Sigma$, defined by
  %
  \begin{equation*} \forall_X(U) =
    \begin{cases} \top & \text{if $U = X$,}\\ \bot & \text{otherwise}
    \end{cases}
  \end{equation*}
  %
  is continuous.
\end{proposition}

\begin{proof} By Proposition~\ref{proposition:map-sigma-continuous} continuity
of~$\forall_X$ is equivalent to $\forall_X^{-1}(\set{\top}) = \set{X}$ being
open, which in turn is equivalent to~$X$ being compact by
Proposition~\ref{proposition:compact-top-open}.
\end{proof}

If we turn around the second slogan for a moment,
Proposition~\ref{proposition:compact-iff-forall-continuous} suggests that we
should be able to compute the map $\forall_X$ when $X$ is compact. To explain
what that means precisely, we need to say a few words about how topological
spaces are represented in a programming language.

\section{Representations of spaces}
\label{sec:representations}

A topological space $X$ is an abstract set. In a programming language
it is represented by a suitable datatype $\mathtt{X}$ whose values
represent points of $X$. The relationship between $X$ and $\mathtt{X}$
is expressed as a \emph{realizability} relation $\rz_X$ which relates
values of type~$\mathtt{X}$ to point of $X$. For $\R{r} : \mathtt{X}$
and $a \in X$ we read $\R{r} \rz_X a$ as ``the value $\R{r}$ realizes,
or represents, the point $a$''. We require that each point have at
least one realizer. The triple $(X, \mathtt{X}, {\rz_X})$ is called an
\emph{assembly}. Note that some values of type $\mathtt{X}$ may
represent nothing, and that a point of~$X$ may have many
representations.

A map $f : X \to Y$ is \emph{realized} or represented by a value $\R{f}$ of
type $\mathtt{X} \to \mathtt{Y}$ which \emph{tracks}~$f$:
%
\begin{equation*}
  \text{if $\R{a} \rz_X a$ then $\R{f}\;\R{a} \rz_Y f(a)$.}
\end{equation*}
%
This is just a formal definition of the informal idea of what it means
to ``implement'' an abstract function between two sets.

We adopt the notational convention that datatypes and realizers are written in
typewriter font. For example, if $X$ is the underlying set of an assembly, $a
\in X$, and $f : X \to Y$ a realized map, the corresponding datatype and
realizers are $\mathtt{X}$, $\R{a}$, and $\R{f}$, respectively.

In these notes we want to focus on topology and programming, so we
shall keep assemblies and realized maps in the background as much as
possible. However, it is useful to know that there is a precise
mathematical connection bewtween topology and programming.\footnote{To
  be honest we should point out that realizability is not the only one
  way of relating topology with programming.}

\section{Searchable spaces}
\label{sec:searchable-spaces}

To sensibly talk about computability of the operator $\forall_X : \tpl{X} \to
\Sigma$, we should represent $X$ by a datatype $\mathtt{X}$ (and a
corresponding realizability relation $\rz_X$), and similarly represent
$\Sigma$ by a suitably chosen datatype $\mathtt{S}$. The topology $\tpl{X}$ is
represented by the type $\mathtt{X} \to \mathtt{S}$ because $\tpl{X}$ is in
bijective correspondence with continuous maps $X \to \Sigma$. Hence,
$\forall_X$ is computable if there is a value
%
\begin{equation*} \R{forall} : (\mathtt{X} \to \mathtt{S}) \to \mathtt{S},
\end{equation*}
%
which tracks it, i.e., for all $\R{p}$ of type $\mathtt{X} \to \mathtt{S}$ and
all continuous maps $p : X \to \Sigma$,
%
\begin{equation*} \text{if $\R{p} \rz_{X \to \Sigma} p$ then
$\R{forall}\;\R{p} \rz_\Sigma \forall_X(p)$.}
\end{equation*}
%
There are several ways of representing $\Sigma$ by a datatype $\mathtt{S}$.
Because all of them are a bit unusual, we first focus on a related but simpler
case
%
\begin{equation}
  \label{eq:forall-bool} \mathtt{forall} : (\mathtt{X} \to \Bool) \to \Bool.
\end{equation}
%
The datatype $\Bool$ does \emph{not} represent~$\Sigma$ but the discrete
topological space $\two = \set{0, 1}$. Values of type $\mathtt{X} \to \Bool$
track continuous maps $X \to \two$. Because a map $f : X \to \two$ is
continuous if, and only if, $f^{-1}(\set{1})$ is clopen (closed and open), the
decidable properties correspond to clopen subsets.

\begin{exercise} Show that a map $f : X \to \two$ is continuous if, and only
if, $f^{-1}(\set{1})$ clopen.
\end{exercise}

\begin{exercise} Which properties of $\RR$ are decidable?
\end{exercise}
%
How could we implement the universal quantifier $\mathtt{forall}$? When $X$ is
finite, say $X = \set{a_1, \ldots, a_n}$ we can simply define
%
\begin{equation*} \forall_X(p) = p(a_1) \land p(a_2) \land \cdots \land
p(a_n),
\end{equation*}
%
which is easily implemented.
%
However, this would not work for infinite sets, where all the fun is. Instead,
we are going to use the notion of a \emph{searchable} space.

\begin{definition} A space $X$ is \emph{searchable} if there is a realized map
$\epsilon : (X \to \two) \to \two$ such that, for all $p : X \to \two$,
  %
  \begin{equation*} p (\epsilon(p)) \iff \xsome{x}{X}{p(x)}.
  \end{equation*}
\end{definition}

The operator $\epsilon$ takes as input a decidable property $p$ and returns a
candidate $\epsilon(p) \in X$ such that $p(\epsilon(p))$ holds. If there is no
$x \in X$ for which $p(x)$ holds, then $\epsilon(p)$ may be any element of
$X$. We emphasize that $\epsilon(p)$ \emph{must} return a candidate and is not
allowed to diverge. The operator $\epsilon$ is known as \emph{Hilbert's
operator}.

For a searchable space~$X$ the existential quantifer
%
\begin{equation*} \exists_X(p) = \begin{cases} 1, &\text{if
$\xsome{x}{X}{p(x)}$,}\\ 0, &\text{ otherwise.}
  \end{cases}
\end{equation*}
%
is easily implemented as
\begin{equation*} \exists_X(p) = p (\epsilon(p)).
\end{equation*}
%
As an added bonus, because $\xall{x}{X}{p(x)}$ is equivalent to
$\lnot\xsome{x}{X}{\lnot p(x)}$, we also get the universal quantifier
%
\begin{equation*} \forall_X(p) = \lnot \exists_X(\lnot p).
\end{equation*}
%
We should give a name to datatypes which have the existential quantifier.

\section{Overt spaces}
\label{sec:overt-spaces}

By symmetry there should be a topological notion that is dual to compactness,
as follows.

\begin{definition} A topological space $X$ is \emph{overt}\footnote{The term
``overt space'' was coined by Paul Taylor.} if the map $\exists_X : \tpl{X}
\to \Sigma$, defined by
  %
  \begin{equation*} \exists_X (U) =
    \begin{cases} \bot & \text{if $U = \emptyset$,}\\ \top & \text{otherwise.}
    \end{cases}
  \end{equation*}
  %
  is continuous.
\end{definition}

The following proposition is rather disappointing.

\begin{proposition} Every topological space is overt.
\end{proposition}

\begin{proof} By Proposition~\ref{proposition:map-sigma-continuous} we only
need to check that $\exists_X^{-1}(\set{\top}) = \tpl{X} \setminus
\set{\emptyset}$ is Scott open, which is easy. Clearly $\tpl{X} \setminus
\set{\emptyset}$ is an upper set, and if $\bigcup_{i \in I} U_i$ is non-empty
then at least one member $U_i$ must be non-empty.
\end{proof}

It would be \emph{wrong} to dismiss the notion of overtness just because it is
trivial in classical topology. As we shall see later, in computable topology
overtness is not only interesting but just as fundamental as compactness. We
now return to searchable spaces and their implementation.

\section{Implementation of searchable spaces}
\label{sec:implementation-searchable}

The code from this section is based on that of Martín Escardó's blog
post~\cite{escardo08:blog}. A searchable space is represented by a datatype
$\mathtt{X}$ and the $\epsilon$ operator, which we shall call $\R{epsilon}$ in
code. In Haskell we would define it like this:
%
\begin{lstlisting}
data Searchable a = Finder ((a -> Bool) -> a)
\end{lstlisting}
%
The first line defines a datatype $\mathtt{Searchable}\;\alpha$, where
$\alpha$ is a type parameter. An element of this datatype is of the
form $\mathtt{Finder}\;\epsilon$, where $\epsilon$ is a search
operator. Think of an element $\R{s}$ of type
$\mathtt{Searachable}\;\alpha$ as a searchable subspace of the
datatype~$\alpha$. The subspace is given in terms of its search
operator.

We define an auxiliary function $\mathtt{find}$, so that we can
conveniently write $\R{find}\;\R{s}\R{p}$ and read it ``search in
space $\R{s}$ for a candidate satisfying $\R{p}$'':
%
\begin{lstlisting}
find :: Searchable a -> (a -> Bool) -> a
find (Finder epsilon) p = epsilon p
\end{lstlisting}
%
The function $\mathtt{find}$ always finds a candidate, which may or
may not satisfy the given condition. It is convenient have another
function $\mathtt{search}$ which returns $\mathtt{Nothing}$ or
$\mathtt{Just}\;x$ depending on whether there is an $x$ satisfying the
given condition:
%
\begin{lstlisting}
search :: Searchable a -> (a -> Bool) -> Maybe a
search s p =
    let x = find s p
    in if p x then Just x else Nothing
\end{lstlisting}
%
And here are the quantifiers:
%
\begin{lstlisting}
exists s p = p (find s p)
forall s p = not (exists s (not . p))
\end{lstlisting}
%
Now we actually define some searchable spaces. The easiest is the singleton
space $\set{x}$ where the only candidate is $x$:
%
\begin{lstlisting}
singleton x = Finder (\p -> x)
\end{lstlisting}
%
In Haskell the notation \texttt{\char92 x -> e} means ``the function which
maps $x$ to $e$''. Thus we read the definition above as ``the constant
function which maps every $p$ to $x$''.
%
For a space with two points $\set{x, y}$ the $\epsilon$ operator needs to
check first whether $p(x)$ holds:
%
\begin{lstlisting}
doubleton x y = Finder (\p -> if p x then x else y)
\end{lstlisting}
%
The generalization of singletons and doubletons are finite sets. Given a list
of elements $[x_1, \ldots, x_n]$, we construct the searchable space $\set{x_1,
  \ldots, x_n}$:
%
\begin{lstlisting}
finite_set :: [a] -> Searchable a

finite_set lst = Finder (\p ->
    let loop []     = undefined
        loop [x]    = x
        loop (x:xs) = if p x then x else loop xs
    in loop lst)
\end{lstlisting}
%
Note that \texttt{finite\_set\;[]} is undefined because the empty set is not
searchable.
%
There are many other constructions of searchable spaces, such as the disjoint
sum:\footnote{In Haskell the disjoint sum $X + Y$ is the datatype
  $\mathtt{Either}\;X\;Y$, and the canonical inclusions are called
  $\mathtt{Left}$ and $\mathtt{Right}$, respectively.}
%
\begin{lstlisting}
sum s t = Finder (\p -> let x = Left (find s (p . Left))
                            y = Right (find t (p . Right))
                        in if p x then x else y)
\end{lstlisting}
%
A more complicated operation is a union of a searchable family of
searchable (sub)spaces. Suppose $I$ is a searchable space and
${S_i}_{i \in I}$ a family of searchable subspaces, $S_i \subseteq X$.
Then their union $S = \bigcup_{i \in I} S_i$ is also searchable, with
the search operator defined as follows:
%
\begin{equation*}
  \epsilon_S(p) = \text[not finished]
\end{equation*}
%
To get things organized, we shall define a \emph{search monad} which
will significantly simplify the code we have to write.\footnote{If you
  are not familiar with Haskell monads, you should now read
  Appendix~\ref{app:monads}.}

% BIBLIOGRAPHY (fold)

\bibliographystyle{plain}
\bibliography{../realizability,../cca,../notes}

% bibliogprahy (end)
\appendix

\section{Haskell monads by examples} % (fold)
\label{app:monads}

There are any number of introductions on monads written by Haskell bloggers
around the internet. You may want to look at some of them for further insight.
We shall introduce monads by examples.

Haskell is a purely functional language. In particular, it does not allow
direct invocation of any operations that would allow us to detect the order of
evaluation. This rules out mutable variables, exceptions, I/O, and many other
useful programming concepts. All these can be put back into Haskell with a
clever way of programming known as \emph{monadic style}.

Our first example is a very simple kind of exception which is sometimes known
as \emph{abort}. It is an operation which aborts whatever is being computed
and cannot be intercepted. To have something like that in Haskell, we need to
be explicit about values which may trigger abort. So we define a datatype
$\mathtt{Abortable}\;t$ which means ``either an ordinary value of type $t$, or
a special value $\mathtt{Aborted}$ indicating that abort
happened'':\footnote{the $\mathtt{deriving}$ clause is of no concern right
  now, it means Haskell will automatically derive a way of showing abortable
  values on screen}

\begin{lstlisting}
data Abortable t = Value t | Aborted
                   deriving Show
\end{lstlisting}
%
The constant $\mathtt{Aborted}$ signifies a value whose computation was
aborted. The other possibility is a value of the form $\mathtt{Value}\;v$,
which signifies a successfully computed value $v$ (abort did not happen).
Haskell insists that we write $\mathtt{Value}\;v$ rather than just $v$. This
way it can tell the difference between ordinary values and values that could
have been aborted but were not.

An ordinary value $v$ of type $t$ may always be converted to an abortable
value $\mathtt{Value}\;v$ of type $\mathtt{Abortable}\;t$. The operation that
does this is called $\mathtt{return}$ in Haskell and is the first half of a
monad. The second half of a monad is an operation \cc{>>=}, called
\emph{bind}, which combines an abortable value
%
\begin{lstlisting}
x :: Abortable
\end{lstlisting}
%
and a function
\begin{lstlisting}
f :: a -> Abortable b
\end{lstlisting}
%
which expects an ordinary value and outputs an abortable one. This is written
as
%
\begin{lstlisting}
x >>= f
\end{lstlisting}
%
What should \cc{x >>= f be}? Well, if \cc{x} is \cc{Aborted} then \cc{x >>=} f
must also be \cc{Aborted} (we want \cc{Aborted} to act as an uncatchable
exception). If \cc{x} is of the form \cc{Value v} then \cc{x >>= f} should be
\cc{f v}. This brings us to the official monad definition:
%
\begin{lstlisting}
instance Monad Abortable where
   return v        = Value v
   Aborted >>= f   = Aborted
   (Value v) >>= f = f v
\end{lstlisting}
%
In principle we can use \cc{return} and \cc{>>=} to compute with abortable
values, but it is very cumbersome. For example, suppose we have a division
operation whose result is an abortable integer,
%
\begin{lstlisting}
divide :: Int -> Int -> Abortable Int
divide x 0 = Aborted
divide x y = Value (x `div` y)
\end{lstlisting}
%
In order to compute the function which maps $x$ and $y$ to $x/y + y/x$ we have
to write
%
\begin{lstlisting}
f :: Int -> Int -> Abortable Int
f x y = (divide x y) >>= (\u -> (divide y x) >>= (\v -> return (u + v)))
\end{lstlisting}
%
With good indentation it is possible to improve the code a bit:
%
\begin{lstlisting}
g :: Int -> Int -> Abortable Int
g x y = (divide x y) >>= (\u ->
        (divide y x) >>= (\v ->
        return (u + v)))
\end{lstlisting}
%
This we can read as: feed the abortable value \cc{divide x y} into \cc{u},
feed the abortable value \cc{divide y x} into \cc{v}, then \cc{return} the
abortable value \cc{u+v}. The operator \cc{>>=} makes sure that the whole
result is \cc{Aborted} if either \cc{u} or \cc{v} is. Haskell has special
notation which significantly improves the code:
%
\begin{lstlisting}
h :: Int -> Int -> Abortable Int
h x y = do u <- divide x y
           v <- divide y x
           return (u + v)
\end{lstlisting}
%
The functions \cc{g} and \cc{h} are the exact same thing written in different
notations.

The \cc{Abortable} monad is already built into Haskell, except it is called
the \cc{Maybe} monad. Instead of \cc{Value v} and \cc{Aborted} it has \cc{Just
  v} and \cc{Nothing}. To give an example of its use, suppose we have an
association list
%
\begin{lstlisting}
lst = [("apple", 3), ("orange", 10), ("banana", 2), ("stone", 6)]
\end{lstlisting}
%
and would like to find the value corresponding to \cc{"orange"}. We can do
this by writing
%
\begin{lstlisting}
y = lookup "orange" lst -- y equals Just 10
\end{lstlisting}
%
The answer is \cc{Just 10}. If we lookup something that is not in the list we
get \cc{Nothing}:
%
\begin{lstlisting}
  z = lookup "cow" lst -- z equals Nothing
\end{lstlisting}
%
The monad and do notation come in handy if we have a piece of code that does
several lookups and we want it to fail as soon as one of the lookups fails,
e.g.
%
\begin{lstlisting}
sum = do u <- lookup "banana" lst
         v <- lookup "apple" lst
         w <- lookup "cherry" lst
         return (u + v + w)
\end{lstlisting}
%
The value of \cc{sum} is \cc{Nothing} because the third lookup fails. Had it
succeeded, we would get \cc{Just i} for some integer \cc{i}. Here is one way
of writing the same code without the do notation:
%
\begin{lstlisting}
sum' = case (lookup "banana" lst, lookup "apple" lst, lookup "cherry" lst) of
          (Just u, Just v, Just w) -> Just (u + v + w)
          (_, _, _) -> Nothing
\end{lstlisting}
%
You may judge for yourself which one is more readable.

The next example of a monad is non-deterministic choice operator. Suppose in a
computation we have choice points, at which we can choose any value from a
given list. Such a situation occurs when we perform a search over a tree, and
at each node we can choose one of the branches. We would like a convenient way
of programming choice points so that when we evaluate an expression with
choice points all possible combinations of choices are taken, and the possible
results are stored in a list.

First we define a datatype \cc{Choose t} which holds possible results of a
computation of type \cc{t} with choice points:
%
\begin{lstlisting}
data Choose t = Choices [t]
                deriving Show
\end{lstlisting}
%
For example, the value \cc{Choices [1,2,3]} means that the possible outcomes
are $1$, $2$, and $3$. To get a monad, we must define return, which converts
an ordinary value \cc{v} of type \cc{t} to one of type \cc{Choose t}. This
part is more or less obvious as we simply return \cc{Choices [v]}.
%
To define \cc{>>=} we have to think about how to combine a value
$\mathtt{Choices}\;[v, \ldots, v_n]$ with a function $f$ which accepts an
ordinary value v and returns some choices. It is not hard to see that we
should loop over $v_1, ..., v_n$, get all the different choices produced by
$f$ and combine them into a single choice. The end result is the following
monad
%
\begin{lstlisting}
instance Monad Choose where
     return v = Choices [v]
     (Choices lst) >>= f = Choices (combine f lst [])
         where combine f [] ws     = ws
               combine f (v:vs) ws = let Choices us = f v
                                     in combine f vs (ws ++ us)
\end{lstlisting}
%
Now we can use the do notation to write programs like this:
%
\begin{lstlisting}
-- all sums of the form x+y where x is 1,...,10 and y is 1,...,x.
c = do x <- [1..10]
       y <- [1..x]
       return (x + y)
-- c is Choices [2,3,4,4,5, ..., 18,19,20] (55 elements)
\end{lstlisting}
%
Without the do notation we would have to have a double loop of some kind. The
monad we just considered is also built into Haskell, and is known as the
\emph{list monad}. Possible choices are represented as a list, so we can write
$[x_1, \ldots, x_n]$ rather than $\mathtt{Choices}\; [x_1, \ldots, x_n]$:
%
\begin{lstlisting}
-- all sums of the form x+y where x is 1,...,10 and y is 1,...,x.
d = do x <- [1..10]
       y <- [1..x]
       return (x + y)
-- d is [2,3,4,4,5, ..., 18,19,20] (55 elements)
\end{lstlisting}

Our last example is the state monad. In procedural programming languages we
have variables that can be updated, i.e., their values change as computation
progresses. We say that the computation is \emph{stateful} because it depends
on the state of the variables, and it may change the state of the variable.

In general, stateful computation is a function which accepts the current state
and returns a result together with the new state. That is, in Haskell a
stateful computation computing a result of type \cc{t} and having access to
state of type \cc{s} is a function \cc{s -> (t, s)} which accepts the current
state \cc{m}, and returns a pair \cc{(x,m')} representing the computed value
\cc{x} and the new state \cc{m'}.
%
We define a Haskell type of such stateful computations:
%
\begin{lstlisting}
data State s t = Stateful (s -> (t, s))
\end{lstlisting}
%
Here is an example of a stateful computation:
%
\begin{lstlisting}
incr = Stateful $ \m -> (m, m+1)
\end{lstlisting}
% $
By the way, the mysterious \$ does nothing, except it allows us to write fewer
parenthesis. The meaning of \cc{f \$ x} is the same as \cc{f x}, except that
\cc{\$} is an infix operator with low precedence. If we wrote \cc{incr}
without \$, we would have to write \cc{Stateful (\m -> (m, m+1))}.

The definition of \cc{incr} is read as follows: \cc{incr} is a stateful
computation which takes a memory location \cc{m} and returns the current value
of \cc{m}. It also increases the memory location by \cc{1}. In other words,
this would be written as \cc{m++} in C.

But how do we actually execute \cc{incr}? We give it the initial value of the
memory location and out comes the result together with updated memory:
%
\begin{lstlisting}
(r1,m1) = let Stateful v = incr in v 42 -- r1 is 42, m1 is 44
\end{lstlisting}
%
This is quite ugly, so we define an auxiliary function
%
\begin{lstlisting}
run m (Stateful v) = v m
\end{lstlisting}
%
Now we can write
%
\begin{lstlisting}
(r2, m2) = run 42 incr -- r2 is 42, m2 is 44
\end{lstlisting}
%
and read it as ``run \cc{incr} with initial state 42''. Let us also define the state monad:
%
\begin{lstlisting}
instance Monad (State s) where
     return x = Stateful $ \m -> (x, m)
     v >>= f  = Stateful $ \m -> let (x, m') = run m v in run m' (f x)
\end{lstlisting}
% $
Return converts a pure (non-stateful) value to a stateful one that doesn't change the state:
The operation \cc{>>=} chains together stateful computations:
%
To compute \c{v >>= f} in state \c{m} we first run \c{v} in state \c{m} to
obtain a result \c{x} and the new state \c{m'}. We then compute \c{f x} in
state \c{m'}. This is all good and well, but the do notation does not allow us
to manipulate the state, so we also need basic operations that
do:\footnote{The Haskell value \cc{()} is the empty tuple, the equivalent of
  \cc{void} in C++ and Java.}
%
\begin{lstlisting}
get = Stateful $ \m -> (m, m)        -- get the current value of state
update n = Stateful $ \m -> ((), n)  -- update state to n, give () as result
\end{lstlisting}
%
With this we may write procedural program:
%
\begin{lstlisting}
a = run 42 (do x <- get        -- let x be current value of memory (42)
               update (x+1)    -- update memory to x+1 (43)
               y <- get        -- let y be current value of memory (43)
               update 7        -- update memory to 7
               return (x + y)) -- return x+y (42+43 = 85)
-- a is (85, 7)
\end{lstlisting}
%
Let us conclude this short introduction by giving the official equations that
\cc{return} and \cc{>>=} must satisfy in order to deserve the name
\emph{monad}:
%
\begin{align*}
  \mathtt{return}\; a \bind k &= k\; a \\
  m \bind \mathtt{return}              &=   m \\
  m \bind (\backslash x -> k x \bind h)   &=   (m \bind k) \bind h
\end{align*}
%
Further reading:
%
\begin{enumerate}
\item  \url{http://www.haskell.org/tutorial/monads.html}:
  ``A Gentle Introduction to Haskell'', Chapter 9: About Monads
\item \url{http://www.haskell.org/all_about_monads/html/index.html}
  ``All about Monads:
  A comprehensive guide to the theory and practice of monadic programming in Haskell''
\item \url{http://blog.sigfpe.com/}
  ``A neighborhood of infinity''.
  Dan Piponi's blog has many clever and mind boggling examples of monads.
\end{enumerate}
% section haskell_monads_by_examples (end)
\end{document}


\documentclass[a4paper,12pt]{article}
\usepackage{cdblatex}
\usepackage{hyperref}
\usepackage{geometry}
\usepackage{summary}
\usepackage{config}

\geometry{a4paper,landscape,margin=2cm}
% \geometry{a4paper,portrait,margin=2cm}
\hypersetup{colorlinks=true}% use false for journals and paper
\numberwithin{equation}{section}% requires amsmath

\begin{document}

% =================================================================================================
\section*{Notes}

The convention for the curvature used in these notes conforms to that of Misner-Thorne-Wheeler
(MTW, eq. 11.12) , namely
\begin{align*}
   V^{a}{}_{;bc} - V^{a}{}_{;cb} = - R^{a}{}_{dbc} V^{d}
\end{align*}

Also, note the following shorthand for mixed covariant derivatives
\begin{align*}
   \nabla_a\left(\nabla_b\right) &= \nabla_{ab}\\
   \nabla_a\left(\nabla_b\left(\nabla_c\right)\right) &= \nabla_{abc}\\
   \nabla_a\left(\nabla_b\left(\nabla_c\left(\nabla_d\right)\right)\right) &= \nabla_{abcd}
\end{align*}
and so on.

See for example the Python function {\tts combine_nabla} in {\tts cadabra/dRabcd.tex}.

In terms of $\nabla$ the above MTW definition of $R^{a}{}_{bcd}$ can written as
\begin{align*}
   \left(\nabla_{cb}-\nabla_{bc}\right) V^{a} = - R^{a}{}_{dbc} V^{d}
\end{align*}

% -------------------------------------------------------------------------------------------------
\subsection*{Symmetrisation}
\input{lib/dGamma.cdbtex}

In the following pages there will be frequent constructions of the form
\begin{dgroup*}
   \begin{dmath*}  3 A^b A^c\Gamma^a{}_{d(b,c)} = \cdb{scaled1.002} \end{dmath*}
   \begin{dmath*}  6 A^b A^c A^e \Gamma^a{}_{d(b,ce)} = \cdb{scaled2.002} \end{dmath*}
   \begin{dmath*} 15 A^b A^c A^e A^f \Gamma^a{}_{d(b,cef)} = \cdb{scaled3.002} \end{dmath*}
\end{dgroup*}
The vector $A^{a}$ has no special meaning. Its purpose is to indicate that the
associciated tensor is symmetric over a selection of its indices. If the $A^{a}$ were not included
then the right hand side would either need to be spelt out in full or some other device would
be needed to denote the symmetries. The symmetrisation brackets are included on the left hand
side though they are redundant (in the presence of the $A^{a}$).

\clearpage

% =================================================================================================
\section*{The metric in RNC}
\input{lib/metric.cdbtex}

\begin{dgroup*}
   \begin{dmath*} g_{a b}(x) = \cdb{Metric.601}+\BigO{\eps^6} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Curvature expansion of the metric}
\begin{align*}
     g_{a b}(x) =
     \ngab{0}_{a b}
   + \ngab{2}_{a b}
   + \ngab{3}_{a b}
   + \ngab{4}_{a b}
   + \ngab{5}_{a b}+\BigO{\eps^6}
\end{align*}
\begin{dgroup*}
   \begin{dmath*}     \ngab{0}_{a b} = \cdb{scaled0.601} \end{dmath*}
   \begin{dmath*}   3 \ngab{2}_{a b} = \cdb{scaled2.601} \end{dmath*}
   \begin{dmath*}   6 \ngab{3}_{a b} = \cdb{scaled3.601} \end{dmath*}
   \begin{dmath*} 180 \ngab{4}_{a b} = \cdb{scaled4.601} \end{dmath*}
   \begin{dmath*}  90 \ngab{5}_{a b} = \cdb{scaled5.601} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{The inverse metric in RNC}
\input{lib/metric-inv.cdbtex}

\begin{dgroup*}
   \begin{dmath*} g^{a b}(x) = \cdb{Metric.601}+\BigO{\eps^6} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Curvature expansion of the inverse metric}
\begin{align*}
     g^{a b}(x) =
     \ngab{0}^{a b}
   + \ngab{2}^{a b}
   + \ngab{3}^{a b}
   + \ngab{4}^{a b}
   + \ngab{5}^{a b}+\BigO{\eps^6}
\end{align*}
\begin{dgroup*}
   \begin{dmath*}    \ngab{0}^{a b} = \cdb{scaled0.601} \end{dmath*}
   \begin{dmath*}  3 \ngab{2}^{a b} = \cdb{scaled2.601} \end{dmath*}
   \begin{dmath*}  6 \ngab{3}^{a b} = \cdb{scaled3.601} \end{dmath*}
   \begin{dmath*} 60 \ngab{4}^{a b} = \cdb{scaled4.601} \end{dmath*}
   \begin{dmath*} 90 \ngab{5}^{a b} = \cdb{scaled5.601} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{The metric determinant in RNC}
\input{lib/detg2.cdbtex}

\begin{dgroup*}
   \Dmath*{-\det g(x) = \cdb{Ndetg.701}+\BigO{\eps^6}}
\end{dgroup*}

% =================================================================================================
\section*{The metric Jacobian in RNC}

\begin{dgroup*}
   \Dmath*{\sqrt{-\det g(x)} = \cdb{sqrtNdetg.801}+\BigO{\eps^6}}
\end{dgroup*}

% =================================================================================================
\section*{The log of detg in RNC}

\begin{dgroup*}
   \Dmath*{\log\left(-\det g(x)\right) = \cdb{logNdetg.901}+\BigO{\eps^6}}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{The connection in RNC}
\input{lib/connection.cdbtex}

\begin{dgroup*}
   \begin{dmath*} A^a A^b \Gamma^{d}_{a b} = \cdb{Gamma.301} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} 360 A^a A^b \Gamma^{d}_{a b} = \cdb{Scaled.301} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Curvature expansion of the connection}
\begin{align*}
     A^a A^b \Gamma^{d}_{a b} =
     A^a A^b \nGamma{2}^{d}{}_{a b}
   + A^a A^b \nGamma{3}^{d}{}_{a b}
   + A^a A^b \nGamma{4}^{d}{}_{a b}
   + A^a A^b \nGamma{5}^{d}{}_{a b}+\BigO{\eps^6}
\end{align*}
\begin{dgroup*}
   \begin{dmath*}   3 A^a A^b \nGamma{2}^{d}_{a b} = \cdb{scaled2.301} \end{dmath*}
   \begin{dmath*}  12 A^a A^b \nGamma{3}^{d}_{a b} = \cdb{scaled3.301} \end{dmath*}
   \begin{dmath*} 360 A^a A^b \nGamma{4}^{d}_{a b} = \cdb{scaled4.301} \end{dmath*}
   \begin{dmath*} 180 A^a A^b \nGamma{5}^{d}_{a b} = \cdb{scaled5.301} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Symmetrised partial derivatives of the connection}
\input{lib/dGamma.cdbtex}

\begin{dgroup*}
   \begin{dmath*}   3 A^b A^c\Gamma^a{}_{d(b,c)} = \cdb{scaled1.002} \end{dmath*}
   \begin{dmath*}   6 A^b A^c A^e \Gamma^a{}_{d(b,ce)} = \cdb{scaled2.002} \end{dmath*}
   \begin{dmath*}  15 A^b A^c A^e A^f \Gamma^a{}_{d(b,cef)} = \cdb{scaled3.002} \end{dmath*}
   \begin{dmath*}   9 A^b A^c A^e A^f A^g \Gamma^a{}_{d(b,cefg)} = \cdb{scaled4.002} \end{dmath*}
   \begin{dmath*} 252 A^b A^c A^e A^f A^g A^h\Gamma^a{}_{d(b,cefgh)} = \cdb{scaled5.002} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Symmetrised partial derivatives of $R^a{}_{bcd}$}
\input{lib/dRabcd.cdbtex}

\begin{dgroup*}
   \begin{dmath*}    A^c A^d A^e R^a{}_{cdb,e} = \cdb{scaled1.601} \end{dmath*}
   \begin{dmath*}    A^c A^d A^e A^{f} R^a{}_{cdb,ef} = \cdb{scaled2.601} \end{dmath*}
   \begin{dmath*} -2 A^c A^d A^e A^{f} A^{g} R^a{}_{cdb,efg} = \cdb{scaled3.601} \end{dmath*}
   \begin{dmath*} -5 A^c A^d A^e A^{f} A^{g} A^{h} R^a{}_{cdb,efgh} = \cdb{scaled4.601} \end{dmath*}
   \begin{dmath*} -3 A^c A^d A^e A^{f} A^{g} A^{h} A^{i}R^a{}_{cdb,efghi} = \cdb{scaled5.601} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{The generalised connection in RNC}
\input{lib/genGamma.cdbtex}

\begin{dgroup*}
   \begin{dmath*} A^b A^c \Gamma^{a}_{b c} = \cdb{genGamma0.000} \end{dmath*}
   \begin{dmath*} A^b A^c A^d \Gamma^{a}_{b c d} = \cdb{genGamma1.000} \end{dmath*}
   \begin{dmath*} A^b A^c A^d A^e \Gamma^{a}_{b c d e} = \cdb{genGamma2.000} \end{dmath*}
   \begin{dmath*} A^b A^c A^d A^e A^f \Gamma^{a}_{b c d e f} = \cdb{genGamma3.000} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{The generalised connection in RNC}

This is the same as the previous page but with a small change in the format to avoid fractions.

\begin{dgroup*}
   \begin{dmath*} 360 A^b A^c \Gamma^{a}_{b c} = \cdb{scaledGamma0.001} \end{dmath*}
   \begin{dmath*} 360 A^b A^c A^d \Gamma^{a}_{b c d} = \cdb{scaledGamma1.001} \end{dmath*}
   \begin{dmath*}  90 A^b A^c A^d A^e \Gamma^{a}_{b c d e} = \cdb{scaledGamma2.001} \end{dmath*}
   \begin{dmath*}   3 A^b A^c A^d A^e A^f \Gamma^{a}_{b c d e f} = \cdb{scaledGamma3.001} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Convert from generic (x) to local RNC coords (y)}
\input{lib/gen2rnc.cdbtex}

\begin{align*}
   y^a = \ny{0}^{a} + \ny{1}^{a} + \ny{2}^{a} + \ny{3}^{a} + \ny{4}^{a}
\end{align*}

\begin{dgroup*}
   \begin{dmath*}     \ny{0}^{a} = \cdb{scaled1.002} \end{dmath*}
   \begin{dmath*}   2 \ny{1}^{a} = \cdb{scaled2.002} \end{dmath*}
   \begin{dmath*}   6 \ny{2}^{a} = \cdb{scaled3.002} \end{dmath*}
   \begin{dmath*}  24 \ny{3}^{a} = \cdb{scaled4.002} \end{dmath*}
   \begin{dmath*} 360 \ny{4}^{a} = \cdb{scaled5.002} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{The geodesic ivp}
\input{lib/geodesic-ivp.cdbtex}

\begin{align*}
   x^{a}(s) = x^{a}
            + s {\dot{x}^a}
            + \frac{s^2}{2!} {\dot{x}^b} {\dot{x}^c} A^{a}_{bc}
            + \frac{s^3}{3!} {\dot{x}^b} {\dot{x}^c} {\dot{x}^d} A^{a}_{bcd}
            + \frac{s^4}{4!} {\dot{x}^b} {\dot{x}^c} {\dot{x}^d} {\dot{x}^e} A^{a}_{bcde}
            + \frac{s^5}{5!} {\dot{x}^b} {\dot{x}^c} {\dot{x}^d} {\dot{x}^e} {\dot{x}^f} A^{a}_{bcdef}
            + \dotsb
\end{align*}
\begin{dgroup*}
   \begin{dmath*} 360 A^{a}_{bc} = \cdb{sterm2.002} \end{dmath*}
   \begin{dmath*} 360 A^{a}_{bcd} = \cdb{sterm3.002} \end{dmath*}
   \begin{dmath*}  90 A^{a}_{bcde} = \cdb{sterm4.002} \end{dmath*}
   \begin{dmath*}   3 A^{a}_{bcdef} = \cdb{sterm5.002} \end{dmath*}
\end{dgroup*}
\clearpage

% =================================================================================================
\section*{Geodesic boundary value problem to terms linear in $R$}
\input{lib/geodesic-bvp.cdbtex}

\begin{dgroup*}
   \begin{dmath*} x^{a}(s) = \cdb{bvp.601} + \BigO{s^3,\eps^3} \end{dmath*}
\end{dgroup*}

\begin{align*}
   x^{a}(s) &= x^{a} + s Dx^{a}
                     + (s-s^2) x^{a}_2
                     + \BigO{s^3,\eps^3}
\end{align*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_2 = \nx{2}^{a}_2 + \BigO{\eps^3} \end{dmath*}
   \begin{dmath*} -3 \nx{2}^{a}_2 = \cdb{Rterm22.102} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Geodesic boundary value problem to terms linear in $\nabla R$}

\begin{dgroup*}
   \begin{dmath*} x^{a}(s) = \cdb{bvp.602} + \BigO{s^4,\eps^4} \end{dmath*}
\end{dgroup*}

\begin{align*}
   x^{a}(s) &= x^{a} + s Dx^{a}
                     + (s-s^2) x^{a}_2
                     + (s-s^3) x^{a}_3
                     + \BigO{s^4,\eps^4}
\end{align*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_2 = \nx{2}^{a}_2 + \nx{3}^{a}_2 + \BigO{\eps^4} \end{dmath*}
   \begin{dmath*}   -3 \nx{2}^{a}_2 = \cdb{Rterm22.102} \end{dmath*}
   \begin{dmath*}  -24 \nx{3}^{a}_2 = \cdb{Rterm23.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_3 = \nx{3}^{a}_3 + \BigO{\eps^4} \end{dmath*}
   \begin{dmath*}   -12 \nx{3}^{a}_3 = \cdb{Rterm33.102} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Geodesic boundary value problem to terms linear in $\nabla^2 R$}

\begin{dgroup*}
   \begin{dmath*} x^{a}(s) = \cdb{bvp.603} + \BigO{s^5,\eps^5} \end{dmath*}
\end{dgroup*}

\begin{align*}
   x^{a}(s) &= x^{a} + s Dx^{a}
                     + (s-s^2) x^{a}_2
                     + (s-s^3) x^{a}_3
                     + (s-s^4) x^{a}_4
                     + \BigO{s^5,\eps^5}
\end{align*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_2 = \nx{2}^{a}_2 + \nx{3}^{a}_2 + \nx{4}^{a}_2 + \BigO{\eps^5} \end{dmath*}
   \begin{dmath*}   -3 \nx{2}^{a}_2 = \cdb{Rterm22.102} \end{dmath*}
   \begin{dmath*}  -24 \nx{3}^{a}_2 = \cdb{Rterm23.102} \end{dmath*}
   \begin{dmath*} -720 \nx{4}^{a}_2 = \cdb{Rterm24.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_3 = \nx{3}^{a}_3 + \nx{4}^{a}_3 + \BigO{\eps^5} \end{dmath*}
   \begin{dmath*}   -12 \nx{3}^{a}_3 = \cdb{Rterm33.102} \end{dmath*}
   \begin{dmath*}  -720 \nx{4}^{a}_3 = \cdb{Rterm34.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_4 = \nx{4}^{a}_4 + \BigO{\eps^5} \end{dmath*}
   \begin{dmath*}  -180 \nx{4}^{a}_4 = \cdb{Rterm44.102} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Geodesic boundary value problem to terms linear in $\nabla^3 R$}

The geodesic that connects the points with RNC coordinates $x^a$ and $x^a+Dx^a$ is described, for $0\le s\le 1$, by
%
% \begin{dgroup*}
%    \begin{dmath*} x^{a}(s) = \cdb{bvp.604} + \BigO{s^6,\eps^6} \end{dmath*} % too big for pdfLaTeX
% \end{dgroup*}
%
\begin{align*}
   x^{a}(s) &= x^{a} + s Dx^{a}
                     + (s-s^2) x^{a}_2
                     + (s-s^3) x^{a}_3
                     + (s-s^4) x^{a}_4
                     + (s-s^5) x^{a}_5
                     + \BigO{s^6,\eps^6}
\end{align*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_2 = \nx{2}^{a}_2 + \nx{3}^{a}_2 + \nx{4}^{a}_2 + \nx{5}^{a}_2 + \BigO{\eps^6} \end{dmath*}
   \begin{dmath*}   -3 \nx{2}^{a}_2 = \cdb{Rterm22.102} \end{dmath*}
   \begin{dmath*}  -24 \nx{3}^{a}_2 = \cdb{Rterm23.102} \end{dmath*}
   \begin{dmath*} -720 \nx{4}^{a}_2 = \cdb{Rterm24.102} \end{dmath*}
   \begin{dmath*} -360 \nx{5}^{a}_2 = \cdb{Rterm25.102} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} x^{a}_3 = \nx{3}^{a}_3 + \nx{4}^{a}_3 + \nx{5}^{a}_3 + \BigO{\eps^6} \end{dmath*}
   \begin{dmath*}   -12 \nx{3}^{a}_3 = \cdb{Rterm33.102} \end{dmath*}
   \begin{dmath*}  -720 \nx{4}^{a}_3 = \cdb{Rterm34.102} \end{dmath*}
   \begin{dmath*} -1080 \nx{5}^{a}_3 = \cdb{Rterm35.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_4 = \nx{4}^{a}_4 + \nx{5}^{a}_4 + \BigO{\eps^6} \end{dmath*}
   \begin{dmath*}  -180 \nx{4}^{a}_4 = \cdb{Rterm44.102} \end{dmath*}
   \begin{dmath*} -2160 \nx{5}^{a}_4 = \cdb{Rterm45.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} x^{a}_5 = \nx{5}^{a}_5 + \BigO{\eps^6} \end{dmath*}
   \begin{dmath*} -360 \nx{5}^{a}_5 = \cdb{Rterm55.102} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Geodesic arc-length}
\input{lib/geodesic-lsq.cdbtex}

\begin{dgroup*}[spread=5pt]
   % LCB: which of these is correct?
   % \begin{dmath*} \left(\Delta s\right)^2 = \cdb{lsq.301} + \BigO{\eps^6,Dx^6} \end{dmath*}
   % \begin{dmath*} \left(\Delta s\right)^2 = \cdb{lsq.301} + \BigO{\eps^6,Dx^7} \end{dmath*}
   \begin{dmath*} \left(\Delta s\right)^2 = \cdb{lsq.301} + \BigO{\eps^6} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Geodesic arc-length curvature expansion}

\begin{align*}
   % LCB: which of these is correct?
   % \left(\Delta s\right)^2 = \nD{0} + \nD{2} + \nD{3} + \nD{4} + \nD{5} + \BigO{\eps^6,Dx^6}
   % \left(\Delta s\right)^2 = \nD{0} + \nD{2} + \nD{3} + \nD{4} + \nD{5} + \BigO{\eps^6,Dx^7}
   \left(\Delta s\right)^2 = \nD{0} + \nD{2} + \nD{3} + \nD{4} + \nD{5} + \BigO{\eps^6}
\end{align*}

\begin{dgroup*}[spread=5pt]
   \begin{dmath*}      \nD{0} = \cdb{scaled0.301} \end{dmath*}
   \begin{dmath*}    3 \nD{2} = \cdb{scaled2.301} \end{dmath*}
   \begin{dmath*}   12 \nD{3} = \cdb{scaled3.301} \end{dmath*}
   \begin{dmath*}  360 \nD{4} = \cdb{scaled4.301} \end{dmath*}
   \begin{dmath*} 1080 \nD{5} = \cdb{scaled5.301} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Tranformation between two RNC frames}
\input{lib/rnc2rnc.cdbtex}

\begin{align*}
   y^{a} = \ny{0}^{a} + \ny{2}^{a} + \ny{3}^{a} + \ny{4}^{a} + \ny{5}^{a} + \BigO{\eps^6}
\end{align*}

\begin{dgroup*}
   \begin{dmath*} \ny{0}^{a} = Dx^{a} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \ny{2}^{a} = \ny{2}^{a}_1 \end{dmath*}
   \begin{dmath*}   3 \ny{2}^{a}_1 = \cdb{xDxterm12.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \ny{3}^{a} = \ny{3}^{a}_1 + \ny{3}^{a}_2 \end{dmath*}
   \begin{dmath*} -12 \ny{3}^{a}_1 = \cdb{xDxterm13.102} \end{dmath*}
   \begin{dmath*} -24 \ny{3}^{a}_2 = \cdb{xDxterm22.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \ny{4}^{a} = \ny{4}^{a}_1 + \ny{4}^{a}_2 + \ny{4}^{a}_3 \end{dmath*}
   \begin{dmath*} -180 \ny{4}^{a}_1 = \cdb{xDxterm14.102} \end{dmath*}
   \begin{dmath*} -720 \ny{4}^{a}_2 = \cdb{xDxterm23.102} \end{dmath*}
   \begin{dmath*} -720 \ny{4}^{a}_3 = \cdb{xDxterm32.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \ny{5}^{a} = \ny{5}^{a}_1 + \ny{5}^{a}_2 + \ny{5}^{a}_3 + \ny{5}^{a}_4 \end{dmath*}
   \begin{dmath*}  -360 \ny{5}^{a}_1 = \cdb{xDxterm15.102} \end{dmath*}
   \begin{dmath*} -2160 \ny{5}^{a}_2 = \cdb{xDxterm24.102} \end{dmath*}
   \begin{dmath*} -1080 \ny{5}^{a}_3 = \cdb{xDxterm33.102} \end{dmath*}
   \begin{dmath*}  -360 \ny{5}^{a}_4 = \cdb{xDxterm42.102} \end{dmath*}
\end{dgroup*}

\end{document}


\begin{intro}
  In this section, we develop error estimates of the following type
  \begin{verse}
    If the size of mesh cells converges to zero, then the difference
    between the true solution and the finite element solution
    converges to zero with a certain order.
  \end{verse}
  They are thus a prediction, that the solutions actually converge,
  and they measure the asymptotic convergence rate. They do contain
  unknown constants, such that they are no prediction of the error on
  a given mesh.

  The theory in this chapter is about bilinear forms which are bounded
  and elliptic on a subspace $V \subset H^1(\domain)$ determined by
  boundary conditions. We will choose $V = H^1_0(\domain)$, even if
  more general boundary conditions are possible. It is a good approach
  to think of the Dirichlet problem for the Laplacian, even if we
  allow for somewhat more general equations.
\end{intro}

\subsection{Approximation of Sobolev spaces by finite elements}

\begin{Lemma*}{poincare}{Poincaré inequality}
  Let $\domain$ be a bounded Lipschitz domain. For any function
  $u\in H^1(\domain)$ define
  \begin{gather}
    \overline u = \frac1{\abs{\domain}} \int_\domain u(\vx) \dvx,
  \end{gather}
  where $\abs{\domain}$ denotes the measure of $\domain$. There exists
  a constant $c$ depending on the domain only, such that each of the
  following inequalities hold:
  \begin{align}
    \norm{u-\overline u}_{L^2(\domain)} &\le c \norm{\nabla u}_{L^2(\domain)}\\
    \norm{u}_{L^2(\domain)}^2 &\le c \Bigl(\norm{\nabla u}_{L^2(\domain)}^2 + \overline u^2\Bigr)
  \end{align}
\end{Lemma*}

\begin{proof}
  The proof exceeds the tools we have developed in this class. The
  proof in \cite[Section 7.8]{GilbargTrudinger98} seems elementary and
  direct, but is technical and requires star-shaped domains. The proof
  in \cite[Section 5.8.1]{Evans98} is more elegant, but it uses
  compact embedding and is indirect, such that the constant cannot be
  determined.
\end{proof}

\begin{Lemma*}{bramble-hilbert}{Bramble-Hilbert}
  Let $\cell\subset \R^d$ be a domain with Lipschitz boundary and let
  $s(.)$ be a bounded sublinear functional on $H^{k+1}(\cell)$ with
  the property
  \begin{gather}
    s(p) = 0 \qquad\forall p\in \P_k.
  \end{gather}
  Then, there exists a constant $c$ only dependent on $\cell$ such that
  \begin{gather}
    \abs{s(v)} \le c \snorm{v}_{k+1,\cell}.
  \end{gather}
\end{Lemma*}

\begin{proof}
  Since $s(\cdot)$ is sublinear and vanishes on $\P_k$, we have for
  $v\in H^{k+1}(\cell)$:
  \begin{gather}
    \label{eq:bramble-hilbert-1}
    \abs{s(v)} \le \abs{s(v+p)} + \abs{s(p)} = \abs{s(v+p)}
    \qquad\forall p\in\P_k.
  \end{gather}
  We will construct a polynomial, such that
  \begin{gather}
    \label{eq:bramble-hilbert-2}
    \overline{\d^\alpha(v+p)}
    = \frac1{\abs{\cell}}\int_\cell \d^\alpha (v+p) \dx = 0
    \qquad\forall \abs{\alpha} \le k,
  \end{gather}
  that is, the sum $v+p$ and all its derivatives up to order $k$ are
  mean-value free. Thus, by recursive application of Poincaré
  inequality, we get for $\abs{\alpha}\le k$
  \begin{alignat*}2
    \norm{v+p}_{L^2(\cell)}^2
    &\le c \left[ \norm{\nabla(v+p)}_{L^2(\cell)}^2 + \overline{v+p}^2\right]
      && \le c \snorm{v+p}_{1;\cell}^2\\
    \norm{\d^\alpha(v+p)}_{L^2(\cell)}^2,
    &\le c \left[ \norm{\nabla\d^\alpha(v+p)}_{L^2(\cell)}^2
      + \overline{\d^\alpha(v+p)}^2\right]
      && \le c \snorm{v+p}_{\abs{\alpha}+1;\cell}^2,
  \end{alignat*}
  such that $\norm{v+p}_{k+1;\cell} \le \snorm{v+p}_{k+1;\cell}$.
  Furthermore, since $p\in\P_k$
  \begin{gather*}
    \norm{\d^\alpha(v+p)}_{L^2(\cell)} = \norm{\d^\alpha v}_{L^2(\cell)}
    \qquad\forall \abs{\alpha} = k+1.
  \end{gather*}
  Combining with~\eqref{eq:bramble-hilbert-1}, we obtain
  \begin{gather*}
    \abs{s(v)} \le c \snorm{v+p}_{k+1;\cell} \le c \snorm{v}_{k+1;\cell}.
  \end{gather*}
  It remains to construct the polynomial $p$ with the desired
  properties. To this end, we note that for two multi-indices $\alpha$
  and $\beta$ holds that $\d^\alpha \vx^\beta =0$ as soon as
  $\alpha_i>\beta_i$ for some index $i$. Let
  \begin{gather*}
    p(\vx) = \sum_{\abs{\beta}\le k} a_\beta \vx^\beta.
  \end{gather*}
  Then, for any $\abs{\alpha} = k$ we get
  \begin{gather*}
    \d^\alpha p(\vx) = \alpha! \,\delta_{\alpha\beta},
  \end{gather*}
  where $\alpha! = \alpha_1!\alpha_2!\dots\alpha_d!$. Thus, we can use
  condition~\eqref{eq:bramble-hilbert-2} to fix the coefficients
  $a_\beta$ to
  \begin{gather*}
    a_\beta = \frac1{\beta!\,\abs{\cell}} \int_\cell \d^\beta v\dx
    \qquad \abs{\beta} = k.
  \end{gather*}
  Thus, we have decomposed $p = \tilde p_k + p_{k-1}$, where
  $\tilde p_k$ is known and $p_{k-1}\in \P_{k-1}$. Thus, we can repeat
  the process determining the coefficients of highest order in
  $p_{k-1}$,
  \begin{gather*}
    a_\beta = \frac1{\beta!\,\abs{\cell}} \int_\cell \d^\beta (v-\tilde p_k)\dx
    \qquad \abs{\beta} = k-1.
  \end{gather*}
  Recursion down to $k=0$ yields the polynomial $p$ with the desired property.
\end{proof}

\begin{Corollary}{b-h-projector}
  Let $\Pi\colon H^{k+1}(\cell) \to \P_k$ be a continuous, linear
  projector. For any $m\le k$ there exists a constant $c$ such that
  \begin{gather}
    \norm{u-\Pi u}_{m,\cell} \le c \snorm{u}_{k+1,\cell}.
  \end{gather}
\end{Corollary}

\begin{Definition}{mesh-family}
  Let $\{\mesh_h\}$ for $h>0$ be a family of meshes parametrized by
  the parameter
  \begin{gather}
    h = \max_{\cell\in\mesh_h} h_\cell,
  \end{gather}
  where $h_\cell$ is the characteristic length from the discussion of
  mappings, for instance the diameter of $\cell$. Such a family is
  called \define{shape regular}, if the constants $M_\cell$,
  $m_\cell$, $d_\cell$, and $D_\cell$ in the scaling lemma
  can be chosen independent of the cell $\cell\in\mesh_h$ and of
  $h>0$. The family is called \define{quasi-uniform}, if in addition
  there is a positive constant independent of $h$ such that
  \begin{gather}
    h \le c \min_{\cell\in\mesh_h} h_\cell.
  \end{gather}
\end{Definition}

\begin{Definition}{nodal-interpolation}
  Let $V$ be a function space on $\domain$, and let
  $V_h = V_{\mesh_h}$ be a finite element space on the mesh $\mesh_h$
  on $\domain$ with node functionals $\nodal_i$ and dual basis $p_i$,
  where $i=1,\dots,n_h$. We define the \define{nodal interpolation}
  operator by
  \begin{gather}
    \begin{split}
      I_h\colon V&\to V_h\\
      v &\mapsto \sum \nodal_i(v)p_i.
    \end{split}
  \end{gather}
\end{Definition}

\begin{Lemma}{nodal-interpolation}
  The nodal interpolation operator $I_h$ is a projector. It is
  continuous on $H^2(\domain)$ if the dimension is $d=2,3$ and the
  node functionals are defined as Lagrange interpolation.
\end{Lemma}

\begin{Definition}{broken-sobolev-norm}
  On a mesh $\mesh_h$, we define the \define{broken Sobolev norm} and
  seminorm by
  \begin{gather}
    \begin{split}
      \norm{u}_{k;h}^2 &= \sum_{\cell\in\mesh_h} \norm{u}_{k;\cell}^2\\
      \snorm{u}_{k;h}^2 &= \sum_{\cell\in\mesh_h} \snorm{u}_{k;\cell}^2
    \end{split}
  \end{gather}
\end{Definition}

\begin{Theorem}{fe-interpolation}
  Let $\{\mesh_h\}$ be a shape regular family of meshes.
  Let the finite element spaces $V_h = V_{\mesh_h}$. Let the nodal
  interpolation operator $I_h$ be surjective onto $\P_k$ on every cell
  $\cell\in\mesh_h$ and continuous on $H^{k+1}(\domain)$. Then, there
  is a constant $c$ such that for any $u\in H^{k+1}(\domain)$ and
  $m\le k+1$ there holds
  \begin{gather}
    \label{eq:fe-interpolation}
    \norm{u-I_h u}_{m;h} \le c h^{k+1-m} \snorm{u}_{k+1;h}.
  \end{gather}
\end{Theorem}

\begin{proof}
  We have by definition
  \begin{gather*}
    \snorm{u-I_h u}_{m;h} = \sum_{\cell\in\mesh_h} \snorm{u-I_h u}_{m;\cell}.
  \end{gather*}
  Using the scaling lemma, we get
  \begin{gather*}
    \snorm{u-I_h u}_{m;\cell}
    \le c h_\cell^{\nicefrac d2-m} \snorm{\refu - \widehat{I_hu}}.
  \end{gather*}
  On the reference cell, we use the Bramble-Hilbert lemma, more
  precisely, \slideref{Corollary}{b-h-projector} to obtain
  \begin{gather*}
    \snorm{\refu - \widehat{I_hu}} \le c \snorm{\refu}_{k+1;\refcell}.
  \end{gather*}
  Scaling back yields
  \begin{gather*}
    \snorm{\refu}_{k+1;\refcell}
    \le c h_\cell^{k+1-\nicefrac d2} \snorm{u}_{k+1;\cell}.
  \end{gather*}
  Combining, we obtain
  \begin{gather*}
    \snorm{u-I_h u}_{m;\cell} \le c h_\cell^{k+1-\nicefrac d2 - m +
      \nicefrac d2}\snorm{u}_{k+1;\cell}.
  \end{gather*}
  Summing up and pulling the maximum of $h_\cell^{k+1-m}$ out of the
  sum yields the result for $h_\cell \le 1$.
\end{proof}

\begin{remark}
  Strictly speaking, we have only proven the result for $h_T \le
  1$.
  But then, if $\diam\domain = 1$, this condition is always
  true. Therefore, by rescaling the domain before computing, the
  estimate holds in general.
\end{remark}

\begin{Corollary}{fe-approximation}
  Let $a(.,.)$ be a bounded and elliptic bilinear form on
  $V = H^1_0(\domain)$ and let the finite element space $V_h$ be
  defined on a shape-regular family of meshes $\{\mesh_h\}$, such that
  the interpolation estimate~\eqref{eq:fe-interpolation} holds. If
  furthermore the solution $u\in H^{k+1}(\domain)$, the error of the
  finite element solution $u_h\in V_h \subset V$ admits the estimate
  \begin{gather}
    \norm{u-u_h}_{1;h} \le c h^{k} \snorm{u}_{k+1;h}.
  \end{gather}
\end{Corollary}

\begin{intro}
  For 2nd order elliptic problems, we have now derived estimates of
  the $H^1$-norm of the error under the assumption that the solution
  exhibits further regularity. Now, let us drop this assumptionfor an
  assumption on the boundary condition only, to obtain a qualitative
  convergence result.
\end{intro}

\begin{Theorem}{fe-convergence}
  Let $a(.,.)$ be a bounded and elliptic bilinear form on
  $V = H^1_0(\domain)$ and let the finite element space $V_h$ be
  defined on a shape-regular family of meshes $\{\mesh_h\}$, such that
  the interpolation estimate~\eqref{eq:fe-interpolation} holds. Let
  $u\in V$ and $u_h\in V_h$ be solutions to the exact and the finite
  element versions of a 2nd order boundary value problem. Then,
  \begin{gather}
    \lim_{h\searrow 0} \norm{u-u_h}_{1;\domain} = 0.
  \end{gather}
\end{Theorem}

\subsection{Estimates of stronger norms}

\begin{intro}
  So far, we have seen error estimates in a ``natural norm'' defined
  as a norm such that the Lax-Milgram lemma holds for a given bilinear
  form $a(.,.)$. In this subsection, we now consider the question of
  estimates in stronger norms, such that the bilinear form is not
  elliptic with respect to this norm.
\end{intro}

\begin{Definition}{stronger-norm}
  Let $\norm{\cdot}_X$ and $\norm{\cdot}_Y$ be norms on a vector space
  $V$. We call $\norm{\cdot}_X$ a \define{stronger norm} than
  $\norm{\cdot}_Y$, if there is a constant $c$ such that for all
  $v\in V$:
  \begin{gather}
    \norm{v}_Y \le c \norm{v}_X.
  \end{gather}
  In this case, $\norm{\cdot}_Y$ is called the \define{weaker
    norm}. If a converse inequality holds, the norms are called
  \define{equivalent}.
\end{Definition}

\begin{example}
  For a bounded domain $\domain$, the norms $\norm{\cdot}_{k+1}$ and
  $\norm{\cdot}_{k}$ are both defined on $V = H^1_0(\domain)$. By the
  Sobolev embedding theorem, there is a constant $c$ such that for any
  $v\in V$
  \begin{gather*}
    \norm{v}_{k} \le c \norm{v}_{k+1}
  \end{gather*}
\end{example}

\begin{Lemma*}{inverse-estimate}{Inverse estimate}
  Let $\cell$ be a mesh cell of size $h_\cell$. Then, there is a
  constant only depending on $k$ and the constants of the scaling
  lemma, such that for every $u\in \P_k$ there holds
  \begin{gather}
    \norm{u}_{1;\cell} \le c h_T^{-1} \norm{u}_{0;\cell}.
  \end{gather}
\end{Lemma*}

\begin{Theorem}{h2-error}
  Let $a(.,.)$ be a bounded and elliptic bilinear form on
  $V\subset H^1(\domain)$ and let $\{\mesh_h\}$ be a family of
  quasi-uniform meshes with finite element spaces $V_h \subset V$
  containing the space $\P_k$ with $k\ge 2$ on each mesh cell. If
  furthermore the solution $u\in H^{k+1}(\domain)$, the error between
  the exact and the finite element solution to a uniquely solvable
  elliptic boundary value problem, admits the estimate
  \begin{gather}
    \norm{u-u_h}_{2;h} \le c h^{k-1} \snorm{u}_{k+1;h}.
  \end{gather}
\end{Theorem}

\begin{proof}
  We cannot apply Céa's lemma directly, since the bilinear form is not
  elliptic with respect to the broken $H^2$-inner product on the space
  $H^1(\domain)$. On the other hand, the error is not polynomial, such
  that we cannot apply the inverse estimate to it. Instead, we use
  triangle inequality
  \begin{gather*}
    \norm{u-u_h}_{2;h} \le \norm{u-I_h u}_{2;h} + \norm{I_h u-u_h}_{2;h},
  \end{gather*}
  and observe, that we already have the desired estimate for the first
  term. For the second, we estimate by inverse estimate on each cell
  \begin{gather*}
    \min_{\cell\in\mesh_h} h_T \norm{I_h u-u_h}_{2;h}
    \norm{I_hu-u_h}_{1} \le c \norm{I_h u-u_h}_{1}^2,
  \end{gather*}
  and
  \begin{align*}
    \norm{I_h u-u_h}_{1}^2
    & \le \frac c\gamma a(I_h u-u_h, I_h u-u_h)
    \\& = \frac c\gamma a(I_h u-u, I_h u-u_h)
    \\& \le \frac{cM}{\gamma}\norm{I_h u-u}_{1} \norm{I_h u-u_h}_{1}
    \\& \le C h^{k} \snorm{u}_{k+1;h} \norm{I_h u-u_h}_{1},
  \end{align*}
  where we have used Galerkin orthogonality and the interpolation
  estimate. Combining the two and using the quasi-uniformity, we
  obtain the result of the theorem.
\end{proof}

\subsection{Estimates of weaker norms and linear functionals}

\begin{intro}
  Deriving optimal error estimates in the $L^2$-norm cannot be
  achieved by the same technique as used for the $H^2$-norm, as the
  following simple argument shows: using triangle inequality, we obtain
  \begin{gather*}
    \norm{u-u_h}_{L^2} \le \norm{u-I_h u}_{L^2} + \norm{I_h u-u_h}_{L^2},
  \end{gather*}
  we obtain that the first term is of order $h^{k+1}$. Thus, for an
  optimal error estimate, we require that the second term be of order
  $h^{k+1}$ as well. We need a replacement of the inverse estimate,
  which gains an order of $h$ instead of loosing it. This is Poincaré
  inequality, but it requires an almost mean-value free function. And
  since $I_h u$ is not the interpolant of $u_h$, we cannot guarantee a
  small mean value of the difference on each mesh cell.

  To the rescue comes a ``duality argument'' known as Aubin-Nitsche
  trick, which we introduce now.
\end{intro}

\begin{Definition}{dual-problem}
  Let the weak form of a boundary value problem on the domain
  $\domain$ be defined as: find $u\in V$ such that
  \begin{gather*}
    a(u,v) = f(v) \qquad\forall v\in V.
  \end{gather*}
  Then, the \define{dual problem}, also called \define{adjoint
    problem}, with right hand side $g\in V^*$ is: find $u^* \in V$ such
  that
  \begin{gather*}
    a(v,u^*) = g(v) \qquad\forall v\in V.
  \end{gather*}
\end{Definition}

\begin{Lemma}{poisson-dual}
  The adjoint problem of the Dirichlet boundary value problem for
  Poisson's equation is equal to the dual problem, that is, for
  $u\in H^1_0(\domain)$, the two statements
  \begin{xalignat*}2
    a(u,v) &= f(v) &\forall v&\in V,\\
    a(v,u) &= f(v) &\forall v&\in V,
  \end{xalignat*}
  are equivalent.
\end{Lemma}

\begin{Assumption*}{elliptic-regularity}{Elliptic regularity}
  Let $a(.,.)$ be a bounded and elliptic bilinear form on
  $H^1_0(\domain)$. We say that a boundary value problem has
  \define{elliptic regularity}, if for any $g\in L^2(\domain)$ the
  solution $u$ is in $H^2(\domain)$. In other words, there is a
  constant $c$ independent of $g$, such that
  \begin{gather}
    \norm{u}_{2;\domain} \le c \norm{g}_{0;\domain}.
  \end{gather}
\end{Assumption*}

\begin{example}
  By \slideref{Remark}{classical-convex}, a second order PDE with
  coefficients $a_{ij}\in C^{0,1}(\overline\domain)$ and
  $b_i, c\in L^\infty(\domain)$ has elliptic regularity. The same
  holds by integration by parts for ints adjoint.

  The same boundary value problem does not have elliptic regularity,
  if the domain has a nonconvex corner, since we have corner
  singularity functions which are not in $H^2(\domain)$, and we can
  construct a right hand side $g\in L^2(\domain)$, which produces such
  singularities.
\end{example}

\begin{Theorem}{fe-l2}
  Let $a(.,.)$ be a bounded and elliptic bilinear form on
  $V = H^1_0(\domain)$ and let the finite element space $V_h$ be
  defined on a shape-regular family of meshes $\{\mesh_h\}$, such that
  the interpolation estimate~\eqref{eq:fe-interpolation} holds. If
  furthermore the solution $u\in H^{k+1}(\domain)$ and the dual
  problem has \putindex{elliptic regularity}, the error of the finite
  element solution $u_h\in V_h \subset V$ admits the estimate
  \begin{gather}
    \norm{u-u_h}_{0} \le c h^{k+1} \snorm{u}_{k+1;h}.
  \end{gather}
\end{Theorem}

\begin{Corollary}{fe-functional}
  Under the assumptions of \slideref{Theorem}{fe-l2}, let $J(.)$ be a
  bounded linear functional on $L^2(\domain)$. Then,
  \begin{gather}
    \abs{J(u)-J(u_h)}_{0} \le c h^{k+1} \snorm{u}_{k+1;h}.
  \end{gather}
\end{Corollary}

\subsection{Green's function and maximum norm estimates}

\begin{intro}
  In this section, we will introduce the basic concepts needed for
  pointwise error estimation. They heavily rely on Green's function,
  which is useful for a general understanding of the solution
  structure as well.
\end{intro}

\begin{Definition}{greens-function}
  For a differential equation $Lu = f$ in $\domain$ with boundary
  conditions $u=0$ on the boundary $\d\domain$, we define
  \define{Green's function} $G(\vy,\vx)$ associated to the point
  $\vy\in\domain$ as solution to the problem
  \begin{gather}
    \begin{aligned}
      L G(\vy,\vx) &= \delta(\vx-\vy)&\qquad\forall \vx&\in\domain,\\
      G(\vy,\vx) &= 0&\qquad\forall \vx&\in\d\domain.
    \end{aligned}
  \end{gather}
\end{Definition}

\begin{Theorem}{greens-function-rd}
  Green's function for Poisson's equation on the whole space
  $\domain=\R^d$ is
  \begin{gather}
    G(\vy,\vx) =
    \begin{cases}
      - \frac1{2\pi} \log \abs{\vx-\vy} & d=2\\
      \frac1{d(d-2)\abs{B_1(0)}} \frac1{\abs{\vx-\vy}^{d-2}} & d\ge3.
    \end{cases}
  \end{gather}
\end{Theorem}

\begin{proof}
  See~\cite[Section 2.2]{Evans98}.
\end{proof}

\begin{Lemma}{greens-function-domain}
  Let $\domain\subset \R^d$ be a bounded domain. Then, Green's
  function associated to a point $\vy\in\domain$ for a linear
  differential operator $L$ on $\domain$ is obtained as the sum
  \begin{gather}
    G(\vy,\vx) = G_\infty(\vy,\vx) - G_0(\vy,\vx),
  \end{gather}
  where $G_\infty(\vy,\vx)$ is Green's function for the whole space
  and $G_0(\vy,\vx)$ solves $LG_0(\vy,\vx)=0$ with boundary values
  $G_\infty(\vy,\vx)$. If the domain is convex, then,
  $G_0(\vy,.)\in H^2(\domain)$ for any interior point $\vy$.
\end{Lemma}

\begin{Theorem}{greens-function-representation}
  Let $f\in C(\overline\domain)$ and let $\domain$ be such that the
  solution to
  \begin{gather}
    \begin{aligned}
      Lu &= f &\qquad\text{in }&\domain,\\
      u &= 0 &\text{on }&\d\domain,
    \end{aligned}
  \end{gather}
  is in $C^2(\overline\domain)$. Then,
  \begin{gather}
    u(\vx) = \int_\domain f(\vy)G(\vy,\vx)\dvy.
  \end{gather}
\end{Theorem}

\begin{proof}
  See \cite[Section 2.2]{Evans98}
\end{proof}

\begin{Theorem}{linfty-error}
  Let $a(.,.)$ be a bounded and elliptic bilinear form on
  $V = H^1_0(\domain)$ on a bounded, convex domain $\domain\subset \R^2$. Let the
  finite element space $V_h$ be defined on a quasi-uniform family of
  meshes $\{\mesh_h\}$ with local spaces $\P_1$ or $\Q_1$. If
  furthermore the solution $u\in W^{2,\infty}(\domain)$, the error of
  the finite element solution $u_h\in V_h \subset V$ admits the
  estimate
  \begin{gather}
    \norm{u-u_h}_{\infty} \le c h^{2} (1+\abs{\log h}) \snorm{u}_{2,\infty}.
  \end{gather}
\end{Theorem}

\begin{proof}
  The proof relies on solving a dual problem for the error in a single
  point. The solution is Green's function for the adjoint equation,
  which is very irregular at the point of interest. Then, complicated
  analysis is needed to generate useful approximation estimates in
  spite of the singularity. Details can be found
  in~\cite{SchatzWahlbin77,RannacherScott82}.
\end{proof}

\begin{remark}
  This estimate extends to $\domain\in\R^d$ for $d\ge 3$ and to higher
  polynomial degrees \emph{without} the logarithmic factor. The
  regularity assumptions are quite high then.
\end{remark}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


% $Id: 785a41386b8ef8716fb66a73bb45d2dfa3eaee4f $

\section{Equational Reasoning with Rigid Unit Superposition}
\label{sec:super}

There are many ways of integrating equational reasoning in tableau
methods~\cite{DB75,LS02,BR15,DV96}. Because our prover does not rely on clausal
forms, but on arbitrary formulas with quantifiers occurring deep inside
branches, we deal with rigid variables, i.e. variables that can be instantiated
only once. The problem we want to solve, rigid E-unification modulo rewrite
rules, is the following. Assume a set of equations $E$, containing rigid
variables, a rewrite system $\mathcal{RE}$, and target terms $s$ and $t$. We
want a substitution $\sigma$ such that
$\bigwedge_{e \in E} e\sigma \vdash s\sigma =_\mathcal{E} t\sigma$. Such a
substitution is a solution to the rigid E-unification problem.

We propose here an approach based on superposition with rigid variables, as in
previous work by Degtyarev and Voronkov~\cite{DV96} and earlier work on rigid
paramodulation~\cite{DAP00}, but with significant differences. First, in order
to avoid constraint solving, we do not use basic superposition nor
constraints. Second, we introduce a merging rule, which factors together
intermediate (dis)equations that are alpha-equivalent: with multiple instances
of some of the quantified formulas (amplification), it becomes important not to
duplicate work. In this aspect, our calculus is quite close to labeled unit
superposition~\cite{KS10} when using sets as labels. Third, unlike rigid
paramodulation, we use a term ordering to orient the equations.

\subsection{Preliminary Definitions}

We write $ \clauseWithSubst{ s \approx t }{ \Sigma}$ (resp.
$\clauseWithSubst{ s \not\approx t }{ \Sigma}$), the unit clause that contains
exactly one equation (resp.~disequation) under hypothesis $\Sigma$ (which is a
set of substitutions). We write $\clauseWithSubst{\emptyset}{\Sigma}$ for the
empty clause under hypothesis $\Sigma$. We define $\renameVars{e}$, where $e$
is a (dis)equation, as follows: let $\sigma$ map every rigid variable of $e$ to
a fresh non-rigid variable, then
$\renameVars{e} = \clauseWithSubst{ e\sigma }{ \{ \sigma \} }$. For example,
$\renameVars{p(X)\approx a}$ is $\clauseWithSubst{ p(Y)\approx a}{ \{ X\mapsto
Y\} }$. The E-unification problem $E \vdash s\approx t$ can be solved by proving
$\clauseWithSubst{\emptyset }{ \Sigma}$ from
$\{ \renameVars{e} \}_{ e \in E } \cup \{ \renameVars{ s \not\approx t } \}$,
where $\Sigma$ contains the solutions. The meaning of $s \approx t | \Sigma$ is
that for every $\sigma \in \Sigma$, $s \approx t$ is provable using the
substitution $\sigma$ for the metavariables.

As can be noticed, we keep a set of substitutions, rather than unit clauses
paired with individual substitutions, in order to avoid duplicating the work for
alpha-equivalent clauses. Indeed, because of amplification, many instances of a
given (dis)equation might be present in a branch of the tableau. It would be
inefficient to repeat the same inference steps with each variant of the axioms.
Because we apply $\renameVars{e}$ on every initial $e$, clauses do not share any
variable, except in their attached sets of substitutions.

To perform an inference step between two unit (dis)equations, we merge their
sets of substitutions. Merging $\Sigma$ and $\Sigma'$, intuitively, means
computing $\{ \textsf{merge}(\sigma,\sigma') ~|~ \sigma \in \Sigma, \sigma'\in
\Sigma' \}$ for every pair $(\sigma,\sigma')$ of compatible substitutions. For
example, the resolution step between $p(x,x)| \{ X \mapsto a \}$ and
$\lnot p(y,b)| \{ X \mapsto y \}$ is not possible, because the result would need
to map $X$ to $a$ and $b$, which is impossible because $X$ is rigid.
Compatibility relies on a partial ordering $\leq$, such that
$\sigma \leq \sigma'$ means that $\sigma$ is less general than $\sigma'$.

Considering a substitution as a function from variables to terms, we define the
domain of a substitution $\sigma$ as the set of variables that have a
non-trivial binding in $\sigma$.\footnote{A trivial binding maps a variable to
itself.} The co-domain of a substitution is the set of variables occurring in
terms in the image of the domain of the substitution. In the following, we will
consider idempotent substitutions, i.e. substitutions for which the domain and
co-domain have an empty intersection.

The composition of two substitutions $\sigma$ and $\sigma'$, denoted by
$\sigma \circ \sigma'$, is said to be well-defined if and only if the domains of
$\sigma$ and $\sigma'$ have no intersection. In this case,
$\sigma \circ \sigma' \triangleq \left\{ x \mapsto (x\sigma)\sigma' | x \in
\text{domain}(\sigma) \right\}$. This definition extends to sets of
substitutions: $\Sigma \circ \sigma' \triangleq \left\{ \sigma \circ \sigma' |
\sigma \in \Sigma \right\}$. We then have $\sigma \leq \sigma'$ if and only if
$\exists \sigma''.~ \sigma \circ \sigma'' = \sigma'$. This notion also extends
to sets of substitutions: $\smash{ \Sigma \leq \Sigma' }$ if and only if
$\smash{ \forall \sigma' \in \Sigma'.~ \exists \sigma \in \Sigma. \sigma \leq
\sigma' }$. The merging of two substitutions $\sigma \uparrow \sigma'$ is the
supremum of $\{\sigma,\sigma'\}$ for the order $\leq$, if it exists, or $\bot$
otherwise. The merging of sets of substitutions is
$\Sigma \uparrow \Sigma' \triangleq \left\{ \sigma \uparrow \sigma' ~|~ \sigma
\in \Sigma, \sigma' \in \Sigma' \right., \sigma \uparrow \sigma' \not= \bot
\}$. An inference rule is said to be successful if the merging of the premises'
substitution sets is non-empty.

\subsection{Inference System}

In Fig.~\ref{fig:unit-sup-rules}, we present the rules for unit superposition
with rigid variables. We adopt notations and names from Schulz's paper on
E~\cite{SS02}. A single bar denotes an inference, i.e. we add the result to the
saturation set, whereas a double bar is a simplification in which the premises
are replaced by the conclusion(s). The relation $\prec$ is a reduction ordering,
used to orient equations and restrict inferences, thus pruning the search space.
Typically, $\prec$ is one of RPO or KBO. The rules of
Fig.~\ref{fig:unit-sup-rules} work as described below:

\begin{description}
\item[ER] is equality resolution, where a disequation
$\clauseWithSubst{s \not\approx t}\Sigma$ is solved by syntactically unifying
$s$ and $t$ with $\sigma$, if $\sigma$ is compatible with $\Sigma$.
\item[SN] is superposition into negative literals. A subterm of $u$ is rewritten
using $s \approx t$ after unifying it with $s$ by $\sigma$. The rewriting is
done only if $s\sigma \not\preceq t\sigma$, a sufficient (but not necessary)
condition for a ground instance of $s\sigma \approx t\sigma$ to be oriented
left-to-right.
\item[SP] is similar to SN, but superposes into a positive literal.
\item[TD1] deletes trivial equations that will never contribute to a proof.
\item[TD2] deletes clauses with an empty set of substitutions. In practice, we
only apply a rule if the conclusion is labeled with a non-empty set of
substitutions.
\item[ME] merges two alpha-equivalent clauses into a single clause, by merging
the sets of substitutions. This rule is very important in practice, to prevent
the search space from exploding due to the duplicates of most formulas.
Superposition deals with this explosion by removing duplicates using
subsumption, but in our context subsumption is not complete because rigid
variables are only proxy for ground terms: even if $C\sigma \subseteq D$, the
one ground instance of $C$ might not be compatible with the ground instance of
$D$.
\item[ES] is a restricted form of equality subsumption. The active equation
$\clauseWithSubst{ s\approx t}\Sigma $ can be used to delete another clause, as
in E~\cite{SS02}. However, ES only works if $s$ and $t$ are syntactically equal
to the corresponding subterms in the subsumed clause $C$. Otherwise, there is no
guarantee that further instantiations will not make $s\approx t$ incompatible
with $C$. Moreover, $C$ needs not be entirely removed. Only its substitutions
that are compatible with $\Sigma$ are subsumed.
\item[RP] is rewriting of positive clauses, which only works for syntactical
equality, not matching.
\item[RN] is the same as RP but for rewriting negative clauses.
\end{description}

Rule \textbf{SN} (resp. \textbf{SP}) generates as many equations (resp.
disequations) as there are in the set
$(\Sigma \circ \sigma'') \uparrow (\Sigma' \circ \sigma'')$ because all
substitutions may not always be merged. For instance, given
$f(x) = t | \{ \{ X_1 \mapsto x \}, \{ X_2 \mapsto x \} \}$ and
$f(a) = v | \{ \{ X_1 \mapsto a \} \} \}$, we have to derive two distinct
non-mergeable equations $(t = v)\{ x \mapsto a \} | \{ \{ X_1 \mapsto a \} \}$
and $(t = v)\{ x \mapsto a \} | \{ \{ X_1 \mapsto a; X_2 \mapsto a \} \}$.

\begin{figure}[htb]
\begin{center}
% ER
\AXC{$s \not\approx t |\Sigma$}
\LL{ER}
\RL{if $\sigma = \text{mgu}(s, t)$}
\UIC{$\emptyset | \Sigma \circ \sigma $}\DP\\[12pt]

% SN
\AXC{$s \approx t | \Sigma$}
\AXC{$u \not\approx v | \Sigma'$}
\LL{SN}
\BIC{$\sigma''(u[p \leftarrow t] \not\approx v) | \sigma'''$}\DP
$\text{if} \left\{ \begin{array}{l@{\quad}l}
\sigma'' = \text{mgu}(u_{|p}, s) & u_{|p} \not\in V\\
\sigma''(s) \not\preceq \sigma''(t) & \sigma''(u) \not\preceq \sigma''(v)\\
\multicolumn{2}{l}{
\sigma''' \in (\Sigma \circ \sigma'') \uparrow (\Sigma' \circ \sigma'')}
\end{array}\right.$\\[12pt]

% SP
\AXC{$s \approx t | \Sigma$}
\AXC{$u \approx v | \Sigma'$}
\LL{SP}
\BIC{$\sigma''(u[p \leftarrow t] \approx v) | \sigma'''$}\DP
$\text{if} \left\{ \begin{array}{l@{\quad}l}
\sigma'' = \text{mgu}(u_{|p}, s) & u_{|p} \not\in V\\
\sigma''(s) \not\preceq \sigma''(t) & \sigma''(u) \not\preceq \sigma''(v)\\
\multicolumn{2}{l}{
\sigma''' \in (\Sigma \circ \sigma'') \uparrow (\Sigma' \circ \sigma'')}
\end{array}\right.$\\[12pt]

\mbox{
% TD1
\AXC{$s \approx s | \Sigma $}
\LL{TD1}
\doubleLine{}
\UIC{$\top$}\DP

% TD2
\AXC{$s \mathrel{R} t | \emptyset$}
\LL{TD2}
\RL{$ R \in \{ \approx, \not\approx \} $}
\doubleLine{}
\UIC{$\top$}
\DP}\\[12pt]

% ME
\AXC{$\rho(u) \approx \rho(v) | \Sigma$}
\AXC{$u \approx v | \Sigma'$}
\LL{ME}
\RL{$\rho \text{ is a variable renaming}$}
\doubleLine{}
\BIC{$\rho(u) \approx \rho(v) | \Sigma \cup (\Sigma' \circ \rho)$}\DP\\[12pt]

% ES
\AXC{$s \approx t | \Sigma$}
\AXC{$u[p \leftarrow s] \approx u[p \leftarrow t] | \Sigma' \cup \Sigma''$}
\LL{ES}
\RL{$
\text{if} \left\{ \begin{array}{l}
\Sigma'' \not= \emptyset\\
\Sigma \leq \Sigma''
\end{array}\right.$}
\doubleLine{}
\BIC{$s\approx t | \Sigma \qquad u[p\leftarrow s] \approx u[p \leftarrow t] |
\Sigma'$}\DP\\[12pt]

% RP
\AXC{$s \approx t | \Sigma$}
\AXC{$u \approx v | \Sigma'$}
\LL{RP}
\doubleLine{}
\BIC{$s \approx t | \Sigma$ \qquad $u[p \leftarrow t] \approx v | \Sigma'$}\DP
$\text{if} \left\{\begin{array}{l}
u_{|p} = s\\
s \succ t\\
\Sigma \leq \Sigma'\\
u \not\succeq v ~ \text{or} ~ p \neq \lambda\\
\end{array}\right.$\\[12pt]

% RN
\AXC{$s \approx t | \Sigma$}
\AXC{$u \not\approx v | \Sigma'$}
\LL{RN}
\doubleLine{}
\BIC{$s \approx t | \Sigma$ \qquad $u[p \leftarrow t] \not\approx v |
\Sigma'$}\DP
$\text{if} \left\{\begin{array}{l}
u_{|p} = s\\
s \succ t\\
\Sigma \leq \Sigma'\\
\end{array}\right.$
\caption{The Set of Rules for Unit Rigid Superposition}
\label{fig:unit-sup-rules}
\end{center}
\end{figure}

\subsection{Rewriting}

Rewrite rules can be integrated to the rigid unit superposition easily. In fact,
a rewrite rule $l\rew{}r$ can be expressed as an equality with a hypothesis set
consisting of a single trivial substitution
$s\approx{}t|\{\text{identity}\}$. Since the trivial substitution is compatible
with every substitution, it will never prevent any inference, thus allowing us
to use the unit clause as many times as needed to rewrite terms without
accumulating constraints, particularly using the rules RP and RN, whose side
conditions are always verified by rewrite rules. Rigid unit superposition
therefore provides an algorithm for rigid E-unification modulo rewrite rules.

\subsection{Main Loop}

Our objective with rigid E-unification is to attempt to close a branch of the
tableau prover (i.e. a set of Boolean literals set to true). To do so, all
equational or atomic literals are added to a set of unit clauses to process,
with a label $\Sigma \triangleq \{ \emptyset \}$. Then, the given-clause
algorithm is applied to try and saturate the set. Assuming a fair strategy, this
will eventually find a solution (i.e. derive
$\clauseWithSubst{\emptyset}{\Sigma}$) if there exists one. We refer the
interested reader to~\cite{SS02} for more details.

Because the whole branch is managed by a single given-clause saturation loop, we
look for all solutions susceptible to close the branch at the same time.
Moreover, this technique is amenable to incrementality, i.e. every time a
(dis)equation is decided by the SAT solver, we could add it to the saturation
set and perform a (limited) number of steps of the given-clause algorithm.

\subsection{Example}

To illustrate the calculus, we detail a refutation of the following set of
clauses stemming from set theory, where pair, fst, and snd are the constructor
and destructors of tuples, $f$ a function on tuples, and $X$ a rigid variable:

\[\begin{array}{rcl}
\text{pair}(\text{fst}(x), \text{snd}(x))) &\rew& x\\
\text{fst}(a) &\approx& \text{fst}(b)\\
p(a) &\not\approx& p(\text{pair}(\text{fst}(b), X))\\
\end{array}\]

Because the problem is purely equational, the tableau structure is trivial, and
all the work is done by the rigid superposition procedure as shown in
Fig.~\ref{fig:unit-sup-proof-example}.

\begin{figure}[t]
\begin{center}
\begin{tabular}{clc}
1 & axiom & $\text{pair}(\text{fst}(x), \text{snd}(x))) \rew x$\\

2 & axiom & $\text{fst}(a) = \text{fst}(b)$\\

3 & axiom & $p(a) \not= p(\text{pair}(\text{fst}(b), X))$\\

4 & \renameVarsSymb(1) &
$\clauseWithSubst
{ \text{pair}(\text{fst}(x), \text{snd}(x)) \approx x }
{ \{ \} }$\\

5 & \renameVarsSymb(2) &
$\clauseWithSubst
{ \text{fst}(a) \approx \text{fst}(b) }
{ \{ \} }$\\

6 & \renameVarsSymb(3) &
$\clauseWithSubst
{ f(a) \not\approx f(\text{pair}(\text{fst}(b), y)) }
{ \{ \mapVar{X}y \} }$\\

\midrule

7 & RN(5,6) &
$\clauseWithSubst
{ f(a) \not\approx f(\text{pair}(\text{fst}(a), y)) }
{ \{ \mapVar{X}y \} }$\\

8 & SN(4,7) &
$\clauseWithSubst
{ f(a) \not\approx f(a) }
{ \{ \mapVar{X}{\text{snd}(a)} \} }$\\

9 & ER(8) &
$\clauseWithSubst
{ \emptyset }
{ \{ \mapVar{X}{\text{snd}(a)} \} }$
\end{tabular}
\caption{Proof of a Set Theory Problem}
\label{fig:unit-sup-proof-example}
\end{center}
\end{figure}


\documentclass[a4paper,12pt]{article}
\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{amsmath,amssymb,amsthm,algorithm,algorithmic,graphicx,yhmath,url,enumitem,lscape,mathtools}
\usepackage{wrapfig,subfigure}

\newcounter{problem}
\newenvironment{problem}{\refstepcounter{problem} \noindent {\bf Problem \arabic{problem}}}{\newpage}
\newenvironment{solution}{\vspace{0.3cm} \par \noindent {\bf Solution}}{}
\newenvironment{verification}{\vspace{0.3cm} \par \noindent {\bf Verification}}{}
\newenvironment{hint}{\vspace{0.3cm} \par {\bf Hint:}}{}

\newcounter{remark}
\newenvironment{remark}{\refstepcounter{remark} \vspace{0.3cm} \par \noindent {\bf Remark \arabic{remark}}}{\vspace{0.3cm}}
\newcounter{lesson}
\newenvironment{lesson}{\refstepcounter{lesson} \vspace{0.3cm} \par \noindent {\bf Lesson \arabic{lesson}}}{\vspace{0.3cm}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Rn}{\mathbb{R}^n}
\newcommand{\Rnn}{\mathbb{R}^{n \times n}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\eps}{\epsilon}
\newcommand{\fl}{\text{fl}}

\begin{document}

\title{5DV005, Fall 2018, Lab session 5}
\author{Carl Christian Kjelgaard Mikkelsen}

\maketitle
\tableofcontents

\section{The time and the place}
The lab session will take place on
\begin{center}
Wednesday, December 5th, 2018, (kl. 13.00-16.00), Room MA416-426.
\end{center}

\section{Introduction}

This week's problems do not require much in terms of programming. However, however careful inspection and analysis of the output is required. Use any excess time to complete problems from previous weeks.

\section{The problems}

\begin{problem} Consider the problem of computing the derivative $f'(x)$ using the finite difference approximation
  \bes
  D_1(f,x,h) = \frac{f(x+h)-f(x)}{h}
  \ees
  Execute the script {\tt rdifmwe1} and examine output in detail:
  \begin{enumerate}
  \item Determine the value of $k$ where the computed value of Richardson's fraction has executed an illegal jump.
  \item Determine the range of $k$ values for which the computed value of Richardson's fraction convergences monotonically to $2^p$ for a suitable value of $p$.
  \item Determine the range of $k$ values for which the computed value of Richardson's fraction converges to $2^p$ at the correct rate.
  \item Determine the range of $k$ values where the error estimates become more and more accurate.
  \item How is the behavior of Richardson's fraction related to the quality of Richardson's error estimate?
    \end{enumerate}
  \end{problem}

  \begin{problem} Copy {\tt rdifmwe1.m} into {\tt /work/l5p2.m} and adapt it to the problem of computing $f'(2)$ where
    \bes
    f(x) = e^x \sin(x)
    \ees
    Do \textit{not} include the derivative when you call {\tt rdif}.
    \begin{enumerate}
    \item Verify that the computed value of Richardson's fraction appears to converge towards $2^p$ for a suitable value of $p$ as $h$ tends to zero.
    \item Find the last value of $k$, where the computed value of Richardson's fraction behaved exactly as predicted for the exact value of Richardson's fraction.
    \item Include the exact derivative when you call {\tt rdif}. Find the value of $k$ where the accuracy of Richardson's error estimate is maximal.
    \item How is the behavior of Richardson's fraction related to the quality of Richardson's error estimate?
      \end{enumerate}
 \end{problem}

\begin{problem} Consider the problem of computing the derivative $f'(x)$ using the finite difference approximation
  \bes
  D_2(f,x,h) = \frac{f(x+h)-f(x-h)}{2h}
  \ees
  Execute the script {\tt rdifmwe2} and examine output in detail:
  \begin{enumerate}
  \item Determine the value of $k$ where the computed value of Richardson's fraction has executed an illegal jump.
  \item Determine the range of $k$ values for which the computed value of Richardson's fraction convergences monotonically to $2^p$ for a suitable value of $p$.
  \item Determine the range of $k$ values for which the computed value of RichRichardson's fraction converges to $2^p$ at the correct rate.
  \item Determine the range of $k$ values where the error estimates become more and more accurate.
  \item Is the behavior of Richardson's fraction related to the quality of Richardson's error estimate?
    \end{enumerate}
\end{problem}

 \begin{problem} Copy {\tt rdifmwe2.m} into {\tt /work/l5p4.m} and adapt it to the problem of computing $f'(2)$ where
    \bes
    f(x) = e^x \sin(x).
    \ees
    Do \textit{not} include the derivative when you call {\tt rdif} initially.
    \begin{enumerate}
    \item Verify that the computed value of Richardson's fraction appears to converge towards $2^p$ for a suitable value of $p$ as $h$ tends to zero.
    \item Find the last value of $k$, where the computed value of Richardson's fraction behaved exactly as predicted for the exact value of Richardson's fraction.
    \item Include the exact derivative when you call {\tt rdif}. Find the value of $k$ where the accuracy of Richardson's error estimate is maximal.
    \item Is the behavior of Richardson's fraction related to the quality of Richardson's error estimate?
    \end{enumerate}
 \end{problem}

\bibliographystyle{plain}
  \bibliography{../../../lecture-notes/refs}

\end{document}