%As explained in Section \ref{sec:background}, comparing elements over $\mathbb{F}_{p^d}$ boils down to their comparison over $\mathbb{F}_p$.
In this section, we study the structure of basic comparison circuits over $\mathbb{F}_p$ used in Section~\ref{sec:background} to compare integers, namely $\LT_{\S}$ and $\EQ_{\S}$ for some $\S \subseteq [0, p-1]$.

%Let $\S$ be a subset of $[0,p-1]$ such that $\S$ can be embedded canonically embedded into $\F_p$.
For any choice of $\S$, the corresponding equality function over $\F_p$ is equal to
\begin{align*}
  \EQ_{\S}(x,y) = 1 - (x-y)^{p-1}.
\end{align*}
Unfortunately, $\LT_{\S}$ is not that simple and universal and we have to rely on Lagrange interpolation (Lemma~\ref{lem:interpolation}) to compute it.
Yet, there are two different ways to evaluate it.
The first method (as done in \cite{TLWRK20}) uses $\S = [0,p-1]$ and directly interpolates $\LT_{\F_p}(x,y)$ as a bivariate polynomial over $\F_{p}$.
The second approach (as done in \cite{NGEG17} and \cite{PoPETS:SFR20}) has $\S = [0, (p-1)/2]$ and interpolates a univariate polynomial of $\LT_{\S}(z, 0)$ with $z = x - y$.
%In this case, $x,y$ must belong to the set $[0, (p-1)/2]$.
%However, these works evaluated $\LT_{\F_p}$ without exploiting its structure.
In this section, we show how to exploit the structure of these polynomials to speed-up their evaluation.

\subsection{Bivariate interpolation of $\LT_\S$.}

  Let $\S = [0,p-1]$.
  The less-than function can be interpolated using Lemma~\ref{lem:interpolation} and the following truth table.
  \begin{table}[h]
    \centering
    \begin{tabular}{c|ccccc}
        $<$ & 0 & 1 & 2 & $\cdots$ & $p-1$ \\
        \hline
        0 & 0 & 1 & 1 & $\cdots$ & 1 \\
        1 & 0 & 0 & 1 & $\cdots$ & 1 \\
        2 & 0 & 0 & 0 & $\cdots$ & 1 \\
        $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ \\
        $p-1$ & 0 & 0 & 0 & $\cdots$ & 0 \\
    \end{tabular}
  \end{table}

  In particular, the interpolation polynomial of $\LT_\S$ over $\F_p$ is equal to
  \begin{align*}%\label{eq:less_than_function}
    P_{\LT_\S}(X,Y) &= \sum_{a = 0}^{p-2} \EQ_\S(X,a)\sum_{b = a+1}^{p-1} \EQ_\S(Y,b) \nonumber\\
    = \sum_{a = 0}^{p-2}& \left(1-\left(X - a\right)^{p-1}\right) \sum_{b = a+1}^{p-1} \left(1-\left(Y - b\right)^{p-1}\right).
  \end{align*}
  Surprisingly, the total degree of $P_{\LT_\S}(X,Y)$ is only $p$ and its coefficients can be described by the following theorem.
  \begin{theorem} \label{thm:less_than_total_degree}
    Let $p>2$ be a prime number and $\S = [0,p-1]$, then the interpolation polynomial of $\LT_\S$ over $\F_p$ has the following form
    \begin{align*}
      P_{\LT_\S}(X,Y) = Y^{p-1} - \frac{p-1}{2} (XY)^{\frac{p-1}{2}} + \sum_{\substack{i,j>0, \\ i \ne j, \\ i+j \le p}} a_{ij} X^i Y^j
    \end{align*}
    where $a_{ij} = \sum_{a=0}^{p-2} \sum_{b=a+1}^{p-1} a^{p-1-i} b^{p-1-j} \in \F_p$.
    The total degree of $P_{\LT_\S}(X,Y)$ is $p$.
  \end{theorem}
  \begin{proof}
    See Appendix \ref{app:proof_thm_less_than_total_degree}.
  \end{proof}
  From the definition of $\LT_\S$, one can easily prove the following facts about $P_{\LT_\S}$:
  \begin{itemize}[label=--]
    \item $P_{\LT_\S} (X, 0) = 0$, thus $Y$ divides $P_{\LT_\S} (X, Y)$;
    \item $P_{\LT_\S} (X, X) = P_{\LT_\S} (Y,Y) = 0$, thus $(X - Y)$ divides $P_{\LT_\S} (X, Y)$;
    \item $P_{\LT_\S} (p-1, Y)=0$ thus $X + 1$ divides $P_{\LT_\S} (X, Y)$.
  \end{itemize}
  Hence, there exists a bivariate polynomial $f(X,Y)$ of total degree $p - 3$ over $\F_p$ such that:
  \begin{equation}
    \label{eq:decomposition-LT}
    P_{\LT_\S} (X, Y) = Y(X - Y)(X + 1)f(X, Y).
  \end{equation}
  The following theorem describes the structure of $f(X,Y)$.
  \begin{theorem}\label{thm:decomposition-f}
    Let $p$ be an odd prime and $\S = [0,p-1]$.
    Let $P_{\LT_\S} (X, Y)$ be the interpolation polynomial of $\LT_\S$ over $\F_p$ and $P_{\LT_\S} (X, Y) = Y(X - Y)(X + 1)f(X, Y)$.
    Then, for any $z \in \F_p$ we have
    \begin{equation}
      \label{eq:3}
       f(z,z) = f(z,0) = f(p-1,z).
    \end{equation}
    As a consequence,
    %there exists a bivariate polynomials $f_1(X,Y)$ of total degree $p-5$ over $\F_p$ such that:
    %\begin{align}
    %  \label{eq:dec-f}
    %  f(X,Y) &= f(X,0) + Y(X-Y)f_1(X,Y) \nonumber \\
    %  &= f_0(X) + Y(X-Y)f_1(X,Y).
    %\end{align}
    %This decomposition can be applied recursively to $f_1(X,Y)$, so that
    there exists $(p-1)/2$ polynomials $f_i(X)$ over $\F_p$, $0\leq i \leq (p-3)/2$, such that:
    \begin{align}\label{eq:decomposition-f-final}
      f(X,Y) = \sum_{i=0}^{(p-3)/2} f_i(X)Z^i,
    \end{align}
    with $Z=Y(X-Y)$ and $\deg (f_{i}(X)) = p-3 - 2i$.

    % or equivalently a bivariate polynomials $f'_1$ of total degree $p-5$ over $\F_p$ such that:
    % \begin{equation}
    %   \label{eq:dec-f'}
    %   f(x,y) = f(p-1,y) + (x+1)(x-y)f'_1(x,y)
    % \end{equation}
  \end{theorem}

  Since our proof of Theorem~\ref{thm:decomposition-f} is quite long and with no real interest for the purpose of this work, we defer it to an extended version of this paper.
  In our experiments, we used the decompositions~(\ref{eq:decomposition-f-final}) of $f(X,Y)$ only for small $p$ (between $3$ and $7$), which you can find in Appendix~\ref{app:decomposition-f}.\newline

%   In order to show Eq. (\ref{eq:3}) we will need the following lemma:

%   \begin{lemma}\label{lem:structure-f}
%     Let $p>3$ be an odd prime, $i\in[0,p-2]$ and $f$ be the polynomial defined in Eq. (\ref{eq:decomposition-LT}), then for any $z\in[0,p-1]$ we have:

%     $$ f(i,z) = f(p-1-z,p-1-i) = -\displaystyle\sum_{k=i+1}^{p-1}\frac{1-(z-k)^{p-1}}{(i+1)z(z-i)} \bmod p.$$
%   \end{lemma}

%   \begin{proof}
%     We know that for any $z\in[0,p-1]$ we have:
%     $$\LT_\S(i,z) = \left\{
%       \begin{array}{l}
%         0 ~\text{ if }~ 0\leq z\leq i \\
%         1 ~\text{ otherwise}~
%       \end{array}
%     \right.$$
%     Note that since $i<p-1$, $\LT_\S(i,\cdot)$ is not the zero function. It can be interpolated by the univariate polynomial:
%     $$P_{\LT_\S}(i,z) = \displaystyle\sum_{k=i+1}^{p-1}\left[1-(z-k)^{p-1}\right] \bmod p. $$

%     Similarly:
%     \begin{align*}
%       P_{\LT_\S}(x,p-1-i) &= \displaystyle\sum_{k=0}^{p-2}\left[1-(x-k)^{p-1}\right]\displaystyle\sum_{l=k+1}^{p-1}\left[1-(p-1-i-l)^{p-1}\right] \\
%                           &= \displaystyle\sum_{k=0}^{p-2-i}\left[1-(x-k)^{p-1}\right]  \bmod p
%     \end{align*}
%     So:
%     \begin{align*}
%       P_{\LT_\S}(p-1-z,p-1-i) &= \displaystyle\sum_{k=0}^{p-2-i}\left[1-(p-1-z-k)^{p-1}\right]  \bmod p \\
%                               &= \displaystyle\sum_{k=i+1}^{p-1}\left[1-(k-z)^{p-1}\right]  \bmod p \\
%                               &= \displaystyle\sum_{k=i+1}^{p-1}\left[1-(z-k)^{p-1}\right]  \bmod p \\
%                               &=  P_{\LT_\S}(i,z) \bmod p.
%     \end{align*}
%     Now let $A$ be the bivariate polynomial defined over $\F_p$ by:
%     $$A(x,y) = y(x-y)(x+1).$$
%     We have:
%     \begin{align*}
%       A(p-1-z,p-1-i) &= -(i+1)(-z+i)(-z) \bmod p \\
%                      &= -(i+1)z(z-i) \bmod p\\
%                      &= A(i,z) \bmod p.
%     \end{align*}
%     Again, note that since $i < p-1$, $A(i,z)\neq 0 \bmod p$.

%     Starting from Eq. (\ref{eq:decomposition-LT}) we can write:
%     \begin{align*}
%       P_i(z) =& A(i,z)f(i,z) = A(p-1-z,p-1-i)f(p-1-z,p-1-i) \bmod p \\
%       \Leftrightarrow & A(i,z)f(i,z) - A(p-1-z,p-1-i)f(p-1-z,p-1-i) = 0 \bmod p \\
%       \Leftrightarrow & A(i,z)(f(i,z) - f(p-1-z,p-1-i)) = 0 \bmod p
%     \end{align*}
%     Given that $A(i,z)\neq 0 \bmod p$ and that $\F_p[z]$ is an integral domain we obtain what we want:

%     $$ f(i,z) = f(p-1-z,p-1-i) \bmod p. $$

%     The last equality is obtained by dividing $P_{LT_\S}(i,z)$ with $A(i,z)\neq 0 \bmod p$.
%   \end{proof}
%   Now we can start the proof of Theorem \ref{thm:decomposition-f}.
%   \begin{proof}[Theorem \ref{thm:decomposition-f}]
%     Equation (\ref{eq:3}) says that the first column, the last line and the descending diagonal of the table of values of $f$ are equals (cf. Table \ref{tab:values-f}).
%     \begin{table}[h]
%       \centering
%       \begin{tabular}{m{1.5em}|m{1em}m{1em}m{1em}m{1em}m{1em}m{1em}c}
%         \backslashbox{$x$}{$y$} & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
%         \hline
%         0 & \bf{0} & 6 & 5 & 3 & 3 & 5 & 6 \\
%         1 & \bf{4} & \bf{4} & 5 & 4 & 2 & 4 & 5 \\
%         2 & \bf{2} & 0 & \bf{2} & 3 & 2 & 3 & 2 \\
%         3 & \bf{2} & 0 & 0 & \bf{2} & 3 & 4 & 3 \\
%         4 & \bf{2} & 0 & 0 & 0 & \bf{2} & 5 & 5 \\
%         5 & \bf{4} & 0 & 0 & 0 & 0 & \bf{4} & 6 \\
%         6 & \bf{0} & \bf{4} & \bf{2} & \bf{2} & \bf{2} & \bf{4} & \bf{0} \\
%       \end{tabular}
%       \vspace{1em}\caption{Values $f(x,y)$ for $x,y\in\F_7$.}
%       \label{tab:values-f}
%     \end{table}

%     Lemma \ref{lem:structure-f} says that for any $0\leq i< p-1$ the $i$-th row (starting from $y=0$) and the $p-1-i$-th column (starting from $x=p-1$) of the table are equals. Another consequence of Lemma \ref{lem:structure-f} is that the values on any descending diagonal of the table form a palindrome (i.e. the values in the table are symmetric around the axis $x = p-1-y$). This is true in particular for the main descending diagonal $(x=y)$.

%     Now let us show that for any $0\leq i < p-1$ we have $f(i,0) = f(i,i)$. The case $i=0$ is trivial, for $i>0$ we know from Lemma \ref{lem:structure-f} that:
%     $$ f(i,z) = -\displaystyle\sum_{k=i+1}^{p-1}\frac{1-(z-k)^{p-1}}{(i+1)z(z-i)} \bmod p, $$
%     which can be rewritten modulo $p$ as:
%     \begin{align*}
%       f(i,z) & = -\frac{p-1-i - \displaystyle\sum_{k=i+1}^{p-1}(z-k)^{p-1}}{(i+1)z(z-i)} = -\frac{p-1-i - \displaystyle\sum_{k=i+1}^{p-1}\displaystyle\sum_{j=0}^{p-1}z^j k^{p-1-j}}{(i+1)z(z-i)} \\
%              & = -\frac{p-1-i - \displaystyle\sum_{j=0}^{p-1}\left(\displaystyle\sum_{k=i+1}^{p-1} k^{p-1-j}\right)z^j}{(i+1)z(z-i)}  = \frac{\displaystyle\sum_{j=1}^{p-1}\left(\displaystyle\sum_{k=i+1}^{p-1} k^{p-1-j}\right)z^{j-1}}{(i+1)(z-i)}.
%     \end{align*}
%     Similarly:
%     \begin{align*}
%       f(i,z) & = -\frac{p-1-i - \displaystyle\sum_{k=1}^{p-1-i}(z-i-k)^{p-1}}{(i+1)z(z-i)} = -\frac{p-1-i - \displaystyle\sum_{k=1}^{p-1-i}\displaystyle\sum_{j=0}^{p-1}(z-i)^j k^{p-1-j}}{(i+1)z(z-i)} \\
%              & = -\frac{p-1-i - \displaystyle\sum_{j=0}^{p-1}\left(\displaystyle\sum_{k=1}^{p-1-i} k^{p-1-j}\right)(z-i)^j}{(i+1)z(z-i)}  = \frac{\displaystyle\sum_{j=1}^{p-1}\left(\displaystyle\sum_{k=1}^{p-1-i} k^{p-1-j}\right)(z-i)^{j-1}}{(i+1)z}
%     \end{align*}

%     So for any $0 < i < p-1$, from the first expression we obtain:
%     $$f(i,0) = -\frac{\sum_{k=i+1}^{p-1} k^{p-2}}{i(i+1)},$$
%     from the second expression we get:
%     \begin{align*}
%       f(i,i) &= \frac{\sum_{k=1}^{p-1-i} k^{p-2}}{i(i+1)} = \frac{\sum_{k'=i+1}^{p-1} (p-k')^{p-2}}{i(i+1)} = \frac{\sum_{k'=i+1}^{p-1} (-k')^{p-2}}{i(i+1)} \bmod p \\
%       &= -\frac{\sum_{k'=i+1}^{p-1} (k')^{p-2}}{i(i+1)} = f(i,0).
%     \end{align*}

%     At this point we have shown that for $0\leq i<p-1$ we have $f(i,0) = f(i,i)$.
%     This means that the first column and the descending diagonal are equals up to the last line.
%     Since the values of the descending diagonal form a palindrome, the same applies to the values of the first column and thus of the last line. More precisely, for any $0\leq i < p-1$ we have:
%     $$f(i,0) = f(i,i) = f(p-1-i, p-1-i) = f(p-1-i, 0) = f(p-1, i)$$

%     At this point the last thing we have to prove to get Eq. (\ref{eq:3}) is that $f(0,0) = f(p-1,0) = f(p-1,p-1) \bmod p$. Lemma \ref{lem:structure-f} already gives us $f(0,0) = f(p-1,p-1)$, so we just have to prove the last one.

%     We have:
%     $$ P_{\LT_\S}(0,z)  = -\sum_{j=1}^{p-1}\left(\sum_{k=1}^{p-1}k^{p-1-j}\right)z^j  = z^{p-1} \bmod p \text{ (cf. Lemma \ref{lem:sum_poly}).} $$

%     Moreover, let $A(x,y) = y(x-y)(x+1)$, we have $A(0,z) = -z^2$. So from Eq.~(\ref{eq:decomposition-LT}) we obtain $f(0,z) = -z^{p-3}$ and so $f(0,0) = f(p-1,p-1) = -1 \bmod p$ if $p = 3$ and $0$ otherwise.

%     To conclude we have to show that $f(p-1,0) = -1 \bmod p$ if $p=3$ and $0$ otherwise.
%     Since both $A$ and $\LT_\S$ vanish on the first column of the table ($y=0$) and the last line ($x=p-1$) we cannot use their values on these lines to derive the value of $f(p-1,0)$. So this time we will estimate $\LT_\S$ and $A$ on the ascending diagonal. Since $A(p-1-z,z) = z^2(1+2z) \bmod p$ if we want to prove that $f(p-1,0) = 0 \bmod p$ (resp. $1$ if $p=3$) we have to show that the coefficients of degree $0$, $1$ and $2$ of $P_{\LT_\S}(p-1-z,z)$ are equals to $0$, (resp $0, 1$ are equals to $0$ and the coefficient of degree $2$ is equal to $-1$).

%     By definition, $\LT_\S(p-1,0) = P_{LT_\S}(p-1,0) = 0 \bmod p$, so the coefficient of degree $0$ is equal to $0$. Now let us have a look at the formal derivative of $P_{\LT_\S}(p-1-z,z)$. We have:
%     $$ P_{LT_\S}(p-1-z,z) = \sum_{k=0}^{p-2}\underbrace{[1-(1+z+k)^{p-1}]}_{=g_k(z)}\underbrace{\sum_{l=k+1}^{p-1}[1-(z-l)^{p-1}]}_{=h_k(z)} \bmod p $$

%   For $0\leq k \leq p-2$, we have $g_k(0) = 1-(1+k)^{p-1} = 0 \bmod p$, and also $h_k(0) = \sum_{l=k+1}^{p-1}[1-l^{p-1}] = 0 \bmod p$ since $0<l\leq p-1$.

% Therefore $P'_{LT_\S}(p-1,0) = \sum_{k=0}^{p-2}\left(g_k'(0)h_k(0) + g_k(0)h'_k(0) \right) = 0 \bmod p$ therefore the coefficient of degree $1$ is also equal to $0$.

% Now let us consider the formal derivative at the second order of $P_{\LT_\S}(p-1-z)$:
% $$P''_{\LT_\S}(p-1-z,z) = \sum_{k=0}^{p-2}\left(g_k''(z)h_k(z) + 2g_k'(z)h'_k(z) + g_k(z)h''_k(z) \right).$$
% Thus in $z=0$ we obtain:
% \begin{align*}
%   P''_{\LT_\S}(p-1,0) & = 2\sum_{k=0}^{p-2}g_k'(0)h'_k(0) = -2\sum_{k=0}^{p-2}(1+k)^{p-2}\sum_{l=k+1}^{p-1}l^{p-2} \\
%                       &= -2\left(\sum_{k=1}^{(p-1)/2}k^{p-2}\sum_{l=k}^{p-1}l^{p-2} + \sum_{k=(p+1)/2}^{p-1}k^{p-2}\sum_{l=k}^{p-1}l^{p-2}\right) \\
%                       & = -2\left(\sum_{k=1}^{(p-1)/2}k^{p-2}\sum_{l=k}^{p-1}l^{p-2} + \sum_{k=1}^{(p-1)/2}(-k)^{p-2}\sum_{l=p-k}^{p-1}l^{p-2}\right) \\
%                       & = -2\sum_{k=1}^{(p-1)/2}k^{p-2}\left(\sum_{l=k}^{p-1}l^{p-2} -  \sum_{l=p-k}^{p-1}l^{p-2}\right) \\
%                       & = -2\sum_{k=1}^{(p-1)/2}k^{p-2}\sum_{l=k}^{p-1-k}l^{p-2} = -2\sum_{k=1}^{(p-1)/2}k^{2p-4} \\
%                       & = -2\sum_{k=1}^{(p-1)/2}k^{p-3} = -\sum_{k=1}^{(p-1)/2}k^{p-3} - \sum_{k=1}^{(p-1)/2}(-k)^{p-3} \\
%                       & = -\sum_{k=1}^{p-1}k^{p-3}  \bmod p\\
%                       & = 1 ~\text{ if } p = 3 ~\text{ and }~ 0 ~\text{ otherwise.}
% \end{align*}
% The coefficient of degree 2 is equal to $P''_{\LT_\S}(p-1,0)/2 = -1 \bmod 3$.
% Thus overall $f(p-1,0) = f(p-1,p-1) = f(0,0)$ and we have proved Eq. (\ref{eq:3}). The rest of the theorem is straightforward:
% \begin{itemize}
% \item $y$ and $(x-y)$ divide $f(x,y)-f(x,0) = f(x,y)-f(x,x) \bmod p$ which implies (\ref{eq:dec-f}).
% \item $x+1$ and $(x-y)$ divide $f(x,y)-f(p-1,y) = f(x,y)-f(y,y) \bmod p$ which implies (\ref{eq:dec-f'}).
% \end{itemize}
% Note that when $p=3$ $f(x,y) = 1 \bmod p.$
% \end{proof}

\textbf{Complexity analysis.}
In \cite{TLWRK20}, the authors proposed to evaluate $P_{\LT_S}(X,Y)$ by evaluating each monomials separately before summing them up.
Given $x,y \in \F_p$, they precompute the powers of $x$ and $y$ up to $p-1$ for a total of $2p-4$ non-scalar multiplications.
Then, another $p-1$ non-scalar multiplications are needed to evaluate each monomial $((\sum_i c_i X^i)Y^j)_{j}$ where $c_i$'s are scalars in $\F_p$, before summing them together to get the final result.
Overall their evaluation of $P_{\LT_\S}(X,Y)$ requires $3p-5$ non-scalar multiplications.

Following this idea and using the decomposition of $f(X,Y)$ given in Eq. (\ref{eq:decomposition-f-final}) one needs:
\begin{itemize}
\item $2$ multiplications to compute $(X+1)Z$ if $p\geq 3$ or $1$ multiplication when $p=2$;
\end{itemize}
and then for $p\geq 5$:
\begin{itemize}
\item $p-4$ multiplications to compute the $X^i$'s for $2\leq i \leq p-3$ required to compute the terms $f_i(X)$;
\item $(p-5)/2$ multiplications to compute the $Z^i$ for $2\leq i \leq (p-3)/2$;
\item $(p-5)/2$ multiplications to compute the products $f_i(X)\cdot Z^i$;
\item $1$ final multiplication $(X+1)Z\cdot f(X,Y)$.
\end{itemize}
Overall, at most $2p-6$ non-scalar multiplications are needed to homomorphically evaluate $P_{\LT_\S}(X,Y)$ for \mbox{$p \geq 5$}.
This number can be slightly reduced by optimizing the way of computing $f_i$'s.
For instance, it can be done with only $6$ multiplications for $p=7$, (see Appendix \ref{app:decomposition-f}), which is smaller than $2p-6=8$.

Overall, for $p\geq 5$, our method saves $p+1$ multiplications over the method of Tan et al.~\cite{TLWRK20}.
However, the complexity of the bivariate circuit remains linear in $p$ which is unpractical for performing homomorphic comparisons using large digits (i.e. a large $p$).

\subsection{Univariate interpolation of $\LT_\S$}
Unlike bivariate polynomials, it is possible to evaluate univariate polynomials of degree $p-1$ in $\mathcal{O}(\sqrt{p})$ non-scalar multiplications using the Paterson-Stockmeyer algorithm~\cite{SIAM:PS73}. The Paterson-Stockmeyer algorithm has been used in various works related to homomorphic encryption in order to speed-up polynomial evaluation. As a recent example, it was applied by Shaul et al \cite{PoPETS:SFR20} in the context of top-$k$ selection, which uses small-number comparison as a subroutine. However, in our case the study of the structure of $\LT_\S$ as a univariate polynomial will allow us to speed-up its evaluation for large $p$ beyond what could be achieved using only the Paterson-Stockmeyer algorithm.

To evaluate $\LT_S$ as a univariate polynomial, we compute the difference $x-y$ of the two input values and check its sign.
To compute the sign function using finite field arithmetic, we need to split finite field elements into two classes:  negative ($\F_p^-$) and non-negative ($\F_p^+$).
In addition, for any $x, y \in \S$ the following property should hold:
\begin{align*}
  x - y \in
  \begin{cases}
    \F_p^+ \text{ if } \LT_\S(x,y) = 0, \\
    \F_p^- \text{ if } \LT_\S(x,y) = 1.
  \end{cases}
\end{align*}
It is easy to see that these constraints are satisfied by $\S = [0, (p-1)/2]$.
Let us split $\F_p$ into $\F_p^+ = [0, (p-1)/2]$ and $\F_p^- = [-(p-1)/2, -1]$.
Notice that for any $x, y \in \S$, their difference $x - y$ belongs to $\F_p^-$ if and only if $x < y$.

Let $\chi_{\F_p^-}(z)$ be a function that outputs $1$ if $z$ is negative and $0$ otherwise.
According to Lemma~\ref{lem:interpolation}, $\chi_{\F_p^-}(z)$ is equal to
\begin{align*}
  \chi_{\F_p^-}(z) = \sum_{a=-\frac{p-1}{2}}^{-1} 1 - (z - a)^{p-1}.
\end{align*}
  Combining the above facts, the $\LT_\S$ function can be interpolated by the following polynomial over $\F_p$
  \begin{align*}
    Q_{\LT_\S}(X,Y) = \sum_{a=-\frac{p-1}{2}}^{-1} 1 - (X - Y - a)^{p-1}\,.
  \end{align*}
  The following theorem describes all the coefficients of this interpolation polynomial.
  \begin{theorem}\label{th:univariate}
    For an odd prime $p$ and $\S = [0, (p-1)/2]$, the $\LT_\S$ function can be interpolated by the following polynomial over $\F_p$
    \begin{align}\label{eq:univariate_circuit}
      Q_{\LT_\S}(X,Y) = \frac{p+1}{2} (X-Y)^{p-1} + \sum_{i=1, \text{odd}}^{p-2} c_i (X-Y)^i.
    \end{align}
    where $c_i = \sum_{a=1}^{\frac{p-1}{2}} a^{p-1-i}$.
  \end{theorem}
  \begin{proof}
    See Appendix \ref{app:proof-lem-univariate}
  \end{proof}
  \begin{remark}\label{rem:sign_function}
    The polynomial $Q_{\LT_\S}(X,Y)$ yields the interpolation polynomial of the sign function $\sign_{\S'}$ defined on $\S' = [-(p-1)/2, (p-1)/2]$ as $\sign_{\S'}(x) = 1$ if $x < 0$ and $\sign_{\S'}(x) = 1$ if $x \ge 0$.
    In particular, we have
    \begin{align}\label{eq:sign_interpolation}
      Q_{\sign_{\S'}}(X) = Q_{\LT_\S}(X,0)\,.
    \end{align}
  \end{remark}
  \textbf{Complexity analysis.} The above theorem implies that the less-than function can be expressed by a univariate polynomial of degree $p-1$.
  In general, such polynomials are evaluated in $p-1$ multiplications according to Horner's method.

  To reduce the number of non-scalar multiplications, we can resort to the Paterson-Stockmeyer algorithm~\cite{SIAM:PS73} that requires $\sqrt{2(p-1)} + \log_2 (p-1) + \mathcal{O}(1)$ such multiplications.
  However, we can improve this complexity by exploiting the fact that the polynomial in~(\ref{eq:univariate_circuit}) has only one coefficient with an even index, the leading one.
  Thus, if $Z=X-Y$, we can rewrite~(\ref{eq:univariate_circuit}) as follows
  \begin{align*}
    \alpha_{p-1} Z^{p-1} + Z \sum_{i=0, \text{even}}^{p-3} \alpha_{i+1} Z^i =  \alpha_{p-1} Z^{p-1} + Z g(Z^2)
  \end{align*}
  where $\alpha_i = \sum_{a=1}^{\frac{p-1}{2}} a^{p-1-i}$ and $g(X)$ is a polynomial of degree $(p-3)/2$.
  To evaluate $g(X)$, the Paterson-Stockmeyer algorithm requires $\sqrt{p-3} + \log_2 \left(\frac{p-3}{2}\right) + \mathcal{O}(1)$ non-scalar multiplications.
  Furthermore, the preprocessing phase of this algorithm computes the powers $Z^2, Z^4, \dots, Z^{2k}$ and $Z^{4k}, Z^{8k}, \dots, Z^{2^r k}$ with $2k(2^r-1) = p-3$.
  We can use these powers to compute the leading term in $r$ non-scalar multiplications, namely
  \begin{align*}
    Z^2 Z^{2k} Z^{4k} \cdots Z^{2^r k} = Z^{2 + 2k(2^r-1)} = Z^{2 + p - 3} = Z^{p-1}.
  \end{align*}
  Since the optimal $k$ is about $\sqrt{(p-3)/2}$, we obtain that $r$ must be about $\log_2 \sqrt{p-3}$.
  Hence, the total non-scalar complexity of evaluating~(\ref{eq:univariate_circuit}) is equal to
  \begin{align*}
    \sqrt{p-3} + \frac{3 \log_2 \left(p-3\right)}{2} + \mathcal{O}(1).
  \end{align*}

  \begin{remark}
    A careful reader can notice that the leading term of~(\ref{eq:univariate_circuit}) is equal to $(X-Y)^{p-1}$, which is the heaviest part of the equality circuit $\EQ_\S(X,Y)$.
    Thus, we can get $\EQ_\S(X,Y)$ almost for free (at the cost of one homomorphic subtraction) after evaluating $\LT_\S(X,Y)$, which saves $\mathcal{O}(\log (p-1))$ non-scalar multiplications.

    This feature of the univariate circuit allows to compute all the equality operations while comparing large integers using the less-than function $\LT$ from~(\ref{eq:general_lex_order}).
    This saves $\mathcal{O}((d'-1)(k-1) \log (p-1))$ homomorphic multiplications, thus leading to a better running time than for the bivariate circuit.

    The downside of the univariate circuit is that only $(1/2)^d$ of the plaintext space is used to encode input integers in comparison to the bivariate method.
  \end{remark}

\subsection{Min/max function}

  Given the less-than function $\LT$ defined on some set, one can compute the minimum of two elements $x, y$ of this set in the following generic way
  \begin{align}\label{eq:generic_minimum}
    \min(x,y) &= x \cdot \LT(x,y) + y \cdot (1 - \LT(x,y)) \nonumber\\
    &= y + (x-y) \cdot \LT(x,y)\,.
  \end{align}
  Notice that the input difference $x - y$ naturally emerges in this expression, thus hinting that the univariate circuit from~(\ref{eq:univariate_circuit}) might be useful here.
  Indeed, by replacing $X - Y$ with a variable $Z$ we obtain the univariate polynomial representation of the minimum function on the set $\S=[0,(p-1)/2]$
  \begin{align*}
    Q_{\min_\S}(X,Y) &= Y + Z \cdot Q_{\LT_S}(X,Y) \\
    & = Y + \frac{p+1}{2} Z + \sum_{i=1}^{\frac{p-1}{2}} Z^{2i} \sum_{a=1}^{\frac{p-1}{2}} a^{p-2i} \\
    & = \frac{p+1}{2} (X+Y) + \sum_{i=1}^{\frac{p-1}{2}} Z^{2i} \sum_{a=1}^{\frac{p-1}{2}} a^{p-2i} \\
    & = \frac{p+1}{2} (X+Y) + g(Z^2)\,,
  \end{align*}
  where $g(X)$ is a polynomial of degree $(p-1)/2$.
  As a result, $\min_S(x,y)$ can be computed with $\mathcal{O}(\sqrt{p-1})$ non-scalar multiplications via the Paterson-Stockmeyer algorithm.

  Following the above reasoning, the maximum function can be computed with the following polynomial
  \begin{align*}
    Q_{\max_\S}(X,Y) &= \frac{p+1}{2} (X+Y) - \sum_{i=1}^{\frac{p-1}{2}} Z^{2i} \sum_{a=1}^{\frac{p-1}{2}} a^{p-2i}.
  \end{align*}
  \begin{remark}
    Maximum and minimum functions are basic building blocks in the design of neural networks.
    For example, one of the most popular activation functions in neural networks is the rectifier, or ReLU, which is equal to $\max(x,0)$.
    By analogy with~(\ref{eq:generic_minimum}), we have $\max(x,0) = x \cdot (1 - \sign_{\S'}(x))$ where $\S' = [-(p-1)/2,(p-1)/2]$ (see Remark~\ref{rem:sign_function}).
    Thus, Eq.~(\ref{eq:sign_interpolation}) yields the following interpolation polynomial of the ReLU function on $\S'$
    %The above polynomial of $\max_\S$ yields the following simple polynomial for the ReLU function defined on $\S=[0,(p-1)/2]$
    \begin{align*}
      Q_{\ReLU_{\S'}}(X) &= X \cdot (1 - Q_{\sign_{\S'}}(X))\\
      &= \frac{p+1}{2} X - \sum_{i=1}^{\frac{p-1}{2}} X^{2i} \sum_{a=1}^{\frac{p-1}{2}} a^{p-2i}.
    \end{align*}
  \end{remark}

  \subsection{Impact on the overall complexity}
  In this section, we summarize the complexities of our method as compared to the work of Tan et al. for the evaluation of the less-than function using the lexicographical order method described in Section \ref{sec:background}.

  For fixed $p$ and $d$, Tan et al.~\cite[Section 4.4]{TLWRK20} determined that the depth of the circuit evaluating the less-than function of two $b$-bits integers is equal to
  \begin{equation}
    \label{eq:circuit-depth}
    \lfloor \log_2 d \rfloor + \lfloor \log_2 (p-1) \rfloor + \lfloor \log_2 (\log_p 2^b)/d) \rfloor + 4.
  \end{equation}
  Note that our algorithms do not decrease the depth of the circuit.
  Similarly, Tan et al. showed that the number of homomorphic multiplications required to evaluate the less-than function of two $b$-bit integers with the bivariate interpolation is
  $$ d\cdot\left(T+ \lceil\log_2(p-1)\rceil + \lceil \log_2 d \rceil \right) + \lfloor\log_2(\log_p 2^b)/d)\rfloor+2. $$
  where $T$ is the number of homomorphic multiplications required to evaluate the comparison circuit over $\mathbb{F}_p$.
  In the work of Tan et al. $T = 3p-5$, while in our case it is $T = 2p-6$.

  The univariate method saves even more multiplications since one can extract $1 - \EQ_\S(x,y)$ while computing $\LT_\S(x,y)$.
  Hence, we obtain $\EQ_\S(x,y)$ almost for free when evaluating the lexicographical order (Remark 2). Thus, in this case the comparison of two $b$-bits integers requires
  $$ d\cdot\left(T + \lceil \log_2 d \rceil \right) + \lfloor\log_2(\log_p 2^b)/d)\rfloor+2. $$
  with $T\approx \sqrt{2p-4}+3(\log_2(2p-4))/2$ by using the Paterson-Stockmeyer algorithm.

% \subsection{Lexicographic order}\label{subsec:lexicographic_order}
%   Let $\vx=(x_0,x_1,\ldots,x_{\ell-1})$ and $\vy=(y_0,y_1,\ldots,y_{\ell-1}) \in \F_\fieldcard^\ell$ for the lexicographical order $<$ defined by the choice of $\S$:
%   \begin{align*}
%     \vx < \vy \Leftrightarrow \exists i\in[0,\ell-1] \text{ such that } x_i < y_i \text{ and } \forall j > i ~~ x_j = y_j\,.
%   \end{align*}
%   This order induces a function $\LT_{\F_\fieldcard}(\vx, \vy)$ that returns $1$ if $\vx < \vy$ and $0$ otherwise.
%   As done in~\cite{TLWRK20}, we can employ $\EQ_{\F_\fieldcard}$ and $\LT_{\F_\fieldcard}$ to compute $\LT_{\F_\fieldcard}(\vx, \vy)$ as follows
%   \begin{align*}
%     \LT_{\F_\fieldcard}(\vx, \vy) = \sum_{i=0}^{\ell-2} \LT_{\F_\fieldcard}(x_{i}, y_{i}) \prod_{j=i+1}^{\ell-1} \EQ_{\F_\fieldcard}(x_{j}, y_{j}) + \LT_{\F_\fieldcard}(x_{\ell-1}, y_{\ell-1}).
%   \end{align*}
%   Notice that the multiplicative depth of this function solely depends on the products of the equality functions.
%   In fact, these products compare subvectors $\vx_i = (x_i, x_{i+1},\dots,x_{\ell-1})$ and $\vy_i = (y_i, y_{i+1},\dots,y_{\ell-1})$ for $i \in [1,\ell-1]$.
%   Thus, we can rewrite $\LT_{\F_\fieldcard}$ as
%   \begin{align}\label{eq:general_lex_order}
%     \LT_{\F_\fieldcard}(\vx, \vy) = \sum_{i=0}^{\ell-2} \LT_{\F_\fieldcard}(x_{i}, y_{i}) \EQ_{\F_\fieldcard}(\vx_{i+1}, \vy_{i+1}) + \LT_{\F_\fieldcard}(x_{\ell-1}, y_{\ell-1})
%   \end{align}
%   with the equality function $\EQ_{\F_\fieldcard}(\vx_{i+1}, \vy_{i+1})$ that returns $1$ if $\vx_{i+1} = \vy_{i+1}$ and $0$ otherwise.
%   As shown in~\todo{cite our work}, this function can be realized by a constant-depth circuit in the following way.
%   \begin{align}\label{eq:rand_eq_circuit}
%     \EQ_{\F_\fieldcard, e}(\vx_{i+1},\vy_{i+1}) = 1 - \princhar_{\fieldcard^e}\left(\sum_{j=i+1}^{\ell-1} r_j (x_j - y_j)\right)
%   \end{align}
%   where $r_j$ are uniformly random elements from $\F_{\fieldcard^e}$.
%   This circuit is false-biased with error probability $\fieldcard^{-e}$.
%   We can compute all $\EQ_{\F_\fieldcard, e}(\vx_{i+1},\vy_{i+1})$ using the same number of multiplications as for the single equality using Algorithm~\ref{alg:vector_equalities_circuit}.\todo{What is the complexity?}
%   \begin{algorithm}[t]
%     \KwIn{
%     $\ct_\vx$ -- a ciphertext encrypting $\vx \in \F^\ell_\fieldcard$,
%     $\ct_\vy$ -- a ciphertext encrypting $\vy \in \F^\ell_\fieldcard$.
%     }
%     \KwOut{$\ct$ -- a ciphertext containing the output of $\EQ_{\F_\fieldcard, e}(\vx_{i+1},\vy_{i+1})$ in the $i$th SIMD slot}
%     $\ct_1 \leftarrow \Shift(\ct_\vx, 1)$ // removes the value $x_0$ and shifts $\vx$ to the left\\
%     $\ct_2 \leftarrow \Shift(\ct_\vy, 1)$ // removes the value $y_0$ and shifts $\vy$ to the left\\
%     $\ct \leftarrow \Sub(\ct_1, \ct_2)$ // $(x_i - y_i), i \in [1,\ell-1]$\\
%     $r_0,r_1,\dots,r_{\ell-1} \leftarrow \udist(\F_{\fieldcard^e})$ //\todo{define uniform distribution}\\
%     $\pt_r \leftarrow \pt(r_0,r_1,\dots,r_{\ell-1})$\\
%     $\ct \leftarrow \ct \cdot \pt_r$ // $r_i(x_i - y_i), i \in [1,\ell-1]$\\
%     $k \leftarrow 1$// $\sum_{j=i}^{\ell-1} r_i(x_i - y_i), i \in [1,\ell-1]$\\
%     \While{$k < \ell-1$}{
%       $\ct_{tmp} \leftarrow \Shift(\ct, k)$\\
%       $\ct \leftarrow \ct + \ct_{tmp}$\\
%       $k \leftarrow 2k$\\
%     }
%     $\ct \leftarrow \Power(\ct, \fieldcard^e-1)$ //$\princhar_{\fieldcard^e}\left(\sum_{j=i}^{\ell-1} r_i(x_i - y_i)\right), i \in [1,\ell-1]$ \\
%     $\ct \leftarrow 1 - \ct$\\
%     \textbf{Return} $\ct$.
%     \caption{Homomorphic circuit computing $\EQ_{\F_\fieldcard, e}(\vx_{i+1},\vy_{i+1})$ in parallel.}\label{alg:vector_equalities_circuit}
%   \end{algorithm}

%   Let us go back to the lexicographic order in equation~(\ref{eq:general_lex_order}).
%   Assume that we have a ciphertext $\ct_{\LT}$ containing $\LT_{\F_\fieldcard}(x_i, y_i)$ in the $i$th slot (\todo{elaborate on that}) and the output $\ct_{\EQ}$ of Algorithm~\ref{alg:vector_equalities_circuit}.
%   We set the $\ell-1$ slot of $\ct_{\EQ}$ to $1$ and multiply it by $\ct_{\LT}$.
%   The resulting ciphertext contains all the products $\LT_{\F_\fieldcard}(x_{i}, y_{i}) \EQ_{\F_\fieldcard}(\vx_{i+1}, \vy_{i+1})$ for any $i \in [0,\ell-2]$ and $\LT_{\F_\fieldcard}(x_{\ell-1}, y_{\ell-1})$, which can be summed in the same way as in the while circuit of Algorithm~\ref{alg:vector_equalities_circuit}.
%   As a result, we obtain a ciphertext with the output of $\LT_{\F_\fieldcard}(\vx, \vy)$ in the first SIMD slot.

%   \subsubsection{Comparing large integers.}
%   Since any integer $z$ can be represented in base $\fieldcard$ as $z = \sum_{i=0}^{\ell-1} z_i q^i$, we can encode $z$ into SIMD slots as a vector $(z_0,z_1,\dots,z_{\ell-1}) \in \F_{\fieldcard}^\ell$.
%   As shown above, we can compare such vectors using the lexicographic order function in~(\ref{eq:general_lex_order}) and thus compare integers larger than $\fieldcard$.

%   \todo{Incorporate the following into the complexity analysis.}
%   We can obtain ciphertexts encrypting $(x,x,\ldots, x)$ and $(y,y,\ldots, y)$ with $2\log_2(q-1)\texttt{Rot}$ and $2\log_2(q-1)\texttt{Add}$.

%   From there we can obtain encryptions of $(x,x-1,\ldots, x-q-2)$ and $(y-1,y-2,\ldots, y-q-1)$ with $2\texttt{Add}$. We can apply $f$ to these vectors in parallel with a depth of $\log (p-1) + \log d$ for a cost of $2(\log (p-1) + wt(p-1) + d - 2) \texttt{Mult}$. This can be minimized by choosing $p = 2^d + 1$ for some $d$.

%   With $2$ more $\texttt{Sub}$ we obtain encryptions of $(1-f(x), 1-f(x-1), \ldots, 1-f(x-q-2))$ and $(1-f(y-1), 1-f(y-2), \ldots, 1-f(y-q-1))$. From there we can get an encryption of the different partial sums in $\log_2(q-1)\texttt{Rot}$, $\log_2(q-1)\texttt{Select}$ and $\log_2(q-1)\texttt{Add}$. The algorithm works as follow:

%   \begin{center}
%     \begin{tikzpicture}[scale=0.8]
%       \newcommand\y{-4};

%       \draw (0,2) -- (16,2);
%       \draw (0,0) -- (16,0);
%       \foreach \x in {0,...,8}{
%         \draw (2*\x,0) -- (2*\x,2);
%       }
%       \foreach \x in {0,...,7}{
%         \node at (2*\x+1,1) {$x_\x$};
%       }

%       \draw (0,2+\y) -- (16,2+\y);
%       \draw (0,\y) -- (16,\y);
%       \foreach \x in {0,...,8}{
%         \draw (2*\x,0+\y) -- (2*\x,2+\y);
%       }

%       \node at (1,1+\y) {$x_0 + x_1$};
%       \node at (3,1+\y) {$x_1 + x_2$};
%       \node at (5,1+\y) {$x_2 + x_3$};
%       \node at (7,1+\y) {$x_3 + x_4$};
%       \node at (9,1+\y) {$x_4 + x_5$};
%       \node at (11,1+\y) {$x_5 + x_6$};
%       \node at (13,1+\y) {$x_6 + x_7$};
%       \node at (15,1+\y) {$x_7$};

%       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%       \draw (0,2+2*\y) -- (16,2+2*\y);
%       \draw (0,0+2*\y) -- (16,0+2*\y);
%       \foreach \x in {0,...,8}{
%         \draw (2*\x,0+2*\y) -- (2*\x,2+2*\y);
%       }

%       \node at (1,1+2*\y) {$\begin{array}{c}
%           x_0 + x_1  \\
%           + x_2 + x_3
%         \end{array}$};
%       \node at (3,1+2*\y) {$\begin{array}{c}
%           x_1 + x_2  \\
%           + x_3 + x_4
%         \end{array}$};
%       \node at (5,1+2*\y) {$\begin{array}{c}
%           x_2 + x_3  \\
%           + x_4 + x_5
%         \end{array}$};
%       \node at (7,1+2*\y) {$\begin{array}{c}
%           x_3 + x_4  \\
%           + x_5 + x_6
%         \end{array}$};
%       \node at (9,1+2*\y) {$\begin{array}{c}
%           x_4 + x_5  \\
%           +x_6 + x_7
%         \end{array}$};
%       \node at (11,1+2*\y) {$\begin{array}{c}
%           x_5 + x_6  \\
%           + x_7
%         \end{array}$};
%       \node at (13,1+2*\y) {$x_6 + x_7$};
%       \node at (15,1+2*\y) {$x_7$};

%       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%       \draw (0,2+3*\y) -- (16,2+3*\y);
%       \draw (0,0+3*\y) -- (16,0+3*\y);
%       \foreach \x in {0,...,8}{
%         \draw (2*\x,0+3*\y) -- (2*\x,2+3*\y);
%       }

%       \node at (1,1+3*\y) {$\begin{array}{c}
%           x_0 + x_1  \\
%                               + x_2 + x_3 \\
%                               + x_4 + x_5 \\
%                               + x_6 + x_7
%         \end{array}$};
%       \node at (3,1+3*\y) {$\begin{array}{c}
%           x_1 + x_2  \\
%                               + x_3 + x_4 \\
%                               + x_5 + x_6 \\
%                               + x_7 \\
%         \end{array}$};
%       \node at (5,1+3*\y) {$\begin{array}{c}
%           x_2 + x_3  \\
%                               + x_4 + x_5 \\
%                               + x_6 + x_7
%         \end{array}$};
%       \node at (7,1+3*\y) {$\begin{array}{c}
%           x_3 + x_4  \\
%                               + x_5 + x_6 \\
%                               +x_7
%         \end{array}$};
%       \node at (9,1+3*\y) {$\begin{array}{c}
%           x_4 + x_5  \\
%           +x_6 + x_7
%         \end{array}$};
%       \node at (11,1+3*\y) {$\begin{array}{c}
%           x_5 + x_6  \\
%           + x_7
%         \end{array}$};
%       \node at (13,1+3*\y) {$x_6 + x_7$};
%       \node at (15,1+3*\y) {$x_7$};

%       \foreach \x in {2,...,8}
%       \draw[->,thick = 2pt] (2*\x-0.1-1,2) to[bend right] (2*\x-3+0.1,2);

%       \foreach \x in {3,...,8}
%       \draw[->,thick = 2pt] (2*\x-0.1-1,2+\y) to[bend right] (2*\x-5+0.1,2+\y);

%       \foreach \x in {5,...,8}
%       \draw[->,thick = 2pt] (2*\x-0.1-1,2+2*\y) to[bend right] (2*\x-9+0.1,2+2*\y);

%   \end{tikzpicture}
%   \end{center}

%   From there we just have to compute the scalar product of the two vectors with $1\texttt{Mult} + \log_2(q-1)\texttt{Rot} + \log_2(q-1)\texttt{Add}$. \newline

%   So overall we can compute $<$ over $\mathbb{F}_q$ for $q = p^d$ in:

%   \begin{itemize}
%   \item $4\log_2 (q-1) \texttt{Rot}$
%   \item $(4\log_2 (q-1) + 4) \texttt{Add}$
%   \item $(2(\log (p-1) + wt(p-1) + d - 2) + 1) \texttt{Mult}$
%   \item $(\log_2 (q-1) + 1) \texttt{Select}$
%   \end{itemize}

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


\documentclass[12pt]{article}

\usepackage{setspace}

\usepackage{amsmath, amsfonts, amssymb, graphicx, color, fancyhdr, mathrsfs, tikz-cd, mdframed, enumitem, framed, adjustbox, bbm, upgreek, xcolor, hyperref}
\usepackage[framed,thmmarks]{ntheorem}
\usepackage[style=alphabetic]{biblatex}
%Set the bibliography file
\bibliography{sources}

%Replacement for the old geometry package
\usepackage{fullpage}

%Input my definitions
\input{./mydefs.tex}

%Shade definitions
\theoremindent0cm
\theoremheaderfont{\normalfont\bfseries}
\def\theoremframecommand{\colorbox[rgb]{0.9,1,.8}}
\newshadedtheorem{defn}[thm]{Definition}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% Customize Below %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%header stuff
\setlength{\headsep}{24pt}  % space between header and text
\pagestyle{fancy}     % set pagestyle for document
\lhead{Notes on the Grassmannian} % put text in header (left side)
\rhead{Nico Courts} % put text in header (right side)
\cfoot{\itshape p. \thepage}
\setlength{\headheight}{15pt}
\allowdisplaybreaks

% Document-Specific Macros
\DeclareMathOperator{\Gr}{Gr}
\DeclareMathOperator{\Flag}{Flag}
\DeclareMathOperator{\GL}{GL}
\newcommand{\Alg}{\mathbf{Alg}}
\newcommand{\CRing}{\mathbf{CRing}}
\DeclareMathOperator{\inv}{inv}
\newcommand{\detq}{\operatorname{det}_q}
\let\k\relax
\newcommand{\k}{\mathbbm{k}}

\begin{document}
%make the title page
\title{Notes on the Grassmannian \vspace{-1ex}}
\author{Nico Courts}
\date{Summer 2019}
\maketitle

\begin{abstract}
	These notes are my summary of the realization of the Grassmanian $\Gr(n,k)$ as a quotient of
	the Lie group $\GL(n,\k)$. In particular the focus will be on $\k=\bbR$ or $\bbC$. I also talk about quantum
	deformations of $\GL(n,\k)$ and $\Gr(n,k)$.
\end{abstract}

\section*{Vista: Where We're Headed}
The idea that $\GL_n$ acts on vector subspaces of a Euclidean space should be unsurprising and natural, but
the upshot to considering this viewpoint is that is allows us to consider this object from the perspective of smooth
manifold theory. This gives us some great machinery to grasp onto to prove some nice properties
about $\Gr(n,k)$.

Eventually I will lead us slightly astray by investigating a ``quantum analog'' of $\Gr(n,k)$. This $q$-deformation
is related closely to the kinds of structures I have been thinking about recently: specifically quantum groups. One can think of
these as ``deformations'' of groups in some controlled way.

\section{The Grassmannian as a Lie group quotient}
In the following, let $\k=\bbR$ or $\bbC$ and let $V=\k^n$. For a great introduction to this theory see \cite{LeeISM},
(specifically chapters 1, 7, and 21), which serves as the primary source for this section.
\subsection{Smooth Manifolds}
Recall that a smooth manifold is a topological manifold equipped with a \textbf{smooth structure}: that is, an atlas comprised
of smoothly-compatable charts (ones where the transition functions are smooth as maps of Euclidean spaces).
\subsection{The general linear Lie group}
Let $G=\GL(V)$, initially considered just as a group. In fact, one can apply to $G$ a smooth structure very naturally
by recognizing $\GL(V)\subseteq M_{n\times n}(\k)$, the latter of which is identified with the Euclidean space $\k^{n^2}$,
whose smooth structure is the obvious one (the identity map).

That $G$ itself is a smooth manifold comes from the fact that $\GL(V)=\det^{-1}(\k\setminus\{0\})$, which is
itself an open set as the inverse image of an open set under a continuous map. So then $G$ is a (codimension zero) open (smooth) submanifold
of $M_{n\times n}(k)$ whose smooth structure is inherited from the ambient space.

In fact, the algebraic and geometric structure of $G$ come together in a very nice way to define what is called
a \textbf{Lie group:}
\begin{defn}
	Let $G$ be a smooth manifold. Then a \textbf{Lie group} is $G$ along with a group structure given by maps $m:G\times G\to G$ and $i:G\to G$
	(representing multiplication and inverse maps) such that $m$ and $i$ are smooth maps (smooth in charts).
\end{defn}

\begin{prop}
	$G$ is a Lie group.
\end{prop}
\begin{prf}
	Since we have already defined the smooth and group structures on $G$, it suffices to show that
	$m$ and $i$ (matrix multiplication and the inverse map) are smooth maps.

	Multiplication is smooth since if we consider the $i^{th}$ component function of $m$, where $i=an+b$ for $1\le a,b\le n$, we get (for $\mathbf x$ and $\mathbf y$ in $\k^{n^2}$)
	\[m_i(\mathbf x,\mathbf y)=\sum_{k=1}^{n}\mathbf x_{an+k}\mathbf y_{kn+b}\]
	which is a polynomial in the $x_i$ and $y_i$ and is thus (clearly) smooth.

	That the inverse map is also smooth follows via similar reasoning: since $\det$ is smooth (again a polynomial in the entries),
	computing the adjugate matrix is a smooth operation and so via Cramer's rule (since $\det A\ne 0$)
	\[i(A)=\frac{1}{\det A}\operatorname{adj}A\]
	is also a smooth operation.
\end{prf}

\subsection{The action on \texorpdfstring{$\Gr(n,k)$}{Gr(n,k)}}
The first thing to notice is that there is a natural action
of $G$ on the set of $k$-dimensional subspaces of $V$ in the following way: let $A\in\GL(V)$ and let $W\le V$ be a $k$-dimensional
subspace. Then $A(W)$ is also $k$-dimensional since $A$ is invertible\footnote{If you are not convinced, remember that $A$ being invertible means all minors are nonsingular,
so by extending a basis for $W$ to $V$ and looking at $A$ in this basis, the top-left $k\times k$ matrix defines an isomorphism
of $W$ onto some other subspace of $V$.}.
\begin{prop}
	The action defined above gives a group action of $\GL(V)$ on $\Gr(n,k)$.
\end{prop}
\begin{prf}
	This is clear since the identity matrix $I_n$ fixes subspaces and since matrix multiplication is associative.
\end{prf}

\subsection{Defining a smooth structure on the Grassmanian}
As we are working in the context of smooth manifolds, we need to make some sense of how this action fits into the theory of smooth group actions.
Normally,
\begin{defn}
	If $G$ is a Lie group and $M$ is a smooth manifold, we say $G$ acts smoothly on $M$ if $G$ acts on $M$ as a set and the map
	\[\rho:G\times M\to M\]
	given by
	\[\rho(g,m)=g.m\]
	is a smooth map.
\end{defn}
In this case, we don't have a smooth structure (yet!) on $\Gr(n,k)$, so we will define one:

\subsubsection{Stabilizers}
Our first step is to show that the stabilizer of an arbitrary $W\in\Gr(n,k)$, denoted $G_W$, is a closed Lie subgroup (that is a Lie group and closed smooth submanifold).
To this end:
\begin{thm}[Closed Subgroup Theorem]\label{thm-closed-subgroup}
	Suppose $G$ is a Lie group and $H\subseteq G$ is a subgroup that is also a closed subset of $G$. Then $H$ is an embedded
	Lie subgroup.
\end{thm}
\begin{rmk}
	The proof of this theorem is two pages of Lie theory and is a little involved for this talk. Jack does
	a great job (as always) in his proof (cf. \cite[Thm. 20.12]{LeeISM})
\end{rmk}

\noindent Using this theorem we start by proving something about a particular subset:
\begin{prop}\label{prop-GW}
	Fix some basis $\calB$ for $V$. Let $W\le V$ be the subspace of $\k^n$ by setting the last $(n-k)$ coordinates in this basis to zero (which is isomorphic to $\k^k$). Then
	the stabilizer $G_W$ of $W$ is
	\[G_W=\left\{\begin{pmatrix}
		A & B\\ 0 & D
	\end{pmatrix}:A\in\GL_k(\k),\ D\in\GL_{n-k}(\k),\ B\in M_{k\times n-k}(\k)\right\}\]
	and this set is a closed Lie subgroup of $\GL(V)$.
\end{prop}
\begin{prf}
	We begin by noticing that $G_W$ as above is precisely the stabilizer of $W$. But because we picked
	$W$ in the way we did, we know immediately that $\calA\in\GL(V)$ fixes $W$ if the $i^{th}$ coordinate
	of $\calA(\mathbf x)$ is zero for all $\mathbf x=(x_1,\dots,x_k,0,\dots,0)$. Since that $x_i$ are arbitrary,
	we get that $\calA$ is block upper triangular as above. That $A$ and $D$ are invertible comes from the fact that
	\[\det\calA=\det A\det D\ne 0.\]
	Therefore the stabilizer of $W$ is contained in $G_W$. The reverse inclusion is clear.

	That $G_W$ is a subgroup of $\GL(V)$ then follows from group theory. In light of thm.~\ref{thm-closed-subgroup},
	proving that $G_W$ is a Lie subgroup amounts to showing that $G_W$ forms a closed subset of $\GL(V)$. But this is clear because
	this is inverse image of all of $\GL_k(\k)$ under $F:\GL(V)\to\GL_k(\k)$ that maps a matrix to the $k\times k$ minor in the upper left corner.

	Equivalently, $G_W$ is defined by the closed condition $\calA_{ij}=0$ if $i\ge k_1$ and $j\le k$. That every such matrix has the form of $G_W$ is
	clear as argued above.

	Thus $G_W$ is closed, so is a closed Lie subgroup of $G$.
\end{prf}

So we have shown that a particular stabilizer $G_{\k^k}$ is a closed Lie subgroup, but in fact this holds for \textit{any $W\in\Gr(n,k)$:}
\begin{cor}
	For any $W\in\Gr(n,k)$, $G_W$ is a closed Lie subgroup of $G$.
\end{cor}
\begin{prf}
	Simply choose a new basis for $V$ such that all vectors in $W$ are of the form
	\[(v_1,\dots,v_k,0,\dots,0)\]
	and apply prop.~\ref{prop-GW}.
\end{prf}

\subsubsection{The Quotient Manifold Theorem}
Recall from point-set topology that a proper map is one that pulls back compact sets to compact sets.
\begin{defn}
	An action of a Lie group $G$ on a smooth manifold $M$ is \textbf{proper} if the map
	\[G\times M\to M\times M\qquad \text{via}\qquad (g,p)\mapsto(g.p,p)\]
	is a proper map.
\end{defn}
\begin{rmk}
	Jack (\cite[Ex. 21.3]{LeeISM}) says that this is a \textit{strictly weaker} condition than saying
	$(g,p)\mapsto g.p$ is proper.
\end{rmk}
\begin{thm}[Quotient Manifold Theorem]\label{thm-QMT}
	Let $G$ be a Lie group acting \textit{smoothly, freely, and properly} on a smooth manifold $M$. Then
	the orbit space $M/G$ is a topological manifold of dimension $\dim M-\dim G$ and has a unique smooth structure
	making the quotient map $\pi:M\to M/G$ a smooth submersion.
\end{thm}
\begin{prf}
	As before, see Jack's proof \cite[thm. 21.10]{LeeISM}.
\end{prf}
\begin{rmk}
	In case this wasn't obvious, this is a rather high-powered result and is the primary facilitator of what follows.
\end{rmk}

\subsubsection{Homogeneous Spaces}
\begin{defn}
	A smooth manifold $M$ endowed with a \textit{transitive, smooth} action by a Lie group $G$ is called
	a \textbf{homogeneous space.}
\end{defn}
Then we use the quotient manifold theorem to construct a homogeneous space for ourselves (following part of the proof of \cite[thm. 21.17]{LeeISM}):
\begin{prop}
	Let $W$ be an arbitrary element in $\Gr(n,k)$. Then if $G=\GL(V)$, $G/G_W$ is a homogeneous space given by the action
	\[g\cdot (g'G_W)=(gg')G_W\]
\end{prop}
\begin{prf}
	Consider the action of $G_W$ on $G$ by left multiplication. This action is free since if $hg=g$, we get $h=e$. The action is a restriction of
	$G$ on itself by left multiplication, which is smooth by virtue of being a Lie group, so the action is smooth.

	To see the action is proper, we use the fact (proved in \cite[prop. 21.5(a,b)]{LeeISM}) that the action is proper if and only if $(h_i)$ is a sequence in $G_W$ and
	$(g_i)$ are a sequence in $G$, if both $(h_i)$ and $(h_ig_i)$ converge then the $(g_i)$ converge.

	Let $(g_i)$ be a convergent sequence in $G$ and $(h_i)$ a sequence in $G_W$ such that $(h_ig_i)$ converges. Then by the continuity of
	the $G$ action on itself, $h_i=(h_ig_i)g_i^{-1}$ converges to a point in $G$. Since $G_W$ is closed in $G$, this limit converges in $G_W$.

	Thus we can apply thm~\ref{thm-QMT} to say that $G/G_W$ has a unique smooth manifold structure making the quotient map $\pi:G\to G/G_W$ a smooth submersion. The action
	\[g\cdot g'G_W=(gg')G_W\]
	is transitive and smooth, giving us our homogeneous space.
\end{prf}
\subsubsection{Bringing it home}
Now that we have that $G/G_W$ is a smooth manifold, consider the map
\[F:G/G_W\to \Gr(n,k)\]
be defined by
\[F(A\cdot G_W)=A(W).\]

\begin{lem}
	$F$ defined as above is a $G$-equivariant bijection.
\end{lem}
\begin{prf}
	This is a well-defined map since if $gG_W=g'G_W$, we get that $g=g'h$ for some $h\in G_W$, thus
	\[F(gG_W)=g\cdot W=g'hW=g'W=F(g'G_W).\]

	Then that this map is surjective follows since the action of $G$ on $\Gr(n,k)$ has a single orbit. That
	the map is injective follows since if the images of the same, this means precisely that $gW=g'W$, so $g^{-1}g'\in G_W$,
	proving $gG_W=g'G_W$.

	$G$-equivariance is a simple consequence of the fact
	\[g\cdot F(g'G_W)=g\cdot (g'W)=(gg')W=F(gg'G_W)=F(g(g'G_W)).\]
\end{prf}

\noindent Now we can give $\Gr(n,k)$ a smooth structure such that $F$ is a diffeomorphism\footnote{Open sets are precisely the images of open sets of $G/G_V$ and the smooth
structure is the one pulled back through $F$.}. Notice now that the action of $G$ on $\Gr(n,k)$ is smooth since we can write
\[g\cdot V=F(g\cdot F^{-1}(V))\]
since $F$ and the action of $G$ on $G/G_W$ is smooth.

We still need to establish that such a smooth structure is, in some sense, \textit{the} structure that makes
the action provided into a smooth action. This will be the smooth structure we give the Grassmannian.

We need one more theorem from smooth manifolds to finish this off:
\begin{thm}[Equivariant Rank Theorem]
	Let $M$ and $N$ be smooth manifolds and $G$ be a Lie group. If $F:M\to N$ is a smooth, bijective, $G$-equivariant map with respect to
	a smooth, transitive action of $G$ on $M$ and any smooth action of $G$ on $N$, then $F$ is a diffeomorphism.
\end{thm}
\begin{prf}
	See \cite[thm 7.25]{LeeISM}.
\end{prf}
\begin{lem}
	There is only one smooth structure on $X=\Gr(n,k)$ such that the action of $G$ on $X$ is smooth.
\end{lem}
\begin{prf}
	Let $\tilde X$ be $X$ with any other smooth structure. Then if $G$ acts smoothly on $\tilde X$, the (smooth) action $\theta^{(W)}:G\to \tilde X$ given by $\theta^{(W)}(g)=g\cdot W$
	descends to the quotient to give us a smooth map $\calF:G/G_W\to \tilde X$, which as before can be shown to be a $G$-equivariant bijection.

	But then by the equivariant rank theorem since the action of $G$ on $G/G_W$ is smooth and transitive, and the action of $G$ on $\tilde X$ is smooth,
	the map $\calF$ is a diffeomorphism. But then in particular since $F$ gave us a diffeomorphism from $G/G_W$ to $X$,
	we have a diffeomorphism $X\cong \tilde X$, so the smooth structure on $X$ is unique.
\end{prf}
\subsection{Denouement: \texorpdfstring{$\Gr(n,k)$}{Gr(n,k)} is compact.}
I found a neat proof of this online \href{https://math.stackexchange.com/questions/148088/compactness-of-the-grassmannian}{here}.
\begin{prop}
	$\Gr(n,k)$ is compact.
\end{prop}
\begin{prf}
	Let $S=\{v\in V=\k^n: \|v\|=1\}$. Notice that $S\cong \bbS^{n-1}$, the $n-1$ sphere in $\k^n$, which is compact. Then $S^d=S\times \cdots\times S$ is compact as well.

	Considering $S^d$ as some choice of $d$ unit vectors in $\k^n$, we can consider the map
	\[S^d\to\k^{\binom{d}{2}}\qquad\text{via}\qquad (v_1\dots,v_d)\mapsto (v_1\cdot v_2,v_1\cdot v_3,\dots,v_1\cdot v_n,v_2\cdot v_3,\dots,v_{n-1}\cdot v_n)\]
	and notice that pulling back $\mathbf 0$ in this map gets us a (closed whence) compact subspace $C$ of $S^d$ corresponding to the
	sets of $d$ orthonormal vectors in $\k^n$.

	Finally define the equivalence relation on $C$ where $c_1\sim c_2$ if $\operatorname{span} c_1=\operatorname{span} c_2$. Then the quotient
	$C/\sim$ is precisely $\Gr(n,k)$ which, as a quotient of a compact space, is compact.
\end{prf}

\section{Aside: Quantized Grassmanians}
In this section I will take a little time to develop some of the things I have been learning about quickly,
specifically developing non-commutative algebraic geometry by relying on intuitions from traditional algebraic geometry
while ``deforming'' things in a controlled way so that we can use our intuition to develop analogous ideas.

\subsection{Algebra vs. Geometry}
The discussion that follows is a relatively constructive method for $q$-deforming the Grassmannian and studying the action it
inherits from $\GL_q(n)$. It gives a good flavor for the field, but is very strongly rooted in algebra.

That is, the methods we describe take the coordinate ring of the Grassmannian and deform it purely in the realm of algebra, with the understanding
that there is some parallel geometric structure that is being analogously twisted.

Late in my research, I found a paper by Aaron Lauve \cite{lauve} takes the results of Taft and Towber and reimagines them in a context that
preserves a certain level of geometry. I haven't had time to read it in its entirety but it may be a good place to look for those interested in the geometry.

\subsection{Hopf Algebras}
The leading idea here is that Hopf algebras lie at the heart of a lot of modern algebra---especially representation theory. Sometimes you are working with
a Hopf algebra without knowing it!

Let's begin with a definition:
\begin{defn}
	A \textbf{Hopf algebra} is a $k$-vector space $A$ equipped with maps
	\begin{gather*}
		\mu:A\otimes A\to A\\
		\eta:k\to A\\
		\Delta:A\to A\otimes A\\
		\varepsilon:A\to k\\
		S:A\to A
	\end{gather*}
	such that $\mu$ and $\eta$ form an associative algebra structure on $A$, $\Delta$ and $\varepsilon$ form a coassociative coalgebra structure on $A$,
	$\mu$ is a coalgebra morphism, $\Delta$ is an algebra morphism (so far we have defined a bialgebra) and furthermore $S:A\to A$ is an antihomomorphism:
	\[S(ab)=S(b)S(a)\]
	and such that all the maps satisfy the following:
	\[\mu\circ S\otimes\id\circ \Delta(a)=S(a_1)a_2=a_2S(a_2)=\mu\circ \id\otimes S\circ\Delta(x)=\eta\circ\varepsilon(x)\]
\end{defn}
\begin{rmk}
	We used Sweedler notation above to simplify things although it looks deceptively simple to the uninitiated.
\end{rmk}
\begin{rmk}
	In shorter terms,
\end{rmk}

\subsubsection{Examples of Hopf algebras}
These algebras pop up relatively frequently! For instance, the tensor, symmetric, and exterior algebras on a vector space are all
readily made into Hopf algebras.

I am a representation theorist, so my primary examples tend to revolve around
the group algebra $k[G]$ of a group. It is a Hopf algebra where you define the Hopf algebra structure by making all
elements of $G$ grouplike\footnote{$\Delta(x)=x\otimes x$, $\varepsilon(x)=1$ and $S(x)=x^{-1}$} and extending $k$-linearly.

You can also dualize things somewhat and consider the algebra of regular functions on $G$, denoted $kG$ or $k(G)$. When $G$ is finite,
these are isomorphic but when $G$ is infinite these can be quite different. In either of these contexts one can interchange ``group''
with ``group scheme'' or ``algebraic group''. A quite nice treatment of the affine case (that is when the Hopf algebra is finite dimensional over a field)
can be found in \cite{waterhouse}. If you are interested in a highly representation-theoretic treatment of algebraic groups, you can can check out \cite{jantzen-algebraic}
or \cite{Milne}.

Finally the last way these arise in nature is in the universal enveloping algebra $\calU(\frakg)$ of a Lie algebra $\frakg$. One can find the theory here developed in Jantzen's
other book \cite{jantzen-quantum}.

\subsection{Quantum deformations of Hopf algebras}
In all of the above examples, the Hopf algebra is either commutative or cocommutative and in fact you get some nice equivalences of categories
between, for instance, group schemes over a field $k$ and commutative Hopf algebras over $k$. The ``quantum perspective'' is the tendency to
ask the question: \textit{what about the non-commutative, non-cocommutative Hopf algebras?}

In some way, the study of quantum groups is the attempt to consider the Hopf algebras that fall in the gaps between the more ``natural'' ones.

\subsection{The idea}
The primary source for this section is Taft and Towber's \textit{Quantum deformation of flag schemes and Grassmann schemes} \cite{quantum-flag}.
Our tact here is to build up an algebra (thought of as the ring of functions on the flag or Grassmannian scheme) and through deformation of this algebra,
$q$-deform the space.

\begin{rmk}
	Generally when working with vector spaces one can more-or-less forget about which basis is chosen when working in coordinates. Unfortunately here
	the commutativity (or lack thereof) of a quantum deformation is highly dependent on the choice of \textit{ordering} of any basis. Thus we will be considering commutative rings $\k$ and
	$\k$-algebras freely generated by some fixed \textbf{ordered} basis $\calB=\{v_1,\dots,v_n\}$.

	In what follows I will suppress the basis $\calB$ (e.g. write $\Flag^n(\calB)$ as $\Flag^n$) but remember that it is vital to the construction.
\end{rmk}

\subsection{The affine flag scheme \texorpdfstring{$\Flag^n(\calB)$}{Flag-n(B)}}
\begin{rmk}
	I will admit that here is the most difficult part for me: defining these objects\footnote{As well as seeing why these objects are what their names imply they should be} requires some geometry
	that is beyond my understanding at the moment. I will do my best, but the geometers among you may notice some
	holes in my justification. Corrections are warmly welcomed.
\end{rmk}
The idea here is to define the scheme $\Flag^n:=\Flag^n(\calB):\CRing\to\Set$ which assigns to any commutative ring $\k$ the (commutative, associative, unital) $\k$-algebra
$\Flag^n(\k)$ generated over $\k$ by the elements of $\Lambda^\ast(\calB)$
\[v_{i_1}\wedge\cdots\wedge v_{i_r}\qquad (1\le r\le n,\ \forall j,\  1\le i_j\le n)\]
subject to the relations: $v_{i_1}\wedge\cdots\wedge v_{i_s}=0$ if two $i_k$ coincide and if $\sigma\in\frakS_n$,
\[v_{i_{\sigma 1}}\wedge\cdots\wedge v_{i_{\sigma s}}=(\operatorname{sgn}\sigma)\  v_{i_1}\wedge\cdots\wedge v_{i_s}\]
together with the relation
\[\sum_{1\le \lambda_1\le\cdots\le\lambda_r\le t+r}(-1)^{\sum \lambda_i}\bigwedge_{k\ne \lambda_i \forall i}v_{k}\times_{\Lambda^+(\calB)}(v_{\lambda_1}\wedge\cdots\wedge v_{\lambda_r}\wedge v_{j_1}\wedge\cdots\wedge v_{j_{s-r}})=0\]
for all $1\le r\le s\le t\le n$ and all choices of $i_1,\dots,i_{t+r}$ and $j_1,\dots,j_{s-r}$.

\subsubsection{The grading}
This algebra admits a $P(n)$ grading where $P(n)$ is the semigroup (here no inverses) of nonincreasing sequences of positive integers
\[(\alpha_1,\dots,\alpha_k)\]
with $n\ge \alpha_1\ge\cdots\ge \alpha_1\ge 1$ where multiplication is defined by (disjoint) union and sorting the multiset. The $P(n)$ grading determines the ``\textbf{shape}'' of a monomial in
$\Flag^n(\k)$ in the following way: we can write each monomial $\omega\in\Flag^n(\k)$ as $\omega_1\cdots\omega_r$ where $\omega_i\in\Lambda^{\alpha_i}(\calB)$
and such that $n\ge\alpha_1\ge\cdots\ge\alpha_r\ge 1$. For notation, if $\alpha=(\alpha_1,\dots,\alpha_r)$, write
\[\Flag^\alpha(\k)=\Lambda^\alpha(\calB,\k)=\Lambda^\alpha(\calB)\]
to be the $\k$-span of all products of shape $\alpha$.

This gives us a graded algebra structure (called the \textbf{shape algebra})
\[\Lambda^+(\calB)=\bigoplus_{\alpha\in P(n)}\Lambda^\alpha(\calB)\]
of $\Flag^n(\k)$.

The upshot here is that each $\Lambda^\alpha$ inherits a natural $\GL(n,\k)$ action by acting on each $v_i$ independently.

Then defining a deformation of this algebra amounts to deforming $\GL(n,\k)$.

\subsection{The affine Grassmann scheme \texorpdfstring{$\Gr^{t,n}(\calB)$}{Gr(t,n)(B)}}
We define the \textbf{affine Grassmann scheme} $\Gr^{t,n}:=\Gr^{t,n}(\calB)$ to be a closed subscheme of $\Flag^n$ such that
$\Gr^{t,n}(\k)$ is the $\k$-subalgebra of $\Flag^n(\k)$ generated by the $t$-fold wedges in $\calB$. Notice this also inherits a grading,
but this time we can view it as a $\bbZ$-grading since all monomials in $\Gr^{t,n}(\k)$ are of shape $(t,t,\dots,t)$.

\subsection{Quantized \texorpdfstring{$\GL(n)$}{GL(n)}}
Let $q$ be an indeterminate (often thought of as an element in the base ring [e.g an odd root of unity] and always as a \textit{deformation parameter})
and let $\k_q:=\k[q,q^{-1}]$, the Laurent polynomials in $q$. To proceed we need the \textit{(strict) inversion statistic} seen in the combinatorics of $\frakS_n$.
\begin{defn}
	If $\sigma\in\frakS_n$, let
	\[\inv\sigma=\#\{(i,j)|1\le i\le j\le n,\ \sigma(i)>\sigma(j)\}\]
\end{defn}

Then we can go on to define $M_q(n,\k)$ to be the $\k_q$-algebra generated by $n^2$ elements $X_i^j$ for $1\le i,j\le n$
subject to the $q$-commutativity relations
\begin{equation}
\begin{gathered}
	X_{k}^jX_i^j=qX_i^jX_{k}^j,\qquad \text{if } i<k\\
	X_i^kX_i^j=qX_i^jX_i^k,\qquad\text{if } j<k\\
	X_k^lX_i^j=X_i^jX_k^l+(q-q^{-1})X_i^lX_k^j,\qquad\text{if } i<k \text{ and } j<l\\
	X_k^lX_i^j=X_i^jX_k^l\qquad\text{otherwise.}
\end{gathered} \label{eqn:qcomm}
\end{equation}

We define the \textbf{$q$-determinant} $\det_q$ to be (thinking of $\mathbf X=(X_i^j)$ as a matrix)
\[\detq(\mathbf X)=\detq=\sum_{\sigma\in\frakS_n}(-q)^{-\inv\sigma} X_1^{\sigma 1}\cdots X_n^{\sigma n}\]
and can therefore define the $q$-analog of $\GL(n,\k)$ (written $\GL_q(n,\k)$) to be the $\k_q$-algebra generated by
the $X_i^j$ and an indeterminate $D$ satisfying the relations in (1) above as well as
\[D\cdot\detq =\detq\cdot D=1\in\k\]
as well as $DX_i^j=X_i^jD$ for all $i$ and $j$.

The coalgebra structure given by $\Delta(X_i^j)=\sum_k X_i^k\otimes X_k^j$, $\Delta(D)=D\otimes D$,
$\varepsilon(X_i^j)=\delta_i^j$ and $\varepsilon(D)=1$.

The antipode $S$ is given as
\[S(X_i^j)=(-q)^{j-i}\ |X^{1\cdots\hat i\cdots n}_{1\cdots\hat j\cdots n}|_q\ D\]
where in general $|X^{i_1\cdots i_s}_{j_1\cdots j_s}|_q$ denotes the $q$ determinant of the $s\times s$ matrix formed by the rows $j$ and the columns $i$ of $\mathbf X$ in that order.
Finally $S(D)=\detq$. This gives us a Hopf algebra structure on $\GL_q(n,\k)$ and thus realizes $\GL_q(n)$ as a quantum group.

Notice that we can give $\k$ a $\k_q$-module structure by the evaluation map $ev:\k_q\to\k$ sending $q$ to 1. Under this structure,
we get
\[\GL_q(n,\k)\otimes_{\k_q}\k\cong \k[\GL(n,\k)]\]
so indeed this quantization collapses to the regular $\k$ functions on $\GL(n)$, indicating we have found the (perhaps \textit{a}) ``correct'' object.

\subsection{The quantized Grassmannian}
Then we can define $\Gr_q^{t,n}$ to be the $\k_q$ algebra generated by the $t$-fold wedges (notice that we are losing the intuition of the wedge product now so this is just a notational designation)
in $\Lambda_q^+(\calB)$,
the quantized shape algebra where we replace the usual relations with
\[v_{i_{\sigma 1}}\wedge\cdots\wedge v_{i_{\sigma s}}=(-q)^{\inv\sigma}\  v_{i_1}\wedge\cdots\wedge v_{i_s}\]
as well as the quantum Young symmetry relation
\[\sum_{1\le \lambda_1\le\cdots\le\lambda_r\le t+r}(-q)^{-\inv(i_1,\dots,i_{\hat\lambda_i}\cdots i_{t+r},i_{\lambda_1},\dots,i_{\lambda_r})}\bigwedge_{k\ne \lambda_i \forall i}v_{k}\times_{\Lambda_q^+(\calB)}(v_{\lambda_1}\wedge\cdots\wedge v_{\lambda_r}\wedge v_{j_1}\wedge\cdots\wedge v_{j_{s-r}})=0\]
along with a (rather nasty) $q$-commutativity relation (i.e. $\Lambda_q^+$ is no longer commutative)
\begin{align*}
	&(v_{j_1}\wedge\cdots\wedge v_{j_r})\cdot (v_{i_1}\wedge\cdots\wedge v_{i_r})=\\
	&\sum_{1\le \lambda_1\le\cdots\le\lambda_r\le s}(-q)^{\inv(\lambda_1,\dots,\lambda_r,1,\dots,\hat\lambda_i,\dots,s)}(v_{j_1}\wedge\cdots\wedge v_{j_r}\wedge v_{i_1}\wedge\cdots\wedge\hat v_{i_{\lambda_i}}\wedge\cdots v_{i_s})(v_{\lambda_1}\wedge\cdots\wedge v_{\lambda_r})
\end{align*}

The punchline (after many pages of theorems and lemmas) is that $\Gr_q^{t,n}(\k)$ inherits a natural $\GL_q(n)$-module structure as well as a $\GL_q(n)$-comodule structure
from the structure map
\[\rho:\Lambda_q^t(\calB)\to \GL_q(n,\k)\otimes \Lambda_q^t(\calB)\]
where
\[\rho(v_{\lambda_1}\wedge\cdots\wedge v_{\lambda_t})=\sum_{1\le \mu_1\le\cdots\le \mu_t\le n}|X^{\mu_1,\dots,\mu_t}_{\lambda_1,\dots,\lambda_t}|_q\otimes(v_{\mu_1}\wedge\cdots\wedge v_{\mu_t})\]

Furthermore, this comodule structure is the unique comodule structure extending the natural comodule structure of $\GL_q(n)$ on itself (cf. the ``normal representation'').

Finally the good stuff: let $L_q^t(\calB)$ denote the (unital) $\k_q$ subalgebra of $M_q(n,\k)$ generated
by the quantum minors $|X^{1,\dots,t}_{\lambda_1,\dots,\lambda_t}|_q$ for $1\le \lambda_i\le n$. There is an isomorphism of $\GL_q(n,\k)$-comodule algebras
between $\Lambda^t_q(\calB)$ and $L^t_q(\calB)$ by sending every such element to $v_{\lambda_1}\wedge\cdots\wedge v_{\lambda_t}$. So this gives us an easy generating set
for the quantum Grassmannian over $\k_q$.

Of course it is also shown that the map $ev:\k_q\to \k$ sending $q$ to 1 induces an isomorphism
\[\Lambda_q^t(\calB)\otimes_{\k_q}\k\cong \Lambda^t(\calB)\cong \k[\Gr^{t,n}]\]
and since we used the same map $ev$, we get that this isomorphism is compatible with the $\GL_q(n,\k)$ action.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%  Bibliography %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\medskip

\printbibliography

\end{document}


\clearpage
\subsection{C++ Expression} % (fold)
\label{sub:program-creation-c_expression}

An \nameref{sub:expression} in C++ is a mathematical calculation or a \nameref{sub:program-creation-c_literal} value. Each expression will have a \nameref{sub:type}, and can contain a number of mathematic operators. Table \ref{tbl:program-creation-c operators and expresions} lists the operators that you can include in your expressions, listed in order of precedence.\footnote{Expressions follow the standard mathematic order of precedence (BODMAS).} The operators you can use depend on the kind of data that you are using within the expression.

\begin{table}[h]
  \begin{minipage}{\textwidth}
  \centering
  \begin{tabular}{|c|l|l|}
    \hline
    \textbf{Operator} & \textbf{Description} & \textbf{Example} \\
    \hline
    \texttt{ ( ) }     &   Parenthesis                 & \texttt{(1 + 1) * 2}  \\
    \texttt{\% * /}      &   Modulo\footnote{The remainder after division. For example 9 modulo 3 is 0, 10 modulo 3 is 1, 11 modulo 3 is 2 etc.}, Multiplication and Division & \texttt{1 / 2 * 5 \% 3}    \\
    \texttt{+ -}      &   Addition and subtraction    & \texttt{10 + 3 - 4}   \\
    \hline
  \end{tabular}
  \end{minipage}
  \caption{C++ Operators and Example Expressions}
  \label{tbl:program-creation-c operators and expresions}
\end{table}

\begin{table}[h]
  \begin{minipage}{\textwidth}
  \centering
  \begin{tabular}{|c|c|l|}
    \hline
    \textbf{Example Expression} & \textbf{Value} & \textbf{Type} \\
    \hline
    \texttt{ 73 }     &   73                 & \texttt{int}  \\
    \texttt{ 2.1 }      & 2.1   & \texttt{float}    \\
    \texttt{ "Hello World" }      &   "Hello World"    & \texttt{string}\footnote{This is technically a \texttt{char*} which denotes a reference to a \textit{string} of characters.}   \\
    \texttt{ "Fred" }      &   "Fred"    & \texttt{string}   \\
    \texttt{ 3 * 2 } & 6 & \texttt{int} \\
    \texttt{ 1 + 3 * 2 }  & 7 & \texttt{int} \\
    \texttt{ (1 + 3) * 2} & 8 & \texttt{int} \\
    \texttt{ 7 - 3 + 1 }  & 5 & \texttt{int} \\
    \texttt{ 3 / 2 } & 1\footnote{C does integer division for int values, rounding the value down.} & \texttt{int} \\
    \texttt{ 3.0 / 2.0} & 1.5 & \texttt{float} \\
    \texttt{ 3 \% 2} & 1 & \texttt{int} \\
    \texttt{ 11 \% 3} & 2 & \texttt{int} \\
    \texttt{ 3 / 2.0 } & 1.5\footnote{If either, or both, values are real (floating point) numbers the result is also a real number.} & \texttt{float} \\
    \texttt{ 1 + (3 / 2.0) + 6 * 2 - 8} & 6.5 & \texttt{float} \\
    \hline
  \end{tabular}
\end{minipage}
  \caption{Example C++ Expressions and their values}
  \label{tbl:program-creation-c example expresions}
\end{table}

\mynote{
\begin{itemize}
  \item Table \ref{tbl:program-creation-c example expresions} shows some example expressions, their values, and types.
  \item Expressions can be literal values, entered in the code.
  \item Expression can contain mathematical calculations using standard addition, subtraction, multiplication, division, and groupings.
\end{itemize}
}

% subsection c_expression (end)


\section{Information Theory}

% ======================================
% SINGLE VARIATE MEASURES
% ======================================
\subsection{Single Variable}
\newcommand{\entropy}[1]{\text{H}\left(#1\right)}
\newcommand{\info}[1]{\text{I}\left(#1\right)}
\newcommand{\totalcorr}[1]{\text{TC}\left(#1\right)}

\begin{table}[h]
    \centering
    \caption{List of symbols and their meaning for single variable measures.}
    \begin{tabular}{m{7em}m{20em}}
        \toprule
        \textbf{Symbol}             & \textbf{Name} \\
        \midrule
        $\info{\mathbf{X}}$         & Self-Information\\
        $\entropy{\mathbf{X}}$      & Entropy \\
        $\totalcorr{\mathbf{X}}$    & Total Correlation \\
        \bottomrule
    \end{tabular}
    \label{tab:info_theory}
\end{table}

% ======================================
% MULTI VARIATE MEASURES
% ======================================
\subsection{Multiple Variables}

\newcommand{\jointentropy}[2]{\text{H}\left(#1,#2\right)}
\newcommand{\mutualinfo}[2]{\text{I}\left(#1,#2\right)}
\newcommand{\kld}[2]{\text{D}_{\text{KL}}\left[#1||#2\right]}

\begin{table}[h]
    \centering
    \caption{List of symbols and their meaning for multiple variable measures.}
    \begin{tabular}{m{7em}m{20em}}
        \toprule
        \textbf{Symbol} & \textbf{Meaning} \\
        \midrule
        $\jointentropy{\mathbf{X}}{\mathbf{Y}}$ & Joint Entropy \\
        $\mutualinfo{\mathbf{X}}{\mathbf{Y}}$   & Mutual Information \\
        $\kld{\mathbf{X}}{\mathbf{Y}}$          & Kullback-Leibler Divergence \\
        \bottomrule
    \end{tabular}
    \label{tab:info_theory}
\end{table}


% --------------------------- %
% SimpleTreeTest Start
% --------------------------- %
\section{\textbf{SimpleTreeTest}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Particular Case}
\par
The problem we want to solve now is how we can implement a bounded priority
queue that can be accessed concurrently by multiple threads.
\par
Remember that priority queue is said to be \textit{bounded} when the range of
the priorities are taken from the range $0,...,m-1$.
\par
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Solution}
\par
One possible solution to this problem is given by the \textit{Tree-Based Bounded
Priority Queue} data structure. This structure is essentially a binary tree where
the leaf nodes have a bin holding items of priority $i$. Internal nodes maintain
a shared counter that indicates the number of elements stored to the left of
a given node.
\par
The interesting methods in this data structure are the \textit{add()} and
\textit{removeMin()}, so let us talk about them.
\par
The \textit{add()} method first takes the bin associated with the given
priority. It puts the item into that bin and then starts increasing the counter
of the parent nodes all the way to the root. Note that it only increases the
counter if the current node happens to be a left child of the parent.
\par
\hfill
\begin{lstlisting}[style=numbers]
  /**
   *  add item to priority queue
   * @param item new item
   * @param priority item''s priority
   */
  public void add(T item, int priority) {
    TreeNode node = leaves.get(priority);
    node.bin.put(item);
    while(node != root) {
      TreeNode parent = node.parent;
      if (node == parent.left) { // increment if ascending from left
        parent.counter.getAndIncrement();
      }
      node = parent;
    }
  }
\end{lstlisting}
\hfill
\par
The \textit{removeMin()} method has to retrieve the item with the lowest
priority. In order to do that, the method starts from the root and traverses the
tree. If the current counter of the inner node is $0$, then it knows that the
min must be on the left. Otherwise, it goes through the right child.
\par
\hfill
\begin{lstlisting}[style=numbers]
  public T removeMin() {
    TreeNode node = root;
    while(!node.isLeaf()) {
      if (node.counter.getAndDecrement() > 0 ) {
        node = node.left;
      } else {
        node = node.right;
      }
    }
    return node.bin.get(); // if null pqueue is empty
  }
\end{lstlisting}
\hfill
\par
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Experiment Description}
\par
Three test cases were provided to exercise this code:
\begin{itemize}
\item testAdd. This test adds elements with random priority to the priority
queue one by one. At the end, it extracts each element and it must be the case
that the previously removed element had a lower priority than the current
element.
\item testParallelAdd. This test spawns 8 threads. Each of the test adds 8
elements to the queue concurrently. At the end, it performs the same checking as
in the previous test case. Notice that each thread is in charge of adding
elements from a fixed range in ascending order.
\item testParallelBoth. Does the same as the previous test case but also removes
elements in parallel. Each remover thread will perform the same checking. Since
adders add elements in ascending order, it is guaranteed that any removal from
any thread will retrieve an element with a lower priority than the next one.
\end{itemize}
\par
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Sample Results}
\par
Here is the result of the execution of the test cases:
\par
\hfill
\begin{verbatim}
[oraadm@gdlaa008 ch15]$ junit priority.SimpleTreeTest
.sequential test
OK.
.testParallelBoth
OK.
.testParallelAdd
OK.

Time: 0.01

OK (3 tests)
\end{verbatim}
\hfill
\par
The tests passed every time
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --------------------------- %
% SimpleTreeTest End
% --------------------------- %


\section{Hydrodynamic Equations in Comoving Coordinates}

\subsection{Conservative Form}

We solve the equations of gas dynamics in a coordinate system that is comoving
with the expanding universe,  with expansion factor, $a,$ related to the redshift, $z$, by $a = 1 / (1 + z).$
The continuity equation is written,
\begin{equation}
\label{eq:dens}
\frac{\partial \rho_b}{\partial t} = - \frac{1}{a} \nabla \cdot (\rho_b \Ub) \enskip , \\
\end{equation}
where $\rho_b$ is the comoving baryonic density, related to the proper density by $\rho_b = a^3 \rho_{proper},$
and $\Ub$ is the proper peculiar baryonic velocity.

The momentum evolution equation can be expressed as
\begin{eqnarray}
\frac{\partial (\rho_b \Ub)}{\partial t} &=&  \frac{1}{a} \left(
- \nabla \cdot (\rho_b \Ub \Ub)
- \nabla p
+ \rho_b \gb
+ {\bf S}_{\rho \Ub}
- \dot{a} \rho_b \Ub \right) \enskip ,
\end{eqnarray}
or equivalently,
\begin{eqnarray}
\label{eq:momt}
\frac{\partial (a \rho_b \Ub)}{\partial t} &=&
-             \nabla \cdot (\rho_b \Ub \Ub)
-             \nabla p
+             \rho_b \gb
+             {\bf S}_{\rho \Ub} \enskip ,
\end{eqnarray}
where the pressure, $p$, that appears in the
evolution equations is related to the proper pressure, $p_{proper},$ by  $p = a^3 p_{proper}.$
Here $\gb = - \nabla \phi$ is the gravitational acceleration vector, and
${\bf S}_{\rho \Ub}$ represents any external forcing terms.

The energy equation can be written,
\begin{eqnarray}
\frac{\partial (\rho_b E)}{\partial t} &=& \frac{1}{a} \left[
- \nabla \cdot (\rho_b \Ub E + p \Ub)
+ ( \rho_b \Ub \cdot \gb +  S_{\rho E} )
- \dot{a} ( 3 (\gamma - 1) \rho_b e + \rho_b ( \Ub \cdot \Ub) ) \right] \enskip .
\end{eqnarray}
or equivalently,
\begin{eqnarray}
\label{eq:energy}
\frac{\partial (a^2 \rho_b E)}{\partial t} &=& a \left[
- \nabla \cdot (\rho_b \Ub E + p \Ub)
+  \rho_b \Ub \cdot \gb
+  S_{\rho E}
+  \dot{a} ( \; ( 2 - 3 (\gamma - 1) ) \; \rho_b e ) \right] \enskip .
\end{eqnarray}
Here $E = e + \Ub \cdot \Ub / 2$ is the total energy per unit mass,
where $e$ is the specific internal energy.
$S_{\rho E} = S_{\rho e} + \Ub \cdot {\bf S}_{\rho \Ub}$
where $S_{\rho e} = \Lambda^H - \Lambda^C$ represents the heating and cooling terms, respectively.
We can write the evolution equation for internal energy as
\begin{eqnarray}
\frac{\partial (\rho_b e)}{\partial t} &=& \frac{1}{a} \left[
- \nabla \cdot (\rho_b \Ub e)
- p \nabla \cdot \Ub
- \dot{a} ( 3 (\gamma - 1) \rho_b e )
+ S_{\rho e}  \right] \enskip .
\end{eqnarray}
or equivalently,
\begin{eqnarray}
\frac{\partial (a^2 \rho_b e)}{\partial t} &=&  a \left[
- \nabla \cdot (\rho_b \Ub e)
- p \nabla \cdot \Ub
+ S_{\rho e}
+ \dot{a} ( \; ( 2 - 3 (\gamma - 1) ) \; \rho_b e ) \right] \enskip .
\end{eqnarray}

Note that for a gamma-law gas with $\gamma = 5/3,$ we can write
\begin{eqnarray}
\frac{\partial (a^2 \rho_b E)}{\partial t} &=&  a \left[
 -\nabla \cdot (\rho_b \Ub E + p \Ub)
+  \rho_b \Ub \cdot \gb
+  S_{\rho e}  \right]  \enskip .
\end{eqnarray}
and
\begin{eqnarray}
\frac{\partial (a^2 \rho_b e)}{\partial t} &=& a \left[
- \nabla \cdot (\rho_b \Ub e)
-  p \nabla \cdot \Ub
+  S_{\rho e}  \right]  \enskip .
\end{eqnarray}

\subsection{Tracing}

In order to compute the fluxes on faces, we trace $\rho, \Ub, \rho e$ and $p$ to the faces.

\noindent Thus we must convert the momentum evolution equation into a velocity evolution equation:
\begin{eqnarray}
\frac{\partial\Ub}{\partial t} &=&  \frac{1}{\rho_b} \left(
\frac{\partial (\rho_b \Ub)}{\partial t}  - \Ub \frac{\partial \rho_b}{\partial t}  \right) \\
&=&  \frac{1}{a \rho_b} \left(
- \nabla \cdot (\rho_b \Ub \Ub)
- \nabla p
+ \rho_b \gb
+ S_{\rho \Ub}
- \dot{a} \rho_b \Ub \right)
+ \frac{1}{a}  \Ub \; \nabla \cdot (\rho_b \Ub) \\
&=&  \frac{1}{a} \left(
- \Ub \cdot \nabla \Ub
- \frac{1}{\rho_b} \nabla p
+ \gb
+ \frac{1}{\rho_b} {\bf S}_{\rho \Ub}
- \dot{a} \Ub \right) \enskip .
\end{eqnarray}

\section{Subgrid Scale Model in Comoving Coordinates}

The fundamental modification to the standard compressible equations is the addition
of a SGS turbulence energy variable, $K$ and associated source terms in the equations
for the evolution of velocity, total energy, and $K$ \cite{schumann:1975,sagaut,schmidt:2006}.
The set of conservation equations in comoving coordinates~(\ref{eq:dens})--(\ref{eq:energy}) then becomes
\cite{maier:2009}:
\begin{align}
\frac{\partial \rho_b}{\partial t} =& - \frac{1}{a} \nabla \cdot (\rho_b \Ub) \enskip , \\
\label{eq:momt_les}
\frac{\partial (a \rho_b \Ub)}{\partial t} =&
-             \nabla \cdot (\rho_b \Ub \Ub)
-             \nabla p
+             \nabla \cdot \boldsymbol{\tau}
+             \rho_b \gb  \enskip , \\
\label{eq:energy_les}
\frac{\partial (a^2 \rho_b E)}{\partial t} =& - a \nabla \cdot (\rho_b \Ub E + p \Ub)
+  a \rho_b \Ub \cdot \gb
+ a \nabla \cdot (\Ub\cdot\boldsymbol{\tau}) - a^2(\Sigma - \rho_b \varepsilon) \enskip \\
\nonumber
&+ a \dot{a} \left( ( 2 - 3 (\gamma - 1) ) \rho_b e \right)
+ a^2 ( \Lambda^H  - \Lambda^C )  \enskip , \\
\label{eq:k_les}
\frac{\partial (a^2\rho_b K)}{\partial t} =&
- a\nabla \cdot \left(\rho_b \Ub K\right)
+ a\nabla \cdot \left(\rho_b \kappa_{\rm sgs}\nabla K\right)
+ a^2(\Sigma - \rho_b \varepsilon)\enskip .
\end{align}
The interaction between resolved and unresolved turbulent eddies is described by
the SGS turbulence stress tensor $\boldsymbol{\tau}$. Since inertial-range dynamics of
turbulence is scale-invariant, we conjecture that $\boldsymbol{\tau}$ in comoving coordinates
has the same form as for non-expanding fluids. For compressible turbulence,
the following closure is proposed in \cite{schmidt:2011}:
\begin{equation}
 \label{eq:tau_nonlin}
  \tau_{ij}= 2C_{1}\Delta\rho_b(2 K_{\mathrm{sgs}})^{1/2}S_{\! ij}^{\ast}
  -4C_{2}\rho_bK\frac{U_{i,k}U_{j,k}}{|\nabla\Ub|^{2}}
  -\frac{2}{3}(1-C_{2})\rho_bK\delta_{ij}.
\end{equation}
where $|\nabla\Ub|:=(2U_{i,k}U_{i,k})^{1/2}$ is the norm of the resolved velocity derivative,
\begin{equation}
S_{ij}^{\ast} = S_{ij} - \frac{1}{3}\delta_{ij}d =
\frac{1}{2} (U_{i,j} + U_{j,i}) - \frac{1}{3}\delta_{ij}U_{k,k}
\end{equation}
is the trace-free rate-of strain, and $\Delta=(\vartriangle\!x\,\vartriangle\!y\,\vartriangle\!z)^{1/3}$
is the grid scale in comoving coordinates. The production and dissipation terms in equation~(\ref{eq:k_les})
are defined as follows:
\begin{eqnarray}
\Sigma             &=& \frac{1}{a}\tau_{ij} S_{ij}, \\
\varepsilon &=& \frac{C_\varepsilon K^{3/2}}{a\Delta},
\end{eqnarray}
and $\kappa_{\rm sgs} = C_{\kappa}\Delta K^{1/2}$ is the SGS diffusivity.
Here we assume that the Reynolds number of turbulence is high such that the damping of turbulent eddies by the microscopic
viscosity of the fluid occurs entirely on the subgrid scales. Because of the numerical viscosity of PPM,
however, part of the numerically resolved kinetic energy will be dissipated directly into internal energy.


\graphicspath{{Pics/}}

\newpage\subsection{Projective Constructions}

\begin{minipage}{.6\linewidth}
    \begin{construction}[Second Intersection of Line with Conic]
        Given four points $ A, B, C, D $, no three collinear, and a point $ P
        $ on a line $ l $ passing through at most one of the four points,
        construct the point $ P'\in l $ such that $ A, B, C, D, P, P' $ line
        on the same conic.

        \solu{
            Let $ AP\cap BC = X,\ l\cap CD = Y,\ XY\cap AD=Z $. Then by
            Pascal's Hexagrummum Mysticum Theorem, we have, $\ \  P' = BZ\cap
            l $
        }
    \end{construction}
\end{minipage}\hfill%
\begin{minipage}{.35\linewidth}
    \figdf{}{constructing_second_intersection_with_conic}{}
\end{minipage}

\begin{minipage}{.6\linewidth}
    \begin{construction}[Conic touching conic]
        Given a conic $ \mathcal{C} $, and two points $ A, B $ on it, and $ C
        $ inside of it. Construct the conic $ \mathcal{H} $ that is tangent to
        $ \mathcal{C} $ at $ A, B $ and passes through $ C $.
    \end{construction}
    \solu{
        Draw the two tangest at $ A,B $ which meet at $ X $. Take an arbitrary
        line passing through $ X $ that intersects $ AC, BC $ at $ Y, Z $.
        Take $ D=BY\cap AZ $. Then $ D $ lies on $ \mathcal{H} $ by Pascal.
        Construct another point $ E $ similarly and draw the conic.
    }
\end{minipage}\hfill%
\begin{minipage}{.35\linewidth}
    \figdf{.9}{conic_touching_conic}{}
\end{minipage}

\begin{construction}[Inconic of a quadrilateral]
    Given a convex quadrilateral $ ABCD $. $ P=AC\cap BD $, $ S\in AD, T\in BC
    $ such that $ S, P, T $ are collinear. Construct the conic that touches $
    AB, CD $, and also touches $ AD, BC $ at $ S, T $ respectively.
\end{construction}

\solu{[the\textunderscore Construction]
    Draw the polar line $ l $ of $ P $ wrt to the quadrilateral. Let $
    Z=BC\cap l $. Let $ ZS\cap AB = U $, $ ZT\cap CD = V $. Then $ SSUUTTVV $
    is our desired conic.
}

\begin{minipage}{.5\linewidth}
    \proof{
        If $ U, V\in CD, AB $ such that $ UV $ passes through $ P $, and if
        the conic passing through $ U, V $ and tangent to $ AD, BC $ at $ S, T
        $ intersects $ CD $ at $ U' $ again, then $ SV, U'T, DB $ are
        concurrent. So to show our construction works, we just need to prove
        that $ U, V, P $ are collinear.\\

        Since Pascal's theorem works on $ SVBTUD $, we know $ S, V, B, T, U, D $
        lie on a conic $ \mathcal{H} $ and $ l $ is the pole of $ P $ wrt $
        \mathcal{H} $. Now, applying Pascal's theorem on $ TDVUBS $, and quadrilateral
        theorem on $ BTUD $ and $ BVSD $, we have, $ ST\cap UV\in AC $, which is $ P
        $. So we are done.
    }
\end{minipage}\hfill%
\begin{minipage}{.45\linewidth}
    \figdf{}{conic_touching_quad}{}
\end{minipage}

\begin{minipage}{.5\linewidth}
    \begin{construction}[\href{http://www.geometry.ru/persons/beluhov/selected.pdf}{Sharygin
        Olympiad 2010}]
        A conic $ \mathcal{C} $ passing through the vertices of $ \triangle
        ABC $ is drawn, and three points $ A', B', C' $ on its sides $ BC, CA,
        AB $ are chosen. Then the original triangle is erased. Prove that the
        original triangle can be constructed iff $ AA', BB', CC' $ are
        concurrent.
    \end{construction}

    \solu{[the\textunderscore Construction]
        Draw $ B'C' $. It intersects the circle at $ X_1, X_2 $. Draw the
        conic $ \mathcal{H} $ that is tangent to $ \mathcal{C} $ at $ X_1, X_2
        $ and passes through $ A' $. Then $ BC $ is tangent to $ \mathcal{H} $
        at $ A' $.
    }

\end{minipage}\hfill%
\begin{minipage}{.45\linewidth}
    \figdf{1}{reconstruct_ABC}{}
\end{minipage}

\proof{
    The only if part is easy to prove. Becase if $ AA', BB', CC' $ aren't
    concurrent, then we can get multiple triangles $ ABC $. So suppose that
    they are concurrent. \\

    Now we define some intersetion points.
    \begin{center}
        \begin{tabular}{ccccc}
            $W_1$	&= &$BB'$	&$\cap$ &$\mathcal{C}$\\
            $S$	&=	&$X_1X_1$	&$\cap$ &$AW_1$\\
            $T$	&=	&$X_1B$	&$\cap$ &$AX_2$\\
            $U$	&=	&$X_1X_1$	&$\cap$ &$BC$\\
            $V$	&=	&$X_2X_2$	&$\cap$ &$BC$\\
            $R$	&=	&$X_2X_2$	&$\cap$ &$AW_1$\\
            $Y_1$	&=	&$A'B'$	&$\cap$ &$SR$
        \end{tabular}
    \end{center}

    $T, S, B'$ are collinear by Pascal's theorem on $ BX_1X_1X_2AW_1 $. $ T,
    B', V $ are similarly collinear for $ AX_2X_2X_1BC $. And similarly $ R,
    B', U $ are collinear.\\

    We will prove that $ \mathcal{H} $ is an inconic of $ SRVU $ that goes
    through $ A', X_1, X_2 $. \\

    For a point $ X $ on $ UV $, define $ f:UV\to UV $ such that $ f(X) $ is
    the second intersection of the conic $ X_1X_1X_2X_2X $ ($ X_1X_1 = SU,
    X_2X_2=RV  $) with $ UV $.
    $ f $ is an involution by \autoref{theorem:Three Conic Law}. \\

    Suppose $A_1$ is the intersection with the inconic of $ SRUV $ through $
    X_1, X_2 $ and $ UV $. Let $ A_2 = X_1X_2\cap UV $. Then $ f(A_1) =A_1,
    f(A_2)=A_2, f(B)=C $. \\

    Which means, $A(B, C; A_1, A_2) = -1$. Which means $ A_1=A' $. So, $
    X_1X_2A'X_2X_2 $ is an inconic of $ SRVU $, just as we wanted.

    \figdf{.8}{reconstruct_ABC_1}{}
}

\newpage
\begin{construction}[Focus and Directrix of a Parabola]
    First draw two parallel segments on the parabola, join their midpoints to
    get the line parallel to the axis. Then draw the main axis and find out
    the tip of the parabola. Then draw $f(x) = \frac{x}{2}$ line through $P$.
    And find the foot of the intersection of it with the parabola. It is the
    focus.
    \figdf{.5}{parabola_foci_construction}{}
\end{construction}


\section{Sparse Coding}

\subsection*{Orthogonal Basis}
For $\mathbf{x}$ and o.n.b. $\mathbf{U}$ compute $\mathbf{z} = \mathbf{U}^\top \mathbf{x} $. Approx $ \mathbf{\hat{x}} = \mathbf{U\hat{z}}$, $\hat{z}_i = z_i$ if $ \lvert z_i \rvert > \epsilon$ else 0.
Reconstruction Error $\|\mathbf{x}-\mathbf{\hat{x}}\|^2 = \sum_{d\notin\sigma}\langle\mathbf{x},\mathbf{u}_d\rangle ^2$.
Choice of base depends on signal. Fourier for global, wavelet for local support. PCA basis optimal for given $\Sigma$. (Haar Wavelet) include the scaling function in the family.
Change of base complexity = $O(D^2)$ but fast transforms = $O(DlogD)$
\subsection*{Overcomplete Basis}
$\mathbf{U} \in \mathbb{R}^{D \times  L}$ for \# atoms $ = L > D = \mathsf{dim}\text{(data)}$. Decoding involved $\rightarrow$ add constraint $\mathbf{z}^\star \in \argmin_\mathbf{z} \lVert \mathbf{z} \rVert_0$ s.t. $\mathbf{x} = \mathbf{Uz}$. NP-hard $\rightarrow$ approximate with 1-norm (convex) or with MP.

\textbf{Coherence}
\begin{inparaitem}[\color{red}\textbullet]
	\item $m(\mathbf{U}) = \max_{i,j:\, i \neq j} | \mathbf{u}_i^\top \mathbf{u}_j |$
	\item $m(\mathbf{B}) = 0$ if $\mathbf{B}$ orthogonal matrix
	\item $m([\mathbf{B}, \mathbf{u}]) \geq \frac{1}{\sqrt{D}}$ if atom $\mathbf{u}$ is added to orthogonal basis $\mathbf{B}$ (o.n.b. = orthonormal base)
\end{inparaitem}
\textbf{Matching Pursuit (MP)}
approximation of $\mathbf{x}$ onto $\mathbf{U}$, using $K$ entries.
Objective: $\mathbf{z}^\star \in \argmin_{\mathbf{z}} \|\mathbf{x} - \mathbf{Uz} \|_2$, s.t. $\|\mathbf{z}\|_0 \leq K$
\begin{inparaenum}[\color{red}1.]
	\item init: $z \leftarrow 0, r \leftarrow x$
	\item while $\|\mathbf{z}\|_0 < K$ do
	\item select atom with smallest angle $i^\star = \argmax_i |\langle \mathbf{u}_i, \mathbf{r} \rangle|$
	\item update coefficients: $z_{i^\star} \leftarrow z_{i^\star} + \langle \mathbf{u}_{i^\star}, \mathbf{r} \rangle$
	\item update residual: $\mathbf{r} \leftarrow \mathbf{r} - \langle \mathbf{u}_{i^\star}, \mathbf{r} \rangle \mathbf{u}_{i^\star}$.
\end{inparaenum}
\\\textbf{Exact recovery} when: $K<1/2( 1+1/m(\mathbf{U}))$

\textbf{Compressive Sensing}: Compress data while gathering:
\begin{inparaitem}[\color{red}\textbullet]
  \item $\mathbf{x} \in \mathbb{R}^D$, $K$-sparse in o.n.b. $\mathbf{U}$. $\mathbf{y} \in \mathbb{R}^M$ with $y_i = \langle \mathbf{w}_i, \mathbf{x}\rangle $: $M$ lin. combinations of signal; $\mathbf{y} = \mathbf{Wx} = \mathbf{WUz} = \mathbf{\theta z}$, $\theta \in \mathbb{R}^{M \times D}$
  \item Reconstruct $\mathbf{x} \in \mathbb{R}^D$ from $\mathbf{y}$; find $\mathbf{z}^\star \in \argmin_{\mathbf{z}}\|\mathbf{z}\|_0$, s.t. $\mathbf{y} = \mathbf{\theta z}$ (e.g. with MP). Given $\mathbf{z}$, reconstruct $\mathbf{x}$ via $\mathbf{x} = \mathbf{Uz}$
\end{inparaitem}
\\Sufficient conditions:
\begin{inparaitem}[\color{red}\textbullet]
  \item $\mathbf{W} = $ Gaussian random projection, i.e. $w_{ij}\sim\mathcal{N}(0, \frac{1}{D})$
  \item M $\geq cK log(\frac{D}{K})$, where $c$ is some constant
\end{inparaitem}

\subsection*{Dictionary Learning}
Adapt the dictionary to signal characteristics. Objective: $(\mathbf{U}^\star, \mathbf{Z}^\star) \in \argmin_\mathbf{U,Z} \| \mathbf{X} - \mathbf{U} \cdot \mathbf{Z} \|_F^2$ not jointly convex but convex in 1 argument.

\textbf{Matrix Factorization by Iter Greedy Minimization}
\begin{inparaenum}[\color{red} 1.]
  \item Coding step: $\mathbf{Z}^{t+1} \in \argmin_\mathbf{Z} \| \mathbf{X} - \mathbf{U}^t \mathbf{Z} \|_F^2$ subject to $\mathbf{Z}$ being sparse ($\mathbf{z}_n^{t+1}\in \argmin_\mathbf{z}\|\mathbf{z}\|_0$ s.t.$\|\mathbf{x}_n - \mathbf{U}^t\mathbf{z}\|_2 \le \sigma \|\mathbf{x}_n\|_2$)
  \item Dict update step: $\mathbf{U}^{t+1} \in \argmin_\mathbf{U} \| \mathbf{X} - \mathbf{UZ}^{t+1} \|_F^2$, subj to $\forall l\in [L]:\|\mathbf{u}_l\|_2 = 1$. (set $\mathbf{U} = [\mathbf{u}_1^t\cdots \mathbf{u}_l\cdots \mathbf{u}_L^t],~ \min_{u_l}\|\mathbf{X} - \mathbf{U}\mathbf{Z}^{t+1}\|_F^2 = \min_{u_l}\|\mathbf{R}_l^t - \mathbf{u}_l(\mathbf{z}_l^{t+1})^\top\|_F^2$ with $\mathbf{R}_l^t = \tilde{\mathbf{U}}\Sigma\tilde{\mathbf{V}}^\top$ by $\mathbf{u}^*_l=\tilde{\mathbf{u}}_1$)
\end{inparaenum}


\subsection{Independent Contour Method}
\begin{frame}{Definition}
	\begin{block}{Formula}
		For a closed mechanism, the number of independent contours $N$ is calculated as follows:
		\[N=c-n\]
		where\\
		$c$ is the number of joints\\
		$n$ is the number of links, excluding ground
	\end{block}
	The number of independent contours depends on the number of joint connections to ground. Its graphical representation can be referred to as \textit{connectivity table}, \textit{structural diagram} or \textit{\textbf{contour diagram}}.
\end{frame}
\begin{frame}{Velocity Analysis}
	\begin{block}{Formulas}
		For a closed kinematic chain:
		\begin{itemize}
			\item $\displaystyle\sum_{i}\vb{\omega}{i-1,i}=\vb{0}{}$
			\item $\displaystyle\sum_{i}\vb{r}{A_i}\times\vb{\omega}{i-1,i} + \sum_{i}\vb{v}{A_{i-1,i}}=\vb{0}{}$
		\end{itemize}
		where:\\
		$\vb{\omega}{i-1,i}$ is the angular velocity of link $i$ relative to link $i-1$\\
		$\vb{r}{A_i}$ is the position vector of joint $A_i$\\
		$\vb{v}{A_{i-1,i}}$ is the velocity vector of joint $A_i$ on link $i$ relative to joint $A_i$ on link $A_{i-1}$\\
	\end{block}
\end{frame}
\begin{frame}{Acceleration Analysis}
\begin{block}{Formulas}
	For a closed kinematic chain:
	\begin{itemize}
		\item $\displaystyle\sum_{i}\vb{\alpha}{i-1,i}+\sum_{i}\vb{\omega}{i}\times\vb{\omega}{i-1,i}=\vb{0}{}$
		\item $\displaystyle\sum_{i}\vb{r}{A_i}\times(\vb{\alpha}{i-1,i}+\vb{\omega}{i}\times\vb{\omega}{i-1,i}) +  \sum_{i}\vb{a}{A_{i-1,i}} + 2 \sum_i\vb{\omega}{i-1}\times \vb{v}{A_{i-1,i}}+ \sum_{i}\vb{\omega}{i}\times(\vb{\omega}{i}\times \vb{r}{A_{i+1}A_i})=\vb{0}{}$
	\end{itemize}
	where:\\
	$\vb{\omega}{i}$, $\vb{\omega}{i-1}$ are the angular velocities of link $i$ and $i-1$ relative to ground\\
	$\vb{\alpha}{i-1,i}$ is the angular acceleration of joint $A_i$ relative to joint $A_{i-1}$\\
	$\vb{a}{A_{i-1,i}}$ is the acceleration vector of joint $A_i$ on link $i$ relative to joint $A_i$ on link $A_{i-1}$\\
\end{block}
\end{frame}
\begin{frame}
	In planar motions, the above equations for acceleration analysis can be reduced to:
	\begin{itemize}
		\item$\displaystyle\sum_{i}\vb{\alpha}{i-1,i}=\vb{0}{}$
		\item $\displaystyle\sum_{i}\vb{r}{A_i}\times\vb{\alpha}{i-1,i} +  \sum_{i}\vb{a}{A_{i-1,i}} + 2 \sum_i\vb{\omega}{i-1}\times \vb{v}{A_{i-1,i}}- \sum_{i}\vb{\omega}{i}^2\vb{r}{A_{i+1}A_i})=\vb{0}{}$
	\end{itemize}\vskip3mm
	In general, the steps of this method are:
	\begin{enumerate}
		\item Perform position analysis.
		\item Draw the contour diagram of the mechanism.
		\item Use the formulas above to obtain the results.
		\item Calculate $\vb{\omega}{i}$ and $\vb{a}{i}$ with respect to ground.
		\item Compute relevant velocities and accelerations.
	\end{enumerate}
\end{frame}