\documentclass[12pt,a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{graphicx}
\usepackage{biblatex}
\usepackage{hyperref}
\usepackage{cleveref}
\bibliography{MLnotes}
\title{Notes on the Mittag--Leffler function}
\author{William McLean}
\date{\today}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{example}[theorem]{Example}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareMathOperator*{\res}{res}
\newcommand{\arcosh}{\operatorname{arcosh}}
\newcommand{\diag}{\operatorname{diag}}
\newcommand{\argmin}{\operatorname*{arg\,min}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % %
\begin{document}
\maketitle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The two-argument, Mittag--Leffler function is defined by the power series
\begin{equation}\label{eq: E alpha beta def}
E_{\alpha,\beta}(z)=\sum_{n=0}^\infty\frac{z^n}{\Gamma(\beta+n\alpha)}
\quad\text{for $z\in\mathbb{C}$, $\alpha\ge0$, $\beta\in\mathbb{R}$.}
\end{equation}
The reciprocal of the Gamma function may be written as an integral along a
Hankel contour,
\[
\frac{1}{\Gamma(\beta+n\alpha)}=\frac{1}{2\pi i}\int_{-\infty}^{0^+}
    \frac{e^w\,dw}{w^{\beta+n\alpha}},
\]
where we take a branch cut along the negative real axis so that
$-\pi<\arg w<\pi$. Therefore, if $|z|<|w^\alpha|$ for all~$w$ on the contour,
then
\[
E_{\alpha,\beta}(z)=\frac{1}{2\pi i}\int_{-\infty}^{0^+}\frac{e^w}{w^\beta}
    \sum_{n=0}^\infty(zw^{-\alpha})^n\,dw
    =\frac{1}{2\pi i}\int_{-\infty}^{0^+}\frac{e^w}{w^\beta}\,
    \frac{dw}{1-zw^{-\alpha}},
\]
and so
\begin{equation}\label{eq: integral repn}
E_{\alpha,\beta}(z)=\frac{1}{2\pi i}\int_{-\infty}^{0^+}
    \frac{e^w\,dw}{w^\beta-zw^{\beta-\alpha}}.
\end{equation}

If $\alpha>0$, then it suffices to treat the case~$\beta>0$ because the identity
\begin{equation}\label{eq: beta identity}
z^rE_{\alpha,\beta+r\alpha}=E_{\alpha,\beta}(z)
    -\sum_{n=0}^{r-1}\frac{z^n}{\Gamma(\beta+n\alpha)},\quad
r\in\{1,2,3,\ldots\},
\end{equation}
allows us to express $E_{\alpha,\beta}(z)$ in terms
of~$E_{\alpha,\beta+r\alpha}(z)$.  Also, in the case~$\alpha=0$,
\[
E_{0,\beta}(z)=\frac{1}{\Gamma(\beta)(1+z)}.
\]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Taylor approximation for $z$ near zero}
Since
$\Gamma(t)\ge\Gamma(1{\cdot}46163\,21456\,31155)=0{\cdot}88560\,31944\,10889
=1/1{\cdot}12917\,38854\,50141$, a crude bound for the remainder term~$R_N(z)$
in the Taylor expansion,
\[
E_{\alpha,\beta}(z)=\sum_{n=0}^N\frac{z^n}{\Gamma(\beta+n\alpha)}+R_N(z)
\]
is given by
\[
|R_N(z)|\le1{\cdot}3\sum_{n=N+1}^\infty|z|^n=\frac{1{\cdot}3\,|z|^{N+1}}{1-|z|}
\quad\text{for $|z|<1$.}
\]
Hence, if
\[
N+1\ge\frac{\log\bigl((1-|z|)\epsilon/1{\cdot}3\bigr)}{\log|z|}
\quad\text{and}\quad|z|<1,
\]
then $|R_N(z)|\le\epsilon$.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Quadrature approximation: negative real argument}\label{sec: quad neg}
Assume now that $0<\alpha<1$. Let $x>0$ and put $z=-x$
in~\eqref{eq: integral repn} to obtain
\[
E_{\alpha,\beta}(-x)=\frac{1}{2\pi i}\int_{-\infty}^{0^+}
    e^wF(w,x)\,dw
\quad\text{where}\quad
F(w,x)=\frac{w^{\alpha-\beta}}{w^\alpha+x}.
\]
We note that since $|\arg(w)|<\pi$ if follows that $|\arg(w^\alpha)|<\alpha\pi$
so $w^\alpha+x\ne0$.  Consider the Hankel contour parameterised
by~\cite{WeidemanTrefethen2007}
\[
w(u)=\mu\bigl(1+\sin(iu-\phi)\bigr)\quad\text{for $-\infty<u<\infty$,}
\]
with $\mu>0$ and $0<\phi<\pi/2$. Since
\begin{align*}
\Re w&=\mu(1-\cosh u\,\sin\phi),\\
\Im w&=\mu\sinh u\,\cos\phi,
\end{align*}
we have
\[
\biggl(\frac{\Re w-1}{\mu\sin\phi}\biggr)^2
    -\biggl(\frac{\Im w}{\mu\cos\phi}\biggr)^2=1,
\]
showing that the contour is the left branch of an hyperbola with asymptotes
\[
\Im w=\pm(\Re w-1)\tan\phi.
\]
Thus,
\[
E_{\alpha,\beta}(-x)=\frac{1}{2\pi i}\int_{-\infty}^\infty
e^{w(u)}F\bigl(w(u),x\bigr)z'(u)\,du\approx Q_h(x),
\]
where, for a step size~$h>0$, we put
\[
u_n=nh,\qquad w_n=w(u_n),\qquad w'_n=w'(u_n),
\]
and define the series approximation
\[
Q_h(x)=\frac{h}{2\pi i}\sum_{n=-\infty}^\infty e^{w_n}F(w_n,x)w'_n.
\]
For a fixed~$v$ with $0<\phi+v<\pi/2$, we see that
$w(u+iv)=\mu\bigl[1+\sin(iu-(\phi+v)\bigr)\bigr]$ parameterises the left
branch of an hyperbola with asymptotes
\[
\Im w=\pm(\Re w-1)\tan(\phi+v).
\]
Putting
\[
M(x,v)=\int_{-\infty}^\infty\bigl|\exp\bigl(w(u+iv)\bigr)
    F\bigl(w(u+iv),x\bigr)w'(u+iv)\bigr|\,du
    \quad\text{for $-\phi<v<\frac{\pi}{2}$,}
\]
we have the error bound~\cite[Theorem~2.1]{WeidemanTrefethen2007}
\begin{equation}\label{eq: Qh error}
|Q_h(x)-E_{\alpha,\beta}(-x)|\le\frac{M(x,r)}{\exp(2\pi r/h)-1}
    +\frac{M(x,-s)}{\exp(2\pi s/h)-1}
\end{equation}
for $0<s<\phi$ and $0<r<\pi/2-\phi$.  For the finite sum,
\begin{equation}\label{eq: Q_hN}
Q_{h,N}(x)=\frac{h}{2\pi i}\sum_{n=-N}^N e^{w_n}F(w_n,x)w'_n,
\end{equation}
we have an additional truncation error
\[
T_{h,N}=h\sum_{n=N+1}^\infty\bigl(e^{w_n}F(w_n,x)w'_n
    +e^{w_{-n}}F(w_{-n},x)w'_{-n}\bigr).
\]
Choosing the largest possible values $s=\phi$~and $r=\pi/2-\phi$, the three
error terms are of order $\exp\bigl(-(\pi^2-2\pi\phi)/h\bigr)$,
$\exp(\mu-2\pi\phi/h)$ and $\exp\bigl(\mu(1-\cosh(Nh)\sin\phi)\bigr)$.
To balance these quantities, we seek to choose the parameters so that
\cite[(4.2)]{WeidemanTrefethen2007}
\[
-\frac{\pi^2-2\pi\phi}{h}=\mu-\frac{2\pi\phi}{h}
    =\mu\bigl(1-\cosh(Nh)\sin\phi\bigr).
\]
The left-hand equation implies that
\[
\mu=\frac{4\pi\phi-\pi^2}{h},
\]
which allows us to eliminate $\mu$ in the right-hand equation, to obtain
\[
\cosh(Nh)=\frac{2\pi\phi}{(4\phi-\pi)\pi\sin\phi}.
\]
We therefore define
\[
a(\phi)=\arcosh\biggl(\frac{2\pi\phi}{(4\phi-\pi)\pi\sin\phi}\biggr)
\quad\text{and}\quad b(\phi)=\frac{4\pi\phi-\pi^2}{A(\phi)}
\]
for $\pi/4<\phi<\pi/2$, and set
\[
h=\frac{a(\phi)}{N}\quad\text{and}\quad \mu=b(\phi)\,N,
\]
so that the error~$Q_{h,N}(x)-E_{\alpha,\beta}(-x)$ is order~$e^{-C(\phi)N}$
for
\begin{equation}\label{eq: C function}
C(\phi)=\frac{\pi^2-2\pi\phi}{A(\phi)}.
\end{equation}
\Cref{fig: C plot} shows a plot of~$C(\phi)$, and we find using a standard
optimization package that the maximum value occurs at
\[
\phi=\phi_\star=1.172104\quad\text{with}\quad C(\phi_\star)=2.315654.
\]
Furthermore,
\[
a(\phi_\star)=1.081792\quad\text{and}\quad
b(\phi_\star)=4.492075,
\]
leading to the optimal values
\[
h=h_\star=\frac{a(\phi_\star)}{N}\quad\text{and}\quad
\mu=\mu_\star=b(\phi_\star)\,N.
\]
Since $e^{B(\phi_\star)}=10.131547$ we expect to gain about an extra decimal
digit of accuracy each time we increase $N$ by~$1$.

\begin{figure}
\caption{Plot of $C(\phi)$ from~\eqref{eq: C function} showing the
maximum at~$\phi_\star$.}\label{fig: C plot}
\begin{center}
\includegraphics[scale=0.75]{Bplot.pdf}
\end{center}
\end{figure}

Notice that
\[
\frac{hw'(u)}{2\pi i}=\frac{h\mu}{2\pi}\,\cos(iu-\phi)
    =\frac{a(\phi_\star)b(\phi_\star)}{2\pi}\,\cos(iu-\phi)
\]
so we can re-write the sum~\eqref{eq: Q_hN} as
\[
Q_{hN}(x)=\frac{a(\phi_\star)b(\phi_\star)}{2\pi}\sum_{n=-N}^N
    e^{w_n}F(w_n,x)\cos(iu_n-\phi).
\]
Also, $u_{-n}=-u_n$, $w(-u)=\overline{w(u)}$~and
$F(\bar w,x)=\overline{F(w,x)}$, so the terms of the sum occur in complex
conjugate pairs,
\[
e^{w_{-n}}F(w_{-n},x)\cos(iu_{-n}-\phi)
    =\overline{e^{w_n}F(w_n,x)\cos(iu_n-\phi)}.
\]
Thus,
\[
Q_{h,N}(x)=\frac{a(\phi_\star)b(\phi_\star)}{\pi}\biggl(
    \tfrac12e^{w_0}F(w_0,x)\cos\phi
    +\sum_{n=1}^N\Re\bigl(e^{w_n}F(w_n,x)\cos(iu_n-\phi)\bigr)\biggr),
\]
but note that $w_n$~and $u_n$ depend on~$N$ through $h$~and $\mu$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Quadrature approximation: positive real argument}
We now consider
\[
E_{\alpha,\beta}(x)=\frac{1}{2\pi i}\int_{-\infty}^{0^+}
    e^wF(w,-x)\,dx,
\]
where the Hankel contour must pass to the right of the pole at~$w=x^{1/\alpha}$.
Write
\[
F(w,-x)=w^{\alpha-\beta}\,\frac{\rho(w,x)}{w-x^{1/\alpha}}\quad\text{where}\quad
\rho(w,x)=\frac{w-x^{1/\alpha}}{w^\alpha-x},
\]
and observe that $\rho(w,x)$ has a removable singularity at~$w=x^{1/\alpha}$.
In fact, using L'H\^ospital's rule,
\[
\rho(x^{1/\alpha},x)=\lim_{w\to x^{1/\alpha}}
    \frac{w-x}{w^\alpha-x}=\frac{x^{(1/\alpha)-1}}{\alpha},
\]
and if we define
\[
H(w;x)=\frac{w^{\alpha-\beta}\rho(w;x)
-(x^{1/\alpha})^{\alpha-\beta}\rho(x^{1/\alpha};x)}{w-x^{1/\alpha}}
    =\frac{w^{\alpha-\beta}}{w^\alpha-x}
    -\frac{\alpha^{-1}x^{(1-\beta)/\alpha}}{w-x^{1/\alpha}}
\]
then
\[
F(w;-x)=\frac{\alpha^{-1}x^{(1-\beta)/\alpha}}{w-x^{1/\alpha}}+H(w;x).
\]
Hence,
\begin{align*}
E_{\alpha,\beta}(x)&=\frac{1}{2\pi i}\int_{-\infty}^{0^+}e^w F(w;-x)\,dw\\
    &=\frac{\alpha^{-1}x^{(1-\beta)/\alpha}}{2\pi i}\int_{-\infty}^{0^+}
    \frac{e^w\,dw}{w-x^{1/\alpha}}
    +\frac{1}{2\pi i}\int_{-\infty}^{0^+}e^w H(w;x)\,dw,
\end{align*}
that is,
\begin{equation}\label{eq: pos H}
E_{\alpha,\beta}(x)=\alpha^{-1}x^{(1-\beta)/\alpha}\exp(x^{1/\alpha})
    +\frac{1}{2\pi i}\int_{-\infty}^{0^+}e^w H(w,x)\,dw.
\end{equation}
The integral term in \eqref{eq: pos H} can be approximated using the same
approach as in \Cref{sec: quad neg}, with $H(w,x)$ replacing $F(w,x)$.

To evaluate $H(w,x)$ for $w$ near~$x^{1/\alpha}$, put
\[
w=x^{1/\alpha}(1+\epsilon)\quad\text{where}\quad
\epsilon=\frac{w-x^{1/\alpha}}{x^{1/\alpha}}
\]
and define
\[
\psi_{1,\alpha}(\epsilon)=\frac{(1+\epsilon)^\alpha-1}{\epsilon}
    =\sum_{k=1}^\infty\binom{\alpha}{k}\epsilon^{k-1}
\]
and
\[
\psi_{2,\alpha}(\epsilon)
    =\frac{(1+\epsilon)^\alpha-(1+\alpha\epsilon)}{\epsilon}
    =\sum_{k=2}^\infty\binom{\alpha}{k}\epsilon^{k-2}.
\]
In this way,
\[
w^\alpha-x=x\epsilon\psi_{1,\alpha}(\epsilon)
    =x\epsilon[\alpha+\epsilon\psi_{2,\alpha}(\epsilon)],
\]
so
\begin{align*}
H(w;x)&=\frac{w^{\alpha-\beta}(w-x^{1/\alpha})
-\alpha^{-1}x^{(1-\beta)/\alpha}(w^\alpha-x)}{(w^\alpha-x)(w-x^{1/\alpha})}\\
&=\frac{x^{(\alpha-\beta)/\alpha}(1+\epsilon)^{\alpha-\beta}
(x^{1/\alpha}\epsilon)-x^{(1-\beta)/\alpha}x\epsilon
[1+\alpha^{-1}\epsilon\psi_{2,\alpha}(\epsilon)]}%
{x\epsilon\psi_{1,\alpha}(\epsilon)(x^{1/\alpha}\epsilon)}\\
&=\frac{x^{1+(1-\beta)/\alpha}\epsilon}{x^{1+(1/\alpha)}\epsilon}\,
\frac{[1+\epsilon\psi_{1,\alpha-\beta}(\epsilon)]
-[1+\alpha^{-1}\epsilon\psi_{2,\alpha}(\epsilon)]}%
{\epsilon\psi_{1,\alpha}(\epsilon)}\\
&=\frac{\psi_{1,\alpha-\beta}(\epsilon)-\alpha^{-1}\psi_{2,\alpha}(\epsilon)}%
{x^{\beta/\alpha}\psi_{1,\alpha}(\epsilon)},
\end{align*}
and thus
\[
H(x^{1/\alpha};x)=\frac{\psi_{1,\alpha-\beta}(0)
-\alpha^{-1}\psi_{2,\alpha}(0)}{x^{\beta/\alpha}\psi_{1,\alpha}(0)}
    =\frac{1+\alpha-2\beta}{2\alpha x^{\beta/\alpha}}.
\]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Asymptotic expansion: negative real argument}
Since
\[
\frac{1}{w^\beta-zw^{\beta-\alpha}}=\frac{-1}{zw^{\beta-\alpha}}
    \,\frac{1}{1-w^\alpha z^{-1}}
\]
and
\[
\frac{1}{1-w^\alpha z^{-1}}=\sum_{n=0}^{N-1}(w^\alpha z^{-1})^n
    +\frac{(w^\alpha z^{-1})^N}{1-w^\alpha z^{-1}},
\]
we see from~\eqref{eq: integral repn} that
\[
E_{\alpha,\beta}(z)=\sum_{n=0}^{N-1}\frac{-1}{2\pi i}\int_{-\infty}^{0^+}
    \frac{e^w(w^\alpha z^{-1})^n}{zw^{\beta-\alpha}}\,dw+R_N(z),
\]
where the remainder term is
\[
R_N(z)=\frac{-1}{2\pi i}\int_{-\infty}^{0^+}
    \frac{e^w(w^\alpha z^{-1})^N\,dw}{zw^{\beta-\alpha}(1-w^\alpha z^{-1})}.
\]
The $n$th term equals
\[
\frac{-z^{-1-n}}{2\pi i}\int_{-\infty}^{0^+}e^w w^{(n+1)\alpha-\beta}\,dw,
\]
and if we assume $\alpha-\beta>-1$ then by collapsing the contour onto the
negative real axis and using the substitutions~$w=re^{\pm i\pi}$, we obtain
\[
\frac{-1}{2\pi i}\int_{-\infty}^{0^+}e^w w^{(n+1)\alpha-\beta}\,dw
    =\frac{e^{i\pi[(n+1)\alpha-\beta]}-e^{-i\pi[(n+1)\alpha-\beta]}}{2\pi i}
    \int_0^\infty e^{-r}r^{(n+1)\alpha-\beta}\,dr
\]
so
\[
E_{\alpha,\beta}(z)=R_N(z)+\frac{1}{\pi}\sum_{n=0}^{N-1}
    \sin\pi[(n+1)\alpha-\beta]\,\Gamma\bigl((n+1)\alpha-\beta+1\bigr)z^{-n-1}.
\]
Also,
\begin{equation}\label{eq: RN(z)}
R_N(z)=\frac{-z^{-N-1}}{2\pi i}\int_{-\infty}^{0^+}
    \frac{e^w w^{(N+1)\alpha-\beta}}{1-z^{-1}w^\alpha}\,dw.
\end{equation}

Suppose $z=-x<0$, and choose $\theta\in(0,\pi/2)$.  Define the semi-infinite
lines
\[
\varGamma_\pm=\{\,re^{\pm i(\pi-\theta)}:0<r<\infty\,\},
\]
and consider
\[
R_N(-x)=\frac{(-1)^Nx^{-N-1}}{2\pi i}\int_{-\infty}^{0+}
    \frac{e^w w^{(N+1)\alpha-\beta}}{1+x^{-1}w^\alpha}\,dw.
\]
By integrating along $-\varGamma_-$ and $\varGamma_+$, we see that
\[
|R_N(-x)|\le\frac{x^{-N-1}}{\pi}\int_0^\infty
\frac{e^{-r\cos\theta}r^{(N+1)\alpha-\beta}}%
{|1+x^{-1}r^\alpha e^{i\phi}|}\,dr\quad\text{where}\quad
\phi=(\pi-\theta)\alpha.
\]
Since
\[
|1+x^{-1}r^\alpha e^{i\phi}|\ge\Re(1+x^{-1}r^\alpha\cos\phi)
    =1+x^{-1}r^\alpha\cos\phi,
\]
if $0<\phi\le\pi/2$ then $\cos\phi\ge0$ and hence $|1+x^{-1}r^\alpha|\ge1$ so,
using the substitution~$y=r\cos\theta$,
\begin{align*}
|R_N(-x)|&\le\frac{x^{-N-1}}{\pi}\int_0^\infty
    e^{-r\cos\theta}r^{(N+1)\alpha-\beta}\,dr
    =\frac{x^{-N-1}}{\pi}\,\frac{1}{(\cos\theta)^{(N+1)\alpha-\beta+1}}
    \int_0^\infty e^{-y}y^{(N+1)\alpha-\beta}\,dy\\
    &=\frac{(\cos\theta)^{1-\beta}}{\pi}\,
    \bigl(x(\cos\theta)^\alpha\bigr)^{-N-1}\,
    \Gamma\bigl((N+1)\alpha-\beta+1\bigr)=O(x^{-N-1}).
\end{align*}
Otherwise, if $\pi/2<\phi<\pi$, then $\cos\phi<0$ and we put $q=x/|\cos\phi|$
so that
\[
|1+x^{-1}r^\alpha e^{i\phi}|\ge1/2\quad\text{for}\quad 0<r<(q/2)^{1/\alpha}
\quad\text{and}\quad (3q/2)^{1/\alpha}<r<\infty,
\]
whereas, for $(q/2)^{1/\alpha}\le r\le(3q/2)^{1/\alpha}$, we use the lower bound
\[
|1+x^{-1}r^\alpha e^{i\phi}|\ge|\Im(1+x^{-1}r^\alpha e^{i\phi})|
    =x^{-1}r^\alpha|\sin\phi|.
\]
Thus, $|R_N(-x)|\le I_1+I_2$ where $I_1=O(x^{-N-1})$ and
\begin{align*}
I_2&=\frac{x^{-N}}{\pi\sin\phi}\int_{(q/2)^{1/\alpha}}^{(3q/2)^{1/\alpha}}
    e^{-r\cos\theta}r^{N\alpha-\beta}\,dr\\
&\le\frac{x^{-N}}{\pi\sin\phi}\,\exp\bigl(-(q/2)^{1/\alpha}\cos\theta\bigr)
    \biggl[\frac{r^{N\alpha-\beta+1}}{N\alpha-\beta+1}
    \biggr]_{(q/2)^{1/\alpha}}^{(3q/2)^{1/\alpha}}\\
&\le\frac{x^{-N-1}q\cos\phi}{\pi\sin\phi}\,(3q/2)^{N+(1-\beta)/\alpha}\,
\frac{\exp\bigl(-(q/2)^{1/\alpha}\cos\theta\bigr)}{N\alpha-\beta+1}
=O(x^{-N-1}),
\end{align*}
yielding the asymptotic expansion
\[
E_{\alpha,\beta}(-x)=\frac{1}{\pi}\sum_{n=1}^N(-1)^n
    \sin\pi(n\alpha-\beta)\,\Gamma(n\alpha-\beta+1)\,x^{-n}
    +O(x^{-N-1})\quad\text{as $x\to\infty$.}
\]
Notice that the identity
\[
\Gamma(z)\,\Gamma(1-z)=\frac{\pi}{\sin\pi z}
\]
allows us to re-write the expansion as
\[
E_{\alpha,\beta}(-x)=-\sum_{n=1}^N\frac{(-x)^n}{\Gamma(\beta-n\alpha)}
    +O(x^{-N-1}).
\]

By Stirling's formula,
\[
\log\Gamma(z)=z\log z-z+\tfrac12\log z+O(1)\quad\text{as $|z|\to\infty$,}
\]
so as $n\to\infty$, and putting $\beta'=1-\beta$,
\begin{align*}
\smash[b]{\log\biggl(\frac{\Gamma(n\alpha+\beta')}%
{\Gamma\bigl((n-1)\alpha+\beta')}\biggr)}&=
\bigl(n\alpha+\beta'\bigr)\log(n\alpha+\beta')\\
&\qquad{}-\bigl((n-1)\alpha+\beta'\bigr)
    \log\bigl((n-1)\alpha+\beta'\bigr)+O(1)\\
    &=\alpha\log(n\alpha+\beta')+\bigl((n-1)\alpha+\beta'\bigr)
    \log\frac{n\alpha+\beta'}{(n-1)\alpha+\beta'}+O(1)\\
    &=\alpha\log\bigl(n(\alpha+O(n^{-1})\bigr)+\bigl((n-1)\alpha+\beta'\bigr)
    \log\frac{1+O(n^{-1})}{1+O(n^{-1})}+O(1)\\
    &=\alpha\log n+O(1)=\log n^\alpha+O(1).
\end{align*}
Thus,
\[
\log\frac{\Gamma(n\alpha+\beta')x^{-n}}%
{\Gamma\bigl((n-1)\alpha+\beta'\bigr)x^{-n+1}}=\log{n^\alpha}{x}+O(1),
\]
showing that the terms of the asymptotic expansion decrease in magnitude until
$n^\alpha\approx x$.

For large~$n$, there is a risk that $\Gamma(n\alpha-\beta+1)$ overflows.
For example, in IEEE double precision arithmetic, $\Gamma(172)=\mathtt{Inf}$.
Standard numerical libraries therefore provide a $\log\Gamma(x)$ function
which will not overflow unless $x$ itself is close to overflowing.  We
therefore store
\[
a_n=(-1)^n\sin\pi(n\alpha-\beta)
\quad\text{and}\quad
b_n=\log\Gamma(n\alpha-\beta+1),
\]
and compute the terms of the asymptotic expansion as
\[
a_nb_nx^{-n}=a_n\exp(b_n-n\log x).
\]
(Notice that $a_1=\sin\pi(\beta-\alpha)>0$ if $0<\beta-\alpha<1$.)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Asymptotic expansion: positive real argument}
Putting $z=x>0$ in~\eqref{eq: RN(z)} gives
\[
R_N(x)=\frac{-x^{-N-1}}{2\pi i}\int_{-\infty}^{0^+}
\frac{e^w w^{(N+1)\alpha-\beta}}{1-x^{-1}w^\alpha}\,dw,
\]
where the Hankel contour must be such that $x<|w^\alpha|$ for all~$w$.
Since we want to consider large~$x$, we move the contour to the left of the
pole at~$w=x^{1/\alpha}$, picking up a residue
\[
\res_{w=x^{1/\alpha}}\frac{e^w w^{(N+1)\alpha-\beta}}{1-x^{-1}w^\alpha}
    =\lim_{w\to x^{1/\alpha}}e^w w^{(N+1)\alpha-\beta}\,
    \frac{w-x^{1/\alpha}}{1-x^{-1}w^\alpha}
    =\frac{-x^{N+1}}{\alpha}\,x^{(1-\beta)/\alpha}\exp(x^{1/\alpha}),
\]
leading to the expansion
\[
E_{\alpha,\beta}(x)=x^{(1-\beta)/\alpha}\exp(x^{1/\alpha})
    +\frac{1}{\pi}\sum_{n=1}^Na_nb_nx^{-n}+\tilde R_N(x).
\]

A deeper analysis of the exponential asymptotics of~$E_{\alpha,\beta}$ shows
that~\cite[Theorem~2.2]{WongZhao2002}
\[
E_{\alpha,\beta}(-x)=\frac{1}{\pi}\sum_{n=1}^{[x^{1/\alpha}]}
    A_nB_nx^{-n}+O\bigl(x^{1/2-\beta}e^{-x}\bigr)
\]
for $x>0$ and $0<\alpha\le 1-\epsilon$, where
\[
A_n=(-1)^{n+1}\sin\pi(n\alpha-\beta)
\quad\text{and}\quad
B_n=\Gamma(n\alpha-\beta+1).
\]
To reduce the risk of overflow for large~$n$, we store $\log B_n$ and compute
\[
B_nx^{-n}=\exp(\log B_n-n\log x).
\]
For optimal truncation, we choose $N$ so that if $x=N^\alpha$ (and hence
$N\approx x^{1/\alpha}$) then $B_Nx^{-N}=B_N/N^{N\alpha}<\epsilon$, or
equivalently,
\[
N\alpha\log N-\log B_N>\log\epsilon^{-1}.
\]

Replacing $\beta$ with $\beta-r\alpha$ in the identity~\eqref{eq: beta identity}
gives
\[
z^rE_{\alpha,\beta}(z)=E_{\alpha,\beta-r\alpha}(z)-\sum_{n=0}^{r-1}
\frac{z^n}{\Gamma(\beta-r\alpha+n\alpha)},
\]
and so
\[
E_{\alpha,\beta}(z)=z^{-r}E_{\alpha,\beta-r\alpha}(z)-\sum_{n=0}^{r-1}
\frac{z^{-(r-n)}}{\Gamma\bigl(\beta-(r-n)\alpha\bigr)},
\]
leading to the asymptotic expansion
\[
E_{\alpha,\beta}(z)=-\sum_{n=1}^r\frac{z^{-n}}{\Gamma(\beta-n\alpha)}
    +O(z^{-r-1}).
\]
Recalling that the Gamma function satisfies
\[
\Gamma(z)\Gamma(1-z)=\frac{\pi}{\sin\pi z},
\]
it follows that
\[
\frac{-1}{\Gamma(\beta-n\alpha)}=\frac{1}{\pi}\,\sin\pi(n\alpha-\beta)
    \Gamma(1+n\alpha-\beta),
\]
so
\[
E_{\alpha,\beta}(z)=\frac{1}{\pi}\sum_{n=1}^r\sin\pi(n\alpha-\beta)
    \Gamma(1+n\alpha-\beta)z^{-n}+O(z^{-r-1}).
\]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Chebyshev expansion}
Consider the substitution
\[
y=\frac{x-1}{x+1}\quad\text{for $0\le x<\infty$.}
\]
The function~$x\mapsto y$ maps the half-line~$[0,\infty)$ onto~$[-1,1)$, and
the inverse function~$y\mapsto x$ is given by
\[
x=\frac{1+y}{1-y}\quad\text{for $-1\le y<1$.}
\]
We define a function~$g$ by requiring that
\[
E_{\alpha,\beta}(-x)=\tfrac12(1-y)[1+(1+y)g(y)],
\]
or equivalently,
\[
g(y)=\frac{1}{1+y}\biggl(\frac{2E_{\alpha,\beta}(-x)}{1-y}-1\biggr).
\]
Notice that
\[
1+y=\frac{2x}{x+1}\quad\text{and}\quad 1-y=\frac{2}{x+1}.
\]

On the one hand, the power series~\eqref{eq: E alpha beta def} implies that
\[
g(y)=\frac{1}{2}\biggl(1-\frac{1}{\Gamma(\beta+\alpha)}\biggr)+O(x)
\quad\text{as $y\to-1$ (so $x\to0$),}
\]
and on the other hand, the asymptotic expansion~\eqref{eq: E minus asymptotic}
implies that
\[
g(y)=\frac{1}{2}\biggl(-1+\frac{1}{\pi}\,\sin\pi(\beta-\alpha)\,
    \Gamma(1+\alpha-\beta)\biggr)+O(x^{-1})\quad
\text{as $y\to1$ (so $x\to\infty$).}
\]
In particular, $g$ and all its derivatives are continuous on~$[-1,1]$.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Negative real argument when $1<\alpha<2$}
Assume for this section that $x>0$ and $1<\alpha<2$.  If follows that $F(w,x)$
has poles at $\gamma_\pm=x^{1/\alpha}e^{\pm i\pi/\alpha}$,
with $\arg\gamma_\pm=\pm\pi/\alpha$ and hence
\[
\frac{\pi}{2}<\arg\gamma_+<\pi
\quad\text{and}\quad
-\pi<\arg\gamma_-<-\frac{\pi}{2}.
\]
Let
\[
\varphi(w,x)=\frac{(w-\gamma_+)(w-\gamma_-)}%
{(w^\alpha+x)(2w-\gamma_+-\gamma_-)}
\]
so that
\[
\frac{1}{w^\alpha+x}=\varphi(w;x)\biggl(
    \frac{1}{w-\gamma_+}+\frac{1}{w-\gamma_-}\biggr)
\]
with
\[
\varphi(\gamma_\pm;x)=\lim_{x\to\gamma_\pm}\varphi(w;x)
    =\frac{\gamma_\pm^{1-\alpha}}{\alpha}.
\]
Putting
\[
H_\pm(w,x)=\frac{w^{\alpha-\beta}\varphi(w;x)
-\gamma_\pm^{\alpha-\beta}\varphi(\gamma_\pm;x)}{w-\gamma_\pm}
    =\frac{w^{\alpha-\beta}(w-\gamma_\mp)}{(w^\alpha+x)(2w-\gamma_+-\gamma_-)}
-\frac{\alpha^{-1}\gamma_\pm^{1-\beta}}{w-\gamma_\pm},
\]
we have
\[
w^{\alpha-\beta}\,\frac{\varphi(w;x)}{w-\gamma_\pm}
    =\frac{\alpha^{-1}\gamma_\pm^{1-\beta}}{w-\gamma_\pm}+H_\pm(w,x)
\]
so
\[
F(w,x)=\frac{1}{\alpha}\biggl(
     \frac{\gamma_+^{1-\beta}}{w-\gamma_+}
    +\frac{\gamma_-^{1-\beta}}{w-\gamma_-}\biggr)
    +H_+(w;x)+H_-(w;x)
\]
and hence
\begin{align*}
E_{\alpha,\beta}(-x)&=\frac{1}{2\pi i}\int_{-\infty}^{0^+}e^wF(w,x)\,dw\\
&=\frac{1}{\alpha}\,\bigl(\gamma_+^{1-\beta}e^{\gamma_+}
    +\gamma_-^{1-\beta}e^{\gamma_-}\bigr)
     +\frac{1}{2\pi i}\int_{-\infty}^{0^+}e^w\bigl(H_+(w,x)+H_-(w,x)\bigr)\,dw.
\end{align*}
Since
\begin{align*}
\gamma_+^{1-\beta}e^\gamma_+&=x^{(1-\beta)/\alpha}
    \exp\bigl(i\pi(1-\beta)/\alpha\bigr)
    \exp\bigl(x^{1/\alpha}(\cos\pi/\alpha+i\sin\pi/\alpha)\bigr)\\
    &=x^{(1-\beta)/\alpha}\exp(x^{1/\alpha}\cos\pi/\alpha)
    \exp\bigl(i\pi(1-\beta)/\alpha+ix^{1/\alpha}\sin\pi/\alpha\bigr)
\end{align*}
it follows that
\[
\gamma_+^{1-\beta}e^{\gamma_+}
    +\gamma_-^{1-\beta}e^{\gamma_-}
    =2x^{(1-\beta)/\alpha}\,\exp(x^{1/\alpha}\cos\pi/\alpha)
    \cos\bigl(\pi(1-\beta)/\alpha+x^{1/\alpha}\sin\pi/\alpha\bigr).
\]

To evaluate $H_\pm(w;x)$ for~$w$ near~$\gamma_\pm$, let
\[
w=\gamma_\pm(1+\epsilon_\pm)\quad\text{where}\quad
\epsilon_\pm=\frac{w-\gamma_\pm}{\gamma_\pm}.
\]
so that
\[
w^\alpha+x=-x(1+\epsilon_\pm)^\alpha+x
    =-x\epsilon_\pm\psi_{1,\alpha}(\epsilon_\pm)
    =-x\epsilon_\pm[\alpha+\epsilon_\pm\psi_{2,\alpha}(\epsilon_\pm)]
\]
with
\begin{gather*}
w-\gamma_\pm=\gamma_\pm\epsilon_\pm,\qquad
2w-\gamma_+-\gamma_-=w-\gamma_\mp+\gamma_\pm\epsilon_\pm,\\
w^{\alpha-\beta}=-x\gamma_\pm^{-\beta}
    [1+\epsilon_\pm\psi_{1,\alpha-\beta}(\epsilon_\pm)].
\end{gather*}
We have
\[
H_\pm(w;x)=\frac{w^{\alpha-\beta}(w-\gamma_\mp)(w-\gamma_\pm)
-\alpha^{-1}\gamma_\pm^{1-\beta}(w^\alpha+x)(2w-\gamma_\pm-\gamma_\mp)}%
{(w^\alpha+x)(2w-\gamma_+-\gamma_-)(w-\gamma_\pm)},
\]
where the numerator equals
\begin{align*}
-x\gamma_\pm^{-\beta}&[1+\epsilon_\pm\psi_{1,\alpha-\beta}(\epsilon_\pm)]
(w-\gamma_\mp)(\gamma_\pm\epsilon_\pm)
+\alpha^{-1}\gamma_\pm^{1-\beta}
x\epsilon_\pm[\alpha+\epsilon_\pm\psi_{2,\alpha}(\epsilon_\pm)]
(w-\gamma_\mp+\gamma_\pm\epsilon_\pm)\\
&=x\gamma_\pm^{1-\beta}\epsilon_\pm\Bigl(
[1+\alpha^{-1}\epsilon_\pm\psi_{2,\alpha}(\epsilon_\pm)]
(w-\gamma_\mp+\gamma_\pm\epsilon_\pm)
-[1+\epsilon_\pm\psi_{1,\alpha-\beta}(\epsilon_\pm)](w-\gamma_\mp)
\Bigr)\\
&=x\gamma_\pm^{1-\beta}\epsilon_\pm^2\Bigl((w-\gamma_\mp)
[\alpha^{-1}\psi_{2,\alpha}(\epsilon_\pm)-\psi_{1,\alpha-\beta}(\epsilon_\pm)]
+\gamma_\pm[1+\alpha^{-1}\epsilon_\pm\psi_{2,\alpha}(\epsilon_\pm)]\Bigr)
\end{align*}
and the denominator equals
\[
-x\epsilon_\pm\psi_{1,\alpha}(\epsilon_\pm)
(w-\gamma_\mp+\gamma_\pm\epsilon_\pm)
(\gamma_\pm\epsilon_\pm)=-x\gamma_\pm\epsilon_\pm^2\psi_{1,\alpha}(\epsilon_\pm)
(w-\gamma_\mp+\gamma_\pm\epsilon_\pm)
\]
so
\[
H_\pm(w;x)=\frac{(w-\gamma_\mp)
[\psi_{1,\alpha-\beta}(\epsilon_\pm)-\alpha^{-1}\psi_{2,\alpha}(\epsilon_\pm)]
-\gamma_\pm\alpha^{-1}\psi_{1,\alpha}(\epsilon_\pm)}%
{\gamma_\pm^\beta\,\psi_{1,\alpha}
(\epsilon_\pm)(w-\gamma_\mp-\gamma_\pm\epsilon_\pm)}.
\]
In particular,
\[
H_\pm(\gamma_\pm;x)
=\frac{(1+\alpha-2\beta)(\gamma_\pm-\gamma_\mp)-2\gamma_\pm}%
{\alpha\gamma_\pm^\beta(\gamma_\pm-\gamma_\mp)}.
\]
Similarly,
\[
H_\mp(w;x)=\frac{w^{\alpha-\beta}(w-\gamma_\pm)(w-\gamma_\mp)
-\alpha^{-1}\gamma_\mp^{1-\beta}(w^\alpha+x)(2w-\gamma_\mp-\gamma_\pm)}%
{(w^\alpha+x)(2w-\gamma_+-\gamma_-)(w-\gamma_\mp)},
\]
where the numerator equals
\begin{align*}
\gamma_\pm^{\alpha-\beta}&(1+\epsilon_\pm)^{\alpha-\beta}
(\gamma_\pm\epsilon_\pm)
(\gamma_\pm-\gamma_\mp+\gamma_\pm\epsilon_\pm)
+\alpha^{-1}\gamma_\mp^{1-\beta}x\epsilon_\pm\psi_{1,\alpha}(\epsilon_\pm)
(\gamma_\pm-\gamma_\mp+2\gamma_\pm\epsilon_\pm)\\
&=-x\epsilon_\pm\Bigl(\gamma_\pm^{1-\beta}(1+\epsilon_\pm)^{\alpha-\beta}
(w-\gamma_\mp)
-\alpha^{-1}\gamma_\mp^{1-\beta}\psi_{1,\alpha}(\epsilon_\pm)
(2w-\gamma_+-\gamma_-)\Bigr)
\end{align*}
and the denominator equals
\[
-x\epsilon_\pm\psi_{1,\alpha}(\epsilon_\pm)
(2w-\gamma_+-\gamma_-)(w-\gamma_\mp)
\]
so
\begin{align*}
H_\mp(w;x)&=\frac{\gamma_\pm^{1-\beta}(1+\epsilon_\pm)^{\alpha-\beta}
(w-\gamma_\mp)-\alpha^{-1}\gamma_\mp^{1-\beta}\psi_{1,\alpha}(\epsilon_\pm)
(2w-\gamma_+-\gamma_-)}%
{\psi_{1,\alpha}(\epsilon_\pm)(2w-\gamma_+-\gamma_-)(w-\gamma_\mp)}\\
&=\frac{\gamma_\pm^{1-\beta}(1+\epsilon_\pm)^{\alpha-\beta}}%
{\psi_{1,\alpha}(\epsilon_\pm)(2w-\gamma_+-\gamma_-)}
-\frac{\alpha^{-1}\gamma_\mp^{1-\beta}}{w-\gamma_\mp}.
\end{align*}
In particular,
\[
H_\mp(\gamma_\pm;x)=\frac{\gamma_\pm^{1-\beta}-\gamma_\mp^{1-\beta}}%
{\alpha(\gamma_\pm-\gamma_\mp)}=\frac{1}{x^{\beta/\alpha}}\,
\frac{\sin\pi(1-\beta)/\alpha}{\alpha\sin\pi/\alpha}.
\]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Parabolic contour}
Consider $\mathcal{C}$ of the form
\[
w(u)=\mu(iu+1)^2\quad\text{for $-\infty<u<\infty$,}
\]
with $\mu>0$.  It follows that
\begin{align*}
\Re w(u+iv)&=\mu\bigl((1-v)^2-u^2\bigr),\\
\Im w(u+iv)&=2\mu(1-v)u,
\end{align*}
and so $\Im w(u+iv)\to-\infty$ as~$|u|\to\infty$ provided $v<1$.  Thus, we can
apply the error bound~\eqref{eq: Qh error} for $r=1-\epsilon$ and $s>0$.
Neglecting $\epsilon$, we deduce that the error is of order
\[
\exp(-2\pi/h)+\exp\bigl(\mu(1+s)^2-2\pi s/h\bigr)
    +\exp\bigl(\mu(1-(Nh)^2)\bigr).
\]
The exponent
\[
\mu(1+s)^2-\frac{2\pi s}{h}=\mu\bigg[\biggl(1+s-\frac{\pi}{\mu h}\biggr)^2
    +\frac{2\pi}{\mu h}-\biggl(\frac{\pi}{\mu h}\biggr)^2\biggr]
\]
is minimised if
\[
s=1-\frac{\pi}{\mu h},
\]
and using this value we balance the three error terms by satisfying
\[
\frac{-2\pi}{h}=\frac{2\pi}{h}-\frac{\pi^2}{\mu h^2}=\mu\bigl(1-(Nh)^2\bigr).
\]
The left-hand equation yields $\mu h=\pi/4$ so $1-(Nh)^2=-2\pi/(\mu h)=-8$
and hence $Nh=3$.  Thus, for a given~$N$, the optimal quadrature parameters are
\[
h_\star=\frac{3}{N}\quad\text{and}\quad\mu_\star=\frac{\pi}{12}\,N,
\]
yielding an error of order $\exp(-2\pi/h_\star)=\exp(-2\pi N/3)$ or
$\exp(2\pi/3)^N\approx8.12^N$.

Since $w'(u)=2\mu i(iu+1)$ we see that
\[
\frac{hw'(u)}{2\pi i}=\frac{\mu h}{\pi}(iu+1)=\frac{1}{4}(1+iu)
\]
and so
\begin{align*}
Q_{h,N}(x)&=\frac{1}{4}\sum_{n=-N}^Ne^{w_n}f(w_n;x)(1+inh)\\
    &=\frac{1}{2}\biggl(\tfrac12e^{w_0}f(w_0;x)+\sum_{n=1}^N\Re\bigl(
    e^{w_n}f(w_n;x)(1+inh)\bigr)\biggr).
\end{align*}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Carath\'eodory--Fejer method}
Let $D=\{\,z\in\mathbb{C}:|z|<1\,\}$ denote the open unit disk in the complex
plane, so that its boundary~$\partial D=\{\,z\in\mathbb{C}:|z|=1\,\}$ is the
unit circle.  Given a function~$F:[-1,1]\to\mathbb{R}$ and an integer~$M\ge0$,
denote the partial Chebyshev expansion of~$F$ by
\[
F_M(x)=\sideset{}{'}\sum_{k=0}^Ma_kT_k(x)
    \equiv\tfrac12 a_0+\sum_{k=1}^Ma_kT_k(x)\quad\text{for
$-1\le x\le 1$,}
\]
where $T_k$ denote the Chebyshev polynomial (of the first kind) with degree~$k$,
and
\[
a_k=\frac{2}{\pi}\int_{-1}^1\frac{F(x)T_k(x)}{\sqrt{1-x^2}}\,dx
\]
is the $k$th Chebyshev coefficient of~$F$.  The change of variable
\[
x=\Re z=\tfrac12(z+z^{-1})
\]
defines a bijection~$z\mapsto x$ from the unit circle~$\partial D$ onto the
real interval~$[-1,1]$, with
\[
T_k(x)=\tfrac12(z^k+z^{-k}).
\]
Put $a_{-k}=a_k$ and define
\[
f_M(z)=\sum_{k=-M}^M a_kz^k,
\]
and given fixed integers $m\ge 0$~and $n\ge0$, let
\[
f^+(z)=\sum_{k=m-n+1}^M a_kz^k\quad\text{and}\quad
f^0(z)=\begin{cases}
    \sum_{k=n-m}^{m-n}a_kz^k,&\text{if $m\ge n$,}\\
    -\sum_{k=m-n+1}^{n-m-1}a_kz^k&\text{if $m<n$.}
       \end{cases}
\]
In this way,
\begin{equation}\label{eq: FM}
F_M(x)=\tfrac12f_M(z)=\tfrac12\bigl[f^+(z)+f^+(z^{-1}) +f^0(z)\bigr].
\end{equation}

We wish to approximate $F(x)$ by a rational function of type~$(m,n)$, that is,
by a function $R(x)=p(x)/q(z)$ where $p$~and $q$ are real polynomials of degree
$m$~and $n$, respectively.  Let $V_{mn}$ denote the set of such rational
functions, and let $\tilde V_{mn}$ denote the set of functions of the form
\[
\tilde r(z)=\sum_{k=-\infty}^m d_kz^k\bigg/\sum_{k=0}^n e_kz^k,
\]
where the coefficients $d_k$~and $e_k$ are real, the numerator converges to
a bounded analytic function in~$|z|>1$ and the denominator has no zeros
in~$D\cup\partial D$.

Construct a real, $(M-m+n)\times(M-m+n)$ symmetric Hankel matrix
\[
H=[H_{ij}]\quad\text{where}\quad
H_{ij}=\begin{cases}
    a_{m-n+i+j},&\text{if $i+j\le M-m+n$,}\\
    0,&\text{otherwise.}
\end{cases}
\]

\begin{example}
If $M=5$, $m=3$ and $n=4$, then
\[
H=\begin{bmatrix}
a_0&a_1&a_2&a_3&a_4&a_5\\
a_1&a_2&a_3&a_4&a_5&0\\
a_2&a_3&a_4&a_5&0  &0\\
a_3&a_4&a_5&0  &0  &0\\
a_4&a_5&0  &0  &0  &0\\
a_5&0  &0  &0  &0  &0
\end{bmatrix}.
\]
\end{example}

Since $H$ is real and symmetric, it has an eigenvalue decomposition
\[
H=U\Lambda U^\top,
\]
where $U=[\boldsymbol{u}_1\quad\boldsymbol{u}_2\quad\cdots
\quad\boldsymbol{u}_{M-m+n}]$ is orthogonal and
$\Lambda=\diag(\lambda_1,\lambda_2,\ldots,
\lambda_{M-m+n})$.  We order the (real) eigenvalues by absolute magnitude:
\[
|\lambda_1|\ge|\lambda_2|\ge\cdots\ge|\lambda_{M-m+n}|.
\]
We denote the $(n+1)$st eigenvalue and eigenvector by
\[
\lambda=\lambda_{n+1}\quad\text{and}\quad
\boldsymbol{u}_{n+1}=[u_0,u_1,\ldots,u_{M-m+n-1}]^\top,
\]
and define
\begin{align*}
b(z)&=\lambda z^M\sum_{j=0}^{M-m+n-1}u_jz^j\bigg/
\sum_{j=0}^{M-m+n-1}u_{M-m+n-j}z^j\\
    &=\lambda z^M\,\frac{u_0+u_1z+\cdots+u_{M-m+n-1}z^{M-m+n-1}}%
{u_{M-m+n-1}+u_{M-m+n-2}z+\cdots+u_0z^{M_n-m+n-1}}
\end{align*}
and
\begin{equation}\label{eq: upsilon}
\upsilon(z)=\sum_{j=0}^{M-m+n-1}u_{M-m+n-j}z^j.
\end{equation}
Since
\[
\sum_{j=0}^{M-m+n-1}u_jz^j=\sum_{j=0}^{M-m+n-1}u_{M-m+n-j}z^{M-m+n-j}
    =M^{M-m+n}\upsilon(z^{-1})
\]
we see that
\[
b(z)=\lambda z^{m-n}\frac{\upsilon(z^{-1})}{\upsilon(z)}.
\]
Thus, $|b(z)|=|\lambda|$ for~$z\in\partial D$, and since $\lambda$ and the
components of~$\boldsymbol{u}_{n+1}$ are real,
\begin{equation}\label{eq: b zbar}
\overline{\upsilon(z)}=\upsilon(\bar z)\quad\text{and}\quad
\overline{b(z)}=b(\bar z),
\end{equation}
and in particular,
\[
\overline{\upsilon(z)}=\upsilon(z^{-1})\quad\text{and}\quad
\overline{b(z)}=b(z^{-1})\quad\text{for $z\in\partial D$.}
\]

\begin{theorem}
The function $\tilde r^*=f^+-b$ is the unique best approximation to~$f^+$
from $\tilde V_{mn}$ on~$\partial D$, that is, $\tilde r^*$ is the unique
function in~$V_{mn}$ satisfying
\[
\|f^+-\tilde r^*\|_{L_\infty(\partial D)}=\min_{g\in\tilde V_{mn}}
\|f^+-g\|_{L_\infty(\partial D)}.
\]
Moreover,
\[
\|f^+-\tilde r^*\|_{L_\infty(\partial D)}=|\lambda|,
\]
and if $|\lambda_n|>|\lambda|>|\lambda_{n+2}|$ then the winding number
of~$b$ is $m+n+1$.
\end{theorem}
\begin{proof}
See~\cite[Theorem~1]{TrefethenGutknecht1983}.
\end{proof}

Define
\[
\tilde R(x)=\tfrac12\bigl[\tilde r^*(z)+\tilde r^*(z^{-1})+f^0(z)\bigr],
\]
and observe that by~\eqref{eq: FM},
\begin{equation}\label{eq: Rtilde FM}
\tilde R(x)=\tfrac12\bigl[f_M(z)-b(z)-b(z^{-1})\bigr]
    =F_M(x)-\tfrac12[b(z)+b(z^{-1})],
\end{equation}
so
\[
\tilde R(x)=F_M(x)-\Re b(z).
\]
The theorem above implies that there are points
\[
1=x_0>x_1>\cdots>x_{m+n+1}=-1
\]
such that
\[
\|F_M-\tilde R\|_\infty=|\lambda|\quad\text{and}\quad
(F_M-\tilde R)(x_j)=(-1)^j\lambda\quad\text{for $0\le j\le m+n+1$.}
\]

Let
\[
B(x)=\tfrac12[b(z)+b(z^{-1})]=\sideset{}{'}\sum_{k=0}^\infty b_kT_k(x)
\]
and note that the Chebyshev coefficients
\[
b_k=\frac{2}{\pi}\int_{-1}^1\frac{B(x)T_k(x)}{\sqrt{1-x^2}}\,dx
    =\frac{2}{\pi}\int_0^\pi B(\cos\theta)\cos(k\theta)\,d\theta.
\]
Thus, by~\eqref{eq: Rtilde FM},
\[
\tilde R(x)=\sideset{}{'}\sum_{k=0}^\infty\tilde c_kT_k(x)
\quad\text{where}\quad\tilde c_k=a_k-b_k.
\]

Let us factorize the polynomial~\eqref{eq: upsilon},
\[
\upsilon(z)=u_0\prod_{j=1}^{M-m+n}(z-\zeta_j),
\]
and number the zeros~$\zeta_j$ so that
\[
\begin{aligned}
|\zeta_j|&>1&&\text{for $1\le j\le J$,}\\
|\zeta_j|&<1&&\text{for $J+1\le j\le M-m+n$.}
\end{aligned}
\]
Define
\[
q(z)=\prod_{j=1}^J\frac{z-\zeta_j}{-\zeta_j},
\]
which satisfies $q(0)=1$, and
\[
Q(x)=\frac{q(z)q(z^{-1})}{q(i)q(-i)}
    =\prod_{j=1}^J\frac{(z-\zeta_j)(z^{-1}-\zeta_j)}{(i-\zeta_j)(-i-\zeta_j)}
    =\prod_{j=1}^J\frac{1+\zeta_j^2-2x\zeta_j}{1+\zeta_j^2}
    =\prod_{j=1}^J\biggl(1-\frac{2x\zeta_j}{1+\zeta_j^2}\biggr),
\]
which satisfies $Q(0)=1$ and $|Q(x)|>0$ for~$-1\le x\le 1$.  We therefore have
a Chebyshev expansion,
\[
\frac{1}{Q(x)}=\sideset{}{'}\sum_{k=0}^\infty\gamma_kT_k(x).
\]
Finally, we define
\[
P(x)=\sideset{}{'}\sum_{k=0}^m\beta_kT_k(x)
\]
where the Chebyshev coefficients satisfy
\[
\begin{bmatrix}
\gamma_0     &\gamma_1&\cdots&\gamma_m    &\cdots&\gamma_{2m-1}&\gamma_{2m}\\
\gamma_1     &\gamma_0&\cdots&\gamma_{m-1}&\cdots&\gamma_{2m-2}&\gamma_{2m-1}\\
\vdots       &\vdots  &\ddots&\vdots      &\ddots&\vdots       &\vdots\\
\gamma_m     &\gamma_{m-1}&\cdots&\gamma_0&\cdots&\gamma_{m-1} &\gamma_m\\
\vdots       &\vdots  &\ddots&\vdots      &\ddots&\vdots       &\vdots\\
\gamma_{2m-1}&\gamma_{2m-2}&\cdots&\gamma_{m-1}&\cdots&\gamma_0&\gamma_1\\
\gamma_{2m}  &\gamma_{2m-1}&\cdots&\gamma_m&\cdots&\gamma_1&\gamma_0
\end{bmatrix}
\begin{bmatrix}\beta_m\\ \beta_{m-1}\\ \vdots\\ \beta_0\\ \vdots\\
\beta_{m-1}\\ \beta_m
\end{bmatrix}
=\begin{bmatrix}\tilde c_m\\ \tilde c_{m-1}\\ \vdots\\ \tilde c_0\\ \vdots\\
\tilde c_{m-1}\\ \tilde c_m
 \end{bmatrix}.
\]
Here, the symmetric Toeplitz matrix is known to be positive definite.  Our
rational approximation is then
\[
F(x)\approx R(x)=\frac{P(x)}{Q(x)}.
\]

If we are given a function $G:[0,\infty]\to\mathbb{R}$, then by putting
\[
F(x)=G(t)\quad\text{where}\quad t=\frac{1+x}{1-x},
\]
we can construct $R(x)$ as above and use
\[
G(t)\approx R(x)\quad\text{where}\quad x=\frac{t-1}{t+1}.
\]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Adaptive Antoulas--Anderson algorithm}
We work with the barycentric representation
\[
r(z)=\frac{n(z)}{d(z)}
\quad\text{where}\quad
n(z)=\sum_{j=1}^m\frac{w_jf_j}{z-z_j}
\quad\text{and}\quad
d(z)=\sum_{j=1}^m\frac{w_j}{z-z_j},
\]
for a set of distinct (real or complex) \emph{support points} $z_1$, $z_2$,
\dots, $z_m$.  The \emph{data values} $f_1$, $f_2$, \dots, $f_m$ and
\emph{weight} $w_1$, $w_2$, \dots, $w_m$ may also be real or complex.  The
\emph{node polynomial} associated with the support points is
\[
\ell(z)=\prod_{j=1}^m(z-z_j),
\]
and if we define the polynomials of degree at most~$m-1$,
\[
p(z)=\ell(z)n(z)=\sum_{j=1}^mw_jf_j\prod_{\substack{k=1\\ k\ne j}}^m(z-z_k)
\quad\text{and}\quad
q(z)=\ell(z)d(z)=\sum_{j=1}^mw_j\prod_{\substack{k=1\\ k\ne j}}^m(z-z_k),
\]
then
\[
r(z)=\frac{p(z)}{q(z)}.
\]

The AAA algorithm requires as input a large
\emph{sample set}~$S=\{s_k\}_{k=1}^K\subseteq\mathbb{C}$.  In step~1,
we define the constant approximation
\[
r^{(1)}=\frac{1}{K}\sum_{k=1}^Kf(s_j)
\]
and choose $z_1\in S$ by requiring
\[
|f(z_1)-r^{(0)}|=\max_{z\in S}|f(z)-r^{(0)}|.
\]
Defining $f_1=f(z_1)$, $S^{(1)}=S\setminus\{z_1\}$ and the discrete 2-norm
\[
\|g\|_{S^{(1)}}=\sqrt{\sum_{k=1}^K|g(s_j)|^2},
\]
we choose
\[
w^{(1)}_1=\argmin_{|w|=1}
\bigl\|fd^{(1)}-n^{(1)}\bigr\|_{S^{(1)}},
\]
where
\[
n^{(1)}(z)=\frac{w^{(1)}_1f_1}{z-z_1}\quad\text{and}\quad
d^{(1)}(z)=\frac{w^{(1)}_1}{z-z_1}.
\]

For~$m\ge1$, at the start of the $m$th step we have already constructed
\[
r^{(m-1)}(z)=\frac{n^{(m-1)}(z)}{d^{(m-1)}(z)},\quad
n^{(m-1)}(z)=\sum_{j=1}^{m-1}\frac{w^{(m-1)}_jf_j}{z-z_j},\quad
d^{(m-1)}(z)=\sum_{j=1}^{m-1}\frac{w^{(m-1)}_j}{z-z_j}.
\]
We choose $z_m\in S^{(m-1)}=S\setminus\{z_1,z_2,\ldots,z_{m-1}\}$ by requiring
\[
\bigl|f(z_m)-r^{(m-1)}(z_m)\bigr|=\max_{z\in S^{(m-1)}}
    \bigl|f(z)-r^{(m-1)}(z)\bigr|,
\]
and put $f_m=f(z_m)$.  The vector of
weights~$\boldsymbol{w}^{(m)}\in\mathbb{C}^m$ is then chosen as
\[
\boldsymbol{w}^{(m-1)}=\argmin_{\|w\|=1}\|fd^{(m)}-n^{(m)}\|_{S^{(m)}}.
\]
We stop the iteration when this norm falls below the desired error threshhold.

To solve the least-squares problem at the $m$th step, we enumerate the elements
of the set~$S^{(m)}=\{s_{k_1},s_{k_2},\ldots,s_{k_{M-m}}\}$ and
define the column vectors
\[
\boldsymbol{S}^{(m)}=\begin{bmatrix}s_{k_1}\\ s_{k_2}\\ \vdots\\
s_{k_{K-m}}\end{bmatrix}
\quad\text{and}\quad
\boldsymbol{F}^{(m)}=\begin{bmatrix}f(s_{k_1})\\ f(s_{k_2})\\
\vdots\\ f(s_{k_{K-m}})\end{bmatrix},
\]
so that
\begin{equation}\label{eq: Aw}
f(s_{k_i})d^{(m)}(s_{k_i})-n^{(m)}(s_{k_i})
    =\sum_{j=1}^m\frac{F^{(m)}_i-f_j}{S^{(m)}_i-z_j}\,w_j
    =(A^{(m)}\boldsymbol{w})_i,
\end{equation}
where the $(K-m)\times m$ matrix~$A^{(m)}$ has entries
\[
(A^{(m)})_{ij}=\frac{F^{(m)}_i-f_j}{S^{(m)}_i-z_j}
\quad\text{for $1\le i\le M-m$ and $1\le j\le m$.}
\]
We compute the thin singular value decomposition $A^{(m)}=U\Sigma V^*$,
so $\Sigma=\diag(\sigma_1,\sigma_2,\ldots,\sigma_m)$ is $(M-m)\times m$ and
\[
\|A^{(m)}\boldsymbol{w}\|^2=\|\Sigma V^*\boldsymbol{w}\|^2
    =\sum_{j=1}^m\bigl(\sigma_j\boldsymbol{v}_j^*\boldsymbol{w}\bigr)^2,
\]
where $\boldsymbol{v}_j$ is the $j$th column of~$V$.  Since
$\sigma_1\ge\sigma_2\ge\cdots\ge\sigma_m$, the norm is minimised choosing
$\boldsymbol{w}=\boldsymbol{v}_m$, in which case
\[
\|fd^{(m)}-n^{(m)}\|_{S^{(m)}}=\|A^{(m)}\boldsymbol{w}^{(m)}\|=\sigma_m.
\]

In an alternative, non-interpolatory approach we set
\[
n(z)=\sum_{j=1}^m\frac{\alpha_j}{z-z_j}\quad\text{and}\quad
d(z)=\sum_{j=1}^m\frac{\beta_j}{z-z_j},
\]
so that instead of~\eqref{eq: Aw},
\[
f(s_i)d^{(m)}(s_i)-n^{(m)}(s_i)=\sum_{j=1}^m
\frac{\beta_jF_i-\alpha_j}{s_i-z_j}
    =\bigl(A_1^{(m)}\boldsymbol{\alpha}+A_2^{(m)}\boldsymbol{\beta}\bigr)_i,
\]
where the $K\times m$~matrices $A_1^{(m)}$~and $A_2^{(m)}$ have entries
\[
(A_1^{(m)})_{ij}=\frac{-1}{s_i-z_j}\quad\text{and}\quad
(A_2^{(m)})_{ij}=\frac{F_i}{s_i-z_j}.
\]
Let $A^{(m)}=[A_1^{(m)}\quad A_2^{(m)}]$ so that
\[
A_1^{(m)}\boldsymbol{\alpha}+A_2^{(m)}\boldsymbol{\beta}
    =A^{(m)}\begin{bmatrix}\boldsymbol{\alpha}\\ \boldsymbol{\beta}
\end{bmatrix}.
\]
We compute the SVD $A^{(m)}=U\Sigma V^\top$ and put
\[
\begin{bmatrix}\boldsymbol{\alpha}\\ \boldsymbol{\beta}\end{bmatrix}
    =V\boldsymbol{e}_{2m}.
\]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{A rational Remez algorithm}
For a function~$f:[a,b]\to\mathbb{R}$ we seek a rational approximation in
barycentric form,
\[
r(x)=\frac{N(x)}{D(x)},\qquad
N(x)=\sum_{k=0}^n\frac{\alpha_k}{x-t_k},\qquad
D(x)=\sum_{k=0}^n\frac{\beta_k}{x-t_k},
\]
and note that
\[
r(t_k)=\lim_{x\to t_k}r(x)=\frac{\alpha_k}{\beta_k}.
\]
The node polynomial associated with the~$t_k$ is denoted
\[
\omega_t(x)=\prod_{k=0}^n(x-t_k),
\]
and we define
\[
\mu_k(x)=\frac{\omega_t(x)}{x-t_k}=\prod_{\substack{p=0\\ p\ne k}}(x-t_p)
\]
so that $r(x)=p(x)/q(x)$ where
\[
p(x)=\omega_t(x)N(x)=\sum_{k=0}^n\alpha_k\mu_k(x)
\quad\text{and}\quad
q(x)=\omega_t(x)D(x)=\sum_{k=0}^n\beta_k\mu_k(x)
\]
are polynomials of degree~$n$.  The optimal $L_\infty$ approximation~$r^*$ has
the equioscillation property
\[
f(x_l)-r^*(x_l)=(-1)^{l+1}\lambda\quad\text{for $0\le l\le 2n+1$,}
\]
with
\[
a\le x_0<x_1<\cdots<x_{2n+1}\le b\quad\text{and}\quad
\lambda=\|f-r^*\|_{L_\infty(a,b)},
\]
assuming no degeneracy.

In the Remez algorithm, we start from candidate points~$x_l$ and seek weights
$\alpha_k$~and $\beta_k$, along with a value~$\lambda$, such that the resulting
$r$ has the equioscillation property.  We then update the~$x_l$ to be the
local extrema of this~$r$, and iterate until the amplitudes of the local extrema
are constant to within a desired tolerance.

The equioscillation property is equivalent to
\begin{equation}\label{eq: equiosc p q}
f(x_l)q(x_l)-p(x_l)=(-1)^{l+1}\lambda q(x_l)\quad\text{for $0\le l\le2n+1$.}
\end{equation}
Notice that
\[
\omega_x'(x)=\frac{d}{dx}\prod_{l=0}^{2n+1}(x-x_l)
    =\sum_{l=0}^{2n+1}\prod_{\substack{p=0\\p\ne l}}^{2n+1}(x-x_p)
\]
and in particular
\[
\omega_x'(x_l)=\prod_{\substack{p=0\\p\ne l}}^{2n+1}(x_l-x_p)
    =\biggl(\prod_{p=0}^{l-1}(x_l-x_p)\biggr)
    \biggl(\prod_{p=l+1}^{2n+1}(x_l-x_p)\biggr)\\
\]
so if we let
\[
d_l=\biggl(\prod_{\substack{p=0\\ p\ne l}}^{2n+1}|x_l-x_p|\biggr)^{-1/2}
\]
then
\[
\omega_x'(x_l)=(-1)^{2n+1-l}d_l^{-2}\quad\text{for $0\le l\le 2n+1$.}
\]
Hence, multiplying both sides of~\eqref{eq: equiosc p q} by~$d_l$ gives
\[
d_lf(x_l)\sum_{k=0}^n\mu_k(x_l)\beta_k-d_l\sum_{k=0}^n\mu_k(x_l)\alpha_k
    =(-1)^{l+1}d_l\lambda\sum_{k=0}^n\mu_k(x_l)\beta_l
\]
which is equivalent to the vector equation
\begin{equation}\label{eq: equiosc matrix}
DFM\boldsymbol{\beta}-DM\boldsymbol{\alpha}=\lambda DSM\boldsymbol{\beta},
\end{equation}
where
\[
\boldsymbol{\alpha}=\begin{bmatrix}
\alpha_0\\ \alpha_1\\ \vdots\\\alpha_n \end{bmatrix},\qquad
\boldsymbol{\beta}=\begin{bmatrix}
\beta_0\\ \beta_1\\ \vdots\\ \beta_n\end{bmatrix},\qquad
M=\begin{bmatrix}
\mu_0(x_0)&\mu_1(x_0)&\cdots&\mu_n(x_0)\\
\mu_0(x_1)&\mu_1(x_1)&\cdots&\mu_n(x_1)\\
\vdots    &\vdots    &\ddots&\vdots\\
\mu_0(x_{2n+1})&\mu_1(x_{2n+1})&\cdots&\mu_n(x_{2n+1})
\end{bmatrix}
\]
and
\[
D=\diag[d_l]_{l=0}^{2n+1},\qquad
F=\diag[f(x_l)]_{l=0}^{2n+1},\qquad
S=\diag[(-1)^{l+1}]_{l=0}^{2n+1}.
\]

Take the thin $QR$ decomposition
\[
DM=Q_1R,
\]
and put $Q_2=SQ_1$.  It can be shown~\cite[Lemma~4.3]{FilipEtAl2018} that
$M^\top SD^2M=0$, and therefore
\[
0=(D^{-1}Q_1R)^\top SD(Q_1R)=R^\top Q_1^\top D^{-1}SDQ_1R
=R^\top(SQ_1)^\top Q_1R=R^\top(Q_2^\top Q_1)R.
\]
Since $R$ is non-singular~\cite[Theorem~4.4]{FilipEtAl2018}, it follows that
\[
Q_2^\top Q_1=0.
\]
Rewriting \eqref{eq: equiosc matrix} as
\begin{equation}\label{eq: equiosc Q1}
FQ_1R\boldsymbol{\beta}-Q_1R\boldsymbol{\alpha}
    =\lambda SQ_1R\boldsymbol{\beta}.
\end{equation}
we multiply on the left by~$Q_2^\top=Q_1^\top S$ to
eliminate~$\boldsymbol{\alpha}$ and obtain
\[
Q_1^\top(SF)Q_1R\boldsymbol{\beta}=\lambda Q_1^\top S^2Q_1R\boldsymbol{\beta}
    =\lambda R\boldsymbol{\beta}.
\]
Equivalently,
\[
Q_1^\top(SF)Q_1\boldsymbol{y}=\lambda\boldsymbol{y}
\quad\text{where}\quad\boldsymbol{y}=R\boldsymbol{\beta},
\]
so we can compute $\boldsymbol{\beta}$ and $\lambda$ by solving a symmetric
eigenvalue problem.  Multiplying \eqref{eq: equiosc Q1} on the left
by~$Q_1^\top$ gives
\[
Q_1^\top FQ_1\boldsymbol{y}-R\boldsymbol{\alpha}
    =\lambda Q_1^\top SQ_1\boldsymbol{y}
    =\lambda Q_2^\top Q_1\boldsymbol{y}=\boldsymbol{0},
\]
and so we can determine $\boldsymbol{\alpha}$ by solving
\[
R\boldsymbol{\alpha}=Q_1^\top FQ_1\boldsymbol{y}.
\]
It can be shown that at most one eigenpair yields $q(x)=\omega_t(x)D(x)$ with
no root in~$[a,b]$.  We can determine this eigenpair by examining the signs of
\[
q(x_l)=\sum_{k=0}^n\beta_k\mu_k(x_l)=(M\boldsymbol{\beta})_l
    =(D^{-1}Q_1\boldsymbol{y})_l.
\]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\printbibliography
\end{document}


\chapter{parElm}

\section{Introduction}

A linearized process may have parameters that do not affect the behavior of that process in any way.
These parameters are called \emph{inert}.

Removing inert parameters from a process has the advantages of fewer states, smaller state vectors (and therefore reduced memory usage), and faster performance in general.
These advantages may be small; however, detection and removal of inert parameters can be done fairly cheaply.

\section{Algorithm}

The algorithm consists of the following steps \cite{groote2001computer}:

\begin{enumerate}

\item Mark all process parameters.
(This means that, initially, we assume that all process parameters are inert.)

\item Unmark all process parameters that occur in the guard of a summand.

\item Consider the assignments that occur as part of the recursive process instantiations of the summands of the LPE.
Unmark all process parameters that occur in the expression of which the value is assigned to an \emph{unmarked} process parameter.

\item Repeat the previous step until no process parameter is unmarked.
All remaining marked process parameters can be safely removed the process.

\end{enumerate}

\clearpage
\section{Example}

Consider the following LPE:

\begin{lstlisting}
//Process definition:
PROCDEF example[A :: Int, B](x, y, z :: Int)
  = A ? i [[x==0]] >-> example[A, B](i, y, z)
  + A ? i [[x==1]] >-> example[A, B](0, i, z)
  + B [[x==2]] >-> example[A, B](0, y, z)
  + B >-> example[A, B](z, y, x)
  ;

//Initialization:
example[A, B](0, 0, 0);
\end{lstlisting}

First, $x$ is unmarked, because it occurs in the guards of the first three summands.

In the fourth summand, $z$ is used in the expression of which the value is assigned to $x$.
Therefore $z$ must also be unmarked.

$y$ remains marked: it does not occur in a guard, nor is it used in the assignment to a process parameter other than itself.
Removing $y$ gives

\begin{lstlisting}
//Process definition:
PROCDEF example[A :: Int, B](x, z :: Int)
  = A ? i [[x==0]] >-> example[A, B](i, z)
  + A ? i [[x==1]] >-> example[A, B](0, z)
  + B [[x==2]] >-> example[A, B](0, z)
  + B >-> example[A, B](z, x)
  ;

//Initialization:
example[A, B](0, 0);
\end{lstlisting}


\documentclass[a4paper]{scrartcl}

% Text
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}

% Math
\usepackage{amsmath, amssymb}
\usepackage{bm}
	\newcommand{\vv}[1]{\ensuremath{\bm{#1}}}
	\newcommand\lphi{\ensuremath{\phi^{\text{left}}}}
	\newcommand\lH{\ensuremath{H^{\text{left}}}}
	\newcommand\lh{\ensuremath{h^{\text{left}}}}

	\newcommand\rphi{\ensuremath{\phi^{\text{right}}}}
	\newcommand\rH{\ensuremath{H^{\text{right}}}}
	\newcommand\rh{\ensuremath{h^{\text{right}}}}

	\newcommand\R{\ensuremath{\mathbb{R}}}
	\DeclareMathOperator\supp{supp}

\usepackage{graphicx}

\usepackage[colorlinks=true]{hyperref}

\usepackage{cleveref}

\usepackage{biblatex}
\bibliography{literature.bib}

\title{Daubechies wavelets}
\author{Robert Dahl Jacobsen}

\begin{document}

\maketitle

The purpose of the Julia package \href{https://github.com/robertdj/IntervalWavelets.jl}{IntervalWavelets.jl} is to compute ordinary Daubechies scaling functions (see e.g.\ \cite{Mallat:2009}) and the moment-preserving boundary scaling functions from \cite{Cohen:Daubechies:Vial:1993}.
A common approach is to use the inverse discrete wavelet transform on a unit vector in $R^{2^n}$, but this only guarantees a pointwise \emph{approximation} to the scaling functions.

The alternative used here is to rely solely on the recursive definitions as in \cite{Strang:1989}.
In this short note I summarize these methods with all the details needed in the implementation.

\section{Interior scaling functions}
\label{sec:internal}

A Daubechies scaling function $\phi$ and associated wavelet $\psi$ with $p$ vanishing moments are defined by a filter $\{h_k\}_k$.
The filter, scaling function and wavelet have supports of the same lengths, and we know from \cite[Theorem 7.5]{Mallat:2009} that if $\supp \{h_k\}_k = [N_1, N_2]$, then
\begin{equation*}
	\supp\phi = [N_1, N_2],
	\quad
	\supp\psi = \Bigl[\frac{N_1-N_2+1}2, \frac{N_2-N_1+1}2\Bigr].
\end{equation*}
It is customary to let $N_1 = 0$ and $N_2 = 2p-1$.
However, when constructing the boundary scaling functions we have $N_1 = -p+1$ and $N_2 = p$.

The scaling function satisfies the dilation equation
\begin{equation}
	\label{eq:internal_scaling_function_definition}
	\phi(x)
	= \sqrt2 \sum_{k=0}^{2p-1} h_k \phi_k(2x)
	= \sqrt2 \sum_{k=0}^{2p-1} h_k \phi(2x - k).
\end{equation}
For $p\geq2$, $\phi$ is continuous and hence zero at the endpoints of the support.
These properties allow us to compute $\phi$ at the integer values (in the support).
As an example, for $p=3$:
\begin{align*}
	\frac1{\sqrt2} \phi(1)
	& = h_1\phi(1) + h_0\phi(2),
	\\
	\frac1{\sqrt2} \phi(2)
	& = h_4\phi(1) + h_3\phi(2) + h_2\phi(3) + h_1\phi(4),
	\\
	\frac1{\sqrt2} \phi(3)
	& = h_5\phi(1) + h_4\phi(2) + h_3\phi(3) + h_2\phi(4),
	\\
	\frac1{\sqrt2} \phi(4)
	& = h_5\phi(3) + h_4\phi(4).
\end{align*}
In matrix form, we have an eigenvalue problem:
\begin{equation*}
	\begin{bmatrix}
		\phi(1) \\ \phi(2) \\ \phi(3) \\ \phi(4)
	\end{bmatrix}
	=
	\sqrt2
	\begin{bmatrix}
		h_1 & h_0 & 0 & 0
		\\
		h_3 & h_2 & h_1 & h_0
		\\
		h_5 & h_4 & h_3 & h_2
		\\
		0 & 0 & h_5 & h_4
	\end{bmatrix}
	\begin{bmatrix}
		\phi(1) \\ \phi(2) \\ \phi(3) \\ \phi(4)
	\end{bmatrix}.
\end{equation*}
The $(i,j)$'th entry of the matrix is $\sqrt2 h_{2i-j}$ and the vector $\vv\phi = [\phi(n)]_{n=1}^4$ is an eigenvector of the eigenvalue 1.
This eigenspace is one-dimensional, so the only question is how to scale $\vv\phi$.
From e.g.\ \cite[page 69]{Cohen:Daubechies:Vial:1993} we know that
\begin{equation*}
	\sum_{k\in\mathbb{Z}} \phi(k)
	= \sum_{k=0}^{2p-1} \phi(k)
	= 1.
\end{equation*}

From the function values at the integers we can compute the function values at the half-integers using \eqref{eq:internal_scaling_function_definition}.
As an example,
\begin{equation*}
	\frac1{\sqrt2} \phi\Bigl(\frac32\Bigr)
	= h_0 \phi(3) + h_1 \phi(2) + h_2 \phi(1).
\end{equation*}
This process can be repeated to recursively yield $\phi(k/2^R)$, for all integers $k$ and positive integers $R$.

Note that the filter $\{h_k\}_k$ defining the scaling function is not unique.
In \cref{fig:Daubechies4} is shown the usual, minimum-phase Daubechies 4 scaling function along with Daubechies 'symmlet'/linear phase scaling function used in \cref{sec:boundary_Daubechies} and \cite{Cohen:Daubechies:Vial:1993} -- see e.g.\ \cite[Section 7.2.3]{Mallat:2009}.

\begin{figure}
	\centering
	\includegraphics[scale=0.5]{interior}
	\caption{The usual minimum-phase Daubechies 4 scaling function (black) and the symmlet version (red).}
	\label{fig:Daubechies4}
\end{figure}

\section{Boundary scaling functions}
\label{sec:boundary_Daubechies}

The moment preserving Daubechies boundary scaling functions were introduced in \cite{Cohen:Daubechies:Vial:1993} and are also described in \cite{Mallat:2009} (albeit with some indexing errors).

An important difference between the internal and boundary scaling functions is that the left (right) boundary scaling functions are \emph{not} continuous at the left (right) endpoint of their support.

As in \cref{sec:internal}, the dilation equations defining the boundary scaling functions can yield function values at all dyadic rationals once we have the function values at the integers (in the support).
In the subsequent sections the focus is therefore on how to compute these function values at the integers.

The filters used for the boundary scaling functions are available at \url{http://www.pacm.princeton.edu/~ingrid/publications/54.txt} and \url{http://numerical.recipes/contrib}.

\subsection{Left boundary scaling functions}

Let $p$ denote the number of vanishing moments and $\phi$ be the interior symmlet Daubechies scaling function associated with the wavelet with $p$ vanishing moments translated such that $\supp\phi = [-p+1, p]$.

We want a family of functions satisfying a multiresolution analysis on $L^2([0,\infty))$ or, equivalently, a dilation equation like \cref{eq:internal_scaling_function_definition}.
The starting point is $\{\phi_k\}_{k\geq 0}$.
The functions $\phi_k$ with $\supp\phi_k \subseteq [0,\infty)$ do not need any alteration, but the $\phi_k$ with $\supp\phi_k \cap (-\infty,0) \neq \emptyset$ (i.e., with $0\leq k < p-1$) must be replaced with a corresponding $\lphi_k$.
It turns out that we should also replace $\phi_{p-1}$ with $\lphi_{p-1}$ in order to keep the number of vanishing moments even though $\supp\phi_{p-1} = [0,2p-1]$.
The boundary scaling functions are constructed such that $\supp\bigl(\lphi_k\bigr) = [0,p+k]$.

The relevant counterpart to the dilation equation \cref{eq:internal_scaling_function_definition} for interior scaling functions is
\begin{align}
	\frac1{\sqrt2} \lphi_k(x)
	& = \sum_{l=0}^{p-1} \lH_{k,l} \lphi_l(2x) + \sum_{m=p}^{p+2k} \lh_{k,m} \phi_m(2x)
	\nonumber
	\\
	& = \sum_{l=0}^{p-1} \lH_{k,l} \lphi_l(2x) + \sum_{m=p}^{p+2k} \lh_{k,m} \phi(2x-m),
	\label{eq:left_scaling_function_definition}
\end{align}
for $0\leq k\leq p-1$, where $(\lH_{k,l})$ and $(\lh_{k,m})$ are filter coefficients.

For $x=0$, \eqref{eq:left_scaling_function_definition} becomes
\begin{equation*}
	\frac1{\sqrt2} \lphi_k(0)
	= \sum_{l=0}^{p-1} \lH_{k,l} \lphi_l(0)
\end{equation*}
and these function values can be found as an eigenvector.
% As in Section \ref{sec:internal}, we must scale this eigenvector such that the $\lphi_k$'s are normalized in $L^2([0,\infty))$.

At the remaining integers we make use of the compact support.
Consider e.g.\ the case $p=2$ (where is $\phi$ is supported on $[-1,2]$, $\lphi_0$ is supported on $[0,2]$ and $\lphi_1$ is supported on $[0,3]$):
\begin{align*}
	\frac1{\sqrt2} \lphi_0(1)
	& = \lH_{0,1} \lphi_1(2) + \lh_{0,2} \phi(0),
	\\
	\frac1{\sqrt2} \lphi_1(1)
	& = \lH_{1,1} \lphi_1(2) + \lh_{1,2} \phi(0),
	\\
	\frac1{\sqrt2} \lphi_1(2)
	& = \lh_{1,3} \phi(1) + \lh_{1,4} \phi(0).
\end{align*}
From Section \ref{sec:internal} we know how to calculate the internal scaling function and thus the boundary scaling function as well.
The four boundary scaling functions related to four vanishing moments are seen in \cref{fig:left_Daubechies4}.
There is a large resemblance between $\lphi_3$ and the symmlet scaling function in \cref{fig:Daubechies4} (here denoted $\phi_4$).

\begin{figure}
	\centering
	\includegraphics[scale=0.5]{left}
	\caption{The left boundary scaling function with 4 vanishing moments.}
	\label{fig:left_Daubechies4}
\end{figure}

\subsection{Right boundary scaling functions}

Let again $\phi$ denote the interior symmlet Daubechies scaling function and $p$ denote the number of vanishing moments of the associated wavelet.
The idea for the right boundary scaling functions is the same as for the the left:
We want a multiresolution analysis on $L^2((-\infty,0])$ by modifiying the interior scaling functions.
The $\phi_k$ with $\supp\phi_k \subset (-\infty,0)$ are unaltered, but those with $\supp\phi_k \cap [0, \infty) \neq \emptyset$ are replaced by a corresponding $\rphi_k$.
In conclusion, for $k=0,\ldots,p-1$, the right boundary scaling functions satisfies the dilation equations
\begin{equation}
	\label{eq:right_scaling_function_definition}
	\frac1{\sqrt2} \rphi_k(x)
	= \sum_{l=0}^{p-1} \rH_{k,l} \rphi_l(2x) + \sum_{m=p}^{p+2k} \rh_{k,m} \phi(2x+m+1),
\end{equation}
where $(\rH_{k,l})$ and $(\rh_{k,m})$ are filter coefficients.
The support of $\rphi_k$ is $[-p-k,0]$.

The four right boundary scaling functions related to four vanishing moments are seen in \cref{fig:right_Daubechies4}.

\begin{figure}
	\centering
	\includegraphics[scale=0.5]{right}
	\caption{The right boundary scaling function with 4 vanishing moments.}
	\label{fig:right_Daubechies4}
\end{figure}

\printbibliography

\end{document}


\chapter{Gradient Methods for CMDP}
\label{gradient_cmdp}
\thispagestyle{empty}
In this section we provide the straightforward extension of REINFORCE and G(PO)MDP gradient estimation optimizing the policy and the configuration parameters.
\section{REINFORCE}
Let us start by stating the expression of the gradient of the expected return with respect to a parametric transition model differentiable in its parameters $\boldsymbol{\omega}$.
\begin{theorem}[P-Gradient Theorem, from \citep{cmdp}] Let $P_\omega$ be a class of parametric stochastic transition models differentiable in $\boldsymbol{\omega}$, $\pi$ be the current policy, the gradient of the expected return with respect to $\boldsymbol{\omega}$ is given by:
$$
\nabla_{\boldsymbol{\omega}}J^{P,\pi} = \int_{\mathcal{S}}\int_{\mathcal{A}} d^{P,\pi}(s,a) \int_{\mathcal{S}} \nabla_{\boldsymbol{\omega}}P_{\boldsymbol{\omega}}(s'|s,a)u^{P,\pi}(s,a,s') \mathrm{d}s' \mathrm{d}a \mathrm{d}s
$$

\end{theorem}

We can now derive in a straightforward manner the REINFORCE estimator for model learning:
\begin{equation}
\widehat{\nabla_{\boldsymbol{\omega}} J^{P,\pi}}_{RF} = \langle \left(\sum_{k=0}^H \nabla_{\bm{\omega}} \log P_{\boldsymbol{\omega}}(s_{k+1} |s_k, a_k) \right) \left( \sum_{k=0}^H \gamma^k R(s_k,a_k, s_{k+1}) \right) \rangle_N \, ,
\end{equation}
where $\langle \cdot \rangle_N$ denotes the empirical average over a batch size of dimension $N$.

\section{G(PO)MDP}
\label{gpomdp_cmdp}
In order to derive the G(PO)MDP estimator for model learning we start from a trajectory based perspective:

$$
J^{P,\pi} = \int p_{\boldsymbol{\theta},\boldsymbol{\omega}}(\tau)G(\tau) \mathrm{d}\tau,
$$
where $p_{\boldsymbol{\theta},\boldsymbol{\omega}}(\tau)$ is the probability of the trajectory $\tau$ under the distribution induced by the parameters $\boldsymbol{\theta},\boldsymbol{\omega}$ and $G(\tau)$ is the return of the trajectory $\tau$.
Using the log-trick and taking the derivative with respect to the model parameters we obtain:
\begin{align}
	\nabla_{\boldsymbol{\omega}}J^{P,\pi} &= \int p_{\boldsymbol{\theta},\boldsymbol{\omega}}(\tau) \nabla_{\boldsymbol{\omega}}\log p(\tau) G(\tau) \mathrm{d}\tau \\
	&= \int p_{\boldsymbol{\theta},\boldsymbol{\omega}}(\tau) \left(\sum_{k=0}^{H} \log P_{\boldsymbol{\omega}}(s_{k+1} | s_k, a_k)  \right) G(\tau) .
\end{align}
Now we are exactly in the G(PO)MDP settings and we can use the following approximation of the gradient:
\begin{equation}
\widehat{\nabla_{\boldsymbol{\omega}} J^{P\pi}}_{G(PO)MDP} = \langle \sum_{l=0}^H \left( \sum_{k=l}^H \nabla_{\bm{\omega}} \log P_{\boldsymbol{\omega}}(s_{k+1} | s_k, a_k) \right) \left( \gamma^l R(s_l,a_l, s_{l+1}) \right) \rangle_N \, ,
\end{equation}
where $\langle \cdot \rangle_N$ denotes the empirical average over a batch size of dimension $N$.


\section{Background}\label{sec:background}
We first introduce the reader to Belief Propagation, then to Top-N recommendation.

\mypar{Belief Propagation}
BP is a technique in the domain of machine learning to perform probabilistic inference on graphical models. The standard version of BP is designed to deal with \textit{factor graphs}, special bipartite graphs that can represent Bayesian Networks or Markov Random Fields. Nodes in a factor graph $G(V,F,E)$ are either variables $v \in V = \{ v_1, \ldots, v_N \}$ or factors $f \in F = \{f_1, \ldots, f_M \}$. Edges $e\in E$ model dependencies between nodes.
\textit{Variable nodes} $v$ hold a belief about the variable assigned to them. A belief $p(i):=p[v=x_i\in\Omega_{v}]$ is a density function that assigns a probability to each state $x_v \in \Omega_v$ of variable $v$. Since the number of states of a variable is often finite this belief can be represented as a vector $v \in \mathbb{R}^n$, with $n$ being the number of states.
\textit{Factor nodes} $f$, on the other hand, hold a belief about the joint probabilities of their neighbors.
This means that if, for example, there are two (discrete) variable nodes $v_a, v_b$ connected to a factor node $f$ the belief can be represented as a matrix, where entry $i,j$ holds the belief about the variables being in state $i$ or $j$ respectively. Figuratively speaking, \textit{messages} are sent to inform neighboring nodes about the beliefs of the sender. All receivers update their beliefs accordingly and forward the updated messages to their neighbors. This is repeated until messages (and therefore beliefs) converge.

\begin{figure}
\begin{equation*}
\mu_{v\rightarrow f}(x_v) = \prod_{\hat f \in N(v)\backslash \{f\}} \mu_{\hat f\rightarrow v}(x_v)
\end{equation*}
\begin{equation*}
\mu_{f\rightarrow v}(x_v) = \sum_{x_f \sim x_v}\phi_f(x_f) \prod_{\hat v \in N(f)\backslash \{v\}} \mu_{\hat v\rightarrow f}(x_{\hat v})
\end{equation*}
\caption{Update equations for the standard BP algorithm. The first one describes messages from variable $v$ to factor $f$ and the second for messages from factor $f$ to variable node $v$, $x_v$ is the specific state for which we want to send our belief, $\phi_f(x_f)$ denotes the belief of the factor node $f$ about state $x_f$, $\mu$ is a message, $k \in N(i)\backslash j$ denotes all neighbours of $i$ except the neighbouring node $j$, and $x_f \sim x_v$ is used to denote all possible states that are consistent with state $x_v$.}
\label{eqn_bp_message}
\end{figure}

Conceptually there are two types of messages: $\mu_{v\rightarrow f}$ from variable nodes $v$ to factor nodes $f$, and $\mu_{f\rightarrow v}$ from factor nodes $f$ to variable nodes $v$. Both update equations are given in figure \ref{eqn_bp_message}. They show nicely why this version of BP is often called the \textit{sum-product algorithm}. The update equations involve a product over all neighboring nodes, followed by a sum that marginalizes over all variables except the one to which the message is sent.

The standard version of BP is designed to deal with acyclic graphs. When graphical models contain loops BP is often called \textit{Loopy Belief Propagation} (LBP).

Compared to standard BP, loopy BP problems don't always converge and infer much higher computational costs. Nevertheless, the approximative solutions are often accurate enough to be used in real world applications. Elidan et al. \cite{elidan2012residual} proposed a method to improve the convergence rate by propagating belief in an informed way through the graph. The technique is called \textit{Residual Belief Propagation} because a residual is calculated for each message that estimates the impact of updating it. Therefore messages with a large residual are updated first. Formally, the residual is defined as the $L_\infty$ norm of the difference of the current value of a message and its prospected value: $||\mu_{new} - \mu_{old}||_\infty$.

\begin{figure}
	\centering
	\begin{subfigure}{\columnwidth}
	   \centering
	   \includegraphics[scale=0.33]{graphics/top-n-graph.pdf}%
	      \caption{Factor Graph for predicting Top-N movies for user $\hat u = u_2$.
	      \label{top_n_graph}
	   }
	\end{subfigure}\hfill%
	\vspace{5mm}
	\begin{subfigure}{\columnwidth}
	   \centering
	   \includegraphics[scale=0.33]{graphics/top-n-important-messages.pdf}%
      	   \caption{Propagate belief from observed node $m_2$ to unobserved ones.
	      \label{top_n_graph_important_msg}
	   }
	\end{subfigure}\hfill%
	\vspace{5mm}
	\begin{subfigure}{\columnwidth}
	   \centering
	   \includegraphics[scale=0.33]{graphics/top-n-final.pdf}%
	      \caption{A possible third state: $m_1$ is the top-1 recommendation for $u_2$.
	      \label{top_n_graph_final_state}
	   }
	\end{subfigure}
	\caption{Top-N step by step}
\end{figure}

\mypar{Top-N Recommendation}
Top-N Recommendation is the problem of generating a list of recommended items for a user $\hat u$. The list is based on the available ratings of the user $\hat u$ and the ratings of the other users. Jiwoon Ha et al. \cite{Ha:2012:TRT:2396761.2398636} proposed a method for Top-N Recommendation using LBP. In the following, we sketch the method by means of an online video shop with users $u_i$ and movies $m_j$. The factor graph consists of variable nodes for every user and movie. The state of each node can be either
\begin{enumerate}
   \itemsep0em
   \item $\hat u$ likes this user/movie or
   \item $\hat u$ does not like this user/movie.
\end{enumerate}
Movies are connected with users $u_i\neq \hat u$ in the following way: $u_i$ is linked with movie $m_j$ (through a factor) if $u_i$ actually liked it, that is, the rating is considered only if it is above some threshold. The factor between $u_i$ and $m_j$ has four joint states, best represented by a $2\times 2$ matrix $A$. We set the values $A(1,1), A(2,2) = 0.5 + \alpha$, with $\alpha = 0.0001$, to express the belief about user $\hat u$ to also like movie $m_j$, given that $\hat u$ likes $u_i$, and the other way around. Furthermore we set $A(1,2), A(2,1) = 0.5 - \alpha$ to express our belief that it is unlikely that user $\hat u$ only likes the movie or the user but not both. $\alpha$ is a tuning parameter, the value $0.0001$ was recommended by Jiwoon Ha et al. \cite{Ha:2012:TRT:2396761.2398636}.

Furthermore we need to incorporate the known ratings of $\hat u$. For a rating of $\hat u$ for movie $m_j$, we set the belief of node $m_j$ correspondingly. To exemplify this, assume that ratings vary between 1 and 5. We assign the probability for the two states \textit{like} and \textit{dislike} of movie $m_j$ to $[0.9,0.1]$ for a rating of 5. Similarly, a rating of 4 is mapped to $[0.7,0.3]$, 3 to $[0.5,0.5]$, 2 to $[0.3,0.7]$ and 1 to $[0.1,0.9]$. The beliefs for all other movies, for which no rating exists, are initialized with $[0.5,0.5]$.

Figure \ref{top_n_graph} shows a small factor graph for  $\hat u = u_2$ where user $u_1$ has rated the movies $m_1,m_2$, $u_2$ the movie $m_2$ and $u_3$ the movies $m_1,m_2$ and $m_3$. Given our model, the only other belief available about the system is that user $\hat u$ rated movie $m_2$ with a 4.

Now, using BP, this initial belief is propagated through the factor graph by sending messages (see Figure \ref{top_n_graph_important_msg}). Once the BP's message passing has converged, each movie has a probability assigned that tells us, how likely user $\hat u$ liked this movie. Figure \ref{top_n_graph_final_state} shows a possible final state. The movies can be sorted by these probabilities and the top $N$ elements are returned. In this example movie $m_1$ would be the top-one recommendation for $\hat u$.

\mypar{Cost Analysis}
A reasonable choice for the cost measure is the FLOP count, since BP operates on floating point numbers to calculate the beliefs. Unfortunately, it is not viable to calculate the exact amount of FLOPS for a given input size analytically, as BP is driven by the list of maximal message residuals and it cannot be foreseen, how many messages have to be calculated until convergence. Even worse, the count of processed messages (and, related, the FLOPS) is not only a function of the input \textit{size}, but also a function of the actual \textit{shape} of the graph. Therefore, we decided to count FLOPS using performance counters. The following counters were used:

\begin{itemize}
	\item \texttt{FP\_COMP\_OPS\_EXE.SSE\_SCALAR\_SINGLE} and \\* \texttt{FP\_COMP\_OPS\_EXE.SSE\_SCALAR\_DOUBLE}: count the number of SSE instructions on single floats and doubles.
	\item \texttt{FP\_COMP\_OPS\_EXE.SSE\_PACKED\_SINGLE} and \\* \texttt{FP\_COMP\_OPS\_EXE.SSE\_PACKED\_DOUBLE}: count the number of packed SSE instructions on floats and doubles.
	\item \texttt{SIMD\_FP\_256.PACKED\_SINGLE} and \\* \texttt{SIMD\_FP\_256.PACKED\_DOUBLE}: count the number of packed AVX instructions on floats and doubles.
	\item \texttt{FP\_COMP\_OPS\_EXE.X87}: counts the X87 floating point instructions.
\end{itemize}

The performance counters were evaluated using VTune Amplifier XE 2015 (see section~\ref{sec:results}).
Since it is impossible to distinguish the different kinds of operations, all FLOPS are weighted the same.

%\mypar{Discrete Fourier Transform}
%Precisely define the transform so I understand it even if I have never
%seen it before.
%
%\mypar{Fast Fourier Transforms}
%Explain the algorithm you use.
%
%\mypar{Cost Analysis}
%First define you cost measure (what you count) and then compute the
%cost. Ideally precisely, at least asymptotically. In the latter case you will need to instrument your code to count
%the operations so you can create a performance plot.
%
%Also state what is
%known about the complexity (asymptotic usually)
%about your problem (including citations).


\subsection{Autoregressive Integrated Moving Average models (ARIMA)}

Uses differences to remove non statiority

Also estiamted with box-jenkins


%!TEX root = forallxsol.tex
%\part{Truth-functional logic}
%\label{ch.TFL}
%\addtocontents{toc}{\protect\mbox{}\protect\hrulefill\par}

\setcounter{chapter}{9}
\chapter{Complete truth tables}\setcounter{ProbPart}{0}
\problempart
\label{pr.TT.TTorC}
Complete truth tables for each of the following:
\begin{earg}
\item $A \eif A$ %taut
\myanswer{\begin{center}
\begin{tabular}{c | def}
$A$ & $A$&$\eif$&$A$\\
\hline
 T & T&\TTbf{T}&T\\
F & F&\TTbf{T}&F
\end{tabular}
\end{center}}
\item $C \eif\enot C$ %contingent
\myanswer{\begin{center}
\begin{tabular}{c | d e e f}
$C$ & $C$&$\eif$&$\enot$&$C$\\
\hline
 T & T & \TTbf{F}& F& T\\
F & F & \TTbf{T}& T& F\\
\end{tabular}
\end{center}}
\item $(A \eiff B) \eiff \enot(A\eiff \enot B)$ %tautology
\myanswer{\begin{center}
\begin{tabular}{c c | d e e e e e e e f}
$A$ & $B$&$(A$&$\eiff$&$B)$&$\eiff$&$\enot$&$(A$&$\eiff$&$\enot$&$B)$ \\
\hline
T & T & T & T & T & \TTbf{T} & T & T & F & F & T\\
T & F & T & F & F & \TTbf{T} & F & T & T & T & F\\
F & T & F & F & T & \TTbf{T} & F & F & T & F & T\\
F & F & F & T & F & \TTbf{T} & T & F & F & T & F
 \end{tabular}
\end{center}}
\item $(A \eif B) \eor (B \eif A)$ % taut
\myanswer{
\begin{center}
\begin{tabular}{c c | d e e e e e f}
$A$ & $B$&$(A$&$\eif$&$B)$&$\eor$&$(B$&$\eif$&$A)$ \\
\hline
T & T & T & T & T & \TTbf{T} & T & T & T\\
T & F & T & F & F & \TTbf{T} & F & T & T\\
F & T & F & T & T & \TTbf{T} & T & F & F \\
F & F & F & T & F & \TTbf{T} & F & T & F
 \end{tabular}
\end{center}}
\item $(A \eand B) \eif (B \eor A)$  %taut
\myanswer{
\begin{center}
\begin{tabular}{c c | d e e e e e f}
$A$ & $B$&$(A$&$\eand$&$B)$&$\eif$&$(B$&$\eor$&$A)$ \\
\hline
T & T & T & T & T & \TTbf{T} & T & T & T\\
T & F & T & F & F & \TTbf{T} & F & T & T\\
F & T & F & F & T & \TTbf{T} & T & T & F \\
F & F & F & F & F & \TTbf{T} & F & F & F
 \end{tabular}
\end{center}}
\item $\enot(A \eor B) \eiff (\enot A \eand \enot B)$ %taut
\myanswer{\begin{center}
\begin{tabular}{c c | d e e e e e e e e f}
$A$ & $B$&$\enot$&$(A$&$\eor$&$B)$&$\eiff$&$(\enot$&$A$&$\eand$&$\enot$&$B)$\\
\hline
T & T & F & T & T & T & \TTbf{T} & F & T & F & F & T\\
T & F & F & T& T & F & \TTbf{T} & F & T & F & T & F\\
F & T & F & F & T & T & \TTbf{T} & T & F & F & F & T\\
F & F & T & F & F & F & \TTbf{T} & T & F & T & T & F
 \end{tabular}
\end{center}}
\item $\bigl[(A\eand B) \eand\enot(A\eand B)\bigr] \eand C$ %contradiction
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e e e e e e f}
$A$ & $B$&$C$&$\bigl[(A$&$\eand$&$B)$&$ \eand$&$\enot$&$(A$&$\eand$&$B)\bigr]$&$\eand$&$C$\\
\hline
T & T & T & T & T & T & F & F & T & T & T & \TTbf{F} & T\\
T & T & F & T& T & T & F & F & T & T & T & \TTbf{F}& F\\
T & F & T & T & F & F & F & T & T & F & F & \TTbf{F} & T\\
T & F & F & T & F & F & F & T & T & F & F & \TTbf{F} & F\\
F & T & T & F & F & T & F & T & F & F & T & \TTbf{F} & T\\
F & T & F & F & F & T & F & T & F & F & T & \TTbf{F} & F\\
F & F & T & F & F & F & F & T & F & F & F & \TTbf{F} & T\\
F & F & F & F & F & F & F & T & F & F & F & \TTbf{F} & F
\end{tabular}
\end{center}}
\item $[(A \eand B) \eand C] \eif B$ %taut
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e e e f}
$A$ & $B$&$C$&$[(A$&$\eand$&$B)$&$\eand$&$C]$&$\eif$&$B$\\
\hline
T & T & T & T & T & T & T & T & \TTbf{T} & T\\
T & T & F & T & T & T & F & F & \TTbf{T} & T\\
T & F & T & T & F & F & F & T & \TTbf{T} & F\\
T & F & F & T & F & F & F & F & \TTbf{T} & F\\
F & T & T & F & F & T & F & T & \TTbf{T} & T\\
F & T & F & F & F & T & F & F & \TTbf{T} & T\\
F & F & T & F & F & F & F & T & \TTbf{T} & F\\
F & F & F & F & F & F & F & F & \TTbf{T} & F\\
\end{tabular}
\end{center}}
\item $\enot\bigl[(C\eor A) \eor B\bigr]$ %contingent
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e e f}
$A$ & $B$&$C$&$\enot\bigl[($&$C$&$\eor$&$A)$&$\eor$&$B\bigr]$\\
\hline
T & T & T & \TTbf{F} & T & T & T & T & T\\
T & T & F & \TTbf{F} & F & T & T & T & T\\
T & F & T & \TTbf{F} & T & T & T & T & F\\
T & F & F & \TTbf{F} & F & T & T & T & F\\
F & T & T & \TTbf{F} & T & T & F & T & T\\
F & T & F & \TTbf{F} & F & F & F & T & T\\
F & F & T & \TTbf{F} & T & T & F & T & F\\
F & F & F & \TTbf{T} & F & F & F & F & F
\end{tabular}
\end{center}}
\end{earg}

\problempart
Check all the claims made in introducing the new notational conventions in \S10.3, i.e.\ show that:
\begin{earg}
	\item `$((A \eand B) \eand C)$' and `$(A \eand (B \eand C))$' have the same truth table
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e f | d e e e f }
$A$ & $B$ & $C$ & $(A$&$\eand$& $B)$ &$ \eand$ & $C$ & $A$ & $\eand$ & $(B$&$\eand$&$C)$\\
\hline
T & T & T & T & T & T &  \TTbf{T} & T &T & \TTbf{T} & T & T& T \\
T & T & F & T& T & T &  \TTbf{F} & F & T& \TTbf{F} & T & F& F\\
T & F & T & T & F & F &  \TTbf{F} & T & T & \TTbf{F} & F & F & T \\
T & F & F &  T & F & F &  \TTbf{F} & F & T& \TTbf{F} & F & F & F\\
F & T & T & F & F & T & \TTbf{F} & T & F& \TTbf{F} & T & T & T\\
F & T & F & F & F & T & \TTbf{F} & F & F& \TTbf{F} &  T & F & F\\
F & F & T & F & F & F & \TTbf{F} & T & F& \TTbf{F} & F& F & T\\
F & F & F & F & F & F & \TTbf{F} & F & F& \TTbf{F} &  F& F & F\\
\end{tabular}
\end{center}}
	\item `$((A \eor B) \eor C)$' and `$(A \eor (B \eor C))$' have the same truth table
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e f | d e e e f }
$A$ & $B$ & $C$ & $(A$&$\eor$& $B)$ &$ \eor$ & $C$ & $A$ & $\eor$ & $(B$&$\eor$&$C)$\\
\hline
T & T & T & T & T & T &  \TTbf{T} & T &T & \TTbf{T} & T & T& T \\
T & T & F & T& T & T &  \TTbf{T} & F & T& \TTbf{T} & T & T& F\\
T & F & T & T & T & F &  \TTbf{T} & T & T & \TTbf{T} & F & T & T \\
T & F & F &  T & T& F &  \TTbf{T} & F & T& \TTbf{T} & F & F & F\\
F & T & T & F & T & T & \TTbf{T} & T & F& \TTbf{T} & T & T & T\\
F & T & F & F & T & T & \TTbf{T} & F & F& \TTbf{T} &  T & T & F\\
F & F & T & F & F & F & \TTbf{T} & T & F& \TTbf{T} & F& T & T\\
F & F & F & F & F & F & \TTbf{F} & F & F& \TTbf{F} &  F& F & F\\
\end{tabular}
\end{center}}
	\item `$((A \eor B) \eand C)$' and `$(A \eor (B \eand C))$' do not have the same truth table
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e f | d e e e f }
$A$ & $B$ & $C$ & $(A$&$\eor$& $B)$ &$ \eand$ & $C$ & $A$ & $\eor$ & $(B$&$\eand$&$C)$\\
\hline
T & T & T & T & T & T &  \TTbf{T} & T &T & \TTbf{T} & T & T& T \\
T & T & F & T& T & T &  \TTbf{F} & F & T& \TTbf{T} & T & F& F\\
T & F & T & T & T & F &  \TTbf{T} & T & T & \TTbf{T} & F & F & T \\
T & F & F &  T & T& F &  \TTbf{F} & F & T& \TTbf{T} & F & F & F\\
F & T & T & F & T & T & \TTbf{T} & T & F& \TTbf{T} & T & T & T\\
F & T & F & F & T & T & \TTbf{F} & F & F& \TTbf{F} &  T & F & F\\
F & F & T & F & F & F & \TTbf{F} & T & F& \TTbf{F} & F& F & T\\
F & F & F & F & F & F & \TTbf{F} & F & F& \TTbf{F} &  F& F & F\\
\end{tabular}
\end{center}}
	\item `$((A \eif B) \eif C)$' and `$(A \eif (B \eif C))$' do not have the same truth table
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e f | d e e e f }
$A$ & $B$ & $C$ & $(A$&$\eif$& $B)$ &$ \eif$ & $C$ & $A$ & $\eif$ & $(B$&$\eif$&$C)$\\
\hline
T & T & T & T & T & T &  \TTbf{T} & T &T & \TTbf{T} & T & T& T \\
T & T & F & T& T & T &  \TTbf{F} & F & T& \TTbf{F} & T & F& F\\
T & F & T & T & F & F &  \TTbf{T} & T & T & \TTbf{T} & F & T & T \\
T & F & F &  T & F& F &  \TTbf{T} & F & T& \TTbf{T} & F & T & F\\
F & T & T & F & T & T & \TTbf{T} & T & F& \TTbf{T} & T & T & T\\
F & T & F & F & T & T & \TTbf{F} & F & F& \TTbf{T} &  T & F & F\\
F & F & T & F & T & F & \TTbf{T} & T & F& \TTbf{T} & F& T & T\\
F & F & F & F & T & F & \TTbf{F} & F & F& \TTbf{T} &  F& T & F\\
\end{tabular}
\end{center}}
\end{earg}
Also, check whether:
\begin{earg}
	\item[5.] `$((A \eiff B) \eiff C)$' and `$(A \eiff (B \eiff C))$' have the same truth table
		\\\myanswer{Indeed they do:
\begin{center}
\begin{tabular}{c c c | d e e e f | d e e e f }
$A$ & $B$ & $C$ & $(A$&$\eiff$& $B)$ &$ \eiff$ & $C$ & $A$ & $\eiff$ & $(B$&$\eiff$&$C)$\\
\hline
T & T & T & T & T & T &  \TTbf{T} & T &T & \TTbf{T} & T & T& T \\
T & T & F & T& T & T &  \TTbf{F} & F & T& \TTbf{F} & T & F& F\\
T & F & T & T & F & F &  \TTbf{F} & T & T & \TTbf{F} & F & F & T \\
T & F & F &  T & F& F &  \TTbf{T} & F & T& \TTbf{T} & F & T & F\\
F & T & T & F & F & T & \TTbf{F} & T & F& \TTbf{F} & T & T & T\\
F & T & F & F & F & T & \TTbf{T} & F & F& \TTbf{T} &  T & F & F\\
F & F & T & F & T & F & \TTbf{T} & T & F& \TTbf{T} & F& F & T\\
F & F & F & F & T & F & \TTbf{F} & F & F& \TTbf{F} &  F& T & F\\
\end{tabular}
\end{center}}
\end{earg}

\chapter{Semantic concepts}\setcounter{ProbPart}{0}
\problempart
Revisit your answers to \S10\textbf{A}. Determine which sentences were tautologies, which were contradictions, and which were neither tautologies nor contradictions.
\begin{earg}
\item $A \eif A$ \hfill \myanswer{Tautology}
\item $C \eif\enot C$ \hfill \myanswer{Neither}
\item $(A \eiff B) \eiff \enot(A\eiff \enot B)$  \hfill \myanswer{Tautology}
\item $(A \eif B) \eor (B \eif A)$  \hfill \myanswer{Tautology}
\item $(A \eand B) \eif (B \eor A)$  \hfill \myanswer{Tautology}
\item $\enot(A \eor B) \eiff (\enot A \eand \enot B)$ \hfill \myanswer{Tautology}
\item $\bigl[(A\eand B) \eand\enot(A\eand B)\bigr] \eand C$  \hfill \myanswer{Contradiction}
\item $[(A \eand B) \eand C] \eif B$  \hfill \myanswer{Tautology}
\item $\enot\bigl[(C\eor A) \eor B\bigr]$  \hfill \myanswer{Neither}
\end{earg}

\

\problempart
\label{pr.TT.consistent}
Use truth tables to determine whether these sentences are jointly consistent, or jointly inconsistent:
\begin{earg}
\item $A\eif A$, $\enot A \eif \enot A$, $A\eand A$, $A\eor A$ \hfill \myanswer{Jointly consistent (see line 1)}
\myanswer{\begin{center}
\begin{tabular}{c | d e f | d e e e f | d e f | d e f}
$A$ &  $A$&$\eif$&$A$&$\enot$&$A$&$\eif$&$\enot$&$A$&$A$&$\eand$&$A$&$A$&$\eor$&$A$\\
\hline
T & T & \TTbf{T} & T& F & T & \TTbf{T} & F & T & T & \TTbf{T} & T & T & \TTbf{T} & T\\
F & F & \TTbf{T} & F& T & F & \TTbf{T} & T & F & F & \TTbf{F} & F & F & \TTbf{F} & F
\end{tabular}
\end{center}}
\item $A\eor B$, $A\eif C$, $B\eif C$ \hfill \myanswer{Jointly consistent (see line 1)}
\myanswer{\begin{center}
\begin{tabular}{c c c | d e f | d e f | d e f}
$A$ & $B$ & $C$ & $A$&$\eor$&$B$&$A$&$\eif$&$C$&$B$&$\eif$&$C$\\
\hline
T & T & T & T & \TTbf{T} & T & T & \TTbf{T} & T & T & \TTbf{T} & T\\
T & T & F & T & \TTbf{T} & T & T & \TTbf{F} & F & T & \TTbf{F} & F\\
T & F & T & T & \TTbf{T} & T & T & \TTbf{T} & T & F & \TTbf{T} & T\\
T & F & F & T & \TTbf{T} & F & T & \TTbf{F} & F & F & \TTbf{T} & F\\
F & T & T & F & \TTbf{T} & F & F & \TTbf{T} & T & T & \TTbf{T} & T\\
F & T & F & F & \TTbf{T} & T & F & \TTbf{T} & F & T & \TTbf{F} & F\\
F & F & T & F & \TTbf{F} & F & F & \TTbf{T} & T & F & \TTbf{T} & T\\
F & F & F & F & \TTbf{F} & F & F & \TTbf{T} & F & F & \TTbf{T} & F\\
\end{tabular}
\end{center}}
\item $B\eand(C\eor A)$, $A\eif B$, $\enot(B\eor C)$ \hfill \myanswer{Jointly inconsistent}
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e f | d e f | d e e f}
$A$ & $B$ & $C$ & $B$&$\eand$&$(C$&$\eor$&$A)$&$A$&$\eif$&$B$&$\enot$&$(B$&$\eor$&$C)$\\
\hline
T & T & T & T & \TTbf{T} & T & T & T & T & \TTbf{T} & T & \TTbf{F} & T & T & T\\
T & T & F & T & \TTbf{T} & F & T & T & T & \TTbf{T} & T & \TTbf{F} & T &  T & F\\
T & F & T & F & \TTbf{F} & T & T & T & T & \TTbf{F} & F & \TTbf{F} & F &  T & T\\
T & F & F & F & \TTbf{F} & F & T & T & T & \TTbf{F} & F & \TTbf{T} & F & F & F\\
F & T & T & T & \TTbf{T} & T & T & F & F & \TTbf{T} & T & \TTbf{F} & T & T & T\\
F & T & F & T & \TTbf{F} & F & F & F & F & \TTbf{T} & T & \TTbf{F} & T & T & F\\
F & F & T & F & \TTbf{F} & T & T & F & F & \TTbf{T} & F & \TTbf{F} & F & T & T\\
F & F & F & F & \TTbf{F} & F & F & F & F & \TTbf{T} & F & \TTbf{T} & F & F & F\\
\end{tabular}
\end{center}}
\item $A\eiff(B\eor C)$, $C\eif \enot A$, $A\eif \enot B$  \hfill \myanswer{Jointly consistent (see line 8)}
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e f | d e e f | d e e f}
$A$ & $B$ & $C$ & $A$&$\eiff$&$(B$&$\eor$&$C)$&$C$&$\eif$&$\enot$&$A$&$A$&$\eif$&$\enot$&$B$\\
\hline
T & T & T & T & \TTbf{T} & T & T & T & T & \TTbf{F} & F & T & T & \TTbf{F} & F & T\\
T & T & F & T & \TTbf{T} & T & T & F & F & \TTbf{T} & F & T & T & \TTbf{F} & F & T\\
T & F & T & T & \TTbf{T} & F & T & T & T & \TTbf{F} & F & T & T & \TTbf{T} & T & F\\
T & F & F & T & \TTbf{F} & F & F & F & F & \TTbf{T} & F & T & T & \TTbf{T} & T & F\\
F & T & T & F & \TTbf{F} & T & T & T & T & \TTbf{T} & T & F & F & \TTbf{T} &  F & T\\
F & T & F & F & \TTbf{F} & T & T & F & F & \TTbf{T} & T & F & F & \TTbf{T} & F & T\\
F & F & T & F & \TTbf{F} & F & T & T & T & \TTbf{T} & T & F & F & \TTbf{T} &T & F\\
F & F & F & F & \TTbf{T} & F & F & F & F & \TTbf{T} & T & F & F & \TTbf{T} & T & F
\end{tabular}
\end{center}}
\end{earg}

\problempart
\label{pr.TT.valid}
Use truth tables to determine whether each argument is valid or invalid.
\begin{earg}
\item $A\eif A \therefore A$  \hfill \myanswer{Invalid (see line 2)}
\myanswer{\begin{center}
\begin{tabular}{c | d e f | c}
$A$ &$A$&$\eif$&$A$&$A$\\
\hline
 T & T & \TTbf{T} & T & T\\
 F & F & \TTbf{T} & F & F
 \end{tabular}
\end{center}}
\item $A\eif(A\eand\enot A) \therefore \enot A$  \hfill \myanswer{Valid}
\myanswer{\begin{center}
\begin{tabular}{c | d e e e e f | df}
$A$&$A$&$\eif$&$(A$&$\eand$&$\enot$&$A)$&$\enot$&$A$\\
\hline
 T & T & \TTbf{F} & T & F& F&T&\TTbf{F}&T\\
 F & F & \TTbf{T} & F & F&T&F&\TTbf{T}&F
 \end{tabular}
\end{center}}
\item $A\eor(B\eif A) \therefore \enot A \eif \enot B$  \hfill \myanswer{Valid}
\myanswer{\begin{center}
\begin{tabular}{c c | d e e e f | d e e e f}
$A$ & $B$ & $A$&$\eor$&$(B$&$\eif$&$A)$&$\enot$&$A$&$\eif$&$\enot$&$B$\\
\hline
T & T & T & \TTbf{T} & T & T & T & F & T & \TTbf{T} & F & T \\
T & F & T & \TTbf{T} & F & T & T & F & T & \TTbf{T} & T & F \\
F & T & F & \TTbf{F} & T & F & F & T & F & \TTbf{F} & F & T \\
F & F & F & \TTbf{T} & F & T & F & T & F & \TTbf{T} & T & F
\end{tabular}
\end{center}}
\item $A\eor B, B\eor C, \enot A \therefore B \eand C$  \hfill \myanswer{Invalid (see line 6)}
\myanswer{\begin{center}
\begin{tabular}{c c c | d e f | d e f | d f | d e f}
$A$ & $B$ & $C$ & $A$&$\eor$&$B$&$B$&$\eor$&$C$&$\enot$&$A$&$B$&$\eand$&$C$\\
\hline
T & T & T & T & \TTbf{T} & T & T & \TTbf{T} & T & \TTbf{F} & T & T & \TTbf{T} & T \\
T & T & F & T & \TTbf{T} & T & T & \TTbf{T} & F & \TTbf{F} & T & T &\TTbf{F} & F \\
T & F & T & T & \TTbf{T} & F & F & \TTbf{T} & T & \TTbf{F} & T & F & \TTbf{F} & T \\
T & F & F & T & \TTbf{T} & F & F & \TTbf{F} & F & \TTbf{F} & T & F & \TTbf{F} & F\\
T & T & T & F & \TTbf{T} & T & T & \TTbf{T} & T & \TTbf{T} & F & T & \TTbf{T} & T \\
T & T & F & F & \TTbf{T} & T & T & \TTbf{T} & F & \TTbf{T} & F & T &\TTbf{F} & F \\
T & F & T & F & \TTbf{F} & F & F & \TTbf{T} & T & \TTbf{T} & F & F & \TTbf{F} & T \\
T & F & F & F & \TTbf{F} & F & F & \TTbf{F} & F & \TTbf{T} & F & F & \TTbf{F} & F
\end{tabular}
\end{center}}
\item $(B\eand A)\eif C, (C\eand A)\eif B \therefore (C\eand B)\eif A$  \hfill \myanswer{Invalid (see line 5)}
\myanswer{\begin{center}
\begin{tabular}{c c c | d e e e f | d e e e f | d e e e f}
$A$ & $B$ & $C$ & $(B$&$\eand$&$A)$&$\eif$&$C$&$(C$&$\eand$&$A)$&$\eif$&$B$&$(C$&$\eand$&$ B)$&$\eif$&$A$\\
\hline
T & T & T & T & T & T & \TTbf{T} & T & T & T & T & \TTbf{T} & T & T & T & T & \TTbf{T} & T\\
T & T & F & T & T & T & \TTbf{F} & F & F & F & T & \TTbf{T} & T & F & F & T & \TTbf{T} & T\\
T & F & T & F & F & T & \TTbf{T} & T & T & T & T & \TTbf{F} & F & T & F & F & \TTbf{T} & T\\
T & F & F & F & F & T & \TTbf{T} & F & F & F & T & \TTbf{T} & F & F & F & F & \TTbf{T} & T\\
F & T & T & T & F & F & \TTbf{T} & T & T & F & F & \TTbf{T} & T & T & T & T & \TTbf{F} & F\\
F & T & F & T & F & F & \TTbf{T} & F & F & F & F & \TTbf{T} & T & F & F & T & \TTbf{T} & F\\
F & F & T & F & F & F & \TTbf{T} & T & T & F & F & \TTbf{T} & F & T & F & F & \TTbf{T} & F\\
F & F & F & F & F & F & \TTbf{T} & F & F & F & F & \TTbf{T} & F & F & F & F & \TTbf{T} & F
\end{tabular}
\end{center}}
\end{earg}

\problempart
\label{pr.TT.concepts}
Answer each of the questions below and justify your answer.
\begin{earg}
\item Suppose that \meta{A} and \meta{B} are tautologically equivalent. What can you say about $\meta{A}\eiff\meta{B}$?
\item[] \myanswer{\meta{A} and \meta{B} have the same truth value on every line of a complete truth table, so $\meta{A}\eiff\meta{B}$ is true on every line. It is a tautology.}
\item Suppose that $(\meta{A}\eand\meta{B})\eif\meta{C}$ is neither a tautology nor a contradiction. What can you say about this: $\meta{A}, \meta{B} \entails \meta{C}$?
\item[] \myanswer{Since the sentence $(\meta{A}\eand\meta{B})\eif\meta{C}$ is not a tautology, there is some line on which it is false. Since it is a conditional, on that line, \meta{A} and \meta{B} are true and \meta{C} is false. So in fact $\meta{A}, \meta{B} \nentails \meta{C}$ .}
\item Suppose that $\meta{A}$, $\meta{B}$ and $\meta{C}$  are jointly tautologically inconsistent. What can you say about $(\meta{A}\eand\meta{B}\eand\meta{C})$?
\item[] \myanswer{Since the sentences are jointly tautologically inconsistent, there is no valuation on which they are all true. So their conjunction is false on every valuation. It is a contradiction}
\item Suppose that \meta{A} is a contradiction. What can you say about this: $\meta{A}, \meta{B} \entails \meta{C}$?
\item[] \myanswer{Since \meta{A} is false on every line of a complete truth table, there is no line on which \meta{A} and \meta{B} are true and \meta{C} is false. So the entailment holds.}
\item Suppose that \meta{C} is a tautology. What can you say about this: $\meta{A}, \meta{B}\entails \meta{C}$?
\item[] \myanswer{Since \meta{C} is true on every line of a complete truth table, there is no line on which \meta{A} and \meta{B} are true and \meta{C} is false. So the entailment holds.}
\item Suppose that \meta{A} and \meta{B} are tautologically equivalent. What can you say about $(\meta{A}\eor\meta{B})$?
\item[] \myanswer{Not much! Since $\meta{A}$ and $\meta{B}$ are true on exactly the same lines of the truth table, their disjunction is true on exactly the same lines. So, their disjunction is tautologically equivalent to them.}
\item Suppose that \meta{A} and \meta{B} are \emph{not} tautologically equivalent. What can you say about $(\meta{A}\eor\meta{B})$?
\item[] \myanswer{\meta{A} and \meta{B} have different truth values on at least one line of a complete truth table, and $(\meta{A}\eor\meta{B})$ will be true on that line. On other lines, it might be true or false. So $(\meta{A}\eor\meta{B})$ is either a tautology or it is contingent; it is \emph{not} a contradiction.}
\end{earg}

\problempart
Consider the following principle:
	\begin{ebullet}
		\item Suppose $\meta{A}$ and $\meta{B}$ are tautologically equivalent. Suppose an argument contains $\meta{A}$ (either as a premise, or as the conclusion). The validity of the argument would be unaffected, if we replaced $\meta{A}$ with $\meta{B}$.
	\end{ebullet}
Is this principle correct? Explain your answer.
\\\myanswer{The principle is correct. Since $\meta{A}$ and $\meta{B}$ are tautologically equivalent, they have the same truth table. So every valuation that makes $\meta{A}$ true also makes $\meta{B}$ true, and every valuation that makes $\meta{A}$ false also makes $\meta{B}$ false. So if no valuation makes all the premises true and the conclusion false, when $\meta{A}$ was among the premises or the conclusion, then no valuation makes all the premises true and the conclusion false, when we replace $\meta{A}$ with $\meta{B}$.}

\chapter{Truth table shortcuts}\setcounter{ProbPart}{0}
\problempart
\label{pr.TT.TTorC}
Using shortcuts, determine whether each sentence is a tautology, a contradiction, or neither.
\begin{earg}
\item $\enot B \eand B$ %contra
\myanswer{ \hfill Contradiction\begin{center}
\begin{tabular}{c | d e e f }
$B$ & $\enot$&$B$&$\eand$&$B$\\
\hline
T & F & & \TTbf{F}\\
F & & & \TTbf{F} &
\end{tabular}
\end{center}}
\item $\enot D \eor D$ %taut
\myanswer{\hfill Tautology
\begin{center}
\begin{tabular}{c | d e e f }
$D$ & $\enot$&$D$&$\eor$&$D$\\
\hline
T &  & & \TTbf{T}\\
F & T & & \TTbf{T}
\end{tabular}
\end{center}}
\item $(A\eand B) \eor (B\eand A)$ %contingent
\myanswer{\hfill Neither
\begin{center}
\begin{tabular}{c c | d e e e e e f }
$A$ & $B$ & $(A$&$\eand$&$B)$&$\eor$&$(B$&$\eand$&$A)$\\
\hline
T & T & & T & & \TTbf{T}\\
T & F & & F & & \TTbf{F} & & F \\
F & T & & F & & \TTbf{F} & & F \\
F & F & & F & & \TTbf{F} & & F
\end{tabular}
\end{center}}
\item $\enot[A \eif (B \eif A)]$ %contra
\myanswer{\hfill Contradiction
\begin{center}
\begin{tabular}{c c | d e e e e f }
$A$ & $B$ & $\enot[$&$A$&$\eif$&$(B$&$\eif$&$A)]$\\
\hline
T & T & \TTbf{F} &  & T & & T\\
T & F & \TTbf{F} &  & T & & T \\
F & T & \TTbf{F} &  & T & &  \\
F & F & \TTbf{F} &  & T & &
\end{tabular}
\end{center}}
\item $A \eiff [A \eif (B \eand \enot B)]$ %contra
\myanswer{\hfill Contradiction
\begin{center}
\begin{tabular}{c c | d e e e e e e f }
$A$ & $B$ & $A$&$\eiff$&$[A$&$\eif$&$(B$&$\eand$&$\enot$&$B)]$\\
\hline
T & T & & \TTbf{F} &  & F & & F& F\\
T & F & & \TTbf{F} &  & F & & F \\
F & T & & \TTbf{F} &  & T & &  \\
F & F & & \TTbf{F} &  & T & &
\end{tabular}
\end{center}}
\item $\enot(A\eand B) \eiff A$ %contingent
\myanswer{\hfill Neither
\begin{center}
\begin{tabular}{c c | d e e e e f }
$A$ & $B$ & $\enot$&$(A$&$\eand$&$B)$&$\eiff$&$A$\\
\hline
T & T & F & & T & & \TTbf{F} \\
T & F & T & & F & & \TTbf{T} \\
F & T & T & & F & & \TTbf{F} \\
F & F & T & & F & & \TTbf{F} \\
\end{tabular}
\end{center}}
\item $A\eif(B\eor C)$ %contingent
\myanswer{\hfill Neither
\begin{center}
\begin{tabular}{c c c | d e e e f }
$A$ & $B$ & $C$ & $A$&$\eif$&$(B$&$\eor$&$C)$\\
\hline
T & T & T & & \TTbf{T} & & T \\
T & T & F & & \TTbf{T} & & T \\
T & F & T & & \TTbf{T} & & T \\
T & F & F & & \TTbf{F} & & F \\
F & T & T & & \TTbf{T} & &  \\
F & T & F & & \TTbf{T} & &  \\
F & F & T & & \TTbf{T} & &  \\
F & F & F & & \TTbf{T} & &
\end{tabular}
\end{center}}
\item $(A \eand\enot A) \eif (B \eor C)$ %tautology
\myanswer{\hfill Tautology
\begin{center}
\begin{tabular}{c c c | d e e e e e e f }
$A$ & $B$ & $C$ & $(A$&$\eand$&$\enot$&$A)$&$\eif$&$(B$&$\eor$&$C)$\\
\hline
T & T & T & & \TTbf{F} & F& & T \\
T & T & F & & \TTbf{F} &F & & T \\
T & F & T & & \TTbf{F} &F & & T \\
T & F & F & & \TTbf{F} & F& & T \\
F & T & T & & \TTbf{F} & & & T \\
F & T & F & & \TTbf{F} & & & T \\
F & F & T & & \TTbf{F} & & & T \\
F & F & F & & \TTbf{F} & &  & T \\
\end{tabular}
\end{center}}
\item $(B\eand D) \eiff [A \eiff(A \eor C)]$%contingent
\myanswer{\hfill Neither
\begin{center}
\begin{tabular}{c c c c | d e e e e e e e f }
$A$ & $B$ & $C$ & $D$ & $(B$&$\eand$&$D)$&$\eiff $&$[A$&$\eiff$&$(A$&$\eor$&$C)]$\\
\hline
T & T & T & T & & T & & \TTbf{T} &  & T & &  T\\
T & T & T & F & & F & & \TTbf{F} &  & T & &  T\\
T & T & F & T & & T & & \TTbf{T} &  & T & &  T\\
T & T & F & F & & F & & \TTbf{F} &  & T & &  T\\
T & F & T & T & & F & & \TTbf{F} &  & T & &  T\\
T & F & T & F & & F & & \TTbf{F} &  & T & &  T\\
T & F & F & T & & F & & \TTbf{F} &  & T & &  T\\
T & F & F & F & & F & & \TTbf{F} &  & T & &  T\\
F & T & T & T & & T & & \TTbf{F} &  & F & &  T\\
F & T & T & F & & F & & \TTbf{T} &  & F & &  T\\
F & T & F & T & & T & & \TTbf{T} &  & T & &  F\\
F & T & F & F & & F & & \TTbf{F} &  & T & &  F\\
F & F & T & T & & F & & \TTbf{T} &  & F & &  T\\
F & F & T & F & & F & & \TTbf{T} &  & F & &  T\\
F & F & F & T & & F & & \TTbf{F} &  & T & &  F\\
F & F & F & F & & F & & \TTbf{F} &  & T & &  F
\end{tabular}
\end{center}}
\end{earg}

\chapter{Partial truth tables}\setcounter{ProbPart}{0}
\problempart
\label{pr.TT.equiv}
Use complete or partial truth tables (as appropriate) to determine whether these pairs of sentences are tautologically equivalent:
\begin{earg}
\item $A$, $\enot A$
\myanswer{\hfill Not tautologically equivalent
\begin{center}
\begin{tabular}{c | c | c}
$A$ &$A$&$\enot A$\\
\hline
 T & T & F
 \end{tabular}
\end{center}}
\item $A$, $A \eor A$
\myanswer{\hfill Tautologically equivalent
\begin{center}
\begin{tabular}{c | c | c}
$A$ &$A$&$A \eor A$\\
\hline
 T & T & T\\
 T & T & T
 \end{tabular}
\end{center}}
\item $A\eif A$, $A \eiff A$ %Yes
\myanswer{\hfill Tautologically equivalent
\begin{center}
\begin{tabular}{c | c | c}
$A$ &$A \eif A$&$A \eiff A$\\
\hline
T & T & T\\
F & T & T
\end{tabular}
\end{center}}
\item $A \eor \enot B$, $A\eif B$ %No
\myanswer{\hfill Not tautologically equivalent
\begin{center}
\begin{tabular}{c c | c | c}
$A$ & $B$ &$A\eor \enot B$&$A \eif B$\\
\hline
T & F & {T} & F
\end{tabular}
\end{center}}
\item $A \eand \enot A$, $\enot B \eiff B$ %Yes
\myanswer{\hfill Tautologically equivalent
\begin{center}
\begin{tabular}{c c | d e e f | d e e f}
$A$ & $B$ &$A$&$\eand$&$\enot$&$A$&$\enot$&$B$&$\eiff$&$B$\\
\hline
T & T & & \TTbf{F} & F & & F & & \TTbf{F} & \\
T & F & & \TTbf{F} & F & & T & & \TTbf{F} & \\
F & T & & \TTbf{F} &  & & F & & \TTbf{F} & \\
F & F & & \TTbf{F} &  & &  T & & \TTbf{F} & \\
\end{tabular}
\end{center}}

\item $\enot(A \eand B)$, $\enot A \eor \enot B$ %Yes
\myanswer{\hfill Tautologically equivalent
\begin{center}
\begin{tabular}{c c | d e e f | d e e e f}
$A$ & $B$ &$\enot$&$(A$&$\eand$&$B)$&$\enot$&$A$&$\eor$&$\enot$&$B$\\
\hline
T & T &\TTbf{F}& & T & & F & & \TTbf{F} & F\\
T & F & \TTbf{T} & & F & & F & & \TTbf{T} & T\\
F & T & \TTbf{T} & & F & & T & & \TTbf{T} & F\\
F & F & \TTbf{T} & & F & &  T& & \TTbf{T} & T\\
\end{tabular}
\end{center}}
\item $\enot(A \eif B)$, $\enot A \eif \enot B$ %No
\myanswer{\hfill Not tautologically equivalent
\begin{center}
\begin{tabular}{c c | d e e f | d e e e f}
$A$ & $B$ &$\enot$&$(A$&$\eif$&$B)$&$\enot$&$A$&$\eif$&$\enot$&$B$\\
\hline
T & T &\TTbf{F}& & T & & F & & \TTbf{T} & F\\
\end{tabular}
\end{center}}
\item $(A \eif B)$, $(\enot B \eif \enot A)$ %Yes
\myanswer{\hfill Tautologically equivalent
\begin{center}
\begin{tabular}{c c | c | d e e e f}
$A$ & $B$ &$(A \eif B)$&$(\enot$&$B$&$\eif$&$\enot$&$A)$\\
\hline
T & T &T& F & & \TTbf{T} &  \\
T & F &F & T & & \TTbf{F} & F  \\
F & T &T& F & & \TTbf{T} &  \\
F & F &T& T & & \TTbf{T} & T
\end{tabular}
\end{center}}
\end{earg}

\problempart
\label{pr.TT.consistent}
Use complete or partial truth tables (as appropriate) to determine whether these sentences are jointly tautologically consistent, or jointly tautologically inconsistent:
\begin{earg}
\item $A \eand B$, $C\eif \enot B$, $C$ %inconsistent
\myanswer{\hfill Jointly tautologically inconsistent
\begin{center}
\begin{tabular}{c c c | c | d e f | c c c c  }
$A$ & $B$ & $C$ & $A \eand B$ & $C$&$\eif$&$\enot B$&$C$\\
\hline
T & T & T & T & & \TTbf{F} & F& T \\
T & T & F & T & & \TTbf{T} & & F \\
T & F & T & F & & \TTbf{T} &T & T \\
T & F & F & F & & \TTbf{T} & & F \\
F & T & T & F & & \TTbf{F} &F & T \\
F & T & F & F & & \TTbf{T} & & F \\
F & F & T & F & & \TTbf{T} & T& T \\
F & F & F & F & & \TTbf{T} & &  F \\
\end{tabular}
\end{center}}
\item $A\eif B$, $B\eif C$, $A$, $\enot C$ %inconsistent
\myanswer{\hfill Jointly tautologically inconsistent
\begin{center}
\begin{tabular}{c c c | c | c | c | c }
$A$ & $B$ & $C$ & $A \eif B$ & $B \eif C$ & $A$ & $\enot C$\\
\hline
T & T & T & T & T & T & F\\
T & T & F & T & F & T & T\\
T & F & T & F & T & T & F\\
T & F & F & F & T & T & T\\
F & T & T & T & T & F & F\\
F & T & F & T & F & F & T\\
F & F & T & T & T & F & F\\
F & F & F & T & T & F & T
\end{tabular}
\end{center}}
\item $A \eor B$, $B\eor C$, $C\eif \enot A$ %consistent
\myanswer{\hfill Jointly tautologically consistent
\begin{center}
\begin{tabular}{c c c | c | c | d e f }
$A$ & $B$ & $C$ & $A \eor B$ & $B \eor C$ & $C$&$\eif$& $\enot A$\\
\hline
F & T & T & T & T & & \TTbf{T} & T\\
\end{tabular}
\end{center}}
\item $A$, $B$, $C$, $\enot D$, $\enot E$, $F$ %consistent
\myanswer{\hfill Jointly tautologically consistent
\begin{center}
\begin{tabular}{c c c c c c| c | c | c | c |c | c }
$A$ & $B$ & $C$ & $D$ & $E$ & $F$ & $A$ & $B$ & $C$ & $\enot D$ & $\enot E$ & $F$\\
\hline
T & T & T & F & F & T & T & T& T& T& T& T
\end{tabular}
\end{center}}
\end{earg}

\problempart
\label{pr.TT.valid}
Use complete or partial truth tables (as appropriate) to determine whether each argument is valid or invalid:
\begin{earg}
\item $A\eor\bigl[A\eif(A\eiff A)\bigr] \therefore A$ %invalid
\myanswer{\hfill Invalid
\begin{center}
\begin{tabular}{c |  d e e e e e f | c}
$A$ & $A$&$\eor$&$\bigl[A$&$\eif$&$(A$&$\eiff$&$A)\bigr]$ & $A$\\
\hline
F & & \TTbf{T} & & T & & & & F
\end{tabular}
\end{center}}
\item $A\eiff\enot(B\eiff A) \therefore A$ %invalid
\myanswer{\hfill Invalid
\begin{center}
\begin{tabular}{c c | d e e f | c}
$A$&$B$ & $A$&$\eiff$&$\enot$&$(B\eiff A)$ & $A$\\
\hline
F & F & & \TTbf{T} & F & T & F
\end{tabular}
\end{center}}

\item $A\eif B, B \therefore A$ %invalid
\myanswer{\hfill Invalid
\begin{center}
\begin{tabular}{c c | c | c | c}
$A$&$B$ & $A \eif B$ & $B$ & $A$\\
\hline
F & T & T & T & F
\end{tabular}
\end{center}}

\item $A\eor B, B\eor C, \enot B \therefore A \eand C$ %valid
\myanswer{\hfill Valid
\begin{center}
\begin{tabular}{c c c | c | c | c | c }
$A$ & $B$ & $C$ & $A \eor B$ & $B \eor C$ & $\enot B$ & $A \eand C$\\
\hline
T & T & T &  &  &  & T\\
T & T & F &  &  & F & F\\
T & F & T &  &  &  & T\\
T & F & F & T & F & T & F\\
F & T & T &  &  & F & F\\
F & T & F &  &  & F & F\\
F & F & T & F &  & T & F\\
F & F & F & F &  & T & F
\end{tabular}
\end{center}}

\item $A\eiff B, B\eiff C \therefore A\eiff C$ %valid
\myanswer{\hfill Valid
\begin{center}
\begin{tabular}{c c c | c | c | c }
$A$ & $B$ & $C$ & $A \eiff B$ & $B \eiff C$ & $A \eiff C$\\
\hline
T & T & T &  &  & T\\
T & T & F & T & F & F\\
T & F & T &  &  & T\\
T & F & F & F &  & F\\
F & T & T & F &  & F\\
F & T & F &  &  & T\\
F & F & T & T & F & F\\
F & F & F &  &  & T
\end{tabular}
\end{center}}
\end{earg}