\documentclass[../main.tex]{subfiles}
\begin{document}
 \subsection{Base Characterisation of a Matroid}
As quoted above, the bases of a matroid are the maximally independent sets of $\mathcal{I}.$  These are most naturally visualised as being akin to a basis in a matrix. Where the basis of a matrix is a spanning set and every vector is a linearly combination of the basis. Bases are also spanning sets in  matroid. And as such have very useful properties that we will use extensively in later sections. Most notably, the collection of subsets $\mathcal{I}$ can be generated using the bases (bases are not in general unique) due to the hereditary property $(I2).$ \\
The below theorem gives us a useful property that can be applied to the bases of a matroid, namely that the bases all have the same cardinality.
 \begin{thm}
 Show that if $\mathcal{I}$ is a non-empty hereditary set of subsets of a finite set E, then $(E,\mathcal{I})$ is a matroid if and only if, for all $X \subset E$, all maximal members of $\{I : I \in \mathcal{I} $ and $ I \subset X\}$ have the same number of elements.
 \end{thm}
\begin{proof}
 Let $B_1 , B_2$ be maximal elements of $\{I : I \in \mathcal{I} $and $ I \subset X\}$ \\
\noindent Assume $|B_1| < |B_2|, B_1, B_2 \in \mathcal{I}$ and since we have a matroid
\\
there exists $e \in (B_2 \setminus B_1)$ such that $B_1 \cup \{e\} \in \mathcal{I}.$
\\
This contradicts the maximality of $B_1$.\\
 \noindent $\implies$ All maximal elements of the set $\{I : I \in \mathcal{I} $ and $ I \subset X\}$ in our matroid M have the same cardinality.

\end{proof}
 \end{document}


\documentclass[a4paper]{article}

\def\ntitle{Quadratic fields}
\def\ndate{}

\input{header}

\renewcommand*{\O}{\mathcal{O}}
\DeclareMathOperator{\n}{N}
\DeclareMathOperator{\disc}{disc}
\DeclareMathOperator{\Cl}{Cl}%ideal class group
\newcommand*{\red}[1]{\overline{#1}}%reduction mod

\begin{document}

\maketitle

Let \(d \in \Z\) be square-free and \(d \neq 0, 1\). Then
\[
  L = \Q(\sqrt d) = \Q[x]/(x^2 - d)
\]
is a degree \(2\) extension over \(\Q\). It is called a \emph{quadratic field}. If \(d > 0\) then there are two real embeddings, in which case we call \(L\) a real quadratic field. Otherwise \(L\) is an imaginary quadratic field. Note that in using this notation, we implicitly assume that there is a complex embedding \(\sigma: L \to \C\).

\paragraph{Ring of integers}

A particularly nice characterisation of algebraic intgers in a quadratic field is \(\alpha \in \O_L\) if and only if \(\n_{L/\Q}(\alpha), \tr_{L/\Q}(\alpha) \in \Z\).

Suppose \(\alpha = \frac{u}{2} + \frac{v}{2}\sqrt d \in \O_L\) where \(u, v \in \Q\). Then multiplication by \(\alpha\) has with respect to the basis \(\{1, \sqrt d\}\) matrix representation
\[
  \frac{1}{2}
  \begin{pmatrix}
    u & vd \\
    v & u
  \end{pmatrix}
\]
so
\begin{align*}
  \n_{L/\Q}(\alpha) &= \frac{1}{4}(u^2 - v^2d) \in \Z \\
  \tr_{L/\Q}(\alpha) &= u \in \Z
\end{align*}

so \(v^2d \in \Z\). Suppose \(v = \frac{r}{s}\) is an expression in coprime integers. Then \(d^2r^2 \in s^2\Z\) so \(s^2 \divides d^2r^2\). If \(p\) is a prime dividing \(s\) then \(p^2 \divides d^2\). As \(d\) is square-free, \(p \divides d\). Absurd. Thus \(v \in \Z\) and
\[
  \Z[\sqrt d] \subseteq \O_L \subseteq \frac{1}{2}\Z[\sqrt d].
\]

\begin{itemize}
\item If \(d = 2, 3 \pmod 4\) then \(u^2 = 0, 1 \pmod 4, v^2 = 0, 1 \pmod 4\). As \(u^2 = v^2d \pmod 4\), \(u, v \in 2\Z\) so \(\alpha \in \Z[\sqrt d]\). Thus \(\O_L = \Z[\sqrt d]\).
\item If \(d = 1 \pmod 4\) then \(u^2 = v^2 \pmod 4\) so \(u = v \pmod 2\). Thus
  \[
    \O_L \subseteq \left\{ \frac{u}{2} + \frac{v}{2}\sqrt d: u = v \pmod 2 \right\} = \Z \oplus \Z \frac{1 + \sqrt d}{2}.
  \]
  Now check that \(\frac{1 + \sqrt d}{2} \in \O_L\) so we conclude that \(\O_L = \Z[\frac{1 + \sqrt d}{2}]\).
\end{itemize}

\paragraph{Discriminant}

Recall that
\[
  D_L
  = \det (\sigma_i(\alpha_j))^2
  = \det (\tr_{L/\Q}(\alpha_i\alpha_j))
  = (-1)^{\binom{n}{2}}\n_{L/\Q}(f'(\alpha))
\]
where \(\{\alpha_i\}\) is an integral basis, \(\{\sigma_i\}\) are the complex embeddings, \(\alpha\) is a generator of \(\O_L\) as a \(\Z\)-algebra and \(f\) is the minimal polynomial whereof.

\begin{itemize}
\item If \(d = 2, 3 \pmod 4\) then \(\alpha = \sqrt d, f(x) = x^2 - d\). Thus
  \[
    D_L = -\n_{L/\Q}(2\sqrt d) = 4d.
  \]
  Alternatively, since \(\tr_{L/\Q}(1) = 2, \tr_{L/\Q}(\sqrt d) = 0\), we can easily compute the matrix \(\tr_{L/\Q}(\alpha_i\alpha_j)\).
\item If \(d = 1 \pmod 4\) then \(\alpha = \frac{1 + \sqrt d}{2}, f(x) = x^2 + x + \frac{1 - d}{4}\). Thus
  \[
    D_L = -\n_{L/\Q}(\sqrt d) = d.
  \]
\end{itemize}

\paragraph{Factorisation of ideals}

Recall that Dedekind's criterion says that subject to certain divisibility condition, given \(L = \Q(\alpha)\) and \(\alpha \in \O_L\) with minimal polynomial \(f(x)\) and \(p\) prime, if
\[
  \red f(t) = \prod_{i = 1}^r \red g_i(t)^{e_i} \in \F_p[x]
\]
is a factorisation into irreducibles then
\[
  (p) = \prod_{i = 1}^r \mathfrak{p}_i^{e_i}
\]
is a factorisation into prime ideals.

\begin{itemize}
\item If \(p = 2\),
  \begin{itemize}
  \item if \(d = 2, 3 \pmod 4\) then let \(\alpha = \sqrt d\) so
    \[
      \red f(x) = x^2 - d = (x - d)^2 \in \F_2[x]
    \]
    so \((2) = \mathfrak{p}^2\), i.e.\ ramifies.
  \item if \(d = 1 \pmod 8\) then let \(\alpha = \frac{1 + \sqrt d}{2}\) so
    \[
      \red f(x) = x^2 + x + \frac{1 - d}{4} = x^2 + x = x(x + 1) \in \F_2[x]
    \]
    so \((2) = \mathfrak{p}\mathfrak{q}\), i.e.\ splits completely.
  \item if \(d = 5 \pmod 8\) then \(\red f(x) \in \F_2[x]\) is irreducible so \(2\) is inert.
  \end{itemize}
\item If \(p\) is odd, let \(\alpha = \sqrt d\) and \(f(x) = x^2 - d\) so
  \begin{itemize}
  \item if \(\legendre{d}{p} = 0\) then \((p) = \mathfrak{p}^2\), i.e.\ ramifies.
  \item if \(\legendre{d}{p} = 1\) then \((p) = \mathfrak{p}\mathfrak{q}\), i.e.\ splits completely.
  \item if \(\legendre{d}{p} = -1\) then \(p\) is inert.
  \end{itemize}
\end{itemize}

\paragraph{Lattice}

Recall that the covolume of a lattice formed by an ideal of the ring of integers is the volume of the parallelepiped spanned by its \(\Z\)-basis.

Given an \emph{imaginary} quadratic field \(L\), claim that
\[
  A(I) = \frac{1}{2}\sqrt{|\disc(I)|} = \frac{\n(I)}{2}\sqrt{|D_L|}
\]
for \(I \subseteq \O_L\).

\begin{proof}
  Let \(\alpha_1 = x_1 + iy_1, \alpha_2 = x_2 + iy_2\) be an integral basis for \(I\). Then
  \[
    A(I) = \left| \det
      \begin{pmatrix}
        x_1 & x_2 \\
        y_1 & y_2
      \end{pmatrix}
    \right|.
  \]
  Meanwhile
  \[
    \disc(I)
    = \det
    \begin{pmatrix}
      x_1 + iy_1 & x_2 + iy_2 \\
      x_1 - iy_1 & x_2 - iy_2
    \end{pmatrix}
    ^2
    = (2i)^2 \det
    \begin{pmatrix}
      x_1 & x_2 \\
      y_1 & y_2
    \end{pmatrix}
    ^2
    .
  \]
\end{proof}

By Minkowski's theorem and multiplicativity of norm, we can deduce that for any number field \(L\), the ideal class group \(\Cl(\O_L)\) is finite and can be generated by the class of prime ideals \(\mathfrak{p}\) with \(\n(\mathfrak{p}) \leq c_L\) where \(c_L = \frac{2}{\pi}\sqrt{|D_L|}\).

\begin{eg}\leavevmode
  \begin{enumerate}
  \item \(d = -7\). As \(d = 1 \pmod 4\), \(D_L = -7\). Thus
    \[
      c_L = \frac{2}{\pi} \sqrt 7 < \frac{2}{3} \sqrt 7 < 2
    \]
    so \(\Cl(\O_L)\) is generated by ideals of norm \(< 2\). There are none except \(\O_L\). Thus \(\Cl(\O_L)\) is trivial. Hence \(\O_L = \Z[\frac{1 + \sqrt{-7}}{2}]\) is a UFD.
  \item \(d = -5\). \(D_L = -20\) so
    \[
      c_L = \frac{2}{\pi}\sqrt{20} = \frac{4}{\pi}\sqrt 5 < \frac{4}{3} \sqrt 5 < 3
    \]
    so \(\Cl(\O_L)\) is generated by prime ideals \(\mathfrak p \subseteq \O_L\) of norm \(\n(\mathfrak p) = 2\). We know by Dedekind's criterion that \(2\O_L = \mathfrak p^2\). Thus \(\Cl(\O_L)\) is generated by \([\mathfrak p]\) and \([\mathfrak p]^2 = [2\O_L] = [\O_L]\) is the trivial class. Hence there are two possibilities:
    \begin{enumerate}
    \item if \(\mathfrak p\) is principal then \(\Cl(\O_L)\) is trivial.
    \item if \(\mathfrak p\) is not principal then \(\Cl(\O_L) \cong \Z/2\Z\).
    \end{enumerate}
    But we already knew that \(\O_L\) is not a UFD so \(\Cl(\O_L)\) is not trivial so must have
    \[
      \Cl(\O_L) \cong \Z/2\Z.
    \]
  \end{enumerate}
\end{eg}

For real quadratic fields \(L = \Q(\sqrt d)\), it is instructive as an exercise to derive the baby Minkowski constant, which should be \(c_L = \frac{1}{2}\sqrt{|D_L|}\).

\begin{eg}
  \(d = 10\). Then \(c_L = \frac{1}{2} \sqrt{4 \cdot 10} < 4\). By Dedekind's criterion,
  \begin{align*}
    (2) &= \mathfrak p_2^2 \\
    (3) &= \mathfrak p_3 \mathfrak p_3'
  \end{align*}
  What we can do at this stage is to compute the norm of some elements. For example \(\n(2 + \sqrt{10}) = 6\) so \((2 + \sqrt{10}) = \mathfrak p_2 \mathfrak p_3'\) or \(\mathfrak p_2 \mathfrak p_3'\). In either case, \([\mathfrak p_2]\) generates \(\Cl(\O_L)\). If \(\mathfrak p_2\) is principal then there exists \(a, b \in \Z\) such that
  \[
    a^2 - 10b^2 = \pm 2.
  \]
  Reduce modulo \(5\), \(\pm 2\) is not a quadratic residue so impossible. Thus \(\Cl(\O_L) \cong \Z/2\Z\).
\end{eg}

\begin{ex}
  Find the class group of ring of integers of \(\Q(\sqrt{-17})\).
\end{ex}

\paragraph{Dirichlet's unit theorem}

Dirichlet's unit theorem states that there is an isomorphism
\[
  \O_L^\times \cong \mu_L \times \Z^{r + s - 1}
\]
where \(\mu_L\) is the group of roots of unity in \(\O_L^\times\).

Thus \(\O_L^\times\) is finite if and only if
\begin{enumerate}
\item \(r = 1, s = 0\), so \(L = \Q\), or
\item \(r = 0, s = 1\), so \(L = \Q(\sqrt d)\) for some \(d \in \Z\) negative square-free.
\end{enumerate}

For real quadratic fields \(L = \Q(\sqrt d)\), let \(\sigma: L \to \R\) be the real embedding such that \(\sigma(\sqrt d) > 0\). As \(\sigma(\mu_L) \subseteq \R^\times\), must have \(\mu_L =  \{\pm 1\}\). Consider the homomorphism
\begin{align*}
  \ell': \O_L^\times &\to \R \\
  \alpha &\mapsto \log |\sigma(\alpha)|
\end{align*}
As \(\ell'(\O_L^\times) \subseteq \R\) is a lattice, there is a unique element \(\alpha \in \O_L^\times\) such that \(\sigma(\alpha) > 0\), \(\ell'(\alpha)\) generates the lattice. Then
\[
  \O_L^\times = \{\pm \alpha^n: n \in \Z\}.
\]
This \(\alpha\) is called the \emph{fundamental unit}. It has the property that \(\log |\sigma(\alpha)|\) is minimal, i.e.\ \(\sigma(\alpha) > 1\) is minimal. This gives us a way to find fundamental units.

\begin{lemma}
  Suppose \(d = 2, 3 \pmod 4\), \(v \in \O_L^\times\) and \(v > 1\). Then \(v = a + b \sqrt d\) where \(a \geq b \geq 1\).
\end{lemma}

\begin{proof}
  Let \(v' = a - b \sqrt d\). Then
  \[
    vv' = a^2 - db^2 = \pm 1.
  \]
  As \(v > 1\), \(|v'| < 1\) so
  \begin{align*}
    2a &= v + v' > 0 \\
    2b &= v - v' > 0
  \end{align*}
  Also
  \[
    \left( \frac{a}{b} \right)^2 = d \pm \frac{1}{b^2} > 1.
  \]
\end{proof}

There is an entirely analogous result for \(d = 1 \pmod 4\) which is left as an exercise.

Now suppose \(d = 2, 3 \pmod 4\). Suppose \(u = a + b \sqrt d \in \O_L^\times\) is the fundamental unit. Let \(u^k = a_k + b_k \sqrt d\). Then
\begin{align*}
  u^{k + 1}
  &= u \cdot u^k \\
  &= (a_1 + b_1 \sqrt d)(a_k + b_k \sqrt d) \\
  &= (a_1a_k + d b_1b_k) + (b_1a_k + a_1b_k) \sqrt d
\end{align*}
so
\[
  b_{k + 1} = b_1a_k + a_1b_k \geq 2b_k > b_k
\]
so \((b_k)_{k \in \N}\) is strictly increasing. We can therefore characterise \(u\) as follow: let \(b \in \N\) be the least positive integer such that \(db^2 + 1\) or \(db^2 - 1\) is of the form \(a^2\) for some \(a \in \N\). Then \(u = a + b \sqrt d\) is the fundamental unit.

If instead \(d = 1 \pmod 4\), we get
\[
  b_{k + 1} = \frac{1}{2}(b_1a_k + a_1b_k) \geq b_k
\]
with equality if and only if \(a_1 = b_1 = 1, a_k = b_k\). In this case
\[
  \n(u) = \left| \frac{1 - d}{4} \right| = 1
\]
so \(d = 5\). In this case \(u = \frac{1}{2} (1 + \sqrt 5)\) is the fundamental unit.

If instead \(d > 5\), we proceed as before and characterise \(u\) as follow: let \(b \in \N\) be the least positive integer such that \(db^2 + 4\) or \(db^2 - 4\) is of the form \(a^2\) for some \(a \in \N\). Then \(u = \frac{1}{2} (a + b \sqrt d)\) is the fundamental unit.

\begin{eg}\leavevmode
  \begin{enumerate}
  \item \(d = 2\). Then \(b = 1\) works since \(2 - 1 = 1^2\) so \(1 + \sqrt 2\) is a fundamental unit.
  \item \(d = 7\).
    \begin{align*}
      & b = 1: 7 \pm 1 \text{ not a square} \\
      & b = 2: 4 \cdot 7 \pm 1 \text{ not a square} \\
      & b = 3: 9 \cdot 7 + 1 = 8^2
    \end{align*}
    so \(8 + 3 \sqrt 7\) is a fundamental unit.
  \end{enumerate}
\end{eg}

\end{document}


\section*{Summary of Section 2}
\begin{enumerate}
  \item The group $\bbz/100$ of 2-digit integers sits in a short exact sequence/group extension
  \begin{equation*}
    \begin{tikzcd}
      0 \ar[r] & \bbz/10 \ar[r,"i"] &  \bbz/100  \ar[r,"p"] & \bbz/10 \ar[r] & 0 \\
       & \mbox{tens} \ar[u, equal]  &  \mbox{2-digit numbers}  \ar[u,equal] & \mbox{units}  \ar[u, equal] &
    \end{tikzcd}
  \end{equation*}

  \item Every group extension arises in this manner.
  For an extension of abelian groups,
  \begin{equation*}
    \begin{tikzcd}
      0 \ar[r] & H \ar[r,"i"] &  G  \ar[r, "p"] & K \ar[r] & 0.
    \end{tikzcd}
  \end{equation*}
  every element of $G$ can be uniquely written as $\units{a}\tens{b}$ for some $a \in H$ and $b \in K$.
\end{enumerate}

\vspace{2cm}
\hrule
\vspace{2cm}

% Show that for every element $g \in G$, there exist unique elements $a \in H$ and $ b \in K $ such that $g = \units{a}\tens{b}$.
% \hint{Look at $p(g)$ and $g - [p(g)]\units{0}$.}
\begin{proof}[Solution to Q.\ref{q:existenceOfDigits}]
  We will only prove existence as uniqueness follows by Q.\ref{q:uniquenessOfDigits}.

  Consider the element $g \in G$. Let $b = p(g) \in K$ and let \begin{equation*}
    h = g - \tens{0}\units{b}.
  \end{equation*}
  Applying $p$ to both sides we get
  \begin{align*}
    p(h)
    &= p(g - \tens{0}\units{b}) \\
    &= p(g) - p(\tens{0}\units{b}) && \mbox{ as $p$ is a group homomorphism}\\
    &= b -b \\
    &= 0
  \end{align*}
  Hence, $h \in \ker p$, which implies that $h \in \im i$.
  Hence, $ h = i(a) = \tens{a}\units{0}$ for some $a \in H$, giving us
  \begin{equation*}
    g = h + \tens{0}\units{b} = \tens{a}\units{0} + \tens{0}\units{b} = \tens{a}\units{b}.
  \end{equation*}
\end{proof}


\section{Part 2.a Numerical Integrator}

The file of the functions used for this exercise is:

\lstinputlisting{two_a.py}

The result of this function is given by:

\lstinputlisting{2a.txt}

\section{Part 2.b Interpolation}

The file of the functions used for this exercise is:

\lstinputlisting{two_b.py}

My script produces the following result, see Fig. \ref{fig:interp}. This shows the differences between the linear
interpolation and cubic spline. Both are essentially the same for this data, except between 0.1 and 1. In comparison to
the actual values, the interpolated values underestimate for all values between $x$ = 1 and $x$ = 5.

\begin{figure}[h!]
  \centering
  \includegraphics[width=0.9\linewidth]{./plots/interpolation.png}
  \caption{The interpolation function in action.}
  \label{fig:interp}
\end{figure}

\section{Part 2.c Numerical Derivative}

The file of the functions used for this exercise is:

\lstinputlisting{two_c.py}

The result of this function is given by:

\lstinputlisting{2c.txt}

\section{Part 2.d Random Sampling}

The file of the functions used for this exercise is:

\lstinputlisting{two_d.py}

My script produces the following result, see Fig. \ref{fig:rand_sample}

\begin{figure}[h!]
  \centering
  \includegraphics[width=0.9\linewidth]{./plots/random_sample.png}
  \caption{The results of the random sample with rejection sampling.}
  \label{fig:rand_sample}
\end{figure}

The positions in (r, $\phi$, $\theta$) are given by:

\lstinputlisting{2d.txt}

\section{Part 2.e 1000 Haloes}

The file of the functions used for this exercise is:

\lstinputlisting{two_e.py}

My script produces the following result, see Fig. \ref{fig:1000_haloes}. As can be seen, the generated galaxies mostly match
the $N(x) = n(x)4\pi x^2$ distribution.

\begin{figure}[h!]
  \centering
  \includegraphics[width=0.9\linewidth]{./plots/1000_haloes.png}
  \caption{The results of 1000 haloes each with 100 satellites. }
  \label{fig:1000_haloes}
\end{figure}

\section{Part 2.f Root Finding}

The file of the functions used for this exercise is:

\lstinputlisting{two_f.py}

The result of this function is given by:

\lstinputlisting{2f.txt}

\section{Part 2.g Percentiles and Poisson}

The file of the functions used for this exercise is:

\lstinputlisting{two_g.py}

The median, 16th, and 84th percentiles for the radial bin with the largest number of falaxies is given in:

\lstinputlisting{2g.txt}

My script produces the following result, see Fig. \ref{fig:hist_poisson}. As can be seen, histogram fairly closely follows
the Poisson distribution with $\lambda$ equal to the mean number of galaxies in this radial bin.

\begin{figure}[h!]
  \centering
  \includegraphics[width=0.9\linewidth]{./plots/hist_poisson.png}
  \caption{The results of 1000 haloes each with 100 satellites. }
  \label{fig:hist_poisson}
\end{figure}

\section{Part 2.h 3D interpolator}

The file of the functions used for this exercise is:

\lstinputlisting{two_h.py}

While no output was requested, I did test the 3D interpolator, with the a,b,and c values generated earlier.
The error is quite large for these, which I believe is a result of the linear interpolation used. Cubic splines took too
long to run, and were expensive to create.

\lstinputlisting{2h.txt}


% This LaTeX was auto-generated from MATLAB code.
% To make changes, update the MATLAB code and republish this document.

\documentclass{article}
\usepackage{graphicx}
\usepackage{color}

\sloppy
\definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}

\begin{document}

\section*{HOMEWORK 1 - FRANCISCO CASTILLO}

\subsection*{Contents}

\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item Problem 2
\end{itemize}

\subsection*{Problem 2}

\begin{verbatim}
format long;clear all;close all;clc
x_0=33.3;
f = @(x) (1+2*x^2*cos(x))/(x^(2.4));
fp = @(x) (2*x^2*(2*cos(x)-x*sin(x))-2.4*(1+2*x^2*cos(x)))/(x^3.4);
for k = -3:1:25
    H(k+4) = 2^(-k);
end
for k = 1:length(H)
    h = H(k);
    df1(k) = (f(x_0+h)-f(x_0))/h;
    df2(k) = (f(x_0+h)-f(x_0-h))/(2*h);
    df6(k) = (45*(f(x_0+h)-f(x_0-h))-9*(f(x_0+2*h)-f(x_0-2*h))...
        +(f(x_0+3*h)-f(x_0-3*h)))/(60*h);
end
linewidth=2;
darkgreen=[0 0.6 0];
figure('units','normalized','outerposition',[0 0 1 1])
loglog(H,abs(df1-fp(x_0)),'*',H,abs(df2-fp(x_0)),'*')
hold on
loglog(H,abs(df6-fp(x_0)),'*','Color',darkgreen)
loglog(H,H/2,'b--',H,H.^(2)/6,'r--','linewidth',linewidth)
loglog(H,H.^(6)/140,'--','Color',darkgreen,'linewidth',linewidth)
loglog(H,eps./H,'k:','linewidth',linewidth)
set(gca,'fontsize',14)
axis([1e-8 1e1 1e-20 1e5])
grid on
xlabel('$h$ (log scale)','fontsize',20,'interpreter','latex')
ylabel('Error (log scale)','fontsize',20,'interpreter','latex')
saveas(gcf,'IMAGES/problem2_1','epsc')
saveas(gcf,'IMAGES/problem2_1','fig')
\end{verbatim}

\includegraphics [width=4in]{HW1_01.eps}

\end{document}


\section{Mean-field approximation for Ising Model}
This is the main equation
\begin{align}
    h_{\mathrm{eff}}
    &=
    h
    +
    4J T gh \beta h_{\mathrm{eff}}
\end{align}
The critical temperature
\begin{align}
    k_B T_c &= 4J
\end{align}
The susceptibility
\begin{align}
    \chi
    &=
    \frac{1}{\beta}
    \left.\frac{\partial m}{\partial h}\right|_{T=T_c, h=0}
    \sim
    \left| T - T_c \right|^{\overbrace{-1}^{\gamma}}
\end{align}
and the magnetisation is
\begin{align}
    m &\sim
    \left| T - T_c \right|^{\overbrace{1/2}^{\beta}}
\end{align}
I can then write
\begin{align}
    \underbrace{h_{\mathrm{eff}}}_{h + 4Jm}
    &=
    h
    +
    4 J T gh \beta h_{\mathrm{eff}}
\end{align}
which implies
\begin{align}
    m &=
    Tgh \beta \left( 4J m + h \right)
\end{align}
so
\begin{align}
    4J m + h
    &=
    \frac{1}{\beta_c}
    \arctanh m\\
    &\approx
    \frac{1}{\beta_c}
    \left(
    m
    +
    \frac{m^3}{3}
    + \cdots
    \right)
\end{align}
so then
\begin{align}
    h \sim m^{\overbrace{3}^{\delta}}
\end{align}
which is not obvious at all.

The relation between $m$ and $h$ depends on that equation,
but depends only on the fact that this s an odd function and that it is smooth.
This is very robust because even though it's only approximate.

There are perfect analogies of mean field all over physics.
In fact you've seen those before.
So I'm going to erase this and I'm going to make some drawings in two different
colours.
On the left we have the mean field approximation,
and on the right I'm going to tell another thing that you already know,
which are fluids that obey the van der Waals equation of state.

\subsection{Ising}
I'm going to draw the external magnetic field vs the temperature.
This is $T_c$.
What happens when I'm above $T_c$ and I have a negative $h$?
It favours spin down so magnetisation is going to be down.
If $h>0$,
then up is favoured.
If the magnetic field is zero,
then it's zero.
So nothing interesting happens here when I cross $h=0$ for $T>T_c$.

Now below $T_c$,
the magnetisation doesn't go to zero.
When $h$ is slightly negative,
they are all spin down.

The discontinuity disappears in the critical region.

The analogy with the van der Waals fluid is
\begin{align}
    h &\sim P\\
    m &\sim \frac{1}{V}
\end{align}

[lots of pictures]

In a lot of systems,
there is an order parameter $\phi$ such that its average value is
\begin{align}
    \begin{cases}
        \langle \phi \rangle
        =
        0 & T > T_c\\
        \langle \phi \rangle
        \ne
        0 & T > T_c
    \end{cases}
\end{align}
If there is such a situation,
then there is spontaneous symmetry breaking.
The order parameter doesn't have the symmetry of the Hamiltonian,
because when it flips it flips sign,
but the Hamiltonian doesn't change.
The thermal average is not zero,
even though it should be naively if you look at the Hamiltonian.

A lot of cases,
when the expectation picks up a non-zero expectation value like this,
frequently this means spontaneous symmetry breaking.

It happens even when equal to zero.

It's worth while going close to the critical point and looking at the
configuration that contributes the most.
The ones with smallest energy are ordered and there are few of them.
They are not typical.
The more typical ones are the high energy ones.

I'm going to try to draw some configurations that are critical.

[picture]

When above the critical temperature,
the typical size of clusters $\xi\approx a$,
the lattice size.
When at $T=T_c$,
you're going to get clusters of all sizes,
from the size of a lattice spacing to large clusters that go from one corner of
the system to another,
and everything in between.

So we talk about the critical exponents in the mean field model.
I want it to be the centre piece of everything we compute here.
It turns out that close to the critical point,
the heat capacity diverges.
\begin{align}
    C &\sim \left| T - T_c \right|^{-\alpha}
\end{align}
Let's compute $\alpha$.

The magnetisation when you approach the critical temperature is like
\begin{align}
    m ~ \left| T - T_c \right|^{\beta}
\end{align}
and the susceptibility
\begin{align}
    \chi &=
    \left| \frac{\partial m}{\partial h} \right|_{h=0}
    \sim
    \left| T - T_c \right|^{-\gamma}
\end{align}
Suppose we calculate the correlation
about how close or far spins influence each other
\begin{align}
    \left\langle
    \sigma_0
    \sigma_{0 + R}
    \right\rangle
    &\sim
    e^{-R/\xi}
\end{align}
and this parameter $\xi$ is the correlation length,
which is measurer f how far you need to go to not get correlation.
The correlation length diverges too at the critical temperature.
\begin{align}
    \xi &\sim
    \left| T - T_c\right|^{-\nu}
\end{align}
I didn't show you but $\nu=\frac{1}{2}$ for mean field Ising.

I can take a Fourier transform.

This is the only integral you need to do in your head
\begin{align}
    \sum_{\vec{R}}
    \left\langle
    \sigma_0
    \sigma_{0 + R}
    \right\rangle
    e^{i\vec{k}\cdot\vec{R}}
    \sim
    \frac{1}{k^{2 - \eta}}
\end{align}
where $\eta$ is called the \emph{anomalous dimension}.

\section{Universality classes}
Numerical experiments and exact results.
The Ising model in 2D was solved exactly on paper.
First surprise,
it's not what mean field theory says.
It maybe shouldn't surprise you much,
because mean field was a bit hand waving anyway.

But the surprising thing was a different one.
It wasa big surprise back them.

There was a theory called Landau mean field theory,
a lot of hand wavin,
but it's Landau hand waving,
and he talks to God directly.
It's like mean field theory on steroids.
Tremendous theory,
no argument whatsoever.

Then you find something interesting with the exact solution.
There are what we call Universality classes.

People looked at the 2D Ising model.
People made this relation between this and the liquid phase transition.
You can measure the critical exponents of water evapoerating,
and you find it's 3D Ising model.
One is a stupid magnet model,
one is a real system.
They agree within error bars.
But then you look at other systems,
and there are sets of critical exponents that appear frequently.

The critical exponents of the 3D Ising model are common,
probably the most common one.
And then there are other common ones.
The systems are completely diffrent.
In the notes,
I give some critical exponents calculated from numerics,
conformal bootstrap.
Let me just write these here.
\begin{table}
    \centering
    \begin{tabular}{cccc}
        & 3D Ising & CO$_2$ & Ni Magnet\\
        $\alpha$ & 0.11008(1) & 0.10 & 0.0(?)\\
        \vdots\\
        $\delta$ & 4.28984(1) & 4.20 & 4.22
    \end{tabular}
    \caption{Critical Exponents Theory vs Experiment}%
    \label{tab:criticalexponents}
\end{table}
There's an uncertainty for Ni magnet that I don't know.
All systems in nature seem to fall into

Here are some common universality classes
\begin{itemize}
    \item 3D Ising
    \item 2D Ising
    \item Mean field
    \item Kosterlitz-Thouless
    \item 3-Potts model
\end{itemize}
I knew Thouless.
A lot of things come from experience.
People get data and they see a pattern.
Roughly the pattern people see is the following.

The first thing you have to discern is the dimensionality of the state.
The other one is more subtle,
it's the ``pattern of spontaneous symmetry breaking''.
For example,
consider the Ising model.
The Hamiltonian has a symmetry $\mathbb{Z}_2$
which is basically spin flip.
This symmetry has 2 elements,
do nothing and flip all the spins.
The point is that at low temperatures,
the magnetisation,
the order parameter,
is not zero.
It's pointing either up or down.
When I did a spin flip,
I get a different state.
What's the symmetry of the sate below the critical temperature?
That's what I mean by a matter of symmetry breaking,
how it's broken to the final state
$\mathbb{Z}_2 \to \textrm{nothing}$.

Another model is the Heisenberg model,
every point on a lattice has a spin-$\frac{1}{2}$ on it.
You can make it ferromagnetic or antiferromagnetic or whatever.
The point is that it's not just up or down,
it could be many other states you can rotate by.

The dot product between two spins stays the same under rotation.
People call this SO(3),
which are 3 by 3 orthogonal matrices.
The special orthogonal matrices.
Also known as rotations.
You don't know this,
but the ferromagnetic model,
the ground state is all spins pointing in the same direction,
because that maximizes the dot product and minimized the energy just like thei
Ising model.

Suppose this direction is picked up,
there's still some symmetry left.
If I do rotations around this axis,
the magnetisation order parameter doesn't change.
$SO(3) \to O(2)$.

There is a particular type of liquid crystal called nematic liquid crystal.
How can something be a liquid and a crystal at the same time?
It's made of long molecules,
and the head and tails are different.
It turns out below a certain critical temperature,
they organize themselves like this.
Their position is not organized on a crystal,
like a liquid,
not organized in a nice pattern.
Their direction is not organized either,
there are as much head up and head down.
The only thing is that they are all aligned that way.
The Hamiltonian has a symmetry that they can rotate any direction they like.
Here there's nothing to point,
the order parameter is a tensor.
But it can still flip.
\begin{align}
    SO(3) \to O(2)\times \mathbb{Z}_3
\end{align}
Rotation goes to 2D rotation and flips.

Meanwhile there are other liquid crystals
where the centres of molecule positions are fixed by the orientation are not.

Remember the Bose gas,
which has a phase transition,
a condensate.
I claimed that it's superfluid.
I'm not even going to attempt to explain.
The pattern of symmetry breaking in that case is $U(1)$.
That's exactly the same group as $O(2)$ by the way.
This is broken to almost nothing.
This phase has to do with changing the wave function by a phase
$\psi \to e^{i\beta} \psi$.
Superfluid helium and BEC follow this pattern,
and they have their own universality class.

You probably heard something that if you look at the physics of elementary
particles,
there is a symmetry
\begin{align}
    SU_c(3)
    \times
    SU_w(2)
    \times
    U_Y(1)
    \to
    SU_c(3)
    \times
    U_{EM}(1)
\end{align}
If you have 2 systems with the same dimension,
they follow the same universality class.
That was an experimental observation.

Examples.

Consider the Ising model in 2D
\begin{align}
    H &=
    -J \sum \sigma_i \sigma_j
\end{align}
consider my made up Paulo model
\begin{align}
    H^P &=
    -J \sum_{\textrm{plaquette}}
    \sigma_{i} \sigma_{j} \sigma_{k} \sigma_{l}
\end{align}
They have the same dimensionality and the same pattern of spontaneous symmetry
breaking so they should have the same critical exponents.
Same for the sum
\begin{align}
    H &=
    -\tilde{J} \sum \sigma_i \sigma_j
    -J \sum_{\textrm{plaquette}}
    \sigma_{i} \sigma_{j} \sigma_{k} \sigma_{l}
\end{align}


% IRAM.tex
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}

\title{Post-Processing Arnoldi's Method}
\author{Jeremy L. Conlin}

\newcommand{\A}{\mathbf{A}}
\newcommand{\qp}[1]{q'_{#1}}
\newcommand{\qh}[1]{\hat{q}_{#1}}
\newcommand{\qt}[1]{\tilde{q}_{#1}}
\newcommand{\qc}[1]{\check{q}_{#1}}
\newcommand{\Aq}[1]{\A q_{#1}}
\newcommand{\Ap}[1]{\A \qp{#1}}
\newcommand{\Ah}[1]{\A \qh{#1}}
\newcommand{\At}[1]{\A \qt{#1}}
\newcommand{\Ac}[1]{\A \qc{#1}}

\begin{document}
\maketitle

The purpose of this document is to explore the possibility of performing an Arnoldi factorization by post-processing a set of Krylov vectors.

\section{The beginning}
Suppose we have the matrix
\begin{equation*}
    \A \equiv \begin{pmatrix} 1 & 0 & 0 & 0 & 0 \\
                              0 & 2 & 0 & 0 & 0 \\
                              0 & 1 & 3 & 0 & 0 \\
                              0 & 0 & 0 & 4 & 0 \\
                              0 & 0 & 0 & 0 & 5 \end{pmatrix}.
\end{equation*}
This problem is not specific to this matrix, but this matrix is easily studied.

A Krylov subspace of dimension $k$ is defined as
\begin{equation}
    \mathcal{K}_k \equiv \left\{q, \A q, \A^2, \ldots, A^{k-1}q\right\} = \left\{q_0, q_1, \ldots, q_k\right\}.
    \label{eq:KrylovSubspace}
\end{equation}
The simplest way to construct a basis for a Krylov subspace is to repeatedly apply a linear operator (in our case the matrix $\A$) to a vector $q$.  This is what is done with the power method which is used to calculate the dominant eigenvalue of the linear operator.

\section{Arnoldi's Method}
Arnoldi's method generates the same Krylov subspace found in Equation \ref{eq:KrylovSubspace} but orthonormalizes the basis vectors.  The question remains if we can begin with Krylov subspace and orthogonalize and normalize the vectors after the fact to create the Arnoldi factorization
\begin{equation}
    \A V = V H.
    \label{eq:ArnoldiFactorization}
\end{equation}

To begin, let's rewrite Equation \ref{eq:KrylovSubspace} as
\begin{equation}
    \mathcal{K}'_k \equiv \left\{q, \A q, \A^2, \ldots, A^{k-1}q\right\} = \left\{\qp{0}, \qp{1}, \ldots, \qp{k}\right\}.
\end{equation}
This is merely to keep our notation straight.  Another way to write this is
\begin{subequations}\begin{align}
    \qp{0} &\equiv q_0 \\
    \qp{1} &= \A \qp{0} \\
    \qp{2} &= \A \qp{1} \\
    &\ldots \\
    \qp{k} &= \A \qp{k-1}.
    \label{}
\end{align}\end{subequations}

We have already applied our linear operator $k$ times and have our $k$-dimensional Krylov subspace.  Can we then orthogonalize it and keep it mathematically equivalent to creating an Arnoldi factorization in the traditional fashion.

Let's begin with the first iteration.

\begin{align}
    \qh{1} &= \Aq{0} \\
    \qt{1} &= \qh{1} - h_{0,1}*q_0 \\
    q_1 &= \qt{1}/\left|\qt{1}\right|.
\end{align}

There is nothing special here.  For a 1-dimensional subspace, we could create a post-Arnoldi factorization from a Krylov subspace.  Of course if that's all we can do, then it isn't very interesting.  Let's move onto the second iteration.

\begin{subequations}
    \begin{align}
    \qh{2} &= \A q_1 \\
    &= \frac{1}{\left|\qt{1}\right|}\At{1} \\
    &= \frac{1}{\left|\qt{1}\right|}\A \left\{\qh{1}-h_{0,1}*q_0\right\} \\
    &= \frac{1}{\left|\qt{1}\right|} \left\{\Ah{1}-h_{0,1}*\Aq{0}\right\} \\
    &= \frac{1}{\left|\qt{1}\right|} \left\{\Ah{1}-h_{0,1}*\qh{1}\right\} \label{eq:2Ihat}.
    \end{align}
\end{subequations}
Equation \ref{eq:2Ihat} contains only one application of the linear operator that hasn't already been performed.  Eliminating this operation is crucial if we are to use this technique since the time required to apply the linear operator is by far the most computationally expensive.  We will introduce a new variable $\qc{1} = \Ah{1}$ but leave discussion about this variable until later.  At this point, let's just assume we know what it is without applying the linear operator.

Using $\qc{1}$ in Equation \ref{eq:2Ihat}, we define $\qh{2}$ in terms of known quantities without the need for additional applications of the linear operator
\begin{equation}
    \qh{2} = \frac{1}{\left|\qt{1}\right|} \left\{\qc{1}-h_{0,1}*\qh{1}\right\}
    \label{eq:2IhatFinal}.
\end{equation}

Continuing the iteration we find an expression of $q_2$ of all known quantities.  (Can you see a recurring pattern here?)
\begin{subequations}
    \begin{align}
        \qt{2} &= \qh{2} - h_{0,2}*q_0 - h_{1,2}*q_1 \\
        q_2 &= \qt{2}/\left|\qt{2}\right|.
    \end{align}
    \label{eq:2I}
\end{subequations}

We have remained in the realm of simple iterations.  Let's take this one more iteration to see if future iterations will cause a problem.
\begin{subequations}
    \begin{align}
    \qh{3} &= \A q_2 \\
    &= \frac{1}{\left|\qt{2}\right|}\At{2} \\
    &= \frac{1}{\left|\qt{2}\right|}\A \left\{\qh{2} - h_{0,2}*q_0 - h_{1,2}*q_1 \right\} \\
    &= \frac{1}{\left|\qt{2}\right|} \left\{\Ah{2} - h_{0,2}*\Aq{0} - h_{1,2}*\Aq{1} \right\} \\
    &= \frac{1}{\left|\qt{2}\right|} \left\{\qc{2} - h_{0,2}*\qh{1} - h_{1,2}*\qh{2} \right\} \label{eq:3Ihat}
    \end{align}
\end{subequations}

From Equation \ref{eq:3Ihat} (as well as Equation \ref{eq:2IhatFinal}) we see that we must store all the ``hat''vectors in addition to what we have already stored.  This shouldn't normally be a problem since the number we are storing should be relatively small.  Again I've taken the liberty of using $\qc{2}$ without further explanation.

We can finish the iteration as usual.
\begin{subequations}
    \begin{align}
    \qt{3} &= \qh{3} - h_{0,3}*q_0 - h_{1,3}*q_1 - h_{2,3}*q_2 \\
    q_3 &= \qt{3}/\left|\qt{3}\right|.
    \end{align}
\end{subequations}

\subsection{What about the $\qc{i}$'s?}
Similarly to what we have already done, let's write out the $\qc{i}$ for the first few iterations to see if we can come up with something that works for every iteration.

The first one is easy
\begin{equation}
    \qc{1} = \Ah{1} = \A \left(\Aq{0}\right) = \Ap{1} = \qp{2}
    \label{eq:qc1}
\end{equation}

The second one takes a little more work,
\begin{subequations}
    \begin{align}
        \qc{2} &= \Ah{2} \\
        &= \A \left\{\frac{1}{\left|\qt{1}\right|} \left\{\qc{1}-h_{0,1}*\qh{1}\right\} \right\} \\
        &= \frac{1}{\left|\qt{1}\right|} \left\{\Ac{1}-h_{0,1}*\Ah{1}\right\} \\
        &= \frac{1}{\left|\qt{1}\right|} \left\{\Ac{1}-h_{0,1}*\qc{1}\right\}
        \label{eq:qc2}
    \end{align}
\end{subequations}
Let's expand $\Ac{1}$.
\begin{equation}
    \Ac{1} = \A \left(\qp{2}\right) = \qp{3}
    \label{eq:qc2sub}
\end{equation}
Substituting Equation \ref{eq:qc2sub} into Equation \ref{eq:qc2} we obtain
\begin{equation}
    \qc{2} = \frac{1}{\left|\qt{1}\right|} \left\{\qp{3}-h_{0,1}*\qc{1}\right\}.
    \label{eq:qc2final}
\end{equation}

Let's do another iteration (I'm not seeing a pattern yet).
\begin{subequations}
    \begin{align}
        \qc{3} &= \Ah{3} \\
        &= \A \left[ \frac{1}{\left|\qt{2}\right|} \left\{\qc{2} - h_{0,2}*\qh{1} - h_{1,2}*\qh{2} \right\} \right] \\
        &= \frac{1}{\left|\qt{2}\right|} \left\{\Ac{2} - h_{0,2}*\Ah{1} - h_{1,2}*\Ah{2} \right\} \\
        &= \frac{1}{\left|\qt{2}\right|} \left\{\Ac{2} - h_{0,2}*\qc{1} - h_{1,2}*\qc{2} \right\}
        \label{eq:qc3}
    \end{align}
\end{subequations}
Let's expand $\Ac{2}$.
\begin{subequations}
    \begin{align}
        \Ac{2} &= \A \left[\frac{1}{\left|\qt{1}\right|} \left\{\qp{3}-h_{0,1}*\qc{1}\right\}\right] \\
         &= \frac{1}{\left|\qt{1}\right|} \left\{\Ap{3}-h_{0,1}*\Ac{1}\right\} \\
         &= \frac{1}{\left|\qt{1}\right|} \left\{\qp{4}-h_{0,1}*\qp{3}\right\}
        \label{eq:qc3sub}
    \end{align}
\end{subequations}
Substituting Equation \ref{eq:qc3sub} into Equation \ref{eq:qc3} followed by substituting in Equation \ref{eq:qc2final} we obtain
\begin{subequations}
    \begin{align}
        \qc{3} &= \frac{1}{\left|\qt{2}\right|} \left\{\left[\frac{1}{\left|\qt{1}\right|} \left\{\qp{4}-h_{0,1}*\qp{3}\right\}\right] - h_{0,2}*\qc{1} - h_{1,2}*\qc{2} \right\} \\
         &= \frac{1}{\left|\qt{2}\right|} \left\{\left[\frac{1}{\left|\qt{1}\right|} \left\{\qp{4}-h_{0,1}*\qp{3}\right\}\right] - h_{0,2}*\qc{1} - h_{1,2}*\left[\frac{1}{\left|\qt{1}\right|} \left\{\qp{3}-h_{0,1}*\qc{1}\right\}\right] \right\}
    \end{align}
\end{subequations}

Well, this doesn't look good.  It is clear that there are no matrix-vector multiplications needed, but I can't yet see a recursive pattern.  I'm sure it's there, I just can't see it yet.

\section{General Format}
Now let's try to write this in a general format.  We have already shown that it works for up to three iterations.  What if we are performing the $n+1$st iteration?

\begin{subequations}
    \begin{align}
        \qh{n+1} &= \Aq{n} \\
        &= \frac{1}{\qt{n}}\At{n} \\
        &= \frac{1}{\qt{n}}\A
        \left\{\qh{n} - h_{0,n}*q_0 - h_{1,n}*q_1 \cdots h_{n-1,n}*q_{n-1}\right\} \\
        &= \frac{1}{\qt{n}}
        \left\{\Ah{n} - h_{0,n}*\Aq{0} - h_{1,n}*\Aq{1} \cdots h_{n-1,n}*\Aq{n-1}\right\} \\
        &= \frac{1}{\qt{n}}
        \left\{\qc{n} - h_{0,n}*\qh{1} - h_{1,n}*\qh{2} \cdots h_{n-1,n}*\qh{n}\right\}
    \end{align}
\end{subequations}
\begin{subequations}
    \begin{align}
        \qt{n+1} &= \qh{n+1} - h_{0,n+1}*q_0 \cdots h_{n.n+1}*q_n \\
        q_{n+1} &= \qt{n+1}/\left|\qt{n+1}\right|.
    \end{align}
\end{subequations}

\section{Conclusion}
So I think a post-processing Arnoldi's method is possible.  I just haven't yet found the inductive proof for the $\qc{i}$'s.
\end{document}


We are interested in leveled HE schemes that support SIMD operations on their plaintexts.
Such schemes include $\FV$~\cite{FV12} and $\BGV$~\cite{BGV12}, have the ring $\intring_p$ as plaintext space for some $p \geq 2$.
We refer to such schemes as \emph{SIMD-schemes}.
The general framework of such schemes is outlined below.

\subsection{Basic setup}

Let $\lambda$ be the security level of an HE scheme.
Let $L$ be the maximal multiplicative depth of homomorphic circuits we want to evaluate.
Let $d$ be the order of the plaintext modulus $p$ modulo the order $m$ of $\intring$.
Assume that the plaintext space $\intring_p$ has $\slots$ SIMD slots, i.e. $\intring_p \cong \F^\ell_{p^d}$.
% For a vector $\va \in \F^k_{p^d}$, we denote the plaintext encoding of $\va$ by $\pt(\va)$.
The basic part of a SIMD-scheme consists of key generation, encryption and decryption algorithms.

$\KeyGen(1^\lambda, 1^L) \rightarrow (\sk, \pk)$. Given $\lambda$ and $L$, this function generates the secret key $\sk$ and the public key $\pk$.
Note that the public key contains special key-switching keys that help to transform ciphertexts encrypted under other secret keys back to ciphertexts encrypted under $\sk$.

$\Encrypt(\pt \in \intring_t, \pk) \rightarrow \ct$. The encryption algorithm takes a plaintext $\pt$ and the public key $\pk$ and outputs a ciphertext $\ct$.

$\Decrypt(\ct, \sk) \rightarrow \pt$. The decryption algorithm takes a ciphertext $\ct$ and the secret key $\sk$ and returns a plaintext $\pt$.
For freshly encrypted ciphertexts, the decryption correctness means that $\Decrypt(\Encrypt(\pt, \pk), \sk) = \pt$.

\subsection{Arithmetic operations}

Homomorphic arithmetic operations are addition and multiplication.

$\Add(\ct_1, \ct_2) \rightarrow \ct$. The addition algorithm takes two input ciphertexts $\ct_1$ and $\ct_2$ encrypting plaintexts $\pt_1$ and $\pt_2$ respectively.
It outputs a ciphertext $\ct$ that encrypts the sum of these plaintexts in the ring $\intring_p$.
%It implies that homomorphic addition sums respective SIMD slots of $\pt_1$ and $\pt_2$.

$\AddPlain(\ct_1, \pt_2) \rightarrow \ct$. This algorithm takes a ciphertext $\ct_1$ encrypting a plaintext $\pt_1$ and a plaintext $\pt_2$.
It outputs a ciphertext $\ct$ that encrypts $\pt_1 + \pt_2$.
%As for the $\Add$ algorithm, $\AddPlain$ sums respective SIMD slots of $\pt_1$ and $\pt_2$.

$\Mul(\ct_1, \ct_2) \rightarrow \ct$. Given two input ciphertext $\ct_1$ and $\ct_2$ encrypting plaintext $\pt_1$ and $\pt_2$ respectively, the multiplication algorithm outputs a ciphertext $\ct$ that encrypts the plaintext product $\pt_1 \cdot \pt_2$.
%As a result, homomorphic multiplication multiplies respective SIMD slots of $\pt_1$ and $\pt_2$.

$\MulPlain(\ct_1, \pt_2) \rightarrow \ct$. Given a ciphertext $\ct_1$ encrypting plaintext $\pt_1$ and a plaintext $\pt_2$, this algorithm outputs a ciphertext $\ct$ that encrypts the plaintext product $\pt_1 \cdot \pt_2$.
%As a result, homomorphic multiplication multiplies respective SIMD slots of $\pt_1$ and $\pt_2$.

Using the above operations as building blocks, one can design homomorphic subtraction algorithms.

$\Sub(\ct_1, \ct_2) = \Add(\ct_1, \MulPlain(\ct_2, \pt(-\1))) \rightarrow \ct$. The subtraction algorithm returns a ciphertext $\ct$ that encrypts the difference of two plaintext messages $\pt_1 - \pt_2$ encrypted by $\ct_1$ and $\ct_2$, respectively.

$\SubPlain(\ct_1, \pt_2) = \AddPlain(\ct_1, \pt_2 \cdot \pt(-\1)) \rightarrow \ct$. This algorithm returns a ciphertext $\ct$ that encrypts $\pt_1 - \pt_2$ where $\pt_1$ is encrypted by $\ct_1$.
We can also change the order of arguments such that $\SubPlain(\pt_1, \ct_2)$ returns a ciphertext $\ct$ encrypting $\pt_1 - \pt_2$.

As shown in Section~\ref{subsec:crt}, the projection map $\proj_I$ can select the SIMD slots indexed by a set $I \subseteq \{0,\dots,\slots-1\}$ and set the rest to zero.
This functionality is homomorphically realized by the $\Select$ function.

$\Select(\ct, I) = \MulPlain(\ct, \pt(\1_I)) \rightarrow \ct'$ where $\1_I$ is a vector having $1$'s in the coordinates indexed by a set $I$ and zeros everywhere else.
Given a ciphertext $\ct$ encrypting SIMD slots $\vm = (m_0,m_1,\dots,m_{\slots-1})$ and a set $I$, this function returns a ciphertext $\ct'$ that encrypts $\vm' = (m'_0,\dots,m'_{\slots-1})$ such that $m'_i = m_i$ if $i \in I$ and $m'_i = 0$ otherwise.

\subsection{Special operations}\label{subsec:special_operations}

One can also homomorphically permute the SIMD slots of a given ciphertext and act on them with the Frobenius automorphism.

$\Rotate(\ct, i) \rightarrow \ct'$ with $i \in [0, \slots-1]$. Given a ciphertext $\ct$ encrypting SIMD slots
$$\vm = (m_0,m_1,\dots,m_{\slots-1}),$$
the rotation algorithm returns a ciphertext $\ct'$ that encrypts the cyclic shift of $\vm$ by $i$ positions, namely $(m_i,m_{(i+1) \mod \slots},\dots,m_{(i-1) \mod \slots})$.

$\Frob(\ct, i) \rightarrow \ct'$ with $i\in[0,d-1]$. Given a ciphertext $\ct$ encrypting SIMD slots $\vm$ as above, the Frobenius algorithm returns a ciphertext $\ct'$ that encrypts a Frobenius map action on $\vm$, namely $(m^{p^i}_0,m^{p^i}_1,\dots,m^{p^i}_{\slots-1})$.

As discussed in Section~\ref{subsec:crt}, the $\Frob$ and $\Mul$ operations can be combined to compute the principal character $\princhar$, which turns non-zero values of SIMD slots into $1$ and leaves slots with zeros unchanged.

$\IsNonZero(\ct) \rightarrow \ct'$. Given a ciphertext $\ct$ encrypting SIMD slots $\vm = (m_0,m_1,\dots,m_{\slots-1})$, this function returns a ciphertext $\ct'$ that encrypts:
\[
  (\princhar(m_0), \princhar(m_1), \dots, \princhar(m_{\slots-1})).
\]
% Kim et al.~\cite{TDSC:KLLW16} showed that one can employ the Frobenius map to decrease the multiplicative depth of $\IsNonZero$.
Recall that $\princhar(m) = m^{p^d-1} = \prod_{i=0}^{d-1} (m^{p-1})^{p^i}$ as shown in~(\ref{eq:exp_frob}).
The multiplicative depth of $x^{p-1}$ is equal to $\ceil{\log_2 (p-1)}$.
The multiplicative depth of $x^{p^i}$ is zero as it can be done by the $\Frob$ operation.
In total, $d-1$ $\Frob$ operations are needed to compute $\princhar(m)$.
As a result, the total multiplicative depth of $\IsNonZero$ is
\begin{align}\label{eq:nonzero_depth}
  \ceil{\log_2 (p-1)} + \ceil{\log_2 d}.
\end{align}
Using general exponentiation by squaring, $x^{p-1}$ requires $\floor{\log_2 (p-1)} + \wt(p-1) - 1$ field multiplications.
Since $d-1$ field multiplications are needed to compute $\prod_{i=0}^{d-1} (x^{p-1})^{p^i}$, the total number of multiplications to compute $\princhar(m)$ is:
\begin{align}\label{eq:nonzero_width}
  \floor{\log_2 (p-1)} + \wt(p-1) + d - 2.
\end{align}

\subsection{Noise cost of homomorphic operations}\label{subsec:cost}
Note that every homomorphic ciphertext contains a special component called \emph{noise} that is removed during decryption.
However, the decryption function can deal only with noise of small enough magnitude; otherwise, this function fails.
This noise bound is defined by encryption parameters in a way that larger parameters result in a larger bound.
The ciphertext noise increases after every homomorphic operation and, therefore, approaches its maximal possible bound.
It implies that to reduce encryption parameters one needs to avoid homomorphic operations that significantly increase the noise.
Therefore, while designing homomorphic circuits, we need to take into account not only the running time of homomorphic operations but also their effect on the noise.

Table~\ref{table:he_operations} summarizes the running time and the noise cost of the aforementioned homomorphic operations.
Similar to~\cite{C:HalSho14}, we divide the operations into expensive, moderate and cheap.
The expensive operations dominate the cost of a homomorphic circuit.
The moderate operations are less important, but if there are many of them in a circuit, their total cost can dominate the total cost.
The cheap operations are the least important and can be omitted in the cost analysis.

\subsection{Complexity of homomorphic algorithms}
While evaluating polynomials in variables $X_1, X_2, \dots, X_n$, we refer to multiplication of expressions containing these variables as \emph{non-scalar}.
There are two multiplication functions $\Mul$ (ciphertext-ciphertext multiplication) and $\MulPlain$ (ciphertext-plaintext multiplication).
The former one corresponds to non-scalar multiplication of two expressions containing input values, while the latter is related to the product of an expression with input values and unencrypted finite field elements.
Since $\Mul$ is much slower and introduces more noise than $\MulPlain$, the multiplicative depth and complexity of a homomorphic circuit is usually calculated with relation to the number of $\Mul$'s, or non-scalar multiplications.

\begin{table}[t!]
  \centering
  \begin{tabular*}{.45\textwidth}{@{\extracolsep{\fill} } c c c }
    \toprule
    Operation	& Time			& Noise \\
    \midrule
    $\Add$		& cheap			& cheap 	\\
    $\AddPlain$	& cheap			& cheap \\
    $\Mul$		& expensive		& expensive 	\\
    $\MulPlain$	& cheap			& moderate 	\\
    $\Sub$		& cheap			& cheap  \\
    $\SubPlain$	& cheap			& cheap  \\
    $\Select$	& cheap			& moderate \\
    $\Rotate$ 	 & expensive	& moderate \\
    $\Frob$		 & expensive	& cheap \\
    $\IsNonZero$ & expensive    & expensive \\
    \bottomrule
  \end{tabular*}
  \caption{The cost of homomorphic operations with relation to running time and noise growth.}
  \label{table:he_operations}
\end{table}

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


\subsection{Orthogonal and orthonormal sets}

In this section, we examine what it means for vectors (and sets of
vectors) to be orthogonal and orthonormal. First, it is necessary to
review some important concepts. You may recall the definitions for the
span of a set of vectors and a linear independent set of vectors. We
include the definitions and examples here for convenience.

\begin{definition}{Span of a set of vectors and subspace}{span}
  The collection of all linear combinations of a set of vectors
  $\set{\vect{u}_1,\ldots,\vect{u}_k}$ in $\R^{n}$ is known as the
  span\index{span}\index{vector!span} of these vectors and is written
  as $\sspan \set{\vect{u}_1,\ldots,
    \vect{u}_k}$. \\
  We call a collection of the form
  $\sspan \set{\vect{u}_1,\ldots, \vect{u}_k}$ a subspace of $\R^{n}$.
\end{definition}

Consider the following example.

\begin{example}{Span of vectors}{span-vectors}
Describe the span of the vectors $\vect{u}=\begin{mymatrix}{rrr}
1  & 1 & 0
\end{mymatrix}^T$ and
$\vect{v}=\begin{mymatrix}{rrr}
3  & 2 & 0
\end{mymatrix}^T \in \R^{3}$.
\end{example}

\begin{solution}
You can see that any linear combination of the vectors $\vect{u}$ and $\vect{v}$ yields a vector
$\begin{mymatrix}{rrr}
x  & y & 0
\end{mymatrix}^T$ in the $XY$-plane.

Moreover every vector in the $XY$-plane is in fact such a linear
combination of the vectors $\vect{u}$ and $\vect{v}$. That's because
\[ \begin{mymatrix}{r}
x \\
y \\
0
\end{mymatrix}
=
(-2x+3y) \begin{mymatrix}{r}
1 \\
1 \\
0
\end{mymatrix}
+
(x-y)\begin{mymatrix}{r}
3 \\
2 \\
0
\end{mymatrix}
\]

Thus  span$\set{\vect{u},\vect{v}}$ is precisely the $XY$-plane.
\end{solution}

The span of a set of a vectors in $\R^n$ is what we call a \textbf{subspace of $\R^n$}. A subspace $W$ is characterized by the feature that any linear combination of vectors of $W$ is again a vector contained in $W$.

Another important property of sets of vectors is called linear independence.

\begin{definition}{Linearly independent set of vectors}{linear-independent-orthogonality}
A set of non-zero vectors $\set{\vect{u}_1,\ldots,\vect{u}_k}$ in $\R^{n}$ is said to be
\textbf{linearly independent}\index{linear independence}\index{vector!linear independence}
 if no vector in that set is in the span of the other vectors of that set.
\end{definition}

Here is an example.

\begin{example}{Linearly independent vectors}{linearly-independent-vectors}
Consider vectors $\vect{u}=\begin{mymatrix}{rrr}
1  & 1 & 0
\end{mymatrix}^T$,
$\vect{v}=\begin{mymatrix}{rrr}
3  & 2 & 0
\end{mymatrix}^T$, and
$\vect{w}=\begin{mymatrix}{rrr}
4  & 5 & 0
\end{mymatrix}^T  \in \R^{3}$.
Verify whether the set $\set{\vect{u}, \vect{v}, \vect{w}}$ is linearly independent.
\end{example}

\begin{solution}
We already verified in Example~\ref{exa:span-vectors} that
$\sspan \set{\vect{u}, \vect{v}}$ is the $XY$-plane. Since $\vect{w}$
is clearly also in the $XY$-plane, then the set $\set{\vect{u}, \vect{v},
\vect{w}}$ is \textbf{not} linearly independent.
\end{solution}

In terms of spanning, a set of vectors is linearly independent if it
does not contain unnecessary vectors. In the previous example you
can see that the vector $\vect{w}$ does not help to span any new vector
not already in the span of the other two vectors. However you can
verify that the set $\set{\vect{u}, \vect{v}}$ is linearly independent,
since you will not get the $XY$-plane as the span of a single vector.

We can also determine if a set of vectors is linearly independent by examining linear combinations. A set of vectors is linearly independent if and only if
whenever a linear combination of these vectors equals zero, it follows
that all the coefficients equal zero. It is a good exercise to verify
this equivalence, and this latter condition is often used as the
(equivalent) definition of linear independence.

If a subspace is spanned by a linearly independent set of vectors,
then we say that it is a basis for the subspace.

\begin{definition}{Basis of a subspace}{subspace-basis}
Let $V$ be a subspace of $\R^{n}$. Then $\set{
\vect{u}_{1},\ldots,\vect{u}_{k}} $ is a \textbf{basis}\index{basis}\index{vector!basis}\index{subspace!basis} for
$V$ if the following two conditions
hold.

\begin{enumerate}
\item $\sspan\set{\vect{u}_{1},\ldots,\vect{u}_{k}} =V$
\item $\set{\vect{u}_{1},\ldots,\vect{u}_{k}} $ is linearly
independent
\end{enumerate}
\end{definition}

Thus the set of vectors $\set{\vect{u}, \vect{v}}$ from Example~\ref{exa:linearly-independent-vectors} is a basis for $XY$-plane in
$\R^{3}$ since it is both linearly independent and spans
the $XY$-plane.

 Recall from the properties of the dot product of vectors
that two vectors $\vect{u}$ and $\vect{v}$ are orthogonal if $\vect{u}
\dotprod \vect{v} = 0$. Suppose a vector is orthogonal to a spanning set of $\R^n$. What can be said about such a vector? This is the discussion in the following example.

\begin{example}{Orthogonal vector to a spanning set}{}
Let $\set{\vect{x}_1, \vect{x}_2, \ldots, \vect{x}_k}\in\R^n$ and
suppose $\R^n=\sspan\set{\vect{x}_1, \vect{x}_2, \ldots, \vect{x}_k}$.
Furthermore, suppose that there exists a vector $\vect{u}\in\R^n$ for which $\vect{u}\dotprod \vect{x}_j=0$ for all $j$, $1\leq j\leq k$.
What type of vector is $\vect{u}$?
\end{example}

\begin{solution}
Write $\vect{u}=t_1\vect{x}_1 + t_2\vect{x}_2 +\ldots +t_k\vect{x}_k$
for some $t_1, t_2, \ldots, t_k\in\R$
(this is possible because
$\vect{x}_1, \vect{x}_2, \ldots, \vect{x}_k$ span $\R^n$).

Then
\begin{eqnarray*}
\norm{\vect{u}}^2 & = & \vect{u}\dotprod\vect{u} \\
& = & \vect{u}\dotprod(t_1\vect{x}_1 + t_2\vect{x}_2 +\ldots +t_k\vect{x}_k) \\
& = & \vect{u}\dotprod (t_1\vect{x}_1) +  \vect{u}\dotprod (t_2\vect{x}_2) +
\ldots +  \vect{u}\dotprod (t_k\vect{x}_k) \\
& = & t_1(\vect{u}\dotprod \vect{x}_1) + t_2(\vect{u}\dotprod \vect{x}_2) + \ldots
+ t_k(\vect{u}\dotprod \vect{x}_k) \\
& = & t_1(0) + t_2(0) + \ldots + t_k(0) = 0.
\end{eqnarray*}
Since $\norm{\vect{u}}^2 =0$, $\norm{\vect{u}} =0$.
We know that $\norm{\vect{u}}=0$ if and only if
$\vect{u}=\vect{0}_n$.
Therefore, $\vect{u}=\vect{0}_n$.
In conclusion, the only vector orthogonal to every vector of
a spanning set of $\R^n$ is the zero vector.
\end{solution}

We can now discuss what is meant by an orthogonal\index{orthogonal} set of vectors.

\begin{definition}{Orthogonal set of vectors}{orthogonal-set}
Let $\set{\vect{u}_1, \vect{u}_2,\ldots, \vect{u}_m}$ be a set of
vectors in $\R^n$. Then this set is called an
\textbf{orthogonal set}\index{orthogonal}\index{vector!orthogonal}
if the following conditions hold:
\begin{enumerate}
\item
$\vect{u}_i \dotprod \vect{u}_j = 0$ for all $i \neq j$
\item
$\vect{u}_i \neq \vect{0}$ for all $i$
\end{enumerate}
\end{definition}

If we have an orthogonal set of vectors and normalize each vector so
they have length 1, the resulting set is called an \textbf{orthonormal
set} of vectors. They can be described as follows.

\begin{definition}{Orthonormal set of vectors}{orthonormal-set-vectors}
A set of vectors, $\set{\vect{w}_{1},\ldots,\vect{w}_{m}} $
is said to be an
\textbf{orthonormal}\index{orthonormal}\index{vector!orthonormal}
set if
\[
\vect{w}_i \dotprod \vect{w}_j = \delta _{ij} = \left\{
\begin{array}{c}
1\text{ if }i=j \\
0\text{ if }i\neq j
\end{array}
\right.
\]
\end{definition}

Note that all orthonormal sets are orthogonal, but the reverse is not
necessarily true since the vectors may not be normalized. In order to
normalize the vectors, we simply need divide each one by its length.

\begin{definition}{Normalizing an orthogonal set}{normalizing}
Normalizing an orthogonal set is the process of
turning an orthogonal (but not orthonormal) set into
an orthonormal set.
If $\set{\vect{u}_1, \vect{u}_2, \ldots, \vect{u}_k}$
is an orthogonal subset of $\R^n$,
then
\[ \set{
\frac{1}{\norm{\vect{u}_1}}\vect{u}_1,
\frac{1}{\norm{\vect{u}_2}}\vect{u}_2, \ldots,
\frac{1}{\norm{\vect{u}_k}}\vect{u}_k }
\]
is an orthonormal set.
\end{definition}

We illustrate this concept in the following example.

\begin{example}{Orthonormal set}{orthonormal-set}
Consider the set of vectors  given by
\[
\set{\vect{u}_1, \vect{u}_2 } = \set{
\begin{mymatrix}{c}
1 \\
1
\end{mymatrix},
\begin{mymatrix}{r}
-1 \\
1
\end{mymatrix}
}
\]
Show that it is an orthogonal set of vectors  but not an orthonormal one. Find the corresponding orthonormal set.
\end{example}

\begin{solution}
One easily verifies that $\vect{u}_1 \dotprod \vect{u}_2 = 0$ and
$\set{\vect{u}_1, \vect{u}_2 }$ is an orthogonal set of
vectors. On the other hand one can compute that $\norm{\vect{u}_1}= \norm{\vect{u}_2} =
\sqrt{2} \neq 1$ and thus it is not an orthonormal set.

Thus to find a corresponding orthonormal set, we simply need to
normalize each vector. We will write $\set{\vect{w}_1, \vect{w}_2}$
for the corresponding orthonormal set. Then,
\begin{eqnarray*}
\vect{w}_1 &=& \frac{1}{\norm{\vect{u}_1}} \vect{u}_1\\
&=& \frac{1}{\sqrt{2}} \begin{mymatrix}{c}
1 \\
1
\end{mymatrix} \\
&=&
\begin{mymatrix}{c}
\vspace{0.05in} \frac{1}{\sqrt{2}}\\
\vspace{0.05in}\frac{1}{\sqrt{2}}
\end{mymatrix}
\end{eqnarray*}

Similarly,
\begin{eqnarray*}
\vect{w}_2 &=& \frac{1}{\norm{\vect{u}_2}} \vect{u}_2\\
&=& \frac{1}{\sqrt{2}} \begin{mymatrix}{r}
-1 \\
1
\end{mymatrix} \\
&=&
\begin{mymatrix}{r}
\vspace{0.05in} -\frac{1}{\sqrt{2}}\\
\vspace{0.05in}\frac{1}{\sqrt{2}}
\end{mymatrix}
\end{eqnarray*}

Therefore the corresponding orthonormal set is
\[
\set{\vect{w}_1, \vect{w}_2 } =
\set{
\begin{mymatrix}{c}
\vspace{0.05in} \frac{1}{\sqrt{2}}\\
\vspace{0.05in}\frac{1}{\sqrt{2}}
\end{mymatrix},
\begin{mymatrix}{r}
\vspace{0.05in} -\frac{1}{\sqrt{2}}\\
\vspace{0.05in}\frac{1}{\sqrt{2}}
\end{mymatrix}
}
\]

You can verify that this set is orthogonal.
\end{solution}

Consider an orthogonal set of vectors in $\R^n$, written $\set{
\vect{w}_1,\ldots, \vect{w}_k}$ with $k \leq n$. The span of these
vectors is a subspace $W$ of $\R^n$. If we
could show that this orthogonal set is also linearly independent, we
would have a basis of $W$. We will show this in the next theorem.

\begin{theorem}{Orthogonal basis of a subspace}{orthonormal-basis}
Let $ \set{\vect{w}_1, \vect{w}_2,\ldots, \vect{w}_k}$ be an
orthonormal set of vectors in $\R^n$. Then this set is
linearly independent and forms a basis for the subspace $W =
\sspan \set{\vect{w}_1, \vect{w}_2,\ldots, \vect{w}_k}$.
\end{theorem}

\begin{proof}
To show it is a linearly independent set, suppose a linear combination
of these vectors equals $\vect{0}$, such as:
\[
a_1 \vect{w}_1 + a_2 \vect{w}_2 + \ldots + a_k \vect{w}_k = \vect{0}, a_i \in \R
\]
We need to show that all $a_i = 0$. To do so, take the dot product of
each side of the above equation with the vector $\vect{w}_i$ and obtain the following.

\begin{eqnarray*}
\vect{w}_i \dotprod (a_1 \vect{w}_1 + a_2 \vect{w}_2 + \ldots + a_k \vect{w}_k ) &=& \vect{w}_i \dotprod \vect{0}\\
a_1 (\vect{w}_i \dotprod \vect{w}_1) + a_2 (\vect{w}_i \dotprod \vect{w}_2) + \ldots + a_k (\vect{w}_i \dotprod \vect{w}_k)  &=& 0
\end{eqnarray*}
Now since the set is orthogonal, $\vect{w}_i \dotprod \vect{w}_m = 0$ for all $m \neq i$, so we have:
\[
a_1 (0) + \ldots + a_i(\vect{w}_i \dotprod \vect{w}_i) + \ldots + a_k (0) = 0
\]
\[
a_i \norm{\vect{w}_i}^2 = 0
\]

Since the set is orthogonal, we know that $\norm{\vect{w}_i}^2  \neq 0$. It follows that $a_i =0$. Since the $a_i$ was chosen arbitrarily, the set $\set{\vect{w}_1, \vect{w}_2,\ldots, \vect{w}_k}$ is linearly independent.

Finally since $W = \mbox{span} \set{\vect{w}_1, \vect{w}_2,\ldots,
\vect{w}_k}$, the set of vectors also spans $W$ and therefore forms a basis of $W$.

\end{proof}

If an orthogonal set is a basis for a subspace, we call this an
orthogonal basis. Similarly, if an orthonormal set is a basis, we call
this an orthonormal basis.

We conclude this section with a discussion of Fourier expansions. Given any orthogonal basis $B$ of $\R^n$ and an arbitrary vector $\vect{x} \in \R^n$, how do we express $\vect{x}$ as a linear combination of vectors in $B$? The solution is Fourier expansion.

\begin{theorem}{Fourier expansion}{fourier-expansion}
Let $V$ be a subspace of $\R^n$ and suppose $\set{\vect{u}_1, \vect{u}_2, \ldots, \vect{u}_m}$
is an orthogonal basis of $V$.
Then for any $\vect{x}\in V$,
\[ \vect{x} =
\paren{\frac{\vect{x}\dotprod \vect{u}_1}{\norm{\vect{u}_1}^2}} \vect{u}_1 +
\paren{\frac{\vect{x}\dotprod \vect{u}_2}{\norm{\vect{u}_2}^2}} \vect{u}_2 +
\ldots +
\paren{\frac{\vect{x}\dotprod \vect{u}_m}{\norm{\vect{u}_m}^2}} \vect{u}_m.
\]
This expression is called the Fourier expansion
of $\vect{x}$, and
\[ \frac{\vect{x}\dotprod \vect{u}_j}{\norm{\vect{u}_j}^2},\]
$j=1,2,\ldots,m$
are the Fourier coefficients.
\end{theorem}

Consider the following example.

\begin{example}{Fourier expansion}{fourier}
Let
$\vect{u}_1= \begin{mymatrix}{r} 1 \\ -1 \\ 2 \end{mymatrix},
\vect{u}_2= \begin{mymatrix}{r} 0 \\ 2 \\ 1  \end{mymatrix}$,
and
$\vect{u}_3 =\begin{mymatrix}{r} 5 \\ 1 \\ -2 \end{mymatrix}$,
and let
$\vect{x} =\begin{mymatrix}{r} 1 \\ 1 \\ 1 \end{mymatrix}$.

Then $B=\set{\vect{u}_1, \vect{u}_2, \vect{u}_3}$
is an orthogonal basis of $\R^3$.

Compute the Fourier expansion of $\vect{x}$, thus writing $\vect{x}$ as  a linear combination of the vectors of $B$.
\end{example}

\begin{solution}
Since $B$ is a basis (verify!) there is a unique way to express $\vect{x}$ as a
linear combination of the vectors of $B$. Moreover since $B$ is an
orthogonal basis (verify!), then this can be done by computing the
Fourier expansion of $\vect{x}$.

That is:

\[
\vect{x}   =
\paren{\frac{\vect{x}\dotprod \vect{u}_1}{\norm{\vect{u}_1}^2}} \vect{u}_1 +
\paren{\frac{\vect{x}\dotprod \vect{u}_2}{\norm{\vect{u}_2}^2}} \vect{u}_2 +
\paren{\frac{\vect{x}\dotprod \vect{u}_3}{\norm{\vect{u}_3}^2}} \vect{u}_3.
\]

We readily compute:

\[
\frac{\vect{x}\dotprod\vect{u}_1}{\norm{\vect{u}_1}^2} = \frac{2}{6}, \;
\frac{\vect{x}\dotprod\vect{u}_2}{\norm{\vect{u}_2}^2} = \frac{3}{5},
\mbox{ and }
\frac{\vect{x}\dotprod\vect{u}_3}{\norm{\vect{u}_3}^2} = \frac{4}{30}.\]

Therefore,
\[ \begin{mymatrix}{r} 1 \\ 1 \\ 1 \end{mymatrix}
= \frac{1}{3}\begin{mymatrix}{r} 1 \\ -1 \\ 2 \end{mymatrix}
+\frac{3}{5}\begin{mymatrix}{r} 0 \\ 2 \\ 1  \end{mymatrix}
+\frac{2}{15}\begin{mymatrix}{r} 5 \\ 1 \\ -2 \end{mymatrix}.\]
\end{solution}


\section{The \lowerbound algorithm}
\Label{sec:lowerbound}

The \lowerbound algorithm is one of the four binary search algorithms
of the \cxx Standard Library \cite[\S 28.7.3.1]{cxx-17-draft}.
For our purposes we have modified
the generic implementation
to that of an array of type \valuetype.
The signature now reads:

\begin{lstlisting}[style = acsl-block]

  size_type
  lower_bound(const value_type* a, size_type n, value_type v);
\end{lstlisting}

As with the other binary search algorithms \lowerbound requires that
its input array is in increasing order.
The index~\inl{lb}, that \lowerbound returns satisfies the inequality

\begin{align}
\Label{eq:lower-bound-result}
0 \leq \mathtt{lb} \leq n
\end{align}

and has the following properties for a valid index~\inl{k} of the array under consideration

\begin{alignat}{3}
\Label{eq:lower-bound-left}
0 &\leq k < \mathtt{lb} && \qquad\Longrightarrow\qquad && a[k] < \mathtt{v} \\
\Label{eq:lower-bound-right}
\mathtt{lb} &\leq k < n && \qquad\Longrightarrow\qquad && \mathtt{v} \leq a[k]
\end{alignat}

Conditions~\eqref{eq:lower-bound-left} and~\eqref{eq:lower-bound-right} imply that~\inl{v}
can only occur in the array section \inl{a[lb..n-1]}.
In this sense \lowerbound returns a \emph{lower bound} for the potential indices.

As an example, we consider in Figure~\ref{fig:lowerbound} an increasingly ordered array.
The arrows indicate which indices will be returned by \lowerbound for a given value.
Note that the index~9 points \emph{one past end} of the array.
Values that are not contained in the array are colored in gray.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.60\textwidth]{Figures/lower_bound.pdf}
\caption{\Label{fig:lowerbound}Some examples for \lowerbound}
\end{figure}

%\FloatBarrier

Figure~\ref{fig:lowerbound} also clarifies that care must
be taken when interpreting the return value of \lowerbound.
%
An important difference to the algorithms in Chapter~\ref{cha:non-mutating}
is that a return value of \lowerbound that is less than~$n$
does not necessarily implies \inl{a[lb] == v}.
We can only be sure that \inl{v <= a[lb]} holds.

\subsection{Formal specification of \lowerbound}

The specification of \specref{lowerbound} is shown in the following listing.
The preconditions \inl{increasing} expresses
that the array values need to be in increasing order.
%
The postconditions reflect the conditions listed above and can be expressed
using the predicates \logicref{LowerBound} and \logicref{StrictUpperBound}.

\begin{itemize}
\item Condition~\eqref{eq:lower-bound-result} becomes postcondition \inl{result}
\item Condition~\eqref{eq:lower-bound-left} becomes postcondition \inl{left}
\item Condition~\eqref{eq:lower-bound-right} becomes postcondition \inl{right}
\end{itemize}

\input{Listings/lower_bound.h.tex}

\subsection{Implementation of \lowerbound}
\Label{subsec:lowerbound:impl}

The following listing shows our implementation of \implref{lowerbound}.
Each iteration step narrows down the range that contains the
sought-after result.
The loop invariants express that in each iteration step all indices
less than the temporary left bound
\inl{left} contain values that are less than \inl{v} and all indices
not less than the temporary right bound \inl{right} contain values
that are greater or equal than \inl{v}.
%
The expression to compute \inl{middle} is slightly more complex than the
naïve \inl{(left+right)/2}, but it avoids potential overflows.

\input{Listings/lower_bound.c.tex}


\subsection{Data Preparation} \label{data_preparation}

All of our data records are resampled and quantized before further analysis. In general, dimensionality and cardinality reduction of time series is performed to ease and accelerate data processing by providing a more compact representation of equidistant measurements \cite{liu2009uwave}.

\paragraph{Resampling:} The recorded acceleration data was resampled by means of the moving average technique, using a window size of 50 ms and step size of 30 ms.

\paragraph{Quantization:} The resampled records were then converted into time series with integer values between -16 and 16, such as suggested in related work \cite{liu2009uwave} and summarized in table \ref{table:conversion}.

\begin{table}
    \begin{center}
        \begin{tabularx}{\textwidth}{XX}
            \hline
            \textbf{Acceleration data ($a$) in $\frac{dm}{s^2}$} & \textbf{Converted value}\\
            \hline
            $a > 200$ & 16\\
            $100 < a < 200$ & 11 to 15 (five levels linearly)\\
            $0 < a < 100$ & 1 to 10 (ten levels linearly)\\
            $a = 0$ & 0\\
            $-100 < a < 0$ & -1 to - 10 (ten levels linearly)\\
            $-200 < a < -100$ & -11 to - 15 (five levels linearly)\\
            $a < -200$ & -16\\
            \hline
        \end{tabularx}
    \end{center}
    \caption{Conversion of recorded acceleration data from $\frac{dm}{s^2}$ scale to integer values.}
	\label{table:conversion}
\end{table}


\section{Exercise 03}
\subsection{}

\begin{frame}
\frametitleTC{Problem}
\framesubtitleTC{This one we solve together}
 Given the two DT LTI dynamic systems
 \begin{displaymath}
  S_1:
  \left\{\begin{array}{rcl}
   x_1(k) &=& 0.5x_1(k-1)+u(k-1)\\
   x_2(k) &=& 0.5x_2(k-1)+u(k-1)\\
   y(k)   &=& x_1(k)+x_2(k)
  \end{array}\right. \quad
  S_2:
  \left\{\begin{array}{rcl}
   x_1(k) &=& 0.4x_1(k-1)+u(k-1)\\
   x_2(k) &=& 0.8x_2(k-1)+u(k-1)\\
   y(k)   &=& x_2(k)
  \end{array}\right.
 \end{displaymath}

 \begin{itemize}[<+-| alert@+>]
 \item[(a)] compute their transfer functions,
 \item[(b)] comment on the result.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Solution}
\framesubtitleTC{Item (a)}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item We start with $S_1$:
       \begin{itemize}
       \item[] \begin{itemize}[<+-| alert@+>]
               \item[$G(z)$] \vspace{1mm}
                    $= \begin{bmatrix} 1 & 1  \end{bmatrix} \,
                       \begin{bmatrix} z-0.5 & 0 \\
                                       0     & z-0.5 \end{bmatrix}^{-1} \,
                       \begin{bmatrix} 1 \\ 1 \end{bmatrix}
                       +0
                    $
               \item[] \vspace{1mm}
                    $= \cfrac{1}{(z-0.5)^2}
                       \begin{bmatrix} 1 & 1 \end{bmatrix} \,
                       \begin{bmatrix} z-0.5 & 0 \\
                                       0     & z-0.5 \end{bmatrix} \,
                       \begin{bmatrix} 1 \\ 1 \end{bmatrix}
                    $
               \item[] \vspace{1mm}
                    $= \cfrac{1}{(z-0.5)^2}
                       \begin{bmatrix} z-0.5 & z-0.5 \end{bmatrix} \,
                       \begin{bmatrix} 1 \\ 1 \end{bmatrix}
                    $
               \item[] \vspace{1mm}
                    $= \cfrac{2\cancel{(z-0.5)}}{(z-0.5)^{\cancel{2}}} \qquad \qquad
                       \TC{\leftarrow \text{zero/pole \underline{cancellation}}}
                    $
               \item[] \vspace{1mm}
                    $= \cfrac{2}{z-0.5}.
                    $
               \end{itemize}
       \end{itemize}
 \end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitleTC{Solution}
\framesubtitleTC{Item (a)}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item And now $S_2$:
       \begin{itemize}
       \item[] \begin{itemize}[<+-| alert@+>]
               \item[] wxMaxima, we are lazy \smiley
                       \begin{verbatim}
A:matrix([0.4,0],[0,0.8]);
b:matrix([1],[1]);
c:matrix([0,1]);
G:c.invert(z*ident(2)-A).b;
                       \end{verbatim}
               \item[] \vspace{1mm}
                    $ G(z) = \cfrac{1}{z-0.8}.
                    $
               \end{itemize}
               \item \vspace{3mm}Another case with cancellation: the characteristic polynomial of $A$\\
                     has degree 2, the denominator of $G(z)$ has degree 1.
       \end{itemize}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Solution}
\framesubtitleTC{Item (b) -- comments on the $S_1$ case}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item In fact $S_1$ is a ``fake'' 2nd order system, since as far as induced motions are\\
       concerned  $x_1$ and $x_2$ are the same, and the system is \TC{input-output} (i.e, as far\\
       as we only look at $u$ and $y$) \TC{equivalent} to a 1st order one:
       \begin{displaymath}
        \left\{\begin{array}{rcl}
         x_1(k) &=& 0.5x_1(k-1)+u(k-1)\\
         x_2(k) &=& 0.5x_2(k-1)+u(k-1)\\
         y(k)   &=& x_1(k)+x_2(k)
        \end{array}\right. \quad
        \Rightarrow \quad
        \left\{\begin{array}{rcl}
         x(k) &=& 0.5x(k-1)+u(k-1)\\
         y(k) &=& 2x(k)
        \end{array}\right.
        \end{displaymath}
        apparently with
        \begin{displaymath}
         G(z)=\cfrac{2}{z-0.5}.
        \end{displaymath}
 \item This system cannot move in the whole $(x_1,x_2)$ plane, but only\\
       on the straight line $x_1=x_2$.
 \item In general, systems like this can only move on a \TC{subspace} (line)\\
       of their \TC{state space} (plane).
 \item We call them \TC{not fully reachable} (the term should be intuitive).
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Solution}
\framesubtitleTC{Item (b) -- comments on the $S_2$ case}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Also $S_2$ is a ``fake'' 2nd order system, because however $x_1$ moves, $y$ does not
       reveal this, and thus we can reduce this system as well to a 1st order one:
       \begin{displaymath}
        \left\{\begin{array}{rcl}
         x_1(k) &=& 0.4x_1(k-1)+u(k-1)\\
         x_2(k) &=& 0.8x_2(k-1)+u(k-1)\\
         y(k)   &=& x_2(k)
        \end{array}\right. \quad
        \Rightarrow \quad
        \left\{\begin{array}{rcl}
         x(k) &=& 0.8x(k-1)+u(k-1)\\
         y(k) &=& x(k)
        \end{array}\right.
        \end{displaymath}
        apparently with
        \begin{displaymath}
         G(z)=\cfrac{1}{z-0.8}.
        \end{displaymath}
 \item In this system one state variable does not influence the output.
 \item We call such systems \TC{not fully observable} (the term should be\\
       once again intuitive).
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Proposed exercise 03}
\framesubtitleTC{Try this at home, ask questions next time if needed}
\myPause
 Take the two system of exercise 03, and turn them into block diagrams.\\
 \vspace{5mm}Analyse those diagrams along the idea that parts of the system are not influenced
 by the input, or do not influence the output.
\end{frame}

\begin{frame}
\frametitleTC{Takeaways}
\framesubtitleTC{from exercise 03 (and the proposed one)}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item There are cases in which a system cannot move in all its state space, or equivalently,
       some state variables are not influenced by the input.
 \item Suggestion for reflections: why ``equivalently''?
 \item There are also cases in which some state variables do not influence the output.
 \item There are also cases where both facts occur.
 \item We detect this because in computing the transfer function we get\\
       \TC{cancellations}.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Takeaways}
\framesubtitleTC{from exercise 03 (and the proposed one)}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Do we need to bother?
 \item Yes, because this collectively means that a system may have \TC{hidden parts}\\
       (things the transfer function does not tell).
 \item In setting up controls, we must be careful to not generate UNSTABLE hidden parts.
 \item We do not mind about asymptotically stable ones, because their effect\\
       vanishes with their free motion.
 \end{itemize}
\end{frame}


\Lecture{Jayalal Sarma }{ 2 october, 2020}{11}{More on PIE, PIE -Tuttes-Matrix-Tree-Theorem-Part2}{Shrinidhi Bajpayee}{$\alpha$}{JS}

\section{Introduction}
We finished Tutte's Matrix Tree Theorem in non trivial way.Let's just recall Tutte's Theorem.We have directed graph $G(V,E)$.We have $V={v_1,v_2,....v_n}$.\\
A $n \times n$ matrix $L(G)$ called the \textit{Laplacian matrix} of $G$ as follows.
\[
  L(G)_{ij} =
  \begin{cases}
    indeg(v_i) & \mbox{ if } i = j \\
    -1   & \mbox{ if }~ i \neq j ~\text{and}~(v_i,v_j)\in E \\
    0    & \mbox{ otherwise (When there is no edge) }
  \end{cases}
\]
What theorem says,the number of spanning arborescences rooted at some vertex n is given by exactly equal to $det(L_G[i])$ Here i=n.\\
Quickly Recap Definition of Spanning arborescences :An \textit{Arborescence} is a directed graph in which a vertex $u$ is called the root and for every other vertex $v$ in the graph, there is exactly one directed path from $u$ to $v$. In simpler terms, an arborescence is an directed tree in which all the edges are directed away from the root. A \textit{Spanning Arborescence} $S(V,E)$ of a directed graph $G(V',E')$ is an arborescence such that $V=V'$ and $E\subseteq E'$.\\
One condition is that there is a directed path from V to every vertex in G within E'.\\
Second condition is underlying undirected graph should be a tree. \\ \\
Recall the following from the last lecture.
\begin{align}
  det(L_G[n]) = \sum_{\sigma \in S_{n-1}}~
  Sign(\sigma)~\prod_{i=1}^{n-1}L_{i\sigma(i)}
  \label{eq:to_prove:Tutte}
\end{align} \\
$S(n-1)$ is notation for permutation of $n-1$.
This is expression of determinant that we have seen in last lecture.
So we want to show it is equal to spanning arborescence we introduce concept called Spreg.So what is Spreg $?$.
We quickly define Spreg.
\begin{definition}\textbf{Spregs:} Single prdecessor graphs or \textit{Spregs} with distinguished vertex $v$ of a directed graph $G(V,E)$ is a subgraph $T(V,E')$, $E' \subseteq E$, such that each vertex in $T$ except the vertex $v$ has exactly one predecessor and the vertex $v$ has no predecessors. In other words; in the spreg T, $indeg(v) = 0$ and for every $u \neq v$, $indeg(u)=1$.
\end{definition}
Every vertex other than distinguished vertex must be indegree 1.Subgraph of G is called Spregs.So there are several spregs are possible similar to several spanning arborescence possible.\\
We want to count spanning arborescence using spregs.That will be very nice combinatorial interpretation of this topic,that is plan.\\

%1. We want to count the number of spanning arborescence rooted at Vn.\\ \\
2.We want to count the number of spregs distinguished vertex Vn.\\
We associated with last lecture that every spanning arborescence corresponds to spregs .It turns out there are more spregs.There is some structure,Spregs looks like are of the form arborescence $+$ weekly connected component 1 $+$ weekly connected component 2......\\
V can not be part of cycle.V can be vertex in component.Weekly connecetd component has exactly 1 cycle.\\
So what we want to count spregs in inner circle with distinguished vertex Vn.Ok so already know what we have to count.Basic strategy is as follows:\\
Strategy is that count the number of spregs with distinguished vertex Vn which does not have any cycle.So this is what we want to count.We want to use Inclusion Exclusion.In fact we will not only count through Inclusion exclusion but we will go through each term of the determinant expression corresponds to our counting terms.\\
Let's demonstrate by writing down Inclusion exclusion.\\
In order to define Inclusion Exclusion formulation we need to define the \\ \\
1.Universe (Called as X).\\
2.Component $A_i$.\\
To define that Let's consider,notice that we want to count spregs without any cycle.\\
We need to be set of all spregs with distinguished vertex $V_n$.\\
Let $C_1,C_2,C_3, \dots , C_n$ be the set of cycles in graph G.We looking at simple cycle.\\
$A_i$ define as spregs which contain the cycle $C_1$.The number of spregs which does not contain any cycle.This what we want to count.So,\\

$|X|$ $-$ $|\bigcup_{i=1}^{n} A_i|$
It is same as,
$$|X| - \sum_{I \subseteq [n] , I \neq \emptyset} (-1)^{|I|+1}|\bigcap_{i \in I} A_i|$$
So already applied Inclusion Exclusion,Now write it as
$$ |X| + \sum_{I \subseteq [n] , I \neq \emptyset} (-1)^{|I|+1}|\bigcap_{i \in I} A_i| $$

So basically we need to count this.We can say that each term in these expression are exactly same as term used in determinant expression.As number of Spregs are equal to number of spanning arborescence,hence theorem is called.This is strategy.Hence each term is associated with terms of determinant theorem.\\
\textbf{Observation:}Let's consider C1,C2 be two cycles.\\
What can say about $$ A1 \bigcap A2 = \emptyset iff C1
  \bigcap C2 \neq \emptyset.$$\\
Every spregs looks like arborescence + uniquely weekly connected component 1 +uniquely weekly connected component 2.\\
$$ If C1 \bigcap C2 \neq \emptyset then |A1 \bigcap A2| =0.$$\\
Using the observation,\\
The number of spregs with distinguished vertex Vn which is acyclic is nothing but \\
$$ |X| + \sum_{I \subseteq [n] ,I \neq \emptyset ,for J,K \in I, J \neq K, cj \bigcap ck =\emptyset}       (-1)^{|I|+1}|\bigcap_{i \in I} A_i| $$

\textbf{Recall:} We counted |X| =Total number of spregs\\
$$det(L_G[n]) = \sum_{\sigma \in S_n} Sign(\sigma)  \prod_{i=1}^{n} a_{i\sigma(i)}$$\\
This is determinant expression. term   corresponds   to   $$ \sigma=id $$
$$\prod_{i=1}^{n-1} (L_i) = \prod_{i=1}^{n-1} deg_in(L_i) $$

Now we count the singleton sized I.
Spregs that contain exactly one cycle.
Fix,I={1},We are counting spregs which contain only C1.
Let  CI be (Vi1,Vi2,Vi3,....Vin)

$$\sigma(i1)=i2$$
$$\sigma(i2)=i3$$
$$\sigma(ik-1)=ik$$
$$\sigma(ik)=iI$$
$$\sigma \in S_n-1$$
$$\forall other  i \in {1...n} $$
$$ \sigma(i)=i $$

This is permutation which contain one cycle.
Now we just able to do following

\textbf{Claim:} Term in the determinant expression for
$$LG[n] corresponds to \sigma=number of spregs which contain C1$$
Right now we are talking about one circle.
Let's see proof of this.
Proof of this is very natural.

$$sign(\sigma)\prod_{i=1}^{n-1} L_i,\sigma(i   $$
sign of permutation is exactly equal to
$(-1)^{(l-1)} $.Here length is l.

Second term is
$$ (-1)^{(l-1)} (\prod_i,|\sigma(i)|=i L_i,i)(\prod_i,|\sigma(i)| \neq i L_i,\sigma(i)) $$
$$ L_i,\sigma(i) =-1,if V_i,V_\sigma(i) is edge in graph \in E\\ ootherwise  $$
If corresponding edge is present then this term is non zero otherwise zero.\\
$$ (-1)^{(l-1)}(\prod_i,|\sigma(i)| deg_in(v_i))*(-1)^{l} $$
$$= (-1)^{(2l-1)} |number of spregs which contain C1|  $$
$$= -|number of spregs which contain C1 | $$
Proposition for $$ \sigma \in S_n-1 comsisting of single cycle.   $$$$ \sigma =(i1,i2,.....il)   $$
Associate$ C\sigma $ as a cycle corresponds to vertex sequence (Vi1,Vi2,Vi3.....Vil,Vii)\\
Then the term in the determinant corresponds to $\sigma$ satisfies following.\\
$$sgn(\sigma)(\prod_{i=1}^{n-1}L_i,\sigma(i))$$

$$-(\prod_{i,\sigma(i)=i}deg_in(v_i))C_\sigma \subseteq G(V,E) $$\\
$$ 0 if C\sigma \nsubseteq G(V,E) $$ \\
$$-1  if C\sigma \subseteq G(V,E) if \forall i \sigma(i) \neq i     $$\\

\textbf{Corollary:}$$For \sigma,C\sigma as above $$\\
$$ |\prod_{i=1}^{n-1}L_i,\sigma(i)|=number of spregs which contain C_\sigma   $$\\
Now this is case for single cycle.\\Now we will generalise case for multiple cycle.\\
So it is very natural.

\textbf{Question:}Suppose $\sigma \in S_{n-1}$ is the product of $k>0$ disjoint cycle.
$$\sigma=(i11,i12,i13.....iil) (i21,i22,i23....(ikl,ik2,ik3...ikl)   $$
k is number of cycles. So now we are associate
$$ C_\sigma = \cup  {j=1}^{k}C_j  where C_j is (V_ij1....V_ijLj.....VijI)$$

Then the term  corresponds to $\sigma$ in $det(L_G[n])$
$$sgn(\sigma) = (-1)^{K} \prod_{i|\sigma(i)|}deg_in(V_i) if C_\sigma \subseteq G   $$\\
$$ o if C\sigma \nsubseteq G $$

\textbf{Corollary:}If we look at\\
$$|\prod_{i=1}^{n}L_i,\sigma(i)|=number of spregs which contain C_\sigma = \bigcup_{j=1}^{k}C_j   $$\\
$$ det(L_G[n]) =\sum_{\sigma \in S_n-1}sig(\sigma) \prod_{i=1}^{n} L_i\sigma      $$\\
This is how determinant expression looks like.\\
Number of spanning arborescence rooted at Vn  as distinguished vertex and not containing cycle.\\
%$$&=|X| + \sum_{I \subseteq [n] ,I \neq \emptyset, cj \bigcap   ck=\emptyset ,j,k \in I}(-1)^I    $$\\
This is strategy.
This lecture is combinatorial application of PIE.

\Lecture{Jayalal Sarma}{Oct 10, 2020}{12}{Algorithmic Application of PIE}{Shrinidhi Bajpayee}{$\alpha$}{JS}

\section{Introduction} We talk about counting problem.Its about given a $n*n$ bipartite graph,We want to count the number of perfect matching in it?\\
subset of edges such that every vertex has exactly one edge incident on it from the
subset.\\
Bipartite adjacency matrix is different from adjacency matrix.\\ \\
\textbf{Trivial Algorithm:}Run through all n sized subsets of E.\\
$${n^{2} \choose n } \sim {n^{2} \choose n}^{n}    \sim n^{n} \sim 2^{nlogn}$$\\

$$ {n \choose k}^{k} \leq {n \choose k} \leq {n_e \choose k}^{k} $$\\
e=natural log base \\
\section{Decision Problem:}
\textbf{Binpacking Problem:}
Given a positive integer (bin capacity B),positive integer k\\
We have n item with weight S1,S2,S3.....,Sn\\
partition the items into u1,u2,u3.....,uk\\
Capacity is such that sum of weights of items in each ui is almost B.\\
This is binpacking problem.\\
It is NP-problem.\\
By PIE Time complexity is $O(nB2^{n})$\\
n=number of items\\
B=capacity\\
Now we will reformulate PIE.\\

Given a collection of N combinatorial objects \\
Let p(1),p(2),p(3)...p(n) be properties.\\
$p_i$ is essential function \\
$$ N \to {0,1}   $$\\
It is possible that some object doesn't have properties of that.\\
$$N_i \to Number of objects among N with property P(i).$$\\
$$ {i_1,i_2,....i_r} \subseteq {1,2,3,...N} $$\\
$$N_{i_1,i_2,i_3....i_r} = Number of objects with properties p(i_1) p(i_2)....p(i_r) $$
N(0)=Number of objects not having any of the property.\\
$$ N(0)=N-\sum_{i=1}^{n} N_{i_1} +\sum_{i_1<i_2}N_{i_1,i_2} -\sum_{i_1 < i_2 <i_3}.......(-1)^{j} \sum_{i_1<i_2<...i_j}N_{i_1,i_2...i_j} (-1)^{x}N_1...r   $$\\
Restatement (Complementary term)(For the discussion)\\
$$N \to Number of objects.$$\\
$$Q(1),Q(2),....Q(n) $$be properties that some of these objects have.\\
$$W \subseteq {1,2,....n}  $$\\
Let N(W) be the number of objects having none of the properties Q(i).\\
$$i \in W   $$\\
Now what we want to count the other set.\\
$$X \to number of objects which has all the properties.$$\\
$$X = \sum_{W \subseteq [n]}(-1)^{|W|} N(W)   $$\\
\textbf{Pf:}$Define P(i) iff \neg Q(i)$\\
Now the above restatement is applicable.\\
Given a bipartite graph $G(u,v,E)\\
  |u|=|v|=n $\\
count the number of perfect matching.\\
\textbf{I/p:}Bipartite adjacency matrix.\\
\includegraphics{images/graph.jpg}\\ \\
There are 2 perfect matching is in these graph.\\
Matching 1: There is bijection.\\
There are 4!=24 permutation.But matching 1 and matching 2 are two permutation for perfect matching.\\
How's the algebric way of writing itself.\\
Let's write $\sigma \in S_n$ \\
Consider,\\
$$ \prod_{i=1}{n} a_i \sigma(i)$$\\
When $a_i \sigma_i$ is non zero value.
When $i\sigma _i$ is true.\\
$$\prod a_ii = a11 .a22 .a33. a44$$\\
$$ 1 $$\\
What will be product of \\
$$\prod_{i=1}{n} a_i \sigma(i) $$\\
$$ a12. a21.a33.a44  $$\\
$$ 0  $$\\
If corresponding edge is there in graph then value will be 1 otherwise 0.\\
a12=0 since no edge from 1 to 2.\\
Let's write,\\
Permanant of A=\\
$$ \sum_{\sigma \in S_n}  = Number of perfect matching in the graph.$$\\
Given a matrix A,\\
Its two types are:\\
!)permutataion (A) that is per(A): It is number of perfect matching in graph.\\
2)Determinant (A) that is det(A)\\
\\
\textbf{Problem:}Given a matrix A o/p the value of per(A)\\
\textbf{Trivial Algorithm:}Run over all $\sigma \in S_n$ compute the product \\
$$\prod_{i=1}{n}a_i \sigma(i)$$ and add.\\
$$O(n!) \sim O(n ^{n}) \sim 2^{nlogn} $$\\
\textbf{Lemma:}A is bipartite adjacency matrix of a bipartite graph G\\
$$Per(A) = \sum_{W \in {1...n}}(-1)^{|W|} \prod_{i=1}^{n}(\sum_{j \notin W}a_ij)$$\\
Applying Lemma, $2^{n}$ W's and $n^{2}=remaining Computation$\\
$2^{n}n^{2}$ time algorithm.\\
\textbf{PF:}To apply complementary form PIE.\\
Define N objects: $M \in N$\\
$M \subseteq E$ such that for  every \\
$\forall i \in {1...n}$ the vertex $X_i$ is the endpoint of some vertex in M.\\
$\forall j \in [n] Q(j)$: Vertex $Y_j$ is the endpoint of some vertex in M.\\
We want to count number of objects from underlined part which satisfies Q(1) .....Q(n)\\
The number of perfect matching=per(A)=number of objects which satisfies all of Q(1) Q(2)....Q(n)\\
Q(1) says first one is matched.\\
Q(2) says second one is matched.\\
Like this etc etc.\\
When all vertex are matched from both side.\\
$$ \sum_{W \in {1...n}}(-1)^{|W|}$$\\
N(W)=Number of objects which satisfies none of property in W.\\
\includegraphics{images/img.jpg}\\ \\
Per(A)=Number of perfect matching.\\
$$ \sum_{W \subseteq {1...n}}(-1)^{|W|}(\prod_{i=1}^{n}(\sum_{j \in w}aij)) $$\\
This completes the proof of the Lemma.\\
This lemma gives $O(2^{n}n^{2})$ algorithm for computing number of perfect matching in a given bipartite graph.\\

\textbf{Quickly Recap:}\\
\textbf{Binpacking problem:}\\
$Bin capacity B,We have number of bins K,We have n items S1....Sn are sizes.$
Question is Can we partition items to $u1....uk[n]$ such that
%$$\forall_{i\leq j \leq k} j\sum_{i \in u}Si \leq B}$$
  We want to count this.\\
  \textbf{Algorithm:}\\
  \textbf{Trivial Algorithm:}Run through partition.\\
$$ n \choose k$$\\
$O(nB2^{n})$ time space.\\
A partition of [n] into u1....uk is said to be feasible if the sum of the sizes of item $\leq$ B in uj.\\
\textbf{Relax:}Items can appear more than once.\\
\textbf{observation:}A feasible solution with relaxation will remain feasible without relaxation.\\
\textbf{Relaxed Solution:}ordered set of K lists of items from ${1...n}$.\\
1.Each of the elements in ${1...n}$ appears atleast in one list.\\
2.For each list $a1,a2....ap$
$$\sum_{h=1}{p}S_ak \leq B $$\\
To apply PIE,we need to define objects $Q1....$\\
\textbf{Objects:}Ordered sets of K list of elements from {1...n} such that for each list (a1...ap) $$\sum_{h=1}{p}S_an \leq B $$\\
Q(1):=The ordered list of k lists contain 1 in atleast one list in it.\\
.\\
.\\
.\\
Q(W):=W  is contained in atleast one of the lists in the ordered set of list.\\
.\\
.\\
.\\
Q(n)\\
X=Set of objects which satisfy all of the properties Q(1)....Q(n)\\
$$X=\sum_{w \subseteq [n]}(-1)^{|w|} N(W) $$\\
\textbf{Aim:}To compute N(W)\\
A(W):=Number of list a1....ap of elements list in W.\\
$$ \sum_{h=1}{p}S(an) \leq B $$\\
$$N(W)=(A(W))^{k}  $$\\
\textbf{Aim:}Compute A(W)\\
$P_w(j)$ =number of list a1....ap of which element not in w such that
$$\sum_{h=1}{p}S(ak)=j  $$\\
$$A(w)=\sum_{j=0}{B}P_w(j)$$\\
$$P_w(j)=\sum_{i \notin w}P_W(j-s(w)) $$\\
$$ p_W(j)=0, j<0 $$\\
$$P_w(0)=1 $$\\
Time taken is $O(nB2^{n})$

% Lecture 3

\Lecture{Jayalal Sarma}{Oct 10, 2020}{13}{From Principle of Inclusion-Exclusions to Mobius Inversion}{Sandip Saha}{$\alpha$}{JS}

% \section{Introduction}
The journey so far has been that we have started with pigeon hole principle and its applications then we used double counting and bijections to establish different identities then we moved to PIE and its different applications.
% Then we came to Principle of Inclusion-Exclusion(PIE) as a consequence of a bijection argument.
In this lecture, we will look at a more generalized version of PIE and move gradually towards the Mobius Inversion.

\subsection{PIE Revisited}
Previously we have used PIE to compute $\left| \bigcup^n _{i=n} A_i \right|$ as follows,
\[ \left| \bigcup^n _{i=n} A_i \right|=\sum_{\emptyset \neq I \subseteq [n]} (-1)^{|I|+1}\left|\bigcap_{i\in I} A_i\right|\]
Now, we are interested to compute $\left|\bigcap_{i=1}^n  \overline{A_i}\right|$, which can be rewritten as,
\begin{align}
  \left|\bigcap_{i=1}^n  \overline{A_i}\right| & = \left|
  \overline{\bigcup_{i=1}^n  A_i}
  \right| \nonumber \tag{using De-morgan's law}                                                                                \\
                                               & = \left| X \right| - \left| \bigcup^n _{i=n} A_i \right| \nonumber                                                \\
                                               & = \left| X \right| -\sum_{\emptyset \neq I \subseteq [n]} (-1)^{|I|+1}\left|\bigcap_{i\in I} A_i\right| \nonumber \\
                                               & = \sum_{ I \subseteq [n]} (-1)^{|I|}\left|\bigcap_{i\in I} A_i\right|
\end{align}

Note that $\bigcap_{i\in \emptyset} A_i =X$. This thing can also be stated in the following way.

\begin{theorem}
  Let $X$ be a finite set and $P_1,\dots, P_m$ properties. Further define for $S \subseteq [m]$ the set $N(S) = \{x\in X \mid \forall i \in S: x \text{ has property } P_i\}$  then, number of elements in $X$ satisfying none of the properties $P_1,\dots, P_m$ is given by,
  $$ \sum_{S \subseteq [m]} (-1)^{|S|} \left| N(S) \right|$$
\end{theorem}

\subsection{Stronger version of PIE}
The Inclusion-Exclusion Principle has a stronger version which is as follows.

\begin{theorem}[Stronger PIE]
  \label{stronger PIE}
  Let $f,g:2^{[n]}\longrightarrow \mathbb{R}$ are functions assigning real numbers to subsets of $[n]$ with the property that for any $A\subseteq [n]$

  \[ g(A)=\sum_{S\subseteq A} f(S)\]

  Then,
  \[ f(A) = \sum_{S \subseteq A} (-1)^{|A|-|S|}g(S)\]

\end{theorem}

\begin{proof}
  Let $f$ and $g$ are functions from the powerset of $[n]$ to real numbers and for all $A \subseteq [n]$
  \[g(A)=\sum_{S\subseteq A}f(S)\]

  \begin{align}
    \sum _{s\subseteq A}( -1)^{|A|-|S|} g( S) & =\sum _{s\subseteq A}( -1)^{|A|-|S|}\left(\sum _{T\subseteq A} f( T)\right) \nonumber \\
                                              & =\sum _{T\subseteq A} C_{T} f( T)
  \end{align}
  Where $C_T$ is appropriate signed number. Our aim is now to find $C_T$ for different $T$

  \begin{description}
    \item{\textbf{Case 1: }($T=A$)} $C_T=1$, since $f(A)$ is only encountered for $T=S=A$.

    \item{\textbf{Case 2: }($T \neq A$)} choosing a set between $T$ and $A$ is equivalent of choosing a set from $A\setminus T$
          \[C_T=\sum _{T \subseteq S\subseteq A}( -1)^{|A|-|S|}=\sum^k_{i=0}(-1)^{k-1} {k \choose i} =0 \]
  \end{description}
  This proves the claim.
  \[\boxed{\therefore f(A) =  \sum_{S \subseteq A} (-1)^{|A|-|S|}g(S)}\]
\end{proof}

\textbf{Why it is strong version?} it implies PIE.
Assume the strong version, we can derive PIE.
\begin{proof}
  Properties $P_1,\dots, P_m$ of elements of $X$ . $X_1,\dots, X_m$ are the subsets of $X$ satisfying the respective property i.e. $X_i=\{ x\in X \mid x \text{ satisfy } P_i\}$.
  then for $S \subseteq [m]$  we define $f(S)$ to be the number of elements in $X$ having all properties $P_i$ such that $i \notin S$ and none of the properties $P_j$ such that $ j \in S$ i.e.
  \[ f(S) = \left| \bigcap_{i\in [m] \setminus S} X_i \setminus \bigcup_{i\in S} X_i \right| \]
  We are interested in counting the number of elements in $X$ which does not satisfy any property in $P_1,\dots, P_m$ i.e. $f([m])$. We define,

  \begin{align*}
    g(A) & = \sum_{S\subseteq A} f(S)                         \\
         & = \left| \bigcap_{i \in [m] \setminus A}X_i\right| \\
         & = N([m]\setminus A)
  \end{align*}
  $g(A)$ counts $x\in X$ if the property that $x$ does not satisfy forms a subset of $A$. By \ref{stronger PIE}
  \begin{align*}
    f([m]) & = \sum_{S\subseteq [m]}(-1)^{m-|S|} g(S) \\
           & = \sum_{\substack{
    S'\subseteq [m]\setminus S                        \\
        S\subseteq [m]}}
    (-1)^{|S'|} N(S')                                 \\
           & = \sum_{S \subseteq [m]} (-1)^{|S|} N(S)
  \end{align*}
  This concludes the proof.
\end{proof}


\documentclass{article}
\usepackage{fullpage}
\usepackage{nopageno}
\begin{document}
\title{Section 1.1 Problems 2, 18, 26, 46}
\author{Jon Allen}
\date{September 4, 2013}
\maketitle
\section*{\#2}
Determine if each of the following equations is an ODE or a PDE. If the equation is an ODE, then determine (a) the order of the ODE and (b) if the equation is leinear or nonlinear.

$y\frac{\mathrm{d}y}{\mathrm{d}x}+y^4=\sin x$

The equation is an ODE of order one. It is nonlinear as neither the $y\frac{\mathrm{d}y}{\mathrm{d}x}$ term or the $y^4$ term fit the definition for linearity.
\section*{\#18}
Verify that the given function is a solution to the corresponding differential equation.

$\mathrm{d}y/\mathrm{d}x+xy=0$, $y(x)=e^{-x^2/2}$

We find $\frac{\mathrm{d}y}{\mathrm{d}x}=-xe^{-x^2/2}$. Substituting this result into the differential equation we find $-xe^{-x^2/2}+x\cdot e^{-x^2/2}=0$ which is true. The given function is a solution to the differential equation.
\section*{\#26}
Verify that the given function is a solution to the corresponding differential equation.

$y'''-2y''=0$, $y=A+Bt+Ce^{2t}$

We start by finding the first, second and third derivatives of $y$. $y'=B+2Ce^{2t}$, $y''=4Ce^{2t}$, $y'''=8Ce^{2t}$. Substituting $y'''$ and $y''$ into the differential we have $8Ce^{2t}-2\cdot4Ce^{2t}=0$. We see that the function $y$ is a solution to the differential equation regardless of the values of $A$, $B$, and $C$.
\section*{\#46}
Use the indicated conditions with the indicated solution to determine the solution to the given problem.

$\mathrm{d}y/\mathrm{d}t+y=\sin t$, $y(0)=-1$, $y(t)=Ae^{-t}-\frac{1}{2}\cos t+\frac{1}{2}\sin t$

First we substitute the initial value of $y(0)=-1$ into $y(t)$ to obtain $-1=Ae^0-\frac{1}{2}\cdot1+\frac{1}{2}\cdot0=A-\frac{1}{2}$ or $A=-\frac{1}{2}$. Our solution then is $y(t)=-\frac{1}{2}\left(e^{-t}+\cos t-\sin t\right)$
\end{document}


% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\markright{mexhat}
\section*{\hspace*{-1.6cm} mexhat}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Mexican hat wavelet in time domain.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
h = mexhat
h = mexhat(nu)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
        {\ty mexhat} returns the mexican hat wavelet, with central
        frequency {\ty nu} ({\ty nu} is a normalized frequency). Its
        expression writes
\[h(t)=\nu\ \frac{\sqrt{\pi}}{2}\ (1-2(\pi\nu t)^2)\ \exp[-(\pi\nu\ t)^2].\]

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}
Name & Description & Default value\\
\hline
        {\ty nu} & any real between 0 and 0.5         & {\ty 0.05} \\
 \hline {\ty h}  & time vector containing the mexhat samples\\
                 & {\ty length(h)=2*ceil(1.5/nu)+1}\\
\hline
\end{tabular*}

\end{minipage}
\vspace*{1cm}

{\bf \large \sf Example}
\begin{verbatim}
         plot(mexhat);
\end{verbatim}
\vspace*{.5cm}

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
klauder.
\end{verbatim}
\end{minipage}


\documentclass{scrartcl}

\input{../../shared.tex}

\begin{document}

\section*{Exercises on (quasi) Newton methods}

\paragraph{Exercise (i)} (2P) Show that Newton's method applied to a nondegenerate quadratic function yields a Quasi-Newton method.\\
\textbf{Bonus points:} Show that this is an \textit{if and only if}.

\paragraph{Exercise (ii)} (2P) Consider a step of the secant method:
        \begin{equation}
          x_{k+1} = x_k - f(x_k)\frac{x_k-x_{k-1}}{f(x_k)-f(x_{k-1})}.
        \end{equation}
        Assuming that $x_k\neq x_{k-1}$ and $f(x_k)\neq f(x_{k-1})$, prove that the line through the two points $(x_{k-1}, f(x_{k-1}))$ and $(x_k, f(x_k))$ intersects the $x$-axis at the point $x=x_{k+1}$.
\paragraph{Exercise (iii)} (6P) Complete the notebook.

\end{document}