\documentclass[main.tex]{subfiles}
\begin{document}

\subsection{Classical system with infinite DoF}

\marginpar{Sunday\\ 2020-5-3, \\ compiled \\ \today}

We move from a system of particles to a field, basically. We make the following substitutions:
\begin{enumerate}
    \item the coordinates \(q_{i}(t)\) become a field, a function of the coordinates \(\varphi (\vec{x}, t)\);
    \item sums over the coordinates, \(\sum _{i}\), become integrals in space: \(\int \dd[3]{x}\);
    \item the Lagrangian \(L(q_{i}, \dot{q}_{i})\) becomes a Lagrangian density \(\mathscr{L} (\varphi , \partial_{\mu } \varphi )\).
\end{enumerate}

The Lagrangian density is a function of position in space, we can recover the full Lagrangian by integrating:
%
\begin{align}
L(t) = \int \dd[3]{x} \mathscr{L}(\varphi (\vec{x}, t), \partial_{\mu } \varphi (\vec{x}, t))
\,.
\end{align}

The action is now a functional of the fields:
%
\begin{align}
S [ \varphi ] = \int \dd[4]{x} \mathscr{L} (\varphi, \partial_{\mu } \varphi )
\,,
\end{align}
%
where we integrate in spacetime since we must integrate in \(\dd[3]{x}\) to recover the Lagrangian, and then in time to recover the action from the Lagrangian.
Note that this yields a number as an output, and takes the whole field in spacetime as an input. As such, it is not a function of the spacetime coordinates.

The domain of integration is usually Minkowski spacetime with some boundary conditions at infinity: we assume that the fields and their derivatives vanish at infinity.

As in the finite DoF case, we stationarize the action and set \(\delta S =0\).
What does it mean to vary the field? We assume the variation to be ``synchronous'', that is,
%
\begin{align}
\varphi '(x) = \varphi (x) + \delta_0 \varphi (x)
\,,
\end{align}
%
so the point in spacetime is not affected: only the field changes.

The variation of the action is given by
%
\begin{subequations}
\begin{align}
\delta_0 S [\varphi ] &= S [ \varphi + \delta_0 \varphi ] - S[\varphi ]  \\
&= \int \dd[4]{x} \qty{ \mathscr{L} (\varphi + \delta_0 \varphi , \partial_{\mu } \varphi + \delta_0 \partial_{\mu } \varphi ) - \mathscr{L} (\varphi, \partial_{\mu } \varphi )}  \\
&= \int \dd[4]{x } \delta_0 \mathscr{L} (\varphi , \partial_{\mu }\varphi )  \\
&= \int \dd[4]{x}
\qty{ \pdv{\mathscr{L}}{\varphi } \delta_0 \varphi  + \pdv{\mathscr{L}}{\partial_{\mu } \varphi } \delta_0\partial_{\mu }  \varphi  }  \\
&= \int \dd[4]{x} \qty{\pdv{\mathscr{L}}{\varphi } - \partial_{\mu }\pdv{\mathscr{L}}{\partial_{\mu } \varphi }} \delta_0 \varphi
\,.
\end{align}
\end{subequations}

We integrated by parts, and the boundary term vanished because of our boundary conditions on the fields.
Also, we assumed that \(\delta_0 \qty(\dd[4]{x}) =0 \) in our second step.

In this case, like in the finite-DoF one, \(\qty[\partial_{\mu }, \delta_0 ] =0\).

Since \(\delta_0 S = 0\) must hold for all \(\delta_0 \varphi \), the rest of the integrand must be equal to zero: these are the Euler-Lagrange equations of the theory,
%
\begin{align}
\pdv{\mathscr{L}}{\varphi } - \partial_{\mu }\pdv{\mathscr{L}}{\partial_{\mu } \varphi } =0
\,.
\end{align}

\begin{claim}
Two Lagrangians which are equal up to the divergence of a function of the field, \(\partial_{\mu } k^{\mu }(\varphi )\), are equivalent (they have the same EL equations).
\end{claim}

\begin{proof}
We make this assumption, we can calculate the variation of the action we get after adding this term:
%
\begin{align}
\Delta S = \int \dd[4]{x} \partial_{\mu } k^{\mu }
\,,
\end{align}
%
so we can calculate this in a region whose radius we send to infinity. Properly speaking, our region should be in the form \(I \times B_R\), the product of an interval in time an a spere in space. We then apply the divergence theorem: the field \(\varphi \) goes to zero at infinity, so as long as \(k^{\mu }\) is regular it will tend to a constant value \(k^{\mu } (0)\), of which we must take the flux on a symmetric region: it will be zero.
\end{proof}

\subsection{Interlude: functional derivatives}

We define a space \(\varphi \) of smooth functions:
%
\begin{subequations}
\begin{align}
\varphi = \qty{
 f:
\left|
  \begin{array}{rcl}
    M_{4} & \longrightarrow & \mathbb{R} \text{ or } \mathbb{C} \\
    x & \longmapsto & f(x) \\
  \end{array}
\right.
}
\,,
\end{align}
\end{subequations}
%
and define \textbf{functionals} to be maps from \(\varphi \) to \(\mathbb{R}\) (or \(\mathbb{C}\)), so the space of functionals is the dual of \(\varphi \): a functional \(F\) is in the form
%
\begin{subequations}
\begin{align}
 F:
\left|
  \begin{array}{rcl}
    \varphi  & \longrightarrow & \mathbb{R} \text{ or } \mathbb{C}   \\
    f & \longmapsto & F[f] \\
  \end{array}
\right.
\,.
\end{align}
\end{subequations}

We are giving general definitions, but the case we will be interested in is usually the one of real-valued functionals.

We encountered two functionals so far: the Lagrangian is a functional of the field \(\varphi (\vec{x}, \overline{t})\) for a fixed \(\overline{t}\); the action is a functional of the field \(\varphi (x^{\mu })\).

We can vary a functional: if we are given a function \(g \in \varphi \), we can select a small perturbation \(\delta g\) so that we can define
%
\begin{align}
\delta S[g] =  \eval{\dv{}{\epsilon } S[g + \epsilon (\delta g )]}_{\epsilon =0}
= \eval{S[g + \delta g] - S[g]}_{\text{first order}}
\,.
\end{align}

The functional derivative of \(F[g]\), which is denoted by \(\fdv*{f}{g}\), is defined by the relation
%
\begin{align}
\delta F = \int \fdv{F}{g} \delta g \dd{x}
\,,
\end{align}
%
which should be interpreted as the functional analogue of the formula for the differential
%
\begin{align}
\dd{F} (x_{i}) = \sum _{i} \pdv{F}{x_{i}} \dd{x_{i}}
\,.
\end{align}

\begin{claim}
The functional derivative is indeed a derivative: it is linear
%
\begin{align}
\fdv{}{g} \qty(\alpha F + \beta  G) = \alpha \fdv{F}{g} + \beta \fdv{G}{g}
\,;
\end{align}
%
zero for constants: \(\fdv*{C}{g} = 0 \) if \(C[g] \equiv C \in \mathbb{R}\); and finally it satisfies the Leibniz rule:
%
\begin{align}
\fdv{}{g} \qty(FG)= \fdv{F}{g} G + F \fdv{G}{g}
\,.
\end{align}
\end{claim}

\begin{proof}
First of all, what to we mean by sum and product of functionals?
The intuitive definition to give is that the sum of two functionals \(F[g]\) and \(G[g]\) is the functional \(F+G\) such that \((F+G)[g] = F[g] + G[g]\).
For the product we adopt a similar definition.

Then, we get
%
\begin{subequations}
\begin{align}
\delta (\alpha F + \beta G)[g] &= \eval{\qty(\alpha F[g+ \delta g] + \beta G[g + \delta g]) - \qty(\alpha F[g] + \beta G[g])}_{\text{lin}}
\\
&= \alpha \eval{\qty(F[g + \delta g] - F[g])}_{\text{lin}} + \beta \eval{\qty(G [g + \delta g] - G[g])}_{\text{lin}}  \\
&= \alpha \delta F [g] + \beta \delta G[g]
\,.
\end{align}
\end{subequations}

For a constant we get \(C[g + \delta g] = C[g]\), so the differential is zero.

For the Leibniz rule, we have
%
\begin{subequations}
\begin{align}
\delta (FG)[g] &= F[g + \delta g] G[g + \delta g] - F[g] G[g]  \\
&=
\,,
\end{align}
\end{subequations}
%
\todo[inline]{To finish}

A reference: \cite[]{engelDensityFunctionalTheory2011}.
\end{proof}

A possible functional we can apply to smooth functions is the \emph{evaluation} functional: \(F_{\mathbb{1}}[g] = g(y )\); we can represent it as an integral by introducing the delta function,
%
\begin{align}
F_{\mathbb{1}} [g]  = \int \delta (x - y) g(x) \dd{x}
\,.
\end{align}
%
This is sometimes referred to as the \emph{identity functional}, since it does not alter the function beyond changing the name of the variable.

By the definition of the functional derivative, we find
%
\begin{align}
F_{\mathbb{1}} [g] = \int \delta (x-y) g(x) \dd{x} = \int \fdv{F_{\mathbb{1}}}{g} g(x) \dd{x}
\,,
\end{align}
%
so we must identify
%
\begin{align}
\fdv{F_{\mathbb{1}}}{g(x)} = \fdv{g(y)}{g(x)} = \delta (x -y )
\,.
\end{align}

In the 4D case we have, analogously:
%
\begin{align}
\fdv{\varphi (x^{\mu })}{ \varphi (y^{\mu })} = \delta^{(4)} (x^{\mu } - y^{\mu })
\,,
\end{align}
%
and if we fix one or more of the coordinates the dimension of the \(\delta \) function diminishes accordingly.

\begin{claim}
We can derive the Euler-Lagrange equations using functional derivatives.
\end{claim}

\todo[inline]{To finish}

\subsection{Hamiltonian formulation}

We define the \textbf{canonically conjugate momentum} as
%
\begin{align}
\pi (\vec{x}, t) = \fdv{L(t)}{\dot{\varphi}_{t} (\vec{x})} = \pdv{\mathscr{L}}{\partial_0 \varphi (\vec{x})}
\,,
\end{align}
%
so that we can introduce the Hamiltonian density via the Legendre transform:
%
\begin{align}
\mathscr{H} = \pi (\vec{x}, t) \partial_0 \varphi (\vec{x}, t) - \mathscr{L} (\varphi , \partial_{\mu } \varphi )
\,,
\end{align}
%
and the Hamiltonian as its integral
%
\begin{align}
H(t) = \int \dd[3]{x} \mathscr{H}
\,.
\end{align}

The Hamiltonian is a functional of the fields \(\pi \) and \(\varphi \):
%
\begin{align}
H(t) = H[\pi_{t}, \varphi_{t}]
\,.
\end{align}

\begin{claim}
We can calculate Hamilton's equations from the functional variation of \(H\): they read
%
\begin{align}
\dot{\varphi} (\vec{x}, t) = \fdv{H}{\pi_{t}(\vec{x})}
\qquad \text{and} \qquad
\dot{\pi}(\vec{x}, t) = - \fdv{H}{\varphi_{t}(\vec{x})}
\,.
\end{align}
\end{claim}

We can also write the HE with the Poisson brackets: the definition must however be adapted; it will read
%
\begin{align}
\qty{F, G}_{t} = \int \dd[3]{x} \qty(\fdv{F}{\varphi_{t}(\vec{x})} \fdv{G}{\pi_{t}(\vec{x})} - \fdv{F}{\pi_{t}(\vec{x})} \fdv{G}{\varphi_{t}(\vec{x})})
\,,
\end{align}
%

Then, Hamilton's equations will read
%
\begin{align}
\dot{\varphi}_{t} = \qty{\varphi, H}_{t}
\qquad \text{and} \qquad
\dot{\pi}_{t} = -\qty{\pi , H}(t)
\,.
\end{align}

The brackets of the fields \(\varphi \) and \(\pi \) are the same as in the finite-DoF case, substituting \(\delta_{j}^{i}\) with \(\delta^{(3)} (\vec{x}- \vec{y})\).

\end{document}


\documentclass{article}

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

\begin{document}

\section{Introduction}
\cite{Cohen+:doi:10.1080/10586458.2000.10504632}

\section{Wynn's $\epsilon$-algorithm}
Wynn \cite{Wynn:10.2307/2002183} developed the $\epsilon$-algorithm based on
Shanks' series. It goes as follows. Given a sequence of partial sums
$\{s_n\}$ with $n=1,2,\ldots,N$, define
\begin{align}
  \epsilon_{-1}(s_n) &= 0\,, &
  \epsilon_{0}(s_n) &= s_n\,.
\end{align}
Then,
\begin{align}
  \epsilon_{j+1}(s_n)
  &=
  \epsilon_{j-1}(s_{n+1})
  + \frac{1}{\epsilon_j(s_{n+1}) - \epsilon_j(s_n)}
\end{align}
for $j=0,1,2,\ldots$. The $\epsilon_{2j}(s_n)$ are approximations to the
series.

The $\epsilon$-table is of the form
\begin{align}
  \begin{matrix}
    %0 & s_0 & \epsilon_1(s_0) & \epsilon_2(s_0) & \epsilon_3(s_0) & \epsilon_4(s_0) & \ldots \\
    0 & s_1 & \epsilon_1(s_1) & \epsilon_2(s_1) & \epsilon_3(s_1) & \epsilon_4(s_1) & \ldots \\
    0 & s_2 & \epsilon_1(s_2) & \epsilon_2(s_2) & \epsilon_3(s_2) & \ldots & \ldots \\
    0 & s_3 & \epsilon_1(s_3) & \epsilon_2(s_3) & \ldots & \ldots & \ldots \\
    0 & s_4 & \epsilon_1(s_4) & \ldots & \ldots & \ldots & \ldots \\
    0 & s_5 & \ldots & \ldots & \ldots & \ldots & \ldots \\
    \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots \\
  \end{matrix}
\end{align}
The best approximations are usually taken to be $\epsilon_{2j}(s_1)$ for odd
$N$, or $\epsilon_{2j}(s_2)$ for even $N$.

To implement, we need two arrays for even and add $j$. To generte the next
$j$, we can overwrite the very first entry in the older array.

\bibliographystyle{plain}
\bibliography{refs/tandf_uexm209_3,refs/10.2307_2002183}

\end{document}

% vim: set sw=2 sts=2 et :


\documentclass[]{article}

\usepackage{pdfpages}

\begin{document}

A qualitative statement of the problem, for context:

\begin{quote}
An arbitrary waveform, given in the frequency domain as $F(\omega)$, propagates through a dispersive, lossy medium. It then drives a damped harmonic oscillator that is initially at rest. \\

What $F$ produces the peak {\it transient} amplitude on the oscillator?

\end{quote}

(this might be completely ill-posed or otherwise intractable - I grasp very little of the below, unfortunately)

\section{Zhu et al 's dispersive waveform optimization propagation formulation}

(there're lots of different approaches to this - Oughston's asympototic method, Macke and Segard - but this one seems sensible) \\

Zhu et al, in doi: 10.1109/APS.2012.6348428 offer a method to maximize the electric field $e_x(z,t)$, (see Franzen's fourier-transform method \\ http://www.dtic.mil/docs/citations/ADA371944)\\

Prof. Costas gave me a page (unpublished it seems) with more details - see the blue attached pdf.\\

Given

$$ e_x(z,t) = \frac{1}{\sqrt{2 \pi}} \int_{-\infty}^{+\infty}{F(\omega) e^{- j (\omega/c_0)n(\omega)z}\ e^{j\omega t} d\omega} $$

$$W = \frac{1}{\eta_0} \int_{-\infty}^{+\infty}{(n_r(\omega))\ |F(\omega)|^2}\ d\omega$$\\

Where $n(\omega)$ is a complex refractive index per Debye relaxation equation, $n_r()$ is the real part of the same, everything else is a real constant. Set up a functional with a lagrange multiplier\\

$$\xi = -e_x(z,t) + \lambda W$$\\

Take the functional ("variational") gradient with respect to $F(\omega)$.

$$ \nabla \xi = -\frac{1}{\sqrt{2\pi}} \left(e^{- j (\omega/c_0)n(\omega)z}\right)^\star \  e^{-j\omega T} + \lambda...$$

Where * is the complex conjugate.\\

The $\nabla H() = H()^\star$ thing seems to come from Franks, Signal Theory, 1969, page 140 onwards; I cannot make heads or tails of his formulation. \\

Neither Mathematica's VariationalD, Matlab's Fundiff, nor Maple's functionalDerivative seem to yield any meaningful result for grad xi.\\

Then set

$$\nabla \xi = 0$$

and solve for $F(\omega)$ normally. (then fourier transform back to $F(t)$, whatever)

\section{Harmonic oscillator Green's function}

From the below pdf, (renamed F(force) to $e_x$ to avoid confusion), where q is a charge, oscillation amplitude is

$$x(t) = \int_{-\infty}^{+\infty}{G(t,t')\ \frac{q\cdot e_x(z,t'))}{m}\ } dt'$$\\

Where G() is listed therein (eq. 15, for the underdamped case) (Keeping the Green function in the frequency-domain could maybe simplify things a bit? Wouldn't have to fourier-transform back and forth?)\\

Anyhow, then modify the lagrange multiplier,

$$\xi = -x(t) + \lambda W$$\\

And now,

$$\nabla \xi = 0$$

That seems to be the hard part.\\

How do you take the functional derivative of such an equation?

\includepdf[pages=-,pagecommand={}]{paper.pdf}

\includepdf[pages=-,pagecommand={}]{10_greens_function.pdf}

\end{document}


\documentclass[12pt]{article}
\author{David Alves}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{dirtytalk}
\usepackage{forest}
\usepackage{skak}
\usepackage{tikz}
\usepackage{titling}

\title{Math 142 Problem Set 3}
\author{David Alves}
\date{2016-09-13}

\begin{document}
\pagenumbering{gobble}

\begin{center}
\Large \thetitle \\
\large \theauthor \\
\thedate
\end{center}

\subsection*{Sources}

    \begin{itemize}
    \item Notes from lecture and my own memory from Math 42 for solving the problems
    \item http://tex.stackexchange.com and https://www.sharelatex.com for help with \LaTeX
    \item Wikipedia articles on equivalence relations.
    \end{itemize}

\section{Equivalence Relations and Partitions}

\subsection*{Problem Statement}
Show that there is a bijection between the set of (equivalence relations on a set $A$) and the set of (partitions of $A$).
\subsection*{Solution}

%{a b | c} <=> {(a,a), (b,b), (a,b), (b,a), (c,c)}

Let $P$ be a partition of $A$ and let $p_1, p_2, \ldots, p_n (n\geq 1)$ refer to the subsets in that partition. By the definition of a partition, each element of $A$ is contained in exactly one subset of $P$. Let $g(e) \in p_1, p_2, \ldots, p_n$ denote the subset that element $e$ is in.

Let $f(P)$ be the set of ordered pairs $\{(a, b) : g(a) = g(b)\}$. Note that $a$ and $b$ can be the same element in this definition. $f(P)$ is an equivalence relation, and $f$ is a bijection because it is both an injection and a surjection. Therefore there is a bijection between the set of (equivalence relations on a set $A$) and the set of (partitions of $A$).

\subsubsection*{Proof that $f(P)$ is an Equivalence Relation}
\begin{proof}
$f(P)$ is relation on $A\times A$ because it is a subset of $A\times A$ and satisfies the three requirements of an equivalence relation as follows:
\begin{itemize}
\item Reflexive property: $(e, e) \in f(P)$ for all $e \in A$. True because $g(e) = g(e)$.
\item Symmetric property: If $(a, b)$ is in $f(P)$, $(b, a)$ must be in $f(P)$ for all $a, b \in A$. True because if $g(a) = g(b)$, then $g(b) = g(a)$.
\item Transitive property: If $(a,b)$ and $(b,c)$ are in $f(P)$, then $(a,c)$ is in  $f(P)$. True because if $g(a) = g(b)$ and $g(b) = g(c)$, then $g(a)$ = $g(c)$.
\end{itemize}

\end{proof}
\subsubsection*{Proof that $f$ is an Injection}
\begin{proof}
Suppose that $f$ is not an injection. Then there must be some two partitions $a,b$ of $A$ such that $f(a) = f(b)$ and $a \neq b$. Since $a \neq b$, there must be some two elements $e_1, e_2$ such that they are in the same group in one partition and in different groups in the other partition. Without loss of generality, suppose $e_1, e_2$ are in the same group in $a$ and different groups in $b$. Then $(a,b) \in f(a)$ and $(a,b) \notin f(b)$, which contradicts our assumption. Therefore our assumption is incorrect and $f$ must be an injection.
\end{proof}
\subsubsection*{Proof that $f$ is a Surjection}
\begin{proof}
Suppose that $f$ is not a surjection. Then there must be some equivalence relation $R$ such that this is no corresponding partition $p$ where $f(p) = R$. Let two members $a, b \in A$ be part of the same \emph{equivalence class} if $(a, b) \in R$. Select an element $e_1 \in A$. Let $e_1, \ldots, e_k \in R$ be the $k$ members of $e_1$'s \emph{equivalence class}. We know that $(e_1, e_1) \in R$ because $R$ satisfies the reflexive property. $(e_1, e_i), (e_1, e_j) \in R: i,j \leq k$ by definition, therefore $(e_i, e_1) \in R: i \leq k$ due to the symmetric property and $(e_i, e_j) \in R: i,j \leq k$ due to the transitive property. Therefore every edge between elements in $e_1, \ldots, e_k$ exists.

There cannot be any edge $(f, e_i)$ or $(e_i, f) \in R$ such that $f \notin e_1, e_2, \ldots, e_k$ because $(e_1, f)$ would exist by the transitive property, therefore $f$ would be a member of $e_1$'s \emph{equivalence class}.

We can therefore construct a partition $p$ of $A$ such that $e_1, e_2, \ldots, e_k$ are in the same group. We know that all edges $(e_i, e_j): 1 \leq i, j \leq k$ exist in $f(p)$ and no edge $(f, e_i)$ or $(e_i, f)$ exists by the definition of $f$. Since we chose $e_1$ arbitrarily the same logic applies for all other groups. Therefore there exists a partition $p$ such that $f(p) = R$, which contradicts our assumption that $f$ is not a surjection. Therefore our assumption is false and $f$ is a surjection.
\end{proof}

\section{Amusement Park Counting}

There are $n$ couples. For each couple, there are two ways to select who sits on the left, giving $2^n$ choices by the product principle. For a roller coaster, there are $n!$ ways to order the couples in the cars, giving a total of $n!2^n$ arrangements. For a Ferris wheel, each arrangement of people is being overcounted $n$ times, one for each position that the Ferris wheel can be rotated into. Therefore we need to divide by $n$, giving a total of $(n-1)!2^n$ arrangements for a Ferris wheel.

\section{Binomial Coefficients}

\[
\sum_{\substack{k=0\\ \text{k odd}}}^{n}\binom{n}{k} =
\sum_{\substack{k=0\\ \text{k even}}}^{n}\binom{n}{k} =
\sum_{k=0}^{n-1}\binom{n}{k}
\]
\\
Below is an illustration to show why. $\sum_{k=0}^{n}\binom{n}{k}$ for alternate elements (either $k$ even or $k$ odd) is equal to the sum of the $\binom{n-1}{k}$ for all elements since each element on the $n-1$ row contributes to exactly one element on the following row (rather than both).

\begin{center}
\begin{tikzpicture}[
    scale=1,
    tcancel/.append style={draw=#1, cross out, inner sep=1pt}
]
\node at ( 0, 0) {1};
\node at (-1,-1) {1};
\node at ( 1,-1) {1};
\node at (-2,-2) {1};
\node at ( 0,-2) {2};
\node at ( 2,-2) {1};
\node at (-3,-3) {1};
\node at (-1,-3) {3};
\node at ( 1,-3) {3};
\node at ( 3,-3) {1};
\node at ( 0, -4.5) {$\vdots$};
\node at (-6, -6) {1};
\node at (-4.5, -6) {$\ldots$};
\node at (-3, -6) (up2l) {$\binom{n-1}{k-2}$};
\node at (-1, -6) (up1l) {$\binom{n-1}{k-1}$};
\node at ( 1, -6) (up1r) {$\binom{n-1}{k}$};
\node at ( 3, -6) (up2r) {$\binom{n-1}{k+1}$};
\node at ( 4.5, -6) {$\ldots$};
\node at ( 6, -6) {1};
\node at (-7, -7) {1};
\node at (-5.5, -7) {$\ldots$};
\node at (-4, -7) (main2l) {$\binom{n}{k-2}$};
\node [color=gray,tcancel=red]at (-2, -7) (main1l) {$\binom{n}{k-1}$};
\node at ( 0, -7) (maincc)  {$\binom{n}{k}$};
\node [color=gray,tcancel=red] at ( 2, -7) (main1r){$\binom{n}{k+1}$};
\node at ( 4, -7) (main2r){$\binom{n}{k+2}$};
\node at (5.5, -7) {$\ldots$};
\node at ( 7, -7) {1};
\draw [->, thick] (up2r)--(main2r);
\draw [->, thick] (up1r)--(maincc);
\draw [->, thick] (up1l)--(maincc);
\draw [->, thick] (up2l)--(main2l);
\end{tikzpicture}
\end{center}

\section{Card Counting}

% With n ranks and k suits, how many ways are there to make 3 of a kind with a set of 5 cards?
% What about two pair?
% Which one is more rare for a normal deck?
% Give a deck where the rarity is switched

With $n$ ranks and $k$ suits, there are $nk^2\binom{k}{3}\binom{n-1}{2}$ ways to make 3-of-a-kind and $(n-2)k\binom{n}{2}\binom{k}{2}^2$ ways to make two pair.

\subsection*{Three-of-a-kind}

Three-of-a-kind consists of three cards with identical rank and two cards which do not have that rank and do not share a rank with each other. There are $\binom{k}{3}$ ways to select the suits for the three cards and $n$ different possible ranks. There are $\binom{n-1}{2}$ ways to choose the ranks for the other two cards and $k$ possible suits for each of them. Therefore the total number of unique three-of-a-kind hands is
\[
nk^2\binom{k}{3}\binom{n-1}{2}
\]

\subsection*{Two Pair}
For two pair, there are $\binom{n}{2}$ ways to choose the ranks for the two pairs and $n-2$ possible ranks for the remaining card. There are $\binom{k}{2}$ ways to select the suits for each of the two pairs. Finally there are $k$ possible suits for the remaining card. Therefore the total number of unique two pair hands is
\[
(n-2)k\binom{n}{2}\binom{k}{2}^2
\]

\subsection*{Rarity}
Plugging in the numbers for a normal ($n=13, k=4$) deck gives 10816 possible three-of-a-kind hands and 123552 possible two pair hands, therefore three-of-a-kind is more rare.

The rarity is switched for a deck with $n=3$ and $k=10$ because there are 108,000 unique 3-of-a-kind hands and 60,750 unique two pair hands.

\section{Fixed Elements}

\subsection*{Involutions and Fixed Points}

% Prove that the number of non-fixed points in an involution is even
\begin{proof}
For each non-fixed element, we have $f(a) = a', a \neq a'$. Since $f$ is an involution, we also know that $f(a') = a$. We can remove $a$ and $a'$ from the domain and codomain of $f$ respectively to construct $f'$. Repeatedly applying the same process we will eventually construct a function consisting of only zero or more fixed elements. After this process is complete we will have removed two elements from the domain $k$ times, meaning $2k$ total non-fixed elements existed. Therefore the the number of non-fixed elements in $f$ is even.\end{proof}

\subsection*{Odd divisors}

Note: I'm assuming that the problem is asking for positive divisors although that was not explicitly stated.

Let $n$ be a positive integer and let $D$ be the set of integers that evenly divide $n$. $|D|$ is odd if and only if $n$ is a perfect square, that is if there is some positive integer $k$ such that $k^2 = n$.
\begin{proof}
For each element $e$ of $D$, there exists an element $e'$ of $D$ such that $e*e' = n$ since $D$ contains all integer divisors of $n$. For each $e \neq e'$ we have exactly one corresponding element, so the total size of such elements is even. If $n$ is a perfect square then $D$ also contains a single element $e$ such that $e^2=n$, and therefore $|D|$ is odd if and only if $n$ is a perfect square.
\end{proof}
\section{Time Spent}

I spent about ten hours on this assignment. Most of them were pretty straightforward but \#1 took a very long time to do rigorously. (Maybe there's some clever shortcut?)

\end{document}


\documentclass[a4paper,11pt,leqno,fleqn]{artikel3}

\usepackage[dvips]{color}
%\definecolor{backgray}{gray}{0.925}
%\definecolor{verylightgray}{gray}{0.95}

\usepackage{fullpage, fancyvrb, amssymb, listings, url}
%\usepackage[breqn, inline]{emaxima}
%\usepackage[cmbase]{flexisym}
%% \usepackage{breqn}
%% \setkeys{breqn}{compact}

\lstset{
  language={},
  keepspaces=true,
  xleftmargin=3mm,
  xrightmargin=3mm,
  basicstyle=\ttfamily,
  frame=tb,
  framesep=1mm,
  framerule=0.5pt,
  frameround=tttt,
  columns=flexible %,
  %backgroundcolor=\color[gray]{0.9}
}

\newcommand{\N}{\noindent}
\newcommand{\D}{\displaystyle}
\newcommand{\bc}{\begin{center}}
\newcommand{\ec}{\end{center}}
\newcommand{\bv}{\begin{verbatim}}
\newcommand{\ev}{\end{verbatim}}
\newcommand{\tr}[1]{\textcolor{red}{#1}}
\newcommand{\tb}[1]{\textcolor{blue}{#1}}
\newcommand{\rb}[1]{\raisebox{2mm}[0mm][1mm]{#1}}
\newcommand{\rbb}[1]{\raisebox{-4mm}[0mm][9mm]{#1}}

\title{Finite Fields Computations in Maxima}

\author{
\begin{tabular}{lr}  Fabrizio Caruso &  \url{caruso@dm.unipi.it} \\
 Jacopo D'Aurizio &  \url{elianto84@gmail.com} \\
 Alasdair McAndrew & \url{amca01@gmail.com}  \\
 Volker van Nek & \url{volkervannek@gmail.com}
\end{tabular}
}

\date{April, 2008 - July, 2013}

\begin{document}
\maketitle

This file documents a Maxima package for computations in finite fields.
It is suitable for teaching and exploration.
The first version of the package was based on the paper
``Finite Fields Manipulations in Macsyma'' by Kevin Rowley and Robert
Silverman, SIGSAM 1989, but for which the source code is long gone.
Meanwhile it contains lots of new features
and optimizations implemented by Fabrizio Caruso and Jacopo D'Aurizio.

A full review was done in 2012 and 2013 by Volker van Nek. Most of the functions described below
became core functions and some function names have been modified.
If you use a version of Maxima prior to 5.31 please refer to an appropriate
version of this file or alternatively load the necessary files from current sources.
These are \texttt{src/numth.lisp} (all basic Galois Fields functions)
and \texttt{share/contrib/gf/gf.mac} (square and cubic roots).
If speed matters compile these two files and load the binaries.

In version 5.29 and later only for root computations it is necessary to
load \texttt{gf.mac}.

Tests for basic computations in Galois Fields are located in
\texttt{src/rtest\_numth.mac}, tests for root computations in
\texttt{share/contrib/gf/gf\_test.mac}. Tests can be performed by \\
\texttt{batch(<path\_to\_test\_file>, test)}.

\section*{Getting started}
All user commands are prefixed with ``\verb!gf_!''. All you need to start is
to enter the parameters for your field.  All fields in this package are of the
form
\[
\mathbb{F}_p[x]/{m(x)}
\]
where $p$ is a prime number and $m(x)$ is an polynomial irreducible over
$\mathbb{F}_p$.  If the degree of $m(x)$ is $n$, the the finite
field will contain $p^n$ elements, each element being a polynomial of degree
strictly less than $n$, and all coefficients being in $\{0,1,\ldots,p-1\}$.
Such a field is called a \emph{finite field} or \emph{Galois field} of order
$p^n$, and is denoted $\mathbb{F}_{p^n}$.  Note that although there are many different
irreducible polynomials to choose from, if $m(x)$ and $n(x)$ are different
polynomials irreducible over $\mathbb{F}_p$  and of the same degree,
then the fields
\[
\mathbb{F}_p[x]/{m(x)}
\]
and
\[
\mathbb{F}_p[x]/{n(x)}
\]
are isomorphic.

In these fields, addition and subtraction are performed on the coefficients
modulo $p$, and multiplication and division modulo $m(x)$.

Given a prime number $p$ and a polynomial $m(x)$
you can create a field by using the command ``\verb!gf_set_data(p, m(x))!''.
\verb!gf_set_data! checks that $p$ is prime, and it also checks
whether $m(x)$ is irreducible over $\mathbb{F}_p$. If these conditions are met,
a primitive element in this field is computed and some pre-calculations are performed.
Maxima returns a Lisp structure containing the fields data which is
suitable for later use by ``\verb!gf_set_again(gf_data)!'' if needed again (see below).
Some of these data can be viewed by ``\verb!gf_info()!'' and ``\verb!gf_infolist()!''.

%\begin{maximasession}
%  \maximaoutput*
%  \i1. gf_set_data(2, x^4+x+1);\\
%  \o1. [x, x^4+x+1]\\
%\end{maximasession}
%
\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i1)}# F16 : gf_set_data(2, x^4+x+1);
  #\tr{(\%o1)}\bc\rb{$\tb{Structure [GF-DATA]}$}\ec#
  #\vspace{2mm}\tr{(\%i2)}# gf_info()$
  #\rb{$\tb{characteristic\ =\ 2}$}#
  #\rb{$\tb{reduction\ polynomial\ =\ x^4+x+1}$}#
  #\rb{$\tb{primitive\ element\ =\ x}$}#
  #\rb{$\tb{nr\ of\ elements\ =\ 16}$}#
  #\rb{$\tb{nr\ of\ units\ =\ 15}$}#
  #\rb{$\tb{nr\ of\ primitive\ elements\ =\ 8}$}#
\end{lstlisting}

In case there is no irreducible polynomial $m(x)$ available
it is sufficient to set an exponent instead.
E.g. ``\verb!gf_set_data(2, 4)!'' returns the same as ``\verb!gf_set_data(2, x^4+x+1)!''.

In addition to \verb!gf_set_data! there is a command ``\verb!gf_minimal_set(p, m(x))!''
to allow basic arithmetics without checking irreducibility and
without computing a primitive element.

\bigskip

Having set up the field, we can now perform arithmetic on field elements:

\paragraph{Addition/subtraction.}

These are performed with the commands ``\verb!gf_add!'' and ``\verb!gf_sub!''.
In the particular field entered above, since all arithmetic of coefficients is
performed modulo 2, addition and subtraction are equivalent:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i3)}# a : x^3+x;
  #\tr{(\%o3)}\bc\rb{$\tb{x^3+x}$}\ec#
  #\tr{(\%i4)}# b : x^3+x^2+1;
  #\tr{(\%o4)}\bc\rb{$\tb{x^3+x^2+1}$}\ec#
  #\tr{(\%i5)}# gf_add(a, b);
  #\tr{(\%o5)}\bc\rb{$\tb{x^2+x+1}$}\ec#
\end{lstlisting}

\paragraph{Multiplication.}

This is performed with the command ``\verb!gf_mult!'':

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i6)}# gf_mult(a, b);
  #\tr{(\%o6)}\bc\rb{$\tb{x^3+x+1}$}\ec#
\end{lstlisting}

\paragraph{Inversion and division.}

The inverse of a field element $p(x)$ is the element $q(x)$ for which their
product is equal to 1 (modulo $m(x)$).  This is performed by
``\verb!gf_inv!''.  In a finite field, division is defined as multiplying by
the inverse; thus
\[
a(x)/b(x)=a(x)(b(x))^{-1}.
\]
These operations are performed with the commands ``\verb!gf_inv!'' and
``\verb!gf_div!'':

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i7)}# gf_inv(b);
  #\tr{(\%o7)}\bc\rb{$\tb{x^2}$}\ec#
  #\tr{(\%i8)}# gf_div(a, b);
  #\tr{(\%o8)}\bc\rb{$\tb{x^3+x^2+x}$}\ec#
  #\tr{(\%i9)}# gf_mult(a, gf_inv(b));
  #\tr{(\%o9)}\bc\rb{$\tb{x^3+x^2+x}$}\ec#
\end{lstlisting}

\paragraph{Exponentiation.}

To raise a field element to an integer power, use ``\verb!gf_exp!'':

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i10)}# gf_exp(a, 14);
  #\tr{(\%o10)}\bc\rb{$\tb{x^3+x^2}$}\ec#
  #\tr{(\%i11)}# gf_exp(a, 15);
  #\tr{(\%o11)}\bc\rb{$\tb{1}$}\ec#
\end{lstlisting}

\paragraph{Random elements.}

Finally, a random element can be obtained with ``\verb!gf_random()!'':

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i12)}# makelist(gf_random(), i,1,3);
  #\tr{(\%o12)}\bc\rb{$\tb{[\,x^2+x+1,\ x^2+x,\ x^3\,]}$}\ec#
\end{lstlisting}

\section*{Primitive elements, powers and logarithms}

The non-zero elements of a finite field form a multiplicative group; a
generator of this group is a \emph{primitive element} in the field.  The
command ``\verb!gf_primitive()!'' returns the already computed primitive element:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i13)}# gf_primitive();
  #\tr{(\%o13)}\bc\rb{$\tb{x}$}\ec#
\end{lstlisting}

Given that any non-zero element in the field can be expressed as a power of
this primitive element, this power is the \emph{index} of the element; its
value is obtained with ``\verb!gf_index!'':

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i14)}# a : x^3+x#\$#
  #\tr{(\%i15)}# gf_index(a);
  #\tr{(\%o15)}\bc\rb{$\tb{9}$}\ec#
  #\tr{(\%i16)}# is(a = gf_exp(x, 9));
  #\tr{(\%o16)}\bc\rb{$\tb{true}$}\ec#
\end{lstlisting}

Since every element of the field can be represented as a polynomial
\[
a_{n-1}x^{n-1}+a_{n-2}x^{n-2}+\cdots+a_2x^2+a_1x+a_0
\]
where every coefficient $a_i$ satisfies $0\le a_i\le p-1$, a field element can
also be considered as a list:
\[
[a_{n-1},a_{n-2},\ldots,a_2,a_1,a_0].
\]
This list can be considered as the ``digits'' of a number in base $p$, in
which the field element is equivalent to the number
\[
a_{n-1}p^{n-1}+a_{n-2}p^{n-2}+\cdots+a_2p^2+a_1p+a_0.
\]
Thus every polynomial is equivalent to a number between 0 and $p^n-1$; this
number is obtained by ``\texttt{gf\_p2n}''.
The reverse direction is given by ``\texttt{gf\_n2p}''.

Since every non-zero field element $a=a(x)$ is both equivalent to a number $A$
and a power $i$ of a primitive element $e$, we can create an array of powers
corresponding to particular numbers.  This array, \texttt{gf\_powers},
which is created by \verb!gf_make_logs!,
is defined as follows:
its $i$-th element (starting with zero) is the numerical form of the $i$-th power of the
primitive element.  Thus, if
\[
a(x)\equiv A\equiv e^i
\]
where $e$ is the primitive element, then the $i$-th element of \texttt{gf\_powers} is
$A$.  By definition we have $e^{p^n-1}=1$.

The numbers $A$ run over all integers from 1 to $p^n-1$, and the powers $i$
run over all the integers from 0 to $p^n-1$, there is a corresponding
``logarithm'' array, \texttt{gf\_logs}.
The logarithm table may be considered to be
indexed from 0 to $p^n-1$, and its $i$-th element (ignoring the 0-th) is the power
corresponding to that element.

The last array returned by \verb!gf_make_logs! is \verb!gf_zech_logs!
which enables efficient addition.

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i17)}# map(listarray, gf_make_logs());
  #\vspace{-4mm}#
  #\tr{(\%o17)}\bc\rb{$\tb{
    [\,\,[1,2,4,8,3,6,12,11,5,10,7,14,15,13,9,1],
  }$}\ec#
  #\bc\hspace*{1mm}\rb{$\tb{
      [false,0,1,4,2,8,5,10,3,14,9,7,6,13,11,12],
  }$}\ec#
  #\bc\hspace*{1mm}\rb{$\tb{
      [false,4,8,14,1,10,13,9,2,7,5,12,11,6,3,false]\,\,]
  }$}\ec#
  #\tr{(\%i18)}# c : gf_exp(x, 4);
  #\tr{(\%o18)}\bc\rb{$\tb{x + 1}$}\ec#
  #\tr{(\%i19)}# gf_p2n(c);
  #\tr{(\%o19)}\bc\rb{$\tb{3}$}\ec#
  #\tr{(\%i20)}# gf_index(c);
  #\tr{(\%o20)}\bc\rb{$\tb{4}$}\ec#
  #\tr{(\%i21)}# gf_logs[3];
  #\tr{(\%o21)}\bc\rb{$\tb{4}$}\ec#
  #\tr{(\%i22)}# gf_powers[4];
  #\tr{(\%o22)}\bc\rb{$\tb{3}$}\ec#
\end{lstlisting}

The creation of the arrays \texttt{gf\_logs} and \texttt{gf\_powers}
only has to be done once.

\paragraph{Logarithms.}

The array \texttt{gf\_logs} contains the logarithm of any non-zero element
with respect to the primitive element \texttt{e} of the field.
The same holds for \texttt{gf\_ind}. The logarithm
of any element relative to the base of another can be obtained by the
command ``\verb!gf_log!'':

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i23)}# a : x^3+x#\$#
  #\tr{(\%i24)}# b : x^3+x^2+1#\$#
  #\tr{(\%i25)}# gf_log(a, b);
  #\tr{(\%o25)}\vspace*{2mm}\bc\rb{$\tb{3}$}\ec#
  #\tr{(\%i26)}# is(a = gf_exp(b, 3));
  #\tr{(\%o26)}\bc\rb{$\tb{true}$}\ec#
\end{lstlisting}

We conclude that, in our field, $a=b^{3}$.

\paragraph{Primitive elements.}

A given field will have many primitive elements, and the command \\
``\verb!gf_primitive_p!'' tests whether an element is primitive:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i27)}# gf_primitive_p(a);
  #\tr{(\%o27)}\vspace{0mm}\bc\rb{$\tb{false}$}\ec#
  #\tr{(\%i28)}# gf_primitive_p(b);
  #\tr{(\%o28)}\bc\rb{$\tb{true}$}\ec#
\end{lstlisting}

\paragraph{Order.}

By definition, any element $a$ of the field will satisfy $a^{p^n-1}=1$.  The
\emph{order} of $a$ is the \emph{lowest} power $m$ for which $a^m=1$.  It will
be a factor of $p^n-1$, and is obtained with ``\verb!gf_order!'':

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i29)}# gf_order(a);
  #\tr{(\%o29)}\bc\rb{$\tb{5}$}\ec#
  #\tr{(\%i30)}# gf_order(b);
  #\tr{(\%o30)}\bc\rb{$\tb{15}$}\ec#
\end{lstlisting}

\section*{Minimal polynomials}

Associated with every element $a\in GF(p^n)$ is a polynomial $p(x)$ which
satisfies:
\begin{enumerate}
\item $p(a)=0$,
\item the coefficient of the highest power in $p(x)$ is one,
\item for any other polynomial $q(x)$ with $q(a)=0$, $p(x)$ is a divisor of $q(x)$.
\end{enumerate}
The polynomial $p(x)$ is thus, in a very strict sense, the \emph{smallest}
polynomial which has $a$ as a root.  It is the \emph{minimal polynomial} of
$a$.  The command ``\verb!gf_minimal_poly!'' calculates it:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i31)}# a : x^3+x#\$#
  #\tr{(\%i32)}# p : gf_minimal_poly(a);
  #\tr{(\%o32)}\bc\rb{$\tb{z^4+z^3+z^2+z+1}$}\ec#
\end{lstlisting}

To check this, substitute $a$ for $z$ in $p$:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i33)}# subst(a, z, p);
  #\tr{(\%o33)}\bc\rb{$\tb{(x^3+x)^4+(x^3+x)^3+(x^3+x)^2+x^3+x+1}$}\ec#
  #\tr{(\%i34)}# gf_eval(%);
  #\tr{(\%o34)}\bc\rb{$\tb{0}$}\ec#
\end{lstlisting}

\section*{An application: the Chor-Rivest knapsack cryptosystem}

The Chor-Rivest knapsack cryptosystem is the only knapsack cryptosystem which
doesn't use modular arithmetic; instead it uses the arithmetic of finite
fields.  Although it has been broken, it is still a very good example of
finite field arithmetic.

Assuming the two protagonists are Alice and Bob, and Alice wishes to set up a
public key for Bob to encrypt messages to her.  Alice chooses a finite field
$\mathbb{F}_{p^n}=\mathbb{F}_p[x]/m(x)$, and a random primitive element $g(x)$.  She
then computes $a_i=\log_{g(x)}(x+i)$ for every $i\in\mathbb{F}_p$.  She
selects a random integer $d$ for which $0\le d\le p^n-2$, and computes
$c_i=(a_i+d)\pmod{p^n-1}$.  Her public key is the sequence $c_i$, with the
parameters $p$ and $n$.

To encrypt a message to Alice, Bob encodes the message as binary blocks of
length $p$ which contain $n$ ones.  Given one such block
$M=(M_0,M_1,\ldots,M_{p-1})$, Bob creates the cipher text
\[
c=\sum_{i=0}^{p-1}M_ic_i\pmod{p^n-1}
\]
which he sends to Alice.

To decrypt $c$, Alice first computes $r=(c-nd)\pmod{p^n-1}$, and then computes
$u(x)=g(x)^r\pmod{m(x)}$.  She then computes $s(x)=u(x)+m(x)$ and factors $s$
into linear factors $x+t_i$.  The $t_i$ values are the positions of the ones
in the message block $M$.

Actually, the complete cryptosystem also involves a permutation, which is
applied to the sequence $a_i$ to create $c_i$.  But for this example we are
just interested in the field arithmetic.

We shall choose the example given in chapter 8 of HAC, but without the
permutation.  Here the field is
\[
GF(7^4)=\mathbb{F}_7[x]/(x^4+3x^3+5x^2+6x+2)
\]
and the primitive element chosen is $g(x)=3x^3+3x^2+6$ and the random integer
$d$ is 1702.

First, Alice must compute her public key:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i35)}# gf_set_data(7, x^4+3*x^3+5*x^2+6*x+2)#\$#
  #\tr{(\%i36)}# g : 3*x^3+3*x^2+6#\$#
  #\tr{(\%i37)}# gf_primitive_p(g);
  #\tr{(\%o37)}\bc\rb{$\tb{true}$}\ec#
  #\tr{(\%i38)}# a : makelist(gf_log(x+i, g), i,0,6);
  #\tr{(\%o38)}\bc\rb{$\tb{[\,1028,\,1935,\,2054,\,1008,\,379,\,1780,\,223\,]}$}\ec#
  #\tr{(\%i39)}# d : 1702#\$#
  #\tr{(\%i40)}# c : makelist(mod(a[i] + d, gf_order()), i,1,7);
  #\tr{(\%o40)}\bc\rb{$\tb{[\,330,\,1237,\,1356,\,310,\,2081,\,1082,\,1925\,]}$}\ec#
\end{lstlisting}

Now Bob can encrypt a message to Alice; suppose one such block is
$[1,0,1,1,0,0,1]$, which is a block of length 7 which contains exactly 4 ones.

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i41)}# M : [1,0,1,1,0,0,1];
  #\tr{(\%o41)}\bc\rb{$\tb{[\,1,\,0,\,1,\,1,\,0,\,0,\,1\,]}$}\ec#
  #\tr{(\%i42)}# c : mod(sum(M[i] * c[i], i,1,7), gf_order());
  #\tr{(\%o42)}\bc\rb{$\tb{1521}$}\ec#
\end{lstlisting}

This last value is the ciphertext.  Alice now needs to decrypt it:

\vspace*{-4mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i43)}# r : mod(c - gf_exponent() * d, gf_order());
  #\tr{(\%o43)}\bc\rb{$\tb{1913}$}\ec#
  #\tr{(\%i44)}# u : gf_exp(g, r);
  #\tr{(\%o44)}\bc\rb{$\tb{x^3+3\,x^2+2\,x+5}$}\ec#
  #\tr{(\%i45)}# s : u + gf_reduction();
  #\tr{(\%o45)}\bc\rb{$\tb{x^4+4\,x^3+8\,x^2+8\,x+7}$}\ec#
  #\tr{(\%i46)}# gf_factor(s);
  #\tr{(\%o46)}\vspace{0mm}\bc\rb{$\tb{x\ (x + 2)\ (x + 3)\ (x + 6)}$}\ec#
\end{lstlisting}

The $t_i$ values are $0,2,3,6$ and these are the positions of the ones in $M$.

\vspace*{-3mm}
\section*{Matrices}

There are commands for dealing with matrices over finite fields. E.g.
``\verb!gf_invert_by_lu!'' for inverting a matrix, and ``\verb!gf_matmult!'' for
multiplying matrices.

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i47)}# gf_set_again(F16)#\$#
  #\tr{(\%i48)}# m : matrix([1,x^3+1], [x^2+1,x]);
  #\tr{(\%o48)}\bc\rbb{$\tb{\D{\left(\begin{array}[h]{cc}1&x^3+1\\x^2+1&x\end{array}\right)}}$}\vspace{3mm}\ec#
  #\tr{(\%i49)}# m_inv : gf_invert_by_lu(m);
  #\tr{(\%o49)}\bc\rbb{$\tb{\D{\left(\begin{array}[h]{cc}x^2&1\\x^3+x&x\end{array}\right)}}$}\vspace{3mm}\ec#
  #\tr{(\%i50)}# gf_matmult(m, m_inv);
  #\tr{(\%o50)}\bc\rbb{$\tb{\D{\left(\begin{array}[h]{cc}1&0\\0&1\end{array}\right)}}$}\vspace{0mm}\ec#
\end{lstlisting}

\vspace*{-3mm}
\section*{Normal bases}

Any field $GF(p^n)$ may be considered as a vector space over
$\mathbb{F}_p$; one basis is the set
\[
\{1,x,x^2,\ldots,x^{n-1}\}
\]
which is called the \emph{polynomial basis}.  A \emph{normal element} is a
field element $e$ for which the set
\[
\{e,e^p,e^{p^2},\ldots,e^{p^{n-1}}\}
\]
forms a basis.  There are several commands for dealing with normal elements
and bases.  The command ``\verb!gf_random_normal()!'' finds a normal element by
simply picking field elements at random and testing each one for normality.
Although this is a probabilistic algorithm, in practice it works very quickly:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i51)}# gf_set_data(2, x^10+x^3+1)#\$#
  #\tr{(\%i52)}# p : gf_random_normal();
  #\tr{(\%o52)}\vspace{0mm}\bc\rb{$\tb{x^9+x^8+x^7+x^6+x^5+x}$}\ec#
\end{lstlisting}

The command ``\verb!gf_normal()!'' is a brute force search through all
field elements; in general it is slower than \verb!gf_random_normal()!.

Having found a normal element the command ``\verb!gf_normal_basis()!'' produces a
matrix the rows of which are the coefficients of the basis elements
$e^{p^k}$.  This command takes an optional parameter; a polynomial $p$.  If
present, \verb!gf_normal_basis()! checks if the field element is normal, and if
so, produces the matrix, otherwise prints an error message.  If the parameter
is not given, \verb!gf_normal_basis()! first finds a normal element, and then
uses that element to produce the matrix.

With the normal basis, the command ``\verb!gf_normal_basis_rep(p, mat)!'' produces the
normal basis representation of \texttt{p}, with respect to the basis
\texttt{mat}, as a list of coefficients.  One attraction of using normal bases
is that much arithmetic can be simplified; for example, in a normal basis
representation, a power of the prime $p$ is equivalent to a shift of
coefficients:

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i53)}# m : gf_normal_basis(p)#\$#
  #\tr{(\%i54)}# a : gf_random();
  #\tr{(\%o54)}\vspace{0mm}\bc\rb{$\tb{x^9+x^5+x^3+x^2+1}$}\ec#
  #\tr{(\%i55)}# gf_normal_basis_rep(a, m);
  #\tr{(\%o55)}\bc\rb{$\tb{[\,1,\,0,\,1,\,0,\,0,\,1,\,1,\,0,\,0,\,0\,]}$}\ec#
  #\tr{(\%i56)}# gf_normal_basis_rep(gf_exp(a, 2), m);
  #\tr{(\%o56)}\bc\rb{$\tb{[\,1,\,1,\,0,\,1,\,0,\,1,\,0,\,1,\,1,\,1\,]}$}\ec#
\end{lstlisting}

\section*{Large fields}

\texttt{gf\_set\_data} computes and stores powers $x^{p^k}$.
In case \texttt{gf\_set\_data} was called \verb!gf_exp! uses the technique
of modular composition. Otherwise \verb!gf_exp! performs ``repeated squaring''.
\verb!gf_index! resp. \verb!gf_log! use a
Pohlig-Hellman reduction and Brent's version of Pollard Rho.

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i57)}# gf_set_data(2, x^20+x^3+1);
  #\tr{(\%o57)}\bc\rb{$\tb{Structure [GF-DATA]}$}\ec#
  #\vspace{2mm}\tr{(\%i58)}# gf_info()$
  #\rb{$\tb{characteristic\ =\ 2}$}#
  #\rb{$\tb{reduction\ polynomial\ =\ x^{20}+x^3+1}$}#
  #\rb{$\tb{primitive\ element\ =\ x}$}#
  #\rb{$\tb{nr\ of\ elements\ =\ 1048576}$}#
  #\rb{$\tb{nr\ of\ units\ =\ 1048575}$}#
  #\rb{$\tb{nr\ of\ primitive\ elements\ =\ 480000}$}#
  #\tr{(\%i59)}# a : x^15+x^5+1;
  #\tr{(\%o59)}\bc\rb{$\tb{x^{15}+x^5+1}$}\ec#
  #\tr{(\%i60)}# index : gf_index(a);
  #\tr{(\%o60)}\bc\rb{$\tb{720548}$}\ec#
  #\tr{(\%i61)}# gf_exp(gf_primitive(), index);
  #\tr{(\%o61)}\bc\rb{$\tb{x^{15}+x^5+1}$}\ec#
  #\tr{(\%i62)}# gf_exp(a, 3^12);
  #\tr{(\%o62)}\bc\rb{$\tb{x^{17}+x^{16}+x^{13}+x^{12}+x^{11}+x^3+x^2+x}$}\ec#
\end{lstlisting}

\section*{Field extensions - the AES mixed columns operation}

Above we described that an element of a finite field $GF(p^n)$ can be interpreted as a polynomial
$f(x) = c_{n-1}\,x^{n-1} + c_{n-2}\,x^{n-2} + \cdot \cdot +\,c_1\,x + c_0$
of degree $n-1$ with coefficients in the prime field $GF(p)$.

An element of an extension field $GF(q^k)$ where $q$ is a power of $p$, $q = p^n$,
can be interpreted as a polynomial of degree $k-1$ with coefficients in
the base field $GF(p^n)$ which means that the coefficients itself can be interpreted
as polynomials of degree $n-1$ over $GF(p)$ and all coefficient arithmetic
is carried out in $GF(p^n)$.

The reduction polynomial of degree $k$ used to define $GF(q^k)$
must be irreducible over $GF(p^n)$. Otherwise the defined extension is no field and
not every non-zero element is invertible.

The AES mixed columns operation is for example defined by a multiplication
in $GF(256^4)$ where the non-irreducible polynomial $x^4+1$ is used for reduction.
The element $a = 3\,x^3+x^2+x+2$ used for the mixed columns multiplication is invertible,
$a^{-1} = B\,x^3+D\,x^2+9\,x+E$ in base $16$, so the inverse operation is guaranteed.

The following session shows the mixed columns operation applied to one column represented
by the list $[30, 5D, BF, D4]$. (These four bytes are taken from the example on page 33 of the
AES specification document fips-197.pdf and they are the first four bytes that are modified
by the mixed columns operation there.)

User commands for field extensions are prefixed with ``\verb!ef_!'' and for nearly every
\texttt{gf}-function there is a corresponding \texttt{ef}-function.
The polynomial \texttt{m(x)} used for reduction can be defined by
``\verb!ef_minimal_set(m(x))!'' or ``\verb!ef_set_data(m(x))!''.
The \texttt{ef}-functions then refer to the
previously by \texttt{gf\_set\_data} defined field as the base field.

\vspace*{4mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i1)}# gf_set_data(2, x^8+x^4+x^3+x+1)#\$#
  #\tr{(\%i2)}# ef_irreducible_p(x^4+1);
  #\tr{(\%o2)}\bc\rb{$\tb{false}$}\ec#
  #\tr{(\%i3)}# ef_minimal_set(x^4+1);
  #\tr{(\%o3)}\bc\rb{$\tb{reduction\ polynomial\ =\ x^4+1}$}\ec#
  #\tr{(\%i4)}# ibase : obase : 16#\$#
  #\tr{(\%i5)}# p : ef_l2p([30, 5D, 0BF, 0D4]);
  #\tr{(\%o5)}\bc\rb{$\tb{30\ x^3+5D\ x^2+0BF\ x+0D4}$}\ec#
  #\tr{(\%i6)}# a : 3*x^3+x^2+x+2;
  #\tr{(\%o6)}\bc\rb{$\tb{3\ x^3+x^2+x+2}$}\ec#
  #\tr{(\%i7)}# ef_p2l(pa : ef_mult(p, a));
  #\tr{(\%o7)}\bc\rb{$\tb{[0E5,\ 81,\ 66,\ 4]}$}\ec#
  #\tr{(\%i8)}# ai : ef_inv(a);
  #\tr{(\%o8)}\bc\rb{$\tb{0B\ x^3+0D\ x^2+9\ x+0E}$}\ec#
  #\tr{(\%i9)}# ef_mult(ai, a);
  #\tr{(\%o9)}\bc\rb{$\tb{1}$}\ec#
  #\tr{(\%i10)}# ef_mult(ai, pa);
  #\tr{(\%o10)}\bc\rb{$\tb{30\ x^3+5D\ x^2+0BF\ x+0D4}$}\ec#
  #\tr{(\%i11)}# ibase : obase : 10.#\$#
\end{lstlisting}

\section*{Square and cube roots}
Multiple algorithms have been implemented in order to solve the square and cube root extraction problem over $\mathbb{F}_p$; all of them basically perform an exponentiation in a extension field (ie $\mathbb{F}_{p^2}=\mathbb{F}_{p}[x]/(x^2+bx+a)$ or $\mathbb{F}_{p^3}=\mathbb{F}_{p}[x]/(x^3-bx-a)$) through a repeated-squaring scheme, reaching so a complexity of $O(n \log(p))$ multiplications in $\mathbb{F}_p$; however, due to some differences in the representation and multiplication of elements in the extension field, they do not have exactly the same running time:
\begin{enumerate}
\item \verb!msqrt(a,p)! returns the two square roots of $a$ in $\mathbb{F}_p$ (if they exist) representing every $k$-th power of $x$ in $\mathbb{F}_{p}[x]/(x^2+bx+a)$ as the first column of the matrix $M^k$, where $M$ is the companion matrix associated with the polynomial $x^2+bx+a$ and $b^2-4a$ is a quadratic non-residue in $\mathbb{F}_p^*$. It requires $5 \log_2(p)$ multiplications in $\mathbb{F}_p$.
\item \verb!ssqrt(a,p)! returns the two square roots of $a$ in $\mathbb{F}_p$ (if they exist) using Shanks algorithm. It requires $5 \log_2(p)$ multiplications in $\mathbb{F}_p$.
\item \verb!gf_sqrt(a,p)! returns the two square roots of $a$ in $\mathbb{F}_p$ (if they exist) using the Muller algorithm (an improved, shifted version of Cipolla-Lehmer's) and should reach the best performance, requiring only $2 \log_2(p)$ multiplications in $\mathbb{F}_p$.
\item \verb!mcbrt(a,p)! returns the cube roots of $a$ in $\mathbb{F}_p$ (if they exist) representing every $k$-th power of $x$ in $\mathbb{F}_{p}[x]/(x^3+bx+a)$ as the vector $(M_{2,2},M_{2,3},M_{3,2})$ in the matrix $M^k$, where $M$ is the companion matrix associated with the polynomial $x^3+bx+a$, irreducible over $\mathbb{F}_p$ (Stickelberger-Redei irreducibility test for cubic polynomials is used). It requires $10 \log_2(p)$ multiplications in $\mathbb{F}_p$.
\item \verb!scbrt(a,p)! follows the same multiplication steps of \verb!mcbrt(a,p)!, using a simpler polynomial representation for the elements of the field extension. It requires about $11 \log_2(p)$ multiplications in $\mathbb{F}_p$.
\item \verb!gf_cbrt(a,p)! returns the cube roots of $a$ in $\mathbb{F}_p$ (if they exist) using the generalized Shanks algorithm: it's pretty fast, requiring about $4 \log_2(p)$ multiplications in $\mathbb{F}_p$, being so the candidate choice for cube root extraction.
\end{enumerate}
Other implemented routines, using about the same ideas, are:
\begin{enumerate}
\item \verb!lucas(n)!, returning the $n$-th Lucas number through a Muller-like scheme; it requires exactly $2$ squarings and $3$ sums for each bit in the binary representation of $n$, having so a bit-complexity bounded by $2\log_2(n)^{3+\varepsilon}$, with $\varepsilon$ depending on the adopted integer squaring algorithm.
\item \verb!qsplit(p)! and \verb!csplit(p)!, splitting a prime $p$ over $\mathbb{Z}[i]$ and $\mathbb{Z}[\omega]$, ie finding $(a,b)$ such that $p=a^2+b^2$ (this is possible only when $p$ is in the form $4k+1$) or $p=a^2+ab+b^2$ (this is possible only when $p$ is in the form $3k+1$), by the reduction of a binary quadratic form of the proper discriminant. They have the same complexity of the computation of a single Jacobi symbol, $O(\log(p)^2)$ bit-operations.
\end{enumerate}
\vspace{1cm}

In Maxima 5.29 and later \verb!lucas! is a core function.

\vspace*{2mm}
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i1)}# lucas(141);
  #\tr{(\%o1)}\bc\rb{$\tb{293263001536128903730947142076}$}\ec#
\end{lstlisting}

\vspace*{4mm}
All the other functions listed above need to be loaded by ``\verb!load(gf)!'':

\pagebreak
\begin{lstlisting}[escapechar=\#]
  #\tr{(\%i2)}# load(gf)#\$#
  #\tr{(\%i3)}# msqrt(64, 1789); ssqrt(64, 1789); gf_sqrt(64, 1789);
  #\tr{(\%o3)}\bc\rb{$\tb{[\,1781,\,8\,]}$}\ec#
  #\tr{(\%o4)}\bc\rb{$\tb{[\,8,\,1781\,]}$}\ec#
  #\tr{(\%o5)}\bc\rb{$\tb{[\,1781,\,8\,]}$}\ec#
  #\tr{(\%i6)}# mcbrt(64, 1789); scbrt(64, 1789); gf_cbrt(64, 1789);
  #\tr{(\%o6)}\bc\rb{$\tb{[\,4,\,608,\,1177\,]}$}\ec#
  #\tr{(\%o7)}\bc\rb{$\tb{[\,4,\,608,\,1177\,]}$}\ec#
  #\tr{(\%o8)}\bc\rb{$\tb{[\,4,\,1177,\,608\,]}$}\ec#
  #\tr{(\%i9)}# gf_factor(x^3-64, 1789);
  #\tr{(\%o9)}\bc\rb{$\tb{(x + 612)\ (x + 1181)\ (x + 1785)}$}\ec#
  #\tr{(\%i10)}# map(lambda([n], n - 1789), %);
  #\tr{(\%o10)}\bc\rb{$\tb{(x - 1177)\ (x - 608)\ (x - 4)}$}\ec#
  #\tr{(\%i11)}# qsplit(1789);
  #\tr{(\%o11)}\bc\rb{$\tb{[\,5,\,42\,]}$}\ec#
  #\tr{(\%i12)}# csplit(1789);
  #\tr{(\%o12)}\bc\rb{$\tb{[\,12,\,35\,]}$}\ec#
\end{lstlisting}

\end{document}

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


\section{Arrays}

\begin{itemize}

	\item If $ A $ is an array, then $ A.\len $ is the number of elements in $ A $

	\item $ A_i $ is the zero-indexed $ i $\textsuperscript{th} element of $ A $ if $ 0 \le i < A.\len $

	\begin{itemize}

		\item If $ i $ is outside of $ \left[ 0, A.\len \right) $ then $ A_i $ is undefined

	\end{itemize}

	\item $ \arrayslice{A}{i}{j} $ is the subarray from containing the elements from $ A_i $ to $ A_{j - 1} $

	\begin{itemize}

		\item $ \arrayslice{A}{i}{i} $ is the empty array $ [] $

		\item If $ i > j $ or $ i < 0 $ or $ j > A.\len $ then the subarray is undefined

	\end{itemize}

\end{itemize}

\section{Derivation}

\begin{itemize}

	\item Deriving a loop based program: follow the strategy for repetition

	\begin{itemize}
		\item Strengthen postcondition, use composition, assignment rule for initialisation, repetition rule
	\end{itemize}

	\item Patterns for finding an invariant when deriving a loop-based program

	\begin{itemize}

		\item \textbf{Pattern 1}: Given postcondition $ Q \defeq Q_1 \land Q_2 $, let $ Q_1 $ be the invariant and $ Q_2 $ be the negation of the guard

		\begin{itemize}

			\item Use this pattern if the postcondition consists of conjunct conditions and one looks like a useful negation of the guard

			\item If there is only one condition, remember the invariant could always just be $ \true $

		\end{itemize}

		\item \textbf{Pattern 2}: Given postcondition $ Q $ which uses some constant $ N $, replace $ N $ with a variable $ x $, and let the negation of the guard be $ x = N $

		\begin{itemize}

			\item Use this pattern to create an iterator variable $ x $ when there is something clear to iterate over

			\item This is commonly used for array-based programs

			\item In an array-based program with no obvious constants, remember that $ A = \arrayslice{A}{0}{A.\len} $

		\end{itemize}

		\item Note that often these will just be `starting' invariants that may require strengthening

	\end{itemize}

\end{itemize}


\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{amsthm}
\usepackage{amsfonts,amsmath, amssymb,latexsym,mathrsfs}
\usepackage[margin=1.15in]{geometry}
\usepackage{enumitem}
\setlength{\parindent}{0pt}
\usepackage{tikz-cd}
\usepackage{fancyhdr}

\theoremstyle{definition}
\newtheorem{thm}{Theorem}[section]

\newtheorem{prop}{Proposition}[section]

\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{remark}
\newtheorem*{remark}{Remark}

\theoremstyle{definition}
\newtheorem{example}{Example}[section]

\theoremstyle{definition}
\newtheorem{lem}{Lemma}[section]

\theoremstyle{definition}
\newtheorem{cor}{Corollary}[section]

\date{}
\title{Chapter 10: Taylor Polynomial and Taylor Series}

\begin{document}
\maketitle
\section{Power Series}
\begin{definition}
	A power series about $x = a$ is a sum of constants times powers of $(x - a)$:
	$C_0 + C_1(x - a) + C_2(x - a)^2 + \ldots + C_n(x - a)^n + \ldots =	\sum_{n
	=0}^{\infty}	C_n(x - a)^n$.
\end{definition}

If we fix a specific value of $x$, we can just consider plugging x with the value we have, and convergence here makes sense.

\begin{definition}
For a fixed value of $x$, if this sequence of partial sums converges to a limit $L$, that is, if
$\lim_{n \to \infty}S_n(x) = L$, then we say that the power series converges to $L$ for this value of $x$.
\end{definition}

Based on the discussion we will see that, The interval of convergence for a power series is usually centered at a point $x=a$, and extends the same length to both side, thus we denote this length as radius of convergence.\\

Moreover, each power series falls into one of the three following cases, characterized by its \textcolor{red}{radius of convergence}, $R$.
\begin{itemize}
\item The series converges only for $x = a$; the radius of convergence is defined to be $R = 0$.
\item The series converges for all values of $x$; the radius of convergence is defined to be
$R = \infty$.
\item There is a positive number $R$, called the radius of convergence, such that the series
converges for $|x - a| < R$ and diverges for $|x - a| > R$.
\end{itemize}
The interval of convergence is the interval between $a - R$ and $a + R$, including any
endpoint where the series converges.
\\

Then there is a question arises, how to find this radius of convergence then?\\

This question can be determined by considering using \textcolor{red}{ratio test} on the series, assuming $x\neq a$.
The details are included in Chapter 9.5 in the book.

\section{Taylor Polynomial and Taylor Series}
\subsection{Taylor Polynomial}
If we try to approximate the function locally using a polynomial, there is one thing we want to acquire, i.e. we want the polynomial $P(x)$ with the property that $P^{(n)}(a)=f^{(n)}(a)$ if we approximate the function at the point $x=a$. Considering merely the situation about $x=0$, recall what we did in the class, we will have the following.

\textcolor{red}{Taylor Polynomial of Degree $n$ Approximating $f(x)$ for $x$ near $0$} is \[f(x) \approx P_n(x)
	= f(0) + f'(0)x + \frac{f''(0)}{2!}x^2 + \frac{f'''(0)}{3!}x^3 + \frac{f^{(4)}(0)}{4!} x^4 + \ldots + \frac{f^{(n)}(0)}{n!} x^n\]
	We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = 0$, or the Taylor poly
	nomial about $x = 0$.\\

More generally, \textcolor{red}{Taylor Polynomial of Degree $n$ Approximating $f(x)$ for $x$ near $a$} is \[f(x) \approx P_n(x)
= f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3  + \ldots + \frac{f^{(n)}(a)}{n!} (x-a)^n\]
We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = a$, or the Taylor poly
nomial about $x =a$.\\

Notice that Taylor Polynomial of Degree $n$ Approximating $f(x)$ for $x$ near $a$ will have the property that $P_n^{(m)}(a)=f^{(m)}(a)$ for $0 \leq m \leq n$.

\subsection{Taylor Series}

Notice that in the Taylor polynomial, if we let $n$ here goes to infinity, we will get a series $P(x)$ with $P^{(m)}(a)=f^{(m)}(a)$ for $0 \leq m < \infty$ and thus we will expect that the series gives a good approximation about $f(x)$ around $a$, and actually when it converges, it is exactly the value you will get in $f(x)$, and this is called the Taylor Series.

\textcolor{red}{Taylor Series for $f(x)$ about $x=0$} is \[f(x) = f(0) + f'(0)x + \frac{f''(0)}{2!}x^2 + \frac{f'''(0)}{3!}x^3 + \frac{f^{(4)}(0)}{4!} x^4 + \ldots + \frac{f^{(n)}(0)}{n!} x^n+ \ldots \]
We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = 0$, or the Taylor poly
nomial about $x = 0$.\\

More generally, \textcolor{red}{Taylor Series for $f(x)$ about $x=a$} is \[f(x) = f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3  + \ldots + \frac{f^{(n)}(a)}{n!} (x-a)^n+ \ldots \]
We call $P_n(x)$ the Taylor polynomial of degree $n$ centered at $x = a$, or the Taylor poly
nomial about $x =a$.\\

Moreover, there are \textcolor{red}{several important cases} that we consider, each of them is an Taylor expansion of a function about $x=0$:
\begin{itemize}
\item \[e^{x}= 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \frac{x^5}{5!} + \frac{x^6}{6!} + \frac{x^7}{7!} + \frac{x^8}{8!} + \cdots\text{ converges for all } x\]
\item \[\sin(x)=\sum\limits_{n=0}^\infty \dfrac{x^{2n+1}}{(2n+1)!}\cdot(-1)^n = x-\dfrac{x^3}{3!}+\dfrac{x^5}{5!}-\dfrac{x^7}{7!}+\dots\text{ converges for all } x\]
\item \[\cos(x)=\sum\limits_{n=0}^\infty \dfrac{x^{2n}}{(2n)!}\cdot(-1)^n = 1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+\dots \text{ converges for all } x\]
\item \[(1 + x)^p = \sum_{k=0}^{\infty} \binom{p}{k} x^k= \sum_{k=0}^{\infty} \frac{p!}{k!(p-k)!} x^k=\]\[1 + px + \frac{p(p - 1)}{2!}x^2 + \frac{p(p - 1)(p - 2)}{3!}x^3 + \cdots \text{ converges for } -1 < x < 1.\]
\item \[\ln(1+x) =\sum_{n = 0}^{\infty}\frac{(-1)^nx^{n+1}}{n+1}= x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+\cdots,\]

\end{itemize}

Moreover, we can definitely find Taylor Series based on the existing series using \textcolor{red}{four methods}:
\begin{itemize}
	\item Substitude

Example: Taylor Series about $x=0$ for $f(x)=e^{-x^2}$

	\item Differentiate

Example: Taylor Series about $x=0$ for $f(x)=\frac{1}{(1-x)^2}$

	\item Integrate

Example: Taylor Series about $x=0$ for $f(x)=\arctan x$ (Hint: What is $\frac{d}{dx}(\arctan x)$?)
	\item Multiply

	Example: Taylor Series about $x=0$ for $f(x)=x^2 \sin x$\\
	Example: Taylor Series about $x=0$ for $f(x)=\sin x \cos x$\\
	Example: Taylor Series about $x=0$ for $f(x)=e^{\sin x}$\\

\end{itemize}
\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
	\DeclareGraphicsExtensions{.png, .jpeg}
\usepackage{caption}
% \usepackage{subcaption}
\usepackage{csvsimple}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}

\title{PA02: Vector Reduction\\CS791v: Parallel Computing}
\author{Terence Henriod}
\date{\today}

\begin{document}

\clearpage
\maketitle
\thispagestyle{empty} % removes the page number from the title page

\begin{abstract}
Vector reduction is a readily parallelizable task. The fact that it is a common task provides the motivation to carry out the parallelization. This report discusses the implementation and results of the task.
\end{abstract}

\newpage
\section{Introduction}
Vector Reduction is a commonly performed task, and is simple enough that it begs parallelization. While the best way to do this may not be readily apparent, it essentially boils down to giving threads a share of the vector to reduce, then passing the result to a logarithmically decreasing number of threads to finish the task. In fact, it is not the actual reduction algorithm that requires the most thought and care, but rather the tailoring of the algorithm to the GPU architecture.

\section{Theory}
\subsection{Sequential Algorithm}
Vector reduction in the sequential form equates to the use of a common \texttt{for (int i = 0; i < size; i++)} style loop. I think little more discussion is required here.

\subsection{Parallelization on the GPU}
\subsubsection{Parallel Algorithm}
In the simplest case, vector reduction in parallel means that as many threads as there are elements of a vector are used to reduce $2$ of the elements of the vector, and then half as many threads can carry on the process recursively, and half of those threads can recursively reduce, and so on until one thread reduces the last $2$ resulting elements. In the case that there are fewer threads than elements, one might use a striding strategy to stride threads across the vector in order to reduce the vector to a size that can be handled by the previously described algorithm (I have no proof that this is either performance optimal or sub-optimal). If there are more threads than elements, then one just needs to carry out the original algorithm carefully so as to use a number of threads that is a power of two so as not to miss any vector elements in the reduction.

\subsubsection{The GPU}
The algorithm is relatively straightforward. The complexity comes when it is tailored to use on a GPU.

First, the GPU uses blocks of threads, so the vector must be subsetted appropriately so that each block gets a sub-vector, then the algorithm can be applied at the thread level. Second, the GPU architecture is such that not all threads can have the rapid memory access required for fast reduction (this is similar to the CPU case if the vector would not fit in cache memory, or similar). Because of this, vector segments must be duplicated in shared memory which allows faster memory access to threads at the block level (as would caching for CPU threads). Finally, as with most parallel tasks, synchronization is an unfortunate necessity. While synchronization is relatively straightforward for threads within a block, the GPU offers no method of synchronization between blocks. This problem is easily remedied however, but splitting the reduction into two separate kernel launches: one to reduce the vector into a small enough intermediate vector that can be handled by a single block, and the second one to perform the final reduction.

\newpage
\section{Results}
The performance results of the vector reduction implementation are listed here. To provide representative data of performance of the GPU over the CPU, samples representing Vector Reduce at size $14000000$ and using $256$ threads per block, $63$ blocks were chosen.

\subsection{Information on the GPU device used}
\csvautotabular{gpu_properties.csv}

\subsection{Performance Graphs}
  \begin{figure}[h]
    \centering
    \includegraphics[width=.9\linewidth]{runtime_scatter}
    \caption{Runtimes for vector reduce (using a good number of GPU blocks/threads).}
    \label{fig:runtime_scatter}
  \end{figure}

  \begin{figure}[h]
    \centering
    \includegraphics[width=.9\linewidth]{throughput_scatter}
    \caption{Runtimes for vector reduce (using a good number of GPU blocks/threads).}
    \label{fig:throughput_scatter}
  \end{figure}

  \begin{figure}[h]
    \centering
    \includegraphics[width=.9\linewidth]{speedup_surface}
    \caption{A comparison of speedup for the computation portion of vector reduce across differing numbers of block and threads using a good vector size.}
    \label{fig:compute_speedup_surface}
  \end{figure}

  \begin{figure}[h]
    \centering
    \includegraphics[width=.9\linewidth]{compute_runtime_surface}
    \caption{A comparison of runtime for the computation portion of vector reduce across differing numbers of block and threads using a good vector size.}
    \label{fig:compute_runtime_surface}
  \end{figure}

  \begin{figure}[h]
    \centering
    \includegraphics[width=.9\linewidth]{total_runtime_surface}
    \caption{A comparison of runtime for the computation and data transfer of vector reduce across differing numbers of block and threads using a good vector size.}
    \label{fig:total_runtime_surface}
  \end{figure}

  \begin{figure}[h]
    \centering
    \includegraphics[width=.9\linewidth]{compute_throughput_surface}
    \caption{A comparison of throughput for the computation portion of vector reduce across differing numbers of block and threads using a good vector size.}
    \label{fig:compute_throughput_surface}
  \end{figure}

  \begin{figure}[h]
    \centering
    \includegraphics[width=.9\linewidth]{total_throughput_surface}
    \caption{A comparison of throughput for the computation and data transfer of vector reduce across differing numbers of block and threads using a good vector size.}
    \label{fig:total_throughput_surface}
  \end{figure}

\newpage
\section{Discussion}
\subsection{Speedups}
The speedups were lower than I would have expected, with a maximum speedup of around $11$. As usual, this was likely due to the weak GPU. However, we can still see where the best speedups occurred. It appears that the best speedup occurrs using around $128$ - $256$ threads with around $63$ - $255$ blocks. Note that there is a sharp dropoff in speed once more than $1024$ blocks are used due to the fact that this is when the reduction algorithm makes a significant change: intermediate kernel launches start to be used to reduce the vector enough (so that it has fewer elements than the maximum of threads per block) for the final kernel call to complete the reduction. Over using threads does seem to cause some reduction in performance, but not as significantly as overuse of blocks does.

\subsection{Data Transfer}
Data transfer was a small, but relatively uniform hindrance to performance. Interestingly enough, however, data transfer apears to play a smaller role in the runtime of the GPU reduction at larger vector sizes. It would be interesting to explore this further in an environment where GPU operations weren't limited to 2 seconds to see if the performance hit truly does level off.

\section{Issues}
\subsection{Windows Takes Away the GPU}
As I have stated before, Windows takes control of the GPU away from the program should a GPU operation take longer than $2$ seconds. While this does limit the range of vector sizes I am allowed to try, I believe I still acquire meaningful runs that demonstrate the necessary penomena.

\subsection{Weak GPU}
The weakness of the GPU makes it hard to demonstrate impressive performance.

\subsection{Ill Defined Assignment}
Not having specific guidelines made it somewhat difficult to complete the assignment on an appropriate timeline.

\subsection{Personal Folly}
I wanted to attempt using a personal algorithm where I divided the vector into shares for each block rather than simply striding the threads across the entire array. This became difficult to debug and likely would have reduced performance, so this strategy was abandoned (although much later than it should have been).

\end{document}


\subsection{Ply (order) of a cover}


\subsection{Power of instruments}


\documentclass[../main.tex]{subfiles}

\begin{document}

\section{xAPI Formal Specification}
The current formal specification only defines xAPI statements
abstractly within the context of Z. A concrete definition for xAPI
statements is outside the scope of this document.

\subsection{Basic and Free Types}
$[MBOX, MBOX\_SHA1SUM, OPENID, ACCOUNT]$
\begin{itemize}
\item Basic Types for the abstract representation of the different forms of Inverse Functional Identifiers found in xAPI
\end{itemize}
$[CHOICES, SCALE, SOURCE, TARGET, STEPS]$
\begin{itemize}
\item Basic Types for the abstract representation of the different forms of Interaction Components found in xAPI
\end{itemize}
$IFI$ ::=$ MBOX \,|\, MBOX\_SHA1SUM \,|\, OPENID \,|\, ACCOUNT$
\begin{itemize}
\item Free Type unique to Agents and Groups, The concrete definition of the listed Basic Types
  is outside the scope of this specification
\end{itemize}
$OBJECTTYPE$ ::=$ Agent \,|\, Group \,|\, SubStatement \,|\,
StatementRef \,|\, Activity$
\begin{itemize}
\item A type which can be present in all activities as defined by
  the xAPI specification
\end{itemize}
$INTERACTIONTYPE$ ::= $true-false \,|\, choice \,|\, fill-in \,|\,
long-fill-in \,|\, matching \,| \\ performance \,|\, sequencing \,|\,
likert \,|\, numeric \,|\, other$
\begin{itemize}
\item A type which represents the possible interactionTypes as
  defined within the xAPI specification
\end{itemize}
$INTERACTIONCOMPONENT$ ::= $CHOICES \,|\, SCALE \,|\, SOURCE \,|\,
TARGET \,|\, STEPS$
\begin{itemize}
\item A type which represents the possible interaction components as
  defined within the xAPI specification
\item the concrete definition of the listed Basic Types is outside the
  scope of this specification
\end{itemize}
$CONTEXTTYPES$ ::= $parent \,|\, grouping \,|\, category \,|\, other$
\begin{itemize}
\item A type which represents the possible context types as
  defined within the xAPI specification
\end{itemize}
$[STATEMENT]$
\begin{itemize}
\item Basic type for an xAPI data point
\end{itemize}
$[AGENT, GROUP]$
\begin{itemize}
\item Basic types for Agents and collections of Agents
\end{itemize}

\subsection{Id Schema}
\begin{schema}{Id}
  id : \finset_1 \#1
\end{schema}
\begin{itemize}
\item the schema $Id$ introduces the component $id$ which is a
  non-empty, finite set of 1 value
\end{itemize}

\subsection{Schemas for Agents, Groups and Actors}

\begin{schema}{Agent}
  agent : AGENT \\
  objectType : OBJECTTYPE \\
  name : \finset_1 \#1 \\
  ifi : IFI
  \where
  objectType = Agent \\
  agent = \{ifi\} \cup \power \{name, objectType\}
\end{schema}
\begin{itemize}
\item The schema $Agent$ introduces the component $agent$ which is a set
  consisting of an $ifi$ and optionally an $objectType$ and/or $name$
\end{itemize}

\begin{schema}{Member}
  Agent \\
  member : \finset_1
  \where
  member = \{a : AGENT \,|\, \forall a_{n}: a_{i}..a_{j} @ i \leq n
  \leq j @ a = agent\}
\end{schema}
\begin{itemize}
\item The schema $Member$ introduces the component $member$ which is a set of
  objects $a$, where for every $a$ within $a_{0}..a_{n}$, $a$ is an $agent$
\end{itemize}

\begin{schema}{Group}
  Member \\
  group : GROUP \\
  objectType : OBJECTTYPE \\
  ifi : IFI\\
  name : \finset_1 \#1
  \where
  objectType = Group \\
  group = \{objectType, name, member\} \lor \{objectType, member\}
  \lor \\ \t2 \{objectType, ifi\} \cup \power \{name, member\}
\end{schema}
\begin{itemize}
\item The schema $Group$ introduces the component $group$ which is of
  type $GROUP$ and is a set of either $objectType$ and $member$ with optionaly $name$ or
  $objectType$ and $ifi$ with optionally $name$ and/or $member$
\end{itemize}

\begin{schema}{Actor}
  Agent \\
  Group \\
  actor : AGENT \lor GROUP
  \where
  actor = agent \lor group
\end{schema}
\begin{itemize}
\item The schema $Actor$ introduces the component $actor$ which
  is either an $agent$ or $group$
\end{itemize}

\subsection{Verb Schema}
\begin{schema}{Verb}
  Id \\
  display, verb : \finset_1
  \where
  verb = \{id, display\} \lor \{id\}
\end{schema}
\begin{itemize}
\item The schema $Verb$ introduces the component $verb$ which
  is a set that consists of either $id$ and the non-empty, finite set
  $display$ or just $id$
\end{itemize}

\subsection{Object Schema}

\begin{schema}{Extensions}
  extensions, extensionVal : \finset_1 \\
  extensionId : \finset_1 \#1 \\
  \where
  extensions = \{e : (extensionId, extensionVal)\ \,|\,
  \forall e_{n} : e_{i}..e_{j} @ i \leq n \leq j @ \\
  \t3 \, (extensionId_{i}, extensionVal_{i})
  \lor (extensionId_{i}, extensionVal_{j}) \land \\
  \t3 \, (extensionId_{j}, extensionVal_{i})
  \lor (extensionId_{j}, extensionVal_{j})
  \land \\ \t3 \, extensionId_{i} \not = extensionId_{j}\}
\end{schema}
\begin{itemize}
\item The schema $Extensions$ introduces the component $extensions$ which
  is a non-empty, finite set that consists of ordered pairs of
  $extensionId$ and $extensionVal$. Different $extensionId$s can
  have the same $extensionVal$ but there can not be two identical
  $extensionId$ values
\item $extensionId$ is a non-empty, finite set with one value
\item $extensionVal$ is a non-empty, finite set
\end{itemize}

\begin{schema}{InteractionActivity}
  interactionType : INTERACTIONTYPE \\
  correctResponsePattern : \seq_1 \\
  interactionComponent: INTERACTIONCOMPONENT \\
  \where
  interactionActivity = \{interactionType, correctReponsePattern,
  interactionComponent\} \lor \\ \t5 \{interactionType, correctResponsePattern\}
\end{schema}
\begin{itemize}
\item The schema $InteractionActivity$ introduces the component
  $interactionActivity$ which is a set of either $interactionType$
  and $correctResponsePattern$ or $interactionType$ and
  $correctResponsePattern$ and $interactionComponent$
\end{itemize}

\begin{schema}{Definition}
  InteractionActivity \\
  Extensions \\
  definition, name, description : \finset_1 \\
  type, moreInfo : \finset_1 \#1
  \where
  definition = \power_1 \{name, description, type, moreInfo,
  extensions, interactionActivity\} \\
\end{schema}
\begin{itemize}
\item The schema $Definition$ introduces the component
  $definition$ which is the non-empty, finite power set of $name$, $description$,
  $type$, $moreInfo$ and $extensions$
\end{itemize}

\begin{schema}{Object}
  Id \\
  Definition \\
  Agent \\
  Group \\
  Statement \\
  objectTypeA, objectTypeS, objectTypeSub, objectType  : OBJECTTYPE \\
  substatement : STATEMENT \\
  object : \finset_1 \\
  \where
  substatement = statement \\
  objectTypeA = Activity \\
  objectTypeS = StatementRef \\
  objectTypeSub = SubStatement \\
  objectType = objectTypeA \lor objectTypeS \\
  object = \{id\} \lor \{id, objectType\} \lor \{id, objectTypeA,
  definition\} \\ \t2 \lor \{id, definition\} \lor \{agent\} \lor
  \{group\} \lor \{objectTypeSub, substatement\} \\
  \t2 \lor \{id, objectTypeA\}
\end{schema}
\begin{itemize}
\item The schema $Object$ introduces the component $object$ which
  is a non-empty, finite set of either $id$, $id$ and $objectType$,
  $id$ and $objectTypeA$, $id$ and $objectTypeA$ and $definition$,
  $agent$, $group$, or $substatement$
\item The schema $Statement$ and the corresponding component
  $statement$ will be defined later on in this specification
\end{itemize}

$\\\\\\\\\\\\$ %%% Header with content

\subsection{Result Schema}

\begin{schema}{Score}
  score : \finset_1 \\
  scaled, min, max, raw : \num \\
  \where
  scaled = \{ n : \num \,|\, -1.0 \leq n \leq 1.0 \} \\
  min = n < max \\
  max = n > min \\
  raw = \{ n : \num \,|\, min \leq n \leq max \} \\
  score = \power_1 \{scaled, raw, min, max\}
\end{schema}
\begin{itemize}
\item The schema $Score$ introduces the component $score$ which is
  the non-empty powerset of $min$, $max$, $raw$ and $scaled$
\end{itemize}

\begin{schema}{Result}
  Score \\
  Extensions \\
  success, completion, response, duration : \finset_1 \#1 \\
  result : \finset_1
  \where
  success = \{true\} \lor \{false\} \\
  completion = \{true\} \lor \{false\} \\
  result = \power_1 \{score, success, completion, response,
  duration, extensions\}
\end{schema}
\begin{itemize}
\item The schema $Result$ introduces the component $result$ which is
  the non-empty power set of $score$, $success$, $completion$,
  $response$, $duration$ and $extensions$
\end{itemize}

\subsection{Context Schema}

\begin{schema}{Instructor}
  Agent \\
  Group \\
  instructor : AGENT \lor GROUP
  \where
  instructor = agent \lor group
\end{schema}
\begin{itemize}
\item The schema $Instructor$ introduces the component $instructor$
  which can be either an $agent$ or a $group$
\end{itemize}

\begin{schema}{Team}
  Group \\
  team : GROUP
  \where
  team = group
\end{schema}
\begin{itemize}
\item The schema $Team$ introduces the component $team$ which is a $group$
\end{itemize}

\begin{schema}{Context}
  Instructor \\
  Team \\
  Object \\
  Extensions \\
  registration, revision, platform, language : \finset_1 \#1 \\
  parentT, groupingT, categoryT, otherT : CONTEXTTYPES \\
  contextActivities, statement : \finset_1
  \where
  statement = object \hide (id, objectType, agent, group,
  definition) \\
  parentT = parent \\
  groupingT = grouping \\
  categoryT = category \\
  otherT = other \\
  contextActivity = \{ca : object \hide (agent, group, objectType,
  objectTypeSub, substatement)\} \\
  contextActivityParent = (parentT, contextActivity) \\
  contextActivityCategory = (categoryT, contextActivity) \\
  contextActivityGrouping = (groupingT, contextActivity) \\
  contextActivityOther = (otherT, contextActivity) \\
  contextActivities = \power_1 \{contextActivityParent,
  contextActivityCategory, \\ \t5 \:\: contextActivityGrouping,
  contextActivityOther\} \\
  context = \power_1 \{registration, instructor, team,
  contextActivities, revision, \\ \t3 platform, language, statement, extensions\}
\end{schema}
\begin{itemize}
\item The schema $Context$ introduces the component $context$
  which is the non-empty powerset of $registration$, $instructor$,
  $team$, $contextActivities$, $revision$, $platform$, $language$,
  $statement$ and $extensions$
\item The notation $object \hide agent$ represents the component
  $object$ except for its subcomponent $agent$
\end{itemize}

\subsection{Timestamp and Stored Schema}

\begin{schema}{Timestamp}
  timestamp : \finset_1 \#1
\end{schema}

\begin{schema}{Stored}
  stored : \finset_1 \#1
\end{schema}
\begin{itemize}
\item The schema $Timestamp$ and $stored$ introduce the components
  $timestamp$ and $stored$ respectively. Each are non-empty, finite
  sets containing one value
\end{itemize}

\subsection{Attachments Schema}

\begin{schema}{Attachments}
  display, description, attachment, attachments: \finset_1 \\
  usageType, sha2, fileUrl, contentType : \finset_1 \#1 \\
  length : \nat
  \where
  attachment = \{usageType, display, contentType, length, sha2 \}
  \cup \power \{description, fileUrl\} \\
  attachments = \{a : attachment\}
\end{schema}
\begin{itemize}
\item The schema $Attachments$ introduces the component
  $attachments$ which is a non-empty, finite set of the component
  $attachment$
\item The component $attachment$ is a non-empty, finite set of the
  components $usageType$, $display$, $contentType$, $length$,
  $sha2$ with optionally $description$ and/or $fileUrl$
\end{itemize}

\subsection{Statement and Statements Schema}

\begin{schema}{Statement}
  Id \\
  Actor \\
  Verb \\
  Object \\
  Result \\
  Context \\
  Timestamp \\
  Stored \\
  Attachments \\
  statement : STATEMENT
  \where
  statement = \{actor, verb, object, stored\} \cup \\\t3 \power \{\id,
  result, context, timestamp, attachments \} \\
\end{schema}
\begin{itemize}
\item The schema $Statement$ introduces the component $statement$
  which consists of the components $actor$, $verb$, $object$ and
  $stored$ and the optional components $id$, $result$, $context$,
  $timestamp$, and/or $attachments$
\item The schema $Statement$ allows for subcomponent of $statement$
  to referenced via the $.$ (selection) operator
\end{itemize}

\begin{schema}{Statements}
  Statement \\
  IsoToUnix \\
  statements : \finset_1
  \where
  statements = \{s : statement \,|\, \forall s_{n}: s_{i}..s_{j} @ i
  \leq n \leq j \\\t3\: @ convert(s_{i}.timestamp) \leq convert(s_{j}.timestamp) \}
\end{schema}
\begin{itemize}
\item The schema $Statements$ introduces the component $statements$
  which is a non-empty, finite set of the component $statement$ which
  are in chronological order.
\end{itemize}

\end{document}


\documentclass{memoir}
\usepackage{notestemplate}

%\logo{~/School-Work/Auxiliary-Files/resources/png/logo.png}
%\institute{Rice University}
%\faculty{Faculty of Whatever Sciences}
%\department{Department of Mathematics}
%\title{Class Notes}
%\subtitle{Based on MATH xxx}
%\author{\textit{Author}\\Gabriel \textsc{Gress}}
%\supervisor{Linus \textsc{Torvalds}}
%\context{Well, I was bored...}
%\date{\today}

%\makeindex

\begin{document}

% \maketitle

% Notes taken on 06/03/21

\section{Nilpotent and Solvable Groups}
\label{sec:nilpotent_and_solvable_groups}

\begin{defn}[Nilpotence]
	For any group \(G\), define the following subgroups inductively:
	\begin{align*}
		Z_0(G) = 1, \quad Z_1(G) = Z(G),\\
		Z_i(G) \subset Z_{i+1}(G) < G \quad Z_{i+1}(G) / Z_i(G) = Z(G / Z_i(G))
	\end{align*}
	That is, \(Z_{i+1}(G)\) is a subgroup of \(G\) containing \(Z_i(G)\) that is the complete preimage in \(G\) of the center of \(G / Z_i(G)\) under the natural projection. We call the chain of subgroups
	\begin{align*}
		Z_0(G) \leq Z_1(G) \leq Z_2(G) \leq \ldots
	\end{align*}
	the \textbf{upper central series} of \(G\).\\

	A group \(G\) is called \textbf{nilpotent} if \(Z_c(G) = G\) for some \(c \in \Z\); the smallest such \(c\) is called the \textbf{nilpotence class of \(G\)}.
\end{defn}
Nilpotence is a more general form of being abelian-- a group may not be abelian, but when one quotients out abelian elements, the quotient might have abelian elements within itself-- if we can iterate this process until all elements are abelian under some quotient of centers, then our group is nilpotent.

\begin{rmrk}
	If \(G\) is abelian, then \(G\) is nilpotent with nilpotence class \(1\). This holds because \(Z(G) = G\). Furthermore, we will show the following hierarchy:
	\begin{align*}
		\text{cyclic groups}\subset \text{abelian groups}\subset \text{nilpotent groups}\subset \text{solvable groups}\subset \text{all groups}
	\end{align*}
	If \(G\) is finite, there must be an integer \(N\) so that for all \(n\geq N\),
	\begin{align*}
		Z_n(G) = Z_{n+1}(G) = \ldots
	\end{align*}
	If there is a point such that \(Z_n(G) = Z_{n+1}(G)\), then the upper limit has been reached.\\

	Infinite groups act a little bit differently with nilpotency; for example, \(Z_i(G) < G\) might all be proper subgroups of \(G\) (i.e \(G\) is not nilpotent), yet
	\begin{align*}
		G = \bigcup_{i=0} ^{\infty}Z_i(G).
	\end{align*}
	We call these groups \textbf{hypernilpotent}.
\end{rmrk}
\begin{prop}
	Let \(p\) be a prime and let \(P\) be a group of order \(p^{a}\). Then \(P\) is nilpotent of nilpotence class at most \(a-1\).
\end{prop}
\begin{proof}
	Observe that for \(i\geq 0\), \(P / Z_i(P)\) is a \(p\)-group. Hence, if \(\left| P / Z_i(P) \right| >1\), then \(Z(P / Z_i(P)) \neq 1\).\\

	Assume that \(Z_i(P) \neq G\). Then
	\begin{align*}
	\left| Z_{i+1}(P)  \right| \geq p \left| Z_i(P) \right|
	\end{align*}
	and so \(\left| Z_{i+1}(P) \right| \geq p^{i+1}\). Thus,
\begin{align*}
\left| Z_a(P) \right| \geq p^{a} \implies P = Z_a(P)
\end{align*}
	This is just an upper bound however-- \(P\) is only nilpotence of class \(a\) if \(\left| Z_i(P) \right| = p^{i}\). This cannot occur, however, as \(Z_{a-2}(P)\) would have index \(p^2\) in \(P\), and hence be abelian (in which case \(Z_{a-1}(P) = P\)). Hence, the class of \(P\) is at most \(a-1\).
\end{proof}

\begin{exmp}
	Both \(D_8\) and \(Q_8\) are nilpotent of class \(2\). Moreover, \(D_{2^{n}}\) is nilpotent of class \(n-1\). This can be proven inductively by showing \(\left| Z(D_{2^{n}}) \right| =2\) and \(D_{2^{n}}/ Z(D_{2^{n}}) \cong D_{2^{n-1}}\) for \(n\geq 3\).\\

	If \(n\) is not a power of 2, then \(D_{2n}\) is not nilpotent.
\end{exmp}

\begin{thm}
	Let \(G\) be a finite group, and let \(p_1,p_2,\ldots,p_s\mid \left| G \right| \) be distinct primes that divide its order. Let \(P_i \in \textrm{Syl}_{p_i}(G)\). The following are equivalent:
	\begin{itemize}
		\item \(G\) is nilpotent
		\item if \(H<G\), then \(H <  N_G(H)\)
		\item \(P_i \triangleleft G\) for all \(1\leq i\leq s\)
		\item \(G \cong P_1\times P_2\times \ldots\times P_s\)
	\end{itemize}
\end{thm}
This theorem proves part of the fundamental theorem of finite abelian groups.

\begin{cor}
	A finite abelian group is the direct product of its Sylow subgroups.
\end{cor}

\begin{prop}
	If \(G\) is a finite group such that, for all \(n\mid \left| G \right| \) positive, \(G\) has at most \(n\) elements that satisfy \(x^{n}=1\), then \(G\) is cyclic.
\end{prop}
\begin{prop}[Frattini's Argument]
	Let \(G\) be a finite group and \(H \triangleleft G\), and let \(P\) be a Sylow \(p\)-subgroup of \(H\). Then
	\begin{align*}
		G = HN_G(P)\\
		\left| G : H \right| \mid \left| N_G(P) \right| .
	\end{align*}
\end{prop}

\begin{prop}
	A finite group is nilpotent if and only if every maximal subgroup is normal.
\end{prop}
\begin{proof}
	Let \(G\) be a finite nilpotent group and let \(M\) be the maximal subgroup of \(G\). Because \(M < N_G(M)\), by maximality, \(N_G(M) = G\) and hence \(M \triangleleft G\).\\

	For the reverse direction, assume every maximal subgroup of the finite group \(G\) is normal. Let \(P\) be a Sylow \(p\)-subgroup of \(G\). For the sake of contradiction, assume that \(P \not\triangleleft G\), and let \(M\) be a maximal subgroup of \(G\) containing \(N_G(P)\). Frattini's argument tells us that \(G = MN_G(P)\). But \(N_G(P) \leq M\) and so \(MN_G(P) = M\) giving us a contradiction. Hence \(P \triangleleft G\) which is equivalent to nilpotency.
\end{proof}

\begin{defn}[Lower central series]
	Let \(G\) be a group, and define the following subgroups inductively:
	\begin{align*}
		G^{0} = G, \quad G^{1}= [G,G],\\
		G^{i+1}= [G,G^{i}].
	\end{align*}
	Then the chain of groups
	\begin{align*}
		G^{0}\geq G^{1}\geq G^2\geq \ldots
	\end{align*}
	is called the \textbf{lower central series} of \(G\).
\end{defn}
\begin{hw}
	Prove that \(G^{i}\) is a characteristic subgroup of \(G\) for all \(i\).
\end{hw}

\begin{thm}
	A group \(G\) is nilpotent of class \(c\) if and only if \(c\) is the smallest nonnegative integer such that \(G^{c}=1\). If \(G\) is nilpotent of class \(c\) then
	\begin{align*}
		Z_i(G) \leq G^{c-i-1}\leq Z_{i+1}(G) \quad \forall i \in \left\{ 0,1,\ldots,c-1 \right\} .
	\end{align*}
\end{thm}
The terms in the upper and lower central series do not necessarily coincide (although this does happen sometimes).

\begin{rmrk}
	If \(G\) is abelian, then \(G' = G^{1} = 1\) and so the lower central series is identity after one term. Similar to the upper central series, for any finite group there is some integer \(N\) so that for all \(n\geq N\),
	\begin{align*}
		G^{n}= G^{n+1} = G^{n+2} = \ldots
	\end{align*}
	For non-nilpotent groups, \(G^{n}\) is a nontrivial subgroup of \(G\). Once equality holds for some \(G^{n}= G^{n+1}\), it holds for all terms after.
\end{rmrk}

\begin{thm}[Krull-Schmidt Theorem]
	We say that a group \(G\) satisfies the \textbf{ascending chain condition} on subgroups if every sequence of subgroups of \(G\)
	\begin{align*}
		1 = G_0\leq G_1\leq G_2\leq \ldots
	\end{align*}
	is eventually constant. Likewise, we say that \(G\) satisfies the \textbf{descending chain condition} on subgroups if
	\begin{align*}
		G = G_0 \geq G_1 \geq G_2 \geq \ldots
	\end{align*}
	is eventually constant.\\

	Assume \(G\) is a group that satisfies one of these chain conditions on normal subgroups. Then there is a unique way to write \(G\) by
	\begin{align*}
		G \cong G_1 \times G_2 \times \ldots\times G_k
	\end{align*}
	where \(G_k\) are indecomposable (i.e. cannot be written as a direct product of two proper subgroups).
\end{thm}
Note that the decomposition could be non-trivial-- all the theorem gives is uniqueness.
\subsection{Solvable Groups}
\label{sub:solvable_groups}

\begin{defn}
	Let \(G\) be a group. A \textbf{subnormal series} is a sequence of subgroups satisfying:
	\begin{align*}
		1 = H_0 \triangleleft H_1 \triangleleft \ldots \triangleleft H_s = G
	\end{align*}
	If moreover \(H_i \triangleleft G\) for all \(i\), then we say it is a \textbf{normal series}.\\

	A \textbf{solvable group} is a group with a subnormal series such that  \(H_{i+1} / H_i\) is abelian.
\end{defn}
We will see that in fact the subnormal series of a solvable group is actually a normal series.

We will shortly see that this is related to the notions described above.

\begin{defn}
	Let \(G\) be a group. We define the following sequence of subgroups inductively:
	\begin{align*}
		G^{(0)}= G, \quad G^{(1)} = [G,G]\\
		G^{(i+1)}= [G^{(i)}, G^{(i)}]
	\end{align*}
	This series of subgroups is called the \textbf{derived} or \textbf{commutator} series of \(G\).
\end{defn}
Note that sometimes we notate \(G^{(1)}= G'\), \(G^{(2)} = G''\), and so on. One can show that \(G^{(i)}\) is characteristic in \(G\).\\

Caution must be used here-- \(G^{(0)} = G^{0}\), \(G^{(1)}= G^{1}\), but this does not hold necessarily for all \(i\). The terms are noticably smaller, so \(G^{(i)}\leq G^{i}\).

\begin{thm}
	A group \(G\) is solvable if and only if \(G^{(n)}=1\) for some \(n\geq 0\).\\

	If \(G\) is solvable, the smallest nonnegative \(n\) for which \(G^{(n)}=1\) is called the \textbf{solvable length} of \(G\).
\end{thm}

\begin{prop}
	Let \(G, K\) be groups, let \(H\leq G\), and let \(\varphi :G\to K\) be a surjective homomorphism. Then
	\begin{itemize}
		\item \(H^{(i)}\leq G^{(i)}\)-- thus if \(G\) is solvable, then \(H\) is solvable
		\item \(\varphi (G^{(i)} = K^{(i)}\)-- homomorphic images and quotient groups of solvable groups are solvable
		\item If \(N \triangleleft G\) and \(N\), \(G / N\) are solvable, then so is \(G\).
	\end{itemize}
\end{prop}

\begin{thm}
	Let \(G\) be a finite group.
	\begin{itemize}
		\item If \(\left| G \right| = p^{a}q^{b}\) for some primes \(p,q\), then \(G\) is solvable (Burnside)\\
		\item If for every prime \(p \mid \left| G \right| \) we factor the order of \(G\) as \(\left| G \right| = p^{a}m\) where \((p,m) = 1\), and \(G\) has a subgroup of order \(m\), then \(G\) is solvable (Philip Hall)
		\item If \(\left| G \right| \) is odd then \(G\) is solvable (Feit-Thompson)
		\item If for every pair of elements \(x,y \in G\), \(\langle x,y \rangle \) is a solvable group, then \(G\) is solvable.
	\end{itemize}
\end{thm}

% \printindex
\end{document}


\documentclass[12pt]{cdblatex}
\usepackage{exercises}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% --------------------------------------------------------------------------------------------
\section*{Exercise 1.5 A sort hack}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z#}::Indices(position=independent).

   foo := A_{a} A^{a} + A^{a} A_{a}.            # cdb (ex-0105.100,foo)

   sort_product (foo)                           # cdb (ex-0105.101,foo)

   substitute   (foo, $A^{a} -> Z^{a}$)         # cdb (ex-0105.102,foo)
   sort_product (foo)                           # cdb (ex-0105.103,foo)
   substitute   (foo, $Z^{a} -> A^{a}$)         # cdb (ex-0105.104,foo)

\end{cadabra}

\begin{align*}
   &\cdb*{ex-0105.100}\\
   &\cdb*{ex-0105.101}\\
   &\cdb*{ex-0105.102}\\
   &\cdb*{ex-0105.103}\\
   &\cdb*{ex-0105.104}
\end{align*}

\end{document}


%%
%% Author: novitoll
%% 2/24/18
%%

% Preamble
\documentclass[11pt]{article}

% Packages
\usepackage{amsmath}
\usepackage{graphicx}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator{\atantwo}{atan2}

\title{CVT: Lecture 3}
\date{2018-02-25}
\author{Novitoll}

\graphicspath{ {code/} }

% Document
\begin{document}
    \maketitle
    \pagenumbering{arabic}

    \section{Projection peaks}

    Given calculated projection of text lines in the input image,
    then you want to find maxima of them:

    \begin{align}
        y_{\text{bm}} = \argmax{p_y(y)}
    \end{align}

    In this case, first we need to find left and right minimum per some coefficient of the peak:

    \begin{align}
        y_{\text{b0}} = \max_{y_0 < y < y_{\text{bm}}}(y|p_y(y) <= c_y * p_y(y_{\text{bm}})) \\
        y_{\text{b1}} = \min_{y_0 < y < y_{1}}(y|p_y(y) <= c_y * p_y(y_{\text{bm}}))
    \end{align}

    \includegraphics[scale=0.2]{peaks}

    \section{Sobel gradients magnitude}

    Given calculated with Sobel filter gradients of X and Y axis,
    you can combine them, deriving
    \begin{itemize}
        \item magnitude - $\sqrt{x^2 + y^2}$
        \item gradient angle - $\atantwo(y, x)$
    \end{itemize}

    \section{HOG}

    HOG (Histogram of oriented gradients) can be used for generating features (Sobel X, Y gradients magnitude and angle)
    for machine learning model (Was presented in CVPR 2005 with SVM usage for object detection).

    HOG requires params as:
    \begin{itemize}
        \item cell\_size
        \item orientation
        \item block\_size
    \end{itemize}

    , where orientation is integer (in opencv2) of N-dimensionality of axis.

    HOG can be also used as normalization for rotation and region (template) detection, e\.g\. for normalization -
    can be used to analyze the rotation effect (histogram will be shifted but magnitude values remain same),
    for template detection - take the tiny part of the image, get its HOG, and you can find its position in the image,
    comparing template HOG with image's testing region HOG

    \includegraphics[scale=0.2]{hog}
    \includegraphics[scale=0.2]{hog_feature}
    \includegraphics[scale=0.2]{hog_usage}

\end{document}