\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}

\title{Chapter 6\\Eigenvalue Problems}
\author{solutions by Hikari}
\date{August 2021}

\begin{document}

\newcommand{\br}[2]{\langle#1|#2\rangle}
\newcommand{\brr}[2]{\left\langle#1|#2\right\rangle}
\newcommand{\pdv}[2]{\frac{\partial#1}{\partial#2}}
\newcommand{\M}{\mathrm}
\newcommand{\V}{\mathbf}
\newcommand{\VE}{\mathbf{\hat{e}}}
\newcommand{\ket}[1]{|#1\rangle}
\newcommand{\bra}[1]{\langle#1|}

\maketitle

\section*{6.2 Matrix Eigenvalue Problems}

\newcommand{\n}{\lambda}
\paragraph{6.2.1}
\[
\begin{vmatrix}
1-\n&0&1\\
0&1-\n&0\\
1&0&1-\n
\end{vmatrix}=
(1-\n)(2-\n)(-\n)=0
\]
\begin{alignat*}{4}
    & \n_1=0,\qquad && x_1+x_3=0,\qquad && x_2=0,\qquad && \V{c}_1=\frac{1}{\sqrt{2}}(1,0,-1)\\
    & \n_2=1,\qquad && x_3=0,\qquad && x_1=0,\qquad && \V{c}_2=(0,1,0)\\
    & \n_3=2,\qquad && -x_1+x_3=0,\qquad && -x_2=0,\qquad && \V{c}_3=\frac{1}{\sqrt{2}}(1,0,1)\\
\end{alignat*}

\paragraph{6.2.2}
\[
\begin{vmatrix}
1-\n&\sqrt{2}&0\\
\sqrt{2}&-\n&0\\
0&0&-\n
\end{vmatrix}=
-\n(\n-2)(\n+1)=0
\]
\begin{alignat*}{4}
    & \n_1=-1,\qquad && 2x_1+\sqrt{2}x_2=0,\qquad && x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{3}}(1,-\sqrt{2},0)\\
    & \n_2=0,\qquad && x_1+\sqrt{2}x_2=0,\qquad && \sqrt{2}x_1=0,\qquad && \V{c}_2=(0,0,1)\\
    & \n_3=2,\qquad && -x_1+\sqrt{2}x_2=0,\qquad && -2x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{3}}(\sqrt{2},1,0)\\
\end{alignat*}

\paragraph{6.2.3}
\[
\begin{vmatrix}
1-\n&1&0\\
1&-\n&1\\
0&1&1-\n
\end{vmatrix}=
(1-\n)(\n-2)(\n+1)=0
\]
\begin{alignat*}{4}
    & \n_1=-1,\qquad && 2x_1+x_2=0,\qquad && x_1+x_2+x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{6}}(1,-2,1)\\
    & \n_2=1,\qquad && x_2=0,\qquad && x_1-x_2+x_3=0,\qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,0,-1)\\
    & \n_3=2,\qquad && -x_1+x_2=0,\qquad && x_1-2 x_2+x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{3}}(1,1,1)\\
\end{alignat*}

\paragraph{6.2.4}
\[
\begin{vmatrix}
 1-\n&\sqrt{8} &0 \\
 \sqrt{8}& 1-\n&\sqrt{8} \\
0 &\sqrt{8} & 1-\n
\end{vmatrix}=
(1-\n)(5-\n)(-3-\n)=0
\]
\begin{alignat*}{4}
    & \n_1=-3 ,\qquad && 4x_1+\sqrt{8}x_2=0,\qquad && \sqrt{8}x_2+4x_3=0,\qquad && \V{c}_1=\frac{1}{2}(1,-\sqrt{2},1)\\
    & \n_2=1 ,\qquad && \sqrt{8}x_2=0,\qquad && \sqrt{8}x_1+\sqrt{8}x_3=0,\qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,0,-1)\\
    & \n_3=5 ,\qquad && -4x_1+\sqrt{8}x_2=0,\qquad && \sqrt{8}x_2-4x_3=0,\qquad && \V{c}_3=\frac{1}{2}(1,\sqrt{2},1)\\
\end{alignat*}

\paragraph{6.2.5}
\[
\begin{vmatrix}
 1-\n& 0& 0\\
 0& 1-\n&1 \\
 0& 1& 1-\n
\end{vmatrix}=
(1-\n)(2-\n)(-\n)=0
\]
\begin{alignat*}{4}
    & \n_1=0 ,\qquad && x_1=0,\qquad && x_2+x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{2}}(0,1,-1)\\
    & \n_2=1 ,\qquad && x_3=0,\qquad && x_2=0,\qquad && \V{c}_2=(1,0,0)\\
    & \n_3=2 ,\qquad && -x_1=0,\qquad && -x_2+x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{2}}(0,1,1)\\
\end{alignat*}

\paragraph{6.2.6}
\[
\begin{vmatrix}
 1-\n& 0& 0\\
 0& 1-\n& \sqrt{2}\\
 0&\sqrt{2} & -\n
\end{vmatrix}=
(1-\n)(\n-2)(\n+1)=0
\]
\begin{alignat*}{4}
    & \n_1=-1 ,\qquad && 2x_1=0,\qquad && 2x_2+\sqrt{2}x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{3}}(0,-1,\sqrt{2})\\
    & \n_2=1 ,\qquad && \sqrt{2}x_3=0,\qquad && \sqrt{2}x_2-x_3=0,\qquad && \V{c}_2=(1,0,0)\\
    & \n_3=2 ,\qquad && -x_1=0,\qquad && -x_2+\sqrt{2}x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{3}}(0,\sqrt{2},1)\\
\end{alignat*}

\paragraph{6.2.7}
\[
\begin{vmatrix}
 -\n&1 &0 \\
 1& -\n&1 \\
 0& 1& -\n
\end{vmatrix}=
(-\n)(\n+\sqrt{2})(\n-\sqrt{2})=0
\]
\begin{alignat*}{4}
    & \n_1=-\sqrt{2} ,\qquad && \sqrt{2}x_1+x_2=0,\qquad && x_2+\sqrt{2}x_3=0,\qquad && \V{c}_1=\frac{1}{2}(1,-\sqrt{2},1)\\
    & \n_2=0 ,\qquad && x_2=0,\qquad && x_1+x_3=0,\qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,0,-1)\\
    & \n_3=\sqrt{2} ,\qquad && -\sqrt{2}x_1+x_2=0,\qquad && x_2-\sqrt{2}x_3=0,\qquad && \V{c}_3=\frac{1}{2}(1,\sqrt{2},1)\\
\end{alignat*}

\paragraph{6.2.8}
\[
\begin{vmatrix}
 2-\n&0 &0 \\
 0& 1-\n&1 \\
 0&1 & 1-\n
\end{vmatrix}=
(2-\n)(2-\n)(-\n)=0
\]
\begin{alignat*}{5}
    & \n_1=0 ,\qquad && 2x_1=0,\qquad && x_2+x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{2}}(0,1,-1)\\
    & \n_{2,3}=2 ,\qquad && -x_2+x_3=0,\qquad && \qquad && \V{c}_2=(1,0,0)\qquad&&\textit{(not unique)}\\
    &\qquad && \qquad && \qquad && \V{c}_3=\frac{1}{\sqrt{2}}(0,1,1)\qquad&&\textit{(not unique)}\\
\end{alignat*}

\paragraph{6.2.9}
\[
\begin{vmatrix}
 -\n&1&1 \\
1 & -\n& 1\\
1 & 1& -\n
\end{vmatrix}=
-(\n+1)(\n-2)(\n+1)=0
\]
\begin{alignat*}{5}
    & \n_{1,2}=-1 ,\qquad && x_1+x_2+x_3=0,\qquad && \qquad && \V{c}_1=\frac{1}{\sqrt{2}}(1,-1,0)\quad &&\textit{(not unique)}\\
    & \qquad && \qquad && \qquad && \V{c}_2=\frac{1}{\sqrt{6}}(1,1,-2)\qquad &&\textit{(not unique)}\\
    & \n_3=2 ,\qquad && -2x_1+x_2+x_3=0,\qquad && x_1+x_2-2x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{3}}(1,1,1) \\
\end{alignat*}

\paragraph{6.2.10}
\[
\begin{vmatrix}
 1-\n&-1 &-1 \\
 -1& 1-\n& -1\\
 -1&-1 & 1-\n
\end{vmatrix}=
-(\n-2)(\n-2)(\n+1)=0
\]
\begin{alignat*}{5}
    & \n_1=-1 ,\qquad && 2x_1-x_2-x_3=0,\qquad && -x_1-x_2+2x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{3}}(1,1,1)\\
    & \n_{2,3}=2 ,\qquad && -x_1-x_2-x_3=0,\qquad && \qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,-1,0)  \quad &&\textit{(not unique)}\\
    &  \qquad && \qquad && \qquad && \V{c}_3=  \frac{1}{\sqrt{6}}(1,1,-2)\quad &&\textit{(not unique)}\\
\end{alignat*}

\paragraph{6.2.11}
\[
\begin{vmatrix}
 1-\n&1 &1 \\
 1& 1-\n&1 \\
 1& 1& 1-\n
\end{vmatrix}=
-\n^2(\n-3)=0
\]
\begin{alignat*}{5}
    & \n_{1,2}=0 ,\qquad && x_1+x_2+x_3=0,\qquad && \qquad && \V{c}_1=\frac{1}{\sqrt{2}}(1,-1,0)  \quad &&\textit{(not unique)}\\
    &  \qquad && \qquad && \qquad && \V{c}_2=\frac{1}{\sqrt{6}}(1,1,-2)  \quad &&\textit{(not unique)}\\
    & \n_3=3 ,\qquad && -2x_1+x_2+x_3=0,\qquad && x_1+x_2-2x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{3}}(1,1,1)\\
\end{alignat*}

\paragraph{6.2.12}
\[
\begin{vmatrix}
 5-\n&0 &2 \\
 0& 1-\n&0 \\
 2& 0& 2-\n
\end{vmatrix}=
-(\n-1)(\n-6)(\n-1)=0
\]
\begin{alignat*}{5}
    & \n_{1,2}=1 ,\qquad && 2x_1+x_3=0,\qquad && \qquad && \V{c}_1=(0,1,0)  \quad &&\textit{(not unique)}\\
    & \qquad && \qquad && \qquad && \V{c}_2=\frac{1}{\sqrt{5}}(1,0,-2)  \quad &&\textit{(not unique)}\\
    & \n_3=6 ,\qquad && -x_1+2x_3=0,\qquad && -5x_2=0,\qquad && \V{c}_3=\frac{1}{\sqrt{5}}(2,0,1)  \\
\end{alignat*}

\paragraph{6.2.13}
\[
\begin{vmatrix}
 1-\n& 1&0 \\
 1& 1-\n&0 \\
 0& 0& -\n
\end{vmatrix}=
-\n^2(\n-2)=0
\]
\begin{alignat*}{5}
    & \n_{1,2}=0 ,\qquad && x_1+x_2=0,\qquad && \qquad && \V{c}_1=(0,0,1)  \quad &&\textit{(not unique)}\\
    & \qquad && \qquad && \qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,-1,0)  \quad &&\textit{(not unique)}\\
    & \n_3=2 ,\qquad && -x_1+x_2=0,\qquad && -2x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{2}}(1,1,0)  \\
\end{alignat*}

\paragraph{6.2.14}
\[
\begin{vmatrix}
 5-\n&0 &\sqrt{3} \\
 0& 3-\n&0 \\
 \sqrt{3}&0 & 3-\n
\end{vmatrix}=
-(\n-3)(\n-6)(\n-2)=0
\]
\begin{alignat*}{4}
    & \n_1=2 ,\qquad && \sqrt{3}x_1+x_3=0,\qquad && x_2=0,\qquad && \V{c}_1=\frac{1}{2}(1,0,-\sqrt{3})\\
    & \n_2=3 ,\qquad && 2x_1+\sqrt{3}x_3=0,\qquad && \sqrt{3}x_1=0,\qquad && \V{c}_2=(0,1,0)\\
    & \n_3=6 ,\qquad && -x_1+\sqrt{3}x_3=0,\qquad && -3x_2=0,\qquad && \V{c}_3=\frac{1}{2}(\sqrt{3},0,1)\\
\end{alignat*}

\paragraph{6.2.15}
\renewcommand{\arraystretch}{1.5}
For every real coefficient homogeneous quadratic function (equation) in three variables \[a_{11}x^2+a_{22}y^2+a_{33}z^2+a_{12}xy+a_{13}xz+a_{23}yz=1\]
it can be verified that it is equivalent to the matrix equation
\[
\begin{pmatrix}
x,y,z
\end{pmatrix}
\begin{pmatrix}
a_{11}&\frac{a_{12}}{2}&\frac{a_{13}}{2}\\
\frac{a_{12}}{2}&a_{22}&\frac{a_{23}}{2}\\
\frac{a_{13}}{2}&\frac{a_{23}}{2}&a_{33}
\end{pmatrix}
\begin{pmatrix}
x\\y\\z
\end{pmatrix}=1
\]
Note that the middle matrix is Hermitian, so it can be diagonalized by a unitary transformation, which will transform the equation to
\[
\begin{pmatrix}
x',y',z'
\end{pmatrix}
\begin{pmatrix}
\n_1&0&0\\
0&\n_2&0\\
0&0&\n_3
\end{pmatrix}
\begin{pmatrix}
x'\\y'\\z'
\end{pmatrix}=1
\]
or $\n_1(x')^2+\n_2(y')^2+\n_3(z')^2=1$, which can be an ellipsoid, hyperboloid, elliptic cylinder, hyperbolic cylinder, or two parallel planes, depends on the sign of $\n_1,\n_2,\n_3$.

\renewcommand{\arraystretch}{1}
$x^2+2xy+2y^2+2yz+z^2=1$ is equivalent to
\[
\begin{pmatrix}
x,y,z
\end{pmatrix}
\begin{pmatrix}
1&1&0\\
1&2&1\\
0&1&1
\end{pmatrix}
\begin{pmatrix}
x\\y\\z
\end{pmatrix}=1
\]
Find the eigenvectors to diagonalize it:
\[
\begin{vmatrix}
1-\n&1&0\\
1&2-\n&1\\
0&1&1-\n
\end{vmatrix}=0
\]
\begin{alignat*}{4}
    & \n_1=0 ,\qquad && x_1+x_2=0,\qquad && x_2+x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{3}}(1,-1,1)\\
    & \n_2=1 ,\qquad && x_2=0,\qquad && x_1+x_2+x_3=0,\qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,0,-1)\\
    & \n_3=3 ,\qquad && -2x_1+x_2=0,\qquad && x_2-2x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{6}}(1,2,1)\\
\end{alignat*}
Transform into the $\V{c}_1,\V{c}_2,\V{c}_3$ basis, the equation becomes
\[
\begin{pmatrix}
x',y',z'
\end{pmatrix}
\begin{pmatrix}
0&0&0\\
0&1&0\\
0&0&3
\end{pmatrix}
\begin{pmatrix}
x'\\y'\\z'
\end{pmatrix}=1
\]
or
\[
(y')^2+3(z')^2=1
\]
which is an elliptic cylinder.
The axis of cylinder is in the $x'$ direction, which is the $\V{c}_1$ direction, $(1,-1,1)$.
The major axis of ellipse is in the $y'$ direction,  which is the $\V{c}_2$ direction, $(1,0,-1)$, with the length of semi-major axis being $1$.
The minor axis of ellipse is in the $z'$ direction,  which is the $\V{c}_3$ direction, $(1,2,1)$, with the length of semi-minor axis being $\frac{1}{\sqrt{3}}$.

\section*{6.4 Hermitian Matrix Diagonalization}

\paragraph{6.4.1}
\[
\M{A}\V{x}=\n\V{x}
\]
\[
\M{G}\M{A}\M{G}^{-1}\M{G}\V{x}=\n\M{G}\V{x}
\]
\[
\M{A}'\V{x}'=\n\V{x}'
\]
the same is for the transformation from $\M{A}'$ to $\M{A}$. So if $\n$ is an eigenvalue of $\M{A}$, it is an eigenvalue of $\M{A}'$, and vice versa. So $\M{A}'$ and $\M{A}$ have the same eigenvalues (though the eigenvectors may be different.)

The invariance of trace and determinant under similarity transformation can be shown by the invariance of eigenvalues along with the fact that sum of eigenvalues equals trace (compare the coefficient of $\n^{n-1}$ in $\det(\M{A}-\n \M{I})=(-1)^n(\n^n-(\mathrm{tr} \M{A})\n^{n-1}+\cdots)=(-1)^n(\n-\n_1)\cdots(\n-\n_n)$\;) and product of eigenvalues equals determinant (let $\n=0$ in $\det(\M{A}-\n \M{I})=(\n_1-\n)\cdots(\n_n-\n)$). However, they can be proved more simply by
\newcommand{\tr}{\mathrm{tr}}
\[
\tr(\M{G}\M{A}\M{G}^{-1})=\tr(\M{A}\M{G}^{-1}\M{G})=\tr(\M{A})
\]
\[
\det(\M{G}\M{A}\M{G}^{-1})=\det(\M{G})\det(\M{A})\det(\M{G}^{-1})=\det(\M{A})
\]

\paragraph{6.4.2}
(The theorem is correct only when the eigenvectors form a complete set, which means the number of independent eigenvectors is equal to the dimension of the matrix.)

If matrix $\M{A}$ has real eigenvalues and orthonormal eigenvectors, then by transforming into the basis of the eigenvectors , it will be diagonalized, with the diagonal components being the real eigenvalues:
\[
\M{A}=\M{U}\M{A'}\M{U}^{-1}
\]
($\M{U}$ is unitary, $\M{A'}$ is diagonal and real, and therefore Hermitian)
\[
\M{A}^\dagger=(\M{U}\M{A'}\M{U}^{-1})^\dagger=(U^{-1})^\dagger(A')^\dagger(U)^\dagger=\M{U}\M{A'}\M{U}^{-1}=\M{A}
\]
so $\M{A}$ is Hermitian.

\paragraph{6.4.3}
(A non-symmetric real matrix cannot be diagonalized by an orthogonal transformation, but may be diagonalized by an unitary transformation)

If $\M{A}$ is real and non-symmetric, but can be diagonalized by an orthogonal transformation, then
\[
\M{A}=\M{S}\M{A'}\M{S}^{-1}
\]
$\M{S}$ is orthogonal, and $\M{A'}$ is diagonal. Then
\[
\M{A}^T=(\M{S}^{-1})^T(\M{A'})^T\M{S}^T=\M{S}\M{A'}\M{S}^{-1}=\M{A}
\]
so $A$ is symmetric, contradict.

To show a non-symmetric real matrix may be diagonalized by an unitary transformation, we give a counterexample:
\[
\M{A}=
\begin{pmatrix}
1&1\\
-1&1
\end{pmatrix}\qquad \M{U}=\frac{1}{\sqrt{2}}
\begin{pmatrix}
1&-i\\
1&i
\end{pmatrix}
\]
it can be checked that $\M{U}$ is unitary:
\[
\M{U}\M{U}^\dagger=
\frac{1}{\sqrt{2}}\frac{1}{\sqrt{2}}
\begin{pmatrix}
1&-i\\1&i
\end{pmatrix}
\begin{pmatrix}
1&1\\
i&-i
\end{pmatrix}=
\begin{pmatrix}
1&0\\0&1
\end{pmatrix}=\M{I}
\]
and
\[
\M{U}\M{A}\M{U}^{-1}=
\frac{1}{\sqrt{2}}\frac{1}{\sqrt{2}}
\begin{pmatrix}
1&-i\\1&i
\end{pmatrix}
\begin{pmatrix}
1&1\\
-1&1
\end{pmatrix}
\begin{pmatrix}
1&1\\
i&-i
\end{pmatrix}=
\begin{pmatrix}
1+i&0\\
0&1-i
\end{pmatrix}
\]
so an non-symmetric real matrix may be diagonalized by an unitary transformation.

\paragraph{6.4.4}
$L_x,L_y,L_z$ are Hermitain, so
\[
(\V{L}^2)^\dagger=(L_x^2)^\dagger+(L_y^2)^\dagger+(L_z^2)^\dagger=L_x^2+L_y^2+L_z^2=\V{L}^2
\]
so $\V{L}^2$ is Hermitian, and therefore its eigenvalues are real.
\medskip

Let $\V{x}$ be an eigenvector of $\V{L}^2$, so $\V{L}^2\V{x}=\n\V{x}$. Then
\[
\br{\V{x}|\V{L}^2}{\V{x}}=\br{\V{x}|L_x^2}{\V{x}}+\br{\V{x}|L_y^2}{\V{x}}+\br{\V{x}|L_z^2}{\V{x}}=\br{L_x\V{x}}{L_x\V{x}}+\br{L_y\V{x}}{L_y\V{x}}+\br{L_z\V{x}}{L_z\V{x}}\geq0
\]
but also
\[
\br{\V{x}|\V{L}^2}{\V{x}}=\n\br{\V{x}}{\V{x}}
\]
so $\n\br{\V{x}}{\V{x}}\geq0$, and therefore $\n\geq0$.

\paragraph{6.4.5}
\[
\M{A}\V{x_i}=\n_i\V{x_i}
\]
\[
\V{x_i}=\M{A}^{-1}\M{A}\V{x_i}=\n_i\V{A}^{-1}\V{x_i}
\]
so
\[
\M{A}^{-1}\V{x_i}=\frac{1}{\n_i}\V{x_i}
\]

\paragraph{6.4.6}
(a) By making $\n=0$ in $\det(\M{A}-\n\M{I})=(\n_1-\n)\cdots(\n_n-\n)$, we know that $\det(\M{A})$ equals to the product of its eigenvalues. So $\det(\M{A})=0$ means that at least one of its eigenvalue is zero, then let $\V{x}$ be the eigenvector corresponding to the eigenvalue, we have
\[
\M{A}\V{x}=0\V{x}=0
\]
(
It is a circular reasoning because the existence of eigenvector corresponding to an eigenvalue depends on the fact that $\V{x}$ exists when
\[
(\M{A}-\n\M{I})\V{x}=0
\]
and $\det(\M{A}-\n\M{I})=0$, while this is exactly what we want to prove in this problem. However, a formal proof probably requires knowledge of linear algebra such as rank, Gaussian elimination, etc, which are beyond the scope of the book and probably not intended by the author.
)

(b) If $\M{A}|\V{v}\rangle=0$, then $|\V{v}\rangle$ is an eigenvector of $\M{A}$ with zero eigenvalue. So
\[
\det(\M{A})=\n_1\n_2\cdots\n_n=0
\]
and therefore $\M{A}$ is singular.

\paragraph{6.4.7}
\renewcommand{\arraystretch}{1.0}
Transform $\M{A}$ and $\M{B}$ into their orthonormal eigenvector basis (which is unitary because $\M{A}$ and $\M{B}$ are Hermitian), we have
\[
\M{U}_1\M{A}\M{U}_1^{-1}=
\begin{pmatrix}
\n_1&&\\
 &\ddots& \\
  & &\n_n
\end{pmatrix}=
\M{U}_2\M{B}\M{U}_2^{-1}
\]
so
\[
\M{A}=\M{U}_1^{-1}\M{U}_2\M{B}\M{U}_2^{-1}\M{U}_1
=(\M{U}_1^{-1}\M{U}_2)\M{B}(\M{U}_1^{-1}\M{U}_2)^{-1}=\M{U}\M{B}\M{U}^{-1}
\]

\paragraph{6.4.8}
\renewcommand{\arraystretch}{1.5}
\[
\M{M}_x:\quad
\begin{vmatrix}
 -\n&\frac{1}{\sqrt{2}} &0 \\
 \frac{1}{\sqrt{2}} & -\n&\frac{1}{\sqrt{2}} \\
 0 &\frac{1}{\sqrt{2}} &-\n
\end{vmatrix}=
-\n(\n-1)(\n+1)=0
\]
\begin{alignat*}{4}
    & \n_1=-1 ,\qquad && x_1+\frac{1}{\sqrt{2}}x_2=0,\qquad && \frac{1}{\sqrt{2}}x_2+x_3=0,\qquad && \V{c}_1=\frac{1}{2}(1,-\sqrt{2},1) \\
    & \n_2=0 ,\qquad && x_2=0,\qquad && \frac{1}{\sqrt{2}}x_1+\frac{1}{\sqrt{2}}x_3=0,\qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,0,-1)\\
    & \n_3=1 ,\qquad && -x_1+\frac{1}{\sqrt{2}}x_2=0,\qquad && \frac{1}{\sqrt{2}}x_2-x_3=0,\qquad && \V{c}_3=\frac{1}{2}(1,\sqrt{2},1) \\
\end{alignat*}
\[
\M{M}_y:\quad
\begin{vmatrix}
 -\n&\frac{-i}{\sqrt{2}} &0 \\
 \frac{i}{\sqrt{2}} & -\n&\frac{-i}{\sqrt{2}} \\
 0 &\frac{i}{\sqrt{2}} &-\n
\end{vmatrix}=
-\n(\n-1)(\n+1)=0
\]
\begin{alignat*}{4}
    & \n_1=-1 ,\qquad && x_1-\frac{i}{\sqrt{2}}x_2=0,\qquad && \frac{i}{\sqrt{2}}x_2+x_3=0,\qquad && \V{c}_1=\frac{1}{2}(1,-\sqrt{2}i,-1) \\
    & \n_2=0 ,\qquad && \frac{-i}{\sqrt{2}}x_2=0,\qquad && \frac{i}{\sqrt{2}}x_1-\frac{i}{\sqrt{2}}x_3=0,\qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,0,1)\\
    & \n_3=1 ,\qquad && -x_1-\frac{i}{\sqrt{2}}x_2=0,\qquad && \frac{i}{\sqrt{2}}x_2-x_3=0,\qquad && \V{c}_3=\frac{1}{2}(1,\sqrt{2}i,-1) \\
\end{alignat*}
\[
\M{M}_z:\quad
\begin{vmatrix}
 1-\n&0 &0 \\
 0 & -\n&0 \\
 0 &0 &-1-\n
\end{vmatrix}=
\n(1-\n)(1+\n)=0
\]
\begin{alignat*}{4}
    & \n_1=-1 ,\qquad && 2x_1=0,\qquad && x_2=0,\qquad && \V{c}_1=(0,0,1) \\
    & \n_2=0 ,\qquad && x_1=0,\qquad && -x_3=0,\qquad && \V{c}_2=(0,1,0)\\
    & \n_3=1 ,\qquad && -x_2=0,\qquad && -2x_3=0,\qquad && \V{c}_3=(1,0,0) \\
\end{alignat*}

\paragraph{6.4.9}
(a)
\[
a'_{ij}=\br{\varphi'_i|\M{A}}{\varphi'_j}=\br{\varphi_i\cos\theta-\varphi_j\sin\theta|\M{A}}{\varphi_i\sin\theta+\varphi_j\cos\theta}
\]
\[
=\br{\varphi_i|\M{A}}{\varphi_i}\sin\theta\cos\theta+\br{\varphi_i|\M{A}}{\varphi_j}\cos^2\theta-\br{\varphi_j|\M{A}}{\varphi_i}\sin^2\theta-\br{\varphi_j|\M{A}}{\varphi_j}\sin\theta\cos\theta
\]
\[
=a_{ii}\sin\theta\cos\theta+a_{ij}\cos^2\theta-a_{ji}\sin^2\theta-a_{jj}\sin\theta\cos\theta
\]
\[
=a_{ij}\cos2\theta-(a_{jj}-a_{ii})\frac{1}{2}\sin2\theta=0
\]
when $\frac{2a_{ij}}{a_{jj}-a_{ii}}=\frac{\sin2\theta}{\cos2\theta}=\tan2\theta$
\medskip

(b)
\[
a'_{\mu\nu}=\br{\varphi'_\mu|\M{A}}{\varphi'_\nu}=\br{\varphi_\mu|\M{A}}{\varphi_\nu}=a_{\mu\nu}
\]

(c)
\[
a'_{ii}=\br{\varphi'_i|\M{A}}{\varphi'_i}=\br{\varphi_i\cos\theta-\varphi_j\sin\theta|\M{A}}{\varphi_i\cos\theta-\varphi_j\sin\theta}
\]
\[
=\br{\varphi_i|\M{A}}{\varphi_i}\cos^2\theta-\br{\varphi_i|\M{A}}{\varphi_j}\sin\theta\cos\theta-\br{\varphi_j|\M{A}}{\varphi_i}\sin\theta\cos\theta+\br{\varphi_j|\M{A}}{\varphi_j}\sin^2\theta
\]
\[
=a_{ii}\cos^2\theta+a_{jj}\sin^2\theta-2a_{ij}\sin\theta\cos\theta
\]
\[
a'_{jj}=\br{\varphi'_j|\M{A}}{\varphi'_j}=\br{\varphi_i\sin\theta+\varphi_j\cos\theta|\M{A}}{\varphi_i\sin\theta+\varphi_j\cos\theta}
\]
\[
=\br{\varphi_i|\M{A}}{\varphi_i}\sin^2\theta+\br{\varphi_i|\M{A}}{\varphi_j}\sin\theta\cos\theta+\br{\varphi_j|\M{A}}{\varphi_i}\sin\theta\cos\theta+\br{\varphi_j|\M{A}}{\varphi_j}\cos^2\theta
\]
\[
=a_{ii}\sin^2\theta+a_{jj}\cos^2\theta+2a_{ij}\sin\theta\cos\theta
\]
\[
\tr(\M{A'})-\tr(\M{A})=a'_{ii}+a'_{jj}-a_{ii}-a_{jj}=0
\]

(d)
\[
a'_{i\mu}=\br{\varphi'_i|\M{A}}{\varphi'_\mu}=\br{\varphi_i\cos\theta-\varphi_j\sin\theta|\M{A}}{\varphi_\mu}=a_{i\mu}\cos\theta-a_{j\mu}\sin\theta
\]
\[
a'_{j\mu}=\br{\varphi'_j|\M{A}}{\varphi'_\mu}=\br{\varphi_i\sin\theta+\varphi_j\cos\theta|\M{A}}{\varphi_\mu}=a_{i\mu}\sin\theta+a_{j\mu}\cos\theta
\]
Note that $a_{i\mu}'^2+a_{j\mu}'^2-a_{i\mu}^2-a_{j\mu}^2=0$. Let $S$ be the sum of the squares
of the off-diagonal elements of $\M{A}$, and let $\mu,\nu\neq i,j$, \,$\mu\neq\nu$, then
\[
S'-S=\sum_\mu\sum_\nu(a_{\mu\nu}'^2-a_{\mu\nu}^2)+\sum_\mu(a_{i\mu}'^2+a_{j\mu}'^2-a_{i\mu}^2-a_{j\mu}^2)-\sum_\mu(a_{\mu i}'^2+a_{\mu j}'^2-a_{\mu i}^2-a_{\mu j}^2)\,+(a_{ij}'^2+a_{ji}'^2-a_{ij}^2-a_{ji}^2)
\]\[
=-2a_{ij}^2\]
because the first three summations are zero.

\section*{6.5 Normal Matrices}

\paragraph{6.5.1}
\[
\begin{vmatrix}
 2-\n&4 \\
 1 & 2-\n
\end{vmatrix}=
\n(\n-4)=0
\]
\begin{alignat*}{3}
    & \n_1=0 ,\qquad && x_1+2x_2=0,\qquad && \V{c}_1=\frac{1}{\sqrt{5}}(2,-1) \\
    & \n_2=4 ,\qquad && x_1-2x_2=0,\qquad && \V{c}_2=\frac{1}{\sqrt{5}}(2,1)\\
\end{alignat*}

\paragraph{6.5.2}
\renewcommand{\arraystretch}{1.0}
Let
\[
\M{A}=\begin{pmatrix}
a&b\\c&d
\end{pmatrix}
\]
then its eigenvalue $\n$ satisfies
\[
\begin{vmatrix}
a-\n&b\\c&d-\n
\end{vmatrix}=\n^2-\n(a+d)+(ad-bc)=\n^2-\n\,\mathrm{trace}(\M{A})+\det(\M{A})=0
\]

\paragraph{6.5.3}
\[
\M{U}\V{c}=\n\V{c}
\]
\[
\V{c}^\dagger\M{U}^\dagger=\n^*\V{c}^\dagger
\]
\[
(\n^*\V{c}^\dagger)(\n\V{c})=|\n|^2\V{c}^\dagger\V{c}=\V{c}^\dagger\M{U}^\dagger\M{U}\V{c}=\V{c}^\dagger\V{c}
\]
so
\[|\n|^2=1\]

\paragraph{6.5.4}
(The results hold only when the orthogonal matrix is a rotation, not a reflection, which means the determinant is $1$, not $-1$.)

(a)
Transform the matrix to the coordinate system where the axis of rotation coincides with the new $x$-axis, then it becomes
\[
\begin{pmatrix}
1&0&0\\
0&\cos\varphi&\sin\varphi\\
0&-\sin\varphi&\cos\varphi
\end{pmatrix}
\]
By exercise 6.4.1, the trace (sum of eigenvalues) of a matrix is invariant under a similarity transformation, so the sum of the three eigenvalues of the original matrix equals the trace of the new matrix, which is
\[
1+2\cos\varphi
\]

(b) By exercise 6.4.1, the determinant (product of eigenvalues) of a matrix is invariant under a similarity transformation, so the product of the three eigenvalues of the original matrix equals the determinant of the new matrix, which is $\cos^2\varphi+\sin^2\varphi=1$. Let the other two eigenvalues be $a$ and $b$, then
\[
a+b=2\cos\varphi,\qquad ab=1
\]
so
\[
a+\frac{1}{a}=2\cos\varphi
\]
solving for $a$, we have
\[
a=\frac{2\cos\varphi\pm\sqrt{4\cos^\varphi-4}}{2}=\cos\varphi\pm i\sin\varphi=e^{i\varphi}, e^{-i\varphi}
\]
So one of $a,b$ must be $e^{i\varphi}$, and the other must be $e^{-i\varphi}$.

\paragraph{6.5.5}
Expand $\V{y}$ in the orthonormal basis of $\V{x}_i$, we have
\[
\br{\V{y}|\M{A}}{\V{y}}=\sum_i\sum_j\br{\V{y}}{\V{x}_j}\br{\V{x}_i|\M{A}}{\V{x}_j}\br{\V{x}_j}{\V{y}}
\]
\[
=\sum_i\sum_j\br{\V{y}}{\V{x}_j}\delta_{ij}\n_i\br{\V{x}_j}{\V{y}}
\]
\[
=\sum_i|y_i|^2\n_i
\]
Note that $\br{\V{y}}{\V{y}}=\sum_i|y_i|^2=1$, and $|y_i|^2\geq0$, so
\[
\n_1=(\sum_i|y_i|^2)\n_1\leq\sum_i|y_i|^2\n_i\leq(\sum_i|y_i|^2)\n_n=\n_n
\]
so
\[
\n_1\leq\br{\V{y}|\M{A}}{\V{y}}\leq\n_n
\]

\paragraph{6.5.6}
The eigenvalues of a Hermitian matrix is real, and the eigenvalues of a unitary matrix have unit magnitude (from exercise 6.5.3), so the eigenvalues can only be $\pm1$.

\paragraph{6.5.7}
To prove the statement, we only need the anti-commuting condition and the fact that the metrics are non-singular (because they are unitary). If $\gamma_i\gamma_j=-\gamma_j\gamma_i$, then
\[
\det(\gamma_i)\det(\gamma_j)=(-1)^n\det(\gamma_j)\det(\gamma_i)
\]
Because $\det(\gamma_i),\det(\gamma_i)\neq0$, so $(-1)^n=1$, which means $n$ is even.
\medskip

To show that $2\times2$ matrices are inadequate to form a set of four anticommuting, Hermitian,
unitary matrices, let the matrix satisfying the conditions be
\[
\begin{pmatrix}
a&b\\c&d
\end{pmatrix}
\]
It is Hermitian, so $c=b^*$, and $a,d$ are real:
\[
\begin{pmatrix}
a&b\\b^*&d
\end{pmatrix}
\]
It is unitary, so
\[
\begin{pmatrix}
a&b\\b^*&d
\end{pmatrix}
\begin{pmatrix}
a&b\\b^*&d
\end{pmatrix}=\begin{pmatrix}
a^2+|b|^2&b(a+d)\\
b^*(a+d)&d^2+|b|^2
\end{pmatrix}=
\begin{pmatrix}
1&0\\0&1
\end{pmatrix}
\]
so $b=0$ or $a+d=0$.

If $a+d=0$, then $a^2+|b|^2=1$, which means we can find $0\leq\theta\leq\frac{\pi}{2}$ such that $a^2=\cos^2\theta$, $|b|^2=\sin^2\theta$. So the matrix has the form
\[\pm
\begin{pmatrix}
\cos\theta&\sin\theta e^{i\varphi}\\
\sin\theta e^{-i\varphi}& -\cos\theta
\end{pmatrix}
\]

If $b=0$, then $a,d=\pm1$. If $a,d$ have same sign, then the matrix is $\pm\M{I}$, and it will contradict with the anti-commuting property because $\M{A}\M{I}+\M{I}\M{A}=0$ implies $\M{A}=0$. Therefore, it must be $a=1,d=-1$ or $a=-1,d=1$, which is of the form of above equation by making $\theta=0$.

Now using the anti-commuting property,
\[
\begin{pmatrix}
\cos\theta_1&\sin\theta_1 e^{i\varphi_1}\\
\sin\theta_1 e^{-i\varphi_1}& -\cos\theta_1
\end{pmatrix}
\begin{pmatrix}
\cos\theta_2&\sin\theta_2 e^{i\varphi_2}\\
\sin\theta_2 e^{-i\varphi_2}& -\cos\theta_2
\end{pmatrix}+
\begin{pmatrix}
\cos\theta_2&\sin\theta_2 e^{i\varphi_2}\\
\sin\theta_2 e^{-i\varphi_2}& -\cos\theta_2
\end{pmatrix}
\begin{pmatrix}
\cos\theta_1&\sin\theta_1 e^{i\varphi_1}\\
\sin\theta_1 e^{-i\varphi_1}& -\cos\theta_1
\end{pmatrix}\]
\[
=\begin{pmatrix}
2\cos\theta_1\cos\theta_2+2\sin\theta_1\sin\theta_2\cos(\varphi_1-\varphi_2)& 0\\
0& 2\cos\theta_1\cos\theta_2+2\sin\theta_1\sin\theta_2\cos(\varphi_1-\varphi_2)
\end{pmatrix}
\]
so
\[
2\cos\theta_1\cos\theta_2+2\sin\theta_1\sin\theta_2\cos(\varphi_1-\varphi_2)=0
\]
Because both the terms are non-negative ($0\leq\theta\leq\frac{\pi}{2}$), we must have \[\cos\theta_1\cos\theta_2=0\] and \[\sin\theta_1\sin\theta_2\cos(\varphi_1-\varphi_2)=0\]
From $\cos\theta_1\cos\theta_2=0$ we know at most one of the matrix can have non-zero $\cos\theta$, which means except this matrix, all the other matrices have $\theta=\frac{\pi}{2}$.

From $\sin\theta_1\sin\theta_2\cos(\varphi_1-\varphi_2)=0$, we know when $\theta_1,\theta_2=\frac{\pi}{2}$, we must have $\varphi_1-\varphi_2=\pm\frac{\pi}{2}$, which means there are at most two matrices with $\theta=\frac{\pi}{2}$.

In conclusion, we can have at most two matrices with $\theta=\frac{\pi}{2}$ and one matrix with $\theta\neq\frac{\pi}{2}$, so it is inadequate for $2\times2$ matrices to form four anticommuting, Hermitian,
unitary matrices.
\medskip

(The three Pauli matrices are:
\begin{alignat*}{3}
    & \theta=0 ,\qquad&& && \sigma_1=\begin{pmatrix}0&1\\1&0\end{pmatrix}\\
    & \theta=\frac{\pi}{2},\qquad&& \varphi=-\frac{\pi}{2},\qquad&&\sigma_2=\begin{pmatrix}0&-i\\i&0\end{pmatrix}\\
    & \theta=\frac{\pi}{2},\qquad && \varphi=0 ,\qquad&& \sigma_3=
\begin{pmatrix}
1&0\\0&-1
\end{pmatrix}\\
\end{alignat*}
which are anticommuting, Hermitian and
unitary.
)

\paragraph{6.5.8}
\[
|\V{y}\rangle=\sum_n|\V{x}_n\rangle\br{\V{x}_n}{\V{y}}
\]
so
\[
\M{A}|\V{y}\rangle=\sum_n\M{A}|\V{x}_n\rangle\br{\V{x}_n}{\V{y}}=\sum_n\n_n|\V{x}_n\rangle\br{\V{x}_n}{\V{y}}=\left(\sum_n\n_n|\V{x_n}\rangle\langle\V{x}_n|\right)|\V{y}\rangle
\]
\[
\M{A}=\sum_n\n_n|\V{x_n}\rangle\langle\V{x}_n|
\]

\paragraph{6.5.9}
\[
\begin{pmatrix}
1&0\\0&1
\end{pmatrix}
\M{A}
\begin{pmatrix}
1&0\\0&1
\end{pmatrix}=
\begin{pmatrix}
1&0\\0&-1
\end{pmatrix}
\]
so
\[
\M{A}=\begin{pmatrix}
1&0\\0&-1
\end{pmatrix}
\]

\paragraph{6.5.10}
\[
\M{A}\ket{\V{u}_j}=\n_j\ket{\V{u}_j}
\]
\[
\M{A}^\dagger\ket{\V{v}_i}=\n_i\ket{\V{v}_i}
\]
so
\[
\br{\V{v}_i|\M{A}}{\V{u}_j}=\n_j\br{\V{v}_i}{\V{u}_j}=\n_i^*\br{\V{v}_i}{\V{u}_j}
\]
if $\n_j\neq\n_i^*$, we must have $\br{\V{v}_i}{\V{u}_j}=0$.

\paragraph{6.5.11}
(a)
\[
(\tilde{\M{A}}\M{A})\ket{\V{f}_n}=\n_n\tilde{\M{A}}\ket{\V{g}_n}=\n_n^2\ket{\V{f}_n}
\]

(b)
\[
(\M{A}\tilde{\M{A}})\ket{\V{g}_n}=\n_n\M{A}\ket{\V{f}_n}=\n_n^2\ket{\V{g}_n}
\]

(c)
\[
(\tilde{\M{A}}\M{A})^\dagger=\M{A}^\dagger(\tilde{\M{A}})^\dagger=\tilde{\M{A}}\M{A}
\]
\[
(\M{A}\tilde{\M{A}})^\dagger=(\tilde{\M{A}})^\dagger\M{A}^\dagger=\M{A}\tilde{\M{A}}
\]
so $(\tilde{\M{A}}\M{A})$ and $(\M{A}\tilde{\M{A}})$ are Hermitian, which means their eigenvectors $\ket{\V{f}_n}$ and $\ket{\V{g}_n}$ form an orthogonal set, and their eigenvalue $\n_n^2$ is real.

\paragraph{6.5.12}
\[
\ket{\V{y}}=\sum_n\ket{\V{f}_n}\br{\V{f}_n}{\V{y}}
\]
\[
\M{A}\ket{\V{y}}=\sum_n\M{A}\ket{\V{f}_n}\br{\V{f}_n}{\V{y}}=\sum_n\n_n\ket{\V{g}_n}\br{\V{f}_n}{\V{y}}=\left(\sum_n\n_n\ket{\V{g}_n}\bra{\V{f}_n} \right)\ket{\V{y}}
\]
so
\[
\M{A}=\sum_n\n_n\ket{\V{g}_n}\bra{\V{f}_n}
\]

\paragraph{6.5.13}
(a)
\[
\tilde{\M{A}}=\frac{1}{\sqrt{5}}
\begin{pmatrix}
2&1\\2&-4
\end{pmatrix}\qquad
\tilde{\M{A}}\M{A}=
\begin{pmatrix}
1&0\\0&4
\end{pmatrix}\qquad
\M{A}\tilde{\M{A}}=\frac{1}{5}
\begin{pmatrix}
8&-6\\-6&17
\end{pmatrix}
\]

(b)
\renewcommand{\arraystretch}{1.5}
\[
\begin{vmatrix}
 \frac{8}{5}-\n_n^2&\frac{-6}{5} \\
 \frac{-6}{5} & \frac{17}{5}-\n_n^2
\end{vmatrix}=
(\n_n^2-1)(\n_n^2-4)=0
\]
\begin{alignat*}{3}
    & \n_1^2=1 ,\qquad && x_1-2x_2=0,\qquad && \V{g}_1=\frac{1}{\sqrt{5}}(2,1) \\
    & \n_2^2=4 ,\qquad && 2x_1+x_2=0,\qquad && \V{g}_2=\frac{1}{\sqrt{5}}(1,-2)\\
\end{alignat*}

(c)
\[
\begin{vmatrix}
 1-\n_n^2&0 \\
0& 4-\n_n^2
\end{vmatrix}=
(\n_n^2-1)(\n_n^2-4)=0
\]
\begin{alignat*}{3}
    & \n_1^2=1 ,\qquad && 3x_2=0,\qquad && \V{f}_1=(1,0) \\
    & \n_2^2=4 ,\qquad && -3x_1=0,\qquad && \V{f}_2=(0,1)\\
\end{alignat*}

(d)
$\n_1^2=1$ ($\n_1=1$) :
\[
\frac{1}{\sqrt{5}}
\begin{pmatrix}
2&2\\1&-4
\end{pmatrix}
\begin{pmatrix}
1\\0
\end{pmatrix}=1\cdot\frac{1}{\sqrt{5}}
\begin{pmatrix}
2\\1
\end{pmatrix}
\]
\[
\frac{1}{\sqrt{5}}
\begin{pmatrix}
2&1\\2&-4
\end{pmatrix}\frac{1}{\sqrt{5}}
\begin{pmatrix}
2\\1
\end{pmatrix}=1\cdot\begin{pmatrix}
1\\0
\end{pmatrix}
\]

$\n_2^2=4$ ($\n_2=2$) :
\[
\frac{1}{\sqrt{5}}
\begin{pmatrix}
2&2\\1&-4
\end{pmatrix}
\begin{pmatrix}
0\\1
\end{pmatrix}=2\cdot\frac{1}{\sqrt{5}}
\begin{pmatrix}
1\\-2
\end{pmatrix}
\]
\[
\frac{1}{\sqrt{5}}
\begin{pmatrix}
2&1\\2&-4
\end{pmatrix}\frac{1}{\sqrt{5}}
\begin{pmatrix}
1\\-2
\end{pmatrix}=2\cdot\begin{pmatrix}
0\\1
\end{pmatrix}
\]

(e)
\[
\sum_n\n_n\ket{\V{g}_n}\bra{\V{f}_n}=1\cdot
\begin{pmatrix}
\frac{2}{\sqrt{5}}\\\frac{1}{\sqrt{5}}
\end{pmatrix}
\begin{pmatrix}
1&0
\end{pmatrix}+2\cdot
\begin{pmatrix}
\frac{1}{\sqrt{5}}\\\frac{-2}{\sqrt{5}}
\end{pmatrix}
\begin{pmatrix}
0&1
\end{pmatrix}=
\frac{1}{\sqrt{5}}
\begin{pmatrix}
2&2\\1&-4
\end{pmatrix}=\M{A}
\]

\paragraph{6.5.14}
(a)
\[
\M{A}=\sum_n\n_n\ket{\V{g}_n}\bra{\V{f}_n}=1\cdot
\begin{pmatrix}
\frac{1}{\sqrt{2}}\\\frac{1}{\sqrt{2}}
\end{pmatrix}
\begin{pmatrix}
1&0
\end{pmatrix}-1\cdot
\begin{pmatrix}
\frac{1}{\sqrt{2}}\\\frac{-1}{\sqrt{2}}
\end{pmatrix}
\begin{pmatrix}
0&1
\end{pmatrix}=
\begin{pmatrix}
\frac{1}{\sqrt{2}}&\frac{-1}{\sqrt{2}}\\
\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}
\end{pmatrix}=
\frac{1}{\sqrt{2}}
\begin{pmatrix}
1&-1\\1&1
\end{pmatrix}
\]

(b)
\[
\frac{1}{\sqrt{2}}\begin{pmatrix}
1&-1\\1&1
\end{pmatrix}
\begin{pmatrix}
1\\0
\end{pmatrix}=1\cdot\frac{1}{\sqrt{2}}
\begin{pmatrix}
1\\1
\end{pmatrix}
\]
\[
\frac{1}{\sqrt{2}}\begin{pmatrix}
1&-1\\1&1
\end{pmatrix}
\begin{pmatrix}
0\\1
\end{pmatrix}=-1\cdot\frac{1}{\sqrt{2}}
\begin{pmatrix}
1\\-1
\end{pmatrix}
\]

(c)
\[
\frac{1}{\sqrt{2}}\begin{pmatrix}
1&1\\-1&1
\end{pmatrix}\frac{1}{\sqrt{2}}
\begin{pmatrix}
1\\1
\end{pmatrix}=1\cdot
\begin{pmatrix}
1\\0
\end{pmatrix}
\]
\[
\frac{1}{\sqrt{2}}\begin{pmatrix}
1&1\\-1&1
\end{pmatrix}\frac{1}{\sqrt{2}}
\begin{pmatrix}
1\\-1
\end{pmatrix}=-1\cdot
\begin{pmatrix}
0\\1
\end{pmatrix}
\]

\paragraph{6.5.15}
(a)
\[
\M{U}^\dagger=e^{-ia\M{H}^\dagger}=e^{-ia\M{H}}=\M{U}^{-1}
\]
so $\M{U}$ is unitary.

(b)
\[
\M{U}^\dagger\M{U}=e^{-ia\M{H}^\dagger}e^{ia\M{H}}=e^{ia(\M{H-\M{H}^\dagger})}=\M{I}=e^{i2n\pi\M{I}}
\]
so $a(\M{H}-\M{H}^\dagger)=2n\pi\M{I}$. Because $\M{H}-\M{H}^\dagger$ is independent of $a$, so it must be $n=0$, and therefore $\M{H}-\M{H}^\dagger=0$, $\M{H}=\M{H}^\dagger$, which means $\M{H}$ is Hermitian.

(c) It can be verified that $u_j=e^{iah_j}$, with $u_j$ and $h_j$ being eigenvalues of $\M{U}$ and $\M{H}$. Transform into the eigenvector basis, and note that determinant and trace of a matrix is invariant under unitary transformation, we have
\[
\det\M{U}=\prod_j u_j=\prod_j e^{iah_j}=e^{ia\sum_j h_j}=e^{ia\,\mathrm{trace}\M{H}}
\]
so when $\mathrm{trace}\,\M{H}=0$, $\det\M{U}=1$.
\medskip

(d) When $\det\M{U}=1=e^{i2n\pi}$, $a\,\mathrm{trace}\,\M{H}=2n\pi$, and because $\M{H}$ is independent of $a$, it must be $n=
0$, so $\mathrm{trace}\,\M{H}=0$.

\paragraph{6.5.16}
$\M{B}$ is defined as \[\M{B}=\sum_{j=0}^\infty\frac{1}{j!}\M{A}^j\]
If $\V{x}_i$ is an eigenvector of $\M{A}$, so $\M{A}\V{x}_i=A_i\V{x}_i$, then
\[
\M{B}\V{x}_i=\sum_{j=o}^\infty\frac{1}{j!}\M{A}^j
\V{x}_i=\sum_{j=0}^\infty\frac{1}{j!}(A_i)^j\V{x}_i=e^{A_i}\V{x}_i\]
which means $\V{x}_i$ is also an eigenvector of $\M{B}$ with eigenvalue being $e^{A_i}$.

\paragraph{6.5.17}
Let $\V{x}$ be an eigenvector of $\M{P}$ so $\M{P}\V{x}=\rho_\lambda\V{x}$. Then
\[
\M{P}^2\V{x}=\M{P}(\M{P}\V{x})=\M{P}(\rho_\lambda\V{x})=(\rho_\lambda)^2\V{x}
\]
But also
\[
\M{P}^2\V{x}=\M{P}\V{x}=\rho_\lambda\V{x}
\]
so $(\rho_\lambda)^2=\rho_\lambda$, which means $\rho_\lambda=0,1$.

\paragraph{6.5.18}
$\br{\V{x}_i|\M{A}}{\V{x}_j}=\lambda_j\br{\V{x}_i}{\V{x}_j}=\lambda_j\delta_{ij}$. So
\[
\br{\V{x}|\M{A}}{\V{x}}=\left( \bra{\V{x}_1}+\sum_{i=2}^n\delta_i\bra{\V{x}_i} \right)\M{A}\left( \ket{\V{x}_1}+\sum_{j=2}^n\delta_j\ket{\V{x}_i} \right)
\]
\[
=\br{\V{x}_1|\M{A}}{\V{x}_1}+\sum_{j=2}^n\delta_j\br{\V{x}_1|\M{A}}{\V{x}_j}+\sum_{i=2}^n\delta_i^*\br{\V{x}_i|\M{A}}{\V{x}_1}+\sum_{i=2}^n\sum_{j=2}^n\delta_i^*\delta_j\br{\V{x}_i|\M{A}}{\V{x}_j}
\]
\[
=\lambda_1\br{\V{x}_1}{\V{x}_1}+\sum_{i=2}^n|\delta_i|^2\lambda_i\br{\V{x}_i}{\V{x}_i}
\]
and
\[
\br{\V{x}}{\V{x}}=\left( \bra{\V{x}_1}+\sum_{i=2}^n\delta_i\bra{\V{x}_i} \right)\left( \ket{\V{x}_1}+\sum_{j=2}^n\delta_j\ket{\V{x}_i} \right)
\]
\[
=\br{\V{x}_1}{\V{x}_1}+\sum_{j=2}^n\delta_j\br{\V{x}_1}{\V{x}_j}+\sum_{i=2}^n\delta_i^*\br{\V{x}_i}{\V{x}_1}+\sum_{i=2}^n\sum_{j=2}^n\delta_i^*\delta_j\br{\V{x}_i}{\V{x}_j}
\]
\[
=\br{\V{x}_1}{\V{x}_1}+\sum_{i=2}^n|\delta_i|^2\br{\V{x}_i}{\V{x}_i}
\]
so
\[
\frac{\br{\V{x}|\M{A}}{\V{x}}}{\br{\V{x}}{\V{x}}}=\frac{\lambda_1\br{\V{x}_1}{\V{x}_1}+\sum_{i=2}^n|\delta_i|^2\lambda_i\br{\V{x}_i}{\V{x}_i}}{\br{\V{x}_1}{\V{x}_1}+\sum_{i=2}^n|\delta_i|^2\br{\V{x}_i}{\V{x}_i}}\leq
\frac{\lambda_1\br{\V{x}_1}{\V{x}_1}+\sum_{i=2}^n|\delta_i|^2\lambda_1\br{\V{x}_i}{\V{x}_i}}{\br{\V{x}_1}{\V{x}_1}+\sum_{i=2}^n|\delta_i|^2\br{\V{x}_i}{\V{x}_i}}=\lambda_1
\]
and the error in $\lambda_1$ is
\[
\lambda_1-\frac{\br{\V{x}|\M{A}}{\V{x}}}{\br{\V{x}}{\V{x}}}=\frac{\sum_{i=2}^n|\delta_i|^2(\lambda_1-\lambda_i)\br{\V{x}_i}{\V{x}_i}}{\br{\V{x}_1}{\V{x}_1}+\sum_{i=2}^n|\delta_i|^2\br{\V{x}_i}{\V{x}_i}}\simeq
\frac{\sum_{i=2 }^n|\delta_i|^2(\lambda_1-\lambda_i)\br{\V{x}_i}{\V{x}_i}}{\br{\V{x}_1}{\V{x}_1}}
\]
so the error is of the order of $|\delta_i|^2$.

\paragraph{6.5.19}
(a)
\begin{align*}
    m\ddot{x_1}&=-kx_1+k(x_2-x_1)=-2kx_1+kx_2\\
    m\ddot{x_2}&=k(x_1-x_2)-kx_2=kx_1-2kx_2
\end{align*}

(b)
To find the normal mode, let $x_1(t)=x_1\sin\omega t$,\; $x_2(t)=x_2\sin\omega t$. Substitute and cancel
out $\sin\omega t$, we have
\[
\begin{pmatrix}
\frac{2k}{m}&\frac{-k}{m}\\
\frac{-k}{m}&\frac{2k}{m}
\end{pmatrix}
\begin{pmatrix}
x_1\\x_2
\end{pmatrix}=\omega^2
\begin{pmatrix}
x_1\\x_2
\end{pmatrix}
\]
so the secular equation is
\[
\begin{vmatrix}
\frac{2k}{m}-\omega^2&\frac{-k}{m}\\
\frac{-k}{m}&\frac{2k}{m}-\omega^2
\end{vmatrix}=
(\omega^2-\frac{k}{m})(\omega^2-\frac{3k}{m})=0
\]
\begin{alignat*}{3}
    & \omega^2=\frac{k}{m} ,\qquad && x_1-x_2=0,\qquad && \V{c}_1=\frac{1}{\sqrt{2}}(1,1) \\
    & \omega^2=\frac{3k}{m} ,\qquad && -x_1-x_2=0,\qquad && \V{c}_2=\frac{1}{\sqrt{2}}(1,-1) \\
\end{alignat*}

(c) For $\omega^2=\frac{k}{m}$, $x_1=x_2$, so the two masses vibrate in phase (move together). For $\omega^2=\frac{3k}{m}$, $x_1=-x_2$, so the two masses vibrate in anti-symmetry movement.

\paragraph{6.5.20}
Follow the proof in Section 6.5 (p.319), we know if $\M{A}\V{x}_j=\lambda_j\V{x}_j$, or $(\M{A}-\lambda_j\M{I})\ket{\V{x}_j}=0$, then we have $(\M{A}^\dagger-\lambda_j^*\M{I})\ket{\V{x}_j}=0$, or $\M{A}^\dagger\V{x}_j=\lambda_j^*\V{x}_j$, so $\ket{\V{x}_j}$ is also an eigenvector of $\M{A}^\dagger$ with eigenvalue $\lambda_j^*$.
\[
\frac{\M{A}+\M{A}^\dagger}{2}\V{x}_j=\frac{\n_j+\n_j^*}{2}\V{x}_j=\mathfrak{Re}(\n_j)\,\V{x}_j
\]
so $\V{x}_j$ is an eigenvector of $\frac{\M{A}+\M{A}^\dagger}{2}$ with $\mathfrak{Re}(\n_j)$ as eigenvalue.
\[
\frac{\M{A}-\M{A}^\dagger}{2i}\V{x}_j=\frac{\n_j-\n_j^*}{2i}\V{x}_j=\mathfrak{Im}(\n_j)\,\V{x}_j
\]
so $\V{x}_j$ is an eigenvector of $\frac{\M{A}-\M{A}^\dagger}{2i}$ with $\mathfrak{Im}(\n_j)$ as eigenvalue.

\paragraph{6.5.21}
(a) Substituting into Eq. 3.37, we have
\[
\M{U}=
\begin{pmatrix}
\frac{1}{2}&\frac{-1}{2}&\frac{1}{\sqrt{2}}\\
\frac{1}{2}&\frac{-1}{2}&\frac{-1}{\sqrt{2}}\\
\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}&0
\end{pmatrix}
\]

(b)
\[
\begin{vmatrix}
\frac{1}{2}-\n&\frac{-1}{2}&\frac{1}{\sqrt{2}}\\
\frac{1}{2}&\frac{-1}{2}-\n&\frac{-1}{\sqrt{2}}\\
\frac{1}{\sqrt{2}}&\frac{1}{\sqrt{2}}&-\n
\end{vmatrix}=-(\n-1)(\n-\frac{-1+\sqrt{3}i}{2})(\n-\frac{-1-\sqrt{3}i}{2})=0
\]
\begin{alignat*}{4}
    & \n_1=1,\qquad && -x_1-x_2+\sqrt{2}x_3=0,\qquad && x_1-3x_2-\sqrt{2}x_3=0,\qquad && \V{c}_1=\frac{1}{\sqrt{3}}(\sqrt{2},0,1)\\
    & \n_2=\frac{-1+\sqrt{3}i}{2},\qquad && (2-\sqrt{3}i)x_1-x_2+\sqrt{2}x_3=0,\qquad && x_1-\sqrt{3}ix_2-\sqrt{2}x_3=0,\qquad && \V{c}_2=\frac{1}{\sqrt{6}}(1,-\sqrt{3}i,-\sqrt{2})\\
    & \n_3=\frac{-1-\sqrt{3}i}{2},\qquad && (2+\sqrt{3}i)x_1-x_2+\sqrt{2}x_3=0,\qquad && x_1+\sqrt{3}ix_2-\sqrt{2}x_3=0,\qquad && \V{c}_3=\frac{1}{\sqrt{6}}(1,\sqrt{3}i,-\sqrt{2})\\
\end{alignat*}
The eigenvector with $\n=1$ is in the direction of rotation axis, which is $\V{c}_1=\frac{1}{\sqrt{3}}(\sqrt{2},0,1)$.
From Exercise 6.5.4, we know the other two eigenvalues of a rotation are $e^{i\varphi}$ and $e^{-i\varphi}$. Compared with $\n_2=e^{i\frac{2\pi}{3}}$, $\n_3=e^{-i\frac{2\pi}{3}}$, we know the rotation angle is $\frac{2\pi}{3}$.

\end{document}

Mathematical Methods for Physicists/Chapter 06/main.tex


\documentclass[english]{../thermomemo/thermomemo}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
%\input{mathdef}
\usepackage[per-mode=symbol]{siunitx}
\usepackage[numbers]{natbib}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}% improves tabular environment.
\usepackage{dcolumn}% also improves tabular environment, with decimal centring.
\usepackage{chemformula}     % For easy typing of chemical formulae
\usepackage{booktabs}
\usepackage{a4wide}
\usepackage{xspace}
\usepackage{todonotes}
\presetkeys{todonotes}{inline}{}
\usepackage{subcaption,caption}
%\pdfminorversion=4
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{snakes}
\usepackage{verbatim}
\usepackage{hyperref}
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  urlcolor=blue,
  citecolor=blue
}
\usepackage{blkarray, bigstrut}

%
% Egendefinerte
%
% Kolonnetyper for array.sty:
\newcolumntype{C}{>{$}c<{$}}% for å slippe å taste inn disse $
\newcolumntype{L}{>{$}l<{$}}% for å slippe å taste inn disse $
%
\newcommand*{\unit}[1]{\ensuremath{\,\mathrm{#1}}}
\newcommand*{\uunit}[1]{\ensuremath{\mathrm{#1}}}
%\newcommand*{\od}[3][]{\frac{\mathrm{d}^{#1}#2}{\mathrm{d}{#3}^{#1}}}% ordinary derivative
\newcommand*{\od}[3][]{\frac{\dif^{#1}#2}{\dif{#3}^{#1}}}% ordinary derivative
\newcommand*{\pd}[3][]{\frac{\partial^{#1}#2}{\partial{#3}^{#1}}}% partial derivative
\newcommand*{\pdc}[3]{\frac{\partial^{2}#1}{\partial{#2}\partial{#3}}}% partial derivative
\newcommand*{\pdt}[3][]{{\partial^{#1}#2}/{\partial{#3}^{#1}}}% partial
                                % derivative for inline use.
\newcommand{\pone}[3]{\frac{\partial #1}{\partial #2}_{#3}}% partial
                                % derivative with information of
                                % constant variables
\newcommand{\ponel}[3]{\frac{\partial #1}{\partial #2}\bigg|_{#3}} % partial derivative with informatio of constant variable. A line is added.
\newcommand{\ptwo}[3]{\frac{\partial^{2} #1}{\partial #2 \partial
    #3}} % partial differential in two different variables
\newcommand{\pdn}[3]{\frac{\partial^{#1}#2}{\partial{#3}^{#1}}}% partial derivative
\newcommand*{\pder}[2]{\left(\frac{\partial #1}{\partial #2}\right)}
\newcommand*{\pdder}[2]{\left(\frac{\partial^2 #1}{\partial #2^2}\right)}
\newcommand*{\pdersub}[3]{\left(\frac{\partial #1}{\partial #2}\right)_{#3}}

% Total derivative:
\newcommand*{\ttd}[2]{\frac{\mathrm{D} #1}{\mathrm{D} #2}}
\newcommand*{\td}[2]{\frac{\mathrm{d} #1}{\mathrm{d} #2}}
\newcommand*{\ddt}{\frac{\partial}{\partial t}}
\newcommand*{\ddx}{\frac{\partial}{\partial x}}
% Vectors etc:
% For Computer Modern:

\DeclareMathAlphabet{\mathsfsl}{OT1}{cmss}{m}{sl}
\renewcommand*{\vec}[1]{\boldsymbol{#1}}%
\newcommand*{\vektor}[1]{\boldsymbol{#1}}%
\newcommand*{\tensor}[1]{\mathsfsl{#1}}% 2. order tensor
\newcommand*{\matr}[1]{\tensor{#1}}% matrix
\renewcommand*{\div}{\boldsymbol{\nabla\cdot}}% divergence
\newcommand*{\grad}{\boldsymbol{\nabla}}% gradient
% fancy differential from Claudio Beccari, TUGboat:
% adjusts spacing automatically
\makeatletter
\newcommand*{\dif}{\@ifnextchar^{\DIfF}{\DIfF^{}}}
\def\DIfF^#1{\mathop{\mathrm{\mathstrut d}}\nolimits^{#1}\gobblesp@ce}
\def\gobblesp@ce{\futurelet\diffarg\opsp@ce}
\def\opsp@ce{%
  \let\DiffSpace\!%
  \ifx\diffarg(%
    \let\DiffSpace\relax
  \else
    \ifx\diffarg[%
      \let\DiffSpace\relax
    \else
      \ifx\diffarg\{%
        \let\DiffSpace\relax
      \fi\fi\fi\DiffSpace}
\makeatother
%
\newcommand*{\me}{\mathrm{e}}% e is not a variable (2.718281828...)
%\newcommand*{\mi}{\mathrm{i}}%  nor i (\sqrt{-1})
\newcommand*{\mpi}{\uppi}% nor pi (3.141592...) (works for for Lucida)
%
% lav tekst-indeks/subscript/pedex
\newcommand*{\ped}[1]{\ensuremath{_{\text{#1}}}}
% høy tekst-indeks/superscript/apex
\newcommand*{\ap}[1]{\ensuremath{^{\text{#1}}}}
\newcommand*{\apr}[1]{\ensuremath{^{\mathrm{#1}}}}
\newcommand*{\pedr}[1]{\ensuremath{_{\mathrm{#1}}}}
%
\newcommand*{\volfrac}{\alpha}% volume fraction
\newcommand*{\surften}{\sigma}% coeff. of surface tension
\newcommand*{\curv}{\kappa}% curvature
\newcommand*{\ls}{\phi}% level-set function
\newcommand*{\ep}{\Phi}% electric potential
\newcommand*{\perm}{\varepsilon}% electric permittivity
\newcommand*{\visc}{\mu}% molecular (dymamic) viscosity
\newcommand*{\kvisc}{\nu}% kinematic viscosity
\newcommand*{\cfl}{C}% CFL number

\newcommand*{\cons}{\vec U}
\newcommand*{\flux}{\vec F}
\newcommand*{\dens}{\rho}
\newcommand*{\svol}{\ensuremath v}
\newcommand*{\temp}{\ensuremath T}
\newcommand*{\vel}{\ensuremath u}
\newcommand*{\mom}{\dens\vel}
\newcommand*{\toten}{\ensuremath E}
\newcommand*{\inten}{\ensuremath e}
\newcommand*{\press}{\ensuremath p}
\renewcommand*{\ss}{\ensuremath a}
\newcommand*{\jac}{\matr A}
%
\newcommand*{\abs}[1]{\lvert#1\rvert}
\newcommand*{\bigabs}[1]{\bigl\lvert#1\bigr\rvert}
\newcommand*{\biggabs}[1]{\biggl\lvert#1\biggr\rvert}
\newcommand*{\norm}[1]{\lVert#1\rVert}
%
\newcommand*{\e}[1]{\times 10^{#1}}
\newcommand*{\ex}[1]{\times 10^{#1}}%shorthand -- for use e.g. in tables
\newcommand*{\exi}[1]{10^{#1}}%shorthand -- for use e.g. in tables
\newcommand*{\nondim}[1]{\ensuremath{\mathit{#1}}}% italic iflg. ISO. (???)
\newcommand*{\rey}{\nondim{Re}}
\newcommand*{\acro}[1]{\textsc{\MakeLowercase{#1}}}%acronyms etc.

\newcommand{\nto}{\ensuremath{\mbox{N}_{\mbox{\scriptsize 2}}}}
\newcommand{\chfire}{\ensuremath{\mbox{CH}_{\mbox{\scriptsize 4}}}}
%\newcommand*{\checked}{\ding{51}}
\newcommand{\coto}{\ensuremath{\text{CO}_{\text{\scriptsize 2}}}}
\newcommand{\celsius}{\ensuremath{^\circ\text{C}}}
\newcommand{\clap}{Clapeyron~}
\newcommand{\subl}{\ensuremath{\text{sub}}}
\newcommand{\spec}{\text{spec}}
\newcommand{\sat}{\text{sat}}
\newcommand{\sol}{\text{sol}}
\newcommand{\liq}{\text{liq}}
\newcommand{\vap}{\text{vap}}
\newcommand{\amb}{\text{amb}}
\newcommand{\tr}{\text{tr}}
\newcommand{\crit}{\text{crit}}
\newcommand{\entr}{\ensuremath{\text{s}}}
\newcommand{\fus}{\text{fus}}
\newcommand{\flash}[1]{\ensuremath{#1\text{-flash}}}
\newcommand{\spce}[2]{\ensuremath{#1\, #2\text{ space}}}
\newcommand{\spanwagner}{\text{Span--Wagner}}
\newcommand{\triplepoint}{\text{TP triple point}}
\newcommand{\wrpt}{\text{with respect to~}}
\newcommand{\tpd}{\ensuremath{\text{tpd}}\xspace}
\newcommand{\TPD}{\ensuremath{\text{TPD}}\xspace}
\newcommand{\lp}{\ensuremath{\left(}\xspace}
\newcommand{\rp}{\ensuremath{\right)}\xspace}
\newcommand{\mbn}[0]{\mathbf n}
\newcommand{\mbe}[0]{\mathbf e}
\newcommand{\mbx}[0]{\mathbf x}
\newcommand{\app}{\ensuremath{\text{App}}\xspace}
\newcommand{\nacl}{\ensuremath{\text{\ch{NaCl}}}\xspace}
\newcommand{\na}{\ensuremath{\text{\ch{Na+}}}\xspace}
\newcommand{\cl}{\ensuremath{\text{\ch{Cl-}}}\xspace}
\newcommand{\ideal}{\ensuremath{\text{Id}}\xspace}

\title{Apparent composition approach}
\author{Morten Hammer}

\graphicspath{{gfx/}}

\begin{document}
\frontmatter
\tableofcontents
\section{Introduction}
\citet[Chap. 13, Sec. 7]{Michelsen2007} describe the apparent
composition approach in the context of chemical
reactions. \citet[App. C.3]{Mogensen2014} uses this approach when
modelling phase equilibrium for electrolyte system, using the salts as
apparent composition.

The idea is to use a model with all species ($\vektor{n}$) to model
other species, the apparent species ($\vektor{e}$). The relation
between the apparent and real species are derived from the following,
\begin{equation}
  A\lp T, V, \mbe \rp = A\lp T, V, \mbn \rp,
\label{eq:helmholtz}
\end{equation}
and its differentials. We immediately see that the volume and
temperature differentials are unaffected by the mole number
representation.

Using salt (\ch{NaCl}) to represent ions (\ch{Na+},\ch{Cl-}) as an
example, some additional differentials are required. The apparent mole
vector will then be $\mbe$ (salts) while the actual mole vector will
be $\mbn$ (ions). We then have,

\begin{align}
  F\lp T, V, \mbn \rp &= F\lp T, V, \mbe \rp,\\
  F_i^\app = \pdersub{F}{e_i}{T,V} &=
  \sum_k\pdersub{F}{n_k}{T,V}\pder{n_k}{e_i}
  = \sum_k v_{ik} \pdersub{F}{n_k}{T,V},\\
  F_{ij}^\app &
  = \sum_k v_{ik} \sum_m v_{jm} F_{ij}.
\end{align}
Here $v_{ik}$ is the stoichiometric composition of ion $j$ in salt
$i$. For a system of \ch{NaCl}, \ch{H2O} and \ch{CO2}, $\mathbf{v}$
will look as follows,
\begin{equation}
  \begin{blockarray}{*{4}{c} l}
    \begin{block}{*{4}{>{$\footnotesize}c<{$}} l}
      \ch{H2O} & \ch{CO2} & \ch{Na+} & \ch{Cl-} & \\
    \end{block}
    \begin{block}{[*{4}{c}]>{$\footnotesize}l<{$}}
      1 & 0 & 0 & 0  \bigstrut[t] & \ch{H2O} \\
      0 & 1 & 0 & 0 & \ch{CO2} \\
      0 & 0 & 1 & 1 & \ch{NaCl} \\
    \end{block}
  \end{blockarray}
\end{equation}

With this approach, no special handling of the charge balance in the
phases are required when calculating phase equilibrium. Another
advantage is equilibrium calculation of solid \ch{NaCl}, as the
solid fugacity only need to equate the fugacity of the fictitious
dissolved salt component.

\section{Thermodynamic differentials}

If we consider the chemical potentials (enthalpy, entropy, Gibbs free
energy, Helmholtz free energy or internal energy) as a function of the
real or apparent composition, the value remains the same. IE. it is
only the compositional differentials of the potentials that differ
when introducing the apparent composition.

We therefore need to map only the fugacities, compressibillity factor
and their differentials.

\subsection{Compressibillity factor}
For the compressibillity factor, the following applies,
\begin{equation}
  \frac{PV}{RT} = \sum_j e_j Z^\app = \sum_i n_i Z.
  \label{eq:compressibillity_factor_relation}
\end{equation}
We therefore have
\begin{equation}
  Z^\app = Z \frac{\sum_i n_i}{\sum_j e_j }.
  \label{eq:compressibillity_factor}
\end{equation}
The pressure and temperature differential must be scaled in the same
manner for the apparent mode, while the compositional differentials
are slightly more complicated.

\subsection{Fugacity coefficients}
\begin{equation}
  \ln \lp x_\nacl^\app \varphi_\nacl^\app \rp  = v_\na \ln \lp x_\na \varphi_\na \rp + v_\cl \ln \lp x_\cl \varphi_\cl \rp
\label{eq:fugacity_coeff}
\end{equation}

Assuming we have one mole of water, and want to look at the infinite
dilution value of $\ln \varphi_\nacl^\app$. The mole number relation between \nacl and the ions \na and \cl are one-to-one, giving,
\begin{gather}
  \ln n_\nacl + \ln \varphi_\nacl^\app - \ln \lp 1 + n_\nacl \rp  = 2 \ln n_\nacl + \ln \lp\varphi_\na\varphi_\cl\rp - 2\ln \lp 1 + 2 n_\nacl \rp \nonumber \\
  \ln \varphi_\nacl^\app = \ln n_\nacl + \ln \lp\varphi_\na\varphi_\cl\rp - 2\ln \lp 1 + 2 n_\nacl \rp + \ln \lp 1 + n_\nacl \rp \nonumber \\
  \lim_{n_\nacl \rightarrow 0}\ln \varphi_\nacl^\app = \lim_{n_\nacl \rightarrow 0} \ln \lp n_\nacl \varphi_\na\varphi_\cl\rp \rightarrow - \infty
\label{eq:fugacity_coeff_inf}
\end{gather}

Since the fugacity depend on the composition, and the infinite
dilution fugacity approaches an infinity value, this approach can be
challenging to handle numerically.

\subsubsection{Differentials}
Additionally there is an effect of the difference in overall mole
numbers, as $\sum_i n_i \neq \sum_i e_i$. See Maribo--Mogensen
\cite[App. C.3]{Mogensen2014}.

The equilibrium condition becomes,
\begin{equation}
  \ln \lp \frac{x^\app \varphi^\app P}{P^0} \rp  = \sum_j v_{ij} \ln \lp \frac{x_j \varphi_j P}{P^0} \rp
\label{eq:fugacity}
\end{equation}

To describe the apparent fugacity coefficient, the relation become,
\begin{equation}
  \ln \varphi^\app_i  = \sum_j v_{ij} \ln x_j \varphi_j - \ln x_i^\app - \lp 1 - \sum_j v_{ij} \rp \ln \frac{P}{P^0}
\label{eq:fugacity_coeff_app}
\end{equation}
Differentiating with respect to temperature,
\begin{equation}
  \pd{\ln \varphi^\app_i}{T}  = \sum_j v_{ij} \ln \pd{\varphi_j}{T}.
\label{eq:fugacity_coeff_app_T}
\end{equation}
Differentiating with respect to pressure,
\begin{equation}
  \pd{\ln \varphi^\app_i}{P}  = \sum_j v_{ij} \ln \pd{\varphi_j}{P} - \frac{1}{P} + \frac{\sum_j v_{ij}}{P}.
\label{eq:fugacity_coeff_app_P}
\end{equation}

Differentiating with respect to mole numbers, using $\sum_i e_i = e_T$,
$n_T = \sum_j \sum_i v_{ij} e_i = n_T$, and

\begin{align}
  x_j  &= \frac{\sum_l v_{jl} e_l}{n_T}\\
  \pd{\ln x_j}{e_k} &= \sum_l \lp\pd{n_l}{e_k}\rp \lp \pd{\ln x_i}{n_l} \rp = \sum_l v_{kl} \lp \pd{\ln n_j}{n_l} -\pd{\ln n_T}{n_l} \rp \nonumber \\
  &= \sum_l v_{kl} \lp \frac{\delta_{jl}}{n_l} - \frac{1}{n_T} \rp = \frac{v_{kj}}{n_j} - \frac{\sum_l v_{kl}}{n_T},
\label{eq:x_ion}
\end{align}

\begin{align}
  \pd{\ln \varphi^\app_i}{e_k}  &= - \frac{\delta_{ik}}{e_k} + \frac{1}{e_T} + \sum_j v_{ij} \pd{\ln \varphi_j}{e_k} + \sum_j v_{ij} \pd{\ln x_j}{e_k} \nonumber \\
  &= - \frac{\delta_{ik}}{e_k} + \frac{1}{e_T} + \sum_j v_{ij} \sum_l v_{kl} \pd{\ln \varphi_j}{n_l} + \sum_j v_{ij} \lp \frac{v_{kj}}{n_j} - \frac{\sum_l v_{kl}}{n_T} \rp
\label{eq:fugacity_coeff_app_n}
\end{align}

\subsection{Ideal properties}
In order to calculate equilibrium between a salt (solid), and the
apparent composition in the fluid phases, the ideal Gibbs free energy
is required.

For the enthalpy we have,
\begin{equation}
  h^\ideal \lp \vektor{e},  T \rp = \sum_j e_j h_j^\ideal \lp T \rp,
\label{eq:id_enthalpy}
\end{equation}
and for the entropy,
\begin{equation}
  s^\ideal \lp \vektor{e},  T, P \rp = \sum_j e_j \lp s_j^{\ideal,*} \lp T \rp  - R \ln \frac{e_j}{e_T} - R \ln P \rp.
\label{eq:id_entropy}
\end{equation}
Here $s_j^{\ideal,*} \lp T \rp$ simply is the temperature integral of $Cp(T)/T$.

The ideal Gibbs free energy is,
\begin{equation}
  g^\ideal \lp \vektor{e},  T, P \rp = h^\ideal \lp \vektor{e},  T \rp - T s^\ideal \lp \vektor{e},  T, P \rp.
\label{eq:id_gibbs}
\end{equation}

The ideal chemical potential therefore becomes,
\begin{align}
  \mu_i &= \pd{g^\ideal}{e_i} = h^\ideal_i - T \lp s_i^{\ideal,*}  - R \ln \frac{e_i}{e_T} - R \ln P \rp, \\
  &= h^\ideal_i - T s_i^{\ideal,*}  + RT \ln \lp x_i P \rp.
\label{eq:id_chempot}
\end{align}

Since the $\ln \lp x_i P \rp$ is accounted for in the fugacity
coefficient, we only need to account for $h^\ideal_i - T
s_i^{\ideal,*}$.

\clearpage
\bibliographystyle{plainnat}
\bibliography{../thermopack}

\end{document}


\section{Refinement Reflection}
\label{sec:formalism}
\label{sec:types-reflection}

Our first step towards formalizing refinement
reflection is a core calculus \corelan with an
\emph{undecidable} type system based on
denotational semantics.
We show how the soundness of the type system
allows us to \emph{prove theorems} using \corelan.

%
%% Note that \smtlan programs are a subset of
%% \corelan programs derivations
%%
%% a subset of \corelan where the that forms a
%% decidable logic of
%% refinements, and use it to obtain \corelan with
%% decidable SMT-based algorithmic typing.

\subsection{Syntax}
\input{text/refinementreflection/syntax}
%
Figure~\ref{fig:syntax} summarizes the syntax of \corelan,
which is essentially the calculus \undeclang~\cite{Vazou14}
with explicit recursion and a special $\erefname$ binding form
to denote terms that are reflected into the refinement logic.
%
In \corelan refinements $r$ are arbitrary expressions $e$
(hence $r ::= e$ in Figure~\ref{fig:syntax}).
%
This choice allows us to prove preservation and progress,
but renders typechecking undecidable.
%
In \S~\ref{sec:algorithmic} we will see how to recover
decidability by soundly approximating refinements.

The syntactic elements of \corelan are layered into
primitive constants, values, expressions, binders
and programs.

\mypara{Constants}
The primitive constants of \corelan
include all the primitive logical
operators $\op$, here, the set $\{ =, <\}$.
%
Moreover, they include the
primitive booleans $\etrue$, $\efalse$,
integers $\mathtt{-1}, \mathtt{0}$, $\mathtt{1}$, \etc,
and logical operators $\mathtt{\land}$, $\mathtt{\lor}$, $\mathtt{\lnot}$, \etc.

\mypara{Data Constructors}
%
We encode data constructors as special constants.
% Each data type has an equality predicate $\haseq{T}$
% that is true only if values of type $T$ can be finitely compared.
For example the data type \tintlist, which represents
finite lists of integers, has two data constructors: $\dnull$ (``nil'')
and $\dcons$ (``cons'').
% and satisfies $\haseq{\tintlist}$.

%% NV Arity is not used anywhere
%%Each data type has an arity $\arity{T}$ that represents
%%the exact number of data constructors that return
%%a value of type $T$.
%
%%For example the data type \tintlist, which represents
%%lists of integers, has two data constructors: $\dnull$ (``nil'')
%%and $\dcons$ (``cons'') and so has arity $2$.

\mypara{Values \& Expressions}
%
The values of \corelan include
constants, $\lambda$-abstractions
$\efun{x}{\typ}{e}$, and fully
applied data constructors $D$
that wrap values.
%
The expressions of \corelan
include values and variables $x$,
applications $\eapp{e}{e}$, and
$\mathtt{case}$ expressions.

\mypara{Binders \& Programs}
%
A \emph{binder} $\bd$ is a series of possibly recursive
let definitions, followed by an expression.
%
A \emph{program} \prog is a series of $\erefname$
definitions, each of which names a function
that can be reflected into the refinement
logic, followed by a binder.
%
The stratification of programs via binders
is required so that arbitrary recursive definitions
are allowed but cannot be inserted into the logic
via refinements or reflection.
%
(We \emph{can} allow non-recursive $\mathtt{let}$
binders in $e$, but omit them for simplicity.)

\subsection{Operational Semantics}

Figure~\ref{fig:syntax} summarizes the small
step contextual $\beta$-reduction semantics for
\corelan.
%
%%There are two points to note.
%%%
%%First, we allow for reductions under
%%data constructors, and thus, values may
%%be further reduced.
%%%
%%Second, for simplicity, we treat both
%%$\eletname$ and $\erefname$ as possibly
%%recursive (\ie $\mathtt{let\ rec}$) binders.
%% Note that, for simplicity, we treat each
%% $\eletname$ as a possibly
%% recursive (\ie $\mathtt{let\ rec}$) binder.
%
We write \evalj{e}{e'}{j} if there exist
$e_1,\ldots,e_j$ such that $e$ is $e_1$,
$e'$ is $e_j$ and $\forall i,j, 1 \leq i < j$,
we have $\evals{e_i}{e_{i+1}}$.
%
We write $\evalsto{e}{e'}$ if there exists
some finite $j$ such that $\evalj{e}{e'}{j}$.
%
We define $\betaeq{}{}$ to be the reflexive,
symmetric, transitive closure of $\evals{}{}$.

\mypara{Constants} Application of a constant requires the
argument be reduced to a value; in a single step the
expression is reduced to the output of the primitive
constant operation.
%
For example, consider $=$, the primitive equality
operator on integers.
%
We have $\ceval{=}{n} \defeq =_n$
where $\ceval{=_n}{m}$ equals \etrue
iff $m$ is the same as $n$.
%
%\mypara{Equality}
%
We assume that the equality operator
is defined \emph{for all} values,
and, for functions, is defined as
extensional equality.
%
That is, for all
$f$ and
$f'$
we have
$\evals{(f = f')}{\etrue}
  \quad \mbox{iff} \quad
  \forall v.\ \betaeq{f\ v}{f'\ v}$.
%
We assume source \emph{terms} only contain implementable equalities
over non-function types; the above only appears in \emph{refinements}
and allows us to state and prove facts about extensional
equality~\S~\ref{subsec:extensionality}.
%% % \RJ{CHECK}

%%That is, for all
%%$f \defeq \efun{x}{\typ}{e}$ and
%%$f' \defeq \efun{x}{\typ}{e'}$
%%we have
%%$$\evals{(f = f')}{\etrue}
%%  \quad \mbox{iff} \quad
%%  \forall v.\ \evalsto{(\SUBST{e}{x}{v} = \SUBST{e'}{x}{v})}{\etrue}
%%$$

\subsection{Types}

\corelan types include basic types, which are \emph{refined} with predicates,
and dependent function types.
%
\emph{Basic types} \btyp comprise integers, booleans, and a family of data-types
$T$ (representing lists, trees \etc.)
%
For example the data type \tintlist represents lists of integers.
%
We refine basic types with predicates (boolean valued expressions \refa) to obtain
\emph{basic refinement types} $\tref{v}{\btyp}{\refa}$.
%
Finally, we have dependent \emph{function types} $\tfun{x}{\typ_x}{\typ}$
where the input $x$ has the type $\typ_x$ and the output $\typ$ may
refer to the input binder $x$.
%
We write $\btyp$ to abbreviate $\tref{v}{\btyp}{\etrue}$,
and \tfunbasic{\typ_x}{\typ} to abbreviate \tfun{x}{\typ_x}{\typ} if
$x$ does not appear in $\typ$.
%
We use $r$ to refer to refinements.

\mypara{Denotations}
%
Each type $\typ$ \emph{denotes} a set of expressions $\interp{\typ}$,
that are defined via the dynamic semantics~\cite{Knowles10}.
%
Let $\shape{\typ}$ be the type we get if we erase all refinements
from $\typ$ and $\bhastype{}{e}{\shape{\typ}}$ be the
standard typing relation for the typed lambda calculus.
%
Then, we define the denotation of types as:
\begin{align*}
\interp{\tref{x}{\btyp}{r}} \defeq &
    \{e \mid  \bhastype{}{e}{\btyp},
              \mbox{ if } \evalsto{e}{w}
              \mbox{ then } \evalsto{r\subst{x}{w}}{\etrue} \}\\
\interp{\tfun{x}{\typ_x}{\typ}} \defeq &
    \{e \mid  \bhastype{}{e}{\shape{\tfunbasic{\typ_x}{\typ}}},
              \forall e_x \in \interp{\typ_x}.\ \eapp{e}{e_x} \in \interp{\typ\subst{x}{e_x}}
    \}
\end{align*}

\mypara{Constants}
For each constant $c$ we define its type \constty{c}
such that $c \in \interp{\constty{c}}$.
%
For example,
%
$$
\begin{array}{lcl}
\constty{3} &\doteq& \tref{v}{\tint}{v = 3}\\
\constty{+} &\doteq& \tfun{\ttx}{\tint}{\tfun{\tty}{\tint}{\tref{v}{\tint}{v = x + y}}}\\
\constty{\leq} &\doteq& \tfun{\ttx}{\tint}{\tfun{\tty}{\tint}{\tref{v}{\tbool}{v \Leftrightarrow x \leq y}}}\\
\end{array}
$$
%
So, by definition we get the constant typing lemma
%
\begin{lemma}{[Constant Typing]}\label{lemma:constants}
Every constant $c \in \interp{\constty{c}}$.
\end{lemma}
%
Thus, if $\constty{c} \defeq \tfun{x}{\typ_x}{\typ}$,
then for every value $w \in \interp{\typ_x}$, we require
$\ceval{c}{w} \in \interp{\typ\subst{x}{w}}$.

%% \mypara{Equality}
%% The equality predicate
%% $\haseq{B}$, is defined to be true for \tint and \tbool,
%% and for each type constructor $T$
%% whose values can be finitely compared.
%% %
%% So, by definition we get the equality lemma
%% %
%% \begin{lemma}{[Equality]}\label{lemma:equality}
%% If $\haseq{B}$ then for each value $\bhastype{\emptyset}{w}{B}$
%% \evalsto{w = w}{\etrue}
%% \end{lemma}

\subsection{Refinement Reflection}
\label{subsec:logicalannotations}
%
The simple, but key idea in our work is to
\emph{strengthen} the output type of functions
with a refinement that \emph{reflects} the
definition of the function in the logic.
%
We do this by treating each
%
$\erefname$-binder:
%
${\erefb{f}{\gtyp}{e}{\prog}}$
%
as a $\eletname$-binder:
%
${\eletb{f}{\exacttype{\gtyp}{e}}{e}{\prog}}$
%
during type checking (rule $\rtreflect$ in Figure~\ref{fig:typing}).

\mypara{Reflection}
%
We write \exacttype{\typ}{e} for the \emph{reflection}
of term $e$ into the type $\typ$,  defined by strengthening
\typ as:
%
$$
\begin{array}{lcl}
\exacttype{\tref{v}{\btyp}{r}}{e}
  & \defeq
  & \tref{v}{\btyp}{r \land v = e}\\
\exacttype{\tfun{x}{\typ_x}{\typ}}{\efun{y}{}{e}}
  & \defeq
  & \tfun{x}{\typ_x}{\exacttype{\typ}{e\subst{y}{x}}}
\end{array}
$$
%
As an example, recall from \S~\ref{sec:refinementreflection:overview}
that the @reflect fib @ strengthens the type of
@fib@ with the reflected refinement @fibP@.
%% NV In Overview, we have fibP v n = v = fib n && fibR v n
%% NV Here we get the reflection part (fibR v n)
%% NV which we can verify
%% NV at each fix invocation we also get the v = fib n portion
%% NV via the exact rule
%% NV We can not add the v = fib n as a port condition, because
%% NV we cannot prove it.

\mypara{Consequences for Verification}
%
Reflection has two consequences for verification.
%
First, the reflected refinement is \emph{not trusted};
it is itself verified (as a valid output type)
during type checking.
%
Second, instead of being tethered to quantifier
instantiation heuristics or having to program
``triggers'' as in Dafny~\citep{dafny} or
\fstar~\citep{fstar}
%
the programmer can predictably ``unfold'' the
definition of the function during a proof simply
by ``calling'' the function, which we have found
to be a very natural way of structuring
proofs~\S~\ref{sec:evaluation}.

\subsection{Refining \& Reflecting Data Constructors with Measures}
\label{subsec:measures}
\label{subsec:list}

% We reuse the notion of \emph{measures}~\cite{Vazou14}
% to reflect functions over datatypes into the refinement
% logic.

We assume that each data type is equipped with
a set of \emph{measures} which are \emph{unary}
functions whose (1)~domain is the data type, and
(2)~body is a single case-expression over the
datatype~\cite{Vazou14}:
%
$$\emeasb{f}
         {\gtyp}
         {\efun{x}{\typ}{\ecase{y}{x}{\dc_i}{\overline{z}}{e_i}}}$$
%
For example, @len@ measures the size of an $\tintlist$:
%
\begin{code}
  measure len :: [Int] -> Nat
  len = \x -> case x of
                []     -> 0
                (x:xs) -> 1 + len xs
\end{code}

\mypara{Checking and Projection}
%
We assume the existence of measures that
\emph{check} the top-level constructor,
and \emph{project} their individual fields.
%
\NV{Remove this pointer since we removed the text}
In \S~\ref{subsec:embedding} we show how to
use these measures to reflect functions over
datatypes.
%
% Such measures are straightforward to generate
% automatically from the data-type definition.)
%
For example, for lists, we assume the existence of measures:
%
\begin{code}
  isNil []      = True
  isNil (x:xs)  = False

  isCons (x:xs) = True
  isCons []     = False

  sel1 (x:xs)   = x
  sel2 (x:xs)   = xs
\end{code}

\mypara{Refining Data Constructors with Measures}
%
We use measures to strengthen the types
of data constructors, and we use these
strengthened types during construction
and destruction (pattern-matching).
%
Let:
%
(1)~$\dc$ be a data constructor,
   with \emph{unrefined} type
   $\tfun{\overline{x}}{\overline{\gtyp}}{T}$
%
(2)~the $i$-th measure definition with
   domain $T$ is:
%
$$\emeasb{f_i}
         {\gtyp}
         {\efun{x}{\typ}{\ecase{y}{x}{\dc}{\overline{z}}{e_{i}}}}
$$
%
Then, the refined type of $\dc$ is defined:
$$
\constty{\dc} \defeq
   \tfun{\overline{x}}
        {\overline{\typ}}
        {\tref{v}{T}{ \wedge_i f_i\ v = \SUBST{e_{i}}{\overline{z}}{\overline{x}}}}
$$

Thus, each data constructor's output type is refined to reflect
the definition of each of its measures.
%
For example, we use the measures @len@, @isNil@, @isCons@, @sel1@,
and @sel2@ to strengthen the types of $\dnull$ and $\dcons$ to:
%
\begin{align*}
\constty{\dnull}  \defeq & \tref{v}{\tintlist}{r_{\dnull}} \\
\constty{\dcons}  \defeq & \tfun{x}{\tint}
                                   {\tfun{\mathit{xs}}
                                         {\tintlist}
                                         {\tref{v}{\tintlist}{r_\dcons}}}
\intertext{where the output refinements are}
r_{\dnull} \defeq &\ \mathtt{len}\ v = 0
             \land  \mathtt{isNil}\ v
             \land  \lnot \mathtt{isCons}\ v \\
r_{\dcons} \defeq &\ \mathtt{len}\ v = 1 + \mathtt{len}\ \mathit{xs}
             \land  \lnot \mathtt{isNil}\ v
             \land  \mathtt{isCons}\ v \\
             \land & \  \mathtt{sel1}\ v = x
             \land  \mathtt{sel2}\ v = \mathit{xs}
\end{align*}
%
It is easy to prove that Lemma~\ref{lemma:constants}
holds for data constructors, by construction.
%
For example, $\mathtt{len}\ \dnull = 0$ evaluates to $\tttrue$.

%%
%% The above annotation \emph{strengthens} the types of data constructors
%% $\dc_i$ to reflect the
%% behavior of $f$:
%%
%%
%% \preproc{\eletrecoptsmall{f}{\efun{x}{\typ}{\ecase{y}{x}{\dc_i}{\overline{z}}{e_i}}}{\gtyp}{M}{\prog}}
%%
%% %
%% Where \exacttypefun{f}{\gtyp}{e} strengthens the result $v$ of the type \typ to exactly
%% describe that $f\ v = e$:
%% %
%% \begin{align*}
%% \exacttypefun{f}{\tref{v}{\btyp}{r}}{e} &= \tref{v}{\btyp}{r \land f\ v = e}\\
%% \exacttypefun{f}{\tfun{x}{\typ_x}{\typ}}{\efun{y}{}{e}} &=\tfun{x}{\typ_x}{\exacttype{\typ}{e\subst{y}{x}}}
%% \end{align*}

\subsection{Typing Rules}
\input{text/refinementreflection/typing}
%
Next, we present the type-checking
judgments and rules of \corelan.

\mypara{Environments and Closing Substitutions}
A \emph{type environment} $\env$ is a sequence of type bindings
$\tbind{x_1}{\typ_1},\ldots,\tbind{x_n}{\typ_n}$. An environment
denotes a set of \emph{closing substitutions} $\sto$ which are
sequences of expression bindings:
$\gbind{x_1}{e_1}, \ldots, \gbind{x_n}{e_n}$ such that:
$$
\interp{\env} \defeq  \{\sto \mid \forall \tbind{x}{\typ} \in \Env.
                                    \sto(x) \in \interp{\applysub{\sto}{\typ}} \}
$$

\mypara{Judgments}
We use environments to define three kinds of
rules: Well-formedness, Subtyping,
and Typing~\citep{Knowles10,Vazou14}.
%
%\mypara{Well-formedness}
A judgment \iswellformed{\env}{\typ} states that
the refinement type $\typ$ is well-formed in
the environment $\env$.
%
Intuitively, the type $\typ$ is well-formed if all
the refinements in $\typ$ are $\tbool$-typed in $\env$.
%
%\mypara{Subtyping}
A judgment \issubtype{\env}{\typ_1}{\typ_2} states
that the type $\typ_1$ is a subtype of %the type
$\typ_2$ in the environment $\env$.
%
Informally, $\typ_1$ is a subtype of $\typ_2$ if, when
the free variables of $\typ_1$ and $\typ_2$
are bound to expressions described by $\env$,
the denotation of $\typ_1$
is \emph{contained in} the denotation of $\typ_2$.
%
Subtyping of basic types reduces to denotational containment checking.
%
%\mypara{Implication}
%%A judgment \issubref{\Env}{p_1}{p_2} states
%%that the predicate $p_1$ \emph{implies}
%%the predicate $p_2$ in the environment $\Env$.
%
That is, for any closing substitution $\sto$
in the denotation of $\env$, for every expression $e$,
if $e \in \interp{\applysub{\sto}{\typ_1}}$ then
$ e \in \interp{\applysub{\sto}{\typ_2}}$.
%
%\mypara{Typing}
A judgment \hastype{\env}{\prog}{\typ} states that
the program $\prog$ has the type $\typ$ in
the environment $\env$.
That is, when the free variables in $\prog$ are
bound to expressions described by $\env$, the
program $\prog$ will evaluate to a value
described by $\typ$.

\mypara{Rules}
%
All but three of the rules are standard~\cite{Knowles10,Vazou14}.
%
First, rule \rtreflect is used to strengthen the type of each
reflected binder with its definition, as described previously
in \S~\ref{subsec:logicalannotations}.
%
% \NV{FIX:Eq}
% applies only to expressions that can be finitely compared
% (\ie whose type satisfies the \haseq{B} predicate) and
Second, rule \rtexact strengthens the expression with
a singleton type equating the value and the expression
(\ie reflecting the expression in the type).
%
This is a generalization of the ``selfification'' rules
from \cite{Ou2004,Knowles10}, and is required to
equate the reflected functions with their definitions.
%
For example, the application $(\fib\ 1)$ is typed as
${\tref{v}{\tint}{\fibdef\ v\ 1 \wedge v = \fib\ 1}}$ where
the first conjunct comes from the (reflection-strengthened)
output refinement of \fib~\S~\ref{sec:refinementreflection:overview}, and
the second conjunct comes from rule~\rtexact.
%
Finally, rule \rtfix is used to type the intermediate
$\texttt{fix}$ expressions that appear, not in the
surface language but as intermediate terms in the
operational semantics.

\mypara{Soundness}
Following \undeclang~\citep{Vazou14}, we can show that
evaluation preserves typing and that typing implies
denotational inclusion.
%
\begin{theorem}{[Soundness of \corelan]}\label{thm:safety}
\begin{itemize}
\item\textbf{Denotations}
If $\hastype{\env}{\prog}{\typ}$ then
$\forall \sto\in \interp{\env}. \applysub{\sto}{\prog} \in \interp{\applysub{\sto}{\typ}}$.
\item\textbf{Preservation}
If \hastype{\emptyset}{\prog}{\typ}
       and $\evalsto{\prog}{w}$ then $\hastype{\emptyset}{w}{\typ}$.
\end{itemize}
\end{theorem}

\subsection{From Programs \& Types to Propositions \& Proofs}

The denotational soundness Theorem~\ref{thm:safety}
lets us interpret well typed programs as proofs of
propositions.

\NV{say that definition is a context that will be used later}
\mypara{``Definitions''}
A \emph{definition} $\defn$ is a sequence of reflected binders:
%
$$\defn \ ::= \ \bullet \spmid \erefb{x}{\gtyp}{e}{\defn}$$
%
A \emph{definition's environment} $\env(\defn)$ comprises
its binders and their reflected types:
%
\begin{align*}
\aenv(\bullet)                    \defeq & \emptyset \\
\aenv(\erefb{f}{\gtyp}{e}{\defn}) \defeq & (f, \exacttype{\gtyp}{e}),\ \env(\defn) \\
\end{align*}
%
A \emph{definition's substitution} $\sto(\defn)$ maps each binder
to its definition:
%
\begin{align*}
\sto(\bullet)                     \defeq & \emptysto \\
\sto(\erefb{f}{\gtyp}{e}{\defn})  \defeq & \extendsto{f}{\efix{f}\ e}{\sto(\defn)}
\end{align*}

\mypara{``Propositions''}
%
A \emph{proposition} is a type
%
$$\tbind{x_1}{\typ_1} \rightarrow \ldots
  \rightarrow \tbind{x_n}{\typ_n}
  \rightarrow \tref{v}{\tunit}{\ppn}$$
%
For brevity, we abbreviate propositions like the above to
%
$\tfun{\overline{x}}{\overline{\typ}}{\ttref{\ppn}}$
%
and we call $\ppn$ the \emph{proposition's refinement}.
%
For simplicity we assume that $\freevars{\typ_i} = \emptyset$.

\mypara{``Validity''}
%
\NV{add termination: proofs should provably terminates}

A proposition $\tfun{\overline{x}}{\overline{\typ}}{\ttref{\ppn}}$
is \emph{valid under} $\defn$ if
%
$$\forall \overline{w} \in \interp{\overline{\typ}}.\
  \evalsto{\applysub{\sto(\defn)}{\SUBST{\ppn}{\overline{x}}{\overline{w}}}}{\etrue}$$
%
That is, the proposition is valid if its refinement
evaluates to $\etrue$ for every (well typed)
interpretation for its parameters $\overline{x}$
under $\defn$.

\mypara{``Proofs''}
%
A binder $\bd$ \emph{proves} a proposition $\gtyp$ under $\defn$ if
$$\hastype{\emptyset}{\defn[\eletb{x}{\typ}{\bd}{\eunit}]}{\tunit}$$
%
That is, if the binder $\bd$ has the proposition's type $\gtyp$
under the definition $\defn$'s environment.

\begin{theorem}{[Proofs]} \label{thm:validity}
If $\bd$ proves $\typ$ under $\defn$ then $\typ$ is valid under $d$.
\end{theorem}

\begin{proof}
As $\bd$ proves $\typ$ under $\defn$, we have
%
\begin{align}
\hastype{\emptyset}{\defn[\eletb{x}{\typ}{\bd}{\eunit}]}{\tunit}
\label{pf:1} \\
%
\intertext{By Theorem~\ref{thm:safety} on \ref{pf:1} we get}
%
\sto(\defn) \in \interp{\env(\defn)} \label{pf:2}\\
%
\intertext{Furthermore,  by the typing rules \ref{pf:1}
implies $\hastype{\env(\defn)}{\bd}{\typ}$ and hence, via Theorem~\ref{thm:safety}}
%
\forall \sub \in \interp{\env(\defn)}.\ \applysub{\sub}{\bd} \in \interp{\applysub{\sub}{\typ}}
\label{pf:3} \\
\intertext{Together, \ref{pf:2} and \ref{pf:3} imply}
\applysub{\sto(\defn)}{\bd} \in \interp{\applysub{\sto(\defn)}{\typ}}
\label{pf:4}
\intertext{By the definition of type denotations, we have}
%
\interp{\applysub{\sto(\defn)}{\typ}}
  \defeq \{ f\ |\ \typ \mbox{ is valid under}\ \defn\}
  \label{pf:5}
\end{align}
By \ref{pf:4}, the above set is not empty, and hence $\typ$ is valid under $\defn$.
\end{proof}

%%%%%  \begin{definition}[Theorem]
%%%%%  Let $\aenv=\aenv(\prog)$ be the set of axioms for some program \prog.
%%%%%  Then
%%%%%  $\typ\defeq\tbind{x_1}{\typ_1} \rightarrow \dots \rightarrow \tbind{x_n}{\typ_n} \rightarrow \ttreft{v}{\btyp}{\refa}$
%%%%%  is a theorem if
%%%%%  $\freevars{\refa} \subseteq \{x_1, \dots, x_n\} \cup \domain{\aenv}$,
%%%%%  and for simplicity $\freevars{\typ_i} = \emptyset$.
%%%%%
%%%%%  Moreover, every expression $e'$ such that  \hastype{\aenv}{e'}{\typ}
%%%%%  provides a proof of the theorem $\typ$ with respect to the definitions in \prog.
%%%%%  \end{definition}
%%%%%  %
%%%%%  In other words, any expression $e'$ provides an evidence that the theorem expressed
%%%%%  by \typ holds.
%%%%%  The above definition is an instance of the Curry-Howard correspondence,
%%%%%  where programs as interpreted as proofs or the theorems expressed by their types.
%%%%%  %
%%%%%  %% Moreover, since the proof of the theorem is any expression $e'$ with type $\typ$
%%%%%  %% the definition states that our proof system is proof irrelevant.
%%%%%
%%%%%  \begin{theorem}
%%%%%  Let $\aenv=\aenv(\prog)$.
%%%%%  For every theorem
%%%%%  $\typ \equiv \tbind{x_1}{\typ_1} \rightarrow \dots \rightarrow \tbind{x_n}{\typ_n} \rightarrow \ttreft{v}{\btyp}{\refa}$
%%%%%  with a proof $e_\typ$ with respect to $p$,
%%%%%  then $\forall x_1\in\interp{\typ_1},\dots, x_n\in\interp{\typ_n}. \evalsto{\applysub{\Theta_\aenv(\prog)}{\refa}}{\etrue}$.
%%%%%  \end{theorem}
%%%%%  \begin{myproof}
%%%%%  Since \hastype{\aenv}{e_\typ}{\typ}
%%%%%  by Theorem~\ref{thm:safety} we have
%%%%%  $\forall \sub \in \interp{\aenv}.
%%%%%  \applysub{\sub}{e_\typ} \in \interp{\applysub{\sub}{\typ}}
%%%%%  $.
%%%%%  %
%%%%%  Since \prog type checks
%%%%%  we have $\Theta_\aenv(\prog)\in\interp{\aenv}$, thus
%%%%%  $\applysub{\Theta_\aenv(\prog)}{\refa} \in \interp{\applysub{\Theta_\aenv(\prog)}{\typ}}$.
%%%%%  %
%%%%%  By the Definition of Type Denotations we have
%%%%%  $\interp{\typ} =  \{f |\forall x_1\in\interp{\typ_1},\dots, x_n\in\interp{\typ_n}. \evalsto{\applysub{\Theta_\aenv(\prog)}{\refa}}{\etrue} \}$.
%%%%%  %
%%%%%  But $e_\typ$ is a witness that the set \interp{\typ} is not empty, thus
%%%%%  $\forall x_1\in\interp{\typ_1},\dots, x_n\in\interp{\typ_n}. \evalsto{\applysub{\Theta_\aenv(\prog)}{\refa}}{\etrue}$.
%%%%%  \end{myproof}

%% Theta_\aenv(\eletrec{f}{e}{\gtyp}{L}{\prog})
 %% & = (f, \efix{f}\ e),\aenv(p) \\
%% \Theta_\aenv(\elet{f}{e}{\gtyp}{L}{\prog})
 %% & = (f, e),\aenv(p) \\
%% \Theta_\aenv(\eletrecopt{f}{e}{\gtyp}{}{\prog})
 %% & = \Theta_\aenv(p) \\
%% \Theta_\aenv(e) &= \emptyset
%% \end{align*}

%% A proposition is \emph{well-formed} under $\defn$ if
%% $\freevars{\refa} \subseteq \{x_1, \dots, x_n\} \cup \domain{\aenv}$,

\mypara{Example: Fibonacci is increasing}
%
In \S~\ref{sec:refinementreflection:overview} we verified that
under a definition $\defn$ that includes \fibname,
the term \fibincrname proves
$${\tfun{n}{\tnat}{\ttref{\fib{n} \leq \fib{(n+1)}}}}$$
%
Thus, by Theorem~\ref{thm:validity} we get
%that the \fib{}, as defined in $\defn$ is increasing
%
%$$
%\forall n\in\interp{\tnat}. \evalsto{\fib{n} \leq \fib{(n+1)}}{\etrue}
%$$
%Equivalently
$$
\forall n. \evalsto{0 \leq n}{\etrue} \Rightarrow \evalsto{\fib{n} \leq \fib{(n+1)}}{\etrue}
$$


\begin{comment}

 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.

\end{comment}

\subsection{Multinomial Logistic Regression}

\noindent{\bf Description}
\smallskip

Our logistic regression script performs both binomial and multinomial logistic regression.
The script is given a dataset $(X, Y)$ where matrix $X$ has $m$~columns and matrix $Y$ has
one column; both $X$ and~$Y$ have $n$~rows.  The rows of $X$ and~$Y$ are viewed as a collection
of records: $(X, Y) = (x_i, y_i)_{i=1}^n$ where $x_i$ is a numerical vector of explanatory
(feature) variables and $y_i$ is a categorical response variable.
Each row~$x_i$ in~$X$ has size~\mbox{$\dim x_i = m$}, while its corresponding $y_i$ is an
integer that represents the observed response value for record~$i$.

The goal of logistic regression is to learn a linear model over the feature vector
$x_i$ that can be used to predict how likely each categorical label is expected to
be observed as the actual~$y_i$.
Note that logistic regression predicts more than a label: it predicts the probability
for every possible label.  The binomial case allows only two possible labels, the
multinomial case has no such restriction.

Just as linear regression estimates the mean value $\mu_i$ of a numerical response
variable, logistic regression does the same for category label probabilities.
In linear regression, the mean of $y_i$ is estimated as a linear combination of the features:
$\mu_i = \beta_0 + \beta_1 x_{i,1} + \ldots + \beta_m x_{i,m} = \beta_0 + x_i\beta_{1:m}$.
In logistic regression, the
label probability has to lie between 0 and~1, so a link function is applied to connect
it to $\beta_0 + x_i\beta_{1:m}$.  If there are just two possible category labels, for example
0~and~1, the logistic link looks as follows:
\begin{equation*}
\Prob[y_i\,{=}\,1\mid x_i; \beta] \,=\,
\frac{e^{\,\beta_0 + x_i\beta_{1:m}}}{1 + e^{\,\beta_0 + x_i\beta_{1:m}}};
\quad
\Prob[y_i\,{=}\,0\mid x_i; \beta] \,=\,
\frac{1}{1 + e^{\,\beta_0 + x_i\beta_{1:m}}}
\end{equation*}
Here category label~0 serves as the \emph{baseline}, and function
$\exp(\beta_0 + x_i\beta_{1:m})$
shows how likely we expect to see ``$y_i = 1$'' in comparison to the baseline.
Like in a loaded coin, the predicted odds of seeing 1~versus~0 are
$\exp(\beta_0 + x_i\beta_{1:m})$ to~1,
with each feature $x_{i,j}$ multiplying its own factor $\exp(\beta_j x_{i,j})$ to the odds.
Given a large collection of pairs $(x_i, y_i)$, $i=1\ldots n$, logistic regression seeks
to find the $\beta_j$'s that maximize the product of probabilities
\hbox{$\Prob[y_i\mid x_i; \beta]$}
for actually observed $y_i$-labels (assuming no regularization).

Multinomial logistic regression~\cite{Agresti2002:CDA} extends this link to $k \geq 3$ possible
categories.  Again we identify one category as the baseline, for example the $k$-th category.
Instead of a coin, here we have a loaded multisided die, one side per category.  Each non-baseline
category $l = 1\ldots k\,{-}\,1$ has its own vector $(\beta_{0,l}, \beta_{1,l}, \ldots, \beta_{m,l})$
of regression parameters with the intercept, making up a matrix $B$ of size
$(m\,{+}\,1)\times(k\,{-}\,1)$.  The predicted odds of seeing non-baseline category~$l$ versus
the baseline~$k$ are $\exp\big(\beta_{0,l} + \sum\nolimits_{j=1}^m x_{i,j}\beta_{j,l}\big)$
to~1, and the predicted probabilities are:
\begin{align}
l < k:\quad\Prob[y_i\,{=}\,\makebox[0.5em][c]{$l$}\mid x_i; B] \,\,\,{=}\,\,\,&
\frac{\exp\big(\beta_{0,l} + \sum\nolimits_{j=1}^m x_{i,j}\beta_{j,l}\big)}%
{1 \,+\, \sum_{l'=1}^{k-1}\exp\big(\beta_{0,l'} + \sum\nolimits_{j=1}^m x_{i,j}\beta_{j,l'}\big)};
\label{eqn:mlogreg:nonbaseprob}\\
\Prob[y_i\,{=}\,\makebox[0.5em][c]{$k$}\mid x_i; B] \,\,\,{=}\,\,\,& \frac{1}%
{1 \,+\, \sum_{l'=1}^{k-1}\exp\big(\beta_{0,l'} + \sum\nolimits_{j=1}^m x_{i,j}\beta_{j,l'}\big)}.
\label{eqn:mlogreg:baseprob}
\end{align}
The goal of the regression is to estimate the parameter matrix~$B$ from the provided dataset
$(X, Y) = (x_i, y_i)_{i=1}^n$ by maximizing the product of \hbox{$\Prob[y_i\mid x_i; B]$}
over the observed labels~$y_i$.  Taking its logarithm, negating, and adding a regularization term
gives us a minimization objective:
\begin{equation}
f(B; X, Y) \,\,=\,\,
-\sum_{i=1}^n \,\log \Prob[y_i\mid x_i; B] \,+\,
\frac{\lambda}{2} \sum_{j=1}^m \sum_{l=1}^{k-1} |\beta_{j,l}|^2
\,\,\to\,\,\min
\label{eqn:mlogreg:loss}
\end{equation}
The optional regularization term is added to mitigate overfitting and degeneracy in the data;
to reduce bias, the intercepts $\beta_{0,l}$ are not regularized.  Once the~$\beta_{j,l}$'s
are accurately estimated, we can make predictions about the category label~$y$ for a new
feature vector~$x$ using Eqs.~(\ref{eqn:mlogreg:nonbaseprob}) and~(\ref{eqn:mlogreg:baseprob}).

\smallskip
\noindent{\bf Usage}
\smallskip

{\hangindent=\parindent\noindent\it%
{\tt{}-f }path/\/{\tt{}MultiLogReg.dml}
{\tt{} -nvargs}
{\tt{} X=}path/file
{\tt{} Y=}path/file
{\tt{} B=}path/file
{\tt{} Log=}path/file
{\tt{} icpt=}int
{\tt{} reg=}double
{\tt{} tol=}double
{\tt{} moi=}int
{\tt{} mii=}int
{\tt{} fmt=}format

}

\smallskip
\noindent{\bf Arguments}
\begin{Description}
\item[{\tt X}:]
Location (on HDFS) to read the input matrix of feature vectors; each row constitutes
one feature vector.
\item[{\tt Y}:]
Location to read the input one-column matrix of category labels that correspond to
feature vectors in~{\tt X}.  Note the following:\\
-- Each non-baseline category label must be a positive integer.\\
-- If all labels are positive, the largest represents the baseline category.\\
-- If non-positive labels such as $-1$ or~$0$ are present, then they represent the (same)
baseline category and are converted to label $\max(\texttt{Y})\,{+}\,1$.
\item[{\tt B}:]
Location to store the matrix of estimated regression parameters (the $\beta_{j, l}$'s),
with the intercept parameters~$\beta_{0, l}$ at position {\tt B[}$m\,{+}\,1$, $l${\tt ]}
if available.  The size of {\tt B} is $(m\,{+}\,1)\times (k\,{-}\,1)$ with the intercepts
or $m \times (k\,{-}\,1)$ without the intercepts, one column per non-baseline category
and one row per feature.
\item[{\tt Log}:] (default:\mbox{ }{\tt " "})
Location to store iteration-specific variables for monitoring and debugging purposes,
see Table~\ref{table:mlogreg:log} for details.
\item[{\tt icpt}:] (default:\mbox{ }{\tt 0})
Intercept and shifting/rescaling of the features in~$X$:\\
{\tt 0} = no intercept (hence no~$\beta_0$), no shifting/rescaling of the features;\\
{\tt 1} = add intercept, but do not shift/rescale the features in~$X$;\\
{\tt 2} = add intercept, shift/rescale the features in~$X$ to mean~0, variance~1
\item[{\tt reg}:] (default:\mbox{ }{\tt 0.0})
L2-regularization parameter (lambda)
\item[{\tt tol}:] (default:\mbox{ }{\tt 0.000001})
Tolerance (epsilon) used in the convergence criterion
\item[{\tt moi}:] (default:\mbox{ }{\tt 100})
Maximum number of outer (Fisher scoring) iterations
\item[{\tt mii}:] (default:\mbox{ }{\tt 0})
Maximum number of inner (conjugate gradient) iterations, or~0 if no maximum
limit provided
\item[{\tt fmt}:] (default:\mbox{ }{\tt "text"})
Matrix file output format, such as {\tt text}, {\tt mm}, or {\tt csv};
see read/write functions in SystemDS Language Reference for details.
\end{Description}

\begin{table}[t]\small\centerline{%
\begin{tabular}{|ll|}
\hline
Name & Meaning \\
\hline
{\tt LINEAR\_TERM\_MIN}  & The minimum value of $X \pxp B$, used to check for overflows \\
{\tt LINEAR\_TERM\_MAX}  & The maximum value of $X \pxp B$, used to check for overflows \\
{\tt NUM\_CG\_ITERS}     & Number of inner (Conj.\ Gradient) iterations in this outer iteration \\
{\tt IS\_TRUST\_REACHED} & $1 = {}$trust region boundary was reached, $0 = {}$otherwise \\
{\tt POINT\_STEP\_NORM}  & L2-norm of iteration step from old point (matrix $B$) to new point \\
{\tt OBJECTIVE}          & The loss function we minimize (negative regularized log-likelihood) \\
{\tt OBJ\_DROP\_REAL}    & Reduction in the objective during this iteration, actual value \\
{\tt OBJ\_DROP\_PRED}    & Reduction in the objective predicted by a quadratic approximation \\
{\tt OBJ\_DROP\_RATIO}   & Actual-to-predicted reduction ratio, used to update the trust region \\
{\tt IS\_POINT\_UPDATED} & $1 = {}$new point accepted; $0 = {}$new point rejected, old point restored \\
{\tt GRADIENT\_NORM}     & L2-norm of the loss function gradient (omitted if point is rejected) \\
{\tt TRUST\_DELTA}       & Updated trust region size, the ``delta'' \\
\hline
\end{tabular}}
\caption{
The {\tt Log} file for multinomial logistic regression contains the above \mbox{per-}iteration
variables in CSV format, each line containing triple (Name, Iteration\#, Value) with Iteration\#
being~0 for initial values.}
\label{table:mlogreg:log}
\end{table}

\noindent{\bf Details}
\smallskip

We estimate the logistic regression parameters via L2-regularized negative
log-likelihood minimization~(\ref{eqn:mlogreg:loss}).
The optimization method used in the script closely follows the trust region
Newton method for logistic regression described in~\cite{Lin2008:logistic}.
For convenience, let us make some changes in notation:
\begin{Itemize}
\item Convert the input vector of observed category labels into an indicator matrix $Y$
of size $n \times k$ such that $Y_{i, l} = 1$ if the $i$-th category label is~$l$ and
$Y_{i, l} = 0$ otherwise;
\item Append an extra column of all ones, i.e.\ $(1, 1, \ldots, 1)^T$, as the
$m\,{+}\,1$-st column to the feature matrix $X$ to represent the intercept;
\item Append an all-zero column as the $k$-th column to $B$, the matrix of regression
parameters, to represent the baseline category;
\item Convert the regularization constant $\lambda$ into matrix $\Lambda$ of the same
size as $B$, placing 0's into the $m\,{+}\,1$-st row to disable intercept regularization,
and placing $\lambda$'s everywhere else.
\end{Itemize}
Now the ($n\,{\times}\,k$)-matrix of predicted probabilities given
by (\ref{eqn:mlogreg:nonbaseprob}) and~(\ref{eqn:mlogreg:baseprob})
and the objective function $f$ in~(\ref{eqn:mlogreg:loss}) have the matrix form
\begin{align*}
P \,\,&=\,\, \exp(XB) \,\,/\,\, \big(\exp(XB)\,1_{k\times k}\big)\\
f \,\,&=\,\, - \,\,{\textstyle\sum} \,\,Y \cdot (X B)\, + \,
{\textstyle\sum}\,\log\big(\exp(XB)\,1_{k\times 1}\big) \,+ \,
(1/2)\,\, {\textstyle\sum} \,\,\Lambda \cdot B \cdot B
\end{align*}
where operations $\cdot\,$, $/$, $\exp$, and $\log$ are applied cellwise,
and $\textstyle\sum$ denotes the sum of all cells in a matrix.
The gradient of~$f$ with respect to~$B$ can be represented as a matrix too:
\begin{equation*}
\nabla f \,\,=\,\, X^T (P - Y) \,+\, \Lambda \cdot B
\end{equation*}
The Hessian $\mathcal{H}$ of~$f$ is a tensor, but, fortunately, the conjugate
gradient inner loop of the trust region algorithm in~\cite{Lin2008:logistic}
does not need to instantiate it.  We only need to multiply $\mathcal{H}$ by
ordinary matrices of the same size as $B$ and $\nabla f$, and this can be done
in matrix form:
\begin{equation*}
\mathcal{H}V \,\,=\,\, X^T \big( Q \,-\, P \cdot (Q\,1_{k\times k}) \big) \,+\,
\Lambda \cdot V, \,\,\,\,\textrm{where}\,\,\,\,Q \,=\, P \cdot (XV)
\end{equation*}
At each Newton iteration (the \emph{outer} iteration) the minimization algorithm
approximates the difference $\varDelta f(S; B) = f(B + S; X, Y) \,-\, f(B; X, Y)$
attained in the objective function after a step $B \mapsto B\,{+}\,S$ by a
second-degree formula
\begin{equation*}
\varDelta f(S; B) \,\,\,\approx\,\,\, (1/2)\,\,{\textstyle\sum}\,\,S \cdot \mathcal{H}S
 \,+\, {\textstyle\sum}\,\,S\cdot \nabla f
\end{equation*}
This approximation is then minimized by trust-region conjugate gradient iterations
(the \emph{inner} iterations) subject to the constraint $\|S\|_2 \leq \delta$.
The trust region size $\delta$ is initialized as $0.5\sqrt{m}\,/ \max\nolimits_i \|x_i\|_2$
and updated as described in~\cite{Lin2008:logistic}.
Users can specify the maximum number of the outer and the inner iterations with
input parameters {\tt moi} and {\tt mii}, respectively.  The iterative minimizer
terminates successfully if $\|\nabla f\|_2 < \eps\,\|\nabla f_{B=0}\|_2$,
where $\eps > 0$ is a tolerance supplied by the user via input parameter~{\tt tol}.

\smallskip
\noindent{\bf Returns}
\smallskip

The estimated regression parameters (the $\hat{\beta}_{j, l}$) are populated into
a matrix and written to an HDFS file whose path/name was provided as the ``{\tt B}''
input argument.  Only the non-baseline categories ($1\leq l \leq k\,{-}\,1$) have
their $\hat{\beta}_{j, l}$ in the output; to add the baseline category, just append
a column of zeros.  If {\tt icpt=0} in the input command line, no intercepts are used
and {\tt B} has size $m\times (k\,{-}\,1)$; otherwise {\tt B} has size
$(m\,{+}\,1)\times (k\,{-}\,1)$
and the intercepts are in the $m\,{+}\,1$-st row.  If {\tt icpt=2}, then initially
the feature columns in~$X$ are shifted to mean${} = 0$ and rescaled to variance${} = 1$.
After the iterations converge, the $\hat{\beta}_{j, l}$'s are rescaled and shifted
to work with the original features.

\smallskip
\noindent{\bf Examples}
\smallskip

{\hangindent=\parindent\noindent\tt
\hml -f MultiLogReg.dml -nvargs X=/user/biadmin/X.mtx
  Y=/user/biadmin/Y.mtx B=/user/biadmin/B.mtx fmt=csv
  icpt=2 reg=1.0 tol=0.0001 moi=100 mii=10 Log=/user/biadmin/log.csv

}

\smallskip
\noindent{\bf References}
\begin{itemize}
\item A.~Agresti.
\newblock {\em Categorical Data Analysis}.
\newblock Wiley Series in Probability and Statistics. Wiley-Interscience,  second edition, 2002.
\end{itemize}


\section{Link/activation functions: Classification}


\section{Data Reduction}
% description of how reduced and calibrated  your data

In this session we discuss how we treat the raw data, which was registered with the  software LoggerPro \cite{loggerpro} as measurements of the total output voltage vs time of  signal.

\subsection{Treatment of the Voltage V(t) Raw Data}

To normalize and delogarithm  all the four sets of data described in the section \ref{observations},  we use the equations (\ref{pdb}) and (\ref{pdb2}). The negative slope indicates that the output voltage decreases as the input power increase. The interferometry results for the Sun and for the satellite are shown in the figures \ref{voltpow2} and \ref{voltpow3}. The total power is the amplitude squared of the summed  electric vectors of the electromagnetic signals, as we described before.

 \begin{figure}[htb]
\begin{center}
 \includegraphics[scale=0.7]{plots/sun1pow.pdf}
 \includegraphics[scale=0.7]{plots/sun1powc.pdf}
 \includegraphics[scale=0.7]{plots/sun2pow.pdf}
 \includegraphics[scale=0.7]{plots/sun2powc.pdf}
 \includegraphics[scale=0.7]{plots/sun3pow.pdf}
 \includegraphics[scale=0.7]{plots/sun3powc.pdf}
 \includegraphics[scale=0.7]{plots/sun4pow.pdf}
 \includegraphics[scale=0.7]{plots/sun4powc.pdf}
 \includegraphics[scale=0.7]{plots/sun5pow.pdf}
 \includegraphics[scale=0.7]{plots/sun5powc.pdf}
\caption{Interferometer measurements of total power of the Sun, in function of time, for the five set of measurements. On the right, after the  cuts.}
\label{voltpow2}
\end{center}
\end{figure}

 \begin{figure}[htb]
\begin{center}
 \includegraphics[scale=0.7]{plots/sat1pow.pdf}
 \includegraphics[scale=0.7]{plots/sat1powc.pdf}
 \includegraphics[scale=0.7]{plots/sat2pow.pdf}
 \includegraphics[scale=0.7]{plots/sat2powc.pdf}
 \includegraphics[scale=0.7]{plots/sat3pow.pdf}
 \includegraphics[scale=0.7]{plots/sat3powc.pdf}
 \includegraphics[scale=0.7]{plots/sat4pow.pdf}
 \includegraphics[scale=0.7]{plots/sat4powc.pdf}
 \includegraphics[scale=0.7]{plots/sat5pow.pdf}
 \includegraphics[scale=0.7]{plots/sat5powc.pdf}
\caption{Interferometer measurements of total power of the satellite, in function of time, for the five set of measurements. On the right, after the  cuts.}
\label{voltpow3}
\end{center}
\end{figure}

\bigskip

\subsection{The Single Dish Measurements for the Sun and the Satellite}

In the single dish mode, the size of the solar disk is the {\it deconvolution} of the single dish solar profile with the single dish satellite profile. We report the single dish profile for one of the measurements of each of the sources in the figure \ref{voltpow4}. We use these two profiles to resolve a first approximation of the solar angular diameter.

 \begin{figure}[htb]
\begin{center}
 \includegraphics[scale=0.8]{plots/single/1.pdf}
 \includegraphics[scale=0.8]{plots/single/2.pdf}
 \includegraphics[scale=0.8]{plots/single/3.pdf}
 \includegraphics[scale=0.8]{plots/single/4.pdf}

\caption{Single dish measurements for the Sun and the satellite.}
\label{voltpow4}
\end{center}
\end{figure}