\section{Class List}
Here are the classes, structs, unions and interfaces with brief descriptions\+:\begin{DoxyCompactList}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1add}{numpp\+::differentiation\+::symbolic\+::add$<$ Left, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1add}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1matrix_1_1sparse_1_1block}{numpp\+::matrix\+::sparse\+::block$<$ T, Rows, Columns $>$} \\*Block version of sparse matrix }{\pageref{classnumpp_1_1matrix_1_1sparse_1_1block}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1constant}{numpp\+::differentiation\+::symbolic\+::constant$<$ Value $>$} \\*Class representing constant integer number }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1constant}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1cosinus}{numpp\+::differentiation\+::symbolic\+::cosinus$<$ T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1cosinus}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1matrix_1_1dense}{numpp\+::matrix\+::dense$<$ T, Rows, Columns $>$} }{\pageref{classnumpp_1_1matrix_1_1dense}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{numpp\+::differentiation\+::symbolic\+::differentiate$<$ Function, Order $>$} \\*Allows differentiation of N-\/th order }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_3_01Function_00_011_01_4}{numpp\+::differentiation\+::symbolic\+::differentiate$<$ Function, 1 $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_3_01Function_00_011_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1divide}{numpp\+::differentiation\+::symbolic\+::divide$<$ Left, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1divide}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1exponential}{numpp\+::differentiation\+::symbolic\+::exponential$<$ T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1exponential}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1automatic_1_1forward}{numpp\+::differentiation\+::automatic\+::forward$<$ T $>$} }{\pageref{classnumpp_1_1differentiation_1_1automatic_1_1forward}}{}
\item\contentsline{section}{\hyperlink{structnumpp_1_1matrix_1_1sparse_1_1impl_1_1inner__block}{numpp\+::matrix\+::sparse\+::impl\+::inner\+\_\+block$<$ T $>$} }{\pageref{structnumpp_1_1matrix_1_1sparse_1_1impl_1_1inner__block}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1logarithm}{numpp\+::differentiation\+::symbolic\+::logarithm$<$ T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1logarithm}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1minus}{numpp\+::differentiation\+::symbolic\+::minus$<$ T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1minus}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1multiply}{numpp\+::differentiation\+::symbolic\+::multiply$<$ Left, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1multiply}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1matrix_1_1sparse_1_1nested}{numpp\+::matrix\+::sparse\+::nested$<$ T, Rows, Columns $>$} \\*Block nested version of sparse matrix }{\pageref{classnumpp_1_1matrix_1_1sparse_1_1nested}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1power}{numpp\+::differentiation\+::symbolic\+::power$<$ Left, Exp $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1power}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ Left, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01constant_3_0a2e8fcb21917ecf6b67a5c4cb33302f3}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ add$<$ constant$<$ left\+\_\+value $>$, Right $>$, constant$<$ right\+\_\+value $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01constant_3_0a2e8fcb21917ecf6b67a5c4cb33302f3}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01Left_00_01co9800d9c084c22272aa6400ee9a366a08}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ add$<$ Left, constant$<$ left\+\_\+value $>$ $>$, constant$<$ right\+\_\+value $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01add_3_01Left_00_01co9800d9c084c22272aa6400ee9a366a08}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01constant_3_010_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ constant$<$ 0 $>$, constant$<$ 0 $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01constant_3_010_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01minus_3_01Right_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ constant$<$ 0 $>$, minus$<$ Right $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01minus_3_01Right_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01Right_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ constant$<$ 0 $>$, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_010_01_4_00_01Right_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__vfa025c621c0342a297dcef4b571ae845}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ constant$<$ left\+\_\+value $>$, add$<$ constant$<$ right\+\_\+value $>$, Right $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__vfa025c621c0342a297dcef4b571ae845}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__v2b04d4fb76b2adc8e73af8cc3aa482e4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ constant$<$ left\+\_\+value $>$, add$<$ Left, constant$<$ right\+\_\+value $>$ $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01constant_3_01left__v2b04d4fb76b2adc8e73af8cc3aa482e4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01constant_3_010_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ Left, constant$<$ 0 $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01constant_3_010_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01minus_3_01Right_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ Left, minus$<$ Right $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01Left_00_01minus_3_01Right_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01constant_3_010_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ minus$<$ Left $>$, constant$<$ 0 $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01constant_3_010_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01Right_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+addition$<$ minus$<$ Left $>$, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__addition_3_01minus_3_01Left_01_4_00_01Right_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ Upper, Lower $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_010_01_4_00_01T_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ constant$<$ 0 $>$, T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_010_01_4_00_01T_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_011_01_4_b4d4ff9717ee8780cd1da6b85e108a8c}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ constant$<$ 1 $>$, divide$<$ First, Second $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01constant_3_011_01_4_b4d4ff9717ee8780cd1da6b85e108a8c}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01First_00_01multiply_3_01First_00_01Second_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ First, multiply$<$ First, Second $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01First_00_01multiply_3_01First_00_01Second_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_009a599186e504c392075b7a47787417d}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ multiply$<$ First, Second $>$, multiply$<$ Second, Third $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_009a599186e504c392075b7a47787417d}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_0c33d7e82a36da3303a0a365fc4a46997}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ multiply$<$ First, Second $>$, Second $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01multiply_3_01First_0c33d7e82a36da3303a0a365fc4a46997}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01constant_3_011_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ T, constant$<$ 1 $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01constant_3_011_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01T_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+division$<$ T, T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__division_3_01T_00_01T_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+minus$<$ T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01constant_3_010_01_4_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+minus$<$ minus$<$ constant$<$ 0 $>$ $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01constant_3_010_01_4_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01subtract_3_01Left_00_01Right_01_4_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+minus$<$ minus$<$ subtract$<$ Left, Right $>$ $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01subtract_3_01Left_00_01Right_01_4_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01T_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+minus$<$ minus$<$ T $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__minus_3_01minus_3_01T_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ Left, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_010_01_4_00_01Right_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ constant$<$ 0 $>$, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_010_01_4_00_01Right_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_011_01_4_00_01Right_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ constant$<$ 1 $>$, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_011_01_4_00_01Right_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_01ld8b2feb223452c4aaaf6eb83932601c0}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ constant$<$ left\+\_\+value $>$, multiply$<$ T, constant$<$ right\+\_\+value $>$ $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01constant_3_01ld8b2feb223452c4aaaf6eb83932601c0}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01First_00_01dive5d11c87e98ba09157b84506291511c8}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ First, divide$<$ constant$<$ 1 $>$, Second $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01First_00_01dive5d11c87e98ba09157b84506291511c8}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_010_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ Left, constant$<$ 0 $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_010_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_011_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ Left, constant$<$ 1 $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01Left_00_01constant_3_011_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01minus_3_01Firsc21300ab659abf99cc3eaf6c7230201c}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ minus$<$ First $>$, minus$<$ Second $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01minus_3_01Firsc21300ab659abf99cc3eaf6c7230201c}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01multiply_3_01Te3834a073b1fa2b6ff55d54d5efcdc27}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+multiplication$<$ multiply$<$ T, constant$<$ left\+\_\+value $>$ $>$, constant$<$ right\+\_\+value $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__multiplication_3_01multiply_3_01Te3834a073b1fa2b6ff55d54d5efcdc27}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+subtraction$<$ Left, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction_3_01Left_00_01minus_3_01Right_01_4_01_4}{numpp\+::differentiation\+::symbolic\+::impl\+::simplify\+\_\+subtraction$<$ Left, minus$<$ Right $>$ $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1impl_1_1simplify__subtraction_3_01Left_00_01minus_3_01Right_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1sinus}{numpp\+::differentiation\+::symbolic\+::sinus$<$ T $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1sinus}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1subtract}{numpp\+::differentiation\+::symbolic\+::subtract$<$ Left, Right $>$} }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1subtract}}{}
\item\contentsline{section}{\hyperlink{classtuple__element}{tuple\+\_\+element} \\*Tuple\+\_\+element specialization for \hyperlink{classnumpp_1_1vector}{numpp\+::vector} }{\pageref{classtuple__element}}{}
\item\contentsline{section}{\hyperlink{classtuple__element}{tuple\+\_\+element} \\*Tuple\+\_\+element specialization for \hyperlink{classnumpp_1_1matrix_1_1dense}{numpp\+::matrix\+::dense} }{\pageref{classtuple__element}}{}
\item\contentsline{section}{\hyperlink{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}{std\+::tuple\+\_\+element$<$ Index, numpp\+::matrix\+::dense$<$ T, Rows, Columns $>$ $>$} }{\pageref{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1vector_3_01T_00_01Size_00_01Transposition_01_4_01_4}{std\+::tuple\+\_\+element$<$ Index, numpp\+::vector$<$ T, Size, Transposition $>$ $>$} }{\pageref{classstd_1_1tuple__element_3_01Index_00_01numpp_1_1vector_3_01T_00_01Size_00_01Transposition_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classtuple__size}{tuple\+\_\+size} \\*Tuple\+\_\+size specialization for \hyperlink{classnumpp_1_1matrix_1_1dense}{numpp\+::matrix\+::dense} }{\pageref{classtuple__size}}{}
\item\contentsline{section}{\hyperlink{classtuple__size}{tuple\+\_\+size} \\*Tuple\+\_\+size specialization for \hyperlink{classnumpp_1_1vector}{numpp\+::vector} }{\pageref{classtuple__size}}{}
\item\contentsline{section}{\hyperlink{classstd_1_1tuple__size_3_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}{std\+::tuple\+\_\+size$<$ numpp\+::matrix\+::dense$<$ T, Rows, Columns $>$ $>$} }{\pageref{classstd_1_1tuple__size_3_01numpp_1_1matrix_1_1dense_3_01T_00_01Rows_00_01Columns_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classstd_1_1tuple__size_3_01numpp_1_1vector_3_01T_00_01Size_00_01Tranposition_01_4_01_4}{std\+::tuple\+\_\+size$<$ numpp\+::vector$<$ T, Size, Tranposition $>$ $>$} }{\pageref{classstd_1_1tuple__size_3_01numpp_1_1vector_3_01T_00_01Size_00_01Tranposition_01_4_01_4}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1variable}{numpp\+::differentiation\+::symbolic\+::variable$<$ T, Number $>$} \\*Class representing variable of any type }{\pageref{classnumpp_1_1differentiation_1_1symbolic_1_1variable}}{}
\item\contentsline{section}{\hyperlink{classnumpp_1_1vector}{numpp\+::vector$<$ T, Size, Transposition $>$} }{\pageref{classnumpp_1_1vector}}{}
\end{DoxyCompactList}


\chapter{Uncountable Sets}

In the previous chapter we proved that many sets are countable; moreover, we
proved that standard operations such as union, intersection, and product of
countable sets is also countable. This chapter shows that we know at least one
uncountable set. Moreover, this chapter gives tools to compare cardinalities of
sets.

\section{Cardinality of Reals}
\begin{theorem}[Cantor]
\label{theorem:reals-are-uncountable}
  The set of real number $\R$ is uncountable.
\end{theorem}

To prove this theorem we need the following two lemmas.
\begin{lemma}
\label{lemma:segment-is-uncountable}
  The set $\set[0 < x < 1]{x \in \R}$ of real numbers between $0$ and $1$ is
  uncountable.
\end{lemma}

\begin{lemma}
\label{lemma:segment-equipotent-to-reals}
  The set $\R$ is equipotent to $\set[0 < x < 1]{x \in \R}$.
\end{lemma}

\begin{proof}[Proof of \Cref{theorem:reals-are-uncountable}]
  Assume that $\R$ is denumerable. Then by
  \Cref{remark:denumerable-equipotent-to-denumerable,lemma:segment-equipotent-to-reals},
  $\set[0 \le x \le 1]{x \in \R}$ is also denumerable, which contradicts
  \Cref{lemma:segment-is-uncountable}.
\end{proof}

To complete the proof of \Cref{theorem:reals-are-uncountable} we need to prove
these two lemmas.
\begin{proof}[Proof of \Cref{lemma:segment-is-uncountable}]
  Assume $\set[0 < x < 1]{x \in \R}$ is countable; this implies that
  $S = \set[0 \le x \le 1]{x \in \R}$ is also countable.

  Note that each number $x \in S$ can be represented as an infinite decimal
  \[
    x = 0.a_1 a_2 a_3 \dots
  \]
  where $0 \le a_i \le 9$ for all $i \in \N$ (the number $1$ can be represented
  as $0.\dot{9}$).

  Let $f : \N \to S$ be a bijection, and let $f(n) = .a_{n, 1} a_{n, 2} \dots$.
  Consider the sequence $b_1$, $b_2$, \dots such that
  \[
    b_i =
    \begin{cases}
      0 & \text{if } a_{i, i} \neq 0 \\
      1 & \text{otherwise}
    \end{cases}.
  \]
  Let $y = 0.b_1 b_2 \dots$ and let $m \in \N$ be an integer such that $f(m) =
  y$. Note that
  \[
    .a_{m, 1} a_{m, 2} \dots = f(m) =  0.b_1 b_2 \dots
  \]
  However, $a_{m, m} \neq b_m$ which is a contradiction.
\end{proof}

\begin{proof}[Proof of \Cref{lemma:segment-equipotent-to-reals}]
  To prove this lemma we start from proving that $\R$ is equipotent to
  $\set[-\pi / 2 < x < \pi / 2]{x \in \R}$; indeed, we may consider the tangent
  function which is a bijection between these two sets.

  The next step is to note that the sets $\set[-\pi / 2 < x < \pi / 2]{x \in \R}$ and
  $\set[0 < x < 1]{x \in \R}$ are also equipotent. Consider the function
  $f : \set[0 < x < 1]{x \in \R} \to \set[-\pi / 2 < x < \pi / 2]{x \in \R}$
  such that $f(x) = \pi (x - 1 / 2)$. It is clear that $f$ is a bijection, which
  finishes the proof.
\end{proof}

\begin{exercise}
  Show that $(\set[0 < x < 1]{x \in \R})^2$ and $\set[0 < x < 1]{x \in \R}$ are equipotent.
\end{exercise}

\section{Inequalities Between Cardinalities}
Since $\N \subseteq \R$ the statement that $\R$ is uncountable can be
interpreted as `the set of reals is larger than the set of integers (or the set
of rationals)'. The following definition allows to make this reformulation
precise.
\begin{definition}
  Let $X$ and $Y$ be two sets.
  \begin{itemize}
    \item We say that $X$ and $Y$ have the same cardinality if they are
      equipotent; i.e., if $\cardinality{X} = \cardinality{Y}$.
    \item We write that $\cardinality{X} \ge \cardinality{Y}$ and say that the
      cardinality of $X$ is at most the cardinality of $Y$ if there is an
      injection from $X$ to $Y$.
    \item We also write $\cardinality{X} < \cardinality{Y}$ and say that the
      cardinality of $X$ is less than the cardinality of $Y$ if
      $\cardinality{X} \neq \cardinality{Y}$ and $\cardinality{X} \le
      \cardinality{Y}$.
  \end{itemize}
\end{definition}
Cantor's theorem says that $\cardinality{\R} > \cardinality{\N}$ or
$\cardinality{\R} > \aleph_0$.\footnote{%
  A quesiotn that immidiately come in mind after lookin at this reformulation is
  whether exists something in between; i.e., whether exists a set $S$ such that
  $\aleph_0 < \cardinality{S} < \cardinality{\R}$. The hypothesis that such a
  set exists is called \emph{the continuum hypothesis}. In 1963, Paul Cohen
  proved that it is not possible to prove or disprove thus hypothesis starting
  from axioms of the set theory.
}

Moreover, Cantor proved that there are even bigger sets
\begin{theorem}
  For any set $X$, $\cardinality{\subsets{X}} > \cardinality{X}$.
\end{theorem}
\begin{proof}
  The idea of this proof is simialr to the proof of Cantor's theorem
  (\Cref{theorem:reals-are-uncountable}).

  Firs of all we may notice that $\cardinality{\subsets{X}} \ge \cardinality{X}$
  since $f : X \to \subsets{X}$ such that $f(x) = \set{x}$ is an injection.

  It is also clear that the set $\subsets{X}$ is equipotent to the set
  $\functions{X}{\set{0, 1}}$ (this can be proven similarly to
  \Cref{corollary:power-set-and-set-of-binary-strings}).

  Let us now prove that $\cardinality{\functions{X}{\set{0, 1}}} \neq
  \cardinality{X}$. Assume this is not true and
  there is a bijection $F : X \to \functions{X}{\set{0, 1}}$. Let $f_x = F(x)$.
  Consider $g : X \to \set{0, 1}$ such that
  \[
    g(x) =
    \begin{cases}
      0 & \text{if } f_x(x) = 1 \\
      1 & \text{if } f_x(x) = 0 \\
    \end{cases}
  \]
  (note that for any $x$, $g(x) \neq f_x(x)$). It is clear that
  $g \in \functions{X}{\set{0, 1}}$; however, if $g = F(y) = f_y$, then $g(y) =
  f_y(y) \neq f_y(y)$, which is a contradiction. Therefore $F$ is not a bijection.
\end{proof}

We devoted the whole chapter to the pigeonhole principle, unsurprisengly one may
prove a similar theorem for infinite sets.\footnote{%
  This theorem is often called Schr\"{o}der--Bernstein theorem since Schr\"{o}der
  and Bernstein published independently proofs of this theorem in 1898. Cantor
  is often added because he first stated the result in 1887, while
  Schr\"{o}der's name is often omitted because his proof turned out to be
  flawed. Howerver, the name of Dedekind, who first proved it is not mentioned
  at all.
}
\begin{theorem}[Schr\"{o}der--Bernstein]
  Let $X$ and $Y$ be two nonempty sets such that $\cardinality{X} >
  \cardinality{Y}$. Then any function $f : X \to Y$ is not an injection; i.e.,
  there are $x_1, x_2 \in X$ such that $f(x_1) = f(x_2)$.
\end{theorem}

We are not going to prove this theorem; however, let us formulate a very
important corollary of this theorem.
\begin{corollary}
\label{corollary:schroder-bernstein}
  Let $X$ and $Y$ be two nonempty sets. If $\cardinality{X} \le \cardinality{Y}$
  and $\cardinality{Y} \ge \cardinality{X}$, then $\cardinality{X} =
  \cardinality{Y}$.
\end{corollary}

Using this theorem we may prove that
\[
  \cardinality{\set[x, y \in \R, x^2 + y^2 = 1]{(x, y)}} =
  \cardinality{\set[-1 \le x \le 1]{x \in \R}}.
\]
First of all note that
\[
  \set[x, y \in \R, x^2 + y^2 = 1]{(x, y)}
  \subseteq \set[-1 \le x \le 1]{x \in \R};
\]
hence
\[
  \cardinality{\set[x, y \in \R, x^2 + y^2 = 1]{(x, y)}} \le
  \cardinality{\set[-1 \le x \le 1]{x \in \R}}.
\]
In addition, one may prove using scaling and shift that
\[
  \cardinality{\set[-1 \le x \le 1]{x \in \R}} =
  \cardinality{\set[-\frac{1}{\sqrt{2}} \le x \le \frac{1}{\sqrt{2}}]{x \in \R}}.
\]
Finally,
\[
  \set[-\frac{1}{\sqrt{2}} \le x \le \frac{1}{\sqrt{2}}]{x \in \R}
  \subseteq
  \set[x, y \in \R, x^2 + y^2 = 1]{(x, y)}
\]
hence
\[
  \cardinality{
    \set[-\frac{1}{\sqrt{2}} \le x \le \frac{1}{\sqrt{2}}]{x \in \R}
  }
  \le
  \cardinality{
    \set[x, y \in \R, x^2 + y^2 = 1]{(x, y)}
  }.
\]
Combining all this together we can obtain that
\begin{gather*}
  \cardinality{
    \set[x, y \in \R, x^2 + y^2 = 1]{(x, y)}
  } \le
  \cardinality{\set[-1 \le x \le 1]{x \in \R}} \\
  \text{and}\\
  \cardinality{\set[-1 \le x \le 1]{x \in \R}} \le
  \cardinality{
    \set[x, y \in \R, x^2 + y^2 = 1]{(x, y)}
  }.
\end{gather*}
Hence, using the Schr\"{o}der–Bernstein theorem we can prove the equality.

\begin{chapterendexercises}
    \exercise[recommended] Prove that $\cardinality{\functions{X}{\set{0, 1}}} =
      \cardinality{2^X}$ for any set $X$.
    \exercise[recommended] Prove \Cref{corollary:schroder-bernstein}
    \exercise Show that $\functions{\N}{\set{0, 1}}$ is equipotent to
      $\functions{\N}{\set{0, 1, 2}}$.
      \begin{solution}
        We are going to prove it using Cantor-Bernstein theorem.
        Hence, the proof consists of two parts.
        \begin{enumerate}
          \item In the first part we prove that
            $\cardinality{\functions{\N}{\set{0, 1}}} \le
            \cardinality{\functions{\N}{\set{0, 1, 2}}}$. To prove this we need to show that
            there is an injection from $\functions{\N}{\set{0, 1}}$ to
            $\functions{\N}{\set{0, 1, 2}}$ and it is clear that
            $F :  \functions{\N}{\set{0, 1}} \to \functions{\N}{\set{0, 1, 2}}$
            such that $F(f) = f$ is an injection.
          \item In the second part we prove that
            $\cardinality{\functions{\N}{\set{0, 1, 2}}} \le
            \cardinality{\functions{\N}{\set{0, 1}}}$.
            To prove this we need to show that there is an
            injection from $\functions{\N}{\set{0, 1, 2}}$ to $\functions{\N}{\set{0, 1}}$.
            Let us consider
            $G : \functions{\N}{\set{0, 1, 2}} \to \functions{\N}{\set{0, 1}}$
            such that $G(f) = f'$, where
            \begin{gather*}
              h'(2n - 1) =
              \begin{cases}
                0 & \text{ if } h(n) \neq 2 \\
                1 & \text{otherwise}
              \end{cases} \\
              \text{and} \\
              h'(2n) =
              \begin{cases}
                0 & \text{ if } h(n) \neq 1 \\
                1 & \text{otherwise}.
              \end{cases}
            \end{gather*}
            We need to prove that this is an injection. Assume the opposite
            i.e. that $G(h_1) = G(h_2)$ but $h_1 \neq h_2$.
            There is $n$ such that $h_1(n) \neq h_2(n)$ since $h_1 \neq h_2$.
            Without loss of generality, it is enough to consider the following
            cases.
            \begin{itemize}
              \item If $h_1(n) = 0$ and $h_2(n) = 1$, then $G(h_1)(2n) = 0$
                and $G(h_2)(2n) = 1$ which is a contradiction.
              \item If $h_1(n) = 0$ and $h_2(n) = 2$, then
                $G(h_1)(2n - 1) = 0$ and $\mathcal{G}(h_2)(2n - 1) = 1$ which
                is a contradiction.
              \item If $h_1(n) = 1$ and $h_2(n) = 2$, then $G(h_1)(2n - 1) =
              0$ and $G(h_2)(2n - 1) = 1$ which is a contradiction.
            \end{itemize}
        \end{enumerate}
      \end{solution}
    \exercise Show that if a set $A \subseteq \R^2$ contains a line, then $A$
      and $\R$ are equipotent.
\end{chapterendexercises}


\section{Group Actions}
\begin{definition}
    Let $(G,\cdot,e)$ be a group and $S$ be a set.
    The action of $G$ on $S$ is a function $\star:G\times S\to S$ satisfying\\
    A1. $\forall x\in S,e\star x=x$.\\
    A2. $\forall g_1,g_2\in G, \forall x\in S, (g_1\cdot g_2)\star x=g_1\star(g_2\star x)$.
\end{definition}
\begin{example}
    1. $\forall g\in G, x\in S, g\star x=x$ always defines a group action.\\
    2. A group $G$ acts on the set $S=G$ by left multiplication.
    That is, via $g\star g'=g\cdot g'$.
    This is called the \textit{left regular action}.\\
    3. Consider $\operatorname{Sym}S$, it acts on $S$ by applying the permutation.\\
    4. The symmetries of a solid $X$ acts on the set of points of $X$ (or a special subset like the set of vertices).
    Note that the dihedral group $D_{2n}$ acts on an $n$-gon in this way.
\end{example}
\begin{definition}
    The orbit of $x\in S$ is the set
    $$G\star x=\{y\in X:\exists g\in G,y=g\star x\}$$
    If this set is equal to $X$, then this action is called transitive.
    The stabiliser of $x\in S$ is the set
    $$G_x=\{g\in G:g\star x=x\}$$
    The kernel is defined as
    $$\{g\in G:\forall x\in S,g\star x=x\}=\bigcap_{x\in S}G_x$$
    An action is faithful if its kernel is $\{e\}$.
\end{definition}
\begin{theorem}
    An action is the same as a homomorphism $\rho:G\to\operatorname{Sym}S$.
\end{theorem}
\begin{proof}
    The function $t_g:x\mapsto g\star x$ is a permutation of $X$ for any $g\in G$.
    Indeed, we can find an inverse of it which is exactly $t_{g^{-1}}$.
    Now we shall show that the map $\rho:g\mapsto t_g$ is an homomorphism.
    We can evaluate $\rho(gh)=t_{gh}$, but $t_{gh}(x)=(gh)\star x=g\star(h\star x)=t_g\circ t_h(x)$, therefore
    $$\rho(gh)=t_g\circ t_h=\rho(g)\rho(h)$$
    Conversely, let $\rho$ be an homomorphism, then consider the function $\star$ defined by $g\star x=(\rho(g))(x)$ is an action.
\end{proof}
Note that the same actions are corrsponded to the same homomorphism.
\begin{theorem}[Cayley's Theorem]
    Any group is isomorphic to a subgroup of some symmetric group.
\end{theorem}
\begin{proof}
    Consider the left regular action of the group $G$ on the set $G$.
    There is then a homomorphism $\rho:G\to \operatorname{Sym}G$.
    Now this action is faithful.
    Indeed, $\rho(g)=e\iff\forall x\in G, gx=x\iff g=e$ (Or simply we can write $g=ge=e$).\\
    Therefore this homomorphism is injective, hence $G\cong\operatorname{Im}\rho\le\operatorname{Sym}G$.
\end{proof}
We now want to dive deeper into orbits and stabiliser.
Let $G$ act on $X$.
\begin{theorem}
    For each $x\in X$, $G_x\le G$, and the collection of all orbits $G\star x$ for every $x\in X$ partitions $X$.
\end{theorem}
\begin{proof}
    Note that $e\in G_x$ for each $x$ so $G_x$ is nonempty.
    If $a,b\in G_x$, then $x=e\star x=(b^{-1}b)\star x=b^{-1}\star (b\star x)=b^{-1}\star x\implies b^{-1}\in G_x$.
    Therefore $(ab^{-1})\star x=a\star(b^{-1}\star x)=a\star x=x\implies ab^{-1}\in G_x$, so $G_x\le G$.\\
    Now the union of orbits contains each $x\in X$ since $x\in G\star x$.
    Now if $G\star x\cap G\star y\neq\varnothing$, there is some $g,h\in G$ such that $g\star x=h\star y$.
    Therefore for any $z\in G\star x$, then $z=k\star x$ for some $k\in G$, then $z=k\star((g^{-1})\star(h\star y))=(kg^{-1}h)\star y\implies z\in G\star y$.
    So $G\star x\subseteq G\star y$ and $G\star y\subseteq G\star x$, so $G\star x=G\star y$.
    Hence the orbits form a parition of $X$.
\end{proof}
What we have discussed so far is called the left action.
The right action $\diamond:X\times G\to X$ is defined analogously.
So $x\diamond e=x$ and $(x\diamond g)\diamond h=x\diamond (gh)$.
\begin{proposition}
    If $\diamond$ is a right action, then we can define a left action $\star$ by $g\star x=x\diamond g^{-1}$.
    We can also have the other way around.
\end{proposition}
\begin{proof}
    Trivial.
\end{proof}
So we can only use left actions during the scope of our study.
\begin{definition}
    If $G$ has a left action on $X$, the set of orbits is called $G\backslash X=\{G\star x:x\in X\}$.
    If $G$ has a right action on $X$, the set of orbits is called $X/G=\{x\diamond G:x\in X\}$
\end{definition}
\begin{example}
    The dihedral group $D_{2n}$ acts on the regular $n$-gon $X$ in the obvious way.\\
    The orbit of a vertex is then all vertices.
    The stabiliser of a vertex is the identity and the reflection across the axis which is the diagonal through the vertex.
    Note here that the size of the orbit times the size of stabiliser is the size of the dihedral group.\\
    Now consider a point in the interior of a side of the square.
    Then the orbit of this point would consist of $8$ points, and nothing stabilises it, so we also get that the product of the sizes of the orbit and the stabiliser is $8$, the size of the dihedral group.\\
    Let us now look at the symmetries of the tetrahedron with vertices $1,2,3,4$.
    Suppose the rotation across midpoints of opposite sides be $S$ and the rotation across the central axis through a vertex $R$.\\
    Let $V$ be the set of vertices and let this group act on it.
    Then it is obvious that this action is transitive, and the stabiliser of a vertex are the rotations with respect to the axis through that vertex.\\
    So again the sizes of the orbit and stabiliser give a product of $12$, the size of the group.\\
    Now we act on the set of edges $E$.
    Pick one of the edge $X$, then the action of the group on it is yet again transitive, and the stabilisers are the identity and the rotation $R$ on the midpoint of $E$ and its opposite edge.
    Again they give a product of $6\times 2=12$, the size of the group.
\end{example}
The preceding observation triggers the following theorem.
\begin{theorem}[Orbit-Stabiliser Theorem on finite groups]\label{ost_finite}
    $|G_x||G\star x|=|G|$
\end{theorem}
To prove it, we need some preparation.
\begin{proposition}
    If $H\le G$, the left regular action of $H$ on $G$ is the left multiplication of element in $H$ on $G$, i.e. $h\star g=hg$.
    The right regular action then is $g\diamond h=gh$
\end{proposition}
\begin{definition}
    A left coset of $H$ in $G$ is an orbit of the right regular action.
    Write $G/H$ to denote the collection of these cosets.\\
    We can define the right coset the other way around which are collected as $H\backslash G$.
\end{definition}
So each left coset is in the form $gH=\{gh:h\in H\}$, and the right coset in the form $Hg=\{hg:h\in H\}$.
Note that it is not always true that a left coset is equal to the right coset.\\
Also $G/H=\{S\subseteq G:\exists g\in G,S=gH\}$ and we can find $H\backslash G$ similarly.
\footnote{Some authors use $G:H$ for the collection of left cosets.}\\
Note that $gH=g'H\iff g'^{-1}g\in H$, and for right cosets $Hg=Hg'\iff g'g^{-1}\in H$ but again these two conditions may or may not be equivalent.
\begin{example}
    The (left and right) cosets of $2\mathbb Z$ are $2\mathbb Z$ and $2\mathbb Z+1=1+2\mathbb Z$.\\
    The (left and right) cosets of $n\mathbb Z$ are $k+n\mathbb Z, k\in\{0,1,\ldots n-1\}$.\\
    Consider $D_6$, $R=\{e,r,r^2\}, S=\{e,s\}$ are subgroups.
    The (left and right) coset of $R$ are $R$ and $sR=Rs$
    And the left cosets of $S$ are $S$, $rS$ and $r^2S$ and the right ones are $S$, $Sr$, $Sr^2$, but in this case the left and right cosets are not equal.
\end{example}
\begin{theorem}
    If $H\subset G$ and $g\in G$, then there is a bijection $H\to gH$.
\end{theorem}
\begin{proof}
    $h\mapsto gh$ is the bijection.
\end{proof}
\begin{corollary}[Lagrange's Theorem]\label{lagrange}
    If $G$ is finite and $H\le G$, then we have $|H||G/H|=G$.
    In particular $|H|$ divides $|G|$.
\end{corollary}
\begin{proof}
    The cosets are orbits thus parition $G$ and they are of the same cardinality due to the preceding theorem.
\end{proof}
We can repeat the same argument to see that the same also applies to right cosets.
\begin{definition}
    Let $G$ be a group, and $H\le G$, then the index of $H$ is the order of $G/H$ given that it is finite, otherwise we say the index is infinite.
\end{definition}
Equivalently, the index is $|G|/|H|$ (given that $H$ is finite).
\begin{corollary}
    If $G$ is finite and $g\in G$, then $g^{|G|}=e$, that is, $\operatorname{ord}g||G|$.
\end{corollary}
\begin{proof}
    Consider the subgroup $\langle g\rangle\le G$.
\end{proof}
\begin{corollary}
    If $G$ is finite $|G|$ is prime, then $G\cong C_p$ and it is generated by any identity element.
\end{corollary}
\begin{proof}
    $G$ contains some non-identity element since $|G|=p>1$.
    Choose any $g\in G$ such that $g\neq e$.
    Then $1<\operatorname{ord}g||G|=p$, so since $p$ is prime, then $\operatorname{ord}g=p$.
    Thus since $\langle g\rangle\le G$ and they are both finite and of the same order, $C_p\cong \langle g\rangle=G$.
\end{proof}
There is a corollary of this in number theory.
We consider the collection of all (equivalent classes) of integers $k\in\mathbb Z_n$ such that $(k,n)=1$.
Since $(k,n)=1$, $k$ is invertible in $\mathbb Z_n$ for any such $k$ in the collection.
Conversely, if $k$ cannot be invertible in $\mathbb Z_n$ if $(k,n)\neq 1$.\\
So this collection is a group $\mathbb Z_n^{\times}$ under multiplication modulo $n$.
Also, this group has order $\phi(n)$ which is the number of positive integers less than $n$ that are coprime to it.
\begin{corollary}[Fermat-Euler Theorem]
    If $(k,n)=1$, then
    $$k^{\phi(n)}\equiv 1\pmod{n}$$
\end{corollary}
\begin{proof}
    Apply the preceding corollary to $\mathbb Z_n^\times$.
\end{proof}
After these warm-ups, we shall prove the Orbit-Stabiliser Theorem (in a stronger form).
\begin{theorem}[Orbit-Stabiliser Theorem]
    Suppose a group $G$ acts on a set $X$ and $x\in X$, then there is a bijection $G/G_x\to G\star x$ by $\phi:gG_x\mapsto g\star x$.
\end{theorem}
\begin{proof}
    To see $\phi$ is well defined, observe that $\forall h\in G_x, g\star x=g\star (h\star x)=(gh)\star x$.
    It is obviously surjective by the definition of orbit.
    It is injective since if $\phi(gH)=\phi(g'H)$, then $(g^{-1}g')\star x=x\implies g^{-1}g'\in H\implies gH=g'H$.
\end{proof}
\begin{corollary}
    Theorem \ref{ost_finite}.
\end{corollary}
\begin{proof}
    Due to the existence of this bijection, if $G$ is finite, then $|G|/|G_x|=|G/G_x|=|G\star x|\implies |G\star x||G_x|=|G|$.
\end{proof}
One of the most important application of this theorem is to work out the order of some finite group.
\begin{example}
    We look at the rotational symmetries of a cube.
    Collect the symmetries as the group $G$ and consider its action on the eight vertices $X$.
    Now this action is transitive, obviously, so fixing any $x\in X$, $|G\star x|=8$.
    Also, any member of the stabiliser of $x$ must be rotations though the axis through $x$ and the centre of the centre of the group since it fixes that.
    There are three rotations of this form, so $|G|=|G_x||G\star x|=24$.
\end{example}
\begin{theorem}[Cauchy's Theorem]\label{cauchy}
    Let $G$ be a finite group and suppose $p$ is a prime dividing its order, then $G$ contains an element of order $p$.
\end{theorem}
\begin{proof}
    Consider a subset $X\subseteq G^p$ defined by $X=\{(g_1,g_2,\ldots, g_p)\in G^p:g_1g_2\cdots g_p=e\}$.
    Since $|G^p|=|G|^p$, and $|X|=|G|^{p-1}$.
    Let $H=C_p=\langle\xi\rangle$, consider the action of $H$ on $X$ by
    $$\xi\star (g_1,g_2,\ldots,g_p)=(g_2,g_3,\ldots,g_p,g_1)$$
    This is an action, indeed, if $g_1g_2\cdots g_p=e$, then $g_2g_3\cdots g_pg_1=g_1^{-1}eg_1=e$.
    For any element $x\in X$, by Theorem \ref{ost_finite}, $p=|H|=|H_x||H\star x|$.
    But $p$ is prime, so every orbit has to have either size $1$ or size $p$, also the ordrs of the orbits sum to $|X|=|G|^{p-1}$ which is divisible by $p$.
    So the number of size $1$ orbits must be divisible by $p$, thus at least $2$.
    But all such orbits must be in the form $(g,g,\ldots, p)$, but since there are $2$ of them, there is some $g\neq e$ such that this tuple is in $X$, thus $g^p=e$ and $g\neq e$, therefore $g$ has order $p$.
\end{proof}
In fact, we have shown that the number of elements of order $p$ is congruent to $p-1\pmod{p}$.
\begin{definition}
    Fix a group $G$.
    $a,b\in G$ are conjugates of each other if $\exists g\in G, a=gbg^{-1}$.\\
    The conjugation action is an action of a group $g$ on itself by $g\star h=ghg^{-1}$.
\end{definition}
One can check that the conjugation is indeed an action.
\begin{definition}
    The orbits of the conjugation are called the conjugacy classes of $G$.
    The stabiliser of the conjugation of an element $h$ is called the centraliser $C_G(h)$ of $h$.
    The kernel of the conjugation action is called the centre $Z(G)$ of $G$.
\end{definition}
We can extend the conjugation action to the subgroups of $G$.
\begin{definition}
    If $H\le G$, then the conjugate of $H$ by $g$ is the subgroup $\{ghg^{-1}:h\in H\}$.
\end{definition}
It is trivial that the conjugate of a subgroup is indeed a subgroup.


\section*{Discrete Choice (Threshold) Problems}\label{SecDiscrChoice}

One powerful application of dynamic programming that illustrates its versatility as a dynamic solution method is to models that have both continuous and discrete state variables. These models are sometimes referred to as discrete choice problems or optimal stopping problems.  Examples include models of employment that involve both the choice of whether to work and how much to work, models of firm entry and exit that involve the choice of both whether to produce and how much to produce, and models of marriage that involve the choice of whether to date (get married or keep dating) and how much to date.

In this problem set, we follow a simple version of a standard job search model.  Assume that workers are infinitely lived. Let the value of entering a period with most recent wage $w$, current job offer wage $w'$, and employment status $s$ be given by the following value function,
\begin{equation}\label{EqV}
   V(w,w',s) = \begin{cases}
                  V^E(w)    \quad&\text{if}\quad s = E \\
                  V^U(w,w') \quad&\text{if}\quad s = U \\
               \end{cases}
\end{equation}
where employment status is a binary variable $s=\{E,U\}$; a person can be either employed or unemployed.

If an individual's job status is employed ($s = E$) in a given period, then expected utility is the utility of consumption in the current period plus the discounted expected value of the entering the next period with wage $w$, job offer wage $w''$, and employment status $s'$.
\begin{equation}\label{EqVe1}
   V^E(w) = u(w) + \beta E_{w'',s'}V(w,w'',s')
\end{equation}
Here we assume that individuals spend all of their earnings each period so that utility from the consumption in the current period is $u(w)$.  The discount factor is $\beta$.  The next periods wage, $w''$, and job offer, $s'$, are unknown and we consider them as random variables.  Consequently, the expectations operator $E_{w'',s'}$ is over the job offer wage, and employment status in the next period, and next period's value function is simply \eqref{EqV} with the future value of employment status $s'$.

The joint probability distribution over $w''$ and $s'$ is characterized in the following simple way. If the worker stays employed in the next period $s' = E$, then next period's wage equals the current period's wage. If the worker becomes unemployed in the next period $s' = U$, then the worker's unemployment benefits will be a percentage of his current wage $\alpha w$. Any worker who is unemployed will receive one wage offer per period $w'$, which that worker will receive in the following period, drawn from the cumulative density function $F(w')$ or probability density function $f(w')$, which is independent of the worker's previous wage (for simplicity). Lastly, let $\gamma$ represent the probability that an employed worker becomes unemployed in the next period. So \eqref{EqVe1} can be rewritten in the following way.
\begin{equation}\label{EqVe2}
   V^E(w) = u(w) + \beta \Bigl[(1-\gamma)V^E(w) + \gamma E_{w''}V^U(w,w'')\Bigr]
\end{equation}

The value of being unemployed in a given period is a function of both the wage at the most recent job $w$ as well as the wage of the current job offer $w'$,
\begin{equation}\label{EqVu}
   V^U(w,w') = u(\alpha w) + \beta\max_{s'\in\{E,U\}}\Bigl\{V^E(w'),E_{w''}\left[V^U(w,w'')\right]\Bigr\}
\end{equation}
where $\alpha\in(0,1)$ is the fraction of the worker's previous wage paid in unemployment insurance benefits. The maximization in \eqref{EqVu} reflects the decision of whether to accept the current job offer or remain unemployed for another period.  It is only in the unemployed state $s=U$ in which the worker makes a decision. Once the job offer ($w'$) is received, the worker can choose whether to accept or reject the offer. The expectation in \eqref{EqVu} is, therefore, not over $w'$ but over the possible job offers in the following period, $w''$; if the worker chooses to reject the current job offer, then $s' = U$.

The policy function for the decision of the unemployed worker whether to accept a job $s'=E$ or whether to reject a job $s'=U$ will be a function of both the amount of the most recent wage $w$ and the amount of the current job offer: $s' = \psi(w,w')$. These discrete choice problems are often called threshold problems because the policy choice depends on whether the state variable is greater than or less than some threshold level. That is, an unemployed worker will accept a job if and only if the offer wage is above some set amount. In the labor search model, the threshold level is called the ``reservation wage'' $w_R'$. The reservation wage $w_R'$ is defined as the wage offer such that the worker is indifferent between accepting the job $s' = E$ and staying unemployed $s' = U$.
\begin{equation}\label{EqWR}
   w_R' \equiv w': V^E(w') = E_{w''}\left[V^U(w,w'')\right]
\end{equation}
Note that the reservation wage $w_R'$ is a function of the wage at the most recent job $w$ (if you have higher unemployment benefits you will wait for a higher job offer). The policy function will then take the form of accepting the job if $w' \geq w_R'$ or rejecting the job offer and stay unemployed if $w' < w_R'$.
\begin{equation}\label{EqSprime}
   s' = \psi(w,w') = \begin{cases}
                      E \quad\text{if}\quad w' \geq w_R' \\
                      U \quad\text{if}\quad w' < w_R'
                   \end{cases}
\end{equation}

In summary, the labor search discrete choice problem is characterized by the value functions \eqref{EqV}, \eqref{EqVe2}, and \eqref{EqVu}, the reservation wage \eqref{EqWR}, and the policy function \eqref{EqSprime}. Because wage offers are distributed according to the cdf $F(w')$ and because the policy function takes the form of \eqref{EqSprime}, the probability that the unemployed worker receives a wage offer that he will reject is $F(w_R')$ and the probability that he receives a wage offer that he will accept is $1 - F(w_R')$. Just like the continuous choice cake eating problems, this problem can be solved by value function, policy function, or modified policy function iteration.

The value function iteration solution method for the equilibrium in the labor search problem is analogous to the value function iteration from the previous labs. The only difference is that two value functions ($V^E$ and $V^U$) must converge to a fixed point in this problem instead of just one value function converging in the previous problems.  Although there are two value functions to consider, there is only one policy function since decisions are only made in the unemployed state.  Thus there is only one policy function to iterate on in the case of policy or modified policy iteration.

Assume that the probability of becoming unemployed in a given period is $\gamma = 0.10$, the fraction of wages paid in unemployment benefits is $\alpha = 0.5$, and the discount factor is $\beta = 0.9$. Assume that the log of wage offers are distributed normally.  We then say that offers are distributed lognormally and write $w'\sim \text{LogN}(\mu,\sigma)$.  We let $m=20$ be the mean wage, $v=400$ be the variance of the wage.  Often lognormal distributions are reported with the mean and variance of $\log(w')$ which is distributed normally, but for simplicity you will not have to deal with that here. This is a convenient choice for the distribution of wage offers.  Among other things, it guarantees that wage offers will be positive.  Denote the cdf of the lognormal distribution as $F(w')$ and the pdf of the distribution as $f(w')$.

\vspace{5mm}

\begin{problem}
\begin{enumerate}

   \item Approximate the support of $w\in(0,\infty)$ by generating a column vector of possible values for $w$. Let the maximum value be $w_{max} = 100$, let the minimum value be $w_{min} = 0$, and let the number of equally spaced points in the vector be $N = 500$. Let the wage of a job offer in any period be lognormally distributed with mean job offer of $m=20$ and variance $v =200$.  Generate the discrete approximation of the lognormal probability density function $f(w')$ using the function defined in discretelognorm.py which is provided.  As arguments, it takes the points where the approximation is needed (w), along with the mean and variance so that it can be called as

\begin{lstlisting}[style=python]
f = discretelognorm(w,m,v)
\end{lstlisting}

    Then the $n$th entry of $f$ represents the probability that the job offer in the next period equals the $n$th entry of $w$, $\text{Pr}(w' = w_n)$.

   \item Solve for the equilibrium optimal policy function $s' = \psi(w,w')$ by value function iteration.  In this case we iterate on both value functions $V^E$ and $V^U$ each time through the loop.  In order to compute the expected value of $V^U$, just matrix multiply $V^U$ and $f$. Remember, the policy function $\psi(w,w')$ gives the choice of whether to accept the job offer if unemployed with a given previous wage and current job offer.  Thus it will be a vector of length $N$ of zeros and ones.  Again, use a tolerance level of $10^{-9}$ and require that both value functions must converge (compute a delta for each and iterate until both are less than $10^{-9}$).

   \item Compute the reservation wage $w_R'$ as a function of the current wage $w$.  The reservation wage is the value of $w$ where the policy function changes from zeros to ones (the optimal choice changes from remaining unemployed to accepting the job offer).  If psi is an $N\times N$ matrix representing the policy function, the reservation wage wr could be computed as follows
   \begin{lstlisting}[style = python]
    wr_ind = sp.argmin(sp.diff(psi), axis = 1)
    wr = w[wr_ind]
   \end{lstlisting}
	where the rows of psi correspond to values of $w$ and the columns correspond to values of $w'$.

   \item Plot the equilibrium reservation wage $w_R'$ of the converged problem as a function of the current wage $w$ with the current wage on the $x$-axis and the reservation wage $w_R'$ on the $y$-axis. This is the most common way to plot discrete choice policy functions. The reservation wage represents the wage that makes the unemployed worker indifferent between taking a job offer and rejecting it. So any wage above the reservation wage line represents $s' = E$ and any wage below the reservation wage line represents $s' = U$.

\end{enumerate}
\end{problem}

In the previous problem, it was necessary to iterate on two value functions.  Consequently the convergence is relatively slow.  Thus the gains by using modified policy function iteration are considerable.

\begin{problem}
Solve the same problem, this time using modified policy function iteration with $m=15$ value function iterations within each policy iteration.  Roughly, you can structure your code as follows:

\begin{enumerate}
	\item Initialize $w$,$u(\alpha w)$, $f$, $\gamma$, and $\beta$.  This should be the same as the previous problem.

	\item	Initialize $V^E$, $V^U$, and $E[V^U]$ to zeros.  Then begin the while loop.

	\item Inside the while loop update the policy function.  It is determined as
	\begin{equation}
		\psi (w,w') = \text{argmax} \left\{ V^E(w'), E_{w''}[V^U(w,w'')]\right\}
	\end{equation}

	\item Begin a for loop to iterate on the value functions.  Unlike in the previous algorithms lab, there is no $Q$ matrix in this case.  Given the previous iteration's value functions, updating $V^E$ should be simple because it does not depend directly on the policy function.

	To iterate on $V^U$, we need to compute $V^U$ given the current policy.  The policy determines the maximization in equation \eqref{EqVu}.  One way to compute the max is to use $\psi$ as a mask.  $V^U$ could be computed as follows:

	\begin{lstlisting}[style = python]
	arg1 = sp.repeat(sp.transpose(VE),N,0)*(1-psi)
    arg2 = sp.repeat(EVU,N,1)*psi
    arg = arg1+arg2
    VUprime = alpha_util_grid + beta*arg
	\end{lstlisting}
\newpage
	where the ordering is such that $1$ corresponds to the state $E$ and $0$ corresponds to the state $U$.

	\item Compute the $\delta$'s.

	\item After the while loop you should compute the reservation wage and plot it.
\end{enumerate}
\end{problem}

\begin{problem}
How many iterations did value function iteration take?
How many iterations did modified policy function iteration take?
Which was faster?
\end{problem}


\chapter[Quadrature]{Numerical Quadrature}

\section{Introduction}

There are many circumstances in mathematical modelling when we need to
evaluate an integral, like
%
\begin{equation}
 \mint{a}{b}{f(x)}{x} .\label{Qua:eq:1}
\end{equation}
%
However, the integrals that can be evaluated analytically are few and
many integrals of great interest in engineering, like, for example,
the error function,
%
\begin{equation}
 \mbox{Erf}(x) = \mint{-\infty}{x}{e^{-\xi^2}}{\xi} \label{Qua:eq:2}
\end{equation}
%
can only be evaluated numerically.

We discuss two major techniques to evaluate integrals
(\textit{quadrature}): the first is based on \textit{interpolation},
the second on \textit{Gaussian quadrature}.

\section{Polynomial interpolation}

If we want to work with any function $f(x)$ numerically we must expect
to represent it using a finite amount of information. Typically this
is done by assuming that we know only the value of the function at a
finite set of points, call \textit{nodes}, $\{x_j\}$, with
$j=0,\ldots,N$. We denote the function values $f_j \equiv f(x_j)$.

One standard approach is to approximate the function $f$ by another
function $g(x)$ which is easy to manipulate and \textit{interpolates}
$f$ at the nodes, i.e.
%
\begin{equation}
  g(x_j) = f_j = f(x_j), \quad j = 0, \ldots, N.
\end{equation}
%
We then use $g$ in place of $f$ wherever necessary, as we shall see
below.

One standard, simple choice of \textit{interpolating function} $g(x)$
is a polynomial. Given the $N+1$ values $f_j$ at the nodes $x_j$ there
is a \emph{unique} polynomial $g$ of order $N$ that interpolates $f$
(as should be clear, as a polynomial of order $N$ has $N+1$
coefficients to be fixed). There are two standard forms of writing
this polynomial explicitly. Here we just show the Lagrange form to
show the explicit construction is possible. Often the Newton form is
used in numerical calculations instead.

First, given the nodes $x_j$, define the \textit{fundamental
  polynomials} $\ell_j(x)$ by
%
\begin{equation}
  \ell_j(x) = \prod_{\substack{i = 0\\i \ne j}}^N \frac{x - x_i}{x_j -
    x_i}, \quad j = 0, 1, \dots, N.
\end{equation}
%
These have the property that $\ell_j(x_j) = 1$ and $\ell_j(x_k) = 0, j
\ne k$. It follows that
%
\begin{equation}
  g(x) = \sum_{j=0}^N f(x_j) \ell_j(x)
\end{equation}
%
is the polynomial of degree $N$ that interpolates the function $f(x)$
at the nodes $x_j$.

In what follows we shall see methods for solving quadrature and
differential equations based on polynomial interpolation. For these
the defining features are the locations of the nodes and the order of
the interpolating polynomial. In many cases the formulas will simplify
greatly from the general Lagrange form above, so each case is treated
separately.

\section[Using polynomial interpolation]{Numerical integration based on polynomial interpolation}

\subsection{Introduction}

We assume that we can evaluate the function at a finite set of points,
called \textit{nodes}, $\{x_j\}$, with $j=0,\ldots, N$ in the interval
$[a,b]$ and we want to estimate~(\ref{Qua:eq:1}).  The idea behind all
the methods based on polynomial interpolation is that we can replace
the function $f(x)$ with a simpler function $g(x)$, i.e.\ a function
whose integral we can evaluate analytically.  We require that the
function $g(x)$ \textit{interpolates} the function $f(x)$, i.e.\ that
it has the same value as $f(x)$ at the nodes:
%
\begin{equation}
  g(x_j) = f(x_j) , \qquad j = 0,1,\ldots,N. \label{Qua:eq:3}
\end{equation}
%
The simplest choice of class of functions $g(x)$ are polynomials and
the different quadrature interpolation methods are differentiated by
the order of the polynomial interpolation.  Formulae based on
polynomial interpolation with equally spaced nodes go under the
generic name of \textit{Newton-Cotes formulae}.

\subsection{Trapezoidal rule}

\begin{figure}
  \centerline{\includegraphics[width=135mm]{figures/trapez}}
  \caption{\label{fig:trapez} \it The trapezoidal rule is based on the
    approximation of the given function $f(x)$ with an order one
    polynomial (left).  In general one uses a composite trapezoidal
    rule: the integration range is divided in intervals of length $h$
    and the function is approximated by a different polynomial on each
    interval (right).}
\end{figure}

The simplest case results if we choose an interpolating polynomial of
order one, i.e.\ we replace the function with a straight line that
interpolates the function at the end points of the integration range
(see left panel of Figure~\ref{fig:trapez}).   The area under the line
is given by
%
\begin{equation}
  A = \frac{1}{2} (b-a) [f(a) + f(b)]
  \label{Qua:eq:32}
\end{equation}
%
and this is the approximate value of~(\ref{Qua:eq:1}) according to the
\textit{trapezoidal rule}.  It is clear that unless the range $[a,b]$
is very small the error in the estimate obtained using the trapezoidal
rule is very large.  The standard procedure is to make use of the
\textit{composite trapezoidal rule}: the integration range is divided
into $N$ intervals of length $h$ and the function $f(x)$ is
approximated on each interval by a straight line that interpolates the
function at the nodes (see right panel of Figure~\ref{fig:trapez}).
The area under each segment of the piecewise linear curve is
%
\begin{equation}
  A_j = \frac{1}{2} (x_{j}-x_{j-1}) [f(x_{j})+f(x_{j-1})] , \quad
  j = 1,2, \ldots, N.
  \label{Qua:eq:4}
\end{equation}
%
By summing all the areas we obtain the composite trapezoidal rule:
%
\begin{equation}
  \mint{a}{b}{f(x)}{x} = \sum_{j=1}^{N} A_j =
  \frac{1}{2} \sum_{j=1}^{N} (x_{j}-x_{j-1}) [f(x_{j})+f(x_{j-1})]
  \label{Qua:eq:5}
\end{equation}
%
If the nodes are equally spaced, i.e.\ if $(x_{j}-x_{j-1}) = h$ for all
$j=1, \ldots, N$, this formula reduces to:
%
\begin{equation}
 \mint{a}{b}{f(x)}{x} =
  \frac{h}{2} \sum_{j=1}^{N} [f(x_{j})+f(x_{j-1})] =
  \frac{h}{2} ( f_0 + 2 f_1 + 2 f_2 + \ldots + 2 f_{N-1} + f_N ) ,
\label{Qua:eq:12}
\end{equation}
%
where $f_j \equiv f(x_j)$.  The error in the approximation is given by
%
\begin{equation}
  \text{Error} \le \frac{1}{12} h^3 N M_2 =
  \frac{(b-a) h^2}{12} M_2 , \qquad
  M_2 = \max_{x\in[a,b]} |f''(x)| .
  \label{Qua:eq:6}
\end{equation}

\subsection{Simpson's rule}

\begin{figure}
  \centerline{\includegraphics[width=135mm]{figures/simpson}}
  \caption{\label{fig:simpson} \it Simpson's rule is based on the
    approximation of the given function $f(x)$ with an order two
    polynomial (left).  In general one uses a composite Simpson's
    rule: the integration range is divided in intervals of length $2
    h$ and the function is approximated by different parabolas on each
    interval.}
\end{figure}

In this case the function is approximated with a polynomial of order
two (a parabola, see left panel of Figure~\ref{fig:simpson}).  We can
obtain the formula for the quadrature by writing the interpolating
polynomial and integrating it.  It turns out that the area under the
parabola is given by
%
\begin{equation}
  A = \frac{b-a}{6}
  \left [ f(a) + 4 f\left(\frac{a+b}{2}\right) + f(b) \right ],
  \label{Qua:eq:33}
\end{equation}
%
and this is the approximate value of~(\ref{Qua:eq:1}) according to
\textit{Simpson's rule}.  It is clear that unless the range $[a,b]$ is
very small the error in the estimate obtained using the trapezoidal
rule is very large.  The standard procedure is to make use of the
\textit{composite Simpson's rule}: the integration range is divided
into $N/2$ intervals of length $2 h$, with $N$ an even number. The
function $f(x)$ is approximated on each interval by a parabola that
interpolates the function at the nodes (see right panel of
Figure~\ref{fig:simpson}).  For simplicity we assume that the
interpolation points $\{x_j\}$, $j=0,1,2,\ldots,N$ are all equally
spaced so that we can write:
%
\begin{equation*}
  x_j = x_0 + j h .
\end{equation*}
%
The area under the parabola joining the nodes $x_{j-1}$, $x_{j}$ and
$x_{j+1}$ is
%
\begin{equation}
  A_j = \frac{h}{3} \left[f(x_{j-1})+4f(x_{j})+f(x_{j+1})\right]
  \label{Qua:eq:9}
\end{equation}
%
where $j=1,3,5,\ldots, N-1$.  This result is known as
\textit{Simpson's rule}.  If we apply it to all the sub-intervals in
$[a,b]$ we obtain the composite Simpson rule:
%
\begin{equation}
  \mint{a}{b}{f(x)}{x} = \sum_{k=1}^{N/2} A_{2k-1} =
  \frac{h}{3} \left[ f(a) +
    2 \sum_{j=1}^{N/2-1} f(x_{2j}) +
    4 \sum_{j=1}^{N/2} f(x_{2j-1}) + f(b) \right] + R,
  \label{Qua:eq:10}
\end{equation}
%
where the estimate for the error is given by
%
\begin{equation}
  |R|\le \frac{M_4}{180}(b-a)h^4,\label{Qua:eq:11}
\end{equation}
%
where $M_4=\max|f^{(4)}(x)|$ with $a \le x \le b$.  Note that
Simpson's rule is exact for any cubic polynomial as $f^{(4)}(x) \equiv
0$ for all polynomials of order three.

We can obtain an estimate of the error by proceeding as follows.  We
compare the Taylor expansion of Simpson's rule for the integral in the
range $[x_{j-1},x_{j+1}]$, given by equation~(\ref{Qua:eq:9}), to the
Taylor expansion of the exact integral.  The error is the first term
in the difference of the two Taylor expansions.  We start with the
Taylor expansion of the Simpson's rule estimate of
%
\begin{equation}
  \mint{x_{j-1}}{x_{j+1}}{f(x)}{x} \simeq A_j =
  \frac{h}{3} [ f(x_{j-1}) + 4 f(x_{j}) + f(x_{j+1}) ] ,
  \label{Qua:eq:19}
\end{equation}
%
where, to simplify the notation, we use the notation $f_j=f(x_j)$,
$f'_j=f'(x_j)$, and, in general, $f^{(n)}_j$ for the $n$-th derivative
of $f(x)$ evaluated at $x=x_j$.  Using Taylor's theorem to expand
$f(x)$ at $x=x_j$ we can write
%
\begin{equation}
  A_j = 2 h f_j + \frac{h^3}{3} f_j'' + \frac{h^5}{36} f_j^{(4)} + \order{h^6}
  \label{Qua:eq:20}
\end{equation}
%
We now need to compute the Taylor expansion in powers of $h$ of the
exact result.  In order to do this we introduce the function
%
\begin{equation}
  F(t) = \mint{x_j-t}{x_j+t}{f(x)}{x} .
  \label{Qua:eq:21}
\end{equation}
%
Note that with this notation
%
\begin{equation}
  \mint{x_{j-1}}{x_{j+1}}{f(x)}{x} = F(h).
  \label{Qua:eq:14}
\end{equation}
%
Therefore, in order to compute the Taylor expansion in powers of $h$
of the exact result of the integral in equation~(\ref{Qua:eq:14}), we
need to expand $F(t)$ in Taylor series around $t=0$:
%
\begin{equation}
  F(h) = F(0) +
  h \eval{\dv{F}{t}}_{t=0}  +
  \frac{h^2}{2} \, \eval{\dv[2]{F}{t}}_{t=0}  +
  \ldots +
  \frac{h^5}{5!} \, \eval{\dv[5]{F}{t}}_{t=0} +
  \order{h^6}
  \label{Qua:eq:15}
\end{equation}
%
We note that $F(0)=0$.  Moreover, by the fundamental theorem of
calculus (with a little help from the chain rule)
%
\begin{equation*}
  \dv{F}{t} = f(x_j+t) + f(x_j-t) \implies
  \dv[n]{F}{d} = f^{(n-1)}(x_j+t) +
  (-1)^{n+1} f^{(n-1)}(x_j-t) .
\end{equation*}
%
Note that all the even derivatives of $F(t)$ are zero at $t=0$ so that
the Taylor expansion of~(\ref{Qua:eq:15}) becomes
%
\begin{equation}
  2 h f_j + \frac{h^3}{3} f_j'' + \frac{h^5}{60} f_j^{(4)} + \order{h^6}.
  \label{Qua:eq:30}
\end{equation}
%
Combining these two expansions, we have that the local error in the
interval $[x_{j-1},x_{j+1}]$ is, up to order $h^6$,
%
\begin{equation}
  E_j \equiv F(h) - A_j = - \frac{1}{90} h^5 f_j^{(4)} \implies
  \abs{E_j} \le \frac{1}{90} h^5 M_4 ,
  \label{Qua:eq:31}
\end{equation}
%
where $M_4$ is the same as in equation~(\ref{Qua:eq:11}).  Summing the
local errors over all the intervals used in the composite Simpson's
rule gives the total error, $R$,
%
\begin{equation}
  \abs{R} = \abs{\sum_{k=1}^{N/2} E_{2k-1}} \le
  \sum_{k=1}^{N/2} \abs{ E_{2k-1} } \le
  \sum_{k=1}^{N/2} \frac{1}{90} h^5 M_4 = \frac{M_4}{180}(b-a)h^4.
\end{equation}

\subsection{Richardson extrapolation}

This is a very general technique that uses the information on the rate
of decrease of the error to get a better estimate of the numerical
result required.  As such it can be applied to many different
algorithms, not just quadratures.  However, here we illustrate it in
the context of Simpson's rule.

Equation~(\ref{Qua:eq:11}) tells us that the error on the estimate of
the integral decreases with the fourth power of the integration step,
$h$.  However, in order to estimate the error using this formula we
would also need the value of the coefficient $M_4$.  We can get round
this problem by using the following procedure.  Indicate with $I_n$
the estimate of the integral using $n$ intervals and with $I$ the
exact value of the integral.  From~(\ref{Qua:eq:11}) we have that
%
\begin{equation}
  I - I_{2n} \simeq C (2n)^{-4} =
  2^{-4} \left ( C n^{-4} \right ) \simeq 2^{-4} (I - I_n) .
  \label{Qua:eq:16}
\end{equation}
%
In this last step we have assumed that the constant $C$ is the same
whether we use $n$ or $2n$ intervals to estimate the integral.  This
not strictly true, but it is a reasonable approximation if the
integration range is small enough.  From~(\ref{Qua:eq:16}) we have
that the exact value of the integral is approximately
%
\begin{equation*}
  I \simeq \frac{2^4 I_{2 n} - I_n}{2^4 -1}
\end{equation*}
%
and we use this as the new estimate of the integral
(\textit{Richardson extrapolated value}):
%
\begin{equation}
  R_{2 n} = \frac{2^4 I_{2 n} - I_n}{2^4 -1} .
  \label{Qua:eq:22}
\end{equation}
%
The error in the approximation is roughly
%
\begin{equation}
  E_{2n} \equiv \abs{ R_{2 n} - I_{2 n} } = \frac{\abs{I_n - I_{2 n}}}{2^4 -1} .
  \label{Qua:eq:17}
\end{equation}
%
This quantity is called the \textit{computable estimate of the error}.

\subsection{Adaptive quadrature}

Adaptive quadrature methods are intended to compute definite integrals
to a given precision by automatically choosing a set of nodes that
takes into account the behaviour of the integrand by being denser
where the integrand varies more rapidly. Ideally, the user supplies
only the integrand $f$, the interval $[a,b]$, and the accuracy
$\epsilon$ desired for computing the integral
%
\begin{equation}
  \mint{a}{b}{f(x)}{x} . \label{Qua:eq:23}
\end{equation}
%
The program then divides the interval into sub-intervals of varying
length so that numerical integration on these sub-intervals will
produce results of acceptable precision. The main idea is that if
Simpson's rule on a given sub-interval is not sufficiently accurate,
that interval will be divided into two equal parts, and Simpson's rule
will be used on each half. This procedure will be repeated in an
effort to obtain an approximation to the integral with the same
accuracy over all the sub-intervals involved.  A rough algorithm is as
follows:

\begin{enumerate}
  %
\item Compute the integral~(\ref{Qua:eq:23}) using $3$ points and
  estimate the global error.  If the error is smaller than the
  tolerance stop.
  %
\item Divide the interval into two equal parts.  Consider each part in
  turn.
  %
\item Compute the integral on the sub-interval using $3$ points,
  i.e.\ using a finer grid.
%
\item Estimate the error on the evaluation of the integral over the
  sub-interval.  If it is larger than the maximum acceptable local
  error then divide the sub-interval in two and start again from point
  (2).  Otherwise go to point (3) and work on the next sub-interval if
  there are any left.
%
\end{enumerate}

In order to apply this idea we need to firstly to estimate the
\textit{local error}: we can do this using Richardson's extrapolation
and equation~(\ref{Qua:eq:17}).  Secondly, we need to estimate the
\textit{global error} on the integration over the entire interval
$[a,b]$ as a function of the local errors.

\smallskip

\noindent
We indicate with $e_i$ the local error on the integration over the
segment $[x_{i-1},x_i]$. If
%
\begin{equation}
  \abs{e_i} \le \epsilon (x_i-x_{i-1})/(b-a),
  \label{Qua:eq:25}
\end{equation}
%
then the total error will be bounded by
%
\begin{equation}
  \abs{ \sum_{i=1}^n e_i} \le \sum_{i=1}^n \abs{e_i} \le
  \frac{\epsilon}{b-a} \sum_{i=1}^n (x_i-x_{i-1}) = \epsilon.
  \label{Qua:eq:26}
\end{equation}
%
Therefore in the adaptive quadrature algorithm outlined above we have
to ensure that the local error satisfies~(\ref{Qua:eq:25}).

\section{Gaussian Quadrature}

The aim of all quadrature techniques is to create formulae of the type
%
\begin{equation}
  \mint{a}{b}{f(x)}{x} \simeq \sum_{i=1}^n w_i f(x_i) .
 \label{Qua:eq:18}
\end{equation}
%
In the trapezoidal and Simpson's rule the points where the function is
evaluated, $x_i$, are fixed \textit{a priori} and we obtain
that~(\ref{Qua:eq:18}) is exact for all polynomial of degree less than
or equal to $n$.  In the case of the trapezoidal rule we have $n=2$
and the rule is exact for all linear functions.  In the case of
Simpson's rule we have $n=3$ and we would expect the formula to be
exact for all quadratic polynomials.  As a matter of fact, it is exact
for polynomials of order three, but this is due to a happy
cancellation.

However, there is no obligation to fix the nodes.  As a matter of fact
we could fix the coefficients (called \textit{weights}) $w_i$, for
example set them all to one, or we could not fix anything.  The
general criterion to find nodes and weights is to require that
equation~(\ref{Qua:eq:18}) is as accurate as possible, i.e.\ that it is
exact for polynomials of degree as high as possible.  In other words,
we require that the nodes and weights are such that
%
\begin{equation}
  \mint{a}{b}{x^s}{x} = \sum_{i=1}^n w_i x_i^s, \quad s=0,1,...,N,
  \label{Qua:eq:27}
\end{equation}
%
with $N$ as large as possible.

As above, we define the \textit{fundamental polynomials}
$\ell_i(x)$ given by
%
\begin{equation}
  \ell_i(x) = \prod_{\substack{j = 0\\j \ne i}}^N \frac{x - x_j}{x_i -
    x_j}, \quad i = 0, 1, \dots, N,
\end{equation}
%
have the property that $\ell_i(x_i) = 1$ and $\ell_i(x_k) = 0, i \ne
k$. It follows that
%
\begin{equation}
  p(x) = \sum_{i=0}^N f(x_i) \ell_i(x)
\end{equation}
%
is the polynomial of degree $N$ that interpolates the arbitrary
function $f(x)$ at the given nodes $x_i$. If the nodes are known or
fixed we can therefore immediately compute the weights as
%
\begin{equation}
  w_i = \mint{a}{b}{\ell_i(x)}{x}.
\end{equation}
%

If neither the nodes nor the weights are fixed we have $N$ nonlinear
equations for $2n$ unknowns $x_1,...,x_n$ and $w_1,...,w_n$.  One can
show that this problem has a unique solution if $N=2n-1$, i.e.\ that it
is possible to compute exactly the integrals of polynomials of degree
up to $2 n - 1$.  The resulting algorithm is called a {\bf Gaussian
  quadrature}.  There are many formulae for Gaussian quadrature that
depend mainly on the choice of integration interval and on the type of
the integral.  A generic Gauss quadrature formula is
%
\begin{equation}
  \mint{a}{b}{W(x) f(x)}{x} = \sum_{i=1}^n w_i f(x_i)
\end{equation}
%
and the different formulae are summarised in the following table:

\begin{center}
 \begin{tabular}{lll} \hline
  $(a,b)$ & $W(x)$ & Gauss- \\ \hline
  $(-1,1)$ & 1 & Legendre \\
  $(-1,1)$ & $(1-x^2)^{-1/2}$ & Chebychev \\
  $(0,\infty)$ & $x^c e^{-x}$ & Laguerre $c=0,1,\ldots$ \\
  $(-\infty,+\infty)$ & $e^{-x^2}$ & Hermite \\ \hline
 \end{tabular}
\end{center}

\section*{Further reading}

Topics covered here are also covered in
\begin{itemize}
\item Chapter 6 of Linz \& Wang, \textit{Exploring Numerical
    Methods} (QA297 LIN),
\item Chapter 7 of Kincaid \& Cheney, \textit{Numerical Analysis}
  (QA297 KIN),
\item Chapters 7 and 10 of S{\"u}li \& Mayers, \textit{An Introduction
    to Numerical Analysis} (not in library).
\end{itemize}

The issue of representing an arbitrary function by an interpolating
function, which will recur in later chapters, is covered in
considerable detail elsewhere; for example\begin{itemize}
\item Chapters 4 and 5 of Linz \& Wang, \textit{Exploring Numerical
    Methods} (QA297 LIN),
\item Chapter 6 of Kincaid \& Cheney, \textit{Numerical Analysis}
  (QA297 KIN),
\item Chapters 6, 8, 9 and 11 of S{\"u}li \& Mayers, \textit{An Introduction
    to Numerical Analysis} (not in library).
\end{itemize}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CS624: Analysis of Algorithms
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/beacon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{Question 7}

Show how to implement a queue using two stacks.
Analyze the running time of the queue operations and argue about their amortized cost.

\subsection*{Solution}

To implement a standard queue with \textsc{Enqueue} and \textsc{Dequeue} operations, using two stacks with pop and push operations, Algorithms \ref{alg61} and \ref{alg62} are respectively proposed, in which number of elements in stack $S$ is noted with $S.length$.

\begin{algorithm}[H]
\caption{\textsc{Enqueue($x$)}}\label{alg61}
\begin{algorithmic}[1]
\State \textsc{Push($S_1$, $x$)}
\State $S_1.length \leftarrow S_1.length + 1$
\end{algorithmic}
\end{algorithm}

\begin{algorithm}[H]
\caption{\textsc{Dequeue()}}\label{alg62}
\begin{algorithmic}[1]
\If {$S_2.length == 0$}
\For {$i \leftarrow S_1.length$ down to $1$}
\State $q \leftarrow$ \textsc{Pop}($S_1$)
\State \textsc{Push}($S_2$, $q$)
\EndFor
\EndIf
\State \Return \textsc{Pop}($S2$)
\end{algorithmic}
\end{algorithm}

It is trivial to show that the runtime for \textsc{Enqueue}$(x)$ using Algorithm \ref{alg61} is $\mathcal{O}(1)$ since each \textsc{Push} operation for an stack takes a constant time $C$.

When stack $S_2$ is not empty, \textsc{Dequeue} operation takes a constant time as well, simply because there is only one \textsc{Pop} operation with cost $C$.

In the worst-case however, when stack $S_2$ is empty and there are $n$ elements in stack $S_1$, the for loop will iterate $n$ times, leading to a run-time of $\mathcal{O}(n)$.
Thus the \textsc{Dequeue} algorithm is linear in number of elements in queue.

An amortize analysis, however, reveal both \textsc{Enqueue} and \textsc{Dequeue} algorithms only take constant time $C$ per item.
This is trivial for \textsc{Enqueue} since each element is \textsc{Push}ed only once.

To prove this statement for \textsc{Dequeue}, suppose a stack $S_1$ of $m$ elements.
It suffices to prove that it takes a multiple of $m$ constant-time cost to dequeue all $m$ elements, thus leading to a $\mathcal{O}(1)$ cost per element.

To dequeue the first element, all $m$ elements are \textsc{Pop}ed from stack $S_1$ and \textsc{Push}ed to stack $S_2$.
Once in $S_2$, they await their turn to be \textsc{Pop}ed again in later \textsc{Dequeue} operations.
This means each individual element of queue is \textsc{Pop}ed, \textsc{Push}ed and \textsc{Pop}ed only once, and since both two operations have constant-time cost, a \textsc{Dequeue} will have an amortized cost of 3, i.e. $\mathcal{O}(1)$.


\documentclass{article}
\title{ALO for LASSO with Intercept through Generalized LASSO}
\author{Yuze Zhou}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{subfigure}
\begin{document}
\maketitle
\section{The Dual of LASSO with intercept}
\paragraph{}For the generalized LASSO problem $\min\limits_{\beta}\frac{1}{2}||y-X\beta||+\lambda||D\beta||_{1}$, the dual problem is derived as:
\begin{center}
$\min\limits_{u}\frac{1}{2}||y-\theta||_{2}^{2}$\\
$\theta \in \{X^{\tau}\theta = D^{\tau}u, ||u||_{\infty} \leq \lambda\}$
\end{center}
\paragraph{}The dual problem could be written in a proximal approach such that:
\begin{center}
$\hat{u} = \textbf{prox}_{R}(y)$\\
$R(u) = \left\{
\begin{aligned}
0 \quad \if \theta \in \{X^{\tau}\theta = D^{\tau}u, ||u||_{\infty} \leq \lambda\}\\
+\infty \quad otherwise
\end{aligned}
\right.
$
\end{center}
\paragraph{}Denote $J$ as the jacobian of the proximal operator at the full data problem $y$, then the ALO estimator could be obtained as:
\begin{center}
$y^{/i} = y_{i} - \frac{\hat{u}_{i}}{J_{ii}}$
\end{center}
\paragraph{}For the case of LASSO with an intercept, we could expand the $X$ with a column of ones in the first column, expand $\beta$ with another dimension and choose $D = [\textbf{0}, I ]$.
\paragraph{}Denote $E := \{j: |X_{i}^{\tau}\theta| = \lambda \}$ to be the active set. Then the Jacobian is locally given as the projection onto the orthogonal complement of the span of $X_{E}$ and the ones vector. Further denote $\tilde{X}_{E} = [\textbf{1}, X_{E}]$, then the Jacobian is given as $I - \tilde{X_{E}}(\tilde{X_{E}}^{\tau}\tilde{X_{E}})\tilde{X_{E}}^{\tau}$.
\end{document}


\chapter{Expression of Angular Eigenstates of Harmonic Oscillators} \label{appA}

In this appendix, we derive some results on harmonic oscillators which are useful to show the abilities of entanglement detection of the SRPT criterion.

\section{Two Dimensional Harmonic Oscillator}

In two dimensions, the Hamiltonian describing a particle of mass $m$ subject to an isotropic harmonic potential is

\[ H =  \frac{p_x^2}{2m}+\frac{p_y^2}{2m} + \frac 1 2 m \omega^2 \left( x^2 + y^2 \right),\]
with $x_i, p_i$ the position and momentum of the particle in the directions $i=x,y$ and $\omega$ a constant. Since $H$ is the sum of two  oscillators Hamiltonians along the directions $x$ and $y$, it is clear that the eigenvalues of the hamiltonian will be written as
\[ \ket{n_x, n_y} \equiv \ket{n_x} \otimes \ket{n_y}, \]
when the $\ket{n_i}$ are the eigenstates of the two one dimensional Hamiltonians. We may define the annihilation operators:
\begin{eqnarray}
    a_x &=& \frac{1}{\sqrt 2} \left( \sqrt{\frac{m\omega}{\hbar}} x + \frac{i}{\sqrt{m \hbar \omega}} p_x \right), \\
    a_y &=& \frac{1}{\sqrt 2} \left( \sqrt{\frac{m\omega}{\hbar}} y +\frac{i}{\sqrt{m \hbar \omega}} p_y \right).
\end{eqnarray}
The creation operators $a^\dagger_i$ are the hermitian conjugates of the above operators. We have
\[ [a_x,a^\dagger_x]= [a_y,a^\dagger_y]=1, \]
while all other commutators between the four operators are zero. Let us finally define the number operators
\begin{eqnarray}
    N_x &=&a_x^\dagger a_x, \\
    N_y &=& a_y^\dagger a_y,
\end{eqnarray}
which allow us to write $H$ as
\[ H = (N_x + N_y +1) \hbar \omega. \]

The eigenstates have the properties
\begin{eqnarray}
    a_i \ket{n_i} &=& \sqrt{n_i} \ket{n_i-1},\\
    a_i^\dagger \ket{n_i} &=& \sqrt{n_i+1} \ket{n_i+1},\\
    N_i \ket{n_i} &=& n_i \ket{n_i},
\end{eqnarray}
and therefore, we have
\[  \ket{n_x,n_y} = \frac{1}{\sqrt{n_x! n_y!}} \left( a_x^\dagger \right)^{n_x}  \left( a_y^\dagger \right)^{n_y} \ket{0,0}, \]
with $\ket{0,0}$ the ground state of the oscillator.

We can also prove that
\[ H \ket{n_x,n_y} = (n_x + n_y +1) \hbar \omega \ket{n_x,n_y}.\]

If we define the total quantum number
\[ n = n_x + n_y, \]
we note that one particular value of $n$ corresponds to the $n+1$ orthogonal eigenstates
\[ \ket{n,0}, \; \ket{n-1,1}, \ldots, \; \ket{0,n}, \]
which shows that the measure of the energy alone does not allow us to pinpoint one proper state. The discrimination between all these states could be achieved by measuring the energy separately in the $x$ and $y$ direction, but there is another method that takes advantage of the angular momentum $L_z$. That operator is defined by
\[ L_z = x p_y - y p_x,\]
or in other terms
\[ L_z= i\hbar(a_x a_y^\dagger-a_x^\dagger a_y), \]
and it is clear that the $\ket{n_x,n_y}$ states are not eigenstates of $L_z$.

However, it is possible to show that
\[ [H,L_z]=0, \]
which indicates there must be a common eigenstate basis for the two operators. That basis is made of the $\ket{\psi_{k,M}}$ eigenvectors which has the following properties:
\begin{eqnarray}
    H \ket{\psi_{k,M}} &=& \hbar \omega(2k+|M|+1) \ket{\psi_{k,M}},\\
    L_z \ket{\psi_{k,M}} &=& \hbar M \ket{\psi_{k,M}}.
\end{eqnarray}

We wish to express any $\ket{\psi_{k,M}}$ state in function of the $\ket{n_x,n_y}$ states. It is quite clear that $n=n_x+n_y=2k+|M|$ and therefore for given $k$ and $M$ we have in general
\[ \ket{\psi_{k,M}} = \sum_{i=0}^n c_i \ket{n_x=n-i, n_y=i}. \label{eq-2Dsum}\]

To find the analytical expression of the $c_i$ coefficients, we need to define an intermediate basis as follow
\begin{eqnarray}
    a_r &=& \frac{1}{\sqrt 2} \left(a_x-ia_y \right), \\
    a_l &=& \frac{1}{\sqrt 2} \left(a_x+ia_y \right),
\end{eqnarray}
where $r$ and $l$ stand for right and left, as those operators can be interpreted as annihilators of right and left  ``circular quanta''. They are very similar to $a_x$ and $a_y$, they follow the commutation rules
\[ [a_r,a^\dagger_r]= [a_l,a^\dagger_l]=1, \]
and all other combinations are zero. It is possible to express the regular ladder operators in function of the circular one and we find that
\begin{eqnarray}
    H&=&(N_r + N_l +1) \hbar \omega,\\
    L_z &=& \hbar (N_r- N_l) ,
\end{eqnarray}
with $N_r=a^\dagger_r a_r$ and $N_l=a^\dagger_l a_l$ the new number operators. We see that there is a $\ket{\varphi_{n_r,n_l}}$ basis in which both $H$ and $L_z$ are diagonal and which behaves exactly like the $\ket{n_x,n_y}$ basis. We also find
\begin{eqnarray}
    n &=& n_r + n_l = 2k+ |M|, \\
    M &=& n_r - n_l,
\end{eqnarray}

This result does allow to associate a definite $\ket{\psi_{k,M}}$ state to a single state $\ket{\varphi_{n_r,n_l}}$. There are two cases depending on the sign of $M$; if $M>0$, it means $n_r>n_l$ and $|M|=n_r-n_l$ and $k=n_l$, if $M<0$, then $|M|=n_l-n_r$ and $k=n_r$. Globally,
\begin{eqnarray}
    \ket{\psi_{k,M}} &=& \ket{\varphi_{n_r=k+|M|,n_l=k}} \:\: \textrm{if } M>0, \\
    \ket{\psi_{k,M}} &=& \ket{\varphi_{n_r=k,n_l=k+|M|}} \:\: \textrm{if } M<0.
\end{eqnarray}

We see that a state with a positive helicity $M$ has more ``right'' quanta than ``left'' quanta and inversely for $M<0$. Now, to express a $\ket{\varphi_{n_r,n_l}}$ into a combination of $\ket{n_x,n_y}$ we have
\begin{eqnarray}
    \ket{\varphi_{n_r,n_l}}&=& \frac{1}{\sqrt{n_r! n_l!}} \left( a_r^\dagger \right)^{n_r}  \left( a_l^\dagger \right)^{n_l} \ket{\varphi_{0,0}}, \\
    &=&   \frac{1}{\sqrt{2^n n_r! n_l!}} \left( a_x^\dagger +ia_y^\dagger \right)^{n_r}  \left( a_x^\dagger -ia_y^\dagger\right)^{n_l} \ket{0,0}, \label{eq-2D2}\\
    &=&   \frac{1}{\sqrt{2^n n_r! n_l!}} \sum_{k=0}^{n_r} \sum_{l=0}^{n_l}  \binom{n_r}{k} \binom{n_l}{l} \left( a_x^\dagger \right)^{n-k-l}  \left(a_y^\dagger \right)^{j+k} (i)^{k-l} \ket{0,0}, \label{eq-2D3}\\
    &=&   \frac{1}{\sqrt{2^n n_r! n_l!}} \sum_{i=0}^{n} \sum_{j}^{\{-i,-i+2,\cdots, i\}}  \binom{n_r}{\frac{i-j}{2}} \binom{n_l}{\frac{i+j}{2}} \left( a_x^\dagger \right)^{n-i}  \left(a_y^\dagger \right)^i (i)^{j} \ket{0,0}, \label{eq-2D4}\\
    &=&   \frac{1}{\sqrt{2^n n_r! n_l!}} \sum_{i=0}^{n} \sum_{j=0}^{i}  \binom{n_r}{j} \binom{n_l}{i-j} \left( a_x^\dagger \right)^{n-i}  \left(a_y^\dagger \right)^i (i)^{2j-i} \ket{0,0},\label{eq-2D5} \\
    &=&   \sum_{i=0}^{n}(-i)^i  \sqrt{ \frac{(n-i)! i!}{2^n n_r! n_l!}}    \sum_{j=0}^{i} (-1)^j \binom{n_r}{j} \binom{n_l}{i-j}  \ket{n-i,i},\label{eq-2D6} \\
    &=&   \sum_{i=0}^{n}(-i)^i  \sqrt{\frac{\binom{n}{n_r} }{2^n \binom{n}{i}}}    \sum_{j=0}^{i}(-1)^j \binom{n_r}{j} \binom{n_l}{i-j}  \ket{n-i,i}, \label{eq-2D7}
\end{eqnarray}
where on line (\ref{eq-2D2}) we simply used the definition of $a_r$ and $a_l$ and noted the ground state is the same in both basis, in (\ref{eq-2D3}) we used the binomial formula twice and in (\ref{eq-2D4}) we applied the change of variables $i=k+l$ and $j=k-l$. In order to span all values of $(k,l)$ only once, we span all ``antidiagonal'' lines with $k+l=i$ $(i=0,1,\ldots,n)$ and along those lines we consider the elements $(k=\frac{i+j}{2},l=\frac{i-j}{2})$ $(j=-i, -i+2,\ldots, i-2,i)$. The values of $j$ should actually only go from $\max\{-i,i-2 n_l\}$ to  $\min\{i,2 n_r -i\}$ in order not to go beyond $k=n_r$ and $l=n_l$ but we can simplify it since the binomial coefficients will yield zero if $k>n_r$ or $l>n_l$. In line (\ref{eq-2D5}) we applied yet another change of variable as $j'=\frac{i+j}{2}$ $(j=0, 1, \ldots, i)$ and renamed $j'$ as $j$, in (\ref{eq-2D6}) we applied the creation operators to the ground state and in (\ref{eq-2D7}) we multiplied the numerator and denominator in the root term by $n!$ and simplified the expression. The final sum on $j$ may be expressed differently as we find that
\[  \sum_{j=0}^{i}(-1)^j \binom{n_r}{j} \binom{n_l}{i-j} = \binom{n_l}{i} {}_2F_1(-i,-n_r; n_l -i+1;-1), \]
with ${}_2F_1$ the hypergeometric function, but we choose to keep the sum as it is for its implementation simplicity.

Now,  we need to express directly the $\ket{\psi_{k,n}}$ state in the $\ket{n_x, n_y}$ basis. Depending on the sign of $M$, we need to consider the state $\ket{\varphi_{k+|M|, k}}$ or $\ket{\varphi_{k,k+|M|}}$. The easiest way to see the effect of a swap of $n_r$ and $n_l$ is in line (\ref{eq-2D3}) where the only difference is $i^{k-l}$  becoming $i^{l-k}=(-i)^{k-l}$. With that consideration, we finally have the $c_i$ coefficients we wanted in (\ref{eq-2Dsum}) up to an overall phase:
\[ c_i =  \left(- \textrm{sign}(M) i \right)^i  \sqrt{\frac{\binom{n}{k} }{2^n \binom{n}{i}}}    \sum_{j=0}^{i}(-1)^j \binom{k+|M|}{j} \binom{k}{i-j}.\]

The last property we want to investigate is the relation
\[ c_i = i^n (-1)^{n_l-i} c_{n-i} . \]
On the left hand side, we have
\begin{eqnarray}
    c_i&=& (-i)^i  \sqrt{\frac{\binom{n}{n_r} }{2^n \binom{n}{i}}}  \sum_{j=0}^{i}(-1)^j \binom{n_r}{j} \binom{n_l}{i-j} ,
\end{eqnarray}
and on the right hand side
\begin{eqnarray}
    c_{n-i}&=&  (-i)^{n-i} \sqrt{\frac{\binom{n}{n_r} }{2^n \binom{n}{n-i}}}    \sum_{j=0}^{n-i}(-1)^j \binom{n_r}{j} \binom{n_l}{n-i-j} , \\
    &=&  (-i)^{n-i}  \sqrt{\frac{\binom{n}{n_r} }{2^n \binom{n}{i}}}    \sum_{j=n_l-i}^{n_r}(-1)^{n_r-j} \binom{n_r}{n_r-j} \binom{n_l}{n-i+j-n_r} , \\
    &=&  (-i)^{n-i} (-1)^{n_r}  \sqrt{\frac{\binom{n}{n_r} }{2^n \binom{n}{i}}}    \sum_{j=n_l-i}^{n_r}(-1)^{j} \binom{n_r}{j} \binom{n_l}{i-j} ,
\end{eqnarray}
where in the second step we used the variable change $j'=n_r-j$ and in the last step simplified the expression. Aside from the phase, the only remaining difference is the borns of the sum but thanks to the binomial coefficients, that difference vanishes. Indeed, for both sums, the condition of having non zero terms is $\max\{ 0, i- n_l\} \le j \le \min\{ i,n_r \} $, so that all terms considered outside those limits are zero. Of course, we have $|c_i|=|c_{n-i}|$.

\section{Three Dimensional Harmonic Oscillator}

In three dimensions, the Hamiltonian describing a particle of mass $m$ subject to an isotropic harmonic potential is

\[ H =  \frac{p_x^2}{2m}+\frac{p_y^2}{2m} + \frac{p_z^2}{2m}+ \frac 1 2 m \omega^2 \left( x^2 + y^2 +z^2\right),\]
with $x_i, p_i$ the position and momentum of the particle in the directions $i=x,y,z$ and $\omega$ a constant. Once again, since $H$ is the sum of three oscillators Hamiltonians, the eigenvalues of the hamiltonian will be written as
\[ \ket{n_x, n_y,n_z} \equiv \ket{n_x} \otimes \ket{n_y} \otimes \ket{n_z}, \]
when the $\ket{n_i}$ are the eigenstates of the three one dimensional Hamiltonians. We may define the third annihilation operator:
\[ a_z = \frac{1}{\sqrt 2} \left( \sqrt{\frac{m\omega}{\hbar}} z + \frac{i}{\sqrt{m \hbar \omega}} p_z \right),\]
which behaves exactly as the others. We also define its number operator
\[ N_z = a_z^\dagger a_z, \]
which allow us to write $H$ as
\[ H = \left(N_x + N_y + N_z +\frac 3 2 \right) \hbar \omega. \]

The eigenstates are of the form
\[  \ket{n_x,n_y,n_z} = \frac{1}{\sqrt{n_x! n_y!n_z!}} \left( a_x^\dagger \right)^{n_x}  \left( a_y^\dagger \right)^{n_y} \left( a_z^\dagger \right)^{n_z} \ket{0,0,0}, \]
with $\ket{0,0,0}$ the ground state of the oscillator. This time for a definite energy $n=n_x+n_y+n_z$ there is a degree of degenerescence $g_n$ of
\[ g_n = \sum_{i=0}^n (i+1) = \frac{n(n+1)}{2} + (n+1) = \frac 1 2 (n+1)(n+2). \]
Just as we introduced $L_z$ in the two dimensional harmonic oscillator, we introduce the additional observable
\[ \mathbf{L}^2 = \frac 1 2 (L_+ L_- + L_- L_+) + L_z^2, \]
with
\begin{eqnarray}
    L_+ &=& \hbar \sqrt 2 (a^\dagger_z a_l - a^\dagger_r a_z), \\
    L_- &=& \hbar \sqrt 2 (a^\dagger_l a_z - a^\dagger_z a_r).
\end{eqnarray}

It can be checked that $[H,\mathbf{L}^2]=0$ and $[L_z,\mathbf{L}^2]=0$ which implies there must be a common set of eigenstates for $H$, $L_z$ and $\mathbf{L}^2$ . Those eigenstates are the $\ket{\psi_{k,l,m}}$ states and have the following properties
\begin{eqnarray}
    H \ket{\psi_{k,l,m}} &=& \hbar \omega(2k+l+\frac 3 2) \ket{\psi_{k,l,m}},\\
    L_z \ket{\psi_{k,l,m}} &=& \hbar m \ket{\psi_{k,l,m}},\\
    \mathbf{L}^2 \ket{\psi_{k,l,m}} &=& \hbar^2 l(l+1) \ket{\psi_{k,l,m}}, \\
    L_\pm \ket{\psi_{k,l,m}} &=& \hbar \sqrt{l(l+1)-m(m\pm1)} \ket{\psi_{k,l,m\pm1}}.\\
\end{eqnarray}

The last relation implies that $m$ can take any integer value from $-l$ to $l$. So by repeatedly applying the $L_-$ operator on a $\ket{\psi_{k,l,l}}$ state, we should be able to generate all states down to $\ket{\psi_{k,l,-l}}$. The first step is to find the expression of the $\ket{\psi_{k,l,l}}$ in the $\ket{\varphi_{n_r,n_l,n_z}}$ basis using the particular property $L_+ \ket{\psi_{k,l,l}} = 0$. By identifying the quantum numbers we find
\begin{eqnarray}
    n&=& n_r + n_l + n_z = 2k+ l, \\
    m &=& n_r - n_l.
\end{eqnarray}

Since $n_r-n_l=m$ we can always write $n_r = K+m$, $n_r=K$ with $K$ a positive integer and therefore we must have $n_z=n-m-2K$, which cannot be negative hence we have $K \le \frac{n-m}{2}$.  We are now able to write
\[ \ket{\psi_{k,l,l}} = \sum_{K=0}^k c_K \ket{\varphi_{n_r=K+l, n_l=K, n_z = 2k-2K}}, \]
since $\frac{n-l}{2} = k$ and with normalized coefficient $c_K$. The effect of $L_+$ on such a decomposition is
\bea
L_+ \ket{\psi_{k,l,l}} &=& \sum_{K=0}^k c_K \sqrt 2 \hbar \left( \sqrt{K} \sqrt{2k-2K+1} \ket{\varphi_{K+l, K-1,2k-2K+1}} \right. \nonumber \\
&& \ - \left. \sqrt{K+l+1}\sqrt{2k-2K} \ket{\varphi_{K+l+1, K,2k-2K-1}} \right),
\eea
which is zero if
\[ c_K  \sqrt{K+l+1}\sqrt{2k-2K} = c_{K+1} \sqrt{K+1} \sqrt{2k-2K-1}. \]

From that relation, we can express all $c_K$ in function of $c_0$ and then normalize all coefficient. We have
\bea
c_K^2 &=& c_0^2 \prod_{j=0}^{K-1} \frac{(j+l+1)(2k-2j)}{(j+1)(2k-2j-1)} ,\\
&=& c_0^2 \frac{(l+1)(l+2)\ldots(l+K)(2k)(2k-2)\ldots(2k-2K+2)}{(1)(2)\ldots K (2k-1)(2k-3)\ldots(2k-2K+1)} ,\\
&=& c_0^2 \frac{(l+K)!}{l!K! } \frac{(2k)!!}{(2k-2K)!!} \frac{(2k-2K-1)!!}{(2k-1)!!}, \\
&=& c_0^2 \binom{l+K}{K} \frac{2^k k! }{2^{k-K}(k-K)! }\frac{(2k-2K)!}{2^{k-K}(k-K)! }\frac{2^{k}(k)! }{(2k)!}, \\
&=& c_0^2 \,2^{2K}\,\frac{ \binom{l+K}{K} \binom{2k-2K}{k-K}  }{ \binom{2k}{k} },
\eea
where $k!!$ is the double factorial of $k$ which has the property
\bea
(2k)!! &=&(2k)(2k-2)\ldots2 = k! 2^{k}, \\
(2k+1)!! &=&(2k+1)(2k-1)\ldots1 = \frac{(2k)!}{k! 2^{k}},
\eea
that we used in the process.

With that expression, we are now able to calculate the value of $c_0$ by normalizing the expression. We have
\bea
\sum_{K=0}^k c_K^2 &=& c_0^2 \sum_{K=0}^k \,2^{2K}\,\frac{ \binom{l+K}{K} \binom{2k-2K}{k-K}  }{ \binom{2k}{k} }, \\
&=& c_0^2 \frac{ \binom{2(k+l+1)}{2k}}{ \binom{k+l+1}{k} },
\eea
Since that expression must be 1, we have he value of $c_0$. Finally, we get up to a global phase
\[ \ket{\psi_{k,l,l}} = \sum_{K=0}^k\,2^{K}\, \sqrt{ \frac{ \binom{l+K}{K} \binom{2k-2K}{k-K} \binom{k+l+1}{k} }{ \binom{2k}{k}  \binom{2(k+l+1)}{2k} }} \ket{\varphi_{K+l, K, 2k-2K}}. \]

%From that state we can get any other  $\ket{\psi_{k,l,m}}$ by applying $L_-$ the right number of time. Indeed, we have
%\[ \ket{\psi_{k,l,m}}=\frac{(L_-/\hbar)^{l-m}}{\prod_{j=m+1}^l \sqrt{l(l+1)-j(j-1)}} \ket{\psi_{k,l,l}}. \]
%
%First, we simplify the product at the denominator
%\bea
%\prod_{j=m+1}^l \sqrt{l(l+1)-j(j-1)} &=& \prod_{j=m+1}^l \sqrt{l+j}\sqrt{l-j+1}, \\
%&=& \sqrt{\frac{(2l)!}{(l+m)!}}\sqrt{(l-m)!}=\sqrt{\binom{2l}{l+m}} (l-m)!.
%\eea
%We also have
%\[ \left(\frac{L_-}{\hbar}\right)^{l-m} = 2^{\frac{l-m}{2}} (a^\dagger_l a_z - a^\dagger_z a_r)^{l-m} = 2^{\frac{l-m}{2}} \sum_{j=0}^{l-m} (-1)^j \binom{l-m}{j} (a^\dagger_l a_z)^{l-m-j} (a^\dagger_z a_r)^j, \]
%and by noting that
%\bea
%a^{k} \ket{n} &=& \sqrt\frac{n!}{(n-k)!} \ket{n-k}, \\
%(a^\dagger)^{k} \ket{n} &=& \sqrt\frac{(n+k)!}{n!} \ket{n+k},
%\eea
%we see that
%\bea
%(a^\dagger_l a_z)^{l-m-j} (a^\dagger_z a_r)^j  \ket{\varphi_{K+l, K, 2k-2K}} &=&   \sqrt\frac{(K+l)!}{(K+l-j)!} \sqrt\frac{(K+l-m-j)!}{K!} \nonumber \\
%&& \ \sqrt\frac{(2k-2K+j)!}{(2k-2K-l+m+2j)!} \sqrt\frac{(2k-2K+j)!}{(2k-2K)!} \nonumber \\
%&& \ \ket{\varphi_{K+l-j, K+l-m-j, 2k-2K-l+m+2j}},
%\eea
%and if we apply the variable change $j'=K+l-j$ ($j'=K+m,\ldots, K+l$)
%\[ (a^\dagger_l a_z)^{l-m-j} (a^\dagger_z a_r)^j  \ket{\varphi_{K+l, K, 2k-2K}} =   \sqrt\frac{(K+l)!(j-m)!(n-K-j)!^2}{j!K!(n+m-2j)!(2k-2K)!} \ket{\varphi_{j, j-m, n+m-2j}}.\]
%
%The expression became
%\[ \ket{\psi_{k,l,m}}=\sum_{K=0}^k   \sum_{j=K+m}^{K+l}  (-1)^j  c_{K,j}\ket{\varphi_{j, j-m, n+m-2j}},\]
%with
%\bea
%c_{K,j}&=&  \sqrt{ \frac{  \binom{l-m}{K+l-j}^2  \binom{l+K}{K} \binom{2k-2K}{k-K} \binom{k+l+1}{k} }{2^{l-m-2K} \binom{2k}{k}  \binom{2(k+l+1)}{2k} \binom{2l}{l+m}}}  \sqrt\frac{(K+l)!(j-m)!(n-K-j)!^2}{(l-m)!^2j!K!(n+m-2j)!(2k-2K)!}
%\eea