\documentclass[11pt]{article}

\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{algorithmic}
\usepackage{algorithm}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
    \framebox{
      \vbox{
        \hbox to 5.78in { {\bf Algebra and Computation } \hfill Course Instructor: #2 }
        \vspace{4mm}
        \hbox to 5.78in { {\Large \hfill #5  \hfill} }
        \vspace{2mm}
        \hbox to 5.78in { {\em #3 \hfill #4} }
      }
    }
  \end{center}
  \vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{Lecturer: #3}{Scribe: #4}{Lecture #1}}

\newtheorem{theorem}{Theorem}
\newtheorem{theorem*}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{subclaim}[theorem]{Subclaim}

% my custom commands
\newcommand{\inparen}[1]{\left(#1\right)}             %\inparen{x+y}  is (x+y)
\newcommand{\inbrace}[1]{\left\{#1\right\}}           %\inbrace{x+y}  is {x+y}
\newcommand{\insquar}[1]{\left[#1\right]}             %\insquar{x+y}  is [x+y]
\newcommand{\inangle}[1]{\left\langle#1\right\rangle} %\inangle{A}    is <A>
\newcommand{\abs}[1]{\left|#1\right|}                 %\abs{x}        is |x|
\newcommand{\norm}[1]{\left\Vert#1\right\Vert}        %\norm{x}       is ||x||
\newcommand{\union}{\cup}
\newcommand{\Union}{\bigcup}
\newcommand{\intersection}{\cap}
\newcommand{\super}[2]{#1^{\inparen{#2}}}             %\super{G}{i-1} is G^{(i-1)}
\newcommand{\setdef}[2]{\inbrace{{#1}\ : \ {#2}}}
\newcommand{\inv}[1]{#1^{-1}}

% Commands specific to this file
% TODO: Find the right way to typeset group index
\DeclareMathOperator{\Sym}{Sym}
\newcommand{\gpidx}[2]{\insquar{#1 : #2}}             %\gpidx{H}{K}   is [H : K]
\newcommand{\gpigs}[2]{\gpidx{\super{G}{#1}}{\super{G}{#2}}} %Group index of g super ...
\newcommand{\llhd}{\!\!\lhd\!\!\lhd}

% \newcommand{\ceil}[1]{\lceil #1 \rceil}
\newcommand{\floor}[1]{\lfloor #1 \rfloor}
% \newcommand{\f}{\mathbb{F}}
% \newcommand{\R}{\mathbb{R}}

%for algorithms
\renewcommand{\algorithmicrequire}{\textbf{Input:}}


\begin{document}

\lecture{4: Membership Testing in Permutation Groups}{V. Arvind}{V.
  Arvind}{Shreevatsa R and Ramprasad Saptharishi}

\section{Overview}
In the previous lecture, we began studying the problem of testing
membership in permutation groups. In this lecture, we describe its
solution and explore related problems.

\section{The problem}
Given a subgroup $G$ (given by a small generating set, say
$G=\inangle{A}$) of the permutation group $S_n$, and a permutation $g
\in S_n$, the \textbf{membership testing} problem is to decide whether
$g \in G$. If the answer is yes, we might also want a representation
of $g$ in terms of the generators.\medskip

If the output has to be a product $g = a_{i_1}a_{i_2} \dots a_{i_N}$,
how large might $N$ have to be, in the worst case? It is easy to see
that we can ensure $N$ is at most by $\abs{G}-1$: consider the prefix
products $s_1 = a_{i_1}, s_2 = a_{i_1}a_{i_2}, \dots,
s_N=a_{i_1}a_{i_2} \dots a_{i_N}$.  If $N > \abs{G}-1$, either some
$s_j$ is the identity, in which case we can write $g = a_{i_{j+1}}
\dots a_{i_N}$, or $s_j = s_k$ for some $j$ and $k$, in which case we
can write $g = a_{i_1} \dots a_{i_j}a_{i_{k+1}} \dots a_{i_N}$, so in
either case $N$ can be made smaller.

However, $N$ might have to be very large. As an example, write $n$ as
$n = p_1 + p_2 + \dots + p_m$ where the $p_i$s are distinct primes,
and look at the cyclic group generated by
% TODO: figure out how to do permutations
\[ a = (1\ 2\ \dots\ p_1) (p_1+1\ \dots\ p_1+p_2)
(\dots)\quad\dots\quad(\dots) = C_1 C_2 \dots C_m .\] The $C_i$s are
disjoint cycles with lengths $p_i$, so the order of $a$ is $M = p_1p_2
\dots p_m$. The group is $G = \inangle{\inbrace{a}} = {1, a, a^2,
  \dots, a^{M-1}}$, in which the element $a^{M-1}$ can be written only
as the product of $M-1$ $a$s. So here, $N = p_1p_2 \dots p_m - 1 \geq
2^m-1$, and we know by the prime number theorem that $m =
\Omega(\frac{p_m}{\ln p_m})$. Further, as $n = p_1 + p_2 + \dots + p_m
\leq 1 + 2 + 3 + \dots + p_m \leq {p_m}^2$, we have that $p_m \geq
\sqrt{n}$, so $N \geq 2^{\frac{c\sqrt{n}}{\log n}} - 1$ for some $c$.
This is not polynomial in $n$.

Thus, we cannot hope to solve the problem in polynomial time if the
required output is an explicit product; the ``representation'' has to
be a circuit on $A$. In the example above, $a^{M-1}$ can easily be
expressed (or computed) in terms of the $a$ through repeated squaring.
Our algorithm will give a similar good representation.

\section{Idea}
Membership testing reduces to the problem of \textbf{order
  computation}, as $g \in G \iff \abs{G} = \abs{G \union g}$. The idea
for solving the latter, as we saw in the previous lecture, is to find
a tower of subgroups \[ G = \super{G}{0} \geq \super{G}{1} \geq \dots
\geq \super{G}{n-1} = \inbrace{1} \] such that the index
$\gpigs{i-1}{i}$ is easy to calculate, for each $i$. Then, as $\abs{G}
= \prod_{i=1}^{n-1}{\gpigs{i-1}{i}}$, we can easily compute
it.\bigskip

\noindent
Consider the pointwise stabilisers, and look at the tower of subgroups
\[ \super{G}{i} = \setdef{g \in G}{j^g=j\text{ for all }j,\ 1 \leq j
  \leq i} \] Here, $\gpigs{i-1}{i} \leq n-i$ for every $i$(why? since
fixing $i-1$ leaves $n-i$ choices for the $i$th index), and our
algorithm will compute it by computing a system of coset
representatives for this. The algorithm will also give us a \emph{new}
generating set for $G$; thus it can be used to decide many membership
queries without recomputing it.


\section{Algorithm}
\subsection{Finding the cosets at each level of the tower}
How do we find the coset representatives of $\super{G}{1}$ in $G$? Let
$X_1$ be the orbit of $1$
% Used X to avoid confusion with the symmetric groups (and to be easy to replace if this is bad!)
under the action of $G$, and for any $k \in X_1$, let $g_{1k}$ be the
element that maps $1$ to it (i.e., $1^{g_{1k}}=k$). Then \[ G =
\Union_{k \in X_1}{\super{G}{1}g_{1k}} \] We shall see shortly (in
\autoref{sec:schreier}) how to find a small generating set for
$\super{G}{1}$. Assuming that we can do it, we can similarly find
$X_2$, the orbit of $2$ under the action of $\super{G}{1}$, find the
$g_{2k}$s such that $k = 2^{g_{2k}}$, and similarly find
representatives for the cosets of $\super{G}{2}$ in $\super{G}{1}$.

In general, for each $i$ from $1$ to $n$, we find the orbit $X_i$ of
$i$ under the action of $\super{G}{i-1}$, and also, for each element
$k \in X_i$, the element $g_{ik}$ such that $i^{g_{ik}}=k$. Then
$\super{G}{i-1} = \Union_{k \in X}{\super{G}{i}g_{ik}}$

Taking the union of the sets of coset representatives we get for each
$\gpigs{i-1}{i}$ gives us a generating set for $G$. What we have just
found has a name:

\begin{definition}
  Let $\Omega$ be an ordered set $\{\omega_1,\omega_2,\dots,\omega_n\}$ and let $G \leq
  \Sym(\Omega)$. A \textbf{strong generating set} with respect to this ordering is the union of the
  sets of right-coset representatives (or the right-transversals) for $\super{G}{i}$ in
  $\super{G}{i-1}$, for $0 \le i \le n-1$.
\end{definition}

\subsection{Testing membership of a given $g$}
Given a $g \in G$, let $k_1 = 1^g$. If $k \notin X_1$, we can
immediately conclude that $g \notin G$. Else, let $\super{g}{1} =
g\inv{g_{1k}}$. By construction, $\super{g}{1} \in \super{G}{1}$.
Next, letting $k_2 = 2^{\super{g}{1}}$, if $k_2 \notin X_2$, we can
abort and report that $g \notin G$; else we let $\super{g}{2} =
g\inv{g_{1k_1}}\inv{g_{2k_2}}$ and continue similarly. In other words,
for each $i$ from $1$ to $n$, we let $k_i = i^{\super{g}{i-1}}$, abort
if $k_i \notin X_i$, and set
$\super{g}{i}=\super{g}{i-1}\inv{g_{ik_i}}$ otherwise, in which case
it is guaranteed to be in $\super{G}{i}$. If at any time $\super{g}{r}
= g\inv{g_{1k_1}}\inv{g_{2k_2}}\dots\inv{g_{rk_r}} = 1$ then we have
$g$ as a product of elements of $G$. If $g \in G$, it is guaranteed
that this will eventually happen, for if we have not aborted by the
time $i$ takes the value of $n$, then it is guaranteed that
$\super{g}{n-1} \in \super{G}{n-1} = {1}$.


\subsection{Finding generating sets for the subgroups}
\label{sec:schreier}
Our algorithm above for finding the strong generating set depends on
being able to find a generating set for $\super{G}{i}$ when we know
one for $\super{G}{i-1}$. This is made possible by Schreier's lemma,
as we saw in the previous lecture.

\begin{theorem*}[Schreier's lemma]
  If $G = \inangle{A}$ and $R$ is a set of distinct right coset
  representatives for the subgroup $H$ in $G$, then
  \[ B = \setdef{r_1a\inv{r_2}}{a \in A, r_1,r_2 \in R} \intersection H \] generates $H$.
\end{theorem*}

For every $r_1$ and $a$, there is a unique $r_2$ such that $r_1a\inv{r_2} = h$, for any $h$ in $H$,
so we know that $\abs{B} \le \abs{R}\abs{A}$. However, this alone is not sufficient for us to
complete our algorithm, as it does not ensure polynomial time --- the size of the generating set
might increase by $\Theta(n)$ each time. To avoid this, we need to make sure we can keep the
generating set small. We now show that it can be done.

\subsection{The {\sc reduce} Algorithm}

\begin{theorem*}
  Given a group $G \leq S_n$, we can find a generating set for it of size at most $n^2$.
\end{theorem*}

%RP scribing from here
The idea is to remove collisions as you see them. Suppose $\pi$ and
$\psi$ are two elements of your generating set such that they map $1$
to the same element, (i.e) $1\pi = 1\psi$. What we do then is replace
$\inbrace{\pi,\psi}$ by $\inbrace{\pi, \psi\inv{\pi}}$. This then
ensures that one of the elements fix $1$, and is taken care in the
following levels. A better way to look at it would be to think of a
table where row $i$ represents $\super{G}{i}$. 

Start with the bottom row, representing $\super{G}{0}=G$. For each
element $\pi \in B$, if $1\pi = 1$, move it to the row $\super{G}{1}$,
else place it in column $1^\pi$. Whenever you have collisions, do the
pruning process and send the element that fixes $1$ and send it to the
next row. Once row $1$ is done (no more collisions), move to the next
and repeat this process.

\medskip

The complete algorithms for {\sc reduce} and {\sc membership} can
be found at the end of this file.

\section{Other Problems}

Using the technique of using group towers, there is a whole pool of
problems we could inspect. We shall see a few of them now, which will
be very useful for the lectures to follow. \bigskip

\noindent
{\sc subgroup:} Given $H = \inangle{B}$ and $G=\inangle{A}$, subgroups
of $\Sym_n$. Check if $H\leq G$. 

The solution is extremely simple, for every element $b\in B$, check if
$b\in G$ using the {\sc membership} algorithm. \\

\noindent
{\sc normal:} Given $H =\inangle{B}$ and $G = \inangle{A}$, subgroups
of $\Sym_n$. Check if $H$ is a normal subgroup of $G$, denoted by
$H\lhd G$. 

This is also easy, for each $a\in A$ and each $b\in B$, check if
$ab\inv{a} \in H$ using {\sc membership}. \\

\begin{definition}
For any subgroup $H$ of $G$, normal closure of $H$ is defined as the
smallest normal subgroup of $G$ that contains $H$. It is denoted
by $\inangle{H^G}$
$$
H\leq \inangle{H^G}\lhd G
$$
The normalizer of $H$, denoted by $N_G(H)$, is the largest subgroup of
$G$ in which $H$ is normal. 
$$
H \lhd N_G(H) \leq G
$$
\end{definition}

\noindent
{\sc normal closure:} Given $H = \inangle{B}$ and $G = \inangle{A}$,
subgroups of $\Sym_n$, find $\inangle{H^G}$

This is easy too, look at $\setdef{ab\inv{a}}{a\in A, b\in B}$. If
something of this set is not in $H$, throw it into $B$ and
repeat. Everytime, the size of the group doubles and hence you will
definitely hit the normal closure quickly. 

\subsection{The Group-Intersection Problem}

{\sc group-inter:} Given $G = \inangle{A}$ and $H = \inangle{B}$,
subgroups of $\Sym_n$. Find $G\intersection H$. 

There is no known polynomial time algorithm for this problem in
general, and we don't expect one to exists even because of the
following theorem. 

\begin{theorem}
  {\sc set-stab} is polynomial time equivalent to {\sc group-inter}
\end{theorem}
\begin{proof}{\sc set-stab} $\leq_P$ {\sc group-inter}:
  
  Suppose $\Delta$ is the set we want to stabilize, all we need to do
  is to compute $G\intersection\inbrace{\Sym_{\Delta}\times
    \Sym_{\Omega \setminus \Delta}}$. One could just choose
  transpositions as a generating set for the product.

  The intersection of the two sets precisely yields
  $stab_\Delta(G)$. \\
  
  {\sc group-inter} $\leq_P$ {\sc set-stab}:

  Look at the product $G\times H \leq \Sym_\Omega \times \Sym_\Omega
  \leq Sym_{\Omega\times \Omega}$ and let the action be just the
  coordinate wise action, $(g,h)(i,j) = (i^g, j^h)$. All we need to do
  now is stabilize the diagonal, $\Omega\times \Omega =
  \setdef{(i,i)}{i\in \Omega}$ and this would yield $G\intersection H$. 
\end{proof}

And since we say that graph isomorphism reduced to {\sc set-stab}, it
is unlikely that we have a polynomial time algorithm for the
intersection problem. 

However, for a special case when $G$ normalizes $H$ (i.e $G\leq
N_{\Sym_\Omega}(H)$), we can solve the intersection problem in
polynomials time. 

\begin{claim}
  If $G$ normalizes $H$, then we can compute $G\intersection H$ in
  polynomial time. 
\end{claim}
\begin{proof}
  Again, we are looking for a tower of subgroups with ``nice''
  properties. And since $G$ normalizes $H$, the central idea is that
  $GH = \setdef{gh}{g\in G, h\in H}$ is a subgroup of $\Sym_n$. And
  hence, for all $i$, $\super{G}{i}H$ is also a subgroup. Further, $G$
  normalizes $H$ $\implies H \lhd GH$. 

  The tower we are looking for is
  $$
  G\cap H = G\cap \super{G}{n-1}H \leq G \cap \super{G}{n-2}H\leq \cdots
  \leq G\cap GH = G
  $$
  And since the generating set for $\super{G}{i}H$ is just the union
  of the generating set for $\super{G}{i}$ and $H$, we can check for
  membership in $G\cap \super{G}{i}H$. Thus, using Schreier's lemma
  and the {\sc reduce} algorithm, we can descend the tower computing
  generating sets. 

  An additional property we need is that the index between consecutive
  elements of the tower is small. We leave it as an exercise to show
  that $\gpidx{G\cap \super{G}{i-1}H}{G\cap \super{G}{i}H}\leq n-i$. 
\end{proof}
\newpage
\begin{algorithm}
\caption{\sc{reduce}}
\begin{algorithmic}[1]
\STATE $B_0 = B$
\STATE $A[\ ][\ ]$, an empty $n\times n$ array
\FOR{$i=0$ to $n-1$}
\FORALL{$\psi\in B_i$}
\STATE $j = i^\psi$
\IF{$A[i][j]$ is empty}
\IF{$j=i$}
\STATE $B_{i+1} = B_{i+1} \union \inbrace{\psi}$
\ELSE
\STATE $A[i][j] = \psi$
\ENDIF
\ELSE
\STATE $\pi = A[i][j]$
\STATE $B_{i+1} = B_{i+1} \union \inbrace{\pi\cdot\inv{\psi}}$
\ENDIF
\ENDFOR
\ENDFOR
\STATE discard all trivial elements from $\Union B_i$
\STATE {\bf return} $\Union B_i$
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{{\sc membership}}
\begin{algorithmic}[1]
\REQUIRE $g\in \Sym_n$ and a generating set $A$ for $\super{G}{i}
\leq \Sym_n$ and the index $i$
\IF{$g = id$}
\STATE {\bf return true}
\ENDIF
\STATE $X_i =(i+1)^{\super{G}{i}}$\quad\COMMENT{use the {\sc orbit}
  algorithm}
\STATE compute the set $R$ of distinct coset representatives of
$\super{G}{i+1}$ in $\super{G}{i}$
\STATE $k = (i+1)^g$\quad\COMMENT{image of $i+1$ under the action of $g$}
\IF{$k\notin X_i$}
\STATE {\bf return} {\bf false}
\ELSE 
\STATE compute generating set $B$ for $\super{G}{i+1}$ using Schreier's
lemma
\STATE {\sc reduce} $B$
\STATE pick $g_{ik}$ from $R$, the coset representative of
$\super{G}{i}$ 
\STATE $g'= g\cdot \inv{g_{ik}}$
\STATE {\bf return} {\sc membership}($g'$,$B$, $i+1$)
\ENDIF
\end{algorithmic}
\end{algorithm}

\end{document}



%The algorithm is as follows:
%% TODO: Get a better algorithms package!

% \begin{algorithmic}[1]
%   \FOR{$i = 1$ to $n$}
%   \IF{$g = id$} \RETURN \TRUE \ENDIF
%   \STATE Let $X$ be the orbit of $i$ under action of $\super{G}{i-1}$.
%   \STATE Write $\super{G}{i-1} = \Union_{k \in X}{\super{G}{i}g_{ik}}$ where $i^{g_{ik}}=k$.
%   \STATE $k \gets i^g$
%   \IF{$k \notin X$} \RETURN \FALSE \ENDIF
%   \STATE $g \gets g\inv{g_{ik}}$
%   \ENDFOR
% \end{algorithmic}

