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

\title{Chapter 12\\Further Topics in Analysis}
\author{solutions by Hikari}
\date{November 2021}

\begin{document}

\newcommand{\pdv}[2]{\frac{\partial#1}{\partial#2}}
\newcommand{\V}{\mathbf}
\newcommand{\del}{\boldsymbol{\nabla}}
\newcommand{\lfpr}[1]{\left(#1\right)}
\newcommand{\lfbr}[1]{\left[#1\right]}
%dashint
\def\Xint#1{\mathchoice
   {\XXint\displaystyle\textstyle{#1}}%
   {\XXint\textstyle\scriptstyle{#1}}%
   {\XXint\scriptstyle\scriptscriptstyle{#1}}%
   {\XXint\scriptscriptstyle\scriptscriptstyle{#1}}%
   \!\int}
\def\XXint#1#2#3{{\setbox0=\hbox{$#1{#2#3}{\int}$}
     \vcenter{\hbox{$#2#3$}}\kern-.5\wd0}}
\def\ddashint{\Xint{\;\,-}}
\def\dashint{\Xint-}

\maketitle

\section*{12.1 Orthogonal Polynomials}

\paragraph{12.1.1}
\[
g(x,t)=\sum_{n=0}^\infty\frac{1}{n!}H_n(x)t^n
\]
\[
=\sum_{n=0}^\infty\frac{(-1)^n}{n!}t^ne^{x^2}\left(\frac{d}{dx}\right)^ne^{-x^2}
\]
\[
=\sum_{n=0}^\infty\frac{(-1)^n}{n!}t^ne^{x^2}\frac{n!}{2\pi i}\oint\displaylimits_{c}\frac{e^{-z^2}}{(z-x)^{n+1}}dz
\]
\[
=\oint\displaylimits_c\left(\sum_{n=0}^\infty\left(\frac{-t}{z-x}\right)^n\frac{e^{x^2-z^2}}{2\pi i(z-x)} \right)dz
\]
\[
=\oint\displaylimits_c\frac{1}{1-\frac{-t}{z-x}}\frac{e^{x^2-z^2}}{2\pi i(z-x)}
\]
\[
=\oint\displaylimits_c\frac{e^{x^2-z^2}}{2\pi i(z-x+t)}dz
\]
The function has a simple pole at $z=x-t$ with residue
\[
\lim_{z\to x-t}(z-x+t)\cdot\frac{e^{x^2-z^2}}{2\pi i(z-x+t)}=\frac{e^{-t^2+2xt}}{2\pi i}
\]
so we have
\[
g(x,t)=2\pi i\cdot\frac{e^{-t^2+2xt}}{2\pi i}=e^{-t^2+2xt}
\]

\paragraph{12.1.2}
(a)
\[
w(x)=\frac{1}{x}\cdot e^{\int\frac{1-x}{x}dx}=\frac{1}{x}\cdot e^{\ln x-x}=e^{-x}
\]
Using the Rodrigues formula,
\[
y_n(x)=e^x\left(\frac{d}{dx}\right)^n\left[e^{-x}x^n\right]
\]

(b)
(Using the rescaled polynomials with a factor $\frac{1}{n!}$ from the table)
\[
g(x,t)=\sum_{n=0}^\infty L_n(x)t^n
\]
\[
=\sum_{n=0}^\infty\frac{e^xt^n}{n!}\left(\frac{d}{dx}\right)^n\left[x^ne^{-x} \right]
\]
\[
=\sum_{n=0}^\infty\frac{e^xt^n}{n!}\frac{n!}{2\pi i}\oint\displaylimits_c\frac{z^ne^{-z}}{(z-x)^{n+1}}dz
\]
\[
=\oint\displaylimits_c\left(\sum_{n=0}^\infty\left(\frac{tz}{z-x}\right)^n\frac{e^{x-z}}{2\pi i(z-x)} \right)dz
\]
\[
=\oint\displaylimits_c\frac{1}{1-\frac{tz}{z-x}}\frac{e^{x-z}}{2\pi i(z-x)}dz
\]
\[
=\oint\displaylimits_c\frac{e^{x-z}}{2\pi i(1-t)(z-\frac{x}{1-t})}dz
\]
The function has a simple pole at $z=\frac{x}{1-t}$ with residue
\[
\lim_{z\to\frac{x}{1-t}}(z-\frac{x}{1-t})\cdot\frac{e^{x-z}}{2\pi i(1-t)(z-\frac{x}{1-t})}=\frac{e^{\frac{-xt}{1-t}}}{2\pi i(1-t)}
\]
so we have
\[
g(x,t)=2\pi i\cdot\frac{e^{\frac{-xt}{1-t}}}{2\pi i(1-t)}=\frac{e^{\frac{-xt}{1-t}}}{1-t}
\]

\paragraph{12.1.3}
From Equation 12.10:
\[
p\left[wp^n\right]'=wp^n\left[(n-1)p'+q\right]
\]
Note that $\frac{d^kp}{dx^k}=0$ for $k>2$, so we have
\[
\left(\frac{d}{dx} \right)^{n+1}\left(p\left[wp^n\right]' \right)=\sum_{k=0}^{n+1}\binom{n+1}{k}\frac{d^kp}{dx^k}\frac{d^{n+1-k}\left[wp^n\right]'}{dx^{n+1-k}}
\]
\[
=p\lfpr{\frac{d}{dx}}^{n+2}\lfbr{wp^n}+(n+1)p'\lfpr{\frac{d}{dx}}^{n+1}\lfbr{wp^n}+\frac{(n+1)n}{2}p''\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}
\]
Also note that $\frac{d^k[(n-1)p'+q]}{dx^k}=0$ for $k>1$, so we have
\[
\lfpr{\frac{d}{dx}}^{n+1}\lfbr{(n-1)p'+q}wp^n=\sum_{k=0}^{n+1}\binom{n+1}{k}\frac{d^k\lfbr{(n-1)p'+q}}{dx^k}\frac{d^{n+1-k}\lfbr{wp^n}}{dx^{n+1-k}}
\]
\[
=\lfbr{(n-1)p'+q}\lfpr{\frac{d}{dx}}^{n+1}\lfbr{wp^n}\;+\;(n+1)\lfbr{(n+1)p''+q'}\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}
\]
Equating the two sides of the equation, dividing by $w$, rearranging, and using $y_n=\frac{1}{w}\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}$, we have
\[
\frac{p}{w}\lfpr{\frac{d}{dx}}^{n+2}\lfbr{wp^n}+\frac{2p'-q}{w}\lfpr{\frac{d}{dx}}^{n+1}\lfbr{wp^n}-\lfbr{\frac{n^2-n-2}{2}p''+(n+1)q'}y_n=0
\]

\paragraph{12.1.4}
From Equation 12.12:
\[
\frac{p}{w}\lfpr{\frac{d}{dx}}^{n+2}\lfbr{wp^n}+\frac{2p'-q}{w}\lfpr{\frac{d}{dx}}^{n+1}\lfbr{wp^n}=\lfbr{\frac{n^2-n-2}{2}p''+(n+1)q'}y_n
\]
Calculate $py_n''$ and $qy_n'$:
\begin{align*}
    & p\,y_n''=p\lfbr{\frac{1}{w}\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}}''=\frac{p}{w}\lfpr{\frac{d}{dx}}^{n+2}\lfbr{wp^n}+2p\frac{dw^{-1}}{dx}\lfpr{\frac{d}{dx}}^{n+1}\lfbr{wp^n}+p\frac{d^2w^{-1}}{dx^2}\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}\\
    & q\,y_n'=q\lfbr{\frac{1}{w}\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}}'=\frac{q}{w}\lfpr{\frac{d}{dx}}^{n+1}\lfbr{wp^n}+q\frac{dw^{-1}}{dx}\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}
\end{align*}
Note that by definition we have
\begin{align*}
    & \frac{dw^{-1}}{dx}=-\frac{w'}{w^2}=\frac{p'-q}{wp}\\
    & \frac{d^2w^{-1}}{dx^2}=\frac{p''-q'}{wp}-\frac{p'-q}{(wp)^2}(wp)'=\frac{1}{wp}\lfbr{p''-q'-\frac{q(p'-q)}{p}}
\end{align*}
Substituting, summing together and using Equation 12.12, we have
\[
p\,y_n''+q\,y_n'=\frac{p}{w}\lfpr{\frac{d}{dx}}^{n+2}\lfbr{wp^n}+\frac{2p'-q}{w}\lfpr{\frac{d}{dx}}^{n+1}\lfbr{wp^n}+\frac{p''-q'}{w}\lfpr{\frac{d}{dx}}^n\lfbr{wp^n}
\]
\[
=\lfbr{\frac{n^2-n-2}{2}p''+(n+1)q'}y_n+\lfbr{p''-q'}y_n=\lfbr{\frac{n^2-n}{2}p''+nq'}y_n
\]
which is Equation 12.16:
\[
p\,y_n''+q\,y_n'-\lfbr{\frac{n^2-n}{2}p''+nq'}y_n=0
\]

\paragraph{12.1.5}
(a)
\[
g(x,t)=\sum_{n=0}^\infty J_n(x)t^n
\]
\[
=\sum_{n=0}^\infty\frac{t^n}{2\pi i}\oint\displaylimits_c e^{\frac{x}{2}(z-\frac{1}{z})}z^{-n-1}dz
\]
\[
=\oint\displaylimits_c\lfpr{\sum_{n=0}^\infty\frac{e^{\frac{x}{2}{(z-\frac{1}{z})}}}{2\pi iz}\lfpr{\frac{t}{z}}^n }dz
\]
\[
=\oint\displaylimits_c\frac{e^{\frac{x}{2}{(x-\frac{1}{z})}}}{2\pi iz}\frac{1}{1-\frac{t}{z}}dz
\]
\[
=\oint\displaylimits_c\frac{e^{\frac{x}{2}{(z-\frac{1}{z})}}}{2\pi i(z-t)}dz
\]
The function has a simple pole at $z=t$ with residue
\[
\lim_{z\to t}(z-t)\cdot\frac{e^{\frac{x}{2}{(z-\frac{1}{z})}}}{2\pi i(z-t)}=\frac{e^{\frac{x}{2}{(t-\frac{1}{t})}}}{2\pi i}
\]
So the generating function of Bessel functions is
\[
g(x,t)=e^{\frac{x}{2}{(t-\frac{1}{t})}}
\]

(b)
With similar process, the generating function of modified Bessel functions is
\[
g(x,t)=e^{\frac{x}{2}{(t+\frac{1}{t})}}
\]

\paragraph{12.1.6}
\[
\lfbr{1+(t^2-2tz)}^{-\frac{1}{2}}=1-\frac{1}{2}\lfpr{t^2-2tz}+\frac{3}{8}\lfpr{t^2-2tz}^2+\cdots=1+zt+\frac{3z^2-1}{2}t^2+\cdots
\]
so the coefficient is
\begin{align*}
    & a_0=P_0(z)=1\\
    & a_1=P_1(z)=z\\
    & a_2=P_2(z)=\frac{1}{2}\lfpr{3z^2-1}
\end{align*}

\paragraph{12.1.7}
\begin{align*}
    & \pdv{}{t}\lfpr{\frac{1}{1-2xt+t^2}}=\frac{2x-2t}{(1-2xt+t^2)^2}=\frac{2x-2t}{1-2xt+t^2}\sum_{n=0}^\infty U_n(x)t^n\\
    & \pdv{}{t}\lfpr{\sum_{n=0}^\infty U_n(x)t^n}=\sum_{n=1}^\infty nU_n(x)t^{n-1}
\end{align*}
Equating the two sides, we have
\[
\sum_{n=0}^\infty 2xU_nt^n-\sum_{n=0}^\infty2U_nt^{n+1}=\sum_{n=1}^\infty nU_nt^{n-1}-\sum_{n=1}^\infty 2xnU_nt^n+\sum_{n=1}^\infty nU_nt^{n+1}
\]
Collect the terms of $t^n$, we have
\[
2xU_n-2U_{n-1}=(n+1)U_{n+1}-2xnU_n+(n-1)U_{n-1}
\]
so the recurrence relation is (for $n\geq1$):
\[
U_{n+1}(x)-2xU_n(x)+U_{n-1}(x)=0
\]

\section*{12.2 Bernoulli Numbers}

\paragraph{12.2.1}
\[
\frac{t}{e^t-1}=\frac{-te^{-t}}{e^{-t}-1}=\frac{-t(e^{-t}-1)-t}{e^{-t}-1}=\frac{-t}{e^{-t}-1}-t
\]
\[
\frac{te^{t}}{e^t-1}=\frac{t}{1-e^{-t}}=\frac{-t}{e^{-t}-1}
\]

\paragraph{12.2.2}
\begin{equation*}
    \begin{split}
        \frac{te^{ts}}{e^t-1} & =\frac{t(1+ts+\frac{t^2s^2}{2}+\cdots)}{1+t+\frac{t^2}{2}+\frac{t^3}{6}+\cdots-1}\\
        & =\frac{1+ts+\frac{t^2s^2}{2}+\cdots}{1+\frac{t}{2}+\frac{t^2}{6}+\cdots}\\
        & =(1+ts+\frac{t^2s^2}{2}+\cdots)(1-\frac{t}{2}-\frac{t^2}{6}+\frac{t^2}{4}+\cdots)\\
        & =1+(s-\frac{1}{2})t+(\frac{s^2}{2}-\frac{s}{2}+\frac{1}{12})t^2+\cdots\\
        & =B_0+B_1t+\frac{B_2}{2}t^2
    \end{split}
\end{equation*}
so we have
\begin{equation*}
    \begin{split}
        B_0(s) & =1\\
        B_1(s) & =s-\frac{1}{2}\\
        B_2(s) & =s^2-s+\frac{1}{6}
    \end{split}
\end{equation*}

\paragraph{12.2.3}
\[
\cot 2x=\frac{\cos 2x}{\sin 2x}=\frac{\cos^2x-\sin^2x}{2\sin x\cos x}=\frac{\cot x}{2}-\frac{\tan x}{2}
\]
so
\[
\tan x=\cot x-2\cot2x
\]
From Equation 12.35, we have
\begin{equation*}
    \begin{split}
        \cot x & =\sum_{n=0}^\infty(-1)^nB_{2n}\frac{2^{2n}x^{2n-1}}{(2n)!}\\
        2\cot2x & =\sum_{n=0}^\infty(-1)^nB_{2n}\frac{2^{2n+1}(2x)^{2n-1}}{(2n)!}=\sum_{n=0}^\infty(-1)^nB_{2n}\frac{2^{4n}x^{2n-1}}{(2n)!}
    \end{split}
\end{equation*}
so
\[
\tan x & =\cot x-2\cot 2x
\]
\[
=\sum_{n=0}^\infty\frac{(-1)^n2^{2n}(1-2^{2n})B_{2n}}{(2n)!}x^{2n-1}
\]
\[
=\sum_{n=0}^\infty\frac{(-1)^{n-1}2^{2n}(2^{2n}-1)B_{2n}}{(2n)!}x^{2n-1}
\]

\section*{12.3 Euler-Maclaurin Integration Formula}

\paragraph{12.3.1}
\begin{equation*}
    \begin{split}
        \sum_{m=1}^n m &= \int_1^n xdx+\frac{1}{2}+\frac{n}{2}+\frac{B_2}{2!}[1-1]\\
        & =\frac{n^2-1}{2}+\frac{n+1}{2}=\frac{1}{2}n(n+1)\\
        \sum_{m=1}^n m^2 & =\int_1^n x^2 dx+\frac{1}{2}+\frac{n^2}{2}+\frac{B_2}{2!}[2n-2]\\
        & =\frac{n^3-1}{3}+\frac{n^2+1}{2}+\frac{n-1}{6}=\frac{1}{6}n(n+1)(2n+1)\\
        \sum_{m=1}^n m^3 & =\int_1^n x^3dx+\frac{1}{2}+\frac{n^3}{2}+\frac{B_2}{2!}[3n^2-3]+\frac{B_4}{4!}[6-6]\\
        & =\frac{n^4-1}{4}+\frac{n^3+1}{2}+\frac{n^2-1}{4}=\frac{1}{4}n^2(n+1)^2\\
        \sum_{m=1}^n m^4 & =\int_1^n x^4 dx+\frac{1}{2}+\frac{n^4}{2}+\frac{B_2}{2!}[4n^3-4]+\frac{B_4}{4!}[24n-24]\\
        & =\frac{n^5-1}{5}+\frac{n^4+1}{2}+\frac{n^3-1}{3}-\frac{n-1}{30}\\
        & =\frac{1}{30}n(n+1)(2n+1)(3n^2+3n-1)
    \end{split}
\end{equation*}

\paragraph{12.3.2}
\[
\gamma=\lim_{n\to\infty}\lfpr{\sum_{s=1}^n\frac{1}{s}-\ln n}=\sum_{s=1}^n\frac{1}{s}-\ln n+\lim_{n'\to\infty}\lfpr{\sum_{s=n+1}^{n'}\frac{1}{s}-\ln\frac{n'}{n}}
\]
The last term can be evaluated by Euler-Maclaurin formula:

\begin{equation*}
    \begin{split}
        \lim_{n'\to\infty}\lfpr{\sum_{s=n+1}^{n'}\frac{1}{s}-\int\displaylimits_{n}^{n'}\frac{1}{s}ds} & =\lim_{n'\to\infty}\lfbr{\frac{\frac{1}{n'}-\frac{1}{n}}{2}+\sum_{k=1}^N\frac{B_{2k}}{(2k)!}\lfpr{f^{(2k-1)}(n')-f^{2k-1}(n) } }+remainder\\
        & =\lim_{n'\to\infty}\lfbr{\frac{1}{2n'}-\frac{1}{2n}-\sum_{k=1}^N\frac{B_{2k}}{2k}\lfpr{\frac{1}{(n')^{2k}}-\frac{1}{n^{2k}} } }+remainder\\
        & =-\frac{1}{2n}+\sum_{k=1}^N\frac{B_{2k}}{(2k)n^{2k}}+remainder
    \end{split}
\end{equation*}
where we have evaluated
\[
f^{(2k-1)}(n)=-(2k-1)!\frac{1}{n^{2k}}
\]
So by ignoring the remainder term, we have
\[
\gamma=\sum_{s=1}^n\frac{1}{s}-\ln n-\frac{1}{2n}+\sum_{k=1}^N\frac{B_{2k}}{(2k)n^{2k}}
\]
Let $n=1000$ and $N=2$ (evaluate the term of $B_2$ and $B4$), we have
\[
\gamma=0.577215664902
\]

\section*{12.4 Dirichlet Series}

\paragraph{12.4.1}
Use $N-1=\sum_{n=1}^{N-1}\binom{2N}{2n}B_{2n}$ to obtain $B_{2n}$, and use $B_{2n}=(-1)^{n+1}\frac{2(2n)!}{(2\pi)^{2n}}\zeta(2n)$ to obtain $\zeta(2n)$:
\begin{alignat*}{3}
    & n=1: \qquad && B_{2}=\frac{1}{6}\qquad && \zeta(2)=\frac{\pi^2}{6}\\
    & n=2: \qquad && B_4=-\frac{1}{30}\qquad && \zeta(4)=\frac{\pi^4}{90}\\
    & n=3: \qquad && B_6=\frac{1}{42}\qquad && \zeta(6)=\frac{\pi^6}{945}\\
    & n=4: \qquad && B_8=-\frac{1}{30}\qquad && \zeta(8)=\frac{\pi^8}{9450}\\
    & n=5: \qquad && B_{10}=\frac{5}{66}\qquad && \zeta(10)=\frac{\pi^{10}}{93555}
\end{alignat*}

\paragraph{12.4.2}
Using the substitution $1-x=e^{-t}$, we have
\begin{equation*}
\begin{split}
    \int_0^1\lfbr{\ln(1-x)}^2\frac{dx}{x} & =\int_0^\infty\frac{t^2e^{-t}}{1-e^{-t}}dt\\
    & =\int_0^\infty\lfpr{t^2e^{-t}\sum_{n=0}^\infty e^{-nt} }dt\\
    & =\sum_{n=0}^\infty\int_0^\infty t^2e^{-(1+n)t}dt\\
    & =\sum_{n=0}^\infty\frac{2}{(1+n)^3}\\
    & =\sum_{n=1}^\infty\frac{2}{n^3}\\
    & =2\zeta(3)
\end{split}
\end{equation*}
where we expanded $(1-e^{-t})^{-1}$, and integrated by parts.

\paragraph{12.4.3}
(This is essentially Exercise 11.8.18)
\medskip

(a)
\[
\int\displaylimits_0^\infty\frac{(\ln z)^2}{1+z^2}dz=\int\displaylimits_0^1\frac{(\ln z)^2}{1+z^2}dz+\int\displaylimits_1^\infty\frac{(\ln z)^2}{1+z^2}dz
\]
By the substitution $z=\frac{1}{t}$, the first integral becomes
\[
\int\displaylimits_0^1\frac{(\ln z)^2}{1+z^2}dz=\int\displaylimits_{\infty}^1\frac{(-\ln t)^2}{1+t^{-2}}(-t^{-2}dt)=\int\displaylimits_1^\infty\frac{(\ln t)^2}{1+t^2}dt
\]
which is the same with the second integral. By another substitution $z=e^t$, we have
\[
\int\displaylimits_1^\infty\frac{(\ln z)^2}{1+z^2}dz
=\int\displaylimits_0^\infty\frac{t^2e^t}{1+e^{2t}}dt=\int\displaylimits_0^\infty\frac{t^2e^{-t}}{1+e^{-2t}}dt
\]
\[
=\int\displaylimits_0^\infty\left(\sum_{n=0}^\infty(-1)^n\,t^2\, e^{-(2n+1)t} \right)dt
\]
\[
=\sum_{n=0}^\infty(-1)^n\int\displaylimits_0^\infty t^2\,e^{-(2n+1)t}dt
\]
\[
=\sum_{n=0}^\infty(-1)^n\left[\frac{2e^{-(2n+1)t}}{-(2n+1)^3} \right]_0^\infty
\]
\[
=2\sum_{n=0}^\infty(-1)^n(2n+1)^{-3}
\]
so
\[
\int\displaylimits_0^\infty\frac{(\ln z)^2}{1+z^2}dz=2\int\displaylimits_1^\infty\frac{(\ln z)^2}{1+z^2}dz\]
\[=4\sum_{n=0}^\infty(-1)^n(2n+1)^{-3}\]
\[=4\lfpr{1-\frac{1}{3^3}+\frac{1}{5^3}-\frac{1}{7^3}+\cdots}
\]

(b)
By the substitution $z=e^t$, we have
\[
I=\int\displaylimits_0^\infty\frac{(\ln z)^2}{1+z^2}dz=\int\displaylimits_{-\infty}^\infty\frac{t^2}{1+e^{2t}}\cdot e^t dt=\int\displaylimits_{-\infty}^\infty\frac{t^2}{e^t+e^{-t}}dt
\]
The function has poles at $z=(n+\frac{1}{2})i\pi$, and the pole at $z=\frac{i\pi}{2}$ is
\[
\lim_{z\to\frac{i\pi}{2}}(z-\frac{i\pi}{2})\cdot\frac{z^2e^z}{1+e^{2z}}=\lim_{z\to\frac{i\pi}{2}}\frac{z^2e^z}{2e^{2z}}=\frac{\pi^2i}{8}
\]
Take the contour to be that in Figure 11.29. Integral on the two vertical segments vanish as $R\to\infty$, and integral on the segment at $x+i\pi$ is
\[
\int\displaylimits_{\infty}^{-\infty}\frac{(t+i\pi)^2}{e^{t+i\pi}+e^{-t-i\pi}}dt=\int\displaylimits_{-\infty}^\infty\frac{(t+i\pi)^2}{e^t+e^{-t}}\]
\[=\int\displaylimits_{-\infty}^\infty\frac{t^2}{e^t+e^{-t}}dt+\int\displaylimits_{-\infty}^\infty\frac{2i\pi t}{e^t+e^{-t}}dt+\int\displaylimits_{-\infty}^\infty\frac{-\pi^2}{e^t+e^{-t}}dt
\]
The first integral is $I$, the second integral vanishes as it is an odd function, and the third integral is
\[
\int\displaylimits_{-\infty}^\infty\frac{-\pi^2}{e^t+e^{-t}}dt=\int\displaylimits_0^\infty\frac{-\pi^2}{x^2+1}dx=-\pi^2\Big[\tan^{-1}x\Big]_0^\infty=-\frac{\pi^3}{2}
\]
Using the residue theorem, we have
\[
I+I-\frac{\pi^3}{2}=2\pi i\cdot\frac{\pi^2i}{8}
\]
\[
I=\frac{\pi^3}{8}
\]

\paragraph{12.4.4}
\begin{alignat*}{4}
    & \beta(2)=1 && -\frac{1}{3^2} && +\frac{1}{5^2} && -\frac{1}{7^2}+\cdots \\
    & \zeta(2)=1+\frac{1}{2^2} && +\frac{1}{3^2}+\frac{1}{4^2} && +\frac{1}{5^2}+\frac{1}{6^2} && +\frac{1}{7^2}+\cdots
\end{alignat*}
so
\[
\zeta(2)+\beta(2)=2\lfpr{1+\frac{1}{5^2}+\frac{1}{9^2}+\cdots}+\lfpr{\frac{1}{2^2}+\frac{1}{4^2}+\frac{1}{6^2}+\cdots}
\]
\[
=2\sum_{k=1}^\infty(4k-3)^{-2}+\frac{1}{4}\zeta(2)
\]
Therefore
\[
\beta(2)=2\sum_{k=1}^\infty(4k-3)^{-2}-\frac{3}{4}\zeta(2)
\]
\[
=2\sum_{k=1}^\infty(4k-3)^{-2}-\frac{\pi^2}{8}
\]

\paragraph{12.4.5}
(a)
\begin{equation*}
    \begin{split}
        \int_0^1\frac{\ln(1+x)}{x}dx & =\int_0^1\frac{1}{x}\left(x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+\cdots\right)dx\\
        & =\int_0^1\left(1-\frac{x}{2}+\frac{x^2}{3}-\frac{x^3}{4}+\cdots \right)dx\\
        & =\left[x-\frac{x^2}{2^2}+\frac{x^3}{3^2}-\frac{x^4}{4^2}+\cdots \right]_0^1\\
        & =\frac{1}{1^2}-\frac{1}{2^2}+\frac{1}{3^2}-\frac{1}{4^2}+\cdots
    \end{split}
\end{equation*}
Let the integral be $S$, and note that
\[
\zeta(2)=\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{3^2}+\frac{1}{4^2}+\cdots
\]
so
\[
\zeta(2)-S=2\left(\frac{1}{2^2}+\frac{1}{4^2}+\frac{1}{6^2}+\cdots \right)
\]
\[
=\frac{1}{2}\left(\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{3^2}+\cdots \right)=\frac{1}{2}\zeta(2)
\]
Therefore,
\[
S=\frac{1}{2}\zeta(2)
\]

(b)
\begin{equation*}
    \begin{split}
        \lim_{a\to1}\int_0^a\frac{\ln(1-x)}{x}dx & =\lim_{a\to1}\int_0^a\frac{-1}{x}\left(x+\frac{x^2}{2}+\frac{x^3}{3}+\frac{x^4}{4}+\cdots \right)dx \\
        & =-\lim_{a\to1}\int_0^a\left(1+\frac{x}{2}+\frac{x^2}{3}+\frac{x^3}{4}+\cdots \right)dx\\
        & =-\lim_{a\to1}\left[x+\frac{x^2}{2^2}+\frac{x^3}{3^2}+\frac{x^4}{4^2}+\cdots \right]_0^a\\
        & =-\left(\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{3^2}+\frac{1}{4^2}+\cdots \right)\\
        & =-\zeta(2)
    \end{split}
\end{equation*}

\paragraph{12.4.6}
(a)
\[
\sum_{s=2}^n 2^{-s}\zeta(s)=\sum_{s=2}^n 2^{-s}\sum_{p=1}^\infty\frac{1}{p^s}=\sum_{s=2}^n\sum_{p=1}^\infty\frac{1}{(2p)^s}
\]
\[
\sum_{p=1}^\infty(2p)^{-n-1}\left[1-\frac{1}{2p} \right]^{-1}=\sum_{p=1}^\infty\sum_{s=n+1}^\infty\frac{1}{(2p)^s}
\]
Therefore,
\begin{equation*}
    \begin{split}
         & \quad\,\sum_{s=2}^n 2^{-s}\zeta(2)+\sum_{p=1}^\infty(2p)^{-n-1}\left[1-\frac{1}{2p} \right]^{-1}\\
        & =  \sum_{p=1}^\infty\left(\sum_{s=2}^n\frac{1}{(2p)^s}+\sum_{n+1}^\infty\frac{1}{(2p)^s} \right)\\
        & =  \sum_{p=1}^\infty\sum_{s=2}^\infty\frac{1}{(2p)^s}=\sum_{p=1}^\infty\frac{\frac{1}{(2p)^2}}{1-\frac{1}{2p}}\\
        & =  \sum_{p=1}^\infty\frac{1}{2p(2p-1)}=\sum_{p=1}^\infty\lfpr{\frac{1}{2p-1}-\frac{1}{2p} }\\
        & =  1-\frac{1}{2}+\frac{1}{3}-\frac{1}{4}+\cdots\\
        & =  \ln 2
    \end{split}
\end{equation*}

(b)
\[
\sum_{p=1}^\infty(2p)^{-n-1}\lfbr{1-\frac{1}{2p} }^{-1}<\sum_{p=1}^\infty(2p)^{-n-1}\cdot2=\frac{1}{2^n}\zeta(n+1)<1\times10^{-6},\qquad n\geq20
\]
So by taking $n=20$, we can obtain $\ln 2$ from the first summation of the precision to the sixth decimal place:
\[
\sum_{s=2}^{20}2^{-s}\zeta(s)=0.693146
\]

\paragraph{12.4.7}
(a)
\[
\sum_{s=1}^n 4^{-2s}\zeta(2s)=\sum_{s=1}^n 4^{-2s}\sum_{p=1}^\infty\frac{1}{p^{2s}}=\sum_{s=1}^n\sum_{p=1}^\infty\frac{1}{(4p)^{2s}}
\]
\[
\sum_{p=1}^\infty(4p)^{-2n-2}\lfbr{1-\frac{1}{(4p)^2}}^{-1}=\sum_{p=1}^\infty\sum_{s=n+1}^\infty\frac{1}{(4p)^{2s}}
\]
Therefore,
\begin{equation*}
    \begin{split}
        & \quad\,\, 1-2\sum_{s=1}^n 4^{-2s}\zeta(2s)-2\sum_{p=1}^\infty(4p)^{-2n-2}\lfbr{1-\frac{1}{(4p)^2} }^{-1}\\
        & =1-2\sum_{p=1}^\infty\lfpr{\sum_{s=1}^n\frac{1}{(4p)^{2s}}+\sum_{s=n+1}^\infty\frac{1}{(4p)^{2s}} }\\
        & =1-2\sum_{p=1}^\infty\sum_{s=1}^\infty\frac{1}{(4p)^{2s}}=1-2\sum_{p=1}^\infty\frac{\frac{1}{(4p)^2}}{1-\frac{1}{(4p)^2}}\\
        & =1-2\sum_{p=1}^\infty\frac{1}{(4p+1)(4p-1)}=1-\sum_{p=1}^\infty\lfpr{\frac{1}{4p-1}-\frac{1}{4p+1} }\\
        & =1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\frac{1}{9}-\cdots\\
        & =\frac{\pi}{4}
    \end{split}
\end{equation*}

(b)
\[
2\sum_{p=1}^\infty(4p)^{-2n-2}\lfbr{1-\frac{1}{(4p)^2} }^{-1}<2\sum_{p=1}^\infty(4p)^{-2n-2}\cdot2=\frac{1}{4^{2n+1}}\zeta(2n+2)<1\times10^{-6},\qquad n\geq5
\]
So by taking $n=5$, we can obtain $\frac{\pi}{4}$ from the equation of the precision to the sixth decimal place:
\[
1-2\sum_{s=1}^5 4^{-2s}\zeta(2s)=0.785398
\]

\section*{12.5 Infinite Products}

\paragraph{12.5.1}
(There should be a condition that $0\leq a_n<1$)

For the $1+a_n$ case, if $\sum a_n$ converges,
\[
1+a_n\leq e^{a_n}
\]
\[
|\ln(1+a_n)|\leq a_n
\]
$\sum a_n$ converges, so $\sum\ln(1+a_n)$ converges by comparison test. Therefore, $\ln\prod(1+a_n)$ converges, which implies $\prod(1+a_n)$ converges.
\medskip

For the $1+a_n$ case, if $\sum a_n$ diverges,
\[
p_n=\prod_{n=1}^N(1+a_n)\geq\sum_{n=1}^N a_n=s_n
\]
$s_n$ is monotonically increasing but diverges, which implies it is infinite, so $p_n$ is infinite and diverges.
\medskip

For $1-a_n$ case, note that for $a_n<\frac{1}{2}$, we have $(1-a_n)\geq(1+2a_n)^{-1}$ and $(1-a_n)\leq(1+a_n)^{-1}$:
\[
|\ln(1-a_n)|\leq|\ln(1+2a_n)|\leq 2a_n
\]
So if $\sum a_n$ converges, then $\sum\ln(1-a_n)$ converges, and therefore $\prod(1-a_n)$ converges.
\[
-\ln(1-a_n)\geq\ln(1+a_n)
\]
So if $\sum a_n$ diverges, $\sum\ln(1+a_n)$ diverges, $\sum\ln(1-a_n)$ diverges, and therefore $\prod(1-a_n)$ diverges.

\paragraph{12.5.2}
\[
\prod_{n=1}^\infty\lfpr{\frac{1+\frac{a}{n}}{1+\frac{b}{n}} }=\prod_{n=1}^\infty\lfpr{1+\frac{a-b}{n+b} }
\]
$\sum\frac{a-b}{n+b}=(a-b)\sum\frac{1}{n+b}$ diverges when $a\neq b$, so $\prod\lfpr{\frac{1+\frac{a}{n}}{1+\frac{b}{n}} }$ diverges by Theorem in Exercise 12.5.1.

\paragraph{12.5.3}
From Equation 11.89 and 11.90:
\[
\sin z=z\prod_{n=1}^\infty\lfpr{1-\frac{z^2}{n^2\pi^2} } =z\prod_{n=1}^\infty\lfpr{1-\frac{(2z)^2}{(2n)^2\pi^2} } =z\prod_{n\;even}\lfpr{1-\frac{(2z)^2}{n^2\pi^2} }
\]
\[
\cos z=\prod_{n=1}^\infty\lfpr{1-\frac{z^2}{(n-\frac{1}{2})^2\pi^2} }=\prod_{n=1}^\infty\lfpr{1-\frac{(2z)^2}{(2n-1)^2\pi^2} } =\prod_{n\;odd}\lfpr{1-\frac{(2z)^2}{n^2\pi^2} }
\]
Therefore,
\[
2\sin z\cos z=2z\prod_{n=1}^\infty\lfpr{1-\frac{(2z)^2}{n^2\pi^2} }=\sin2z
\]

\paragraph{12.5.4}
\[
\prod_{n=2}^\infty\lfpr{1+\frac{(-1)^n}{n} }=\prod_{n\;even}\lfpr{1+\frac{1}{n} }\lfpr{1+\frac{-1}{n+1} }=\prod_{n\;even}\frac{n+1}{n}\frac{n}{n+1}=1
\]

\paragraph{12.5.5}
\[
\prod_{n=2}^\infty\lfbr{1-\frac{2}{n(n+1)} }=\prod_{n=2}^\infty\frac{(n-1)(n+2)}{n(n+1)}=\prod_{n=2}^\infty\frac{n-1}{n}\prod_{n=4}^\infty\frac{n}{n-1}=\frac{1}{2}\cdot\frac{2}{3}=\frac{1}{3}
\]

\paragraph{12.5.6}
\[
\prod_{n=2}^\infty\lfpr{1-\frac{1}{n^2} }=\prod_{n=2}^\infty\frac{(n-1)(n+1)}{n\cdot n}=\prod_{n=2}^\infty\frac{n-1}{n}\prod_{n=3}^\infty\frac{n}{n-1}=\frac{1}{2}
\]

\paragraph{12.5.7}
\[
\prod_{p=1}^\infty(1+z^p)=\prod_{p=1}^\infty\frac{1-z^{2p}}{1-z^p}=\frac{\prod_{q=1}^\infty(1-z^{2q})}{\prod_{p=1}^\infty(1-z^p)}=\frac{1}{\prod_{q=1}^\infty(1-z^{2q-1})}=\prod_{q=1}^\infty(1-z^{2q-1})^{-1}
\]
The convergence of the infinite product requires the condition $|z|<1$ because $\sum z^n$ converges when $|z|<1$.

\paragraph{12.5.8}
\[
\prod_{r=1}^\infty\lfpr{1+\frac{x}{r}}e^{-\frac{x}{r}}=\prod_{r=1}^\infty\lfpr{1+\frac{x}{r}}\lfpr{1-\frac{x}{r}+\sum_{n=2}^\infty a_n\left(\frac{x}{r}\right)^n}=\prod_{r=1}^\infty\lfpr{1+\sum_{n=2}^\infty b_n\left(\frac{x}{r}\right)^n }
\]
To verify the convergence, evaluate the sum:
\[
\sum_{r=1}^\infty\sum_{n=2}^\infty b_n\lfpr{\frac{x}{r}}^n=\sum_{n=2}^\infty\sum_{r=1}^\infty b_n\lfpr{\frac{x}{r}}^n=\sum_{n=2}^\infty b_nx^n\zeta(n)
\]
which converges for finite $x$, so the infinte products converges.

\paragraph{12.5.9}
From Equation 12.35,
\[
\cot x=\frac{1}{x}+\sum_{n=1}^\infty(-1)^n B_{2n}\frac{(2x)^{2n-1}}{(2n)!}
\]
so by integrating $\frac{d(\ln\sin x)}{dx}=\cot x$, we have
\[
\ln\sin x=\ln x+\sum_{n=1}^\infty(-1)^nB_{2n}\frac{(2x)^{2n}}{(2n)\cdot(2n)!}=\ln x+\sum_{n=1}^\infty\frac{(-1)^n 2^{2n}B_{2n}}{(2n)\cdot(2n)!}x^{2n}
\]
so we have
\[
a_0=0,\qquad a_{2n-1}=0,\qquad a_{2n}=\frac{(-1)^n2^{2n}B_{2n}}{(2n)\cdot(2n)!}
\]
for $n\in\mathbb{N}$.

\paragraph{12.5.10}
From Equation 11.89,
\[
\ln\sin z=\ln z+\sum_{n=1}^\infty\ln\lfpr{1-\left(\frac{z}{n\pi}\right)^2 }=\ln z-\sum_{n=1}^\infty\sum_{m=1}^\infty\frac{1}{m}\lfpr{\frac{z}{n\pi} }^{2m}
\]
Therefore,
\[
z\cot z=z\frac{d(\ln\sin z)}{dz}=z\cdot\frac{1}{z}-z\sum_{n=1}^\infty\sum_{m=1}^\infty2\frac{z^{2m-1}}{(n\pi)^{2m}}=1-2\sum_{m,n=1}^\infty\lfpr{\frac{z}{n\pi} }^{2m}=1-2\sum_{m=1}^\infty\frac{\zeta(2m)}{\pi^{2m}}z^{2m}
\]
From Equation 12.35, we have
\[
z\cot z=1+\sum_{n=1}^\infty\frac{(-1)^n2^{2n}B_{2n}}{(2n)!}z^{2n}
\]
So by equating each term in the summation of the two expression of $z\cot z$, we have
\[
\frac{(-1)^n2^{2n}B_{2n}}{(2n)!}=-\frac{2\zeta(2n)}{\pi^{2n}}
\]
\[
B_{2n}=(-1)^{n-1}\frac{2(2n)!}{(2\pi)^{2n}}\zeta(2n)
\]

\section*{12.6 Asymptotic Series}

\paragraph{12.6.1}
From Exercise 11.8.26, we have
\[
\int_0^\infty\cos\frac{\pi u^2}{2}du=\int_0^\infty\sin\frac{\pi u^2}{2}du=\frac{1}{2}
\]
so
\[
C(x)=\frac{1}{2}-\int_x^\infty\cos\frac{\pi u^2}{2}du
\]
\[
s(x)=\frac{1}{2}-\int_x^\infty\sin\frac{\pi u^2}{2}du
\]

(a)
Substitute $\frac{\pi u^2}{2}=t$ and integrate by parts continuously, we have
\begin{equation*}
    \begin{split}
        C(x) & =\frac{1}{2}-\int_{\frac{\pi x^2}{2}}^\infty\frac{\cos t}{\sqrt{2\pi t}}\,dt\\
        & \approx\frac{1}{2}-\left[\frac{\sin t}{(2\pi t)^{\frac{1}{2}}}-(-\pi)\frac{-\cos t}{(2\pi t)^{\frac{3}{2}}}+(-\pi)(-3\pi)\frac{-\sin t}{(2\pi t)^{\frac{5}{2}}}-(-\pi)(-3\pi)(-5\pi)\frac{\cos t}{(2\pi t)^{\frac{7}{2}}}+\cdots \right]_{\frac{\pi x^2}{2}}^\infty\\
        &  \approx\frac{1}{2}+\frac{1}{\pi x}\sin\frac{\pi x^2}{2}-\frac{\pi}{(\pi x)^3}\cos\frac{\pi x^2}{2}-\frac{1\cdot3\cdot\pi^2}{(\pi x)^5}\sin\frac{\pi x^2}{2}+\frac{1\cdot3\cdot5\cdot\pi^3}{(\pi x)^7}\cos\frac{\pi x^2}{2}+\cdots
    \end{split}
\end{equation*}
Note that the sign changes every two terms.
\medskip

(b)
Substitute $\frac{\pi u^2}{2}=t$ and integrate by parts continuously, we have
\begin{equation*}
    \begin{split}
        s(x) & =\frac{1}{2}-\int_{\frac{\pi x^2}{2}}^\infty\frac{\sin t}{\sqrt{2\pi t}}\,dt\\
        & \approx\frac{1}{2}-\left[\frac{-\cos t}{(2\pi t)^{\frac{1}{2}}}-(-\pi)\frac{-\sin t}{(2\pi t)^{\frac{3}{2}}}+(-\pi)(-3\pi)\frac{\cos t}{(2\pi t)^{\frac{5}{2}}}-(-\pi)(-3\pi)(-5\pi)\frac{\sin t}{(2\pi t)^{\frac{7}{2}}}+\cdots \right]_{\frac{\pi x^2}{2}}^\infty\\
        &  \approx\frac{1}{2}-\frac{1}{\pi x}\cos\frac{\pi x^2}{2}-\frac{\pi}{(\pi x)^3}\sin\frac{\pi x^2}{2}+\frac{1\cdot3\cdot\pi^2}{(\pi x)^5}\cos\frac{\pi x^2}{2}+\frac{1\cdot3\cdot5\cdot\pi^3}{(\pi x)^7}\cos\frac{\pi x^2}{2}-\cdots
    \end{split}
\end{equation*}
Note that the sign changes every two terms.

\paragraph{12.6.2}
Integrate by parts continuously:
\begin{equation*}
    \begin{split}
        & \quad Ci(x)+i\,si(x) \\
        & =-\int_x^\infty\frac{e^{it}}{t}dt\\
        & \approx -\left[\frac{e^{it}}{i}\frac{1}{t}-\frac{e^{it}}{i^2}\frac{(-1)}{t^2}+\frac{e^{it}}{i^3}\frac{(-1)(-2)}{t^3}-\frac{e^{it}}{i^4}\frac{(-1)(-2)(-3)}{t^4}+\frac{e^{it}}{i^5}\frac{(-1)(-2)(-3)(-4)}{t^5}-\cdots \right]_x^\infty\\
        & \approx -\frac{i\,e^{it}}{t}\left[1-i\lfpr{\frac{1!}{t}}-\lfpr{\frac{2!}{t^2}}+i\lfpr{\frac{3!}{t^3}}+\lfpr{\frac{4!}{t^4}}-\cdots \right]
    \end{split}
\end{equation*}
which is Equation 12.92, so the asymptotic expansions of $Ci(x)$ and $si(x)$ are the same with that given in the text.

\paragraph{12.6.3}
\begin{equation*}
    \begin{split}
        \mathrm{erf}(x) & =1-\frac{2}{\sqrt{\pi}}\int_x^\infty e^{-t^2}dt\\
        & =1-\frac{1}{\sqrt{\pi}}\int_{x^2}^\infty\frac{e^{-u}}{\sqrt{u}}\,du\\
        & \approx 1-\frac{1}{\sqrt{\pi}}\lfbr{\frac{-e^{-u}}{u^{\frac{1}{2}}}-\lfpr{-\frac{1}{2}}\frac{e^{-u}}{u^{\frac{3}{2}}}+\lfpr{-\frac{1}{2}}\lfpr{-\frac{3}{2}}\frac{-e^{-u}}{u^{\frac{5}{2}}}-\lfpr{-\frac{1}{2}}\lfpr{-\frac{3}{2}}\lfpr{-\frac{5}{2}}\frac{e^{-u}}{u^{\frac{7}{2}}}+\cdots }_{x^2}^\infty\\
        & \approx 1+\frac{1}{\sqrt{\pi}}\lfbr{-\frac{e^{-x^2}}{x}+\frac{1}{2}\frac{e^{-x^2}}{x^3}-\frac{1\cdot3}{2^2}\frac{e^{-x^2}}{x^5}+\frac{1\cdot3\cdot5}{2^3}\frac{e^{-x^2}}{x^7}-\cdots }\\
        & \approx 1-\frac{e^{-x^2}}{\sqrt{\pi}x}\lfbr{1-\frac{1}{2x^2}+\frac{1\cdot3}{2^2x^4}-\frac{1\cdot3\cdot5}{2^3x^6}+\cdots+(-1)^n\frac{(2n-1)!!}{2^nx^{2n}} }
    \end{split}
\end{equation*}

\paragraph{12.6.4}
Let $P_\nu(z)=1+\sum_{n=1}^\infty a_n$, then
\[
\lim_{n\to\infty}\left|\frac{a_n}{a_{n-1}} \right|=\frac{(4n)^2(4n)^2}{(2n)(2n)(8z)^2}=\frac{n^2}{z^2}\to\infty
\]
as $n\to\infty$ for finite $z$, so $P_\nu(z)$ diverges and can only be an asymptotic series. Similarly is $Q_\nu(z)$.

\paragraph{12.6.5}
$\sum_{n=0}^\infty(-1)^n\frac{1}{x^{n+1}}$ is an alternating series and $\lim_{n\to\infty}\frac{1}{x^{n+1}}=0$, so it converges and is therefore not an asymptotic series.

\paragraph{12.6.6}
By the definition,
\[
\gamma=\lim_{N\to\infty}\left(\sum_{s=1}^Ns^{-1}-\ln N \right)=\left(\sum_{s=1}^ns^{-1}-\ln n \right)+\lim_{N\to\infty}\left(\sum_{s=n+1}^N s^{-1}-\ln\frac{N}{n} \right)
\]
Let $f(x)=x^{-1}$, then $f^{(2k-1)}(x)=-(2k-1)!\,x^{-2k}$. By Euler-Maclaurin integration formula, we have
\[
\sum_{s=n+1}^\infty s^{-1}=\int_n^Ns^{-1}ds+\frac{\frac{1}{N}-\frac{1}{n}}{2}+\sum_{k=1}^p\frac{B_{2k}}{(2k)!}\left(-\frac{(2k-1)!}{N^{2k}}+\frac{(2k-1)!}{n^{2k}} \right)+R_p
\]
so
\[
\lim_{N\to\infty}\lfpr{\sum_{s=n+1}^Ns^{-1}-\ln\frac{N}{n} }=-\frac{1}{2n}+\sum_{k=1}^p\frac{B_{2k}}{(2k)n^{2k}}+R_p
\]
where $R_p$ can be arbitrarily small when $p$ is large enough. Therfore,
\[
\gamma\approx\sum_{s=1}^ns^{-1}-\ln n-\frac{1}{2n}+\sum_{k=1}^\infty\frac{B_{2k}}{(2k)n^{2k}}
\]

\paragraph{12.6.7}
\textit{(The answer given is incorrect. It is the asymptotic series for $\int_0^\infty\frac{e^{-xv}}{(1+v^2)}dv$)}

Substitute $u=xv$ and use the binomial expansion, we have
\begin{equation*}
\begin{split}
    & \quad\int_0^\infty\frac{e^{-xv}}{(1+v^2)^2}dv \\
    & =\int_0^\infty e^{-u}\lfpr{1+\frac{u^2}{x^2} }^{-2}\frac{du}{x}\\
    & =\int_0^\infty e^{-u}\sum_{n=0}^\infty\binom{-2}{n}\frac{u^{2n}}{x^{2n+1}}du\\
    & =\sum_{n=0}^\infty\binom{-2}{n}\frac{1}{x^{2n+1}}\int_0^\infty e^{-u}u^{2n}du\\
    & =\sum_{n=0}^\infty\frac{(-1)^n(n+1)\cdot(2n)!}{x^{2n+1}}\\
    & \approx\frac{1}{x}-\frac{2\cdot2!}{x^{3}}+\frac{3\cdot4!}{x^5}-\cdots+\frac{(-1)^n(n+1)\cdot(2n)!}{x^{2n+1}}
\end{split}
\end{equation*}
where we have used $\binom{-2}{n}=(-1)^n(n+1)$ and $\int_0^\infty e^{-u}u^ndu=n!$.

\section*{12.7 Method of Steepest Descents}
\paragraph{12.7.1}
\textit {The statement that "$|F(z)|^2$ can have no extremum in the interior of a region in which $F$ is analytic" is incorrect. Let $F(z)=z$, then $|F(z)|^2$ has a minimum at $z=0$. However, the fact used in the text is that "$\ln|F|$" has no extremum in the interior where $F$ is analytic (Equation 12.100), and it is a true statement which we are going to prove.}

We first prove that $\ln|F(z)|$ is harmonic (satisfies the Laplace equation) if $F(z)$ is analytic. Let $F(z)=u(z)+iv(z)$, then
\begin{equation*}
\begin{split}
    \ln|F| & = \ln|\sqrt{u^2+v^2}|=\frac{1}{2}\ln(u^2+v^2)\\
    \pdv{\ln|F|}{x} & =\frac{u\pdv{u}{x}+v\pdv{v}{x}}{u^2+v^2}\\
    \pdv{^2\ln|F|}{x^2}&=\frac{\lfpr{\pdv{u}{x}}^2+\lfpr{\pdv{v}{x}}^2+u\pdv{^2u}{x^2}+v\pdv{^2v}{x^2}}{u^2+v^2}-\frac{2\lfpr{u\pdv{u}{x}+v\pdv{v}{x} }^2}{(u^2+v^2)^2}\\
    &=\frac{-(u^2-v^2)\lfbr{\lfpr{\pdv{u}{x}}^2-\lfpr{\pdv{v}{x}}^2 }-4uv\pdv{u}{x}\pdv{v}{x}+u\pdv{^2u}{x^2}+v\pdv{^2v}{x^2} }{(u^2+v^2)^2}\\
    \pdv{^2\ln|F|}{y^2}&=\frac{-(u^2-v^2)\lfbr{\lfpr{\pdv{u}{y}}^2-\lfpr{\pdv{v}{y}}^2 }-4uv\pdv{u}{y}\pdv{v}{y}+u\pdv{^2u}{y^2}+v\pdv{^2v}{y^2} }{(u^2+v^2)^2}
\end{split}
\end{equation*}
Summing the two equations, and noting that by  Cauchy-Riemann conditions $\pdv{u}{x}=\pdv{v}{y}$,\; $\pdv{u}{y}=-\pdv{v}{x}$, we have
\[
\lfpr{\pdv{u}{x}}^2-\lfpr{\pdv{v}{x}}^2+\lfpr{\pdv{u}{y}}^2-\lfpr{\pdv{v}{y}}^2=\lfpr{\pdv{u}{x}}^2-\lfpr{\pdv{v}{x}}^2+\lfpr{\pdv{v}{x}}^2-\lfpr{\pdv{u}{x}}^2=0
\]
\[
\pdv{u}{x}\pdv{v}{x}+\pdv{u}{y}\pdv{v}{y}=\pdv{u}{x}\pdv{v}{x}-\pdv{v}{x}\pdv{u}{x}=0
\]
\[
\pdv{^2u}{x^2}+\pdv{^2u}{y^2}=0\qquad \pdv{^2v}{x^2}+\pdv{^2v}{y^2}=0
\]
Therefore,
\[
\pdv{^2\ln|F|}{x^2}+\pdv{^2\ln|F|}{y^2}=0
\]
which means $\ln|F|$ is harmonic. By the mean value property of harmonic function (the 3D version of which has been proved in Exercise 3.9.9), we have
\[
\ln|F(z_0)|=\frac{1}{2\pi r}\int_0^{2\pi}\ln|F(z_0+re^{i\theta})|\,rd\theta
\]
so the mean value of $\ln|F|$ on a circle about any point $z_0$ is equal to $\ln|F|$. Therefore, there cannot be an extremum of $\ln|F|$ at $z_0$, otherwise the mean value on an circle around $z_0$ will be less than or greater than $\ln|F(z_0)|$ (For the case $z_0$ being an maximum or minimum, respectively.)

\paragraph{12.7.2}
\[
\int_0^s\cos x^2\,dx+i\int_0^s\sin x^2\,dx=\int_0^s e^{ix^2}dx=s\int_0^1 e^{is^2z^2}dz=\sqrt{t}\int_0^1 e^{itz^2}dz
\]
Let $w(z)=itz^2$, then $w'(z)=2itz$,\; $w''(z)=2it$. So the saddle point is $z=0$, and the direction of steepest descent is
\[
\theta=-\frac{\arg w''}{2}+\frac{\pi}{2}=\frac{\pi}{4}
\]
Which means the original path moving from $(0,0)$ to $(1,0)$, is deformed to the path that starts from $(0,0)$, moving in the $\frac{\pi}{4}$ direction, and ends at $(1,0)$. To use Equation 12.108, note that in Equation 12.104 which is derived from , there is a factor "$2$" since both the ascending and descending parts are included, while in this problem since the saddle point happens to be the start point, only the descending part is involved in the integration. Therefore, use Equation 12.108 with an additional factor $\frac{1}{2}$, we have
\[
f(t)\approx\frac{1}{2}\sqrt{t}e^0e^{i\frac{\pi}{4}}\sqrt{\frac{2\pi}{|2it|}}=\sqrt{\frac{\pi}{8}}+\sqrt{\frac{\pi}{8}}i
\]
so
\[
\int_0^s\cos x^2\,dx\approx\sqrt{\frac{\pi}{8}}
\]
\[
\int_0^s\sin x^2\,dx\approx\sqrt{\frac{\pi}{8}}
\]

\paragraph{12.7.3}
Let $s=|s|e^{i\alpha}$, then
\[
\Gamma(s+1)=\int_0^\infty \rho^s e^{-\rho}d\rho=s^{s+1}\int_0^\infty e^{s(\ln z-z)}dz
\]
Proceeding as in Example 12.7.1, the saddle point is still $z=1$, and since $w''(1,s)=-s=-|s|e^{\alpha}$, we have
\[
\theta=-\frac{\arg w''}{2}+(\frac{\pi}{2}\; or\; \frac{3\pi}{2})=-\frac{\alpha}{2}\; or\; \pi-\frac{\alpha}{2}
\]
Choose $\theta=-\frac{\alpha}{2}$, and use Equation 12.108,
\[
\Gamma(s+1)\approx s^{s+1}e^{-s}e^{-\frac{i\alpha}{2}}\sqrt{\frac{2\pi}{|s|}}=\sqrt{2\pi s}\,s^se^{-s}\frac{\sqrt{s}}{\sqrt{|s|e^{i\alpha}}}=\sqrt{2\pi s}\,s^se^{-s}
\]
Note that at the vicinity of the saddle point $z=1$,\; $\mathfrak{Im}[s(\ln z-z)]=-|s|\cos\alpha$ is constant.

\section*{12.8 Dispersion Relations}
\paragraph{12.8.1}
Let $f(z)=u(z)+iv(z)$ be a function meeting the conditions of Schwarz reflection principle. For real number $x$,\; $f(x)=f^*(x^*)=f^*(x)$, which means $f(z)$ is real when $x$ is real, so $v(x)=0$. By the dispersion relation, $u(x)=0$, so $f(x)=0$. Therefore,
\[
f(z)=\frac{1}{2\pi i}\int_{-\infty}^\infty\frac{f(x)}{x-z}dx=0
\]
which means $f(z)$ is identically zero.

\paragraph{12.8.2}
\begin{equation*}
    \begin{split}
        f(x_0) & =\frac{1}{2\pi i}\left\{\int\displaylimits_{-\infty}^{x_0-\delta}\frac{f(x)}{x-x_0}dx+\int\displaylimits_{x_0+\delta}^\infty\frac{f(x)}{x-x_0}dx \right\}+\frac{1}{2\pi i}\int\displaylimits_C\frac{f(x)}{x-x_0}dx\\
        & =\frac{1}{2\pi i}\ddashint\displaylimits_{-\infty}^\infty\frac{f(x)}{x-x_0}dx+\frac{f(x_0)}{2}
    \end{split}
\end{equation*}
Therefore,
\[
f(x_0)=\frac{1}{\pi i}\ddashint\displaylimits_{-\infty}^\infty\frac{f(x)}{x-x_0}dx
\]

\paragraph{12.8.3}
(a)
Let $f(z)=e^{iz}$, then by Jordan's lemma, since $\lim_{R\to\infty}\frac{1}{z-z_0}=0$,
\[
\lim_{R\to\infty}\int\displaylimits_C\frac{e^{iz}}{z-z_0}dz=0
\]
where $C$ is a semicircle of radius $R$ in the upper half-plane with center at the origin. Therefore, using the same contour, Equation 12.116 still holds:
\[
f(z_0)=\frac{1}{2\pi i}\int\displaylimits_{-\infty}^\infty\frac{f(x)}{x-z_0}dx
\]

(b)
$e^{ix}=\cos x+i\sin x$, so
\[
\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\sin x}{x-x_0}dx=\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\sin(x+x_0)}{x}dx=\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\sin x\cos x_0}{x}dx+\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\cos x\sin x_0}{x}dx
\]
$\frac{\sin x}{x}$ is an even function, so by Exercise 1.10.2,
\[
\ddashint\displaylimits_{-\infty}^\infty\frac{\sin x}{x}dx=2\int\displaylimits_0^\infty\frac{\sin x}{x}dx=\pi
\]
$\frac{\cos x}{x}$ is an odd function, so
\[
\ddashint\displaylimits_{-\infty}^\infty\frac{\cos x}{x}dx=0
\]
Therefore,
\[
\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\sin x}{x-x_0}dx=\cos x_0
\]
which is the first part of the dispersion relations. The second part can be proved similarly:
\[
\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\cos x}{x-x_0}dx
=\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\cos(x+x_0)}{x}dx
=\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\cos x\cos x_0}{x}dx-\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\sin x\sin x_0}{x}dx
\]
\[
\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\cos x}{x-x_0}dx=-\sin x_0
\]

\paragraph{12.8.4}
If $f(x)=u(x)+iv(x)$ and $f(x)=f^*(-x)$, then $u(x)+iv(x)=u(-x)-iv(-x)$, which means $u(x)$ is even and $v(x)$ is odd.
\medskip

(a)
\begin{equation*}
    \begin{split}
        u(x_0) & =\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{v(x)}{x-x_0}dx\\
        & =\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{v(x)}{-x_0}\left(1+\frac{x}{x_0}+\cdots \right)dx\\
        & \approx -\frac{1}{\pi x_0}\ddashint\displaylimits_{-\infty}^\infty v(x)dx-\frac{1}{\pi x_0^2}\ddashint\displaylimits_{-\infty}^\infty xv(x)dx
    \end{split}
\end{equation*}
$v(x)$ is odd, so the first integral vanishes. $xv(x)$ is even, so the second integral becomes $2\int_0^\infty xv(x)dx$. Therefore,
\[
u(x_0)\approx-\frac{2}{\pi x_0^2}\int_0^\infty xv(x)dx
\]

(b)
\begin{equation*}
    \begin{split}
        v(x_0) & =-\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{u(x)}{x-x_0}dx\\
        & =-\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{u(x)}{-x_0}\left(1+\frac{x}{x_0}+\cdots \right)dx\\
        & \approx\frac{1}{\pi x_0}\ddashint\displaylimits_{-\infty}^\infty u(x)dx+\frac{1}{\pi x_0^2}\ddashint\displaylimits_{-\infty}^\infty xu(x)dx
    \end{split}
\end{equation*}
$u(x)$ is even, so the first integral becomes $2\int_0^\infty u(x)dx$.\; $xu(x)$ is odd, so the second integral vanishes. Therefore,
\[
v(x_0)\approx\frac{2}{\pi x_0}\int_0^\infty u(x)dx
\]

\paragraph{12.8.5}
(a)
From the dispersion relations,
\begin{equation*}
    \begin{split}
        v(x_0)&=-\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{u(x)}{x-x_0}dx=-\frac{1}{1+x_0^2}\\
        u(x_0) & =\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty \frac{v(x)}{x-x_0}dx\\
        & =-\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{1}{1+x^2}\frac{1}{x-x_0}dx
    \end{split}
\end{equation*}
The function has three simple poles:
\begin{alignat*}{2}
    & z=i\qquad && residue=\frac{1}{2i(i-x_0)}\\
    & z=-i\qquad && residue=\frac{1}{2i(i+x_0)}\\
    & z=x_0\qquad && residue=\frac{1}{1+x_0^2}
\end{alignat*}
The contour encloses $z=i$, and passes a semi-circle at $z=x_0$, so by the residue theorem,
\[
u(x_0)=-\frac{1}{\pi}\lfbr{2\pi i\cdot\frac{1}{2i(i-x_0)}+\pi i\frac{1}{1+x_0^2} }=\frac{x_0}{1+x_0^2}
\]

(b)
Substituting,
\[
\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{u(x)}{x-x_0}dx=\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{x}{(1+x^2)(x-x_0)}dx
\]
Find the poles with residues and use the residue theorem:
\[
\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{u(x)}{x-x_0}dx  =\frac{1}{\pi}\lfbr{2\pi i\cdot\frac{i}{2i(i-x_0)}+\pi i\cdot\frac{x_0}{1+x_0^2} }=\frac{1}{1+x_0^2}
\]

(c)
\[
f(z)|_{y=0}=u(x)+iv(x)=\frac{x}{1+x^2}-\frac{i}{1+x^2}=(x-i)^{-1}
\]
Therefore,
\[
f(z)=(z-i)^{-1}
\]
Since $\lim_{R\to\infty}z\cdot\frac{f(z)}{z-z_0}=0$, the semicircular part of the integral vanishes, so the conditions for the Hilbert transforms are satisfied.
\medskip

(d)
$f(-x)=(-x-i)^{-1}\neq f^*(x)=(x+i)^{-1}$, so the crossing conditions are not satisfied.

\paragraph{12.8.6}
By the dispersion relations:
\begin{equation*}
    \begin{split}
        \mathfrak{Re}\lfbr{n^2(\omega_0)-1 }& =k\\
        \mathfrak{Im}\lfbr{n^2(\omega_0)-1 }& =-\frac{2}{\pi}\dashint\displaylimits_0^\infty\frac{\omega_0k}{\omega^2-\omega_0^2}d\omega\\
        & =-\frac{k}{\pi}\lim_{\delta\to0}\lfpr{\lfbr{\ln\frac{\omega_0-\omega}{\omega+\omega_0} }_0^{\omega_0-\delta}+\lfbr{\ln\frac{\omega-\omega_0}{\omega+\omega_0}}_{\omega_0+\delta}^\infty}\\
        & =-\frac{k}{\pi}\lim_{\delta\to0}\left(\ln\frac{2\omega_0+\delta}{2\omega_0-\delta}\right)\\
        & =0
    \end{split}
\end{equation*}
which means when the real part is constant, the imaginary part is zero.
\medskip

(b)
It is just the converse of (a).

\paragraph{12.8.7}
\[
\int\displaylimits_{-\infty}^\infty |v(x)|^2dx=\int\displaylimits_{-\infty}^\infty\frac{1}{(x^2+1)^2}dx
\]
The function has a second pole at $z=i$ with residue
\[
residue=\lim_{z\to i}\frac{d}{dz}\lfbr{(z-i)^2\cdot\frac{1}{(z^2+1)^2} }=\frac{1}{4i}
\]
Therefore,
\[
\int\displaylimits_{-\infty}^\infty|v(x)|^2dx=2\pi i\cdot\frac{1}{4i}=\frac{\pi}{2}
\]
Note that $|u(x)|^2+|v(x)|^2=\frac{1}{x^2+1}$, and
\[
\int\displaylimits_{-\infty}^\infty\frac{1}{x^2+1}dx=2\pi i\cdot\frac{1}{2i}=\pi
\]
so
\[
\int\displaylimits_{-\infty}^\infty|u(x)|^2dx=\pi-\frac{\pi}{2}=\frac{\pi}{2}
\]

\paragraph{12.8.8}
(a)
Using the Hilbert transform:
\begin{equation*}
    \begin{split}
        v(y)& =-\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{\delta(x)}{x-y}dx=\frac{1}{\pi y}\\
        \delta(w)& =\frac{1}{\pi}\ddashint\displaylimits_{-\infty}^\infty\frac{v(y)}{y-w}dy=\frac{1}{\pi^2}\ddashint\displaylimits_{-\infty}^\infty\frac{dy}{y(y-w)}
    \end{split}
\end{equation*}

(b)
Changing the variables $w=s-t$,\; $x=y+t$, so $y=x-t$,\; $y-w=x-s$, then the equation becomes
\[
\delta(s-t)=\frac{1}{\pi^2}\ddashint\displaylimits_{-\infty}^\infty\frac{dx}{(x-t)(x-s)}
\]

\end{document}

Mathematical Methods for Physicists/Chapter 12/main.tex


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage{amssymb}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}

\usetikzlibrary{automata,positioning}

% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Assignment\ \#4}
\newcommand{\hmwkDueDate}{Due 21st September 2018}
\newcommand{\hmwkClass}{Classical Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{Prof.Manas Kulkarni}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}
\maketitle
\begin{homeworkProblem}
	\textbf{Part (a)}\\
	The formal definition of the functional derivative is given by,

	\begin{equation*}
	\dfrac{\delta F[q(x)]}{\delta q(y)} = \lim\limits_{\epsilon \rightarrow 0} \dfrac{F[q(y) + \epsilon \delta (x-y)] - F[q(y)]}{\epsilon}
	\end{equation*}
	Using familiar notions from calculus, we can write the following

	Consider the variation of the action $ S = \int L (q,\dot{q},t)dt $,
	\begin{align*}
	\delta S &= \int \delta L dt\\
	&= \int \qty(\pdv{L}{q} \delta q + \pdv{L}{\dot{q}} \delta \dot{q} )dt\\
	&= \int \qty(\pdv{L}{q} \delta q + \dv{t}\qty(\pdv{L}{\dot{q}} \delta {q}) - \dv{t}\qty(\pdv{L}{\dot{q}}) \delta {q} )dt\\
	&= \int \qty(\pdv{L}{q} - \dv{t}\qty(\pdv{L}{\dot{q}})) \delta {q} dt + \eval{\pdv{L}{\dot{q}} \delta {q}}_{x_1}^{x_2}
	\end{align*}
	As the variation at the end points in zero, the second term vanishes. The variation of the action $ \delta S $ should also be zero, and the only way this can happen is if,
	\begin{equation*}
	\pdv{L}{q} - \dv{t}\qty(\pdv{L}{\dot{q}}) = 0
	\end{equation*}
	which is the Euler-Lagrange equation.

	\textbf{Part (b)}\\
	The Lagrangian for the linear harmonic chain can be written as follows,
	\begin{equation*}
	L = \sum_n \dfrac{1}{2}m \dot{x}_i^2 - \dfrac{1}{2}k (x_i - x_{i-1})^2
	\end{equation*}
	where the $ x_i $'s are the displacements from the mean positions of the respective particles. Lets change our notations such that $ \phi_i = x_i $. Hence,
	\begin{equation*}
	L = \sum_n \dfrac{1}{2}m \dot{\phi}_i^2 - \dfrac{1}{2}k (\phi_i - \phi_{i-1})^2
	\end{equation*}
	In the limit of separation between successive $ \phi_i $'s $ \rightarrow 0 $ and $ n \rightarrow \infty $, the potential terms becomes a spatial derivative. The whole expression can be written as,
	\begin{equation*}
	L =  \int dx \qty( \dfrac{1}{2}m \dot{\phi}^2(x,t) - \dfrac{1}{2}k \phi'^2(x,t) )
	\end{equation*}
	The term in the parenthesis is called the \textit{Lagrangian Density} $\mathcal{L}$. Obtaining the equations of motion is fairly straighforward by,
	\begin{align*}
	\partial_\mu \qty(\pdv{\mathcal{L}}{(\partial_\mu \phi)}) - \pdv{\mathcal{L}}{\phi} &= 0\\
	m \ddot{\phi} - k \phi'' &= 0 \implies \qq{wave equation}
	\end{align*}
\end{homeworkProblem}

\begin{homeworkProblem}
	The idea is to write the equations of motion of this system in a combined matrix form as $ \ddot{X} = (M^{-1} V) X $. $ M $ and $ V $ can be written as follows,
	\begin{equation*}
	M = \mqty(\dmat{m_1,m_2,m_3}) \qq{and} V = \mqty(k_1 & -k_1 & 0 \\ -k_1 & k_1 + k_2 & -k_2 \\ 0 & -k_2 & k_2)
	\end{equation*}
	The normal mode frequencies are given by the eigenvalues of the matrix $ M^{-1} V $. The eigenvalues are given by,
	\begin{align*}
	\omega_1 &= 0 \\
	\omega_2 &= \frac{\sqrt{\frac{k_2 m_1 m_2^2+k_1 m_3 m_2^2+k_1 m_1 m_3 m_2+k_2 m_1 m_3 m_2-\sqrt{m_2^2 \left(\left(k_1 \left(m_1+m_2\right) m_3+k_2 m_1 \left(m_2+m_3\right)\right){}^2-4 k_1 k_2 m_1 m_2 m_3 \left(m_1+m_2+m_3\right)\right)}}{m_1 m_2^2 m_3}}}{\sqrt{2}}\\
	\omega_3 &= \frac{\sqrt{\frac{k_2 m_1 m_2^2+k_1 m_3 m_2^2+k_1 m_1 m_3 m_2+k_2 m_1 m_3 m_2+\sqrt{m_2^2 \left(\left(k_1 \left(m_1+m_2\right) m_3+k_2 m_1 \left(m_2+m_3\right)\right){}^2-4 k_1 k_2 m_1 m_2 m_3 \left(m_1+m_2+m_3\right)\right)}}{m_1 m_2^2 m_3}}}{\sqrt{2}}
	\end{align*}

	Now that we have obtained the normal mode frequencies, let's consider a few special cases,
	\begin{itemize}
		\item  $ m_1 = m_2 = m_3 = m $, $ k_1 = k_2 = k $ $\rightarrow$ $ \omega_1 = 0 , \omega_2 = \sqrt{\dfrac{k}{m}}, \omega_3 = \sqrt{\dfrac{3k}{m}}$
		\item $ m_1 = m_3 = m $, $ k_1 = k_2 = k $ $ \rightarrow$ $ \omega_1 = 0 , \omega_2 = \sqrt{\dfrac{k}{m}}, \omega_3 = \sqrt{\dfrac{k(2m + m_2)}{m m_2}} $
	\end{itemize}
	 Let's calculate the normal mode frequencies for CO$ _2 $. $m_O = 2.66 \cross 10^{-26} $ kg and $ m_C = 1.99 \cross 10^{-26} $ kg and $ k = 840  $ N/m. This gives $ \omega_1 = 0 , \omega_2 = 1.78 \cross 10^{14} $ s$ ^{-1} $ and $ \omega_3 = 3.41 \cross 10^{14} $ s$ ^{-1} $.
\end{homeworkProblem}

\begin{homeworkProblem}
The Lagrangian for this system can be written as,
\begin{equation*}
L = \dfrac{1}{2}m_1 \abs{\dot{\vb{r_1}}}^2 + \dfrac{1}{2}m_2 \abs{\dot{\vb{r_2}}}^2 - V(\vb{r_1}-\vb{r_2})
\end{equation*}
We also know, from the question, that
\begin{equation*}
\vb{R} = \dfrac{m_1\vb{r_1} + m_2\vb{r_2}}{m_1 + m_2} \qq{and} \vb{r} = \vb{r_1} - \vb{r_2}
\end{equation*}
This leads us to,
\begin{equation*}
\vb{r_1} = \vb{R} + \dfrac{m_2 \vb{r}}{m_1 + m_2} \qq{and} \vb{r_2} = \vb{R} - \dfrac{m_1 \vb{r}}{m_1 + m_2}
\end{equation*}
\begin{equation*}
\abs{\dot{\vb{r_1}}}^2 = \abs{\dot{\vb{R}}}^2 + \dfrac{m_2^2 \abs{\dot{\vb{r}}}^2}{(m_1 + m_2)^2} + \dfrac{2 m_2}{m_1 + m_2}\dot{\vb{R}} \vdot \dot{\vb{r}} \qq{and} \abs{\dot{\vb{r_2}}}^2 = \abs{\dot{\vb{R}}}^2 + \dfrac{m_1^2 \abs{\dot{\vb{r}}}^2}{(m_1 + m_2)^2} - \dfrac{2 m_1}{m_1 + m_2}\dot{\vb{R}} \vdot \dot{\vb{r}}
\end{equation*}
Substituting into the expression for the Lagrangian, one gets,
\begin{equation*}
L = \dfrac{M}{2}\abs{\dot{\vb{R}}}^2  + \dfrac{\mu}{2}\abs{\dot{\vb{r}}}^2 - V(\vb{r}) \qq{where} M = m_1 + m_2 \qq{,} \mu = \dfrac{m_1 m_2}{M}
\end{equation*}
Each component of $ \dot{\vb{R}} $ will be conserved separately as all of them are cyclic coordinates. Using $ \vb{R} = X \vu{x} + Y \vu{y} + Z \vu{z} $ and $ \dot{\vb{{r}}} = \dot{r}\vu{r} + r \dot{\vu{r}} $,
\begin{equation*}
L = \dfrac{M}{2} (\dot{X}^2 + \dot{Y}^2 )  + \dfrac{\mu}{2} (\dot{r}^2 + r^2 \dot{\theta}^2)- V(r)
\end{equation*}
\textbf{Part (a)}\\
We can see from the form of the above Lagrangian that,
\begin{equation*}
M\dot{X}= constant \qq{,} M\dot{Y}= constant \qq{,} \mu r^2 \dot{\theta}= constant
\end{equation*}
Consider the infinitesimal area swept by the vector $\vb{r}$,
\begin{equation*}
dA = \frac{r^2 d\theta}{2} \implies \dot{A} = r^2 \dfrac{\dot{\theta}}{2} = constant = l
\end{equation*}
Hence, the radius vector sweeps equal areas in equal intervals of time.
\\

\textbf{Part (b)}\\
If $  m_2 \gg m_1 $, $ \vb{R} \approx \vb{r_2}$, $ \mu \approx m_1 $ and the mass $ m_2  $ does not move. Using energy conservation (and  the fact that the centre of mass does not move),
\begin{equation*}
	\dfrac{\mu}{2} (\dot{r}^2 + r^2 \dot{\theta}^2) + V(r) = E \implies \dot{r}^2 + \dfrac{4 l^2}{r^2} = \dfrac{2}{\mu} (E - V(r))
\end{equation*}
$ r(t) $ will be given by the solution of this differential equation.\\

\textbf{Part (c)}\\
The Euler-Lagrange equation for the coordinate $ r $ is given by,
\begin{equation*}
\mu \ddot{r} = \mu r \dfrac{4 l^2}{r^4}- \dfrac{k}{r^2} \implies \ddot{r} - \dfrac{4l^2}{r^3} + \dfrac{k}{\mu r^2} = 0
\end{equation*}
Multiplying by $ \dot{r} $ and integrating with time, we get,
\begin{equation*}
\dot{r}^2 + \dfrac{2l^2}{r^2} - \dfrac{k}{\mu r} = constant = E
\end{equation*}
\end{homeworkProblem}
\end{document}


\documentclass[11pt,oneside]{article}	%use"amsart"insteadof"article"forAMSLaTeXformat
\usepackage{geometry}		%Seegeometry.pdftolearnthelayoutoptions.Therearelots.
\geometry{letterpaper}		%...ora4paperora5paperor...
%\geometry{landscape}		%Activateforforrotatedpagegeometry
%\usepackage[parfill]{parskip}		%Activatetobeginparagraphswithanemptylineratherthananindent
\usepackage{graphicx}				%Usepdf,png,jpg,orepsßwithpdflatex;useepsinDVImode
								%TeXwillautomaticallyconverteps-->pdfinpdflatex
\usepackage{amssymb}
\usepackage[colorlinks]{hyperref}

%----macros begin---------------------------------------------------------------
\usepackage{color}
\usepackage{amsthm}

\def\conv{\mbox{\textrm{conv}\,}}
\def\aff{\mbox{\textrm{aff}\,}}
\def\E{\mathbb{E}}
\def\R{\mathbb{R}}
\def\Z{\mathbb{Z}}
\def\tex{\TeX}
\def\latex{\LaTeX}
\def\v#1{{\bf #1}}
\def\p#1{{\bf #1}}
\def\T#1{{\bf #1}}

\def\vet#1{{\left(\begin{array}{cccccccccccccccccccc}#1\end{array}\right)}}
\def\mat#1{{\left(\begin{array}{cccccccccccccccccccc}#1\end{array}\right)}}

\def\lin{\mbox{\rm lin}\,}
\def\aff{\mbox{\rm aff}\,}
\def\pos{\mbox{\rm pos}\,}
\def\cone{\mbox{\rm cone}\,}
\def\conv{\mbox{\rm conv}\,}
\newcommand{\homog}[0]{\mbox{\rm homog}\,}
\newcommand{\relint}[0]{\mbox{\rm relint}\,}

%----macros end-----------------------------------------------------------------

\title{Modeling Geometry with Assemblies in SysML
\footnote{This document is part of the \emph{Linear Algebraic Representation with CoChains} (LAR-CC) framework~\cite{cclar-proj:2013:00}. \today}
}
%\author{TheAuthor}
%\date{}							%Activatetodisplayagivendateornodate

\begin{document}
\maketitle
\nonstopmode

\begin{abstract}
In this module a preliminary concept implementation is provided for the possible introduction of a novel kind of 3D diagram in SysML. Such ``Assembly" Diagram in used to specify an operable description of the 3D geometry of a system part.
\end{abstract}

\tableofcontents

%===============================================================================
\section{Introduction}
%===============================================================================
%-------------------------------------------------------------------------------
\subsection{bbbbbbbb}
%-------------------------------------------------------------------------------
%===============================================================================
\section{Implementation}
%===============================================================================
%-------------------------------------------------------------------------------
\subsection{Diagram initialization}
%-------------------------------------------------------------------------------

\paragraph{Uniform cell sizing}

A cuboidal 3-complex is generated by the script below, where the cells have uniform dimension on each coordinate direction.

%-------------------------------------------------------------------------------
@D Diagram initialization
@{""" Diagram initialization """
def assemblyDiagramInit(shape):
	print "\n shape =",shape
	# shape must be 3D, i.e. a python array with 3 indices
	assert len(shape) == 3
	diagram = larCuboids(shape)
	return diagram
@}
%-------------------------------------------------------------------------------

\paragraph{Non-uniform cell sizing}

The parameter \texttt{quoteList} is used here to generate the new vertices of the \texttt{diagram}, previously generated with uniform spacing between the cell vertices in every coordinate direction.
Each \texttt{pattern} in \texttt{quoteList} is a list of positive numbers, each corresponding to the size of the corresponding "coordinate stripe".

%-------------------------------------------------------------------------------
@D Diagram initialization (non-uniform sizing)
@{""" Diagram initialization """
def assemblyDiagramInit (shape):
	def assemblyDiagram (quoteList):
		print "\n shape =",shape
		# shape and quoteList must be 3D, i.e. a python array with 3 indices
		assert (len(shape) == 3) and (len(quoteList) == 3)
		coordList = [list(cumsum([0]+pattern)) for pattern in quoteList]
		verts = CART(coordList)
		_,CV = larCuboids(shape)
		return verts,CV
	return assemblyDiagram
@}
%-------------------------------------------------------------------------------

\paragraph{Diagram scaling to cuboid of given size}
The \texttt{size} parameter is the array of lateral dimensions to which to scale the
\texttt{diagram} parameter. \texttt{size} must be an array of 3 numbers; \texttt{diagram} is
a LAR model

%-------------------------------------------------------------------------------
@D Diagram scaling to sized cuboid
@{""" Diagram scaling to given size """
def unitDiagram(diagram, size=[1,1,1]):
	V,CV = diagram
	print "\n shape =",shape
	# size must be a python array with 3 numbers
	assert (len(size) == 3) and (AND(AA(ISNUM)(size)) == True)
	V_ = array(V) / AA(float)(max(V))
	V = (V_ * size).tolist()
	diagram = V,CV
	return diagram
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsection{Diagram segmentation}
%-------------------------------------------------------------------------------

\paragraph{Boundary cells ($3D\to 2D$) computation}
The computations of boundary cells is executed by calling the \texttt{boundaryCells} from the \texttt{larcc} module.

%-------------------------------------------------------------------------------
@D Boundary cells ($3D\to 2D$) computation
@{def lar2boundaryFaces(CV,FV):
	""" Boundary cells computation """
	return boundaryCells(CV,FV)
@}
%-------------------------------------------------------------------------------

\paragraph{Interior partitions ($3D\to 2D$) computation}
The indices of the boundary 2-cells are returned in \texttt{boundarychain2D}, and subtracted from the set $\{0,1,\ldots,|E|-1\}$ in order to return the indices of the \texttt{interiorCells}.
%-------------------------------------------------------------------------------
@D Interior partitions ($3D\to 2D$) computation
@{def lar2InteriorFaces(CV,FV):
	""" Boundary cells computation """
	boundarychain2D = boundaryCells(CV,FV)
	totalChain2D = range(len(FV))
	interiorCells = set(totalChain2D).difference(boundarychain2D)
	return interiorCells
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsection{Subdiagram mapping}
%-------------------------------------------------------------------------------

The aim of this section is to allow for separate development of subdiagrams of a geometric diagram.
When satisfied with the current design situation,  the developer may map a whole diagram into a single 3D cell of the upper-level diagram --- in the following called the \emph{master} diagram.
Of course, such nesting may happen several times within a (father) master, producing a hierarchical decomposition (of any depth) of the geometry diagrams.

\paragraph{Task decomposition}
The procedure to map a diagram to a sub diagram is described below in a top-down manner,
decomposing the task into an ordered set of subtasks.

The \texttt{diagram2cell} functions below works as follows.  Its job is to map the LAR model \texttt{diagram} (semantically a 3-array of cuboidal blocks) onto the 3D-cell of the \texttt{master} LAR model (another 3-array of cuboidal blocks), indexed by the integer \texttt{cell} parameter. In few words: mapping \texttt{diagram} onto the given \texttt{cell} of \texttt{master}.

First, the matrix \texttt{mat}of this 3D-window to 3D-viewport transformation is computed, by invoking \texttt{diagram2cellMatrix}. Then, the \texttt(mat) transformation is applied to \texttt{vertices}.
Then both such LAR models are passed as parameters of the \texttt{vertexSieve} function, that returns a single vertex list \texttt{V}, two (reindexed) lists \texttt{CV1} and \texttt{CV2}, and the number \texttt{n12} of common vertices.

We can look at their common incidence matrix as shown in Figure~\ref{}.

\begin{figure}[htbp] %  figure placement: here, top, bottom, or page
   \centering
   \includegraphics[width=0.4\linewidth]{images/merge}
   \caption{Structure of the characteristic matrix $M(CV)$ afre the merge of two LAR models, and identification of the common vertices.}
   \label{fig:example}
\end{figure}

%-------------------------------------------------------------------------------
@D Subdiagram to diagram mapping
@{
@< 3D window to viewport transformation @>

def diagram2cell(diagram,master,cell):
	mat = diagram2cellMatrix(diagram)(master,cell)
	diagram =larApply(mat)(diagram)
	(V1,CV1),(V2,CV2) = master,diagram
	n1,n2 = len(V1), len(V2)

	# identification of common vertices
	V, CV1, CV2, n12 = vertexSieve(master,diagram)
	commonRange = range(n1-n12, n1)
	newRange = range(n1,n1-n12+n2)

	# addition of incident vertices into the adjacents of theCell
	def checkInclusion(V,theCell,newRange):
		theVerts = [V[v] for v in theCell]
		theMin, theMax = min(theVerts), max(theVerts)
		theCell += [v for v in newRange if (
			theMin[0] <= V[v][0] and theMin[1] <= V[v][1] and theMin[2] <= V[v][2]
			and
			V[v][0] <= theMax[0] and V[v][1] <= theMax[1] and V[v][2] <= theMax[2]
			)]
		return theCell

	# addition of new vertices into the adjacents of cell c
	CV1 = [checkInclusion(V,c,newRange)
			if set(c).intersection(commonRange) != set() else c
			 for c in CV1]

	# masterBoundaryFaces = boundaryOfChain(CV,FV)([cell])
	# diagramBoundaryFaces = lar2boundaryFaces(CV,FV)
	CV = [c for k,c in enumerate(CV1) if k != cell] + CV2

	master = V, CV
	return master
@}
%-------------------------------------------------------------------------------

\paragraph{3D window to viewport transformation}
%-------------------------------------------------------------------------------
@D 3D window to viewport transformation
@{""" 3D window to viewport transformation """
def diagram2cellMatrix(diagram):
	def diagramToCellMatrix0(master,cell):
		wdw = min(diagram[0]) + max(diagram[0])			# window3D
		cV = [master[0][v] for v in master[1][cell]]
		vpt = min(cV) + max(cV)								# viewport3D
		print "\n window3D =",wdw
		print "\n viewport3D =",vpt

		mat = zeros((4,4))
		mat[0,0] = (vpt[3]-vpt[0])/(wdw[3]-wdw[0])
		mat[0,3] = vpt[0] - mat[0,0]*wdw[0]
		mat[1,1] = (vpt[4]-vpt[1])/(wdw[4]-wdw[1])
		mat[1,3] = vpt[1] - mat[1,1]*wdw[1]
		mat[2,2] = (vpt[5]-vpt[2])/(wdw[5]-wdw[2])
		mat[2,3] = vpt[2] - mat[2,2]*wdw[2]
		mat[3,3] = 1
		print "\n mat =",mat
		return mat
	return diagramToCellMatrix0
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
%===============================================================================
\section{Topological consistency}
%===============================================================================
%-------------------------------------------------------------------------------

When a 3D diagram is generated as a Cartesian product of 1D complexes, it is relatively easy to
compute its cells of any dimension. For this purpose, see the the module \texttt{largrid}
and/or the function \texttt{gridSkeletons(shape)}, that returns the list of skeletons
generated by the cellular complex of a given \texttt{shape}.

Two different strategies may be used to guarantee the correctness of topology after
local refinements, that provide a replacement of single cells with subdivided complexes. Such two
strategies are
discussed and developed in the next two subsections.

%-------------------------------------------------------------------------------
\subsection{Decomposition of the whole space}
%-------------------------------------------------------------------------------
As already coped with in module \texttt{larcc}, the facets, i.e.~the ($d-1$)-faces,
of a cellular $d$-complex may be easily computed using the product of the sparse
characteristic matrix $M_d$ times its transpose $M_d^t$. It is easy to see that
each element $a_{ij}$ of
\[
A_d = M_d\, M_d^t = (a_{ij})
\]
provides the number of common vertices between the $d$-face $\gamma_i$ and the
$d$-face $\gamma_j$. When this number is greater or equal than $d$, there is a common
$(d-1)$-face shared between $\gamma_i$ and $\gamma_j$.

In order to guarantee that all $(d-1)$-faces can be discovered by this method, a
cellular decomposition of the whole $\E^d$ must be maintained, including both \emph{solid} cells,
i.e.~the decomposition of the interior space, and \emph{empty} cells, corresponding to a
decomposition of the exterior space.

\paragraph{Exterior space of a block diagram}

%-------------------------------------------------------------------------------
@D Exterior space of a block diagram
@{""" Exterior space of a block diagram """
def exteriorCells(diagram):
	V,CV = diagram
	minVert, maxVert = min(V), max(V)
	d = len(V[0])
	outchain = [[] for k in range(2*d)]
	for k,v in enumerate(V):
		for h in range(d):
			if v[h] == minVert[h]: outchain[h] += [k]
			if v[h] == maxVert[h]: outchain[h+d] += [k]
	return outchain
@}
%-------------------------------------------------------------------------------

The aim of computing che chain of exterior cells is associated to the computation of
of the $(d-1)$-skeleton, in turn needed for the computation of the boundary and coboundary operators.
Look to Section~\ref{sec:exterior} for a worked example.

%-------------------------------------------------------------------------------
\subsection{Promoting local upgrades in all dimensions}
%-------------------------------------------------------------------------------

%===============================================================================
\section{Library export}
%===============================================================================
%-------------------------------------------------------------------------------
\subsection{Exporting the library}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
@O larlib/larlib/sysml.py
@{""" sysml library """
from larlib import *
DRAW = COMP([VIEW,STRUCT,MKPOLS])

@< To compute the boundary (d-1)-chain of a given d-chain @>
@< Diagram initialization (non-uniform sizing) @>
@< Boundary cells ($3D\to 2D$) computation @>
@< Interior partitions ($3D\to 2D$) computation @>
@< Diagram scaling to sized cuboid @>
@< Drawing numbers of cells @>
@< Subdiagram to diagram mapping @>
@< Exterior space of a block diagram @>
@< Place vertices of two LAR models in a common space @>
@}
%-------------------------------------------------------------------------------

%===============================================================================
\section{Tests}
%===============================================================================
%-------------------------------------------------------------------------------
\subsection{Diagram initialization}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
@O test/py/sysml/test01.py
@{""" testing initial steps of Assembly Diagram construction """
from larlib import *

shape = [1,2,2]
sizePatterns = [[1],[2,1],[0.8,0.2]]
diagram = assemblyDiagramInit(shape)(sizePatterns)
print "\n diagram =",diagram
VIEW(SKEL_1(STRUCT(MKPOLS(diagram))))

VV,EV,FV,CV = gridSkeletons(shape)
boundaryFaces = lar2boundaryFaces(CV,FV)
interiorFaces = list(set(range(len(FV))).difference(boundaryFaces))
print "\n boundary faces =",boundaryFaces
print "\n interior faces =",interiorFaces
diagram1 = unitDiagram(diagram)
VIEW(SKEL_1(STRUCT(MKPOLS(diagram1))))

hpc = SKEL_1(STRUCT(MKPOLS(diagram1)))
V = diagram1[0]
hpc = cellNumbering((V,FV),hpc)(interiorFaces,YELLOW,.5)
VIEW(hpc)
hpc = cellNumbering((V,EV),hpc)([f for f in interiorFaces],GREEN,.4)
VIEW(hpc)
hpc = cellNumbering((V,VV),hpc)(range(len(VV)),RED,.3)
VIEW(hpc)

@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsection{Diagram merging}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
@O test/py/sysml/test02.py
@{""" definition and merging of two diagrams into a single diagram """
from larlib import *

master = assemblyDiagramInit([2,2,2])([[.4,.6],[.4,.6],[.4,.6]])
diagram = assemblyDiagramInit([3,3,3])([[.4,.2,.4],[.4,.2,.4],[.4,.2,.4]])
VIEW(SKEL_1(STRUCT([DRAW(master),T(2)(1),DRAW(diagram)])))

hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(master[1])),WHITE,.5)
VIEW(hpc)

master = diagram2cell(diagram,master,7)
VIEW(SKEL_1(STRUCT( MKPOLS(master) )))

@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsection{Diagram visualization}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
@O test/py/sysml/test03.py
@{""" definition and merging of two diagrams into a single diagram """
from larlib import *

master = assemblyDiagramInit([2,2,2])([[.4,.6],[.4,.6],[.4,.6]])
diagram = assemblyDiagramInit([3,3,3])([[.4,.2,.4],[.4,.2,.4],[.4,.2,.4]])

VV,EV,FV,CV = gridSkeletons([2,2,2])
V,CV = master
hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(CV)),CYAN,.5)
VIEW(hpc)

master = diagram2cell(diagram,master,7)
VIEW(SKEL_1(STRUCT( MKPOLS(master) )))

VIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS(larFacets(master))))

masterBoundaryFaces = boundaryOfChain(CV,FV)([7])
diagramBoundaryFaces = lar2boundaryFaces(CV,FV)
@}
%-------------------------------------------------------------------------------

\begin{figure}[htbp] %  figure placement: here, top, bottom, or page
   \centering
   \includegraphics[height=0.49\linewidth,width=0.49\linewidth]{images/mastermerged}
   \includegraphics[height=0.49\linewidth,width=0.49\linewidth]{images/masterfacets}
   \caption{Example of a geometry diagram merged in a master diagram}
   \label{fig:mastermerged}
\end{figure}

\begin{figure}[htbp] %  figure placement: here, top, bottom, or page
   \centering
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig2}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig4}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig5}

   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig6}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig7}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig8}

   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig9}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig10}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig11}

   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig12}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig13}
   \includegraphics[height=0.3\linewidth,width=0.3\linewidth]{images/fig14}

   \caption{The construction process of the \texttt{master} block diagram built by the example \texttt{test/py/sysml/test4.py} of Section~\ref{sec:master}.}
   \label{fig:master}
\end{figure}

%-------------------------------------------------------------------------------
\subsection{progressive refinement of a block diagram}
\label{sec:master}
%-------------------------------------------------------------------------------

In this example, a step-by step generation of a simple apartment is produced, using
\texttt{assemblyDiagramInit} to produce a block diagram of given \texttt{shape} and
\texttt{size}, the \texttt{cellNumbering} function to generate an \emph{hpc} value
with the numbers of 3-cells in the current "master" diagram, the \texttt{diagram2cell}
function to map and merge a \texttt{diagram} into a \texttt{cell} of the \texttt{master}.

The construction process is visualised in Figure~\ref{fig:master}.

Remember that in \texttt{lar-cc} the numbering of cells in a model is 0-based (like
in python). Conversely, in \texttt{pyplasm} the numbering of cells (for example of
vertex indices in \texttt{MKPOL}) is 1-based, like in Fortran or MATLAB.

%-------------------------------------------------------------------------------
@O test/py/sysml/test04.py
@{""" progressive refinement of a block diagram """
from larlib import *

master = assemblyDiagramInit([5,5,2])([[.3,3.2,.1,5,.3],[.3,4,.1,2.9,.3],[.3,2.7]])
V,CV = master
hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(CV)),CYAN,2)
VIEW(hpc)

toRemove = [13,33,17,37]
master = V,[cell for k,cell in enumerate(CV) if not (k in toRemove)]
DRAW(master)

hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(master[1])),CYAN,2)
VIEW(hpc)

toMerge = 29
cell = MKPOL([master[0],[[v+1 for v in  master[1][toMerge]]],None])
VIEW(STRUCT([hpc,cell]))

diagram = assemblyDiagramInit([3,1,2])([[2,1,2],[.3],[2.2,.5]])
master = diagram2cell(diagram,master,toMerge)
hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(master[1])),CYAN,2)
VIEW(hpc)

toRemove = [47]
master = master[0], [cell for k,cell in enumerate(master[1]) if not (k in toRemove)]
DRAW(master)

hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(master[1])),CYAN,2)
VIEW(hpc)

toMerge = 34
cell = MKPOL([master[0],[[v+1 for v in  master[1][toMerge]]],None])
VIEW(STRUCT([hpc,cell]))

diagram = assemblyDiagramInit([5,1,3])([[1.5,0.9,.2,.9,1.5],[.3],[1,1.4,.3]])
master = diagram2cell(diagram,master,toMerge)
hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(master[1])),CYAN,2)
VIEW(hpc)

toRemove = [53,59]
master = master[0], [cell for k,cell in enumerate(master[1]) if not (k in toRemove)]
DRAW(master)
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsection{Using the cochain of exterior cells}
\label{sec:exterior}
%-------------------------------------------------------------------------------

Here we develop the same example \texttt{} given above, but using also a cochain of empty cells,
in order to be able to extract the boundary and coboundary operators of the cell decompositions.
The \texttt{exteriorChain}
of the \texttt{master} diagram is first computed after the \texttt{master} initialisation, and later updated with cells defined as empty

%-------------------------------------------------------------------------------
@O test/py/sysml/test05.py
@{""" boundary extraction of a block diagram """
from larlib import *

DRAW = COMP([VIEW,STRUCT,MKPOLS])

master = assemblyDiagramInit([5,5,2])([[.3,3.2,.1,5,.3],[.3,4,.1,2.9,.3],[.3,2.7]])
diagram1 = assemblyDiagramInit([3,1,2])([[2,1,2],[.3],[2.2,.5]])
diagram2 = assemblyDiagramInit([5,1,3])([[1.5,0.9,.2,.9,1.5],[.3],[1,1.4,.3]])

hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(master[1])),CYAN,2)
VIEW(hpc)

master = diagram2cell(diagram2,master,39)
master = diagram2cell(diagram1,master,31)

hpc = SKEL_1(STRUCT(MKPOLS(master)))
hpc = cellNumbering (master,hpc)(range(len(master[1])),CYAN,2)
VIEW(hpc)

emptyChain = [17,13,32,36,52,58,65]
solidCV = [cell for k,cell in enumerate(master[1]) if not (k in emptyChain)]
DRAW((master[0],solidCV))

exteriorCV =  [cell for k,cell in enumerate(master[1]) if k in emptyChain]
exteriorCV += exteriorCells(master)
CV = solidCV + exteriorCV
V = master[0]
FV = [f for f in larFacets((V,CV),3,len(exteriorCV))[1] if len(f) >= 4]
VIEW(EXPLODE(1.5,1.5,1.5)(MKPOLS((V,FV))))

BF = boundaryCells(solidCV,FV)
boundaryFaces = [FV[face] for face in BF]
B_Rep = V,boundaryFaces
VIEW(EXPLODE(1.1,1.1,1.1)(MKPOLS(B_Rep)))
VIEW(STRUCT(MKPOLS(B_Rep)))

@< Transform the LAR boundary model in a triangle model @>
@}
%-------------------------------------------------------------------------------

\paragraph{Transform the LAR boundary model in a triangles model}
The transformation from a boundary representation made by general 2D convex faces to a set of triangle faces is provided below.

%-------------------------------------------------------------------------------
@D Transform the LAR boundary model in a triangle model
@{
verts, triangles = quads2tria(B_Rep)
B_Rep = V,boundaryFaces
VIEW(EXPLODE(1.1,1.1,1.1)(MKPOLS((verts, triangles))))
VIEW(STRUCT(MKPOLS((verts, triangles))))
@}
@}
%-------------------------------------------------------------------------------

%===============================================================================
\appendix
\section{Utilities}
%===============================================================================

%-------------------------------------------------------------------------------
@D To compute the boundary (d-1)-chain of a given d-chain
@{
def boundaryOfChain(cells,facets):
	csrBoundaryMat = larBoundary(cells,facets)
	csrChain = zeros((len(cells),1))
	def boundaryOfChain0(chain):
		for cell in chain:  csrChain[cell,0]=1.0
		csrBoundaryChain = matrixProduct(csrBoundaryMat, csrChain)
		boundaryCells = [k for k,val in enumerate(csrBoundaryChain.tolist())
							if val == [1.0]]
		return boundaryCells
	return boundaryOfChain0
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsection{Initial import of modules}
%-------------------------------------------------------------------------------

\paragraph{Initial import of modules}

%-------------------------------------------------------------------------------
@D Initial import of modules
@{""" Initial import of modules """
from lar2psm import *
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsection{Reordering of vertex coordinates}
%-------------------------------------------------------------------------------

A global reordering of vertex coordinates is executed as the first step of the Boolean algorithm, in order to eliminate the duplicate vertices, by substituting duplicate vertex copies (coming from two close points) with a single instance.

Two dictionaries are created, then merged in a single dictionary, and finally split into three subsets of (vertex,index) pairs, with the aim of rebuilding the input representations, by making use of a novel and more useful vertex indexing.

The union set of vertices is finally reordered using the three subsets of vertices belonging (a) only to the first argument, (b) only to the second argument and (c) to both, respectively denoted as $V_1, V_2, V_{12}$. A top-down description of this initial computational step is provided by the set of macros discussed in this section.

%-------------------------------------------------------------------------------
@D Place vertices of two LAR models in a common space
@{""" Place vertices of two LAR models in a common space """
@< Initial indexing of vertex positions @>
@< Merge two dictionaries with keys the point locations @>
@< Filter the common dictionary into three subsets @>
@< Compute an inverted index to reorder the vertices of arguments @>
@< Return the single reordered pointset and the two $d$-cell arrays @>
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsubsection{Re-indexing of vertices}
%-------------------------------------------------------------------------------

\paragraph{Initial indexing of vertex positions}
The input LAR models are located in a common space by (implicitly) joining \texttt{V1} and \texttt{V2} in a same array, and (explicitly) shifting the vertex indices in \texttt{CV2} by the length of \texttt{V1}.
%-------------------------------------------------------------------------------
@D Initial indexing of vertex positions
@{from collections import defaultdict, OrderedDict

def vertexSieve(model1, model2):
	V1,CV1 = model1; V2,CV2 = model2
	n = len(V1); m = len(V2)
	def shift(CV, n):
		return [[v+n for v in cell]for cell in CV]
	CV2 = shift(CV2,n)
@}
%-------------------------------------------------------------------------------

\paragraph{Merge two dictionaries with point location as keys}
Since currently \texttt{CV1} and \texttt{CV2} point to a set of vertices larger than their initial sets
\texttt{V1} and \texttt{V2}, we index the set $\texttt{V1} \cup \texttt{V2}$ using a Python \texttt{defaultdict} dictionary, in order to avoid errors of "missing key". As dictionary keys, we use the string representation of the vertex position vector provided by the \texttt{vcode(4)} function given in the Appendix.
%-------------------------------------------------------------------------------
@D Merge two dictionaries with keys the point locations
@{
	vdict1 = defaultdict(list)
	for k,v in enumerate(V1): vdict1[vcode(4)(v)].append(k)
	vdict2 = defaultdict(list)
	for k,v in enumerate(V2): vdict2[vcode(4)(v)].append(k+n)

	vertdict = defaultdict(list)
	for point in vdict1.keys(): vertdict[point] += vdict1[point]
	for point in vdict2.keys(): vertdict[point] += vdict2[point]
@}
%-------------------------------------------------------------------------------

\paragraph{Example of string coding of a vertex position}
The position vector of a point of real coordinates is provided by the function \texttt{vcode(4)}.
An example of coding is given below. The \emph{precision} of the string representation can be tuned at will.
{\small
\begin{verbatim}
>>> vcode(4)([-0.011660381062724849, 0.297350056848685860])
'[-0.0116604, 0.2973501]'
\end{verbatim}}

\paragraph{Filter the common dictionary into three subsets}
\texttt{Vertdict}, dictionary of vertices, uses as key stye position vectors of vertices coded as string, and as values the list of integer indices of vertices on the given position. If the point position belongs either to the first or to second argument only, it is stored in \texttt{case1} or \texttt{case2} lists respectively. If the position (\texttt{item.key}) is shared between two vertices, it is stored in \texttt{case12}.
The variables \texttt{n1}, \texttt{n2}, and \texttt{n12} remember the number of vertices respectively stored in each repository.
%-------------------------------------------------------------------------------
@D Filter the common dictionary into three subsets
@{
	case1, case12, case2 = [],[],[]
	for item in vertdict.items():
		key,val = item
		if len(val)==2:  case12 += [item]
		elif val[0] < n: case1 += [item]
		else: case2 += [item]
	n1 = len(case1); n2 = len(case12); n3 = len(case2)
@}
%-------------------------------------------------------------------------------

\paragraph{Compute an inverted index to reorder the vertices of Boolean arguments}
The new indices of vertices are computed according with their position within the storage repositories \texttt{case1}, \texttt{case2}, and \texttt{case12}. Notice that every \texttt{item[1]} stored in \texttt{case1} or \texttt{case2} is a list with only one integer member. Two such values are conversely stored in each \texttt{item[1]} within \texttt{case12}.
%-------------------------------------------------------------------------------
@D Compute an inverted index to reorder the vertices of arguments
@{
	invertedindex = list(0 for k in range(n+m))
	for k,item in enumerate(case1):
		invertedindex[item[1][0]] = k
	for k,item in enumerate(case12):
		invertedindex[item[1][0]] = k+n1
		invertedindex[item[1][1]] = k+n1
	for k,item in enumerate(case2):
		invertedindex[item[1][0]] = k+n1+n2
@}
%-------------------------------------------------------------------------------

%-------------------------------------------------------------------------------
\subsubsection{Re-indexing of d-cells}
%-------------------------------------------------------------------------------

\paragraph{Return the single reordered pointset and the two $d$-cell arrays}
We are now finally ready to return two reordered LAR models defined over the same set \texttt{V} of vertices, and where (a) the vertex array \texttt{V} can be written as the union of three disjoint sets of points $C_1,C_{12},C_2$; (b) the $d$-cell array \texttt{CV1} is indexed over $C_1\cup C_{12}$; (b) the $d$-cell array \texttt{CV2} is indexed over $C_{12}\cup C_{2}$.

The \texttt{vertexSieve} function will return the new reordered vertex set $V = (V_1 \cup V_2) \setminus (V_1 \cap V_2)$, the two renumbered $s$-cell sets \texttt{CV1} and \texttt{CV2}, and the size \texttt{len(case12)} of $V_1 \cap V_2$.
%-------------------------------------------------------------------------------
@D Return the single reordered pointset and the two $d$-cell arrays
@{
	V = [eval(p[0]) for p in case1] + [eval(p[0]) for p in case12] + [eval(
				p[0]) for p in case2]
	CV1 = [sorted([invertedindex[v] for v in cell]) for cell in CV1]
	CV2 = [sorted([invertedindex[v] for v in cell]) for cell in CV2]
	return V, CV1, CV2, len(case12)
@}
%-------------------------------------------------------------------------------

\bibliographystyle{amsalpha}
\bibliography{sysml}

\end{document}