\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{tensor}
\usepackage{tikz-cd}

\begin{document}

\section*{Double backward of a function composition}

In a reverse autodiff, given a forward function $g\circ f:\mathbf x\rightarrow \mathbf y\rightarrow \mathbf z$, one needs to implement a backward function $B[g\circ f]:(\bar{\mathbf z},\mathbf x)\rightarrow\bar{\mathbf x}$, where $\bar\square\equiv{\partial L_0(\mathbf z)}/{\partial \square}$ and $L_0$ is some arbitrary unknown function.
A double backward is simply the backward of $B[g\circ f]$, that is, $B^2[g\circ f]:(\tilde{\bar{\mathbf x}},\bar{\mathbf z},\mathbf x)\rightarrow(\tilde{\bar{\mathbf z}},\tilde{\mathbf x})$, where $\tilde{\bar \square}\equiv{\partial L_1(\bar{\mathbf x})}/{\partial\bar\square}$, $\tilde\square\equiv{\partial L_1(\bar{\mathbf x})}/{\partial\square}$.

Einstein notation is used:
$$
\frac{\partial f^i(\mathbf x)}{\partial x^j}\equiv f\indices{^\prime^i_j}(\mathbf x),\qquad
\frac{\partial^2f^i(\mathbf x)}{\partial x^j\partial x^k}\equiv f\indices{^{\prime\prime}^i_{jk}}(\mathbf x),\qquad
\sum_j A_{ij}x^j\equiv A_{ij}x^j
$$

\paragraph{Forward \& backward}

\begin{tikzcd}
x^i \ar[r,"f"]\ar[d]
& f^\mu(\mathbf x)=y^\mu \ar[r,"g"]\ar[d]
& g^a(\mathbf y)=z^a
\\
\bar x_i=\bar y_\mu f\indices{^\prime^\mu_i}(\mathbf x) & \bar y_\mu=\bar z_ag\indices{^\prime^a_\mu}(\mathbf y) \ar[l,"B\lbrack f\rbrack"'] & \bar z_a \ar[l,"B\lbrack g\rbrack"']
\end{tikzcd}

\paragraph{Double backward}

\begin{tikzcd}
\tilde{\bar x}^i \ar[r,"B^2_{(1)}\lbrack f\rbrack"] \ar[rd,"B^2_{(2)}\lbrack f\rbrack"']
& f\indices{^\prime^\mu_i}(\mathbf x)\tilde{\bar x}^i=\tilde{\bar y}^\mu \ar[r,"B^2_{(1)}\lbrack g\rbrack"] \ar[rd,"B^2_{(2)}\lbrack g\rbrack"]
& g\indices{^\prime^a_\mu}(\mathbf y)\tilde{\bar y}^\mu=\tilde{\bar z}^a
\\
& \bar y_\mu f\indices{^{\prime\prime}^\mu_{ij}}(\mathbf x)\tilde{\bar x}^j=\tilde x_i \ar[rd]
& \bar z_a g\indices{^{\prime\prime}^a_{\mu\nu}}(\mathbf y)\tilde{\bar y}^\nu=\tilde y_\mu \ar[d]
\\
& & \tilde x_i:=\tilde x_i+\underbrace{\tilde y_\mu f\indices{^\prime^\mu_i}(\mathbf x)}_{=B[f]_i(\tilde{\mathbf y})}
\end{tikzcd}

\section*{\texttt{SLogLinearDet}}

\paragraph{Forward}
$$
f(\mathbf A):=\det\mathbf A\equiv D,\qquad
%
\frac{\partial D}{\partial A^{ij}}
\equiv f'_{ij}
=(\operatorname{Cof}\mathbf A)_{ij}
\equiv C_{ij}
$$
%
$$
g(\mathbf c,\mathbf D):=\ln c_pD^p,\qquad
\frac{\partial g}{\partial c_p}\equiv g'^p=\Psi^{-1}D^p,\quad
\frac{\partial g}{\partial D^p}\equiv g'_{p}=\Psi^{-1}c_p
$$
%
$$
F(\mathbf c,\mathbf A^q)
:=g(\mathbf c,f(\mathbf A^q))
=\ln c_p\det\mathbf A^p\equiv\ln\Psi\equiv P
$$
\paragraph{Backward}
$$
\begin{aligned}
B[g]^p(\bar P)\equiv\bar Pg'^p\equiv\bar c^p&=\bar P\Psi^{-1}D^p \\
B[g]_p(\bar P)\equiv\bar Pg'_p\equiv\bar D_p&=\bar P\Psi^{-1}c_p \\
B[f]_{ij}(\bar D)\equiv\bar Df'_{ij}\equiv\bar A_{ij}&=\bar DC_{ij} \\
B[F]^p(\bar P)\equiv\bar c^p&=B[g]^p(\bar P) \\
B[F]_{pij}(\bar P)
=\bar A_{pij}
&=B[f]_{ij}(\bar D_p)
\leftarrow\bar D_p=B[g]_p(\bar P)
\end{aligned}
$$
\paragraph{Double backward}
$$
f''_{ij,kl}=A^{-1}_{ji}C_{kl}-A^{-1}_{li}C_{kj}
$$
%
$$
g''^{pq}=-\Psi^{-2}D^pD^q,\quad
g''_{pq}=-\Psi^{-2}c_pc_q,\quad
g''^p_q=-\Psi^{-2}D^pc_q+\Psi^{-1}\delta^p_q
$$
%
$$
\begin{aligned}
B_{(1)}^2[f](\tilde{\bar{\mathbf A}})
\equiv f'_{ij}\tilde{\bar A}^{ij}
\equiv\tilde{\bar D}
&=C_{ij}\tilde{\bar A}^{ij}
=\operatorname{Tr}[\mathbf C\tilde{\bar{\mathbf A}}^\mathrm T]
\\
B_{(2)}^2[f]_{ij}(\tilde{\bar{\mathbf A}})
\equiv\bar Df''_{ij,kl}\tilde{\bar A}^{kl}
\equiv\tilde A_{ij}&=
\bar D(A^{-\mathrm T}_{ij}C_{kl}\tilde{\bar A}^{kl}-A^{-\mathrm T}_{il}\tilde{\bar A}^{kl}C_{kj}) \\
&=\bar D\{\mathbf A^{-\mathrm T}(\operatorname{Tr}[\mathbf C\tilde{\bar{\mathbf A}}^\mathrm T]\mathbf I-\tilde{\bar{\mathbf A}}^\mathrm T\mathbf C)\}_{ij}\ (\equiv\bar DY_{ij})
\\
B_{(1)}^2[g](\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf D}})
\equiv g'^p\tilde{\bar c}_p+g'_p\tilde{\bar D}^p
\equiv\tilde{\bar P}
&=\Psi^{-1}D^p\tilde{\bar c}_p+\Psi^{-1}c_p\tilde{\bar D}^p=\Psi^{-1}(\mathbf D\cdot\tilde{\bar{\mathbf c}}+\mathbf c\cdot\tilde{\bar{\mathbf D}})
\\
B_{(2)}^2[g]^p(\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf D}})
\equiv\bar P(g''^{pq}\tilde{\bar c}_q+g''^p_q\tilde{\bar D}^q)
\equiv\tilde c^p
&=\bar P(-\Psi^{-2}D^pD^q\tilde{\bar c}_q+(-\Psi^{-2}D^pc_q+\Psi^{-1}\delta^p_q)\tilde{\bar D}^q) \\
&=\bar P(-\Psi^{-2}(\mathbf D\cdot\tilde{\bar{\mathbf c}}+\mathbf c\cdot\tilde{\bar{\mathbf D}})\mathbf D+\Psi^{-1}\tilde{\bar{\mathbf D}})^p
\\
B_{(2)}^2[g]_p(\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf D}})
\equiv\bar P(g''^q_p\tilde{\bar c}_q+g''_{pq}\tilde{\bar D}^q)
\equiv\tilde D_p
&=\bar P((-\Psi^{-2}D^qc_p+\Psi^{-1}\delta^q_p)\tilde{\bar c}_q-\Psi^{-2}c_pc_q\tilde{\bar D}^q) \\
&=\bar P(-\Psi^{-2}(\mathbf D\cdot\tilde{\bar{\mathbf c}}+\mathbf c\cdot\tilde{\bar{\mathbf D}})\mathbf c+\Psi^{-1}\tilde{\bar{\mathbf c}})_p
\\
B_{(1)}^2[F](\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf A}}^q)
\equiv\tilde{\bar P}
&=B_{(1)}^2[g](\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf D}})
\leftarrow\tilde{\bar D}^p=B^2_{(1)}[f](\tilde{\bar{\mathbf A}}^p)
\\
B_{(2)}^2[F]^p(\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf A}}^q)
\equiv\tilde c^p
&=B^2_{(2)}[g]^p(\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf D}})
\\
B_{(2)}^2[F]_{pij}(\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf A}}^q)
\equiv\tilde A_{pij}
&=B^2_{(2)}[f]_{ij}(\tilde{\bar{\mathbf A}}^p)+B^2_{(2)}[g]_p(\tilde{\bar{\mathbf c}},\tilde{\bar{\mathbf D}})C_{pij}
\end{aligned}
$$

\end{document}


\documentclass{article}
\usepackage{mathtools}
\usepackage{mathrsfs}
\usepackage{hyperref}
\usepackage{multirow}
\hypersetup{colorlinks,citecolor=black,filecolor=black,linkcolor=black,urlcolor=black}

\begin{document}

\section*{DEFINITION OF TEXTURE FEATURES}
\bigskip

\noindent \textbf{Input volume:} Volume of interest $V(x,y,z)$ with isotropic voxel size. The necessity for isotropically resampling $V$ to a given voxel dimension prior to texture analysis results from the fact that: 1) \textit{Global} features are computed from histograms counting the number of gray-levels in 3D space; and 2) all higher-order texture measurements explicitly or implicitly involve a distance parameter in the matrix computation (GLCM, GLRLM, GLSZM and NGTDM). For this parameter to be meaningful in 3D space and in order for the orientation dependence of the tumour to be minimized, isotropic resolution is required.
\bigskip \bigskip

% GLOBAL TEXTURES
\noindent \textbf{Global texture features (first-order gray-level statistics).} \\
Let $P$ define the first-order histogram of a volume $V(x,y,z)$ with isotropic voxel size. $P(i)$ represents the number of voxels with gray-level $i$, and $N_g$ represents the number of gray-level bins set for $P$. The $i^{\mathrm{th}}$ entry of the normalized histogram is then defined as:

\[p(i) = \frac{P(i)}{\sum_{i=1}^{N_g} P(i)}.\] \\

\noindent The \textit{Global} texture features are then defined as:

\begin{itemize}
	\item Variance:
		  \[\sigma^2 = \sum_{i=1}^{N_g} (i-\mu)^2\,p(i)\]
	\item Skewness:
		  \[s = \sigma^{-3} \sum_{i=1}^{N_g} (i-\mu)^3\,p(i)\]
	\item Kurtosis
		  \[k = \sigma^{-4} \sum_{i=1}^{N_g} \left[(i-\mu)^4\,p(i)\right]-3\]
	\\
\end{itemize}

% GLCM TEXTURES
\noindent \textbf{Gray-Level Co-occurence Matrix (GLCM) texture features.} \\
Let $P$ define the GLCM of a quantized volume $V(x,y,z)$ with isotropic voxel size. $P(i,j)$ represents the number of times voxels of gray-level $i$ were neighbours with voxels of gray-level $j$ in $V$, and $N_g$ represents the pre-defined number of quantized gray-levels set in $V$. Only one GLCM of size $N_g \times N_g$ is computed per volume $V$ by simultaneously adding up the frequency of co-occurences of all voxels with their 26-connected neighbours in 3D space, with all voxels (\textit{including} the peripheral region) considered once as a center voxel (according to \cite{HaralickRM1973}, thus always using $d=1$). To account for discretization length differences, neighbours at a distance of $\sqrt{3}$ voxels around a center voxel increment the GLCM by a value of $\sqrt{3}$, neighbours at a distance of $\sqrt{2}$ voxels around a center voxel increment the GLCM by a value of $\sqrt{2}$, and neighbours at a distance of 1 voxel around a center voxel increment the GLCM by a value of 1. The entry $(i,j)$ of the of the normalized GLCM is then defined as:

\[p(i,j) = \frac{P(i,j)}{\sum_{i=1}^{N_g}\sum_{j=1}^{N_g} P(i,j)}.\]

\noindent The following quantities are also defined:
\[\mu_i = \sum_{i=1}^{N_g} i \sum_{j=1}^{N_g} p(i,j), \qquad \mu_j = \sum_{j=1}^{N_g} j \sum_{i=1}^{N_g} p(i,j),\]
\[\sigma_i = \sum_{i=1}^{N_g} (i-\mu_i)^2 \sum_{j=1}^{N_g} p(i,j), \qquad \sigma_j = \sum_{j=1}^{N_g} (j-\mu_j)^2 \sum_{i=1}^{N_g} p(i,j).\] \\

\noindent The GLCM texture features are then defined as:

\begin{itemize}
	\item Energy \cite{HaralickRM1973}:
		  \[energy = \sum_{i=1}^{N_g}\sum_{j=1}^{N_g} \left[p(i,j)\right]^2\]
	\item Contrast \cite{HaralickRM1973}:
		  \[contrast = \sum_{i=1}^{N_g}\sum_{j=1}^{N_g} (i-j)^2\,p(i,j)\]
	\item Correlation (adapted from \cite{HaralickRM1973}):
		  \[correlation = \sum_{i=1}^{N_g}\sum_{j=1}^{N_g} \frac{(i-\mu_i)\,(j-\mu_j)\,p(i,j)}
		  {\sigma_i\,\sigma_j}\]
	\item Homogeneity (adapted from \cite{HaralickRM1973}):
		  \[homogeneity = \sum_{i=1}^{N_g}\sum_{j=1}^{N_g} \frac{p(i,j)}{1 + \vert i-j \vert}\]
	\item Variance (adapted from \cite{HaralickRM1973}):
		  \[variance = \frac{1}{N_g \times N_g} \sum_{i=1}^{N_g}\sum_{j=1}^{N_g}
		  \left[(i-\mu_i)^2\,p(i,j) + (j-\mu_j)^2\,p(i,j)\right]\]
	\item Sum Average (adapted from \cite{HaralickRM1973}):
		  \[sum\text{ }average = \frac{1}{N_g \times N_g} \sum_{i=1}^{N_g}\sum_{j=1}^{N_g}
		  \left[i\,p(i,j) + j\,p(i,j)\right]\]
	\item Entropy \cite{HaralickRM1973}:
		  \[entropy = -\sum_{i=1}^{N_g}\sum_{j=1}^{N_g} p(i,j)\,\text{log}_2\big(p(i,j)\big)\]
	\item Dissimilarity \cite{ThibaultG2009t}:
		  \[dissimilarity = \sum_{i=1}^{N_g}\sum_{j=1}^{N_g} \vert i-j \vert \,p(i,j)\]
	\\
\end{itemize}

% GLRLM TEXTURES
\noindent \textbf{Gray-Level Run-Length Matrix (GLRLM) texture features.} \\
Let $P$ define the GLRLM of a quantized volume $V(x,y,z)$ with isotropic voxel size. $P(i,j)$ represents the number of runs of gray-level $i$ and of length $j$ in $V$, $N_g$ represents the pre-defined number of quantized gray-levels set in $V$, and $L_r$ represents the length of the longest run (of any gray-level) in $V$. Only one GLRLM of size $N_g \times L_r$ is computed per volume $V$ by simultaneously adding up all possible longest run-lengths in the 13 directions of 3D space (one voxel can be part of multiple runs in different directions, but can be part of only one run in a given direction). A MATLAB toolbox created by Xunkai Wei \cite{WeiX2008} computes GLRLMs from 2D images, and it can be used to facilitate the computation of GLRLMs from 3D volumes. To account for discretization length differences, runs constructed from voxels separated by a distance of $\sqrt{3}$ increment the GLRLM by a value of $\sqrt{3}$, runs constructed from voxels separated by a distance of $\sqrt{2}$ increment the GLRLM by a value of $\sqrt{2}$, and runs constructed from voxels separated by a distance of 1 increment the GLRLM by a value of 1. The entry $(i,j)$ of the of the normalized GLRLM is then defined as:

\[p(i,j) = \frac{P(i,j)}{\sum_{i=1}^{N_g}\sum_{j=1}^{L_r} P(i,j)}.\]

\noindent The following quantities are also defined:
\[\mu_i = \sum_{i=1}^{N_g} i \sum_{j=1}^{L_r} p(i,j), \qquad \mu_j = \sum_{j=1}^{L_r} j \sum_{i=1}^{N_g} p(i,j).\] \\

\noindent The GLRLM texture features are then defined as:

\begin{itemize}
	\item Short Run Emphasis (SRE) \cite{GallowayMM1975}:
		  \[SRE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} \frac{p(i,j)}{j^2}\]
	\item Long Run Emphasis (LRE) \cite{GallowayMM1975}:
		  \[LRE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} j^2\,p(i,j)\]
	\item Gray-Level Nonuniformity (GLN) (adapted from \cite{GallowayMM1975}):
		  \[GLN = \sum_{i=1}^{N_g}\left(\sum_{j=1}^{L_r} p(i,j)\right)^2\]
	\item Run-Length Nonuniformity (RLN) (adapted from \cite{GallowayMM1975}):
		  \[RLN = \sum_{j=1}^{L_r}\left(\sum_{i=1}^{N_g} p(i,j)\right)^2\]
	\item Run Percentage (RP) (adapted from \cite{GallowayMM1975}):
		  \[RP = \frac{\sum_{i=1}^{N_g}\sum_{j=1}^{L_r} p(i,j)}{\sum_{j=1}^{L_r} j
		  \sum_{i=1}^{N_g} p(i,j)}\]
	\item Low Gray-Level Run Emphasis (LGRE) \cite{ChuA1990}:
		  \[LGRE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} \frac{p(i,j)}{i^2}\]
	\item High Gray-Level Run Emphasis (HGRE) \cite{ChuA1990}:
		  \[HGRE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} i^2\,p(i,j)\]
	\item Short Run Low Gray-Level Emphasis (SRLGE) \cite{DasarathyBV1991}:
		  \[SRLGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} \frac{p(i,j)}{i^2j^2}\]
	\item Short Run High Gray-Level Emphasis (SRHGE) \cite{DasarathyBV1991}:
		  \[SRHGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} \frac{i^2\,p(i,j)}{j^2}\]
	\item Long Run Low Gray-Level Emphasis (LRLGE) \cite{DasarathyBV1991}:
		  \[LRLGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} \frac{j^2\,p(i,j)}{i^2}\]
	\item Long Run High Gray-Level Emphasis (LRHGE) \cite{DasarathyBV1991}:
		  \[LRHGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_r} i^2j^2\,p(i,j)\]
	\item Gray-Level Variance (GLV) (adapted from \cite{ThibaultG2009}):
		  \[GLV = \frac{1}{N_g \times L_r} \sum_{i=1}^{N_g}\sum_{j=1}^{L_r}
		  \left(i\,p(i,j)-\mu_i\right)^2\]
	\item Run-Length Variance (RLV) (adapted from \cite{ThibaultG2009}):
		  \[RLV = \frac{1}{N_g \times L_r} \sum_{i=1}^{N_g}\sum_{j=1}^{L_r}
		  \left(j\,p(i,j)-\mu_j\right)^2\]
	\\
\end{itemize}

% GLSZM TEXTURES
\noindent \textbf{Gray-Level Size Zone Matrix (GLSZM) texture features.} \\
Let $P$ define the GLSZM of a quantized volume $V(x,y,z)$ with isotropic voxel size. $P(i,j)$ represents the number of 3D zones of gray-levels $i$ and of size $j$ in $V$, $N_g$ represents the pre-defined number of quantized gray-levels set in $V$, and $L_z$ represents the size of the largest zone (of any gray-level) in $V$.  One GLSZM of size $N_g \times L_z$ is computed per volume $V$ by adding up all possible largest zone-sizes, with zones constructed from 26-connected neighbours  of the same gray-level in 3D space (one voxel can be part of only one zone). The entry $(i,j)$ of the normalized GLSZM is then defined as:

\[p(i,j) = \frac{P(i,j)}{\sum_{i=1}^{N_g}\sum_{j=1}^{L_z} P(i,j)}.\]

\noindent The following quantities are also defined:
\[\mu_i = \sum_{i=1}^{N_g} i \sum_{j=1}^{L_z} p(i,j), \qquad \mu_j = \sum_{j=1}^{L_z} j \sum_{i=1}^{N_g} p(i,j).\] \\

\noindent The GLSZM texture features are then defined as:

\begin{itemize}
	\item Small Zone Emphasis (SZE) \cite{GallowayMM1975,ThibaultG2009}:
		  \[SZE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} \frac{p(i,j)}{j^2}\]
	\item Large Zone Emphasis (LZE) \cite{GallowayMM1975,ThibaultG2009}:
		  \[LZE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} j^2\,p(i,j)\]
	\item Gray-Level Nonuniformity (GLN) (adapted from \cite{GallowayMM1975,ThibaultG2009}):
		  \[GLN = \sum_{i=1}^{N_g}\left(\sum_{j=1}^{L_z} p(i,j)\right)^2\]
	\item Zone-Size Nonuniformity (ZSN) (adapted from \cite{GallowayMM1975,ThibaultG2009}):
		  \[ZSN = \sum_{j=1}^{L_z}\left(\sum_{i=1}^{N_g} p(i,j)\right)^2\]
	\item Zone Percentage (RP) (adapted from \cite{GallowayMM1975,ThibaultG2009}):
		  \[ZP = \frac{\sum_{i=1}^{N_g}\sum_{j=1}^{L_z} p(i,j)}{\sum_{j=1}^{L_z} j
		  \sum_{i=1}^{N_g} p(i,j)}\]
	\item Low Gray-Level Zone Emphasis (LGZE) \cite{ChuA1990,ThibaultG2009}:
		  \[LGZE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} \frac{p(i,j)}{i^2}\]
	\item High Gray-Level Zone Emphasis (HGZE) \cite{ChuA1990,ThibaultG2009}:
		  \[HGZE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} i^2\,p(i,j)\]
	\item Small Zone Low Gray-Level Emphasis (SZLGE) \cite{DasarathyBV1991,ThibaultG2009}:
		  \[SZLGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} \frac{p(i,j)}{i^2j^2}\]
	\item Small Zone High Gray-Level Emphasis (SZHGE) \cite{DasarathyBV1991,ThibaultG2009}:
		  \[SZHGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} \frac{i^2\,p(i,j)}{j^2}\]
	\item Large Zone Low Gray-Level Emphasis (LZLGE) \cite{DasarathyBV1991,ThibaultG2009}:
		  \[LZLGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} \frac{j^2\,p(i,j)}{i^2}\]
	\item Large Zone High Gray-Level Emphasis (LZHGE) \cite{DasarathyBV1991,ThibaultG2009}:
		  \[LZHGE = \sum_{i=1}^{N_g}\sum_{j=1}^{L_z} i^2j^2\,p(i,j)\]
	\item Gray-Level Variance (GLV) (adapted from \cite{ThibaultG2009}):
		  \[GLV = \frac{1}{N_g \times L_z} \sum_{i=1}^{N_g}\sum_{j=1}^{L_z}
		  \left(i\,p(i,j)-\mu_i\right)^2\]
	\item Zone-Size Variance (ZSV) (adapted from \cite{ThibaultG2009}):
		  \[ZSV = \frac{1}{N_g \times L_z} \sum_{i=1}^{N_g}\sum_{j=1}^{L_z}
		  \left(j\,p(i,j)-\mu_j\right)^2\]
	\\
\end{itemize}

% NGTDM TEXTURES
\noindent \textbf{Neighbourhood Gray-Tone Difference Matrix (NGTDM) texture features.} \\
Let $P(i)$ define the NGTDM of a quantized volume $V(x,y,z)$ with isotropic voxel size. $P(i)$ represents the summation of the gray-level differences between all voxels with gray-level $i$ and the average gray-level of their 26-connected neighbours in 3D space. $N_g$ represents the pre-defined number of quantized gray-levels set in $V$, and $(N_g)_{eff}$ is the effective number of gray-levels in $V$, with $(N_g)_{eff} < N_g$ (let the vector of gray-levels values in $V$ be denoted as $\textbf{g} = g(1),g(2),\ldots,g(N_g)$; some gray-levels excluding $g(1)$ and $g(N_g)$ may not appear in $V$ due to different quantization schemes). One NGTDM of size $N_g \times 1$ is computed per volume $V$. To account for discretization length differences, all averages around a center voxel located at position $(j,k,l)$ in $V$ are performed such that the neighbours at a distance of $\sqrt{3}$ voxels are given a weight of $1/\sqrt{3}$, the neighbours at a distance of $\sqrt{2}$ voxels are given a weight of $1/\sqrt{2}$, and the neighbours at a distance of 1 voxel are given a weight of 1. The $i^{\mathrm{th}}$ entry of the NGTDM is then defined as:

\[P(i) = \begin{cases}
		 \sum_{\text{all voxels}\,\in \{N_i\}} \vert i-\overline{A}_i \vert & \text{if } N_i >
		 0, \\
		 0 & \text{if } N_i = 0.
		 \end{cases}
\]

\noindent where $\{N_i\}$ is the set of all voxels with gray-level $i$ in $V$ (\textit{including} the peripheral region), $N_i$ is the number of voxels with gray-level $i$ in $V$, and $\overline{A}_i$ is the average gray-level of the 26-connected neighbours around a center voxel with gray-level $i$ and located at position $(j,k,l)$ in $V$ such that:

\[\overline{A}_i = \overline{A}(j,k,l) = \frac{\sum_{m=-1}^{m=1}\sum_{n=-1}^{n=1}\sum_{o=-1}^{o=1} w_{m,n,o} \cdot V(j+m,k+n,l+o)}{\sum_{m=-1}^{m=1}\sum_{n=-1}^{n=1}\sum_{o=-1}^{o=1} w_{m,n,o}},\]

\[\text{where} \quad w_{m,n,o} =  \begin{cases}
									1 & \text{if } |j-m| + |k-n| + |l-o| = 1,\\
									\frac{1}{\sqrt{2}} & \text{if } |j-m| + |k-n| + |l-o| =
									2,\\
									\frac{1}{\sqrt{3}} & \text{if } |j-m| + |k-n| + |l-o| =
									3,\\
									0 & \text{if } V(j+m,k+n,l+o) \text{ is undefined.} \\
								\end{cases}\]

\noindent The following quantity is also defined:
\[n_i = \frac{N_i}{N}.\]

\noindent where $N$ is the total number of voxels in $V$. The NGTDM texture features are then defined as:

\begin{itemize}
	\item Coarseness \cite{AmadasunM1989}:
		  \[coarseness = \left[\epsilon + \sum_{i=1}^{N_g} n_i\,P(i)\right]^{-1}\]
		  where $\epsilon$ is a small number to prevent $coarseness$ becoming infinite.
	\item Contrast \cite{AmadasunM1989}:
		  \[contrast = \left[\frac{1}{(N_g)_{eff}\,\big[(N_g)_{eff}-1\big]}\sum_{i=1}^{N_g}\sum_{j=1}^{N_g}
		  n_i\,n_j\,(i-j)^2\right]\left[\frac{1}{N}\sum_{i=1}^{N_g} P(i)\right]\]
	\item Busyness \cite{AmadasunM1989}:
		  \[busyness = \frac{\sum_{i=1}^{N_g} n_i\,P(i)}{\sum_{i=1}^{N_g}\sum_{j=1}^{N_g} (i\,n_i - j\,n_j)},
		  \quad n_i \neq 0,n_j \neq 0\]
	\item Complexity \cite{AmadasunM1989}:
		  \[complexity = \sum_{i=1}^{N_g}\sum_{j=1}^{N_g} \frac{|i-j|\,\big[n_i\,P(i) + n_j\,P(j)\big]}{N\,(n_i
		  + n_j)}, \quad n_i \neq 0,n_j \neq 0\]
	\item Strength \cite{AmadasunM1989}:
		  \[strength = \frac{\sum_{i=1}^{N_g}\sum_{j=1}^{N_g} (n_i + n_j)\,(i-j)^2}{\left[\epsilon +
		  \sum_{i=1}^{N_g} P(i)\right]},  \quad n_i \neq 0,n_j \neq 0\]
		  where $\epsilon$ is a small number to prevent $strength$ becoming infinite.
	\\
\end{itemize}

\section*{Online resources}
MATLAB$^{\textregistered}$ software code is freely shared under the GNU General Public License at: \url{https://github.com/mvallieres/radiomics}.

\footnotesize
\begin{thebibliography}{99} % Referencing close to Harvard style, but better looking than in PMB

	\bibitem	{HaralickRM1973} Haralick, R.M., Shanmugam, K. and Dinstein, I. (1973).
			{Textural features for image classification}.
			{\em IEEE Transactions on Systems, Man, and Cybernetics}, smc \textbf{3}(6),
			610-621.

	\bibitem{ThibaultG2009t}	 Thibault, G. (2009).
			{Indices de formes et de textures: de la 2D vers la 3D. Application au classement de noyaux de cellules}.
			{\em PhD Thesis}, Universit\'e AIX-Marseille: p.172.

	\bibitem{GallowayMM1975} Galloway, M.M. (1975).
			{Texture analysis using gray level run lengths}.
			{\em Computer Graphics and Image Processing}, \textbf{4}(2), 172-179.

	\bibitem{AmadasunM1989} Amadasun, M. and King, R. (1989).
			{Textural features corresponding to textural properties}.
			{\em IEEE Transactions on Systems, Man, and Cybernetics}, \textbf{19}(5), 1264-1274.

	\bibitem{ChuA1990} Chu, A. Sehgal, C.M. and Greenleaf, J.F. (1990).
			{Use of gray value distribution of run lengths for texture analysis}.
			{\em Pattern Recognition Letters}, \textbf{11}(6), 415-419.

	\bibitem{DasarathyBV1991} Dasarathy, B.V. and Holder, E.B. (1991).
			{Image characterization based on joint gray level-run length distributions}.
			{\em Pattern Recognition Letters}, \textbf{12}(8), 497-502.

	\bibitem{ThibaultG2009} Thibault, G. et al. (2009).
			{Texture indexes and gray level size zone matrix. Application to cell nuclei
			classification}. In {\em Pattern Recognition and Information Processing}.
			Minsk, Belarus, 140-145.

	\bibitem{WeiX2008} Wei, X. (2007).
			{Gray Level Run Length Matrix Toolbox v1.0, computer software}.
			{Beijing Aeronautical Technology Research Center}.
			{Available from: http://www.mathworks.com/matlabcentral/fileexchange/17482-gray-level-run-length-matrix-toolbox}. [11 January 2013]

\end{thebibliography}

\end{document}


\subsection{First-order logic}\label{subsec:first_order_logic}

\begin{definition}\label{def:first_order_language}\mcite[sec. 15.2]{OpenLogicFull}
  The idea of first-order predicate logic (we will omit \enquote{predicate} and only refer to \enquote{first-order logic}) is to create a formal language whose semantics (given by structures) support boolean operations and can quantify over all elements of an ambient universe. Unlike in \hyperref[subsec:propositional_logic]{propositional logic}, there are different first-order logic languages.

  The alphabet for a \term{first-order logic \hyperref[def:formal_language]{language}} \( \mscrL \) extends that of \hyperref[subsec:propositional_logic]{propositional logic} and consists of two types of symbols (note that \fullref{rem:propositional_language_is_alphabet} holds here also).

  \begin{description}
    \item[Logical symbols]
    \hfill
    \begin{thmenum}[series=def:first_order_language]
      \thmitem{def:first_order_language/propositional} The entirety of the \hyperref[subsec:propositional_logic]{propositional logic language} except for the \hyperref[def:propositional_language/prop]{propositional variables}.

      \thmitem{def:first_order_language/var} A nonempty at most \hyperref[thm:omega_is_a_cardinal]{countable} alphabet of \term{individual variables} \( \boldop{Var} \), usually denoted by small Greek letters \( \xi_1, \xi_2, \ldots \) or \( \xi, \eta, \zeta \) --- see \fullref{rem:mathematical_logic_conventions/variable_symbols}.

      \thmitem{def:first_order_language/quantifiers} The quantifiers \( Q = \set{ \forall, \exists } \):
      \begin{thmenum}
        \thmitem{def:first_order_language/quantifiers/universal} The \term{universal quantifier} \( \forall \).
        \thmitem{def:first_order_language/quantifiers/existential} The \term{existential quantifier} \( \exists \).
        \thmitem{def:first_order_language/quantifiers/dot} The dot \( . \) for separating a quantifier from its formula.
      \end{thmenum}

      The dot is not itself a quantifier and is not formally necessary --- we use it only for readability.

      \thmitem{def:first_order_language/equality} A symbol for \term{formal equality} \( \doteq \). Equality is sometimes omitted by logicians, but examples of first-order languages without formal equality are obscure.
    \end{thmenum}

    \item[Non-logical symbols]
    \hfill
    \begin{thmenum}[resume=def:first_order_language]
      \thmitem{def:first_order_language/func} A set of functional symbols, \( \boldop{Fun} \), whose elements are usually denoted by \( f_1, f_2, \ldots \) or \( f, g \) or by symbols like \( \otimes \). In the latter case we usually use infix notation (see \fullref{rem:first_order_formula_conventions/infix}). Each functional symbol has an associated natural number called its \term{arity}, denoted by \( \# f \). Functional symbols with a zero arity are called \term{constants}.

      \thmitem{def:first_order_language/pred} A set of predicate symbols, \( \boldop{Pred} \), whose elements are usually denoted by \( p_1, p_2, \ldots \) or by symbols like \( \leq \). Again, in the latter case we use infix notation. Predicate symbols also have an associated arity. Predicate symbols with zero arity are called \term{propositional variables}.
    \end{thmenum}
  \end{description}

  The logical symbols are common for all first-order languages. Thus, first-order languages differ by their non-logical symbols. The collection of functional and predicate symbols of a language are sometimes called its \term{signature}.
\end{definition}

\begin{definition}\label{def:first_order_syntax}
  Similarly to the \hyperref[def:propositional_syntax]{syntax of propositional logic}, we define the \term{syntax} of a fixed first-order language \( \mscrL \).

  \begin{thmenum}
    \thmitem{def:first_order_syntax/grammar_schema} Consider the following \hyperref[ex:natural_number_arithmetic_grammar/backus_naur_form]{grammar schema}:
    \begin{bnf*}
      \bnfprod{variable}        {v \in \boldop{Var}} \\
      \bnfprod{connective}      {\bincirc \in \Sigma} \\
      \bnfprod{quantifier}      {\bnfts{\( \forall \)} \bnfor \bnfts{\( \exists \)}} \\
      \bnfprod{unary function}  {f \in \boldop{Fun}, \#f = 1} \\
      \bnfmore                  {\vdots} \\
      \bnfprod{n-ary function}  {f \in \boldop{Fun}, \#f = n \T{(standalone rule for each \( n \))}} \\
      \bnfmore                  {\vdots} \\
      \bnfprod{unary predicate} {p \in \boldop{Pred}, \#p = 1} \\
      \bnfmore                  {\vdots} \\
      \bnfprod{n-ary predicate} {p \in \boldop{Pred}, \#p = n \T{(standalone rule for each \( n \))}} \\
      \bnfmore                  {\vdots} \\
      \bnfprod{term}            {\bnfpn{variable} \bnfor} \\
      \bnfmore                  {\bnfpn{unary function} \bnfsp \bnfts{(} \bnfsp \bnfpn{term} \bnfsp \bnfts{)} \bnfor} \\
      \bnfmore                  {\hspace{3cm} \vdots} \\
      \bnfmore                  {\bnfpn{n-ary function} \bnfsp \underbrace{\bnfts{(} \bnfsp \bnfpn{term} \bnfts{,} \bnfsk \bnfts{,} \bnfpn{term} \bnfsp \bnfts{)}}_{n \T{terms}} \bnfor} \\
      \bnfmore                  {\hspace{3cm} \vdots} \\
      \bnfprod{atomic formula}  {\bnfts{\( \top \)} \bnfor \bnfts{\( \bot \)} \bnfor} \\
      \bnfmore                  {\bnfts{(} \bnfsp \bnfpn{term} \bnfsp \bnfts{\( \doteq \)} \bnfsp \bnfpn{term} \bnfsp \bnfts{)} \bnfor} \\
      \bnfmore                  {\bnfpn{unary predicate} \bnfsp \bnfts{(} \bnfsp \bnfpn{term} \bnfsp \bnfts{)} \bnfor} \\
      \bnfmore                  {\hspace{3cm} \vdots} \\
      \bnfmore                  {\bnfpn{n-ary predicate} \bnfsp \underbrace{\bnfts{(} \bnfsp \bnfpn{term} \bnfts{,} \bnfsk \bnfts{,} \bnfpn{term} \bnfsp \bnfts{)}}_{n \T{terms}} \bnfor} \\
      \bnfmore                  {\hspace{3cm} \vdots} \\
      \bnfprod{formula}         {\bnfpn{atomic formula} \bnfor} \\
      \bnfmore                  {\bnfts{\( \neg \)} \bnfpn{formula} \bnfor} \\
      \bnfmore                  {\bnfts{(} \bnfsp \bnfpn{formula} \bnfsp \bnfpn{connective} \bnfsp \bnfpn{formula} \bnfsp \bnfts{)} \bnfor} \\
      \bnfmore                  {\bnfpn{quantifier} \bnfsp \bnfpn{variable} \bnfsp \bnfts{.} \bnfsp \bnfpn{formula}}
    \end{bnf*}

    In practice, we usually only have functions and predicates of specific arities. Note that we can have infinitely many functions, but only finitely many different arities. The \hyperref[rem:theory_of_left_monoid_actions]{theory of monoid actions} is an example of a first-order language with infinitely many unary functional symbols, one constant and one binary functional symbol.

    If we need the grammars to have a finite set of rules, except for having only finitely many different arities, we need to introduce appropriate naming conventions for variables, functions and predicates, analogously to the \hyperref[def:propositional_syntax/grammar_schema]{grammar schema of propositional logic}.

    We use the conventions in \fullref{rem:propositional_formula_parentheses} regarding parentheses by extending them wherever appropriate.

    In order to simplify notation, we also use the conventions in \fullref{rem:first_order_formula_conventions}.

    \thmitem{def:first_order_syntax/term} The set \( \boldop{Term} \) of \term{terms} in \( \mscrL \) is the language \hyperref[def:grammar_derivation/grammar_language]{generated} by this grammar schema with \( \bnfpn{term} \) as a starting rule.

    The grammar of first-order terms is unambiguous due to \fullref{thm:first_order_terms_and_formulas_are_unambiguous}, which makes it possible to perform proofs via \fullref{thm:structural_induction_on_unambiguous_grammars}.

    \thmitem{def:first_order_syntax/subterm} If \( \tau \) and \( \kappa \) are terms and \( \kappa \) is a \hyperref[def:formal_language/subword]{subword} of \( \tau \), we say that \( \kappa \) is a \term{subterm} of \( \tau \).

    \thmitem{def:first_order_syntax/term_variables} For each term \( \tau \), we define its variables as
    \begin{equation}\label{eq:def:first_order_syntax/term_variables}
      \boldop{Var}(\tau) \coloneqq \begin{cases}
        \xi,                                                        &\tau = \xi \in \boldop{Var}, \\
        \boldop{Var}(\tau_1) \cup \ldots \cup \boldop{Var}(\tau_n), &\tau = f(\tau_1, \ldots, \tau_n).
      \end{cases}
    \end{equation}

    As in \fullref{def:propositional_syntax/variables}, \( \boldop{Var} \) is ordered by the position of the first occurrence of a variable.

    \thmitem{def:first_order_syntax/ground_term} A term \( \tau \) is called a \term{ground term} if \( \boldop{Var}(\tau) = \varnothing \). Ground terms are also called \term{closed terms}.

    \thmitem{def:first_order_syntax/atomic_formula} The set \( \boldop{Atom} \) of \term{atomic formulas} in \( \mscrL \) is the language \hyperref[def:grammar_derivation/grammar_language]{generated} by this grammar schema with \( \bnfpn{atomic formula} \) as a starting rule.

    \thmitem{def:first_order_syntax/formula} The set \( \boldop{Form} \) of \term{formulas} in \( \mscrL \) is the language \hyperref[def:grammar_derivation/grammar_language]{generated} by this grammar schema with \( \bnfpn{formula} \) as a starting rule.

    The \term{atomic formulas} are the ones generated from \( \bnfpn{atomic formula} \).

    The grammar of first-order formulas is unambiguous as shown by \fullref{thm:first_order_terms_and_formulas_are_unambiguous}.

    See \fullref{ex:first_order_substitution} for examples of first-order formulas.

    \thmitem{def:first_order_syntax/subformula} If \( \varphi \) and \( \psi \) are formulas and \( \psi \) is a \hyperref[def:formal_language/subword]{subword} of \( \varphi \), we say that \( \psi \) is a \term{subformula} of \( \varphi \).

    \thmitem{def:first_order_syntax/formula_terms} If \( \varphi \) is a formula, if \( \tau \) is a term and if \( \tau \) is a \hyperref[def:formal_language/subword]{subword} of \( \varphi \), we say that \( \tau \) is a \term{term} of \( \varphi \).

    \thmitem{def:first_order_syntax/formula_free_variables} The \term{free variables} of a formula are defined as
    \begin{equation}\label{eq:def:first_order_syntax/formula_free_variables}
      \boldop{Free}(\varphi) \coloneqq \begin{cases}
        \varnothing,                                                &\varphi \in \set{ \top, \bot } \\
        \boldop{Var}(\tau_1) \cup \ldots \cup \boldop{Var}(\tau_n), &\varphi = p(\tau_1, \ldots, \tau_n) \\
        \boldop{Var}(\tau_1) \cup \boldop{Var}(\tau_2),             &\varphi = \tau_1 \doteq \tau_2, \\
        \boldop{Free}(\psi),                                        &\varphi = \neg \psi, \\
        \boldop{Free}(\psi_1) \cup \boldop{Free}(\psi_2),           &\varphi = \psi_1 \bincirc \psi_2, \bincirc \in \Sigma, \\
        \boldop{Free}(\psi) \setminus \set{ \xi },                  &\varphi = \quantifier{Q}{\xi} \psi, Q \in \set{ \forall, \exists }
      \end{cases}
    \end{equation}

    \thmitem{def:first_order_syntax/ground_formula} A formula \( \varphi \) is called a \term{ground formula} if \( \boldop{Free}(\varphi) = \varnothing \). Ground formulas are also called \term{closed formulas} or \term{sentences} (unlike in propositional logic where all formulas are called sentences --- see \fullref{def:propositional_syntax/formula}).

    We will not restrict our attention only to closed formulas, and we will even rely on implicit quantification as mentioned in \fullref{rem:mathematical_logic_conventions/quantification}. That being said, certain important theorems like \fullref{thm:semantic_deduction_theorem} and \fullref{thm:syntactic_deduction_theorem} require some of the formulas to be closed, so we will often follow this restriction.

    \thmitem{def:first_order_syntax/formula_bound_variables} Dually, the \term{bound variables} of a formula are defined as
    \begin{equation}\label{eq:def:first_order_syntax/formula_bound_variables}
      \boldop{Bound}(\varphi) \coloneqq \begin{cases}
        \varnothing,                                        &\varphi \T{is atomic,} \\
        \boldop{Bound}(\psi),                               &\varphi = \neg \psi, \\
        \boldop{Bound}(\psi_1) \cup \boldop{Bound}(\psi_2), &\varphi = \psi_1 \bincirc \psi_2, \bincirc \in \Sigma, \\
        \boldop{Bound}(\psi) \cup \set{ \xi },              &\varphi = \quantifier{Q}{\xi} \psi, Q \in \set{ \forall, \exists }.
      \end{cases}
    \end{equation}

    \thmitem{def:first_order_syntax/formula_variables} Finally, the set of all variables of a formula \( \varphi \) is
    \begin{equation}\label{eq:def:first_order_syntax/formula_variables}
      \boldop{Var}(\varphi) \coloneqq \boldop{Free}(\varphi) \cup \boldop{Bound}(\varphi).
    \end{equation}
  \end{thmenum}
\end{definition}

\begin{proposition}\label{thm:first_order_terms_and_formulas_are_unambiguous}
  The grammars of \hyperref[def:first_order_syntax/term]{first-order terms} and of \hyperref[def:first_order_syntax/formula]{first-order formulas} are \hyperref[def:grammar_derivation/unambiguous]{unambiguous}.
\end{proposition}
\begin{proof}
  The proof is more complicated, but similar in spirit to \fullref{thm:propositional_formulas_are_unambiguous}.
\end{proof}

\begin{remark}\label{rem:first_order_formula_conventions}
  In order to simplify exposition, we use the following conventions
  \begin{thmenum}
    \thmitem{rem:first_order_formula_conventions/infix} Binary functional symbols are often written using \term{infix notation}, i.e.
    \begin{equation*}
      \zeta \doteq \xi + \eta
    \end{equation*}
    rather than the \term{prefix notation}
    \begin{equation*}
      \zeta \doteq +(\xi, \eta).
    \end{equation*}

    This also applies to predicates --- we write \( \xi \sim \eta \) rather than \( \sim(\xi, \eta) \).

    \thmitem{rem:first_order_formula_conventions/negation} Negation of an infix binary predicate symbol \( \sim \) can be written more simply as
    \begin{equation*}
      \xi \not\sim \eta
    \end{equation*}
    rather than
    \begin{equation*}
      \neg(\xi \sim \eta).
    \end{equation*}

    \thmitem{rem:first_order_formula_conventions/relativization}\mcite{LeanFOL} If \( \sim \) is a binary predicate, to further shorten notation, we write
    \begin{equation*}
      \qforall {\xi \sim \eta} \varphi
    \end{equation*}
    as a shorthand for
    \begin{equation*}
      \qforall \xi (\xi \sim \eta \rightarrow \varphi)
    \end{equation*}
    and
    \begin{equation*}
      \qexists {\xi \sim \eta} \varphi
    \end{equation*}
    as a shorthand for
    \begin{equation*}
      \qexists \xi (\xi \sim \eta \wedge \varphi).
    \end{equation*}

    This is called \term{relativization} of the quantifier and is immensely useful when working with heterogeneous objects or even in \hyperref[sec:set_theory]{set theory}.

    \thmitem{rem:first_order_formula_conventions/exists_unique} We sometimes want to specify not only existence, but also uniqueness. This is the case in \eqref{eq:def:zfc/choice}, for example. It is conventional to write
    \begin{equation*}
      \qExists \xi \varphi
    \end{equation*}
    as a shorthand for
    \begin{equation*}
      \qexists \xi \parens[\Big]{ \varphi \wedge \parens[\Big]{ \qforall \eta \varphi[\xi \mapsto \eta] \rightarrow (\xi \doteq \eta) } }.
    \end{equation*}

    \thmitem{rem:first_order_formula_conventions/necessary_signature} We only add to the language itself the functional and predicate symbols that are necessary for our desired axioms --- see \fullref{def:first_order_theory}. We can define additional functions and predicates in terms of these, but we avoid using them as much as possible when writing formulas in the object language. For example, we avoid adding the functional symbols \hyperref[thm:well_ordered_order_type_existence]{\( \ord(A) \)} and \hyperref[def:cardinal]{\( \card(A) \)} or even \hyperref[def:basic_set_operations/union]{\( \cup \)} and \hyperref[def:basic_set_operations/intersection]{\( \cap \)} to \hyperref[def:zfc]{\logic{ZFC}}.

    If needed, we can consider these new functions and predicates to be abbreviations for more verbose terms and formulas as described in \fullref{rem:predicate_formula}.
  \end{thmenum}

  As for \fullref{rem:propositional_formula_parentheses}, both of these conventions exist only in the metalanguage and the formulas themselves are assumed to have the former form within the object language.
\end{remark}

\begin{definition}\label{def:first_order_structure}\mcite[def. 16.1]{OpenLogicFull}
  Fix a first-order logic language \( \mscrL \). A \term{structure} for \( \mscrL \) is a pair \( \mscrX = (X, I) \), where
  \begin{thmenum}
    \thmitem{def:first_order_structure/set} \( X \) is a nonempty set called the \term{domain} or \term{universe} of the structure \( \mscrX \). See \fullref{rem:empty_models}.

    \thmitem{def:first_order_structure/interpretation} The \term{interpretation} \( I \) of the structure \( \mscrX \) is a \hyperref[def:function]{function} that is defined on the signature of \( \mscrL \) and satisfies the following conditions:
    \begin{thmenum}
      \thmitem{def:first_order_structure/interpretation/function} For every \( n \)-ary function symbol \( f \), its interpretation is a \hyperref[def:function]{function} with signature \( I(f): X^n \to X \).

      \thmitem{def:first_order_structure/interpretation/predicate} For every \( n \)-ary predicate \( p \), its interpretation is a an n-ary \hyperref[def:boolean_function]{Boolean-valued function} with signature \( I(p): X^n \to \set{ T, F } \). A tuple \( (x_1, \ldots, x_n) \) satisfies \( p \) if \( p(x_1, \ldots, x_n) = T \).

      It is conventional to define the interpretation of a predicate to be a \hyperref[def:relation]{relation} \( I(p) \subseteq X^n \) (see e.g. \mcite[def. 16.1]{OpenLogicFull}), however it is more convenient for us to work with Boolean-valued functions. The two approaches are equivalent as explained in \fullref{rem:boolean_valued_functions_and_predicates}.
    \end{thmenum}
  \end{thmenum}

  Unlike in the rest of this document, when dealing with first-order structures, it is important to distinguish between the structure \( \mscrX \) as a pair and its domain \( X \) as a set. See \fullref{rem:first_order_model_notation}.
\end{definition}

\begin{remark}\label{rem:empty_models}
   If we allow for the domain of a structure to be empty, we would have to reformulate a lot of important theorems (e.g. see the proof of \fullref{thm:renaming_assignment_compatibility/formulas}), which would complicate compatibility between semantics and \hyperref[def:deductive_system]{deductive systems}.

   See \fullref{thm:substructures_form_complete_lattice/bottom} for a context where empty sets are justified as domains of first-order structures.
\end{remark}

\begin{definition}\label{def:first_order_valuation}
  Fix a structure \( \mscrX = (X, I) \) for a first-order logic language \( \mscrL \).

  \begin{thmenum}
    \thmitem{def:first_order_valuation/variable_assignment}\mcite[def. 16.7]{OpenLogicFull} A \term{variable assignment} for the variables of \( \mscrL \) is any function \( v: \boldop{Var} \to X \) (loosely similar to \hyperref[def:propositional_valuation/interpretation]{propositional interpretations}).

    \thmitem{def:first_order_valuation/modified_assignment} For every variable \( \xi \) and every domain element \( x \in X \) we also define the \term{modified assignment} at \( \xi \) with \( x \):
    \begin{equation*}
      v_{\xi \mapsto x}(\zeta) \coloneqq \begin{cases}
        x,        &\zeta = \xi, \\
        v(\zeta), &\zeta \neq \xi.
      \end{cases}
    \end{equation*}

    We can also modify the value at \( \xi \) with another variable, e.g.
    \begin{equation*}
      v_{\xi \mapsto \eta}(\zeta) \coloneqq \begin{cases}
        v(\eta),  &\zeta = \xi, \\
        v(\zeta), &\zeta \neq \xi.
      \end{cases}
    \end{equation*}

    Inductively,
    \begin{equation*}
      v_{\xi_1 \mapsto x_1, \ldots, \xi_n \mapsto x_n}(\eta) \coloneqq ((\ldots(v_{\xi_1 \mapsto x_1})\ldots)_{\xi_n \mapsto x_n})(\eta).
    \end{equation*}

    Except for semantics of quantification, these are also used in other places like \fullref{thm:renaming_assignment_compatibility} and \fullref{rem:first_order_formula_valuation_without_variable_assignment}.

    \thmitem{def:first_order_valuation/term_valuation}\mcite[def. 16.8]{OpenLogicFull} The \term{valuation} of a term \( \tau \) is a value in the domain \( X \) given by
    \begin{equation}\label{eq:def:first_order_valuation/term_valuation}
      \tau\Bracks{v} \coloneqq \begin{cases}
        v(\xi),                                           &\tau = \xi \in \boldop{Var}, \\
        I(f)(\tau_1\Bracks{v}, \ldots, \tau_n\Bracks{v}), &\tau = f(\tau_1, \ldots, \tau_n).
      \end{cases}
    \end{equation}

    \thmitem{def:first_order_valuation/formula_valuation}\mcite[def. 16.11]{OpenLogicFull} We extend the classical propositional valuations from \fullref{def:propositional_valuation}. The (classical) \term{valuation} of a formula \( \varphi \) is a \hyperref[def:boolean_value]{Boolean value} given by
    \begin{equation}\label{eq:def:first_order_valuation/formula_valuation}
      \varphi\Bracks{v} \coloneqq \begin{cases}
        T,                                                              &\varphi = \top, \\
        F,                                                              &\varphi = \bot, \\
        \tau_1\Bracks{v} = \tau_2\Bracks{v},                            &\varphi = \tau_1 \doteq \tau_2, \\
        I(p)(\tau_1\Bracks{v}, \ldots, \tau_n\Bracks{v}),               &\varphi = p(\tau_1, \ldots, \tau_n), \\
        \overline{\psi\Bracks{v}},                                      &\varphi = \neg \psi, \\
        \psi_1\Bracks{v} \bincirc \psi_2\Bracks{v},                     &\varphi = \psi_1 \bincirc \psi_2, \bincirc \in \Sigma, \\
        \bigvee\set{ \psi\Bracks{v_{\xi \mapsto x}} \given x \in X },   &\varphi = \qforall \xi \psi, \\
        \bigwedge\set{ \psi\Bracks{v_{\xi \mapsto x}} \given x \in X }, &\varphi = \qexists \xi \psi.
      \end{cases}
    \end{equation}

    The rules for evaluating constants, negations and connectives are a direct extension of the \hyperref[def:propositional_valuation/formula_valuation]{rules for propositional logic}.

    It is important that the domain is nonempty because \( \bigwedge\varnothing = T \), which directly contradicts our intent of defining \( \exists \) as a quantifier for existence.
  \end{thmenum}
\end{definition}

\begin{remark}\label{rem:first_order_formula_valuation_without_variable_assignment}
  Somewhat similar to \fullref{rem:propositional_formula_valuation_without_variable_assignment}, if we know that \( \boldop{Free}(\varphi) \subseteq \{ \xi_1, \ldots, \xi_n \} \), we know that the \hyperref[def:first_order_valuation/formula_valuation]{valuation} \( \varphi\Bracks{v} \) only depends on the values \( v(\xi_1), \ldots, v(\xi_n) \). This allows us to introduce the shorthand
  \begin{equation}\label{eq:rem:first_order_formula_valuation_without_variable_assignment/long_semantic}
    \varphi\Bracks{\xi_1 \mapsto x_1, \ldots, \xi_n \mapsto x_n}
  \end{equation}
  or even
  \begin{equation}\label{eq:rem:first_order_formula_valuation_without_variable_assignment/short_semantic}
    \varphi\Bracks{x_1, \ldots, x_n}
  \end{equation}
  for
  \begin{equation*}
    \varphi\Bracks{v_{\xi_1 \mapsto x_1, \ldots, \xi_n \mapsto x_n}}
  \end{equation*}
  because the variable assignment \( v \) plays no role here.

  When using either of these shorthand notations, we implicitly assume that \( \boldop{Free}(\varphi) \subseteq \set{ \xi_1, \ldots, \xi_n } \).

  When \( \varphi = p(\xi_1, \ldots, \xi_n) \) is a predicate formula, the shorter notation \eqref{eq:rem:first_order_formula_valuation_without_variable_assignment/short_semantic} translates to
  \begin{equation*}
    p\Bracks{x_1, \ldots, x_n} = I(p)(x_1, \ldots, x_n) \in \set{ T, F }
  \end{equation*}
  and analogously for function terms we have
  \begin{equation*}
    f\Bracks{x_1, \ldots, x_n} = I(f)(x_1, \ldots, x_n) \in X.
  \end{equation*}

  Of course, we avoid this notation for formulas like \( p(f(\xi)) \) because \( p\Bracks{x} \) would mean \( I(p)(I(f)(x)) \) rather than \( I(p)(x) \), which would be confusing.

  We apply this notation for terms and, in particular, functions.

  We also sometimes use the shortened notation
  \begin{equation}\label{eq:rem:first_order_formula_valuation_without_variable_assignment/short_syntactic}
    \varphi[\tau_1, \ldots, \tau_n]
  \end{equation}
  for \hyperref[def:first_order_substitution/term_in_formula]{substituting terms in formulas}.
\end{remark}

\begin{definition}\label{def:first_order_equation}
  A \term{first-order equation} is a formula of the form
  \begin{equation}\label{eq:def:first_order_equation}
    f(\xi_1, \ldots, \xi_n) \doteq g(\xi_1, \ldots, \xi_n),
  \end{equation}
  where both \( f(\xi_1, \ldots, \xi_n) \) and \( g(\xi_1, \ldots, \xi_n) \) are functional symbols with the same free variables.

  Given a structure \( \mscrX = (X, I) \), we call the elements of the set defined by this formula \term{solutions}. That is, we say that the tuple \( (x_1, \ldots, x_n) \) is a, solution to the equation \eqref{eq:def:first_order_equation} if
  \begin{equation*}
    f\Bracks{x_1, \ldots, x_n} = g\Bracks{x_1, \ldots, x_n}.
  \end{equation*}

  We can actually replace \( f \) and \( g \) with more general terms \( \tau \) and \( \sigma \), in which case the equation becomes \( (\tau \doteq \sigma) \) and is satisfied if
  \begin{equation*}
    \tau\Bracks{x_1, \ldots, x_n} = \sigma\Bracks{x_1, \ldots, x_n}.
  \end{equation*}
\end{definition}

\begin{example}\label{ex:equations}
  A remarkable portion of mathematics concerns the study of different types of equations (even though they are not generally restricted to \hyperref[def:first_order_equation]{equations in first-order logic}). The reason for this is that equations provide a simple way to specify rich semantic structure using simple syntactic objects.

  \begin{itemize}
    \item Matrix theory can be regarded as the study of linear equations. See \fullref{subsec:matrices}.
    \item Differential equations is aptly named since it studies equations in functional spaces concerning functions and their derivatives. See \fullref{sec:diffeq}.
    \item Roots of generalized derivatives are studied in optimization. See \fullref{subsec:nonsmooth_derivatives}.
    \item Diophantine equations are studied in number theory. See \fullref{subsec:integers}.
    \item Fixed points of functions are studied in different branches of mathematics. See \fullref{thm:banach_fixed_point_theorem} or \fullref{thm:knaster_tarski_theorem}.
    \item Affine varieties, which are sets of roots of polynomials, are studied in algebraic geometry. See \fullref{subsec:affine_varieties}.
  \end{itemize}
\end{example}

\begin{definition}\label{def:first_order_semantics}
  Fix a first-order logic language \( \mscrL \). We introduce notions analogous to \hyperref[def:propositional_semantics]{propositional semantics}:
  \begin{thmenum}
    \thmitem{def:first_order_semantics/satisfiability}\mcite[def. 16.11]{OpenLogicFull} Given a \hyperref[def:first_order_structure]{structure} \( \mscrX = (X, I) \), a \hyperref[def:first_order_valuation/variable_assignment]{variable assignment} \( v \) and a set \( \Gamma \) of \hyperref[def:first_order_syntax/formula]{first-order formulas}, we say that the variable assignment \( v \) \term{satisfies} \( \Gamma \) and we write \( \mscrX \vDash_v \Gamma \) if, for every formula \( \gamma \in \Gamma \) we have \( \gamma\Bracks{v} = T \).

    If every variable assignment in \( \mscrX \) satisfies \( \Gamma \), we say that \( \mscrX \) itself satisfies \( \Gamma \) or that \( \mscrX \) is a \term{model} of \( \Gamma \) and write \( \mscrX \vDash \Gamma \) (or simply \( \mscrX \vDash \Gamma \) if the interpretation is clear from the context).

    Analogously to \fullref{def:propositional_semantics/satisfiability}, we say that \( \Gamma \) is satisfiable if there exists a model for \( \Gamma \).

    \thmitem{def:first_order_semantics/entailment} We say that the set of formulas \( \Gamma \) \term{entails} the set of formulas \( \Delta \) and write \( \Gamma \vDash \Delta \) if every model of \( \Gamma \) is also a model of \( \Delta \).

    \thmitem{def:first_order_semantics/tautology} The formula \( \varphi \) is a \term{tautology} if every structure is a model of \( \varphi \).

    \thmitem{def:first_order_semantics/contradiction} Dually, \( \varphi \) is a \term{contradiction} is no structure is a model of \( \varphi \).

    \thmitem{def:first_order_semantics/equivalence} As in the simplest case with \hyperref[def:propositional_semantics/equivalence]{propositional semantical equivalence}, we say that \( \Gamma \) and \( \Delta \) are \term{semantically equivalent} and write \( \Gamma \gleichstark \Delta \) if both \( \Gamma \vDash \Delta \) and \( \Delta \vDash \Gamma \).

    \thmitem{def:first_order_semantics/equisatisfiability} Again as in the simplest case with \hyperref[def:propositional_semantics/equisatisfiability]{propositional equisatisfiability}, we say that the sets of formulas \( \Gamma \) and \( \Delta \) are \term{equisatisfiable} when it holds that \( \Gamma \) is satisfiable if and only if \( \Delta \) is satisfiable.

    \Fullref{thm:quantifier_satisfiability/existential} provides an important example of equisatisfiable formulas that are not equivalent.
  \end{thmenum}
\end{definition}

\begin{remark}\label{rem:propositional_logic_as_first_order_logic}
  It is now clear that the \hyperref[subsec:propositional_logic]{propositional logic language} can be regarded as a degenerate first-order logic language with no at most countably many predicate symbols, all of arity \( 0 \), and no functional symbols. Thus, first-order logic is indeed an extension of propositional logic.
\end{remark}

\begin{remark}\label{rem:first_order_model_notation}
  In first-order logic, \hyperref[def:first_order_semantics/satisfiability]{models} are defined as pairs \( \mscrX = (X, I) \). Each area of mathematics has its own conventions and models are usually specified as simply as possible without being unambiguous (and sometimes even beyond ambiguity).

  A popular convention is to use compatible letters like we did with \( X \) and \( \mscrX \) or \( G \) and \( \mscrG \), where the structure itself is named using calligraphic letters while the domain is named using the corresponding capital letter in normal font. This only works very simple cases where we can say \enquote{Let \( \mscrP = (P, \leq) \) be a \hyperref[def:partially_ordered_set]{partially ordered set}}. In the case of Banach lattices, for example, this becomes \( \mscrX = (X, \BbbK, +, \norm \anon, \vee, \wedge) \), which is quite cumbersome.

  Consider another example. In the sense of first-order structures, the language of the \hyperref[def:group/theory]{theory of groups} has a signature consisting of three functional symbols and no predicate symbols. Specifying a structure for this language is thus the same as specifying a quadruple \( \mscrG = (G, e, (\anon)^{-1}, \cdot) \). We usually identify the group \( \mscrG \) as a tuple with its domain \( G \) and even go as far as to say \enquote{Let \( (\mscrG, \cdot) \) be a group}. This is technically wrong, but it is both convenient and conventional. Furthermore, the rest of the definition of the group can easily be inferred. In case of ambiguity, the simplest disambiguation is to use lower indices with the name of the structure, e.g. \( +_\mscrG \) and \( +_\mscrH \) may be the addition operation in different abelian groups.
\end{remark}


\documentclass[a4paper]{article}

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

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

\usepackage{url}

\newcommand{\Hcal}{\mathcal{H}}
\newcommand{\real}{\mathbb{R}}

\title{Study of the constructive proof of weak compactness}
\author{Nazarov Ivan}

\date{\today}

\begin{document}
\maketitle

Let $(\Hcal, \langle\cdot,\cdot\rangle)$ be a Hilbert space. A sequence $(x_n)_{n\geq1}
\in \Hcal$ converges {\bf strongly} to $x\in\Hcal$ if $\|x_n - x\| \to 0$, and {\bf
weakly} if $\langle x_n, z \rangle \to \langle x, z\rangle$ for all $z\in \Hcal$.
Weak convergence is necessary for strong convergence, since for every $z\in \Hcal$
by the Cauchy-Schwartz inequality
\begin{equation*}
  \liminf_{n\to \infty}
    \lvert \langle x_n - x, z\rangle \rvert
    \leq \limsup_{n\to \infty}
      \lvert \langle x_n - x, z\rangle \rvert
    \leq \|z\| \limsup_{n\to \infty} \|x_n - x \|
    = 0
    \,.
\end{equation*}
Let $(x_n)_{n\geq1} \in \Hcal$ be a bounded sequence $M = \sup_{n\geq1} \|x_n\| < +\infty$.
Then there is $(n_k)_{k\geq1}\uparrow$ such that $x_{n_k}$ converges weakly to some
$h \in \Hcal$, i.e. $x_{n_k}\rightharpoonup h$.

\paragraph{Proof} % (fold)
\label{par:proof}

Let $\Hcal^0_0 = \{\sum_{i=1}^n \beta_i x_i \colon \beta_i \in \real,\,n\geq 0 \}$.
The set $\Hcal^0_0$ is a linear subspace of $\Hcal$. It is a pre-Hilbert space with
respect to $\langle\cdot, \cdot \rangle$, since it can be completed w.r.t. this inner
product to get $\Hcal_0$ and $\Hcal^0_0$ is dense in its completion.

\paragraph{Subsequence} % (fold)
\label{par:subsequence}

Let's construct a subsequence, which could potentially weakly converge to something.
Let $x^0_n = x_n$. Suppose for $k\geq 0$ we have $(x^k_n)_{n\geq 1} \subseteq (x_n)_{n\geq 1}$
and $(\alpha_i)_{i\leq k}$, such that $\langle x_i, x^k_n\rangle \to \alpha_i$ for
all $1\leq i\leq k$ as $n\to \infty$.

A sequence $\alpha^{k+1}_n = \langle x_{k+1}, x^k_n \rangle$ in $\real$ is bounded,
since $\lvert\alpha^{k+1}_n\rvert \leq \|x_{k+1}\| \|x^k_n\| \leq M^2$ and $x^k_n \in
\{x_n\colon n\geq 1\}$. Therefore, it contains a subsequence $(n_p)_{p\geq1}$ such that
$\alpha^{k+1}_{n_p}$ converges to some $\alpha^{k+1} \in \real$. If we let $x^{k+1}_p
= x^k_{n_p}$, then
\begin{itemize}
  \item $\langle x_j, x^{k+1}_p \rangle \to \alpha^j$ since $(x^{k+1}_p)_{p\geq 1}
  \subseteq (x^k_p)_{p\geq 1} \subseteq (x^j_p)_{p\geq 1}$ for $j\leq k$, and
  subsequences converge to the same limit as the parent sequence;
  \item $\langle x_{k+1}, x^{k+1}_p \rangle = \alpha^{k+1}_{n_p} \to \alpha^{k+1}$
  by construction.
\end{itemize}
For the diagonal sequence $(x^p_p)_{p\geq1}$ there are indices $(n_p)_{p\geq1} \uparrow$
such that $x^p_p = x_{n_p}$, and we have $(x^p_p)_{p\geq1} \subseteq (x^k_p)_{p\geq1}$
for all $k\geq 0$, whence we must have  $\langle x_n, x^p_p \rangle \to \alpha^n$
for all $n\geq 1$.

% paragraph subsequence (end)

\paragraph{A mapping} % (fold)
\label{par:a_mapping}

We shall show that a map $l(x) = \lim_{p\to \infty} \langle x, x_{n_p} \rangle$ is
well defined.

Right from the start we know that $l(x_n) = \alpha^n$ for all $n\geq 1$. Since the
inner product is bilinear and the limit is additive, for any $z = \sum_{i=1}^n \beta_i x_i$
we have
\begin{equation*}
  l(z)
    = \lim_{p\to \infty} \Bigl \langle \sum_{i=1}^n \beta_i x_i, x_{n_p} \Bigr \rangle
    = \sum_{i=1}^n \beta_i \lim_{p\to \infty} \langle x_i, x_{n_p} \rangle
    = \sum_{i=1}^n \beta_i l(x_i)
    = \sum_{i=1}^n \beta_i \alpha^i
    \in \real
    \,.
\end{equation*}
Therefore $l$ is defined on $\Hcal^0_0$.

Since $\Hcal^0_0$ is dense in $\Hcal_0$ w.r.t the induced norm, for any $z\in \Hcal_0$
there is $(z_k)_{k\geq1} \in \Hcal^0_0$ such that $\|z_k - z\|\to 0$. Thus for any
$\varepsilon > 0$ there is $n_\varepsilon \geq 1$ such that for all $n\geq n_\varepsilon$
we have $\|z_k - z\| \leq \tfrac\varepsilon{M}$. Hence for every $p\geq 1$ we get
\begin{align*}
  \bigl\lvert \langle z, x_{n_p} \rangle -  \langle z_k, x_{n_p} \rangle \bigr\rvert
    \leq \| z - z_k \| \|x_{n_p} \|
    \leq \tfrac\varepsilon{M} M
    \,.
\end{align*}
We conclude that $\sup_{p\geq 1} \lvert \langle z - z_k, x_{n_p} \rangle \rvert \to 0$
as $k\to \infty$, since for any $\varepsilon > 0$ there is $k_\varepsilon \geq 1$ such
that $\sup_{p\geq 1} \lvert \langle z - z_k, x_{n_p} \rangle \rvert \leq \varepsilon$ for
all $k\geq k_\varepsilon$.

Next observe that for any $k \geq j$ and all $p$ we have
\begin{align*}
  \lvert l(z_k) - l(z_j) \rvert
    &\leq \lvert l(z_j) - \langle z_j, x_{n_p} \rangle \rvert
      + \lvert l(z_k) - \langle z_k, x_{n_p} \rangle \rvert
    \\
    &+ \lvert \langle z_j - z, x_{n_p} \rangle \rvert
      + \lvert \langle z_k - z, x_{n_p} \rangle \rvert
      \,.
\end{align*}
From the convergence of the supremum above we can pick $k_\varepsilon \geq1$ such
that the last two terms are bounded each by $\tfrac\varepsilon2$ for all $j,k \geq
k_\varepsilon$. Taking limit suprema of both sides with respect to $p$ eliminates
the first two absolute terms of the right hand side, thereby implying that
$\lvert l(z_k) - l(z_j) \rvert \leq \varepsilon$ for all such $j$ and $k$. Hence
$(l(z_k))_{k\geq 1}$ is Cauchy in $\real$, and thus $l(z_k) \to \alpha$ for some
$\alpha \in \real$.

To show that $l(z) = \alpha$ we make the following observation: for all $k,p\geq 1$
\begin{equation*}
  \lvert \langle z, x_{n_p} \rangle - \alpha \rvert
    \leq \lvert l(z_k) - \alpha \rvert
    + \lvert \langle z_k, x_{n_p} \rangle - l(z_k) \rvert
    + \sup_{p\geq 1} \lvert \langle z - z_k, x_{n_p} \rangle \rvert
    \,.
\end{equation*}
For any $\varepsilon > 0$ there is $k_\varepsilon \geq 1$ such that the sum of the
first and last terms on the right hand side is not greater than $\varepsilon$ at
$k_\varepsilon$. Hence the $\limsup_{p\to \infty}$ of the expression in the left
is not greater than $\varepsilon$, since
\begin{equation*}
  \limsup_{p\to \infty} \lvert \langle z, x_{n_p} \rangle - \alpha \rvert
    \leq \varepsilon
    + \limsup_{p\to \infty} \lvert
        \langle z_{k_\varepsilon}, x_{n_p} \rangle - l(z_{k_\varepsilon})
      \rvert
    \,,
\end{equation*}
and $\langle z_k, x_{n_p} \rangle \to l(z_k)$ in $\real$ as $p\to \infty$ for any
$k \geq 1$. Since the last bound holds for arbitrarily small $\varepsilon > 0$,
$\langle z, x_{n_p} \rangle \to \alpha$, and therefore $l$ is defined on $\Hcal_0$.

What about $z\in \Hcal_0^\perp$, the orthogonal complement of $\Hcal_0$ in $\Hcal$?
For any $z\in \Hcal_0^\perp$ by orthogonality $\langle z, x_n \rangle = 0$ for all
$n\geq 1$, whence $\lim_{p\to\infty} \langle z, x_{n_p} \rangle = 0$. Therefore $l$
is defined on $\Hcal_0^\perp$.

% paragraph a_mapping (end)

\paragraph{Linearity and continuity} % (fold)
\label{par:linearity_and_continuity}

Thus $z\mapsto l(z) = \lim_{p\to\infty} \langle z, x_{n_p} \rangle$ is a well defined
$\Hcal \to \real$ map. Furthermore, it is linear, since the inner product is bilinear:
\begin{equation*}
  l(z + \alpha x)
    = \lim_{p\to\infty} \langle z + \alpha x, x_{n_p} \rangle
    = \lim_{p\to\infty} \langle z, x_{n_p} \rangle
    + \alpha \lim_{p\to\infty} \langle x, x_{n_p} \rangle
    = l(z) + \alpha l(x)
    \,.
\end{equation*}
Finally, $l$ is also a bounded map, since for all $z\in \Hcal$
\begin{equation*}
  \lvert l(z) \rvert
    = \lim_{p\to\infty} \lvert \langle z, x_{n_p} \rangle \rvert
    \leq \sup_{p\geq 1} \|z\| \| x_{n_p}\|
    \leq M \|z\|
    \,.
\end{equation*}
So the map $l$ is linear and bounded, hence continuous.

% paragraph linearity_and_continuity (end)

\paragraph{Weak limit} % (fold)
\label{par:weak_limit}

Riesz representer theorem therefore implies the existence of some $h\in \Hcal$ such
that $l(z) = \langle z, h\rangle$ for any $z\in \Hcal$. Therefore $x_{n_p} \rightharpoonup
h$ for this $(x_{n_p})_{p\geq 1} \subseteq (x_n)_{n\geq 1}$.

% paragraph weak_limit (end)

% paragraph proof (end)

\end{document}


\subsection{Orders of integration}

How many diffs do you need to do to get a stationary process?

If something is first order integrated it is \(I(1)\).


\chapter{Arithmetic}

You are probably somewhat familiar with doing various forms of arithmetic, and have probably even memorized the results of many operations. But the idea in computer science is to break down that process into a sequence of steps called an algorithm. It is important to understand that there are multiple possible algorithms to accomplish the same result. Remember that an algorithm is a set of directions to a destination, but the same destination can have several possible routes.

\section{Addition and Subtraction}

Let's start simple with the addition of two digits. Like 1+1, or 2+5. You probably don't even need to think about how to do these, you just know the answer. But I want you to think about how to explain what is going on as an algorithm. Something you might not even think about anymore is why do these symbols 1, 2, 3, ... mean anything? We simply memorize their meaning, and the symbol itself does not have any intrinsic value.\\

Let's start by adding 1 to any of the 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). We might use some conditional branching, and simply give the answer for each possibility. For the algorithm to be able to handle any digit, we need the idea of a variable. In this example it's called \(x\). And let's call the result \(y\). So We are basically saying how to computer \(y = x+1\), if \(x\) is any digit 0 through 9.\\

\begin{center}\imagegraphic[0.75]{add_1_flowchart.png}\end{center}

Basically, the algorithm defines what adding 1 means for each possible value of \(x\). It checks for what value \(x\) actually has, and gives the answer based on that. But if \(x\) is not 0 through 9, then the answer is undefined because the algorithm doesn't know what to do in that case.\\

\section{Multiplication}

\section{Floating Point Division}

\section{Integer Division}

\section{Modulus}


%-------------------------------------------------------------------------------
% LF
%-------------------------------------------------------------------------------

\section{LF: A Logical Framework}

The original LF logical framework was specified as follows:
$$
\begin{array}{llll}
\textbf{Kinds} & K & ::= & \Type \Spb \PiTyp{x}{A}{K} \\
\textbf{Families} & A & ::= & a \Spb \PiTyp{x}{A_2}{A} \Spb \Lam{x : A_2}{A} \Spb \Appl{A}{M} \\
\textbf{Terms} & M & ::= & c \Spb x \Spb \Lam{x : A}{M} \Spb \Appl{M}{M_2} \\
\textbf{Signatures} & \Sigma & ::= & \cdot \Spb \Sigma,\Of{c}{A}
\Spb \Sigma,\Of{a}{K}\\
\textbf{Contexts} & \Gamma & ::= & \cdot \Spb \Gamma,\Of{x}{A}\\
% \textbf{Simple Types} & \alpha & ::= & a \Spb \Arr{\alpha_1}{\alpha_2} \\
\end{array}
$$

While this definition is the simplest, the meta-theory of LF was
significantly simplfied by the introduction of Canonical LF, admitting
only the so-called \emph{canonical forms} into the language.

%-------------------------------------------------------------------------------
% Canonical LF
%-------------------------------------------------------------------------------

\section{Canonical LF}
We begin by describing Canonical LF, the language at the heart of our
work.  While the various representations will differ from the one presented here,
(e.g., for efficiency) this language should always be kept in mind.

The main difference between Canonical LF and earlier versions
is the lack of explicit $\beta$-redices in types and terms.
Also, a type annotation on $\lambda$-expressions is no longer required (or allowed).
See Harper and Licata\cite{Harper:2006:Mechanizing} for an extended
exposition.

$$
\begin{array}{llll}
\textbf{Kinds} & K & ::= & \Type \Spb \PiTyp{x}{A}{K} \\
\textbf{Canonical Type Families} & A & ::= & P \Spb \PiTyp{x}{A_2}{A} \\
\textbf{Atomic Type Families} & P & ::= & a \Spb \Appl{P}{M} \\
\textbf{Canonical Terms} & M & ::= & R \Spb \Lam{x}{M} \\
\textbf{Atomic Terms} & R & ::= &  x \Spb c \Spb \Appl{R}{M}\\
\textbf{Signatures} & \Sigma & ::= & \cdot \Spb \Sigma,\Of{c}{A}
\Spb \Sigma,\Of{a}{K}\\
\textbf{Contexts} & \Gamma & ::= & \cdot \Spb \Gamma,\Of{x}{A}\\
% \textbf{Simple Types} & \alpha & ::= & a \Spb \Arr{\alpha_1}{\alpha_2} \\
\end{array}
$$

%-------------------------------------------------------------------------------
% Spine Form LF
%-------------------------------------------------------------------------------

\subsection{Spine-Form Canonical LF}

There are a number of difficulties with the name-carrying
representation\footnote{i.e., variable names associated with binders}
of Canonical LF.  The first is that we must
implement capture-avoiding substitution and $\alpha$-conversion,
a notoriously delicate and error-prone process.
We can circumvent this difficulty
by using DeBruijn indices\cite{DeBruijn:1972:Terms}.

 A more significant
difficulty lies in the implementation of hereditary substitution.
\XXX{citation needed}
When applying a substitution, we often need to determine whether
the head of an expression is a constant or a variable in order
to know which rule to apply.  Thus, for a term of the form
$$f\ x_1\ x_2\ \ldots\ x_n = (\ldots((f\ x_1)\ x_2)\ \ldots\ x_n) $$
we need to take apart $n$ applications just to determine how
a substitution should be applied.  Later, when we implement
unification, that algorithm will need to compare the heads
of such terms for equality.  Thus, quick access to the head
of such a term is essential for a reasonably efficient implementation.
We thus define \emph{Spine-Form Canonical LF}.

$$
\begin{array}{llll}
\mathbf{Kinds} & K & ::= & \Type \Spb \SpPiTyp{A}{K} \\
\mathbf{Canonical\ Type\ Families} & A & ::= & P \Spb \SpPiTyp{A_1}{A_2} \\
\mathbf{Atomic\ Type\ Families} & P & ::= & a\cdot S \\
\mathbf{Canonical\ Terms} & M & ::= & R \Spb \SpLam{M} \\
\mathbf{Atomic\ Terms} & R & ::= & H\cdot S \\
\mathbf{Heads} & H & ::= & c \Spb i\\
\mathbf{Spines} & S & ::= & \Nil \Spb M;S\\
\end{array}
$$

In the following judgments will have the same
form for different classes.  For instance,
the rules for $\Pi$-types and $\Pi$-kinds will
oftentimes be identical in structure.  To avoid the
repetition of rules, we introduce a convenient
syntax.

$$
\begin{array}{llll}
\mathbf{Levels} & L & ::= & \Type \Spb \Kind \\
\mathbf{Expressions} & U & ::= & L \Spb \SpPiTyp{U_1}{U_2} \Spb \lambda U \Spb H\cdot S \\
\mathbf{Heads} & H & ::= & c \Spb i\\
\mathbf{Spines} & S & ::= & \Nil \Spb U;S\\
\end{array}
$$

Constants $c$ are either type ($a$) or term ($c$) constants.
The rules that follow will refer to this basic syntax.  While this
is somewhat less precise than the more explicit separation of
levels in the syntax above (indeed, we can easily write gramatically
correct nonsense in this language, such as $\SpLam{(\SpPiTyp{U1}{U2})}$)
we are willing to allow such terms to lessen the number of rules.
Terms that are not even gramatically correct (much less type-correct)
in the original language, will be excluded by type-checking (rather than expression
formation, as in the previous version).

We will freely mix the more concrete classes such as $K,A$ and $P$
above when the rules restrict the expressions to such cases.
We see no potential for confusion however, and again notational
convenience is our guide.


\hypertarget{polygon-triangulation}{%
\section{Polygon Triangulation}\label{polygon-triangulation}}

\hypertarget{introduction}{%
\subsection{Introduction}\label{introduction}}

The decomposition of a polygon into triangles whose union again results
in the original polygon is called polygon triangulation. In the method,
no new Vertices are added. Only the diagonals of the polygon results in
the triangulation. There need not be a unique triangulation for a given
polygon.

There are various methods which can be used to perform polygon
triangulation. In our implementation, we
\protect\hyperlink{algorithm-approach}{discuss} two types of
triangulation which are: 1) Ear Clipping Triangulation. 2) Plane sweep
monotone division combined with Monotone triangulation.

\hypertarget{how-to-run}{%
\subsection{How to Run}\label{how-to-run}}

The src folder contains the source code for the convex hull program.
\texttt{g++} from the GNU compiler suite is required to compile the
program to a executable.

Steps to Compile:

\begin{enumerate}
\def\labelenumi{\arabic{enumi})}
\tightlist
\item
  \texttt{cd} into the src directory
\item
  Run \texttt{g++\ main.cpp} which generates an executable called
  \texttt{a.out} in the same directory
\item
  Run the executable using \texttt{./a.out} (on linux)

  \begin{enumerate}
  \def\labelenumii{\arabic{enumii})}
  \tightlist
  \item
    The executable takes a dataset from command line argument. For
    example, to use an existing dataset, run
    \texttt{./a.out\ ../datasets/complex.txt}
  \item
    If no command-line argument is given, it takes input from the shell
    directly (stdin)
  \end{enumerate}
\end{enumerate}

\hypertarget{input}{%
\subsection{Input}\label{input}}

The required file format for the algorithm to work correctly is:

\begin{itemize}
\tightlist
\item
  The input \textbf{must} be a clockwise ordering of Poins present on
  the polygon.
\item
  First line must contain the no of Points to be taken as input by the
  program.
\item
  Each of next line must contain 2 integers, space seperated denoting
  the (x, y) coordinates of each point.
\item
  Each coordinate must be of integer type in the range -10\^{}8 to
  10\^{}8.
\item
  No of coordinates must be less than 1 Billion.
\end{itemize}

\hypertarget{output}{%
\subsection{Output}\label{output}}

Each line of output contains three coordinates of points present on each
triangulation.\\
The last two lines of output show the time taken to take input in
microseconds and the time taken by the algorithm to compute
Triangulation (also in microseconds).

This is the output of one of the datasets
\href{./datasets/long.txt}{long.txt}

\includegraphics[width=8cm,height=8cm]{img/TRIsnake.png}\\

\hypertarget{documentation-and-report}{%
\subsection{Documentation and Report}\label{documentation-and-report}}

Documentation of this algorithm, functions and classes can be found in
the \texttt{docs} folder in the current directory. Open the
\href{../Triangulation/docs/html/index.html}{index.html} file from the
docs directory with your preferred browser to go through the
documentation

\hypertarget{performance-analysis}{%
\subsection{Performance Analysis}\label{performance-analysis}}

Analysis is performed with a system running (does not include printing
time):

\begin{itemize}
\tightlist
\item
  OS: Arch Linux (64Bit) running Linux Kernel version 5.7.2
\item
  Processor: Intel Core i7 7700HQ
\item
  RAM: 8GB
\item
  Compiler: GNU G++ (GCC) 10.1.0
\end{itemize}

\textbf{The following observations are recorded:}

Time taken to triangulate basic shapes:

\begin{longtable}[]{@{}lcccc@{}}
\toprule
\begin{minipage}[b]{0.07\columnwidth}\raggedright
Filename\strut
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\centering
Input Vertices\strut
\end{minipage} & \begin{minipage}[b]{0.15\columnwidth}\centering
Computed Triangles\strut
\end{minipage} & \begin{minipage}[b]{0.25\columnwidth}\centering
Line Sweep Triangulation Runtime\strut
\end{minipage} & \begin{minipage}[b]{0.27\columnwidth}\centering
Ear Clipping Triangulation Runtime\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.07\columnwidth}\raggedright
triangle.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
3\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
1\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
30 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
16 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
downConvex.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
6\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
4\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
43 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
23 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
test.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
6\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
4\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
35 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
24 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
square.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
4\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
2\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
36 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
18 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
hexagon.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
6\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
4\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
38 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
16 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
monotone.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
15\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
13\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
109 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
75 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
uniMonotone.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
8\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
6\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
115 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
42 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
complex.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
17\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
15\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
188 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
17 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
strange.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
16\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
14\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
148 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
122 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
star.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
10\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
8\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
159 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
101 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
spiral.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
32\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
30\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
278 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
214 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
tank.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
55\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
53\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
429 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
452 microsec\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.07\columnwidth}\raggedright
long.txt\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering
72\strut
\end{minipage} & \begin{minipage}[t]{0.15\columnwidth}\centering
70\strut
\end{minipage} & \begin{minipage}[t]{0.25\columnwidth}\centering
593 microsec\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering
1668 microsec\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\hypertarget{algorithm-approach}{%
\subsection{Algorithm Approach}\label{algorithm-approach}}

\hypertarget{ear-clipping}{%
\subsubsection{Ear Clipping}\label{ear-clipping}}

According to the two ears theorem, any simple polygon with minimum of 4
vertices without holes has atleast two ``ears''. An Ear is defined at
the vertex where internal angle is less than PI and the line joining the
adjacent vertices is a diagonal of the polygon.

The algorithm works by removing away these ``ears'' (which are
triangles) until the complete polygon is triangulated. This algorithm is
easy to implement, but slower than some other algorithms, and it only
works on polygons without holes. The runtime complexity of this
algorithm is O(n\textsuperscript{2})

\hypertarget{plane-sweep-monotone-triangulation}{%
\subsubsection{Plane Sweep Monotone
Triangulation}\label{plane-sweep-monotone-triangulation}}

A monotone polygon can be easily triangulated in O(n) complexity. A
simple polygon is said to be monotone w.r.t a line L only if any line
perpendicular to L passes through the polygon at most twice. Any
monotone polygon can be divided into two monotone chains. A polygon that
is monotone w.r.t the x-axis is called x-monotone. Given x-monotone
polygon, the greedy algorithm begins by walking on one chain of the
polygon from top to bottom while adding diagonals (forming triangles)
whenever it is possible.

If a polygon is not monotone, it can be partitioned into monotone sub
polygons in O(n log n) time using line/plane sweep method. Generally,
this algorithm can triangulate a planar subdivision with in O(n log n)
time using O(n) space.

\hypertarget{results}{%
\subsection{Results}\label{results}}

\includegraphics[width=8cm,height=8cm]{img/TRItank.png}\\

In the above image, the red boundary represents the input given to the
algorithm and the random colored triangle represent the output given by
the program.

It can be observed from the examples that increase in number of vertices
affects the runtime of ear clipping triangulation more than the plane
sweep monotone triangulation. From the results of the above datasets, we
can see that for just an increase of vertices from 50 to 70 causes the
ear clipping algorithm to triple its triangulation time.

\hypertarget{conclusion}{%
\subsection{Conclusion}\label{conclusion}}

From the above comparisions, we can see that ear clipping algorithm,
even after being a simple algorithm, due it is asymptotic complexity
being O(n\textsuperscript{2}), it surely is not recomended for
applications where number of vertices go beyond 70 (which almost always
happens).

If we know that the input only has a monotone polygon, it is even more
easier and faster to triangulate it in just O(n). The main plane sweep
algorithm tries to use this to its advantage by dividing the polygon
first into monotones.


\section{Question 1}
System:
$$
G_{1_{(s)}} = \dfrac{1}{(s+1)(2s+1)}\exp(-s) = \dfrac{1}{2s^2+3s+1}
$$
We use Optimal PID to design controller with ITAE, ISE and IAE cont function.
\newpage
 \begin{itemize}
     \item ITAE
     $$
     K_p = 1.6922, \quad K_i = 0.5472, \quad K_d = 1.3675
     $$
     \begin{figure}[H]
        \caption{Step responde with PID controller and ITAE cost function}
        \centering
        \includegraphics[width=11cm]{../Figure/Q1/ITAE.png}
    \end{figure}
    \item ISE
    $$
    K_p =1.8957, \quad K_i = 0.8007, \quad  K_d =2.5416
    $$
    \begin{figure}[H]
       \caption{Step responde with PID controller and ISE cost function}
       \centering
       \includegraphics[width=11cm]{../Figure/Q1/ISE.png}
   \end{figure}
   \item IAE
   $$
   K_p = 1.8356, \quad K_i = 0.6085, \quad K_d = 1.7386
   $$
   \begin{figure}[H]
      \caption{Step responde with PID controller and IAE cost function}
      \centering
      \includegraphics[width=11cm]{../Figure/Q1/IAE.png}
  \end{figure}
 \end{itemize}
 PID designed with ITAE cost function work better system is fast with lower overshoot.