\documentclass{memoir}
\usepackage{notestemplate}

% \begin{figure}[ht]
%     \centering
%     \incfig{riemmans-theorem}
%     \caption{Riemmans theorem}
%     \label{fig:riemmans-theorem}
% \end{figure}

\begin{document}

\begin{defn}[Power Series]
A \textbf{power series} is an infinite sum of monomials
\begin{align*}
	\sum_{n=0}^{\infty} a_n (z-z_0)^{n}
\end{align*}
where \(\left\{ a_n \right\},z_0  \in \C\) and \(z\) is a complex variable. We call \(z_0\) the \textbf{center} of the power series.
\end{defn}
Notice that we make no statements thus far in terms of convergence. Furthermore, one can take \(a_n = 0\) for \(n\geq N\) in order to express a finite power series.\\

\begin{anki}
TARGET DECK
Complex Qual::Complex Analysis
START
MathJaxCloze
Text: A **power series** is an infinite sum of monomials
{{c1::\(\begin{align*}
        	\sum_{n=0}^{\infty} a_n (z-z_0)^{n}
        \end{align*}\)}}
where \(\left\{ a_n \right\},z_0  \in \C\) and \(z\) is a complex variable. We call \(z_0\) the \textbf{center} of the power series.
Extra: One can take \(a_n = 0\) for \(n\geq N\) in order to express a finite power series.
Tags: analysis complex_analysis power_series defn
<!--ID: 1624504053797-->
END
\end{anki}

We briefly describe a stronger form of convergence before looking closer at the convergence of power series:
\begin{defn}[Uniform Convergence]
	Let \(\left\{ f_n \right\} \) be a sequence of complex-valued functions on a set \(\Omega\subset \C\). The sequence \(\left\{ f_n \right\} \) is \textbf{uniformly convergent} on \(E\) with
	\begin{align*}
		\lim_{n \to \infty} f_n = f
	\end{align*}
	if for every \(\varepsilon>0\), there exists an \(N \in \N\) such that, for all \(n\geq N\) and \(z \in \Omega\)
	\begin{align*}
		\left| f_n(z) - f(z) \right| \leq \varepsilon.
	\end{align*}
\end{defn}

\begin{anki}
START
MathJaxCloze
Text: Let \(\left\{ f_n \right\} \) be a sequence of complex-valued functions on a set \(\Omega\subset \C\). The sequence \(\left\{ f_n \right\} \) is **uniformly convergent** on \(E\) with
\(\begin{align*}
  	\lim_{n \to \infty} f_n = f
  \end{align*}\)
	if {{c1::for every \(\varepsilon>0\)}}, {{c1::there exists an \(N \in \N\)}} such that, {{c1::for all \(n\geq N\)}} and {{c1::\(z \in \Omega\)}}:
	{{c1::\(\begin{align*}
	        	\left| f_n(z) - f(z) \right| \leq \varepsilon.
	        \end{align*}\)}}
Tags: analysis complex_analysis defn complex_convergence
<!--ID: 1624504053886-->
END
\end{anki}

Of course, there are less strong and more general notions of convergence:

\begin{defn}[Absolute Convergence]
	A sequence of complex numbers \(\left\{ z_n \right\}\subset \C \) \textbf{absolutely converges} if
	\begin{align*}
	\sum_{n=0}^{\infty} \left| z_n \right|
	\end{align*}
	converges.
\end{defn}

\begin{anki}
START
MathJaxCloze
Text: A sequence of complex numbers \(\left\{ z_n \right\} \subset \C \) **absolutely converges** if
 {{c1::\(\begin{align*}
        \sum_{n=0}^{\infty} \left| z_n \right|
        \end{align*}\)}}
	converges.
Extra: A power series is absolutely convergent at a point \(z_1\) if the power series evaluated at \(z_1\) is absolutely convergent.
Tags:
<!--ID: 1624504053923-->
END
\end{anki}

We urge the reader to be cautious. The sum above is not a power series, and so it does not make semantic sense for a power series to absolutely converge. However, if we fix \(z = z_1\), then we can ask if the power series (absolutely) converges for \(z = z_1\).\\

\begin{prop}
	Absolute convergence implies convergence.
\end{prop}

Observe that if \(z = z_1\) is fixed and the power series is absolutely convergent for that \(z\):
\begin{align*}
	\sum_{n=0}^{\infty} \left| a_n (z-z_0)^{n} \right|
\end{align*}
then
\begin{align*}
	\sum_{n=0}^{\infty} \left| a_n (z-z_0)^{n} \right| = \sum_{n=0}^{\infty} \left| a_n \right| \left| z-z_0 \right|^{n}.
\end{align*}
We will use this form when discussing the absolute convergence of a power series at a point. One can verify that the first sum converges if and only if the second sum converges.

\begin{prop}
	Given a power series
	\begin{align*}
	\sum_{n=0}^{\infty} a_n (z-z_0)^{n},
	\end{align*}
	assume it converges absolutely for some \(z=z_1\). Then the power series converges for all \(z\) such that \(\left| z-z_0 \right| \leq \left| z_1-z_0 \right| \).
\end{prop}
This is a slight simplification. Absolute convergence is uniform in every closed subdisc-- that is, every compact subset within the disc is absolutely convergent. In other words, if a power series absolutely converges for \(z = z_1\), it convergences absolutely and locally uniformly within the disc determined by \(z_1-z_0 \).

\begin{thm}
	Given a power series \(\sum_{n=0}^{\infty} a_n (z-z_0)^{n}\) there exists \(0\leq R\leq \infty\) such that:
	\begin{itemize}
		\item If \(\left| z-z_0 \right| <R\) the series converges absolutely
		\item If \(\left| z -z_0\right| >R\) the series diverges
	\end{itemize}
	Using the convention that \(\frac{1}{0}= \infty\) and \(\frac{1}{\infty}=0\), then \(R\) is given by Hadamard's formula:
	\begin{align*}
		\frac{1}{R}= \limsup \left| a_n \right|^{1 / n} .
	\end{align*}
	The number \(R\) is called the \textbf{radius of convergence} of the power series, and the region \(\left| z-z_0 \right| <R\) is the \textbf{disc of convergence}.
\end{thm}

Notice that the theorem above makes no statement as to convergence on the boundary. On the boundary, it is unclear whether we have convergence or divergence.

\begin{proof}

\end{proof}

\begin{anki}
START
MathJaxCloze
Text: Given a power series \(\sum_{n=0}^{\infty} a_n (z-z_0)^{n}\) there exists \(0\leq R\leq \infty\) such that:

* {{c1::If \(\left| z-z_0 \right| <R\) the series converges absolutely}}
* {{c1::If \(\left| z -z_0\right| >R\) the series diverges}}

Using the convention that \(\frac{1}{0}= \infty\) and \(\frac{1}{\infty}=0\), then \(R\) is given by Hadamard's formula:
 {{c2::\(\begin{align*}
        	\frac{1}{R}= \limsup \left| a_n \right|^{1 / n} .
        \end{align*}\)}}
	The number \(R\) is called the \textbf{radius of convergence} of the power series, and the region {{c1::\(\left| z-z_0 \right| <R\)}}  is the \textbf{disc of convergence}.
Tags: analysis complex_analysis power_series defn
<!--ID: 1624504053960-->
END
\end{anki}

\begin{exmp}[Trigonometric Functions]
	Consider the power series given by
	\begin{align*}
		e^{z} &:= \sum_{n=0}^{\infty} \frac{1}{n!}z^{n}\\
		\cos (z) &:= \sum_{n=0}^{\infty} a_n z^{n}\\
		\sin (z) &:= \sum_{n=0}^{\infty} b_n z^{n}
	\end{align*}
	where
	\begin{align*}
		a_n &= \begin{cases}
			\frac{(-1)^{n}}{(2n)!} & n \equiv 0 \pmod{2} \\
			0 & n \equiv 1 \pmod{2}
		\end{cases}\\
		b_n &= \begin{cases}
			0 & n \equiv 0 \pmod{2}\\
			\frac{(-1)^{n}}{(2n+1)!} & n \equiv 1 \pmod{2}
		\end{cases}.
	\end{align*}
	These power series are absolutely convergent in the whole complex plane. One can check that they agree with the usual exponential, cosine, and sine function of the real plane when \(z\) is real. Within the context of complex analysis, we instead choose to define the functions by the above series.
\end{exmp}

\begin{anki}
START
MathJaxCloze
Text: Consider the power series given by
	\begin{align*}
		e^{z} &:= {{c1::\sum_{n=0}^{\infty} \frac{1}{n!}z^{n}}} \\
		\cos (z) &:= \sum_{n=0}^{\infty} a_n z^{n}\\
		\sin (z) &:= \sum_{n=0}^{\infty} b_n z^{n}
	\end{align*}
	where
	\begin{align*}
		a_n &= {{c2::\begin{cases}
			\frac{(-1)^{n}}{(2n)!} & n \equiv 0 \pmod{2} \\
			0 & n \equiv 1 \pmod{2}
		\end{cases} }} \\
		b_n &= {{c3::\begin{cases}
			0 & n \equiv 0 \pmod{2}\\
			\frac{(-1)^{n}}{(2n+1)!} & n \equiv 1 \pmod{2}
		\end{cases} }} .
	\end{align*}
Extra: These power series are absolutely convergent in the whole complex plane. One can check that they agree with the usual exponential, cosine, and sine function of the real plane when \(z\) is real. Within the context of complex analysis, we instead choose to define the functions by the above series.
Tags: analysis complex_analysis power_series
<!--ID: 1624504053995-->
END
\end{anki}

\begin{hw}
	Show that \(e^{z}, \cos(z), \sin(z)\) converge for all \(z \in \C\). Then show that
	\begin{align*}
		\cos(z) = \frac{1}{2}\left( e^{iz} + e^{-iz} \right) \\
		\sin(z) = \frac{1}{2i} \left( e^{iz} - e^{-iz} \right) .
	\end{align*}
	We call the above formulas the \textbf{Euler formulas} for the cosine and sine functions.
\end{hw}

\begin{hw}
	Show that \(e^{z}\) is the only solution to
	\begin{align*}
		f'(z) = f(z)
	\end{align*}
	with \(f(0) = 1\). Use this formulation of \(e^{z}\) to show that
	\begin{align*}
		e^{a+b} = e^{a}e^{b}
	\end{align*}
	Many references choose to define \(e^{z}\) as the unique solution to the differential equation above. Proving this bridges the gap between the two definitions, and now either formulation can be used interchangably.
\end{hw}

\begin{prop}
	\begin{align*}
		e^{2 \pi i} = 1.
	\end{align*}
\end{prop}
\begin{proof}
	Observe that
	\begin{align*}
		e^{z} = (\cos(z),\sin(z))
	\end{align*}
	and hence
	\begin{align*}
		e^{2\pi i} = \left( \cos(2\pi i), \sin(2\pi i) \right) = \left( 1,0 \right) = 1.
	\end{align*}
\end{proof}

\begin{exmp}[Logarithm]
We define the \textbf{logarithm} to be the inverse function of the exponential:
\begin{align*}
	\log: \C\setminus\left\{ 0 \right\} \to \C
	\log(e^{z}) := z
\end{align*}
Hence by definition, the domain of \(\log\) is the range of \(e^{z}\), that is, \(\C\setminus \left\{ 0 \right\} \).\\

First, notice that the logarithm is not injective. To see this, write \(z = (x,y)\) and notice that
\begin{align*}
	e^{z} = e^{(x,y)} = e^{(x,0)}e^{(0,y)} = e^{(x,0)}e^{(0,2\pi k+ y}
\end{align*}
for \(k \in \Z\). Hence the real part is unique, but the imaginary part is only unique up to multiples of \(2\pi \). We refer to the real part of the logarithm as the \textbf{real logarithm}, and note that it is given by
\begin{align*}
	\log(e^{(x,0)}) = \left| z \right| .
\end{align*}
The imaginary part is referred to as the \textbf{argument of \(z\)} and is given by
\begin{align*}
	\log(e^{(0,y)}) = \sfrac{z}{\left| z \right| }.
\end{align*}
When taking the argument of a complex number, we first must choose a \textbf{branch}-- an interval of length \(2\pi \) in which the argument is to lie. If unstated, then we implicitly are choosing the canonical branch \(0\leq \textrm{arg}(z)<2\pi \).\\

Geometrically, we can view the argument of \(z\) as the angle. Hence, for all \(z \in \C\setminus\left\{ 0 \right\} \), we have
\begin{align*}
	\log(z) = (\log\left| z \right|, \textrm{arg}(z)).
\end{align*}
Let the canonical branch be chosen. This function is not holomorphic on \(\C\setminus \left\{ 0 \right\}\), but is holomorphic on \(\C\setminus \left\{ z\in \R \mid z \leq 0 \right\} \). This is because there is a discontinuity on the negative real line.
\end{exmp}

\begin{thm}
	The power series \(f(z) = \sum_{n=0}^{\infty} a_n (z-z_0)^n\) is a holomorphic function in its disc of convergence. The derivative of \(f\) is also a power series obtained by differentiating term by term the series for \(f\), that is,
	\begin{align*}
		f'(z) = \sum_{n=0}^{\infty} na_n(z-z_0)^{n-1}
	\end{align*}
	Moreover, \(f'\) has the same radius of convergence as \(f\).
\end{thm}
\begin{proof}

\end{proof}

\begin{anki}
START
MathJaxCloze
Text: The power series \(f(z) = \sum_{n=0}^{\infty} a_n (z-z_0)^n\) is a {{c1::holomorphic function}} in its disc of convergence. The derivative of \(f\) is also a {{c1::power series}} obtained by {{c1::differentiating term by term the series for \(f\)}}, that is,
 {{c1::\(\begin{align*}
        	f'(z) = \sum_{n=0}^{\infty} na_n(z-z_0)^{n-1}
        \end{align*}\)}}
	Moreover, \(f'\) has the {{c1::same radius of convergence}} as \(f\).
Extra: A power series is infinitely complex differentiable in its disc of convergence, and the higher derivatives are also power series obtained by termwise differentiation.
Tags: analysis complex_analysis power_series complex_analyticity
<!--ID: 1624504054031-->
END
\end{anki}

\begin{cor}
	A power series is infinitely complex differentiable in its disc of convergence, and the higher derivatives are also power series obtained by termwise differentiation.
\end{cor}
This is an incredibly powerful statement. Compare this to real analysis-- in real analysis, we cannot infer a function has higher derivatives from the existence of a first derivative. The strength of this tool is that now if we want to show a complex equation is holomorphic in a region, we simply show that it is equal to a power series within the region, then show the region is within the power series' region of convergence. Now we formalize this idea:

\begin{defn}[Analytic]
	A function \(f\) defined on an open set is said to be \textbf{analytic} at a point \(z_0\) if there exists a power series centered at \(z_0\) with positive radius of convergence such that
	\begin{align*}
		f(z) = \sum_{n=0}^{\infty} a_n(z-z_0)^{n}
	\end{align*}
	for all \(z\) in a neighborhood of \(z_0\).\\

	If \(f\) has a power series expansion at every point in the open set, it is \textbf{analytic} on the open set.
\end{defn}
It follows immediately that an analytic function on \(\Omega \) is holomorphic on \(\Omega \). We will later show the converse.

\begin{anki}
START
MathJaxCloze
Text: A function \(f\) defined on an open set is said to be **analytic** at a point \(z_0\) if {{c1::there exists a power series centered at \(z_0\)}} with {{c1::positive radius of convergence}} such that
{{c1::\(\begin{align*}
        	f(z) = \sum_{n=0}^{\infty} a_n(z-z_0)^{n}
        \end{align*}\)}}
for all \(z\) in a neighborhood of \(z_0\).

If \(f\) has {{c1::a power series expansion}} at every point in the open set, it is **analytic** on the open set.
Extra: An analytic function on \(\Omega\) is holomorphic on \(\Omega\) (the converse also holds)
Tags: analysis complex_analysis defn power_series complex_analyticity
<!--ID: 1624504054064-->
END
\end{anki}

\begin{prop}
	If \(f,g\) are power series which converge absolutely on \(D(z_0,R)\), then \(f+g\) and \(fg\) converge absolutely on \(D(z_0,R)\). Furthermore, if \(\alpha  \in \C\), then \(\alpha f\) converges absolutely on \(D(z_0,R)\). In fact, we have:
	\begin{align*}
		(f+g)(z-z_0) = f(z-z_0) + g(z-z_0)\\
		(fg)(z-z_0) = f(z-z_0)g(z-z_0)\\
		(\alpha f)(z-z_0) = \alpha f(z-z_0)
	\end{align*}
	for all \(z \in D(z_0,R)\).
\end{prop}

\begin{anki}
START
MathJaxCloze
Text: If \(f,g\) are power series which converge absolutely on \(D(z_0,R)\), then \(f+g\) and \(fg\) {{c1::converge absolutely on \(D(z_0,R)\)}}. Furthermore, if \(\alpha  \in \C\), then {{c1::\(\alpha f\)}} converges absolutely on \(D(z_0,R)\). In fact, we have:
 {{c1::\(\begin{align*}
         	(f+g)(z-z_0) = f(z-z_0) + g(z-z_0)\\
         	(fg)(z-z_0) = f(z-z_0)g(z-z_0)\\
         	(\alpha f)(z-z_0) = \alpha f(z-z_0)
         \end{align*}\)}}
for all \(z \in D(z_0,R)\).
Tags: analysis complex_analysis power_series
<!--ID: 1624845302985-->
END
\end{anki}

This leads to the following theorem:
\begin{thm}
	\begin{enumerate}[(a).]
		\item Let \(f(z) = \sum_{n=0}^{\infty} a_n z^{n}\) be a non-constant power series with non-zero radius of convergence. If \(f(0) = 0\), then there exists a disc of radius \(s>0\) such that
			\begin{align*}
				f(z)\neq 0
			\end{align*}
			for all \(z \in D(0,s)\setminus\left\{ 0 \right\} \).
		\item Suppose that \(f,g\) are convergent power series with
			\begin{align*}
				f(z) = \sum_{n=0}^{\infty} a_n z^n\\
				g(z) = \sum_{n=0}^{\infty} b_n z^{n}.
			\end{align*}
			If \(f(z)=g(z)\) in any infinite set \(A\) with \(0 \in \overline{A}\), then \(f(z)=g(z)\) everywhere-- i.e. \(a_n = b_n\) for all \(n\).
	\end{enumerate}
\end{thm}
\begin{proof}

\end{proof}
This theorem is extremely useful for proving the uniqueness of holomorphic functions, as well as distinguishing holomorphic functions.

\begin{anki}
START
MathJaxCloze
Text:
* Let \(f(z) = \sum_{n=0}^{\infty} a_n z^{n}\) be a non-constant power series with non-zero radius of convergence. If \(f(0) = 0\), then there exists a {{c1::disc of radius \(s>0\)}} such that
{{c1::\(\begin{align*}
        f(z)\neq 0
        \end{align*}\)}}
for all {{c1::\(z \in D(0,s)\setminus\left\{ 0 \right\} \)}}.
* Suppose that \(f,g\) are convergent power series with
\(\begin{align*}
  f(z) = \sum_{n=0}^{\infty} a_n z^n\\
  g(z) = \sum_{n=0}^{\infty} b_n z^{n}.
  \end{align*}\)
If \(f(z)=g(z)\) in {{c2::any infinite set \(A\) with \(0 \in \overline{A}\)}}, then {{c2::\(f(z)=g(z)\) everywhere}}-- i.e. {{c2::\(a_n = b_n\) for all \(n\)::coefficients}}.
Tags: analysis complex_analysis power_series
<!--ID: 1624845303027-->
END
\end{anki}

\begin{prop}[Composition of Power Series]
	Let
	\begin{align*}
		f(z) = \sum_{n=0}^{\infty} a_n z^{n}\\
		g(z) = \sum_{n=0}^{\infty} b_n z^{n}
	\end{align*}
	be convergent power series, and assume that \(b_0 = 0\). If \(f(z)\) is absolutely convergent for \(z \in D(0,R)\), \(R>0\), and there exists an integer \(s>0\) so that
	\begin{align*}
		\sum_{n=0}^{\infty} \left| b_n \right| s^{n} \leq R
	\end{align*}
	then
	\begin{align*}
		h(z) = \sum_{n=0}^{\infty} a_n \left( \sum_{m=0}^{\infty} b_m z^{m} \right)^{n}
	\end{align*}
	converges absolutely for \(z \in D(0,s)\), and within this disc satisfies
	\begin{align*}
		h = f\circ g.
	\end{align*}
\end{prop}

\begin{anki}
START
MathJaxCloze
Text: Let
\(\begin{align*}
  	f(z) = \sum_{n=0}^{\infty} a_n z^{n}\\
  	g(z) = \sum_{n=0}^{\infty} b_n z^{n}
  \end{align*}\)
be convergent power series, and assume that \(b_0 = 0\). If \(f(z)\) is {{c1::absolutely convergent}} for {{c1::\(z \in D(0,R)\)}}, \(R>0\), and there exists {{c1::an integer \(s>0\)}} so that
{{c1::\(\begin{align*}
        	\sum_{n=0}^{\infty} \left| b_n \right| s^{n} \leq R
        \end{align*}\)}}
then
\(\begin{align*}
  	h(z) = \sum_{n=0}^{\infty} a_n \left( \sum_{m=0}^{\infty} b_m z^{m} \right)^{n}
  \end{align*}\)
{{c1::converges absolutely}} for {{c1::\(z \in D(0,s)\)}}, and within this disc satisfies
{{c1::\(\begin{align*}
        	h = f\circ g.
        \end{align*}\)}}
Tags: analysis complex_analysis power_series
<!--ID: 1624845303068-->
END
\end{anki}

There is a slightly more general form of power series that will be useful when discussing holomorphic functions.

\begin{defn}[Laurent Series]
A \textbf{Laurent series} is an infinite sum of monomials
\begin{align*}
	f(z) = \sum_{n-\infty}^{\infty} a_n (z-z_0)^{n}
\end{align*}
where \(\left\{ a_n \right\},z_0  \in \C\) and \(z\) is a complex variable. We say that the Laurent series \textbf{converges absolutely} on \(\Omega \subset \C\) if
\begin{align*}
	f^{+}(z) = \sum_{n=0}^{\infty} a_n (z-z_0)^{n}\\
	f^{-}(z) = \sum_{n=-\infty}^{-1} a_n (z-z_0)^{n}
\end{align*}
converges absolutely on \(\Omega \). Notice that if this holds, then
\begin{align*}
	f = f^{+}+ f^{-}.
\end{align*}
\end{defn}

\begin{anki}
START
MathJaxCloze
Text: A **Laurent series** is an infinite sum of monomials
 {{c1::\(\begin{align*}
         	f(z) = \sum_{n-\infty}^{\infty} a_n (z-z_0)^{n}
         \end{align*}\)}}
where \(\left\{ a_n \right\},z_0  \in \C\) and \(z\) is a complex variable. We say that the Laurent series **converges absolutely** on \(\Omega \subset \C\) if
{{c1::\(\begin{align*}
         	f^{+}(z) = \sum_{n=0}^{\infty} a_n (z-z_0)^{n}\\
         	f^{-}(z) = \sum_{n=-\infty}^{-1} a_n (z-z_0)^{n}
         \end{align*}\)}}
converges absolutely on \(\Omega \). Notice that if this holds, then
 {{c1::\(\begin{align*}
        	f = f^{+}+ f^{-}.
        \end{align*}\)}}
Tags: analysis complex_analysis power_series defn
<!--ID: 1625522318703-->
END
\end{anki}

\subsection{Obtaining Convergence and Absolute Convergence}
\label{sub:obtaining_absolute_convergence}
We will briefly develop a few tools that will help us show a series is absolutely convergent. As discussed earlier, this is a vital step in obtaining holomorphicity of a function.

\begin{thm}[Weierstrass M test]
	Let \(\left\{ f_n \right\} \) be a sequence of real or complex-valued functions, and \(\left\{ A_n \right\} \) a sequence of non-negative real numbers so that
	\begin{align*}
		\left| f_n(z) \right| \leq A_n
	\end{align*}
	for all \(z\) in some region \(\Omega\). If the sum
	\begin{align*}
		\sum_{n=0}^{\infty} A_n
	\end{align*}
	converges, then
	\begin{align*}
		\sum_{n=0}^{\infty} f_n(z)
	\end{align*}
	converges absolutely and uniformly on \(\Omega\).\\

	In this case, we call \(A_n\) a \textbf{majorant} of the \textbf{minorant} \(\left\{ f_n \right\} \).
\end{thm}

\begin{anki}
START
MathJaxCloze
Text: **Weierstrass M-test**
	Let \(\left\{ f_n \right\} \) be a sequence of real or complex-valued functions, and \(\left\{ A_n \right\} \) a sequence of non-negative real numbers so that
	{{c1::\(\begin{align*}
	        	\left| f_n(z) \right| \leq A_n
	        \end{align*}\)}}
	for all \(z\) in some region \(\Omega\). If
	{{c1::\(\begin{align*}
	        	\sum_{n=0}^{\infty} A_n
	        \end{align*}\)}}
	converges, then
	{{c1::\(\begin{align*}
	        	\sum_{n=0}^{\infty} f_n(z)
	        \end{align*}\)}}
	converges absolutely and uniformly on \(\Omega\).

In this case, we call \(A_n\) a **majorant** of the **minorant** \(\left\{ f_n \right\} \).
Tags: analysis complex_analysis power_series
<!--ID: 1624504054101-->
END
\end{anki}

We have another useful tool:

\begin{thm}[Abel's Limit Theorem]
	Let \(G(z)\) be a power series given by
	\begin{align*}
		G(z) = \sum_{n=0}^{\infty} a_n z^{n}
	\end{align*}
	Suppose that the sum below converges:
	\begin{align*}
		\sum_{n=0}^{\infty} a_n = a
	\end{align*}
	for some \(a \in \C\). Then
	\begin{align*}
		\lim_{z \to 1} G(z) = \sum_{n=0}^{\infty} a_n
	\end{align*}
	provided that \(z\) remains within a \textbf{Stolz sector}, that is, satisfies
	\begin{align*}
		\frac{\left| 1-z \right| }{1-\left| z \right| } \leq M
	\end{align*}
	for some \(M \in \R\).
\end{thm}
This is most useful when the radius of convergence of a power series is \(1\), as it can be used to find the limit of the power series from within the disc of convergence. Hence, even if the power series does not have a limit on the radius of convergence, we might be able to obtain an "inner limit" that we can use for calculations.

\begin{anki}
START
MathJaxCloze
Text: **Abel's Limit Theorem**
	Let \(G(z)\) be a power series given by
	\(\begin{align*}
	  	G(z) = \sum_{n=0}^{\infty} a_n z^{n}
	  \end{align*}\)
	Suppose that the sum below converges:
	\(\begin{align*}
	  	\sum_{n=0}^{\infty} a_n = a
	  \end{align*}\)
	for some \(a \in \C\). Then
	{{c1::\(\begin{align*}
	        	\lim_{z \to 1} G(z) = \sum_{n=0}^{\infty} a_n
	        \end{align*}\)}}
	provided that \(z\) remains within a \textbf{Stolz sector}, that is, satisfies
	{{c1::\(\begin{align*}
	        	\frac{\left| 1-z \right| }{1-\left| z \right| } \leq M
	        \end{align*}\)}}
	for some \(M \in \R\).
Tags:  analysis complex_analysis power_series
<!--ID: 1624504054138-->
END
\end{anki}

One last tool that will be helpful is Stirling's formula.

\begin{prop}[Stirling's Formula]
	\begin{align*}
		\sqrt{2\pi n} (n^{n}e^{-n}) \leq n! \leq e\sqrt{n} (n^{n}e^{-n})
	\end{align*}
	for all \(n \in \N\). Furthermore, \(n!\) limits towards the lower bound-- that is,
	\begin{align*}
		\lim_{n \to \infty} \frac{n!}{\sqrt{2\pi n} (n^{n}e^{-n})} =1.
	\end{align*}
	Sometimes, the approximation is written by
	\begin{align*}
		\ln n! \approx n\ln n - n.
	\end{align*}
\end{prop}
This can be useful when comparing power series to show radius of convergence.

\begin{exmp}[Radius of Convergence of Various Series]
	Consider the power series given below by
	\begin{align}
		\sum_{n=0}^{\infty} n! z^{n}\\
		\sum_{n=0}^{\infty} \frac{1}{n!}z^{n}\\
		\sum_{n=0}^{\infty} \frac{n!}{n^{n}}z^{n}\\
	\end{align}
	The radius of convergence of the first power series is 0 because \(\frac{n^{n}}{e^{n}z^{n}}\) is unbounded as \(n\to \infty\). Likewise, \(\frac{z^{n}}{n^{n}e^{n}}\) approaches zero as \(n\to \infty\) and hence the second series has infinite radius of convergence. A similar trick can be used to show that the third series' radius of convergence is \(e\).\\

	In general the ratio test states that if
	\begin{align*}
		\lim_{n \to \infty} \frac{a_{n+1}}{a_n} = A\geq 0
	\end{align*}
	for positive numbers \(a_n\), then
	\begin{align*}
		\lim_{n \to \infty} a_n^{\sfrac{1}{n}}=A.
	\end{align*}
\end{exmp}

\begin{exmp}[Binomial Series]
	Let \(\alpha  \in \C\) be a non-zero complex number. The \textbf{binomial coefficients} are given by
	\begin{align*}
	{\alpha\choose{n}} := \frac{\alpha (\alpha-1)\ldots(\alpha -n+1)}{n!}\\
	{\alpha \choose{0}}=1
	\end{align*}
	and the \textbf{binomial series} by
	\begin{align*}
		B_\alpha (T) := \sum_{n=0}^{\infty} {\alpha \choose{n}}z^{n} = (1+z)^{\alpha }.
	\end{align*}
	One can check that the second equality indeed holds, and in fact the radius of convergence of the binomial series is \(1\) provided that \(\alpha \) is not an integer \(\geq 0\).
\end{exmp}
\begin{proof}
	Observe that
	\begin{align*}
		\left| \frac{ {\alpha \choose{n+1}}}{ {\alpha \choose{n}}} \right| = \left| \frac{\alpha -n}{n+1} \right|
	\end{align*}
	and hence limits to \(1\). By the ratio test, the binomial sum has the radius of convergence desired.
\end{proof}

\end{document}


\documentclass[13pt,onlymath]{beamer}
\usefonttheme{serif}
\usepackage{graphicx,amsmath,amssymb,tikz,psfrag,epstopdf,fancyvrb}
\usepackage[lighttt]{lmodern}
%\usepackage{graphicx,psfrag}

\input defs.tex

%% formatting

\mode<presentation>
{
\usetheme{default}
}
\setbeamertemplate{navigation symbols}{}
\usecolortheme[rgb={0.13,0.28,0.59}]{structure}
\setbeamertemplate{itemize subitem}{--}
\setbeamertemplate{frametitle} {
    \begin{center}
      {\large\bf \insertframetitle}
    \end{center}
}

\newcommand\footlineon{
  \setbeamertemplate{footline} {
    \begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,leftskip=.8cm,rightskip=.6cm]{structure}
      \footnotesize \insertsection
      \hfill
      {\insertframenumber}
    \end{beamercolorbox}
    \vskip 0.45cm
  }
}
\footlineon

\AtBeginSection[]
{
    \begin{frame}<beamer>
        \frametitle{Outline}
        \tableofcontents[currentsection,currentsubsection]
    \end{frame}
}

%% begin presentation

\title{\large \bfseries Combinatorial Games}

\author{Jaehyun Park\\[3ex]
CS 97SI\\
Stanford University}

\date{\today}

\begin{document}

\frame{
\thispagestyle{empty}
\titlepage
}

\begin{frame}{Combinatorial Games}
\BIT
\item Turn-based competitive multi-player games
\item Can be a simple win-or-lose game, or can involve points
\item Everyone has perfect information
\item Each turn, the player changes the current ``state'' using a valid ``move''
\item At some states, there are no valid moves
\BIT
\item The current player immediately loses at these states
\EIT
\EIT
\end{frame}

\section{Simple Games}

\begin{frame}{Combinatorial Game Example}
\BIT
\item Settings: There are $n$ stones in a pile. Two players take turns and remove 1 or 3 stones at a time. The one who takes the last stone wins. Find out the winner if both players play perfectly
\item State space: Each state can be represented by the number of remaining stones in the pile
\item Valid moves from state $x$: $x \rightarrow (x-1)$ or $x \rightarrow (x-3)$, as long as the resulting number is nonnegative
\item State 0 is the losing state
\EIT
\end{frame}

\begin{frame}{Example (continued)}
\BIT
\item No cycles in the state transitions
\BIT
\item Can solve the problem bottom-up (DP)
\EIT
\item A player wins if there is a way to force the opponent to lose
\BIT
\item Conversely, we lose if there is no such a way
\EIT
\item State $x$ is a winning state (W) if
\BIT
\item $(x-1)$ is a losing state,
\item OR $(x-3)$ is a losing state
\EIT
\item Otherwise, state $x$ is a losing state (L)
\EIT
\end{frame}

\begin{frame}{Example (continued)}
\BIT
\item DP table for small values of $n$:

\begin{center}
\begin{tabular}{|c|cccccccc|}
\hline
$n$&0&1&2&3&4&5&6&7 \\ \hline
W/L&L&W&L&W&L&W&L&W \\
\hline
\end{tabular}
\end{center}
\vfill
\item See a pattern?
\vfill
\item Let's prove our conjecture
\EIT
\end{frame}

\begin{frame}{Example (continued)}
\BIT
\item Conjecture: If $n$ is odd, the first player wins. If $n$ is even, the second player wins.
\vfill
\item Holds true for the base case $n=0$
\item In general,
\BIT
\item If $n$ is odd, we can remove one stone and give the opponent an even number of stones
\item If $n$ is even, no matter what we choose, we have to give an odd number of stones to the opponent
\EIT
\EIT
\end{frame}

\section{Minimax Algorithm}

\begin{frame}{More Complex Games}
\BIT
\item Settings: a competitive zero-sum two-player game
\item Zero-sum: if the first player's score is $x$, then the other player gets $-x$
\item Each player tries to maximize his/her own score
\item Both players play perfectly
\vfill
\item Can be solved using a \emph{minimax} algorithm
\EIT
\end{frame}

\begin{frame}{Minimax Algorithm}
\BIT
\item Recursive algorithm that decides the best move for the current player at a given state
\item Define $f(S)$ as the optimal score of the current player who starts at state $S$
\item Let $T_1, T_2, \ldots, T_m$ be states can be reached from $S$ using a single move
\item Let $T$ be the state that minimizes $f(T_i)$
\item Then, $f(S) = -f(T)$
\BIT
\item Intuition: minimizing the opponent's score maximizes my score
\EIT
\EIT
\end{frame}

\begin{frame}{Memoization}
\BIT
\item (Not \emph{memorization} but \emph{memoization})
\item A technique used to avoid repeated calculations in recursive functions
\item High-level idea: take a note (memo) of the return value of a function call. When the function is called with the same argument again, return the stored result
\item Each subproblem is solved at most once
\BIT
\item Some may not be solved at all!
\EIT
\EIT
\end{frame}

\begin{frame}[fragile]{Recursive Function without Memoization}
\begin{Verbatim}[xleftmargin=25pt]
int fib(int n)
{
    if(n <= 1) return n;
    return fib(n - 1) + fib(n - 2);
}
\end{Verbatim}
\vfill
\BIT
\item How many times is \verb,fib(1), called?
\EIT
\end{frame}

\begin{frame}[fragile]{Memoization using \texttt{std::map}}
\begin{Verbatim}[xleftmargin=25pt]
map<int, int> memo;
int fib(int n)
{
    if(memo.count(n)) return memo[n];
    if(n <= 1) return n;
    return memo[n] = fib(n - 1) + fib(n - 2);
}
\end{Verbatim}
\vfill
\BIT
\item How many times is \verb,fib(1), called?
\EIT
\end{frame}

\begin{frame}{Minimax Algorithm Pseudocode}
\BIT
\item Given state $S$, want to compute $f(S)$
\vfill
\item If we know $f(S)$ already, return it
\item Set return value $x \leftarrow -\infty$
\item For each valid next state $T$:
\BIT
\item Update return value $x \leftarrow \max\{x, -f(T)\}$
\EIT
\item Write a memo $f(S) = x$ and return $x$
\EIT
\end{frame}

\begin{frame}{Possible Extensions}
\BIT
\item The game is not zero-sum
\BIT
\item Each player wants to maximize his own score
\item Each player wants to maximize the difference between his score and the opponent's
\EIT
\item There are more than two players
\vfill
\item All of above can be solved using a similar idea
\EIT
\end{frame}

\section{Nim Game}

\begin{frame}{Nim Game}
\BIT
\item Settings: There are $n$ piles of stones. Two players take turns. Each player chooses a pile, and removes any number of stones from the pile. The one who takes the last stone wins. Find out the winner if both players play perfectly
\vfill
\item Can't really use DP if there are many piles, because the state space is huge
\EIT
\end{frame}

\begin{frame}{Nim Game Example}
\BIT
\item Starts with heaps of 3, 4, 5 stones
\BIT
\item We will call them heap A, heap B, and heap C
\EIT
\vfill
\item Alice takes 2 stones from A: $(1, 4, 5)$
\item Bob takes 4 from C: $(1, 4, 1)$
\item Alice takes 4 from B: $(1, 0, 1)$
\item Bob takes 1 from A: $(0, 0, 1)$
\item Alice takes 1 from C and wins: $(0, 0, 0)$
\EIT
\end{frame}

\begin{frame}{Solution to Nim}
\BIT
\item Given heaps of size $n_1, n_2, \ldots, n_m$
\item The first player wins if and only if the \emph{nim-sum} $n_1 \oplus n_2 \oplus \cdots \oplus n_m$ is nonzero ($\oplus$ is bitwise XOR operator)
\vfill
\item Why?
\BIT
\item If the nim-sum is zero, then whatever the current player does, the nim-sum of the next state is nonzero
\item If the nim-sum is nonzero, it is possible to force it to become zero (not obvious, but true)
\EIT
\EIT
\end{frame}

\section{Grundy Numbers (Nimbers)}

\begin{frame}{Playing Multiple Games at Once}
\BIT
\item Suppose that multiple games are played at the same time. At each turn, the player chooses a game and make a move. You lose if there is no possible move. We want to determine the winner
\EIT
\begin{center}
\includegraphics[height=0.5\textheight]{figures/games}

Figure from \url{http://sps.nus.edu.sg/~limchuwe/cgt/}
\end{center}
\end{frame}

\begin{frame}{Grundy Numbers (Nimbers)}
\BIT
\item For each game, we compute its \emph{Grundy number}
\item The first player wins if and only if the XOR of all the Grundy numbers is nonzero
\BIT
\item For example, the Grundy number of a one-pile version of the nim game is equal to the number of stones in the pile (we will see this again later)
\EIT
\vfill
\item Let's see how to compute the Grundy numbers for general games
\EIT
\end{frame}

\begin{frame}{Grundy Numbers}
\BIT
\item Let $S$ be a state, and $T_1, T_2, \ldots, T_m$ be states can be reached from $S$ using a single move
\vfill
\item The Grundy number $g(S)$ of $S$ is the smallest nonnegative integer that doesn't appear in $\{g(T_1), g(T_2), \ldots, g(T_m)\}$
\BIT
\item Note: the Grundy number of a losing state is 0
\item Note: I made up the notation $g(\cdot)$. Don't use it in other places
\EIT
\EIT
\end{frame}

\begin{frame}{Grundy Numbers Example}
\BIT
\item Consider a one-pile nim game
\item $g(0) = 0$, because it is a losing state
\item State 0 is the only state reachable from state 1, so $g(1)$ is the smallest nonnegative integer not appearing in $\{g(0)\} = \{0\}$. Thus, $g(1) = 1$
\item Similarly, $g(2) = 2$, $g(3) = 3$, and so on
\item Grundy numbers for this game is then $g(n) = n$
\BIT
\item That's how we got the nim-sum solution
\EIT
\EIT
\end{frame}

\begin{frame}{Another Example}
\BIT
\item Let's consider a variant of the game we considered before; only 1 or 2 stones can be removed at each turn
\item Now we're going to play many copies of this game at the same time
\item Grundy number table:

\begin{center}
\begin{tabular}{|c|cccccccc|}
\hline
$n$&0&1&2&3&4&5&6&7 \\ \hline
$g(n)$&0&1&2&0&1&2&0&1 \\
\hline
\end{tabular}
\end{center}
\EIT
\end{frame}

\begin{frame}{Another Example (continued)}
\BIT
\item Grundy number table:

\begin{center}
\begin{tabular}{|c|cccccccc|}
\hline
$n$&0&1&2&3&4&5&6&7 \\ \hline
$g(n)$&0&1&2&0&1&2&0&1 \\
\hline
\end{tabular}
\end{center}
\vfill
\item Who wins if there are three piles of stones $(2, 4, 5)$?
\item What if we start with $(5, 11, 13, 16)$?
\item What if we start with $(10^{100}, 10^{200})$?
\EIT
\end{frame}

\begin{frame}{Tips for Solving Game Problems}
\BIT
\item If the state space is small, use memoization
\item If not, print out the result of the game for small test data and look for a pattern
\BIT
\item This actually works really well!
\EIT
\item Try to convert the game into some nim-variant
\item If multiple games are played at once, use Grundy numbers
\EIT
\end{frame}

\end{document}


\documentclass[11pt]{article}
%\usepackage[firstpage]{draftwatermark}
\usepackage{times}
\usepackage{pdfpages}
\usepackage{fullpage}
\usepackage{url}
\usepackage{hyperref}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{enumitem}
\usepackage{indentfirst}
\usepackage{subcaption}
\usepackage{units}
\usepackage{bm}

\usepackage{./math_bbing}

% Highlighting
\usepackage{color,soul}
\DeclareRobustCommand{\hlr}[1]{{\sethlcolor{red}\hl{#1}}}
\DeclareRobustCommand{\hlg}[1]{{\sethlcolor{green}\hl{#1}}}
\DeclareRobustCommand{\hlb}[1]{{\sethlcolor{blue}\hl{#1}}}
\DeclareRobustCommand{\hly}[1]{{\sethlcolor{yellow}\hl{#1}}}

\setcounter{secnumdepth}{4}
\graphicspath{{images/}}
\pagestyle{fancy}

% Conditional for notes
\newif\ifnotes
\notesfalse

\newcommand{\doctitle}{USV Plugins, Theory of Operation}

\newcommand{\docnumber}{\doctitle}

\addtolength{\headheight}{2em}
\addtolength{\headsep}{1.5em}
\lhead{\docnumber}
\rhead{}

\newcommand{\capt}[1]{\caption{\small \em #1}}

\cfoot{\small Brian Bingham \today \\ \thepage}
\renewcommand{\footrulewidth}{0.4pt}

\newenvironment{xitemize}{\begin{itemize}\addtolength{\itemsep}{-0.75em}}{\end{itemize}}
\newenvironment{tasklist}{\begin{enumerate}[label=\textbf{\thesubsubsection-\arabic*},ref=\thesubsubsection-\arabic*,leftmargin=*]}{\end{enumerate}}
\newcommand\todo[1]{{\bf TODO: #1}}
\setcounter{tocdepth}{2}
\setcounter{secnumdepth}{4}

\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

%\renewcommand{\chaptername}{Volume}
%\renewcommand{\thesection}{\Roman{section}}
%\renewcommand{\thesubsection}{\Roman{section}-\Alph{subsection}}

\begin{document}
\input{./Commands}
\input{./defs}
\newpage
% Title Page
\setcounter{page}{1}
\begin{center}
{\huge \doctitle}
\end{center}

\section{Overview}
The rigid body dynamics implemented in Gazebo are augmented with environmental forces to simulate an unmanned surface vessel via a set of Gazebo plugins.  These plugins simulate the effects of
\begin{itemize}
\item Dynamics
  \begin{itemize}
  \item Maneuvering - added mass, drag, etc.
  \item Wave field - motion of the water surface
  \end{itemize}
\item Thrust - vehicle propulsion
\item Wind - windage.
  \end{itemize}

This document is a high-level description of the implementation, but not a full documentation of the models and techniques used.  The code itself is the ultimate documentation; comments have been included in the source to allow for users to adapt and extend these simple techniques for their own purposes.

\section{Maneuvering Model and Waves}
The influence of both maneuvering and wave forces on the motion of the USV is implemented as a single model plugin for Gazebo.  Currently there is only one implementation, but other implementations, with varying fidelity, could be developed in the future.

\subsection{usv gazebo dynamics plugin}

\subsubsection{Maneuvering Model}
The plugin implements a portion of the nonlinear maneuvering equations from \cite{fossen11handbook},
\beqn
\underbrace{\bm{M}_{RB}\dot{\bm{\nu}}+\bm{C}_{RB}(\bm{\nu})\bm{\nu}}_\text{rigid-body forces} +
\underbrace{\bm{M}_A\dot{\bm{\nu}}_r + \bm{C}_A(\bm{\nu}_r)\bm{\nu}_r +
\bm{D}(\bm{\nu}_r)\bm{\nu}_r}_\text{hydrodynamic forces}
= \bm{\tau}+\bm{\tau}_{wind}+\bm{\tau}_{waves}
\label{e:fossenmodel}
\eeqn
where the state vector $\bm{\nu}=[u,v,r]^T$ includes the velocities $u$, $v$ and $r$ are in the surge, sway and yaw directions respectively and  $\bm{\nu}_r$ is the velocity vector relative to an irrotational water current $\bm{\nu}_c$, i.e., $\bm{\nu}=\bm{\nu}_r+\bm{\nu}_c$.
The \emph{rigid-body forces} components are simulated via the Gazebo physics engine, while the \emph{hydrodynamic forces} are determined via the plugin.

The six DOF maneuvering model is specified by the following matrices. The added mass matrix expressed as
\beqn
\bm{M}_{A}= \left[
\begin{array}{cccccc}
-X_{\dot{u}} & 0 & 0 &0 &0 &0 \\
0 & -Y_{\dot{v}} & 0 &0 &0 &0 \\
0 & 0  &0.1 &0 &0 &0 \\
0 &0 &0 &0.1 &0 &0 \\
0 &0 &0 &0 &0.1 &0 \\
0 &0 &0 &0 & 0 & -N_{\dot{r}}
\end{array} \right].
\eeqn
The Coriolis-centripetal matrix for the added mass expressed as
\beqn
\bm{C}_{A}(\bm{\nu}_r)= \left[
\begin{array}{cccccc}
0 &0 &0 &0 & 0 & Y_{\dot{v}}v_r+Y_{\dot{r}}r \\
0 &0 &0 &0 & 0 & -X_{\dot{u}}u_r\\
0 &0 &0 &0 &0 &0 \\
0 &0 &0 &0 &0 &0 \\
0 &0 &0 &0 &0 &0 \\
0 &0 &0 & -Y_{\dot{v}}v_r - Y_{\dot{r}}r& X_{\dot{u}}u_r & 0
\end{array} \right].
\eeqn.
It is worth noting that $\bm{C}_A$ includes the nonlinear Munk moment (see \cite{fossen11handbook} p.121).  Following \cite{fossen11handbook} the SNAME notation for the hydrodynamic derivatives.  Currently these terms are neglected in the model for simplicity and because of the challenges in estimating and verifying the pertinent parameters.

The linear and quadratic drag terms
\beqn
\bm{D}(\bm{\nu}_r)= \left[
\begin{array}{cccccc}
X_u + X_{u|u|}|u| & 0 & 0 &0 &0 &0\\
0 & Y_v + Y_{v|v|}|v| &0  &0 &0 &0\\
0 &0 &Z_w  &0 &0 &0 \\
0 &0 &0 &K_p  &0 &0 \\
0 &0 &0 &0 &M_q &0 \\
0 &0 &0 &0 &0 & N_r+N_{r|r|}|r|
\end{array} \right].
\eeqn
which neglects coupleing between sway and yaw.

\subsubsection{Wave Forcing}

Gerstner waves with three components \cite{tessendorf99simulating}.  Each of the component waves is user-specified by an amplitude, period and direction.  Deep water dispersion is used in simulating the wave behaviors.

To determine the influence of the wave field on the vessel, the vessel footprint is decomposed into a simple grid, with points at each corner of the vessel.  The vertical displacement is calculated for each of these points.  Using the vessel's position and attitude, the buoyancy force at each location is determined and then applied at that grid point.

\section{Thrust}
The external force and torque from the vessel propulsion is implemented in a standalone plugin to allow for independent extension to higher-fidelity thrust configurations and models.

\subsection{usv gazebo thrust plugin}
The plugin subscribes the \verb+cmd_drive+ topic to receive messages of type UsvDrive (defined in the \verb+usv_msgs+ package).  These message specify left and right thrust commands where the commands are scaled from $\{-1.0-1.0\}$.

To emulate the thruster behavior, the commands are mapped to a thrust force applied to the model.  Two possible mappings are currently available.  Users select which mapping using the \verb+mappingType+ SDF tag.

The axial force is applied at a point vertically separated from the CG as specified by the \texttt{thrustOffsetZ} parameter.  This results in coupling between the forward thrust and the vehicle pitch.

\subsubsection{0: Linear thruster map}
The command values (-1.0 to 1.0) are scaled linearly to the \texttt{maxForceFwd} and \texttt{maxForceRev} SDF parameters.  A total forward thrust is caculated as the sum.  A total torque is calculated assuming the two thrust forces are applied at opposite ends of the \texttt{boatWidth} parameter.

\subsubsection{1: GLF thruster map}

In this mode two generalized logistic functions (GLFs) are used to convert commands to thrust force.  One set of GLF parameters are used for positive commands (0 to 1.0) and a second set of parameters are used for negative commands (-1 to 0).  The form of the GLF used is
\begin{equation}
  T = A + \frac{K-A}{\left(C+\exp(-B(x-M))\right)^{1/\nu}}
\end{equation}
where $T$ is the thrust force in Newtons, $x$ is the command and the remaining variables are the GLF parameters.  To identify the GLF parameters, the data from
\cite{sarda17station} was used---Figure\ref{f:sarda}.  The Python script for accomplishing this is include in the \verb+usv_gazebo_plugins+ repository in the \verb+thrust_curve_fit+ directory.

\begin{figure}[h]
  \centering
  \includegraphics[width=0.6\textwidth]{images/sarda_tcurve.png}
  \caption{Empirical thrust performance data from \cite{sarda17station}.}
  \label{f:sarda}
\end{figure}

The data was fit with two separate GLF functions using the \verb+scipy.optimize.fmin+ optimization routine to minimize the squared error.  The results are shown in Figure\ref{f:fit}.

\begin{figure}[h]
  \centering
  \includegraphics[width=0.6\textwidth]{images/wamv_glf_annote.png}
  \caption{GLF fit of empirical data.}
  \label{f:fit}
\end{figure}

\section{Wind}

The influence of wind on the motion of the USV is implemented as a standalone model plugin for Gazebo.  Currently there is only one implementation, but other implementations, with varying fidelity, could be developed in the future.

\subsection{usv gazebo wind plugin}

The wind forces (x and y) and moment (yaw) are predicted following the models presented by Fossen~\cite{fossen94guidance}.

The wind velocity on the vessel ($V_w$) is considered to be a constant velocity and direction.  If desired, this could be extended to include a parameterized wind spectrum the distribution of wind velocities over time, e.g., average wind velocity, gusts, etc.  For the current implementation the constant wind velocity is specified as a three element vector which specifies the wind speed the world-frame x, y and z coordinates with units of \unitfrac[]{m}{s}.  The z component is ignored.

The resulting forces and moments on the vessel are determined based on the user-specified force/moment coefficients and the relative wind velocity.  Within the plugin, the relative (or apparent) wind velocity vector $V_R$.  The forces/moment are calculated as
\begin{eqnarray}
  X_{wind} &=& (C_X) V_{R_x} |V_{R_x}| \\
  Y_{wind} &=& (C_Y) V_{R_y} |V_{R_y}| \\
  N_{wind} &=& -2.0 (C_N) V_{R_x} V_{R_y} \\
\end{eqnarray}
where $C_X$, $C_Y$ and $C_N$ are specified as the three element \verb+wind_coeff_vector+.  Approximate values for these coefficients are given in \cite{sarda17station} which can then be tuned to give reasonable response.

%\newpage
%\setcounter{page}{1}
\bibliographystyle{ieeetr}
\bibliography{refs}

\end{document}


\subsection{Rngs}

A rng is a ring without the multiplicative identity (hense no 'i').


\section{\hogwild}

Prior to 2011, parallel stochastic gradient methods had been introduced, but
most suffered from poor scaling due to the necessity of locks. A naive
implementation could look like:
\begin{breakablealgorithm}
  \caption{Very Naive Parallel Stochastic Gradient}
  \label{alg:naivePSG}
  \begin{algorithmic}[1]
    \Require Number of data points $N$, seperable loss function $f
    = \sum_{e \in E} f_e(x_e)$, Initial $x$.
    \For{epoch $= 1 \to$ MAX\_EPOCHS}
      \State \#pragma omp parallel for
      \For{$k = 1 \to N$}
        \State Choose $i$ uniformly from $\{1, \dots, |E|\}$.
        \State \#pragma omp critical
        \Indent
          \State Read current parameters $x$.
          \State Compute $\nabla f_i(x)$.
          \State $x \gets x - \eta \nabla f_i(x)$.
        \EndIndent
      \EndFor
    \EndFor
  \end{algorithmic}
\end{breakablealgorithm}
Note that the version presented above is one with a fixed number of iterations,
as the discussion of stopping criteria seems to be similar to that of the
stochastic gradient method, and for extremely large data sets, is often
heuristic. But it's clear here that such an algorithm would only effectively be
parallelizing the unform sample of $i$ in $\{1, \dots, |E|\}$, and it's overall
parallel efficiency would likely be poor. Technically, you can improve the above
by replacing the critical section with selective locks on components of $x$
based on the sparsity pattern of $\nabla f_i(x)$, but because the process of
acquiring locks is much more expensive than floating point arithmetic, this
helps little.

However, in 2011, the article "\hogwild: A Lock-Free Approach to Parallelizing
Stochastic Gradient Descent" by Niu et al. \cite{2011NRRW} proposed a very
simple solution to this problem. Remove the locks!%
\footnote{
  Apparently this was discovered by accident by Feng Niu, one of the original
  paper's authors, when he was debugging stochastic gradient method code. I wish
  my troubleshooting was nearly as effective... \cite{2014Recht}
} \clearpage
\begin{breakablealgorithm}
  \caption{\hogwild: Asynchronous Stochastic Gradient with replacement}
  \label{alg:hogwildwreplacement}
  \begin{algorithmic}[1]
    \Require Number of data points $N$, seperable loss function $f
    = \sum_{e \in E} f_e(x_e)$, Initial $x$.
    \For{epoch $= 1 \to$ MAX\_EPOCHS}
      \State \#pragma omp parallel for
      \For{$k = 1 \to N$}
        \State Choose $i$ uniformly from $\{1, \dots, |E|\}$.
        \State Read current parameters $x$.
        \State Compute $\nabla f_i(x)$.
        \State $x \gets x - \eta \nabla f_i(x)$. \Comment{Must be done
        atomically}
      \EndFor
    \EndFor
  \end{algorithmic}
\end{breakablealgorithm}
and should we want to sample without replacement the algorithm is easily
modified to:
\begin{breakablealgorithm}
  \caption{\hogwild: Asynchronous Stochastic Gradient without replacement}
  \label{alg:hogwildworeplacement}
  \begin{algorithmic}[1]
    \Require Number of data points $N$, seperable loss function $f
    = \sum_{e \in E} f_e(x_e)$, Initial $x$.
    \For{epoch $= 1 \to$ MAX\_EPOCHS}
      \State Let $P$ be a random permutation of $\{1, \dots, |E|\}$.
      \Comment{i.e. a Fisher-Yates Shuffle.}
      \State \#pragma omp parallel for
      \For{$k = 1 \to N$}
        \State $i \gets P[k]$.
        \State Read current parameters $x$.
        \State Compute $\nabla f_i(x)$.
        \State $x \gets x - \eta \nabla f_i(x)$. \Comment{Must be done
        atomically}
      \EndFor
    \EndFor
  \end{algorithmic}
\end{breakablealgorithm}

It should be noted that although the formal OMP locks have been removed, atomic
operations are still required in order to prevent mutual exclusion. However, no
guards have been placed to prevent a thread from overwriting another's
computation midway through, and it's not obvious as to why such a race condition
wouldn't destroy the performance of the Stochastic Gradient method. However,
with certain assumptions one can show that \hogwild\ behaves roughly like a noisy
stochastic gradient method, and thus shares its convergence properties.


We performed classification experiments on LSA16, RWTH and CIARP  handshape datasets. For each experiment, we split the dataset in training and test sets, with the latter taking 25\% of the samples.  The split was stratified,  maintaining the proportion of samples of each class in both sets.

We applied normalization feature-wise substracting the mean and dividing by the standard deviation of each feature. For data augmentation we used horizontal flipping, a 10 and 30 degree rotation and a resampling of the images creating new versions of them with a different size reducing each image by 10\% and 20\% in width and height. We found that a 10 degree rotation gave better results because a rotation of 30 degrees showed to be too high for the nature of the datasets.

We made multiple experiments with Prototypical Networks and DenseNet to find out which hyperparameter configuration was the best for each dataset: with and without data augmentation. We describe the hyper parameters for each model/dataset combination.

\subsection{Prototypical Network}

As mentioned in section \ref{models:protonet}, we can use Prototypical Networks' ability to work with small datasets even if all samples are labeled.

Therefor we experimented with Prototypical Networks using an embedding architecture composed of four convolutional blocks. Each block comprises a \{64, 128\}-filter $3 x 3$ convolution, batch normalization layer, a ReLU nonlinearity and a $2 x 2$ max-pooling layer.

We used the same encoder for embedding both support and query points. All of our models were trained  with the ADAM\cite{Adam} optimizer. We used an initial learning rate of $10^{-3}$ and cut the learning rate in half every 2000 episodes.

We trained prototypical networks using Euclidean distance in the 1-shot and 5-shot scenarios with training episodes containing 16, 20 and 10 classes (for LSA16, RWTH and CIARP respectively) and 5 query points per class. We found it advantageous to match the same value of n for train and test scenarios, and to use a higher value of k (more classes) per training episode. We computed classification accuracy for our models by averaging over 1000 randomly generated episodes from the test set.

In the experiments performed with RWTH we used the same four-block embedding architecture by adding an eight-block architecture with the same layer composition with the idea of analyzing the need to increase the size of the network given the difficulty of the dataset. The difference in the results obtained in 1-shot and 5-shot scenarios for this dataset was very large. We found that 5-shot scenarios gave better results. Using this discovery we only used 5-shot learning in the remaining experiments.

The best configurations for all datasets is the 5-shot scenario with equals n for train and test scenarios by using more than or equal to 5 classes per training episode. Better results were obtained when the number of classes approaches the total amount of classes in the dataset except on CIARP where the best results were obtained when the number of classes per training episode is 5. In addition, the best configurations of the embedding architecture is a 64-filter for all datasets.

\subsection{Wide-DenseNet}

We employed a variation on DenseNet called Wide-DenseNet which follows the strategy used by wide residual networks.\cite{He2015DeepRL}.

We employed a Wide-DenseNet including SE blocks after each dense and transition block. We performed a grid search of hyperparameters to find the model with the best accuracy, averaged over all datasets. We tried growth rate values of 32, 64 and 128 and depth of dense layers of no more than [6,12,24,16], where each number represents the number of dense blocks.

We trained the models using a batch size of 16, an initial learning rate of $10^{-3}$ with categorical cross entropy optimizer and 400 epochs with a maximum patience of 25. The resulting model used a growth rate of 64 and two dense blocks with 6 and 12 layers respectively,  for all datasets.

\subsection{Results}

In table \ref{tab:results}, we can observe that all models have a lower accuracy on the RWTH dataset, which is expected since it has more classes, unsegmented hand images and class imbalances. Prototypical Networks have similar accuracy for LSA16 and CIARP datasets beating the rest of the models, also expected since both datasets have very few examples. For LSA16 they achieve better accuracy than VGG16 and DenseNet; and for CIARP they achieve similar or better accuracy than LeNet CNN and DenseNet. The accuracy of DenseNet on the RWTH is slightly bigger than for other models. Our hypothesis was that Prototypical Networks obtained low accuracy because the images of the hands were unsegmented. It should be noted that the use of data augmentation did not bring significant improvements in the accuracy obtained in LSA16 and CIARP.

Another fact to consider is that better results were obtained with those parameters that reduced the size of the architectures.

\begin{table}[h!]
\centering
\begin{tabular}{ p{17em} p{6em} p{6em} p{6em}}
\toprule
\emph{Method} & \emph{LSA16} &  \emph{RWTH}  &  \emph{CIARP} \\ \midrule
LeNet \cite{ciarp2018} & - & - & 99.20  \\
Inception (fine-tuning) \cite{koller16} & - & 85.50 \\
VGG16 \cite{quiroga2017study} & 95.92 & 82.88 \\
Inception+SVM (pre-trained) \cite{quiroga2017study} &  93.67 & 78.12 & - \\
DenseNet  & 98.07 & 91.10 & 99.93 \\
DenseNet ++  & 98.90 & \textbf{94.00} & 99.99 \\
Prototypical Networks  & 99.15 & 79.93 & 99.98 \\
Prototypical Networks ++ & \textbf{99.26} & 80.85 & \textbf{100.00} \\
\bottomrule
\end{tabular}
\caption{Accuracy of various convolutional neural network based models on three datasets: LSA16, RWTH and CIARP. Models with "++" used data augmentation as described in this section. \label{tab:results}}
\end{table}

In figure \ref{fig:results_varying_samples}, we can observe the accuracy of Prototypical Networks and DenseNet models trained by varying sample sizes. We performed experiments using the same embedding architectures and configurations described in this section varying the training sample sizes with percentages of 44\%, 67\% and 85\% and a fixed test size of 25\%. From the obtained results, we can see that the performance of the DenseNet models increases as more training examples are provided. From figure \ref{fig:results_varying_samples_rwth} we can see that the DenseNet model trained using data augmentation obtains better results than the one trained without. On the other hand, Prototypical Networks models do not show a significant increase in performance as the percentage of samples increases. In figures \ref{fig:results_varying_samples_rwth} and \ref{fig:results_varying_samples_ciarp} we can observe how the use of data augmentation, on RWTH and CIARP datasets respectively, results in Prototypical Networks models with great accuracy improvement compared to the results obtained on LSA16, figure \ref{fig:results_varying_samples_lsa16}), where the increase of performance from the use of data augmentation is minimal.

\begin{figure}[h]
\begin{tabular}{ccc}
    \subfigure[LSA16]{\includegraphics[width=0.32\columnwidth]{results/lsa16.png} \label{fig:results_varying_samples_lsa16}} & \subfigure[RWTH]{\includegraphics[width=0.32\columnwidth]{results/rwth.png} \label{fig:results_varying_samples_rwth}} & \subfigure[CIARP]{\includegraphics[width=0.32\columnwidth]{results/ciarp.png} \label{fig:results_varying_samples_ciarp}} \\
\end{tabular}
\caption{Accuracy of Prototypical Networks and DenseNet models trained by varying sample sizes on three datasets: LSA16, RWTH and CIARP. Each plot represents a different dataset where the x-axis is the percentage of samples used and the y-axis is the accuracy obtained. Models with "++" used data augmentation as described in this section. \label{fig:results_varying_samples}}
\end{figure}


\subsection{Stackleberg competition}

Sequential Cournot competition.

There is a first-mover advantage.


\chapter{A Non-Equilibrium Green's Function (NEGF) Based Magnetic Tunnel Junction (MTJ) Simulator in MATLAB\texttrademark}

\section{Introduction}

The Non-Equilibrium Green's Function (NEGF) based transport model was proposed in \cite{Salahuddin2007e,Datta2012b}. This document presents an implementation of a MATLAB\texttrademark{} based solver that calculates the $I-V$ characteristics of a magnetic tunnel junction (MTJ) using the proposed model. The NEGF model is based on the single band effective mass Hamiltonian ($\mathcal{H}$) and self-energy ($\Sigma_{L,R}$) which are used to calculate Green's function ($G$), electron correlation matrix ($G^n$) and charge current density ($J$). Fig.~\ref{fig:negf_grid} shows the device structure and coordinate system used for modeling MTJs. In a 1-D system, the Hamiltonian may be written for five regions: (a) the left ferromagnet (FM) contact, (b) the right FM contact, (c) the oxide channel, (d) the left FM-oxide interface, and (d) the right oxide-FM interface. Generally, the Hamiltonian, $\mathcal{H}$, may be written as \begin{equation}
\mathcal{H}=\left[\begin{IEEEeqnarraybox}[\scriptsize][c]{/c/c/c/c/c/c/c/c/c/c/c/}
\alpha_{HL1} & \beta_{HL1} & 0 & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & 0 \\
\beta^{\dagger}_{HL1} & \ddots & \ddots & \ddots & ~ & ~ & ~ & ~ & ~ & ~ & \vdots \\
0 & \ddots & \alpha_{HL1} & \beta_{HL1} & \ddots & ~ & ~ & ~ & ~ & ~ & \vdots \\
\vdots & \ddots & \beta^{\dagger}_{HL1} & \alpha_{IL} & \beta_{OX} & \ddots & ~ & ~ & ~ & ~ & \vdots \\
\vdots & ~ & \ddots & \beta^{\dagger}_{OX} & \alpha_{OX} & \ddots & \ddots & ~ & ~ & ~ & \vdots \\
\vdots & ~ & ~ & \ddots & \ddots & \ddots & \ddots & \ddots & ~ & ~ & \vdots \\
\vdots & ~ & ~ & ~ & \ddots & \ddots & \alpha_{OX} & \beta_{OX} & \ddots & ~ & \vdots \\
\vdots & ~ & ~ & ~ & ~ & \ddots & \beta^{\dagger}_{OX} & \alpha_{IR} & \beta_{HL2} & \ddots & \vdots \\
\vdots & ~ & ~ & ~ & ~ & ~ & \ddots & \beta^{\dagger}_{FM,R} & \alpha_{HL2} & \ddots & 0 \\
\vdots & ~ & ~ & ~ & ~ & ~ & ~ & \ddots & \ddots & \ddots & \beta_{HL2} \\
0 & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & 0 & \beta^{\dagger}_{HL2} & \alpha_{HL2}
\end{IEEEeqnarraybox}\right]\label{eq:genHam}
\end{equation}where the number of $\alpha_{HL1}$, $\alpha_{OX}$ and $\alpha_{HL2}$ correspond to the number of grid points to model the left FM contact, the oxide channel, and the right FM contact, respectively, in the direction of electron transport (the \emph{longitudinal} direction). When a 1-D problem is considered (refer to Fig.~\ref{fig:negf_grid}), we write \afterpage{
\begin{figure}[!t]
\centering
\includegraphics[scale=0.75]{ResearchNotes_NEGF/figs/simframe/negf_grid.eps}
\caption{Illustration of the reference axis (left) and Non-Equilibrium Green's Function based description of the magnetic tunnel junction (right). The reference axis shows how magnetization angles are named in this work. The coupling between lattice sites are $t_{FM}$ and $t_{OX}$ and individual lattice sites are described by the Hamiltonian $\alpha_{HL1}$, $\alpha_{HL2}$ and $\alpha_{OX}$. The complete Hamiltonian describing the MTJ is written in terms of $t_{FM}$, $t_{OX}$, $\alpha_{HL1}$, $\alpha_{HL2}$ and $\alpha_{OX}$.}
\label{fig:negf_grid}
\end{figure}\begin{figure}[!t]
\centering
\includegraphics[scale=0.75]{ResearchNotes_NEGF/figs/simframe/negf_grid.eps}
\caption{Temp holder}
\label{fig:bandDiags}
\end{figure}
\clearpage
}\begin{IEEEeqnarray}{rCl}
\alpha_{HL1}&=&\alpha_{FM,L} = 2t_{FM,Left}I \\
\alpha_{HL2}&=&\alpha_{FM,R} = 2t_{FM,Right}I \\
\alpha_{OX}&=&\alpha_{Ch} = 2t_{OX}I \\
\alpha_{IL}&=&\frac{\alpha_{OX}+\alpha_{FM,L}}{2} \\
\alpha_{IR}&=&\frac{\alpha_{OX}+\alpha_{FM,R}}{2} \\
\beta_{HL1}&=&\beta_{FM,L} = -t_{FM,Left}I \\
\beta_{HL2}&=&\beta_{FM,R} = -t_{FM,Right}I \\
\beta_{OX}&=&-t_{OX}I
\end{IEEEeqnarray} where $I$ is the $2\times{}2$ identity matrix. Then, effective masses are used to write \begin{IEEEeqnarray}{rCl}
t_{FM,Left}&=&\frac{\hbar^{2}}{2m^{*}_{FM,Left}a^{2}} \\
t_{FM,Right}&=&\frac{\hbar^{2}}{2m^{*}_{FM,Right}a^{2}} \\
t_{OX}&=&\frac{\hbar^{2}}{2m^{*}_{OX}a^{2}}
\end{IEEEeqnarray}where $a$ is the uniform grid spacing, $\hbar=\frac{h}{2\pi}$ is the reduced Planck constant, and $m^{*}_{OX}$, $m^{*}_{FM,Left}$, and $m^{*}_{FM,Right}$ are the effective electron masses in the oxide channel, the left FM contact, and the right FM contact, respectively. Note that the on-site energy at every grid point is represented by a $2\times{}2$ matrix to handle the spin degeneracy when $\mathcal{H}$ is written this way.

In a ferromagnetic material, the conduction bands for up-spin and down -spin electrons are split. As illustrated in Fig.~\ref{fig:bandDiags}, $U_{b}$ is the barrier height of the tunnel barrier, and $\Delta_{L}$ and $\Delta_{R}$ are the splitting energies between the bottom of the conduction bands for up-spin and down-spin electrons in the left FM contact and right FM contact, respectively. The potential barrier of the tunnel oxide is included in $\mathcal{H}$ by writing \begin{IEEEeqnarray}{rCl}
\alpha_{OX}&=&\alpha_{Ch}+U_{b}I \\
\alpha_{IL}&=&0.5\times\left(\alpha_{OX}+\alpha_{FM,L}+U_{b}\right) \\
\alpha_{IR}&=&0.5\times\left(\alpha_{OX}+\alpha_{FM,R}+U_{b}\right)
\end{IEEEeqnarray}where $I$ is the $2\times{}2$ identity matrix. Then, to include the conduction band splitting, we rewrite \begin{IEEEeqnarray}{rCl}
\alpha_{HL1}&=&\alpha_{FM,L}+U_{split,L} \\
\alpha_{HL2}&=&\alpha_{FM,R}+U_{split,R} \\
\alpha_{IL}&=&0.5\times\left(\alpha_{OX}+\alpha_{FM,L}+U_{b}+U_{split,L}\right) \\
\alpha_{IR}&=&0.5\times\left(\alpha_{OX}+\alpha_{FM,R}+U_{b}+U_{split,R}\right) \\
U_{split,L}&=&\begin{bmatrix}
0 & 0 \\
0 & \Delta_{L}
\end{bmatrix} \label{eq:onsiteL} \\
U_{split,R}&=&\begin{bmatrix}
0 & 0 \\
0 & \Delta_{R}
\end{bmatrix} \label{eq:onsiteR}
\end{IEEEeqnarray}Eqs.~(\ref{eq:onsiteL}) and (\ref{eq:onsiteR}) are written assuming the magnetization directions of the left and right FM contacts are the same and are pointing in the $+\widehat{z}$ direction of the reference frame. If they are different, we may choose one of the FM contacts (e.g., left FM contact) to be the reference frame and define its magnetization direction to be the $+\widehat{z}$ direction. Using the left FM contact as the reference frame, the magnetization direction of the right FM contact, $\widehat{m}$, may be written. In this example, a unitary transformation needs to be performed on $U_{split,R}$ to rewrite it as \begin{equation}
U_{split,R} = \frac{\left(I-\vv{\sigma}\cdot\widehat{m}\right)\Delta_{R}}{2} \label{eq:unitaryTrans}
\end{equation}where $\vv{\sigma}$ is the vector of Pauli spin matrices. Note that for any arbitrarily chosen reference frame, unitary transformation is performed on both $U_{split,L}$ and $U_{split,R}$, using $\widehat{m}$ to be the magnetization vector direction for the corresponding ferromagnetic contact in the chosen reference frame. By definition, the dot product in Eq.~(\ref{eq:unitaryTrans}) yields a $2\times{}2$ matrix that is a linear combination of the Pauli spin matrices given by \begin{equation}
\vv{\sigma}\cdot\widehat{m} = m_{x}\vv{\sigma}_{x}+m_{y}\vv{\sigma}_{y}+m_{z}\vv{\sigma}_{z}
\end{equation}where the components of the vectors have been explicitly written. Note that unitary transformations acting on identity matrices does not do anything. Hence, only $U_{split,L}$ and $U_{split,R}$ needs to be modified to obtain $\mathcal{H}$ when any of the magnetizations do not point along the $+\widehat{z}$ direction of the chosen reference frame.

The applied voltage across the MTJ modifies the potential profile along the longitudinal direction of the MTJ and may be modeled as $U_{V}$. The non-zero entries of $U_{V}$ are on its main diagonal and may be calculated using \begin{equation}
U_{V}(i,i)=\left\lbrace \,
\begin{IEEEeqnarraybox}[][c]{l?s}
\frac{qV}{2}I & if $i$ is in $HL1$ or $IL$, \\
\frac{-qV}{2}I & if $i$ is in $HL2$ or $IR$, \\
qV\left(\frac{1}{2}-\frac{i}{N+1}\right)I & if $i$ is in $OX$.
\end{IEEEeqnarraybox} \right.
\end{equation}where $N$ is the total number of grid points in the OX region. Next, the full Hamiltonian, $\mathcal{H}_{Full}$, is written as \begin{equation}
\mathcal{H}_{Full}=\mathcal{H}+U_{V}
\end{equation}

The self-energy matrices, $\Sigma_{L,R}$, represent the coupling of the external system to the contacts. Based on the construction of $\mathcal{H}_{Full}$,  the non-zero components $\Sigma_{L}$ and $\Sigma_{R}$ are on the top left and bottom right, respectively. The non-zero parts of the self-energies may be written as \begin{equation}\label{eq:self_energyL}
\Sigma_{L}=
\begin{bmatrix}
-t_{FM,Left}exp\left(-ik_{L}^{\uparrow}a\right) & 0 \\
0 & -t_{FM,Left}exp\left(-ik_{L}^{\downarrow}a\right)
\end{bmatrix}
\end{equation}\begin{equation}\label{eq:self_energyR}
\Sigma_{R}=
\begin{bmatrix}
-t_{FM,Right}exp\left(-ik_{R}^{\uparrow}a\right) & 0 \\
0 & -t_{FM,Right}exp\left(-ik_{R}^{\downarrow}a\right)
\end{bmatrix}
\end{equation} where \begin{equation}
k_{L}^{\uparrow}=cos^{-1}\left(1-\frac{E+\frac{qV}{2}}{2t_{FM,Left}} \right)
\end{equation}\begin{equation}
k_{R}^{\uparrow}=cos^{-1}\left(1-\frac{E-\frac{qV}{2}}{2t_{FM,Right}} \right)
\end{equation}\begin{equation}
k_{L}^{\downarrow}=cos^{-1}\left(1-\frac{E+\frac{qV}{2}-\Delta_{L}}{2t_{FM,Left}} \right)
\end{equation}\begin{equation}
k_{R}^{\downarrow}=cos^{-1}\left(1-\frac{E-\frac{qV}{2}-\Delta_{R}}{2t_{FM,Right}} \right)
\end{equation}$E$ is the energy level of interest. This form of Eqs.~(\ref{eq:self_energyL}) and (\ref{eq:self_energyR}) are used if the magnetization direction is in the $+\widehat{z}$ direciton. As before, a unitary transformation needs to be performed on $\Sigma_{L,R}$ of the FM contact whose magnetization direction is not in the $+\widehat{z}$ direciton of the reference frame. The matrix for unitary transformation is given by \begin{equation}
\Lambda_{trans} =
\begin{bmatrix}
cos\left(\frac{\theta}{2}\right)exp\left(i\frac{\phi}{2}\right) & sin\left(\frac{\theta}{2}\right)exp\left(-i\frac{\phi}{2}\right) \\
-sin\left(\frac{\theta}{2}\right)exp\left(i\frac{\phi}{2}\right) & cos\left(\frac{\theta}{2}\right)exp\left(-i\frac{\phi}{2}\right) \\
\end{bmatrix}
\end{equation} where $\theta$ and $\phi$ correspond to the spherical angles of the magnetization vector direction to the Cartesian axis in the reference frame. The self-energy matrices are transformed using \begin{equation}
\Sigma_{L,R}^{new}=\Lambda_{trans}\Sigma_{L,R}^{old}\Lambda_{trans}^{\dagger}
\end{equation}

With the Hamiltonian ($\mathcal{H}_{Full}$) and the self-energy matrices ($\Sigma_{L,R}$), all quantities of interest may be calculated from the following:
\begin{align}
\textbf{Green's function: } G(E) &= (EI - \mathcal{H}_{Full} - \Sigma_L - \Sigma_R)^{-1} \\
\textbf{Spectral density: } A &= i(G-G^{\dagger})=G \Gamma G^{\dagger} \\
\textbf{Electron correlation function: } G^{n}(E) &= G(\Sigma_{L}^{in} + \Sigma_{R}^{in})G^{\dagger} \label{eq:eCorrFunc} \\
\textbf{In-scattering function: } \Sigma_{L,R}^{in}(E) &= \Gamma_{L,R}(E)f_{L,R}(E) \\
\textbf{Broadening matrix: } \Gamma_{L,R}(E) &= i(\Sigma_{L,R} - \Sigma_{L,R}^{\dagger})
\end{align} The diagonal elements of $A$ and $G^n$ correspond to the local density of states and electron density, respectively. $\Sigma^{in}$ is the in-scattering function describing the rate at which electrons enter the device from the $L$ and $R$ contacts, and $f_{L,R}(E)$ are the Fermi functions in the $L$ and $R$ contacts. \begin{IEEEeqnarray}{rCl}
f_{L}(E)&=&\frac{1}{1+exp\left(\frac{E-\mu_{L}}{k_{B}T}\right)} \\
f_{R}(E)&=&\frac{1}{1+exp\left(\frac{E-\mu_{R}}{k_{B}T}\right)}
\end{IEEEeqnarray}where $k_{B}$ is the Boltzmann constant, $T$ is the absolute temperature of the system, and $\mu_{L}$ and $\mu_{R}$ are the electrochemical potential of the left and right FM contacts, respectively. The charge and spin currents flowing through the MTJ are then calculated using
\begin{center}
\textbf{\underline{Charge current density}}
\end{center}
\begin{equation}\label{eq:negf_jcurr}
J_{k,k+1} = Real \left(\frac{1}{i\hbar} \int_{E} \left( Trace \left(\mathcal{H}_{Full,k,k+1}G_{k+1,k}^n - G_{k,k+1}^n\mathcal{H}_{Full,k+1,k} \right)\right) dE \right)
\end{equation}\begin{center}
\textbf{\underline{Spin current density}}
\end{center}
\begin{equation}\label{eq:negf_js}\begin{aligned}
\vv{J}_{S} &= J_{k,k+1}^{Spin} \\
&= Real \left(\frac{1}{i2e\mu_{0}M_{S}V_{magnet}} \int_{E} \left( Trace \left\lbrace \widehat{\sigma} \cdot \left(\mathcal{H}_{Full,k,k+1}G_{k+1,k}^n - G_{k,k+1}^n\mathcal{H}_{Full,k+1,k} \right)\right\rbrace\right) dE \right)
\end{aligned}\end{equation} where $G^n$ is the electron correlation function calculated as given by Eq.~(\ref{eq:eCorrFunc}), $e$ is the elementary charge, $\mu_{0}$ is the permeability of vacuum, $M_{S}$ and $V_{magnet}$ is the saturation magnetization and volume of the magnetic layer the torque is acting on in the MTJ. The charge and spin currents calculated using the NEGF approach are used to determine the spin-transfer torque exerted on the free ferromagnetic layer of the MTJ.

\section{Extending the 1-D model to higher dimension systems}\label{sec:extendDim}

The model presented thus far only models the electron transport in the MTJ considered as a 1-D wire. In real devices, the lateral dimensions may be substantially larger and hence, the 1-D model may not apply. However, the methodology above can still be used for systems with higher order dimensions. The Hamiltonian is written differently for 2-D and for 3-D systems. Let us consider the a 2-D MTJ first. The same approach presented earlier may be used to write $\mathcal{H}$, except that $\alpha_{HL1}$, $\alpha_{HL2}$, $\alpha_{IL}$, $\alpha_{IR}$ , $\alpha_{OX}$, $\beta_{HL1}$, $\beta_{HL2}$, $\beta_{IL}$, $\beta_{IR}$, and $\beta_{OX}$ needs to be rewritten. Assume that $N_{t}$ grid points lie in the \emph{transverse} direction (the direction perpendicular to the longitudinal direction). First, note that every line of grid points in the transverse direction lie in only one of the five defined regions. Using the left FM contact as an example, we rewrite \begin{IEEEeqnarray}{rCl}
\alpha_{HL1}&=&\left[ \begin{IEEEeqnarraybox}[][c]{/c/c/c/c/c/}
2\alpha_{FM,L} & \beta_{FM,L} & 0 & \cdots & 0 \\
\beta^{\dagger}_{FM,L} & \ddots & \ddots & \ddots & \vdots \\
0 & \ddots & \ddots & \ddots & 0 \\
\vdots &\ddots & \ddots & \ddots & \beta_{FM,L} \\
0 & \cdots & 0 & \beta^{\dagger}_{FM,L} & 2\alpha_{FM,L}
\end{IEEEeqnarraybox}\right] \label{eq:modAlph2d} \\
\beta_{HL1}&=&-t_{FM,Left}I \label{eq:modBeta2d}
\end{IEEEeqnarray}where $I$ is the $2N_{t}\times2N_{t}$ identity matrix. To account for the conduction splitting, $U_{split,L}$ is added to every $2\times{}2$ entry on the main diagonal of $\alpha_{HL1}$. The same approach is used to modify $\alpha_{HL2}$ and $\beta_{HL2}$. $\alpha_{OX}$ and $\beta_{OX}$ are modified using the same approach given in Eqs.~(\ref{eq:modAlph2d}) and (\ref{eq:modBeta2d}), except that $U_{b}I$ is added to every $2\times{}2$ entry on the main diagonal of $\alpha_{OX}$. Then, \begin{IEEEeqnarray}{rCl}
\alpha_{IL}&=&0.5\times\left(\alpha_{HL1}+\alpha_{OX}\right) \\
\alpha_{IR}&=&0.5\times\left(\alpha_{HL2}+\alpha_{OX}\right)
\end{IEEEeqnarray}The rewritten $\alpha_{HL1}$, $\alpha_{HL2}$, $\alpha_{IL}$, $\alpha_{IR}$ , $\alpha_{OX}$, $\beta_{HL1}$, $\beta_{HL2}$, and $\beta_{OX}$ are then used to write $\mathcal{H}$ as given by Eq.~(\ref{eq:genHam}).

In a 3-D system, transverse directions forms a 2-D plane of grid points. Hence, $\alpha_{HL1}$, $\alpha_{HL2}$, $\alpha_{IL}$, $\alpha_{IR}$ , $\alpha_{OX}$, $\beta_{HL1}$, $\beta_{HL2}$, $\beta_{IL}$, $\beta_{IR}$, and $\beta_{OX}$ each models a 2-D plane of grid points. Consider a 2-D plane in the $HL1$ region with $N_{t1}\times{}N_{t2}$ number of grid points. We write along the direction with $N_{t1}$ points\begin{IEEEeqnarray}{rCl}
\alpha_{1D,HL1}&=&\left[ \begin{IEEEeqnarraybox}[][c]{/c/c/c/c/c/}
3\alpha_{FM,L} & \beta_{FM,L} & 0 & \cdots & 0 \\
\beta^{\dagger}_{FM,L} & \ddots & \ddots & \ddots & \vdots \\
0 & \ddots & \ddots & \ddots & 0 \\
\vdots &\ddots & \ddots & \ddots & \beta_{FM,L} \\
0 & \cdots & 0 & \beta^{\dagger}_{FM,L} & 3\alpha_{FM,L}
\end{IEEEeqnarraybox}\right] \label{eq:modAlph2d_alt} \\
\beta_{1D,HL1}&=&-t_{FM,Left}I \label{eq:modBeta2d_alt}
\end{IEEEeqnarray}where $I$ in Eq.~(\ref{eq:modBeta2d_alt}) is the $2N_{t1}\times2N_{t1}$ identity matrix and $\alpha_{1D,HL1}$ is a $2N_{t1}\times2N_{t1}$ matrix. We can then write \begin{IEEEeqnarray}{rCl}
\alpha_{HL1}&=&\left[ \begin{IEEEeqnarraybox}[][c]{/c/c/c/c/c/}
\alpha_{1D,HL1} & \beta_{1D,HL1} & 0 & \cdots & 0 \\
\beta^{\dagger}_{1D,HL1} & \ddots & \ddots & \ddots & \vdots \\
0 & \ddots & \ddots & \ddots & 0 \\
\vdots &\ddots & \ddots & \ddots & \beta_{1D,HL1} \\
0 & \cdots & 0 & \beta^{\dagger}_{1D,HL1} & \alpha_{1D,HL1}
\end{IEEEeqnarraybox}\right] \label{eq:modAlph3d} \\
\beta_{HL1}&=&-t_{FM,Left}I\label{eq:modBeta3d}
\end{IEEEeqnarray}where $I$ in Eq.~(\ref{eq:modBeta3d}) is the $(2N_{t1}N_{t2})\times(2N_{t1}N_{t2})$ identity matrix and $\alpha_{HL1}$ is a $(2N_{t1}N_{t2})\times(2N_{t1}N_{t2})$ matrix. To account for the conduction band splitting between up-spin and down-spin electrons, $U_{split,L}$ is added to every $2\times2$ entry along the main diagonal of $\alpha_{HL1}$. The same approach is used to rewrite $\alpha_{HL2}$ and $\beta_{HL2}$. $\alpha_{OX}$ is rewritten as prescribed by Eqs.~(\ref{eq:modAlph2d_alt}) and (\ref{eq:modAlph3d}), while $\beta_{OX}$ is rewritten as prescribed by Eqs.~(\ref{eq:modBeta2d_alt}) and (\ref{eq:modBeta3d}). However, $U_{b}I$, where $I$ here is the $2\times2$ identity matrix, is added to every $2\times2$ entry along the main diagonal of $\alpha_{OX}$. Also, just like in the 2-D system, the interfaces are modeled as \begin{IEEEeqnarray}{rCl}
\alpha_{IL}&=&0.5\times\left(\alpha_{HL1}+\alpha_{OX}\right) \\
\alpha_{IR}&=&0.5\times\left(\alpha_{HL2}+\alpha_{OX}\right)
\end{IEEEeqnarray}The rewritten $\alpha_{HL1}$, $\alpha_{HL2}$, $\alpha_{IL}$, $\alpha_{IR}$ , $\alpha_{OX}$, $\beta_{HL1}$, $\beta_{HL2}$, and $\beta_{OX}$ are then used to write $\mathcal{H}$ as given by Eq.~(\ref{eq:genHam}).

\section{The mode space approach}

Note the size of $\mathcal{H}$ grows quadratically with the total number of grid points. As the number of dimensions of the system increases, the size of $\mathcal{H}$ quickly increases as well. Clearly, there may not be enough computer memory to accommodate the numerical program for solving large 3-D systems. Fortunately, the problem for 2-D and 3-D systems may be reduced to multiple 1-D problems using the mode space approach, which drastically reduces the memory requirement for the numerical program. The main reason that allows us to reduce the number of dimensions is that the solutions to the Schr\"odinger equation for the MTJ system may be written as \begin{equation}
\psi_{i}=\psi_{0}\cdot{}exp(i\vv{r}\cdot\vv{k}_{\perp})\cdot{}exp(i\vv{r}\cdot\vv{k}_{\parallel})
\end{equation}where $i=\sqrt{-1}$, $\vv{k}_{\perp}$ is the longitudinal wave vector, and $\vv{k}_{\parallel}$ is the transverse wave vector. In other words, $\alpha_{HL1}$, $\alpha_{HL2}$, $\alpha_{OX}$, $\alpha_{IL}$ and $\alpha_{IR}$ may be diagonalized and our system of equations going into Eq.~(\ref{eq:genHam}) may be rewritten such that \begin{IEEEeqnarray}{rCl}
\alpha_{HL1}&=&2t_{FM,Left}I + E_{t} \\
\alpha_{HL2}&=&2t_{FM,Right}I + \frac{E_{t}t_{FM,Left}}{t_{FM,Right}} \\
\alpha_{OX}&=&2t_{OX}I + \frac{E_{t}t_{FM,Left}}{t_{OX}} \\
\alpha_{IL}&=&(t_{FM,Left}+t_{OX})I + \frac{2E_{t}t_{FM,Left}}{(t_{FM,Left}+t_{OX})} \\
\alpha_{IR}&=&(t_{FM,Right}+t_{OX})I + \frac{2E_{t}t_{FM,Left}}{(t_{FM,Right}+t_{OX})} \\
\beta_{HL1}&=&-t_{FM,Left}I \\
\beta_{HL2}&=&-t_{FM,Right}I \\
\beta_{OX}&=&-t_{OX}I \\
E_{t}(j,j)&=&\frac{\hbar^{2}\left|\vv{k}_{\parallel}(j,j)\right|^{2}}{2m^{*}_{FM,L}}
\end{IEEEeqnarray}The non-zero entries of $E_{t}$ are on its main diagonal, and $I$ is the identity matrix. The size of $I$ is such that the number of entries along each row and column corresponds to twice the number of grid points in the transverse directions of the system. The same system of equations may be solved by considering each $E_{t}$ separately. For each $E_{t}$, $\mathcal{H}$ is written as in the 1-D case but with \begin{IEEEeqnarray}{rCl}
\alpha_{HL1}&=&\alpha_{FM,L} = 2t_{FM,Left}I + E_{t} \\
\alpha_{HL2}&=&\alpha_{FM,R} = 2t_{FM,Right}I + \frac{E_{t}t_{FM,Left}}{t_{FM,Right}}\\
\alpha_{OX}&=&\alpha_{Ch} = 2t_{OX}I + \frac{E_{t}t_{FM,Left}}{t_{OX}} \\
\alpha_{IL}&=&\frac{\alpha_{OX}+\alpha_{FM,L}}{2} \\
\alpha_{IR}&=&\frac{\alpha_{OX}+\alpha_{FM,R}}{2} \\
\beta_{HL1}&=&\beta_{FM,L} = -t_{FM,Left}I \\
\beta_{HL2}&=&\beta_{FM,R} = -t_{FM,Right}I \\
\beta_{OX}&=&-t_{OX}I
\end{IEEEeqnarray} where $I$ is the $2\times{}2$ identity matrix.

The transverse mode energies, $E_{t}$, depends on the dimensionality of the system, the number of transverse grid points, and the type of boundary conditions. In Section~\ref{sec:extendDim}, we have written $\mathcal{H}$ using box boundary conditions. Let us consider the 2-D case first. It turns out that we may write the mode energies as \begin{IEEEeqnarray}{rCl}
E_{t}&=&2t_{FM,Left}\times\left(1-cos\left(k_{\parallel}a\right)\right)
\end{IEEEeqnarray}When the box boundary condition is used, the plane wave solution to the Schr\"odinger equation must be periodic in the transverse direction. Furthermore, it must go to zero at both ends along the transverse direction due to box boundary conditions. Hence, we can write the plane wave solution as \begin{IEEEeqnarray}{rCl}
\Psi_{\nu}&=&\Psi_{0}exp\left(ik_{\perp}l_{\perp}\right)sin(k_{\parallel}l_{\parallel}) \\
k_{\parallel}(N_{t}+1)a &=& \nu\pi \text{~when~}l_{\parallel}=(N_{t}+1)a
\end{IEEEeqnarray}where $\nu$ is an integer in [1, $N_{t}$] and $N_{t}$ is the number of grid points in the transverse direction. Then,\begin{IEEEeqnarray}{rCl}
E_{t}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{\nu\pi}{N_{t}+1}\right)\right)
\end{IEEEeqnarray} On the other hand, periodic boundary conditions (\emph{pbc}) may also be used to model devices where the characteristic does not depend on the boundary condition. When using \emph{pbc}, $\alpha_{HL1}$ is written as \begin{IEEEeqnarray}{rCl}
\alpha_{HL1}&=&\left[\begin{IEEEeqnarraybox}[][c]{/c/c/c/c/c/c/}
2\alpha_{FM,L} & \beta_{FM,L} & 0 & \cdots & 0 & \beta^{\dagger}_{FM,L} \\
\beta^{\dagger}_{FM,L} & \ddots & \ddots & \ddots & \ddots & 0 \\
0 & \ddots & \ddots & \ddots & \ddots & \vdots \\
\vdots & \ddots & \ddots & \ddots & \ddots & 0 \\
0 & \ddots & \ddots & \ddots & \ddots & \beta_{FM,L} \\
\beta_{FM,L} & 0 & \cdots & 0 & \beta^{\dagger}_{FM,L} & 2\alpha_{FM,L}
\end{IEEEeqnarraybox}\right]
\end{IEEEeqnarray}and similarly for $\alpha_{HL2}$, $\alpha_{IL}$, $\alpha_{IR}$ , and $\alpha_{OX}$. The plane wave solution to the Schr\"odinger equation is only required to be periodic in the transverse direction. Hence, \begin{IEEEeqnarray}{rCl}
\Psi_{\nu}&=&\Psi_{0}exp\left(ik_{\perp}l_{\perp}\right)exp(ik_{\parallel}l_{\parallel}) \\
k_{\parallel}(N_{t})a &=& 2\nu\pi \text{~when~} l_{\parallel}=N_{t}a
\end{IEEEeqnarray}where $\nu$ is an integer in [1, $N_{t}$] and $N_{t}$ is the number of grid points in the transverse direction. Then,\begin{IEEEeqnarray}{rCl}
E_{t}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{2\nu\pi}{N_{t}}\right)\right)
\end{IEEEeqnarray}

The transverse mode energies for 3-D systems may be constructed from the same approach we just described. Let us consider the longitudinal direction to be in the $+\widehat{z}$ direction, and the transverse directions to be $+\widehat{x}$ and $+\widehat{y}$. Furthermore, assume there are $N_{t1}$ and $N_{t2}$ grid points in the $x$ and $y$ directions, respectively. We invoke the fact that plane wave solutions to the Schr\"odinger equation have the form \begin{equation}
\Psi_{\nu} = \Psi_{0}e^{i\left(k_{x}r_{x} + k_{y}r_{y} + k_{z}r_{z}\right)}
\end{equation}Since $k_{x}$ and $k_{y}$ are decoupled, the combined transverse mode energy is a linear combination of every permutation of the transverse mode energy in the $x$ and $y$ direction ($E_{t,x}$ and $E_{t,y}$, respectively). Hence, every $E_{t,x}$ and $E_{t,y}$ are first obtained by choosing integers $\nu_{x}$ and $\nu_{y}$ in the range [1, $N_{t1}$] and [1, $N_{t2}$], respectively. If both directions have box boundary conditions, then we can write \begin{IEEEeqnarray}{rCl}
E_{t,x}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{\nu_{1}\pi}{N_{t1}+1}\right)\right) \\
E_{t,y}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{\nu_{2}\pi}{N_{t2}+1}\right)\right)
\end{IEEEeqnarray}and calculate $E_{t}=E_{t,x}+E_{t,y}$ using every permutation of $E_{t,x}$ and $E_{t,y}$. If both directions have \emph{pbc}, then use \begin{IEEEeqnarray}{rCl}
E_{t,x}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{2\nu_{1}\pi}{N_{t1}}\right)\right) \\
E_{t,y}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{2\nu_{2}\pi}{N_{t2}}\right)\right)
\end{IEEEeqnarray}instead. If the box boundary condition is applied along the $x$ direction but \emph{pbc} along the $y$ direction, then use \begin{IEEEeqnarray}{rCl}
E_{t,x}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{\nu_{1}\pi}{N_{t1}+1}\right)\right) \\
E_{t,y}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{2\nu_{2}\pi}{N_{t2}}\right)\right)
\end{IEEEeqnarray}instead. If the box boundary condition is applied along the $y$ direction but \emph{pbc} along the $x$ direction, then use \begin{IEEEeqnarray}{rCl}
E_{t,x}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{2\nu_{1}\pi}{N_{t1}}\right)\right) \\
E_{t,y}&=&2t_{FM,Left}\times\left(1-cos\left(\frac{\nu_{2}\pi}{N_{t2}+1}\right)\right)
\end{IEEEeqnarray} The charge and spin currents flowing through the MTJ are calculated for each mode and all contributions are summed together to obtain the actual charge and spin current flowing through the MTJ, giving
\begin{center}
\textbf{\underline{Charge current density}}
\end{center}
\begin{equation}\label{eq:negf_jcurr_modeDis}
J_{k,k+1} = \sum_{E_{t}} Real \left(\frac{1}{i\hbar} \int_{E_{z}} \left( Trace \left(\Upsilon \right)\right) \partial{}E_{z} \right)
\end{equation}\begin{center}
\textbf{\underline{Spin current density}}
\end{center}
\begin{equation}\label{eq:negf_js_modeDis}
\vv{J}_{S} = \sum_{E_{t}} Real \left(\frac{1}{i2e\mu_{0}M_{S}V_{magnet}} \int_{E_{z}} \left( Trace \left\lbrace \widehat{\sigma} \cdot \Upsilon\right\rbrace\right) \partial{}E_{z} \right)
\end{equation}where $\Upsilon$ is given by\begin{equation}
\Upsilon=\mathcal{H}_{Full,k,k+1}(E_{t})G_{k+1,k}^n(E_{t}) - G_{k,k+1}^n(E_{t})\mathcal{H}_{Full,k+1,k}(E_{t})
\end{equation}and $\mathcal{H}_{Full}$ and $G^{n}$ are now functions of $E_{t}$.

\section{Approximating mode space calculations in NEGF}\label{sec:negf_Soln}

In MTJs, the Fermi level in the FM contacts are deep inside the conduction band and as a result, the grid spacing may need to be very small in order for the numerical solutions to converge (even in the 1-D case). Even for MTJs with $10~\text{nm}\times10~\text{nm}$ cross-sectional area, the number of transverse modes needed to be considered to calculate its $I-V$ characteristic can be in the tens of thousands. Since the NEGF calculations for each transverse mode energy is independent of the others, the numerical simulation can be easily parallelized and executed on a large computer cluster to obtain the results quickly. However, because the data needs to be communicated to every computing node in the cluster, the simulation might be slowed down if the network traffic is too heavy. To overcome this issue, we first note that when the MTJ size is sufficiently large, the number of transverse modes in $k$-space is very dense. Hence, it may be possible to turn the discrete summation in Eqs.~(\ref{eq:negf_jcurr_modeDis}) and (\ref{eq:negf_js_modeDis}) into a continuous integral. This approach was proposed in \cite{Duke1969} and was used by Tsu-Esaki to model resonant tunneling diodes \cite{Tsu1973a}.

When we change the summation over modes in 3-D to a continuous integration, it can be converted as \begin{equation}
\sum_{E_{t,x}}\sum_{E_{t,y}}\sum_{E_{t,z}} \rightarrow \int\int\int\partial{}k_{x}\partial{}k_{y}\partial{}k_{z}
\end{equation}However, the triple integral can be converted into a single integral if we integrate over the actual energy of the transverse mode instead. \begin{equation}
\int\int\int\partial{}k_{x}\partial{}k_{y}\partial{}k_{z} \rightarrow \int\partial{}k_{\parallel} \rightarrow DOS(E_{t}) \int\partial{}E_{t}
\end{equation}where $DOS(E_{t})$ is the density of states. This can be done if we know the dispersion relation, which is assumed to be quadratic for most problems \begin{equation}
E_{t} = \frac{\hbar^{2}(\vv{k}\cdot\vv{k})}{2m^{*}_{eff}}=\frac{\hbar^{2}(k^{2}_{x}+k^{2}_{y}+k^{2}_{z})}{2m^{*}_{eff}}=\frac{\hbar^{2}{}k^{2}_{\parallel}}{2m^{*}_{eff}}
\end{equation}where $m^{*}_{eff}$ is the effective mass of the electron. Rearranging, \begin{equation}
k_{\parallel}=\frac{\sqrt{2m^{*}_{eff}E_{t}}}{\hbar} \label{eq:kERel}
\end{equation}We also need to determine $DOS(E_{t})$. In a 3-D box which has \emph{pbc} in all three Cartesian coordinate directions. The $k$-states are separated by \begin{equation}
\Delta{}k_{x}=\frac{\pi}{L_{x}},~\Delta{}k_{y}=\frac{\pi}{L_{y}},~\Delta{}k_{z}=\frac{\pi}{L_{z}}
\end{equation}where $L_{x}$, $L_{y}$ and $L_{z}$ is the length of each side of the confining box. Furthermore, each $k_{x}$, $k_{y}$ and $k_{z}$ falls in the range [$-\pi$, $\pi$]. Hence, in $k$-space, each state occupies a volume given by \begin{equation}
\text{Volume~occupied~by~a~state~in~k-space~for~a~3-D~box}=\frac{2\pi}{L_{x}}\times\frac{2\pi}{L_{y}}\times\frac{2\pi}{L_{z}}=\frac{8\pi^{3}}{\Omega}
\end{equation}where $\Omega=L_{x}L_{y}L_{z}$. To get the \emph{density of states}, we need to determine how many states are uncovered when $E_{t}$ changes to $E_{t}+\partial{}E_{t}$. This corresponds to a change in volume in $k$-space. When $E_{t}$ changes, the volume changes spherically. \begin{table}[!t]
\caption{Summary of $DOS(E_{t})$ calculations}
\centering
\label{tab:DOS}
\begin{IEEEeqnarraybox}[\IEEEeqnarraystrutmode][c]{v/c/v/c/v/c/v/c/v/c/v/c/v}
\IEEEeqnarrayrulerow \\
& \raisebox{-7pt}[0pt][0pt]{Dimensions} && \raisebox{-7pt}[0pt][0pt]{$\Omega$} && \text{Volume~of} && \text{Volume~of~sphere} && \text{Number~of~states} && \raisebox{-7pt}[0pt][0pt]{$DOS(E_{t})$}  \\
& && && \text{one~state} && \text{in~}k\text{-space} && \text{in~sphere} && \\
\IEEEeqnarrayrulerow \\
& \raisebox{-2pt}[0pt][0pt]{3-D} && \raisebox{-2pt}[0pt][0pt]{$L_{x}L_{y}L_{z}$} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{24pt}{11pt}][c]{c}\frac{8\pi^{3}}{\Omega}\end{IEEEeqnarraybox} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{24pt}{11pt}][c]{c}\frac{4\pi{}k_{\parallel}^{3}}{3}\end{IEEEeqnarraybox} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{27pt}{10pt}][c]{c}\frac{\Omega{}\left(2m^{*}_{eff}E_{t}\right)^{\frac{3}{2}}}{6\pi^{2}\hbar^{3}}\end{IEEEeqnarraybox} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{20pt}{10pt}][c]{c}\frac{\Omega2\pi(2m^{*}_{eff})^\frac{3}{2}}{h^{3}}\sqrt{E_{t}}\end{IEEEeqnarraybox} \\
\IEEEeqnarrayrulerow \\
& \raisebox{-2pt}[0pt][0pt]{2-D} && \raisebox{-2pt}[0pt][0pt]{$L_{x}L_{y}$} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{18pt}{10pt}][c]{c}\frac{4\pi^{2}}{\Omega}\end{IEEEeqnarraybox} && \pi{}k_{\parallel}^{2} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{18pt}{10pt}][c]{c}\frac{\Omega2\pi{}m^{*}_{eff}E_{t}}{h^{2}}\end{IEEEeqnarraybox} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{18pt}{10pt}][c]{c}\frac{\Omega2\pi{}m^{*}_{eff}}{h^{2}}\end{IEEEeqnarraybox} \\
\IEEEeqnarrayrulerow \\
& \raisebox{-1.5pt}[0pt][0pt]{1-D} && \raisebox{-1.5pt}[0pt][0pt]{$L_{x}$} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{18pt}{10pt}][c]{c}\frac{2\pi}{\Omega}\end{IEEEeqnarraybox} && 2k_{\parallel} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{21pt}{8.5pt}][c]{c}\frac{\Omega2\sqrt{2m^{*}_{eff}E_{t}}}{h}\end{IEEEeqnarraybox} && \begin{IEEEeqnarraybox}[\IEEEeqnarraystrutsize{21pt}{13pt}][c]{c}\frac{\Omega}{h}\sqrt{\frac{2m^{*}_{eff}}{E_{t}}}\end{IEEEeqnarraybox} \\
\IEEEeqnarrayrulerow
\end{IEEEeqnarraybox}
\end{table}The volume of a sphere is \begin{equation}
Volume = \frac{4\pi{}k_{\parallel}^{3}}{3}
\end{equation}and the total number of states in that volume is \begin{equation}
\text{Number of states~in~volume}=\frac{4\pi{}k_{\parallel}^{3}}{3}\times\frac{\Omega}{8\pi^{3}}=\frac{\Omega{}k_{\parallel}^{3}}{6\pi^{2}} \label{eq:3dspv}
\end{equation}Substituting Eq.~(\ref{eq:kERel}) into (\ref{eq:3dspv}), we get \begin{equation}
\text{Number of states~in~volume}=\frac{\Omega(2m^{*}_{eff}E_{t})^{\frac{3}{2}}}{6\pi^{2}\hbar^{3}}
\end{equation}Then, we can calculate the density of states given as \begin{equation}
DOS(E_{t}) = \frac{\partial}{\partial{}E_{t}} \left(\text{Number of states~in~volume}\right)=\frac{\Omega2\pi(2m^{*}_{eff})^\frac{3}{2}}{h^{3}}\sqrt{E_{t}}
\end{equation}The same process can be repeated to calculate $DOS(E_{t})$ for 2-D and 1-D confinements, and the results are summarized in Table~\ref{tab:DOS}. Note that the number of states in sphere listed in Table~\ref{tab:DOS} is missing a factor of 2 compared to the texts found in the literature. In the literature, the factor of 2 is used to account for degeneracy in energy levels. In the NEGF approach used in this work, the degeneracy is handled by writing $\mathcal{H}$ to include up-spin and down-spin. Hence, the number of states in sphere is as listed in Table~\ref{tab:DOS}. It is important to note the parabolic dispersion relationship assumption used to obtain these results.

Once we obtain $DOS(E_{t})$, we may then calculate the charge and spin currents as \begin{equation}
\Upsilon=\mathcal{H}_{Full,k,k+1}(E_{t})G_{k+1,k}^n(E_{t}) - G_{k,k+1}^n(E_{t})\mathcal{H}_{Full,k+1,k}(E_{t})
\end{equation}
\begin{center}
\textbf{\underline{Charge current density}}
\end{center}
\begin{equation}\label{eq:negf_jcurr_modeCont}
J_{k,k+1} = Real \left(\frac{1}{i\hbar} \int_{E_{t}}\int_{E_{z}} DOS(E_{t})\cdot\left( Trace \left( \Upsilon \right)\right) \partial E_{z} \partial E_{t} \right)
\end{equation}\begin{center}
\textbf{\underline{Spin current density}}
\end{center}
\begin{equation}\label{eq:negf_js_modeCont}
\vv{J}_{S} = Real \left(\frac{1}{i2e\mu_{0}M_{S}V_{magnet}} \int_{E_{t}}\int_{E_{z}} DOS(E_{t})\cdot\left( Trace \left\lbrace \widehat{\sigma} \cdot \Upsilon\right\rbrace\right) \partial E_{z} \partial E_{t} \right)
\end{equation}

Note that we can use the same procedure to determine $DOS(E_{t})$ if box boundary conditions are used. When box boundary conditions are used, the number of $k$-states long each $k$ direction is same as when \emph{pbc} is used. However, the each state is found in [0, $\pi$] instead of [$-\pi$, $\pi$]. It seems as if the volume occupied by each state in $k$-space is smaller. However, the difference in the range over which the states are found needs to be accounted for. In the 3-D case, all $k$-states are in the first octant. In the 2-D case, all $k$-states are in the first quadrant. In the 1-D case, all $k$-states are in the left half. As a result, we get the same number of states in $k$-space sphere regardless of boundary conditions. Hence, $DOS(E_{t})$ is independent of boundary conditions when the grid spacing is sufficiently small. When we simulate an MTJ, we can assume that the electron tunneling probability is independent of the transverse mode energy. Furthermore, we have $L_{x}, L_{y} \geq 10$~nm and the grid spacing needed for numerical results to converge is usually $a\leq0.1$ \AA. Hence, we can approximate the sum over modes as an integral and calculate the charge and spin currents using \begin{center}
\textbf{\underline{Charge current density}}
\end{center}
\begin{equation}\label{eq:negf_jcurr_mode3D}
J_{k,k+1} = Real \left(\frac{m^{*}_{eff}A_{MTJ}}{i2\pi\hbar^{3}} \int_{E_{t}}\int_{E_{z}} \left( Trace \left( \Upsilon \right)\right) \partial E_{z} \partial E_{t} \right)
\end{equation}\begin{center}
\textbf{\underline{Spin current density}}
\end{center}
\begin{equation}\label{eq:negf_js_mode3D}
\vv{J}_{S} = Real \left(\frac{m^{*}_{eff}A_{MTJ}}{i\hbar^{2}4\pi e\mu_{0}M_{S}V_{magnet}} \int_{E_{t}}\int_{E_{z}} \left( Trace \left\lbrace \widehat{\sigma} \cdot \Upsilon\right\rbrace\right) \partial E_{z} \partial E_{t} \right)
\end{equation}where $A_{MTJ}$ is the cross-sectional area of the MTJ.

\section{Using spin current in simulation of magnetization dynamics}

In the free layer of an MTJ, the Landau-Lifshitz-Gilbert (LLG) equation used to model its behavior. The LLG equation is given as \begin{equation}
\frac{\partial\widehat{m}}{\partial t} = -|\gamma| \widehat{m}\times\vv{H}_{eff} + \alpha\left(\widehat{m}\times\frac{\partial\widehat{m}}{\partial t}\right) + \vv{STT}
\end{equation}where $\vv{H}_{eff}$ is the effective magnetic field (including all anisotropy fields, externally applied magnetic fields and magnetostatic field) acting on the free layer, which has a magnetization direction given by $\widehat{m}$. $\gamma$ is the gyromagnetic ratio (usually $2.211\times10^{5}$ m$\cdot$A$^{-1}\cdot$s$^{-1}$) and $\alpha$ is the unitless Gilbert's damping factor. As proposed by Slonczewski \cite{Slonczewski1996c}, the spin-transfer torque is given by \begin{equation}
\vv{STT}=\widehat{m}\times\vv{J}_{S}\times\widehat{m}
\end{equation}where $\vv{J}_{S}$ was given in Eqs.~(\ref{eq:negf_js}), (\ref{eq:negf_js_modeDis}), (\ref{eq:negf_js_modeCont}) and (\ref{eq:negf_js_mode3D}).