\chapter{Assignment-Matrices}
\section{MCQ}
\begin{enumerate}
	\item The eigen value of matrix $A=\left(\begin{array}{lll}1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 1\end{array}\right)$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\lambda=1,0,2$
		\task[\textbf{b.}]$\lambda=-1,2,2$
		\task[\textbf{c.}] $\lambda=0,0,3$
		\task[\textbf{d.}] $\lambda=1,1,1$
	\end{tasks}
	\item The eigen value of matrix $A=\left(\begin{array}{ccc}1 & \sqrt{8} & 0 \\ \sqrt{8} & 1 & \sqrt{8} \\ 0 & \sqrt{8} & 1\end{array}\right)$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}]$\lambda=1,0,2$
		\task[\textbf{b.}]$\lambda=-1,2,2$
		\task[\textbf{c.}]$\lambda=-3,1,5$
		\task[\textbf{d.}]$\lambda=1,1,1$
	\end{tasks}
	\item The eigen value of matrix $A=\left(\begin{array}{lll}0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0\end{array}\right)$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}]$\lambda=-1,0,1$
		\task[\textbf{b.}]$\lambda=0,-2,2$
		\task[\textbf{c.}]$\lambda=0,0,0$
		\task[\textbf{d.}]  $\lambda=-\sqrt{2}, 0, \sqrt{2}$
	\end{tasks}
	\item The eigen value of matrix $A=\left(\begin{array}{lll}0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0\end{array}\right)$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\lambda=-1,-1,2$
		\task[\textbf{b.}]$\lambda=0,-2,2$
		\task[\textbf{c.}] $\lambda=0,0,0$
		\task[\textbf{d.}] $\lambda=-\sqrt{2}, 0, \sqrt{2}$
	\end{tasks}
	\item The degenerate eigen value of matrix $A=\left(\begin{array}{lll}1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1\end{array}\right)$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}]0
		\task[\textbf{b.}]1
		\task[\textbf{c.}]2
		\task[\textbf{d.}] 3
	\end{tasks}
	\item The eigen vector of matrix $A=\left(\begin{array}{lll}1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 1\end{array}\right)$ corresponding to eigen value 0 is
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\left[\begin{array}{l}1 \\ 0 \\ 0\end{array}\right]$
		\task[\textbf{b.}]$\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right]$
		\task[\textbf{c.}] $\left[\begin{array}{l}1 \\ 0 \\ 1\end{array}\right]$
		\task[\textbf{d.}]  $\left[\begin{array}{c}1 \\ -1 \\ 0\end{array}\right]$
	\end{tasks}
	\item The eigen vector of matrix $A=\left(\begin{array}{ccc}1 & \sqrt{8} & 0 \\ \sqrt{8} & 1 & \sqrt{8} \\ 0 & \sqrt{8} & 1\end{array}\right)$ corresponding to eigen value 5 is
	 \begin{tasks}(2)
		\task[\textbf{a.}]$\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right]$
		\task[\textbf{b.}]$\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right]$
		\task[\textbf{c.}] $\left[\begin{array}{c}\sqrt{2} \\ 1 \\ 1\end{array}\right]$
		\task[\textbf{d.}]  $\left[\begin{array}{c}-\sqrt{2} \\ 1 \\ 1\end{array}\right]$
	\end{tasks}
	\item The eigen vectors of matrix $A=\left(\begin{array}{ccc}0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0\end{array}\right)$ corresponding to eigen values $-\sqrt{2}, 0, \sqrt{2}$ are respectively
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right],\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right]$
		\task[\textbf{b.}]$\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right],\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right]$
		\task[\textbf{c.}]$\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right]$
		\task[\textbf{d.}]  $\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right],\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right]$
	\end{tasks}
	\item If one of the eigen vector of matrix $A=\left(\begin{array}{lll}0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0\end{array}\right)$ corresponding to eigen value $-1$ is $\left[\begin{array}{c}-2 \\ 1 \\ 1\end{array}\right]$ then other orthogonal eigen vector for same eigen value is
	 \begin{tasks}(2)
		\task[\textbf{a.}]$\left[\begin{array}{c}0 \\ 1 \\ -1\end{array}\right] \quad$
		\task[\textbf{b.}]$\left[\begin{array}{c}-4 \\ 2 \\ 2\end{array}\right]$
		\task[\textbf{c.}]$\left[\begin{array}{l}1 \\ 0 \\ 1\end{array}\right]$
		\task[\textbf{d.}] $\left[\begin{array}{c}1 \\ -1 \\ 0\end{array}\right]$
	\end{tasks}
	\item If one of the eigen vector of matrix $A=\left(\begin{array}{lll}1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1\end{array}\right)$ corresponding to eigen value 0 is $\left[\begin{array}{c}0 \\ 1 \\ -1\end{array}\right]$ then other orthogonal eigen vector for same eigen value is
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\left[\begin{array}{c}-2 \\ 1 \\ 1\end{array}\right]$
		\task[\textbf{b.}]$\left[\begin{array}{c}0 \\ 2 \\ -2\end{array}\right]$
		\task[\textbf{c.}]$\left[\begin{array}{l}1 \\ 0 \\ 1\end{array}\right]$
		\task[\textbf{d.}]  $\left[\begin{array}{c}1 \\ -1 \\ 0\end{array}\right]$
	\end{tasks}
	\item A square matrix $3 \times 3$ is given by $A=\left[\begin{array}{lll}2 & 0 & 0 \\ 0 & 1 & 1 \\ 0 & 1 & 1\end{array}\right]$ is diagonalized in eigenvector of
	matrix $S=\left[\begin{array}{ccc}1 & 0 & 0 \\ 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ 0 & -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}}\end{array}\right] .$ Which one of the following is matrix $A$ in the diagonal form in the
	basis of $S$ ?
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\left[\begin{array}{lll}2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 0\end{array}\right] \quad$
		\task[\textbf{b.}] $\left[\begin{array}{lll}0 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 2\end{array}\right] \quad$
		\task[\textbf{c.}]$\left[\begin{array}{lll}2 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 2\end{array}\right] \quad$
		\task[\textbf{d.}] $\left[\begin{array}{lll}1 & 0 & 2 \\ 0 & 1 & 0 \\ 0 & 0 & 2\end{array}\right]$
	\end{tasks}
	\item Consider the matrix $M=\left(\begin{array}{lll}1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1\end{array}\right) .$ The eigenvalues of $M$ are
	 \begin{tasks}(2)
		\task[\textbf{a.}] $0,1,2$
		\task[\textbf{b.}]$0,0,3$
		\task[\textbf{c.}]$1,1,1$
		\task[\textbf{d.}] $-1,1,3$
	\end{tasks}
	\item Consider the matrix $M=\left(\begin{array}{lll}1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1\end{array}\right)$. The exponential of $M$ simplifies to $(I$ is the $3 \times 3$ identity matrix)
	 \begin{tasks}(2)
		\task[\textbf{a.}]$e^{M}=I+\left(\frac{e^{3}-1}{3}\right) M$
		\task[\textbf{b.}] $e^{M}=I+M+\frac{M^{2}}{2 !}$
		\task[\textbf{c.}] $e^{M}=I+3^{3} M$
		\task[\textbf{d.}]  $e^{M}=(e-1) M$
	\end{tasks}
	\item The eigenvalues of the matrix $\left(\begin{array}{lll}2 & 3 & 0 \\ 3 & 2 & 0 \\ 0 & 0 & 1\end{array}\right)$ are
	 \begin{tasks}(2)
		\task[\textbf{a.}]$5,2,-2$
		\task[\textbf{b.}]$-5,-1,-1$
		\task[\textbf{c.}]$5,1,-1$
		\task[\textbf{d.}] $-5,1,1$
	\end{tasks}
	\item The eigen values of the matrix $A=\left(\begin{array}{ccc}1 & 2 & 3 \\ 2 & 4 & 6 \\ 3 & 6 & 9\end{array}\right)$ are
	 \begin{tasks}(2)
		\task[\textbf{a.}]$(1,4,9)$
		\task[\textbf{b.}] $(0,7,7)$
		\task[\textbf{c.}]$(0,1,13)$
		\task[\textbf{d.}] $(0,0,14)$
	\end{tasks}
	\item The eigenvalues of the antisymmetric matrix, $A=\left(\begin{array}{ccc}0 & -n_{3} & n_{2} \\ n_{3} & 0 & -n_{1} \\ -n_{2} & n_{1} & 0\end{array}\right)$ where $n_{1}, n_{2}$ and $n_{3}$ are the components of a unit vector, are
	 \begin{tasks}(2)
		\task[\textbf{a.}]$0, i,-i$
		\task[\textbf{b.}]$0,1,-1$
		\task[\textbf{c.}]$0,1+i,-1,-i$
		\task[\textbf{d.}] $0,0,0$
	\end{tasks}
	\item Consider the matrix $M=\left(\begin{array}{ccc}0 & 2 i & 3 i \\ -2 i & 0 & 6 i \\ -3 i & -6 i & 0\end{array}\right)$. The eigenvalues of $M$ are
	 \begin{tasks}(2)
		\task[\textbf{a.}]$-5,-2,7$
		\task[\textbf{b.}]$-7,0,7$
		\task[\textbf{c.}]$-4 i, 2 i, 2 i$
		\task[\textbf{d.}] $2,3,6$
	\end{tasks}
	\item The column vector $\left(\begin{array}{l}a \\ b \\ a\end{array}\right)$ is a simultaneous eigenvector of
	$A=\left(\begin{array}{lll}0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 0\end{array}\right)$ and $B=\left(\begin{array}{lll}0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0\end{array}\right)$, if
	 \begin{tasks}(2)
		\task[\textbf{a.}] $b=0$ or $a=0$
		\task[\textbf{b.}] $b=a$ or $b=-2 a$
		\task[\textbf{c.}] $b=2 a$ or $b=-a$
		\task[\textbf{d.}]  $b=a / 2$ or $b=-a / 2$
	\end{tasks}
\item Let $\alpha$ and $\beta$ be complex numbers. Which of the following sets of matrices forms a group under matrix multiplication?
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\left(\begin{array}{ll}\alpha & \beta \\ 0 & 0\end{array}\right)$
		\task[\textbf{b.}] $\left(\begin{array}{lr}1 & \alpha \\ \beta & 1\end{array}\right)$, where $\alpha \beta \neq 1$
		\task[\textbf{c.}] $\left(\begin{array}{cc}\alpha & \alpha^{*} \\ \beta & \beta^{*}\end{array}\right)$, where $\alpha \beta^{*}$ is real
		\task[\textbf{d.}]  $\left(\begin{array}{cc}\alpha & \beta \\ -\beta^{*} & \alpha^{*}\end{array}\right)$, where $|\alpha|^{2}+|\beta|^{2}=1$
	\end{tasks}
	\item A $3 \times 3$ matrix $M$ has $\operatorname{Tr}[M]=6, \operatorname{Tr}\left[M^{2}\right]=26$ and $\operatorname{Tr}\left[M^{3}\right]=90$. Which of the following can be a possible set of eigenvalues of $M$ ?
	 \begin{tasks}(2)
		\task[\textbf{a.}]$\{1,1,4\}$
		\task[\textbf{b.}]$\{-1,0,7\}$
		\task[\textbf{c.}]$\{-1,3,4\}$
		\task[\textbf{d.}] $\{2,2,2\}$
	\end{tasks}
	\item The matrix $A=\frac{1}{\sqrt{3}}\left[\begin{array}{cc}1 & 1+i \\ 1-i & -1\end{array}\right]$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}]Orthogonal
		\task[\textbf{b.}] Symmetric
		\task[\textbf{c.}]anti-symmetric
		\task[\textbf{d.}] Unitary
	\end{tasks}
	\item If $H$ is Hermitian matrix then matrix $A=\exp (i H)$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}] Hermitian
		\task[\textbf{b.}]Unitary
		\task[\textbf{c.}]Skew Hermitian
		\task[\textbf{d.}] Identity
	\end{tasks}
	\item The matrix $A=\left(\begin{array}{ccc}0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 2\end{array}\right)$ is diagonalize in the basis of unitary matrices $U$ and get the diagonalise matrix $\left(\begin{array}{ccc}2 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & -1\end{array}\right)$ then matrix $U$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}]$\left(\begin{array}{ccc}0 & 0 & 1 \\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\ \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} & 0\end{array}\right)$
		\task[\textbf{b.}]$\left(\begin{array}{ccc}0 & 0 & 1 \\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\ -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0\end{array}\right)$
		\task[\textbf{c.}] $\left(\begin{array}{ccc}0 & 0 & 0 \\ 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ 1 & \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}}\end{array}\right)$
		\task[\textbf{d.}]  $\left(\begin{array}{ccc}0 & 1 & 0 \\ \frac{1}{\sqrt{2}} & 0 & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & 0 & -\frac{1}{\sqrt{2}}\end{array}\right)$
	\end{tasks}
	\item Given a $2 \times 2$ unitary matrix $U$ satisfying $U^{\dagger} U=U U^{\dagger}=1$ with $\operatorname{det} U=e^{i \varphi}$, one can construct a unitary matrix $V\left(V^{\dagger} V=V V^{\dagger}=1\right)$ with det $V=1$ from it by
	 \begin{tasks}(1)
		\task[\textbf{a.}] Multiplying $U$ by $e^{-i \varphi / 2}$
		\task[\textbf{b.}] Multiplying any single element of $U$ by $e^{-i \varphi}$
		\task[\textbf{c.}] Multiplying any row or column of $U$ by $e^{-i \varphi / 2}$
		\task[\textbf{d.}]  Multiplying $U$ by $e^{-i \varphi}$
	\end{tasks}
	\item Consider an $n \times n(n>1)$ matrix $A$, in which $A_{i j}$ is the product of the indices $i$ and $j$ (namely $A_{i j}=i j$ ). The matrix $A$
	 \begin{tasks}(1)
		\task[\textbf{a.}]Has one degenerate eigevalue with degeneracy $(n-1)$
		\task[\textbf{b.}]Has two degenerate eigenvalues with degeneracies 2 and $(n-2)$
		\task[\textbf{c.}]Has one degenerate eigenvalue with degeneracy $n$
		\task[\textbf{d.}] Does not have any degenerate eigenvalue
	\end{tasks}
	\item Two matrices $A$ and $B$ are said to be similar if $B=P^{1} A P$ for some invertible matrix $P$. Which of the following statements is NOT TRUE?
	 \begin{tasks}(2)
		\task[\textbf{a.}] $\operatorname{Det} A=\operatorname{Det} B$
		\task[\textbf{b.}] Trace of $A=$ Trace of $B$
		\task[\textbf{c.}]$A$ and $B$ have the same eigenvectors
		\task[\textbf{d.}]  $A$ and $B$ have the same eigenvalues
	\end{tasks}
	\item A $3 \times 3$ matrix has elements such that its trace is 11 and its determinant is 36 . The eigenvalues of the matrix are all known to be positive integers. The largest eigenvalues of the matrix is
	 \begin{tasks}(2)
		\task[\textbf{a.}]18
		\task[\textbf{b.}]12
		\task[\textbf{c.}]9
		\task[\textbf{d.}] 6
	\end{tasks}
	\item The inverse of matrix $M=\left(\begin{array}{lll}0 & 1 & 1 \\ 0 & 0 & 1 \\ 1 & 0 & 0\end{array}\right)$ is
	 \begin{tasks}(2)
		\task[\textbf{a.}]$M-1$
		\task[\textbf{b.}]$M^{2}-1$
		\task[\textbf{c.}] $I-M^{2}$
		\task[\textbf{d.}] $I-M$
	\end{tasks}
       \section{MSQ}
 \item For matrix $A=\left(\begin{array}{lll}5 & 0 & 2 \\ 0 & 1 & 0 \\ 2 & 0 & 2\end{array}\right)$, which of the following statements are true?
                 \begin{tasks}(1)
                	\task[\textbf{a.}]The degenerate eigen value is 1
                	\task[\textbf{b.}]One of the eigen vector corresponding to degenerate eigen value is $\left[\begin{array}{c}1 \\ 0 \\ -2\end{array}\right]$
                	\task[\textbf{c.}]The eigen vector corresponding to nondegenerate eigen value is $\left[\begin{array}{l}2 \\ 0 \\ 1\end{array}\right]$
                	\task[\textbf{d.}] The eigen vector corresponding to nondegenerate eigen value is $\left[\begin{array}{l}0 \\ 2 \\ 1\end{array}\right]$
                \end{tasks}
 \item   For matrix $A=\left(\begin{array}{lll}1 & 1 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 0\end{array}\right)$, which of the following statements are true?
                 \begin{tasks}(1)
                	\task[\textbf{a.}]The degenerate eigen value is 0
                	\task[\textbf{b.}]One of the eigen vector corresponding to degenerate eigen value is $\left[\begin{array}{c}1 \\ -1 \\ 0\end{array}\right]$
                	\task[\textbf{c.}]One of the eigen vector corresponding to degenerate eigen value is $\left[\begin{array}{l}0 \\ 0 \\ 1\end{array}\right]$
                	\task[\textbf{d.}] The eigen vector corresponding to nondegenerate eigen value is $\left[\begin{array}{l}1 \\ 1 \\ 0\end{array}\right]$
                \end{tasks}
  \item For matrix $A=\left(\begin{array}{ccc}5 & 0 & \sqrt{3} \\ 0 & 3 & 0 \\ \sqrt{3} & 0 & 3\end{array}\right)$, which of the following statements are true?
  \begin{tasks}(1)
 	\task[\textbf{a.}]The eigen value are $2,3,6$
 	\task[\textbf{b.}]The eigen value are 2, 4, 5
 	\task[\textbf{c.}]Eigen vector corresponding eigen value2 is $\left[\begin{array}{c}1 \\ 0 \\ \sqrt{3}\end{array}\right]$
 	\task[\textbf{d.}] Eigen vector corresponding eigen value 2 is $\left[\begin{array}{c}\sqrt{3} \\ 0 \\ 1\end{array}\right]$
 \end{tasks}
 \item  Which one of following is correct
   \begin{tasks}(1)
  	\task[\textbf{a.}] If $A^{\dagger}=A$ and $B^{\dagger}=-B$ Then $A B+B A$ is skew Hermitian
  	\task[\textbf{b.}] If $A^{\dagger}=A$ and $B^{\dagger}=-B$ Then $A B+B A$ is Hermitian
  	\task[\textbf{c.}]If $A^{\dagger}=A$ and $B^{\dagger}=-B \quad i(A B+B A)$ is skew Hermitian
  	\task[\textbf{d.}] $A^{\dagger}=A$ and $B^{\dagger}=-B i(A B+B A)$ is Hermitian
  \end{tasks}
\item  Which of the following is correct for matrix $A=\left(\begin{array}{lll}1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0\end{array}\right)$
   \begin{tasks}(2)
  	\task[\textbf{a.}] It is its own inverse
  	\task[\textbf{b.}]It is its own transpose
  	\task[\textbf{c.}] It has eigen value $\pm 1$
  	\task[\textbf{d.}]  It is orthogonal matrix.
  \end{tasks}
\section{NAT}
  \item The degenerate eigenvalue of the matrix $\left[\begin{array}{ccc}4 & -1 & -1 \\ -1 & 4 & -1 \\ -1 & -1 & 4\end{array}\right]$ is (your answer should be an integer)-------------
\item  The minimum eigenvalues of the matrix $\left(\begin{array}{lll}0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0\end{array}\right)$ is...........
  \item The degenerate eigen value of matrix $A=\left[\begin{array}{lll}0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 0\end{array}\right]$ is given by
\item  The inverse of matrix $A=\left[\begin{array}{lll}0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 0\end{array}\right]$ is
 \begin{tasks}(2)
	\task[\textbf{a.}]$\left[\begin{array}{ccc}0 & 0 & -1 \\ 0 & -1 & 0 \\ -1 & 0 & 0\end{array}\right]$
	\task[\textbf{b.}]$\left[\begin{array}{ccc}0 & 0 & -1 \\ 0 & -1 & 0 \\ 1 & 0 & 0\end{array}\right]$
	\task[\textbf{c.}]$\left[\begin{array}{ccc}0 & 0 & -1 \\ 0 & 1 & 0 \\ 1 & 0 & 0\end{array}\right]$
	\task[\textbf{d.}] $\left[\begin{array}{lll}0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 0\end{array}\right]$
\end{tasks}
 \item  The eigenvalue of matrix $A=\left(\begin{array}{lll}1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 1\end{array}\right)$ is
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\lambda=1,0,2$
 	\task[\textbf{b.}]$\lambda=-1,2,2$
 	\task[\textbf{c.}]$\lambda=0,0,3$
 	\task[\textbf{d.}]$\lambda=1,1,1$
 \end{tasks}
 \item The eigenvalue of matrix $A=\left(\begin{array}{ccc}1 & \sqrt{8} & 0 \\ \sqrt{8} & 1 & \sqrt{8} \\ 0 & \sqrt{8} & 1\end{array}\right)$ is
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\lambda=1,0,2$
 	\task[\textbf{b.}]$\lambda=-1,2,2$
 	\task[\textbf{c.}]$\lambda=-3,1,5$
 	\task[\textbf{d.}] $\lambda=1,1,1$
 \end{tasks}
 \item The eigenvalue of matrix $A=\left(\begin{array}{lll}0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0\end{array}\right)$ is
  \begin{tasks}(2)
 	\task[\textbf{a.}] $\lambda=-1,0,1$
 	\task[\textbf{b.}] $\lambda=0,-2,2$
 	\task[\textbf{c.}]$\lambda=0,0,0$
 	\task[\textbf{d.}]  $\lambda=-\sqrt{2}, 0, \sqrt{2}$
 \end{tasks}
\item The eigenvalue of matrix $A=\left(\begin{array}{lll}0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0\end{array}\right)$ is
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\lambda=-1,-1,2$
 	\task[\textbf{b.}]$\lambda=0,-2, \quad 2$
 	\task[\textbf{c.}]$\lambda=0,0,0$
 	\task[\textbf{d.}]  $\lambda=-\sqrt{2}, 0, \sqrt{2}$
 \end{tasks}
\item The eigenvector of matrix $A=\left(\begin{array}{lll}1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 1\end{array}\right)$ corresponding to eigenvalue 0 is
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\left[\begin{array}{l}1 \\ 0 \\ 0\end{array}\right]$
 	\task[\textbf{b.}]$\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right]$
 	\task[\textbf{c.}]$-\left[\begin{array}{l}1 \\ 0 \\ 1\end{array}\right] .$
 	\task[\textbf{d.}] $\left[\begin{array}{c}1 \\ -1 \\ 0\end{array}\right]$
 \end{tasks}
 \item 69 The eigenvector of matrix $A=\left(\begin{array}{ccc}1 & \sqrt{8} & 0 \\ \sqrt{8} & 1 & \sqrt{8} \\ 0 & \sqrt{8} & 1\end{array}\right)$ corresponding to eigenvalue 5 is
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right]$
 	\task[\textbf{b.}]$\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right]$
 	\task[\textbf{c.}]$\left[\begin{array}{c}\sqrt{2} \\ 1 \\ 1\end{array}\right]$
 	\task[\textbf{d.}] $\left[\begin{array}{c}-\sqrt{2} \\ 1 \\ 1\end{array}\right]$
 \end{tasks}
 \item 70 The eigen vectors of matrix $A=\left(\begin{array}{lll}0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0\end{array}\right)$ corresponding to eigen values $-\sqrt{2}, 0, \sqrt{2}$ are respectively
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right],\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right]$
 	\task[\textbf{b.}]$\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right],\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right]$
 	\task[\textbf{c.}] $\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right]$
 	\task[\textbf{d.}] $\left[\begin{array}{c}1 \\ 0 \\ -1\end{array}\right],\left[\begin{array}{c}1 \\ -\sqrt{2} \\ 1\end{array}\right],\left[\begin{array}{c}1 \\ \sqrt{2} \\ 1\end{array}\right]$
 \end{tasks}
 \item 71 If one of the eigenvector of matrix $A=\left(\begin{array}{lll}0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0\end{array}\right)$ corresponding to eigenvalue $-1$ is $\left[\begin{array}{c}-2 \\ 1 \\ 1\end{array}\right]$ then other orthogonal eigen vector for same eigen value is
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\left[\begin{array}{c}0 \\ 1 \\ -1\end{array}\right]$
 	\task[\textbf{b.}]$\left[\begin{array}{c}-4 \\ 2 \\ 2\end{array}\right]$
 	\task[\textbf{c.}] $\left[\begin{array}{l}1 \\ 0 \\ 1\end{array}\right]$
 	\task[\textbf{d.}]  $\left[\begin{array}{c}1 \\ -1 \\ 0\end{array}\right]$
 \end{tasks}
 \item 72 If one of the eigen vector of matrix $A=\left(\begin{array}{lll}1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1\end{array}\right)$ corresponding to eigen value 0 is $\left[\begin{array}{c}0 \\ 1 \\ -1\end{array}\right]$ then other orthogonal eigen vector for same eigen value is
  \begin{tasks}(2)
 	\task[\textbf{a.}]$\left[\begin{array}{c}-2 \\ 1 \\ 1\end{array}\right]$
 	\task[\textbf{b.}]$\left[\begin{array}{c}0 \\ 2 \\ -2\end{array}\right]$
 	\task[\textbf{c.}]$\left[\begin{array}{l}1 \\ 0 \\ 1\end{array}\right]$
 	\task[\textbf{d.}] $\left[\begin{array}{c}1 \\ -1 \\ 0\end{array}\right]$
 \end{tasks}
 \item 73  A $3 \times 3$ matrix $M$ has $\operatorname{Tr}[M]=6, \operatorname{Tr}\left[M^{2}\right]=26$ and $\operatorname{Tr}\left[M^{3}\right]=90$. Which of the following can be a possible set of eigenvalues of $M$ ?
      \begin{tasks}(2)
     	\task[\textbf{a.}]$\{1,1,4\}$
     	\task[\textbf{b.}]$\{-1,0,7\}$
     	\task[\textbf{c.}]$\{-1,3,4\}$
     	\task[\textbf{d.}] $\{2,2,2\}$
     \end{tasks}
\item     Q74. Consider an $n \times n(n>1)$ matrix $A$, in which $A_{i j}$ is the product of the indices $i$ and $j$ (namely $\left.A_{i j}=i j\right)$. The matrix $A$
      \begin{tasks}(2)
     	\task[\textbf{a.}]has one degenerate eigevalue with degeneracy $(n-1)$
     	\task[\textbf{b.}]has two degenerate eigenvalues with degeneracies 2 and $(n-2)$
     	\task[\textbf{c.}]has one degenerate eigenvalue with degeneracy $n$
     	\task[\textbf{d.}] does not have any degenerate eigenvalue
     \end{tasks}
 \item     Q75. A $3 \times 3$ matrix has elements such that its trace is 11 and its determinant is 36 . The eigenvalues of the matrix are all known to be positive integers. The largest eigenvalues of the matrix is
     \begin{tasks}(2)
    	\task[\textbf{a.}]18
    	\task[\textbf{b.}]12
    	\task[\textbf{c.}]9
    	\task[\textbf{d.}] 6
    \end{tasks}
\item Q76. The inverse of matrix $M=\left(\begin{array}{lll}0 & 1 & 1 \\ 0 & 0 & 1 \\ 1 & 0 & 0\end{array}\right)$ is
  \begin{tasks}(2)
    	\task[\textbf{a.}]$M-I$
    	\task[\textbf{b.}]$M^{2}-I$
    	\task[\textbf{c.}]$I-M^{2}$
    	\task[\textbf{d.}] $I-M$.
    \end{tasks}
\item Q77. Consider the matrix $M=\left(\begin{array}{ccc}0 & 2 i & 3 i \\ -2 i & 0 & 6 i \\ -3 i & -6 i & 0\end{array}\right)$. The eigenvalues of $M$ are
 \begin{tasks}(2)
	\task[\textbf{a.}]$-5,-2,7$
	\task[\textbf{b.}]$-7,0,7$
	\task[\textbf{c.}]$-4 i, 2 i, 2 i$
	\task[\textbf{d.}] $2,3,6$
\end{tasks}
 \item Q78. The matrix $A=\frac{1}{\sqrt{3}}\left[\begin{array}{cc}1 & 1+i \\ 1-i & -1\end{array}\right]$.
 is
  \begin{tasks}(2)
 	\task[\textbf{a.}]Orthogonal
 	\task[\textbf{b.}]symmetric
 	\task[\textbf{c.}] anti-symmetric
 	\task[\textbf{d.}]  Unitary
 \end{tasks}
\item Q79. If $H$ is Hermitian matrix then matrix $A=\exp (i H)$ is
  \begin{tasks}(2)
 	\task[\textbf{a.}] IIermitian
 	\task[\textbf{b.}] Unitary
 	\task[\textbf{c.}] Skew Hermitian
 	\task[\textbf{d.}] Identity
 \end{tasks}
\item Q80. Which one of following is correct?
      \begin{tasks}(2)
     	\task[\textbf{a.}] If $A^{\dagger}=A$ and $B^{\dagger}=-B$, then $A B+B A$ is skew Hermitian
     	\task[\textbf{b.}]If $A^{\dagger}=A$ and $B^{\dagger}=-B$, then $A B+B A$ is Hermitian
     	\task[\textbf{c.}] If $A^{\dagger}=A$ and $B^{\dagger}=-B$, then $-i(A B+B A)$ is skew Hermitian
     	\task[\textbf{d.}]  If $A^{\dagger}=A$ and $B^{\dagger}=-B$, then $i(A B+B A)$ is skew Hermitian
     \end{tasks}
\item Q81. A square matrix $3 \times 3$ is given by $A=\left[\begin{array}{ccc}2 & 0 & 0 \\ 0 & 1 & 1 \\ 0 & 1 & 1\end{array}\right]$ is diagonalized in eigenvector of matrix $S=\left[\begin{array}{ccc}1 & 0 & 0 \\ 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ 0 & -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}}\end{array}\right]$. Which one of the following is the diagonal matrix of $A$ in form in the basis of $S$ ?
\begin{tasks}(2)
     	\task[\textbf{a.}] $\left[\begin{array}{lll}2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 0\end{array}\right]$
     	\task[\textbf{b.}]$\left[\begin{array}{lll}0 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 2\end{array}\right]$
     	\task[\textbf{c.}] $\left[\begin{array}{lll}2 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 2\end{array}\right]$
     	\task[\textbf{d.}] $\left[\begin{array}{lll}1 & 0 & 2 \\ 0 & 1 & 0 \\ 0 & 0 & 2\end{array}\right]$
     \end{tasks}
\item    Q82. The column vector $\left(\begin{array}{l}a \\ b \\ a\end{array}\right)$ is a simultaneous eigenvector of
$A=\left(\begin{array}{lll}0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 0\end{array}\right)$ and $B=\left(\begin{array}{lll}0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0\end{array}\right)$, if
 \begin{tasks}(2)
	\task[\textbf{a.}]$b=0$ or $a=0$
	\task[\textbf{b.}]$b=a$ or $b=-2 a$
	\task[\textbf{c.}]$b=2 a$ or $b=-a$
	\task[\textbf{d.}] $b=a / 2$ or $b=-a / 2$
\end{tasks}
\item Q83. Two matrices $A$ and $B$ are said to be similar if $B=P^{-1} A P$ for some invertible matrix $P$. Which of the following statements is NOT TRUE?
   \begin{tasks}(2)
  	\task[\textbf{a.}] $\operatorname{Det} A=\operatorname{Det} B$
  	\task[\textbf{b.}] Trace of $A=$ Trace of $B$
  	\task[\textbf{c.}]$\dot{A}$ and $B$ have the same eigenvectors
  	\task[\textbf{d.}] $A$ and $B$ have the same eigenvalues
  \end{tasks}
\item Q84. The matrix $A=\left(\begin{array}{lll}0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 2\end{array}\right)$ is diagonalize in the basis of unitary matrices $U$ and get the diagonalise matrix $\left(\begin{array}{ccc}2 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & -1\end{array}\right)$ then matrix $U$ is
 \begin{tasks}(2)
	\task[\textbf{a.}]$\left(\begin{array}{ccc}0 & 0 & 1 \\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\ \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} & 0\end{array}\right)$
	\task[\textbf{b.}]$\left(\begin{array}{ccc}0 & 0 & 1 \\ \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\ -\frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0\end{array}\right)$
	\task[\textbf{c.}]$\left(\begin{array}{ccc}0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ 0 & \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \\ 1 & 0 & 0\end{array}\right)$
	\task[\textbf{d.}] $\left(\begin{array}{ccc}0 & 1 & 0 \\ \frac{1}{\sqrt{2}} & 0 & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & 0 & -\frac{1}{\sqrt{2}}\end{array}\right)$
\end{tasks}

\end{enumerate}


\section{Playing Around With Our New Toy}

    \frame{\sectionpage}

    \begin{frame}{Fourier Transforming}
        \only<-3>{\uncover<+->{\begin{equation*}
            f(t) = \cos(\omega_0 t)e^{-\pi t^2}
        \end{equation*}}
        \uncover<+->{\begin{equation*}
            \widehat{f}(\omega) = \frac{e^{-\frac{(\omega - \omega_0)^2}{4\pi}} + e^{-\frac{(\omega + \omega_0)^2}{4\pi}}}{2\sqrt{2\pi}}
        \end{equation*}}
        \uncover<+->{\begin{equation*}
            \omega = 2\pi\nu
        \end{equation*}}}
        \only<4>{\begin{equation*}
            f(t) = \cos(2\pi\nu_0 t)e^{-\pi t^2}
        \end{equation*}
        \begin{equation*}
            \widehat{f}(\nu) = \frac{e^{-\pi(\nu - \nu_0)^2} + e^{-\pi(\nu + \nu_0)^2}}{2\sqrt{2\pi}}
        \end{equation*}}
    \end{frame}

    \begin{frame}{Fourier Transforming}
        \begin{equation*}
            f(t) = \cos(2\pi\nu_0 t)e^{-\pi t^2}
        \end{equation*}
        \centering

        \includegraphics[height = 0.7 \textheight]{images/Pulse1.pdf}
    \end{frame}

    \begin{frame}{Fourier Transforming}
        \begin{equation*}
            \widehat{f}(\nu) = \frac{e^{-\pi(\nu - \nu_0)^2} + e^{-\pi(\nu + \nu_0)^2}}{2\sqrt{2\pi}}
        \end{equation*}
        \centering

        \includegraphics[height = 0.65 \textheight]{images/Pulse1-Fourier.pdf}
    \end{frame}

    \begin{frame}{A Harder Example}
        \uncover<+->{\begin{equation*}
            f(t) = e^{i\omega_0 t} = \cos(\omega_0 t) + i \sin(\omega_0 t)
        \end{equation*}}
        \uncover<+->{\begin{equation*}
            \widehat{f}(\omega) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{+\infty} e^{i\omega_0 t} e^{-i \omega t} \dd{t}
        \end{equation*}}
    \end{frame}

    \begin{frame}{The Mathematical Moonwalk}
        \uncover<+->{\begin{equation*}
            f(t) = e^{i\omega_0 t}
        \end{equation*}}
        \uncover<+->{\begin{equation*}
            e^{i\omega_0 t} = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{+\infty} \widehat{f}(\omega) e^{i \omega t} \dd{\omega}
        \end{equation*}}
        \uncover<+->{\begin{equation*}
            \widehat{f}(\omega) = \sqrt{2\pi} \dirac{\omega - \omega_0}
        \end{equation*}}
    \end{frame}

    \begin{frame}{Cosines}
        \begin{equation*}
            f(t) = \cos(\omega_0 t) = \frac{e^{i\omega_0t} + e^{-i\omega_0t}}{2}
        \end{equation*}

        \centering
        \includegraphics[height = 0.65 \textheight]{images/Pulse2.pdf}
    \end{frame}

    \begin{frame}{Cosines}
        \begin{equation*}
            \widehat{f}(\omega) = \sqrt{\frac{\pi}{2}}\prnt{\dirac{\omega-\omega_0} + \dirac{\omega+\omega_0}}
        \end{equation*}

        \centering
        \includegraphics[height = 0.65 \textheight]{images/Pulse2-Fourier.pdf}
    \end{frame}

200+ beamer 模板合集/DeadPhysicistsSocietyPresentationTemplate(DPS 研讨会)/chapters/playing-around.tex


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{November 26, 2014}
\maketitle
\section*{section 6.2.4}
let $f:[a,b]\to\mathbb{R}$ be differentiable, then
\begin{enumerate}
\item
if $f'$ is (strictly) positive, $f$ is (strictly) increasing
\item
same for negative
\item
if $f'(x)=0$ then $\forall x\in[a,b]$, $f$ is constant
\end{enumerate}
\subsubsection*{proof}
suppose $f'$ is strictly positive, let $x,y\in[a,b]$ such that $x<y$. then by mean value theorem $\exists c\in(x,y)$ such that $f'(c)=\frac{f(y)-f(x)}{y-x}$ and so $(y-x)f'(c)=f(y)-f(x)$ and so $y-x>0$ and $f'(c)\ge 0 (>0)$ so $f(y)-f(x)\ge0$ an $f(y)\ge f(x)$

\subsection*{exercise 6.2.L}
a function is convex (lies below that line segment (x,f(x) to (y,f(y))) if $f(tx+(1-t)y)\le tf(x) +(1-t)f(y)$ for all $x,y$ in $[a,b]$ and all $t\in[0,1]$
\subsection*{a)} if $f$ is differentiable and $f'$ is increasing then $f$ is convex.

define $z=tx+(1-t)y$

note that $x\le z\le y$. and there exists $c_1\in(x,z),c_2\in(z,y)$ and $f'(c_1)=\frac{f(z)-f(x)}{z-x}$ and $f'(c_2)=\frac{f(y)-f(z)}{y-z}$ and $c_1< c_2$ and so $f'(c_1)\le f'(c_2)$ and $\frac{f(z)-f(x)}{z-x}\le \frac{f(y)-f(z)}{y-z}$ and on through until $f(z)(y-z)+f(z)(z-x)\le f(y)(z-x)+f(x)(y-z)$ and sub t back in for
\begin{align*}
  f(z)(y-x)&\le f(y)[tx+(1-t)y-x]+f(x)[y-tx-(1-t)y]\\
\end{align*}
and algebra to get definition
\end{document}


\documentclass[../PHYS306Notes.tex]{subfiles}

\begin{document}
\section{Lecture 7}
\subsection{Lecture Notes - Symmetries and Conservation Laws}
\subsubsection{Noether's Theorem}
Idea: Certain symmetries we observe in nature are associated with conservation laws. E.g. momentum with translational symmetry. Formally, we consider the following:
\newline Consider a Lagrangian $\LL(q, \dot{q}, t)$ is invariant under a coordinate transformation $(q_1, \cdots, q_n) \rightarrow (\tilde{q}_1(\alpha), \cdots, \tilde{q}_n(\alpha))$ with $\tilde{q}_i(\alpha) = q_i + \alpha h_i(q,t) + \delta(\alpha^2)$. Consider taking the derivative with respect to $\alpha$ and set $\alpha = 0$:
\[\left.\dod{}{\alpha}\LL(\tilde{q}(\alpha), \dot{\tilde{q}}(\alpha), t)\right|_{\alpha = 0} = 0\]
Where the expression is zero as $\LL$ is invariant of $\alpha$. Now, by the chain rule, we can say:
\[0 = \left. \sum_{j=1}^n\left(\dpd{\LL}{\tilde{q}_j}\dpd{\tilde{q}_j}{\alpha} + \dpd{\LL}{\dot{\tilde{q}}_j}\dpd{\dot{\tilde{q}}_j}{\alpha}\right)\right|_{\alpha=0}\]
Now, we can say that $\dpd{\dot{\tilde{q}}_j}{\alpha} = \dod{}{t}\dpd{\tilde{q}_j}{\alpha}$ my equality of mixed partials. Using the EL equations, we can also say that $\dpd{\LL}{\tilde{q}_j} = \dod{}{t}\dpd{\LL}{\dot{\tilde{q}}_j}$. We can then write the whole expression as:
\[0 = \left.\dod{}{t}\sum_{j=1}^n\left(\dpd{\LL}{\dot{\tilde{q}}_j}\dpd{\tilde{q}_j}{\alpha}\right)\right|_{\alpha=0}\]
By the chain rule. We have just recollapsed the sum using the chain rule multiple times. Now, call this sum $I(q, \dot{q}, t)$. This object is conserved as its time derivative is zero, i.e. $\dod{}{t}I(q, \dot{q}, t) = 0$. Let us apply this to make this more concrete.
\subsubsection{Translational and Rotational Symmetry}
The first symmetry we will consider is the homoegeneity of space. This can be mathematically represented as $\v{r}_i \mapsto \tilde{\v{r}}_i + \alpha\ehat$ (where $\ehat$ is some unit vector) and where $\dot{\v{r}}_i = \dot{\tilde{\v{r}}}_i$.
\newline The next symmetry we can consider is the isotropy of space. This is represented as $\v{r}_i \mapsto \tilde{\v{r}}_i = \v{r}_i + \hat{\bm{\alpha}}\times \v{r}_i$ (where $\hat{\bm{\alpha}}$ is the axis of rotation).
\newline Now, what does Noether tell us about these symmetries? Assuming that the Lagrangians are invariant under the transformations, then $I$ is conserved, and hence:
\[I = \left.\sum_{j=1}^n\left(\dpd{\LL}{\dot{\tilde{q}}_j}\dpd{\tilde{q}_j}{\alpha}\right)\right|_{\alpha=0} = \begin{cases}
\text{(Translation) } \sum_{j=1}^n m_j\dot{\v{r}}_j \cdot \ehat
\\ \text{(Rotation) } \sum_{j=1}^nm_j\dot{r}_j \cdot\left(\hat{\bm{\alpha}} \times \v{r}_j\right) = \hat{\bm{\alpha}}\sum_{j=1}^n \v{r}_j \times m_j \dot{\v{r}}_j
= \hat{\bm{\alpha}}\cdot\v{L}\end{cases}\]
In the first case (with translational symmetry) we have conservation of linear momentum along $\ehat$. In the second case (with rotational symmetry) we have the conservation of angular momentum along $\hat{\bm{\alpha}}$.
\subsubsection{Time symmetry and the Hamiltonian}
We next consider a scenario where we have homogeneity of time; In other words, where $\LL$ is unchanged by $t$. $t \mapsto t + \e$, and $\dpd{\LL}{t} = 0$. Expanding out the total time derivative of the Lagrangian, we have:
\[\dod{}{t}\LL(q, \dot{q}, t) = \sum_{j=1}^n \left(\dpd{\LL}{q_j}\dpd{q_j}{t} + \dpd{\LL}{\dot{q}_j}\dpd{}{t}\dpd{q_j}{t}\right)\]
We recall that $\dpd{q_j}{t} = \dot{q}_j$, $\dpd{\LL}{\dot{q}_j} = p_j$ (generalized momentum) and $\dpd{\LL}{q_j} = \dod{}{t}\dpd{\LL}{\dot{q}_j}$ (generalized force/time derivative of generalized momentum). Again by taking out the time differential operator out of the sum, we have:
\[\dod{}{t}\LL(q, \dot{q}, t) = \dod{}{t}\sum_jp_j\dot{q}_j\]
where $p_j$ is the generalized momentum of the coordinate $q_j$. We can write this as:
\[\dod{}{t}\left(\sum_jp_j\dot{q}_j - \LL\right) = 0\]
And we call the term in the brakets to be the \textbf{Hamiltonian}:
\[\HH = \sum_jp_j\dot{q}_j - \LL\]
which is a conserved quantity.
\end{document}


\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{url}
\usepackage{fullpage}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}

\newcommand{\N}{\mathcal{N}}
\newcommand{\I}{\mathcal{I}}
\newcommand{\R}{\mathbb{R}}
\renewcommand{\v}[1]{\mathbf{#1}}

\begin{document}

\title{Hierarchical Regression for SIG-VISA}
\author{Dave Moore}
\maketitle

\section{Fully Parametric}

We first consider the case where some parameter of interest $y$ (e.g. the amplitude transfer function) is modeled as linear-in-features for some feature representation $\phi$, plus i.i.d. Gaussian noise:
\[\v{y} = \v{w}^T\phi(X) + \v{\epsilon}, \qquad \v{\epsilon} \sim \N(\v{0}, \sigma^2_n \I).\]
We allow weights to vary across stations. The weight $\v{w}^{(s)}$ at station $s$ is modeled as the sum of a global weight vector and a station-specific correction:
\[\v{w}^{(s)} = \v{w} + \v{c}^{(s)}, \qquad \v{w}\sim\N(\v{\mu_g}, \Sigma_g \I), \qquad v{c}^{(s)} \sim \N(\v{0}, \Sigma_e).\]
We observe data $X^{(s)}, \v{y}^{(s)}$ at each station. We assume as a ``black box'' the ability to run a Bayesian linear regression to obtain the posterior distribution $p(\v{w}^{(s)} | X^{(s)}, \v{y}^{(s)})$ on the regression weights given the observed data.

    %% LET:
    %% prior(g) ~ N(\mu_g, sigma_g)
    %% s = g + eps, eps ~ N(0, \sigma_e)

    %% p(g | d) = int_s p(g|s)p(s|d) ds
    %% where
    %% p(s|d) ~ N(s; mu_s, sigma_s)

    %% p(g|s) ~ N(g; mu, sigma)
    %%          mu = sigma * (sigma_e^-1 * s + sigma_g^-1 * mu_g)
    %%          sigma = (sigma_e^-1 + sigma_g^-1)^-1
    %% (see ``observations'' section of my gaussian identity notes)

    %% now let A = sigma * sigma_e^-1, b = sigma * sigma_g^-1 * mu_g, then
    %% p(g|d) = int_s N(g; As+b, sigma) N(s; mu_s, sigma_s) ds
    %% by the ``linear gaussian marginalization'' section of my notes, this gives

    %% p(g|d) ~ N(g; A*mu_s +b, sigma + A * sigma_s * A^T )

    %% so

    %% mu_g <= A*mu_s + b
    %%       = sigma * (sigma_e^-1 * mu_s + sigma_g^-1 * mu_g)
    %%       = sigma * (p_e * mu_s + p_g * mu_g)

    %% sigma_g <= sigma + A * sigma_s * A^T
    %%          = sigma + sigma * sigma_e^-1 * sigma_s * sigma_e^-1 * sigma
    %%          = sigma * (I + sigma_e^-1 * sigma_s * sigma_e^-1)

    %% where sigma = (p_e + p_g)^-1: if we had a specific value of s to update with, we'd get a new precision for the global params by summing our current precision, with the precision on our observed value of s.

    %% TODO: implement the equations above, hope for numerical stability

message passing interpretation?

we have a big tree graph. lots of station params tied together by global params. below each station param in station data, which we observe.

The message passed by the station params to the global params is

m_s->g = \int_s p(s|g) * m_d->s p(d | s)
       = \int_s p(s|g) * p(d|s)

so the marginal on global params is proportional to

p(g) * \prod_s m_s->g

and the marginal on params at any station should be prop to

m_g->s * m_d->s
= \int p(s|g) dg * p(d|s)
which is exactly p(s|d) if we marginalize out g, and just use p(g) + station_slack as our prior on s.
so given a marginal on g, we should be able to get the appropriate marginals on s just by building the regression model.

argh. if we have a single station, and we marginalize out g, we literally just have the standard regression model. so we should get the same results.
but somehow this is just totally incompatible with the idea that we compute p(g|d), then train under that prior.
the answer, somehow, is going to come from the fact that in message passing, we don't pass a node's own messages back down to it. we just pass messages from elsewhere in the tree.

let's take the simplest possible case. just a single scalar. we have

g ~ N(0,1)
s ~ N(g, 1)
d ~ N(s, 1)

we observe d. now we have a ``regression'' procedure which computes p(s|d) \propto p(d|s)p(s)
where p(s) = int dg p(s|g)p(g) = N(0, 2). Then the ``regression'' is given by
p(s|d) = N( d/2, .5  )
following the ``observation'' section of my Gaussian notes.

and the global posterior is now
p(g | d) \propto p(d | g)p(g)
               = p(g) int_s p(d|s) p(s|g)
               = N(g, 0, 1) *
         = N(.25, .75)
following the equations I figured out elsewhere, which seems plausible.
but it would NOT be okay to go back and update s by training with this prior.
why not? shouldn't message passing reach a fixed point? yes, but the messages I pass to s are always going to be the messages from elsewhere. they'll never be exactly the same as the marginal.

so I think it'd be okay to compute, for each station, the posterior on the global params from ALL OTHER stations, then use that as the prior to train. that takes n^2 work though. is there a more efficient way of getting these messages?

repeating from above, our messages are

m_s->g (g) = \int_s p(s|g) * p(d|s)
           = p(d|g)

I have p(g|d) ~ p(d|g)p(g)

now say I want to compute the message to station i
formally speaking this is the product of messages from all the other stations, with the global prior

so if I went through and updated to get the global marginal, can I get the message by ``dividing out'' the contribution from that one station?

dividing by a Gaussian density is (up to constants) the same as multiplying by that density with a negative sign on the covariance matrix.
so let's say I have a marginal on g. now I want the ``message'', i.e., the distribution with which to do regression in order to get s to work.

if my previous ``update'' corresponded to multiplying g by the message from s, then renormalizing to get a posterior on g, I should be able to ``divide'' just by doing the exact same update, but with the negative of the covariance matrix from s.

oh shit.
the ``message'' that I send from s to g should *just* be from the data. it shouldn't have any component from g at all.
in other words, my message should be

M_s->g = \int_s p(s|g) p(d|s)
= N(Hg; d, noise_var*I H sigma_e H^T)

somehow this isn't satisfying though: I should still be able to do an ``update'' on p(g).

so I could write code to do an ``update'' on p(g), by taking whatever the current p(g) mean and cov are, and incorporating the message from d. this doesn't let me use the existing regression code. but hopefully it would work, and would let me debug the current code approach.

okay, so my message-passing approach is

p(g|d) \propto p(d|g)p(g)
             = N(Hg; d, noise_var*I H sigma_e H^T) * N(mu_g, sigma_g)
       where we just update mu_g and sigma_g

my other approach is
p(g|d) = int_s p(g,s|d)
       = int_s p(g|s)p(s|d)
where p(s|d) comes from the bayesian regression. now formally, we have p(s|d) \propto p(d|s)p(s),
where p(s) is a prior on s. in our graph, this comes from pushing down the *prior* on g.
so I should be running my p(s|d) regression using the prior on s, if I want this to work out.

then we have p(g|s). this is
p(s|g)p(g) = N(s; g, cov_e) N(g; mu_g, cov_g)
           = N(c, C)
C = (cov_g^-1 + cov_e^-1)^-1
c = C (cov_g^-1 * mu_g + cov_e^-1 * s)

which matches what I got before.

then p(g|d) = int_s p(g|s) p(s|d)
            = int_s N(C * (cov_e^-1 * s) + C * (cov_g^-1)*mu_g, C) N(mu_s, cov_s)

IT WORKS!

now to ``back out'' a station's contributions.
we have p(g|d) = p(d|g)p(g)
and we want
p(g) = p(g|d)
       ------
       p(d|g)
where p(d|g) = int_s p(d|s)p(s|g)
             = int_s p(s|d)p(d)/p(s) * p(g|s)p(s)/p(g)
             = int_s p(s|d)p(g|s) / p(g)
             = p(g|d) / p(g)

well, we know explicitly that p(d|g) = N(Hg; d, noise_var*I H sigma_e H^T)

we have an expression for the posterior on the global params, given all of our stations
we also have, for station i, a posterior on the station params given the data
(which we previously used to update the global posterior)

maybe I just need to use math.

sg2 = (se^-1 + sg1^-1)^-1 + (se^-1 + sg1^-1)^-1 * se^-1 * sigma_s * se^-1 * (se^-1 + sg1^-1)^-1

sg2 (se^-1 + sg1^-1) = I + (se^-1 + sg1^-1)^-1 * se^-1 * sigma_s * se^-1

(se^-1 + sg1^-1) sg2 (se^-1 + sg1^-1) = se^-1 + sg1^-1 + se^-1 * sigma_s * se^-1

(sei *sg2 * sei) + (sg1i * sg2 * se1) + (sei * sg2 * sg1i) + (sg1i * sg2 * sg1i) =
sei + sg1i + sei * sigma_s * sei

\end{document}


\subsection{One to one and onto transformations}

Recall the following definitions, given here in terms of vector spaces.

\begin{definition}{One to one}{one-to-one-vector-space}
Let $V, W$ be vector spaces with $\vect{v}_1, \vect{v}_2$ vectors in $V$. Then a linear transformation $T: V \to W$ is called one to one if whenever $\vect{v}_1 \neq \vect{v}_2$ it follows that
\[
T(\vect{v}_1) \neq T (\vect{v}_2)
\]
\end{definition}

\begin{definition}{Onto}{onto-vector-space}
Let $V, W$ be vector spaces. Then a linear transformation $T: V \to W$ is called onto if for all $\vect{w} \in \vect{W}$ there exists $\vect{v} \in V$ such that $T(\vect{v}) = \vect{w}$.
\end{definition}

Recall that every linear transformation $T$ has the property that $T(\vect{0})=\vect{0}$. This will be necessary to prove the following useful lemma.

\begin{lemma}{One to one}{one-to-one-abstract}
The assertion that a linear transformation $T$ is one to one is equivalent to
saying that if $T(\vect{v})=\vect{0}$, then $\vect{v}=\vect{0}$.
\end{lemma}

\begin{proof}
Suppose first that $T$ is one to one.
\begin{equation*}
T(\vect{0})=T(\vect{0}+\vect{0}) =T(\vect{0})+T(\vect{0})
\end{equation*}
and so, adding the additive inverse of $T(\vect{0})$ to both sides, one sees
that $T(\vect{0})=\vect{0}$. Therefore, if $T(\vect{v})=\vect{0}$, it must be the
case that $\vect{v}=\vect{0}$ because it was just shown that $T(\vect{0})=\vect{0}$.

Now suppose that if $T(\vect{v})=\vect{0}$, then $\vect{v}=\vect{0}$. If $T(\vect{v})=T(\vect{u})$, then $T(\vect{v})-T(\vect{u})=T(\vect{v}-\vect{u}) =\vect{0}$ which
shows that $\vect{v}-\vect{u}=\vect{0}$ or in other words, $\vect{v}=\vect{u}$.
\end{proof}

Consider the following example.

\begin{example}{One to one transformation}{one-to-one-general}
Let $S:\Poly_2\to\Mat_{2,2}$ be a linear transformation
defined by
\[ S(ax^2+bx+c)
=
\begin{mymatrix}{cc}
a+b & a+c \\ b-c & b+c \end{mymatrix}
\mbox{ for all }
 ax^2+bx+c\in \Poly_2.\]
Prove that $S$ is one to one but not onto.
\end{example}

\begin{solution}
By definition,
\[ \ker(S)=\set{ax^2+bx+c\in \Poly_2 \mid a+b=0, a+c=0, b-c=0, b+c=0}.\]

Suppose $p(x)=ax^2+bx+c\in\ker(S)$.
This leads to a homogeneous system of four equations in three
variables.
Putting the augmented matrix in {\rref}:

\[ \begin{mymatrix}{rrr|c}
1 & 1 & 0 & 0  \\
1 & 0 & 1 & 0  \\
0 & 1 & -1 & 0  \\
0 & 1 & 1 & 0  \end{mymatrix}
\roweq\ldots\roweq
\begin{mymatrix}{ccc|c}
1 & 0 & 0 & 0  \\
0 & 1 & 0 & 0  \\
0 & 0 & 1 & 0  \\
0 & 0 & 0 & 0  \end{mymatrix}. \]

The solution is $a=b=c=0$. This tells us that if $S(p(x)) = 0$, then $p(x) = ax^2+bx+c = 0x^2 + 0x + 0 = 0$. Therefore it is one to one.

To show that $S$ is \textbf{not} onto, find a matrix $A\in\Mat_{2,2}$
such that for every $p(x)\in \Poly_2$,
$S(p(x))\neq A$.
Let
\[ A=\begin{mymatrix}{cc}
0 & 1 \\ 0 & 2 \end{mymatrix},\]
and suppose $p(x)=ax^2+bx+c\in \Poly_2$ is such that
$S(p(x))=A$.
Then
\[ \begin{array}{ll}
a+b=0 & a+c=1 \\ b-c=0 & b+c=2 \end{array}\]
Solving this system
\[ \begin{mymatrix}{ccc|c}
1 & 1 & 0 & 0  \\
1 & 0 & 1 & 1  \\
0 & 1 & -1 & 0  \\
0 & 1 & 1 & 2  \end{mymatrix}
\rightarrow
\begin{mymatrix}{rrr|r}
1 & 1 & 0 & 0  \\
0 & -1 & 1 & 1  \\
0 & 1 & -1 & 0  \\
0 & 1 & 1 & 2  \end{mymatrix}. \]

Since the system is inconsistent, there is no $p(x)\in \Poly_2$ so
that $S(p(x))=A$, and therefore $S$ is not onto.
\end{solution}

\begin{example}{An onto transformation}{onto}
Let $T:\Mat_{2,2}\to\R^2$ be a linear transformation defined by
\[ T\begin{mymatrix}{cc}
a & b \\ c & d \end{mymatrix}
=
\begin{mymatrix}{c}
a+d \\ b+c \end{mymatrix}
\mbox{ for all }
\begin{mymatrix}{cc}
a & b \\ c & d \end{mymatrix} \in\Mat_{2,2}.\]
Prove that $T$ is onto but not one to one.
\end{example}

\begin{solution}
Let $\begin{mymatrix}{c} x \\ y \end{mymatrix}$ be an arbitrary vector in $\R^2$.
Since
$T\begin{mymatrix}{cc} x & y \\ 0 & 0 \end{mymatrix}
=\begin{mymatrix}{c} x \\ y \end{mymatrix}$,
$T$  is onto.

By Lemma~\ref{lem:one-to-one-abstract} $T$ is one to one if and only if $T(A) = \vect{0} $ implies that $A = 0$ the zero matrix.
Observe that
\[
T \paren{\begin{mymatrix}{cc} 1 & 0 \\ 0 & -1 \end{mymatrix}}
=
\begin{mymatrix}{c}
1 + -1 \\
0 + 0
\end{mymatrix}
=
\begin{mymatrix}{c}
0 \\
0
\end{mymatrix}
\]
There exists a non-zero matrix $A$ such that $T(A) = \vect{0}$. It follows that $T$ is not one to one.
\end{solution}

The following example demonstrates that a one to one transformation preserves linear independence.

\begin{example}{One to one and independence}{preserves-independence}
Let $V$ and $W$ be vector spaces and $T: V \to W$ a linear
transformation.
Prove that if $T$ is one to one and
$\set{\vect{v}_1, \vect{v}_2, \ldots, \vect{v}_k}$ is an independent
subset of $V$, then
$\set{T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)}$ is an independent
subset of $W$.
\end{example}

\begin{solution}
Let $\vect{0}_V$ and $\vect{0}_W$ denote the zero vectors of $V$ and $W$,
respectively.
Suppose that

\[ a_1T(\vect{v}_1) + a_2T(\vect{v}_2) +\ldots +a_kT(\vect{v}_k) =\vect{0}_W \]

for some $a_1, a_2, \ldots, a_k\in\R$.
Since linear transformations preserve linear combinations (addition
and scalar multiplication),

\[ T(a_1\vect{v}_1 + a_2\vect{v}_2 +\ldots +a_k\vect{v}_k) =\vect{0}_W. \]

Now, since $T$ is one to one, $\ker(T)=\set{\vect{0}_V}$, and thus

\[ a_1\vect{v}_1 + a_2\vect{v}_2 +\ldots +a_k\vect{v}_k =\vect{0}_V. \]

\noindent However, $\set{\vect{v}_1, \vect{v}_2, \ldots, \vect{v}_k}$ is independent so $a_1=a_2=\ldots=a_k=0$.
Therefore, $\set{T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)}$
is independent.
\end{solution}

A similar claim can be made regarding onto transformations. In this case, an onto transformation preserves a spanning set.

\begin{example}{Onto and spanning}{preserves-spanning}
Let $V$ and $W$ be vector spaces and $T:V\to W$ a linear
transformation.
Prove that if $T$ is onto and
$V=\sspan\set{\vect{v}_1, \vect{v}_2, \ldots, \vect{v}_k}$,
then
\[ W=\sspan\set{T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)}.\]
\end{example}

\begin{solution}
Suppose that $T$ is onto and let $\vect{w}\in W$.
Then there exists $\vect{v}\in V$ such that $T(\vect{v})=\vect{w}$.
Since $V=\sspan\set{\vect{v}_1, \vect{v}_2, \ldots, \vect{v}_k}$, there
exist $a_1, a_2, \ldots a_k\in\R$ such that
$\vect{v} = a_1\vect{v}_1 + a_2\vect{v}_2 + \ldots + a_k\vect{v}_k$.
Using the fact that $T$ is a linear transformation,

\begin{eqnarray*}
\vect{w}=T(\vect{v})
& = & T(a_1\vect{v}_1 + a_2\vect{v}_2 + \ldots + a_k\vect{v}_k) \\
& = & a_1T(\vect{v}_1) + a_2T(\vect{v}_2) + \ldots + a_kT(\vect{v}_k),
\end{eqnarray*}

i.e., $\vect{w}\in\sspan\set{T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)}$,
and thus

\[ W\subseteq \sspan\set{T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)}.\]

Since $T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)\in W$,
it follows from
that
$\sspan\set{T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)}\subseteq W$,
and therefore
$W=\sspan\set{T(\vect{v}_1), T(\vect{v}_2), \ldots, T(\vect{v}_k)}$.
\end{solution}


\SecDef{intro}{Introduction}

S-Boxes play important role in the design of symmetric cryptographic primitives. It is one of the two components of an SPN structure and often S-Boxes are used inside the Feistel functions in Feistel Networks. The main role of S-Boxes is to provide non-linearity and confusion. An S-Box at least should have low linearity, low differential uniformity and high algebraic degree. It is also desirable that the S-Box has good implementation properties: an efficient hardware/bit-slice implementation, small size in order to reduce the memory footprint.

The cryptographic community expects designers to explain all choices done during the design procedure. How the S-Boxes were generated? Do they have an algebraic structure, e.g. an inversion in the finite field? Or do they have a Feistel Network structure? Were they generated at random? If yes, what was the seed used? Which cryptographic properties were optimized and how?

Unfortunately, often the designers describe the S-Box as a look-up table and do not provide any rationale behind its choice. A prominent example is the S-Box of the Skipjack block cipher designed by the American National Security Agency (NSA). Léo Perrin and Alex Biryukov~\cite{LeoRE} attempted to \emph{reverse-engineer} it, i.e. to find the hidden design criteria, an underlying structure or optimization procedure. They succeeded and described a simple optimization method which generates S-Boxes with very close cryptographic properties. The designers of the Russian cryptographic standards did not disclose any rationale behind the S-Box as well, except that it has reasonable cryptographic properties.

The 8-bit S-Box used in the Kuznyechik block cipher and in the Streebog hash function is denoted $\pi$ in this chapter. The look-up table of $\pi\colon \field{8} \to \field{8}$ is given in \TabRef{sbox}. It has linearity equal to 56 and differential uniformity equal to 8. Using methods developed in~\cite{LeoRE}, it can be shown that the probability to randomly sample an S-Box with as good differential properties is approximately $2^{-82.69}$. It follows that $\pi$ has strong resistance against differential cryptanalysis, compared to random S-Boxes. The algebraic degree of all coordinates of $\pi$ is maximal and equal to 7.

\FigTex{sbox.tex}

In this chapter I describe two decompositions of $\pi$ and the way in which they were obtained. A simplified view of the discovered structures of $\pi$ is given in  \FigRef{simplified}. The first decomposition is based on finite field multiplications. It also contains four 4-bit S-Boxes and two whitening (external) linear layers. Interestingly, 16 inputs clearly stand out from the patterns and force the usage of a multiplexer (omitted in the simplified view). The second decomposition is based on a finite field logarithm. It contains only one extra 4-bit S-Box, one whitening linear layer and a simple arithmetic layer.

More recently, my former colleague Léo Perrin studied the logarithm-based decomposition further~\cite{LeoKuz}. He shows that the S-Box maps a partition of $\field{8}$ into multiplicative cosets of $\fielde{4}^*$ into a partition of $\field{8}$ into additive cosets of $\field{4}$. Furthermore, he derives a structure called $\mathsf{TKlog}$ that $\pi$ follows.

\FigTex{simplified.tex}

\subsection{Outline}
\SecRef{multi} described the first decomposition, and \SecRef{expo} explains the second decomposition. The results are summarized and discussed in \SecRef{conclusions}.

\subsection{Differences with~\cite{OurKuz1,OurKuz2}}
This chapter is a reworked version of the two papers~\cite{OurKuz1,OurKuz2} that we wrote with my colleagues Alex Biryukov and Léo Perrin. In this chapter I kept only results directly related to decompositions of $\pi$. The decompositions are kept the same, except that for the first decomposition I performed the analysis for $\pi$ from the beginning, without decomposing $\pi^{-1}$ first. In this way $T$ and $U$ are inverted and swapped, compared to~\cite{OurKuz1}. The final decomposition is the same.


\chapter{Combinatorics}

\section*{1.1. Assigning seats}
\addcontentsline{toc}{section}{1.1. Assigning seats}
Six girls and four boys are to be assigned to ten seats in a row, with the stipulations
that a girl sits in the third seat and a boy sits in the eighth seat. How many arrangements
are possible?

\vspace{1em}

\begin{proof}
    We compute the number of ways that the boy on the eighth seat and the girl on the third seat can be chosen:
    \[
        \binom{6}{1}\binom{4}{1} = 24
    \]

    Now, we see how many ways the other kids can be placed on the seats:
    \[
        !8 = 40,320
    \]

    Our final result is:
    \[
        24 \cdot 40,320 = 967,680
\]
\end{proof}

\section*{1.2. Number of outcomes}
\addcontentsline{toc}{section}{1.2. Number of outcomes}
One person rolls two six-sided dice, and another person flips six two-sided coins.
Which setup has the larger number of possible outcomes, assuming that the order matters?

\vspace{1em}

\begin{proof}
    The two dice rolls have $6^2 = 36$ possible outcomes, while the coin flips have $2^6 = 64$ outcomes.
\end{proof}

\section*{1.3. Subtracting the repeats}
\addcontentsline{toc}{section}{1.3. Subtracting the repeats}
\begin{enumerate}[(a)]
    \item From Eq. (1.6) we know that the number of ordered sets of three people chosen from five people
        is $5 \cdot 4 \cdot 3 = 60$. Reproduce this result by starting with the naive answer of $5^3 = 125$
        ordered sets where repetitions are allowed, and then subtracting off the number of triplets that have
        repeated people.
    \item It's actually not much more difficult to solve this problem in the general case where triplets
        are chosen from N people, instead of five. Repeat part (a) for a general N.
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item The number of triplets that have three repeating people is obviously $5$, while the number of
            triplets with two repetitions is given by $5 \cdot 4 \cdot 2 + 5 \cdot 1 \cdot 4 = 60$.
            Therefore, the number of ordered sets of three people chosen from five people is $125 - 60 = 65$.

        \item The number of triplets that have three repeating people will be $N$, while the number of triplets
            that have two repeating people will be $N(N - 1) \cdot 2 + N(N - 1) = 3N(N-1)$. As a result,
            the number of ordered sets of three people chosen from five people is given by
            $N^3 - 3N(N - 1) - N = N^3 - 3N^2 + 2N$.
    \end{enumerate}
\end{proof}

\section*{1.4. Subtracting the repeats, again}
\addcontentsline{toc}{section}{1.4. Subtracting the repeats, again}
Repeat the task of Problem 1.3(a), but now in the case where you pick quadruplets (instead of triplets)
from five people.

\vspace{1em}

\begin{proof}
    The number of ordered sets of 4 people chosen from five people is $5 \cdot 4 \cdot 3 \cdot 2 = 120$.

    To find the number of repeating quadruplets, we split them into 3 categories:
    \begin{enumerate}
        \item \textbf{4 repeating people} The repeating person can be chosen in 5 ways and there is only one way
            to order (AAAAA), so there are 5 such quadruples.

        \item \textbf{3 repeating people} The repeating person can be chosen in 5 ways, and then the
            non-repeating person in 4 ways, thus the number of unorderd quadruples is given
            by $4 \cdot 5 = 20$. Since there are 4 (AAAB, AABA, ABAA, BAAA) ways to choose the
            order, we get $4 \cdot 20 = 80$ ordered quadruples.

        \item \textbf{2 repeating people} The repeating person can be chosen in 5 ways, and the other 2 people
            can be chosen in $\binom{4}{2} = 6$ ways. Therefore, we have $5 \cdot 30 = 50$ unordered quadruples.
            The sets can be ordered in 12 ways, so we have $30 \cdot 12 = 360$ orderd quadruples with 2
            repeating people.

        \item \textbf{2 groups of repeating people} The repeated persons can be chosen in $\binom{5}{2} = 10$
            ways and can be ordered in 6 modes (AABB, ABAB, ABBA, BBAA, BABA, BAAB), therefore the number
            of such sorted quadruples is 60.

            Therefore, the number of ordered sets of four people from five people is
            \[
                5^4 - 5 - 80 - 360 - 60 = 120
            \]
    \end{enumerate}
\end{proof}

\vspace{1em}

\section*{1.6. Many ways to count}
\addcontentsline{toc}{section}{1.6. Many ways to count}
How many different orderings are there of the six letters: A, A, A, B, B, C? \\
How many different ways can you think of to answer this question?

\vspace{1em}

\begin{proof}
    We analyze the possible orderings of the letters. The positions of the 3 A letters can be chosen
    in $\binom{6}{3} = 20$ ways, and then the positions of the two B letters can be chosen in
    $\binom{3}{2} = 3$ modes. Since the C letter has the last position, we find that the number of possible
    orderings is now $20 \cdot 3 = 60$.

    The same method can be applied for any ordering of letter-position assignments (e.g. we choose the
    possible positions of B and then of A and C). We'll get different formulas, but the result will be the
    same. There are $3 \cdot 2 = 6$ such ways of computing the number of possible orderings.
\end{proof}

\section*{1.7. Committees with a president}
\addcontentsline{toc}{section}{1.7. Committees with a president}
Two students are given the following problem: From $N$ people, how many ways are there to choose a committee
of $n$ people, with one person chosen as the president? One student gives an answer of $n\binom{N}{n}$, while
the other student gives an answer of $N\binom{N-1}{n-1}$.

\begin{enumerate}[(a)]
    \item By writing out the binomial coefficients, show that the two answers are equal.
    \item Explain the (valid) reasoning that lead to these two (correct) answers.
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item We simply rewrite the expressions to obtain the equality:
        \[
            n\binom{N}{n} = n\frac{N!}{n!(N-n)!} = \frac{N!}{(n-1)!(N-n)!} = N\frac{(N-1)!}{(n-1)!(N-n)!}
                          = N\binom{N-1}{n-1}
        \]
        \item The president can be chosen in $N$ ways and then the rest of the group can be chosen in
            $\binom{N-1}{n-1}$ modes, giving us $N\binom{N-1}{n-1}$ ways to form the committee.

            Without thinking about the president, the committee can be chosen in $\binom{N}{n}$ ways. In
            such a committee any of the $n$ persons can be chosen as the president. Therefore, we have
            $n\binom{N}{n}$ ways to form the committee.
    \end{enumerate}
\end{proof}

\section*{1.8. Multinomial coefficients}
\addcontentsline{toc}{section}{1.8. Multinomial coefficients}
\begin{enumerate}[(a)]
    \item A group of ten people are divided into three committees. Three people are on committee
        A, two are on committee B, and five are on committee C. How many different ways are there
        to divide up the people?

    \item
        A group of N people are divided into k committees. $n_1$ people are on committee 1, $n_2$
        people are on committee 2, \dots, and $n_k$ people are on committee $k$, with
        $n_1 + n_2 + \dots + n_k = N$. How many different ways are there to divide up the people?
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item The people on committee A can be chosen in $\binom{10}{3} = 120$ ways and then the people on
            committee B can be chosen in $\binom{7}{2} = 21$ ways. The remaining people will be on the C
            committee. As a result, the group of ten people can be divided in $120 \cdot 21 = 2,520$ ways.

        \item We assign people to committees like in the previous example. The 1st committee's members
            can be chosen in $\binom{N}{n_1}$ modes, the 2nd committee's composition can be chosen in
            $\binom{N - n_1}{N_2}$ ways, and so on. We observe (and can prove using induction), that the
            number of ways the i-th ($2 \leq i < k$) committee can be assembled is given by the expression:
            \[
                M_i = \binom{N - n_1 - \ldots - n_{i - 1}}{n_i}
            \]
            Therefore, the number of ways the group of people can be divided is given by:
            \begin{align*}
                M = \binom{N}{n_1} \prod_{i = 2}^{k}M_i
                    =& \binom{N}{n_1} \binom{N - n_1}{n_2} \ldots \binom{N - n_1 - \ldots - n_{k - 1}}{n_k} \\
                    =& \frac{N!}{n_1! (N - n_1)!} \cdot \frac{(N - n_1)!}{n_2! (N - n_1 - n_2)!} \cdot \ldots
                    \cdot \frac{(N - n_1 - \ldots - n_{k - 1})!}{n_3! (N - n_1 - \ldots - n_{k - 1} - n_k)!} \\
                    =& \frac{N!}{n_1!n_2! \ldots n_k!}
            \end{align*}
    \end{enumerate}
\end{proof}

\section*{1.9. One heart and one 7}
\addcontentsline{toc}{section}{1.9. One heart and one 7}
How many different five-card poker hands contain exactly one heart and exactly one 7? (If the hand
contains the 7 of hearts, then this one card satisfies both requirements.)

\vspace{1em}

\begin{proof}
    There are $52 - 13 - 4 + 1 = 36$ cards that are neither a heart nor a 7. We consider two cases:
    \begin{enumerate}[(i)]
        \item \textbf{The 7 of hearts is in the hand}, so the other 4 cards in the hand
            can be any that are neither a heart nor a 7. As a result, we have
            $\binom{36}{4}= 58,905$ such hands.

        \item \textbf{The 7 of hearts is not in the hand.} There are 12 cards that are hearts and
            not a 7 and 3 cards that are 7 but not a heart. We choose one of each and the rest of
            the cards can be any that are neither a heart nor a 7. Hence, we get
            $12 \cdot 3 \binom{36}{3} = 257,040$ such hands.
    \end{enumerate}
    In conclusion, there are $286,110 + 257,040 = 315,945$ five-card hands that contain exactly
    one heart and exactly one 7.
\end{proof}

\section*{1.14. Yahtzee}
\addcontentsline{toc}{section}{1.14. Yahtzee}
In the game of Yahtzee, five dice are rolled in a group, with the order not mattering.

\begin{enumerate}[(a)]
    \item Using Eq. (1.16), how many unordered rolls (sets) are possible?

    \item In the spirit of the examples at the beginning of Section 1.7. reproduce the
        result in part (a) by determining how many unordered rolls there are
        of each general type (for example, three of one number and two of another, etc.)

    \item In the spirit of the example at the end of Section 1.7., show that the total
        number of \emph{ordered} Yahtzee rolls is $6^5 = 7776$.
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item The number of unordered rolls is given by
            \[
                \binom{5 + (6 - 1)}{6 - 1} = \binom{10}{5} = 252
            \]

        \item We split the rolls in 7 types:
            \begin{enumerate}[(1)]
                \item All five rolls are the same (e.g. 66666). There are 6 sets of this type.

                \item Four rolls have the same value and the other roll has another value (e.g. 66665).
                    There are $6 \cdot 5 = 30$ sets of this type.

                \item Three rolls have the same value and the other two rolls have other (different 2 by 2)
                    values (e.g. 66654). There are  $6 \binom{5}{2} = 6 \cdot 10 = 60$ sets of this type.

                \item Three rolls have the same value and the other two rolls have both another (same) value
                    (e.g. 66655). There are $6 \cdot 5 = 30$ sets of this type.

                \item Two rolls have the same value and the other three rolls have different (2 by 2) values
                    (e.g. 66654). There are $6 \binom{5}{2} = 60$ such sets.

                \item Two rolls have the same value, two rolls have another (same value) and the
                    remaining roll has another different value (e.g. 66554).
                    There are $6 \binom{5}{2} = 60$ such sets of rolls.

                \item Each roll has a different value. (e.g. 65432). There are $\binom{6}{5} = 6$ such sets.
            \end{enumerate}

        By summing all the types, we get that the number of unordered rolls is
        \[
            6 + 30 + 60 + 30 + 60 + 60 + 6 = 252
        \]

    \item We want to see in how many ways can the 5 roll types be ordered:
        \begin{enumerate}[(1)]
            \item All rolls are the same, so the set can be ordered in one way. The number of
                ordered sets with the same 5 rolls is 6.

            \item Four rolls have the same value and the other roll has another value.
                The set can be ordered in 5 ways (we consider the different roll on each
                possible position). Therefore, there are $5 \cdot 30 = 150$ ordered sets of this type.

            \item Three rolls have the same value and the other two have other (different 2 by 2) values.
                The positions of the repeated values can be chosen in $\binom{5}{3} = 10$ and then there
                are two ways to order the other values, so there are $10 \cdot 2 = 20$ ways to order the set.
                As a result, there are $20 \cdot 60 = 1200$ ordered sets of this type.

            \item Three rolls have the same value and the other two rolls have both another (same) value.
                There are $\binom{5}{3} = 10$ ways the sets can be ordered, so we get $10 \cdot 30 = 300$
                such ordered sets.

            \item Two rolls have the same value and the other three have other (different 2 by 2) values.
                As before, we find that the set of values can be ordered in
                $\binom{5}{2} \cdot 3 \cdot 2 = 60$ ways.
                Hence, there are $60 \cdot 60 = 3600$ such ordered sets.

            \item Two rolls have the same value, two rolls have another (same value) and the
                remining roll has another differente value. There are
                $\binom{5}{2}\binom{3}{2} = 10 \cdot 3 = 30$ ways to order this set, so we get
                $30 \cdot 60 = 1800$ such ordered sets.

            \item All rolls have different values. The sets can be ordered in $5! = 120$ ways. As a result,
                there are $120 \cdot 6 = 720$ such ordered sets.
        \end{enumerate}

        In conclusion, we get that the number of $\emph{ordered}$ sets of Yahtzee rolls is:
        \[
            6 + 150 + 1200 + 300 + 3600 + 1800 + 720 = 7776 = 6^5
        \]
    \end{enumerate}
\end{proof}

\section*{1.16. Pascal sum 2}
\addcontentsline{toc}{section}{1.16. Pascal sum 2}
At the end of Section 1.8.3, we demonstrated the relation
$\binom{n}{k} = \binom{n - 1}{k - 1} + \binom{n - 1}{k}$
by using the argument involving committees. Repeat this reasoning,
but now in terms of:
\begin{enumerate}[(a)]
    \item coin flips,
    \item the $(a + b)^n$ binomial expansion.
\end{enumerate}

\vspace{1em}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item The number of ways we can get $k$ tails from $n$ coin flips is given by
            $\binom{n}{k}$. If we single out the first flip, we get two cases:
            \begin{enumerate}[(1)]
                \item The flip was heads, so the number of ways to get tails $k$ times
                    from the rest $n - 1$ of the flips is $\binom{n - 1}{k}$

                \item The flip was tails, so the number of ways to get the remaining
                    $k - 1$ tails flips from the other $n - 1$ rolls is given by $\binom{n - 1}{k - 1}$
            \end{enumerate}

        Therefore, the number of ways we get $k$ tails from $n$ coin flips can be split into the above
        two cases, so:
        \[
            \binom{n}{k} = \binom{n - 1}{k} + \binom{n - 1}{k - 1}
        \]

    \item The coefficient of the term $a^{n - k}b^k$ from the expansion of $(a + b)^n$ is given by
        $\binom{n}{k}$. If we single out the first $(a + b)$ factor, we have two possible situations:
        \begin{enumerate}
            \item The factor was used in getting a power of $b$ in $a^{n - k}b^k$, so there are
                $\binom{n - 1}{k - 1}$ factors to use for the other $k - 1$ powers of $b$ and the $n - k$
                powers of $a$, since
                $\binom{n - 1}{n - k} = \binom{n - 1}{k - 1}$.

            \item The factor wasn't used in getting a power of $b$ in $a^{n - k}b^k$, so there are
                $\binom{n - 1}{k}$ factors to use for the other $k$ b powers and the other $n - k - 1$
                powers of a, since $\binom{n - 1}{n - k - 1} = \binom{n - 1}{k}$.
        \end{enumerate}

    Therefore, the coefficient of $a^{n-k}b^k$ is given by:
    \[
        \binom{n}{k} = \binom{n - 1}{k} + \binom{n - 1}{k - 1}
    \]
    \end{enumerate}
\end{proof}

\section*{1.17. Pascal diagonal sum}
\addcontentsline{toc}{section}{1.17. Pascal diagonal sum}
\begin{enumerate}[(a)]
    \item If we pick an unordered committee of three people from five people (A, B, C, D, E),
        we can list the $\binom{5}{3} = 10$ possibilities as shown in Table 1.19.
        We have grouped them according to which letter comes first. (The order of letters
        doesn't matter, so we've written each triplet in increasing alphabetical order.)
        The columns in the table tell us that we can think of $10$ as equaling $6 + 3+ 1$.
        Explain why it makes sense to write this sum as  $\binom{4}{2} + \binom{3}{2} + \binom{2}{2}$.

        \begin{table}[h]
            \centering
            \begin{tabular}{ccc}
                A B C & & \\
                A B D & & \\
                A B E & & \\
                A C D & B C D & \\
                A C E & B C E & \\
                A D E & B D E & C D E \\
            \end{tabular}
            \caption*{\textbf{Table 1.19:} Unordered triplets chosen from five people.}
        \end{table}

    \item You can also see from Table 1.15 and 1.16 that, for example
        $\binom{6}{3} = \binom{5}{2} + \binom{4}{2} + \binom{3}{2} + \binom{2}{2}$.
    More generally,
    \begin{equation*}\tag{1.29}
        \binom{n}{k} = \binom{n - 1}{k - 1} + \binom{n - 2}{k - 2} + \binom{n - 3}{k - 3} + \ldots +
                        \binom{k}{k - 1} + \binom{k - 1}{k - 1}
    \end{equation*}

    In words: A given number (for example, $\binom{6}{3}$) in Pascal's triangle equals the sum
    of the numbers in the diagonal string that starts with the number that is above and to the
    left of the given number ($\binom{5}{2}$ in this case) and then proceeds upward to the right.
    So the string contains $\binom{5}{2}, \binom{4}{2}, \binom{3}{2}$ and $\binom{2}{2}$
    in this case.

    Prove Eq.(1.29) by making repeated use of Eq.(1.22), which says that each number in Pascal's
    triangle is the sum of the two numbers abot it (or just the "1" above it, if it occurs at the end
    of a line).
\end{enumerate}

\begin{proof}
    \hfill
    \begin{enumerate}[(a)]
        \item We split the committees into 4 categories:
            \begin{enumerate}[(1)]
                \item The set contains A, so there are $\binom{4}{2} = 6$ such sets.
                \item The set contains B and doesn't contain A, so there are $\binom{3}{2} = 3$ sets.
                \item The set contains C and doesn't contain A or B, so there is $\binom{2}{2} = 1$
                \item The set doesn't contain A, B or C. There are obviously no such sets, as we
                    need 3 elements.
           \end{enumerate}

        Since the reunion of those sets contains all the possible unordered committees of 3 members,
        we obtain that:
        \[
            \binom{4}{2} + \binom{3}{2} + \binom{2}{2} = 6 + 3 + 1 = 10 = \binom{5}{3}
        \]

        \item We prove using induction that:
        \begin{equation*}\tag{1.29}
            \binom{n}{k} = \binom{n - 1}{k - 1} + \binom{n - 2}{k - 2} + \ldots +
                            \binom{k}{k - 1} + \binom{k - 1}{k - 1}
                            = \sum_{i = k}^{n} \binom{i - 1}{k - 1}, \forall k \in \mathbb{N^*}, k \leq n
        \end{equation*}
        for all $n \in \mathbb{N}, n \geq 2$.

        The base case is obviously valid, since
        \begin{align*}
            \binom{2}{1} &= \binom{1}{0} + \binom{0}{0} = 1 + 1 = 2 \\
            \binom{2}{2} &= \binom{1}{1} + \binom{0}{1} = 1 + 0 = 1
        \end{align*}

        We assume that the relation holds for a fixed $m \in \mathbb{N}, m \geq 2$, so we have:
        \[
            \binom{m}{k} = \sum_{i = k}^{m}\binom{i - 1}{k - 1}, \forall k \in \mathbb{N^*}, k \leq n
        \]

        Using (1.22), we obtain that:
        \[
            \binom{m + 1}{k} = \binom{m}{k} + \binom{m}{k - 1}
                             = \sum_{i = k}^{m}\binom{i - 1}{k - 1} + \binom{m}{k - 1}
                             = \sum_{i = k}^{m + 1}\binom{i - 1}{k - 1}
        \]

        Since (1.22) holds true for the base case and the $m$ case implies the validity of the $m + 1$ case,
        we proved using induction that (1.29) holds for all $n \in \mathbb{N}, n \geq 2$.
    \end{enumerate}
\end{proof}


\subsection{Application of Array in Image Analysis}
\subsubsection{Intensity Profile and Array Functions}

To learn the actual use of array in image analysis, we explore several example applications. In the first application, we use \ilcom{getProfile} function. We already used \ilcom{getProfile()} in the section \ref{subsec:numericalarray} ``Numerical Array''. This time, we use it in combination with Array functions to get local minima along the intensity profile - just like finding downward peak positions. We use a sample image Tree\textunderscore Rings.jpg (\ijmenu{[File > Open Samples > Tree Rings]}).

We draw a straight line ROI crossing tree rings, and then the aim of the macro we will write is to detect ring positions along that line ROI and indicate those positions by point ROIs. The macro first reads the line-profile from the straight line ROI and then we use \ilcom{Array.findMinima} function to detect local minima (dark rings). Since this function returns the position of minima only as indices of the line-profile array, we need to get \ilcom{x} and \ilcom{y} coordinates of minima from their indices in order to plot minima positions in the original image. For this purpose, we resample the straight line ROI to the same number of points as the length of line-profile array. Let's write the code and learn by doing.

Note: Before running the macro code20\_4.ijm, be sure to have a straight line ROI placed crossing tree rings (fig. \ref{fig:treeRingsSelected}).

\begin{figure}[h!]
\begin{center}
\includegraphics[width=0.9\textwidth]{fig/Tree_Rings_Selected.png}
\caption{A strainght Line ROI crossing rings.}
\label{fig:treeRingsSelected}
\end{center}
\end{figure}

\lstinputlisting[morekeywords={*, getProfile, Array, findMinima, resample, print, getStatistics}]{code/code20_4.ijm}

\begin{itemize}
\item line 3 - 4:  Check if the selection type is a straight line ROI using function \ilcom{selectionType}. If not, macro terminates leaving a message.
\item Line 5: An intensity profile array \ilcom{pA} is sampled by \ilcom{getProfile}().
\item Line 6: Detect local minima using \ilcom{Array.findMinima}. The first argument is the line-profile array, and the second argument is ``tolerance''. A larger tolerance value is less sensitive to intensity minimum - less detection. You could try changing this value later to see the effect. An array containing indices of minima positions is returned.
\item Line 7: \ilcom{getSelectionCoordinates} with straight-line ROI stores two arrays, each for start/end x coordinates and start/end y coordinates. Two arrays, in this case \ilcom{xpoints} and \ilcom{ypoints}, have length of two.
\item Line 8 - 9: Resampling of straight-line ROI by number of points in the line-profile array \ilcom{pA}.
\item Line 10-11: Prepare two new arrays to store x and y coordinates of minima positions.
\item Line 12: For-loop to go through minima indices array.
\item Line 13-14: \ilcom{minsA[i]} is the index for a single minimum, and using that index, x and y coordinate of that minimum position is retrieved and stored into new arrays prepared in line 10-11.
\item Line 16: After the looping, x and y coordinates of minima are used in \ilcom{makeSelection} function to create multiple point ROI.
\end{itemize}

Run the code, then you should see multiple point ROIs indicating positions of rings (See fig. \ref{fig:treeRingsSelected}). Similar macro can be used to measure striated pattens in tissues or cell edges. In case of fluorescence images, \ilcom{Array.findMaxima} can be used to detect high-intensity maxima positions.

\begin{figure}[h!]
\begin{center}
\includegraphics[width=0.9\textwidth]{fig/Tree_Rings_Minima.png}
\caption{Detected ring positions.}
\label{fig:treeRingsMinima}
\end{center}
\end{figure}

\subsubsection{Extending Stack Analysis by Direct Measurements}

We studied how to use for-loops to measure each frame/slice within a stack (\ref{sec:forloopStack}). There we did measurements by firstly setting measurement parameters with \ilcom{run("Set Measurements...")} and then did measurement by \ilcom{run("Measure")}. Measured values were shown in the table in the ``Results'' window. To use those measured values to \textit{e.g.} calculate statistics or plot the results, one should access the table in the ``Results'' window and parse all the values. This is possible with the macro language, but we will not try this method as it is indirect. Instead, we try to access directly to the measured values and compute. There are two ways.

\begin{enumerate}
\item \ilcom{getRawStatistics(nPixels, mean, min, max, std, histogram)}
\item \ilcom{List.setMeasurement}
\end{enumerate}
The function \ilcom{getRawStatistics} measures statistical parameters from the image and returns those values in the variables declared as arguments. In other words, after this function is executed, variable \ilcom{mean} will have the mean intensity of the image
\footnote{In this example we use a variable named \ilcom{mean}, but the name could be anything such as \ilcom{a} or \ilcom{b}.}.
If a ROI is selected, mean intensity of that ROI will be the value of \ilcom{mean}. We could loop each slice/frame within a stack and for each loop we could do \ilcom{getRawStatistics} and store measured values in arrays. But there is a drawback of using this function: the available parameters to measure is limited.

The second method \ilcom{List.setMeasurement} does not have this limitation. One could measure many more parameters because all the available parameters listed in \ilcom{[Analyze > Set Measurements...]} are accessible with this function. The basic usage is shown in the code below, which measures the currently active image, extracts specific measurement value (in this example case ``Mean'' intensity) and then prints out that value in the log window. Try writing this code and test it with any image.

\begin{lstlisting}
List.setMeasurements;
mean = List.getValue("Mean");
print(mean)
\end{lstlisting}

We could do the measurement using \ilcom{List.setMeasurement} function for every loop for stack slices/frames and store the results in arrays. Here is the code, a modified version of code 10 (p~\pageref{code:10}).

\lstinputlisting[morekeywords={*, List, setMeasurements, getValue, newArray}]{code/code10_1.ijm}

\begin{itemize}
  \item Line 2: Checks the ImageJ version, since \ilcom{List.setMeasurements} function is only available after version 1.42i.
  \item Line 5, 6: Create new arrays with their length equal to the number of frames of the stack. These arrays will be used to store measurement results.
  \item Line7: for-loop going through each frames in the stack.
  \item Line 10: Measure. All the parameters will be stored in the List.
  \item Line 11, 12: Retrieve the results, mean intensity and its standard deviation.
  \item Line 15, 16: Print out results in the log window.
\end{itemize}

\subsubsection{Acquiring intensity profile from segmented line ROI}

In recent version of ImageJ, selection thickness controls the width of segmented
line ROI when you do \ijmenu{[Analyze > Plot Profile])}. We try to mimick this
behavior in macro, and instead of choosing the line ROI thickness using GUI, the
macro asks the user to input the thickness.

In the code below, there is only one macro. Two functions are added at the
bottom. One is for profile plotting and the last one is for listing
intensity profile data in the result table. Strategy of this macro is to use
straight line selection for each segment, measure that segment and then profiles
are concatenated to the total profile array.

%\lstinputlisting[morekeywords={*, newArray, selectionType, getProfile, setResult, updateResults}]{code/code20_75.ijm}
%\lstinputlisting[morekeywords={*, getSelectionCoordinates, makeLine, Plot,
% create, setLimits, setColor, add, show}]{code/code20_75.ijm}
\lstinputlisting[morekeywords={*, getSelectionCoordinates, makeLine, Plot,
create, setLimits, setColor, add, show, Array, concat,
getStatistics}]{code/code20_76.ijm}

\begin{itemize}
\item Lines 2 - 16: Main part, macro for the segmented line ROI measurement.

\item Line 3: Check if the selection type is a segmented line ROI. If not, macro
terminates leaving a message.

\item Line 4: Reads the x and y coordinates of the segmented line
and store them in two arrays \ilcom{xCA} and \ilcom{yCA}.

\begin{indentCom}
\textbf{getSelectionCoordinates(xCoordinates, yCoordinates)}\\
Returns two arrays containing the X and Y coordinates of the points that define the current selection.
\end{indentCom}

\item Line 5 - 7: Asks the user to input width of the segmented ROI. The ROI
line width is set to that value.

\item Line 8: A new array \ilcom{totalprofile} is created, initialized without
any element. This new array will store the profile data of full ROI.

\item Line 9 - 13: Profile measurement by placing straight line ROI,
for wach segment of the original ROI. \ilcom{makeLine} function is used for this
purpose, and \ilcom{getProfile} returns intensity profile of the corresponding
line ROI. Profile data in \ilcom{thisprofile} array are concatenated to
\ilcom{totalprofile} array using \ilcom{Array.concat}.

\begin{indentCom}
\textbf{makeLine(x1, y1, x2, y2)}\\
Creates a new straight line selection. The origin (0,0) is assumed to be the upper left corner of the image. Coordinates are in pixels. With ImageJ 1.35b and letter, you can create segmented line selections by specifying more than two coordinate, for example makeLine(25,34,44,19,69,30,71,56).
\end{indentCom}

\item Line 14: Call graph plotting function (Line 20 - 27), passing
\ilcom{totalprofile} array as an argument.

\item Line 15: call function to printout the profile array in the results window
(Lines 32 - 39).

\item Line 20 - 27: Function for plotting the intensity profile.
\item Line 21 : Use \ilcom{Array.getStatistics} function to know the minimum and
the maximum value of the array that was given as argument.
\item Line 22: Creates the window and axes of the plot.
\item Line 23: Set the range for x and y axis using the results of line 21
\ilcom{min} and \ilcom{max}. 5\% of offset is added to both values for some
margins below and above.
\item Line 24: Sets the color of the plot.
\item Line 25: Plot the profile.
\item Line 26: Show the plot on the screen (lot is hidden until this show()
function).

\item Line 30 - 37: Function for outputting the profile array in the result
table. This function is exactly the same function you already used in the
previous chapter (code 20.5).

\end{itemize}

\subsubsection{Build-in Macro Functions using Array}

Many built-in macro functions return an array, to have multiple numerical values as a singular object. Below is a list of those array-returning functions.

\begin{indentCom}
\texttt{
\item Dialog.addChoice("Label", items)
\item Dialog.addChoice("Label", items, default)
\item Fit.doFit(equation, xpoints, ypoints)
\item Fit.doFit(equation, xpoints, ypoints, initialGuesses)
\item getFileList(directory)
\item getHistogram(values, counts, nBins[, histMin, histMax])
\item getList("window.titles")
\item getList("java.properties")
\item getLut(reds, greens, blues)
\item getProfile()
\item getRawStatistics(nPixels, mean, min, max, std, histogram)
\item getSelectionCoordinates(xCoordinates, yCoordinates)
\item getStatistics(area, mean, min, max, std, histogram)
\item makeSelection(type, xcoord, ycoord)
\item newArray(size)
\item newMenu(macroName, stringArray)
\item Plot.create("Title", "X-axis Label", "Y-axis Label", xValues, yValues)
\item Plot.add("circles", xValues, yValues)
\item Plot.getValues(xpoints, ypoints)
\item setLut(reds, greens, blues)
\item split(string, delimiters)
}
\end{indentCom}


\chapter{Survival Trees}

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

\section{The Log-Rank Test}

The \textbf{log-rank test} (Mantel 1966; Peto and Peto 1972) is a test for statistical equivalence of two survival curves. It is obtained by constructing a $2x2$ contingency table at the time of each event and comparing the failure rates between the two groups, conditional on the number at risk in each group\footnote{See https://bookdown.org/sestelo/sa\_financial/comparing-survival-curves.html.}. In this way, the test compares the entire survival experience between groups. The null hypothesis is that the true underlying curves for the two groups are identical.

``In the absence of censoring, these methods reduce to the Wilcoxon-Mann-Whitney rank-sum test (Mann and Whitney 1947) for two samples and to the Kruskal-Wallis test (Kruskal and Wallis 1952) for more than two groups of survival times.''

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

\section{Survival Example: Primary Biliary Cirrhosis}

Now let's consider how the same tree-building machinery

This data is from the Mayo Clinic trial in primary biliary cirrhosis (PBC) of the liver conducted between 1974 and 1984. A total of 424 PBC patients, referred to Mayo Clinic during that ten-year interval, met eligibility criteria for the randomized placebo controlled trial of the drug D-penicillamine. The first 312 cases in the data set participated in the randomized trial and contain largely complete data. The additional 112 cases did not participate in the clinical trial, but consented to have basic measurements recorded and to be followed for survival. Six of those cases were lost to follow-up shortly after diagnosis, so the data here are on an additional 106 cases as well as the 312 randomized participants.

\begin{question}{}
Here's a dataset of survival data... how would you build a survival forest?
\end{question}

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

\section{Random Survival Forests}

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

\section{Boosted Survival Trees}