\chapter[Bremsstrahlung]{Bremsstrahlung}

 The class G4eBremsstrahlung calculates the continuous energy loss
  due to {\em sub-cutoff} photons and
 simulates the 'discrete' part of the interaction ,
the bremsstrahlung  by $e^-/e^+$ . The formulae used here
 are the very similar to those used in GEANT3 (\cite{ebrem.geant3}).
 The only {\em important} difference is that in GEANT4 both of the LPM
effect and dielectric supression of the bremsstrahlung
(\cite{ebrem.galitsky},\cite{ebrem.anthony}) have been implemented,
while GEANT3 contains the latter only (using the name Migdal correction
for it) .

\section{Cross section and energy loss}

Let's call $d\sigma(Z,T,k)/dk$ the differential cross-section for
production of a photon of energy $k$ by an electron of kinetic energy
$T$ in the field of an atom of charge $Z$, and
$k_c$ the energy cut-off below which the soft photons are treated
as continuous energy loss .
Then the mean value of the energy lost by the electron due
to soft photons is
\begin{equation}
  E_{Loss}^{brem} (Z,T,k_c ) =
\int_{0}^{k_ c}k\frac{d \sigma (Z,T,k)}{dk}dk
\end{equation}
whereas the total cross-section for the emission of
a photon of energy larger than $k_c$ is
\begin{equation}
 \sigma_{brem} (Z,T,k_c ) = \int_{k_c}^{T}\frac{d \sigma (Z,T,k)}{dk} dk
\end{equation}
Many theories of the bremsstrahlung process exist, each with its own
limitations and regions of applicability. Perhaps the best synthesis
of these theories can be found in the paper of S.M. Seltzer and M.J.
Berger \cite{ebrem.seltzer}. The authors give a tabulation of the
bremsstrahlung cross-section $d\sigma/dk$ differential in the photon
energy $k$, for electrons with kinetic energies $T$ from 1 keV to 10
GeV. For electron energies above 10 GeV the screened Bethe-Heitler
differential cross-section can be used
(\cite{ebrem.egs4}
together with the dielectric supression
correction (\cite{ebrem.messel} , \cite{ebrem.migdal} ) .
  This correction
 decreases the differential cross-section at photon
energies below a certain fraction of the incident electron energy
($d\sigma/dk$ decreases significantly if $ k/T \leq 10^{-4}$.)

\subsection{Parameterisation of energy loss and total cross-section}
Using the tabulated cross-section values of Seltzer and Berger together
with the corrected Bethe-Heitler formula (which so includes the
 dilelectric supression,too) we have computed
$\sigma(Z,T,k_c ) $
and we have used these computed values as ``data points''
in the fitting procedure.
Calculating the ``low energy'' ($T\leq 10$ GeV) data we have applied the
dielectric supression to the results of Seltzer and Berger.
We have chosen the parameterisations:
\begin{equation}
\label{ebrem.a}
\sigma (Z,T,k_c ) =\frac{Z(Z+\xi_{\sigma} )(T+m)^2}
     {T(T+2m)}[ \ln (T/k_c )]^\alpha F_{\sigma} (Z,X,Y)
\mbox{\quad(barn)}\\
\end{equation}
and
\begin{equation}
\label{ebrem.b}
E_{Loss}^{brem} (Z,T,k_c ) =\frac{Z(Z+ \xi_l)(T+m)^2 }
      {(T+2m)}\left[\frac{k_c C_ M }{T}\right]^\beta
      F_{l} (Z,X,Y) \mbox{\quad(GeV barn)}
\end{equation}
where  $m$ is the mass of the electron,
\[
\begin{array}{lll}
X = \ln(E/m), & Y = \ln (v_{\sigma} E/k_c) &
\mbox{\quad for the total cross-section }\sigma \\
X = \ln(T/m), & Y = \ln(k_c/v_lE)       &
\mbox{\quad for the energy loss }  E_{Loss}^{brem}  \\
\end{array}
\]
with $E=T+m$.
The constants $\xi_{\sigma},\ \xi_l,\ \alpha,\ \beta,\ v_{\sigma},\ v_l$
are parameters to be fitted.
\begin{eqnarray*}
C_M &=&\frac{1}{1+\frac{n r_0 \lambda r^2  (T+m)^2}{\pi k^2_c}}
\end{eqnarray*}
is the Midgal correction factor, with
\begin{description}
\item $r_o$  classical electron radius;
\item $\lambda$  reduced electron Compton wavelength;
\item $n$  electron density in the medium.
\end{description}
The factors $(T+m)^2/T(T+2m)$ and $(T+m)^2/(T+2m)$ come from
the scaled cross-section computed by Seltzer and Berger:
\[
f(k/T) = \frac{\beta^2}{Z^2 }k\frac{d \sigma}{dk}
       = \frac{T(T+2m)} {(T+m)^2 Z^2}  k \frac{d \sigma}{dk}
\]

The functions $F_i(Z,X,Y)$ ($ i=\sigma,l $) have the form
\begin{equation}
 F_i(Z,X,Y) = F_{i0}(X,Y)+ZF_{i1}(X,Y)
\end{equation}
where $F_{ij}(X,Y)$ are polynomials of the variables $X,Y$
\begin{eqnarray}
F_{i0}(X,Y) & = &  (C_1+C_2X+\ldots+C_6X^5)+(C_7+C_8X+\ldots+C_{12}X^5)Y
                                                             \nonumber \\
          &   & +(C_{13}+C_{14}X+\ldots + C_{18}X^5)Y^2+\ldots \nonumber \\
          &   & +(C_{31}+C_{32}X+\ldots+C_{36}X^5)Y^5        \nonumber \\
          &   & \mbox{\hspace{11cm}}  Y\leq 0      \nonumber \\
          & = &  (C_1+C_2X+\ldots+C_6X^5)+(C_7+C_8X+\ldots+C_{12}X^5)
                                                             \nonumber \\
          &   & +(C_{37}+C_{38}X+\ldots+C_{42}X^5)Y^2+\ldots+ \nonumber \\
          &   &  (C_{55}+C_{56}X+\ldots+C_{60}X^5)Y^5        \nonumber \\
          &   & \mbox{\hspace{11cm}}  Y > 0        \nonumber \\
F_{i1}(X,Y) & = &  (C_{61}+C_{62}X+\ldots+C_{65}X^4)
                +(C_{66}+C_{67}X+\ldots+C_{70}X^4)Y          \nonumber \\
          &   & +(C_{71}+C_{72}X+\ldots+C_{75}X^4)Y^2+\ldots \nonumber \\
          &   & +(C_{81}+C_{82}X+\ldots+C_{85}X^4) Y^4       \nonumber \\
          &   &   \mbox{\hspace{11cm}}  Y\leq 0    \nonumber \\
          & = &  (C_{61}+C_{62}X+\ldots+C_{65}X^4)
                +(C_{66}+C_{67}X+\ldots+C_{70}X^4)Y          \nonumber \\
          &   & +(C_{86}+C_{87}X+\ldots+C_{90}X^4)Y^2+\ldots \nonumber \\
          &   & +(C_{96}+C_{97}X+\ldots+C_{100}X^4)Y^4       \nonumber  \\
          &   &  \mbox{\hspace{11cm}}  Y>0         \nonumber \\
           \nonumber
\end{eqnarray}
$F_{ij}(X,Y)$ denotes in fact a function constructed from two
polynomials
\[
F_{ij}(X,Y) = \left \{
\begin{array}{ll}
F_{ij}^{neg}(X,Y) & \mbox{for\hspace{0.5cm}} Y\leq 0 \\
F_{ij}^{pos}(X,Y) & \mbox{for\hspace{0.5cm}} Y>0
\end{array} \right .
\]
where the polynomials $F_{ij}$ fulfil the conditions
\[
F_{ij}^{neg}(X,Y)_{Y=0} = F_{ij}^{pos}(X,Y)_{Y=0}   \hspace{2cm}
\left ( \frac{\partial F_{ij}^{neg}}{\partial Y} \right )_{Y=0} =
\left ( \frac{\partial P_{ij}^{pos}}{\partial Y} \right )_{Y=0}
\]
We have computed 4000 ``data points'' in the range
\[
Z = 6  ;  13  ;  29  ;  47  ;  74  ;  92  \hspace{1cm}
10 \: \mbox{keV} \leq T \leq 10 \: \mbox{TeV}  \hspace{1cm}
10 \: \mbox{keV} \leq k_c \leq T
\]
and we have performed a least-squares fit to determine the parameters.

The values of the parameters ($\xi_{\sigma}$, $\alpha$,
$v_{\sigma}$, $C_i $ for $\sigma$ and
$\xi_l$, $\beta$, $V_l$, $C$ for $E_{Loss}^{brem}$)
can be found in the code of the class itself.

The errors of the parameterisations (\ref{ebrem.a}) and (\ref{ebrem.b})
can be estimated as

\begin{eqnarray*}
\frac{\Delta\sigma} {\sigma} & = & \left \{
\begin{array}{llr}
        12-15\%    & \mbox{for    } & T \leq 1 MeV \\
        \leq 5-6\% & \mbox{for    } & 1 MeV < T \leq 10 TeV
\end{array}
\right . \\[1cm]
\frac{\Delta E_{Loss}^{brem}}
     {E_{Loss}^{brem}} & = & \left \{
\begin{array}{llr}
        10-15\%    & \mbox{for    } & T \leq1 MeV  \\
        5-6\%      & \mbox{for    } & 1 MeV < T \leq 100 GeV\\
        10\%       & \mbox{for    } & 100 GeV < T \leq10 TeV
\end{array}
\right .
\end{eqnarray*}

The energy loss due to soft photon bremsstrahlung is tabulated at
initialisation time as a function of the medium and of the energy.

The mean free path for discrete bremsstrahlung is tabuled at initialisation
time as a function
of the medium and of the energy, too.

\subsection{Corrections for $e^+ e^-$ differences}

The radiative energy loss for electrons or positrons is:

\begin{eqnarray*}
-\frac{1}{\rho} \left ( \frac{dE}{dx} \right )_{rad}^{\pm} & = &
\frac{N_{Av} \alpha r_e^2}{A} (T+m) Z^2 \Phi_{rad}^{\pm}(Z,T) \\
\Phi^{\pm}_{rad}(Z,T) & = & \frac{1}{\alpha r_{e}^2 Z^2 (T+m)}
\int^{T}_{0}{k\frac{d\sigma^{\pm}}{dk}dk}
\end{eqnarray*}

Reference \cite{ebrem.kim} says that: \\
{\it ``The differences between the radiative loss of positrons
and electrons are considerable and cannot be disregarded.

[...] The ratio of the radiative energy loss for positrons
to that for electrons obeys a simple scaling law, [...] is a
function only of the quantity $T/Z^2$''}

In other words:

\begin{eqnarray*}
\eta & = & \frac{\Phi_{rad}^{+}(Z,T)}{\Phi_{rad}^{-}(Z,T)} =
\eta \left (\frac{T}{Z^2}\right )
\end{eqnarray*}

The authors have calculated this function in the range $10^{-7}
\leq \frac{T}{Z^2} \leq 0.5$ (here the kinetic energy T is
expressed in MeV). Their {\it data} can be fairly accurately
reproduced using a parametrisation:

\begin{eqnarray*}
\eta & = & \left \{
\begin{array}{llr}
0 & \mbox{if   } & x \leq -8 \\
\frac{1}{2} + \frac{1}{\pi} \arctan \left( a_1 x + a_3 x^3
+ a_5 x^5 \right ) & \mbox{if  } & -8 < x < 9 \\
1 & \mbox{if   } & x \geq 9
\end{array}
\right .
\end{eqnarray*}

where:

\begin{eqnarray*}
x & = & \log \left ( C \frac{T}{Z^2} \right ) \mbox{(T in GeV)} \\
C & = & 7.5221 \times 10^{6} \\
a_1 & = & 0.415 \\
a_3 & = & 0.0021 \\
a_5 & = & 0.00054
\end{eqnarray*}

This $e^+ e^-$ energy loss difference is not a pure low-energy
phenomenon (at least for high Z), as it can be seen from
Tables~\ref{ebrem.c}.

\begin{table}[hbt]
\begin{centering}
\begin{tabular}{rr|r|r} \hline
\multicolumn{1}{c}{$\frac{T}{Z^2} (GeV)$}
& \multicolumn{1}{c|}{T}
& \multicolumn{1}{c|}{$\eta$}
& \multicolumn{1}{c}{$\left ( \frac{rad. \ loss}{total \ loss}
\right )_{e^-}$} \\[3mm] \hline
$10^{-9}$ & $\sim 7 keV$ & $\sim 0.1$ & $\sim 0\%$ \\
$10^{-8}$ & $67 keV $ & $\sim 0.2$ & $\sim 1\%$ \\
$2 \times 10^{-7}$ & $1.35 MeV$ & $\sim 0.5$ & $\sim 15\%$ \\
$2 \times 10^{-6}$ & $13.5 MeV$ & $\sim 0.8$ & $\sim 60\%$ \\
$2 \times 10^{-5}$ & $135. MeV$ & $\sim 0.95$ & $> 90\%$ \\ \hline
\end{tabular}
\caption{ratio of the $e^+ e^-$ radiative energy loss in lead
(Z=82).}
\label{ebrem.c}
\end{centering}
\end{table}

The scaling holds for the ratio of the total radiative energy
losses, but it is significantly broken for the photon spectrum
in the screened case.
In case of a point Coulomb charge the
scaling would hold also for the spectrum.
The scaling can be expressed by:

\begin{eqnarray*}
\frac{\Phi^+}{\Phi^-} = \eta \left ( \frac{T}{Z^2} \right )
& \hspace{3cm} &
\frac{\frac{d\sigma^+}{dk}}{\frac{d\sigma^-}{dk}} =
\mbox{does not scale}
\end{eqnarray*}

If we consider the photon spectrum from bremsstrahlung reported
in \cite{ebrem.kim} we see that:

\begin{eqnarray*}
\frac{d\sigma^{\pm}}{dk} = S^{\pm} \left( \frac{k}{T} \right )
\hspace{2cm}
\frac{S^{+}(k)}{S^{-}(k)} \leq 1 & \hspace{1cm} & S^{+}(1) = 0
\hspace{2cm} S^{-}(1)  >  0
\end{eqnarray*}

We further assume that:

\begin{eqnarray}
\frac{d\sigma^+}{dk} = f(\epsilon) \frac{d\sigma^-}{dk}
& \hspace{2cm} &
\epsilon = \frac{k}{T}
\label{ebrem.d}
\end{eqnarray}

In order to satisfy approximately the scaling law for the ratio
of the total radiative energy loss, we require for $f(\epsilon)$:

\begin{eqnarray}
\int^{1}_{0}{f(\epsilon)d\epsilon} & = & \eta
\label{ebrem.e}
\end{eqnarray}

From the photon spectra we require:

\begin{eqnarray}
\left .
\begin{array}{l}
f(0) = 1 \\
f(1) = 0
\end{array}
\right \} \hspace{2cm} \mbox{for all $Z,T$}
\label{ebrem.f}
\end{eqnarray}

We have chosen a simple function $f$:

\begin{eqnarray}
f(\epsilon) & = & C (1-\epsilon)^{\alpha} \hspace{3cm} C,\alpha > 0
\label{ebrem.g}
\end{eqnarray}

from the conditions (\ref{ebrem.e}), (\ref{ebrem.f}) we get:

\begin{eqnarray*}
C & = & 1 \\
\alpha & = & \frac{1}{\eta} - 1 \hspace{2cm}
\mbox{($\alpha > 0$ because $\eta < 1$)} \\
f(\epsilon) & = & (1-\epsilon)^{\frac{1}{\eta}-1}
\end{eqnarray*}

We have defined weight factors $F_{l}$ and $F_{\sigma}$ for the
positron continuous energy loss and discrete bremsstrahlung cross
section:

\begin{eqnarray}
F_{l} = \frac{1}{\epsilon_{0}} \int^{\epsilon_{0}}_{0}
{f(\epsilon)d\epsilon} & \hspace{3cm} &
F_{\sigma} = \frac{1}{1-\epsilon_{0}} \int^{1}_{\epsilon_{0}}
{f(\epsilon)d\epsilon}
\label{ebrem.h}
\end{eqnarray}

where $\epsilon_{0} = \frac{k_c}{T}$ and $k_c$ is the photon
cut . In this scheme the positron energy loss and
discrete bremsstrahlung can be calculated as:

\begin{eqnarray*}
\left ( - \frac{dE}{dx} \right )^{+} = F_{l}
\left ( - \frac{dE}{dx} \right )^{-} & \hspace{2cm} &
\sigma^{+}_{brems} = F_{\sigma} \sigma^{-}_{brems}
\end{eqnarray*}

As in this approximation the photon spectra are identical, the
same sampling is used for generating $e^- e^+$ bremsstrahlung.
The following relations hold:

\begin{eqnarray*}
F_{\sigma} & = & \eta (1-\epsilon_{0})^{\frac{1}{\eta}-1}
< \eta \\
\epsilon_{0} F_{l} + (1-\epsilon_{0}) F_{\sigma} & = & \eta
\hspace{6cm} \mbox{from the def (\ref{ebrem.h})} \\
\Rightarrow F_{l} & = & \eta \frac{1-(1-\epsilon_{0})^{\frac{1}
{\eta}})}{\epsilon_{0}} > \eta \frac{1-(1-\epsilon_{0})}
{\epsilon_{0}} = \eta  \hspace{1cm}
\Rightarrow   \left \{
\begin{array}{l}
F_{l} > \eta \\
F_{\sigma} < \eta
\end{array} \right .
\end{eqnarray*}

which is consistent with the spectra.

The effect of this $e^- e^+$ bremsstrahlung difference can be also
seen in e.m. shower development, when the primary energy is not too
high.

\subsection{LPM effect}

The LPM effect (see e.g in \cite{ebrem.galitsky},\cite{ebrem.anthony} )
 is the supression of the photon production due to the
multiple scattering of the electrons.If an electron multiple scatters
while traversing the co called formation zone, the bremsstrahlung
amplitude from before and after the scattering can interfere, reducing the
amplitude for bremsstrahlung photon emission (similar supression occurs
for pair production,too). The supression becomes significant for photon
energies below a certain value, given by
\begin{equation}
\label{ebrem.k}
 \frac{k}{E} < \frac{E}{E_{LPM}}
\end{equation}
 , where
\[
\begin{array}{ll}
k    & \mbox{photon energy} \\
E    & \mbox{electron energy} \\
E_{LPM} & \mbox{characteristic energy for LPM effect (depend on the medium).}
\end{array}
\]

The value of the LPM characteristic energy can be written as

\begin{equation}
\label{ebrem.l}
  E_{LPM} = \frac{\alpha m^2 X_0}{4 h c}
\end{equation}

 , where
\[
\begin{array}{ll}
\alpha  & \mbox{fine structure constant} \\
m       & \mbox{electron mass} \\
X_0     & \mbox{radiation length in the material} \\
h       & \mbox{Planck constant} \\
c       & \mbox{velocity of light in vacuum.}
\end{array}
\]

 The LPM supression of the photon spectrum is given by the formula

\begin{equation}
\label{ebrem.m}
  S_{LPM} = \sqrt{\frac{E_{LPM} \cdot k}{E^2}}
\end{equation}

, while the dielectric supression (included already in the parametrisations)
can be written as

\begin{equation}
\label{ebrem.n}
  S_p = \frac{k^2}{k^2 + C_p \cdot E^2}
\end{equation}

 , where the quantity $C_p$ is given by

\begin{equation}
\label{ebrem.o}
   C_p = \frac{r^2_0 \lambda^2_e n}{\pi}
\end{equation}

In eq. \ref{ebrem.o} the parameters are
\[
\begin{array}{ll}
r_0     & \mbox{classical electron radius} \\
\lambda_e & \mbox{electron Compton wawelength} \\
n       & \mbox{electrondensity in the material.}
\end{array}
\]

 Both of the supression effects reduce the effective formation length
of the photon , so the supressions {\em do not simply multiply.} For the
total supression S the following equation holds (see \cite{ebrem.galitsky})
\begin{equation}
\label{ebrem.p}
  \frac{1}{S} = 1 + \frac{1}{S_p} + \frac{S}{S^2_{LPM}}
\end{equation}
 which can be solved easily for $S$
\begin{equation}
\label{ebrem.q}
  S = \frac{\sqrt{S^4_{LPM}\cdot (1 + \frac{1}{S_p})^2 + 4 \cdot S^2_{LPM}}
      -S^2_{LPM} \cdot (1 + \frac{1}{S_p})}{2}
\end{equation}

 The implementation of the LPM effect has been done in the following way:
The cross section and energy loss should be modified by applying the
 (energy and material dependent ) factor $\frac{S}{S_p}$ . This is done
at initialisation time for the energy loss by computing the correction
factor
\begin{equation}
\label{ebrem.r}
   f_c = \frac{\int_0^{k_cut} n_\gamma (k) \cdot \frac{S}{S_p} dk}
              {\int_0^{k_cut} n_\gamma (k) dk}
\end{equation}
 , wherea $n_\gamma (k)$ is the photon specrum .
 The total cross section given by the parametrization \ref{ebrem.a} has
not been modified , the algorithm of the photon generation takes care
of the LPM effect.

\section{Simulation of the discrete bremsstrahlung}

The photon energy is sampled according to the Seltzer and Berger
bremsstrahlung spectrum~\cite{ebrem.seltzer}.
 Seltzer and Berger have calculated the
spectra for materials with atomic numbers Z = 6,13,29,47,74,92
in the electron (kinetic) energy range  1 keV - 10 GeV. Their tabulated
results have been used as input in a parametrising-fitting procedure.
The functional form of the parameterisation for the quantity:

\[
S(x) = C k \frac{d \sigma}{d k}
\]

can be written as
\begin{equation}
\label{eq:phys341-1}
S(x) = \left \{
\begin{array}{ll}
(1-a_{h} \epsilon )F_{1}(\delta) + b_{h} \epsilon^{2} F_{2} (\delta)
& T \geq 1 MeV \\
1 + a_{l} x + b_{l} x^{2} & T < 1 MeV
\end{array} \right .
\end{equation}
where:
\[
\begin{array}{lcllcl}
C & & \mbox{normalisation constant} &
k & & \mbox{photon energy} \\ [1mm]
T, E & & \mbox{kinetic and total energy of the primary electron} &
x & = & \frac{k}{T} \\ [2mm]
\epsilon & = & \frac{k}{E} = x \frac{T}{E}
\end{array}
\]

The $F_{i}(\delta)$ screening functions depend on the screening variable:
\[
\begin{array}{lcll}
\delta & = & \frac{136 m_{e}}{Z^{1/3} E} \frac{\epsilon}{1-\epsilon} \\
F_{1}(\delta) & = & F_{0} (42.392 - 7.796 \delta +1.961 \delta^{2} - F)
& \delta \leq 1 \\
F_{2}(\delta) & = & F_{0} (41.734 - 6.484 \delta +1.250 \delta^{2} - F)
& \delta \leq 1 \\
F_{1}(\delta) & = & F_{2}(\delta) =
F_{0} (42.24 - 8.368 \ln(\delta + 0.952) -F) & \delta > 1 \\
F_{0} & = & \frac{1}{42.392-F} \\
F & = & 4 \ln Z - 0.55 (\ln Z)^{2}
\end{array}
\]

$a_{h,l}$ and $b_{h,l}$ are parameters to be fitted.

The `high energy' (T $>$  1 MeV) formula comes from the
Coulomb-corrected, sceened Bethe-Heitler formula (see e.g.
\cite{ebrem.williams,ebrem.butcher,ebrem.egs4}). However, there are two things in eq.
(\ref{eq:phys341-1}) which make a difference:

\begin{enumerate}
\item $a_{h}, b_{h}$ depend on T and on the atomic number Z ( in the case
of the Bethe-Heitler spectrum $a_{h} = 1$, $b_{h} =0.75$);
\item the function $F$ is not the same than that in the Bethe-Heitler
cross-section, this function gives a better behaviour in the
high frequency limit, i.e. when $k \rightarrow T$  ($x \rightarrow 1$).
\end{enumerate}

The T and Z dependence of the parameters are described by the equations:

\begin{eqnarray*}
a_{h} & = & 1 + \frac{a_{h1}}{u}+\frac{a_{h2}}{u^{2}}+\frac{a_{h3}}{u^{3}} \\
b_{h} & = & 0.75+\frac{b_{h1}}{u}+\frac{b_{h2}}{u^{2}}+\frac{b_{h3}}{u^{3}} \\
a_{l} & = & a_{l0} + a_{l1} u + a_{l2} u^{2} \\
b_{l} & = & b_{l0} + b_{l1} u + b_{l2} u^{2} \\
\mbox{with} \\
u & = & \ln \left ( \frac{T}{m_{e}} \right )
\end{eqnarray*}

the $a_{hi}, b_{hi}, a_{li}, b_{li}$ parameters are polynomials of second order
in the variable:

\[
v = [Z (Z+1)]^{1/3}
\]

It can be seen relatively easily that for the limiting case $T \rightarrow
\infty$, $a_{h} \rightarrow 1, b_{h} \rightarrow 0.75$,
so eq. (\ref{eq:phys341-1}) gives the Bethe-Heitler cross section.

There are altogether 36 linear parameter in the formulae , their
values are given in the code. The parameterisation reproduces
the Seltzer-Berger tables within a few \% (2-3 \% on average,
the maximum error being less than 10-12 \%), the tables, on the other hand,
agree well with the experimental data and theoretical (low- and high-energy)
results (less than 10 \% below 50 MeV, less than 5 \% above 50 MeV).

Apart from the normalisation the cross section differential in photon
energy can be written as:
\[
\frac{d \sigma}{d k} = \frac{1}{\ln \frac{1}{x_{c}}} \frac{1}{x}
g(x) = \frac{1}{\ln \frac{1}{x_{c}}} \frac{1}{x} \frac{S(x)}{S_{max}}
\]

where $x_{c} = k_{c}/T$, $k_{c}$ is the photon cut-off energy below
which the bremsstrahlung is treated as a continuous energy loss
. Using this decomposition of
the cross section and two random numbers $r_{1}$, $r_{2}$ uniformly
distributed in $]0,1[$, the sampling of $x$ is done as follows:
\begin{enumerate}
\item sample $x$ from
\[
\frac{1}{\ln \frac{1}{x_{c}}} \frac{1}{x} \mbox{\hspace{1cm}setting\hspace{1cm}}
x = e^{r_{1} \ln x_{c}}
\]

\item calculate the rejection function $g(x)$ and:
\begin{itemize}
\item if $r_{2} > g(x)$ reject $x$ and go back to 1;
\item if $r_{2} \leq g(x)$ accept $x$.
\end{itemize}
\end{enumerate}

To apply the dielectric supression  \cite{ebrem.migdal}
  all it has to be done is to
multiply the rejection function by the supression factor , which is
equivalent to the expression \ref{ebrem.n}:

\[
C_M (\epsilon)  =\frac{1 + C_0 / \epsilon_c^2}
               {1 + C_0 / \epsilon^2}
\]
 where
\[
C_0 =\frac{nr_0 \lambda^2 }{\pi}, \hspace{1cm} \epsilon_c = \frac{k_{c}}{E}
\]
\begin{itemize}
\item[$n$]           electron density in the medium
\item[$r_0$]         classical electron radius
\item[$\lambda$]    reduced Compton wavelength of the electron.
\end{itemize}
This correction decreases the cross-section for low photon energy.

 After having $\epsilon$ sampled , the supression factor $f_{LPM}=\frac{S}{S_p}$ is
used as a rejection function in order to take into account the LPM effect , too.
Here the supression factor is compared to a random number $r$ uniformly
distributed in the interval $(0,1)$. If  $f_{LPM} \geq r$ the simulation
is continuing otherwise the bremsstrahlung process is finished
{\em without photon production } .It can be seen easily that this procedure
takes into account the LPM supression correctly.

After the successful sampling of $\epsilon$,  the
polar angles of the radiated photon are generated with respect to the parent
electron's momentum. It is difficult to find in the literature
simple formulas for this angle. For example the double differential
cross section reported by Tsai~\cite{ebrem.tsai1,ebrem.tsai2} is the
following:
\begin{eqnarray*}
\frac{d \sigma}{dkd \Omega}
& = & \frac{2 \alpha^{2}e^{2}}{\pi k m^{4}}
  \left\{ \left[ \frac{2\epsilon-2}{(1+u^2)^2}+
\frac{12u^2(1-\epsilon)}{(1+u^2)^4}\right]
      Z(Z+1)  \right. \\
&   & \mbox{} + \left. \left[ \frac{2-2\epsilon-\epsilon^{2}}{(1+u^2)^2}-
      \frac{4u^2(1-\epsilon)}{(1+u^2)^4}
      \right]
      \left[ X-2Z^{2}f_{c}((\alpha Z)^{2})\right]
      \right\} \\
u & = & \frac{E \theta}{m} \\
X & = & \int_{t_{min}}^{m^{2}(1+u^{2})^{2}}
{\left [ G_{Z}^{el}(t) + G_{Z}^{in}(t) \right ] \frac{t-t_{min}}
{t^{2}} dt} \\
G_{Z}^{el, in}(t) & & \mbox{atomic form factors} \\
t_{min} & = & \left [ \frac{k m^{2} (1+u^{2})}{2 E (E-k)} \right ] ^{2}
 = \left [ \frac{\epsilon m^{2} (1+u^{2})}{2 E (1-\epsilon)} \right ] ^{2}
\end{eqnarray*}

This distribution is complicated to sample, and it is anyway only an
approximation to within few percent, if nothing else, due to
the presence of the atomic form-factors.
The angular dependence is contained in the
variable $u = E \theta m^{-1}$. For a given value
of $u$ the dependence of the shape of the function on $Z$, $E$,
$\epsilon = k/E$ is very weak.
Thus, the distribution can be approximated by a function
\begin{equation}
f(u) = C \left( u e^{-au} + d u e^{-3au} \right)
\end{equation}
where
\[
C = \frac{9a^{2}}{9 + d} \hspace{1cm} a = 0.625 \hspace{1cm}
d = 0.13 \: \left ( 0.8+\frac{1.3}{Z} \right ) \left (100+\frac{1}{E} \right )
(1+\epsilon)
\]
where $E$ is in GeV. While this approximation is good at high energies,
it becomes less accurate around few MeV. However in that region the
ionisation losses dominate over the radiative losses.

The sampling of the function $f(u)$ can be done in the following way
($r_{i},\: i=1,2,3$ are uniformly distributed random numbers
in [0,1]):
\begin{enumerate}
\item Choose between $u e^{-au}$ and $d u e^{-3au}$:
\[
b = \left \{ \begin{array}{ll}
a & \mbox{if\hspace{0.5cm}}r_{1} < 9/(9+d) \\
3a & \mbox{if\hspace{0.5cm}}r_{1} \geq 9/(9+d)
\end{array} \right .
\]
\item Sample $u e^{-bu}$:
\[
u=-\frac{\log ( r_{2} r_{3}) }{b}
\]
\item check that:
\[
u \leq u_{max} = \frac{E \pi}{m}
\]
otherwise go back to 1.
\end{enumerate}

The probability of failing in the last test is reported in
table~\ref{tb:phys341-1}.

\begin{table}
\begin{centering}
\begin{tabular}{|l|l|}
\multicolumn{2}{c}{$\displaystyle
P = \int^{\infty}_{u_{max}}{f(u) \: du} \hfill $} \\ [0.5cm]
\hline
E (MeV) & P(\%) \\ \hline
0.511 & 3.4 \\
0.6 &  2.2 \\
0.8 & 1.2 \\
1.0 & 0.7 \\
2.0 & $<$ 0.1 \\ \hline
\end{tabular}
\caption{Angular sampling efficiency}
\label{tb:phys341-1}
\end{centering}
\end{table}

The function $f(u)$ can be used also to describe
the angular distribution of the photon in $\mu$ bremsstrahlung and to
describe the angular distribution in photon pair production.

The azimuthal angle, $\Phi$, is generated isotropically.
This information is used to calculate the momentum vector of the radiated
photon, to transform it to the global  coordinate system.
Also, the momentum of the parent electron is updated.

\section{Status of this document}

   9.10.98  created by L. Urb\'an.

\begin{thebibliography}{99}

\bibitem[GEANT3]{ebrem.geant3}
  GEANT3 manual ,CERN Program Library Long Writeup W5013 (October 1994).
\bibitem[Gal64]{ebrem.galitsky}
  V.M.Galitsky and I.I.Gurevich. Nuovo Cimento 32 (1964) 1820.
\bibitem[Ant97]{ebrem.anthony}
  P.L. Anthony et al. SLAC-PUB-7413/LBNL-40054 (February 1997)
\bibitem[Sel85]{ebrem.seltzer}
  S.M.Seltzer and M.J.Berger. Nucl.Inst.Meth. 80 (1985) 12.
\bibitem[Mess70]{ebrem.messel}
  H.Messel and D.F.Crawford. Pergamon Press,Oxford,1970.
\bibitem[EGS4]{ebrem.egs4} W.R. Nelson et al.:The EGS4 Code System.
   {\em SLAC-Report-265 , December 1985 }
\bibitem[Mig56]{ebrem.migdal}
   A.B. Migdal. Phys.Rev. 103. (1956) 1811.
\bibitem[Kim86]{ebrem.kim}
   L. Kim et al. Phys. Rev. A33 (1986) 3002.
\bibitem[Tsai74]{ebrem.tsai1}
   Y-S. Tsai . Rev. Mod. Phys. 46. (1974) 815.
\bibitem[Tsai77]{ebrem.tsai2}
   Y-S. Tsai . Rev. Mod. Phys. 49. (1977) 421.
\bibitem[Will60]{ebrem.williams}
   R. W. Williams . Fundamental Formulas of Physics, vol.2. Dover Pubs.Inc,1960.
\bibitem[Butc60]{ebrem.butcher}
   J. C. Butcher and H. Messel. Nucl.Phys. 20. (1960) 15.

\end{thebibliography}


\chapter{IDL Routines}
\label{ch_mrsp_idl}
%\chapterhead{IDL Routines}
\markright{IDL Routines}

\section{Introduction}
A set of routines has been developed in IDL. Starting IDL using the script program {\em isap.pro} allows the user
to get the interactive sparse data analysis  environment, and all routines described in the following can be called.
An online help facility is also available by invoking the {\em isaph} program under IDL. See Chapter~\ref{ch_install} for more
details on the software installation.

\section{Functions for polarized spherical maps}
\index{polar}

\subsection{Reading a polarized spherical map from a file : mrsp\_read}
\index{IDL routines!mrsp\_read}
\index{polar!read polarized map}
Read a polarized spherical map in Healpix format.
{\bf
\begin{center}
     USAGE: map = mrsp\_read( file, noverb=noverb )
\end{center}}
where
\begin{itemize}
\item {\em file} : Input string, name of the file to be read. The pathname can be included in the string, by default 'file.fits' is equivalemt to './file.fits'
\item {\em noverb} : scalar, prevent the printing on the screen of the format (RING or NESTED) of the read map and the number of pixels.
\item {\em map} : Output 3D IDL array of Healpix map read. The map is setted to the NESTED format after reading.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item map = mrsp\_read( 'my\_file\_healpix\_pola.fits', noverb=noverb ) \\
Read the map stored into the file 'my\_file\_healpix\_pola.fits' and load it into map.
\end{itemize}

\subsection{Writing a polarized spherical map into a file : mrsp\_write}
\index{IDL routines!mrsp\_write}
\index{polar!write polarized map}
Write a polarized spherical map in Healpix format.
{\bf
\begin{center}
     USAGE: mrsp\_write, file, map, ring=ring
\end{center}}
where
\begin{itemize}
\item {\em file} : Input string, name of the file to be writen. The pathname can be included in the string, by default 'file.fits' is equivalemt to './file.fits'
\item {\em map} : Input 3D IDL array of Healpix map to be writen. The map is assumed to be in the NESTED format.
\item {\em ring} : scalar, if set convert the Healpix map data to the RING format for the writing.
\end{itemize}

\subsection{Conversion of a polarized spherical map from TQU scheme to TEB scheme : mrsp\_tqu2teb}
\index{IDL routines!mrsp\_tqu2teb}
\index{polar!conversion tqu2teb}
Convert a polarized map in Healpix nested format from TQU scheme to TEB scheme.
{\bf
\begin{center}
     USAGE: mrsp\_tqu2teb, map\_tqu, map\_teb
\end{center}}
where
\begin{itemize}
\item {\em map\_tqu} : Input 3D IDL array of healpix polarized map in TQU scheme.
\item {\em map\_teb} : Output 3D IDL array of healpix polarized map in TEB scheme.
\end{itemize}

\subsection{Conversion of a polarized spherical map from TEB scheme to TQU scheme : mrsp\_teb2tqu}
\index{IDL routines!mrsp\_teb2tqu}
\index{polar!conversion tqu2teb}
Convert a polarized map in Healpix nested format from TEB scheme to TQU scheme.
{\bf
\begin{center}
     USAGE: mrsp\_teb2tqu, map\_teb, map\_tqu
\end{center}}
where
\begin{itemize}
\item {\em map\_teb} : Input 3D IDL array of healpix polarized map in TEB scheme.
\item {\em map\_tqu} : Output 3D IDL array of healpix polarized map in TQU scheme.
\end{itemize}

\subsection{Resizing a polarized spherical map: mrsp\_resize}
\index{IDL routines!mrsp\_resize}
\index{polar!polarized map resizing}
Resize a polarized map in Healpix nested format.
{\bf
\begin{center}
     USAGE: resize\_map = mrsp\_resize( map, nside=nside, ViaAlm=ViaAlm, teb=teb )
\end{center}}
where
\begin{itemize}
\item {\em map} : Input 3D IDL array of healpix polarized map in TQU scheme to be transformed.
\item {\em resize\_map} : Output 3D IDL array of healpix polarized map in TQU scheme. Healpix input map and output resized map are in nested format.
\item {\em nside} : int, the new nside parameter of the output healpix resized map.
\item {\em ViaAlm} : scalar, if set use alm transform for the resizing, otherwise, use interpolation.
Ignored if nside keyword value is lower than imag nside.
\item {\em teb} : scalar, if set specifies that the input and output images are in TEB scheme.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item map2 = mrsp\_resize( map, nside = 256, /ViaAlm ) \\
resize an Healpix map.
\end{itemize}

\section{General transform/reconstruction routines}

\subsection{Transformations of a polarized spherical map : mrsp\_trans}
\index{IDL routines!mrsp\_trans}
\index{polar!transforms of polarized image}
Compute a transform (E-B mode decomposition, wavelet with spline, Meyer or needelet filters, curvelet, \ldots)
on a polarized map on the sphere in the Healpix representation (nested data representation) in TQU scheme.\\ \\
The transform can be:
\begin{enumerate}
\item A E/B decomposition using the spin\_2 transform.
\item An orthogonal wavelet on each T,Q,U component.
\item A pyramidal isotropic wavelet on each T,Q,U component.
\item An undecimated wavelet transform on each component.
\item A decimated modulus-Phase wavelet transform.
\item A undecimated modulus-Phase wavelet transform.
\item A curvelet transform.
\end{enumerate}
{\bf
\begin{center}
     USAGE: mrsp\_trans, Imag, Trans, NbrScale=NbrScale, lmax=lmax, MeyerWave=MeyerWave, ebdec=ebdec, Cur=Cur, uwt=uwt, owt=owt, mpdwt=mpdwt, mpuwt=mpuwt, PyrWT=PyrWT,
     DifInSH=DifInSH, Overlap=Overlap, FirstBlockSize=FirstBlockSize
\end{center}}
where
\begin{itemize}
\item {\em Imag} : Input 3D IDL array of healpix polarized map in TQU scheme. Input image to be transformed.
\item {\em Trans} : Output IDL structure with the following fields:
\begin{itemize}
\item {\em NbrScale} : int, number of scales.
\item {\em nside} : int, Healpix nside parameter.
\item {\em lmax} : int, maximum l value in the Spherical Harmonic Space.
\item {\em npix} : long, number of pixels of the input image.
\item {\em MeyerWave} : int, 1 if the keyword MeyerWave used, otherwise 0.
\item {\em DifInSH} : int, 1 if the keyword DifInSH used, otherwise 0.
\item {\em pyrtrans} : int, 1 if a pyramidal decomposition has been applied, otherwise 0.
\item {\em ebdec} : int, 1 if an EB decomposiiton has been applied, otherwise 0.
\item {\em DEC1} : IDL structure, first component transformation (depends on the chosen transform).
\item {\em DEC2} : IDL structure, second component transformation (depends on the chosen transform).
\item {\em DEC3} : IDL structure, third component transformation (depends on the chosen transform).
\item {\em TransChoice} : string, code of the chosen transform.
\item {\em TabCodeTransform} : string array, array of transforms codes. TabCodeTransform = ['T\_EBDEC', 'T\_OWT', 'T\_PyrWT', 'T\_UWT', 'T\_MPDWT', 'T\_MPUWT', 'T\_CUR']
\item {\em TransName} : string, transform's name.
\item {\em TransTypeName} : string array, array of transforms names.
TransTypeName = ['EBDEC','Bi-Orthogonal WT', 'Pyramidal WT', 'Undecimated WT', 'Module-Phase Decimated Transform', 'Module-Phase Undecimated Transform', 'Curvelet']
\end{itemize}
\item {\em NbrScale} : int, number of scales of the wavelet transforms.
\item {\em ebdec} : scalar, if set an E/B decomposition is applied before the chosen multiscale decomposition.
If no transform is selected, it will be the default transformation.
\item {\em Cur} : scalar, if set perform a curvelet transform.
\item {\em uwt} : scalar, if set perform an undecimated isotropic wavelet transform.
\item {\em PyrWT} : scalar, if set perform a pyramidal isotropic wavelet transform.
\item {\em owt} : scalar, if set perform a bi-orthogonal wavelet transform on each face.
\item {\em mpdwt} : scalar, if set perform a decimated module-phase wavelet transform.
\item {\em mpuwt} : scalar, if set perform a undecimated module-phase wavelet transform.
\item {\em Overlap} : int, if equal to 1 if blocks are overlapping, only used with curvelet transform.
\item {\em FirstBlockSize} : int, block size in the ridgelet transform at the finest scale (default is 16), only used with curvelet transform.
\item {\em lmax} : int, maximum l value in the Spherical Harmonic Space (for isoptropic wavelet transform only).
\item {\em DifInSH} : Input keyword parameter. If set, the wavelet coefficients are computed as the difference between two resolutions in the spherical harmonics representation.
Otherwise, the wavelet coefficients are computed as the difference between two resolutions in direct space. Only used with keyword uwt or PyrWT.
\item {\em MeyerWave} : If set, use Meyer wavelets and set the keyword DifInSH. Only used with keyword uwt or PyrWT.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item mrsp\_trans, Imag, WT, NbrScale=5, /uwt \\
Compute the undecimated wavelet transform of the map Imag with five scales. The result is stored in WT.
\end{itemize}

\subsection{Reconstructions of a polarized spherical map : mrsp\_rec}
\index{IDL routines!mrsp\_rec}
\index{polar!inverse transform of polarized image}
Compute a inverse transform (wavelet, curvelet, \ldots) to get a polarized map on the sphere in the Healpix representation
(nested data representation) in TQU scheme from its decomposition obtained by mrsp\_trans.\\ \\
The transform can be:
\begin{enumerate}
\item A E/B decomposition using the spin\_2 transform.
\item An orthogonal wavelet on each T,Q,U component.
\item A pyramidal isotropic wavelet on each T,Q,U component.
\item An undecimated wavelet transform on each component.
\item A decimated modulus-Phase wavelet transform.
\item A undecimated modulus-Phase wavelet transform.
\item A curvelet transform.
\end{enumerate}
{\bf
\begin{center}
     USAGE: mrsp\_rec, Trans, Rec
\end{center}}
where
\begin{itemize}
\item {\em Trans} : Input IDL structure, see mrsp\_trans for more details.
\item {\em Rec} : Output 3D IDL array of healpix polarized map in TQU scheme. Reconstructed image.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item mrsp\_trans, Imag, WT, NbrScale=5, /uwt \\
Compute the undecimated wavelet transform of the map Imag with five scales. The result is stored in WT.
\item mrsp\_rec, WT, RecIma \\
Reconstruct the image.
\end{itemize}

\section{Spin-2 spherical harmonic transform}

\subsection{ALM transform of a polarized spherical map : mrsp\_almtrans}
\index{IDL routines!mrsp\_almtrans}
\index{polar!polar ALM transform}
Computes the spherical harmonic transform of a polarized TQU map using the Healpix representation (nested data).
{\bf
\begin{center}
     USAGE: mrsp\_almtrans, Imag, Trans, lmax=lmax, tab=tab, complex=complex, norm=norm, fast=fast
\end{center}}
where
\begin{itemize}
\item {\em Imag} : Input 3D IDL array of healpix polarized map in TQU scheme to be transformed.
\item {\em Trans} : Output IDL structure with the following fields:
\begin{itemize}
\item {\em ALM} : array of the ALM coefficients
\begin{center}
ALM = fltarray[*,2,3] list of the real part (ALM[*,0,*]) and imaginary part (ALM[*,1,*]) of the ALM.
This is the default storage, ALM[*,*,0] is ALM T, ALM[*,*,1] is ALM E and ALM[*,*,2] is ALM B\\
ALM = cfarr[*,3] list of the ALM in complex values format if the keyword complex is set.
ALM[*,0] is ALM T, ALM[*,1] is ALM E and ALM[*,2] is ALM B\\
ALM = fltarray[NbrMaxM, NbrMaxL, 2, 3] table of the real part (ALM[*,*,0,*]) and imaginary part (ALM[*,*,1,*])
of the ALM if the keyword tab is set. ALM[*,*,*,0] is ALM T, ALM[*,*,*,1] is ALM E and ALM[*,*,*,2] is ALM B\\
ALM = cfarr[NbrMaxM, NbrMaxL, 3] table of the ALM in complex values format if the keywords complex and tab
are both setted. ALM[*,*,0] is ALM T, ALM[*,*,1] is ALM E and ALM[*,*,2] is ALM B\\
By default, NbrMaxM = NbrMaxL = lmax+1
\end{center}
\item {\em complex\_alm} : int, 0 (default value) if ALM array contains real and imaginary part separated.
1 if ALM is a complex array.
\item {\em PixelType} : int, 0 for a Healpix input map (1 for GLESP but not used).
\item {\em tab} : int, 0 for default ALM representation as a list (i.e. 1D IDL array) and 1 for 2D
representation as a table (i.e. l for the first dimension and m for the second).
\item {\em nside} : int, Healpix nside parameter.
\item {\em lmax} : int, maximum l value in the Spherical Harmonic Space.
\item {\em npix} : long, number of pixels of the input image.
\item {\em TabNbrM} : int array[NbrMaxL], max number of m value for a given l, only used if keyword tab is set otherwise, 0.
\item {\em index} : long array, indicies of the ALM coefficients, used only if keyword tab is not set.
\item {\em NormVal} : float, normalization value applied to the alm coefficients (only if keyword norm used).
\item {\em norm} : int, 0 if no normalization has been aplied, else 1.
\end{itemize}
\item {\em lmax} : int, Number of spherical harmonics computed in the decomposition. For a Healpix map, default is
3*nside and should be between 2*nside and 4*nside.
\item {\em tab} : scalar, if set, ALM coefficients in Trans.alm are stored in a 2D array: Trans.alm[m,l] where m = 0..Trans.TabNbrM[l]-1  and l = 0..lmax-1
\item {\em complex} : scalar, if set Trans.alm will contain complex values instead of the real and imaginary parts.
\item {\em norm} : scalar, if set, a normalization is performed to the alm coefficients.
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item mrsp\_almtrans, Imag, Output \\
Compute the spherical harmonics transform of a polarized image, the result is stored in Output.
\end{itemize}

\subsection{ALM inverse transform of a polarized spherical map : mrsp\_almrec}
\index{IDL routines!mrsp\_almrec}
\index{polar!polar ALM inverse transform}
Computes the inverse spherical harmonic transform of a polarized TQU map using using the Healpix representation (nested data).
{\bf
\begin{center}
     USAGE: mrsp\_almrec, Trans, imag, pixel\_window=pixel\_window
\end{center}}
where
\begin{itemize}
\item {\em Trans} : Input IDL structure of ALM coefficients, see mrsp\_almtrans above for details.
\item {\em Imag} : Output 3D IDL array of healpix polarized map in TQU scheme. Image reconstructed in Healpix nested representation.
\item {\em pixel\_window} : scalar, if set the image is convolved by the healpix pixel window (only for Healpix map).
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item mrsp\_almtrans, PolaImag, Output \\
Compute the spherical harmonics transform of a polarized image, the result is stored in Output.
\item mrsp\_almrec, Output, PolaRec \\
Reconstruct the image.
\end{itemize}

\subsection{Power spectrum and cross spectrum exctraction from polarized ALM~: mrsp\_alm2spec}
\index{IDL routines!mrsp\_alm2spec}
\index{polar!spectrum exctraction from polarized ALM}
Computes the power spectrums and cross spectrums of a polarized map from the polarized ALM coefficients.
{\bf
\begin{center}
     USAGE: spec = mrsp\_alm2spec( ALM, StdPS=StdPS )
\end{center}}
where
\begin{itemize}
\item {\em ALM} : Input IDL structure of ALM polarized coefficients, see mrsp\_almtrans above for details.
\item {\em spec} : Output 2D IDL float array[ALM.lmax+1,6], the TT, EE, BB, TE, TB, EB spectrums. P[k,i] = Mean( SPECTRUM[*,l,i] ) \quad i=0...5.
\item {\em StdPS} : Output 2D IDL float array[ALM.lmax+1,6]: estimated standard deviation of the spectrums coefficients.
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item mrsp\_almtrans, Imag, Output \\
Compute the spherical harmonics transform of a polarized image, the result is stored in Output.
\item spec = mrsp\_alm2spec( Output, StdPS=StdPS ) \\
Compute the spectrums of the image and it's associated standard deviation.
\end{itemize}

\subsection{Power spectrum and cross spectrum exctraction from a polarized image : mrsp\_spec}
\index{IDL routines!mrsp\_spec}
\index{polar!spectrum exctraction from a polarized image}
Computes the power spectrums and cross spectrums of a polarized map, using the HEALPix representation (nested data representation by default).
By default a normalisation is applied on the ALM coefficents.
{\bf
\begin{center}
     USAGE: spec = mrsp\_spec( Imag, nonorm=nonorm, teb=teb, NormVal=NormVal, StdPS=StdPS, lmax=lmax )
\end{center}}
where
\begin{itemize}
\item {\em Imag} : Input 3D IDL array of healpix polarized map in TQU scheme. Input image whose power spectrum will be extracted.
\item {\em spec} : Output 2D IDL float array[ALM.lmax+1,6], the TT, EE, BB, TE, TB, EB spectrums. P[k,i] = Mean( SPECTRUM[*,l,i] ) \quad i=0...5.
\item {\em Lmax} : int, number of spherical harmonics computed in the decomposition and size of the computed spectrum (Lmax+1). Default is 3*nside and should be between 2*nside and 4*nside.
\item {\em nonorm} : scalar, if set no normalisation is applied on the ALM computed.
\item {\em StdPS} : Output 2D IDL float array[ALM.lmax+1,6]: estimated standard deviation of the spectrums coefficients.
\item {\em NormVal} : float, normalization value applied to the alm coefficients.
\item {\em teb} : scalar, if set specifies that the input map is in TEB scheme.
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item P = mrsp\_spec( Imag ) \\
Compute the spectrum of the polarized image.
\end{itemize}

\section{Polarized Wavelets}
\subsection{Undecimated Isotropic Wavelet Transform of a polarized spherical map : mrsp\_wttrans}
\index{IDL routines!mrsp\_wttrans}
\index{polar!undecimated wavelet transform of polarized image}
Computes the undecimated isotropic wavelet transform of polarized maps on the sphere in TQU scheme,
using the Healpix representation (nested data representation). The wavelet function is zonal and its
spherical harmonics coefficients $a_{l,0}$ follow a cubic box-spline profile. If the keyword DifInSH is
set, the wavelet coefficients are derived in the Spherical Harmonic Space, otherwise (default) they
are derived in the direct space.
{\bf
\begin{center}
     USAGE: mrsp\_wttrans, Imag, Trans, NbrScale=NbrScale, lmax=lmax, DifInSH=DifInSH, MeyerWave=MeyerWave
\end{center}}
where
\begin{itemize}
\item {\em Imag} : Input 3D IDL array of healpix polarized map in TQU scheme. Input image to be transformed.
\item {\em Trans} : Output IDL structure with the following fields:
\begin{itemize}
\item {\em NbrScale} : int, number of scales.
\item {\em nside} : int, Healpix nside parameter.
\item {\em lmax} : int, maximum l value in the Spherical Harmonic Space.
\item {\em npix} : long, number of pixels of the input image.
\item {\em MeyerWave} : int, 1 if the keyword MeyerWave used, otherwise 0
\item {\em DifInSH} : int, 1 if the keyword DifInSH used, otherwise 0
\item {\em Coef} : fltarr[npix,NbrScale,3] wavelet transform of the data. Coef[*,*,0] = wavelet transform on T, Coef[*,*,1] = wavelet transform on E, Coef[*,*,2] = wavelet transform on B
\begin{center}
Coef[*,0,*] = wavelet coefficients of the finest scale (highest frequencies).\\
Coef[*,NbrScale-1,*] = coarsest scale (lowest frequencies).
\end{center}
\end{itemize}
\item {\em NbrScale} : int, optional input parameter specifying the number of scales (default is 4).
\item {\em Lmax} : int, optional input parameter specifying the maximum multipole number $l$ in the spherical harmonics decomposition
(default is $3\times \textrm{nside}$, should be between $2\times \textrm{nside}$ and $4\times \textrm{nside}$).
\item {\em DifInSH} : Input keyword parameter. If set, the wavelet coefficients are computed as the difference between two resolutions in the spherical harmonics representation.
Otherwise, the wavelet coefficients are computed as the difference between two resolutions in direct space.
\item {\em MeyerWave} : If set, use Meyer wavelets and set the keyword DifInSH.
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item mrsp\_wttrans, Imag, Output, NbrScale=5 \\
Compute the isotropic wavelet transform of the map Imag with five scales. The result is stored in Output.
\end{itemize}

\subsection{Undecimated Isotropic Wavelet Reconstruction of a polarized spherical map : mrsp\_wtrec}
\index{IDL routines!mrsp\_wtrec}
\index{polar!undecimated wavelet reconstruction of polarized image}
Reconstructs a polarized maps on the sphere in TQU scheme using the Healpix representation (nested data representation)
from its wavelet coefficients obtained with the undecimated isotropic wavelet transform on the sphere, described right above.
{\bf
\begin{center}
     USAGE: mrsp\_wtrec, Trans, Rec, filter=filter
\end{center}}
where
\begin{itemize}
\item {\em Trans}: Input IDL structures with the following fields:
\begin{itemize}
\item {\em NbrScale} : int, number of scales.
\item {\em nside} : int, Healpix nside parameter.
\item {\em lmax} : int, maximum l value in the Spherical Harmonic Space.
\item {\em npix} : long, number of pixels of the input image.
\item {\em MeyerWave} : int, 1 if the keyword MeyerWave used, otherwise 0
\item {\em DifInSH} : int, 1 if the keyword DifInSH used, otherwise 0
\item {\em Coef} : fltarr[npix,NbrScale,3] wavelet transform of the data. Coef[*,*,0] = wavelet transform on T, Coef[*,*,1] = wavelet transform on E, Coef[*,*,2] = wavelet transform on B
\begin{center}
Coef[*,0,*] = wavelet coefficients of the finest scale (highest frequencies).\\
Coef[*,NbrScale-1,*] = coarsest scale (lowest frequencies).
\end{center}
\end{itemize}
\item {\em Rec} : Output 3D IDL array of healpix polarized map in TQU scheme. Reconstructed image from the wavelet coefficients.
\item {\em filter} : Input keyword parameter. Use filters for the reconstructions. If this keyword is not set, the reconstructed image is obtained
by a simple addition of all wavelet scales. Automaticaly applied if keyword MeyerWave or DifInSH were set at the wavelet decomposition.
\end{itemize}

\subsubsection*{Examples:}
\begin{itemize}
\item mrsp\_wttrans, Imag, Output, NbrScale=5 \\
Compute the isotropic wavelet transform of the map Imag with five scales. The result is stored in Output.
\item mrsp\_wtrec, Output, map \\
Reconstruct the map.
\end{itemize}

\subsection{Extract a scale from a polar decomposition : mrsp\_wtget}
\index{IDL routines!mrsp\_wtget}
\index{polar!polar wavelet extraction}
Return a band of a transform for Healpix polarized map (wavelet, curvelet\ldots) obtained by the command mrsp\_trans.
{\bf
\begin{center}
     USAGE:  Scale = mrsp\_wtget( Trans, Component, ScaleNumber, BandNumber=BandNumber, NormVal=NormVal )
\end{center}}
where
\begin{itemize}
\item {\em Trans} : Input IDL structure, see mrsp\_trans for more details.
\item {\em ScaleNumber} : int, scale number of the band to be extracted. The scale number must be between 0 and Trans.NbrScale-1.
\item {\em Component} : int, choice of the component, 0 is for T, 1 for E and 2 for B.
\item {\em NormVal} : float, optional normalization value of the band (for isotropic wavelet transform).
\item {\em BandNumber} : int, ridgelet band number (for curvelet transform).
\item {\em Scale} : return value IDL array of the band extracted. See more details on the 1D versions of the functions.
No band is extracted from Modulus-Phases transforms (return 0). For a E/B decomposition, it will be either the T map, the E map or the B map.
\end{itemize}

\subsection{Put a scale into a polar decomposition : mrsp\_wtput}
\index{IDL routines!mrsp\_wtput}
\index{polar!polar wavelet insertion}
Put a band into a transform for Healpix polarized map (wavelet, curvelet\ldots) obtained by the command mrsp\_trans.
{\bf
\begin{center}
     USAGE:   mrsp\_wtput, Trans, Scale, Component, ScaleNumber, BandNumber=BandNumber
\end{center}}
where
\begin{itemize}
\item {\em Trans} : Input IDL structure, see mrsp\_trans for more details.
\item {\em Scale} : Input IDL array of the band inserted. See more details on the 1D versions of the functions.
No band is inserted into Modulus-Phases transforms. For a E/B decomposition, it will be either the T map, the E map or the B map.
\item {\em ScaleNumber} : int, scale number of the band to be extracted. The scale number must be between 0 and Trans.NbrScale-1.
\item {\em Component} : int, choice of the component, 0 is for T, 1 for E and 2 for B.
\item {\em BandNumber} : int, ridgelet band number (for curvelet transform).
\end{itemize}

\section{Denoising}
\subsection{Wavelet filtering of a polarized spherical map : mrsp\_wtfilter}
\index{IDL routines!mrsp\_wtfilter}
\index{polar!polar wavelet filtering}
Wavelet denoising of a polarized image on the sphere using Healpix representation in TQU scheme (nested pixel representation).
By default Gaussian noise is considered. If the keyword SigmaNoise is not set, then the noise standard deviation is automatically
estimated. If the keyword MAD is set, then a correlated Gaussian noise is considered and the noise level at each scale is derived
from the Median Absolution Deviation (MAD) method. If the keyword KillLastScale is set, the coarsest resolution is set to zero.
The thresholded wavelet coefficients can be obtained using the keyword Trans. If the input keyword niter is set, then an iterative
algorithm is applied and if the pos keyword is also set, then a positivity constraint is added.
{\bf
\begin{center}
     USAGE:  mrsp\_wtfilter, Imag, Filter, NbrScale=NbrScale, NSigma=NSigma, SigmaNoise=SigmaNoise, KillLastScale=KillLastScale,
     pos=pos, mad=mad, Trans=Trans, niter=niter, FirstScale=FirstScale, Use\_FdrAll=Use\_FdrAll, soft=soft, fdr=fdr, lmax=lmax,
     FilterLast=FilterLast, mask=mask
\end{center}}
where
\begin{itemize}
\item {\em Imag} : Input 3D IDL array of healpix polarized map in TQU scheme. Input image to be filtered.
\item {\em Filter} : Output 3D IDL array of healpix polarized map in TQU scheme containing the filtered map.
\item {\em NbrScale} : int, number of scales (default is 4).
\item {\em NSigma} : float, level of thresholding (default is 3).
\item {\em SigmaNoise} : float, noise standard deviation. Default is automatically estimated.
\item {\em mad} : scalar, if set the noise level is derived at each scale using the MAD of the wavelet coefficient.
\item {\em KillLastScale} : scalar, if set the last scale is set to zero.
\item {\em niter} : int, number of iterations used in the reconstruction.
\item {\em pos} : scalar, if set the solution is assumed to be positive.
\item {\em FirstScale} : int, consider only scales larger than FirstScale. Default is 1 (i.e. all scales are used).
\item {\em Soft} : scalar, if set use soft thresholding instead of hard thresholding.
\item {\em fdr} : float between 0 (default) and 1 (max, if greater or equal to 1, set to 0.05), used to estimate a threshold level
instead of a NSigma threshold, threshold is applied from scale j=FirstScale to the last.
\item {\em Use\_FdrAll} : same as fdr but applied to all scales.
\item {\em FilterLast} : scalar, if set the last scale is filtered.
\item {\em mask} : IDL array of healpix map, input mask applied.
\item {\em lmax} : int, maximum l value in the Spherical Harmonic Space.
\item {\em Trans} : IDL structure: Thresholded wavelet decomposition of the input image.
\end{itemize}

\subsubsection*{Example:}
\begin{itemize}
\item mrsp\_wtfilter, Imag, Filter, NbrScale=5, Nsigma=5 \\
Wavelet filtering with five scales and a 5 sigma threshold.
\end{itemize}

\subsection{Thresholding in polarized wavelet or curvelet space  : mrsp\_threshold}
\index{IDL routines!mrsp\_threshold}
\index{polar!polar curvelet filtering}

Threshold the decomposition coefficients of a polarized healpix map. This routine works with several decompositions (see mrsp\_trans).
{\bf
\begin{center}
     USAGE:  mrsp\_threshold, Trans, NSigma=Nsigma, Mad=Mad, KillLastScale=KillLastScale
\end{center}}
where
where
\begin{itemize}
\item {\em Trans} : IDL structures obtained from the {\em mrsp\_trans} routine.
\item {\em Nsigma}: Level of thresholding (default is 3)
\item {\em KillLastScale}: if set, the last scale is set to zero
\end{itemize}

\subsubsection*{Examples:}
 Compute the undecimated wavelet transform of a vector field I with five scales (needlet filters).  The result is stored in WT, then wavelet coefficients are threshold at 2 sigma, and the filtered polarized map is reconstructed.
\begin{itemize}
\item  mrsp\_trans, I, WT, NbrScale=5, /UWT, /NeedletWave
\item  mrsp\_threshold, WT, NSigma=2
\item  mrsp\_rec, WT, RecPola
\end{itemize}
Compute the curvelet transform of a vector field I with five scales.  The result is stored in C, then curvelet coefficients are threshold at 5 sigma, and the filtered polarized map
is reconstructed.
\begin{itemize}
\item  mrsp\_trans, I, C, NbrScale=5, /Cur
\item  mrsp\_threshold, C, NSigma=5
\item  mrsp\_rec, C, RecPola
\end{itemize}


\chapter{Introduction} \label{ch:introduction}

A type system is a delicate balance between expressivity and well-behavedness.
More expressivity allows for more programs to be well typed,
while paradoxically allowing less code to be written,
because some of the onus of ensuring a program is valid is shifted
from the programmer to the process of type checking.
On the other hand, too much expressivity can destroy
desirable metatheoretical properties of the type system ---
strings get be treated as integers, booleans can be called like functions,
and the language falls to chaos and ruin.

The balancing act is particularly perilous for type systems
used by proof assistants for mechanized theorem proving,
because a lack of expressivity can make it too much of a burden to be practically useful,
while it's all to easy to add some convenient, seemingly innocuous feature
that turns out to dismantle the logic of the system,
rendering it unusable for proving.

This thesis deals with dependent type theory, which is commonly used for theorem proving,
together with sized types, a feature for inductively defined types
used to increase the expressivity of recursive functions,
and shows that dependent types can be extended with state-of-the-art sized types
without sacrificing key metatheoretical properties.

\section{Background}

Before we begin, I briefly summarize why dependent types are used for theorem proving,
as well as what sized types have to offer in the context of programming with dependent types.

\subsection{Theorem proving with dependent types} \label{tt}

Many contemporary proof assistants are founded on the Curry--Howard correspondence,
where propositions correspond to types,
proofs of these propositions to terms of those types,
and proof verification to type checking.
Different type theories correspond to different logical systems;
dependent type theories, in particular, correspond to predicate logics.
The primary feature of dependent type theory is the dependent function type,
because it encodes universal quantification by allowing types to \emph{depend on} terms:
the type $\funtype{x}{A}{\app{P}{x}}$ can be interpreted as the statement
``for all objects $x$ in $A$, $P$ holds of $x$'',
with the consequent $\app{P}{x}$ depending on the term $x$.
Other logical constructs can be encoded as well, for example:

\begin{itemize}
  \item Falsehood ($\bot$) as $\funtype{P}{\Prop}{P}$,
    (where $\Prop$ is the type of all propositions),
    the statement that \emph{all} propositions hold;
  \item Implication as $\funtype{\any}{A}{B}$
    (or $\arr*{A}{B}$ for short),
    where $B$ holds only when given a proof of $A$;
  \item Negation as $\arr*{A}{\bot}$,
    or that proving $A$ will yield a falsehood; and
  \item Truthhood as $\funtype{P}{\Prop}{\arr*{P}{P}}$\punctstack{,}%
    \footnote{This encoding is slightly simpler than
    the negation of falsehood $\arr*{\bot}{\bot}$,
    particularly when written out in full.}
    which is trivially inhabited by the identity function
    $\fun{P}{\Prop}{\fun{p}{P}{p}}$;
\end{itemize}
and many other logical connectives such as existential quantification, conjunction, disjunction, and equality.

A key metatheoretical property that a type theory must satisfy
for its interpretation as a logical system to be valid is \emph{consistency}:
falsehood cannot be proven.
In other words, there must not be any term whose type is $\funtype{P}{\Prop}{P}$.
Otherwise, any proposition would be provable,
including those we know to be obviously untrue,
such as $0 = 1$.

The two most important components of a formal description of a dependent type theory
are its typing judgement, whose rules describe when a term has a certain type,
and its equality judgement(s), whose rules describe when two terms are equal.
The latter is relevant in dependent types because they allow determining that,
for instance, a proof of \mbox{$\app{P}{(1 + 1)}$}
is in fact also a proof of $\app{P}{2}$.
Naturally, equality is sometimes described in terms of reduction judgements,
governed by the rules of computation.
This means that, in contrast to nondependent type systems,
whether type checking always terminates depends on whether the language is normalizing.
The issue gets even more complicated with more complex forms of reduction like recursion.

\subsection{Recursive programming with sized types} \label{ss}

Inductively defined data and recursive functions on them
are indispensable tools of programming,
allowing the expression of a variety of constructs, programs,
and in the case of dependent types, their properties.
A crucial restriction on recursive functions
in proof assistants such as Agda, Coq, Idris, Lean, and more
is that recursive functions must be \emph{guarded by destructors}\index{guardedness}
and only recur on structurally smaller arguments~\citep{guard}.
This guardedness check is statically done before or during type checking and,
to vastly simplify, ensures that recursive calls occur only on syntactic subarguments:
if the original argument is some natural $\app{\succ*}{n}$ that is the successor of $n$,
then the function recurs only on $n$;
if it's some cons list $\app{\cons*}{\hd}{\tl}$
consisting of an element and the rest of the list $\tl$,
then it recurs only on $\tl$; and so on.

Although this is usually referred to as a syntactic termination check,
and termination is essential in ensuring decidability of type checking,
the key desired property is rather consistency.
Indeed, a type theory may be consistent yet nonnormalizing
(as is the case with an impredicative\index{impredicativity},
definitionally proof-irrelevant $\Prop$ universe~\citep{impred-proof-irrel}),
but unrestricted recursion easily proves an inconsistency:
the recursive function $f$ defined by $\fun{P}{\Prop}{\app{f}{P}}$,
for instance, can be assigned type $\funtype{P}{\Prop}{P}$,
in addition to being nonterminating.

While the guardedness check, being based on the elimination principles of inductive types,
yields terminating functions and a consistent type theory,
it has known disadvantages:

\begin{itemize}
  \item Calling some other function on a subargument prior to a recursive call is disallowed,
    even if that function doesn't change the structure of that subargument,
    because the input of the recursive call is no longer exactly the syntactic subargument.
    For instance, a recursive function on lists cannot first map over the sublist,
    even though the usual mapping function doesn't change the length of a list
    and therefore presents no threat to termination.
  \item Some proof assistants (Coq, for one) will inline functions and even unfold recursive functions
    so that the guardedness check has more information
    and that more recursive functions pass the check.
    However, this too has its disadvantages:
    \begin{itemize}
      \item Programs become nonmodular and noncompositional:
        not only do recursive functions that require inlining
        depend on the implementation of inlined functions,
        they may also depend on their specific implementation details,
        and even a minor syntactic change otherwise equivalent to the original
        can break guardedness~\citep{CIC-hat-minus}.
      \item As aptly summarized by \citet{coqterm},
        \begin{quote}
        \begin{singlespace}
        \textit{{\rm [\ldots]} unfold{\rm [ing]} all the definitions used in the body of the function, do{\rm [ing]} reductions, e.t.c.
        {\rm [\ldots]} makes typechecking extremely slow at times.
        Also, the unfoldings can cause the code to bloat by orders of magnitude and become impossible to debug.}
        \end{singlespace}
        \end{quote}
    \end{itemize}
\end{itemize}

In cases where the guardedness check fails on terminating functions,
the programmer can refactor the function to recur on a different, related argument,
such as the length of a list in the example above,
but this requires additional work and may bloat programs
with extra code solely for satisfying the guardedness check
that detracts from the programs' original intent.
Alternatives to the syntactic guardedness check that avoid these issues are type-based checks,
where the type system itself is augmented so that successful type checking
immediately guarantees termination and consistency.

The one this thesis focuses on is \emph{sized typing}\punctstack{,}%
\footnote{The other common one uses \emph{guarded types}~\citep{guarded-types}.}
where inductive types are annotated with size information,
and constructors construct constructions whose size is larger than that of their subarguments.
In short, the notion of a ``smaller'' subargument is encoded within the types,
no longer requiring syntactic analysis to determine.
Finally, a recursive function is well typed only if it recurs on an argument
whose size is smaller than that of the original argument.

Because well-typedness is the only required condition,
calling some other function before a recursive call is allowed
as long as that function is \emph{size preserving}\index{size preservation}.
For the list mapping example above,
this means that if the sublist of elements of type $\tau$ has size $s$,
then the mapping function must have type $\arr*{\List{\tau}{s}}{\List{\tau}{s}}$.
Notice that the implementation of the mapping function isn't required,
merely its type, restoring modularity and compositionality.

This thesis then introduces Sizey \textsc{mc}Type Theory (\lang),
a sized dependent type theory that I prove to be logically consistent
and therefore suitable for both recursive programming and theorem proving.

\section{Overview}

But what need is there for yet another sized type system?
Since \citet{hughes}, there has been a little over two decades' worth of past work on sized types.
\citet{flationary} notes that it has been the topic of at least five dissertations.
This chapter alone names a dozen different type systems with sized types.
There have been many advancements along the way,
but none quite satisfactory to close the matter,
especially when it comes to dependent types.

\lang and this thesis as a whole does not aim to resolve
all of the remaining problems of sized types left open by these past works.
Instead, the purpose is threefold:

\begin{itemize}
  \item To fill an existing gap in sized dependent type theories.
    Two modern sized type features are higher-rank and bounded size quantification,
    and there exist a few dependent type theories with one or the other,
    but not both, to my knowledge.
    On the other hand, they are currently in Agda's implementation of sized types.
    By proving the consistency of \lang, a novel type theory with these two features,
    I bring the theoretical state-of-the-art closer to practice. \\
  \item To demonstrate the viability of using a syntactic model to prove consistency
    of a sized type theory.
    Doing so from scratch through a set-theoretic model is notoriously difficult,
    and often requires sacrifices to and constraints on the type theory;
    see Sacchini's dissertation~\citep{CIC-hat-minus} or \CIChatstar~\citep{CIC-hat-star},
    for instance.
    Instead, a syntactic model relies on the consistency of the language in which I'm modelling,
    allowing me to focus on only the interesting parts of the sized type theory
    rather than on consistency as a whole.
  \item To reopen the discussion on sized dependent types.
    Since the discovery of the inconsistency of Agda's sized types~\citep{infinity},
    progress appears to have stagnated a little.
    In \cref{ch:discussion}, I examine these difficulties as they might apply to \lang
    and its interpretation in the syntactic model.
\end{itemize}

In this section I describe and justify the design of
the dependent types and the sized types of \lang,
explain how a syntactic model is used to prove its consistency,
and briefly outline the structure of the proof.

\subsection{Dependent types}

As a simple but expressive foundation for dependent types,
I start with the Generalized Calculus of Constructions (\GCC)\index{Calculus of Constructions!Generalized \textasciitilde} \citep{GCC-Coquand},
which has the following features:

\begin{itemize}
  \item \textbf{Dependent function types}, as is standard in the Calculus of Constructions (CC)~\citep{CoC}\index{Calculus of Constructions};
  \item \textbf{Definitions}, \ie locally-named expressions;
  \item \textbf{Universes \ala Russell}\index{universes \ala Russell}, where the types of types are themselves terms
    (as opposed to universes \ala Tarski\index{universes \ala Tarski}, where their \emph{encodings} are terms);
  \item An \textbf{impredicative universe}\index{impredicativity} $\Prop$ such that function types into types in $\Prop$
    are themselves in $\Prop$;
  \item A \textbf{cumulative hierarchy of universes}\index{cumulativity} such that $\Type{i}: \Type{i+1}$,
    any term in $\Type{i}$ is also in $\Type{j}$ given \emph{universe levels}\index{universe level} $i \leq j$,
    and there is a subtyping relation\index{subtyping} on types induced by this inclusion; and
  \item \textbf{Untyped definitional equality} stating when two terms are judgementally equal to one another.
\end{itemize}

These features cover many modern proof assistants.
To name a few, in terms of universes,
Coq and Arend have all of the above;
Lean lacks cumulativity; and
Agda and \Fstar lack cumulativity and an impredicative universe.
On the other hand, these proof assistants all have some form of
\emph{universe level polymorphism},
but this is much more complex and largely orthogonal to sized types
and the syntactic model.

Perhaps the most contentious design decision so far is the use of untyped equality,
as can be found in Coq, over typed equality, as can be found in Agda.
While typed equality is considered to ``have clearer mathematical semantics''~\citep{typed-NbE},
its judgement depends on the typing judgement;
meanwhile, since types can depend on terms,
typing itself depends on equality to check whether one type can be used in place of another.
As we'll see in \cref{sec:syntactic-model},
these mutually-defined judgements would greatly complicate the proofs for the syntactic model,
so I settle for untyped equality instead.

On top of \GCC, I add two inductive definitions featured in Martin--L\"of type theory (MLTT)~\citep{MLTT}\index{Martin--L\"of type theory}:
the \emph{Peano naturals} and \emph{well-founded trees}\punctstack{,}%
\footnote{The types of well-founded trees are also known as \emph{W types}.}
augmented with sizes.
As the simplest nontrivial inductive,
the naturals make it easy to demonstrate intuitive uses of sized inductives.
On the other hand, well-founded trees are an example of \emph{generalized} inductives,
with recursive arguments that are functions that return well-founded trees.
They can encode all (nonnested) inductives,
as well as their induction principles \citep{whynotW} if there are dependent pair types
and a \emph{propositional equality}\index{propositional equality} type.
I don't add inductive types in general in their place
because the syntactic baggage that comes with handling the generalization
obscures the intuition behind sized inductive types and the syntactic model,
while it's easy to see how one \emph{could} go from the naturals and well-founded trees
to inductive types in general.

\subsection{Sized types}\label{sec:sized-types}

Sized types begin with explicit size quantification $\Funtype{\alpha}{\tau}$,
size abstraction $\Fun{\alpha}{e}$, and size application $\App{e}{s}$.
Sizes themselves consist of size variables, a \emph{base size},
and a \emph{size successor operator}.
This is the standard for size expressions in sized type systems.
Some augment the size grammar with addition of or scalar multiplication of size variables,
for instance, increasing expressivity at the expense of added complexity in size checking.
To keep things simple, I don't include these features and stick to successor sizes.
Size expressions here are \emph{not} terms,
and their quantifications, abstractions, and applications
are syntactically distinct from those of terms,
similar to how, in nondependent polymorphic type systems,
types are distinct from terms.

Having explicit sizes differs from some most prior sized type systems where,
extending the type polymorphism analogy,
there is only implicit \emph{rank-1} or
\emph{prenex} size quantification:
size quantifications never appear inside of a type,
and in fact all size abstractions and applications are fully inferred.
Explicit sizes, in contrast, let us express
\emph{higher-rank} size quantification,
which allow for more expressiveness:
for instance, supposing we have cons lists parametrized over some sized type $\tau$,
one could write a size-preserving mapping function over a list
that leaves the size of its elements untouched.
The type of such a function might be

\vspace{-0.25\baselineskip}
$$\Funtype{\alpha}{\arr*{(\Funtype{\beta}{\arr*{\App{\tau}{\beta}}{\App{\tau}{\beta}}})}{\app{\List*}{(\App{\tau}{\alpha})}}{\app{\List*}{(\App{\tau}{\alpha})}}}.$$

Along with higher-rank sizes, I also include \emph{bounded} size quantification $\Funtype<{\alpha}{s}{\tau}$
and abstraction $\Fun<{\alpha}{s}{e}$.
An order on sizes is induced by these bound instantiations and the successor operator;
this order has nothing to do with subtyping,
and in particular we do \emph{not} have subtyping relations between
$\N{\alpha}$ and $\N{\sss{\alpha}}$, for instance.
Fixpoint expressions recur on smaller sizes according to the order,
summarized by the below typing rule.
%
\begin{mathpar}
\inferrule[]{
  \check{\Phi, \alpha; \Gamma, f: \Funtype<{\beta}{\alpha}{\subst{\tau}{\alpha}{\beta}}}{e}{\tau}
}{
  \infer{\Phi; \Gamma}{\fix{f}{\alpha}{\tau}{e}}{\Funtype{\alpha}{\tau}}
}
\end{mathpar}

Bounded sizes were originally introduced to avoid inconsistencies
from pattern-matching on sizes~\citep{MiniAgda}.
Although \lang has no pattern-matching mechanism,
this style of recursion is more elegant because it corresponds neatly to well-founded induction on sizes,
and because it does away with complex \emph{semi-continuity} or approximative \emph{polarity}
requirements on fixpoints' types that would otherwise be needed for consistency.
Indeed, to \citet{flationary},

\begin{quote}
\begin{singlespace}
\textit{A technical condition like semi-continuity can kill a system
as a candidate for the foundation of logics and programming
{\rm [\ldots]} Most systems for type-based termination replace semi-continuity by a rough approximation,
trading expressivity for simplicity}.
\end{singlespace}
\end{quote}

In summary, the sized type features I include are:

\begin{itemize}[noitemsep]
  \item \textbf{Explicit size} quantification $\Funtype{\alpha}{\tau}$,
    abstraction $\Fun{\alpha}{e}$, and
    application $\App{e}{s}$;
  \item A \textbf{simple size grammar} with size variables $\alpha$, a base size $\circ$, and successors $\sss{s}$;
  \item \textbf{Higher-rank sizes}, \eg $\arr*{(\Funtype{\alpha}{\tau})}{\sigma}$;
  \item \textbf{Bounded size} quantification $\Funtype<{\alpha}{s}{\tau}$ and
  abstraction $\Fun<{\alpha}{s}{e}$.
\end{itemize}

Notably, these are all features found in Agda's implementation of sized types.
On the other hand, \lang excludes Agda's \emph{infinite size}\index{infinite size}
that is strictly larger than all sizes,
since this property is known to be inconsistent in Agda.
A demonstration of the inconsistency of a hypothetical infinite size in \lang
is given in \cref{sec:infinity}.
On the other hand, the lack of an infinite size prevents
certain infinitary constructs from being expressed;
\cref{sec:examples:limitations} gives a concrete example.

\subsection{Syntactic model}\label{sec:syntactic-model}

To show that \lang is consistent and therefore a suitable type theory for proofs,
I define for it a \emph{syntactic model}\index{syntactic model}~\citep{syntactic-models}.
This involves defining a translation from \lang into some target type theory
in whose consistency we have more confidence---in this case,
the \emph{Extensional Calculus of Inductive Constructions}\index{Calculus of Inductive Constructions!Extensional \textasciitilde}
(\CICE)~\citep{CICE}.
It, too, has a cumulative hierarchy of universes \ala Russell and an impredicative universe,
augmented with inductive types and \emph{equality reflection}\index{equality reflection},
where a definitional equality between terms can be derived from a propositional one between them.
The most notable difference from \lang, aside from these features and sized types,
is that \CICE uses a typed, declarative equality rather than an untyped, algorithmic equality
to better accommodate equality reflection.
For concision and to avoid confusion, I henceforth refer to the former as \emph{equivalence}\index{equivalence},
and to the latter as \emph{conversion}\index{conversion}.

This translation from \lang to \CICE must be \emph{type preserving}\index{type preservation}%
\footnote{This terminology comes from compilation;
in the context of syntactic modelling,
this is known as \emph{soundness} with respect to the translation target.}:
if some term $e$ is well typed under some environments $\Phi; \Gamma$ with some type $\tau$,
then the translated term $\compile{e}$ must also be well typed
under the translated environment $\compile{\Phi}, \compile{\Gamma}$
with the translated type $\compile{\tau}$.
By the consistency of \CICE and a type-preserving translation to it,
we prove the consistency of \lang.

\begin{postulate}[Consistency of \CICE]\label{fact:consistency-cice}
There exists no term $\eT$ such that
\mbox{$\type{\mt}{\eT}{\funtypeT{\PT}{\PropT}{\PT}}$}.
\end{postulate}

\begin{theorem}[Consistency of \lang]\label{thm:overview:consistency}
Suppose $\compile{\bot} = \funtypeT{\PT}{\PropT}{\PT}$.
Then there exists no term $e$ such that \mbox{$\type{\mt \mathbin{;} \mt}{e}{\bot}$}.
\end{theorem}
\begin{proof}
Suppose that there were such a term $e$.
By the type-preserving translation, we would have that
$\type{\mt}{\compile{e}}{\funtypeT{\PT}{\PropT}{\PT}}$ holds.
However, this contradicts \cref{fact:consistency-cice},
so there must not be such a term.
\end{proof}

What remains, then, is to define $\bot$ and an appropriate translation from \lang to \CICE
such that $\compile{\bot} = \funtypeT{\PT}{\PropT}{\PT}$,
and to show that this translation is type preserving.
I define my translation by induction on the typing derivations of \lang
rather than merely over its syntax,
ensuring that only well-typed terms need to be considered.

Type preservation of the translation is proven by induction on not only the typing derivations,
but also the derivations of the judgements on which the typing rules depend.
In particular, typing depends on subtyping\index{subtyping} $\preccurlyeq$,
which in turn depends on \emph{$\alpha$-cumulativity}\index{$\alpha$-cumulativity}
$\sqsubseteq$~\citep{MetaCoq}
and on the reflexive, transitive closure of reduction $\rhd^*$.
Finally, this closure of reduction depends on the reduction rules $\rhd$,
most of which are defined by substitution.
Below are the relevant rules showing these dependencies and an example reduction rule.
These judgements will be explained in detail shortly in the next chapter;
I present them here only to motivate the proof structure.
%
\begin{mathpar}
\inferrule[]{
  \dots \\\\
  \infer{\Phi; \Gamma}{e}{\sigma} \\\\
  \subtype{\Phi; \Gamma}{\sigma}{\tau}
}{
  \check{\Phi; \Gamma}{e}{\tau}
}

\inferrule[]{
  \acum{\sigma_1}{\sigma_2} \\\\
  \red*{\Phi; \Gamma}{\tau_1}{\sigma_1} \\\\
  \red*{\Phi; \Gamma}{\tau_2}{\sigma_2}
}{
  \subtype{\Phi; \Gamma}{\tau_1}{\tau_2}
}

\inferrule[]{
  \red{\Phi; \Gamma}{e_1}{e_2}
}{
  \red*{\Phi; \Gamma}{e_1}{e_2}
}

\inferrule[]{~}{
  \red{\Phi; \Gamma}{\app{(\fun{x}{\tau}{e})}{e'}}{\subst{e}{x}{e'}}
}
\end{mathpar}

We therefore need some lemmas showing that the translation respects
substitution, reduction, the closure of reduction, $\alpha$-cumulativity, and subtyping
to prove type preservation.
In short, substitution satisfies a \emph{compositionality}\index{compositionality} principle,
reduction of terms are equivalent by the \CICE equivalence judgement
$\defeq{\GammaT}{\eT_1}{\eT_2}{\tauT}$,
and $\alpha$-cumulative terms and subtypes are correspondingly \CICE subtypes.
I summarize them here, omitting some hypotheses and sublemmas,
solely to outline the proof architecture,
which roughly follows the structure of type-preserving compilation by~\citet{wjb}.

\begin{lemma}[Compositionality]\label{lem:overview:compositionality}\hfill
\begin{enumerate}[noitemsep]
  \item $\compile{\subst{e}{x}{e'}} = \subst{\compile{e}}{x}{\compile{e'}}$.
  \item $\compile{\subst{e}{\alpha}{s}} = \subst{\compile{e}}{\alpha}{\compile{s}}$
\end{enumerate}
\end{lemma}

\begin{proof}
By induction on the derivation of $\type{\Phi; \Gamma}{e}{\tau}$.
\end{proof}

\begin{lemma}[Preservation of reduction]\label{lem:overview:pres-red}
If $\red{\Phi; \Gamma}{e}{e'}$ and
$\type{\compile{\Phi}\compile{\Gamma}}{\compile{e}}{\tauT}$
then $\defeq{\compile{\Phi}\compile{\Gamma}}{\compile{e}}{\compile{e'}}{\tauT}$.
\end{lemma}

\begin{proof}
By cases on the derivation of $\red{\Phi; \Gamma}{e}{e'}$,
using inversion on the derivation of $\type{\compile{\Phi}\compile{\Gamma}}{\compile{e}}{\compile{\tau}}$,
\cref{lem:overview:compositionality},
and an application of equality reflection in the case for reduction of fixpoints.
\end{proof}

\begin{lemma}[Preservation of reflexive, transitive closure of reduction]\label{lem:overview:pres-red*}
If $\red*{\Phi; \Gamma}{e}{e'}$ and
$\type{\compile{\Phi}\compile{\Gamma}}{\compile{e}}{\tauT}$
then $\defeq{\compile{\Phi}\compile{\Gamma}}{\compile{e}}{\compile{e'}}{\tauT}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\red*{\Phi; \Gamma}{e}{e'}$,
using \cref{lem:overview:pres-red},
subject reduction of \lang,
and subject equivalence of \CICE.
\end{proof}

\begin{lemma}[Preservation of $\alpha$-cumulativity]\label{lem:overview:pres-acum}
If $\acum{\tau_1}{\tau_2}$ and
$\type{\compile{\Phi}\compile{\Gamma}}{\compile{\tau_i}}{\UT_i}$
then $\subtype{\compile{\Phi}\compile{\Gamma}}{\compile{\tau_1}}{\compile{\tau_2}}$.
\end{lemma}

\begin{proof}
By induction on the derivation of $\acum{\tau_1}{\tau_2}$,
using inversion on the derivations of $\type{\Phi; \Gamma}{\tau_i}{U_i}$ and
$\type{\compile{\Phi}\compile{\Gamma}}{\compile{\tau_i}}{\UT_i}$.
\end{proof}

\begin{lemma}[Preservation of subtyping]\label{lem:overview:pres-subtyping}
If $\subtype{\Phi; \Gamma}{\tau_1}{\tau_2}$
and $\type{\compile{\Phi}\compile{\Gamma}}{\compile{\tau_i}}{\compile{U}}$
then $\subtype{\compile{\Phi}\compile{\Gamma}}{\compile{\tau_1}}{\compile{\tau_2}}$.
\end{lemma}

\begin{proof}
By cases on the derivation of $\subtype{\Phi; \Gamma}{\tau_1}{\tau_2}$,
using \cref{lem:overview:pres-red*}, \cref{lem:overview:pres-acum},
subject reduction of \lang,
and subject equivalence of \CICE.
\end{proof}

\begin{theorem}[Type preservation]\label{lem:overview:pres-typing}\hfill
\begin{enumerate}[noitemsep]
  \item If $\wf{\Phi}{\Gamma}$ then $\wf{}{\compile{\Phi}\compile{\Gamma}}$.
  \item If $\type{\Phi; \Gamma}{e}{\tau}$ then $\type{\compile{\Phi}\compile{\Gamma}}{\compile{e}}{\compile{\tau}}$.
\end{enumerate}
\end{theorem}

\begin{proof}
By mutual induction on the derivations of $\wf{\Phi}{\Gamma}$ and $\type{\Phi; \Gamma}{e}{\tau}$,
using \cref{lem:overview:pres-subtyping}.
\end{proof}

The most important properties required of \lang are subject reduction\index{subject reduction},
used in \cref{lem:overview:pres-subtyping},
and confluence\index{confluence}, which is used to show that subtyping is transitive,
which in turn is used to prove the inversion principles for the typing judgement.

This proof structure is possible by virtue of the non-mutuality of the judgements of \lang
due to the use of untyped conversion\index{conversion} (and hence untyped reduction).
If it were instead typed, then it would mutually depend on typing and subtyping as well,
and proving the above lemmas would require a seven-part mutual induction on the derivations.

\section{Related Work}

The history and development of sized types spans over two decades of past work,
and that of dependent types far more than that.
I therefore mention here only past work that are directly relevant
or that I refer to again in later chapters.

\subsection{Dependent type theories}

\GCC\index{Calculus of Constructions!Generalized \textasciitilde}
was originally proposed by \citet{GCC-Coquand},
adding a universe hierarchy to CC\index{Calculus of Constructions} with untyped equality
and using \rref{cum} for cumulativity\index{cumulativity}.
The \emph{Extended Calculus of Constructions}\index{Calculus of Constructions!Extended \textasciitilde}
(ECC) by \citet{ECC} adds a dependent pair type
and uses a subtyping relation instead for cumulativity;
\rref{untyped-subtype-prop, untyped-subtype-pi} are the most notable subtyping rules.

\vspace{-\baselineskip}
\begin{mathpar}
\inferrule[\rlabel*{cum}]{
  \type{\Gamma}{e}{\Type{i}}
}{
  \type{\Gamma}{e}{\Type{i+1}}
}
\and
\inferrule[\rlabel{$\preccurlyeq$-prop}{untyped-subtype-prop}]{~}{
  \subtype{\Gamma}{\Prop}{\Type{i}}
}
\and
\inferrule[\rlabel{$\preccurlyeq$-pi}{untyped-subtype-pi}]{
  \Gamma \vdash \sigma_1 \approx \sigma_2 \\
  \subtype{\Gamma, \annot{x}{\sigma_2}}{\tau_1}{\tau_2}
}{
  \subtype{\Gamma}{\funtype{x}{\sigma_1}{\tau_1}}{\funtype{x}{\sigma_2}{\tau_2}}
}
\end{mathpar}

\citet{universes} introduce ways of adding universe polymorphism to \GCC
as well as to a version of \GCC with definitions.
For the purposes of this thesis, I use \GCC to refer to the type theory
with subtyping and definitions.

The \emph{Calculus of Inductive Constructions}\index{Calculus of Inductive Constructions} (CIC) \citep{CIC}
adds inductive types to CC,
while the \emph{Predicative Calculus of Inductive Constructions}\index{Calculus of Inductive Constructions!Predicative \textasciitilde} (pCIC)
further adds definitions and a cumulative universe hierarchy via subtyping\punctstack{.}%
\footnote{More precisely, pCIC refers to Coq's core CIC with the cumulative universe hierarchy
and without an \emph{impredicative $\Set$} universe from version 8 onwards \citep[Chapter~4]{Coq-manual}.
The Coq Reference Manual from version 8.5 onwards refers to it simply as CIC,
as do many others, \eg \citet{CIC-unifier}.
I prefer to use the specific name pCIC,
since most seem to use CIC to refer to whatever Coq's core calculus happens to be based on at the moment,
which is currently pCuIC.}
\citet{pCIC} give a set-theoretic model for a variant of pCIC with typed equality.
The \emph{Predicative Calculus of Cumulative Inductive Constructions}
\index{Predicative Calculus of Cumulative Inductive Constructions} (pCuIC) \citep{pCuIC}
further extends pCIC with additional cumulativity\index{cumulativity} between inductive types,
also providing a set-theoretic model,
and it serves as the modern core calculus of Coq.
Closely related is the MetaCoq project~\citep{MetaCoq}\index{MetaCoq},
which mechanizes pCuIC and various of its metatheorems within Coq itself,
with additional alternate untyped equality and subtyping judgements,
since Coq's implementation of definitional equality is untyped.

\citet{CCE} adds a propositional equality type with
equality reflection\index{equality reflection} to \GCC with \rref{cum} in \CCE,
although transitivity of definitional equality only holds for well-typed terms,
and gives a syntactic model in an extension of CIC.
Following that, \citet{CICE} improve upon the translation,
using ECC with a propositional equality type, typed equality,
and two extensional axioms,
translating from this type theory with equality reflection (ETT) to one without (ITT).
They implement the translation in Template Coq \citep{TemplateCoq},
extending it to include inductive types.

In contrast to these type systems based on CC,
MLTT\index{Martin--L\"of type theory} is a dependent type theory
with a noncumulative universe hierarchy without $\Prop$,
typed equality, and some basic types: the empty type, the unit type,
dependent pair types, disjoint sum types, and a propositional equality type,
as well as the types of naturals and well-founded trees as mentioned.
They can all be implemented as inductive types in pCIC.

The source language \lang and target language \CICE in this thesis aren't exactly
a single type theory from the literature augmented with sized types.
In short, \lang is based on \GCC but with MetaCoq's alternate subtyping rules
and augmented with naturals and well-founded trees,
while \CICE is based on pCIC with extensionality inspired by ETT.

\subsection{Sized type systems}

Sized dependent type systems date all the way back to \CCR by \citet{CCR},
although its sized types are formulated quite differently from ``modern'' sized types.
The first sized dependent type theory recognized as such is \CIChat by \citet{CIC-hat},
which adds prenex sizes
and a size inference algorithm to CIC.
In the intervening years, several nondependent sized type systems were developed,
notably the ML-like type system by \citet{hughes} (independently of \CCR),
\lambdahat~\citep{lambda-hat, lambda-hat-diss},
\Fhat~\citep{F-hat}, and
\Fhattimes~\citep{F-hat-times},
all of which focus on prenex, fully-inferrable sizes.
\Fhatomega~\citep{Abel-diss}, on the other hand,
has higher-rank, explicitly-quantified sizes.
Other sized type systems and more extensive discussions can be found in dissertations by
\citet{lambda-hat-diss} and \citet{Abel-diss}.

\begin{table}[h]
\centering
\iffalse
\begin{tabular}{l c c c l}
Type system & Explicit sizes? & Higher-rank? & Bounded? & Size algebra \\
\hline
\citet{hughes} & \crossmark & \crossmark & \crossmark & $\sss{s}, s + s, n \times s$ \\
\lambdahat~\citep{lambda-hat, lambda-hat-diss} & \crossmark & \crossmark & \crossmark & $\sss{s}$ \\
\Fhat~\citep{F-hat} & \crossmark & \crossmark & \crossmark & $\sss{s}$ \\
\Fhattimes~\citep{F-hat-times} & \crossmark & \crossmark & \crossmark & $\sss{s}, s + s$ \\
\Fhatomega~\citep{Abel-diss} & \checkmark* & \checkmark* & \crossmark & $\sss{s}$ \\
\Fcopomega~\citep{F-omega-cop} & \checkmark* & \checkmark* & \checkmark* & $\sss{s}$ \\
\end{tabular}
\fi

\begin{tabular}{l c c c c}
Type theory & Explicit sizes? & Higher-rank? & Bounded? & Consistent? \\
\hline
\CIChat~\citep{CIC-hat} & \crossmark & \crossmark & \crossmark & \interromark \\
\CIChatminus~\citep{CIC-hat-minus-nat, CIC-hat-minus} & \crossmark & \crossmark & \crossmark & \checkmark* \\
\CChatomega~\citep{CC-hat-omega} & \crossmark & \crossmark & \crossmark & \checkmark* \\
\CIChatl~\citep{CIC-hat-l} & \crossmark & \crossmark & \crossmark & \checkmark* \\
\CIChatsub~\citep{CIC-hat-sub} & \crossmark & \crossmark & \checkmark* & \checkmark* \\
\CIChatstar~\citep{CIC-hat-star} & \crossmark & \crossmark & \crossmark & \interromark \\
\citet{NbE} & \checkmark* & \checkmark* & \crossmark & \checkmark* \\
MiniAgda~\citep{MiniAgda, flationary} & \checkmark* & \checkmark* & \checkmark* & \crossmark \\
\textbf{\lang} & \checkmark* & \checkmark* & \checkmark* & \checkmark*%
\textsuperscript{\labelcref{foot:CICE-consistency}}
\end{tabular}
\caption{Sized dependent type theories and their properties}
\label{tab:sized-types}
\end{table}

\cref{tab:sized-types} lists the sized dependent type theories that follow \CIChat,
along with the main features I focus on:
explicit, higher-rank, bounded size quantification,
and with whether the type theory has been proven consistent.
The type theory of MiniAgda, on which the sized types implemented in Agda are based,
is the only prior one with all three sized type features,
but is known to be inconsistent~\citep{infinity}.
(Interestingly, \Fcopomega~\citep{F-omega-cop}, which extends System F$_\omega$ with (co)inductive types and sized types,
has all three properties \emph{and} has been proven to be strongly normalizing.)
One of the goals of \lang, as mentioned, is to fill in this gap
with a consistent sized dependent type theory with all of the desired features.
However, it's missing two properties that all of these type theories do have:
inductive types in the ``correct'' universes
(as we'll see shortly, the type of naturals and well-founded trees
are one universe higher than is conventional),
and the existence of an infinite size.

% TODO: fix manual footnote number
\footnotetext[6]{\label{foot:CICE-consistency} Under the postulate that \CICE is consistent.}

\begin{center}
\mbox{* * *}
\end{center}
\vspace*{-0.5\baselineskip}

\noindent In the upcoming \cref{ch:sized-dep-types}, I describe the syntax and judgements of \lang in detail
and provide example programs in \lang that use sized types.
Next, in \cref{ch:model} I describe \CICE and define the translation from \lang to \CICE.
Following that, in \cref{ch:proofs} I prove various necessary metatheoretical properties
including confluence and subject reduction,
and elaborate on the proof of type preservation and its associated lemmas.
I conclude in \cref{ch:discussion}, discussing some of the shortcomings of \lang,
namely the universe levels of the inductive types and
decreased expressivity arising from removing the infinite size,
as well directions for future investigation.


%---------------------------------------------------------------------
%  Writeup of the improved search of Run II data for single top quark
%  production at DZero.
%  Started: Oct 2006
%  Authors: The Single Top Working Group
%---------------------------------------------------------------------
%
\section{Signal Acceptances}
\label{signal-acceptances}

The signal acceptance is defined as:
$$
\cal{A} = \frac{\cal{B}}{N_{\rm initial}}
\displaystyle \sum_{N_{\rm selected}} \varepsilon_{\rm trigger}
\varepsilon_{\rm corrections} \varepsilon_{\rm TRF}
$$
\noindent where $\cal{B}$ is the branching fraction for the MC
sample, see Table~\ref{mcstats}, $N_{\rm initial}$ is the initial
number of events in each MC sample (also shown in
Table~\ref{mcstats}), $N_{\rm selected}$ is the number of MC events
remaining after selection, and the $\varepsilon$'s are efficiency
correction factors to account for differences between data and MC from
the trigger, particle ID, the $b$-tagging tag-rate functions, and so
forth (see Section~\ref{mc-modeling}).

Table~\ref{acceptances} shows the percentage of each single top quark
signal that remain after selection, and after $b$-tagged jets have
been required. We can compare the acceptances obtained in this
analysis with the published one~\cite{run2-d0-plb}. In that analysis,
we kept 2.6\% of the s-channel events before tagging (with 2--4 jets)
in the electron channel and 2.5\% in the muon channel. In this
analysis, we keep 2.8\% and 2.2\% in the electron and muon channels
respectively (2--4 jets). In the t-channel, in the published analysis
we kept 2.6\% and 2.4\% in the electron and muon channels, and now we
are keeping 2.5\% and 2.0\%. After $b$~tagging, before we kept 1.3\%
of the electron events and 1.3\% of the muon events in the s-channel;
we now keep 1.8\% and 1.4\% respectively. In the t-channel after
$b$~tagging, we kept before 0.9\% in each of the electron and muon
channels. We now keep 1.2\% and 0.9\% of these tagged events.  The
higher acceptances now are from the use of the more efficient neural
network $b$-tagging algorithm, and probably also from the lower
reconstruction threshold for jets.

% The following is commented out until the comparison is updated to
% be for their latest results.
%
%We can also compare these acceptances to those obtained by CDF in
%their most recent analysis. For s-channel and t-channel combined,
%electron and muon channels combined, and events with exactly two jets
%with one or both $b$~tagged, they keep 1.4\% of the expected
%signal. For the same requirements, we also keep 1.4\% of the expected
%signal. In addition we have available to analyze the acceptances in
%the 1, 3, and 4-jets channels, and the untagged 2, 3, and 4-jets
%channels, which CDF have not yet included in their results.

\vspace{0.2in}
\begin{table}[!h!tbp]
\begin{center}
\begin{minipage}{6.5in}
\begin{ruledtabular}
\begin{tabular}{l||ccccc|ccccc}
\multicolumn{11}{c}{\hspace{1in}\underline{Signal Acceptances}}\vspace{0.1in} \\
& \multicolumn{5}{c|}{Electron Channel} & \multicolumn{5}{c}{Muon Channel} \\
                     & 1 jet & 2 jets & 3 jets & 4 jets & 5+ jets
                     & 1 jet & 2 jets & 3 jets & 4 jets & 5 jets \\
\hline
Before $b$ tagging   &        &        &        &        &        &        &        &        &        &        \\
~~$tb$               & 0.55\% & 1.77\% & 0.83\% & 0.23\% & 0.06\% & 0.33\% & 1.36\% & 0.69\% & 0.19\% & 0.05\% \\
~~$tqb$              & 0.52\% & 1.49\% & 0.79\% & 0.25\% & 0.07\% & 0.36\% & 1.17\% & 0.64\% & 0.20\% & 0.05\% \\
Zero $b$-tagged jets &        &        &        &        &        &        &        &        &        &        \\
~~$tb$               & 0.32\% & 0.65\% & 0.31\% & 0.09\% & 0.02\% & 0.18\% & 0.48\% & 0.25\% & 0.07\% & 0.02\% \\
~~$tqb$              & 0.34\% & 0.86\% & 0.41\% & 0.12\% & 0.03\% & 0.23\% & 0.66\% & 0.32\% & 0.09\% & 0.02\% \\
One $b$-tagged jet   &        &        &        &        &        &        &        &        &        &        \\
~~$tb$               & 0.24\% & 0.82\% & 0.39\% & 0.11\% & 0.03\% & 0.15\% & 0.64\% & 0.32\% & 0.09\% & 0.02\% \\
~~$tqb$              & 0.18\% & 0.61\% & 0.34\% & 0.11\% & 0.03\% & 0.13\% & 0.50\% & 0.28\% & 0.09\% & 0.02\% \\
Two $b$-tagged jets  &        &        &        &        &        &        &        &        &        &        \\
~~$tb$               &  ---   & 0.29\% & 0.14\% & 0.04\% & 0.02\% &  ---   & 0.24\% & 0.12\% & 0.03\% & 0.01\% \\
~~$tqb$              &  ---   & 0.02\% & 0.05\% & 0.02\% & 0.01\% &  ---   & 0.01\% & 0.04\% & 0.02\% & 0.01\%
\end{tabular}
\end{ruledtabular}
\vspace{-0.1in}
\caption[acceptances]{Acceptances after selection.}
\label{acceptances}
\end{minipage}
\end{center}
\end{table}