\documentclass[11pt,twocolumn]{article}

\usepackage{array}
\usepackage{clrscode3e}
\usepackage{amsmath}
\usepackage{kbordermatrix}
\usepackage{mathtools}
\usepackage{cite}
\usepackage{hyperref}
\usepackage{rotating}
\usepackage{pdfpages}

\newcommand{\defeq}{\vcentcolon=}
\newcommand{\eqdef}{=\vcentcolon}

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\begin{document}

\title{Efficient Calculation of Polynomial and Interaction Features on Sparse Matrices}
\author{
  Andrew Nystrom\\
  \texttt{awnystrom@gmail.com}
  \and
  John Hughes\\
  \texttt{jfh@cs.brown.edu}
}
\date{}

\maketitle

\begin{abstract}%   <- trailing '%' for backward compatibility of .sty file
We give an algorithm to efficiently calculate second degree polynomial or interaction features for a sparse matrix.
The algorithm has average time complexity that decreases quadratically with respect to the density of the matrix, which
is a large improvement over the naive approach. It also allows for the matrix to remain in sparse form, reducing memory demands.
We apply the method to several real datasets and give both analytical and empirical comparisons with the
naive approach. The work also gives a generalizable method for creating algorithms for higher orders of polynomials.
\end{abstract}

\section{Introduction}

When performing a modeling task, one is often faced with a non-linearly separable problem,
or is attempting to predict a target that is a non-linear combination of the variables at one's disposal.
There are several general classes of methods for dealing with these situations: kernel methods,
high variance models, and input transformations.

Of the possible types of input transformations one
might apply, a widely used method is the polynomial transformation, which is defined as
all products of all combinations with replacement of $k$ components of a $D$ dimensional row vector $\vec{x}$ (assuming row-wise instance representation), where $k$ is the degree of the polynomial.
In the case of $k=2$, the following set of polynomial features are augmented to each $\vec{x}_i$:

\begin{equation*}
\{x_a \cdot x_b : a, b \in \{0,1,..., D-1\} \land a \le b\}
\end{equation*}

which results in $\binom{D+1}{D-1} = \frac{D^2+D}{2}$ additional features, so the generation of
these features for a matrix of size $N \times D$ has a time complexity of $O(ND^2)$. In the general case of degree $k$, there
are $\binom{D+k-1}{D-1}$ polynomial features and the time complexity is $O(ND^k)$.

To show the types of nonlinearity polynomial features are capable of imbuing a linear model with,
we trained logistic regression models on four inseparable datasets and plot their decision boundaries, as seen in figure \eqref{fig:boundaries} on page \pageref{fig:boundaries}. We compare
these decision boundaries to those learnt by more complex methods, namely a support vector machine with a radial basis function kernel\footnote{\url{http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html}}
and gradient boosted decision trees\footnote{\url{https://github.com/dmlc/xgboost/}}. As can be seen, polynomial features allow a simple linear classifier is capable of drawing decision boundaries
that in the form of arbitrary parabolas, hyperbolas, and elipses.

Beyond classification, polynomial regression \cite{theoryoflinearmodels} is a staple regression method.
We provide a demonstration of the power polynomial features can lend to a regression problem by fitting two ordinary least squares models to $y=sin(x) + \mathcal{N}(0, 0.1), x \in [0, \pi]$. The first model (the blue curve) was given only $x$ as its input. The second model (the green curve) was given $x$ and second degree polynomial features derived from $x$ (namely $x^2$). The curves the models learned can be seen in figure \ref{fig:regression}.

While polynomial features are a well known and used concept in machine learning (e.g. \cite{pavlidis2002learning, konidaris2009skill, wiesler2009investigations}) and work has been done to improve their utilization (e.g. \cite{pevckov2008minimal, huang2010predicting}), this is the first work that we know of that exploits matrix sparcity
to improve the speed with which they are calculated and allows them to be calculated for a sparse matrix.

\begin{sidewaysfigure}
    \centering
    \includegraphics[scale=0.25]{boundaries.eps}

     \caption{\footnotesize{Decision boundaries for four classifier types on four different datasets. The darker the color, the more certain the decision.
             The plain dataset is shown in the first column. Each other column is a type of classifier applied to that dataset. The classifier
             types are logistic regression, logistic regression with second degree polynomial features, RBF SVM, and gradient boosting with decision trees.
             The accuracy of each model is shown in the bottom right corner of that model's subplot.}}
    \label{fig:boundaries}
\end{sidewaysfigure}

\begin{figure}
    \centering
    \includegraphics[scale=0.4]{regression.eps}
     \caption{\footnotesize{Two linear regression models fit to $y=sin(x) + \mathcal{N}(0, 0.1), x \in [0, \pi]$. The blue line's model was given only $x$, while the green line's model was given $x$ and second degree polynomial features.}}
    \label{fig:regression}
\end{figure}

%\newpage

\section{Sparse Polynomial Features} \label{sec:sparse}
If the vectors of a feature matrix are sparse, many of these products of features will be
zero, and are therefore unnecessary to calculate if the matrix is stored in a sparse matrix
data structure. If the density (the fraction of nonzero elements) of the matrix is $d$ where $0 \le d \le 1$,
the number of nonzero polynomial features is

\begin{equation*}
\binom{dD+2-1}{dD-1} = \frac{d^2D^2+dD}{2}
\end{equation*}

and if only they were calculated, the time complexity of generating polynomial features
for a matrix of size $N \times D$ is $O(Nd^2D^2)$, quadratically lower than calculating them via brute force.

The question then is how to devise an algorithm to calculate polynomial features for a vector $\vec{x}$ so that
only the nonzero elements of $\vec{x}$ are considered during the calculation process. Two main components are needed: (1) the ability to
quickly access only the nonzero elements of $\vec{x}$ and (2) The ability to know which polynomial feature column
the product of features with indices $a$ and $b$ should be stored in.

The first of these necessary components is obtained simply by using the appropriate data structure
to store the sparse matrix (e.g. storing it in compressed sparse row form). The second component
is not only less readily available, but its necessity is less obvious. To make this need more clear, consider the
algorithm for the brute force calculation of polynomial features:

\begin{codebox}
\footnotesize
\Procname{$\proc{Dense Polynomial Features}(A)$}
    \zi $N \gets$ row count of $A$
    \zi $D \gets$ column count of $A$
    \zi $B$ $\gets$ Matrix of size $N \times \frac{D^2+D}{2}$
    \zi \For $\id{row}$ in $A$ \Do
    \zi     $k \gets 0$
    \zi     \For $\i \gets 0 \To D$ \Do
    \zi         \For $\j \gets i \To D$ \Do
    \zi             $r \gets$ index of $\id{row}$
    \zi             $B[r, k] \gets \id{row}[i] \cdot \id{row}[j]$
    \zi             $k \gets k + 1$
                \End
            \End
       	\End
\end{codebox}

Notice that, for an individual row, the location of a polynomial feature ($\id{row}[i] \cdot \id{row}[j]$) can be determined
by a simple counter $k$ that is incremented each pass through the inner loop. This cannot be
done if we only calculate products between nonzero elements of $\vec{x}$, because all that
will be known is the nonzero element indices - many iterations will be skipped (hence the improved computational complexity).

What is therefore needed is a mapping between row-column index pairs of $\vec{x}$ and the space ${0, 1, ..., \frac{D^2+D}{2}-1}$
(the output size of second degree polynomial features when $D = |\vec{x}|$). The ordering of the mapping is irrelevant so long as its input

\begin{equation*} \label{eq:input}
I \defeq \{(a, b) : a, b \in \{0,1,..., D-1\} \land a \le b\}
\end{equation*}

is bijective with its output

\begin{equation*} \label{eq:output}
O \defeq \{0, 1, ..., \frac{D^2+D}{2}-1\}
\end{equation*}

Interaction features are a way of capturing correlations between features in a machine
learning setting. A feature vector $\vec{x}$ of dimensionality $D$ has second degree interaction features
$\{x_i \cdot x_j : i, j \in \{0,1,..., D-1\} \land i < j\}$,
so a $D$ dimensional vector has $\binom{D}{2} = \frac{D^2-D}{2}$ second degree interaction features. A naive
approach to calculating these features is to simply iterate through the combinations of the column indices.
For a sparse vector, many of the resulting interaction features would be zero, and could therefore be ignored.
This work describes a method to efficiently calculate second degree interaction features for a sparse matrix
that has time and space complexities that decrease quadratically with the density of the input matrix with respect to the naive approach.

\section{Approach}
Let the list of nonzero columns for a given row $\vec{x}$ be denoted by $N_{zc}$. The nonzero second degree
interaction features are simply the products of all combinations of two elements whose
columns are in $N_{zc}$. However, to properly place an interaction feature into the correct column, a mapping from the column
index pairs of $N_{zc}$ into the columns of the interaction matrix is needed. The mapping is
from pairs $(i, j)$,  where $i$ and $j$ are in $0, 1, \ldots , D-1$, and $i < j$, to $0, 1,2,..., \frac{D^2-D}{2} - 1$,  Such a mapping essentially consists of mapping the indices of entries in the upper triangle of a matrix to indices in a flat
list. We now describe the construction of such a mapping.

\subsection{Mapping construction}

We seek a map from matrix indices $(i, j)$ (with $i < j$ and $0 \le i < D$) to numbers $f(i, j)$ with $0 \le f(i, j) < \frac{D(D-1)}{2}$, one that follows the pattern indicated by
\begin{align}
\begin{bmatrix}
x & 0 & 1 & 3 \\
x & x & 2 & 4 \\
x & x & x & 5 \\
x & x & x & x
\end{bmatrix}
\label{eq:4x4mat}
\end{align}
where the entry in row $i$, column $j$, displays the value $f(i, j)$.

To simplify slightly, we introduce a notation for the $n$th triangular number,
\begin{align}
T_2(n) = \frac{n(n+1)}{2}
\end{align}
\noindent
The subscript $2$ indicates that these are triangles in two dimensions; we'll use $T_3(n)$ to indicate the $n$th tetrahedral number, and so on for higher dimensions.

Observe that in Equation~\ref{eq:4x4mat}, each entry in column $j$ (for $j > 0$) lies in the range
\begin{align}
T_2(j-1) &\le e < T_2(j).
\end{align}
\noindent
And in fact, the entry in the $i$th row of that column is just $i + T_2(j-1)$. Thus we have
\begin{align}
f(i, j)
&= i + T_2(j-1)\\
&= i + \frac{(j-1)j}{2}\\
&=  \frac{2i + j^2-j}{2}.
\end{align}

For instance, in column $j = 2$ in our example (the \emph{third} column), the entries range from $1$ to $2$, while $T_2(j-1) = T_2(1) = 1$ and $T_2(j) = T_2(2) = 3$, and the entry in column $j = 2$, row $i = 1$ is
$i + T_2(j-1) = 1 + 1 = 2$.

\subsubsection{Other indices}
With one-based indexing in both the domain and codomain, the formula above becomes
\begin{align}
f_1(i, j) &= 1+ f(i-1, j-1) \\
&= 1+ f(i-1, j-1) \\
& = \frac{2 + 2(i-1) + (j-1)^2-(j-1)}{2}\\
& = \frac{2i + j^2 - 3j + 2}{2}
\end{align}

\subsubsection{Polynomial Features}
For polynommial features, we seek a map from matrix indices $(i, j)$ (with $i \le j$ and $0 \le i < D$) to numbers $g(i, j)$ with $0 \le f(i, j) < \frac{D(D+1)}{2}$, one that follows the pattern indicated by
\begin{align}
\begin{bmatrix}
 0 & 1 & 3 & 6 \\
 x & 2 & 4 & 7\\
 x & x & 5 & 8 \\
 x & x & x & 9
\end{bmatrix}
\label{eq:4x4mat-poly}
\end{align}
i.e., essentially the same task as before, except that the diagonal is included. One can regard all but the last column of entries in Equation~\ref{eq:4x4mat-poly} as corresponding to the entries in Equation~\ref{eq:4x4mat}, but shifted to the left. Thus the formula for $g(i, j)$ is simply the formula for $f$, shifted by 1, i.e.,
\begin{align}
g(i, j) &= f(i, j+1)  \\
&=  \frac{2i + (j+1)^2-(j+1)}{2}\\
&=  \frac{2i + j^2 + j + 1)}{2}.
\end{align}
Alternatively, we can write this as
\begin{align}
g(i, j) &= i + T_2(j),
\end{align}
\noindent
and get the same result.

\subsubsection{Higher dimensions}
To handle three-way interactions, we need to map triples of indices in a 3-index array to a flat list, and similarly for higher-order interactions.

For three indices, $i,j,k$, with $i < j < k$ and $0 \le i,j,k < D$, we have a similar recurrence. Calling the mapping $h$, we have
\begin{align}
h(i,j,k) = i + T_2(j-1) + T_3(k-2);
\end{align}
if we define $T_1(i) = i$, then this has the very regular form
\begin{align}
h(i,j,k) =  T_1(i) + T_2(j-1) + T_3(k-2);
\end{align}
and from this, the generalization to higher dimensions is straightforward. The formulas for ``higher triangular numbers'', i.e., those defined by
\begin{align}
T_k(n) &= \sum_{i=1}^n T_{k-1}(n)
\end{align}
for $k > 1$ can be determined inductively. For $k = 3$, the result is
\begin{align}
T_3(n) &= \sum_{i=1}^n T_{2}(n)\\
&= \frac{n^3 + 3n^2 + 2n}{6},
\end{align}
so that the formula for 3-way interactions, with zero-based indexing, becomes
\begin{align}
h(i, j, k) &= 1 + (i-1) + \frac{(j-1)j}{2} + \\
& \frac{(k-2)^3 + 3(k-2)^2 + 2(k-2)}{6}.
\end{align}
\subsubsection{Higher-dimension polynomial features}
For the case where we include the diagonal in higher dimensions, we must shift $j$ by $1$, $k$ by $2$, and so on, and the formula becomes
\begin{align}
\ell(i,j,k) =  T_1(i) + T_2(j) + T_3(k),
\end{align}
with analogous formulas for higher degree polynomial interactions.

\subsection{Inversion}
We not only want to be able to compute the ``flat index'' $f(i,j)$ corresponding to a particular index pair $(i, j)$, we'd like, given a value $N = f(i, j)$, to be able to determine $i$ and $j$. We know, given $N$, that $f(0, j) \le N \le f(j,j-1)$, i.e., that
\begin{align}
\frac{j^2 - 3j + 2}{2} &\le N \le \frac{2(j-1) + j^2 - 3j + 2}{2}\\
{j^2 - 3j + 2} &\le 2N \le {j^2 - j}.
\end{align}
If we find the (real number) value $j_{*}$ for which $j_{*}^2 - j_{*} = 2N$, then we know that $j = \lfloor j_{*}\rfloor$. Finding $j_{*}$ amounts to solving a quadratic, whence
\begin{align}
j_{*} = \frac{1 \pm \sqrt{1 + 8N}}{2}.
\end{align}
Clearly the larger value,
\begin{align}
j_{*} = \frac{1 + \sqrt{1 + 8N}}{2},
\end{align}
is the one we seek; we set $j = \lfloor j_{*}\rfloor$, and compute $i = N - \frac{j^2 - j}{2}$.
In practice, repeatedly computing square roots may be annoying; instead, when we compute $N = f(i,j)$, we can record the values of $i$ and $j$ along with the interaction features, making inversion a simple matter of looking up these values.

Similarly, for polynomial features, to invert
\begin{align}
g(i, j) &=  \frac{2i + j^2 + j + 1)}{2}
\end{align}
we know that if $N = g(i,j)$, then $g(0,j) \le N \le g(j,j)$, which tells us that
\begin{align}
2N \le j^2 + 3j + 1, \text{ so}\\
0 \le j^2 + 3j + (1-N^2)
\end{align}.
Solving for $j$ when this last inequality is an equality, we get
\begin{align}
j_{*} = \frac{-3 \pm \sqrt{ 5 - N^2 }}{2};
\end{align}
Once again, we set $j = \lfloor j_{*}\rfloor$, and compute $i = N - \frac{j^2 + j + 1}{2}$.

Inverting the higher-order formulas, which involve cubics, quartics, etc., is infeasible, but storing the inverse map as described above may be practical, especially for sparse feature sets.

\section{The Algorithm}
In section X we showed why a mapping from the space X
onto the space X is necessary for calculating polynomial features for a sparse matrix, then
derived such a mapping.

We now have the necessary components for an algorithm to efficiently calculate polynomial features for
a sparse matrix. The matrix needs to be stored in a form that allows for its nonzero column indices, e.g. in sparse row form,
and we will use the mapping derived in X to determine which column in the output space
the polynomial feature between two input columns is mapping onto. Combining these ideas yields the following algorithm:

\begin{codebox}
\footnotesize
\Procname{$\proc{Sparse Polynomial Features}(A)$}
    \zi $\func{PolyMap}(a, b) = \frac{2Da-a^2+2b-3a-2}{2}+a+1$
    \zi $N \gets$ row count of $A$
    \zi $D \gets$ column count of $A$
    \zi $B$ $\gets$ empty sparse $N \times \frac{D^2+D}{2}$ matrix
    \zi \For $\id{row}$ in $A$ \Do
    \zi     $N_{zc} \gets$ nonzero columns of $row$
    \zi     \For $i \gets 0 \To |N_{zc}|$ \Do
    \zi         \For $j \gets i \To |N_{zc}|$ \Do
    \zi             $k \gets \func{PolyMap}(N_{zc}[i], N_{zc}[j])$
    \zi             $r \gets$ index of $\id{row}$
    \zi             $B[r, k] \gets \id{row}[N_{zc}[i]] \cdot \id{row}[N_{zc}[j]]$
                \End
            \End
       	\End
\end{codebox}

Using the mapping for interaction features and changing the bounds in the loop conditions and the size of the output matrix,
the algorithm can be modified to give second order interaction features:

\begin{codebox}
\footnotesize
\Procname{$\proc{Sparse Interaction Features}(A)$}
    \zi $\func{InterMap}(a, b) = \frac{2Da-a^2+2b-3a-2}{2}$
    \zi $N \gets$ row count of $A$
    \zi $D \gets$ column count of $A$
    \zi $B$ $\gets$ empty sparse $N \times \frac{D^2-D}{2}$ matrix
    \zi \For $\id{row}$ in $A$ \Do
    \zi     $N_{zc} \gets$ nonzero columns of $row$
    \zi     \For $i \gets 0 \To |N_{zc}|-1$ \Do
    \zi         \For $j \gets i+1 \To |N_{zc}|$ \Do
    \zi             $k \gets \func{InterMap}(N_{zc}[i], N_{zc}[j])$
    \zi             $r \gets$ index of $\id{row}$
    \zi             $B[r, k] \gets \id{row}[N_{zc}[i]] \cdot \id{row}[N_{zc}[j]]$
                \End
            \End
       	\End
\end{codebox}

where $N_{zc}$ are the columns of nonzero elements of row $\id{row}$.

\section{Analysis}

\subsection{Analytical}
We assume the input matrix $A$ is in sparse row form. The steps prior to the first loop are
constant operations. The outer loop will be executed $N$ times (once for each row). For each row,
the innermost loop will be executed and the inner loop will be $\frac{|N_{zc}|^2+|N_{zc}|}{2}$ times.
If the density is uniformly distributed across all rows, $E[|N_{zc}|] = dD$, but this cannot be assumed. In the worst case,
then, the innermost loop will each be executed $\frac{D^2+D}{2}$ times, but on average, $\frac{d^2D^2+dD}{2}$ times.
The operations in the innermost loop are constant. The time complexity is therefore $O(ND^2)$ and $\Theta(Nd^2D^2)$.

In machine learning, an input matrix often has near uniform density across its rows.
For example, if the matrix is sparse due to one-of-m encoding (also known as one-hot vectors), each row vector will
have the same number of nonzero components.

\subsection{Empirical}
To assess the performance of the algorithm on data of varied density, we compare its speed
to the PolynomialFeatures class of the popular machine learning scikit-learn \cite{scikit-learn}.
Uniformly random matrices of size $100 \times D$ were generated for $d=0.1$, $0.2$, $0.3$, $0.4$, and $0.5$, and
$D=1$, $101$, $201$, $301$, $401$, and $501$. Each point was resampled five times and averaged to decrease variance. Since the scikit-learn version of the algorithm
does not exploit sparsity, we assume the method's time is invariate with respect the density of the matrix, but
we gave it the lowest density of each dimensionality to be fair. The results are shown in figure \eqref{fig:benchmark} on page \pageref{fig:benchmark}.

\begin{figure}[ht, numbered]
    \includegraphics[scale=0.4]{benchmark.eps}
    \caption{This plot shows how long the sparse polynomial method took to run on matrices with 1000 rows of various dimensionalities and densities and compared to the scikit-learn PolynomialFeatures class on various dimensionalities.}
    \label{fig:benchmark}
    \centering
\end{figure}

As can be seen, the sparse method starts out slower than scikit-learn for each density. This
is either due to the overhead required by the sparse method (e.g. utilizing the mapping function),
or is due to implementation differences. The sparse method eventually becomes faster than scikit-learn
for each density. Note the excellent performance of $d=0.2$. This level of density is not uncommon when
working with sparse matrices.

The above benchmark was done on synthetic data. To more realistically determine the performance of
the algorithm, we applied it to two real world datasets: 20newsgroups\footnote{\url{http://scikit-learn.org/stable/datasets/twenty_newsgroups.html}} and connect-4, which was obtained
from the UCI Machine Learning Repository \cite{Lichman:2013}\footnote{\url{https://archive.ics.uci.edu/ml/datasets/Connect-4}}. We compare the time and space required by the sparse method and scikit-learn in table \eqref{table:results}.

\begin{table}
    \centering
    \small
    \begin{tabular}[numbered]{c | c | c} \label{table:results}
 %       \hline
        dataset             & 20newsgroups  & connect-4 \\ \hline
        instances           & 11,314        & 67,557    \\ \hline
        features            & 130107       & 126       \\ \hline
        polynomial features & 8,463,980,778 & 8,127     \\ \hline
        density             & 0.12          & 0.11      \\ \hline
        dense space (MB)    & Memory Error  & 4191      \\ \hline
        sparse space (MB)   & 5333          & 735       \\ \hline
        dense time (s)      & Memory Error  & 26        \\ \hline
        sparse time (s)     & 109           & 44        \\ \hline
%        \hline
    \end{tabular}
    \caption{Time and space comparison of second degree polynomial feature calculation between the sparse method and scikit-learn.}
\end{table}

Notice that scikit-learn was unable to calculate polynomial features for the 20newsgroups
matrix; a memory error was encountered. The sparse method, however, succeeded in 109 seconds.
The resulting matrix had nearly 8.5 billion features. While most machine learning libraries would
struggle with such a high dimensionality, some, such as the system described in \cite{agarwal2014reliable} (which is
available as part of the Vowpal Wabbit package\footnote{\url{https://github.com/JohnLangford/vowpal_wabbit/wiki}}), would likely be capable
of learning a model from such data.

The connect-4 dataset had its polynomial features computed faster via the dense method than the sparse. This
is likely because the dimensionality is sufficiently low for the overhead of the sparse method
to not have overtaken the dense method in terms of speed. However, the sparse method took less than
a fifth of the memory and took less than twice the speed, so using the sparse method during parameter
optimization in a multi-core setting would drastically increase parameter search throughput.

\section{Summary \& Future Work}
In this work we have given a method of calculating second degree polynomial features on sparse matrices
with time complexity that quadratically decreases with respect to the density of the matrix.

This work also gives a general pattern for calculating polynomial features of arbitrary degrees:
instead of finding a mapping from the 2-tuples of indices onto the space $\{0, 1, ..., \frac{D^2+D}{2}-1\}$,
construct a mapping from k-tuples of indices onto the space $\{0, 1, ..., \binom{D+k-1}{D-1}-1\}$, where $k$ is the degree of the polynomial.
In terms of the upper triangular matrix analogy, this corresponds with mapping the upper k-simplex of a $(D, D, ..., D)$-tensor onto
the space $\{0, 1, ..., \binom{D+k-1}{D-1}-1\}$. For the average case of $dD$ nonzero elements per row,
there will be $\binom{dD+k-1}{dD-1}$ polynomial features, so the average time complexity for an $N \times D$ matrix
is $\Theta(Nd^kD^k)$, which means that its time complexity polynomially decreases with respect to the density
compared to the dense algorithm (which has $O(ND^k)$ and $\Theta(ND^k)$).

\vskip 0.2in
\bibliography{paper2}{}
\bibliographystyle{plain}
\end{document}


\documentclass{article}[18pt]
\input{format}
\lhead{MCS Coursework}
\rhead{mbkb74}
\usepackage{natded}
\lstset
{
	language=[LaTeX]TeX,
	breaklines=true,
	basicstyle=\tt\scriptsize,
}

\begin{document}
\begin{center}
\textbf{\Large Discrete Mathematics and Linear Algebra}
\end{center}
Approximately 10 hours was spent on this coursework
\begin{enumerate}
	\item \textit{Prove \textit{using induction}, that the following holds for all $n\geqslant 1$}:\hfill
[12 marks]

	$$2(\sqrt{n+1}-1)<1+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}<2\sqrt{n}$$
	$ $\\
	\textbf{Base case:} n=1
	$$2(\sqrt{1+1}-1)<1<2\sqrt{1}$$
	This holds\\
\\
\textbf{Proving the 1st half \cite{rosen}}\\
$$ Let \ P(n) \ be \  2(\sqrt{n+1}-1)<\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}$$
\textbf{Basis step: P(1) is true}
$$2(\sqrt{2}-1)<1$$
\textbf{Inductive step: Assume that P(k) is true}
$$2(\sqrt{k+1}-1)+\dfrac{1}{\sqrt{k+1}}<\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{k}}+\dfrac{1}{\sqrt{k+1}}$$
\textbf{By showing that $2(\sqrt{k+1}-1)+\dfrac{1}{\sqrt{k+1}}>2(\sqrt{k+2}-1)$ it follows that P(k+1) is true}
$$2(\sqrt{k+2}-\sqrt{k+1})<\dfrac{1}{\sqrt{k+1}}$$
$$2(\sqrt{k+2}+\sqrt{k+1})(\sqrt{k+2}+\sqrt{k+1})<\dfrac{\sqrt{k+1}}{\sqrt{k+1}}+\dfrac{\sqrt{k+2}}{\sqrt{k+1}}$$
$$2<1+\dfrac{\sqrt{k+2}}{\sqrt{k+1}}$$
$$1<\dfrac{\sqrt{k+2}}{\sqrt{k+1}}$$
$$1<\dfrac{k+2}{k+1}$$
$$k+1<k+2$$
$$1<2$$
$$0<1$$
Trivially True, so true for P(k+1) and so by induction, since the statement is true for n=1, and that it is valid for n=k+1 if it is valid for k, we can conclude that is it valid for all positive integers \\
$$2(\sqrt{n+1}-1)<\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}$$
\newpage
\textbf{Proving the second half}
$$Let \ P(n) \ be \dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}<2\sqrt{n}$$
\textbf{Inductive step: Assume that P(k) is true}
$$\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{k}}<2\sqrt{k}$$
\textbf{Is it true for P(k+1)}
$$\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{k}}+\dfrac{1}{\sqrt{k+1}}<2\sqrt{k}+\dfrac{1}{\sqrt{k+1}}$$
\textbf{By showing that $2\sqrt{k+1}>2\sqrt{k}+\dfrac{1}{\sqrt{k+1}}$ it follows that P(k+1) is true}
$$2(\sqrt{k+1}-\sqrt{k})>\dfrac{1}{\sqrt{k+1}}$$
\textbf{Multiply by $\sqrt{k+1}+\sqrt{k}$}
$$2(1)>\dfrac{\sqrt{k+1}+\sqrt{k}}{\sqrt{k+1}}$$
$$2>1+\dfrac{\sqrt{k}}{\sqrt{k+1}}$$
$$1>\dfrac{\sqrt{k}}{\sqrt{k+1}}$$
$$1>\dfrac{k}{k+1}$$
$$k+1>k$$
$$1>0$$
Trivially True, so true for P(k+1) and so by induction, since the statement is true for n=1, and that it is valid for n=k+1 if it is valid for k, we can conclude that is it valid for all positive integers \\
$$\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}<2\sqrt{n}$$
Since the statement is true for n=1, and that it is valid for n=k+1 if it is valid for k, we can conclude that is it valid for all positive integers \\
\\
As $2(\sqrt{n+1}-1)<\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}$ is true, and $\dfrac{1}{\sqrt{1}}+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}<2\sqrt{n}$ is true, it follows that:
	$$2(\sqrt{n+1}-1)<1+\dfrac{1}{\sqrt{2}}+...+\dfrac{1}{\sqrt{n}}<2\sqrt{n}$$

\newpage
	\item \textit{Four fair dice are thrown. What is more likely; to get exactly one 6 or to get four different numbers?} \hfill [8 marks]\\
	\\
	To get exactly one 6, there is a probability of:
	$$\dfrac{1}{6}\times(\frac{5}{6})^3$$
	per dice, so multiplying by 4 gives
	$$\dfrac{125}{324}$$
	\\
	On the first dice, there is a probability of 1 there is a new number, on the second dice, there is a probability of $\frac{5}{6}$ there is a new number, on the 3rd $\frac{4}{6}$ and on the fourth $\frac{3}{6}$
	$$1\times\frac{5}{6}\times \frac{4}{6}\times\frac{3}{6}=\frac{5}{18}$$
	$\dfrac{5}{18}<\dfrac{125}{324}$ so it is more likely to get one 6.

	\newpage
	\item\textit{ Letters A, B, C, and D are listed in random order. Let X be the random variable
	equal to the number of pairs of letters not in alphabetical order (for example, in
	CADB, such pairs are CA, CB, and DB). Find the expected value and the variance
	of X} \hfill[10 marks]\\
	\begin{tabular}{|c|c|}
		\hline
		Ordering & Pairs not in order (X) \\
		\hline
		ABCD & 0 \\
		\hline
		ABDC & 1 \\
		\hline
		ACBD & 1 \\
		\hline
		ACDB & 2 \\
		\hline
		ADBC & 2 \\
		\hline
		ADCB & 3 \\
		\hline
		BACD & 1 \\
		\hline
		BADC & 2 \\
		\hline
		BCAD & 2 \\
		\hline
		BCDA & 3 \\
		\hline
		BDAC & 3 \\
		\hline
		BDCA & 4 \\
		\hline
		CABD & 2 \\
		\hline
		CADB & 3 \\
		\hline
		CBAD & 3 \\
		\hline
		CBDA & 4 \\
		\hline
		CDAB & 4 \\
		\hline
		CDBA & 5 \\
		\hline
		DABC & 3 \\
		\hline
		DACB & 4 \\
		\hline
		DBAC & 4 \\
		\hline
		DBCA & 5 \\
		\hline
		DCAB & 5 \\
		\hline
		DCBA & 6 \\
		\hline
	\end{tabular}
$$p(x=0)=\dfrac{1}{24}$$
$$p(x=1)=\dfrac{3}{24}$$
$$p(x=2)=\dfrac{5}{24}$$
$$p(x=3)=\dfrac{6}{24}$$
$$p(x=4)=\dfrac{5}{24}$$
$$p(x=5)=\dfrac{3}{24}$$
$$p(x=6)=\dfrac{1}{24}$$
$$E(X)=0\times\dfrac{1}{24}+
1\times\dfrac{3}{24}+
2\times\dfrac{5}{24}+
3\times\dfrac{6}{24}+
4\times\dfrac{5}{24}+
5\times\dfrac{3}{24}+
6\times\dfrac{1}{24}=3$$
$$E(X^2)=0^2\times\dfrac{1}{24}+
1^2\times\dfrac{3}{24}+
2^2\times\dfrac{5}{24}+
3^2\times\dfrac{6}{24}+
4^2\times\dfrac{5}{24}+
5^2\times\dfrac{3}{24}+
6^2\times\dfrac{1}{24}=\dfrac{67}{6}$$
$$Var(X)=E(X^2)-E(X)^2=\dfrac{67}{6}-3^2=\dfrac{13}{6}$$
\newpage

	\item \textit{For each integer $q\geqslant 2$ determine whether the complete bipartite graph $K_{3,q}$ is KO-reducible, and if so find its KO number} \hfill [20 marks]
	\begin{figure}[H]
		\begin{center}
			\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]}]

			\node[main_node] (3) at (0,2) {3};
			\node[main_node] (2) at (0,4) {2};
			\node[main_node] (1) at (0,6) {1};
			\node[main_node] (8) at (4,0) {8};
			\node[main_node] (7) at (4,2) {7};
			\node[main_node] (6) at (4,4) {6};
			\node[main_node] (5) at (4,6) {5};
			\node[main_node] (4) at (4,8) {4};

			\draw (1) -- (4);
			\draw (2) -- (4);
			\draw (3) -- (4);
			\draw (1) -- (5);
			\draw (2) -- (5);
			\draw (3) -- (5);
			\draw (1) -- (6);
			\draw (2) -- (6);
			\draw (3) -- (6);
			\draw (1) -- (7);
			\draw (2) -- (7);
			\draw (3) -- (7);
			\draw (1) -- (8);
			\draw (2) -- (8);
			\draw (3) -- (8);
			\end{tikzpicture}
		\end{center}
		\caption{$K_{3,5}$}
		\label{K3,5}
	\end{figure}
Consider the complete bipartite graph to be made of two sets, set A on the left hand side has 3 elements. Set B on the right hand side has q elements.\\
\\
As in each round each element from each set must select an element from the other set, at a minimum one element from each set will be removed per round.\\
 This means that there is a maximum of 3 rounds as after that set A will be empty, as it contains 3 elements. In this case where the minimum number of elements is removed from set A each turn, there will be 3, then 2, then 1, then 0 elements in that set. This means that the maximum that could be removed from set B in this case is 3 elements, then 2 elements, then 1 element, if all the elements of set A were to choose different elements from set B. This means that if $q>6$ then set B could not be emptied before set A. Therefore for any $q>6$ the graph will not be KO-Reducible.\\
\\
This means that when the number of knockouts that can be performed on set B are:
\begin{itemize}
	\item 3 in round 1
	\item 2 in round 2 - meaning up to 5 can be knocked out at the end of round 2
	\item 1 in round 3 - meaning up to 6 can be knocked out at the end of round 3
\end{itemize}
This means that:
\begin{itemize}
\item $q=3$ has a KO number of 1
\item $q=4$ and $q=5$ have a KO number of 2
\item $q=6$ has a KO number of 3
\end{itemize}
However importantly this does not mean that $q=2$ can be knocked out in one round, as in this case set 2 is the smaller set, so in one round, all of set 2 could be knocked out, but there would be an element remaining in set 1. So in cases where $|Set \ A|>|Set \ B|$, instead of trying to remove the maximal number from set B and the minimal from set A, it should be the other way round.\\
Because of the remaining condition that one needs to be knocked out from each set per round, by removing one from set B each round, 2 can be removed from set A in the first round and 1 in the second, resulting in a KO number of 2 for $q=2$ \\
\\
$q=4$ is treated slightly differently as it is not on one of the maximums for a round. This means that if the elements from set B were to be deleted maximally it would not be KO reducible. Instead, in the first round, two of the elements from set A need to select one element from set B, allowing the second round to have 2 elements in each set, which select each other to reduce to nothing.\\
\\
Method:
Consider the two sets A ($S_A$) and B ($S_B$), below is outlined how many from each set should be selected per round:\\
\\
\textbf{q=2: KO 2}
\begin{itemize}
	\item 1st round $S_A$:2, $S_B$:1
	\item 2nd round $S_A$:1, $S_B$:1
\end{itemize}
\textbf{q=3: KO 1}
\begin{itemize}
	\item 1st round $S_A$:3, $S_B$:3
\end{itemize}
\textbf{q=4: KO 2}
\begin{itemize}
	\item 1st round $S_A$:1, $S_B$:2
	\item 2nd round $S_A$:2, $S_B$:2
\end{itemize}
\textbf{q=5: KO 2}
\begin{itemize}
	\item 1st round $S_A$:1, $S_B$: 3
	\item 2nd round $S_A$:2, $S_B$:2
\end{itemize}
\textbf{q=6: KO 3}
\begin{itemize}
	\item 1st round $S_A$:1, $S_B$:3
	\item 2nd round $S_A$:1, $S_B$:2
	\item 3rd round $S_A$:1, $S_B$:1
\end{itemize}
\newpage
\section{Graphs}
Below is shown the nodes to be selected from the graph in each turn in order for it to be KO reducible. When all the nodes are selected, no nodes will exist in the next round, so it has been reduced.
\subsection{q=2}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]}]

		\node[main_node] (3) at (0,2) {3};
		\node[select_node] (2) at (0,4) {2};
		\node[select_node] (1) at (0,6) {1};
		\node[main_node] (6) at (4,4) {5};
		\node[select_node] (5) at (4,6) {4};

		\draw (1) -- (5);
		\draw (2) -- (5);
		\draw (3) -- (5);
		\draw (1) -- (6);
		\draw (2) -- (6);
		\draw (3) -- (6);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,2}$ - Round 1}
	\label{K3,5}
\end{figure}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]}]

		\node[select_node] (3) at (0,2) {3};
		\node[select_node] (6) at (4,4) {5};

		\draw (3) -- (6);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,2}$ - Round 2}
	\label{K3,5}
\end{figure}
\subsection{q=3}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]}]

		\node[select_node] (3) at (0,2) {3};
		\node[select_node] (2) at (0,4) {2};
		\node[select_node] (1) at (0,6) {1};
		\node[select_node] (7) at (4,2) {6};
		\node[select_node] (6) at (4,4) {5};
		\node[select_node] (5) at (4,6) {4};

		\draw (1) -- (5);
		\draw (2) -- (5);
		\draw (3) -- (5);
		\draw (1) -- (6);
		\draw (2) -- (6);
		\draw (3) -- (6);
		\draw (1) -- (7);
		\draw (2) -- (7);
		\draw (3) -- (7);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,3}$ - Round 1}
	\label{K3,3}
\end{figure}
\subsection{q=4}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]}]

		\node[main_node] (3) at (0,2) {3};
		\node[main_node] (2) at (0,4) {2};
		\node[select_node] (1) at (0,6) {1};
		\node[main_node] (7) at (4,2) {7};
		\node[main_node] (6) at (4,4) {6};
		\node[select_node] (5) at (4,6) {5};
		\node[select_node] (4) at (4,8) {4};

		\draw (1) -- (4);
		\draw (2) -- (4);
		\draw (3) -- (4);
		\draw (1) -- (5);
		\draw (2) -- (5);
		\draw (3) -- (5);
		\draw (1) -- (6);
		\draw (2) -- (6);
		\draw (3) -- (6);
		\draw (1) -- (7);
		\draw (2) -- (7);
		\draw (3) -- (7);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,4}$ - Round 1}
	\label{K3,4}
\end{figure}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]}]

		\node[select_node] (3) at (0,2) {3};
		\node[select_node] (2) at (0,4) {2};
		\node[select_node] (7) at (4,2) {7};
		\node[select_node] (6) at (4,4) {6};

		\draw (2) -- (6);
		\draw (3) -- (6);
		\draw (2) -- (7);
		\draw (3) -- (7);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,4}$ - Round 2}
	\label{K3,4}
\end{figure}
\subsection{q=5}

	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]}]

		\node[main_node] (3) at (0,2) {3};
		\node[main_node] (2) at (0,4) {2};
		\node[select_node] (1) at (0,6) {1};
		\node[main_node] (8) at (4,0) {8};
		\node[main_node] (7) at (4,2) {7};
		\node[select_node] (6) at (4,4) {6};
		\node[select_node] (5) at (4,6) {5};
		\node[select_node] (4) at (4,8) {4};

		\draw (1) -- (4);
		\draw (2) -- (4);
		\draw (3) -- (4);
		\draw (1) -- (5);
		\draw (2) -- (5);
		\draw (3) -- (5);
		\draw (1) -- (6);
		\draw (2) -- (6);
		\draw (3) -- (6);
		\draw (1) -- (7);
		\draw (2) -- (7);
		\draw (3) -- (7);
		\draw (1) -- (8);
		\draw (2) -- (8);
		\draw (3) -- (8);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,5}$ - Round 1}
	\label{K3,5}
\end{figure}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]}]

		\node[select_node] (3) at (0,2) {3};
		\node[select_node] (2) at (0,4) {2};

		\node[select_node] (8) at (4,0) {8};
		\node[select_node] (7) at (4,2) {7};

		\draw (2) -- (7);
		\draw (3) -- (7);

		\draw (2) -- (8);
		\draw (3) -- (8);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,5}$ - Round 2}
	\label{K3,5}
\end{figure}
\subsection{q=6}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]},scale=0.8]

		\node[main_node] (3) at (0,2) {3};
		\node[main_node] (2) at (0,4) {2};
		\node[select_node] (1) at (0,6) {1};
		\node[main_node] (9) at (4,-2) {9};
		\node[main_node] (8) at (4,0) {8};
		\node[main_node] (7) at (4,2) {7};
		\node[select_node] (6) at (4,4) {6};
		\node[select_node] (5) at (4,6) {5};
		\node[select_node] (4) at (4,8) {4};

		\draw (1) -- (4);
		\draw (2) -- (4);
		\draw (3) -- (4);
		\draw (1) -- (5);
		\draw (2) -- (5);
		\draw (3) -- (5);
		\draw (1) -- (6);
		\draw (2) -- (6);
		\draw (3) -- (6);
		\draw (1) -- (7);
		\draw (2) -- (7);
		\draw (3) -- (7);
		\draw (1) -- (8);
		\draw (2) -- (8);
		\draw (3) -- (8);
		\draw (1) -- (9);
		\draw (2) -- (9);
		\draw (3) -- (9);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,6}$ - Round 1}
	\label{K3,6}
\end{figure}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]},scale=0.8]

		\node[main_node] (3) at (0,2) {3};
		\node[select_node] (2) at (0,4) {2};
		\node[main_node] (9) at (4,-2) {9};
		\node[select_node] (8) at (4,0) {8};
		\node[select_node] (7) at (4,2) {7};

		\draw (2) -- (7);
		\draw (3) -- (7);

		\draw (2) -- (8);
		\draw (3) -- (8);

		\draw (2) -- (9);
		\draw (3) -- (9);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,6}$ - Round 2}
	\label{K3,6}
\end{figure}
	\begin{figure}[H]
	\begin{center}
		\begin{tikzpicture}[main_node/.style={circle,fill=blue!20,draw,minimum size=1em,inner sep=3pt]},select_node/.style={circle,fill=red!60,draw,minimum size=1em,inner sep=3pt]},scale=0.8]

		\node[select_node] (3) at (0,2) {3};
		\node[select_node] (9) at (4,-2) {9};

		\draw (3) -- (9);
		\end{tikzpicture}
	\end{center}
	\caption{$K_{3,6}$ - Round 3}
	\label{K3,6}
\end{figure}

\newpage
\begin{center}
	\textbf{\Large Logic and Discrete Structures}
\end{center}
	\item \textit{Let $\varphi$ be the formula $((a\land b)\Rightarrow c)\land (a\lor b)$}
	\begin{enumerate}
		\item \textit{Reduce $\varphi$ to disjunctive normal form using truth tables} \hfill [10 marks]
		\item\textit{ Reduce $\lnot \varphi$ to conjunctive normal form (without using truth tables)}\hfill [5 marks]
	\end{enumerate}
(a).\\
\begin{center}

{\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|c|c|c|c|c|c|c|cc}
	\cline{1-7}
	a & b & c & $((a\land b)$ & $\Rightarrow c)$ & $\land$ & $(a\lor b)$&&$\varphi$ \\
	\cline{1-7}
	F & F & F & F & T & \textbf{F} & F&&F \\
	\cline{1-7}
	F & F & T & F & T & \textbf{F} & F&&F \\
	\cline{1-7}
	F & T & F & F & T & \textbf{T} & T&&T \\
	\cline{1-7}
	F & T & T & F & T & \textbf{T} & T&&T \\
	\cline{1-7}
	T & F & F & F & T & \textbf{T} & T&&T \\
	\cline{1-7}
	T & F & T & F & T & \textbf{T} & T&&T \\
	\cline{1-7}
	T & T & F & T & F & \textbf{F} & T&&F \\
	\cline{1-7}
	T & T & T & T & T & \textbf{T} & T&&T \\
	\cline{1-7}
\end{tabular}}
\end{center}
So $\varphi$ in disjunctive normal form is equivalent to:
$$(\lnot a \land b \land \lnot c)\lor (\lnot a \land b \land c)\lor (a \land \lnot b \land \lnot c)\lor (a \land \lnot b \land c)\lor (a \land b \land c)$$
So the cnf of $\lnot \psi$ is
$$(a \lor \lnot b \lor c)\land ( a \lor \lnot b \lor \lnot c)\land (\lnot a \lor  b \lor  c)\land (\lnot a \lor b \lor \lnot c)\land (\lnot a \lor \lnot b \lor \lnot c)$$

\item \textit{Is the set $\{\land,\oplus\}$, where $p\oplus q \equiv \lnot(p\Leftrightarrow q)$, functionally complete?} \hfill [5 marks]\\

Suppose that $\{\land,\oplus \}$ is functionally complete. If it is functionally complete, then there is a formula using only $\{\land,\oplus\}$ such that
$$\varphi\equiv\lnot p$$
$p\land p$ is false if p is false\\
$p\oplus p$ is false if p is false\\
\\
Hence $\varphi$ cannot exist, so the set is not functionally complete

\item \textit{Prove the following sequents using natural deduction. In your proofs you may (only) use the rules $\land i, \land e1, \land e2, \lnot \lnot i, \lnot\lnot e\\, \Rightarrow e, \Rightarrow i, \lor i1, \lor i2, \lor e, \bot e, \lnot e, \lnot i$ and the Law of the Excluded Middle. At each step mention the rule you have applied. You may write $\lor i$ for $\lor i1$ and $\lor i2$. Similarly, you may write $\land e$ for $\land e1$ and $\land e2$}
\begin{enumerate}
\item $\lnot a\land b\land (a\lor(b\Rightarrow c))\vdash c\lor d$ \hfill [10 marks]

\item $a\lor(\lnot b\land \lnot c\land \lnot d)\vdash (a\lor b)\land (a\lor \lnot c)\land (a\lor \lnot d)$ \hfill [10 marks]
\end{enumerate}
(a)
\[
\Jproof{
	\proofline{\lnot a \land b \land (a\lor (b\Rightarrow c))}{Premise}
	\proofline{\lnot a}{$\land$ e (1)}
	\proofline{\lnot b}{$\land$ e (1)}
	\proofline{\lnot a\lor(b\Rightarrow c)}{$\land$ e (1)}
	\cablk{
		\proofline{a}{Assumption}
		\proofline{\bot}{$\lnot$ e (2) (5)}
		\proofline{b\Rightarrow c}{$\bot$ e (6)}
	}
	\cablk{
		\proofline{b\Rightarrow c}{Assumption}
		\proofline{b\Rightarrow c}{copy (8)}
	}
	\proofline{b\Rightarrow c}{$\lor$ e (4) (5-7)(8-9)}
	\proofline{c}{$\Rightarrow$ e (3) (10)}
	\proofline{c\lor d}{$\lor$ i (11)}
}
\]
(b)
\[
\Jproof{
	\proofline{a\lor (\lnot b\land \lnot c\land \lnot d)}{Premise}
	\cablk{
		\proofline{a}{Assumption}
		\proofline{a\lor \lnot b}{$\lor$ i (2)}
	}
	\cablk{
		\proofline{\lnot b\land \lnot c\land \lnot d}{Assumption}
		\proofline{\lnot b}{$\land$ e (4)}
		\proofline{a\lor \lnot b}{$\lor$ i (5)}
	}
	\proofline{a\lor \lnot b}{$\lor$ e (1) (2-3) (4-6)}
	\cablk{
		\proofline{a}{Assumption}
		\proofline{a\lor \lnot c}{$\lor$ i (8)}
	}
	\cablk{
		\proofline{\lnot b\land \lnot c\land \lnot d}{Assumption}
		\proofline{\lnot c}{$\land$ e (10)}
		\proofline{a\lor \lnot c}{$\lor$ i (11)}
	}
	\proofline{a\lor \lnot c}{$\lor$ e (1) (8-9) (10-12)}
	\cablk{
		\proofline{a}{Assumption}
		\proofline{a\lor \lnot d}{$\lor$ i (14)}
	}
	\cablk{
		\proofline{\lnot b\land \lnot c\land \lnot d}{Assumption}
		\proofline{\lnot d}{$\land$ e (16)}
		\proofline{a\lor \lnot d}{$\lor$ i (17)}
	}
	\proofline{a\lor \lnot d}{$\lor$ e (1) (14-15) (16-18)}
	\proofline{(a\lor\lnot b)\land (a\lor \lnot c)}{$\land$ i (7)(13)}
	\proofline{(a\lor\lnot b)\land(a\lor \lnot c)\land (a\lor \lnot d)}{$\land$ i (19) (20)}
}
\]

\newpage
\item L\textit{et $\varphi$ be the formula $\neg ( a \land ( \neg a \lor \neg b ) \land ( b \lor c ) \land ( \neg c \lor \neg d \lor e ) \land ( e \lor d ) \land ( \neg e \lor \neg c ) )$. Is $\varphi$ a theorem? Use resolution to answer this question. Mention on which clauses you use resolution each time you apply it} \hfill [10 marks]
$$Let \ \varphi = \neg ( a \land ( \neg a \lor \neg b ) \land ( b \lor c ) \land ( \neg c \lor \neg d \lor e ) \land ( e \lor d ) \land ( \neg e \lor \neg c ) )$$
$$Therefore \ \lnot \varphi =  a \land ( \neg a \lor \neg b ) \land ( b \lor c ) \land ( \neg c \lor \neg d \lor e ) \land ( e \lor d ) \land ( \neg e \lor \neg c ) $$
So the set of clauses to which we apply resolution is:
$$a \qquad \lnot a \lor \lnot b \qquad b\lor c \qquad \lnot c\lor \lnot d \lor e \qquad e\lor d \qquad \lnot e\lor\lnot c$$
\begin{enumerate}[label=(\arabic*)]
	\item a
	\item $\lnot a \lor \lnot b$
	\item $b\lor c$
	\item $\lnot c \lor \lnot d \lor e$
	\item $e\lor d$
	\item $\lnot e\lor \lnot c$
	\item $\lnot b \qquad$ \hfill(1,2)
	\item $c\qquad$ \hfill (3,7)
	\item $\lnot d\lor e\qquad$ \hfill (4,8)
	\item $e\lor e$ \hfill (5,9)
	\item $e\qquad$ \hfill (10)
	\item $\lnot c$ \hfill (6,11)
	\item $\varnothing$ \hfill (8,12)
\end{enumerate}
This results in the empty set, so $\varphi$ is a theorem

\end{enumerate}
\newpage
\bibliographystyle{unsrt}
\bibliography{bibliography}
\end{document}


\chapter{Moment Method Formulation}
\label{chap:mom}
In this chapter we describe a procedure for determining
the induced electric or magnetic surface currents on a single-sheet FSS
(frequency selective surface) located at one of the junction planes in
a multiply stratified medium, when excited by an incident plane wave.
The analysis is performed using the method of moments, employing
a space-domain formulation of the potential Green's functions,
which are  described in previous chapters.
Once the equivalent induced
surface currents have been determined, the single-sheet scattering
parameters can be extracted using the formulas presented in
Chapter~\ref{chap:incgsm}.  Scattering parameters of more complicated structures
consisting of several cascaded FSS sheets interlaced with dielectric
layers can be determined from the individual sheet scattering parameters using
the results of Chapter~\ref{chap:gsm}.
%
The following novel features are incorporated in this analysis:
\begin{itemize}
\item The use of a wide-band expansion of the stratified medium
  periodic Green's functions has been incorporated into the moment
  method procedure, greatly reducing the time needed to compute the
  elements of the interaction matrices.  This technique was first
  reported in \cite{simo:01b}.
\item Modifications have been introduced into the triangle subdomain
  basis functions  of Rao, Wilton, and Glisson \cite{rawg:82} to
  enable representation of currents that cross unit cell boundaries.
  This work was previously reported in \cite{simo:02c}.
\end{itemize}
%
%
\begin{figure}[tbhp]
  \begin{center} \footnotesize
    \leavevmode
    \pspicture(1,4.2)(12.9,10)
    \psset{nodesep=2.5pt}
                                % Begin Input Medium:
    \rput(1.5,7){\cstack{Layer \\1 \\ $(\mu_1,\epsilon_1)$}}
    \psline[linewidth=1pt](2.3,4.5)(2.3,8.5)  \uput[d](2.3,4.5){$z_1$}
    \pnode(2.3,8.5){Junction1}
    \rput[b](1.8,9.5){\rnode{Junction1label}{Junction~1}}
    \ncline[linewidth=0.5pt]{->}{Junction1label}{Junction1}
                                % Begin Layer 2:
    \rput(3.15,7){\cstack{Layer \\ 2 \\ $(\mu_2,\epsilon_2)$}}
    \psline[linewidth=1pt](4,4.5)(4,8.5)    \uput[d](4,4.5){$z_2$}
    \pnode(4,8.5){Junction2}
    \rput[b](4,9.5){\rnode{Junction2label}{Junction 2}}
    \ncline[linewidth=0.5pt]{->}{Junction2label}{Junction2}
    \pcline[linewidth=0.5pt,nodesep=1pt]{<->}(2.3,5.5)(4,5.5) \lput*{:U}{$h^{(2)}$}
                                % Begin Layer 3:
    \rput(5,7){\cstack{Layer \\ 3 \\ $(\mu_3,\epsilon_3)$}}
    \psline[linewidth=1pt](6,4.5)(6,8.5)    \uput[d](6,4.5){$z_3$}
    \pnode(6,8.5){Junction3}
    \rput[b](5.5,9){\rnode{Junction3label}{Junction 3}}
    \ncline[linewidth=0.5pt]{->}{Junction3label}{Junction3}
    \pcline[linewidth=0.5pt,nodesep=1pt]{<->}(4,5.5)(6,5.5) \lput*{:U}{$h^{(3)}$}
                                % Ellipses:
    \rput(6.5,6.5){\large$\boldsymbol{\cdots}$}
                                % Begin junction N-3:
    \psline[linewidth=1pt](7,4.5)(7,8.5)    \uput[d](7,4.5){$z_{N-3}$}
    \pnode(7,8.5){JunctionNsm2}
    \rput[b](6.5,9.5){\rnode{JunctionNsm2label}{Junction $N-3$}}
    \ncline[linewidth=0.5pt]{->}{JunctionNsm2label}{JunctionNsm2}
                                % Begin Layer N-2:
    \rput(8.125,7){\cstack{Layer \\ $N-2$ \\ $(\mu_{N-2},\epsilon_{N-2})$}}
    \psline[linewidth=1pt](9.25,4.5)(9.25,8.5)    \uput[d](9.25,4.5){$z_{N-2}$}
    \pnode(9.25,8.5){JunctionNsm1}
    \rput[b](9.25,9){\rnode{JunctionNsm1label}{Junction $N-2$}}
    \ncline[linewidth=0.5pt]{->}{JunctionNsm1label}{JunctionNsm1}
    \pcline[linewidth=0.5pt,nodesep=1pt]{<->}(7,5.5)(9.25,5.5) \lput*{:U}{$h^{(N-2)}$}
                                % Begin Layer N-1:
    \rput(10.375,7){\cstack{Layer \\ $N-1$ \\ $(\mu_{N-1},\epsilon_{N-1})$}}
    \psline[linewidth=1pt](11.5,4.5)(11.5,8.5)    \uput[d](11.5,4.5){$z_{N-1}$}
    \pnode(11.5,8.5){JunctionNs}
    \rput[b](11.5,9.5){\rnode{JunctionNslabel}{Junction $N-1$}}
    \ncline[linewidth=0.5pt]{->}{JunctionNslabel}{JunctionNs}
    \pcline[linewidth=0.5pt,nodesep=1pt]{<->}(9.25,5.5)(11.5,5.5) \lput*{:U}{$h^{(N-1)}$}
                                % Begin Output Medium:
    \rput(12.4,7){\cstack{Layer \\ $N$ \\ $(\mu_{N},\epsilon_{N})$}}
    \endpspicture
  \end{center}
  \caption{The structure under consideration is a stack of $N \geq 2$
    dielectric layers.  Layers~1 and $N$ are semi-infinite in extent.
    For $2 \leq i \leq N-1$, layer~$i$ lies in the region $z_{i-1} < z
    < z_i$, is of thickness $h\eye = z_i - z_{i-1}$, and is characterized by
    permeability $\mu_i$ and permittivity $\epsilon_i$.}
  \label{fig:geom4}
\end{figure}
%

The FSS is located in the interface plane $z=z_s$ of the multiple
layered structure shown in Figure~\ref{fig:geom4}.
The structure is laterally invariant, with each dielectric layer being
homogeneous and isotropic.
Each layer $i=1,2, \ldots, N$ is characterized by a complex
permittivity $\epsilon_i$ and permeability $\mu_i$, each of which lies
either in the fourth quadrant of the complex plane, or on the real axis.  The
medium intrinsic wavenumbers are $k_i = \omega\sqrt{\mu_i\epsilon_i}$.
We will assume that the single FSS sheet is located at interface
number $s$, located between layers $s$ and $s+1$, where $1 \leq s < N.$

In general, we can model a zero-thickness, perfectly conducting FSS
using either electric or magnetic currents as the unknowns.  In the
former case, the metalization is removed, and the support\footnote{%
  The support of a function is defined as the closure of the set of
  points where the function takes nonzero values.}%
of the unknown electric
surface current consists of the region previously occupied by the
metalization.  In the latter case, the entire interface plane $z=0$ is
replaced with a zero-thickness PEC (perfect electric conductor) and
the support of the magnetic current is the portion of the plane
formerly {\em not} occupied by the PEC.

One generally chooses the type of equivalent currents employed in a
given problem so as to minimize the area of the currents' support, and
thus the number of unknowns to be solved for in the MoM problem.
For aperture-type elements magnetic currents are usually
selected; for wire-type elements electric currents are the natural choice.
In the case where an FSS is constructed of lossy material, we are forced
to use electric currents as the unknowns.

\section{Electric Current Mixed Potential Integral Equation}
In this section we consider an FSS that is modeled using equivalent
electric surface current.  This choice is convenient when less than
half of the unit cell area is occupied by metal or when the FSS is
etched onto a sheet of lossy material.

The boundary value problem to be solved is \cite{mitz:68}
\begin{equation}
  Z_s(\vecrho) \Js(\vecrho)  -\Idemfactor_z \bdot \E\scat(\vecrho) =
  \Idemfactor_z \bdot \E\inc(\vecrho), \quad (\vecrho \in S)
  \label{eq:EFIE}
\end{equation}
where $\E\scat$ is the scattered electric field due to the equivalent
currents flowing
on the surface $S$ of the FSS, $\E\inc$ is the incident electric field
(the plane wave, including incident, reflected, and transmitted
components, that would exist in the absence of the FSS), $Z_s$ is the
surface resistance of the FSS sheet material,
and $\Idemfactor_z = \x\x + \y\y$ is the unit surface dyadic.  In
terms of potentials this becomes
\begin{equation}
  Z_s(\vecrho) \Js(\vecrho) + [j\omega \A(\vecrho) +
  \gradient\Phi(\vecrho)] \bdot \Idemfactor_z =
  \E\inc(\vecrho) \bdot \Idemfactor_z, \quad (\vecrho \in S)
  \label{eq:MPIE}
\end{equation}
where the potentials can be expressed as superposition integrals
using appropriately defined Green's functions
(Chapter~\ref{chap:gfstratified})
$\GAxx$ and $\GPhi$:
\begin{gather}
  \Idemfactor_z \bdot \A(\vecrho) =
  \iint \GAxx(\vecrho-\vecrho') \cdot \Js(\vecrho') \, \d S',
  \label{eq:Asup}\\
  \Phi(\vecrho) = \iint \GPhi(\vecrho-\vecrho') \cdot \qe(\vecrho') \, \d S'.
  \label{eq:Phisup}
\end{gather}
In \eqref{eq:Asup} and \eqref{eq:Phisup}, $\Js$ and $\qe$ are the unknown
induced electric surface current and surface charge densities,
respectively, which will be determined
by enforcing
Equation~\eqref{eq:MPIE} in an approximate manner using the method of
moments.  We use the triangle subdomain basis functions of Rao, Wilton and
Glisson \cite{rawg:82}, suitably modified so as to accommodate the
periodic boundary conditions encountered in the unit cell analysis.

\subsection{Basis Functions}
\label{sec:bf}
We now enunciate a few important definitions and
and properties of the basis functions in order to establish
notation.
The support of $\Js$ is first partitioned into a number of triangles.
In \cite{rawg:82} a basis function is defined over each pair of triangles which share a common
edge.  In this work, we include not only these adjacent pairs of
triangles, but also those pairs of triangles which would be adjacent
if one of the pair were translated by $\s_1$ or $\s_2$ from its actual
position.

Consider first a typical pair of adjacent triangles; their common edge
is not on the boundary of the unit cell.
Figure~\ref{fig:basis} shows two such triangles, $T_m^+$ and $T_m^-$,
which comprise the support of the $m$th basis function and which
share an interior edge of the triangulated surface.  Points in $T_m^+$ may be designated
by either the position vector $\r$ which locates them with respect to the global
origin, or by $\vecrho_m^+$, which is defined with respect to the free vertex
of $T_m^+$.  The vector $\vecrho_m^-$ is defined similarly for points in $T_m^-$,
except that it is directed {\em towards} the free vertex of $T_m^-$.
Which of the two triangles is designated ``plus'' and which is ``minus'' depends
on an arbitrary choice of positive current reference direction for the
$m$th basis function.
Positive reference current flows across the edge from $T_m^+$ to $T_m^-$. The basis
function associated with the $m$th edge is then defined as
\begin{equation}
  \label{eq:basis}
  \f_m(\r) =
  \begin{cases}
    \displaystyle
    \frac{l_m e^{j\theta_m^+}}{2A_m^+} \vecrho_m^+ & \text{if $\r \in T_m^+$} \\
    \displaystyle
    \frac{\rule{0pt}{3ex}l_m e^{j\theta_m^-}}{2A_m^-} \vecrho_m^- & \text{if $\r \in T_m^-$} \\
    \0 & \text{otherwise},
  \end{cases}
\end{equation}
where $l_m$ is the length of the common edge, $A_m^{\pm}$ is the area
of triangle $T_m^{\pm}$, and $\theta_m^+ = \theta_m^- = 0$ in this case.
%
\begin{figure}[tbp]
  \begin{center}
    \leavevmode
      \pspicture(-5,-2)(5,5)
      % Begin by defining locations of triangle vertices as PStricks nodes:
      \pnode(-5,0){Pfree}  % The free node of the plus triangle.
      \pnode(4.5,2){Mfree}  % The free node of the plus triangle.
      \pnode(1,4.5){Top}     % The top node of the common edge.
      \pnode(1,0){Bot}     % The bottom node of the common edge.
      \rput(0.5,-2){\rnode{Origin}{$\bullet$}} % The coordinate system origin.
      \rput[l](0.5,-2){\quad Origin}
        \psset{linewidth=1.3pt}   % For triangle legs
       \psset{arrowsize=6pt,arrowinset=0.5,arrowlength=2.5}
        \ncline{Pfree}{Bot}     % BL triangle leg
        \mput{\rnode{BLEdgeCenter}{}}  % Put node at center of bottom left edge.
        \ncline{Pfree}{Top}     % TL triangle leg
        \aput(0.5){$T_m^+$}
        \ncline{Mfree}{Bot}     % BR triangle edge
        \ncline{Mfree}{Top}     % TR triangle edge
        \bput(0.5){$T_m^-$}
        \ncline{Top}{Bot}       % Common triangle edge
        \mput{\rnode{CommonEdgeCenter}{}}  % Put node at center of common edge.
        \psset{linestyle=none}   % Don't want to see the next few lines.
        \ncline{Pfree}{CommonEdgeCenter}
        \lput(0.6667){\rnode{Pcentroid}{\Large$\bullet$}}  % Positive triangle centroid
        \ncline{Mfree}{CommonEdgeCenter}
        \lput(0.6667){\rnode{Mcentroid}{\Large$\bullet$}}  % Negative triangle centroid
        \ncline{Pcentroid}{BLEdgeCenter}
        \lput(0.4){\rnode{ObsPoint}{\Large$\bullet$}}  % Observation point location.
        %
        \psset{linestyle=solid,linewidth=1pt,nodesepA=0pt,nodesepB=0pt}
        \ncline{->}{Pfree}{Pcentroid}  \aput[1pt](0.7){$\vecrhocp_m$}
        \ncline{->}{Pfree}{ObsPoint}  \bput[1pt](0.7){$\vecrho^+_m$}
        \ncline{->}{Mcentroid}{Mfree}  \aput[2pt](0.5){$\vecrhocm_m$}
                                %
        \ncline{->}{Origin}{Pcentroid}  \bput[1pt](0.4){$\rcp_m$}
        \ncline{->}{Origin}{Mcentroid}  \bput[1pt](0.3){$\rcm_m$}
        \ncline{->}{Origin}{ObsPoint}   \aput(0.5){$\r$}
        \ncline[arrowsize=3pt 2,arrowinset=0.5,arrowlength=2,%
        linewidth=0.6pt,offset=10pt,nodesep=1pt]{<->}{Bot}{Top}
        \ncline[linewidth=0.6pt,offset=10pt,nodesep=0pt]{|-|}{Bot}{Top} \lput*{:U}{$l_m$}
      \endpspicture
    \caption{Triangular basis function geometry showing two triangles with
      a common edge.  The superscript ``c'' denotes the centroid of the triangle.}
    \label{fig:basis}
  \end{center}
\end{figure}
%
A few facts about the basis functions should be kept in mind.  First,
the basis functions are unitless.  Units are carried by the expansion
coefficients associated with the basis functions.  Second,
the
support of a single basis function is limited to two, typically adjacent triangles.
Third, the total current density in any given triangle is the vector sum
of contributions from up to three distinct basis functions whose common support
includes that triangle.  Fourth, any current flow normal to an edge is due
entirely to the basis function associated with that edge.  Finally, the
basis functions are normalized so that the normal component of current
density crossing the defining edge is unity%
%
\footnote{It is easy to see that the normal current density crossing
  an edge is constant by
recalling that the equation of a plane in space is $\n \bdot \r = \text{constant}$.
Similarly, the equation of the line containing the defining edge for the $m$th
basis function is $\n \bdot \vecrho_m^{\pm} = \text{constant}$.  In fact, the
normalization for the basis functions is selected so that this constant is
unity in magnitude.}
%
at any point of the edge.
This means that the expansion
coefficients $\{\Icoef_m\}$ defined below can be interpreted as the
total current
crossing the associated edge(s) of the triangulated surface.

This definition is identical to that of \cite{rawg:82} except for the
introduction of the factors containing $\theta_n^\pm$.  To see why
these are necessary, consider the situation shown in
Figure~\ref{fig:basis2}.  Points within the unit cell are
parameterized using
\begin{equation}
  \vecrho = \xi \s_1 + \eta \s_2, \quad 0 \leq \xi < 1, \; 0 \leq \eta
  < 1.
\end{equation}
%
\begin{figure}[tbp]
  \begin{center}
    \leavevmode
      \psset{unit=0.3in,linewidth=0.8pt}
      \pspicture(0,0)(10,10)
      % Begin by defining locations of triangle vertices as PStricks nodes:
      \pnode(0,0){Origin}  % The origin is at the lower left corner
      \pnode(9,3){S1}
      \pnode(1,7){S2}
      \pnode(10,10){S1plusS2}
      \pnode(2,3){TplusC}  % Third node of plus triangle
      \pnode(6.5,4){TminusC}  % Third node of plus triangle
      %  Now draw vectors bounding the unit cell:
      \ncline[arrowsize=6pt,arrowinset=0.5,arrowlength=2.5]{->}{Origin}{S1}
      \bput(0.99){$\s_1$}  \bput{:U}(0.5){$\eta = 0$}
      \ncline[arrowsize=6pt,arrowinset=0.5,arrowlength=2.5]{->}{Origin}{S2}
      \aput(0.99){$\s_2$} \aput{:U}(0.6){$\xi = 0$}
      \lput(0.1){\rnode{TplusA}{}}  % Define first node of plus triangle
      \lput(0.4){\rnode{TplusB}{}}  % Define second node of plus triangle
      \ncline{S1}{S1plusS2}
      \bput{:U}(0.6){$\xi = 1$}
      \lput(0.1){\rnode{TminusA}{}}  % Define first node of minus triangle
      \lput(0.4){\rnode{TminusB}{}}  % Define second node of minus triangle
      \ncline{S2}{S1plusS2}
       \aput{:U}(0.5){$\eta = 1$}
       %
       %  Draw the ``plus'' triangle at xi = 0:
       {\psset{linewidth=1.5pt}
         \ncline{TplusA}{TplusB} \ncline{TplusB}{TplusC}
         \ncline{TplusC}{TplusA} }
       \aput[1pt](0.3){$T_m^+$}
       %  Draw the ``minus'' triangle at xi = 1:
       {\psset{linewidth=1.5pt}
       \ncline{TminusA}{TminusB} \ncline{TminusB}{TminusC} \ncline{TminusC}{TminusA} }
       \bput[1pt](0.2){$T_m^-$}
       % Draw the constant eta lines bounding the triangle edges at
       % the unit cell boundaries:
       \ncline[linestyle=dashed]{TplusA}{TminusA}
       \aput{:U}{$\eta=\eta_1$}
       \ncline[linestyle=dashed]{TplusB}{TminusB}
       \aput{:U}{$\eta=\eta_2$}
       % Draw the dimensioning line at xi = 0:
       \ncline[arrowsize=3pt 2,arrowinset=0.5,arrowlength=2,%
        linewidth=0.6pt,offset=9pt,nodesep=1pt]{<->}{TplusA}{TplusB}
        \ncline[linewidth=0.6pt,offset=9pt,nodesep=0pt]{|-|}{TplusA}{TplusB}
        \lput*{:U}{$l_m$}
       % Draw the dimensioning line at xi = 1:
       \ncline[arrowsize=3pt 2,arrowinset=0.5,arrowlength=2,%
        linewidth=0.6pt,offset=-9pt,nodesep=1pt]{<->}{TminusA}{TminusB}
        \ncline[linewidth=0.6pt,offset=-9pt,nodesep=0pt]{|-|}{TminusA}{TminusB}
        \lput*{:U}{$l_m$}
      \endpspicture
    \caption{Triangular basis function geometry showing a pair of triangles
      located at the $\xi = \text{constant}$ unit cell boundaries.}
    \label{fig:basis2}
  \end{center}
\end{figure}
%
Unit cell boundaries are located at $\xi = 0$, $\xi = 1$, $\eta = 0$,
and $\eta = 1$.  In order to preserve the periodicity of the computed
currents we agree to triangulate the unit cell in such a way
that the number and location of the resulting edges along the $\xi = 0$ and $\xi
= 1$ boundaries are identical, and similarly for the $\eta = 0$ and $\eta
= 1$ boundaries.  A pair of triangles $T_m^+$ and $T_m^-$ with
edges at the $\xi=0$ and
$\xi=1$ boundaries, respectively, are shown in the figure.
These edges both span the same range of $\eta$ and so are parallel and
congruent. A basis function is defined for each such pair of triangles
on the $\xi = \text{constant}$ or $\eta = \text{constant}$ boundaries.
We focus attention upon the basis function $\f_m$ whose support is
the union of the two triangle faces shown in the figure.
Because of the boundary condition
\begin{equation}
  V(\r + m\s_1 + n\s_2) = V(\r) e^{-j(m\psi_1 + n \psi_2)}, \quad
  \forall m,n \in \Integers
\end{equation}
enforced on all currents and fields in the unit cell,
it must be true that the normal current density crossing the edge at $\xi=1$
is equal to that crossing the $\xi=0$ edge multiplied by the factor
$e^{-j\psi_1}$.  Therefore, we must insist that
\begin{equation}
  \theta_m^- = \theta_m^+ - \psi_1.
\end{equation}
We will establish the convention that $\theta_m^\pm = 0$ for all edges
except those along the $\xi=1$ and $\eta=1$ unit cell boundaries.  Therefore, for
the situation shown in Figure~\ref{fig:basis2} we have $\theta_m^- =
-\psi_1$ and similarly for all other triangles with one edge located
on the $\xi = 1$ boundary.  For triangles with an edge on the $\eta=1$
boundary we set the corresponding phase to $-\psi_2$.

We now expand the unknown electric surface current density in a series of these basis
functions:
\begin{equation}
  \label{eq:Jexpand}
  \Js(\vecrho) =  \sum_{n=1}^{N_J} \frac{\Icoef_n}{l_n} \f_n(\vecrho).
\end{equation}
The number of basis functions
$N_J$ is equal to the number of interior edges of the triangulated surface in the
$z=0$ plane of the unit cell plus the number of edges along the $\xi=0$ and $\eta=0$
borders of the unit cell.  Note that $\Icoef_n$ has units of \si{A}.

\subsection{Impedance Matrix}
\subsubsection{Reduction to Matrix Equation}
Having expanded the unknown current in a series of suitable basis functions,
it is now desired to determine the coefficients in a way that satisfies
Equation~\eqref{eq:MPIE} as closely as possible.
The method of moments transforms the functional Equation~\eqref{eq:MPIE}
to a matrix equation by enforcing it in an average manner.
This is accomplished by first defining an inner product which maps a pair of
functions to a single complex number, and then repeatedly
{\em testing\/} the equation by taking the inner product of both sides with a
number of {\em testing\/} or {\em weighting\/} functions.

The inner product used in testing Equation~\eqref{eq:MPIE} is
\begin{equation}
  \innerprod{\f, \boldsymbol{g}} = \iint \f \bdot \boldsymbol{g}^* \; \d S.
\end{equation}
The asterisk denotes complex conjugation and the integration is performed over
the portion of the $z=0$ plane containing the common support of the two
functions $\f$ and $\boldsymbol{g}$.
We choose our testing functions to be the same as our basis functions
(Galerkin's method).  Then taking the inner product of \eqref{eq:MPIE}
with each of the functions $\f_m/l_m$  for $m = 1,2,\ldots, N_J$ yields
\begin{multline}
  j\omega \innerprod{\A,\f_m/l_m} + \innerprod{\gradient\Phi,\f_m/l_m}
  + \innerprod{Z_s \Js, \f_m/l_m}
          = \innerprod{\E\inc, \f_m/l_m}, \\
      m = 1, 2, \ldots,  N_J.   \label{eq:Emom}
\end{multline}
Following \cite{rawg:82} we can approximate the second term of
\eqref{eq:Emom} by
\begin{equation}
  \innerprod{\gradient\Phi, \f_m/l_m} \approx
         e^{-j\theta_m^-} \Phi(\rcm_m) - e^{-j\theta_m^+} \Phi(\rcp_m)  \label{eq:Phimom}
\end{equation}
where $\rcpm_m$ is the centroid of triangle $T_m^{\pm}$. The first
term is also approximated as in the reference:
\begin{equation}
  \innerprod{\A, \f_m/l_m} \approx \frac{1}{2}
      \left[ \A(\rcp_m) \bdot \vecrhocp_m e^{-j\theta_m^+} +
             \A(\rcm_m) \bdot \vecrhocm_m  e^{-j\theta_m^-}
      \right].      \label{eq:Amom}
\end{equation}
$\vecrhocpm_m$ is the vector $\vecrho_m^{\pm}$ evaluated at the centroid
of the corresponding triangle.

Substituting the expansion of the current \eqref{eq:Jexpand} into \eqref{eq:Emom}
yields the desired matrix equation.
\begin{equation}
  \mat{Z} \mat{I} =  \mat{V},  \label{eq:matrix}
\end{equation}
where $\mat{Z} = [\matel{Z}_{mn}]$ is the so-called {\em generalized impedance
matrix}, a square matrix of order $N_J$ with units of \si{\ohm}.
$\mat{I} = [\Icoef_m]$ is the column matrix of unknown current
coefficients with units of $\si{A}$.
$\mat{V}= [\matel{V}_m]$ is the excitation vector (or {\em generalized
voltage vector}) with units of $\si{V}$.
The elements of the generalized impedance matrix are
\begin{multline}
  \matel{Z}_{mn} =
  \innerprod{Z_s \f_n/l_n,\f_m/l_m}
   \\
   \mbox{} + j \omega \left(
    \A_{mn}^+ \bdot \frac{\vecrhocp_m}{2} e^{-j\theta_m^+}
    +
    \A_{mn}^- \bdot \frac{\vecrhocm_m}{2} e^{-j\theta_m^-}
  \right)
  + \Phi_{mn}^- e^{-j\theta_m^-} - \Phi_{mn}^+ e^{-j\theta_m^+}
\end{multline}
where
\begin{align}
  \A_{mn}^{\pm} & \equiv
  \frac{1}{l_n} \iint
  \GAxx(\rcpm_m;\r') \, \f_n(\r') \; \d S'  \notag \\
  &=
    \frac{e^{j\theta_n^+}}{2A_n^+} \iint_{T_n^+}  \!\!\!
    \GAxx(\rcpm_m;\r') \, \vecrho_n^+ \; \d S'
    +
    \frac{e^{j\theta_n^-}}{2A_n^-} \iint_{T_n^-}  \!\!\!
    \GAxx(\rcpm_m;\r')  \, \vecrho_n^- \; \d S'
    \label{eq:Amnpm}
\end{align}
and
\begin{align}
  \Phi_{mn}^{\pm} &\equiv \frac{j}{\omega l_n} \iint
  \GPhi(\rcpm_m;\r')
  \gradient'_s \bdot \f_n(\r')
  \; \d S'
  \notag \\
  &= \frac{j}{\omega}
  \left[
    \frac{e^{j\theta_n^+}}{A_n^+} \iint_{T_n^+}  \!\!\!
    \GPhi(\rcpm_m;\r') \; \d S'
    -
    \frac{e^{j\theta_n^-}}{A_n^-} \iint_{T_n^-}{}  \!\!\!
    \GPhi(\rcpm_m;\r') \; \d S'
  \right]    \label{eq:Phimnpm}
\end{align}
and we have used the fact \cite{rawg:82} that
\begin{equation}
  \gradient_s \bdot \f_n(\r) =
  \begin{cases}
    \displaystyle  \frac{l_n}{A_n^+} e^{j\theta_n^+}  & \text{if $\r \in T_n^+$} \\
    \displaystyle \frac{\rule{0pt}{2ex}-l_n}{A_n^-}
    e^{j\theta_n^-} & \text{if $\r \in T_n^-$} \\
    0                               & \text{otherwise}
  \end{cases}
  \label{eq:fdiv}
\end{equation}
which holds true for a basis function consisting of a pair of adjacent
triangles.  For basis functions defined on nonadjacent pairs, the
expression for the surface divergence includes a pair of line
singularities whose contributions to \eqref{eq:Phimnpm} can be
shown to cancel.

 \subsubsection{Efficient Evaluation of the Generalized Impedance Matrix}
 The authors of \cite{rawg:82} discuss the way in which redundant calculations can
 be avoided by considering face-pair contributions to $\mat{Z}$ rather than the
 edge-pair contributions used in the definitions of \eqref{eq:Amnpm} and
 \eqref{eq:Phimnpm}.  Here we apply the same technique using our
 potential Green's functions specific to this problem.  In addition,
 we individually track the contributions to the impedance matrix
 exhibiting distinct frequency dependence, thus allowing a
 wide-band implementation.

 \paragraph{Vector Potential Contributions}

 Consider first a typical vector integral needed
 to evaluate $\matel{Z}_{mn}$.
 The quantity
 \begin{equation}
   \A_i^{uv} =   \frac{e^{j\theta_i^\pm}}{2A^v}  \iint_{T^v}  \!\!\!
           \GAxx(\rcu;\r') \, \vecrho_i \; \d S' \label{eq:Aiuv}
 \end{equation}
 represents the magnetic vector potential at the centroid $\rcu$ of triangle
 $T^u$ due to the $i\text{th}$ basis function defined on triangle $T^v$.
 In \eqref{eq:Aiuv} we have temporarily assumed a local numbering scheme
 on the source triangle, with vertices at $\r_1$, $\r_2$, and $\r_3$,
 and where
 \begin{equation}
   \vecrho_i =  \pm (\r' - \r_i), \quad i = 1, 2, 3.
   \label{eq:vecrhosubi}
 \end{equation}
 The plus sign is selected in \eqref{eq:Aiuv} and \eqref{eq:vecrhosubi}
 if the associated basis function defines
 positive current to flow {\em out\/} through the $i\text{th}$ edge of
 the triangle, which lies opposite the $i$th vertex.
 Using the expressions for the magnetic vector potential Green's
 function given in  Chapter~\ref{chap:gfstratified}, Equation~\eqref{eq:Aiuv} can
 be written as  the sum of a frequency dependent term arising from the modal
 difference series, added to several contributions arising from the
 spatial series:
 \begin{equation}
   \A_i^{uv} = \frac{\tilde{\mu}}{4\pi} e^{j\theta^{\pm}_i}
   \left[
     4\pi \I_{1i}^{uv}%(\mu_1,\epsilon_1,\mu_2,\epsilon_2)
     +
     \frac{1}{2A^v}  \iint_{T^v}  \!
     \frac{\vecrho_i}{\rhocu_{00}} \, \d S' +
     u \J_i^{uv} +
     \frac{c_3(\scriptstyle\mu_s,\epsilon_s,\mu_{s+1},\epsilon_{s+1})}%
     {u} \K_i^{uv}
   \right] \label{eq:Aiuv2}
 \end{equation}
 where
 \begin{subequations}
   \begin{align}
     \I_{1i}^{uv} &=
     \frac{1}{2A^v}  \iint_{T^v}  \!\!\!
     \Sigma_{M1}(\rcu;\r')
     \, \vecrho_i \; \d S', \\
     %
     \Sigma_{M1}(\rcu;\r') &=
     \frac{1}{2A} \summn
     \left[
       \frac{2\Vi\TE(\vecbeta_{mn},z_s,z_s)}{j\omega\tilde{\mu}}
       - \frac{1}{\kappa_{mn}} -
       \frac{c_3({\scriptstyle\mu_s,\epsilon_s,\mu_{s+1},\epsilon_{s+1}})}%
       {\kappa_{mn}^3}
     \right] e^{-j\vecbeta_{mn}\bdot(\rcu-\r')}, \\
                                %
     \J_i^{uv} &=
     \frac{1}{2A^v}  \iint_{T^v}  \!\!\!
     \vecrho_i \,
     \summn  \frac{e^{-u\rhocu_{mn}}-\delta_{m0}\delta_{n0}}{u\rhocu_{mn}}
     e^{-j(m\psi_1+n\psi_2)} \; \d S', \\
                                %
     \K_i^{uv} &=
     \frac{1}{2A^v}  \iint_{T^v}  \!\!\!
     \vecrho_i \,
     \summn  e^{-u\rhocu_{mn}}
     e^{-j(m\psi_1+n\psi_2)} \; \d S',
   \end{align}
 \end{subequations}
 and $\rhocu_{mn} = \norm{\rcu  - \r' - m\s_1 -n\s_2}$.  Note that the
 only frequency dependence in \eqref{eq:Aiuv2} occurs in the terms
 $\I_{1i}^{uv}$ and $c_3$.  Therefore, the contrubutions due to the
 singular integral, $\J_i^{uv}$ and $\K_i^{uv}$ can be computed once,
stored, and combined appropriately at each new analysis frequency.
Although $\I_{1i}^{uv}$ must be computed anew at each frequency, the modal
difference series occurring in its integrand can be very rapidly evaluated by
simple interpolation into a two-dimensional table obtained from the
FFT (Section~\ref{sec:modalFFT}).

Calculation of the singular integral in \eqref{eq:Aiuv2} is discussed
in Appendix~\ref{app:singint}.  Efficient evaluation of the remaining
integrals is discussed next.

Each of the integrals $\I_{1i}^{uv}$, $\J_i^{uv}$,
and $\K_i^{uv}$ is of
the form
\begin{equation}
  \L_i = \x L_{ix} + \y L_{iy} = \frac{1}{2A^v} \iint_{T^v} \!\!\!
  \vecrho_i \,
  f(\r;\r') \, \d S'.
\end{equation}
Each involves a bounded, well-behaved
integrand which can be integrated numerically using a low-order Gaussian
scheme designed especially for surface integration (cubature)
over triangular domains \cite{zien:71}.  However, it is advantageous to first
express them in terms of integrals which do not depend on the particular basis function
index $i$.  To accomplish
this, we employ the so-called {\em normalized area coordinates\/}
$(\xi,\eta,\zeta)$.%
\footnote{In this section ``$\eta$'' is used to mean one of the
  normalized area coordinates.  Elsewhere in these notes the same symbol
  may be used to represent the intrinsic impedance of a dielectric medium.}
The source point can be written in terms of area coordinates as
\begin{equation}
  \r' = \xi \r_1 + \eta \r_2 + \zeta \r_3
\end{equation}
so that
\begin{equation}
  \vecrho_i = \pm(\r' - \r_i) = \pm \left(
    \xi \r_1 + \eta \r_2 + \zeta \r_3 - \r_i
  \right).
\end{equation}
where the $\{ \r_i \}$ are the vertices of the source triangle $T^v$ having
area $A^v$. Only two of the three (nonnegative)
coordinates can be independently specified since $\xi + \eta + \zeta = 1$ for
points in the triangle.
The area element in normalized area coordinates is $\d S' = 2 A^v \,\d\xi\,\d\eta$.

The desired integral $\L_{i}$ can
be expressed in terms of scalar integrals over normalized area coordinates
which are independent of $i$ in the
following way.
\begin{equation}
  \L_{i} = \pm  \left[
    \r_1 L_{\xi} + \r_2 L_{\eta} + \r_3 L_{\zeta}
    - \r_i L
  \right]    \label{eq:Lit}
\end{equation}
where
\begin{subequations}
  \begin{align}
    L_{\xi} &= \int_0^1 \int_0^{1-\eta}  \!\!\!\!
    \xi \, f(\rcu;\xi\r_1 + \eta\r_2 + \zeta\r_3)
    \, \d\xi \, \d\eta   \\
    L_{\eta} &= \int_0^1 \int_0^{1-\eta}  \!\!\!\!
    \eta \, f(\r^{cu};\xi\r_1 + \eta\r_2 + \zeta\r_3)
    \, \d\xi \, \d\eta   \\
    L_{\zeta} &= \int_0^1 \int_0^{1-\eta}  \!\!\!\!
    \zeta \, f(\r^{cu};\xi\r_1 + \eta\r_2 + \zeta\r_3)
    \, \d\xi \, \d\eta   \\
    L &=  \int_0^1 \int_0^{1-\eta}  \!\!\!\!
    f(\r^{cu};\xi\r_1 + \eta\r_2 + \zeta\r_3)
    \, \d\xi \, \d\eta.   \label{eq:L}
  \end{align}
\end{subequations}
It is important to note
that the above integrals are not all independent.  We also have that
\begin{equation}
  L = L_{\xi} + L_{\eta} + L_{\zeta}
\end{equation}
so that in general there are three integrals to be numerically evaluated for
each observation point / source triangle pair.  These integrals,
when weighted according to Equation~\eqref{eq:Lit} contribute
to as many as nine entries of $\mat{Z}$, depending on the number of basis
functions defined in each triangle.  They are computed using the seven-point
cubature formula found in, e.g., \cite{zien:71} or \cite{bali:84}.
\begin{equation}
    \int_0^1 \int_0^{1-\eta} \!\!\!
  f(\xi, \eta) \; \d\xi \; \d\eta \approx \sum_{k=1}^7 w_k f(\xi_k, \eta_k).
  \label{eq:cubtri}
\end{equation}
The sample points and weights are given in Table~\ref{tab:tri}.
\begin{table}
  \begin{center}
    \begin{tabular}{|c|c|c|c|}  \hline
      {\boldmath $k$\unboldmath\rule[-.5ex]{0ex}{3ex}} &
      {\boldmath $\xi_k$} \unboldmath  &
      {\boldmath $\eta_k$ \unboldmath} & {\boldmath $w_k$ \unboldmath}
      \\ \hline
      1 & 0.33333333333333333 & 0.33333333333333333 & 0.11250000000000000 \\
      2 & 0.10128650732345633 & 0.79742698535308730 & 0.06296959027241358 \\
      3 & 0.79742698535308730 & 0.10128650732345633 & 0.06296959027241358 \\
      4 & 0.10128650732345633 & 0.10128650732345633 & 0.06296959027241358 \\
      5 & 0.47014206410511505 & 0.05971587178976989 & 0.06619707639425308 \\
      6 & 0.05971587178976989 & 0.47014206410511505 & 0.06619707639425308 \\
      7 & 0.47014206410511505 & 0.47014206410511505 & 0.06619707639425308 \\
      \hline
    \end{tabular}
  \end{center}
  \caption{Sample points and weights for seven point triangular cubature.}
  \label{tab:tri}
\end{table}

\paragraph{Scalar Potential Contributions}
In addition to the vector integrals just discussed, it is also
necessary to calculate scalar integrals of the form
\begin{equation}
  \Phi_i^{uv} = \pm \frac{je^{j\theta^{\pm}_i}}{\omega A^v} \!
  \iint_{T^v} \!\!
  \GPhi(\r^{cu};\r') \; \d S'.  \label{eq:Phiiuv}
\end{equation}
$\Phi_i^{uv}$ is the electric scalar potential at the centroid of
triangle $T^u$ due to the surface electric charge density associated with
the $i$th basis function defined on triangle $T^v$.  As before, the
sign is taken to be positive if the basis function in question defines
positive reference current to flow {\em out} of $T^v$ through the
$i$th edge.
We proceed as before, using the results in Chapter~\ref{chap:gfstratified} for the
electric scalar potential Green's function to write the above integral
as
\begin{equation}
  \Phi_i^{uv} = \frac{\pm
    je^{j\theta^{\pm}_i}}{2\pi\omega\bar{\epsilon}}
  \left[
     4\pi I_{2}^{uv} +
     \frac{1}{2A^v}  \iint_{T^v}  \!
     \frac{\d S'}{\rhocu_{00}} +
     u J^{uv} +
     \frac{d_3(\scriptstyle\mu_s,\epsilon_s,\mu_{s+1},\epsilon_{s+1})}{u}
     K^{uv}
   \right] \label{eq:Phiiuv2}
\end{equation}
where
\begin{subequations}
  \begin{align}
    I_{2}^{uv} &=
    \frac{1}{2A^v}  \iint_{T^v}  \!\!\!
    \Sigma_{M2}(\rcu;\r')
    \, \d S', \\
                                %
    \Sigma_{M2}(\rcu;\r') & =
    \frac{1}{2A} \summn
    \left[
      \frac{2j\omega\bar{\epsilon}(\Vi\TM-\Vi\TE)}{\beta_{mn}^2}
      - \frac{1}{\kappa_{mn}} -
      \frac{d_3({\scriptstyle\mu_s,\epsilon_s,\mu_{s+1},\epsilon_{s+1}})}
      {\kappa_{mn}^3}
    \right]  e^{-j\vecbeta_{mn}\bdot(\rcu-\r')}, \\
                                %
    J^{uv} &=
    \frac{1}{2A^v}  \iint_{T^v}  \!
    \summn  \frac{e^{-u\rhocu_{mn}}-\delta_{m0}\delta_{n0}}{u\rhocu_{mn}}
    e^{-j(m\psi_1+n\psi_2)} \; \d S', \\
    K^{uv} &=
    \frac{1}{2A^v}  \iint_{T^v}  \!
    \summn  e^{-u\rhocu_{mn}}
    e^{-j(m\psi_1+n\psi_2)} \; \d S'.
  \end{align}
\end{subequations}
Note that $J^{uv}$ and $K^{uv}$ have already been computed as
scalar portions of the corresponding vector integrals
$\J_{i}^{uv}$ and $\K_{i}^{uv}$, respectively (see Equation~\ref{eq:L}).
The only new quantities to be computed are $I_{2}^{uv}$ and the singular
integral. The integral $I_{2}^{uv}$ can be computed in exactly
the same manner as $I_{1}^{uv}$ using the FFT. Evaluation of the singular
integral is discussed in Appendix~\ref{app:singint}.
 Note that the
only frequency dependence in \eqref{eq:Phiiuv2} occurs in the
factor $\omega$ and the terms $I_{2}^{uv}$ and $d_3$.

\paragraph{Surface Impedance Contributions}
The contribution to the generalized impedance matrix due to finite
surface impedance of the conducting layer is given by the inner
product
\begin{equation}
  \innerprod{Z_s \f_n/l_n,\f_m/l_m}.
\end{equation}
Note that in most cases basis functions $m$ and $n$ do not share any
common support and the inner product yields zero.
Otherwise, two cases remain. Either
$n=m$, or $n \neq m$ with edges $n$ and $m$  common to a single
triangle. The formulas for the inner product in these cases, assuming that the
surface impedance is constant on each triangle face,
are derived in
Appendix \ref{ap:ip}.  For $n=m$ the result is
\begin{equation}
\innerprod{Z_s \f_n/l_n,\f_n/l_m} = \frac{Z_s^+}{48A_n^+}(3{l_a^+}^2 +
                     3{l_b^+}^2 - l_n^2)
            + \frac{Z_s^-}{48A_n^-}(3{l_a^-}^2 + 3{l_b^-}^2 - l_n^2)
\end{equation}
where the plus and minus signs refer to triangles $T_n^+$ and $T_n^-$,
respectively, and $l_a^{\pm}$ and $l_b^{\pm}$ are the lengths of the
two other edges on these triangles.  For $n \neq m$ the result is
\begin{equation}
\innerprod{Z_s \f_n/l_n,\f_m/l_m} = \pm
e^{j(\theta_n-\theta_m)}
\frac{Z_s^{mn}}{48A^{mn}}
                    (l_m^2 + l_n^2 - 3 l_{p}^2)
\end{equation}
where the double superscript $mn$ refers to the triangle common
to basis functions $m$ and
$n$ and $l_{p}$ is the length of the third edge.  The minus sign is taken if
one of the basis functions $\f_m$ and $\f_n$ define positive current flow out
of the triangle while the other basis function defines positive current flow
into the triangle.  If the two basis functions agree in this respect the plus
sign is used.

\subsection{\label{subsec:gvm}Generalized Voltage Vector}
The elements of the generalized voltage vector are defined as
\begin{equation}
 \matel{V}_m =  \innerprod{\E\inc, \f_m/l_m} = \frac{1}{l_m}
 \iint \! \E\inc \! \bdot \f_m^* \, \d S, \quad
      m = 1, 2, \ldots,  N_J.  \label{eq:Vm}
\end{equation}
The incident field $\E\inc$ is the field that would exist in the
absence of the FSS metalization due to an incoming, normalized
Floquet mode from Region~$1$ or~$N$ with unit amplitude coefficient.
This scenario was treated in Chapter~\ref{chap:incgsm} and we use the results
derived there.  Let $i \in \{1,N\}$ be the region index designating
the source of the incoming Floquet mode.  The mode index is $q =
(p_q,m_q,n_q)$ where $p_q=1$ for TE modes and $p_q=2$ for TM modes.  The
transverse portion of the incident electric field evaluated in the
$z=z_s$ plane is:
\begin{equation}
  \Idemfactor_z \bdot \E\inc(\vecrho) = V(z_s) \e_q\eye(\vecrho)
  = V(z_s) c_q\eye \t_q e^{-j\vecbeta_{m_q n_q} \bdot
  \vecrho} \label{eq:Eincmom}
\end{equation}
where the modal polarization vector $\t_q$ is defined as
\begin{equation}
  \label{eq:tdef}
  \t_q =
  \begin{cases}
    \z\cross\betahat_{mn} & p_q = 1 \; \text{(TE modes),} \\
    \betahat_{mn}  & p_q = 2 \; \text{(TM modes),}
  \end{cases}
\end{equation}
and $V(z_s)$ is the equivalent transmission line voltage evaluated at
$z=z_s$ using the formulas presented in Chapter~\ref{chap:incgsm}.

Upon substituting the incident field of \eqref{eq:Eincmom} into
\eqref{eq:Vm} we find that
\begin{align}
  \matel{V}_m &=
  \frac{V(z_s) c_q\eye}{l_m}   \t_q \bdot
  \iint \! \! \f_m^*(\vecrho) e^{-j\vecbeta_{m_q n_q}\bdot\vecrho} \, \d S
  \nonumber \\
  &=
  \frac{V(z_s) c_q\eye}{l_m}   \t_q \bdot
  \ftf_m^*(\vecbeta_{m_q n_q}), \quad
  m = 1, 2, \ldots,  N_J,
\end{align}
where
\begin{equation}
    \ftf_m(\k) = \iint \!\!
    \f_m(\vecrho) \, e^{j\k \bdot \vecrho} \, \d S
\end{equation}
is the Fourier transform of the $m$th basis function evaluated at $\k
= \x k_x + \y k_y.$  The Fourier transform is numerically
evaluated using the formulas of \cite{mcsi:91}.

\section{Magnetic Current Mixed Potential Integral Equation}
In this section we consider an FSS that is modeled using equivalent
magnetic surface current.  This choice is convenient when more than
half of the unit cell area is occupied by perfectly conducting metal.

We assume that the primary excitation is an
incoming Floquet mode with unit amplitude, incident
upon the multilayered structure from either Region~$1$ or $N.$

Using the equivalence principle, the FSS aperture $S$ is filled in with PEC
and an unknown magnetic surface current ($\M$ on the incident side,
and $-\M$ on the far side) is impressed just
outside the metal surface, so as to reproduce the scattered
field exactly in all regions.  The incident field is thus the field
that would exist in the structure with an unperforated ground plane at
$z=z_s$.  It includes reflections from the ground plane on the
incident side of $z_s$ and is zero on the far or transmitted side.

In the case where the incoming wave is incident from Region~$1$, the
boundary value problem to be solved is
\begin{equation}
  \Idemfactor_z \bdot [\H\inc(x,y,z_s) + \H\ess\{\M\}(x,y,z_s)]
  =   \Idemfactor_z \bdot \H\spw\{-\M\}(x,y,z_s),
    \quad (\vecrho \in S)
\end{equation}
where
$H\inc$ is the total ``incident'' magnetic field in the presence of
the unperforated PEC plane at $z=0$,
$\H\ess\{\M\}(\r)$ is the magnetic field evaluated at point $\r \in \{z<z_s\}$ that
would be radiated by the periodic magnetic surface current
$\M$ impressed on the groundplane at $z=z_s-0$, and
$\H\spw\{\M\}(\r)$ is the magnetic field evaluated at point $\r \in \{z>z_s\}$ that
would be radiated by the periodic magnetic surface current
$\M$ impressed on the groundplane at $z=z_s+0.$
In the case where the incoming wave is incident from Region~$N$, the
boundary value problem to be solved is
\begin{equation}
  \Idemfactor_z \bdot \H\ess\{-\M\}(x,y,z_s)
  =   \Idemfactor_z \bdot [\H\inc(x,y,z_s) + \H\spw\{\M\}(x,y,z_s)],
    \quad (\vecrho \in S)
\end{equation}

Using the linearity of the magnetic field operator allows
us to rewrite the both integral equations in a unified form:
\begin{equation}
-\Idemfactor_z \bdot [\H\ess\{\M\}(\vecrho) +
\H\spw\{\M\}(\vecrho)] =
\Idemfactor_z \bdot \H\inc(\vecrho), \quad (\vecrho \in S)
  \label{eq:MFIE}
\end{equation}
where it is to be understood that $\vecrho$ represents a point in the
plane $z=z_s.$
%continue here
In terms of potentials the boundary value problem becomes
\begin{equation}
  [-j\omega \F(\vecrho) + \gradient\Psi(\vecrho)] \bdot \Idemfactor_z =
  \H\inc(\vecrho) \bdot \Idemfactor_z, \quad (\vecrho \in S)
  \label{eq:HMPIE}
\end{equation}
where the potentials can be expressed as superposition integrals
 \begin{gather}
   \Idemfactor_z \bdot \F(\vecrho) =
   \iint \GFxx(\vecrho-\vecrho') \cdot \M(\vecrho') \, \d S',
   \label{eq:Fsup}\\
   \Psi(\vecrho) = \iint \GPsi(\vecrho-\vecrho') \cdot \qm(\vecrho') \, \d S'.
   \label{eq:Psisup}
 \end{gather}
In \eqref{eq:Fsup} and \eqref{eq:Psisup}, $\M$ and $\qm$ are the unknown
induced magnetic surface current and surface charge densities,
respectively, which will be determined
by enforcing
Equation~\eqref{eq:HMPIE} in an approximate manner using the method of
moments. The functions $\GFxx$ and $\GPsi$ are the sum of the
left-looking and right-looking Green's functions as defined in
Chapter~\ref{chap:gfstratified}:
\begin{subequations}
  \begin{align}
    \GFxx(\vecrho-\vecrho') &=
    \GlFxx(\vecrho-\vecrho',z_s,z_s) +
    \GrFxx(\vecrho-\vecrho',z_s,z_s) \\
    \GPsi(\vecrho-\vecrho') &=
    \GlPsi(\vecrho-\vecrho',z_s,z_s) +
    \GrPsi(\vecrho-\vecrho',z_s,z_s).
  \end{align}
\end{subequations}

 We again employ the triangle subdomain basis functions that
were described in Section~\ref{sec:bf}.

We now expand the unknown magnetic surface current density
in a series of triangle-pair basis functions:
\begin{equation}
  \label{eq:Mexpand}
  \M(\vecrho) =  \sum_{n=1}^{N_M} \frac{\Vcoef_n}{l_n} \f_n(\vecrho).
\end{equation}
The number of basis functions
$N_M$ is equal to the number of interior edges of the triangulated aperture in the
$z=0$ plane of the unit cell plus the number of edges along the $\xi=0$ and $\eta=0$
borders of the unit cell.  Note that $\Vcoef_n$ has units of \si{V}.

\subsection{Admittance Matrix}
\subsubsection{Reduction to Matrix Equation}
Having expanded the unknown magnetic surface
current in a series of suitable basis functions,
it is now desired to determine the coefficients in a way that satisfies
Equation~\eqref{eq:HMPIE} as closely as possible.

We choose our testing functions to be the same as our basis functions
(Galerkin's method).  Then taking the inner product of \eqref{eq:HMPIE}
with each of the functions $\f_m/l_m$  for $m = 1,2,\ldots, N_M$ yields
\begin{equation}
  -j\omega \innerprod{\F,\f_m/l_m} + \innerprod{\gradient\Psi,\f_m/l_m}
  = \innerprod{\H\inc, \f_m/l_m}, \qquad
  m = 1, 2, \ldots,  N_M.   \label{eq:Hmom}
\end{equation}
We approximate the inner products in the same manner as was done for
the case of electric sources:
\begin{equation}
  \innerprod{\gradient\Psi, \f_m/l_m} \approx
         e^{-j\theta_m^-} \Psi(\rcm_m) - e^{-j\theta_m^+} \Psi(\rcp_m)
         \label{eq:Psimom}
\end{equation}
where $\rcpm_m$ is the centroid of triangle $T_m^{\pm}$. Also, we use
\begin{equation}
  \innerprod{\F, \f_m/l_m} \approx \frac{1}{2}
      \left[ \F(\rcp_m) \bdot \vecrhocp_m e^{-j\theta_m^+} +
             \F(\rcm_m) \bdot \vecrhocm_m  e^{-j\theta_m^-}
      \right].      \label{eq:Fmom}
\end{equation}
$\vecrhocpm_m$ is the vector $\vecrho_m^{\pm}$ evaluated at the centroid
of the corresponding triangle.

Substituting the expansion of the current \eqref{eq:Mexpand} into \eqref{eq:Hmom}
yields the desired matrix equation.
\begin{equation}
  \mat{Y} \mat{V} =  \mat{I},  \label{eq:Hmatrix}
\end{equation}
where $\mat{Y} = [\matel{Y}_{mn}]$ is the so-called {\em generalized admittance
matrix}, a square matrix of order $N_M$ with units of \si{S}.
$\mat{V} = [\Vcoef_m]$ is the column matrix of unknown magnetic current
coefficients with units of \si{V}.
$\mat{I}= [\matel{I}_m]$ is the excitation vector (or {\em generalized
current vector}) with units of \si{A}.
 The elements of the generalized admittance matrix are
\begin{equation}
  \matel{Y}_{mn} =
 -j\omega \left(
    \F_{mn}^+ \bdot \frac{\vecrhocp_m}{2} e^{-j\theta_m^+}
    +
    \F_{mn}^- \bdot \frac{\vecrhocm_m}{2} e^{-j\theta_m^-}
  \right)
  + \Psi_{mn}^- e^{-j\theta_m^-} - \Psi_{mn}^+ e^{-j\theta_m^+}
\end{equation}
where
 \begin{align}
   \F_{mn}^{\pm} & \equiv
   \frac{1}{l_n} \iint
   \GFxx(\rcpm_m;\r') \, \f_n(\r') \; \d S'  \notag \\
   &=
     \frac{e^{j\theta_n^+}}{2A_n^+} \iint_{T_n^+}  \!\!\!
     \GFxx(\rcpm_m;\r') \, \vecrho_n^+ \; \d S'
     +
     \frac{e^{j\theta_n^-}}{2A_n^-} \iint_{T_n^-}  \!\!\!
     \GFxx(\rcpm_m;\r')  \, \vecrho_n^- \; \d S'
     \label{eq:Fmnpm}
 \end{align}
and
\begin{align}
  \Psi_{mn}^{\pm} &\equiv \frac{j}{\omega l_n} \iint
  \GPsi(\rcpm_m;\r')
  \gradient'_s \bdot \f_n(\r')
  \; \d S'
  \notag \\
  &= \frac{j}{\omega}
  \left[
    \frac{e^{j\theta_n^+}}{A_n^+} \iint_{T_n^+}  \!\!\!
    \GPsi(\rcpm_m;\r') \; \d S'
    -
    \frac{e^{j\theta_n^-}}{A_n^-} \iint_{T_n^-}{}  \!\!\!
    \GPsi(\rcpm_m;\r') \; \d S'
  \right]    \label{eq:Psimnpm}
\end{align}

\subsubsection{Efficient Evaluation of the Generalized Admittance Matrix}
\paragraph{Vector Potential Contributions}
Consider first a typical vector integral needed
to evaluate $\matel{Y}_{mn}$.
The quantity
\begin{equation}
  \F_i^{uv} =   \frac{e^{j\theta_i^\pm}}{2A^v}  \iint_{T^v}  \!\!\!
  \GFxx(\rcu;\r') \, \vecrho_i \; \d S' \label{eq:Fiuv}
\end{equation}
represents the electric vector potential at the centroid $\rcu$ of triangle
$T^u$ due to the $i\text{th}$ basis function defined on triangle $T^v$.
In \eqref{eq:Fiuv} we have temporarily assumed a local numbering scheme
on the source triangle, with vertices at $\r_1$, $\r_2$, and $\r_3$,
and where $\vecrho_i$ is defined in Equation~\eqref{eq:vecrhosubi}.
Using the expressions for the electric vector potential Green's
function given in Chapter~\ref{chap:gfstratified},  Equation~\eqref{eq:Fiuv} can
be written as
the sum of a frequency dependent term arising from the modal
difference series, added to several contributions arising from the
spatial series:
\begin{equation}
  \F_i^{uv} = -\frac{\bar{\epsilon}}{\pi} e^{j\theta^{\pm}_i}
  \Biggl[
    \frac{\pi\epsilon_0}{\bar{\epsilon}}  \I_{1i}^{'uv} +
    \frac{1}{2A^v} \! \iint_{T^v}  \!
    \frac{\vecrho_i}{\rhocu_{00}} \, \d S' +
       u \J_i^{uv} +
    \frac{c_3\ess \epsilon_s + c_3\spw \epsilon_{s+1}}{2\bar{\epsilon}u}
     \K_i^{uv}
  \Biggr] \label{eq:Fiuv2}
\end{equation}
where
\begin{equation}
     \I_{1i}^{'uv} =
     \frac{1}{2A^v}  \iint_{T^v}  \!\!\!
     \Sigma'_{M1}(\rcu;\r')
     \, \vecrho_i \; \d S'
\end{equation}
and $\Sigma'_{M1}$ is defined in Equation~\eqref{eq:finalmodalmagnetic}.
Note that the
only frequency dependence in \eqref{eq:Fiuv2} occurs in the terms
$\I_{1i}^{uv}$ and $c_3$.  Therefore, the contrubutions due to the
singular integral, $\J_i^{uv}$ and $\K_i^{uv}$ can be computed once,
stored, and combined appropriately at each new analysis frequency.
Although the value of $\I_{1i}^{'uv}$ must be computed anew
at each frequency, the modal
difference series occurring in its integrand can be very rapidly evaluated by
simple interpolation into a two-dimensional table obtained from the
FFT (Section~\ref{sec:modalFFT}).

\paragraph{Scalar Potential Contributions}
In addition to the vector integrals just discussed, it is also
necessary to calculate scalar integrals of the form
\begin{equation}
  \Psi_i^{uv} = \pm \frac{je^{j\theta^{\pm}_i}}{\omega A^v} \!
  \iint_{T^v} \!\!
  \GPsi(\r^{cu};\r') \; \d S'.  \label{eq:Psiiuv}
\end{equation}
$\Psi_i^{uv}$ is the
magnetic scalar potential evaluated at the centroid of
triangle $T^u$ due to the surface magnetic charge density associated with
the $i$th basis function defined on triangle $T^v$.  As before, the
sign is taken to be positive if the basis function in question defines
positive reference current to flow {\em out} of $T^v$ through the
$i$th edge.
We proceed as before, using the results of Chapter~\ref{chap:gfstratified} for the
magnetic scalar potential Green's function to write the above integral
as
\begin{equation}
  \Psi_i^{uv} = \frac{\pm 2 j e^{j\theta^{\pm}_i}}{\pi\omega\tilde{\mu}}
  \Biggl[
  \frac{\pi\tilde{\mu}}{\mu_0}
  I_{2}^{'uv} +
  \frac{1}{2A^v}  \! \iint_{T^v}  \!
      \frac{\d S'}{\rhocu_{00}} +
      u J_i^{uv} +
      \frac{\tilde{\mu}}{2u}
      \left(
        \frac{d_3\ess}{\mu_s} + \frac{d_3\spw}{\mu_{s+1}}
      \right)
      K_i^{uv}
    \Biggr] \label{eq:Psiiuv2}
 \end{equation}
where
\begin{equation}
     I_{2}^{'uv} =
     \frac{1}{2A^v}  \iint_{T^v}  \!\!\!
     \Sigma'_{M2}(\rcu;\r')
     \; \d S'
\end{equation}
and $\Sigma'_{M2}$ is defined in Equation~\eqref{eq:finalmodalmagnetic}.

All of the integrals in \eqref{eq:Psiiuv2} have been previously
discussed.  Note that the only frequency dependence (apart from the leading factor of
$1/\omega$) occurs in the terms $I_{2}^{'uv}$ and $d_3$.

\subsection{\label{subsec:gcm}Generalized Current Vector}
The elements of the generalized current vector are defined as
\begin{equation}
  \matel{I}_m =  \innerprod{\H\inc, \f_m/l_m} = \frac{1}{l_m}
  \iint \H\inc \bdot \f_m^* \, \d S, \quad
  m = 1, 2, \ldots,  N_J.
  \label{eq:Im}
\end{equation}
The incident field $\H\inc$ is the field that would exist in the
presence of the unperforated FSS metalization due to an incoming, normalized
Floquet mode from Region~$1$ or~$N$ with unit amplitude coefficient.
This scenario was treated in Chapter~\ref{chap:incgsm} and we use the results
derived there.  Let $i \in \{1,N\}$ be the region index designating
the source of the incoming Floquet mode.  The mode index is $q =
(p_q,m_q,n_q)$ where $p_q=1$ for TE modes and $p_q=2$ for TM modes.  The
transverse portion of the incident magnetic field evaluated in the
$z=z_s$ plane is:
\begin{equation}
  \Idemfactor_z \bdot \H\inc(\vecrho) = I(z_s) \h_q\eye(\vecrho)
  = I(z_s) Y_q\eye c_q\eye \z\cross\t_q e^{-j\vecbeta_{m_q n_q} \bdot
  \vecrho} \label{eq:Hincmom}
\end{equation}
where the modal polarization vector $\t_q$ was defined in \eqref{eq:tdef}
and $I(z_s)$ is the equivalent transmission line current evaluated at
$z=z_s$ using the formulas presented in Chapter~\ref{chap:incgsm}.

Upon substituting the incident field of \eqref{eq:Hincmom} into
\eqref{eq:Im} we find that
\begin{align}
  \matel{I}_m &=
  \frac{I(z_s) Y_q\eye c_q\eye}{l_m} \z \cross \t_q \bdot
  \iint \! \! \f_m^*(\vecrho) e^{-j\vecbeta_{m_q n_q}\bdot\vecrho} \, \d S
  \nonumber \\
  &=
  \frac{I(z_s) Y_q\eye c_q\eye}{l_m} \z \cross  \t_q \bdot
  \ftf_m^*(\vecbeta_{m_q n_q}), \quad
  m = 1, 2, \ldots,  N_M,
\end{align}
where
\begin{equation}
    \ftf_m(\k) = \iint \!\!
    \f_m(\vecrho) \, e^{j\k \bdot \vecrho} \, \d S
\end{equation}
is the Fourier transform of the $m$th basis function evaluated at $\k
= \x k_x + \y k_y.$  The Fourier transform is numerically
evaluated using the formulas of \cite{mcsi:91}.