\chapter{Not implemented}
\label{chap:Not implemented}

In this chapter we maintain a list of
features we have chosen not to implement at
the moment, but may add when libzahl matures,
but to a separate library that could be made
to support multiple bignum libraries. Functions
listed herein will only be implemented if it
is shown that it would be overwhelmingly
advantageous. For each feature, a sample
implementation or a mathematical expression
on which you can base your implementation is
included. The sample implementations create
temporary integer references to simplify the
examples. You should try to use dedicated
variables; in case of recursion, a robust
program should store temporary variables on
a stack, so they can be cleaned up if
something happens.

Research problems, like prime factorisation
and discrete logarithms, do not fit in the
scope of bignum libraries % Unless they are extraordinarily bloated with vague mission-scope, like systemd.
and therefore do not fit into libzahl,
and will not be included in this chapter.
Operators and functions that grow so
ridiculously fast that a tiny lookup table
can be constructed to cover all practical
input will also not be included in this
chapter, nor in libzahl.

\vspace{1cm}
\minitoc

\newpage
\section{Extended greatest common divisor}
\label{sec:Extended greatest common divisor}

\begin{alltt}
void
extgcd(z_t bézout_coeff_1, z_t bézout_coeff_2, z_t gcd
       z_t quotient_1, z_t quotient_2, z_t a, z_t b)
\{
#define old_r gcd
#define old_s bézout_coeff_1
#define old_t bézout_coeff_2
#define s quotient_2
#define t quotient_1
    z_t r, q, qs, qt;
    int odd = 0;
    zinit(r), zinit(q), zinit(qs), zinit(qt);
    zset(r, b), zset(old_r, a);
    zseti(s, 0), zseti(old_s, 1);
    zseti(t, 1), zseti(old_t, 0);
    while (!zzero(r)) \{
        odd ^= 1;
        zdivmod(q, old_r, old_r, r), zswap(old_r, r);
        zmul(qs, q, s), zsub(old_s, old_s, qs);
        zmul(qt, q, t), zsub(old_t, old_t, qt);
        zswap(old_s, s), zswap(old_t, t);
    \}
    odd ? abs(s, s) : abs(t, t);
    zfree(r), zfree(q), zfree(qs), zfree(qt);
\}
\end{alltt}

Perhaps you are asking yourself ``wait a minute,
doesn't the extended Euclidean algorithm only
have three outputs if you include the greatest
common divisor, what is this shenanigans?''
No\footnote{Well, technically yes, but it calculates
two values for free in the same ways as division
calculates the remainder for free.}, it has five
outputs, most implementations just ignore two of
them. If this confuses you, or you want to know
more about this, I refer you to Wikipeida.

\newpage
\section{Least common multiple}
\label{sec:Least common multiple}

\( \displaystyle{
    \mbox{lcm}(a, b) = \frac{\lvert a \cdot b \rvert}{\mbox{gcd}(a, b)}
}\)
\vspace{1em}

$\mbox{lcm}(a, b)$ is undefined when $a$ or
$b$ is zero, because division by zero is
undefined. Note however that $\mbox{gcd}(a, b)$
is only zero when both $a$ and $b$ is zero.

\newpage
\section{Modular multiplicative inverse}
\label{sec:Modular multiplicative inverse}

\begin{alltt}
int
modinv(z_t inv, z_t a, z_t m)
\{
    z_t x, _1, _2, _3, gcd, mabs, apos;
    int invertible, aneg = zsignum(a) < 0;
    zinit(x), zinit(_1), zinit(_2), zinit(_3), zinit(gcd);
    *mabs = *m;
    zabs(mabs, mabs);
    if (aneg) \{
        zinit(apos);
        zset(apos, a);
        if (zcmpmag(apos, mabs))
            zmod(apos, apos, mabs);
        zadd(apos, apos, mabs);
    \}
    extgcd(inv, _1, _2, _3, gcd, apos, mabs);
    if ((invertible = !zcmpi(gcd, 1))) \{
        if (zsignum(inv) < 0)
            (zsignum(m) < 0 ? zsub : zadd)(x, x, m);
        zswap(x, inv);
    \}
    if (aneg)
        zfree(apos);
    zfree(x), zfree(_1), zfree(_2), zfree(_3), zfree(gcd);
    return invertible;
\}
\end{alltt}

\newpage
\section{Random prime number generation}
\label{sec:Random prime number generation}

TODO

\newpage
\section{Symbols}
\label{sec:Symbols}

\subsection{Legendre symbol}
\label{sec:Legendre symbol}

\( \displaystyle{
  \left ( \frac{a}{p} \right ) \equiv a^{\frac{p - 1}{2}} ~(\text{Mod}~p),~
  \left ( \frac{a}{p} \right ) \in \{-1,~0,~1\},~
  p \in \textbf{P},~ p > 2
}\)
\vspace{1em}

\noindent
That is, unless $\displaystyle{a^{\frac{p - 1}{2}} \mod p \le 1}$,
$\displaystyle{a^{\frac{p - 1}{2}} \mod p = p - 1}$, so
$\displaystyle{\left ( \frac{a}{p} \right ) = -1}$.

It should be noted that
\( \displaystyle{
  \left ( \frac{a}{p} \right ) =
  \left ( \frac{a ~\text{Mod}~ p}{p} \right ),
}\)
so a compressed lookup table can be used for small $p$.

\subsection{Jacobi symbol}
\label{sec:Jacobi symbol}

\( \displaystyle{
  \left ( \frac{a}{n} \right ) =
  \prod_k \left ( \frac{a}{p_k} \right )^{n_k},
}\)
where $\displaystyle{n = \prod_k p_k^{n_k} > 0}$,
and $p_k \in \textbf{P}$.
\vspace{1em}

Like the Legendre symbol, the Jacobi symbol is $n$-periodic over $a$.
If $n$, is prime, the Jacobi symbol is the Legendre symbol, but
the Jacobi symbol is defined for all odd numbers $n$, where the
Legendre symbol is defined only for odd primes $n$.

Use the following algorithm to calculate the Jacobi symbol:

\vspace{1em}
\hspace{-2.8ex}
\begin{minipage}{\linewidth}
\begin{algorithmic}
    \STATE $a \gets a \mod n$
    \STATE $r \gets \mbox{lsb}~ a$
    \STATE $a \gets a \cdot 2^{-r}$
    \STATE \(\displaystyle{
      r \gets \left \lbrace \begin{array}{rl}
        1 &
          \text{if}~ n \equiv 1, 7 ~(\text{Mod}~ 8)
          ~\text{or}~ r \equiv 0 ~(\text{Mod}~ 2) \\
        -1 & \text{otherwise} \\
      \end{array} \right .
    }\)
    \IF{$a = 1$}
        \RETURN $r$
    \ELSIF{$\gcd(a, n) \neq 1$}
        \RETURN $0$
    \ENDIF
    \STATE $(a, n) = (n, a)$
    \STATE \textbf{start over}
\end{algorithmic}
\end{minipage}

\subsection{Kronecker symbol}
\label{sec:Kronecker symbol}

The Kronecker symbol
$\displaystyle{\left ( \frac{a}{n} \right )}$
is a generalisation of the Jacobi symbol,
where $n$ can be any integer. For positive
odd $n$, the Kronecker symbol is equal to
the Jacobi symbol. For even $n$, the
Kronecker symbol is $2n$-periodic over $a$,
the Kronecker symbol is zero for all
$(a, n)$ with both $a$ and $n$ are even.

\vspace{1em}
\noindent
\( \displaystyle{
    \left ( \frac{a}{2^k \cdot n} \right ) =
    \left ( \frac{a}{n} \right ) \cdot \left ( \frac{a}{2} \right )^k,
}\)
where
\( \displaystyle{
    \left ( \frac{a}{2} \right ) =
    \left \lbrace \begin{array}{rl}
        1  & \text{if}~ a \equiv 1, 7 ~(\text{Mod}~ 8) \\
        -1 & \text{if}~ a \equiv 3, 5 ~(\text{Mod}~ 8) \\
        0  & \text{otherwise}
    \end{array} \right .
}\)

\vspace{1em}
\noindent
\( \displaystyle{
    \left ( \frac{-a}{n} \right ) =
    \left ( \frac{a}{n} \right ) \cdot \left ( \frac{a}{-1} \right ),
}\)
where
\( \displaystyle{
    \left ( \frac{a}{-1} \right ) =
    \left \lbrace \begin{array}{rl}
        1  & \text{if}~ a \ge 0 \\
        -1 & \text{if}~ a < 0
    \end{array} \right .
}\)
\vspace{1em}

\noindent
However, for $n = 0$, the symbol is defined as

\vspace{1em}
\noindent
\( \displaystyle{
    \left ( \frac{a}{0} \right ) =
    \left \lbrace \begin{array}{rl}
        1 & \text{if}~ a = \pm 1 \\
        0 & \text{otherwise.}
    \end{array} \right .
}\)

\subsection{Power residue symbol}
\label{sec:Power residue symbol}

TODO

\subsection{Pochhammer \emph{k}-symbol}
\label{sec:Pochhammer k-symbol}

\( \displaystyle{
    (x)_{n,k} = \prod_{i = 1}^n (x + (i - 1)k)
}\)

\newpage
\section{Logarithm}
\label{sec:Logarithm}

TODO

\newpage
\section{Roots}
\label{sec:Roots}

TODO

\newpage
\section{Modular roots}
\label{sec:Modular roots}

TODO % Square: Cipolla's algorithm, Pocklington's algorithm, Tonelli–Shanks algorithm

\newpage
\section{Combinatorial}
\label{sec:Combinatorial}

\subsection{Factorial}
\label{sec:Factorial}

\( \displaystyle{
    n! = \left \lbrace \begin{array}{ll}
        \displaystyle{\prod_{i = 1}^n i} & \textrm{if}~ n \ge 0 \\
        \textrm{undefined} & \textrm{otherwise}
    \end{array} \right .
}\)
\vspace{1em}

This can be implemented much more efficiently
than using the naïve method, and is a very
important function for many combinatorial
applications, therefore it may be implemented
in the future if the demand is high enough.

An efficient, yet not optimal, implementation
of factorials that about halves the number of
required multiplications compared to the naïve
method can be derived from the observation

\vspace{1em}
\( \displaystyle{
    n! = n!! ~ \lfloor n / 2 \rfloor! ~ 2^{\lfloor n / 2 \rfloor}
}\), $n$ odd.
\vspace{1em}

\noindent
The resulting algorithm can be expressed as

\begin{alltt}
   void
   fact(z_t r, uint64_t n)
   \{
       z_t p, f, two;
       uint64_t *ns, s = 1, i = 1;
       zinit(p), zinit(f), zinit(two);
       zseti(r, 1), zseti(p, 1), zseti(f, n), zseti(two, 2);
       ns = alloca(zbits(f) * sizeof(*ns));
       while (n > 1) \{
           if (n & 1) \{
               ns[i++] = n;
               s += n >>= 1;
           \} else \{
               zmul(r, r, (zsetu(f, n), f));
               n -= 1;
           \}
       \}
       for (zseti(f, 1); i-- > 0; zmul(r, r, p);)
           for (n = ns[i]; zcmpu(f, n); zadd(f, f, two))
               zmul(p, p, f);
       zlsh(r, r, s);
       zfree(two), zfree(f), zfree(p);
   \}
\end{alltt}

\subsection{Subfactorial}
\label{sec:Subfactorial}

\( \displaystyle{
    !n = \left \lbrace \begin{array}{ll}
      n(!(n - 1)) + (-1)^n & \textrm{if}~ n > 0 \\
      1 & \textrm{if}~ n = 0 \\
      \textrm{undefined} & \textrm{otherwise}
    \end{array} \right . =
    n! \sum_{i = 0}^n \frac{(-1)^i}{i!}
}\)

\subsection{Alternating factorial}
\label{sec:Alternating factorial}

\( \displaystyle{
    \mbox{af}(n) = \sum_{i = 1}^n {(-1)^{n - i} i!}
}\)

\subsection{Multifactorial}
\label{sec:Multifactorial}

\( \displaystyle{
    n!^{(k)} = \left \lbrace \begin{array}{ll}
      1 & \textrm{if}~ n = 0 \\
      n & \textrm{if}~ 0 < n \le k \\
      n((n - k)!^{(k)}) & \textrm{if}~ n > k \\
      \textrm{undefined} & \textrm{otherwise}
    \end{array} \right .
}\)

\subsection{Quadruple factorial}
\label{sec:Quadruple factorial}

\( \displaystyle{
    (4n - 2)!^{(4)}
}\)

\subsection{Superfactorial}
\label{sec:Superfactorial}

\( \displaystyle{
    \mbox{sf}(n) = \prod_{k = 1}^n k^{1 + n - k}
}\), undefined for $n < 0$.

\subsection{Hyperfactorial}
\label{sec:Hyperfactorial}

\( \displaystyle{
    H(n) = \prod_{k = 1}^n k^k
}\), undefined for $n < 0$.

\subsection{Raising factorial}
\label{sec:Raising factorial}

\( \displaystyle{
    x^{(n)} = \frac{(x + n - 1)!}{(x - 1)!}
}\), undefined for $n < 0$.

\subsection{Falling factorial}
\label{sec:Falling factorial}

\( \displaystyle{
    (x)_n = \frac{x!}{(x - n)!}
}\), undefined for $n < 0$.

\subsection{Primorial}
\label{sec:Primorial}

\( \displaystyle{
    n\# = \prod_{\lbrace i \in \textbf{P} ~:~ i \le n \rbrace} i
}\)
\vspace{1em}

\noindent
\( \displaystyle{
    p_n\# = \prod_{i \in \textbf{P}_{\pi(n)}} i
}\)

\subsection{Gamma function}
\label{sec:Gamma function}

$\Gamma(n) = (n - 1)!$, undefined for $n \le 0$.

\subsection{K-function}
\label{sec:K-function}

\( \displaystyle{
    K(n) = \left \lbrace \begin{array}{ll}
      \displaystyle{\prod_{i = 1}^{n - 1} i^i}  & \textrm{if}~ n \ge 0 \\
      1 & \textrm{if}~ n = -1 \\
      0 & \textrm{otherwise (result is truncated)}
    \end{array} \right .
}\)

\subsection{Binomial coefficient}
\label{sec:Binomial coefficient}

\( \displaystyle{
    \binom{n}{k} = \frac{n!}{k!(n - k)!}
    = \frac{1}{(n - k)!} \prod_{i = k + 1}^n i
    = \frac{1}{k!} \prod_{i = n - k + 1}^n i
}\)

\subsection{Catalan number}
\label{sec:Catalan number}

\( \displaystyle{
    C_n = \left . \binom{2n}{n} \middle / (n + 1) \right .
}\)

\subsection{Fuss–Catalan number}
\label{sec:Fuss-Catalan number} % not en dash

\( \displaystyle{
    A_m(p, r) = \frac{r}{mp + r} \binom{mp + r}{m}
}\)

\newpage
\section{Fibonacci numbers}
\label{sec:Fibonacci numbers}

Fibonacci numbers can be computed efficiently
using the following algorithm:

\begin{alltt}
   static void
   fib_ll(z_t f, z_t g, z_t n)
   \{
       z_t a, k;
       int odd;
       if (zcmpi(n, 1) <= 0) \{
           zseti(f, !zzero(n));
           zseti(f, zzero(n));
           return;
       \}
       zinit(a), zinit(k);
       zrsh(k, n, 1);
       if (zodd(n)) \{
           odd = zodd(k);
           fib_ll(a, g, k);
           zadd(f, a, a);
           zadd(k, f, g);
           zsub(f, f, g);
           zmul(f, f, k);
           zseti(k, odd ? -2 : +2);
           zadd(f, f, k);
           zadd(g, g, g);
           zadd(g, g, a);
           zmul(g, g, a);
       \} else \{
           fib_ll(g, a, k);
           zadd(f, a, a);
           zadd(f, f, g);
           zmul(f, f, g);
           zsqr(a, a);
           zsqr(g, g);
           zadd(g, a);
       \}
       zfree(k), zfree(a);
   \}
\end{alltt}

\newpage
\begin{alltt}
   void
   fib(z_t f, z_t n)
   \{
       z_t tmp, k;
       zinit(tmp), zinit(k);
       zset(k, n);
       fib_ll(f, tmp, k);
       zfree(k), zfree(tmp);
   \}
\end{alltt}

\noindent
This algorithm is based on the rules

\vspace{1em}
\( \displaystyle{
    F_{2k + 1} = 4F_k^2 - F_{k - 1}^2 + 2(-1)^k = (2F_k + F_{k-1})(2F_k - F_{k-1}) + 2(-1)^k
}\)
\vspace{1em}

\( \displaystyle{
    F_{2k} = F_k \cdot (F_k + 2F_{k - 1})
}\)
\vspace{1em}

\( \displaystyle{
    F_{2k - 1} = F_k^2 + F_{k - 1}^2
}\)
\vspace{1em}

\noindent
Each call to {\tt fib\_ll} returns $F_n$ and $F_{n - 1}$
for any input $n$. $F_{k}$ is only correctly returned
for $k \ge 0$. $F_n$ and $F_{n - 1}$ is used for
calculating $F_{2n}$ or $F_{2n + 1}$. The algorithm
can be sped up with a larger lookup table than one
covering just the base cases. Alternatively, a naïve
calculation could be used for sufficiently small input.

\newpage
\section{Lucas numbers}
\label{sec:Lucas numbers}

Lucas [lyk\textscripta] numbers can be calculated by utilising
{\tt fib\_ll} from \secref{sec:Fibonacci numbers}:

\begin{alltt}
   void
   lucas(z_t l, z_t n)
   \{
       z_t k;
       int odd;
       if (zcmp(n, 1) <= 0) \{
           zset(l, 1 + zzero(n));
           return;
       \}
       zinit(k);
       zrsh(k, n, 1);
       if (zeven(n)) \{
           lucas(l, k);
           zsqr(l, l);
           zseti(k, zodd(k) ? +2 : -2);
           zadd(l, k);
       \} else \{
           odd = zodd(k);
           fib_ll(l, k, k);
           zadd(l, l, l);
           zadd(l, l, k);
           zmul(l, l, k);
           zseti(k, 5);
           zmul(l, l, k);
           zseti(k, odd ? +4 : -4);
           zadd(l, l, k);
       \}
       zfree(k);
   \}
\end{alltt}

\noindent
This algorithm is based on the rules

\vspace{1em}
\( \displaystyle{
    L_{2k} = L_k^2 - 2(-1)^k
}\)
\vspace{1ex}

\( \displaystyle{
    L_{2k + 1} = 5F_{k - 1} \cdot (2F_k + F_{k - 1}) - 4(-1)^k
}\)
\vspace{1em}

\noindent
Alternatively, the function can be implemented
trivially using the rule

\vspace{1em}
\( \displaystyle{
    L_k = F_k + 2F_{k - 1}
}\)

\newpage
\section{Bit operation}
\label{sec:Bit operation unimplemented}

\subsection{Bit scanning}
\label{sec:Bit scanning}

Scanning for the next set or unset bit can be
trivially implemented using {\tt zbtest}. A
more efficient, although not optimally efficient,
implementation would be

\begin{alltt}
   size_t
   bscan(z_t a, size_t whence, int direction, int value)
   \{
       size_t ret;
       z_t t;
       zinit(t);
       value ? zset(t, a) : znot(t, a);
       ret = direction < 0
           ? (ztrunc(t, t, whence + 1), zbits(t) - 1)
           : (zrsh(t, t, whence), zlsb(t) + whence);
       zfree(t);
       return ret;
   \}
\end{alltt}

\subsection{Population count}
\label{sec:Population count}

The following function can be used to compute
the population count, the number of set bits,
in an integer, counting the sign bit:

\begin{alltt}
   size_t
   popcount(z_t a)
   \{
       size_t i, ret = zsignum(a) < 0;
       for (i = 0; i < a->used; i++) \{
           ret += __builtin_popcountll(a->chars[i]);
       \}
       return ret;
   \}
\end{alltt}

\noindent
It requires a compiler extension; if it's not
available, there are other ways to computer the
population count for a word: manually bit-by-bit,
or with a fully unrolled

\begin{alltt}
   int s;
   for (s = 1; s < 64; s <<= 1)
       w = (w >> s) + w;
\end{alltt}

\subsection{Hamming distance}
\label{sec:Hamming distance}

A simple way to compute the Hamming distance,
the number of differing bits between two
numbers is with the function

\begin{alltt}
   size_t
   hammdist(z_t a, z_t b)
   \{
       size_t ret;
       z_t t;
       zinit(t);
       zxor(t, a, b);
       ret = popcount(t);
       zfree(t);
       return ret;
   \}
\end{alltt}

\noindent
The performance of this function could
be improved by comparing character by
character manually using {\tt zxor}.

\newpage
\section{Miscellaneous}
\label{sec:Miscellaneous}

\subsection{Character retrieval}
\label{sec:Character retrieval}

\begin{alltt}
uint64_t
getu(z_t a)
\{
    return zzero(a) ? 0 : a->chars[0];
\}
\end{alltt}

\subsection{Fit test}
\label{sec:Fit test}

Some libraries have functions for testing
whether a big integer is small enough to
fit into an intrinsic type. Since libzahl
does not provide conversion to intrinsic
types this is irrelevant. But additionally,
it can be implemented with a single
one-line macro that does not have any
side-effects.

\begin{alltt}
   #define fits_in(a, type)  (zbits(a) <= 8 * sizeof(type))
   \textcolor{c}{/* \textrm{Just be sure the type is integral.} */}
\end{alltt}

\subsection{Reference duplication}
\label{sec:Reference duplication}

This could be useful for creating duplicates
with modified sign, but only if neither
{\tt r} nor {\tt a} will be modified whilst
both are in use. Because it is unsafe,
fairly simple to create an implementation
with acceptable performance — {\tt *r = *a},
— and probably seldom useful, this has not
been implemented.

\begin{alltt}
   void
   refdup(z_t r, z_t a)
   \{
       \textcolor{c}{/* \textrm{Almost fully optimised, but perfectly portable} *r = *a; */}
       r->sign    = a->sign;
       r->used    = a->used;
       r->alloced = a->alloced;
       r->chars   = a->chars;
   \}
\end{alltt}

\subsection{Variadic initialisation}
\label{sec:Variadic initialisation}

Most bignum libraries have variadic functions
for initialisation and uninitialisation. This
is not available in libzahl, because it is
not useful enough and has performance overhead.
And what's next, support {\tt va\_list},
variadic addition, variadic multiplication,
power towers, set manipulation? Anyone can
implement variadic wrapper for {\tt zinit} and
{\tt zfree} if they really need it. But if
you want to avoid the overhead, you can use
something like this:

\begin{alltt}
   /* \textrm{Call like this:} MANY(zinit, (a), (b), (c)) */
   #define MANY(f, ...)  (_MANY1(f, __VA_ARGS__,,,,,,,,,))

   #define _MANY1(f, a, ...)  (void)f a, _MANY2(f, __VA_ARGS__)
   #define _MANY2(f, a, ...)  (void)f a, _MANY3(f, __VA_ARGS__)
   #define _MANY3(f, a, ...)  (void)f a, _MANY4(f, __VA_ARGS__)
   #define _MANY4(f, a, ...)  (void)f a, _MANY5(f, __VA_ARGS__)
   #define _MANY5(f, a, ...)  (void)f a, _MANY6(f, __VA_ARGS__)
   #define _MANY6(f, a, ...)  (void)f a, _MANY7(f, __VA_ARGS__)
   #define _MANY7(f, a, ...)  (void)f a, _MANY8(f, __VA_ARGS__)
   #define _MANY8(f, a, ...)  (void)f a, _MANY9(f, __VA_ARGS__)
   #define _MANY9(f, a, ...)  (void)f a
\end{alltt}


\input{preamble}
\usepackage{wrapfig}
\usepackage[makeroom]{cancel}

\title{The Quantum Spring}
\author{\small{Apurva Nakade}}
\date{}
\begin{document}
\maketitle
\vspace{-2em}
\epigraph{Not only is the universe stranger than we imagine, it is stranger than we can imagine.}{J.B.S. Haldane}
\vspace{-2em}
\tableofcontents

\section{The Mass-Spring System}
\subsection{The Classical Spring}
A mass-spring system (also called a harmonic oscillator) consists of a point mass $m$ attached to a spring with spring constant $k$. We'll assume that there is no external force or friction. In Newtonian mechanics the laws of motion are given by the equations,
\begin{align*}
	F &= m \dfrac{d^2 x }{dt^2}\\
	F &= -kx
\end{align*}
\begin{wrapfigure}{r}{0.5\textwidth}
		\centering
		\includegraphics[height=1.5cm]{mass-spring}
	\end{wrapfigure}
Combining these we get $\frac {d^2 x }{dt^2} = -\frac{k}{m}x$ which has the solutions
\begin{align}
	\label{eq:classical_solutions}
	x = A \sin (\omega t) + B \cos(\omega t)
\end{align}
where $\omega^2=k/m$ and $A, B$ are constants which depend on the initial conditions. The constant $\omega$ is the frequency of oscillation. We can rewrite this as a conservation of energy equation
\begin{align}
	\label{eq:energy_mass_spring}
	\dfrac{1}{2} \left(\dfrac{p^2}{m} + k x^2\right) = E
\end{align}
where $p = m \frac{dx}{dt}$ is the momentum and $E$ is total energy of the system which is constant.

\begin{ques}
	Show that the solutions \eqref{eq:classical_solutions} satisfy the energy conservation equation \eqref{eq:energy_mass_spring}.
\end{ques}

\subsection{Quantizing a Classical System}
On the microscopic level, this system is seen in a diatomic molecule like $H_2$. If we look at the system from the frame of reference of the center of mass then up to a first approximation the atom behaves like a mass-spring system (plus some rotational motion). One can measure the energy of this mass-spring system and it turns out that the energy is quantized, more specifically the energy of this mass-spring system only takes values of the form
\begin{align*}
	c(n + 1/2)
\end{align*}
where $c$ is a positive real constant that depends on the molecule and $n$ is a non-negative integer!

The Newtonian model on the other hand predicts that we should see a continuous spectrum of possible energy values. As the model does not agree with experiments we need to discard this model and come up with a new model i.e. quantum mechanics. The current model for a quantum mechanical analogue of a classical mechanical system is the following:\\

The entire information about the state of a system is contained in a \textbf{wavefunction} which is simply a time-dependent complex valued function
\begin{align*}
	\psi (x, t)
\end{align*}
Further, we think of these wavefunctions as living in the $\C$-vector space of all complex valued functions.\footnote{As it is stated this is false. We need to impose several analytic conditions on the space of functions for this to make sense. The usual candidate is the $L^2$-space of functions.}\\

In this model, the \emph{observable} quantities like position, momentum, angular momentum, energy etc. are \textbf{linear operators} on this vector space. We'll the denote linear operators as $\hat{-}$;
\begin{align*}
	 \hat{x} &= \mbox{position operator}\\
 \hat{p} &= \mbox{momentum operator}  \\
\hat{E} &= \mbox{energy operator}
\end{align*}

To find equations of motion we replace the observable quantities with the corresponding operators in the energy conservation equation. For the mass-spring system this is Equation \ref{eq:energy_mass_spring} which gives us the \textbf{Schrodinger Equation}

	\begin{align}
		\label{eq:Schrodinger}
		\dfrac{1}{2} \left(\dfrac{\hat{p} \circ \hat{p}}{m} + k \hat{x} \circ \hat{x}\right)\psi = \hat{E} \psi
	\end{align}
where we're solving for $\psi$ (which is a function of $x, t$).

Finally, we need to find the \emph{right} linear operators, this is again a choice we have to make in our model. For the time independent or steady state\footnote{This is saying that no external force is being applied to the system and the system has stabilized into an equilibrium state. For example, standing waves are examples of steady states of the classical waves-on-a-string system.} mass-spring system these are
\begin{align*}
	\hat{x} &= x \cdot (-) \quad(\mbox{ multiplication by } x) \\
	\hat{p} &= -i \hbar \dfrac{d}{d x} \\
		\hat{E} &= \lambda \cdot (-) \quad(\mbox{ multiplication by a fixed positive real number})
\end{align*}
where $i = \sqrt{-1}$ and $\hbar$ is a physical constant called the \textbf{Planck's constant}.\\

\noindent \textbf{Aside: } This is only half the story. Here we're only talking about finding a mathematical model, in particular, a differential equation, for describing the quantum world. There still needs to be an interpretation of this model in terms of physically observable quantities to connect the model to experiments. This in itself is a long and beautiful story which you should explore by yourself.\\

Being mathematicians we'll assume that $m = k = \hbar = 1$ so that the time-independent Schrodinger equation \eqref{eq:Schrodinger} for a mass-spring system becomes
\begin{align*}
	\dfrac{1}{2} \left({\left(-i \dfrac{d}{d x}\right) \circ \left(-i \dfrac{d}{d x}\right)} + k x^2\right)\psi = \lambda \psi \\
	 \dfrac{1}{2} \left(-\dfrac{d^2 \psi}{d x^2} + {x}^2 \psi \right) = \lambda \psi
\end{align*}
Define the \textbf{Schrodinger operator} to be
\begin{align*}
		\hat{H} := \dfrac{1}{2}	\left(- \dfrac{d^2}{d x^2} + {\hat{x}}^2 \right)
\end{align*}
so that we can rewrite the Schrodinger equation simply as
\begin{align*}
	\hat{H} \psi = \lambda \psi
\end{align*}
But notice that the solutions to this are simply the eigenvectors of $\hat{H}$!!!
\begin{prop}
		The solutions to the time-independent Schrodinger equation are precisely the eigenvalues and eigenvectors of the Schrodinger operator.
\end{prop}

\section{Linear Algebra}

\subsection{The Schrodinger Operator}
Thus we've reduced a physics problem to a linear algebra one (yay!). We'll now focus entirely on the Schrodinger operator. The operator $2\hat{H}$  should not be very far from the operator $(-d/dx + x)(d/dx + x)$, more precisely
\begin{align*}
	&\left(-\dfrac{d}{dx} + \hat{x}\right) \circ \left(\dfrac{d}{dx} + \hat{x} \right)\psi \\
	&=\left(-\dfrac{d}{dx} + \hat{x}\right) \circ \left(\dfrac{d \psi}{dx} + x \psi \right) \\
	&= -\dfrac{d}{dx}\left( \dfrac{d \psi}{dx} + x \psi \right) + \hat{x} \left( \dfrac{d \psi}{dx} + x \psi \right) \\
	&= -\dfrac{d^2 \psi}{dx^2} -\dfrac{d}{dx} \left(x \psi \right) + x\dfrac{d \psi}{dx} + x^2 \psi \\
	&= -\dfrac{d^2 \psi}{dx^2} -\psi - \cancel{x\dfrac{d\psi}{dx}} + \cancel{x\dfrac{d \psi}{dx}} + x^2 \psi \\
	&= 2\hat{H} \psi - \psi
\end{align*}

\begin{definition}
	Define the \textbf{creation} operator $\hat{C}$ and \textbf{annihilation} operator $\hat{A}$ as
	\begin{align*}
		\hat C &:= \dfrac{1}{\sqrt{2}}\left(-\dfrac{d}{dx} + \hat{x}\right)
		=\dfrac{1}{\sqrt{2}}\left(-i \hat{p} + \hat{x}\right) \\
			\hat A &:= \dfrac{1}{\sqrt{2}}\left(\dfrac{d}{dx} + \hat{x}\right)
		=\dfrac{1}{\sqrt{2}}\left(i \hat{p} + \hat{x}\right)
	\end{align*}
\end{definition}
\noindent By the above derivation we have
\begin{align*}
	\hat{H} &= \hat{C} \hat{A} + \frac{1}{2}
\end{align*}
The operators $\hat{H}, \hat{C}, \hat{A}$ are the generating elements of an algebra called the \textbf{Weyl algebra} which we'll now analyze.

\subsection{Lie Brackets}
If two operators $\hat{M}$ and $\hat{N}$ commute and if $\psi$ is an eigenvector of $\hat{M}$ with eigenvalue $\lambda$ then
\begin{align*}
	\hat{M} \hat{N} \psi
	&= \hat{N} \hat{M} \psi \\
	&= \lambda \hat{N} \psi
\end{align*}
\begin{prop}
	If $\hat{M}$ and $\hat{N}$ commute and $\psi$ is an eigenvector of $M$ then so is $\hat{N} \psi$ with the same eigenvalue.
\end{prop}

What happens if they don't commute? The notation of Lie (pronounced \emph{lee}) brackets allows us to analyze this systematically.
Lie  brackets measure the failure of commutativity of operators.
\begin{definition}
	For linear operators $\hat{M}, \hat{N}$ on a $\C$-vector space, the \textbf{Lie bracket} is defined as
	\begin{align*}
		[\hat{M}, \hat{N}] := \widehat{M} \circ \widehat{N} - \widehat{N} \circ \widehat{M}
	\end{align*}
\end{definition}

\begin{ques}
	For linear operators $\hat{M}, \hat{N}, \hat{P}$ prove the following identities.
	\begin{enumerate}
		\item $[\hat{M}, \hat{M}] = 0$
		\item $[\hat{M}, \hat{N}] = -[\hat{N}, \hat{M}]$
		\item $[\hat{M}, c \hat{N} + \hat{P}] = c[\hat{M}, \hat{N}] + [\hat{M}, \hat{P}]\quad $ where $c$ is a complex number
		\item $[\hat{M}, [\hat{N}, \hat{P}]] + [\hat{N}, [\hat{P}, \hat{M}]] + [\hat{P}, [\hat{M}, \hat{N}]] = 0$
	\end{enumerate}
	The last identity is called the \textbf{Jacobi identity}.
\end{ques}

Suppose $\psi$ is an eigenvector of a linear operator $\hat{M}$ and let $\hat{N}$ be another linear operator. If we no longer have commutativity then
\begin{align}
	\label{eq:commutator_eigenvalue}
	\begin{split}
		\hat{M} \hat {N} \psi
		&= [\hat{M}, \hat{N}] \psi + \hat{N} \hat{M} \psi \\
		&= [\hat{M}, \hat{N}] \psi + \lambda \hat{N}  \psi
	\end{split}
\end{align}
This is as far as we can get in full generality. We'll now specialize to the operators that are relevant to us. Let us find the Lie brackets.
\begin{align*}
	[\hat{x}, \hat{p}] \psi
	&= \hat{x} \circ \hat{p} (\psi) - \hat{p} \circ \hat{x} (\psi) \\
	&= -i x \dfrac{d \psi}{dx} + i \dfrac{d}{dx}(x \psi) \\
	&= -\cancel{i x \dfrac{d \psi}{dx}} + \cancel{i x\dfrac{d\psi}{dx}} + i \psi \\
	&= i \psi \\
	\Rightarrow [\hat{x}, \hat{p}] = i
\end{align*}
This is the famous non-commutativity relation that leads to the Heisenberg's Uncertainty Principle. For the creation and annihilation operators we get,
\begin{align*}
	[\hat{C}, \hat{A}] \psi
	&= \left[\dfrac{1}{\sqrt{2}}\left(-i \hat{p} + \hat{x}\right), \dfrac{1}{\sqrt{2}}\left(i \hat{p} + \hat{x}\right)\right] \\
	&= \dfrac{1}{2}[-i \hat{p}, \hat{x}] + \dfrac{1}{{2}}[\hat{x},i \hat{p}] \\
	&= \dfrac{1}{{2}}[\hat{x},i \hat{p}] + \dfrac{1}{{2}}[\hat{x},i \hat{p}] \\
	&= i [\hat{x},\hat{p}] \\
	&= -1
\end{align*}

\begin{ques}
	\label{q:commutivity_relations}
	Show that (you'll need to use the Jacobi identity for this problem)
	\begin{align*}
		[\hat{H}, \hat{C}] &= \hat{C} \\
		[\hat{H}, \hat{A}] &= -\hat{A}
\end{align*}
\end{ques}

\noindent If $\psi$ is an eigenvector of $\hat{H}$ with eigenvalue $\lambda$ then using equation \eqref{eq:commutator_eigenvalue} and Question \ref{q:commutivity_relations} we get
\begin{align*}
	\begin{aligned}
		\hat{H} \hat {C} \psi
		&= [\hat{H}, \hat{C}] \psi + \lambda \hat{C}  \psi \\
		&= \hat{C} \psi + \lambda \hat{C}  \psi \\
		&= (\lambda + 1)\hat{C} \psi
	\end{aligned} &&
	 \begin{aligned}
		\hat{H} \hat {A} \psi
		&= [\hat{H}, \hat{A}] \psi + \lambda \hat{A}  \psi \\
		&= -\hat{A} \psi + \lambda \hat{A}  \psi \\
		&= (\lambda - 1)\hat{C} \psi
	\end{aligned}
\end{align*}
Thus we have shown that
\begin{thm}
	\label{thm:shifts}
	If $\psi$ is an eigenvector of $\hat{H}$ with eigenvalue $\lambda$ then so are
	 \footnote{There is a mistake in this theorem. Can you find it?}
	\begin{align*}
		&\hat{C} \psi \mbox{ with eigenvalue } \lambda + 1  \mbox{ and} \\
		&\hat{A} \psi \mbox{ with eigenvalue } \lambda - 1.
	\end{align*}
\end{thm}
This is why the operator $\hat{C}$ and $\hat{A}$ are called creation and annihilation operators, as they create and destroy {energy}. When we're dealing with actual quantum systems, this increase/decrease in energy is realized by an absorption/emission of a mass-less particle like a photon.

\section{Back to Physics}

This is as far as we can get by analyzing just the operators $\hat{H}, \hat{C}, \hat{A}$ abstractly. Going back to physics, we want $\lambda$ to be non-negative as $\lambda$ represents the total energy of the system. But if $\psi$ is an eigenvector with eigenvalue $\lambda$ then so is $\hat{C}^k \psi$ which has eigenvalue $\lambda-k$ and we can make this negative by choosing a large $k$. So if everything we did above is mathematically correct then we're seeing that there are negative energy states for every quantum mass-spring system.

Hmmm.

This is brings us to the mistake in Theorem \ref{thm:shifts}. The vectors $\hat{C} \psi$ and $\hat{A} \psi$ can be eigenvectors only if they are \textbf{non-zero}. Thus we can restate the theorem as
\begin{thm}
	If $\psi$ is an eigenvector of $\hat{H}$ with eigenvalue $\lambda$ then so are
	 \footnote{There is a mistake in this theorem. Can you find it?}
	\begin{align*}
		&\hat{C} \psi \mbox{ with eigenvalue } \lambda + 1  \mbox{ {\bf if $\hat{C} \psi \neq 0$} and} \\
		&\hat{A} \psi \mbox{ with eigenvalue } \lambda - 1 \mbox{ {\bf if $\hat{A} \psi \neq 0$}}.
	\end{align*}
\end{thm}

Thus we cannot use Theorem \ref{thm:shifts} to create eigenvectors with negative eigenvalues if $\hat{A} \psi_0 = 0$. For this eigenvector, the energy equals
\begin{align*}
	\hat{H} \psi_0
	&= (\hat{C} \hat{A} + 1/2) \psi_0 \\
	&= \hat{C} \cancel{\hat{A} \psi_0} + 1/2 \psi_0 \\
	&= \frac{1}{2} \psi_0
\end{align*}
This eigenvector is called the \textbf{ground state}.
Every other eigenvalue is $n + 1/2$ for some positive integer $n$, which corresponds to the eigenvector $\hat{C}^n \psi_0$. This indeed agrees with experiments, and so we can say that this model of quantum mechanics is \emph{not incorrect}.

We can find the ground state explicitly by solving
\begin{align*}
	&\hat{A} \psi = 0 \\
	\Rightarrow\quad &\left( \frac{d}{dx} + x\right) \psi = 0 \\
	\Rightarrow\quad &\frac{d\psi}{dx} + x\psi = 0 \\
	\Rightarrow\quad &\psi = c e^{-x^2/2}
\end{align*}
where $c$ is a constant. This is exactly the \textbf{Gaussian distribution}. The eigenvectors corresponding to higher energies can be obtained by succesively applying the operator $ \hat{C} = -\dfrac{d}{dx} + x$. Combining everything we have so far we get
\begin{mdframed}
	\begin{thm}
		For the quantum mass-spring system \begin{align*}
		\dfrac{1}{2} \left(-\dfrac{d^2 \psi}{d x^2} + {x}^2 \psi \right) = \lambda \psi
	\end{align*}
	The energy $\lambda$ can take values $n + 1/2$ where $n$ is a non-negative integer. The eigenvector corresponding to $n = 0$ is
	\begin{align*}
		\psi_0 = c e^{-x^2/2}
	\end{align*}
	where $c$ is a constant that depends on the initial conditions. The eigenvectors corresponding to $n = k$ is
	\begin{align*}
		\psi_k = \left(-\dfrac{d}{dx} + x\right)^k c e^{-x^2/2}
	\end{align*}
	\end{thm}
\end{mdframed}

\begin{remark}
	Note that the ground state $\psi_0$ has non-zero energy. This is saying that in quantum mechanics a mass-spring system can never be at rest, this is in stark contrast with the classical model. This is a recurring phenomenon in quantum mechanics which is forced by the Heisenberg Uncertainty Principle.
\end{remark}

\begin{ques}
	Explicitly compute the first few eigenvectors $\psi_1, \psi_2, \dots$ etc.
\end{ques}

\begin{ques}
	Remove the assumption $m = k = \hbar = 1$ and restate the above theorem.
\end{ques}

\begin{figure}[H]
		\centering
		\includegraphics[width=0.7\textwidth]{wavefunctions}
		\caption{First few eigenvectors of the quantum mass-spring system. Image from Wikipedia}
	\end{figure}

\subsection{To Summarize}
The above analysis crucially relied on the Lie brackets $[\hat{H},\hat{C}]$ and  $[\hat{H},\hat{A}]$ and as mentioned before these form what is called the Weyl algebra.
The Weyl algebra is related to another structure in mathematics called the \textbf{Heisenberg Lie algebra}.

 For many other quantum mechanical systems, it turns out that the relevant operators are related to other Lie algebras which satisfy similar Lie bracket identities. And thus the analysis of quantum mechanical systems often reduces finding the correct Lie algebra for the system which allows us to write the quantum mechanical operators in terms of simpler operators. For example, the angular momentum operator is related to Lie algebra $\frak{sl}_2(\C)$ the vector space of $2 \times 2$ matrices with trace 0.

Finally, for a large class of Lie algebras it is known that the eigenvalues of operators are a discrete set and thus the quantization of energy levels is a physical manifestation of the representation theory of Lie algebras.

\end{document}


\documentclass[12pt,english]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

% url package
\usepackage[colorlinks=true,
            linkcolor=blue,
            urlcolor=blue,
            anchorcolor = blue,
            citecolor=gray]{hyperref}

% Titling and Author
\title{Latex Example, Equation Cases}
\author{\href{https://fanwangecon.github.io/}{Fan Wang}\thanks{https://fanwangecon.github.io, repository: \href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ}}}
\date{\today}
\begin{document}

\maketitle

\section{Two Cases}

\begin{verbatim}
  x =
  \begin{cases*}
      -x           & if  $x < 0 $  \\
      \phantom{-}x & if  $x\ge 0$
  \end{cases*}
\end{verbatim}

$$
x =
\begin{cases*}
    -x           & if  $x < 0 $  \\
    \phantom{-}x & if  $x\ge 0$
\end{cases*}
$$

\begin{align}
x =
\begin{cases*}
-x           & if  $x < 0 $  \\
\phantom{-}x & if  $x\ge 0$
\end{cases*}
\end{align}

\pagebreak

\section{Two Cases, Same Line}

\begin{verbatim}
  \begin{equation*}
  f(x) = \begin{cases}
               0  & \text{if } x < 0 \\
               1  & \text{if } x \ge 0
         \end{cases} \quad
  g(x) = \begin{cases}
               f(x)+1  & \text{if } x < 0 \\
               f(x)-1  & \text{if } x \ge 0
         \end{cases}
  \end{equation*}
\end{verbatim}

\begin{equation*}
f(x) = \begin{cases}
             0  & \text{if } x < 0 \\
             1  & \text{if } x \ge 0
       \end{cases} \quad
g(x) = \begin{cases}
             f(x)+1  & \text{if } x < 0 \\
             f(x)-1  & \text{if } x \ge 0
       \end{cases}
\end{equation*}

\begin{align}
f(x) = \begin{cases}
             0  & \text{if } x < 0 \\
             1  & \text{if } x \ge 0
       \end{cases} \quad
g(x) = \begin{cases}
             f(x)+1  & \text{if } x < 0 \\
             f(x)-1  & \text{if } x \ge 0
       \end{cases}
\end{align}

case star
\begin{align}
f(x) =
\begin{cases*}
0  & if $x < 0$ \\
1  & if $x \ge 0$
\end{cases*}
\quad
g(x) =
\begin{cases*}
f(x)+1  & if $ x < 0$ \\
f(x)-1  & if $ x \ge 0$
\end{cases*}
\end{align}

\pagebreak

\pagebreak

\section{Cases with Fraction Large Using Array dcases}

Here, we compare the difference between using dcases and cases with fractions.

\subsection{cases}

\begin{align}
f(x) = \begin{cases*}
             \frac{a+b}{c+d}  & \text{if } x < 0 \\
             1  & \text{if } x \ge 0
       \end{cases*}
\end{align}

\subsection{dcases}
Fraction show up larger

\begin{align}
f(x) = \begin{dcases*}
             \frac{a+b}{c+d}  & \text{if } x < 0 \\
             1  & \text{if } x \ge 0
       \end{dcases*}
\end{align}

\end{document}


\documentstyle[11pt,reduce]{article}
\title{{\bf $Z$-Transform Package for {\tt REDUCE}}}
\author{Wolfram Koepf \\ Lisa Temme \\ email: {\tt Koepf@zib.de}}
\date{April 1995 : ZIB Berlin}
\begin{document}
\maketitle
\section{$Z$-Transform}

  The $Z$-Transform of a sequence $\{f_n\}$ is the discrete analogue
  of the Laplace Transform, and
  \[{\cal Z}\{f_n\} = F(z) = \sum^\infty_{n=0} f_nz^{-n}\;.\] \\
  This series converges in the region outside the circle
  $|z|=|z_0|= \limsup\limits_{n \rightarrow \infty} \sqrt[n]{|f_n|}\;.$

\begin{tabbing}

{\bf SYNTAX:}\ \ {\tt ztrans($f_n$, n,  z)}\ \ \ \ \ \ \ \
  \=where $f_n$ is an expression, and $n$,$z$ \\
  \> are identifiers.\\
\end{tabbing}

\section{Inverse $Z$-Transform}
  The calculation of the Laurent coefficients of a regular function
  results in the following inverse formula for the $Z$-Transform:
  \\
  If $F(z)$ is a regular function in the region $|z|> \rho$ then
  $\exists$ a sequence \{$f_n$\} with ${\cal Z} \{f_n\}=F(z)$
  given by
  \[f_n = \frac{1}{2 \pi i}\oint F(z) z^{n-1} dz\]

\begin{tabbing}

{\bf SYNTAX:}\ \ {\tt invztrans($F(z)$, z,  n)}\ \ \ \ \ \ \ \
  \=where $F(z)$ is an expression, \\
  \> and $z$,$n$ are identifiers.
\end{tabbing}

\section{Input for the $Z$-Transform}
\begin{tabbing}
  This pack\=age can compute the \= $Z$-Transforms of the \=following
  list of $f_n$, and \\ certain combinations thereof.\\ \\

\>$1$
\>$e^{\alpha n}$
\>$\frac{1}{(n+k)}$               \\ \\
\>$\frac{1}{n!}$
\>$\frac{1}{(2n)!}$
\>$\frac{1}{(2n+1)!}$             \\ \\
\>$\frac{\sin(\beta n)}{n!}$
\>$\sin(\alpha n+\phi)$
\>$e^{\alpha n} \sin(\beta n)$    \\ \\
\>$\frac{\cos(\beta n)}{n!}$
\>$\cos(\alpha n+\phi)$
\>$e^{\alpha n} \cos(\beta n)$    \\ \\
\>$\frac{\sin(\beta (n+1))}{n+1}$
\>$\sinh(\alpha n+\phi)$
\>$\frac{\cos(\beta (n+1))}{n+1}$ \\ \\
\>$\cosh(\alpha n+\phi)$
\>${n+k \choose m}$\\
\end{tabbing}

\begin{tabbing}
\underline {{\bf Other Combinations}}\= \\ \\

\underline {Linearity}
  \>${\cal Z} \{a f_n+b g_n \} = a{\cal Z} \{f_n\}+b{\cal Z}\{g_n\}$
  \\ \\
\underline {Multiplication by $n$}
  \>${\cal Z} \{n^k \cdot f_n\} = -z \frac{d}{dz} \left({\cal Z}\{n^{k-1} \cdot f_n,n,z\} \right)$
  \\ \\
\underline {Multiplication by $\lambda^n$}
  \>${\cal Z} \{\lambda^n \cdot f_n\}=F \left(\frac{z}{\lambda}\right)$
  \\ \\
\underline {Shift Equation}
  \>${\cal Z} \{f_{n+k}\} =
           z^k \left(F(z) - \sum\limits^{k-1}_{j=0} f_j z^{-j}\right)$
  \\ \\
\underline {Symbolic Sums}

  \> ${\cal Z} \left\{ \sum\limits_{k=0}^{n} f_k \right\} =
                       \frac{z}{z-1} \cdot {\cal Z} \{f_n\}$ \\ \\

  \>${\cal Z} \left\{ \sum\limits_{k=p}^{n+q} f_k \right\}$
  \ \ \ combination of the above \\ \\
  where $k$,$\lambda \in$ {\bf N}$- \{0\}$; and $a$,$b$ are variables
  or fractions; and $p$,$q \in$ {\bf Z} or \\
  are functions of $n$; and $\alpha$, $\beta$ \& $\phi$ are angles
  in radians.
\end{tabbing}

\section{Input for the Inverse $Z$-Transform}
\begin{tabbing}
  This \= package can compute the Inverse \= Z-Transforms of any
  rational function, \\ whose denominator can be factored over
  ${\bf Q}$, in addition to the following list \\ of $F(z)$.\\ \\

\> $\sin \left(\frac{\sin (\beta)}{z} \ \right)
    e^{\left(\frac{\cos (\beta)}{z} \ \right)}$
\> $\cos \left(\frac{\sin (\beta)}{z} \ \right)
    e^{\left(\frac{\cos (\beta)}{z} \ \right)}$ \\ \\
\> $\sqrt{\frac{z}{A}} \sin \left( \sqrt{\frac{z}{A}} \ \right)$
\> $\cos \left( \sqrt{\frac{z}{A}} \ \right)$ \\ \\
\> $\sqrt{\frac{z}{A}} \sinh \left( \sqrt{\frac{z}{A}} \ \right)$
\> $\cosh \left( \sqrt{\frac{z}{A}} \ \right)$ \\ \\
\> $z \ \log \left(\frac{z}{\sqrt{z^2-A z+B}} \ \right)$
\> $z \ \log \left(\frac{\sqrt{z^2+A z+B}}{z} \ \right)$ \\ \\
\> $\arctan \left(\frac{\sin (\beta)}{z+\cos (\beta)} \ \right)$
\\
\end{tabbing}

  where $k$,$\lambda \in$ {\bf N}$ -  \{0\}$ and $A$,$B$ are fractions
  or variables ($B>0$) and $\alpha$,$\beta$, \&  $\phi$ are angles
  in radians.

\section{Application of the $Z$-Transform}
\underline {{\bf Solution of difference equations}}\\

  In the same way that a Laplace Transform can be used to
  solve differential equations, so $Z$-Transforms can be used
  to solve difference equations.\\ \\
  Given a linear difference equation of $k$-th order
\begin{equation}
  f_{n+k} + a_1 f_{n+k-1}+ \ldots + a_k f_n = g_n
\label{eq:1}
\end{equation}

  with initial conditions
  $f_0 = h_0$, $f_1 = h_1$, $\ldots$, $f_{k-1} = h_{k-1}$ (where $h_j$
  are given), it is possible to solve it in the following way.
   If the coefficients $a_1, \ldots , a_k$ are constants, then the
  $Z$-Transform of (\ref{eq:1}) can be calculated using the shift
  equation, and results in a solvable linear equation for
  ${\cal Z} \{f_n\}$. Application of the Inverse $Z$-Transform
  then results in the solution of \ (\ref{eq:1}).\\
  If the coefficients $a_1, \ldots , a_k$ are polynomials in $n$ then
  the $Z$-Transform of (\ref{eq:1}) constitutes a differential
  equation for ${\cal Z} \{f_n\}$. If this differential equation can
  be solved then the Inverse $Z$-Transform once again yields the
  solution of (\ref{eq:1}).
  Some examples of these methods of solution can be found in
  $\S$\ref{sec:Examples}.

\section{EXAMPLES}
\label{sec:Examples}
\underline {{\bf Here are some examples for the $Z$-Transform}}\\
\begin{verbatim}
1: ztrans((-1)^n*n^2,n,z);

    z*( - z + 1)
---------------------
  3      2
 z  + 3*z  + 3*z + 1

2: ztrans(cos(n*omega*t),n,z);

   z*(cos(omega*t) - z)
---------------------------
                     2
 2*cos(omega*t)*z - z  - 1

3: ztrans(cos(b*(n+2))/(n+2),n,z);

                                 z
z*( - cos(b) + log(------------------------------)*z)
                                          2
                    sqrt( - 2*cos(b)*z + z  + 1)

4: ztrans(n*cos(b*n)/factorial(n),n,z);

  cos(b)/z       sin(b)                 sin(b)
 e        *(cos(--------)*cos(b) - sin(--------)*sin(b))
                   z                      z
---------------------------------------------------------
                            z
5: ztrans(sum(1/factorial(k),k,0,n),n,z);

  1/z
 e   *z
--------
 z - 1

6: operator f$

7: ztrans((1+n)^2*f(n),n,z);

                          2
df(ztrans(f(n),n,z),z,2)*z  - df(ztrans(f(n),n,z),z)*z
+ ztrans(f(n),n,z)

\end{verbatim}

\underline {{\bf Here are some examples for the Inverse $Z$-Transform}}
\begin{verbatim}

8: invztrans((z^2-2*z)/(z^2-4*z+1),z,n);

              n       n                n
 (sqrt(3) - 2) *( - 1)  + (sqrt(3) + 2)
-----------------------------------------
                    2

9: invztrans(z/((z-a)*(z-b)),z,n);

  n    n
 a  - b
---------
  a - b

10: invztrans(z/((z-a)*(z-b)*(z-c)),z,n);

  n      n      n      n      n      n
 a *b - a *c - b *a + b *c + c *a - c *b
-----------------------------------------
  2      2        2      2    2        2
 a *b - a *c - a*b  + a*c  + b *c - b*c

11: invztrans(z*log(z/(z-a)),z,n);

  n
 a *a
-------
 n + 1

12: invztrans(e^(1/(a*z)),z,n);

        1
-----------------
  n
 a *factorial(n)

13: invztrans(z*(z-cosh(a))/(z^2-2*z*cosh(a)+1),z,n);

cosh(a*n)

\end{verbatim}

\underline {{\bf Examples: Solutions of Difference Equations}}\\ \\
\begin{tabbing}
{\bf I} \ \ \ \ \ \ \=

  (See \cite{BS}, p.\ 651, Example 1).\\
  \> Consider the \= homogeneous linear difference equation\\ \\
  \>\>  $f_{n+5} - 2 f_{n+3} + 2 f_{n+2} - 3 f_{n+1} + 2 f_{n}=0$\\ \\

  \> with \ initial conditions \ $f_0=0$, $f_1=0$, $f_2=9$, $f_3=-2$,
     $f_4=23$. \  The\\
  \> $Z$-Transform of the left hand side can be written as
     $F(z)=P(z)/Q(z)$ \\
  \> where \ $P(z)=9z^3-2z^2+5z$ \
     and \ $Q(z)=z^5-2z^3+2z^2-3z+2$ \ $=$\\
  \> $(z-1)^2(z+2)(z^2+1)$, \ which can be inverted to give\\ \\

 \>\>  $f_n = 2n + (-2)^n - \cos \frac{\pi}{2}n\;.$ \\ \\

  \> The following REDUCE session shows how the present package can
\\ \> be used to solve the above problem.

\end{tabbing}
\begin{verbatim}
14: operator f$ f(0):=0$ f(1):=0$ f(2):=9$ f(3):=-2$ f(4):=23$

20: equation:=ztrans(f(n+5)-2*f(n+3)+2*f(n+2)-3*f(n+1)+2*f(n),n,z);

                              5                       3
equation := ztrans(f(n),n,z)*z  - 2*ztrans(f(n),n,z)*z

                                   2
             + 2*ztrans(f(n),n,z)*z  - 3*ztrans(f(n),n,z)*z

                                       3      2
             + 2*ztrans(f(n),n,z) - 9*z  + 2*z  - 5*z

21: ztransresult:=solve(equation,ztrans(f(n),n,z));

                                             2
                                       z*(9*z  - 2*z + 5)
ztransresult := {ztrans(f(n),n,z)=----------------------------}
                                    5      3      2
                                   z  - 2*z  + 2*z  - 3*z + 2

22: result:=invztrans(part(first(ztransresult),2),z,n);

                   n    n       n    n
           2*( - 2)  - i *( - 1)  - i  + 4*n
result := -----------------------------------
                          2

\end{verbatim}

\begin{tabbing}
\\ \\
{\bf II} \ \ \ \ \ \ \=

  (See \cite{BS}, p.\ 651, Example 2).\\
  \>    Consider the \= inhom\=ogeneous difference equation:\\ \\
  \>\>  $f_{n+2} - 4 f_{n+1} + 3 f_{n} = 1$\\ \\

  \> with initial conditions $f_0=0$, $f_1=1$. Giving  \\ \\
\>\> $F(z)$\>$ = {\cal Z}\{1\} \left( \frac{1}{z^2-4z+3} + \frac{z}{z^2-4z+3} \right)$\\ \\
\>\>\>       $ = \frac{z}{z-1} \left( \frac{1}{z^2-4z+3} + \frac{z}{z^2-4z+3} \right)$.
\\ \\
  \> The Inverse $Z$-Transform results in the solution\\ \\

\>\>
$f_n = \frac{1}{2} \left( \frac{3^{n+1}-1}{2}-(n+1) \right)$.\\ \\

  \> The following REDUCE session shows how the present package can\\
  \> be used to solve the above problem.

\end{tabbing}
\begin{verbatim}

23: clear(f)$ operator f$ f(0):=0$ f(1):=1$

27: equation:=ztrans(f(n+2)-4*f(n+1)+3*f(n)-1,n,z);

                               3                       2
equation := (ztrans(f(n),n,z)*z  - 5*ztrans(f(n),n,z)*z

                                                           2
    + 7*ztrans(f(n),n,z)*z - 3*ztrans(f(n),n,z) - z )/(z - 1)

28: ztransresult:=solve(equation,ztrans(f(n),n,z));

                                      2
                                     z
result := {ztrans(f(n),n,z)=---------------------}
                              3      2
                             z  - 5*z  + 7*z - 3

29: result:=invztrans(part(first(ztransresult),2),z,n);

              n
           3*3  - 2*n - 3
result := ----------------
                 4
\end{verbatim}

\begin{tabbing}
\\ \\
{\bf III} \ \ \ \ \ \ \=

    Consider the \=following difference equation, which has a
    differential\\
 \> equation for ${\cal Z}\{f_n\}$.\\ \\

 \>\> $(n+1) \cdot f_{n+1}-f_n=0$\\ \\

 \> with initial conditions $f_0=1$, $f_1=1$. It can be solved in REDUCE\\
 \>  using the present package in the following way.\\

\end{tabbing}
\begin{verbatim}
30: clear(f)$ operator f$ f(0):=1$ f(1):=1$

34: equation:=ztrans((n+1)*f(n+1)-f(n),n,z);

                                        2
equation :=  - (df(ztrans(f(n),n,z),z)*z  + ztrans(f(n),n,z))

35: operator tmp;

36: equation:=sub(ztrans(f(n),n,z)=tmp(z),equation);

                              2
equation :=  - (df(tmp(z),z)*z  + tmp(z))

37: load(odesolve);

38: ztransresult:=odesolve(equation,tmp(z),z);

                         1/z
ztransresult := {tmp(z)=e   *arbconst(1)}

39: preresult:=invztrans(part(first(ztransresult),2),z,n);

              arbconst(1)
preresult := --------------
              factorial(n)

40: solve({sub(n=0,preresult)=f(0),sub(n=1,preresult)=f(1)},
arbconst(1));

{arbconst(1)=1}

41: result:=preresult where ws;

                1
result := --------------
           factorial(n)

\end{verbatim}

\begin{thebibliography}{9}
\bibitem{BS} Bronstein, I.N. and Semedjajew, K.A.,
{\it Taschenbuch der Mathematik},
Verlag Harri Deutsch, Thun und Frankfurt(Main),
 1981.\\ISBN 3 87144 492 8.
\end{thebibliography}

\end{document}


\SecDef{multi}{Feistel-like Decomposition based on Finite Field Multiplications}

Similarly to \ChapRef{feistel}, this chapter illustrates the usefulness of the "Jackson Pollock representation" of the LAT of an S-Box. Consider a heatmap of $\LAT{\pi}$ shown in \FigRef{pi_lat}. It looks rather random overall, except several vertical stripes clearly sticking out. This effect is weaker or stronger depending on the colormap chosen for plotting. By a closer inspection it can be observed that the stripes stick out because of the same color appearing mote often than in another columns. In order to strengthen the effect, I define a \emph{column frequency table}.
\begin{definition}
Let $L$ be an $n \times m$ matrix. The \emph{column frequency table} of $L$ is the $n\times m$ matrix $\CF{L}$ over $\ZZ$ given by:
$$
\CF{L}[y,x] \eqdef \pabs{\pset{y' \mid L[y',x] = L[y,x]}}.
$$
\end{definition}

\FigTex{pi_lat.tex}

The column frequency table of the $\LAT{\pi}$ is shown in \FigRef{cf_pi_lat}. The same columns are clearly sticking out as in the LAT of $\pi$. Let $S$ denote their $x$-coordinates:
\begin{multline*}
S = \{
\hex{00},
\hex{1a},
\hex{20},
\hex{3a},
\hex{44},
\hex{5e},
\hex{64},
\hex{7e},\\
\hex{8a},
\hex{90},
\hex{aa},
\hex{b0},
\hex{ce},
\hex{d4},
\hex{ee},
\hex{f4}
\}\subseteq\field{8}.
\end{multline*}
Note that $\hex{00}$ was added in order to complete the set to a linear subspace of $\field{8}$. It follows that we can choose 4 linearly independent coordinates and they will correspond to 4 linearly independent components of $\pi$. By composing $\pi$ with a linear map, the outstanding columns of the $\LAT{\pi}$ can be grouped together. Let $L\in \linbij{8}$ be such that
\begin{align*}
L(\hex{80}) &= \hex{08},~~
L(\hex{40}) = \hex{04},~~
L(\hex{20}) = \hex{02},~~
L(\hex{10}) = \hex{01},\\
L(\hex{08}) &= \hex{8a},~~
L(\hex{04}) = \hex{44},~~
L(\hex{02}) = \hex{20},~~
L(\hex{01}) = \hex{1a}.
\end{align*}
Let $\pi_1 \eqdef L^{\top} \circ \pi$. The LAT of $\pi_1$ is shown in \FigRef{pi1_lat}. According to Proposition~\ref{prelim.prop:linear-lat} from \ChapRef{prelim}, the outstanding columns are grouped on the left. Furthermore, inside these 16 columns we can now observe similarly outstanding rows. Coincidentally, their coordinates form the same linear subspace $S$. In order to group the rows on the top, let $\pi_2 \eqdef L^{\top} \circ \pi \circ \invtop{L}$. The LAT of $\pi_2$ is shown in \FigRef{pi2_lat}.

\FigTex{pi_lat1_2.tex}

\subsection{TU-decomposition}
\Label{sec:tu}

The LAT of $\pi_2$ has interesting artifacts. The special 16 columns now have a visible structure consisting of $16\times16$ squares. More importantly, the topmost square fully consists of zeroes, i.e. $\LAT{\pi_2}(a,b)=0$ for $0 \preceq a,b \preceq \hex{0f}$. These zeroes can be interpreted as follows: if we fix any linear combination of the 4 rightmost input bits to any constant, then any linear combination of the 4 rightmost output bits is balanced. Following this idea, the following multiset property can be verified: for any $c \in \field{4}$,
$$
\Right \pround{\pi_2(X)} = \field{4}, ~\text{where}~X \eqdef \pset{(l, c) \mid l \in \field{4}}.
$$
\Todo{proposition}
In other words, there exists 16 permutations $T_{\hex{0}},\ldots, T_{\hex{f}}$ of $\field{4}$ such that for all $l,r \in \field{4}$
$$\Right(\pi_2(l, r)) = T_{r}(l).$$
Let $U_{\hex{0}},\ldots,U_{\hex{f}}\colon \field{4} \to \field{4}$ be such that $U_{T_r(l)}(r) \eqdef \Left(\pi_2(l,r))$ for all $l,r \in \field{4}$. Then
$$
\pi_2(l,r) = \pround{U_{T_r(l)}(r), T_r(l)}.
$$
The high-level decomposition of $\pi_2$ into $T$ and $U$ is shown in \FigRef{tu} and the look-up tables of $T$ and $U$ are given in \TabRef{tu-lt}. Note that since $\pi_2$ and all $T_i$ are permutations, all $U_i$ must be permutations as well. It can be easily verified from the look-up table of $U$. Due to this bijectivity, $T$ and $U$ can be viewed as mini-block ciphers. Such decomposition into two mini block-ciphers shall be called a \emph{TU-decomposition}. It will prove its usefulness again in \ChapRef{apn}.

\FigTex{tu.tex}

\FigTex{tu-lt.tex}

\begin{remark}
It might seem that the TU-decomposition provides little insight into the structure. Indeed, any 8-bit function can be described by two tables of the same size as $T$ and $U$, for example by considering the left and right halves of the output separately. The only special property that TU-decomposition adds is that each $T_i$ is a permutation (and thus, each $U_i$). This is a very unlikely event that a random permutation has such decomposition, even if extra linear encodings (such as $L$ in the case of $\pi$) are allowed. This property justifies the separation of $T$ and $U$ and their independent analysis.
\end{remark}

The decomposition procedure of $T$ and $U$ are described in \SecRef{t} and \SecRef{u} respectively.

\subimport{}{11u.tex}
\subimport{}{11t.tex}
\subimport{}{12full.tex}


\documentclass[main.tex]{subfiles}
\begin{document}

\marginpar{Monday\\ 2020-12-14, \\ compiled \\ \today}

A general infinitesimal coordinate transformation looks like
%
\begin{align}
x^{\mu } \to x^{\prime \mu } = x^{\mu } - \xi^{\mu }(x)
\,,
\end{align}
%
where both the vector field \(\xi \) and its derivative are infinitesimally small.

A scalar field \(\phi \) will transform trivially, meaning that
%
\begin{align}
\phi' (x') = \phi (x)
\,,
\end{align}
%
while a covariant and a contravariant vector will transform like
%
\begin{align}
V^{\prime }_\mu (x') &= \pdv{x^{\nu }}{x^{\prime \mu }} V_\nu (x)  \\
V^{\prime \mu } (x') &= \pdv{x^{\prime \mu }}{x^{\nu }} V^{\nu }(x)
\,,
\end{align}
%
and tensors with more indices will transform analogously, with a Jacobian for each contravariant index and an inverse Jacobian for each covariant index.

\paragraph{Active approach}

We denote the unperturbed FLRW manifold as \(\mathcal{M}_0\), and the perturbed one as \(\mathcal{M}_\lambda \).
The parameter \(\lambda \) is a bookkeeping tool we can use to keep track of the perturbative order, at the end we will set \(\lambda = 1\).

We denote the map \(\psi _\lambda \) as the one from \(\mathcal{M}_0\) to \(\mathcal{M}_\lambda \), and \(\varphi _\lambda \) as the one going backwards.

% Also, we denote our

Let us fix a coordinate system \(x^{\mu }\) on \(\mathcal{M}_0\), and consider a vector field \(\xi^{\mu }\): then we can define a \textbf{congruence of curves} by
%
\begin{align}
\dv{x^{\mu }}{\lambda } = \xi^{\mu } (\lambda )
\,.
\end{align}

Then, we can define a point \(Q\) which is at a parametric distance \(\lambda \) from \(P\) along these integral curves:
%
\begin{align} \label{eq:infinitesimal-point-transformation-active-approach}
x^{\mu } (Q) = x^{\mu } (P) + \lambda \xi ^{\mu } (x(P)) + \order{\lambda^2}
\,.
\end{align}

This is called an infinitesimal point transformation in the active approach.

\paragraph{Passive approach}

We can also introduce a ``passive approach'' to gauge transformations: the same relation we used can be seen as the one we would get by introducing a new coordinate system \(y^{\mu } (Q)\), such that
%
\begin{align}
y^{\mu } (Q) &= x^{\mu } (P)   \\
&= x^{\mu } (Q) - \lambda \xi^{\mu } (x(P))
\,.
\end{align}

If \(x(P) = x(Q) - \lambda \xi\), this can be expanded as
%
\begin{align}
y^{\mu } (Q) = x^{\mu } (Q) - \lambda \xi^{\mu } (x^{\mu } (Q)) + \order{\lambda^2, \xi^2}
\,.
\end{align}

This is a ``passive coordinate transformation'', since we are simply changing the names we give to the points, in the form
%
\begin{align}
y^{\mu } (\lambda ) = x^{\mu } - \lambda \xi^{\mu } + \order{\lambda^2}
\,,
\end{align}
%
which will become \(y^{\mu } = x^{\mu } - \xi^{\mu }\), a regular coordinate transformation.

Consider a vector field \(Z\) which has components \(Z^{\mu }\) in the \(x\) coordinate system; then we can define a new vector field \(\widetilde{Z}\) which has components \(\widetilde{Z}^{\mu }\) in the \(x\) coordinate system, such that the components \(\widetilde{Z}^{\mu }\) evaluated at the coordinate point \(x^{\mu } (P)\) are equal to the components \(Z^{\prime \mu }\) that the ``old'' vector field \(Z\) has in the \(y\) coordinates.

The relation is
%
\begin{align}
\widetilde{Z}^{\mu } (x (P)) = Z^{\prime \mu } (y (Q))
= \eval{\pdv{y^{\mu }}{x^{\nu }}}_{x(Q)} Z^{\nu } (x(Q))
\,.
\end{align}

In the active approach, instead, we would have related the first term to the third directly.

This provides a transportation law from the point \(Q\) to the point \(P\), in the \emph{same} \(x\) coordinate system.
Looking at the first and last term in the equation is the ``active approach'', looking at the last two terms is the ``passive approach''.

The Jacobian at hand is
%
\begin{align}
\pdv{y^{\mu }}{x^{\nu }} = \delta^{\mu }_{\nu } - \lambda \pdv{\xi^{\mu }}{x^{\nu }} (x (Q))
\,,
\end{align}
%
therefore, Taylor expanding, we get
%
\begin{align}
\widetilde{Z}^{\mu } (x(P)) &= Z^{\mu } (x(Q)) - \lambda \pdv{\xi^{\mu }}{x^{\nu }} Z^{\nu } (x(Q))  \\
&= Z^{\mu } (x(P)) + \pdv{Z^{\mu }}{x^{\nu }} \lambda \xi^{\nu }(x(P))
- \lambda \pdv{\xi^{\mu }}{x^{\nu }} Z^{\nu } x(P)
\marginnote{Using \eqref{eq:infinitesimal-point-transformation-active-approach}.}
\\
&= Z^{\mu } (x(P)) + \lambda \mathscr{L}_\xi Z^{\mu } + \order{\lambda^2}
\,.
\end{align}

This has given us the transformation law for the vector field, in terms of the Lie derivative:
%
\begin{align}
\mathscr{L}_\xi (Z^{\mu }) &= \pdv{Z^{\mu }}{x^{\nu }} \xi^{\nu } - \pdv{\xi^{\mu }}{x^{\nu }} Z^{\nu }  \\
&= (\xi^{\nu } \partial_{\nu }) Z^{\mu } - (Z^{\nu }\partial_\nu ) \xi^{\mu }
\,.
\end{align}

The new \(Z\) is in the \emph{same} coordinates as before. Setting \(\lambda = 1\), we get
%
\begin{align}
\widetilde{Z}^{\mu } = Z^{\mu } + \mathscr{L}_\xi Z^{\mu }
\,.
\end{align}

The effect of a gauge transformation is that the new tensor is equal to the old one plus the Lie derivative (at the \emph{same} coordinate point) of the vector field corresponding to the transformation.
For scalars, we have \(\mathscr{L}_\xi S = S_{, \mu } \xi^{\mu }\); for vectors and tensors we have
%
\begin{align}
\mathscr{L}_\xi V_{\mu } &= V_{\mu , \lambda } \xi^{\lambda } + \xi^{\lambda }_{, \mu } V_{\lambda }
\marginnote{We would instead have a minus on the right if the vector \(V\) was contravariant.}
\\
\mathscr{L}_\xi T_{\mu \nu } &= T_{\mu \nu , \lambda } \xi^{\lambda } + \xi^{\lambda }_{, \mu } T_{\lambda \nu } + \xi^{\lambda }_{, \nu } T_{\mu \lambda }
\,.
\end{align}

We get the same result if we replace the partial derivatives with covariant derivatives, as can be found from a direct calculation, as long as the connection is torsion-free (which is equivalent to the Christoffel symbols' lower indices being symmetric).

If we consider the metric tensor \(T_{\mu \nu } = g_{\mu \nu }\), which is covariantly constant (\(g_{\mu \nu ; \rho } = 0\)) we get
%
\begin{align}
\mathscr{L}_\xi g_{\mu \nu } = g_{\lambda \nu } \xi^{\lambda }_{; \mu } + \xi^{\lambda }_{; \nu } g_{\mu \lambda } = \xi_{\mu ; \nu } + \xi_{\nu ; \mu }
\,.
\end{align}

In two different gauges we can find
%
\begin{align}
\Delta T &= T - T_0  \\
\widetilde{\Delta T} &= \widetilde{T} - T_0
\,,
\end{align}
%
but, using the transformation law for tensors, we know that
%
\begin{align}
\widetilde{T} = T_0 + \widetilde{\Delta T}  &= T + \mathscr{L}_\xi T = T_0 + \Delta T + \mathscr{L}_\xi T  \\
\widetilde{\Delta T} &= \Delta T + \mathscr{L}_\xi T
\,,
\end{align}
%
at least at linear order. At this order, however, we can also substitute the Lie derivative of \(T\) with that of \(T_0 \):
%
\boxalign{
\begin{align}
\widetilde{\Delta T} = \Delta T + \mathscr{L}_\xi T_0
\,.
\end{align}}

This is the crux of the gauge problem: the quantity \(\Delta T\) is gauge dependent.

\subsection{Cosmological perturbations}

We start from the background FLRW metric:
%
\begin{align}
\dd{s^2} &= g_{\mu \nu }^{(0)} \dd{x^{\mu }} \dd{x^{\nu }}  \\
&= a^2(\eta ) \qty[- \dd{\eta^2} + \dd{x^2} + \dd{y^2} + \dd{z^2}]
\,,
\end{align}
%
where, as usual, \(\eta \) is the conformal time, defined by \(\dd{\eta } = \dd{t} / a(t)\).

The perturbed metric reads
%
\begin{align}
\dd{s^2} &= g_{\mu \nu } \dd{x^{\mu }} \dd{x^{\nu }}  \\
g_{00} &= - a^2(\eta ) \qty[1 + 2 \sum _{r=1}^{\infty } \frac{1}{r!} \psi^{(r)} (\vec{x}, \eta )]  \\
g_{0i } = g_{i0} &= a^2(\eta ) \sum _{r=1}^{\infty } \frac{1}{r!} \omega_{i}^{(r)} (\vec{x}, \eta )  \\
g_{ij } &= a^2(\eta ) \qty( \qty[1 - 2 \sum _{r=1}^{\infty } \frac{1}{r!} \phi^{(r)} (\vec{x}, \eta )] \delta_{ij} + \sum _{r=1}^{\infty } \frac{1}{r! } \chi_{ij}^{(r)} (\vec{x}, \eta ))
\,,
\end{align}
%
where \(\psi\) is called the \emph{lapse function}, \(\omega_{i} \) is called the \emph{shift function}, while we take \(\chi_{ij}\) to be a \emph{traceless} perturbation: \(\chi^{i}_{i} = 0\).

\end{document}


\documentclass[gr-notes.tex]{subfiles}

\begin{document}

\setcounter{chapter}{2}

\chapter{Tensor analysis in special relativity}

\setcounter{section}{2}

\section{The $\binom{0}{1}$ tensors: one-forms}

The symbol $\tilde{}$ is used to denote a one-form, as $\vec{}$ is used to denote a vector. So $\tilde{p}$ is a one-form, or a type $\binom{0}{1}$ tensor.

\subsection*{Normal one-forms}

Let $\mathcal{S}$ be some surface.

$\forall \vec{V}$ tangent to $\mathcal{S}$, $\tilde{p}(\vec{V}) = 0 \implies \tilde{p}$ is normal to $\mathcal{S}$.

Furthermore, if $\mathcal{S}$ is a \emph{closed} surface \& $\tilde{p}$ is normal to $\mathcal{S}$ \& $\forall \vec{U}$ pointing outwards from $\mathcal{S}$, $\tilde{p}(\vec{U}) > 0 \implies \tilde{p}$ is an outward normal one-form.

\setcounter{section}{4}

\section{Metric as a mapping of vectors into one-forms}

\subsection*{Normal vectors and unit normal one-forms}

$\vec{V}$ is normal to a surface if $\tilde{V}$ is normal to the surface. They are said to be \emph{unit normal} if their magnitude is $\pm 1$, so $\vec{V}^2 = \tilde{V}^2 = \pm 1$.

\begin{itemize}
\item A time-like unit normal has magnitude $-1$
\item A space-like unit normal has magnitude $+1$
\item A null normal cannot be a unit normal, because $\vec{V}^2 = \tilde{V}^2 = 0$
\end{itemize}

\setcounter{section}{9}

\section{Exercises}

\textbf{3}

(a)
\begin{align*}
  \tilde{p}(A^\alpha \vec{e}_\alpha) &=
  A^\alpha \tilde{p}(\vec{e}_\alpha) =
  \tilde{p}(A^0 \vec{e}_0 + A^1 \vec{e}_1 + A^2 \vec{e}_2 + A^3 \vec{e}_3)
  \\ &=
  A^0 \tilde{p}(\vec{e}_0) + A^1 \tilde{p}(\vec{e}_1 +
  A^2 \tilde{p}(\vec{e}_2) + A^3 \tilde{p}(\vec{e}_3 =
  A^\alpha \tilde{p}(\vec{e}_\alpha) = A^\alpha p_\alpha \in \mathbb{R}
\end{align*}

(b)

\begin{align*}
  \tilde{p} &\underset{\obs}{\to} (-1, 1, 2, 0)
  \\
  \vec{A}   &\underset{\obs}{\to} (2, 1, 0, -1)
  \\
  \vec{B}   &\underset{\obs}{\to} (0, 2, 0, 0)
\end{align*}

\begin{align*}
  \tilde{p}(\vec{A}) &=
  -2 + 1 + 0 + 0 = -1
  \\
  \tilde{p}(\vec{B}) &=
  0 + 2 + 0 + 0 = 2
  \\
  \tilde{p}(\vec{A} - 3 \vec{B}) &=
  \tilde{p}(\vec{A}) - 3 \tilde{p}(\vec{B}) =
  -1 - 3 \cdot 2 = -7
\end{align*}

\textbf{4}
Given the following vectors
\begin{align*}
  \vec{A} & \underset{\obs}{\to} ( 2, 1, 1, 0) &
  \vec{B} & \underset{\obs}{\to} ( 1, 2, 0, 0) \\
  \vec{C} & \underset{\obs}{\to} ( 0, 0, 1, 1) &
  \vec{D} & \underset{\obs}{\to} (-3, 2, 0, 0)
\end{align*}

(Note that all parts were done with the assistance of \texttt{numpy}.)

(a) Show that they are linearly independent.

We do this by constructing a matrix, $\vb{X}$, whose columns correspond to the four vectors. If the determinant of $\vb{X}$ is non-zero, then that means the vectors are linearly independent.
%
\begin{displaymath}
  \det(\vb{X}) =
  \det \mqty(2 &  1 &  0 & -3 \\
             1 &  2 &  0 &  2 \\
             1 &  0 &  1 &  0 \\
             0 &  0 &  1 &  0) =
  -8
\end{displaymath}

(b) Find the components of $\tilde{p}$ if
%
\begin{displaymath}
  \tilde{p}(\vec{A}) =  1, \quad
  \tilde{p}(\vec{B}) = -1, \quad
  \tilde{p}(\vec{C}) = -1, \quad
  \tilde{p}(\vec{D}) =  0
\end{displaymath}

We do this by observing that $\tilde{p} = A^\alpha p_\alpha$, and so we have a system of four equations, which we can write in matrix form as
%
\begin{align*}
  \mqty( \vec{A} \\ \vec{B} \\ \vec{C} \\ \vec{D} ) \tilde{p} &=
  \mqty( 1 \\ -1 \\ -1 \\ 0 )
  \\ \implies
  \tilde{p} &=
  \mqty( \vec{A} \\ \vec{B} \\ \vec{C} \\ \vec{D} )^{-1}
  \mqty( 1 \\ -1 \\ -1 \\ 0 )
  \\ &=
  \mqty( -\frac{1}{4} \\ -\frac{3}{8} \\ +\frac{15}{8} \\ -\frac{23}{8} ).
\end{align*}

(c) Find $\tilde{p}(\vec{E})$, where $\vec{E} \to_\obs (1, 1, 0, 0)$.

\begin{displaymath}
  \tilde{p}(\vec{E}) = p_\alpha E^\alpha = -\frac{5}{8}
\end{displaymath}

(d) Determine whether $\tilde{p}$, $\tilde{q}$, $\tilde{r}$, and $\tilde{s}$ are linearly independent.

We do this by first setting up a system of equations for each of $\tilde{q}$, $\tilde{r}$, and $\tilde{s}$, as was done for $\tilde{p}$, and solving. I will refer to the matrix whose rows were $\vec{A}$, $\vec{B}$, $\vec{C}$, and $\vec{D}$ as $\vb{X}$.
%
\begin{align*}
  \vb{X} \tilde{q} &= \mqty( +0 \\ +0 \\ +1 \\ -1 ) &
  \vb{X} \tilde{r} &= \mqty( +2 \\ +0 \\ +0 \\ +0 ) &
  \vb{X} \tilde{s} &= \mqty( -1 \\ -1 \\ +0 \\ +0 )
  \\
  \tilde{q} &=
  \mqty( +\frac{1}{4} \\ -\frac{1}{8} \\ -\frac{3}{8} \\ +\frac{11}{8} ) &
  \tilde{r} &=
  \mqty( +0 \\ +0 \\ +2 \\ +2 ) &
  \tilde{s} &=
  \mqty( -\frac{1}{4} \\ -\frac{3}{8} \\ -\frac{1}{8} \\ +\frac{1}{8} )
\end{align*}
%
Now if the matrix whose columns are comprised of $\tilde{p}$, $\tilde{q}$, $\tilde{r}$, and $\tilde{s}$ has a non-zero determinant, then the four covectors must be linearly independent.
%
\begin{displaymath}
  \det \mqty( \tilde{p} & \tilde{q} & \tilde{r} & \tilde{s} ) = \frac{1}{4},
\end{displaymath}
%
and so they are indeed linearly independent.

\textbf{6}

(a) Show that $\tilde{p} \neq \tilde{p}(\vec{e}_\alpha) \tilde{\lambda}^\alpha$ for arbitrary $\tilde{p}$.

Let us choose $\tilde{p} \to_\obs (0, 1, e, \pi)$, as a counter-example.
%
\begin{align*}
  p_\alpha \tilde{\lambda}^\alpha &\underset{\obs}{\to}
  0 \cdot (1, 1, 0, 0) +
  1 \cdot (1, -1, 0, 0) +
  e \cdot (0, 0, 1, -1) +
  \pi \cdot (0, 0, 1, 1)
  \\ &\underset{\obs}{\to}
  (1, -1, e+\pi, 0)
  \underset{\obs}{\cancel\to}
  \tilde{p}
\end{align*}

(b) $\tilde{p} \to_\obs (1, 1, 1, 1)$. Find $l_\alpha$ such that
%
\begin{displaymath}
  \tilde{p} = l_\alpha \tilde{\lambda}^\alpha
\end{displaymath}

We may do this with a simple matrix inversion. We define $\vb\Lambda$ to be the matrix whose rows are formed by $\tilde{\lambda}^\alpha$.
%
\begin{displaymath}
  \vb\Lambda l = p \implies
  l = \vb\Lambda^{-1} p =
  \mqty( 1 \\ 0 \\ 1 \\ 0 )
\end{displaymath}

\textbf{8}
Draw the basis one-forms $\tilde{\dd}t$ and $\tilde{\dd}x$ of frame $\obs$.

They are
%
\begin{align*}
  \tilde{\dd}t &\underset{\obs}{\to} (1, 0, 0, 0), \\
  \tilde{\dd}x &\underset{\obs}{\to} (0, 1, 0, 0),
\end{align*}
%
and they are shown in Figure \ref{fig:ch3-problem-8}.

\begin{figure}[h]
  \centering
  \includegraphics[width=0.75\textwidth]{img/ch3_problem_8}
  \caption{Problem 8: Basis one-forms of $\obs$. $\tilde{\dd}t$ is given in blue and $\tilde{\dd}x$ in red.}
  \label{fig:ch3-problem-8}
\end{figure}

\textbf{9}
At the points $\mathcal{P}$ and $\mathcal{Q}$, estimate the components of the gradient $\tilde{\dd}T$.

Recall that $\tilde{\dd}T \to_\obs \qty(\pdv{T}{x}, \pdv{T}{y})$, and so $\Delta T = \tilde{\dd}T_\alpha x^\alpha = \tilde{\dd}T_x \Delta x + \tilde{\dd}T_y \Delta y$.

Now if we move only in the $x$ direction from one of the points, we move some distance $\Delta x$, change our temperature by $\Delta t$, and $\Delta y = 0$. Likewise for a movement in the $y$ direction. Thus we can say
%
\begin{align*}
  \Delta T &= \tilde{\dd}T_x \Delta x &
  \Delta T &= \tilde{\dd}T_y \Delta y
  \\
  \tilde{\dd}T_x &= \frac{\Delta T}{\Delta x} &
  \tilde{\dd}T_y &= \frac{\Delta T}{\Delta y}
\end{align*}
%
In Figure \ref{fig:ch3-problem-9}, from $\mathcal{P}$ I move a distance $\Delta x = 0.5$, which causes a temperature change of $\Delta T = -7$, giving $\tilde{\dd}T_x = -14$. Then I move a distance $\Delta y = 0.5$ and get the same temperature change of $\Delta T = -7$, and so I conclude that at point $\mathcal{P}$, $\tilde{\dd}T \to_\obs (-14, -14)$.

At $\mathcal{Q}$, we are in a flat region where $T = 0$. If we move any non-zero distance $\Delta x$ or $\Delta y$, so long as it does not cross the $T = 0$ isotherm, we have a $\Delta T = 0$, and thus $\tilde{\dd}Tp \to_\obs (0, 0)$.

\begin{figure}[h]
  \centering
  \includegraphics[width=0.75\textwidth]{img/ch3_problem_9}
  \caption{Problem 9: Isotherms.}
  \label{fig:ch3-problem-9}
\end{figure}

\textbf{13}
Prove that $\tilde{\dd}f$ is normal to surfaces of constant $f$.

If we move some small distance $\Delta x^\alpha = \epsilon$, then there will be no change in the value of $f$, and thus we can say $\pdv*{f}{x^\alpha} = 0$, so
%
\begin{displaymath}
  \tilde{\dd}f =
  \pdv{f}{x^\alpha} \tilde{\dd}x^\alpha =
  0 \tilde{\dd}x^\alpha =
  0.
\end{displaymath}
%
Since $\tilde{\dd}f$ is defined to be normal to a surface if it is zero on every tangent vector, we have shown that $\tilde{\dd}f$ is normal to any surface of constant $f$.

\textbf{14}

\begin{align*}
  \tilde{p} &\underset{\obs}{\to} ( 1, 1, 0, 0) &
  \tilde{q} &\underset{\obs}{\to} (-1, 0, 1, 0)
\end{align*}

Prove by giving two vectors $\vec{A}$ and $\vec{B}$ as arguments that $\tilde{p} \otimes \tilde{q} \neq \tilde{q} \otimes \tilde{p}$. Then find the components of $\tilde{p} \otimes \tilde{q}$.

\begin{align*}
  (\tilde{p} \otimes \tilde{q})(\vec{A}, \vec{B}) &=
  \tilde{p}(\vec{A}) \tilde{q}(\vec{B}) =
  A^\alpha p_\alpha B^\beta q_\beta =
  (A^0 + A^1) (-B^0 + B^2),
  \\ &=
  -A^0 B^0 + A^0 B^2 - A^1 B^0 + A^1 B^2
  \\
  (\tilde{q} \otimes \tilde{p})(\vec{A}, \vec{B}) &=
  \tilde{q}(\vec{A}) \tilde{p}(\vec{B}) =
  A^\alpha q_\alpha B^\beta p_\beta =
  (-A^0 + A^2) (B^0 + B^1)
  \\ &=
  -A^0 B^0 - A^0 B^1 + A^2 B^0 + A^2 B^1,
\end{align*}
%
And so we see that $\otimes$ is not commutative.

The components of the outer product of two tensors are given by the products of the components of the individual tensors. Thus we can write the components as a $4 \times 4$ matrix.
%
\begin{displaymath}
  (\tilde{p} \otimes \tilde{q})_{\alpha\beta} =
  p_\alpha q_\beta =
  \mqty(-1 &  0 &  1 &  0 \\
        -1 &  0 &  1 &  0 \\
         0 &  0 &  0 &  0 \\
         0 &  0 &  0 &  0)
\end{displaymath}

\textbf{18}

(a)
Find the one-forms mapped by $\vb{g}$ from
%
\begin{align*}
  \vec{A} &\underset{\obs}{\to} ( 1,  0, -1,  0), &
  \vec{B} &\underset{\obs}{\to} ( 0,  1,  1,  0), \\
  \vec{C} &\underset{\obs}{\to} (-1,  0, -1,  0), &
  \vec{D} &\underset{\obs}{\to} ( 0,  0,  1,  1).
\end{align*}

In general,
%
\begin{displaymath}
  \vec{V} \underset{\obs}{\to} (V^0, V^1, V^2, V^3) \implies
  \tilde{V} =
  \vb{g} \vec{V} \underset{\obs}{\to} (-V^0, V^1, V^2, V^3),
\end{displaymath}
%
and so
%
\begin{align*}
  \tilde{A} &\underset{\obs}{\to} (-1,  0, -1,  0), &
  \tilde{B} &\underset{\obs}{\to} ( 0,  1,  1,  0), \\
  \tilde{C} &\underset{\obs}{\to} ( 1,  0, -1,  0), &
  \tilde{D} &\underset{\obs}{\to} ( 0,  0,  1,  1).
\end{align*}

(b)
Find the vectors mapped by $\vb{g}$ from
%
\begin{align*}
  \tilde{p} &\underset{\obs}{\to} ( 3,  0, -1, -1), &
  \tilde{q} &\underset{\obs}{\to} ( 1, -1,  1,  1), \\
  \tilde{r} &\underset{\obs}{\to} ( 0, -5, -1,  0), &
  \tilde{s} &\underset{\obs}{\to} (-2,  1,  0,  0).
\end{align*}
%
By using the inverse tensor in reverse, we have the same effect as before, of negating the first component
%
\begin{align*}
  \vec{p} &\underset{\obs}{\to} (-3,  0, -1, -1), &
  \vec{q} &\underset{\obs}{\to} (-1, -1,  1,  1), \\
  \vec{r} &\underset{\obs}{\to} ( 0, -5, -1,  0), &
  \vec{s} &\underset{\obs}{\to} ( 2,  1,  0,  0).
\end{align*}

\textbf{20}

In Euclidean 3-space, vectors and covectors are usually treated as the same, because they transform the same. We will now prove this.

(a)
Show that $A^{\bar\alpha} = \tensor{\Lambda}{^{\bar\alpha}_\beta} A^\beta$ and $P_{\bar\beta} = \tensor{\Lambda}{^{\alpha}_{\bar\beta}} P_\alpha$ are the same transformations if $\{ \tensor{\Lambda}{^{\alpha}_{\bar\beta}} \}$ is equal to the transpose of its inverse.

We can write that last statement as
%
\begin{displaymath}
  \tensor{\Lambda}{^{\alpha}_{\bar\beta}} =
  ((\tensor{\Lambda}{^{\alpha}_{\bar\beta}})^{-1})^T
\end{displaymath}
%
and we know that
%
\begin{displaymath}
  (\tensor{\Lambda}{^{\alpha}_{\bar\beta}})^{-1} =
  \tensor{\Lambda}{^{\bar\beta}_{\alpha}},
\end{displaymath}
%
and also we know that the Lorentz transformation is symmetric, and so
%
\begin{displaymath}
  (\tensor{\Lambda}{^{\bar\beta}_{\alpha}})^T =
  \tensor{\Lambda}{^{\bar\beta}_{\alpha}},
\end{displaymath}
%
which leads us to conclude that $\tensor{\Lambda}{^{\alpha}_{\bar\beta}} = \tensor{\Lambda}{^{\bar\beta}_{\alpha}}$, meaning the two transformations are the same.

(b)
The metric has components $\{ \delta_{ij} \}$. Prove that transformations between Cartesian coordinate systems must satisfy
\begin{displaymath}
  \delta_{\bar{i}\bar{j}} =
  \tensor{\Lambda}{^k_{\bar{i}}}
  \tensor{\Lambda}{^l_{\bar{j}}}
  \delta_{kl},
\end{displaymath}
and that this implies that $\tensor{\Lambda}{^k_{\bar{i}}}$ is an orthogonal matrix.

\begin{displaymath}
  \delta_{\bar{i}\bar{j}} =
  \vb{g}(\vec{e}_{\bar{i}}, \vec{e}_{\bar{j}}) =
  \vb{g}(\tensor{\Lambda}{^k_{\bar{i}}} \vec{e}_k,
         \tensor{\Lambda}{^l_{\bar{j}}} \vec{e}_j) =
  \tensor{\Lambda}{^k_{\bar{i}}}
  \tensor{\Lambda}{^l_{\bar{j}}}
  \vb{g}(\vec{e}_k, \vec{e}_j) =
  \tensor{\Lambda}{^k_{\bar{i}}}
  \tensor{\Lambda}{^l_{\bar{j}}}
  \delta_{kl}
\end{displaymath}

\textbf{Now show it is orthogonal}

\textbf{21}

(a) A region of the $t$--$x$ plane is bounded by lines $t=0$, $t=1$, $x=0$, and $x=1$. Within the plane, find the unit outward normal 1-forms and their vectors for each boundary line.

I define unit outward normals as follows:

Let $\mathcal{S}$ be a closed surface. If, for each $\vec{V}$ tangent to $\mathcal{S}$, we have $\tilde{p}(\vec{V}) = 0$, then $\tilde{p}$ is normal to $\mathcal{S}$.

In addition, if, for each $\vec{U}$ which points outwards from the surface, we have $\tilde{p}(\vec{U}) > 0$, then $\tilde{p}$ is an outward normal.

Furthermore, if $\tilde{p}^2 = \pm 1$, then it is a unit outward normal.

For the problem at hand, I define the region inside the four lines to be \emph{Inside}, and the region outside to be \emph{Outside}. For each of the four lines, I draw a vector $\vec{V}$ tangent (parallel) to the line, and $\vec{U}$ pointing outwards (See Figure \ref{fig:ch3-problem-21a}).

It helps to look at $t = 0$ and $t = 1$ together, and likewise for $x$, so I will start with $t$. We start with an arbitrary $\tilde{p} \to_\obs (p_0, p_1)$, and $\vec{V} \to_\obs (0, V^1)$, where $V^1 \neq 0$.
\begin{displaymath}
  \tilde{p}(\vec{V}) =
  p_0 \cdot 0 + p_1 V^1 = 0
  \implies
  p_1 = 0,
\end{displaymath}
so $\tilde{p} \to_\obs (p_0, 0)$ is a normal 1-form to both lines. Now we find the corresponding \emph{unit} normal, by taking
\begin{displaymath}
  \tilde{p}^2 = \pm 1 = -(p_0)^2 \implies
  \tilde{p}^2 = -1 \ \& \ p_0 = \pm 1.
\end{displaymath}

Whether we choose $p_0$ to be positive or negative now depends on the line we are looking at, and which direction is outward. For $t = 0$, we have a vector $\vec{U} = (-U^0, U^1)$, where $U^0 > 0$.
\begin{displaymath}
  \tilde{p}(\vec{U}) =
  p_0 (-U^0) + 0 \cdot U^1 > 0
  \implies
  -p_0 U^0 > 0
  \implies
  p_0 < 0,
\end{displaymath}
so for $t = 0$ we have $\tilde{p} \to_\obs (-1, 0)$, and likewise for $t = 1$ we have $\tilde{p} \to_\obs (1, 0)$. To get the associated \emph{vectors}, we apply the metric $\eta^{\alpha\beta}$, giving us $\vec{p} \to_\obs (1, 0)$ for $t = 0$ and $\vec{p} \to_\obs (-1, 0)$ for $t = 1$.

For $x = 0$ and $x = 1$, we instead have $\vec{V} \to_\obs (V^0, 0)$, and following the same steps as before, we conclude that: for $x = 0$, $\tilde{p} \to_\obs (0, -1)$, $\vec{p} \to_\obs (0, -1)$, and for $x = 1$, $\tilde{p} \to_\obs (0, 1)$, $\vec{p} \to_\obs (0, 1)$.

\begin{figure}[h]
  \centering

  \caption{Problem 21.a}
  \label{fig:ch3-problem-21a}
\end{figure}

(b)
Let another region be bounded by the set of points $\{ (1,0),(1,1),(2,1) \}$. Find an outward normal for the null boundary and the associated vector.

\textbf{23}

(a)
Prove that the set of all $\binom{M}{N}$ tensors forms a vector space, $V$.

Let $T$ be the set of all $\binom{M}{N}$ tensors, $\vb{s}, \vb{p}, \vb{q} \in T$, $\vec{A} \in \mathbb{R}^n$, and $\alpha \in \mathbb{R}$. For $T$ to be a vector space, we must define the operations of addition, and scalar multiplication (amongst others).

\textbf{Addition:}
\begin{displaymath}
  \vb{s} = \vb{p} + \vb{q} \implies
  \vb{s}(\vec{A}) = \vb{p}(\vec{A}) + \vb{q}(\vec{A})
\end{displaymath}

\textbf{Scalar Multiplication:}
\begin{displaymath}
  \vb{r} = \alpha \vb{p} \implies
  \vb{r}(\vec{A}) = \alpha \vb{p}(\vec{A})
\end{displaymath}

(b)

Prove that a basis for $T$ is
\begin{displaymath}
  \{ \vec{e}_\alpha \otimes \ldots \otimes \vec{e}_\gamma
     \otimes
     \tilde{\omega}^\mu \otimes \ldots \otimes \tilde{\omega}^\lambda \}
\end{displaymath}

\textbf{Still working on it}

\textbf{24}
Given:
\begin{displaymath}
  M^{\alpha\beta} \to
  \mqty(
     0 &  1 &  0 &  0 \\
     1 & -1 &  0 &  2 \\
     2 &  0 &  0 &  1 \\
     1 &  0 & -2 &  0
  )
\end{displaymath}

(a)
Find:

(i)
\begin{displaymath}
  M^{(\alpha\beta)} \to
  \mqty(
    0 & 1 & 1 & \frac{1}{2} \\
    1 & -1 & 0 & 1 \\
    1 & 0 & 0 & -\frac{1}{2} \\
    \frac{1}{2} & 1 & -\frac{1}{2} & 0
  );
  \quad
  M^{[\alpha\beta]} \to
  \mqty(
    0 & 0 & -1 & -\frac{1}{2} \\
    0 & 0 & 0 & 1 \\
    1 & 0 & 0 & \frac{3}{2} \\
    \frac{1}{2} & -1 & -\frac{3}{2} & 0
  )
\end{displaymath}

(ii)
\begin{displaymath}
  \tensor{M}{^\alpha_\beta} =
  \tensor{\eta}{_{\beta\mu}} \tensor{M}{^{\alpha\mu}} \to
  \mqty(
    0 & -1 & 0 & 0 \\
    1 & -1 & 0 & 2 \\
    2 & 0 & 0 & 1 \\
    1 & 0 & -2 & 0
  )
\end{displaymath}

(iii)
\begin{displaymath}
  \tensor{M}{_\alpha^\beta} =
  \tensor{\eta}{_{\alpha\mu}} \tensor{M}{^{\mu\beta}} \to
  \mqty(
    0 & -1 & 0 & 0 \\
    1 & -1 & 0 & 2 \\
    2 & 0 & 0 & 1 \\
    1 & 0 & -2 & 0
  )
\end{displaymath}

(iv)
\begin{displaymath}
  \tensor{M}{_{\alpha\beta}} =
  \tensor{\eta}{_{\beta\mu}} \tensor{M}{_\alpha^\mu} \to
  \mqty(
     0 &  1 &  0 &  0 \\
     1 & -1 &  0 &  2 \\
     2 &  0 &  0 &  1 \\
     1 &  0 & -2 &  0
  )
\end{displaymath}

(b) Does it make sense to separate the $\binom{1}{1}$ tensor with components $\tensor{M}{^\alpha_\beta}$ into symmetric and antisymmetric parts?

No, it would not make sense. For one, the notation for (anti)symmetric tensors do not even allow one to write it sensibly ($\tensor{M}{^{(\alpha}_{\beta)}}$). More importantly, one argument refers to vectors, and the other to covectors, so it does not make sense to switch them.

(c)

\begin{displaymath}
  \tensor{\eta}{^\alpha_\beta} =
  \tensor{\eta}{^{\alpha\mu}} \tensor{\eta}{_{\beta\mu}} =
  \mqty(\dmat[0]{-1,1,1,1}) \mqty(\dmat[0]{-1,1,1,1}) =
  \mqty(\imat{4}) =
  \tensor{\delta}{^\alpha_\beta}
\end{displaymath}

\textbf{31}

\textbf{Still working on it}

(\textbf{33})

\textbf{34}
Define double-null coordinates $u = t-x$, $v = t + x$ in Minkowski space.

(a)
Let $\vec{e}_u$ be the vector connecting the $(u,v,y,t)$ coordinates $(0,0,0,0)$ and $(1,0,0,0)$, and let $\vec{e}_v$ be the vector connecting $(0,0,0,0)$ and $(0,1,0,0)$. Find $\vec{e}_u$ and $\vec{e}_v$ in terms of $\vec{e}_t$ and $\vec{e}_x$, and plot the basis vectors in a spacetime diagram of the $t$--$x$ plane.

\begin{align*}
  u &= t - x = 0 \implies t =  +x &
  v &= t + x = 0 \implies t =  -x
  \\
  u &= t - x = 1 \implies t = 1+x &
  v &= t + x = 1 \implies t = 1-x &
\end{align*}

We draw the vectors $\vec{e}_u$ and $\vec{e}_v$ in Figure \ref{fig:ch3-problem-34a}, such that they point from the appropriate points of intersection on these lines of constant $u$ and $v$. From this it is obvious that $\vec{e}_v + \vec{e}_u = \vec{e}_t$, and that $\vec{e}_v - \vec{e}_u = \vec{e}_x$, or likewise $\vec{e}_v = \vec{e}_t - \vec{e}_u$ and $\vec{e}_u = \vec{e}_v - \vec{e}_x$. This is a system of 2 equations with two unknowns.

\begin{align*}
  \vec{e}_v &=
  \vec{e}_t - \vec{e}_v + \vec{e}_x \implies &
  \vec{e}_v &=
  \frac{1}{2} (\vec{e}_t + \vec{e}_x),
  \\
  \vec{e}_u &=
  \frac{1}{2} (\vec{e}_t + \vec{e}_x) - \vec{e}_x \implies &
  \vec{e}_u &=
  \frac{1}{2} (\vec{e}_t - \vec{e}_x).
\end{align*}

\begin{figure}[b]
  \centering
  \includegraphics[width=0.75\textwidth]{img/ch3_problem_34a}
  \caption{Problem 34a: Spacetime diagram of double-null coordinate basis
    vectors in $t$--$x$ plane.}
  \label{fig:ch3-problem-34a}
\end{figure}

(b)
Show that $\vec{e}_\alpha$, $\alpha \in \{ u, v, y, z \}$ form a basis for vectors in Minkowski space.

\begin{align*}
  \vec{A} = A^\alpha \vec{e}_\alpha &=
  A^u \vec{e}_u + A^v \vec{e}_v + A^y \vec{e}_y + A^z \vec{e}_z
  \\ &=
  \frac{A^u}{2} (\vec{e}_t - \vec{e}_x) +
  \frac{A^v}{2} (\vec{e}_t + \vec{e}_x) +
  A^y \vec{e}_y + A^z \vec{e}_z
  \\ &=
  \frac{1}{2} (A^v + A^u) \vec{e}_t +
  \frac{1}{2} (A^v - A^u) \vec{e}_x +
  A^y \vec{e}_y + A^z \vec{e}_z
\end{align*}
%
If we let $A^t = \frac{1}{2} (A^v + A^u)$ and $A^x = \frac{1}{2} (A^v - A^u)$, then
%
\begin{displaymath}
  \vec{A} =
  A^\alpha \vec{e}_\alpha =
  A^t \vec{e}_t + A^x \vec{e}_x + A^y \vec{e}_y + A^z \vec{e}_z
\end{displaymath}

(c)
Find the components of the metric tensor, $\vb{g}$ in this new basis.

To make this concise, we will begin with some definitions. Let $w \in \{ u, v \}$, and $q \in \{ y, z \}$. We also define
%
\begin{displaymath}
  \lambda(w) \equiv
  \begin{dcases*}
    -1, & if $w = u$,
    \\
    +1, & if $w = v$.
  \end{dcases*}
\end{displaymath}
%
It follows that
%
\begin{displaymath}
  \vec{e}_w = \frac{1}{2} (\vec{e}_t + \lambda \vec{e}_x).
\end{displaymath}
%
Now we can show that
%
\begin{align*}
  g_{ww} =
  \vec{e}_w \cdot \vec{e}_w &=
  \frac{1}{2} (\vec{e}_t + \lambda \vec{e}_x) \cdot
  \frac{1}{2} (\vec{e}_t + \lambda \vec{e}_x)
  \\ &=
  \frac{1}{4} [
    \vec{e}_t \cdot \vec{e}_t +
    2 \lambda (\vec{e}_t \cdot \vec{e}_x) +
    \lambda^2 (\vec{e}_x \cdot \vec{e}_x)
  ]
  \\ &=
  \frac{1}{4} (
    -1 + 2 \lambda \cdot 0 + 1 \cdot 1
  ) =
  0,
\end{align*}
%
so $g_{uu} = g_{vv} = 0$.

For the $u$ and $v$ cross terms, we have
%
\begin{align*}
  g_{uv} = g_{vu} =
  \vec{e}_u \cdot \vec{e}_v &=
  \frac{1}{2} (\vec{e}_t - \vec{e}_x) \cdot
  \frac{1}{2} (\vec{e}_t + \vec{e}_x)
  \\ &=
  \frac{1}{4} [
    \vec{e}_t \cdot \vec{e}_t +
    0 \cdot \vec{e}_t \cdot \vec{e}_x -
    \vec{e}_x \cdot \vec{e}_x
  ]
  \\ &=
  \frac{1}{4} ( -1 + 0 - 1 ) =
  -\frac{1}{2}
\end{align*}

For the $w$ with $y$ and $z$ cross terms we have
%
\begin{align*}
  g_{wq} =
  \vec{e}_w \cdot \vec{e}_q &=
  \frac{1}{2} (\vec{e}_t + \lambda \vec{e}_x) \cdot \vec{e}_q
  \\ &=
  \frac{1}{2} [ \vec{e}_t \cdot \vec{e}_t + \lambda \vec{e}_x \cdot \vec{e}_x ]
  \\ &=
  0
\end{align*}
%
so $g_{uy} = g_{vy} = g_{uz} = g_{vz} = 0$. We also already know $g_{yy} = g_{zz} = 1$, and $g_{yz} = g_{zy} = 0$, so we can write the components of the metric tensor in this new coordinate system as
%
\begin{displaymath}
  g_{\alpha\beta} =
  \mqty(
               0 & -\frac{1}{2} & 0 & 0 \\
    -\frac{1}{2} &            0 & 0 & 0 \\
               0 &            0 & 1 & 0 \\
               0 &            0 & 0 & 1
  ).
\end{displaymath}

(d)
Show that $\vec{e}_u$ and $\vec{e}_v$ are null, but not orthogonal.

\begin{align*}
  \vec{e}_u \cdot \vec{e}_u &= g_{uu} = 0
  \implies \vec{e}_u \text{ is null}
  \\
  \vec{e}_v \cdot \vec{e}_v &= g_{vv} = 0
  \implies \vec{e}_v \text{ is null}
  \\
  \vec{e}_u \cdot \vec{e}_v &= g_{uv} = -\frac{1}{2} \neq 0
  \implies \vec{e}_u \text{ and } \vec{e}_v \text{ are not orthogonal.}
\end{align*}

(e)
Compute the four one-forms $\tilde\dd{u}$, $\tilde\dd{v}$, $\vb{g}(\vec{e}_u,)$, and $\vb{g}(\vec{e}_v,)$ in terms of $\tilde\dd{t}$ and $\tilde\dd{x}$.

\begin{displaymath}
  \tilde\dd\phi \to_\obs
  \qty( \pdv{\phi}{t}, \pdv{\phi}{x}, \pdv{\phi}{y}, \pdv{\phi}{z} ),
\end{displaymath}
%
so
\begin{align*}
  \tilde\dd{t} &\to_\obs (1, 0, 0, 0), &
  \tilde\dd{x} &\to_\obs (0, 1, 0, 0),
  \\
  \tilde\dd{u} &\to_\obs \frac{1}{2} (1, -1, 0, 0), &
  \tilde\dd{u} &\to_\obs \frac{1}{2} (1,  1, 0, 0),
\end{align*}
%
from which it is obvious that
\begin{align*}
  \tilde\dd{u} &=
  \frac{1}{2} (\tilde\dd{t} - \tilde\dd{x}), &
  \tilde\dd{v} &=
  \frac{1}{2} (\tilde\dd{t} + \tilde\dd{x}). &
\end{align*}

\end{document}


% !TeX root = ../main.tex
% This document needs to include:
% - An introduction for the concern.
% - Bases for section, specifically EBNF in previous section.
% - Difference between EBNF CFG.
% - HCL as CFL and HCL's CFG.
% - Proof that HCL is a CFL.
% - Proof that shows whether HCL is a regular language or not.
% - Description of identifiers and types in HCL using computational models or Regex.
% - Conclusion.
\section{Mathematical Syntax Theory}
This section contains the concise definitions of HCL's syntax.
First the proper CFG recognizing HCL is presented.
The CFG is used to prove that HCL is a Context-free Language (CFL).
Afterwards the most specific computational model for describing HCL is identified and presented.
Finally the token categories are described in a computational model.
The conclusions of this section provides the basis for implementing and testing the parser of the HCL compiler.
The majority of this section is based on the EBNF details touched upon in appendix \ref{AppendixEBNF}.

\subsection{HCL as an CFL}
This subsection investigates whether HCL is a CFL.
To determine this, a Pushdown Automaton (PDA) is constructed.
The reason being that the set of CFL's is equivalent to the set of languages recognized by a PDA.
To construct the PDA the following rules are used:
\begin{center}
	\begin{itemize}
		\item The marker symbol \$ is first placed on the stack.
		\item Second, the following steps are repeated until all production rules have been handled.
		\begin{itemize}
			\item If the top of the stack is a variable symbol V.
			The machine will nondeterministically select one of the right production rules of V and replace V with that.
			\item If the top of stack is a terminal symbol t.
			The next character on the input string is read and compared to t.
			If matched, repeat.
			If not, reject the branch.
			\item If the top of stack is the marker symbol \$, enter the accept state of the automaton.
			This will accept the input string.
		\end{itemize}
	\end{itemize}
\end{center}

To create the automaton, a start state needs to be added at the beginning of the automaton.
A transition rule on the form $\epsilon,\epsilon->S\$$ needs to be added between the start state and a new state called the loop state.
Here S is a variable.
From the loop state to the accept state there needs to be a transition rule on the form $\epsilon,\$->\epsilon$.
To convert the EBNF's production rules to a PDA, two conversion rules need to be followed.

For each production rule of the form $A->w$, where A is a variable and w is a string the transition rule $\epsilon,A->w$ needs to be added to the automaton from the loop state back to the loop state.
For each terminal a transition rule $a,a->\epsilon$ needs to be added to the automaton from the loop state back to the loop state.
The final non-deterministic PDA (NPDA) can be seen in Appendix \ref{NPDA} on page \pageref{NPDA}.
Thus concludes the proof.

\subsection{Regularity of HCL}
HCL is as CFL recognized by the CFG described in the previous subsections.
Therefore, it is now relevant to investigate whether HCL is a regular language.
If that is the case, it is possible to create a Finite State Automaton (FSA) that recognizes the language.

Since the set of regular languages is a subset of the context free languages, this may be the case.
A FSA is more trivial to implement than a NPDA.
Since the HCL language is a relatively complex language, it would be unrealistic to sequentially go through the entire language while trying to construct a FSA that recognizes HCL.

Considering the fact that the regular languages are closed under the union, concatenation, and the star operations, it would be sufficient to locate a subset of HCL that is not a regular language.
The transition rules described in the EBNF, state that a subset of HCL might consist of an arbitrary number of equal amounts of left and right parentheses.
This subset, referred to as $HCL_{subset}$ can be described as the set:
\begin{center}
	$HCL_{subset} = \{a^nbc^n | a \in \{(\} \wedge b \in P \wedge c \in \{)\}\}$
\end{center}
where P is an arbitrary set containing elements, that are legal in the context.

To prove that HCL is not a regular language, the pumping lemma is used.
The pumping lemma states that:
\begin{center}
	If A is a regular language, there exists a number $p>0$ so all strings $s \in A $, where $|s| \geq p$ can be divided $s = xyz$ so the following properties are true:
	\begin{itemize}
		\item $xy^iz \in A$ for $i \geq 0$
		\item $|y| > 0$
		\item $|xy| \leq p$
	\end{itemize}
\end{center}

First the division is chosen for s.
$s = xyz$, where $s = (((...b)))...$.
Meaning that x consists only of left parentheses, y consists of a concatenation of left parentheses and elements from P and z consists only of right parentheses.

The length of the string is $p < |s| < (p3)/2$, since $s = a^nbc^n$, where $n = p/2$ and $0 < |b| \leq p/2$.

This means that the third condition is upheld since $|xy|$ cannot be greater than p.
The second condition is also upheld since y consists of at least some left parentheses.
If the string does contain right parentheses, which it does, y cannot be of the length 0.

The first condition is not upheld since if $i = 0$ the new string cannot contain an equal amount of left and right parentheses because of the same reason as to why the second condition is upheld.

This concludes the proof by contradiction.
Since HCL does not uphold the required property for it to be a regular language, it is not.
Therefore it cannot be described by a FSA, therefore the implementation will not be trivial.

\subsection{Types and Identifiers}
So far the syntax of HCL has been properly defined as a CFL.
Meaning that all variables, terminals and the transition rules for recognizing HCL has been described in a computational model as seen in appendix \ref{NPDA} on page \pageref{NPDA}.
It is now relevant to define how the types and identifiers in HCL can be described, or recognized, by a computational model.
The goal is to formally describe the languages $L_{none}$, $L_{bool}$, $L_{number}$, $L_{text}$ which are the type languages and the identifier language $L_{identifiers}$.

An alphabet is a finite set of symbols, a string is a finite sequence of symbols and a language is a set of strings.
To describe the languages mentioned above, the Alphabets used in the informal and formal notations needs to be defined.
These can be seen in Table 3.1.

\begin{table}[!htb]
	\centering
	\begin{tabular}{|l|l|}
		\hline
		\textbf{Alphabet} & \textbf{Set}                            \\ \hline
		T                 & \{True\}                                \\ \hline
		F                 & \{False\}                               \\ \hline
		$Z^+$             & The set of all positive integers        \\ \hline
		$Z^-$             & The set of all negative integers        \\ \hline
		R                 & The set of all real numbers             \\ \hline
		D                 & \{$Z^+ \cup Z^-$\}                      \\ \hline
		$S_p$             & The set of all special characters      \\ \hline
		$L_l$             & The set of all lower-case letters       \\ \hline
		$L_u$             & The set of all upper-case letters       \\ \hline
		C                 & $S_p \cup L_l \cup L_u \cup D$          \\ \hline
		$R_{eserved}$     & The set of all reserved keywords, specialchars and types \\ \hline
	\end{tabular}
	\caption{Table containing all utility alphabets used to formally describe the type and identifier languages}
\end{table}

By using the set construction method, the languages can now be defined as shown in Table 3.2.

\begin{table}[!htb]
	\centering
	\begin{tabular}{|l|l|}
		\hline
		\textbf{Name}     & \textbf{Set}                                    \\ \hline
		$L_{none}$        & \{w | w $\in$ \{None\}\}                        \\ \hline
		$L_{bool}$        & \{w | w $\in$ (T $\cup$ F)\}                    \\ \hline
		$L_{number}$      & \{w | w $\in$ R\}                               \\ \hline
		$L_{text}$        & \{"w" | all strings from arbitrary alphabets\}  \\ \hline
		$L_{identifiers}$ & \{w | w $\in (L_{text} - \{", "\}) \wedge w \notin R_{eserved}$\} \\ \hline
	\end{tabular}
	\caption{Table containing the type and identifier alphabets described by the set builder construction}
\end{table}

Intuitively, it is trivial that all of the languages defined above are regular languages, except for $L_{identifiers}$ since it would need to make sure that no strings are an element of $S_p$.
This is the case since a regular language cannot keep track of more than one symbol in terms of counting and iterations.

Since all of the languages in Table 3.2(except for $L_{identifiers}$) consists only of arbitrary concatenations of elements of various alphabets, this means that they are indeed regular.

Now that it has been determined that the languages are regular, a computational model can now be chosen to describe them more specifically.

For the sake of convenience, $R^+$ will be used at a shorthand for $RR^*$ \footnote{Where * is Kleene star}, meaning that $R^+ \cup \epsilon = R^*$ since $R^*$ consists of all strings that are zero or more concatenations from R, and $RR^*$ consists of all strings that are one or more concatenations of strings from R.
The resulting regular expressions are shown in Table 3.3.

\begin{table}[!htb]
	\centering
	\label{my-label}
	\begin{tabular}{|l|l|}
		\hline
		\textbf{Name}     & \textbf{Regular Expression}         \\ \hline
		$L_{none}$        & none                                \\ \hline
		$L_{bool}$        & True $\cup$ False                   \\ \hline
		$L_{number}$      & $D.(D^+)^*$                       \\ \hline
		$L_{text}$        & $"C^*"$                               \\ \hline
	\end{tabular}
	\caption{Regular Expressions describing the type and identifier languages}
\end{table}

In conclusion HCL is a context free language, meaning that it can be described by a NDPA.
Some subsets of HCL is non-regular, meaning that HCL cannot be a regular language.
The token category type languages are all regular languages.
These can therefore be described using regular expressions as presented in this section.