\documentclass[a4paper]{amsart}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{bbm}

\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{conjecture}[theorem]{Conjecture}

\newcommand{\expec}{\mathbf{E}}
\newcommand{\Oh}{\mathrm{O}}
\newcommand{\oh}{\mathrm{o}}
\newcommand{\im}{\mathrm{i}}
\newcommand{\e}{\mathrm{e}}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\prob}{\mathbf{P}}

\title{Disproof of a conjecture by Rademacher on partial fractions}

\author{Michael Drmota}
\address{Vienna University of Technology, Wiedner Hauptstra\ss{}e 8--10/105-1,
A-1040 Vienna, Austria}
\email{michael.drmota@tuwien.ac.at}

\author{Stefan Gerhold}
\address{Vienna University of Technology, Wiedner Hauptstra\ss{}e 8--10/105-1,
A-1040 Vienna, Austria}
\email{sgerhold@fam.tuwien.ac.at}
\thanks{S.~Gerhold gratefully acknowledges financial support from the
Austrian Science Fund (FWF) under grant P~24880-N25.}

\date{\today}

\begin{document}

\begin{abstract}
  In his book Topics in Analytic Number Theory,
  Rademacher considered the generating function
  of partitions into at most $N$ parts, and conjectured certain limits
for the coefficients of its partial fraction decomposition. We carry out an asymptotic
analysis that disproves this conjecture, thus confirming recent observations
of Sills and Zeilberger (Journal of Difference Equations and Applications 19, 2013),
who gave strong  numerical evidence against the conjecture.
\end{abstract}

\keywords{Integer partitions, partial fraction decomposition, Mellin transform,
polylogarithm, saddle point asymptotics}

\subjclass[2010]{11P82, 41A60}

\maketitle

\section{introduction}

In his book Topics in Analytic Number Theory~\cite{Ra73},
Rademacher gave a partial fraction decomposition of the
partition generating function $\prod_{j\geq 1}(1-x^j)^{-1}$.
He conjectured that the decomposition
of the generating function of partitions into at most~$N$
parts,
\[
  \prod_{j=1}^N \frac{1}{1-x^j} = \sum_{k=1}^N
    \sum_{\substack{0\leq h<k \\ \gcd(h,k)=1}} \sum_{l=1}^{\lfloor N/k \rfloor}
    \frac{C_{h,k,l}(N)}{(x-e^{2\pi i h/k})^l},
\]
is consistent with it in the sense that the coefficients~$C_{h,k,l}(N)$
converge as $N\to\infty$ to the coefficients of the decomposition
of the unrestricted generating function.
Despite attracting the attention of several authors~\cite{An07,Eh93,Mu08},
the conjecture has been open since 1973.
See Sills and Zeilberger~\cite{SiZe13} for some further historical remarks.
The latter paper presents a recurrence
for $C_{0,1,l}(N)$; the values computed by it
do not seem to show convergence, but
rather  oscillating and unbounded behavior.
It is well known, though, that there are number-theoretic problems
where the true asymptotics are numerically visible only
for \emph{very} large values. See, e.g.,~\cite{Ge10a} for an example.
The present note rigorously confirms the main observation
from~\cite{SiZe13}, i.e., we disprove Rademacher's
conjecture.\footnote{It is important to note that Cormac O'Sullivan
has disproved Rademacher's conjecture independently from us,
as announced  in his paper~\cite{oS12}, with a different approach.
More precisely, he proved that there exist $h,k \le 100$ such
that $C_{h,k,1}(N)$  does not converge (personal communication), whereas our method
proves directly a conjectural relation from~\cite{oS12} (Conjecture 6.2)
-- with a slightly worse error term.
}
To formulate our main result, recall the definition of the dilogarithm function: $\mathrm{Li}_2(w)
= \sum_{k\geq1}w^k/k^2$, $|w|<1$.  Define $z_0\approx -1.61 + 7.42i$
as the solution of
\begin{equation}\label{eq:z0}
  \log(1-e^z) + \frac{1}{z}(\mathrm{Li}_2(e^z)-\pi^2/6) = 0.
\end{equation}
(It is easy to show that there is a unique root within, say, distance
$1$ of the numerical value given above.)
Furthermore, define $\rho=\exp(i a)$, where
\begin{equation}\label{eq:a}
  a = \frac{ \pi}{2} - \frac12 \arg\left( \frac{e^{z_0}}{z_0(1-e^{z_0})} \right) \approx 1.79.
\end{equation}
\begin{theorem}\label{thm:main}
    For any integer $l\geq1$, we have the asymptotics
    \begin{equation}\label{eq:C asympt}
        C_{0,1,l}(N) = b^N N^{-l-1} H_l(N) + O(b^N N^{-l-117/112}), \quad N\to\infty,
    \end{equation}
    where $b=1/|1-e^{z_0}|\approx 1.07$, and~$H_l$ is a bounded function with period
   $p=2\pi/|\arg(1-e^{z_0})|\approx 31.96$, given by
   \begin{multline*}
       H_l(N) = \frac{(-1)^{l-1}}{\pi}
       \sqrt{-\frac {z_0(1-e^{z_0})}{\rho^2e^{z_0}}}
       \Bigg(\Im\left( \frac{\rho(-z_0)^{l-1/2}}{\sqrt{1-e^{z_0}}}\right)\cos\big(N \arg(1-e^{z_0})\big) \\
        -\Re\left(\frac{\rho(-z_0)^{l-1/2}}{\sqrt{1-e^{z_0}}}\right)\sin\big(N \arg(1-e^{z_0})\big)\Bigg).
   \end{multline*}
\end{theorem}
%
Note that the number under the first radical sign is real and positive.
The period~$p$
of the oscillations is roughly~$32$, as observed by Sills and
Zeilberger~\cite{SiZe13}. It is independent of~$l$, as is the
exponential growth order $b^N$. Moreover, Sills and Zeilberger
found that the successive peaks seem to grow exponentially with
a factor around~$8$. The (asymptotically) true factor
is $b^p\approx 8.81$.
Figures~\ref{fig:1} and~\ref{fig:2} illustrate the quality of the approximation,
which seems to be better for $l=1$ than for $l=2$.
%
\begin{figure}
\begin{center}
\includegraphics[height=2in]{fig1}
\end{center}
\caption{\label{fig:1}The numbers $C_{0,1,1}(N)$ (black)
and the approximation~\eqref{eq:C asympt} (gray), for
$N=100,\dots,150$.}
\end{figure}
%
\begin{figure}
\begin{center}
\includegraphics[height=2in]{fig2}
\end{center}
\caption{\label{fig:2}The numbers $C_{0,1,2}(N)$ (black)
and the approximation~\eqref{eq:C asympt} (gray), for
$N=100,\dots,150$.}
\end{figure}

In principle, it should be possible to extend our approach
from $(h,k)=(0,1)$ to general $h,k$.
Moreover, a natural conjecture is that the period $2\pi/|\arg(1-e^{z_0})|$
of~$H_l$ is a transcendental number.
While there is some literature on transcendence of polylogarithm values
(see, e.g.,~\cite{Ha93}), we are not aware of any result that would imply this.

The rest of the paper is organized as follows. In Section~\ref{se:mellin},
we appeal to the Cauchy integral representation of $C_{0,1,l}(N)$
and find an asymptotic approximation for its integrand.
The new integrand is analysed in Section~\ref{se:saddle}
by the saddle point method. Section~\ref{se:right} completes the proof
of Theorem~\ref{thm:main} by adding estimates in regions
where the asymptotic approximation for the integrand has to be
modified or is invalid. In the conclusion, we comment on the error term
in~\eqref{eq:C asympt}, and on possible future work.

\section{Mellin Transform asymptotics}\label{se:mellin}

Since the $C_{0,1,l}(N)$ are the Laurent coefficients of
$\prod_{j=1}^N (1-x^j)^{-1}$ at $x=1$, we
can express them by Cauchy's formula:
\begin{align}
   C_{0,1,l}(N) &= \frac{1}{2i\pi} \oint x^{l-1} \prod_{j=1}^N \frac{1}{1-(x+1)^j}dx \notag \\
   & =  \frac{(-1)^{l-1}}{N^l} \frac{1}{2i\pi} \oint F(z,N) dz, \label{eq:F}
\end{align}
where we have substituted $x+1=e^{z/N}$, and
\begin{equation}\label{eq:F def}
  F(z,N) := e^{f(z,N)} := e^{z/N}N^{l-1}(1-e^{z/N})^{l-1}\prod_{j=1}^N \frac{1}{1-e^{zj/N}}.
\end{equation}
We wish to replace the integrand~$F$ by an asymptotic approximation,
derived by a Mellin transform approach.
We do the analysis for $\Re z<0$, since the factor~$e^{-Nz/2}$ in
\begin{equation}\label{eq:refl}
  \prod_{j=1}^N \frac 1{1-e^{zj/N}}
  = (-1)^N e^{-z(N+1)/2} \prod_{j=1}^N \frac 1{1-e^{-zj/N}}
\end{equation}
suggests that the contribution of the left half-circle dominates
the integral~\eqref{eq:F}; a rigorous argument is given in Section~\ref{se:right}.
To take the Mellin transform of $f=\log F$ w.r.t.~$N$, we have to interpolate between integral values of~$N$. We therefore rewrite the
logarithm of the product $\prod_{j=1}^N$ in~\eqref{eq:F def} as follows:
\begin{align*}
 g(z,N)  &:= \log \prod_{j=1}^n  \frac{1}{1-e^{zj/N}} \\
 &= - \sum_{j=1}^N \log(1-e^{zj/N}) \\
  &= \sum_{j=1}^N \sum_{k=1}^\infty \frac{1}{k}e^{zjk/N}
 = \sum_{k=1}^\infty \frac{1}{k} \frac{1-e^{kz}}{e^{-kz/N}-1}.
\end{align*}
Now we can compute the Mellin transform of~$g$ w.r.t.~$N$, for $\Re(s)<-1$:
\begin{align}
 \mathcal{M}g(z,\cdot)(s)&=\int_0^\infty g(z,x)x^{s-1}dx \notag \\
&=  \sum_{k=1}^\infty \frac{1-e^{kz}}{k}
    \int_0^\infty \frac{x^{s-1}}{e^{-kz/x}-1} dx \notag \\
  &= \sum_{k=1}^\infty  \frac{1-e^{kz}}{k} (-kz)^s \Gamma(-s)\zeta(-s) \notag \\
  &= (-z)^s \Gamma(-s)\zeta(-s) \left(\sum_{k=1}^\infty k^{s-1}
  - \sum_{k=1}^\infty  k^{s-1} e^{kz}  \right) \notag \\
  &= (-z)^s \Gamma(-s)\zeta(-s) \Big(\zeta(1-s) - \mathrm{Li}_{1-s}(e^z)\Big).
  \label{eq:mellin}
\end{align}
Recall that the polylogarithm is
defined for $|w|<1$  and $\nu\in\mathbb{C}$ by $\mathrm{Li}_\nu(w) = \sum_{k\geq1}w^k/k^\nu$.
For the integral evaluation used in the third equality,
see Titchmarsh~\cite{Ti86}, p.~18; it already appears in Riemann's
original memoir~\cite{Ri59}.
By the Mellin inversion formula~\cite{FlGoDu95},  $g$ can be recovered by
\begin{equation}\label{eq:g mell}
  g(z,N) = \frac{1}{2i\pi} \int_{-3/2-i\infty}^{-3/2+i \infty} \mathcal{M}g(z,\cdot)(s) N^{-s}ds.
\end{equation}
We now move the integration line to the right and collect residues.
To estimate the resulting integral (and justify Mellin inversion),
we first establish a bound on
$ \mathrm{Li}_{1-s}(e^z)$ for $|\Im s|$ large. Note that Pickard~\cite{Pi68}
studied asymptotics of $\mathrm{Li}_\nu(w)$ for $\nu\to0$ and $\nu\to\infty$,
and wrote that ``little is known about behavior in the $\nu$-plane
except along and near the line $(0,\infty)$.''
%
\begin{lemma}\label{le:Li}
  Suppose that $z$ is bounded, bounded away from~$0$ and $\pm 2i\pi$,
  $|\Im z|<8$, and $\Re z \leq 0$. Then,
  for $\Re s>1$ fixed and $|\Im s|\to\infty$, we have
  \[
     \mathrm{Li}_{1-s}(e^z) = O( |\Im s|^{\Re s -1/2}).
  \]
\end{lemma}
\begin{proof}
  We use the representation
  \begin{equation}\label{eq:Li Hurwitz}
    \mathrm{Li}_{1-s}(e^z) = \frac{\Gamma(s)}{(2\pi)^s}
      \left( i^s \zeta\left(s,\frac12 + \frac{\log(-e^z)}{2i\pi}\right)
      + i^{-s} \zeta\left(s,\frac12 - \frac{\log(-e^z)}{2i\pi}\right)\right),
  \end{equation}
  due to Jonqui{\`e}re~\cite{Jo89}, where
  \[
    \zeta(s,q) = \sum_{k=0}^\infty \frac{1}{(q+n)^s}, \quad \Re s >1, \Re q >0,
  \]
  is the Hurwitz zeta function.
  First we establish some simple estimates for this function.
  Suppose that $\Im s \to +\infty$ and that $\Im q <0$. Since
  \begin{equation}\label{eq:q+n}
    |q+n|^{-s} = |q+n|^{-\Re s} e^{\Im(s) \arg(q+n)}
  \end{equation}
  and $\arg(q+n)<0$, we obtain
  \[
     |\zeta(s,q)| \leq \sum_{k=0}^\infty |q+n|^{-\Re s} = O(1),
  \]
  for bounded $q$ with $\Re q>0$ and $q$ bounded away from zero.
  If $\Im q >0$, on the other hand, we use the bound $e^{\Im(s) \arg(q+n)}
  \leq e^{\tfrac12 \pi \Im s}$ in~\eqref{eq:q+n} to conclude
  \[
     \zeta(s,q) = O(e^{\tfrac12 \pi \Im s}).
  \]
  Analogous bounds hold for $\Im s\to-\infty$. To apply them to~\eqref{eq:Li Hurwitz},
  note that
  \[
    \Re\left(\frac12 \pm \frac{\log(-e^z)}{2i\pi}\right)>0 \quad \text{and} \quad
    \Im\left(\frac12 + \frac{\log(-e^z)}{2i\pi}\right)>0
  \]
  in the specified range of~$z$.
  For the desired estimate, it now suffices to observe that
   $|i^{\pm s}|=\exp(\mp \tfrac12\pi
    \Im s)$, that the factor $(2\pi)^{-s}$ is $O(1)$, and that we have
  \[
    \Gamma(s) = O(e^{-\tfrac12 \pi |\Im s|} |\Im s|^{\Re s - 1/2})
  \]
  by Stirling's formula.
\end{proof}
%
We can now find the asymptotics of~$g$ by shifting the integration
in~\eqref{eq:g mell} to the right, where $\Re s =8/7$ turns out to
be a suitable choice.
The polylogarithm $\mathrm{Li}_{1-s}(e^z)$ is an entire function of~$s$.
Moreover, $\zeta(-s)$ has a simple pole at $s=-1$, and $\Gamma(-s)$ has simple
poles at the non-negative integers. Because of the factor $\zeta(1-s)$, the
transform~\eqref{eq:mellin} has a double pole at  $s=0$, which results in
a logarithmic term in the asymptotics of~$g$.
%
\begin{lemma}\label{le:mellin}
  For $\Re z<0$, the function $f$ defined in~\eqref{eq:F def} has the representation
  \begin{multline}\label{eq:f asympt}
     f(z,N) = \frac{1}{z}\Big( \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}\Big)N
   - \frac12 \log N  \\
    - \frac12 \Big(\log 2\pi    +\log(1-e^{z})
 - \log(-z)\Big) +(l-1)\log(-z)+ h(z,N),
 \end{multline}
  where~$h$ is given by
  \begin{multline}\label{eq:h}
    h(z,N) =  \frac{z(e^z+1)}{24(e^z-1)} \frac1N +\frac{z}{N}
      + \frac{1}{2i\pi}\int_{8/7-i\infty}^{8/7+i\infty}  \mathcal{M}g(z,\cdot)(s) N^{-s} ds \\
                -(l-1) \log(-z) + (l-1) (\log N + \log (1-e^{z/N})).
  \end{multline}
  The function~$h$ is
  \begin{itemize}
    \item[(i)] uniformly $O(N^{-1/2})$ if $|\arg z|\geq \pi/2+\varepsilon$, $z$ is  bounded away
      from~$0$, and $z=O(N^{1/2})$,
    \item[(ii)] uniformly $O(N^{33/112})$ if $z$ is bounded, bounded away from~$0$ and $\pm 2i\pi$,
      $|\Im z|<8$, and $\Re z < -N^{-7/8}$.
  \end{itemize}
\end{lemma}
\begin{proof}
    We shift the integration in~\eqref{eq:g mell} to $\Re s=8/7$.
   The residues of~\eqref{eq:mellin} at $s=-1$, $s=0$, and $s=1$ are straightforward
   to compute and yield
  \begin{multline*}
         g(z,N) = \frac{1}{z}\Big( \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}\Big)N
   - \frac12 \log N
    - \frac12 \Big(\log 2\pi    +\log(1-e^{z})  - \log(-z)\Big)\\
         + \frac{z(e^z+1)}{24(e^z-1)} \frac1N
         +\frac{1}{2i\pi}\int_{8/7-i\infty}^{8/7+i\infty}  \mathcal{M}g(z,\cdot)(s) N^{-s} ds.
  \end{multline*}
   Together with the definition of $f=\log F$ in~\eqref{eq:F}, we obtain~\eqref{eq:f asympt}.
   Except for the integral, it is immediate that all terms in~\eqref{eq:h} satisfy
   the bounds stated in~(i) and~(ii). Note  that
   \[
     \log(1-e^{z/N}) = \log(-z) - \log N + O(N^{-1/2})
   \]
   in both cases (i) and (ii), and that
   \[
    \left |\frac{e^z+1}{e^z-1}\right|
      = \frac{1+e^{2 \Re z} +2e^{ \Re z} \cos(\Im z)}
        {1+e^{2 \Re z} -2e^{ \Re z} \cos(\Im z)}
      \leq \frac{1+e^{2 \Re z} +2e^{ \Re z} }
        {1+e^{2 \Re z} -2e^{ \Re z} }
  \]
  is bounded. To estimate the integral in~\eqref{eq:h}, we use
  the following well-known equations resp.\ estimates, for $\Re s= 8/7$ and
  $\Im s\to \infty$ ($\Im s<0$ is treated by conjugation):
  \begin{align}
    |N^{-s}| &= N^{-\Re s}, \notag \\
    |(-z)^s| &= |z|^{\Re s} e^{-\Im(s) \arg(-z)}, \label{eq:-z} \\
    |\Gamma(-s)| &\sim \sqrt{2\pi} e^{-\tfrac12\pi \Im s} (\Im s)^{-\Re s - 1/2},  \label{eq:stirling}  \\
    \zeta(-s) &= O((\Im s)^{\Re s+1/2}),  \label{eq:zeta} \\
    \zeta(1-s)&= O((\Im s)^{ \Re s-1/2}).   \label{eq:zeta1}
  \end{align}
  For~\eqref{eq:zeta} and~\eqref{eq:zeta1}, see Titchmarsh~\cite{Ti86}, p.~95.
  In case~(i), we have
  \[
    |\mathrm{Li}_{1-s}(e^z) | \leq \mathrm{Li}_{\Re(1-s)}(e^{\Re z}) = O(1)
  \]
  by the triangle inequality and the analyticity of the polylogarithm
  in the unit disk.
  Since $|\arg z|\geq \pi/2+\varepsilon$, we see from~\eqref{eq:-z}
  and~\eqref{eq:stirling} that the integrand has an exponentially decaying factor
  $\exp(-\Im(s) (\arg(-z) + \tfrac12 \pi )) \leq \exp(-\varepsilon\Im s)$.
  The integral is thus $O(N^{-\Re s}|z|^{\Re s})=O(N^{-4/7})=O(N^{-1/2})$.

  In case~(ii), the decay of the exponential bound slows down as~$N$ increases,
  because $\arg(-z)$ may approach $-\pi/2$, and we must also take into
  account the powers of~$\Im s$ in the estimates \eqref{eq:-z}--\eqref{eq:zeta1}
  and Lemma~\ref{le:Li}.
  The boundedness of~$z$ guarantees
  that $|z|^{\Re s}$ in~\eqref{eq:-z} stays bounded,
  and that $\arg(-z) + \pi/2 \sim -\Re z$ for $\Re z\to0$.
  We can thus bound the integral by a constant multiple of
  \[
    N^{-\Re s}\int_0^\infty e^{-N^{-7/8}x} x^{\Re s-1/2}dx=
     N^{-8/7} N^{23/26}=O(N^{33/112}).
  \]
  Note that the powers of $\Im s$ in~\eqref{eq:stirling} and~\eqref{eq:zeta} cancel, and
  that~\eqref{eq:zeta1} and Lemma~\ref{le:Li} show that the term in parentheses
  in~\eqref{eq:mellin} is $O((\Im s)^{\Re s-1/2})$.
\end{proof}

Lemma~\ref{le:mellin} suggests the approximate integral representation
\begin{multline}\label{eq:new int}
  C_{0,1,l}(N) \\ \approx \frac{(-1)^{l-1}}{N^{l+1/2}(2\pi)^{3/2}i}
  \int_{|z|=5, \Re z\leq 0}
  \frac{(-z)^{l-1/2}}{\sqrt{1-e^z}} \exp\left( \frac{z}{N} + \frac{N}{z}
  \left( \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}\right) \right) dz,
\end{multline}
where~$h$ from~\eqref{eq:f asympt} has been replaced by zero,
except the term $z/N$, which was retained for better accuracy.
Recall that the right half-circle is negligible, as mentioned
above and proved in Section~\eqref{se:right}.
Even for small~$N$, the fit is very good for $l=1$; see Figure~\ref{fig:approx}.
%
\begin{figure}
\begin{center}
\includegraphics[height=2in]{approx}
\end{center}
\caption{\label{fig:approx}The numbers $C_{0,1,1}(N)$ (black)
and the approximation~\eqref{eq:new int} (gray), for
$N=1,\dots,70$.}
\end{figure}

\section{Saddle point asymptotics}\label{se:saddle}

We now proceed by a saddle point analysis of the integral~\eqref{eq:F},
using the approximation of the integrand provided by Lemma~\ref{le:mellin}.
According to this lemma, the factor
$ \exp\left(  \frac1z
  \left( \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}\right) N \right)$
dominates the integrand in~\eqref{eq:F}. Equating its derivative to zero,
we obtain the saddle point~$z_0$ defined in~\eqref{eq:z0}. The argument
of its axis is (see~\cite{deBr58})
\begin{align*}
   a &= \frac{ \pi}{2} - \frac12 \arg \frac{d^2}{dz^2} \left.\left(
    \frac1z  \left( \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}\right)\right)
    \right|_{z=z_0} \\
   &=  \frac{ \pi}{2} - \frac12 \arg\left( \frac{e^{z_0}}{z_0(1-e^{z_0})} \right) \approx 1.79,
\end{align*}
and $\rho=e^{ia}$ is thus the direction of steepest decent. By symmetry, the conjugate
$\bar{z}_0$ is a saddle point, too, and its direction of steepest descent is $\bar{\rho}$.
We now deform the integration
%
\begin{figure}
\begin{center}
\includegraphics[height=3in]{contour}
\end{center}
\caption{\label{fig:path} The new integration contour, passing through
the saddle point~$z_0$. The (upper) dominating part lies between
$z_2(N)$ and $z_3(N)$. Angles and distances have been modified
for better visibility.}
\end{figure}
%
circle as follows (see Figure~\ref{fig:path}):
In the right half-plane, we stay with a half-circle, of radius~$5$. In the left half-plane,
we connect the point $z_1:=5i$ with the point $ z_0-\rho$ by a straight line. We then proceed by a
line through the saddle point~$z_0$,
up to a point $z_4(N)$. A vertical line then connects this point to the real
axis, to $z_5(N):=-\sqrt{N}$, and so $z_4$ must be
\[
  z_4(N) := -\sqrt{N} + i (\Im z_0-(\sqrt{N}+\Re z_0) \Im \rho / \Re \rho.
\]
Around the saddle point, we identify a range of width $O(N^{-39/112})$,
delimited by the points
\[
  z_2(N):=z_0-\rho N^{-39/112} \quad \text{and} \quad
  z_3(N):=z_0+\rho N^{-39/112}.
\]
In the lower half-plane, the contour is defined symmetrically.
We refer to the line from $z_2$ to $z_3$ to the (upper) central part
of the contour, as it gives the dominant contribution to the
integral (in the upper half-plane).
Note that $-39/112\approx -0.348$ is just a little bit smaller than $-1/3$.
To make the third-order term $N(z-z_0)^3$ in the local expansion of the integrand
negligible, we must have $z-z_0 \ll N^{-1/3}$. It is convenient
to make the central part as large as possible, though, because
this causes faster decrease of $F=e^f$ at $z=z_2(N)$
and $z=z_3(N)$, which
in turn makes it easier to beat the estimate for~$h$ from Lemma~\ref{le:mellin}.
(For details, see the tail estimate in Lemma~\ref{le:tail} below.)

Part~(i) of Lemma~\ref{le:mellin} provides the local
expansion in the central range, where $z=z_0+t\rho$,
$-N^{-39/112}\leq t \leq N^{-39/112}$:
\begin{multline}\label{eq:loc expans}
  f(z,N) = - N \log(1 -e^{z_0}) -\tfrac12 \alpha N t^2 - \tfrac12 \log N \\
     + (l-\tfrac12)\log(-z_0) -\tfrac12 (\log2\pi +\log(1-e^{z_0}))
      + O(N^{-5/112}).
\end{multline}
(Note that the expansion was simplified by using the defining equation~\eqref{eq:z0}
of~$z_0$.) The constant
\[
  \alpha := -\frac{\rho^2e^{z_0}} {z_0(1-e^{z_0})} \approx 0.028
\]
is real and positive. Since
\[
  \int_{-N^{-39/112}}^{N^{-39/112}}\exp(-\tfrac12 \alpha N t^2)dt
  \sim \frac{1}{\sqrt{\alpha N}}\int_{-\infty}^{\infty}e^{-x^2/2}dx
  = \sqrt{\frac{2\pi}{\alpha N}},
\]
with exponentially decaying error term,
the saddle point integral has the asymptotics
\begin{equation}\label{eq:sp int}
  \int_{z_2(N)}^{z_3(N)} e^{f(z,N)}dz =
  \frac{\rho(-z_0)^{l-1/2}}{ \sqrt{\alpha(1-e^{z_0})}}
  \frac1N (1-e^{z_0})^{-N}(1+O(N^{-5/112})).
\end{equation}
The integral over the lower saddle point segment is
\[
  \int_{\bar{z}_3(N)}^{\bar{z}_2(N)}e^{f(z,N)}dz =
    - \overline{\int_{z_2(N)}^{z_3(N)} e^{f(z,N)}dz},
\]
and thus the contribution of both saddle points to the integral~\eqref{eq:F}
is
\[
   \frac{(-1)^{l-1}}{\pi N^l} \Im \left(
     \int_{z_2(N)}^{z_3(N)} e^{f(z,N)}dz \right).
\]
By~\eqref{eq:sp int}, we see that this gives the right hand
side of~\eqref{eq:C asympt}.

To show that the two small line segments containing the saddle points~$z_0$
resp.~$\bar{z}_0$ capture
the asymptotics of the full integral~\eqref{eq:F},
we have to show that the remaining part of the contour in Figure~\ref{fig:path}
is negligible.
By conjugation, it clearly suffices to consider
the upper half-plane.
We begin with the part that, additionally, lies
in the half-plane $\Re z \leq N^{-7/8}$. In the next section,
we show that the integral over the remaining part tends exponentially to zero.

\begin{lemma}\label{le:tail}
  \begin{multline}\label{eq:tail ints}
     \int_{z_1}^{z_2} \mathbf{1}_{\{\Re z \leq -N^{-7/8}\}}F(z,N) dz
     + \int_{z_3}^{z_4}F(z,N) dz \\
+ \int_{z_4}^{z_5}F(z,N)dz = O\Big(b^N \exp\Big( -\tfrac13 \alpha N^{17/56} \Big)\Big).
  \end{multline}
\end{lemma}
\begin{proof}
  We begin with the first integral. By part~(ii)
  of Lemma~\ref{le:mellin}, $f=\log F$ satisfies
  \[
    f(z,N) = \frac{1}{z}\Big( \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}\Big)N
      + O(N^{33/112})
  \]
  there. It is straightforward to verify that the function
  \begin{equation}\label{eq:z Re}
   z\mapsto \Re\left(
  \frac{1}{z}\Big( \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}\Big)\right)
  \end{equation}
  increases as $z$ moves along the contour from $z_1$ to $z_0$.
  By~\eqref{eq:loc expans}, we can therefore bound the first integral in~\eqref{eq:tail ints} by
  \begin{align*}
    \exp &\left(    N \Re \left(     \frac{1}{z}
    \Big(     \mathrm{Li}_2(e^z) - \frac{\pi^2}{6}  \Big)
    \Big|_{z=z_2}
    \right)
    + O(N^{33/112})  \right)    \\
    &= |1-e^{z_0}|^{-N} \exp\Big( -\tfrac12 \alpha N^{17/56} + O(N^{33/112})\Big) \\
    &=   O\Big(b^N \exp\Big( -\tfrac13 \alpha N^{17/56} \Big)\Big),
  \end{align*}
  where the length of the contour was absorbed into the $O$.
  The second integral in~\eqref{eq:tail ints} can be estimated analogously,
   by part~(i) of Lemma~\ref{le:mellin}.
  the function~\eqref{eq:z Re} decreases only eventually as $z$ moves
  from~$z_3$ to~$z_4$, but it is nowhere larger than at $z_3$, which suffices.

  Finally, we bound the last integral in~\eqref{eq:tail ints}. The function
  $h$ from~\eqref{eq:h} is $o(1)$ here, by part~(i) of Lemma~\ref{le:mellin}.
  The factor $(e^z-1)^{-1/2}$ is $O(1)$, and $-\pi^2N/(6z)$ is
  $O(N^{1/2})$. The dilogarithm is $\mathrm{Li}_2(e^z) = O(e^{-\sqrt{N}})$,
  hence $(N/z)\mathrm{Li}_2(e^z) =  o(1)$,  and so
  \[
     f(z,N) = (l-\tfrac12)\log(-z) +O(N^{1/2}).
  \]
  As the integral of $(-z)^{l-1/2}$ from~$z_4$ to~$z_5$ grows only
  polynomially, the last integral in~\eqref{eq:tail ints}
  is $\exp(O(\sqrt{N}))$, and we are done.
\end{proof}

\section{Estimates close to the imaginary axis and in the right
half-plane}\label{se:right}

In the preceding section, have gave an asymptotic evaluation of the
integral~\eqref{eq:F}, where the contour was deformed as in
Figure~\ref{fig:path}, and $\Re z < -N^{-7/8}$. We now show that
the remaining part of the contour is negligible.
Close to the imaginary axis, where $-N^{-7/8} \leq \Re z \leq 0$,
we are outside of the validity region of the Mellin transform asymptotics
of Lemma~\ref{le:mellin}. We thus estimate the integrand
in~\eqref{eq:F} directly.
%
\begin{lemma}\label{le:iR}
  We have
  \[
    \int_{z_1}^{z_2} \mathbf{1}_{\{\Re z \geq -N^{-7/8}\}}F(z,N) dz = O(0.85^N).
  \]
\end{lemma}
\begin{proof}
For simplicity, we assume that $z$ lies on a horizontal line,
so that $\Im z=5$; this is justified, because the monotonicity
used in the proof of Lemma~\ref{le:tail} persists if we adjust the contour like
this in a small neighborhood of~$5i$.
  It thus suffices to show that
  \begin{equation}\label{eq:prod est}
      \prod_{j=1}^N \frac{1}{|1-e^{z j/N}|} = O(0.84^N),
   \end{equation}
  uniformly for $\Im z=5$ and $-N^{-7/8} \leq \Re z \leq 0$,
  because all other factors in~\eqref{eq:F} grow subexponentially.
  A simple calculation yields
  \begin{equation}\label{eq:abs expl}
    \frac{1}{|1-e^{z j/N}|} = \left(1+  e^{2j \Re(z)/N} - 2\cos(5j/N)
    e^{j \Re(z)/N} \right)^{-1/2}.
  \end{equation}
  We divide the product~\eqref{eq:prod est}
  into $j\leq N/10$ and $j>N/10$. In the latter range,
  we have $1/(1-\cos(5j/N))=O(1)$, and thus
  \begin{align}
    1+  e^{2j \Re(z)/N} - 2\cos(5j/N) e^{j \Re(z)/N}
      &= 2(1-\cos(5j/N))+ O(N^{-7/8}) \notag \\
    &= 2(1-\cos(5j/N))(1+ O(N^{-7/8})). \label{eq:j big}
  \end{align}
  Now $(1+ O(N^{-7/8}))^N$ grows subexponentially and can be ignored (by rounding
  up the exponential factor we finally obtain slightly). The remaining product
  \begin{equation}\label{eq:prod sum}
    \prod_{N/10 \leq j\leq N}(1-\cos(5j/N))^{-1/2} =
    \exp\left(-\frac12 \sum_{N/10 \leq j\leq N} \log(1-\cos(5j/N)) \right)
  \end{equation}
  can be treated by Euler's summation formula.
  We have, with $\phi(x):=-\log(1-\cos(5x/N))$,
  \begin{equation}\label{eq:euler}
    \sum_{N/10 \leq j\leq N} \phi(j) = \int_{\lfloor N/10 \rfloor}^{N+1} \phi(x)dx
    -\frac12(\phi(N+1)-\phi(\lfloor N/10 \rfloor)) +
    \int_{\lfloor N/10 \rfloor}^{N+1}(\{x\}-\frac12)\phi'(x)dx.
  \end{equation}
  The term $-\tfrac12(\dots)$ is clearly $O(1)$.
  Since $\phi'(x) = -5/N \cot(5x/2N)$, the last integral can be estimated by
  \begin{align*}
    \int_{\lfloor N/10 \rfloor}^{N+1} | \phi'(x) | dx
    &= \int_{ N/10 }^{N+1} | \phi'(x) | dx  + O(1) \\
    &= -\int_{ N/10 }^{\pi N/5}\phi'(x) dx + \int_{\pi N/5}^{N+1}\phi'(x)dx +O(1) \\
    &= -2\phi(\pi N/5)+\phi(N/10)+\phi(N+1)+O(1) = O(1).
  \end{align*}
  The main integral in~\eqref{eq:euler} can be done in closed form
  (with Mathematica, e.g.):
  \[
    \int \phi(x) dx = -\frac{5i x^2}{2N} + 2x \log(1-e^{5ix/N})
    - x \log(1-\cos(5x/n)) - \frac25 i N \mathrm{Li}_2(e^{5ix/N}).
  \]
  From this we easily deduce
  \[
     \int_{\lfloor N/10 \rfloor}^{N+1} \phi(x)dx = -c N + O(1),
  \]
  where
  \begin{multline*}
    c = \frac{1}{40}(99 i +8\log(1-e^{i/2}) -80 \log(1-e^{5i})
    -4\log(1-\cos(1/2)) \\
     + 40 \log(1-\cos 5)     -16i \mathrm{Li}_2(e^{i/2})
    +16i \mathrm{Li}_2(e^{5i})) \approx 0.11262.
  \end{multline*}
  Inserting all this into~\eqref{eq:prod sum} yields
  \[
    \prod_{N/10 \leq j\leq N}(1-\cos(5j/N))^{-1/2} = \exp(-\tfrac12 cN + O(1)),
  \]
  and therefore (without forgetting the factor~$2$ in~\eqref{eq:j big})
  \begin{equation}\label{eq:prod j big}
    \prod_{N/10 \leq j\leq N} \frac{1}{|1-e^{z j/N}|} = O(2^{-9N/20} e^{-cN/2}
    (1+\varepsilon)^N ) = O(0.7^N).
  \end{equation}

  Now we treat the range $j\leq N/10$. For this we prove an appropriate
  inequality. Noting that $\cos(5j/N)$ is positive, and using truncated
  Taylor series three times, we obtain
  \begin{align*}
    1+  e^{2j \Re(z)/N}& - 2\cos(5j/N)  e^{j \Re(z)/N}
    \geq 1+\left[1+x+\frac{x^2}{2}+\frac{x^3}{6} \right]_{x=2j \Re(z)/N} \\
    &- 2\left[1-\frac{x^2}{2}+\frac{x^4}{24} \right]_{x=5j/N} \cdot
    \left[1+x+\frac{x^2}{2} \right]_{x=j \Re(z)/N}.
  \end{align*}
  This can be bounded from below by
  \begin{equation}\label{eq:lower bd}
    \geq \frac{11j^2}{12N^2}(\Re(z)^2+25).
  \end{equation}
  The latter fact is a polynomial inequality with polynomial constraints,
  and can be established by cylindrical algebraic
  decomposition~\cite{Co75}, e.g., with Mathematica.
  Note that the form of~\eqref{eq:lower bd} was guessed from a Taylor expansion
  of~\eqref{eq:abs expl}
  for $j\approx 0$. From~\eqref{eq:abs expl}
  and~\eqref{eq:lower bd} we have the estimate
  \begin{align}
    \prod_{1\leq j\leq N/10} \frac{1}{|1-e^{z j/N}|} &\leq \prod_{1\leq j\leq N/10}
      \sqrt{\frac{12}{11}} \frac{N}{j} ((\Re z)^2 +25)^{-1/2} \notag \\
    &\leq \left( \frac{12}{275} \right)^{N/10} N^{N/10} \lfloor N/10 \rfloor!^{-1}(1+\varepsilon)^N  \notag \\
    & \leq \left(
     \left(\frac{12}{275}\right)^{1/20}(10e)^{1/10}(1+\varepsilon)\right)^N
    \leq 1.19^N, \label{eq:j small}
  \end{align}
  for $N$ large.
  Now multiply~\eqref{eq:prod j big} and~\eqref{eq:j small} to
  get the result.
\end{proof}

Finally, we estimate the integral over the right half-circle in~\eqref{eq:F},
which completes the proof of Theorem~\ref{thm:main}.
By the reflection formula~\eqref{eq:refl}, we can recycle part of the
analysis from the left half-plane.

\begin{lemma}
  \[
   \frac{(-1)^{l-1}}{N^l} \frac{1}{2i\pi} \int_{|z|=5}
     \mathbf{1}_{\{\Re z>0\}} F(z,N) dz = O(0.95^N).
  \]
\end{lemma}
\begin{proof}
  First consider the range $0< \Re z \leq N^{-7/8}$. All factors
  in front of the products in~\eqref{eq:F def} and~\eqref{eq:refl}
  grow at must subexponentially, and so this part of the integral
  is $O(0.85^N)$ by~\eqref{eq:refl} and~\eqref{eq:prod est}.

  On the other hand, for $N^{-7/8}< \Re z \leq 5$, the proof
  of Lemma~\ref{le:mellin} shows that the product in~\eqref{eq:refl}
  satisfies
  \[
    \prod_{j=1}^N \frac{1}{1-e^{-zj/N}} = \exp\left(
    -\frac{1}{z}\Big( \mathrm{Li}_2(e^{-z}) - \frac{\pi^2}{6}\Big)N
    +O(N^{33/112}) \right).
  \]
  The function
  \[
    z \mapsto \Re\left(-\frac{1}{z}
      \Big( \mathrm{Li}_2(e^{-z}) - \frac{\pi^2}{6}\Big) \right)
  \]
  increases as~$z$ moves on the arc from $-5i$ to $5$ and then
  decreases until $5i$. Close to the imaginary axis, where
  $|\arg z|\geq \tfrac{9}{20}\pi$, we thus
  have the bound
  \[
    \left|\exp\left(
    -\frac{1}{z}\Big( \mathrm{Li}_2(e^{-z}) - \frac{\pi^2}{6}\Big)N \right) \right|
    \leq 0.97^N,
  \]
  obtained by inserting $z=5\exp(\tfrac{9}{20}\pi i)$. Taking into account
  the subexponential factors, this portion of the integral
  is $O(0.98^N)$. If $|\arg z|\leq \tfrac{9}{20}\pi$, i.e., $z$ is bounded away
  from the imaginary axis, we get help from the factor $e^{-zN/2}$
  in~\eqref{eq:refl}. It is bounded by its absolute value
  at $z=5\exp(\tfrac{9}{20}\pi i)$, and thus not larger than $0.68^N$.
  Since
  \[
    \left|\exp\left(
    -\frac{1}{z}\Big( \mathrm{Li}_2(e^{-z}) - \frac{\pi^2}{6}\Big)N \right) \right|
    \leq 1.39^N,
  \]
  as found by plugging in $z=5$, the integral for $N^{-7/8}< \Re z$
  is $O(0.68^N \cdot 1.39^N)=O(0.95^N)$.
\end{proof}

\section{conclusion}

The error term that we obtained in~\eqref{eq:C asympt} can be improved a bit
by considering more terms of the local expansion~\eqref{eq:loc expans}
of~$f$ in the saddle
point analysis. Getting the \emph{correct} order of the error term, i.e.,
the next term in the asymptotic expansion of $C_{0,1,l}(N)$, needs some work, though.
As only the first term on the right-hand side of~\eqref{eq:f asympt}
was used to define the saddle point~$z_0$,
the logarithmic terms in~\eqref{eq:f asympt} contribute a non-vanishing
first order term $O(z-z_0)=O(N^{-39/112})$ to the expansion~\eqref{eq:loc expans}.
To improve it, we need to
replace~$z_0$ by a better approximation of the actual saddle point
of the whole integrand $F=e^f$. But then, the tail estimate in
Lemma~\ref{le:tail} becomes more involved,
because not only the width, but also the location of the saddle point
segment depends on~$N$.

Perhaps more importantly, we comment on possible future work.
Recall that Rademacher's conjecture essentially says that the operations
of limit and partial fraction decomposition commute in the present setting.
While our result refutes the conjecture, it does not clarify the relation
between the partial fraction decompositions of $\prod_{j\geq 1}(1-x^j)^{-1}$
and $\prod_{j=1}^N(1-x^j)^{-1}$; it would be surprising if there was none at all. O'Sullivan~\cite{oS12} suspects
that some modified version of the conjecture might hold, and presents
numerical evidence for convergence of $C_{h,k,l}(N)$ in terms
of Ces{\`ar}o means.

\bibliographystyle{siam}
\bibliography{../gerhold}

\end{document}


\section{Appendix A: Relational Algebra for Rule Evaluation}
Consider the following example:
\begin{align*}
&Order(1, 2),\; Order(2, 3). \quad\quad\quad\quad\quad\quad\quad\quad\quad[r_1]\\
&Order(x, z) \coloneqtwo Order(x, y),\; Order(y, z). \;\quad\quad\quad[r_2]
\end{align*}
\noindent
Rule $[r_1]$ states that the orders $1, 2$ and $2, 3$ holds. Rule $[r_2]$ states that the binary $Order$ relation is transitive. The BUN evaluation proceeds as follows. For each rule that is evaluated, an artificial body-relation $B$ is introduced. The body-relation will be incrementally populated and extended through the evaluation of the atoms in the body.

Initially, the relation associated with each atom is unnamed, i.e. the columns of the relation have no name-restrictions. Given a rule $r$, we order the atoms from the body of the rule as $A_1, \ldots, A_n$. We will consider each atom in turn and use the body relation $B$ as an accumulator. The equations describing the rule-evaluation process is as follows (the notation is explained below):
\begin{align*}
B^{0} &\leftarrow \top \\
B^{i + 1} &\leftarrow B^{i} \bowtie \sigmatwo_{Term(A_{i + 1})}\;(A_{i + 1}), \; i = 0, \ldots, n - 1\\
H & \leftarrow H \cup \Pi_{Term(H)}(B^n)
\end{align*}
\noindent
The body relation is initially assigned to $\top$ denoting an unknown relation: $\top \bowtie R = R \bowtie \top = R$. The $Term$ function gives the terms in the given atom. $H$ is the head of rule $r$. A selection is then done for the atom. The special selection operator is denoted $\sigmatwo$. Informally it selects a set of tuples from the relation associated with the atom that satisfies the constraints imposed by the terms of the atom. As a more formal example:
\begin{align*}
\sigmatwo_{x,x,y,c} = \rho_{x/x_1, y/y_1} \circ \Pi_{x_1, y_1} \circ \sigma_{x_1 = x_2, C_1 = c} \circ \rho_{x_1/N_0, x_2/N_1, y_1/N_2, C_1/N_3}
\end{align*}

The selection is for three variables $x, x, y$ and a constant $c$. First the rename operator $\rho$ is used to rename the columns of the relation ($N_i$ is an artificial initial name for column $i$). Then the ordinary $\sigma$ operator selects all tuples such that the corresponding variables and constants match under the given naming. The result of the selection is then projected (discarding duplicates and constants) using the projection operator $\Pi$, and finally the inverse renaming is performed.

The selection result is joined ($\bowtie$) with the current body relation $B^{i}$ to form the next body relation $B^{i + 1}$. In our example (assuming that $r_1$ has been evaluated) we get:
\begin{align*}
B^{1} &\leftarrow \sigmatwo_{x, y}\;(Order) = \{(1, 2), (2, 3)\}_{x, y}\\
B^{2} &\leftarrow B^{1} \bowtie (\sigmatwo_{y, z}\;(Order) = \{(1, 2), (2, 3)\}_{y, z})\\
      &= \{(1, 2), (2, 3)\}_{x, y} \bowtie \{(1, 2), (2, 3)\}_{y, z}\\
      &= \{(1,2,3)\}_{x,y,z}
\end{align*}
\noindent
Finally we project the result of $B^n$ and add the new tuples to the head relation:
\begin{align*}
Order & \leftarrow Order \cup (\Pi_{x,z}(\{(1,2,3)\}_{x,y,z}) = \{(1,3)\})
\end{align*}
\noindent
The process is iterated until a fix-point is found, i.e. until no new tuples can be derived from the set of rules. In our example, iterating $[r_2]$ again gives no new tuples and so the $Order$ relation has been computed as: $\{(1,2), (1,3), (2,3) \}$.
\clearpage
\section{Appendix B: Correctness of Type Algorithm}
For an atom $A$ in the type algorithm, let the corresponding set of tuples be denoted $A_R$. The typing algorithm reports a type error in one of two cases:
\begin{align*}
&\exists A \in PRED_{P_T}.\;\;|A_R| > 1 \quad\quad (1)\\
&\exists A \in PRED_{P_T}.\;\;|A_R| = 0 \quad\quad (2)
\end{align*}
\noindent
A Datalog program $P$ is said to be \textit{well-typed} if:
\begin{align*}
\forall A \in PRED_{P_T}. \;\; |A_R| = 1 \quad\quad (3)
\end{align*}
\noindent
Let $Pos(x, A)$ give the coordinate of term $x$ in predicate $A$, and $A[n]$ give type of $A$ at coordinate $n$. A rule with two atoms using the same variable name gives a \textit{type constraint}:
\begin{align*}
\infer[(\textit{C-VarLeft})]{A[Pos(x, A)] = \tau}{\begin{array}{c c} &B[Pos(x, B)] = \tau\\&\exists Rule: \ldots, A( \ldots, x, \ldots), \ldots, B(\ldots, x, \ldots), \ldots\end{array}}
\end{align*}
\begin{align*}
\infer[(\textit{C-VarRight})]{B[Pos(x, B)] = \tau}{\begin{array}{c c} &A[Pos(x, A)] = \tau\\&\exists Rule: \ldots, A( \ldots, x, \ldots), \ldots, B(\ldots, x, \ldots), \ldots\end{array}}
\end{align*}
\noindent
Let the type of a constant term $t$ be given by $T(t)$. We get the following constraint for constants:
\begin{align*}
\infer[(\textit{C-Constant})]{A[Pos(t, A)] = T(t)}{\exists Clause\;C: \ldots A(\ldots, t, \ldots), \ldots, \;\; t : Constant }
\end{align*}
\noindent
Finally, the semantics of $TYPEOF$ is added as a rule:
\begin{align*}
\infer[(\textit{C-TypeOf})]{A[Pos(\tau, TYPEOF)] = \tau}{\exists Fact: \; TYPEOF('A,\ldots, \tau, \ldots) }
\end{align*}

\noindent
We say that a type algorithm is \textit{correct} if the type solution satisfies the listed constraints together with the additional requirement that in a valid type assignment, each predicate is assigned exactly one type (property (3) above). \textit{C-TypeOf} is satisfied by the type-checking algorithm by construction. We now show that it additionally satisfies \textit{C-Constant} and \textit{C-Var}. Together with properties (1), (2) this is enough to show correctness since $(3) \iff \neg ((1) \lor (2))$.

\paragraph{Proposition: } \textit{The type-checking algorithm satisfies C-Constant}\NL
A clause is either a fact or a rule. All facts are lifted to the type level and thus trivially satisfy \textit{C-Constant}. Thus assume that have a rule with a constant use in an atom A. We will get a corresponding type-rule with head $R_i$ with $A$ unconditionally in the body:
\begin{align*}
R_i(\ldots) \coloneqtwo \ldots A(\ldots, c, \ldots) \ldots
\end{align*}
By the Datalog semantics, $|R_i| > 0$ if can derive that A contains a fact with the constant (lifted type) $c$ at coordinate $Pos(c, A)$. Since there is no other clause that derives facts for $R_i$, this is the only way to satisfy $|R_i| = 1$ (if $|R_i| \neq 1$ then algorithm fails due to (1), (2)).\\\hspace*{200pt}$\blacksquare$

\paragraph{Proposition: } \textit{The type-checking algorithm satisfies C-Var*}\NL
Since C-VarLeft and C-VarRight are completely symmetrical it suffices to show for C-VarLeft.
Assume that we have a rule $R$ that gets transformed to a type-rule with head $R_i$:
\begin{align*}
&R_i(\ldots, x, \ldots) \coloneqtwo \ldots, A( \ldots, x, \ldots), \ldots, B(\ldots, x, \ldots), \ldots\\
&B[Pos(x, B)] = \tau
\end{align*}
\noindent
The algorithm reports a type error iff (3) does not hold for the type-program. Thus $B[Pos(x, B)]$ has $\tau$ as the only member.
By the Datalog semantics (and from the fact that no other rule populates $R_i$), (3) holds if and only if $A[Pos(x, A)] = \tau$. \\\hspace*{200pt}$\blacksquare$
\clearpage
%\section{Appendix C: Plots for Experimental Data}
%\begin{figure}[!htb]
%%	\hspace*{-25pt}
%%	\begin{minipage}[b]{.5\textwidth}
%		\includegraphics[width=0.9\linewidth]{img/internalloglog.png}
%	%\end{minipage}%
%%	\hspace*{-40pt}
%%	\begin{minipage}[b]{.5\textwidth}
%%		\includegraphics[scale=0.35]{img/souffleloglog.png}
%%	\end{minipage}
%%	\label{figure:natExperimental}
%	\caption{Nat Example, Internal Evaluation (Naive)}
%\end{figure}
%\begin{figure}[!htb]
%	\centering
%	%	\hspace*{-25pt}
%	%	\begin{minipage}[b]{.5\textwidth}
%	\includegraphics[width=1.0\linewidth]{img/souffleloglog.png}
%	%\end{minipage}%
%	%	\hspace*{-40pt}
%	%	\begin{minipage}[b]{.5\textwidth}
%	%		\includegraphics[scale=0.35]{img/souffleloglog.png}
%	%	\end{minipage}
%	%	\label{figure:natExperimental}
%	\caption{Nat Example, Souffle Evaluation (Semi-Naive)}
%\end{figure}
%\begin{figure}[!htb]
%	\centering
%	%	\hspace*{-25pt}
%	%	\begin{minipage}[b]{.5\textwidth}
%	\includegraphics[width=1.0\linewidth]{img/ancestorInternal.png}
%	%\end{minipage}%
%	%	\hspace*{-40pt}
%	%	\begin{minipage}[b]{.5\textwidth}
%	%		\includegraphics[scale=0.35]{img/souffleloglog.png}
%	%	\end{minipage}
%	%	\label{figure:natExperimental}
%	\caption{Nat Example, Souffle Evaluation (Semi-Naive)}
%\end{figure}
%\begin{figure}[!htb]
%	\centering
%	%	\hspace*{-25pt}
%	%	\begin{minipage}[b]{.5\textwidth}
%	\includegraphics[width=1.0\linewidth]{img/ancestorSouffle.png}
%	%\end{minipage}%
%	%	\hspace*{-40pt}
%	%	\begin{minipage}[b]{.5\textwidth}
%	%		\includegraphics[scale=0.35]{img/souffleloglog.png}
%	%	\end{minipage}
%	%	\label{figure:natExperimental}
%	\caption{Nat Example, Souffle Evaluation (Semi-Naive)}
%\end{figure}
%
%
%%\begin{figure*}[!t]
%%	\hspace*{-70pt}
%%	\begin{minipage}[b]{.5\textwidth}
%%		\includegraphics[scale=0.345]{img/ancestorInternal.png}
%%	\end{minipage}%
%%	\hspace*{-70pt}
%%	\begin{minipage}[b]{.5\textwidth}
%%		\includegraphics[scale=0.35]{img/ancestorSouffle.png}
%%	\end{minipage}
%%	\label{figure:ancestorExperimental}
%%	\caption{Ancestor Example, \textbf{Left: } Internal (Naive), \textbf{Right: } Souffle (Optimized Semi-Naive)}
%%\end{figure*}


\section{Matrices}
\noindent
Matrices are an array of mathematical objects, most often numbers. They are often used to represent linear transformations between two spaces and systems of linear equations. We denote the size of a matrix by saying the number of rows then the number of columns.

\ifodd\includeBackgroundReviewExamples\input{./backgroundReview/matrices/matrices_example.tex}\fi

% Types of matrices
\input{./backgroundReview/matrices/typesOfMatrices.tex}
% Row Reduction
\input{./backgroundReview/matrices/rowReduction.tex}
% Determinants
\input{./backgroundReview/matrices/determinants.tex}
% Eigenvalues/vectors
\input{./backgroundReview/matrices/eigenvaluesEigenvectors.tex}


\chapter{Error Calculation}
%------------------------------------------------------------------------------
\section{Error Between Two Sinusoidal Signals}
\label{Ap_Err2S}

The motion equation of an assumed sinusoidal tremor with amplitude, $X_1$, and angular frequency, $\omega$, is represented by
\begin{equation}
x_1(t)= X_1 \cos \omega t.
\end{equation}


\lab{Algorithms}{Conformal Maps}{Conformal Maps}

\objective{To become familiar with some of the basic properties of conformal maps and some of their basic applications.}

The analysis of complex valued functions has been called ``one of the most beautiful and useful fields of mathematics.''  Conformal maps are special functions in complex analysis that have proven to be very useful in several applications, especially those that model physical phenomena.

\section*{Polar Representation of Complex Numbers}

One of the most important results in Complex Analysis is Euler's Formula. It states that:

$$e^{i\theta}=cos(\theta)+i sin(\theta)$$.

One way to derive this important result is to consider the taylor series expansion of each of the functions involved.

From this formula, we can see that $e^x$ maps the imaginary axis onto the unit circle on the complex plane. From our knowledge of the sine and cosine functios, we can also know that this mapping has a period of $2\pi$. From here, notice that we may represent any number on the complex plane in the form $r e^{i\theta}$ for $r\geq 0$ and $0 \leq \theta \leq 2\pi$. This is what is known as the polar representation of a complex number. It is identical to the polar representation of points in the standard cartesian plane, except for the use of the function $e^x$. The number $\theta$ is known as the argument, or phase, of a complex number. The number $r$ is known as the modulus, magnitude, or absolute value of a complex number. In the complex plane we define $|z|$ as the modulus of $z$ and $arg(z)$ as the argument of $z$. These functions are implimented in python through the \li{abs} and \li{sp.angle} functions. The function \li{abs} is a function that is built into python. It is not necessary to import scipy to be able to use it.

It is worth noting that the functions $e^x$, $sin(x)$, and $cos(x)$ are implimended in scipy as \li{sp.exp}, \li{sp.sin}, and \li{sp.cos} respectively. Other trigonometric functions are also usable in a similar manner.

In python we can make a complex number using the \li{complex} function. For example \li{a=complex(1,2)} assigns the value of $a$ to $1+2i$. This is another function which is built into python and not imported as part of scipy.

In scipy the functions \li{sp.real()} and \li{sp.imag()} return the real and immaginary parts of a complex number respectively.

It is also important to understand the idea of the complex conjugate of a number. This is often denoted $\bar{z}$. For $z=a+bi$, $\bar{z}=a-bi$. In scipy, the complex conjugate function is \li{sp.conj}.

The functions that are built into scipy are good for evaluating over arrays of complex numbers. In the case that you do not need to map the function over the array it is often much faster to use the built in module cmath. This module is built into python and includes many of the basic operations you will need when working with complex numers. $Re(z)$ is \li{z.real}, $Im(z)$ is \li{z.imag}, $Arg(z)$ is \li{z.phase()}, $sin(z)$ is \li{cmath.sin(z)}, $cos(z)$ is \li{cmath.cos(z)}, $e^z$ is \li{cmath.exp(z)}, etc.

\begin{problem}
Write a function which accepts a complex number $z$ and returns the ordered pair $(r,\theta)$ corresponding to the polar representation of $z$. Include a special case for $z=0$. Use the built in real part and imaginary part functions, not the modulus and argument functions. You may use the functions \li{sp.arcsin}, \li{sp.arccos}, and \li{hypot} .
\end{problem}

\section*{Conformal Maps}

We begin by examining some maps on the complex plane.  Let
\[
f(z) = \frac{3z - 4}{z - 2}
\]
and
\[
g(z) = z^2 - 2
\]
What happens if we map the box $[0,1]\times[0,i]$ under these mappings?
\newpage
Looking at $g(z)$, we see the box turn into a sort of curved triangle.  On the other hand, if we look at $f(z)$, it seems like there is even more distortion than in the case of $g(z)$.
\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{map1}
\caption{The box $[0,1]\times[0,i]$ under g(z).  The vertical axis is the imaginary line and the horizontal axis is the real line.}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
\includegraphics[scale=0.5]{map2}
\caption{The box $[0,1]\times[0,i]$ under f(z).}
\end{center}
\end{figure}

There is a fundamental difference between these two mappings.  Though in both cases the shape is significantly distorted, in the case of $f(z)$ the angles where two sides meet are preserved, whereas $g(z)$ distorts not only the shape of the lines but also the angles where they meet.  Maps that preserve angles, as in the case of $f(z)$, are called conformal.

\begin{figure}
\begin{center}
\includegraphics[scale=0.33]{map3}
\includegraphics[scale=0.33]{map4}
%\includegraphics[scale=0.33]{./Applications_Labs/ConfMaps/map5}
\caption{Some more conformal maps}
\end{center}
\end{figure}

\begin{problem}
Write a Python script that transforms a shape on the complex plane using the the conformal maps that we have used in the examples.  What do you expect will happen to the unit circle on the complex plane under these transformations?  Do your predictions match the results?  Try this for several shapes.
\end{problem}

\section*{Holomorphic and Analytic Functions}

We will now briefly introduce the idea of holomorphic and analytic functions. Again, there is a lot of heighly developed theory behind these types of functions.

A complex valued function is said to be holomorphic at a point in the complex plane if it is complex differentiable at all points within some arbitrarily small distance of that point. This means that the limit $lim_{\Delta z \to 0} \frac{f(z+\Delta z)-f(z)}{\Delta z}$ exists and is finite. We say that a complex function is holomorphic at some point of the complex plane if it is complex differentiable for all points that are within some nonzero distance of that point. We say a function is holomorphic on a set if it is holomorphic at every point in the set.

A term that is more commonly used to refer to these functions is "Analytic." Generally a function is said to be analytic at a point if it is equal to a convergent power series within some arbitrarily small distance of that point. It can be proven that all holomorphic functions are analytic and that that all functions that are complex analytic are also holomorphic.

A useful result concerning holomorphic functions and conformal mappings is that a holomorphic function with a nonzero derivative on a given complex domain is also conformal on that domain. Strictly speaking, a set is said to be a domain in the complex plane if it contains none of its boundary points and if it lies in one connected whole. There is a more proper definition of connectivity as well, but we will not introduce it here.

Why all the trouble about holomorphic functions? Being holomorphic turns out to be a reasonably strict constraint on a complex function which allows us to know many things about its behavior, for example, any function that is holomorphic on a domain is also infinitely differentiable and infinitely integrable on that domain. It is a very useful property in both theoretical and real-world applications. There are specific applications in electrostatics, fluid flow, and many other fields.

Another useful fact about holomorphic functions is that sums, products and complositions of holomorphic functions are also holomorphic. Quotients of holomorphic functions are holomorphic everywhere where the denominator is nonzero.

One of the quickest ways to tell if a function is complex differentiable is that the real and imaginary parts of the function satisfy the Cauchy-Riemann Equations. To explore the meaning of this phrase, consider the function $f(z)$ on some domain of the complex plane. Let $z=x+i y$ where $x=Re(z)$ and $y=Im(z)$. We may rewrite $f(z)$ in the following form: $$f(z)=f(x+i y)=u(x,y)+i v(x,y)$$ where $u$ and $v$ are two unique real valued functions of two real variables. $f(z)$ will be complex differentiable at a point if and only if the two functions $u$ and $v$ are differentiable at that point and satisfy the equations $$\frac{\partial u}{\partial x}=\frac{\partial v}{\partial y}$$ and $$\frac{\partial u}{\partial y}=-\frac{\partial v}{\partial x}$$

\begin{problem}
Write a function which tests the following complex functions to determine whether or not they are complex diferentiable at a given point z. Do this by taking a sampling of points in a very small circle around z and using each of them to estimate the limit $lim_{\Delta z \to 0} \frac{f(z+\Delta z)-f(z)}{\Delta z}$. Then depending on whether or not the points all give a similar estimate for the limit, have the function return either "differentiable" or "not differentiable."

Use your function to test the following functions for differentiability

$Re(z)$ at $z=1+ i$

$\bar{z}$ at $z=1$

$z Re(z)$ at $z=0$ and at $z=1+ i$

$e^z$ at $\pi i$

$sin(x) cosh(y) + i cos(x) sinh(y)$ at $\pi i$

$sin(x) cosh(y) - i cos(x) sinh(y)$ at $\pi i$
\end{problem}

It follows from the Cauchy-Riemann Equations that if $f$ is holomorphic on a domain, the functions $u$ and $v$ are conjugate harmonic functions on that domain. This means that both $u$ and $v$ satisfy the Cauchy-Riemann Equations and Laplace's equation, which says that: $$\frac{\partial^2 u}{\partial x^2}+\frac{\partial^2 u}{\partial y^2}=0$$ and that: $$\frac{\partial^2 v}{\partial x^2}+\frac{\partial^2 v}{\partial y^2}=0$$.

\begin{problem}
Prove that for $u$ and $v$ as defiined above, if $f$ is analytic on a domain, then $u$ and $v$ will be conjugate harmonic on that domain.
\end{problem}

\begin{problem}
Show that if Laplace's Equation is true for some function $f$ on a domain $D$ that for some conformal mapping $g$, Laplace's Equation will also hold on the image of $D$ under $g(f(z))$.
\end{problem}

The theory of holomorphic functions and conformal mappings is highly developed and well studied.  Here we only scratch the surface and comment on an important theorem for applications that will be useful in later volumes.

% We may want to move the section on the Scwartz-Christoffel Transformation to the second lab on complex integration
% The formula itself requires complex integration, so it cannot serve more than an introductory purpose here.

\section*{The Schwarz-Christoffel Transformation}
This transformation is very useful in applications of complex analysis.  Once again, the theory behind this is very rich, and we only state a theorem and look at some simple implications here.

\begin{theorem}  Let $P$ be a polygon on the complex plane having consecutive corners at $z_1, z_2, ..., z_n$ with corresponding right turn angles $\theta_1, \theta_2,...\theta_n$.  Then there exists a function that is a one to one conformal map from the upper half plane onto the interior of $P$ of the form:
\[
f(z) = A\int_0^z (\zeta - x_1)^{\frac{\theta_1}{\pi}}..(\zeta - x_{n-1})^{\frac{\theta_{n-1}}{\pi}}d\zeta + B
\]
Where $\theta_i$ represents the angle made by adjacent sides of the polygon and $x_i \in \mathbb{R}$.
\end{theorem}

We omit the proof here.  Consider the power of this theorem - we are able to map the upper half of the complex plane onto a polygon of our choosing.  This is very powerful for finding the numerical solutions to differential equations that model physical systems.  It turns out that a conformal mapping retains sufficient structure of a domain so that a solution in a transformed domain will be the same as the solution in the original domain.  This fact along with the theorem allows us to take problems which may be very difficult to solve in one domain and transform the domain to a polygonal domain of our choosing where a solution is much easier to find.  We give an example of such a transformation using built in Python functions:

\begin{example}
We will give an example showing how to find a Schwarz-Christoffel transform.  Suppose we wish to transform the upper half plane onto the triangle with corners at $0, i,$ and $1$.  We choose $x_1 = -1$ and $x_2 = 1$.  Starting from the upper corner, we have $\theta_1 = \theta_2 = \frac{-3\pi}{4}$ and $\theta_3 = \frac{-\pi}{2}$.  Using theorem 36.1, we have an expression for our mapping:
\begin{align*}
f(z) &= A\int_0^z(\zeta + 1)^{\frac{-3}{4}}(\zeta - 1)^{\frac{-3}{4}}d\zeta + B \\
	 &= A\int_0^z(\zeta^2 - 1)^{\frac{-3}{4}}d\zeta + B
\end{align*}

\end{example}

\begin{problem}
Find the conformal map that transforms the upper half plane to the strip $|Re(z) < 1|, Im(z) > 0$.  Display the result in a meaningful way.
\end{problem}


%\section{\texorpdfstring{Polynomial Hierarchy cont}{Polynomial Hierarchy cont}}
%\vspace{5mm}
%\large

\begin{lemma}[Concatenation $A^{\ast}$]\label{concat}
	Let $\C$ be an arbitrary class from PH.
	Then
	\[ \forall A \in \C \iff A^{\ast} \in \C \]
	Where
	\[ A^{\ast} = \{ x |\ \exists n \exists y_1 \in A \ldots \exists y_2 \in A: x = (y_1, \ldots, y_n) \} \]
	And $\forall$ is a normal quantifier.

	In other words, concatenation of the words from $A$ are also in $A$.

	Note that comma separators are important to stay in the same complexity class.
	We cannot guess the split by brute force.
\end{lemma}
\begin{proof} Separately for every class in PH.

	1) $C = \Sigma_0 = \Pi_0 = \Delta_0 = \TP$.\\
	$\Leftarrow$ trivially $A \subseteq A^{\ast}$ for $n = 1$.
	$x = (y)$.\\
	"$\Rightarrow$". $\exists DTM\ M: A = L(M)$

	We run $M$ on all $y_1, y_2, \ldots, y_n$.
	We accept $\iff$ all computations on $y_i$ accepts.

	2) $C = \Delta_k$.
	Same as in 1). We have DTM with an oracle TM.

	3) $C = \Sigma_k, k > 0$.
	We have
	$ \exists NTM\ M$ with oracle $D \in \Sigma_{k - 1}: A = L(M, D)$.
	We simulate computation of $M$ on $y_1$.
	In every accepting path, we run $M$ on $y_2$. And so on.

	4) $C = \Pi_k$
	If there is at least one $y_i \in co-A$, whole string $(y_1, y_2, \ldots, y_n) \in (co-A)^{\ast}$.
	Therefore we proceed roughly the same as in 3), but we proceed for rejecting branches.
\end{proof}

\begin{consequence}\label{concat_cons}
	If we have $A,B,T \in \C \Rightarrow D \in \C$ where
	\[ D = \{ x |\ \exists a \in A, \exists b \in B, \exists t \in T: x = (a, b, t) \} \]

	Proof is the same, as of the lemma, but we have multiple TM.
\end{consequence}

\begin{theorem}[Polynomial hierarchy consequences]
	\[ \exists \Pi_k = \Sigma_{k + 1} \]

	e) from Polynomial Hierarchy with quantifiers \cref{polyn_q}
\end{theorem}
\begin{proof}
	"$\exists \Pi_k \subseteq \Sigma_{k + 1}$"

	\[ A \in \exists \Pi_k \iff \exists B \in \Pi_k \exists p: x \in A \iff \exists^{p(|x|)} y: (x,y) \in B \]
	Construct an $NTM\ M$ which works as following:
	\begin{enumerate}
		\item read x
		\item guess $y: |y| \leq p(|x|)$.
		\item ask oracle if $(x,y) \in B$
	\end{enumerate}

	We get
	\[ A = L(M, B) \Rightarrow A \in \TNP(\Pi_k) = \TNP(\Sigma_k) \stackrel{def}{=} \Sigma_{k + 1} \]

	"$\exists \Pi_k \supseteq \Sigma_{k + 1}$"

	Proof by induction on $k$.

	$k = 0$.
	\[ \Sigma_1 \subseteq \exists \Pi_0 = \exists \TP = \TNP \]

	Induction hypothesis: $\Sigma_k \subseteq \exists \Pi_{k - 1}$.
	Let $A \in \Sigma_{k + 1}$ be arbitrary.
	Then
	\[ \exists NTM\ M \exists B \in \Sigma_k: A = L(M, B) \]
	$x \in A \iff \exists$ accepting computation (polynomially long) of $M$ on input $x$ which asks if $z_1, z_2, \ldots, z_n \in B$ and if $w_1, \ldots, w_n \in co-B$.
	Alternatively
	\[ x \in A \iff \exists^{p(|x|)} y, \exists^{p(|x|)} z = (z_1, z_2, \ldots, z_n), \exists^{p(|x|)} w = (w_1, \ldots, w_n)\]
	such that $y$ encodes an accepting computation of $M$ on $x$ with positive queries $z_1, \ldots, z_n$ and negative queries $w_1, \ldots, w_n$.

	We claim that the language $L = \{ (x, y) \} \in \TP \subseteq \Pi_k$.

	We know
	\begin{gather*}
		B \in \Sigma_k \stackrel{\cref{concat}}{\Rightarrow} z \in B^{\ast} \in \Sigma_k \stackrel{i.h.}{\subseteq} \exists \Pi_{k - 1} \Rightarrow \exists D \in \Pi_{k - 1}, \exists p_1 \\
		co-B \in \Pi_k \stackrel{\cref{concat}}{\Rightarrow} w \in (co-B)^{\ast} \in \Pi_k
	\end{gather*}
	Then
	\[ z \in B^{\ast} \iff \exists^{p_1(|z|)} t: (z, t) \in D, D \in \Pi_{k - 1} \subseteq \Pi_k \]

	So
	\[x \in A \iff \exists^{p(|x|)} y \exists^{p(|x|)} z \exists^{p_1(|z|)} t \exists^{p(|x|)} w : (x, y) \in L, (z, t) \in D, w \in (co-B)^{\ast} \]

	Finally, define
	\[ E = \{ s |\ \exists y \exists (z, t) \exists w: (x, y) \in L, (z, t) \in D, w \in (co-B)^{\ast} \& s = \langle (x, y), (z, t), w \rangle \} \]
	By \cref{concat_cons} $E \in \Pi_k$.

	Then
	\[x \in A \iff \exists^{p_2(|x|)} (x, y), (z, t), w: \langle (x, y), (z, t), w \rangle \in E \]
	By definition $A \in \exists \Pi_k$.
\end{proof}

\begin{definition}[PH by alternating quantifiers]\label{ph_altern}
	\[ A \in \Sigma_k \iff \exists B \in \TP \exists p: x \in A \iff \exists^{p(|x|)} y_1, \forall^{p(|x|)} y_2 \ldots : (x, y_1, y_2, \ldots, y_k) \in B \]
	Also
	\[ A \in \Pi_k \iff \exists B \in \TP \exists p: x \in A \iff \forall^{p(|x|)} y_1, \exists^{p(|x|)} y_2 \ldots : (x, y_1, y_2, \ldots, y_k) \in B \]
\end{definition}
\begin{proof}
	Proof by induction on $k$.

	For $k = 0$ we have no quantifiers.
	\[ A \in \TP \exists B \in \TP \]
	we can take $A = B$.

	$k \to k + 1$. Let $A \in \Sigma_{k + 1} = \exists \Pi_k$.
	Then
	\[ \exists \Pi_k \exists p: x \in A \iff \exists^{p(|x|)} y: (x,y) \in B \]
	By the i.h.
	% todo finish, 4th lecture
	\[ \Rightarrow (x,y) \in B \iff \forall^{p(|x|)} y_1, \exists^{p(|x|)} y_2 \ldots : ((x,y), y_1, y_2, \ldots, y_k) \in D, D \in \TP \]
	Then
	\[ x \in A \iff \exists^{p_2(|x|)} y \forall^{p_1(|x|)} y_1 \exists^{p_2(|x|)} y_2 \ldots :(x, y, y_1, \ldots y_k) \in D \]
\end{proof}

\begin{example}
	Language from $\Sigma_2$.
	Optimization version (Boolean minimization).

	Input: CNF $F$\\
	Output: CNF $H: H \equiv F \land |H|$ is minimal (we can define minimal in many ways, e.g. minimal in bits to represent).

	Now we convert into decision problem.\\
	Input: CNF $F, k \in \N$ \\
	Question: $\exists CNF\ H: F \equiv H \land |H| \leq k $.

	Problem is in $\Sigma_k$ since
	\[ F \in BM \iff \exists^{|H| \leq |F|} H, \forall (x_1, \ldots, x_n): H \leq k \land F(x_1, \ldots, x_n) = H(x_1, \ldots, x_n) \]

	We also know $BM \in \Sigma_2-complete$.
\end{example}

\begin{note}
	If we have a hard problem, it can be encoded in CNF and solved by CNF machinery.

	CNF solvers are highly optimized over more than 20 years.
\end{note}


\section{Sensor Control}
\label{sec:sensorControl}

It has been decided to mount two different EV3 distance measurement sensors on the robot.
The first is a sonar sensor measuring distance by the reflection of high frequency sound waves on objects, and the second is an infrared sensor doing the same thing, but with light instead.
In the documentation\footnote{Document describing the EV3 sensors \url{http://s3.amazonaws.com/scschoolfiles/379/generalusing_sensors.pdf}.} of the sensors it is stated that the sonar sensor have a longer reach of about 2.5 meters, the reach is not exactly stated for the infrared sensor, but it is expected to be lower do to the scattering of light.
Af test is nedded to find the exact value for the infrared sensor range.
The infrared sensor on the other hand should be more precise at short distances.
The idea is to combine these two sensors and both get the benefits of the long range, and the short distance precision.

The sensor control functionality is separated in two classes, one is called \emph{Sensor} handling the EV3 interface and the calibration of the individual sensors, the other is called \emph{SensorFusion} ans is fusing the two sensor measurement into one distance, and also containing the unit tests of the entire sensor system.

\subsection{Sensor calibration}
\label{sec:SensorCalibration}

The infrared sensor is mounted in the front of the robot and the sonar on the back.
This physical setup means that the sensors are measuring a negative and positive offset.
It has been decided to calibrate the sensors to a point right between the wheels of the robot, as this point is stationary when the robot turns.
A simple paper line in front of a wall with marked distances from 10 cm to 80 cm with 5 cm jumps, is used to calibrate the sensors.
The sensor values from both sensors are logged at all marked distances, to get the characteristics of how the sensors operate at different distances.

Figure \ref{fig:SensorCalibration} show the calibration results, plotted in the software tool \emph{Graph}, that have the ability of calculating a linear trend line of a series of points.
It can be seen that the sonar have a very fine linear trend line, and an offset of $ -8.19 $.
The infrared sensor have as expected a shorter range of about 45 cm, where the data points starts to curve sideways.
Only the points below 45 is used to calculate the trend line, and have an offset of $ 10.6 $.

\pagebreak

\myFigure{Implementation/SensorControl/SensorCalibrationPlot}{Graph of the sensor calibration measurements. Points mark the measurements and the line is trend line of the points.}{fig:SensorCalibration}{0.8}

These offsets are included to the software by making an addition constant for each sensor.
This value is added to each sensor measurement in the \emph{Sensor} class to calibrate the sensor, as shown in listing \ref{list:NXT_sensorFuncs}.

\begin{lstlisting}[caption={The function for reading and calibrate the sensor measurements, from the sensor class}, label=list:NXT_sensorFuncs]
public double Read()
{
	Thread.Sleep(20);
	return _brick.Ports[_port].SIValue + calibrationAddition;
}
\end{lstlisting}

\subsection{Sensor fusion}

The sensor fusion is done with a simple Kalman filter setup of only using the update step, to combined the two distance measurements to a single hidden state of the "true" distance to the object, equations can be seen in chapter \ref{chp:kalman}.
Instead of the output matrix \emph{$H$} another matrix called \emph{$C$} is used, defining how much each sensor is contributing to the hidden state.
In this project C is defined so that both sensors are contributing equal to the result, with the C defined in equation \ref{eq:C_matrix}.

\begin{equation}
\label{eq:C_matrix}
C =
\begin{pmatrix}
1 \\
1
\end{pmatrix}
\end{equation}

As mentioned in the Kalman filter theory the Kalman gain is calculated from the variance of the hidden state $\boldsymbol{P}'_{k}$ and the variance of the sensor measurements $\boldsymbol{R}$.
The sensors variances is calculated by logging a big number of sensor measurements at different distances to determined the accuracy of each sensor.
The covariance matrix $\boldsymbol{R}$ of the sensors are shown in equation \ref{eq:R_matrix}.
It can be seen that the sonar sensor actually have a lower variance than the infrared sensor, this was not expected, but just mean that the Kalman filter will apply bigger weight on the sonar based on the variance of the sensors.

\begin{equation}
\label{eq:R_matrix}
R =
\begin{pmatrix}
v_{sonar} & 0 \\
0       & v_{infrared}
\end{pmatrix}
=
\begin{pmatrix}
0.12 & 0 \\
0       & 0.52
\end{pmatrix}
\end{equation}

The Kalman filter actually functions by combining three values, that is the two sensor measurements ${z}_{k}$ and the estimated hidden state from last sample ${x}'_{k}$.
In certain situation this is actually not preferable.
If for example the robot is doing a turn, and going from measuring a short distance to a box, to measuring a longer distance to for example a wall, the estimated hidden state will have a too big impact, and the fusion will make a wrong new distance estimate.
This could for example be fixed by setting a very high variance on the estimated hidden state, and thereby having a much higher weight on the sensor measurements.

It has been decided to fix this in another way, that was giving better results.
Instead of messing with the hidden state covariance matrix, a "simple" hidden state estimate is calculated before the Kalman filter by taking mean of the sensor values, and use this as the hidden state estimate ${x}'_{k}$.

As the infrared sensor starts to measure wrong at about 45 cm, sensor fusion is only used when the sonar distance is lower than 45 cm, else only the sonar is used.

A test of the sensor fusion and calibrated sensors have been conducted in the same way as described in section \ref{sec:SensorCalibration}, of making measurements at fixed distances from a wall.
The error of how wrong the measurements is compared to the true value is calculated for the sensor fusion and both calibrated sensors.
This test show a mean error of 0.8 from the sonar, -2.7 from the infrared sensor and -0.43 from the sensor fusion.
As expected from out measurements of the variance, the infrared sensor have a higher error, but the sensor fusion still mange to generate a result that is smaller than both sensors.

\pagebreak


\problemname{Cleaning Pipes}

\illustration{0.34}{sinkhole}{Picture of sink hole by Ogar93 via \href{https://commons.wikimedia.org/wiki/File:Sinkhole_at_Link%C3%B6ping_University.jpg
}{Wikimedia Commons}}%
\noindent
Linköping has a quite complex water transport system.
Around Linköping there are several wells from which water is drawn.
The water is then transported to other locations using pipes.
Each pipe is a straight canal from one of the wells to some location in the city.

All the pipes are at the same depth under ground.
Therefore, whenever two pipes cross, they form an intersection.
Luckily the pipe system was constructed in such a way that exactly two pipes meet at each such intersection.
The wells do not count as intersections.
Any number of pipes (including zero or more than two) may originate at each well.

The intersections pose a problem, since dirt (a mixture of lime and
other ``remains'') tends to get stuck there.  This dirt causes the
pipes to degrade and collapse, leading to the formation of large sink
holes.  Such sink holes have a mesmerising effect on the students in
Linköping, causing them to neglect their studies and remain
uneducated, which in the long run will lead to a collapse of not just
the pipe system but of the very fabric of society.
Therefore it is imperative that the pipes are regularly cleaned.
The Nordic Water Extraction and Redistribution Company (NWERC) --
which is in charge of Linköping's waterpipes -- has an ample fleet of robots to
perform this task. A robot can be inserted into a pipe at the well where the
pipe begins. The robot then goes through the pipe all the way to its end and
cleans all intersections along the way. After reaching the end, the robot turns
around and returns back to the well where it started.
In order to prevent robot collisions, government regulations stipulate that
whenever two pipes intersect, at most one of them may contain a robot.

% Per: removed -- already explained above that we want to clean the pipes
%The NWERC now wants to clean all the intersections in the whole water transport system.
Since the whole water system has to be shut down while it is being cleaned
(another government regulation), the NWERC would like to do the cleaning
quickly, by using a single batch of cleaning robots, all started at the same time.

Your task is to verify whether this can be done -- i.e., whether we can simultaneously
insert robots into a subset of the pipes in such a way that the robots will clean
all intersections and there will be no risk of two robots colliding.

\section*{Input}

The input consists of:
\begin{itemize}
\item one line with two integers $w$ ($1 \le w \le 1\,000$), the number of wells, and $p$ ($1 \le p \le 1\,000$), the number of pipes;
\item $w$ lines, the $i$th of which contains two integers $x_i$ and $y_i$ ($-10\,000 \le x, y \le 10\,000$), the position of well number $i$ (the wells are numbered from $1$ to $w$);
\item $p$ lines each with three integers $s$ ($1 \le s \leq w$), the well at which the pipe starts, and $x$ and $y$ ($-10\,000 \le x, y \le 10\,000$), the position at which the pipe ends.
\end{itemize}
Each pipe will contain exactly one well, the one at which it starts.
Any point shared by more than two pipes will be a well.
Any two pipes share at most one common point. The common point of two
pipes may be the endpoint of one or both of them.
All pipes have positive length.

\section*{Output}
If it is possible to clean all intersections as described above, output ``\texttt{possible}''. Otherwise, output ``\texttt{impossible}''.


\subsection{The trivial topology}

A topology which contains just \(X\) and \(\varnothing \) is the trivial topology.


\section{Definitions}
\label{sec:definitions}

We recall definitions known in the literature, for convenience of the reader.

It is well known that a language equation can be classified, at first instance,
according to the position of its unknown.
In  particular, we tipically have the following definitions.

\begin{definition}
	\label{dfn:ll-language-equation}
	A left-linear (ll) language equation in the unknown $r$ is a language
	equation of the form

	\begin{equation}
	\label{eqn:ll-language}
	r=ar+s
	\end{equation}
\end{definition}

\begin{definition}
	\label{dfn:rl-language-equation}
	A right-linear (rl) language equation in the unknown $r$ is a language
	equation of the form

	\begin{equation}
	\label{eqn:rl-language}
	r=ra+s
	\end{equation}
\end{definition}

A grammar in wich all productions for a given non-terminal identifiy ll or rl
language equations, always generates a regular language.

The problem of saying whether or not a context-free grammar $G$ generates a
regular language is very important.
In fact, a context-free grammar has greater expressiveness than a regular one.
On the other hand, a regular grammar is much lighter in terms of computational
complexity.
We call this problem \textit{Context-Free (CF) Regularity Problem}.

\begin{definition}
	\label{dfn:cf-regularity-problem}
	The \textit{Context-Free (CF) Regularity Problem} is the subset
	$\Re$ of $\{0,1\}^{*}$ defined as follows:

	\begin{equation}
	\label{eqn:cf-regularity-problem}
	\Re=\{\underline{G}|G\in[G_{CS}]\wedge L(G)\in[L_{REG}]\}
	\end{equation}

	where $\underline{G}$ is the encoding of a context-free grammar $G$ as a
	string in $\{0,1\}^{*}$, $[G_{CS}]$ is the class of context-free grammars,
	and $[L_{REG}]$ is the class of regular languages.
\end{definition}

We now introduce the new definitions, which will be essential in subsequent
sections.

\begin{definition}
	\label{dfn:bl-language-equation}
	A bilateral-linear language equation in the unknown $r$ is a language
	equation of the form

	\begin{equation}
	\label{eqn:ll-rl-language}
	r=ar+rb+s
	\end{equation}
\end{definition}

\begin{definition}
	\label{dfn:looking-forward-property}
	A grammar $G=(V_{T},V_{N},S,P)$ enjoys the looking forward property if and
	only if the digraph $D_{G}$, constructed as follows, does not have any cycle.

	Let $D_{G}$ be a digraph such that for all non-terminal symbol in $V_{T}$
	there exists a node in $D_{G}$, and for all production $A\rightarrow\alpha$
	in $P$ there exists an arc from $A$ to every non-terminal symbol in $\alpha$,
	with the exception of $A$ itself.
\end{definition}

\begin{definition}
	\label{dfn:pseudo-regular-partition}
	Given a grammar $G=(V_{T},V_{N},S,P)$, a symbol $A\in V_{N}$ and the subset
	$P_{A}\subseteq P$ of productions for the non-terminal $A$, the
	\textit{pseudo-regular partition} induced by $A$ is the partition
	$\Upsilon_{A}$ of $P_{A}$, defined as follows:

	\begin{equation}
	\label{eqn:pseudo-regular-partition}
	\Upsilon_{A}:=
	\biggl\{p\in P_{A} \;\bigg|\;
	\{A\rightarrow\alpha A\},
	\{A\rightarrow A\beta\},
	\{A\rightarrow\gamma\}
	\biggl\}
	\end{equation}

	where $\alpha,\beta,\gamma\in\left(V_{T}\cup V_{N}\setminus\{A\}\right)^{*}$.
\end{definition}