\documentclass[letterpaper]{article}

\usepackage[utf8x]{luainputenc}
\usepackage{aeguill}
%\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{fullpage}
\usepackage{fancyhdr}
\setlength{\headheight}{12pt}
\pagestyle{fancy}
\chead{Linear Algebra}
\lhead{October 28, 2015}
\rhead{Jon Allen}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\proj}{\text{proj}}
\newcommand{\rank}{\text{rank}}
\newcommand{\Span}{\text{Span}}

\begin{document}
%\renewcommand{\labelenumii}{\alph{enumii}.}
%\renewcommand{\labelenumiii}{\alph{enumiii}.}
%\renewcommand{\labelenumi}{(\arabic{enumi})}
\section*{3.3}
\begin{enumerate}
\setcounter{enumi}{2}
\item
%3.3 #3
Decide whether the following sets fo vectors give a basis for the indicated space.
  \begin{enumerate}
  \item
  %3.3 #3a
  $[(1,2,1),(2,4,5),(1,2,3)]:\mathbb{R}^3$

  \[
  \left[\begin{array}{rrr}
  1&2&1\\
  2&4&5\\
  1&2&3\\
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrr}
  1&2&1\\
  0&0&3\\
  0&0&2\\
  \end{array}\right]
  \]

  So the span of the vectors has dimension 2, thus it is not a basis of $\mathbb{R}^3$ which has dimension 3.
  \item
  %3.3 #3b
  $[(1,0,1),(1,2,4),(2,2,5),(2,2,-1)]:\mathbb{R}^3$

  Not a basis. The dimension and the cardinality of the basis should be the same.
  \item
  %3.3 #3c
  $[(1,0,2,3),(0,1,1,1),(1,1,4,4)]:\mathbb{R}^4$

  Not a basis for the same reason as above.
  \item
  %3.3 #3d
  $[(1,0,2,3),(0,1,1,1),(1,1,4,4),(2,-2,1,2)]:\mathbb{R}^4$

  \[
  \left[\begin{array}{rrrr}
  1&0&2&3\\
  0&1&1&1\\
  1&1&4&4\\
  2&-2&1&2\\
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrrr}
  1&0&2&3\\
  0&1&1&1\\
  0&1&2&1\\
  0&-2&-3&-4\\
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrrr}
  1&0&2&3\\
  0&1&1&1\\
  0&0&1&0\\
  0&0&1&2\\
  \end{array}\right]
  \]

  And so the span of the vectors has dimension 4, and so it must be $\mathbb{R}^4$ since the vectors are in $\mathbb{R}^4$
  \end{enumerate}
\setcounter{enumi}{4}
\item
%3.3 #5
Following example 10, for each of the following matrices $A$, give a basis for each of the subspaces $\mathbf{R}(A),\mathbf{C}(A),\mathbf{N}(A),$ and $\mathbf{N}(A^T)$.
  \begin{enumerate}
  \setcounter{enumii}{1}
  \item
  %3.3 #5b
  $A=
  \left[\begin{array}{rrr}
  1&1&0\\
  2&1&1\\
  1&-1&2
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrr}
  1&1&0\\
  0&-1&1\\
  0&-2&2
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrr}
  1&0&1\\
  0&1&-1\\
  0&0&0
  \end{array}\right]
  $

  And so
  $\mathbf{R}(A)=\Span\left([1,0,1],[0,1,-1]\right)$,
  $\mathbf{N}(A)=\Span\left([-1,1,1]\right)$,
  and $\mathbf{C}(A)=\Span\left([1,2,1],[1,1,-1]\right)$.

  We formed the zero row of the \emph{rref} by $(r_3-r_1)-2(r_2-2r_1)=3r_1-2r_2+r_3$. And so $\mathbf{N}(A^T)=\Span\left([3,-2,1]\right)$.
  \end{enumerate}
\setcounter{enumi}{6}
\item
%3.3 #7
Let $V\subset \mathbb{R}^5$ be spanned by $(1,0,1,1,1)$ and $(0,1,-1,0,2)$. By finding the left nullspace of an appropriate matric, give a homogeneous system of equation having $V$ as its solution set. Explain how you are using Proposition 3.6.
\setcounter{enumi}{8}
\item
%3.3 #9
Suppose $\mathbf{u},\mathbf{v},\mathbf{w}\in \mathbb{R}^n$ form a linearly independent set. Prove that $\mathbf{u}+\mathbf{v}, \mathbf{v}+2\mathbf{w},$ and $-\mathbf{u}+\mathbf{v}+\mathbf{w}$ likewise form a linearly  independent set.

Let us assume to the contrary, that $\mathbf{u}+\mathbf{v}, \mathbf{v}+2\mathbf{w},$ and $-\mathbf{u}+\mathbf{v}+\mathbf{w}$ are linearly dependent. Then there exists some $a,b,c\in \mathbb{R}$ not zero such that $a(\mathbf{u}+\mathbf{v})+b(\mathbf{v}+2\mathbf{w})+c(-\mathbf{u}+\mathbf{v}+\mathbf{w})=\mathbf{0}$. Then $(a-c)\mathbf{u}+(a+b+c)\mathbf{v}+(2b+c)\mathbf{w}=\mathbf{0}$. But $\mathbf{u},\mathbf{v},\mathbf{w}$ are linearly independent, and so $a-c=a+b+c=2b+c=0$. But then $a=c$ so $b+2c=2b+c$ and so $b=c$. If $a=b=c$ and $a+b+c=0$ then $a=b=c=0$. But our assumption is that $a,b,c$ are not zero, and so $\mathbf{u}+\mathbf{v}, \mathbf{v}+2\mathbf{w}$ and $-\mathbf{u}+\mathbf{v}+\mathbf{w}$ must be linearly dependent.
\setcounter{enumi}{9}
\item
%3.3 #10
Suppose $\mathbf{v}_1,\dots,\mathbf{v}_k$ are nonzero vectors with the property that $\mathbf{v}_i\cdot\mathbf{v}_j=0$ whenever $i\ne j$. Prove that $\{\mathbf{v}_1,\dots,\mathbf{v}_k\}$ is linearly independent.

Suppose $c_1\mathbf{v}_1+c_2\mathbf{v}_2+\dots+c_k\mathbf{v}_k=\mathbf{0}$.
Then for any $i$ such that $1\le i\le k$ we have
\begin{align*}
  c_1\mathbf{v}_1+\dots+c_k\mathbf{v}_k)\cdot\mathbf{v}_i=\mathbf{0}\cdot\mathbf{v}_i\\
  c_1\mathbf{v}_1\cdot\mathbf{v}_i+\dots+c_i\mathbf{v}_i\cdot\mathbf{v}_i+\dots+c_k\mathbf{v}_k\cdot\mathbf{v}_i=0\\
  c_10+\dots+c_i||\mathbf{v}_i||^2+\dots+c_k0=0\\
  c_i||\mathbf{v}_i||^2=0
\end{align*}
Now $\mathbf{v}_i$ is not zero by assumption, and so $||\mathbf{v}_i||^2>0$. Thus $c_i=0$.

Because our choice of $c_i$ was arbitrary, we know that $\{\mathbf{v}_1,\dots,\mathbf{v}_k\}$ is linearly independent.
\item
%3.3 #11
Suppose $\mathbf{v}_1,\dots,\mathbf{v}_n$ are nonzero, mutually orthogonal vectors in $\mathbb{R}^n$.
  \begin{enumerate}
  \item
  %3.3 #11a
  Prove that they form a basis for $\mathbb{R}^n$. (Use Exercise 10)

  We know that they are linearly independent, and there are $n$ of them, therefore they form basis for an $n$-dimensional subspace. The vectors are in $\mathbb{R}^{n}$ and so they form a subspace in $\mathbb{R}^n$. But the only $n$-dimensional subspace of $\mathbb{R}^n$ is $\mathbb{R}^n$ and so our set must form a asis for $\mathbb{R}^n$
  \item
  %3.3 #11b
  Given any $\mathbf{x}\in \mathbb{R}^n$, give an explicit formula for the coordinates of $\mathbf{x}$ with respect to the basis $\{\mathbf{v}_1,\dots,\mathbf{v}_n\}$.

  If $\mathbf{x}=\sum\limits_{i=1}^n{\proj_{\mathbf{v}_i}\mathbf{x}}$ or if $\mathbf{x}=[x_1,\dots,x_n]$ and $\mathbf{v}_i=[v_{i_1},\dots,v_{i_n}]$. Then $x_k=\sum\limits_{i=1}^n{\frac{\mathbf{v}_i\cdot\mathbf{x}}{||\mathbf{x}||^2}x_i}$
  \item
  %3.3 #11c
  Deduce from your answer to part \emph{b} that $\mathbf{x}=\sum\limits_{i=1}^n{\proj_{\mathbf{v}_i}\mathbf{x}}$
  \end{enumerate}
\setcounter{enumi}{13}
\item
%3.3 #14
Suppose $\mathbf{v}_1,\dots,\mathbf{v}_k\in \mathbb{R}^n$ form a linearly independent set. Show that for any $1\le l<k$, the set $\{\mathbf{v}_1,\dots,\mathbf{v}_l\}$ is lenearly  independent as well.

Assume that $\{\mathbf{v}_1,\dots,\mathbf{v}_l\}$ is linearly dependant. Thene there exists some $\{c_1,\dots,c_l\}$ not all zero such that $c_1\mathbf{v}_1+\dots+c_l\mathbf{v}_l=0$. Then $c_1\mathbf{v}_1+\dots+c_l\mathbf{v}_l+0\mathbf{v}_{l+1}+\dots0\mathbf{v}_k=0$ and so $\{\mathbf{v}_1,\dots\mathbf{v}_k\}$ is linearly dependent. And so we have proven the contrapositive.
\setcounter{enumi}{20}
\item
%3.3 #21
Let $A$ be an $m\times n$ matrix of rank $n$. Suppose $\mathbf{v}_1,\dots,\mathbf{v}_k\in \mathbb{R}^n$ and $\{\mathbf{v}_1,\dots,\mathbf{v}_k\}$ is linearly independent. Prove that $\{A\mathbf{v}_1,\dots,A\mathbf{v}_k\}\subset\mathbb{R}^m$ is likewise linearly independent. ({\bfseries N.B.}: If you did not explicitly make use of the assumption that $\text{rank}(A)=n$, your proof cannot be correct. Why?)
\end{enumerate}
\section*{3.4}
\begin{enumerate}
\item
%3.4 #1
Find a basis for each of the given subspaces and determine its dimension.
  \begin{enumerate}
  \setcounter{enumii}{1}
  \item
  %3.4 #1b
  $V=\{\mathbf{x}=\mathbb{R}^4:x_1+x_2+x_3+x_4=0,x_2+x_4=0\}\subset\mathbb{R}^4$

  We need the nullspace of $\left[\begin{array}{rrrr}1&1&1&1\\0&1&0&1\end{array}\right]$ which is $\Span([-1,0,1,0],[0,-1,0,1])$
  \item
  %3.4 #1c
  $V=\left(\text{Span}\left((1,2,3)\right)\right)^\perp\subset\mathbb{R}^3$

  We need all $\mathbf{x}$ such that $(\alpha[1,2,3])\cdot\mathbf{x}=0$ or the nullspace of $\left[\begin{array}{rrr}1&2&3\\0&0&0\\0&0&0\end{array}\right]$. Which is $\Span([-2,1,0],[-3,0,1])$.
  \end{enumerate}
\setcounter{enumi}{2}
\item
%3.4 #3
Fore each of the following matrices $A$, give bases for $\mathbf{R}(A),\mathbf{N}(A),\mathbf{C}(A),$ and $\mathbf{N}(A^T)$. Check dimensions and orthogonality.
  \begin{enumerate}
  \setcounter{enumii}{1}
  \item
  %3.4 #3b
  $A=
  \left[\begin{array}{rrr}
  2&1&3\\
  4&3&5\\
  3&3&3
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrr}
  2&1&3\\
  1&0&2\\
  3&3&3
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrr}
  0&1&-1\\
  1&0&2\\
  0&3&-3
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrr}
  1&0&2\\
  0&1&-1\\
  0&0&0
  \end{array}\right]
  $

  $r_3-3(r_2-r_3)-3(r_1-2(r_2-r_3))$ to get to the zero row in rref leads to $r_3-3r_2+3r_3-3r_1+6r_2-6r_3=-3r_1+3r_2-2r_3$. And so
  $\mathbf{R}(A)=\Span([1,0,2],[0,1,-1])$,
  $\mathbf{N}(A)=\Span([-2,1,1])$,
  $\mathbf{C}(A)=\Span([2,4,3],[1,3,3])$, and
  $\mathbf{N}(A^T)=\Span([-3,3,-2])$,
  \setcounter{enumii}{4}
  \item
  %3.4 #3e
  $A=
  \left[\begin{array}{rrrrr}
  1 & 1& 0& 1&-1\\
  1 & 1& 2&-1& 1\\
  2 & 2& 2& 0& 0\\
  -1&-1& 2&-3& 3
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrrrr}
   1& 1& 0& 1&-1\\
   0& 0& 2&-2& 2\\
   0& 0& 2&-2& 2\\
   0& 0& 2&-2& 2
  \end{array}\right]
  \Rightarrow
  \left[\begin{array}{rrrrr}
   1& 1& 0& 1&-1\\
   0& 0& 1&-1& 1\\
   0& 0& 0& 0& 0\\
   0& 0& 0& 0& 0
  \end{array}\right]
  $

  $(r2-r1)-(r3-2r1)=r1+r2-r3$ and $(r2-r1)-(r4+r1)=r2-r4$ are both zero.

  $\mathbf{R}(A)=\Span([1,1,0,1,-1],[0,0,1,-1,1])$,
  $\mathbf{N}(A)=\Span([-1,1,0,0,0],[-1,0,1,1,0],[1,0,-1,0,1])$,
  $\mathbf{C}(A)=\Span([1,1,2,-1],[0,2,2,2])$, and
  $\mathbf{N}(A^T)=\Span([1,1,-1,0],[0,1,0,-1])$.
  \end{enumerate}
\setcounter{enumi}{7}
\item
%3.4 #8
In each case, construct a matrix with the requisite properties or explain why no such matrix exists.
  \begin{enumerate}
  \item
  %3.4 #8a
  The column space has basis $\left[\begin{array}{r}1\\0\\1\end{array}\right]$, and the nullspace contains $\left[\begin{array}{r}1\\2\\0\end{array}\right]$.

  It must be a $3\times 3$ matrix. We need the first column to be a multiple of $[1,0,1]$ and the first element of a row should be twice the negative of the second element.
  $\left[\begin{array}{rrr}2&-1&0\\0&0&0\\2&-1&0\end{array}\right]$
  \item
  %3.4 #8b
  The nullspace contains
  $\left[\begin{array}{r}1\\0\\1\end{array}\right]$,
  $\left[\begin{array}{r}-1\\2\\1\end{array}\right]$, and the row space contains
  $\left[\begin{array}{r}1\\1\\-1\end{array}\right]$

  We notice that $[1,0,1]\cdot[1,1,-1]=0$ and $[-1,2,1]\cdot[1,1,-1]=0$ and so we can just make our matrix $[1,1,-1]$
  \item
  %3.4 #8c
  The column spacce has basis
  $\left[\begin{array}{r}1\\0\\1\end{array}\right]$,
  $\left[\begin{array}{r}0\\1\\1\end{array}\right]$,
  and the row space has basis
  $\left[\begin{array}{r}1\\1\\1\end{array}\right]$,
  $\left[\begin{array}{r}2\\0\\1\end{array}\right]$.

  \[
  \left[\begin{array}{rrr}1&0&0\\0&1&0\\1&1&0\end{array}\right]\Rightarrow
  \left[\begin{array}{rrr}2&0&1\\0&1&0\\2&1&0\end{array}\right]\Rightarrow
  \left[\begin{array}{rrr}2&0&1\\0&2&0\\2&2&2\end{array}\right]\Rightarrow
  \left[\begin{array}{rrr}2&0&1\\0&2&1\\2&2&2\end{array}\right]
  \]

  \item
  %3.4 #8d
  The column space and the nullspace both have basis $\left[\begin{array}{r}1\\0\end{array}\right]$.

  $\left[\begin{array}{rr}0&1\\0&0\end{array}\right]$
  \item
  %3.4 #8e
  The column space and the nullspace both have basis
  $\left[\begin{array}{r}1\\0\\0\end{array}\right]$.

  The column space basis has the same cardinality as the row space basis. The cardinality of the nullspace basis and the rowspace basis should add up to three. But it adds up to two, and so we can't make a matrix.

  \end{enumerate}
\setcounter{enumi}{10}
\item
%3.4 #11
Let $A=\left[\begin{array}{rrrr}1&-1&0&0\\0&0&1&-1\end{array}\right]$.
  \begin{enumerate}
  %3.4 #11a
  \item
  Given any $\mathbf{x}\in \mathbb{R}^4$, find $\mathbf{u}\in \mathbf{R}(A)$ and $\mathbf{v}\in \mathbf{N}(A)$ so that $\mathbf{x}=\mathbf{u}+\mathbf{v}$.

  $\mathbf{R}(A)=\Span([1,-1,0,0],[0,0,1,-1])$ and $\mathbf{N}(A)=\Span([1,1,0,0],[0,0,1,1]$ and so $[x_1,x_2,x_3,x_4]=x_1/2([1,-1,0,0]+[1,1,0,0])+x_2/2(-[1,-1,0,0]+[1,1,0,0])+x_3/2([0,0,1,-1]+[0,0,1,1])+x_4/2(-[0,0,1,-1]+[0,0,1,1])$

  Then $\mathbf{u}=[x_1/2-x_2/2,x_2/2-x_1/2,x_3/2-x_4/2,x_4/2-x_3/2]$ and $\mathbf{v}=[x_1/2+x_2/2,x_1/2+x_2/2,x_3/2+x_4/2,x_3/2+x_4/2]$
  %3.4 #11b
  \item
  Given $\mathbf{b}\in \mathbb{R}^2$, give the unique element $\mathbf{x}\in \mathbf{R}(A)$ so that $A\mathbf{x}=\mathbf{b}$.

  $\left[\begin{array}{rrrr}1&-1&0&0\\0&0&1&-1\end{array}\right]\left[\begin{array}{r}b_1/2\\-b_1/2\\b_2/2\\-b_2/2\end{array}\right]=\left[\begin{array}{r}b_1\\b_2\end{array}\right]$
  \end{enumerate}
\setcounter{enumi}{16}
\item
%3.4 #17
Let $V\subset \mathbb{R}^n$ be a subspace, and suppose you are given a linearly independent set of vectors $\{\mathbf{v}_1,\dots,\mathbf{v}_k\}\subset V$. Show that if $\dim V>k$ then there are vectors $\mathbf{v}_k+1,\dots,\mathbf{v}_l\in V$ so that $\{\mathbf{v}_1,\dots,\mathbf{v}_l\}$ forms a basis for $V$.

If $\dim V>k$ then we can choose some element $\mathbf{v}_{k+1}\in V$ and $\mathbf{v}_{k+1}\not\in \Span\left(v_1,\dots,v_k\right)$. The set $\{v_1,\dots,v_{k+1}\}$ is linearly independent. If $\dim V>k+1$ then we choose another element From $V$ which is not the span of our set. We can continue in this way, until there are $\dim V$ elements in our set.
\item
%3.4 #18
Suppose $V$ and $W$ are subspaces of $\mathbb{R}^n$ and $W\subset V$. Prove that $\dim W\le \dim V$. (\emph{Hint:} Start with a basis for $W$ and apply Exercise 17.)

We choose a basis for $W$. This set contains $\dim W$ vectors. If $\dim W=\dim V$ then we are done. Otherwise, we choose some element of $V$ not in $W$ and proceed as in the last question until we have formed a basis for $V$. The size of this set is bigger than the size of the basis of $W$ and so $\dim W<\dim V$.
\item
%3.4 #19
Suppose $A$ is an $n\times n$ matrix, and let $\mathbf{v}_1,\dots,\mathbf{v}_n\in \mathbb{R}^n$. Suppose $\{A\mathbf{v}_1,\dots,A\mathbf{v}_n\}$ is linearly independent. Prove that $A$ is nonsingular.

If there exists a $v_i=0$ then $Av_i=0$ and $\{Av_1,\dots,Av_n\}$ is not linearly independent. So $v_i\ne 0$ for all $1\le i\le n$. Now let us assume that some $v_i=\alpha_1\mathbf{v}_1+\dots+\alpha_{i-1}\mathbf{v}_{i-1}+\alpha_{i+1}\mathbf{v}_{i+1}+\dots+\alpha_n\mathbf{v}_{n}$. Then $Av_i=\alpha_1A\mathbf{v}_1+\dots+\alpha_{i-1}A\mathbf{v}_{i-1}+\alpha_{i+1}A\mathbf{v}_{i+1}+\dots+\alpha_nA\mathbf{v}_{n}$. But then $\{A\mathbf{v}_1,\dots,A\mathbf{v}_n\}$ is not linearly independent, and so $\{v_1,\dots,v_k\}$ must be linearly independent. Thus $\Span(\mathbf{v}_1,\dots,\mathbf{v}_n)=\mathbb{R}^n$.

Now if $\alpha_1A\mathbf{v}_1+\dots+\alpha_nA\mathbf{v}_n=0$ then $\alpha_i=0$ for all $1\le i\le n$. And of course $A(\alpha_1\mathbf{v}_1+\dots+\alpha_n\mathbf{v}_n)=0$. But if $A$ is singular, then there exists some $\mathbf{x}\ne \mathbf{0}$ so that $A\mathbf{x}=0$. And $\mathbf{x}\in \Span(\mathbf{v}_1,\dots,\mathbf{v}_2)$ so then there exists some $\alpha_i\ne 0$. But we have already established that $\alpha_i=0$ for all $\alpha_i$ and so we have a contradiction, thus $A$ is nonsingular.
\setcounter{enumi}{20}
\item
%3.4 #21
Let $U$ and $V$ be subspaces of $\mathbb{R}^n$. Prove that $\dim(U+V)=\dim U+\dim V-\dim(U\cap V).$ (\emph{Hint:} This is a generalization of Exercise 20. Start with a basis for $U\cap V$, and use Exercise 17.)

Recall that $U\cap V\le U$ and $U\cap V\le V$. Now any element in $U+V$ is a linear combination of a basis for $U$ and a basis for $V$. But any elements of $U\cap V$ in the basis of $U$ can be expressed as a linear combination of elements from the basis in $V$. And so the dimension of $U+V$ is $\dim V+\dim U-\dim U\cap V$.
\item
%3.4 #22
Continuing Exercise 3.2.10: Let $A$ be an $m\times n$, and let $B$ be an $n\times p$ matrix.
  \begin{enumerate}
  \item
  %3.4 #22a
  Prove that $\rank(AB)\le \rank(A).$ (\emph{Hint:} Look at part $b$ of Exercise 3.2.10.)

  We showed in 3.2.10 that $\mathbf{C}(AB)\subset\mathbf{C}(A)$. And we know that $\dim \mathbf{C}(A)=\dim A=\rank A$ while $\dim \mathbf{C}(AB)=\dim AB=\rank AB$. And so $\rank(AB)\le \rank(A)$
  \item
  %3.4 #22b
  Prove that if $n=p$ and $B$ is nonsingular, then $\rank(AB)=\rank(A)$

  From 3.2.10d we know that $\mathbf{C}(AB)=\mathbf{C}(A)$ and so $\rank(AB)=\dim \mathbf{C}(AB)=\dim\mathbf{C}(A)=\rank(A)$
  \item
  %3.4 #22c
  Prove that $\rank(AB)\le \rank(B)$. (\emph{Hint:} Use part $a$ of Exercise 3.2.10 and Theorem 4.6.)

  $N(B)\subset N(AB)$ so $\dim N(B)\le \dim N(AB)$. But $\dim N(B)=p-\rank(B)$ and $\dim N(AB)=p-\rank(AB)$ and so it follows that $p-\rank(B)\le p-\rank(AB)$ or $\rank(AB)\le \rank(B)$
  \item
  %3.4 #22d
  Prove that if $m=n$ and $A$ is nonsingular, then $\rank(AB)=\rank(B)$.

  We have $\text{row}_i(AB)=a_{i1}\text{row}_1(B)+\dots+a_{in}\text{row}_n(B)\in\Span(\text{row}_1(AB),\dots,\text{row}_n(AB))$ and so $R(AB)\le R(B)$. If $AB=C$ then $B=A^{-1}C$ and $R(B)=R(A^{-1}C)\le R(C)=R(AB)$. Since the size of the rowspace is equal to the rank we have $\rank(AB)=\rank(B)$
  \item
  %3.4 #22e
  Prove that if $\rank(AB)=n$, then $\rank(A)=\rank(B)=n$.

  We know that $n=\rank(AB)\le \rank (A)\le n$ because the rank cannot be greater than the number of columns in $A$. And so $n\le \rank(A)\le n$. Similarly $n\le \rank(B)\le n$ because the rank must be less than the number of rows in $B$.
  \end{enumerate}
\setcounter{enumi}{23}
\item
%3.4 #24
Continuing Exercise 3.2.10: Let $A$ be an $m\times n$ matrix.
  \begin{enumerate}
  \item
  Use Theorem 2.5 to prove that $\mathbf{N}(A^TA)=\mathbf{N}(A)$. (\emph{Hint:} If $\mathbf{x}\in \mathbf{N}(A^TA)$, then $A\mathbf{x}\in \mathbf{C}(A)\cap \mathbf{N}(A^T)$.)

  If $\mathbf{x}\in N(A)$ then $(A^TA)\mathbf{x}=A^T(A\mathbf{x})=A^T\mathbf{0}=0$ and so $N(A)\subset N(A^TA)$. Now if $\mathbf{x}\in N(A^TA)$ then $(A^TA)\mathbf{x}=0=A^T(A\mathbf{x})$ and $A\mathbf{x}\in N(A^T)$. Further $A\mathbf{x}\in C(A)$ by proposition 4.10. But $N(A^T)$ and $C(A)$ are orthogonal and so $A\mathbf{x}=0$. Thus $N(A^TA)\subset N(A)$
  \item
  Prove that $\rank(A)=\rank(A^TA)$.

  $N(A)=n-\rank(A)=N(A^TA)=n-\rank(A^TA)$ and so $\rank(A)=\rank(A^TA)$
  \item
  Prove that $\mathbf{C}(A^TA)=\mathbf{C}(A^T)$.

  From 3.2.10 we have $C(A^TA)\subset C(A^T)$ and from above we have $\dim C(A^TA)=\rank(A)$. And $C(A^T)=R(A)$, thus $\dim C(A^T)=\rank(A)$. And so because they have the same dimension, we know that $C(A^TA)=C(A^T)$
  \end{enumerate}
\end{enumerate}
\end{document}


\chapter{Key and related works}\label{ch:2}

In this chapter, we start by introducing the \textit{HSM model} by \cite{antolik} model, which will be the main focus of our experiments. Further, we describe a model by \cite{klindt}, whose \textit{separable layer} contribution we will also explore. To provide some background, we finish with a quick look at a few additional related works.

\section{Antolík et al. and the DoG layer}

Published in \citeyear{antolik}, the paper \textit{Model Constrained by Visual Hierarchy Improves Prediction of Neural Responses to Natural Scenes} by \citeauthor{antolik} introduced a three layer DNN model to fit primary visual cortex responses to image stimuli. As its main contribution, it explored incorporating biologically plausible components with traditional DNN methods. Doing so, it managed to outperform\footnote{For results refer to \refsection{ch:4.1.2}.}, at the time of writing, other state of the art methods while providing greater interpretability and requiring less free parameters.

The model is grounded in known hierarchical properties of the early visual system in three ways. First, it assumes that LGN units can be well modeled using difference-of-Gaussians filters. Second, that local population of V1 neurons share inputs from a limited number of such LGN units. Third, that simple cells can be constructed as a combination of several LGN neurons and complex cells similarly from simple cells. Based on these assumptions, the model consists of 3 layers (Fig. \ref{fig:2.1}): the first represents both the retinal and LGN computation, and the second and third the two levels of V1 neurons.

\subsection{DoG layer}\label{ch:2.1.1}

Retinal and LGN computations are modeled together using a set of parallel difference-of-Gaussian filters followed by an identity activation function. In the context of the HSM architecture, we will call this the filter layer. The usage of difference-of-Gaussian filters significantly decreases the number of free parameters introduced by this layer while being grounded in biological reality. Instead of \texttt{input\_width}$*$\texttt{input\_height} parameters per filter of a fully connected layer, the \textit{Difference of Gaussians layer (DoG)} is parametrized by only 6 per filter: weight and width of the center and surrounding Gaussians and x, y coordinates of their shared center. The published model contains 9 filters DoG layer. For input $S{x,y}$, weights $\alpha_1$ and $\alpha_2$, widths $\sigma_1$ and $\sigma_2$, and center $\mu_x$, $\mu_y$ the output of a single DoG filter is:

\begin{equation}\label{eq:2.1}
    \sum_{x,y}^{w,h} S_{x,y}
\left(
{\frac{\alpha_1}{ 2 \sigma_1 \pi}} e^{\frac{(x - \mu_x)^2 + (y - \mu_y)^2}{2\sigma_1}} -
{\frac{\alpha_2}{2 (\sigma_1+\sigma_2) \pi}} e^{\frac{(X - \mu_x)^2 + (Y - \mu_y)^2}{ 2(\sigma_1+\sigma_2) }}
\right)
\end{equation}

\subsection{V1 neurons}
The two levels of V1 neurons are modeled as two consecutive fully connected layers. We will call these the hidden and output layers. The output layer has the same size as the number of measured neurons. The hidden layer is proportional to the size of the output layer. In the case of the reported model, its size is 20 \% of the number of measured neurons. Both fully connected layers are followed by a SoftPlus\footnote{Refer to table \ref{tab:1.1}.} nonlinearity.

\begin{figure}[h]
    \centering
    \includegraphics[width=1\textwidth]{../figures/02_HSM}
    \caption[HSM model architecture]{Three layer architecture of \textit{HSM model} and corresponding neural sections. Figure was adopted from \citep{antolik}.}
    \label{fig:2.1}
\end{figure}

\subsection{Training regime}\label{ch:2.1.3}

The published model was trained using a Newton Conjugate-Gradient algorithm\footnote{\href{https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_tnc.html}{https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin\_tnc.html}.} with 100 epochs, each consisting of 10 000 evaluations maximum. The batch size for this optimiser is the entire dataset. In addition to the \textit{hard regularization} provided by the parameterized filters of the DoG layer, all parameters -- of the weights of DoG layer and both fully connected layers -- were kept within predefined bounds by the optimiser throughout the fitting. These bounds were also used for random initialization of the parameters, during which values were drawn from uniform distributions with corresponding bounds. No other \textit{soft} or \textit{hard regularization} is present in the model.

The reported values for the hidden layer size ratio and the number of DoG filters hyperparameters were found empirically using two one-dimensional searches through the parameter space.

\section{Klindt et al. and the separable layer}\label{ch:2.2}

In \citeyear{klindt} \citeauthor{klindt} published a paper \textit{Neural system identification for large populations separating “what” and “where”} that explored deep convolutional neural networks in the context of V1 neural data. It specifically focused on the estimation of individual neurons’ receptive field locations through a novel approach to readout layer\footnote{Readout layer is the first fully connected layer after a set of convolutional layers.} factorization, in an effort to allow effective fitting of thousands of neurons on relatively little data simultaneously. In addition to artificial data, it was also evaluated on the same dataset as \cite{antolik} where it achieved moderate improvements\footnote{For exact results refer to \refsection{ch:4.1.2}.} over the HSM model by \citeauthor{antolik}

\subsection{Architecture}

The model (further also referred to as the \textit{what/where model}) consists of two parts, feature space and receptive fields (Fig. \ref{fig:2.2}). The feature space is a cascade of -- in the variant for \citeauthor{antolik} dataset -- 3 convolutional layers, each followed by a batch normalisation\footnote{\citep{2015arXiv150203167I}} and a SoftPlus activation function. The convolution layers have 48 feature maps per each layer, with the first one having 13 pixel and the other two 3 pixel kernels. In addition, the convolution layers feature two types of \textit{soft regularizations}. A Laplacian regularizations to ensure smoothness of the filters and an L2 based group sparsity regularization\footnote{For a definition, please refer to the original paper \citep{klindt}.} to encourage filters to pool from only a small set of feature maps in the previous layer.

\begin{figure}[h]
    \centering
    \includegraphics[width=1\textwidth]{../figures/02_fig2_A2u}
    \caption[klindt et al. model]{Architecture of \citeauthor{klindt} model, consisting of convolution layers and a factorized readout layer. Figure was adopted from \citep{klindt}.}
    \label{fig:2.2}
\end{figure}

The receptive field consists of a single instance of a specific readout layer (further referred to as the \textit{separable layer}). It is a fully connected layer factored into two masks per each output neuron. First mask, with dimensionality \texttt{feat\_space\_output\_spatial\_dims}, selects the input locations the output neuron will use, in essence its receptive field -- the \textit{where}. The other, with dimensionality of \texttt{feat\_space\_output\_channels}, determines what channels of the feature space at each of the locations will make the neuron’s output -- its \textit{what}. This factorization achieves two things. It decreases the number of free parameters, from \texttt{spatial\_dims}$*$\texttt{channels} to \texttt{spa\-tial\_dims}$+$\texttt{channels} but also enables more direct interpretability of the parameters. Comparing the \textit{what} masks, for example, allows us to identify similar cell types. Both masks feature L1 regularization to encourage sparsity.

The model was trained using ADAM optimiser and early stopping on 20/80 training set split. Reported hyperparameters, such as the number and size of convolution filters, were found and cross-validated using grid search for each region.

\section{Related works}\label{ch:2.3}
To provide some background, this section lists a few related works that are relevant to V1 system identification but are not directly used or in any way referenced by our experiments. Specifically, we will introduce a few convolutional architectures, as they have seen an increase in usage for V1 modeling, similarly as they have taken over classical computer vision\footnote{Even though they are slowly being superseded by attention/transformer-based networks: \citep{2019arXiv190605909R}, \citep{2019arXiv190409925B}), \citep{dosovitskiy2020image}.}.

\subsection{Neural convolutional models}
\cite{ecker} inspired by aforementioned \cite{klindt}, further explored convolutional architectures. In addition to the \citeauthor{klindt}’s observation that many neurons of early visual processing are similar but only have their receptive fields at different locations, \citeauthor{ecker}’s model leveraged the fact that even more V1 neurons are functionally the same, if we assume not only arbitrary receptive field positions but also arbitrary orientations. Based on the same two parts, 3~convolutional layers architecture introduced by \citeauthor{klindt}, their model used \textit{Group equivariant convolutions} \citep{2016arXiv160207576C} instead of traditional convolution layers.

Tackling a similar problem from a different angle, \cite{Walke506956} introduced a convolutional architecture, where the readout locations -- representing the receptive fields of output neurons -- are modulated by a \textit{shifter side network} based on eye movement data. In addition, the neural outputs are further adjusted by a \textit{second side network} using behaviour data (running state, pupil dilation), trying to incorporate extra-retina sources of LGN and further downstream stages of visual processing. For the core network, the model used a three layer convolutional cascade followed by a neuron specific linear readout stage.

\subsection{Transfer learning}

Motivated by the observation that lower parts of the visual pathway can be seen analogous to early layers of classical object recognition neural networks, \cite{10.1371/journal.pcbi.1006897} explored transfer learning within the domain of V1 system identification. Their proposed architecture used 16 feature maps\footnote{The output of one filter of a convolutional layer given a specific input.} from the initial section of an on-image-classification-dataset already trained VGG-16 network \citep{VGG16} and then fitted per output neuron readout layer on neural data. This approach managed to achieve parity with a 3 convolutional layer CNN architecture trained entirely on neural data, while requiring a smaller training dataset.


\subsection{Key steps of a \acrshort{mcts}}%
\label{sub:key_components_of_a_mcts}

A \gls{mcts} algorithm such as \gls{uct} follows four steps that are repeated indefinitely.
Theses steps are the selection, the expansion, the simulation and the backpropagation.
Here, we will give a quick explanation of each of these steps.
But, before going in, we have to explain what the tree used in \gls{mcts} approach looks like.

A \gls{mcts} tree is a tree as defined in graph theory which is not mandatory to explain here.
At the top of the tree, we find the root state, which is the current state of the game, the one for which we search the best action.
Each node of the tree is a state and nodes are connected by actions.

\paragraph*{During the selection}
the algorithm will descend in the tree from node to node, starting from the root node.
At one point, according to a policy, it will stop on a node corresponding to a state \(s\) and begin the expansion phase.

\paragraph*{The expansion}
phase corresponds to the addition of a new node on the tree.
It applies an action \(a \in A_{s}\) chosen according to a policy.
Then, it adds the resulting state, let's say \(s'\) to the tree.

\paragraph*{The simulation}
is a Monte-Carlo simulation.
It is used to evaluate the quality of a node for a given player.
It consists in playing the game randomly from state \(s'\) until a terminal state is reached.
No modification is done to the tree.
The simulation is called a rollout because it is a random playout.
It follows what is called the default policy which chooses the action uniformly.

\paragraph{The backpropagation}
is the last phase.
The result of the rollout is transmitted back to the top of the tree.
It follows back the way chosen at the selection.
We can then have statistics on each node which, often, are useful to create the policy used during the selection and expansion.

All theses steps are repeated over and over again.
The number of repetition is often limited by a search time which is set beforehand.
Based on the tree obtained at the end, the player can choose which action apply on the root state.
Often, the search is repeated on a new tree each turn to avoid the algorithm to be stuck on the same strategy.
erge


\documentclass[a4]{jgaa-art}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[toc,page]{appendix}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{hhline}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newenvironment{definition}[1][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\algnewcommand{\LineComment}[1]{\State \(\triangleright\) #1}

\title{Enhancing PQ-tree Planarity Algorithms for non-adjacent $s$ and $t$ }

\author{Shoichiro Yamanishi}

\date{\today}

\begin{document}

\maketitle

\begin{abstract}
The PQ-tree based planarity testing algorithm presented
by Booth and Lueker in \cite{BL76} requires an st-ordering where $\{s,t\}$ must exist.
We propose an enhancement to the algorithm that permits st-ordering of any vertex pair.
The enhancement is made by introducing a type of circular consecutiveness of pertinent
leaves denoted by  {\it complementarily partial},
 where the pertinent leaves can be consecutively arranged only at both ends of the frontier with
one or more non-pertinent leaves in between.
The implementation is enhanced with 4 additional templates P7, P8, Q4, and Q5.
The correctness of the new algorithm is given following the proof in
 \cite{EVEN79} and \cite{LEC67}
on the equivalence of PQ-tree and its new reduction operations to the corresponding bush form.
The complexity of the new algorithm stays $O(|N|)$.
\end{abstract}

\section{Introduction}\label{se:intro}

%Context
%Purpose
%Summary
%Forecast

PQ-tree data structure and the reduction algorithm were first proposed by Booth and Lueker \cite{BL76}
in 1976.
PQ-tree is a rooted ordered tree with three node types: L-node represents a leaf with no children, P-node
permits any permutation of its children, Q-node has an ordering on its children but it can be reversed.
PQ-tree is used to represent a set of permissible permutations of elements in $S$, and the reduction
operation tries to find a consecutive arrangement of subset $U$ of $S$.
It has many applications including the planarity testing of an undirected biconnected graph $G(V,E)$.
Booth and Lueker proposed a planarity testing algorithm in their original paper \cite{BL76}.
It has $O(|N|)$ time complexity, and it depends on a particular ordering on graph vertices called st-ordering,
where the two terminal nodes $s$ and $t$ must be adjacent as in $\{s,t\}$.
An st-ordering can be found in $O(|N|)$ time with an algorithm such as \cite{TARJAN86}, assuming $|E| \le 3|V| - 6$ .

The algorithm falls in a category called vertex addition.
Each graph vertex $v$ is processed in an iteration according to the st-ordering.
Conceptually each graph vertex is added to the bush form \cite{LEC67},\cite{EVEN79}, and the PQ-tree
evolves reflecting the state of the bush form.
Each iteration of the algorithm transforms the PQ-tree for $v$
 and its incident edges.
In the beginning of an iteration, the tree leaves that correspond to the incoming graph edges incident to $v$,
or {\it pertinent leaves}, are gathered consecutively in the tree by transforming the tree
in a series of template applications.
The minimum connected subtree for all the pertinent leaves, or {\it pertinent tree}, is removed from the tree,
and then new leaves that corresponds to the outgoing graph edges incident to $v$ are added to the tree node
that was the pertinent tree root.
The st-ordering ensures there is at least one incoming graph edge and one out going graph edge at
each iteration except for the first and the last.
At the first iteration the leaves for the outgoing graph edges of the first graph vertex in the st-ordering
are attached to the initial P-node, and the PQ-tree evolves form there over the iterations.
At an iteration, if the pertinent leaves can not be arranged consecutively, the algorithm aborts and declares it
non-planar.
At the second to last iteration, if all the pertinent leaves are consecutively arranged, the graph is declared planar.

The PQ-tree itself is an elegant data structure to represent a set of permissible permutations of elements,
but its reduction algorithm involves 10 rather cumbersome tree transformation operations called templates, though
each of them is straightforward and intuitive to understand.
Since the original algorithm was published, many graph planarity-related algorithms have been proposed,
 but some of them were later proven to have some issues in them \cite{OZAWA81} \cite{JTS89} \cite{KANT92}.
For example, J\"unger, Leipert, and Mutzel \cite{JUNGER97} discuss the pitfalls and difficulties of using
PQ-trees for maximal planarization graphs.
It seems to take a very careful attention when we apply PQ-tree to graph planarity algorithms despite its apparent
straight-forwardness and intuitiveness.

Another data structure called PC-tree was proposed by Shih and Hsu \cite{HSU99}.
It is a rootless tree to express permissible 'circular' permutations.
Hsu \cite{HSU99} proposes a planarity test algorithm using PC-tree with iterative vertex
 addition along a DFS exploration of graph vertices.
Hsu \cite{HSU01} compares PQ-tree and PC-tree in terms of planarity testing.
Hsu\cite{HSU01} mentions testing 'circular ones' property with PC-tree and
'consecutive ones' property with PQ-tree.

In this paper, we will expand the PQ-tree planarity algorithm for any (not necessarily adjacent) $s$,$t$ pair.
A non-adjacent st-ordering will introduce a new type of consecutiveness through the course of the algorithm on the PQ-tree.
It is a type of 'circular' permutation.
We define the type of circular permutations that the original algorithm can not handle
 as {\it complementarily partial}.
We show the insufficiency of the set of the original templates in Booth and Lueker \cite{BL76} with a specific example, and propose 4
new templates to handle complementarily partial nodes.
Then we prove the correctness of the new algorithm following  Lempel, Even, and Cederbaum \cite{LEC67} and Even \cite{EVEN79} in equivalence to the corresponding bush form.
We show the time complexity stays $O(|N|)$.
We then discuss some implementation details.
The algorithm mainly consists of two parts called BUBBLE() and REDUCE() in \cite{BL76}.
We show that no change is required for BUBBLE(), but the 4 new templates have to be added to REDUCE().

PQ-tree and its reduction technique are also used for some planarization algorithms such as
\cite{OZAWA81}, \cite{JTS89}, and \cite{KANT92}.
In those algorithms, the costs are calculated per tree node,
and some tree leaves that have associated graph edges are removed based on the costs to maintain planarity.
The costs are basically the number of descendant tree leaves that would have to be removed to
make the tree node of certain pertinent and non-pertinent type.
We briefly propose an improvement on the cost values.
Without the improvement, some graph edges can be removed unnecessarily as a consequence of lack of handling the {\it complementarily partial} nodes defined below.

\section{Circular Consecutiveness}\label{se:insuff}

The insufficiency of the existing algorithm is best shown by a real example.
Please see figure~\ref{fig:pq_tree_01} and~\ref{fig:bush_form_01}.
They are taken from a snapshot of the original algorithm for the graph and the st-numbering shown in Appendix A.
Figure~\ref{fig:pq_tree_01} is the PQ-tree at the 23rd iteration after
BUBBLE(), and figure~\ref{fig:bush_form_01} is the corresponding bush form.
In this iteration the graph vertex $2$ is to be added.
The pertinent leaves that correspond to $\{8,2\}$,$\{3,2\}$, and $\{7,2\}$
 are about to be consecutively arranged in REDUCE().
Those edges can be consecutively arranged in a circular manner.
However, the reduction fails at Q-node $Q4$ as none of the templates Q1,Q2,
or Q3 can handle this arrangement.
In $Q4$, the pertinent leaves can only be arranged consecutively
 at both ends with one or more non-pertinent leaves in between.

As shown above, the original algorithm is not capable of handling this type
of arrangements of the pertinent leaves with pertinent leaves at both ends.
This is a result of using a rooted tree structure to handle circular
consecutiveness around the outer face of the corresponding bush form.
Once a Q-node has formed in the PQ-tree, at a later iteration
if there is a pertinent node of complementarily partial,
there will be no way to arrange the pertinent nodes consecutively using the
original set of templates,
even if the corresponding bush form permits circular consecutiveness.

\begin{figure}[!htb]
  \centering
  \begin{minipage}[b]{0.64\textwidth}
    \includegraphics[width=\textwidth]{pq_tree_sample_01}
    \caption{PQ-tree}
    \label{fig:pq_tree_01}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.35\textwidth}
    \includegraphics[width=\textwidth]{bush_form_01}
    \caption{Bush form}
    \label{fig:bush_form_01}
  \end{minipage}
\end{figure}

\section{Enhancement with New Templates}\label{se:correction}
In the previous section we showed a type of node arrangement in PQ-tree that
the original algorithm can not handle.
In this section we first formulate this condition by defining a new
pertinent node type {\it complementarily partial}, and then
introduce 4 new templates.
Then we discuss other changes required in BUBBLE() and REDUCE().

\begin{definition}
A \emph{P-node} is \emph{complementarily partial}, if either of the following
holds:
\begin{enumerate}
\item \label{item:P2}It is not a pertinent root, and it satisfies the
condition for template $P6$ on the arrangement of child nodes,
i.e., if there are exactly two singly partial children. (Figure \ref{fig:pq_tree_02})
\item \label{item:P1}There is exactly one complementarily partial child, and all the
 children are full. (Figure \ref{fig:pq_tree_03})
\end{enumerate}
\end{definition}

\begin{definition}
A \emph{Q-node} is \emph{complementarily partial}, if either of the following
holds:
\begin{enumerate}
\item \label{item:Q2}The children are arranged as the complement of permissible arrangement
   for template $Q3$, i.e., if the descendant pertinent leaves can be arranged
   consecutively at both ends with one or more non-pertinent leaves in between.
 (Figure \ref{fig:pq_tree_04})
\item \label{item:Q1}There is exactly one complementarily partial child, and all the children
   are full
 (Figure \ref{fig:pq_tree_05})
\end{enumerate}
\end{definition}

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.9\textwidth]{pq_tree_sample_02}
  \caption{P-node Condition 1, Template P7}
  \label{fig:pq_tree_02}
\end{figure}

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.5\textwidth]{pq_tree_sample_03}
  \caption{P-node Condition 2, Template P8}
  \label{fig:pq_tree_03}
\end{figure}

\begin{figure}[!htb]
  \centering
  \includegraphics[width=\textwidth]{pq_tree_sample_04}
  \caption{Q-node Condition 1, Template Q4}
  \label{fig:pq_tree_04}
\end{figure}

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.55\textwidth]{pq_tree_sample_05}
  \caption{Q-node Condition 2, Template Q5}
  \label{fig:pq_tree_05}
\end{figure}

The first condition for Q-node is formerly defined using a regular expression
for the children as:
\[F+((S(D?|E+D))|(E+D))|SE*D\]

where $F$ denotes a full child, $S$ a singly partial child, $E$ a
 non-pertinent child, and $D:=((F|S)F*)$ for notational convenience.

First we show there is no need to change BUBBLE() to handle the complementarily
 consecutive cases.
If the PQ-tree permits complementarily partial arrangement, then the tree
node will be the pertinent tree node. During BUBBLE(), the parent of
all the pertinent nodes will be eventually found, and there will be no need
for a surrogate parent, or {\it pseudo node} in \cite{BL76}.

Next, we introduce 4 new templates for each of 4 conditions shown in the
 definitions above. Basically Template P7 is a complement version of Template P6,
and Template Q4 is a complementary version of Q3. Template P8 and Q5 are
for trivial recursive cases.

Finally we show the updated REDUCE().

\begin{algorithm}
\caption{Template P7}\label{template_P7}
\begin{algorithmic}[1]
\Procedure{TemplateP7}{X: reference to a node object}
\If {$X.type \ne P$} \Return false
\EndIf
\If {Number of singly partial children $\ne 2$} \Return false
\EndIf
\State $newX \gets \text{CreateNewPNode()}$
\State Move all the full children of $X$ to $newX$
\State $C_1 \gets \text{Singly partial child}_1$
\State $C_2 \gets \text{Singly partial child}_2$
\State Remove links of $C_1$ and $C_2$ from $X$
\LineComment At this point $X$ contains zero or more empty children only.
\State Save the location of $X$ in the PQ-tree to $L_X$
\State Unlink $X$ from the PQ-tree
\If {Number of empty children of $X > 1$}
\State Put $X$ to the empty side of sibling list of $C_1$
\ElsIf {Number of empty children of $X = 1$}
\State Put the empty child to the empty side of sibling list of $C_1$
\State Discard $X$
\Else
\State Discard $X$
\EndIf
\State Concatenate the children list of $C_2$ to $C_1$'s on the empty sides
\State Discard $C_2$
\State $C_1.pertinentType \gets \textit{ComplementarilyPartial}$
\If {Number of full children of $newX \ge 1$}
\State Put $C_1$ under $newX$
\State Link $newX$ at $L_X$ in the PQ-tree
\State $newX.pertinentType \gets \textit{ComplementarilyPartial}$
\Else
\State Link $C_1$ at $L_X$ in the PQ-tree
\EndIf
\Return true
\EndProcedure
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{Template P8}\label{template_P8}
\begin{algorithmic}[1]
\Procedure{TemplateP8}{X: reference to a node object}
\If {$X.type \ne P$} \Return false
\EndIf
\State $|F| \gets $ Number of full children of $X$
\State $|C| \gets $ Number of children of $X$
\If {$|F|+1 \ne |C|$} \Return false
\EndIf
\State $C_{cp} \gets $the non-full child of $X$
\If {$C_{cp}.pertinentType \ne \textit{ComplementarilyPartial}$} \Return false
\EndIf
\State {$X.pertinentType \gets \textit{ComplementarilyPartial}$}
\State\Return {true}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{Template Q4}\label{template_Q4}
\begin{algorithmic}[1]
\Procedure{TemplateQ4}{X: reference to a node object}
\If {$X.type \ne Q$} \Return false
\EndIf
\If {Children of $X$ are not ordered according to the condition for Q4}
\Return false
\EndIf
\For {each $C_{sp}$ of singly partial children}
\State Flatten $C_{sp}$ into $X$ such that the full side of the children list
of $C_{sp}$ is concatenated to the full immediate sibling of $C_{sp}$
\EndFor
\State $X.pertinentType \gets \textit{ComplementarilyPartial}$
\State \Return {true}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{Template Q5}\label{template_Q5}
\begin{algorithmic}[1]
\Procedure{TemplateQ5}{X: reference to a node object}
\If {$X.type \ne Q$} \Return false
\EndIf
\State $|F| \gets $ Number of full children of $X$
\State $|C| \gets $ Number of children of $X$
\If {$|F|+1 \ne |C|$} \Return false
\EndIf
\LineComment {The check above can be made wihtout calculating $|C|$}
\State $C_{cp} \gets $the non-full child of $X$
\If {$C_{cp}.pertinentType \ne \textit{ComplementarilyPartial}$} \Return false
\EndIf
\State {$X.pertinentType \gets \textit{ComplementarilyPartial}$}
\State\Return {true}
\EndProcedure
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\caption{REDUCE}\label{reduce}
\begin{algorithmic}[1]
\Procedure{REDUCE}{T, S}
\LineComment $PERTINENT\_LEAF\_COUNT$ is shortened to $PLC$.
\LineComment $PERTINENT\_CHILD\_COUNT$ is shortened to $PCC$.
\State $QUEUE \gets $ empty list
\For {each leaf $X \in S$}
\State place $X$ to the back of $QUEUE$
\State $X.PLC \gets 1$
\EndFor
\While {$|QUEUE| > 0$}
\State remove $X$ from the front of $QUEUE$
\If {$X.PLC < |S|$}
\Comment $X$ is not $ROOT(T,S)$
\State $Y \gets X.PARENT$
\State $X.PLC \gets X.PLC + Y.PLC$
\State $X.PCC \gets X.PCC - 1$
\If {$X.PCC = 0$}
\State place $Y$ to the back of $QUEUE$
\EndIf
\If {not TEMPLATE\_L1(X)}
\If {not TEMPLATE\_P1(X)}
\If {not TEMPLATE\_P3(X)}
\If {not TEMPLATE\_P5(X)}
\If {not TEMPLATE\_P7(X)}
\If {not TEMPLATE\_P8(X)}
\If {not TEMPLATE\_Q1(X)}
\If {not TEMPLATE\_Q2(X)}
\If {not TEMPLATE\_Q4(X)}
\If {not TEMPLATE\_Q5(X)}
\State {$T \gets T(\emptyset, \emptyset)$}
\State {\bf exit} from {\bf do}
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\Else
\Comment $X$ is not $ROOT(T,S)$
\If {not TEMPLATE\_L1(X)}
\If {not TEMPLATE\_P2(X)}
\If {not TEMPLATE\_P4(X)}
\If {not TEMPLATE\_P6(X)}
\If {not TEMPLATE\_P8(X)}
\If {not TEMPLATE\_Q1(X)}
\If {not TEMPLATE\_Q2(X)}
\If {not TEMPLATE\_Q3(X)}
\If {not TEMPLATE\_Q4(X)}
\If {not EMPLATE\_Q5(X)}
\State {$T \gets T(\emptyset, \emptyset)$}
\State {\bf exit} from {\bf do}
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndIf
\EndWhile
\Return T
\EndProcedure
\end{algorithmic}
\end{algorithm}

\section{Correctness of the New Algorithm}\label{se:correctness}

We prove the correctness following the series of lemmas, theorems, and a corollary given in
Section 8.4 of \cite{EVEN79} by Even.
In their book, the equivalence between the transformations on the bush form
and the reductions on PQ-tree is left for the readers on pp 190.
We fill the missing part with the following proof.

In a similar case, Hsu \cite{HSU01} tries to prove the equivalence between
PQ-tree and PC-tree in its Theorem 5, but it is not sufficient.
It proves the equivalence from PQ-tree to PC-tree for each of the templates.
However the sufficiency of the PQ-tree templates for all the possible
PC-tree transformations is not given.

The proof presented here is relatively long involving many notations and concepts.
However, it may be a useful guide to study the details of the PQ-tree behavior.

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.8\textwidth]{proof_overview}
  \caption{Overview of the Proof of the Correctness of the Proposed Algorithm}
  \label{fig:proof_overview}
\end{figure}

Figure \ref{fig:proof_overview} shows the overview of the proof.
It proves the equivalence between bush form with the operations on it and the
corresponding PQ-tree with the operations on it.
The proof uses two intermediate representations: Marked bush form and its underlying rooted embedded bc-tree.
A marked bush form is based on a bush form by placing a root marker on a cut vertex or an edge on the outer
face of a block.
Such a marker splits the circular arrangement of virtual edges around the bush form into one of three types of
a linear consecutive arrangement with two designated end points at the marker.
The root marker also introduces the root-to-descendants orientation to the bush form.

We prove in Lemma \ref{lem:lemma1} that a circular consecutive arrangement of virtual edges
by arbitrary reorderings of incident edges around cut vertices and flippings of blocks in a bush form is
 equivalent to a linear consecutive arrangement by reordering of cut vertices and flipping of blocks
 from the leave components toward the root. In the proof we also show that the incident components
 around each cut vertex or a block will be arranged in one of 5 types of orderings.

We then introduce the underlying block-cut tree of the marked bush form, called rooted embedded bc-tree,
and prove equivalence between the rooted embedded bc-tree and the PQ-tree with their operations in Lemma 2 and 3.

First, we introduce some concepts, operations, and notations required for the following discussions.

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.4\textwidth]{marked_bush_form_00}
  \caption{A Bush Form}
  \label{fig:bush_form}
\end{figure}

\begin{definition}
Type of nodes and edges along the outer face of a bush form
\begin{itemize}
\item {\bf \emph{virtual node}} of a bush form is a node of degree 1 that represents a copy of a node
in the original graph \cite{EVEN79}. In figure \ref{fig:bush_form}, $v1$...$v14$ are virtual nodes.
\item {\bf \emph{virtual edge}} of a bush form is an edge incident to a virtual node.
\item {\bf \emph{pertinent virtual node}} is a virtual node that  corresponds to a pertinent leaf
in PQ-tree. I.e., a virtual node to be merged.
\item {\bf \emph{pertinent virtual edge}} is a virtual edge incident to a pertinent virtual node.
\end{itemize}
\end{definition}

\begin{definition}
Operations on a bush form and a marked bush form.
\begin{itemize}
\item {\bf \emph{attach}} is an operation to attach new virtual edges to a vertex $v$ in the bush form.
As a result it makes $v$ a cut vertex in the bush form.
\item {\bf \emph{reorder}} of a cut vertex in a bush form is the operation to rearrange the circular ordering of
the incident edges around the cut vertex.
\item {\bf \emph{flip}} of a block in a bush form is reversing the combinatorial embedding of the block.
As a result, the ordering the outer face of the block is reversed.
\item {\bf \emph{merge}} is an operation to merge virtual nodes into single real node in the bush form. As a result a new
block forms in the bush form.
\end{itemize}
\end{definition}

\begin{definition}
If a bush form is decomposed to maximal connected components by removing a cut vertex $c$, or a block $B$,
an {\bf \emph{active component}} of a cut vertex $c$ or $B$ is a maximal connected component incident
to $c$ or $B$ that has at least one virtual node in it.
In figure \ref{fig:bush_form}, $c3$ has three maximally connected components.
The component that includes $b5$, $c11$, $c10$, and $b4$ is not an active component. The other two are.
\end{definition}

\begin{definition}
An {\bf \emph{orienting}} cut vertex or a block is a cut vertex or a block in the bush form that has at least 3 incident
active components if the corresponding node in the PQ-tree is not the root.
If the corresponding PQ-tree is the root, then it is a cut vertex or a block that has at least 2 incident active
components. Such a correspondence is proved in Lemma 3.
In figure \ref{fig:bush_form}, assuming $c1$ corresponds to the root of the PQ-tree, $c1$, $b1$, and $c7$
are orienting.
The components $c3$, $b5$, $c5$, and $c8$ are not.
\end{definition}

\begin{definition}
Additional operations on a marked bush form. These are used in the proof of Lemma \ref{lem:lemma2} and
\ref{lem:lemma3}.
\begin{itemize}
\item {\bf \emph{interlock}} is an operation to fix the orientation of
one block relative to another. As a result, flipping one of them will flip the other.
\item {\bf \emph{split}} is an operation to change a node in the bush form to $k_2$, $k_3$, or $C_4$,
and distribute the incident edges among them. If the split is for a $k_3$ or $C_4$,
a new block will result in the (marked) bush form.
\end{itemize}
\end{definition}

The following definitions are for the marked bush forms.
If we place a root marker on a cut vertex, or an edge of an outer face of a block,
it will split the circular consecutive arrangement around the bush form into one
of 3 types. In figures \ref{fig:marked_bush_form_cut_vertex} and
\ref{fig:marked_bush_form_block}, the dots and line segments in navy blue indicate
the marked vertex or edge. The dots in light blue are pertinent virtual nodes.
The dots in light yellow are non-pertinent virtual nodes.

\begin{figure}[!htb]
  \centering
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{marked_bush_form_01}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{marked_bush_form_02}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{marked_bush_form_03}
  \end{minipage}
  \caption{Bush forms with the root marker on a cut vertex}\label{fig:marked_bush_form_cut_vertex}
\end{figure}

\begin{figure}[!htb]
  \centering
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{marked_bush_form_04}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{marked_bush_form_05}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{marked_bush_form_06}
  \end{minipage}
  \caption{Bush forms with the root marker on a block}\label{fig:marked_bush_form_block}
\end{figure}

\begin{definition}
Types of linear consecutive arrangements on the marked bush form.
\begin{itemize}
\item {\it singly partially consecutive}: the pertinent virtual nodes are arranged
on either side of the linear order.
In figure \ref{fig:marked_bush_form_cut_vertex} left,
($v1$, $v3$, $v4$, $v14$, $v13$, $v12$, $v11$, $v5$, $v7$, $v6$, $v8$, $v9$, $v10$, $v2$) is such an arrangement.
In figure \ref{fig:marked_bush_form_block} left,
($v10$, $v1$, $v2$, $v14$, $v13$, $v12$, $v11$, $v3$, $v4$, $v5$, $v6$, $v7$, $v9$, $v8$) is such an arrangement.

\item {\it doubly partially consecutive}: the pertinent virtual nodes are arranged
in the middle of the linear order.
In figure \ref{fig:marked_bush_form_cut_vertex} center,
($v2$, $v14$, $v13$, $v12$, $v11$, $v1$, $v3$, $v4$, $v5$, $v7$, $v6$, $v8$, $v9$, $v10$) is such an arrangement.
In figure \ref{fig:marked_bush_form_block} center,
($v10$, $v11$, $v12$, $v13$, $v14$, $v1$, $v2$, $v3$, $v4$, $v5$, $v6$, $v7$, $v8$, $v9$) is such an arrangement.

\item {\it complementarily partially consecutive}: the pertinent virtual nodes are arranged on both side of
the linear order with one or more non-pertinent nodes in the middle.
In figure \ref{fig:marked_bush_form_cut_vertex} right,
($v1$, $v2$, $v3$, $v4$, $v5$, $v7$, $v6$, $v9$, $v8$, $v10$, $v11$, $v12$, $v13$, $v14$) is such an arrangement.
In figure \ref{fig:marked_bush_form_block} right,
($v5$, $v4$, $v3$, $v2$, $v1$, $v14$, $v13$, $v12$, $v11$, $v10$, $v6$, $v7$, $v8$, $v9$) is such an arrangement.

\end{itemize}
\end{definition}

\begin{definition}
{\bf \emph{rooted embedded bc-tree}} is the underlying block-cut vertex tree of a marked bush form.
The root marker on the bush form  gives a natural root-to-descendants orientation
on the underlying block-cut tree, and the embedding in the bush form determines
 an embedding of the block-cut tree and the embeddings of the blocks.
\end{definition}

\begin{definition}
{\bf \emph{pertinent root}} of a rooted embedded bc-tree is the highest (the closest to the root) node
in the minimal connected subtree that spans the nodes for all the pertinent virtual nodes.
\end{definition}

The left-to-right ordering of the children of the root node is determined as follows.
If the root is for a cut vertex, then pick an arbitrary incident component of the root of the marked
bush form,  and arrange the incident components in the counter-clock wise ordering.
If the root is for a block, then pick the incident component immediately after the marked edge in the
counter-clock wise ordering, and arrange the incident components accordingly.

\begin{definition}
\emph{Pertinent Types} of the nodes in a rooted embedded bc-tree are recursively defined as follows.
\begin{itemize}
\item {\bf \emph{empty}}:
Each child of the node $n$ is either non-pertinent virtual edge or an empty node.
\item {\bf \emph{singly partial}}:
The node $n$ meets one of the following conditions.
\begin{itemize}
\item $n$ is for a cut vertex, there is one singly partial child, and there is no complementarily partial child.

\item $n$ is for a cut vertex, there is no singly partial child, at least one empty child, at least one full child, and no complementarily partial child.

\item $n$ is for a block, there is no complementarily partial child, there is at least one full child, all the full children are consecutively embedded on the outer face on either side of the parent with possibly at most one singly partial child at the boundary between full children and the empty ones.

\item $n$ is for a block, there is no complementarily partial child, there is no full child, and there is exactly one singly partial child immediately next to the parent.
\end{itemize}
\item {\bf \emph{doubly partial}}:
The node $n$ meets one of the following conditions.
\begin{itemize}
\item $n$ is the pertinent root, $n$ is for a cut vertex, and there are exactly two singly partial children.
\item $n$ is the pertinent root, $n$ is for a block, at least one full child, all the full children are consecutively embedded in the middle of
 the outer face away from the parent, and possibly a singly partial child at each of the two boundaries
between full and empty children.

\item $n$ is the pertinent root, $n$ is for a block, there is no full child,
and there are exactly two consecutively embedded singly partial children.

\end{itemize}
\item {\bf \emph{complementarily partial}}:
The node $n$ meets one of the following conditions.
\begin{itemize}
\item $n$ is not the pertinent root, $n$ is for a cut vertex, and there are exactly two singly partial children.

\item $n$ is for a cut vertex and the children are all full except for one that is complementarily partial.

\item $n$ is for a block, and the children are arranged as the complement of the arrangement for doubly partial.

\item $n$ is for a block and the children are all full except for one that is complementarily partial.
\end{itemize}
\item {\bf \emph{full}}:
If all the children of $n$ are either pertinent virtual edge or full.
\end{itemize}
\end{definition}

We have defined all the necessary types and operations.
Next we prove the equivalence of a PQ-tree to its bush form.

\begin{lemma}\label{lem:lemma1}
If and only if the pertinent virtual nodes in a bush form are arranged consecutively by arbitrary
reorder and flip operations, then there is a sequence of reorder and flip operations
on any rooted embedded bc-tree from the leaf nodes toward the root to arrange the pertinent virtual
edges in one of the linear consecutive arrangements.
At each node of the rooted embedded bc-tree, the operation is such that its children are arranged
in one of 5 pertinent types.
\end{lemma}

\begin{proof}
The details is given in Appendix \ref{App:AppendixB}.
The 'only if' part is trivial.
The 'if' part is by induction on  $|T_{BF}|$ of the rooted embedded bc-tree $T_{BF}$ of a marked bush form $BF$.
\end{proof}

We prove the equivalence between the marked bush \& its underlying rooted embedded bc-tree,
and the PQ-tree with Lemma \ref{lem:lemma2} \& \ref{lem:lemma3} in the same induction step
 on the number of iterations of the algorithm.

\begin{lemma}\label{lem:lemma2}
Following holds for PQ-tree and its bush form:
\begin{itemize}
\item There is a one-to-one mapping between a P-node and an orienting cut vertex in the marked bush form.
\item There is a one-to-one mapping between a Q-node and an orienting block in the marked bush form.
\end{itemize}
\end{lemma}

Lemma \ref{lem:lemma2} gives the location of the marker on the marked bush form.
If the root of the PQ-tree is a P-node, then there is a corresponding orienting cut vertex in the bush form,
and we place the marker on it.
If the root is a Q-node, there is a corresponding block $B$ in the bush form.
We place the marker on an edge $e$ of $B$ on the outer face.
The edge $e$ is determined as follows.
The children of the root Q-node in the left-to-right ordering in the PQ-tree corresponds
to a counter-clock wise ordering of the orienting active components around $B$ in the bush form.
Proceed from the cut vertex that corresponds to the right most child of the Q-node
in the counter-clock wise orientation, find the first edge $e$ on the outer face of $B$.

\begin{lemma}\label{lem:lemma3}
   If and only if the pertinent virtual nodes in the marked bush form
   can be consecutively arranged into one of 5 types
   using a series of reorder and flip operations from the leaves to the root,
   then there is an equivalent series of transformations by templates
   in REDUCE() for the PQ-tree to arrange the corresponding pertinent
   leaves to the same consecutive type.
\end{lemma}

\begin{proof}
   The details of a proof of Lemma \ref{lem:lemma2} \& \ref{lem:lemma3} is given in Appendix \ref{App:AppendixC}.
   The 'only if' part is trivial.
   The 'if' part is by induction on the number of iterations of the algorithm
   Lemma \ref{lem:lemma3} is proved by examining exhaustively
   all the cases of operations on the marked bush form and finding equivalent templates of PQ-tree.
   Lemma \ref{lem:lemma2} is proved by examining all the cases for the births and the deaths of
   the orienting cut vertices and blocks, and find equivalent P-nodes and Q-nodes on PQ-tree.
\end{proof}

\begin{theorem}
   If and only if the pertinent virtual edges in the bush form can be circularly consecutively arranged,
   then REDUCE() can transform the corresponding PQ-tree such that the pertinent
   leaves are arranged consecutively in one of 5 pertinent types.
\end{theorem}
\begin{proof}
   This is a direct application of Lemma 1, 2, and 3.
\end{proof}

This concludes the correctness of the new algorithm.

\section{Time Complexity}\label{se:complexity}

\begin{theorem}
   The time complexity of the new algorithm stays $O(|N|)$.
\end{theorem}
\begin{proof}
   We follow the discussion given in the original \cite{BL76} around
   Theorem 5, which depends on Lemma 2, 3 and 4 in [1].
   Lemma 2 in [1] holds for the new algorithm as there is no change in BUBBLE().

   Lemma 3 in [1] holds for the updated REDUCE() with new templates as follows.
   It's easy to see the required time for P8, Q4, and Q5 are on the order
   of the number of pertinent children. As for P7, just like P5, the empty children
   can implicitly stay in the original P-node, and it will be put under
   the new Q-node. This way, P7 runs in the order of the number of
   pertinent children.

   Lemma 4 holds for the updated REDUCE() as there are only $|S|$ leaves
   and at most $O(|S|)$ nonunary nodes in the PQ-tree.

   Theorem 5 holds as the Lemma 2, 3, and 4 hold, and also
   the new templates P7, P8, Q4, and Q5 do not apply to the unary nodes.

   In theorem 5, We substitute $m=|E|$, $n=|V|$, and $SIZE(\mathbb{S})=|E|$, and hence
   the algorithm runs in $O(|E|+|V|+|E|) = O(|V|)$, assuming $|E| \le 3|V| -6$.
\end{proof}

\section{Implementation Issues}\label{se:implementation}
In this section we discuss two topics regarding implementation.
First we discuss the changes required to remove the pertinent tree of the complementarily partial
type. Second we propose an improvement to Ozawa-type planarization algorithms with a new
cost calculation technique.
A reference implementation is found in github:yamanishi/colameco.

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.7\textwidth]{pq_tree_com}
  \caption{Removal of a Complementarily Partial Pertinet Tree}
  \label{fig:pq_tree_com}
\end{figure}

Removal of a complementarily partial pertinent sub-tree and emitting new leaves
from a new P-node is different from the other cases.
A complementarily partial pertinent subtree originates from a Q-node
in template P7, or Q4. All the other nodes above this lowest Q-node including the tree root
are pertinent nodes.
They will be removed and the Q-node will become the new tree root.
The P-node where the new leaves are attached will be put under
the Q-node on either end. See figure \ref{fig:pq_tree_com}.

There has not been a correct $O(|N|^2)$ linear time maximal planarization algorithm using PQ-tree as shown
in \cite{JUNGER97}, except for $O(|N||E|)$ add-edge-and-test type that calls an $O(|N|)$ planarity test multiple times.
However those algorithms such as the first stage of \cite{JTS89} called
$PLANALIZE(G)$ generates a planar spanning connected subgraph and it can be used as a base graph for further maximal planarization.
Here we base our discussion on \cite{JTS89} and propose an improvement with additional
node type and a cost value. \cite{JTS89} defines 4 node types: W, B, H, and A which correspond to
empty, full, singly partial, and doubly partial respectively. We propose a new type C which
corresponds to 'complementarily partial', and it associated cost value $c$ for each node.
The value for $c$ in $COMPUTE1()$ in \cite{JTS89} is calculated as follows.
\begin{enumerate}
\item $X$ is a pertinent leaf, $c = 0$.
\item $X$ is a full node, $c = 0$.
\item $X$ is a partial P-node, $c = a$.
\item $X$ is a partial Q-node, $c = min\{\gamma_1,\gamma_2\}$.
\end{enumerate}
\begin{equation}
\begin{aligned}
  \gamma_1 &= \sum_{i \in P(X)}(w_i) - max_{i \in P(X)}\{(w_i - c_i)\} \\
  \gamma_2 &= \sum_{i \in P(X)}(w_i) - (max_{i \in P_L(X)}\{(w_i - h_i)\}
                                       + max_{i \in P_R(X)}\{(w_i - h_i))\}
\end{aligned}
\end{equation}
where $P_L(X)$ means the maximal consecutive sequence of pertinent children of X from the
left end such that all the nodes except the right most one are full. The right most one
may be either full or singly partial. $P_R(X)$ is defined similarly from the right end.

After the cost calculation in the bottom-up manner, the type of the nodes can be determined
top-down from the tree root using the new type $C$.
In this way, the algorithm is capable of handling the complementarily partial situations, and
would be able to reduce the number of edges removed.

\section{Experiments}\label{se:experiments}
The execution time of the new algorithm is reported in Figure \ref{fig:plot_02}.
X-axis is the time to process one graph in micro seconds taken from clock() function available on C++ standard.
Y-axis indicates the number of vertices in the given biconnected planar graph.
The test program was run on Mac 2.8GHz Corei7.
The program was compiled by Apple LLVM 8.0.0.
The plot shows the linearity of the algorithm.

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.8\textwidth]{plot_performance_01}
  \caption{Processing Time of the New Algorithm}
  \label{fig:plot_02}
\end{figure}

For all the test cases the new algorithm detected planarity.
Here 'ramdom'ness is not rigorous in the mathematical sense.
It is handled by the pseudo-random number generator library std::rand() and std::srand() in C++.
The code and the data used for this experiments are found in github:yamanishi/colameco.

\section{Conclusion}\label{se:conclusion}
We have shown an enhancement to the original PQ-tree planarity algorithm proposed by \cite{BL76}
and proved the correctness. The time complexity stays in $O(|N|)$.
The enhancement applies not only to the planarity test for the graphs, but also for anything
involving circular consecutive ones. As far as the author knows, it seems
there is no other applications than planarity testing.

\section{Acknowledgements}
The author wishes to thank whoever has encouraged and supported him for this article.

\clearpage

\bibliographystyle{abbrvurl}
\bibliography{pq_tree_enhancement}

\clearpage

% \appendix
\begin{appendices}
\section{A Planar Biconnected Graph and a ST-Numbering}\label{App:AppendixA}
Following is the planar biconnected graph and the
st-numbering used to produce the PQ-tree and the bush form in figure
 \ref{fig:pq_tree_01} and \ref{fig:bush_form_01}.

\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.5\textwidth]{sample_graph}
  \caption{Biconnected Planar Graph Used for Figure \ref{fig:pq_tree_01} and \ref{fig:bush_form_01}}
  \label{fig:sample_graph}
\end{figure}

The st-numbering:

$(8, 13, 7, 14, 19, 20, 25, 24, 23, 22, 21, 16, 11, 17, 15, 9, 10, 5, 4, 3, 2, 1, 6, 12, 18)$

\section{Proof of Lemma \ref{lem:lemma1}}\label{App:AppendixB}

The 'only if' part is trivial.  We prove the 'if' part by induction on
 $|T_{BF}|$
of the rooted embedded bc-tree $T_{BF}$ of a marked bush form $BF$.
Assume after some arbitrary reorder and flip operations, the pertinent virtual edges have been arranged
consecutively around the bush form.
This is equivalent to arranging the pertinent virtual edges into one of 5 types of
linear consecutive arrangements in a marked bush form $BF$.
If $|T_{BF}| = 1$, the lemma trivially holds as the bush form consists of one pertinent or non-pertinent virtual node.
If $|T_{BF}| = 2$, the lemma trivially holds as the bush form consists of $k_2$ whose incident nodes are a cut vertex and a virtual node. Technically the node in $k_2$ is not a cut vertex but we consider it a cut vertex for the sake of the arguments.

Assume $|T_{BF}| \ge 3$.
We split $T_{BF}$ at the root node by splitting one connected component $C$ from the rest of $T_{BF}$.
If the marker in $BF$ is on a cut vertex $c$, then we split one connected active component $C$ of $T_{BF}$.
If the marker is on an edge $e$ of a block $B$ in $BF$, then we pick the closest cut vertex $c$
after $e$ in the counter-clock wise ordering around $B$
such that the maximal connected component after
removing the block from $c$ is still active.
Let $n_c$ be the corresponding node of $c$ in $T_{BF}$.
$C$ is the maximal connected component of $T_{BF} \setminus B$ that contains $n_c$.

Now $T_{BF}$ is decomposed into two components $D=T_{BF} \setminus C$ and $C$ at $n_c$, and
 $BF$ is decomposed into two parts $BF_{D}$ and $BF_{C}$ at $c$.
$BF_{D}$ and $BF_{C}$ can be considered two marked bush form with the marker placed on $c$ in $BF_{C}$.
We examine each of the 5 types of linear consecutive arrangements around $BF$,
and find all the possible combinations of pertinent types of $BF_{D}$ and $BF_{C}$.
We observe table \ref{tab:table1} enumerates all the possible combinations.
We observe for each linear consecutive arrangement around $BF$, any other
arrangements of $BF_{T\setminus C}$ or $BF_{C}$ not shown in table \ref{tab:table1}
would lead to non-nonsecutive arrangement of the pertinent virtual nodes around $BF$.

By the induction hypothesis, the condition on the pertinent types of the children hold
for both $BF_{D}$ and $BF_{C}$.
For each of 14 cases in Table \ref{tab:table1}, if we re-compose $BF_{D}$ and $BF_{C}$ at $c$ into $BF$,
then we can see the condition on the corresponding pertinent type for the case holds for $BF$.
For example, if and only if $BF$ is singly partial, then there will be 6 permissible combinations of the
pertinent types of $BF_{D}$ and $BF_{C}$. We observe any other combination would leat to a different
pertinent type of $BF$ or to a non-planar arrangement.
If $BF_{D}$ ends up in full, and $BF_{C}$ in singly partial after some operations from the leaves to the root
by the induction hypothesis,
then it is easy to see that the $BF$ will end up in singly partial as desired, possibly after flipping
$BF_{C}$ and reordering all the incident component around $c$ or $B$.
The other cases can be proved in the same manner.

\begin{table}[h]
\begin {tabular}{|l|l|l|}
\hhline{|=|=|=|}
{\bf Type on $BF$} & {\bf Type on $BF_{D}$} & {\bf Type on $BF_{C}$} \\
\hhline{|=|=|=|}
Empty                   & Empty                   & Empty \\
\hhline{|=|=|=|}
Singly Partial          & Empty                   & Singly Partial \\
\hline
Singly Partial          & Empty                   & Full           \\
\hline
Singly Partial          & Singly Partial \textsuperscript{*1} & Empty     \\
\hline
Singly Partial          & Singly Partial \textsuperscript{*2} & Full  \\
\hline
Singly Partial          & Full                    & Empty          \\
\hline
Singly Partial          & Full                    & Singly Partial \\
\hhline{|=|=|=|}
Doubly Partial          & Empty                   & Doubly Partial \\
\hline
Doubly Partial          & Singly Partial \textsuperscript{*3} & Empty \\
\hline
Doubly Partial          & Singly Partial \textsuperscript{*2} & Singly Partial \\
\hline
Doubly Partial          & Doubly Partial          & Empty          \\
\hhline{|=|=|=|}
Complementarily Partial & Singly Partial \textsuperscript{*4} & Singly Partial \\
\hline
Complementarily Partial & Full                    & Complementarily Partial \\
\hhline{|=|=|=|}
Full                    & Full                    & Full \\
\hhline{|=|=|=|}
\multicolumn{3}{p{12cm}}{\textsuperscript{*1}\footnotesize{If the root is a block, then the pertinent virtual edges are on $e$ side, not on $c$ side.}}\\
\multicolumn{3}{p{12cm}}{\textsuperscript{*2}\footnotesize{If the root is a block, then the pertinent virtual edges are on $c$ side, not on $e$ side.}}\\
\multicolumn{3}{p{12cm}}{\textsuperscript{*3}\footnotesize{If the root is a block, then the pertinent virtual edges are on $c$.
If the root is a cut vertex, this row does not apply.}}\\
\multicolumn{3}{p{12cm}}{\textsuperscript{*4}\footnotesize{If the root is a block, then the pertinent virtual edges are on $e$. If the root is a cut vertex, this row does not apply.}}\\
\end {tabular}
\caption{\textbf{All the arrangements of pertinent types of $BF_{T\setminus C}$ and $BF_{C}$.}}
\label{tab:table1}

\end{table}

\section{Proof of Lemma \ref{lem:lemma2} and \ref{lem:lemma3}}\label{App:AppendixC}

   At the first iteration, Lemma \ref{lem:lemma2} and \ref{lem:lemma3} trivially hold.
The only operation is an attach operation
   for the initial virtual edges to an initial cut vertex $c$ in the bush form,
   and the corresponding operation on PQ-tree is creation of a new P-node and attaching pertinent
   leaves to it. The root marker will be placed on $c$.

   By the induction hypothesis,  Lemma \ref{lem:lemma2},  and \ref{lem:lemma3},  hold up to $i$-th iteration.
   By Lemma \ref{lem:lemma1} and \ref{lem:lemma2},
   there is a marked bush form $BF$ whose marker is placed on a cut vertex $c$ if
   the root of the PQ-tree is P-node, or on an edge of a block $B$ if the root is a Q-node.
   Assume we have arranged the pertinent nodes for the $i+1$-th iteration by an arbitrary set
   of reorder and flip operations on the bush form.
   Then by Lemma \ref{lem:lemma1},
   we can arrange the child components of each node of the rooted embedded bc-tree $T_{BF}$
   into one of 5 pertinent types from the descendants toward the root in $T_{BF}$.

   Now we examine each pertinent type for a cut vertex and a block in a marked bush form
   for their equivalence to their
   corresponding nodes in the PQ-tree. We introduce two new operations to the marked bush form, which
   are interlock and split.
   Table \ref{tab:table2} shows all the operations on an orienting cut vertex
   and their equivalent templates on PQ-tree.
   Table \ref{tab:table3} is for an orienting block.

   Following explains the symbols used in those tables.
   \begin {itemize}
   \item a square is a component
   \item a circle is a cut vertex
   \item sky blue indicates pertinent component.
   \item yellow indicates non-pertinent component.
   \item a square enclosing '$p$' is a parent bock component.
This does not apply if the cut vertex is the root.
   \item a circle enclosing '$p$' is a parent cut vertex component.
This does not apply if the block is the tree root.
   \item a square in sky blue is a full component.
   \item a square in yellow is a non-pertinent component.
   \item a rectangle enclosing yellow and sky blue squares is a singly partial component.
   \item a circle is in sky blue with a yellow wedge is a complementarily partial component.
   \item a polygon is a block.
   \item a grey triangle or a quadrilateral is a block induced by a split operation at a cut vertex.
   \item a dashed broken line indicates interlocking of two blocks.
   \end {itemize}

   We observe the rows of those tables cover exhaustively all the cases of 4 pertinent types. (Empty type
   is not considered.)
   Then we can prove the equivalence for each case with the aid of interlock and split operations
   as well as reorder and flip.
   For example, take the case for 'Singly Partial 2' for an orienting cut vertex $c$.
   Originally, $c$
   has 3 full child components, 3 non-pertinent child components, and a singly partial child component.
   To make it singly partial, we first reorder the incident ordering of those children so that
   the full children are arranged consecutively on one side, the non-pertinent children on the other,
   and the singly partial child between those two oriented such that the full side of the singly partial
   child is on the full side of children. Please note it is not a circular ordering due to the presence
   of the parent component.
   To make those changes permanent, we split $c$
   to a triangle $k_3$ or a qiadrilateral $C_4$ and fix the orientation of the singly partial child
   relative to them with the interlock operation. The 3rd column in Table \ref{tab:table2} is for the case
   if $c$ is a root component, and the 5th column is for the case if it is not.
   We can see those are in fact equivalent to the template P4 and P5 respectively for the case in which
   the are both full and non-pertinent components.
   In the 3rd column, the interlocked $k_3$ and the singly partial child together correspond to
   the resultant Q-node in P4 with the orientation of the children preserved. If there are more than 1
   full child component, the full vertex on $k_3$ becomes a new orienting cut vertex, which corresponds
   to the new full P-node under the Q-node in P4.  Similarly, in the 5th column, the interlocked $C_4$
   and the singly partial child together correspond to the resultant Q-node in P5.
   The other cases can be examined in the same way.
   We see that in fact, those tables cover all the cases for all the templates for PQ-tree.
    In case of 'Doubly Partial 4', there are no corresponding PQ-tree templates, as those nodes are above the
   pertinent root.
   This concludes the proof of Lemma 3.

   As for Lemma 2, we prove the equivalence in the birth and the death of the orienting cut vertex
   and the corresponding P-node, and the equivalence of an orienting block to Q-node.

   An orienting cut vertex is born only at the following location.
   \begin{itemize}
   \item an attach operation with more than 1 virtual edge to be attached.
   \end{itemize}

   Please note that a split operation can produce $k_3$ or $C_4$, which means 2 or 3 new cut vertices
   are created. However, the one incident to the parent is not orienting as it has just 2 active components.
   The one incident to the interlocked singly partial child is not orienting either.
   The one on the full side is a temporary cut vertex which will be absorbed inside a newly created
   block on a merge operation later. The remaining one on the non-pertinent side is considered to have been
   transferred from the original cut vertex. So, effectively a split operation does not create new orienting cut vertex.

   An orienting cut vertex will die at the following locations.
   \begin{itemize}
   \item Becoming full. In this case the children of the cut vertex will be merged into a new cut vertex,
   and eventually it will have two active components and will become non-orienting.

   \item Becoming complementarily partial, and it has a complementarily partial child.
   In this case all the full children together with the parent will be merged into a new cut vertex,
   and eventually it will have two active components and will become non-orienting.

   \item Singly Partial 1, non-pertinent root, and there is one non-pertinent child. In this case the new cut vertex
   on the non-pertinent side of $k_3$ will have only one child, and it has two active components and it
   will become non-orienting.

   \item Singly Partial 3, non-pertinent root, and there is one non-pertinent child. In this case the new cut vertex
   on the non-pertinent side of $k_3$ will have only one child, and it has two active components and it
   will become non-orienting.

   \item Singly Partial 4, pertinent root and non-pertinent root, and there is no non-pertinent child. In this case, the $k_3$ by the split
   operation does not produce any cut vertex for non-pertinent children and hence the cut vertex vanish.

   \item Doubly Partial or Complementarily Partial 3, Root and Non-root, and there is no non-pertinent child.
In this case, the $C_4$ by the split
   operation does not produce any cut vertex for non-pertinent children and hence the cut vertex vanish.
   \end{itemize}

   An orienting block is born at the following conditions.
   \begin{itemize}
   \item $k_3$ or $C_4$ is generated by a split operation
   \end{itemize}

   An orienting block dies at the following locations.
   \begin{itemize}
   \item Where a singly partial child is interlocked to the parent. In this case there is a singly
   partial block in the component specified by the singly partial child, and the parent.
   \item Becoming full. In this case the children of the block will be merged into a new cut vertex,
   and eventually it will have two active components and will become non-orienting.

   \item Becoming complementarily partial, and it has a complementarily partial child.
   In this case all the full children together with the parent will be merged into a new cut vertex,
   and eventually it will have two active components and will become non-orienting.
   \end{itemize}

   For each of the birth and death cases above, there is a corresponding creation or destruction of
   P-node or Q-node. For example, take the 3rd death case of an orienting cut vertex that is a singly
   partial and non-root and that has one non-pertinent child. This corresponds to template P3.
   Since there is one non-pertinent child, it will be directly placed as one of two children of the Q-node.
   Eventually, the original P-node is considered removed from the PQ-tree.
   We can show the equivalence for the other cases. We can also show those cases cover all the locations
   in the templates, attach and removal of the pertinent subtree in which new P-nodes and Q-nodes are created
   and destructed. This concludes the proof of Lemma \ref{lem:lemma2}.

\begin{table}[h]
  \def\arraystretch{1}
  \centering
  \begin{tabular}
      {|C{0.22\textwidth}|C{0.14\textwidth}|C{0.14\textwidth}|C{0.05\textwidth}|C{0.14\textwidth}|C{0.05\textwidth}|}
      \hline
      Pertinent type & Original State & Operation for Pert Root & PQ Op. & Operation for Non-Pert Root & PQ Op.\\
      \hline
      Full&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_01_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_01_root} &
      P1 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_01_nonroot} &
      P1 \\
      \hline
      Empty &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_11_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_11_root} &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_11_nonroot} &
      - \\
      \hline
      Singly Partial 1&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_02_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_02_root} &
      P2 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_02_nonroot} &
      P3 \\
      \hline
      Singly Partial 2&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_03_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_03_root} &
      P4 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_03_nonroot} &
      P5 \\
      \hline
      Singly Partial 3&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_04_before} &
      N/A&
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_04_nonroot} &
      P5 \\
      \hline
      Singly Partial 4&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_05_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_05_root} &
      P4 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_05_nonroot} &
      P5 \\
      \hline
      Doubly Partial or Complementarily Partial 1&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_06_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_06_root} &
      P6 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_06_nonroot} &
      P7 \\
      \hline
      Doubly Partial or Complementarily Partial 2&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_07_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_07_root} &
      P6 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_07_nonroot} &
      P7 \\
      \hline
      Doubly Partial or Complementarily Partial 3&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_08_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_08_root} &
      P6 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_08_nonroot} &
      P7 \\
      \hline
      Doubly Partial 4&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_10_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_10_root} &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_10_nonroot} &
      - \\
      \hline
      Complementarily Partial&
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_09_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_09_root} &
      P8 &
      \includegraphics[width=0.1\textwidth]{bc_transform_cv_09_nonroot} &
      P8 \\
      \hline

 \end{tabular}
 \caption{Operations on an orienting cut vertex and equivalent PQ-tree templates}
 \label{tab:table2}
\end{table}

\begin{table}[h]
  \def\arraystretch{1}
  \centering
  \begin{tabular}
      {|C{0.22\textwidth}|C{0.14\textwidth}|C{0.14\textwidth}|C{0.05\textwidth}|C{0.14\textwidth}|C{0.05\textwidth}|}
      \hline
      Pertinent type & Original State & Operation for Pert Root & PQ Op. & Operation for Non-Pert Root & PQ Op.\\
      \hline
      Full&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_01_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_01_root} &
      Q1 &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_01_nonroot} &
      Q1 \\
      \hline
      Empty&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_12_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_12_root} &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_12_nonroot} &
      - \\
      \hline
      Singly Partial 1&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_02_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_02_root} &
      Q2 &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_02_nonroot} &
      Q2 \\
      \hline
      Singly Partial 2&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_03_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_03_root} &
      Q2 &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_03_nonroot} &
      Q2 \\
      \hline
      Doubly Partial 1&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_04_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_04_root} &
      Q3 &
      N/A &
      - \\
      \hline
      Doubly Partial 2&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_05_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_05_root} &
      Q3 &
      N/A &
      - \\
      \hline
      Doubly Partial 3&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_06_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_06_root} &
      Q3 &
      N/A &
      - \\
      \hline
      Doubly Partial 4&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_11_before} &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_11_nonroot} &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_11_root} &
      - \\
      \hline
      Complementarily Partial 1&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_07_before} &
      N/A &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_07_nonroot} &
      Q4 \\
      \hline
      Complementarily Partial 2&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_08_before} &
      N/A &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_08_nonroot} &
      Q4 \\
      \hline
      Complementarily Partial 3&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_09_before} &
      N/A &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_09_nonroot} &
      Q4 \\
      \hline
      Complementarily Partial 4&
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_10_before} &
      N/A &
      - &
      \includegraphics[width=0.1\textwidth]{bc_transform_bl_10_nonroot} &
      Q5 \\
      \hline

 \end{tabular}
 \caption{Operations on an orienting block and equivalent PQ-tree templates}
 \label{tab:table3}
\end{table}

\end{appendices}

\end{document}


\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}

\title{MATH 542 Homework 6}
\author{Saket Choudhary\\skchoudh@usc.edu}

\begin{document}
\maketitle
\section*{Problem 1}
\subsection*{Problem 1a}

To find: $f_{y_2,y_4}(y_1,y_3) = \int_{-\infty}^{\infty}f(y_1,y_2,y_2,y_4)dy_2dy_4$
For marginalising a MVN, we simply drop the irrelevant terms(terms with respect to which marginalisation is performed, as they integrate to 1)

Joint Marginal distribution of $y_1,y_3$: $f_{y_2,y_4}(y_1,y_3) \sim N(\begin{pmatrix}1 \\ 3\end{pmatrix},\begin{pmatrix}4 & -1 \\ -1 &5\end{pmatrix})$

\subsection*{Problem 1b}
$f_{y_1,y_3,y_4}(y_2) \sim N(3, 5)$

\subsection*{Problem 1c}
$z=y_1+2y_2-y_3+3y_4$

Thus, $z=aY$ where $a = \begin{pmatrix}1 & 2 & -1 & 3 \end{pmatrix}$ and $Y=\begin{pmatrix}y_1 & y_2 & y_3 & y_4\end{pmatrix}'$

Thus, $Ez = aE[y] = -4$

\begin{align*}
Var(z) &= aVar(y)a'\\
& = 79 \text{ using `R`}
\end{align*}

\subsection*{Problem 1d}

$z_1=a_1y$ and $z_2 = a_2y$ where $a_1 = \begin{pmatrix}1 & 1 & -1 & -1 \end{pmatrix}$
and $a_2 = \begin{pmatrix}-3 & 1 & 2 & -2 \end{pmatrix}$

Then $f_{z_1,z_2} \sim N(\begin{pmatrix} \mu_1 \\ \mu_2 \end{pmatrix}, S)$

$\mu_1 = a_1'E[y] = 2$

$\mu_2 = a_2'E[y] = 9$

$\Sigma^z_{11} = a_1\Sigma a_1^T = 11$

$\Sigma^z_{22} = a_2\Sigma a_2^T = 154$

$\Sigma^z_{12} =  \Sigma^z_{21} =  a_2\Sigma a_2^T = -6$

Thus, $Z = \begin{pmatrix} z_1 \\ z_2 \end{pmatrix}
\sim N(\begin{pmatrix} 2\\ 9\end{pmatrix}, \begin{pmatrix} 11 & -6\\
-6 & 154\end{pmatrix})$

\subsection*{Problem 1e}

$\mu' = \mu_1 + \Sigma_{12}\Sigma_{22}^{-1}(x_2-\mu_2)$

$Cov = \Sigma_{11} - \Sigma_{12}\Sigma_{22}^{-1}\Sigma_{21}$

$\mu' = \begin{pmatrix}1 \\ 2 \end{pmatrix} + \begin{pmatrix} -1 & 2\\ 3 & -2 \end{pmatrix} \begin{pmatrix} 5 & -4\\ -4 & 4\end{pmatrix}^{-1} \begin{pmatrix}y_3-3\\ y_4+2\end{pmatrix} = \begin{pmatrix}1 \\ 2 \end{pmatrix} + \begin{pmatrix} 1&1.5\\ 1 & 0.5 \end{pmatrix} \begin{pmatrix}y_3-3\\ y_4+2\end{pmatrix}$

$Cov' = \begin{pmatrix} 4 & 2\\ 2 & 6 \end{pmatrix}-\begin{pmatrix} -1 & 2\\ 3 & -2 \end{pmatrix} \begin{pmatrix} 5 & -4\\ -4 & 4\end{pmatrix}^{-1}\begin{pmatrix}-1 & 3\\ 2 & -2 \end{pmatrix}=
\begin{pmatrix}2 & 2\\ 2& 4 \end{pmatrix}$

 $f(y_1, y_2 |y_3, y_4) = N(\mu', Cov)$

\subsection*{Problem 1f}

$\mu' =  \begin{pmatrix} 1 \\3 \end{pmatrix} + \begin{pmatrix} -1 & 2\\ 5 &-4 \end{pmatrix}\begin{pmatrix} 3 & -2 \\-4 & 4\end{pmatrix}^{-1}\begin{pmatrix}y_2-2\\ y_4+2\end{pmatrix} = \begin{pmatrix} 1 \\3 \end{pmatrix} + \begin{pmatrix} 1 & 1 \\ 1 & -0.5\end{pmatrix}\begin{pmatrix}y_2-2\\ y_4+2\end{pmatrix}$

$Cov' = \begin{pmatrix} 4 & 2\\ -1 & 3 \end{pmatrix} - \begin{pmatrix} -1 & 2\\ 5 &-4 \end{pmatrix}\begin{pmatrix} 3 & -2 \\-4 & 4\end{pmatrix}^{-1} \begin{pmatrix} 2 & 6\\ 2 & -2\end{pmatrix} $

 $f(y_1, y_2 |y_3, y_4) = N(\mu', Cov)$

\subsection*{Problem 1g}
$Cov(y_1,y_3) = -1 $

\subsection*{Problem 1h}

$\mu' = 1 - \begin{pmatrix} 2 & -1 & 2 \end{pmatrix} \begin{pmatrix} 6 & 3 & -2\\ 3 & 5 & -4 \\ -2 & -4 & 4 \end{pmatrix}^{-1} \begin{pmatrix} y_2-2\\ y_3-3\\ y_4+2 \end{pmatrix} $

$Cov' = 4 - \begin{pmatrix} 2 & -1 & 2 \end{pmatrix} \begin{pmatrix} 6 & 3 & -2\\ 3 & 5 & -4 \\ -2 & -4 & 4 \end{pmatrix}^{-1} \begin{pmatrix} 2 \\ -1 \\ 2 \end{pmatrix}$

 $f(y_1, y_2 |y_3, y_4) = N(\mu', Cov)$

\section*{Problem 2}
Since $\sigma_{12} = \sigma_{13} = \sigma_{14} = 0$ and $y$ follows a MVN, by Theorem 2.2, $y_1$ is pairwise independent with $y_2,y_3,y_4$

\section*{Problem 3}

\begin{align*}
y_2 - \Sigma_{21}\Sigma_{11}^{-1}y_1 &= \begin{pmatrix} 0_{n-r \times r} & I_{n-r \times n-r} \end{pmatrix} \begin{pmatrix}y_1 \\ y_2\end{pmatrix} + \begin{pmatrix} -\Sigma_{21}\Sigma_{11}^{-1} & 0_{n \times r}\end{pmatrix}\begin{pmatrix}y_1 \\ y_2\end{pmatrix} \\
E(y_2 - \Sigma_{21}\Sigma_{11}^{-1}y_1) &= \begin{pmatrix} 0_{n-r \times r} & I_{n-r \times n-r} \end{pmatrix} \begin{pmatrix}Ey_1\\ Ey_2 \end{pmatrix} + \begin{pmatrix} -\Sigma_{21}\Sigma_{11}^{-1} & 0_{n \times r}\end{pmatrix}\begin{pmatrix}Ey_1 \\ Ey_2\end{pmatrix}\\
&= \mu_2 - \Sigma_{21}\Sigma_{11}^{-1}\mu_1
\end{align*}

\begin{align*}
Cov(y_2 - \Sigma_{21}\Sigma_{11}^{-1}y_1 ) &= Cov(\begin{pmatrix} 0_{n-r \times r} & I_{n-r \times n-r} \end{pmatrix} \begin{pmatrix}y_1 \\ y_2\end{pmatrix} + \begin{pmatrix} -\Sigma_{21}\Sigma_{11}^{-1} & 0_{n \times r}\end{pmatrix}\begin{pmatrix}y_1 \\ y_2\end{pmatrix})\\
&= Cov(aY+bY)\\
&= (a+b)Var(Y)(a+b)^T\\
&= \begin{pmatrix} -\Sigma_{21}\Sigma_{11}^{-1} & I \end{pmatrix} \begin{pmatrix}
\Sigma_{11} & \Sigma_{12}\\
\Sigma_{21} & \Sigma_{22}
\end{pmatrix}\begin{pmatrix} -(\Sigma_{11}^{-1})^T\Sigma_{21}^T \\ I^T \end{pmatrix}\\
&= \begin{pmatrix}-\Sigma_{21}+\Sigma_{21} & -\Sigma_{21}\Sigma_{11}^{-1}\Sigma_{12}+\Sigma_{22} \end{pmatrix} \begin{pmatrix}-(\Sigma_{21}\Sigma_{11}^{-1})^T \\ I^T\end{pmatrix}\\
&= \Sigma_{22}-\Sigma_{21}\Sigma_{11}^{-1}\Sigma_{12}
\end{align*}

\section*{Problem 4}
\subsection*{Problem 4a}

Given $t=\frac{z}{\sqrt{\frac{u}{\rho}}} \sim t(\rho)$ we know the following facts:

\begin{itemize}
\item $Z \sim N(0,1)$
\item $u \sim \chi^2_\rho$
\item $Z$ and $u$ are independent
\end{itemize}

$t^2 = \frac{z^2}{{\frac{u}{\rho}}} \sim \frac{\chi_1^2}{\chi_\rho^2} \sim F(1,\rho)$

\subsection*{Problem 5.3}
We consider first the following vector:
$Z=\begin{pmatrix} \bar{Y} & Y_1-Y_2 & Y_2-Y_3 \dots Y_n-Y_{n-1}\end{pmatrix}'$

Let's call $X = \begin{pmatrix} Y_1-Y_2 & Y_2-Y_3 \dots Y_{n-1}-Y_{n}\end{pmatrix}'$ so that it allows us to write $\sum_{i=1}^{n-1}(Y_i-Y_{i+1})^2=X'X$

Now $Z=\begin{pmatrix} \bar{Y} & X \end{pmatrix}$

\begin{align*}
\begin{pmatrix} \bar{Y} & Y_1-Y_2 & Y_2-Y_3 \dots Y_{n-1}-Y_{n}\end{pmatrix}' &= \begin{pmatrix}
1/n & 1/n & 1/n & \dots & 1/n\\
1 & -1 &  0 & \dots & 0\\
0 & 1 & -1 & \dots & 0\\
\vdots \\
0 & 0 & 0 & \dots & -1\\
\end{pmatrix} \begin{pmatrix} Y_1 & Y_2 & Y_3 &\dots Y_n \end{pmatrix}'\\
%&= (I-\frac{1}{n}1_n1_n')\begin{pmatrix} Y_1 & Y_2 & Y_3 &\dots Y_n \end{pmatrix}'
Z &= AY
\end{align*}

Also $Z \sim N(A\mu, A\Sigma A')$

$A\mu = \begin{pmatrix} \mu  & 0 & 0 \dots 0 \end{pmatrix}$

$A\Sigma A' = AA'$ since $\Sigma = I$

$AA'  = \begin{pmatrix} 1/n & 0 & 0 & \dots & 0\\
0 & 2 & -1  & \dots & 0\\
0 & -1 & 2 & -1 & \dots 0\\
\vdots
0 & 0 & 0 & 0 & \dots 2
\end{pmatrix}$

Thus, $Z=\begin{pmatrix}\bar{Y} & X_{n \times 1}\end{pmatrix}'$ is a MVN such that $\bar{Y}$ and $X$ are independent (since the covariance is 0)

We also know that $\sum_{i=1}^{n-1}(Y_i-Y_{i+1})^2=X'X = h(X)$

Since, functions of independent random variables are also independent $\bar{Y}$ and $h(X) = X'X$ are independent.

\subsection*{Problem 5.11}

$Z = \begin{pmatrix} \phi & 1 & 0 & 0 & \dots & 0\\ 0 & \phi & 1 & 0 & \dots & 0\\
0 & 0 & \phi & 1 &  \dots & 0\\
\vdots\\
0 & 0 & 0 & 0 & \dots & 1\\
\end{pmatrix} \begin{pmatrix} y_1\\ y_2 \\ y_3\\ \vdots\\ y_n\end{pmatrix} = AY$

Since $Y \sim N(0, \sigma^2I)$ $\implies$ $Z \sim N(0, \sigma^2 AA^T)$

where $AA^T = \begin{pmatrix}\phi^2+1 & \phi & 0 & 0 & \dots & 0\\
\phi & 1+\phi^2 & \phi & 0 & \dots & 0\\
0 & \phi & 1+\phi^2 & \phi & \dots & 0\\
\vdots & \vdots & \vdots & \vdots & \vdots\\
0 & 0 & 0 & \dots & 1+\phi^2 & \phi
\end{pmatrix}$

\end{document}