\documentclass[12pt]{cdblatex}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% =================================================================================================
% create checkpoint file

\bgroup
\CdbSetup{action=hide}
\begin{cadabra}
   import cdblib
   checkpoint_file = 'tests/semantic/output/metric.json'
   cdblib.create (checkpoint_file)
   checkpoint = []
\end{cadabra}
\egroup

% =================================================================================================
\section*{The metric tensor in Riemann normal coordinates}

In this notebook we compute the recursive sequences
\begin{align}
\label{eq:pdgab}
g_{ab,d\ue} &=  \left(g_{cb}\Gamma^{c}{}_{a(d}\right){}_{,\ue)}
               + \left(g_{ac}\Gamma^{c}{}_{b(d}\right){}_{,\ue)}\\[10pt]
\label{eq:pdGamma}
(n+3)\Gamma^a{}_{d(b,c\ue)} &= (n+1)\left(R^a{}_{(bc\Dot d,\ue)}
                               - \left(\Gamma^a{}_{f(c}\Gamma^f{}_{b{\Dot d}}\right){}_{,\ue)}\right)
\end{align}
for $n=1,2,3,\cdots$. Note in these equations that the (extended) index $\ue$ contains $n$
normal indices.

We then construct a Taylor series for the metric using
\begin{dmath*}[spread=5pt]
g_{ab}(x) = g_{ab} + g_{ab,c}x^c + \frac{1}{2!} g_{ab,cd}x^cx^d + \frac{1}{3!} g_{ab,cde}x^cx^dx^e + \cdots
          = g_{ab} + \sum_{n=1}^\infty\> \frac{1}{n!}\>g_{ab,\uc}\>x^{.\uc}
\end{dmath*}

% =================================================================================================
\section*{Stage 1: Symmetrised partial derivatives of $g_{ab}$}

In this stage, equation (\ref{eq:pdgab}) is used to express the symmetrised partial derivatives
of the metric in terms of the symmetrised partial derivatives of the connection.

\begin{dgroup*}
   \begin{dmath*} g_{ab,c} A^{c} = \cdb{term1.200} \end{dmath*}
   \begin{dmath*} g_{ab,cd} A^{c} A^{d} = \cdb{term2.200} \end{dmath*}
   \begin{dmath*} g_{ab,cde} A^{c} A^{d} A^{e} = \cdb{term3.200} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Stage 2: Replace derivatives of $\Gamma$ with partial derivs of $R$}

Now we use the results from {\verb|dGamma|} to replace derivatives of $\Gamma$ with
partial derivatives of $R$. These were computed in {\verb|dGamma|} using equation
(\ref{eq:pdGamma}) above.

\begin{dgroup*}
   \begin{dmath*} g_{ab,c} A^{c} = \cdb{term1.200} \end{dmath*}
   \begin{dmath*} g_{ab,cd} A^{c} A^{d} = \cdb{term2.303} \end{dmath*}
   \begin{dmath*} g_{ab,cde} A^{c} A^{d} A^{e} = \cdb{term3.305} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Stage 3: Replace partial derivs of $R$ with covariant derivs of $R$}

Next we use the results from {\verb|dRabcd|} to replace the partial derivatives of $R$ with
covariant deriavtives.

\begin{dgroup*}
   \begin{dmath*} g_{ab,c} A^{c} = \cdb{term1.404} \end{dmath*}
   \begin{dmath*} g_{ab,cd} A^{c} A^{d} = \cdb{term2.404} \end{dmath*}
   \begin{dmath*} g_{ab,cde} A^{c} A^{d} A^{e} = \cdb{term3.403} \end{dmath*}
\end{dgroup*}

% =================================================================================================
\section*{Stage 4: Build the Taylor series for $g_{ab}$, reformatting and output}

Each of the above expressions constitutues one term in the Taylor series for the metric.
We also make the trivial change $A\rightarrow x$. Then we do some trivial reformatting.

\begin{align*}
   g_{ab}(x) &=   g_{ab}
                + g_{ab,c} x^c
                + \frac{1}{2!} g_{ab,cd} x^c x^d
                + \frac{1}{3!} g_{ab,cde} x^c x^d x^e +  \BigO{\eps^4}\\
             &= \cdb{metric4.501} + \BigO{\eps^4}
\end{align*}

\clearpage

% =================================================================================================
\section*{Shared properties}

\begin{cadabra}
   import time

   def flatten_Rabcd (obj):
       substitute (obj,$R^{a}_{b c d}   -> g^{a e} R_{e b c d}$)
       substitute (obj,$R_{a}^{b}_{c d} -> g^{b e} R_{a e c d}$)
       substitute (obj,$R_{a b}^{c}_{b} -> g^{c e} R_{a b e d}$)
       substitute (obj,$R_{a b c}^{d}   -> g^{d e} R_{a b c e}$)
       unwrap     (obj)
       return obj

   def impose_rnc (obj):
       # hide the derivatives of Gamma
       substitute (obj,$\partial_{d}{\Gamma^{a}_{b c}} -> zzz_{d}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e}{\Gamma^{a}_{b c}} -> zzz_{d e}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e f}{\Gamma^{a}_{b c}} -> zzz_{d e f}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e f g}{\Gamma^{a}_{b c}} -> zzz_{d e f g}^{a}_{b c}$,repeat=True)
       substitute (obj,$\partial_{d e f g h}{\Gamma^{a}_{b c}} -> zzz_{d e f g h}^{a}_{b c}$,repeat=True)
       # set Gamma to zero
       substitute (obj,$\Gamma^{a}_{b c} -> 0$,repeat=True)
       # recover the derivatives Gamma
       substitute (obj,$zzz_{d}^{a}_{b c} -> \partial_{d}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e}^{a}_{b c} -> \partial_{d e}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e f}^{a}_{b c} -> \partial_{d e f}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e f g}^{a}_{b c} -> \partial_{d e f g}{\Gamma^{a}_{b c}}$,repeat=True)
       substitute (obj,$zzz_{d e f g h}^{a}_{b c} -> \partial_{d e f g h}{\Gamma^{a}_{b c}}$,repeat=True)
       return obj

   def get_xterm (obj,n):

       x^{a}::Weight(label=numx).

       foo := @(obj).
       bah  = Ex("numx = " + str(n))
       keep_weight (foo,bah)

       return foo

   # note: keeping numbering as is (out of order) to ensure R appears before \nabla R etc.
   def product_sort (obj):
       substitute (obj,$ A^{a}                             -> A001^{a}                  $)
       substitute (obj,$ x^{a}                             -> A002^{a}                  $)
       substitute (obj,$ g_{a b}                           -> A003_{a b}                $)
       substitute (obj,$ g^{a b}                           -> A004^{a b}                $)
       substitute (obj,$ \nabla_{e f g h}{R_{a b c d}}     -> A010_{a b c d e f g h}    $)
       substitute (obj,$ \nabla_{e f g}{R_{a b c d}}       -> A009_{a b c d e f g}      $)
       substitute (obj,$ \nabla_{e f}{R_{a b c d}}         -> A008_{a b c d e f}        $)
       substitute (obj,$ \nabla_{e}{R_{a b c d}}           -> A007_{a b c d e}          $)
       substitute (obj,$ \partial_{e f g h}{R_{a b c d}}   -> A014_{a b c d e f g h}    $)
       substitute (obj,$ \partial_{e f g}{R_{a b c d}}     -> A013_{a b c d e f g}      $)
       substitute (obj,$ \partial_{e f}{R_{a b c d}}       -> A012_{a b c d e f}        $)
       substitute (obj,$ \partial_{e}{R_{a b c d}}         -> A011_{a b c d e}          $)
       substitute (obj,$ \partial_{e f g h}{R^{a}_{b c d}} -> A018^{a}_{b c d e f g h}  $)
       substitute (obj,$ \partial_{e f g}{R^{a}_{b c d}}   -> A017^{a}_{b c d e f g}    $)
       substitute (obj,$ \partial_{e f}{R^{a}_{b c d}}     -> A016^{a}_{b c d e f}      $)
       substitute (obj,$ \partial_{e}{R^{a}_{b c d}}       -> A015^{a}_{b c d e}        $)
       substitute (obj,$ R_{a b c d}                       -> A005_{a b c d}            $)
       substitute (obj,$ R^{a}_{b c d}                     -> A006^{a}_{b c d}          $)
       sort_product   (obj)
       rename_dummies (obj)
       substitute (obj,$ A001^{a}                  -> A^{a}                             $)
       substitute (obj,$ A002^{a}                  -> x^{a}                             $)
       substitute (obj,$ A003_{a b}                -> g_{a b}                           $)
       substitute (obj,$ A004^{a b}                -> g^{a b}                           $)
       substitute (obj,$ A005_{a b c d}            -> R_{a b c d}                       $)
       substitute (obj,$ A006^{a}_{b c d}          -> R^{a}_{b c d}                     $)
       substitute (obj,$ A007_{a b c d e}          -> \nabla_{e}{R_{a b c d}}           $)
       substitute (obj,$ A008_{a b c d e f}        -> \nabla_{e f}{R_{a b c d}}         $)
       substitute (obj,$ A009_{a b c d e f g}      -> \nabla_{e f g}{R_{a b c d}}       $)
       substitute (obj,$ A010_{a b c d e f g h}    -> \nabla_{e f g h}{R_{a b c d}}     $)
       substitute (obj,$ A011_{a b c d e}          -> \partial_{e}{R_{a b c d}}         $)
       substitute (obj,$ A012_{a b c d e f}        -> \partial_{e f}{R_{a b c d}}       $)
       substitute (obj,$ A013_{a b c d e f g}      -> \partial_{e f g}{R_{a b c d}}     $)
       substitute (obj,$ A014_{a b c d e f g h}    -> \partial_{e f g h}{R_{a b c d}}   $)
       substitute (obj,$ A015^{a}_{b c d e}        -> \partial_{e}{R^{a}_{b c d}}       $)
       substitute (obj,$ A016^{a}_{b c d e f}      -> \partial_{e f}{R^{a}_{b c d}}     $)
       substitute (obj,$ A017^{a}_{b c d e f g}    -> \partial_{e f g}{R^{a}_{b c d}}   $)
       substitute (obj,$ A018^{a}_{b c d e f g h}  -> \partial_{e f g h}{R^{a}_{b c d}} $)

       return obj

   def reformat_xterm (obj,scale):
       foo  = Ex(str(scale))
       bah := @(foo) @(obj).
       distribute     (bah)
       bah = product_sort (bah)
       rename_dummies (bah)
       canonicalise   (bah)
       factor_out     (bah,$x^{a?}$)
       ans := @(bah) / @(foo).
       return ans

   def rescale_xterm (obj,scale):
       foo  = Ex(str(scale))
       bah := @(foo) @(obj).
       distribute  (bah)
       factor_out  (bah,$x^{a?}$)
       return bah

   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   \nabla{#}::Derivative.
   \partial{#}::PartialDerivative.

   g_{a b}::Metric.
   g^{a b}::InverseMetric.
   g_{a}^{b}::KroneckerDelta.
   g^{a}_{b}::KroneckerDelta.

   R_{a b c d}::RiemannTensor.
   R^{a}_{b c d}::RiemannTensor.
   R_{a b c}^{d}::RiemannTensor.

   \Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2}).

   g_{a b}::Depends(\partial{#}).
   R_{a b c d}::Depends(\partial{#}).
   R^{a}_{b c d}::Depends(\partial{#}).
   \Gamma^{a}_{b c}::Depends(\partial{#}).

   R_{a b c d}::Depends(\nabla{#}).
   R^{a}_{b c d}::Depends(\nabla{#}).

\end{cadabra}

\clearpage

% =================================================================================================
\section*{Stage 1: Symmetrised partial derivatives of $g_{ab}$}

\begin{cadabra}
   beg_stage_1 = time.time()

   # symmetrised partial derivatives of g_{ab}

   gab00:=g_{a b}.                                              # cdb (gab00.101,gab00)

   gab01:=g_{c b}\Gamma^{c}_{a d} + g_{a c}\Gamma^{c}_{b d}.    # cdb (gab01.101,gab01)

   gab02:=\partial_{e}{ @(gab01) }.                             # cdb (gab02.101,gab02)
   distribute   (gab02)                                         # cdb (gab02.102,gab02)
   product_rule (gab02)                                         # cdb (gab02.103,gab02)
   substitute   (gab02, $\partial_{d}{g_{a b}} -> @(gab01)$)    # cdb (gab02.104,gab02)
   distribute   (gab02)                                         # cdb (gab02.105,gab02)

   gab03:=\partial_{f}{ @(gab02) }.                             # cdb (gab03.101,gab03)
   distribute   (gab03)                                         # cdb (gab03.102,gab03)
   product_rule (gab03)                                         # cdb (gab03.103,gab03)
   substitute   (gab03, $\partial_{d}{g_{a b}} -> @(gab01)$)    # cdb (gab03.104,gab03)
   distribute   (gab03)                                         # cdb (gab03.105,gab03)

   gab04:=\partial_{g}{ @(gab03) }.                             # cdb (gab04.101,gab04)
   distribute   (gab04)                                         # cdb (gab04.102,gab04)
   product_rule (gab04)                                         # cdb (gab04.103,gab04)
   substitute   (gab04, $\partial_{d}{g_{a b}} -> @(gab01)$)    # cdb (gab04.104,gab04)
   distribute   (gab04)                                         # cdb (gab04.105,gab04)

   gab05:=\partial_{h}{ @(gab04) }.                             # cdb (gab05.101,gab05)
   distribute   (gab05)                                         # cdb (gab05.102,gab05)
   product_rule (gab05)                                         # cdb (gab05.103,gab05)
   substitute   (gab05, $\partial_{d}{g_{a b}} -> @(gab01)$)    # cdb (gab05.104,gab05)
   distribute   (gab05)                                         # cdb (gab05.105,gab05)

   gab00 = impose_rnc (gab00)   # cdb (gab00.102,gab00)
   gab01 = impose_rnc (gab01)   # cdb (gab01.102,gab01)
   gab02 = impose_rnc (gab02)   # cdb (gab02.106,gab02)
   gab03 = impose_rnc (gab03)   # cdb (gab03.106,gab03)
   gab04 = impose_rnc (gab04)   # cdb (gab04.106,gab04)
   gab05 = impose_rnc (gab05)   # cdb (gab05.106,gab05)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{gab00.101} \end{dmath*}
   \begin{dmath*} \cdb*{gab00.102} \end{dmath*}
   \begin{dmath*} \cdb*{gab01.101} \end{dmath*}
   \begin{dmath*} \cdb*{gab01.102} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{gab02.101} \end{dmath*}
   \begin{dmath*} \cdb*{gab02.102} \end{dmath*}
   \begin{dmath*} \cdb*{gab02.103} \end{dmath*}
   \begin{dmath*} \cdb*{gab02.104} \end{dmath*}
   \begin{dmath*} \cdb*{gab02.105} \end{dmath*}
   \begin{dmath*} \cdb*{gab02.106} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{gab03.101} \end{dmath*}
   \begin{dmath*} \cdb*{gab03.102} \end{dmath*}
   \begin{dmath*} \cdb*{gab03.103} \end{dmath*}
   \begin{dmath*} \cdb*{gab03.104} \end{dmath*}
   \begin{dmath*} \cdb*{gab03.105} \end{dmath*}
   \begin{dmath*} \cdb*{gab03.106} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{gab04.101} \end{dmath*}
   \begin{dmath*} \cdb*{gab04.102} \end{dmath*}
   \begin{dmath*} \cdb*{gab04.103} \end{dmath*}
   \begin{dmath*} \cdb*{gab04.104} \end{dmath*}
   \begin{dmath*} \cdb*{gab04.105} \end{dmath*}
   \begin{dmath*} \cdb*{gab04.106} \end{dmath*}
\end{dgroup*}

\begin{cadabra}
   # prepare first six terms in the Taylor series expansion of g_{ab}(x)

   term0:= @(gab00).
   distribute (term0)                             # cdb(term0.200,term0)

   term1:= @(gab01) A^d.
   distribute (term1)                             # cdb(term1.200,term1)

   term2:= @(gab02) A^d A^e.
   distribute (term2)                             # cdb(term2.200,term2)

   term3:= @(gab03) A^d A^e A^f.
   distribute (term3)                             # cdb(term3.200,term3)

   term4:= @(gab04) A^d A^e A^f A^g.
   distribute (term4)                             # cdb(term4.200,term4)

   term5:= @(gab05) A^d A^e A^f A^g A^h.
   distribute (term5)                             # cdb(term5.200,term5)

   end_stage_1 = time.time()
\end{cadabra}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term0.200} \end{dmath*}
   \begin{dmath*} \cdb*{term1.200} \end{dmath*}
   \begin{dmath*} \cdb*{term2.200} \end{dmath*}
   \begin{dmath*} \cdb*{term3.200} \end{dmath*}
   % \begin{dmath*} \cdb*{term4.200} \end{dmath*}
   % \begin{dmath*} \cdb*{term5.200} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Stage 2: Replace derivatives of $\Gamma$ with partial derivs of $R$}

\begin{cadabra}
   import cdblib

   beg_stage_2 = time.time()

   dGamma01 = cdblib.get ('dGamma01','dGamma.json')  # cdb(dGamma01.300,dGamma01)
   dGamma02 = cdblib.get ('dGamma02','dGamma.json')  # cdb(dGamma02.300,dGamma02)
   dGamma03 = cdblib.get ('dGamma03','dGamma.json')  # cdb(dGamma03.300,dGamma03)
   dGamma04 = cdblib.get ('dGamma04','dGamma.json')  # cdb(dGamma04.300,dGamma04)
   dGamma05 = cdblib.get ('dGamma05','dGamma.json')  # cdb(dGamma05.300,dGamma05)

   # replace partial derivs of \Gamma with products and derivs of Riemann tensor

   substitute (term2,$\partial_{c}{\Gamma^{a}_{b d}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term2.301,term2)
   substitute (term2,$\partial_{c}{\Gamma^{a}_{d b}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term2.302,term2)
   distribute (term2)                                                                                # cdb(term2.303,term2)

   substitute (term3,$\partial_{c e}{\Gamma^{a}_{d b}}A^{c}A^{b}A^{e} -> @(dGamma02)$,repeat=True)                # cdb(term3.301,term3)
   substitute (term3,$\partial_{c e}{\Gamma^{a}_{b d}}A^{c}A^{b}A^{e} -> @(dGamma02)$,repeat=True)                # cdb(term3.302,term3)
   substitute (term3,$\partial_{c}{\Gamma^{a}_{b d}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term3.303,term3)
   substitute (term3,$\partial_{c}{\Gamma^{a}_{d b}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term3.304,term3)
   distribute (term3)                                                                                # cdb(term3.305,term3)

   substitute (term4,$\partial_{c e f}{\Gamma^{a}_{d b}}A^{c}A^{b}A^{e}A^{f} -> @(dGamma03)$,repeat=True)         # cdb(term4.301,term4)
   substitute (term4,$\partial_{c e f}{\Gamma^{a}_{b d}}A^{c}A^{b}A^{e}A^{f} -> @(dGamma03)$,repeat=True)         # cdb(term4.302,term4)
   substitute (term4,$\partial_{c e}{\Gamma^{a}_{d b}}A^{c}A^{b}A^{e} -> @(dGamma02)$,repeat=True)                # cdb(term4.303,term4)
   substitute (term4,$\partial_{c e}{\Gamma^{a}_{b d}}A^{c}A^{b}A^{e} -> @(dGamma02)$,repeat=True)                # cdb(term4.304,term4)
   substitute (term4,$\partial_{c}{\Gamma^{a}_{b d}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term4.305,term4)
   substitute (term4,$\partial_{c}{\Gamma^{a}_{d b}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term4.306,term4)
   distribute (term4)                                                                                # cdb(term4.307,term4)

   substitute (term5,$\partial_{c e f g}{\Gamma^{a}_{d b}}A^{c}A^{b}A^{e}A^{f}A^{g} -> @(dGamma04)$,repeat=True)  # cdb(term5.301,term5)
   substitute (term5,$\partial_{c e f g}{\Gamma^{a}_{b d}}A^{c}A^{b}A^{e}A^{f}A^{g} -> @(dGamma04)$,repeat=True)  # cdb(term5.302,term5)
   substitute (term5,$\partial_{c e f}{\Gamma^{a}_{d b}}A^{c}A^{b}A^{e}A^{f} -> @(dGamma03)$,repeat=True)         # cdb(term5.303,term5)
   substitute (term5,$\partial_{c e f}{\Gamma^{a}_{b d}}A^{c}A^{b}A^{e}A^{f} -> @(dGamma03)$,repeat=True)         # cdb(term5.304,term5)
   substitute (term5,$\partial_{c e}{\Gamma^{a}_{d b}}A^{c}A^{b}A^{e} -> @(dGamma02)$,repeat=True)                # cdb(term5.305,term5)
   substitute (term5,$\partial_{c e}{\Gamma^{a}_{b d}}A^{c}A^{b}A^{e} -> @(dGamma02)$,repeat=True)                # cdb(term5.306,term5)
   substitute (term5,$\partial_{c}{\Gamma^{a}_{b d}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term5.307,term5)
   substitute (term5,$\partial_{c}{\Gamma^{a}_{d b}}A^{c}A^{b} -> @(dGamma01)$,repeat=True)                       # cdb(term5.308,term5)
   distribute (term5)                                                                                # cdb(term5.309,term5)

   end_stage_2 = time.time()

   # -------------------------------------------------------------------------------------------
   # this block of Xterms only produces formatted output, it's not part of the main computation
   # -------------------------------------------------------------------------------------------

   # the metric in terms of partial derivatives of Rabcd

   metric:=@(term0)
         + (1/1) @(term1)  # zero
         + (1/2) @(term2)
         + (1/6) @(term3)
         + (1/24) @(term4)
         + (1/120) @(term5).  # cdb(metric.301,metric)

   substitute (metric,$A^{a} -> x^{a}$)  # cdb (metric.302,metric)

   # reformat and tidy up

   Xterm0 := @(term0).
   Xterm1 := (1/1) @(term1).
   Xterm2 := (1/2) @(term2).
   Xterm3 := (1/6) @(term3).
   Xterm4 := (1/24) @(term4).
   Xterm5 := (1/120) @(term5).

   substitute (Xterm0,$A^{a} -> x^{a}$)
   substitute (Xterm1,$A^{a} -> x^{a}$)
   substitute (Xterm2,$A^{a} -> x^{a}$)
   substitute (Xterm3,$A^{a} -> x^{a}$)
   substitute (Xterm4,$A^{a} -> x^{a}$)
   substitute (Xterm5,$A^{a} -> x^{a}$)

   substitute (Xterm2,$g_{a b} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm2.301,Xterm2)
   substitute (Xterm3,$g_{a b} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm3.301,Xterm3)
   substitute (Xterm4,$g_{a b} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm4.301,Xterm4)
   substitute (Xterm5,$g_{a b} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm5.301,Xterm5)

   substitute (Xterm2,$g_{b a} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm2.301,Xterm2)
   substitute (Xterm3,$g_{b a} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm3.301,Xterm3)
   substitute (Xterm4,$g_{b a} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm4.301,Xterm4)
   substitute (Xterm5,$g_{b a} \partial_{c}{R^{b}_{d e f}} -> \partial_{c}{R_{a d e f}}$)  # cdb(Xterm5.301,Xterm5)

   eliminate_metric (Xterm2)  # cdb(Xterm2.302,Xterm2)
   eliminate_metric (Xterm3)  # cdb(Xterm3.302,Xterm3)
   eliminate_metric (Xterm4)  # cdb(Xterm4.302,Xterm4)
   eliminate_metric (Xterm5)  # cdb(Xterm5.302,Xterm5)

   sort_product     (Xterm2)  # cdb(Xterm2.303,Xterm2)
   sort_product     (Xterm3)  # cdb(Xterm3.303,Xterm3)
   sort_product     (Xterm4)  # cdb(Xterm4.303,Xterm4)
   sort_product     (Xterm5)  # cdb(Xterm5.303,Xterm5)

   rename_dummies   (Xterm2)  # cdb(Xterm2.304,Xterm2)
   rename_dummies   (Xterm3)  # cdb(Xterm3.304,Xterm3)
   rename_dummies   (Xterm4)  # cdb(Xterm4.304,Xterm4)
   rename_dummies   (Xterm5)  # cdb(Xterm5.304,Xterm5)

   canonicalise     (Xterm2)  # cdb(Xterm2.305,Xterm2)
   canonicalise     (Xterm3)  # cdb(Xterm3.305,Xterm3)
   canonicalise     (Xterm4)  # cdb(Xterm4.305,Xterm4)
   canonicalise     (Xterm5)  # cdb(Xterm5.305,Xterm5)

   # push upper index to the left
   def tidy_Rabcd (obj):
       substitute (obj,$R_{a b c}^{d} -> - R^{d}_{c a b}$)
       substitute (obj,$R_{a b}^{c}_{d} -> R^{c}_{d a b}$)
       substitute (obj,$R_{a}^{b}_{c d} -> - R^{b}_{a c d}$)
       return obj

   Xterm0 = tidy_Rabcd (Xterm0)  # cdb(Xterm0.666,Xterm0)
   Xterm2 = tidy_Rabcd (Xterm2)  # cdb(Xterm2.666,Xterm2)
   Xterm3 = tidy_Rabcd (Xterm3)  # cdb(Xterm3.666,Xterm3)
   Xterm4 = tidy_Rabcd (Xterm4)  # cdb(Xterm4.666,Xterm4)
   Xterm5 = tidy_Rabcd (Xterm5)  # cdb(Xterm5.666,Xterm5)

   Xterm0 = reformat_xterm (Xterm0,  1)    # cdb(Xterm0.301,Xterm0)
   Xterm2 = reformat_xterm (Xterm2,  3)    # cdb(Xterm2.301,Xterm2)
   Xterm3 = reformat_xterm (Xterm3,  6)    # cdb(Xterm3.301,Xterm3)
   Xterm4 = reformat_xterm (Xterm4,360)    # cdb(Xterm4.301,Xterm4)
   Xterm5 = reformat_xterm (Xterm5,180)    # cdb(Xterm5.301,Xterm5)

   # canonicalise from reformat_xterm will slide upper index from left hand side
   # so now we slide the upper index back to the left

   Xterm0 = tidy_Rabcd (Xterm0)  # cdb(Xterm0.667,Xterm0)
   Xterm2 = tidy_Rabcd (Xterm2)  # cdb(Xterm2.667,Xterm2)
   Xterm3 = tidy_Rabcd (Xterm3)  # cdb(Xterm3.667,Xterm3)
   Xterm4 = tidy_Rabcd (Xterm4)  # cdb(Xterm4.667,Xterm4)
   Xterm5 = tidy_Rabcd (Xterm5)  # cdb(Xterm5.667,Xterm5)

   # metric to 3rd, 4th, 5th and 6th order terms in powers of x^a

   Metric3 := @(Xterm0) + @(Xterm2).                                      # cdb (Metric3.301,Metric3)
   Metric4 := @(Xterm0) + @(Xterm2) + @(Xterm3).                          # cdb (Metric4.301,Metric4)
   Metric5 := @(Xterm0) + @(Xterm2) + @(Xterm3) + @(Xterm4).              # cdb (Metric5.301,Metric5)
   Metric6 := @(Xterm0) + @(Xterm2) + @(Xterm3) + @(Xterm4) + @(Xterm5).  # cdb (Metric6.301,Metric6)

   # ------------------------------------------------------------------------------------
   # end of format block
   # ------------------------------------------------------------------------------------

\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{term2.301} \end{dmath*}
   \begin{dmath*} \cdb*{term2.302} \end{dmath*}
   \begin{dmath*} \cdb*{term2.303} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term3.301} \end{dmath*}
   \begin{dmath*} \cdb*{term3.302} \end{dmath*}
   \begin{dmath*} \cdb*{term3.303} \end{dmath*}
   \begin{dmath*} \cdb*{term3.304} \end{dmath*}
   \begin{dmath*} \cdb*{term3.305} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term4.301} \end{dmath*}
   \begin{dmath*} \cdb*{term4.302} \end{dmath*}
   \begin{dmath*} \cdb*{term4.303} \end{dmath*}
   \begin{dmath*} \cdb*{term4.304} \end{dmath*}
   \begin{dmath*} \cdb*{term4.305} \end{dmath*}
   \begin{dmath*} \cdb*{term4.306} \end{dmath*}
   \begin{dmath*} \cdb*{term4.307} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} g_{ab}(x) = \cdb{Metric3.301} \end{dmath*}
   \begin{dmath*} g_{ab}(x) = \cdb{Metric4.301} \end{dmath*}
   \begin{dmath*} g_{ab}(x) = \cdb{Metric5.301} \end{dmath*}
   \begin{dmath*} g_{ab}(x) = \cdb{Metric6.301} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Stage 3: Replace partial derivs of $R$ with covariant derivs of $R$}

\begin{cadabra}
   beg_stage_3 = time.time()

   # now convert partial derivs of Rabcd to covariant derivs

   dRabcd01 = cdblib.get ('dRabcd01','dRabcd.json')  # cdb(dRabcd01.400,dRabcd01)
   dRabcd02 = cdblib.get ('dRabcd02','dRabcd.json')  # cdb(dRabcd02.400,dRabcd02)
   dRabcd03 = cdblib.get ('dRabcd03','dRabcd.json')  # cdb(dRabcd03.400,dRabcd03)

   # term1 & term2 need no special care, just a bit of tidying

   eliminate_metric (term1)   # cdb(term1.401,term1)
   sort_product     (term1)   # cdb(term1.402,term1)
   rename_dummies   (term1)   # cdb(term1.403,term1)
   canonicalise     (term1)   # cdb(term1.404,term1)

   eliminate_metric (term2)   # cdb(term2.401,term2)
   sort_product     (term2)   # cdb(term2.402,term2)
   rename_dummies   (term2)   # cdb(term2.403,term2)
   canonicalise     (term2)   # cdb(term2.404,term2)

   # replace partial derivatives of Riemann tensor in term3, term4 etc. with covariant derivatives of Rabcd

   tmp01 := @(dRabcd01).      # cdb(tmp01.403,tmp01)
   tmp02 := @(dRabcd02).      # cdb(tmp02.403,tmp02)
   tmp03 := @(dRabcd03).      # cdb(tmp03.403,tmp03)

   substitute (term3,$A^{c}A^{d}A^{e}\partial_{e}{R^{a}_{c d b}} ->   @(tmp01)$,repeat=True)         # cdb(term3.401,term3)
   substitute (term3,$A^{c}A^{d}A^{e}\partial_{e}{R^{a}_{c b d}} -> - @(tmp01)$,repeat=True)         # cdb(term3.402,term3)
   distribute (term3)                                                                                # cdb(term3.403,term3)

   substitute (term4,$A^{c}A^{d}A^{e}A^{f}\partial_{e f}{R^{a}_{c d b}} ->   @(tmp02)$,repeat=True)  # cdb(term4.401,term4)
   substitute (term4,$A^{c}A^{d}A^{e}A^{f}\partial_{e f}{R^{a}_{c b d}} -> - @(tmp02)$,repeat=True)  # cdb(term4.402,term4)
   substitute (term4,$A^{c}A^{d}A^{e}\partial_{e}{R^{a}_{c d b}} ->   @(tmp01)$,repeat=True)         # cdb(term4.403,term4)
   substitute (term4,$A^{c}A^{d}A^{e}\partial_{e}{R^{a}_{c b d}} -> - @(tmp01)$,repeat=True)         # cdb(term4.404,term4)
   distribute (term4)                                                                                # cdb(term4.405,term4)

   substitute (term5,$A^{c}A^{d}A^{e}A^{f}A^{g}\partial_{e f g}{R^{a}_{c d b}} ->   @(tmp03)$,repeat=True)
   substitute (term5,$A^{c}A^{d}A^{e}A^{f}A^{g}\partial_{e f g}{R^{a}_{c b d}} -> - @(tmp03)$,repeat=True)
   substitute (term5,$A^{c}A^{d}A^{e}A^{f}\partial_{e f}{R^{a}_{c d b}} ->   @(tmp02)$,repeat=True)
   substitute (term5,$A^{c}A^{d}A^{e}A^{f}\partial_{e f}{R^{a}_{c b d}} -> - @(tmp02)$,repeat=True)
   substitute (term5,$A^{c}A^{d}A^{e}\partial_{e}{R^{a}_{c d b}} ->   @(tmp01)$,repeat=True)
   substitute (term5,$A^{c}A^{d}A^{e}\partial_{e}{R^{a}_{c b d}} -> - @(tmp01)$,repeat=True)
   distribute (term5)

   end_stage_3 = time.time()
\end{cadabra}

\begin{dgroup*}
   \begin{dmath*} \cdb*{tmp01.403} \end{dmath*}
   \begin{dmath*} \cdb*{tmp02.403} \end{dmath*}
   \begin{dmath*} \cdb*{tmp03.403} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{term1.401} \end{dmath*}
   \begin{dmath*} \cdb*{term1.402} \end{dmath*}
   \begin{dmath*} \cdb*{term1.403} \end{dmath*}
   \begin{dmath*} \cdb*{term1.404} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term2.401} \end{dmath*}
   \begin{dmath*} \cdb*{term2.402} \end{dmath*}
   \begin{dmath*} \cdb*{term2.403} \end{dmath*}
   \begin{dmath*} \cdb*{term2.404} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term3.401} \end{dmath*}
   \begin{dmath*} \cdb*{term3.402} \end{dmath*}
   \begin{dmath*} \cdb*{term3.403} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term4.401} \end{dmath*}
   \begin{dmath*} \cdb*{term4.402} \end{dmath*}
   \begin{dmath*} \cdb*{term4.403} \end{dmath*}
   \begin{dmath*} \cdb*{term4.404} \end{dmath*}
   \begin{dmath*} \cdb*{term4.405} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Stage 4: Build the Taylor series for $g_{ab}$, reformatting and output}

\begin{cadabra}
   beg_stage_4 = time.time()
   # final housekeeping

   term1 = flatten_Rabcd (term1)         # cdb(term1.501,term1)
   term2 = flatten_Rabcd (term2)         # cdb(term2.501,term2)
   term3 = flatten_Rabcd (term3)         # cdb(term3.501,term3)
   term4 = flatten_Rabcd (term4)         # cdb(term4.501,term4)
   term5 = flatten_Rabcd (term5)         # cdb(term5.501,term5)

   eliminate_metric (term1)
   eliminate_metric (term2)
   eliminate_metric (term3)
   eliminate_metric (term4)
   eliminate_metric (term5)

   eliminate_kronecker (term1)
   eliminate_kronecker (term2)
   eliminate_kronecker (term3)
   eliminate_kronecker (term4)
   eliminate_kronecker (term5)

   sort_product (term1)
   sort_product (term2)
   sort_product (term3)
   sort_product (term4)
   sort_product (term5)

   rename_dummies (term1)
   rename_dummies (term2)
   rename_dummies (term3)
   rename_dummies (term4)
   rename_dummies (term5)

   canonicalise (term1)                  # cdb(term1.502,term1)
   canonicalise (term2)                  # cdb(term2.502,term2)
   canonicalise (term3)                  # cdb(term3.502,term3)
   canonicalise (term4)                  # cdb(term4.502,term4)
   canonicalise (term5)                  # cdb(term5.502,term5)

   # this is out final answer

   metric:=@(term0)
         + (1/1) @(term1)
         + (1/2) @(term2)
         + (1/6) @(term3)
         + (1/24) @(term4)
         + (1/120) @(term5).             # cdb(metric.501,metric)

   substitute (metric,$A^{a} -> x^{a}$)  # cdb (metric.502,metric)

   cdblib.create ('metric.json')

   cdblib.put ('g_ab',metric,'metric.json')

   # extract the terms of the metric in powers of x

   term0 = get_xterm (metric,0)          # cdb(term0.503,term0)
   term1 = get_xterm (metric,1)          # cdb(term1.503,term1)
   term2 = get_xterm (metric,2)          # cdb(term2.503,term2)
   term3 = get_xterm (metric,3)          # cdb(term3.503,term3)
   term4 = get_xterm (metric,4)          # cdb(term4.503,term4)
   term5 = get_xterm (metric,5)          # cdb(term5.503,term5)

   cdblib.put ('g_ab_0',term0,'metric.json')
   cdblib.put ('g_ab_1',term1,'metric.json')
   cdblib.put ('g_ab_2',term2,'metric.json')
   cdblib.put ('g_ab_3',term3,'metric.json')
   cdblib.put ('g_ab_4',term4,'metric.json')
   cdblib.put ('g_ab_5',term5,'metric.json')

   # this version of "metric" is used only in the commentary at the start of this notebook

   metric4:=@(term0) + @(term1) + @(term2) + @(term3).  # cdb(metric4.501,metric4)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{term2.501} \end{dmath*}
   \begin{dmath*} \cdb*{term2.502} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term3.501} \end{dmath*}
   \begin{dmath*} \cdb*{term3.502} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term4.501} \end{dmath*}
   \begin{dmath*} \cdb*{term4.502} \end{dmath*}
\end{dgroup*}

\begin{dgroup*}
   \begin{dmath*} \cdb*{term5.501} \end{dmath*}
   \begin{dmath*} \cdb*{term5.502} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{metric.501} \end{dmath*}
   \begin{dmath*} \cdb*{metric.502} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{term0.503} \end{dmath*}
   \begin{dmath*} \cdb*{term1.503} \end{dmath*}
   \begin{dmath*} \cdb*{term2.503} \end{dmath*}
   \begin{dmath*} \cdb*{term3.503} \end{dmath*}
   \begin{dmath*} \cdb*{term4.503} \end{dmath*}
   \begin{dmath*} \cdb*{term5.503} \end{dmath*}
\end{dgroup*}

% =================================================================================================
% the remaining code is just for pretty printing

\clearpage

\begin{cadabra}
   Xterm0 := @(term0).
   Xterm1 := @(term1).  # zero
   Xterm2 := @(term2).
   Xterm3 := @(term3).
   Xterm4 := @(term4).
   Xterm5 := @(term5).

   Xterm0 = reformat_xterm (Xterm0,  1)    # cdb(Xterm0.601,Xterm0)
   Xterm2 = reformat_xterm (Xterm2,  3)    # cdb(Xterm2.601,Xterm2)
   Xterm3 = reformat_xterm (Xterm3,  6)    # cdb(Xterm3.601,Xterm3)
   Xterm4 = reformat_xterm (Xterm4,180)    # cdb(Xterm4.601,Xterm4)
   Xterm5 = reformat_xterm (Xterm5, 90)    # cdb(Xterm5.601,Xterm5)

   gab3   := @(Xterm0) + @(Xterm2).                                      # cdb (gab3.601,gab3)
   gab4   := @(Xterm0) + @(Xterm2) + @(Xterm3).                          # cdb (gab4.601,gab4)
   gab5   := @(Xterm0) + @(Xterm2) + @(Xterm3) + @(Xterm4).              # cdb (gab5.601,gab5)
   gab6   := @(Xterm0) + @(Xterm2) + @(Xterm3) + @(Xterm4) + @(Xterm5).  # cdb (gab6.601,gab6)

   Metric := @(Xterm0) + @(Xterm2) + @(Xterm3) + @(Xterm4) + @(Xterm5).  # cdb (Metric.601,Metric)

   scaled0 = rescale_xterm (Xterm0,  1)    # cdb(scaled0.601,scaled0)
   scaled2 = rescale_xterm (Xterm2,  3)    # cdb(scaled2.601,scaled2)
   scaled3 = rescale_xterm (Xterm3,  6)    # cdb(scaled3.601,scaled3)
   scaled4 = rescale_xterm (Xterm4,180)    # cdb(scaled4.601,scaled4)
   scaled5 = rescale_xterm (Xterm5, 90)    # cdb(scaled5.601,scaled5)

   end_stage_4 = time.time()
\end{cadabra}

\clearpage

% =================================================================================================
\section*{The metric in Riemann normal coordinates}

\begin{dgroup*}
   \begin{dmath*} g_{a b}(x) = \cdb{Metric.601}+\BigO{\eps^6} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
\section*{Curvature expansion of the metric}
\begin{align*}
     g_{a b}(x) =
     \ngab{0}_{a b}
   + \ngab{2}_{a b}
   + \ngab{3}_{a b}
   + \ngab{4}_{a b}
   + \ngab{5}_{a b}+\BigO{\eps^6}
\end{align*}
\begin{dgroup*}
   \begin{dmath*}     \ngab{0}_{a b} = \cdb{scaled0.601} \end{dmath*}
   \begin{dmath*}   3 \ngab{2}_{a b} = \cdb{scaled2.601} \end{dmath*}
   \begin{dmath*}   6 \ngab{3}_{a b} = \cdb{scaled3.601} \end{dmath*}
   \begin{dmath*} 180 \ngab{4}_{a b} = \cdb{scaled4.601} \end{dmath*}
   \begin{dmath*}  90 \ngab{5}_{a b} = \cdb{scaled5.601} \end{dmath*}
\end{dgroup*}

\clearpage

% =================================================================================================
% export selected objects, these will later be imported into a library
% these are the objects that will appear in the paper

\begin{cadabra}
   cdblib.create ('metric.export')

   cdblib.put ('g_ab_3',Metric3,'metric.export')  # R and \partial R
   cdblib.put ('g_ab_4',Metric4,'metric.export')
   cdblib.put ('g_ab_5',Metric5,'metric.export')
   cdblib.put ('g_ab_6',Metric6,'metric.export')

   cdblib.put ('g_ab',  Metric, 'metric.export')  # R and \nabla R

   cdblib.put ('g_ab_scaled0',scaled0,'metric.export')
   cdblib.put ('g_ab_scaled2',scaled2,'metric.export')
   cdblib.put ('g_ab_scaled3',scaled3,'metric.export')
   cdblib.put ('g_ab_scaled4',scaled4,'metric.export')
   cdblib.put ('g_ab_scaled5',scaled5,'metric.export')

   checkpoint.append (Metric4)
   checkpoint.append (Metric6)

   checkpoint.append (Metric)

   checkpoint.append (scaled0)
   checkpoint.append (scaled2)
   checkpoint.append (scaled3)
   checkpoint.append (scaled4)
   checkpoint.append (scaled5)

   # cdbBeg (timing)
   print ("Stage 1: {:7.1f} secs\\hfill\\break".format(end_stage_1-beg_stage_1))
   print ("Stage 2: {:7.1f} secs\\hfill\\break".format(end_stage_2-beg_stage_2))
   print ("Stage 3: {:7.1f} secs\\hfill\\break".format(end_stage_3-beg_stage_3))
   print ("Stage 4: {:7.1f} secs".format(end_stage_4-beg_stage_4))
   # cdbEnd (timing)

\end{cadabra}

\clearpage

% =================================================================================================
\section*{Timing}

\cdb{timing}

% =================================================================================================
% export checkpoints in json format

\bgroup
\CdbSetup{action=hide}
\begin{cadabra}
   for i in range( len(checkpoint) ):
      cdblib.put ('check{:03d}'.format(i),checkpoint[i],checkpoint_file)
\end{cadabra}
\egroup

\end{document}


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

Let us continue with our discussion of the power spectrum: the \textbf{spectral index} \(n_s\) is defined as\footnote{Note that the dimensionless power spectrum is sometimes denoted as \(\Delta^2\) and sometimes as \(\Delta \): here (in this section) we use the latter definition.}
%
\begin{align}
n_s - 1 = \dv{\log \Delta (k)}{\log k}
\,.
\end{align}

The index \(s\) means ``scalar''.
In general this will depend on the wavenumber \(k\); it is a convenient description of the shape of the power spectrum.

If \(n_s\) were a constant, then we would have a \emph{powerlaw} spectrum: \(\Delta (k) = \Delta (k_0 ) (k / k_0 )^{n_s - 1}\).
If \(n_s = 1\), we have the \textbf{Harrison-Zel'dovich} power spectrum, for which \(\Delta \) does not depend on \(k\).
This would be a \emph{scale-invariant} power spectrum.

In a quantum-mechanical formalism, we will calculate the power spectrum as
%
\begin{align}
\bra{0} \delta \varphi _{\vec{k}_1} \delta \varphi _{\vec{k}_2}^{*} \ket{0}
\,,
\end{align}
%
which will be written in terms of creation and annihilation operators: we have
%
\begin{align}
\bra{0} a a \ket{0}=
\bra{0} a ^\dag a  \ket{0}=
\bra{0} a ^\dag a ^\dag \ket{0}= 0
\,,
\end{align}
%
while
%
\begin{align}
\bra{0} a a ^\dag \ket{0} &= \underbrace{\bra{0} \qty[a, a ^\dag] \ket{0}}_{ \delta^{(3)} (\vec{k}_1 - \vec{k}_2)} - \underbrace{\bra{0} a ^\dag a \ket{0}}_{= 0}
\,,
\end{align}
%
so
%
\begin{align}
\expval{ \delta \varphi _{\vec{k}_1} \delta \varphi _{\vec{k}_2}^{*}} = (2 \pi )^3 \abs{ \delta \varphi _{\vec{k}_1}}^2 \delta^3(\vec{k}_1 - \vec{k}_2)
\,,
\end{align}
%
where \(\delta \varphi _{k_1} = u_{k_1} / a\).
Therefore, the power spectrum is given by
%
\begin{align}
P(k) = \abs{ \delta \varphi _k}^2
\,.
\end{align}

Recall that in the superhorizon case we found
%
\begin{align}
\abs{ \delta \varphi _k} = \frac{H}{\sqrt{2 k^3}} \qty( \frac{k}{aH})^{3/2 - \nu }
\,,
\end{align}
%
where \(\nu^2 = 9/4 + 9 \epsilon - 3 \eta _V\), so \(\nu \approx 3/2 + 3\epsilon - \eta _V \), meaning that the index is \(3/2 - \nu = \eta _V - 3 \epsilon \).

Then, the power spectrum reads
%
\begin{align} \label{eq:scalar-field-power-spectrum}
\Delta_{ \delta \varphi }(k) = \frac{k^3}{2 \pi^2} \abs{ \delta \varphi _k}^2 = \qty( \frac{H}{2 \pi })^2 \qty( \frac{k}{aH})^{3-2\nu }
\,.
\end{align}
%
There will be a weak scale dependence proportional to the slow-roll parameters: \(3 - 2 \nu = 2 \eta _V - 6 \epsilon \).

\section{From \(\delta \varphi \) to primordial density perturbations}

The first Friedmann equation will read
%
\begin{align}
H^2 = \frac{8 \pi G}{3} \rho_\varphi  \approx \frac{8 \pi G}{3} V(\varphi )
\,,
\end{align}
%
so the density fluctuation can be written as
%
\begin{align}
\delta \rho _\varphi \approx V' (\varphi ) \delta \varphi \approx - 3 H \dot{\varphi} \delta \varphi
\marginnote{See equation \eqref{eq:approx-EOM-scalar-field-flat-FLRW}}
\,.
\end{align}

Recall that we can define a time shift \(\delta t = - \delta \varphi / \dot{\varphi} \).
This means that we will have perturbations in the expansion of the universe from place to place.

The number of \(e\)-folds is given by
%
\begin{align}
N = \log \qty( \frac{a(t)}{a (t_*)}) = \int_{t_*}^{t} H(\widetilde{t}) \dd{\widetilde{t}}
\,.
\end{align}

The fluctuations will perturb the number of \(e\)-folds by
%
\begin{align} \label{eq:delta-N-definition}
\zeta =
\delta N = H \delta t = - H \frac{ \delta \varphi }{\dot{\varphi}} \approx - H \frac{ \delta \rho _\varphi }{ \dot{\rho}_\varphi }
\,.
\end{align}

This is called the ``\(\delta N\) formalism'' for the study of large-scale perturbations.
The last equality in \eqref{eq:delta-N-definition} comes from the fact that
%
\begin{align}
\dot{\rho}_\varphi = - 3H \qty(\rho _\varphi + P_\varphi ) = - 3 H \dot{\varphi}^2
\marginnote{From equation \eqref{eq:energy-momentum-scalar-field}.}
\,,
\end{align}
%
so indeed
%
\begin{align}
H \frac{ \delta \rho _\varphi }{\dot{\rho}_\varphi }
= \frac{- 3 H^2 \dot{\varphi}  \delta \varphi }{-3 H \dot{\varphi}^2}
= H \frac{ \delta \varphi }{\dot{\varphi}}
\,.
\end{align}

The quantity \(\delta N = \zeta\) is \textbf{gauge invariant}. It is written as
%
\begin{align}
\zeta = - \hat{\Phi} - H \frac{ \delta \rho }{\dot{\rho} }
\,,
\end{align}
%
where \(\hat{\Phi}\) is related to scalar perturbations  of the spatial part of the metric, \(g_{ij}\). We shall explore this later.

This \(\zeta\) is called the \textbf{curvature perturbation on uniform energy density hypersurfaces}.
Why did we write this with \(\rho \) instead of \(\rho _\varphi \)? This definition is completely general; it can be applied at any time and for a generic evolution of the universe.
We can then specify it to
%
\begin{align}
\zeta_\varphi \approx - H \frac{ \delta \rho _\varphi }{\dot{\rho}_\varphi }
\,.
\end{align}

What we will show is that on superhorizon scales \(\zeta\) remains constant (for single-field inflation, at least).
Therefore, this keeps a sort of ``record'' of what happened after horizon crossing.

Let us denote as \(t^{(1)}_H(k)\) the time of horizon crossing during inflation for perturbations with wavenumber \(k\), and \(t^{(2)}_H(k)\) the time \emph{after inflation} of the second horizon crossing, when the perturbation comes back inside the horizon.
The value of \(\zeta \) at these two times will be the same (again, as long as we are considering a single-field model of inflation).
% \todo[inline]{This can be seen since\dots}

We know that \(\delta \varphi \sim H / 2 \pi \) (statistically), and \(H^2 \approx 8 \pi G V(\varphi ) /3\): then, specifying the potential gives a prediction for the power spectrum.

Suppose that the perturbation re-enters during the radiation-dominated epoch. Then,
%
\begin{align}
H \frac{ \delta \rho }{\dot{\rho} } \approx \frac{H \delta \rho _\gamma }{-4 H \rho _\gamma } = - \frac{1}{4}\frac{ \delta \rho _\gamma }{\rho _\gamma }
\,,
\end{align}
%
since
%
\begin{align}
\dot{\rho} = \dv{\rho }{a} \dot{a} = \frac{\rho}{a} \dv{\log \rho }{\log a} \dot{a} = \frac{\rho}{a} (-4) \dot{a} = - 4 \rho H
\,.
\end{align}

On the other hand, at the first horizon crossing \(\zeta = \delta N = - (H / \dot{\varphi}) \delta \varphi \), therefore the dimensionless power spectrum at the second horizon crossing can be referred back to the first as
%
\begin{align}
\Delta_{ \delta \rho / \rho } (k)=
\eval{\frac{H^2}{ \dot{\varphi}^2} \Delta_{ \delta \varphi } (k)}_{t^{(1)}_H (k)}
\,,
\end{align}
%
and
%
\begin{align}
\Delta_{ \delta \varphi } (k) = \qty( \frac{H}{ 2 \pi })^2 \qty(\frac{k}{aH})^{3-2 \nu }
\,.
\end{align}

\end{document}


%%
%% This is file `sampleEqPg.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% glossary.dtx  (with options: `sampleEqPg.tex,package')
%% Copyright (C) 2006 Nicola Talbot, all rights reserved.
%% If you modify this file, you must change its name first.
%% You are NOT ALLOWED to distribute this file alone. You are NOT
%% ALLOWED to take money for the distribution or use of either this
%% file or a changed version, except for a nominal charge for copying
%% etc.
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\documentclass[a4paper,12pt]{report}

\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage[header,toc,border=none,cols=3,
            number=equation]{glossary}[2006/07/20]

\newcommand{\erf}{\operatorname{erf}}
\newcommand{\erfc}{\operatorname{erfc}}

\renewcommand{\glossaryname}{Index of Special Functions and Notations}

\renewcommand{\glossarypreamble}{Numbers in italic indicate the equation number,
numbers in bold indicate page numbers where the main definition occurs.\par}

\setglossary{glsnumformat=hyperit}

\renewcommand{\entryname}{Notation}

\renewcommand{\descriptionname}{Function Name}

\newcommand{\glossarysubheader}{ & & \\}

\storeglosentry{Gamma}{name=\ensuremath{\Gamma(z)},
description=Gamma function,sort=Gamma}

\storeglosentry{gamma}{name=\ensuremath{\gamma(\alpha,x)},
description=Incomplete gamma function,sort=gamma}

\storeglosentry{iGamma}{name=\ensuremath{\Gamma(\alpha,x)},
description=Incomplete gamma function,sort=Gamma}

\storeglosentry{psi}{name=\ensuremath{\psi(x)},
description=Psi function,sort=psi}

\storeglosentry{erf}{name=\ensuremath{\erf(x)},
description=Error function,sort=erf}

\storeglosentry{erfc}{name=\ensuremath{\erfc(x)},
description=Complementary error function,sort=erfc}

\storeglosentry{beta}{name=\ensuremath{B(x,y)},
description=Beta function,sort=B}

\storeglosentry{Bx}{name=\ensuremath{B_x(p,q)},
description=Incomplete beta function,sort=Bx}

\storeglosentry{Tn}{name=\ensuremath{T_n(x)},
description=Chebyshev's polynomials of the first kind,
sort=Tn}

\storeglosentry{Un}{name=\ensuremath{U_n(x)},
description=Chebyshev's polynomials of the second kind,
sort=Un}

\storeglosentry{Hn}{name=\ensuremath{H_n(x)},
description=Hermite polynomials,sort=Hn}

\storeglosentry{Lna}{name=\ensuremath{L_n^\alpha(x)},
description=Laguerre polynomials,sort=Lna}

\storeglosentry{Znu}{name=\ensuremath{Z_\nu(z)},
description=Bessel functions,sort=Z}

\storeglosentry{Pagz}{name=\ensuremath{\Phi(\alpha,\gamma;z)},
description=confluent hypergeometric function,sort=Pagz}

\storeglosentry{kv}{name=\ensuremath{k_\nu(x)},
description=Bateman's function,sort=kv}

\storeglosentry{Dp}{name=\ensuremath{D_p(z)},
description=Parabolic cylinder functions,sort=Dp}

\storeglosentry{Fpk}{name=\ensuremath{F(\phi,k)},
description=Elliptical integral of the first kind,sort=Fpk}

\storeglosentry{C}{name=\ensuremath{C},
description=Euler's constant,sort=C}

\storeglosentry{G}{name=\ensuremath{G},
description=Catalan's constant,sort=G}

\renewcommand{\shortglossaryname}{Special Functions}

\makeglossary

\pagestyle{headings}

\begin{document}

\title{Sample Document Using Interchangable Numbering}
\author{Nicola Talbot}
\maketitle

\begin{abstract}
This is a sample document illustrating the use of the \textsf{glossary}
package.  The functions here have been taken from ``Tables of
Integrals, Series, and Products'' by I.S.~Gradshteyn and I.M~Ryzhik.

The glossary lists both page numbers and equation numbers.
Since the majority of the entries use the equation number,
\texttt{number=equation} was used as a package option.
The entries that should refer to the page number instead
use the \texttt{number=equation} glossary key.
Note that this example will only work where the
page number and equation number compositor is the same. So
it won't work if, say, the page numbers are of the form
2-4 and the equation numbers are of the form 4.6.
As most of the glossary entries should have an italic
format, it is easiest to set the default format to
italic.

\end{abstract}

\tableofcontents

\printglossary

\chapter{Gamma Functions}

The \useGlosentry[number=page,format=hyperbf]{Gamma}{gamma function} is
defined as
\begin{equation}
\gls{Gamma} = \int_{0}^{\infty}e^{-t}t^{z-1}\,dt
\end{equation}

\begin{equation}
\useGlosentry{Gamma}{\ensuremath{\Gamma(x+1)}} = x\Gamma(x)
\end{equation}

\begin{equation}
\gls{gamma} = \int_0^x e^{-t}t^{\alpha-1}\,dt
\end{equation}

\begin{equation}
\gls{iGamma} = \int_x^\infty e^{-t}t^{\alpha-1}\,dt
\end{equation}

\newpage

\begin{equation}
\useGlosentry{Gamma}{\ensuremath{\Gamma(\alpha)}} = \Gamma(\alpha, x) + \gamma(\alpha, x)
\end{equation}

\begin{equation}
\gls{psi} = \frac{d}{dx}\ln\Gamma(x)
\end{equation}

\chapter{Error Functions}

The \useGlosentry[number=page,format=hyperbf]{erf}{error
function} is defined as:
\begin{equation}
\gls{erf} = \frac{2}{\surd\pi}\int_0^x e^{-t^2}\,dt
\end{equation}

\begin{equation}
\gls{erfc} = 1 - \erf(x)
\end{equation}

\chapter{Beta Function}

\begin{equation}
\gls{beta} = 2\int_0^1 t^{x-1}(1-t^2)^{y-1}\,dt
\end{equation}
Alternatively:
\begin{equation}
\gls{beta} = 2\int_0^{\frac\pi2}\sin^{2x-1}\phi\cos^{2y-1}\phi\,d\phi
\end{equation}

\begin{equation}
\gls{beta} = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)} = B(y,x)
\end{equation}

\begin{equation}
\gls{Bx} = \int_0^x t^{p-1}(1-t)^{q-1}\,dt
\end{equation}

\chapter{Chebyshev's polynomials}

\begin{equation}
\gls{Tn} = \cos(n\arccos x)
\end{equation}

\begin{equation}
\gls{Un} = \frac{\sin[(n+1)\arccos x]}{\sin[\arccos x]}
\end{equation}

\chapter{Hermite polynomials}

\begin{equation}
\gls{Hn} = (-1)^n e^{x^2} \frac{d^n}{dx^n}(e^{-x^2})
\end{equation}

\chapter{Laguerre polynomials}

\begin{equation}
\gls{Lna} = \frac{1}{n!}e^x x^{-\alpha}
\frac{d^n}{dx^n}(e^{-x}x^{n+\alpha})
\end{equation}

\chapter{Bessel Functions}

Bessel functions $Z_\nu(z)$ are solutions of
\begin{equation}
\frac{d^2Z_\nu}{dz^2} + \frac{1}{z}\,\frac{dZ_\nu}{dz} +
\left(
1-\frac{\nu^2}{z^2}Z_\nu = 0
\right)
\end{equation}
\useglosentry{Znu}

\chapter{Confluent hypergeometric function}

\begin{equation}
\gls{Pagz} = 1 + \frac{\alpha}{\gamma}\,\frac{z}{1!}
+ \frac{\alpha(\alpha+1)}{\gamma(\gamma+1)}\,\frac{z^2}{2!}
+\frac{\alpha(\alpha+1)(\alpha+2)}
      {\gamma(\gamma+1)(\gamma+2)}
\,\frac{z^3}{3!}
+ \cdots
\end{equation}

\begin{equation}
\gls{kv} = \frac{2}{\pi}\int_0^{\pi/2}
\cos(x \tan\theta - \nu\theta)\,d\theta
\end{equation}

\chapter{Parabolic cylinder functions}

\begin{equation}
\gls{Dp} = 2^{\frac{p}{2}}e^{-\frac{z^2}{4}}
\left\{
\frac{\surd\pi}{\Gamma\left(\frac{1-p}{2}\right)}
\Phi\left(-\frac{p}{2},\frac{1}{2};\frac{z^2}{2}\right)
-\frac{\sqrt{2\pi}z}{\Gamma\left(-\frac{p}{2}\right)}
\Phi\left(\frac{1-p}{2},\frac{3}{2};\frac{z^2}{2}\right)
\right\}
\end{equation}

\chapter{Elliptical Integral of the First Kind}

\begin{equation}
\gls{Fpk} = \int_0^\phi
\frac{d\alpha}{\sqrt{1-k^2\sin^2\alpha}}
\end{equation}

\chapter{Constants}

\begin{equation}
\gls{C} = 0.577\,215\,664\,901\ldots
\end{equation}

\begin{equation}
\gls{G} = 0.915\,965\,594\ldots
\end{equation}

\end{document}
\endinput
%%
%% End of file `sampleEqPg.tex'.


\subsection{\ystar\ cut Optimization}
\label{section:ystarCutOptimization}

%\todo[inline]{ Clean up formulae. }

In QCD two-to-two scattering, $t$-channel is dominant. The QCD dijet production is proportional to
$\displaystyle{(1-\cos\theta^{*})^{-2}}$, while $H^\prime$ and String production is expected to be flat in
$\cos\theta^{*}$. This means that \ystar\  of QCD background will minimize at 0 and that of $H^\prime$
and String will peak at 0.

The significance is given by
\begin{equation}
\label{eq:signifcanceYstar} % uncomment if label used.
S  = \sqrt{\sum_{i}{2\left[ \left(S_{i}+B_{i} \right)\cdot \ln \left(1+\frac{S_{i}}{B_{i}}\right)-S_{i}\right]}}
\end{equation}
where $S_i$ ($B_i$) is the number of signal (background) events in bin $i$.
For each of the signal samples 95\% of the area under the distribution is
calculated and only those bins are used to calculate the significance. %, not the entire \mjj\ distribution.
Figure \ref{fig: hprime significance as a function of y* cut} shows the $H^\prime$ signal significance as a function
of the value of the \ystar\  cut. The significance peaks  around 0.6, so the optimal $y^{*}$ cut for the $H'$ search is
$|\ystar| < 0.6$.

Figure \ref{fig: string significance as a function of y* cut} shows the String signal significance as a function of \ystar\ cut. The significance peaks at  0.8, so the optimal  cut for the String search is $|\ystar| < 0.8$.

\begin{figure}[htbp]
        \centering
        \subfigure[$\geq$1 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/yStarOptimization/Significance_Hprime_gj.pdf}}
        \subfigure[2 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/yStarOptimization/Significance_Hprime_gg.pdf}}
        \caption{$H^\prime$ significance as a function \ystar\ cut in the case of (a) $\geq$1 g-tag, (b) 2 g-tag.}
        \label{fig: hprime significance as a function of y* cut}
\end{figure}

Table~\ref{tab:ystarstring} shows the \ystar\ cut leading to the maximum significance value for each of the String masses.
Figure \ref{fig: string significance as a function of y* cut} shows the String signal significance as a function of \ystar\ cut. The significance peaks at  0.8, so the optimal  cut for the String search is $|\ystar| < 0.8$.

\begin{table}[htbp]
\begin{center}
\begin{tabular}{SSSS}
\toprule
\multicolumn{1}{c}{String Mass (\TeV) } & \multicolumn{3}{c}{Optimal Selection} \\
& \multicolumn{1}{c|}{Inclusive} & \multicolumn{1}{c|}{$\geq1$ $g$ tag} & \multicolumn{1}{c}{2 $g$ tag} \\
\midrule
7.0 & 0.75 & 0.80 & 0.85 \\
7.5 & 0.75 & 0.80 & 0.85 \\
8.0 & 0.75 & 0.75 & 0.85 \\
9.5 & 0.70 & 0.75 & 0.80 \\
9.0 & 0.70 & 0.75 & 0.70 \\
\bottomrule
\end{tabular}
\end{center}
\caption{$|y^*|$ selection leading to the maximum significance value calculated using Equation~\ref{eq:signifcanceYstar}.}\label{tab:ystarstring}
\end{table}

\begin{figure}[htbp]
        \centering
        \subfigure[$\geq$1 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/yStarOptimization/Significance_String_gj.pdf}}
        \subfigure[2 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/yStarOptimization/Significance_String_gg.pdf}}
        \caption{String significance as a function \ystar\ cut in the case of (a) $\geq$1 g-tag, (b) 2 g-tag.}
        \label{fig: string significance as a function of y* cut}
\end{figure}

\subsection{dijet mass turn-on}
\label{section:dijetmassturn-on} % uncomment if label used.

The \mjj\ turn-on is measured using data by comparing events collected with the highest \pT\
trigger with one with a lower \pt\ threshold.  The efficiency for the HLT\_j420 trigger is calculated by comparing to the
following triggers in each data taking period: 2015 HLT\_j360, 2016 HLT\_j380, 2017 and 2018 HLT\_mu50. We use a muon trigger
2017 and 2018 as HLT\_j420 is the only unprescaled jet trigger available. Since the HLT\_mu50 is available for all running periods
a comparison is made for the complete Run~2 data set.
A mass cut will be applied to remove events where
the trigger efficiency is less than 99.5\%.

Figure \ref{fig: mass turn-on yStar 0.6} shows the efficiencies as a function of \mjj\ for $|\ystar|<0.6$ in
two g-tag regions for both triggers.  The results
are summarised for data taking periods in Table~\ref{table:massTurnOns} and shown for the full Run~2 data
taking period in Figures \ref{fig: mass turn-on yStar 0.6} and \ref{fig: mass turn-on yStar 0.8}. The detailed results for
each year are added to the Appendix~\ref{section:triggerturnon}.

The \mjj\ mass has been chosend to be slightly above th e value of the plateau ($\geq$99.5\%) and is 1100\,\GeV.
for $|\ystar|<0.6$ and 1200\,\GeV for $|\ystar|<0.6$ for samples with either one or two gluon tags.

\begin{table}[h]
	\centering
		\caption{ The \mjj\ value of the plateau ($\geq$99.5\%) for each period of data taking.
		\label{table:massTurnOns}
		}
	\begin{tabular}{SSSSS}
	\toprule
\multicolumn{1}{c}{Data Taking Period}  &  \multicolumn{2}{c}{Mass turn on $|\ystar|<0.6$ } &  \multicolumn{2}{c}{Mass turn on $|\ystar|<0.8$ } \\
 & \multicolumn{1}{c}{$\geq$1 g-tag (\GeV )} &  \multicolumn{1}{c}{2 g-tag (\GeV )}
 & \multicolumn{1}{c}{$\geq$1 g-tag (\GeV )} &  \multicolumn{1}{c}{2 g-tag (\GeV )}  \\
\midrule
2015  & 1040 & 1030 & 1160 & 1160 \\
2016  & 1030 & 1030 & 1160 & 1170 \\
2017  & 990 & 1000  & 1110 & 1120 \\
2018  & 1000 & 1010  & 1110 & 1120 \\
\multicolumn{1}{c}{Run~2} & 1020 & 1030 & 1120 & 1120 \\
\bottomrule
\end{tabular}
\end{table}

\begin{figure}[htbp]
        \centering
        \subfigure[$\geq$1 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p6/mjj_turnon_1gluonTag_yStar0p6}}
        \subfigure[2 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p6/mjj_turnon_2gluonTag_yStar0p6}}
        \\
        \subfigure[$\geq$1 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p6/Ratio_mjj_turnon_1gluonTag_yStar0p6}}
        \subfigure[2 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p6/Ratio_mjj_turnon_2gluonTag_yStar0p6}}

        \caption{Efficiencies as a function of \mjj\ for $|\ystar|<0.6$ using HLT\_j420 compared with HLT\_mu50 in the case of comparison of mass spectra with
        (a) $\geq$1 g-tag, (b) 2 g-tag and the ratio between the two (c) $\geq$1 g-tag and (d) 2 g-tag.}
        \label{fig: mass turn-on yStar 0.6}
\end{figure}

\begin{figure}[htbp]
        \centering
        \subfigure[$\geq$1 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p8/mjj_turnon_1gluonTag_yStar0p8}}
        \subfigure[2 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p8/mjj_turnon_2gluonTag_yStar0p8}}
        \\
        \subfigure[$\geq$1 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p8/Ratio_mjj_turnon_1gluonTag_yStar0p8}}
        \subfigure[2 g-tag]{\includegraphics[width=0.48\columnwidth]{figures/massturnon/yStar0p8/Ratio_mjj_turnon_2gluonTag_yStar0p8}}
        \caption{Efficiencies as a function of \mjj\ for $|\ystar|<0.8$ using HLT\_j420 compared with HLT\_mu50 in the case of comparison of mass spectra with
        (a) $\geq$1 g-tag, (b) 2 g-tag and the ratio between the two (c) $\geq$1 g-tag and (d) 2 g-tag.}
        \label{fig: mass turn-on yStar 0.8}
\end{figure}

\subsection{Optimised selection}

In addition to the baseline selection cuts described in Section~\ref{sec:base_selection},
the following cuts are applied to different regions to optimize the
search potential and to ensure good tracking efficiency.

The following additional cuts are applied to the H$^\prime$ search.
\begin{itemize}
\item $|\ystar| < 0.6$
\item $\mjj > 1100\,\GeV$
\end{itemize}

The following additional cuts are applied to the string resonance search.
\begin{itemize}
\item $|\ystar| < 0.8$
\item $\mjj > 1200\,\GeV$
\end{itemize}

The above cuts define the inclusive samples.
The following additional cuts are for quark-gluon tagging.
\begin{itemize}
\item $|\eta| < 2.1$ (both jets)
\item $\ge 1$ gluon tagged (75\% working point)
\item 2 gluons tagged (75\% working point)
\end{itemize}

\noindent
where the 75\% gluon selection criteria is $n_\mathrm{track} > -7.3 + 4.2\ln(\pt)$.

The cutflow tables obtained on full
Run-2 data are presented in Table~\ref{tab:data1518totalcutflow} in Appendix~\ref{section:cutflow}, where as Tables~\ref{tab:data2015cutflow}-~\ref{tab:data2018cutflow} presents the cutflow separately for each year between 2015-2018.
The tables ~\ref{tab:bckgdcutflowMC16aWeighted} - ~\ref{tab:bckgdcutflowMC16eWeighted} in Appendix~\ref{section:cutflow} shows the cutflows
obtained on Pythia QCD MC separated into campaigns MC16a, MC16d and MC16e. The numbers shown in these tables
are weighted events normalised to the luminosity corresponding to each subcampaign.

\subsection{Basic kinematic plots}
%\label{sec:kinematic_distributions} % uncomment if label used.

\subsection{Gluon-Gluon Data Selection}

In this section a selection of kinematic and monitoring plots produced with the gluon-gluon sample selection on the full dataset is shown
(Figures~\ref{fig:GGmonitoring1}, \ref{fig:GGmonitoring2}, \ref{fig:GGmonitoring3}.

\begin{figure}[htb]
 \centering
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_HT_logY_v01.pdf}}
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_NPV_logY_v01.pdf}}
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_averageInteractionsPerCrossing_logY_v01.pdf}}
  \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_njets_logY_v01.pdf}}
 \caption{Monitoring plots on %2016 data,
 the gluon-gluon sample. (a) $H_T$, %(b) $MH_T$ (missing transverse momentum calculated only from the jets in the event),
 (b) number of primary interaction vertices,
 (c) average interactions per bunch crossing, and
 (d) number of jets.}
 \label{fig:GGmonitoring1}
\end{figure}

 \begin{figure}[htb]
 \centering
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_deltaPhi_logY_v01.pdf}}
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_jet_eta_logY_v01.pdf}}
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_jet_phi_logY_v01.pdf}}
  \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_jet_rapidity_logY_v01.pdf}}
 %
  \caption{Monitoring plots on  the gluon-gluon sample.
  (a) $\Delta\phi$ between the two jets,
  (b) jet $\eta$,
  (c) jet $\phi$, and
  (d)  jet rapidity.  %Fluctuations in the jet $phi$ distribution are attributable to dead modules in the tile calorimeter which lead to fewer jets in small slices of the detector.
  }
 \label{fig:GGmonitoring2}
\end{figure}

 \begin{figure}[htb]
 \centering
 %
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_jet_pt_logY_v01.pdf}}

 %
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_yBoost_logY_v01.pdf}}
 \subfigure[] {\includegraphics[width=0.45\textwidth]{figures/monitoring/GG/newStudy_yStar_logY_v01.pdf}}
 \caption{Monitoring plots on  the gluon-gluon sample.
 (a) jet \pt,
  (b) \yB{}, and
  (c) \ystar{}. }
 \label{fig:GGmonitoring3}
\end{figure}

\clearpage


\documentclass{article}
\usepackage{hyperref}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{color}
\usepackage[section]{placeins}
\usepackage{listings}

\title{Combustion Theory Final Take Home Exam}
\author{Nicholas Malaya\\ Department of Mechanical Engineering \\
University of Texas at Austin}
\date{}

\begin{document}
\maketitle
\newpage

\section*{Turbulent diffusion flames}

In this problem, I want you to assume that the system is turbulent and
that you know the turbulence mass diffusivity ($D_T$) is 10 times the
laminar value. Assume that the fluctuation squared of the mixture
fraction is equal to the gradient of the mean mixture fraction squared
multiplied by the characteristic diffusion length scale squared, i.e.
\begin{equation}
 \bar{z'z'} = \frac{1}{2} (\nabla \bar z)^2 \frac{D_T L_x}{u}
\end{equation}

\subsection*{a) Write down the solution for the mean mixture fraction
field with the turbulent diffusivity.}

We start with the steady state species equation,
\begin{equation}
 \rho u \frac{\partial Y_i}{\partial x} = \rho D \frac{\partial^2
  Y_i}{\partial y^2} \pm \omega_i.
\end{equation}
We note that,
\begin{equation}
 \omega = \frac{\omega_i}{\nu_i W_i} = \frac{\omega_F}{\nu_F W_F} =
  \frac{\omega_O}{\nu_O W_O}.
\end{equation}
This hints at a conserved scalar form of the species equation, where
with,
\begin{equation}
 \beta  = \frac{\omega_F}{\nu_F W_F} - \frac{\omega_O}{\nu_O W_O}
\end{equation}
then our reaction is decoupled from the convection-diffusion of a
conserved scalar quantity. In particular,
\begin{equation}
 \mathcal{L}(\beta)  = \mathcal{L}\left(\frac{\omega_F}{\nu_F W_F} -
				   \frac{\omega_O}{\nu_O W_O} \right)
 \Rightarrow \rho u \frac{\partial \beta_i}{\partial x} - \rho D \frac{\partial^2
  \beta_i}{\partial y^2} = 0.
\end{equation}
Now, we construct z,
\begin{equation}
 z = \frac{\beta -\beta_{O}}{\beta_F - \beta_{O}}
\end{equation}
Here, the boundary conditions are that $z=1$ for all $y>0$ and $x<0$
(e.g. the fuel reserve) and $z=0$ for $y<0$ and $x<0$ (e.g. the oxygen
reserve).

Thus, we are solving,
\begin{equation}
\rho u \frac{\partial z}{\partial x} - \rho D \frac{\partial^2
  z}{\partial y^2} = 0.
\end{equation}
and,
\begin{equation}
\rho u \frac{\partial \bar z}{\partial x} - \rho D_T \frac{\partial^2
  \bar z}{\partial y^2} = 0.
\end{equation}
Where the first equation is from the laminar flow, and the latter case
is the favre-averaged mean field. We now need to discretize this
equation, in order to solve it numerically (It looks like it would be a
trainwreck to solve analytically!). We will completely wimp out, and
only use finite difference methods,
\begin{align}
  \frac{\partial \bar z}{\partial x} &= \frac{\bar z_{i+1}-\bar z_{i}}{\Delta x} \\
  \label{first}
  \frac{\partial^2 \bar z}{\partial y^2} &= \frac{\bar z_{j+1}-2\bar z_{j}+\bar z_{j-1}}{\Delta y^2}
\end{align}
The boundary conditions are $\bar z = 1$ $\forall x<0,y>0$, $\bar z = 0$
$\forall x<0,y<0$. I additionally imposed a Neuman (zero flux) boundary
condition on the top and bottom of the box, essentially forcing the
derivatives to zero at $\pm \infty$. As with the previous examination,
we are now in a position to instantiate this on a computer using python
to solve for the $\bar z(x,y)$ field.

As an interesting implementation detail, because the solution is only
first order in x, we only need one boundary condition for that
direction, as shown above. This is equivalent to an initial condition on
a first order (in time) ODE. Thus, we do not actually need to store our
entire x-domain in memory, but can simply solve for all y-values at our
particular x-coordinate, and then step forward in space and solve for
the next grid location.

%
%
%
%
\subsection*{b) Plot the fluctuation and mean value of the mixture
fraction at 5 cm, 30 cm, and 50 cm.}

  \begin{figure}[!htb]
   \begin{center}
    \includegraphics[width = 12 cm]{figs/mean.pdf}
    \caption{The mixture fraction plotted as a function of y.}
    \label{mean}
   \end{center}
   \end{figure}

The method to arrive at the mean value mixture fraction was described
above. The value of the mixture fraction at several locations is plotted
in figure \ref{mean}. The flow at $x=0$ cm is a sharp interface between
the fuel and the oxidizer. As you move downstream, the fuel and oxidants
mix, which will create a mixing layer that diffuses out and increases in
y-width as a function of distance downstream.

The fluctuation $\bar{z'z'}$
must also be determined. Normally, this would require solving another
differential equation, and potentially using submodels for the scalar
dissipation rate as well. However, we were given a simplified expression
(model) for the variance, namely,
\begin{equation}
 \bar{z'z'} = \frac{1}{2} (\nabla \bar z)^2 \frac{D_T L_x}{u}.
\end{equation}
Variations in y will be much larger than variations in x, and this
expression
can be simplified to be,
\begin{equation}
 \bar{z'z'} = \frac{1}{2} (\frac{\partial \bar z}{\partial y})^2 \frac{D_T L_x}{u}.
 \label{fluc}
\end{equation}
This expression is a model for the variance of the mixture
fraction. Intuitively, this expression is reasonable,  as we expect the
variance (in some sense, our uncertainty) of the value of the mixture
fraction to be largest in regions with large gradients. In the mixing
layer, the gradient will be quite large near the layer ($y=0,x=0$) and expanding outward  at larger x.

We discretize equation \ref{fluc} using the finite difference scheme
shown in equation \ref{first}, however, now the indicies are changed
from i to j, to reflect the different direction of the
derivative. However, upon running the code, I found that a forward
finite difference was very numerically noisy for the solution at $x=5$
cm. This was because the interface at this distance is still quite
sharp, and so squaring the derivative ``blew-up'' the noise. I therefore
switched a centered finite difference scheme, namely:
\begin{equation}
  \frac{\partial \bar z}{\partial y} = \frac{\bar z_{i+1}-\bar z_{i-1}}{2\Delta y}.
\end{equation}

  \begin{figure}[!htb]
   \begin{center}
    \includegraphics[width = 12 cm]{figs/fluc.pdf}
    \caption{The mixture fraction variance plotted as a function of y.}
    \label{fluc}
   \end{center}
  \end{figure}

The results are plotted in figure \ref{fluc}. The results of this figure
display that at anything but low values of x, the variance is nearly
zero. It is only near the sharp interface that the flow is
turbulent. Outside of just a few centimeters, the variance is very
nearly zero, implying essentially laminar flow. As we move downstream,
the pdf opens up, as the mixing layer grows and entrains more fluid
around it. The peak also grows, implying that the turbulence grows to a
higher reynolds number, with larger fluctuations.

%
%
%
%
\subsection*{c) Plot the PDF of the mixture fraction at two points, $y=0$ cm,
$x=30$ and at $y=15$ cm, $x=30$ cm.}

$P(z) =$ probability of z in $z+\Delta z$. If we knew the joint
probability density function we could calculate it directly. However, we
don't know P() (the PDF). Instead, we will use  what Peters calls the
``Presumed Shape PDF Approach''. We must pick a probability
distribution. We are limited to two parameter distributions for the
model to be closed, because we only possess  $\bar z$ and
$\bar{z'z'}$. Essentially, our choice is between a clipped Gaussian and
the Beta  function distribution. We will use the Beta distribution, as
it should have much more appropriate  limit behavior for the mixing
layer. In particular, due to the effect of intermittency, we expect the
edges of the mixing layer to act like a delta function. This effect can
be captured by the Beta distribution. The distribution function pdf has
the form,
\begin{equation}
P(\bar z) = \frac{\bar z^{\alpha-1}(1-\bar z)^{\beta-1}}{\Gamma(\alpha)\Gamma(\beta)}\Gamma(\alpha + \beta)
\end{equation}
We further define,
\begin{align}
\alpha &= \bar z \gamma \\
\beta  &= (1-\bar z) \gamma
\end{align}
Where the variable $\gamma$ is defined as,
\begin{equation}
  \gamma = \frac{\bar z (1-\bar z)}{\bar{z'z'}^2} -1 \geq 0.
\end{equation}

For the two locations, we can already predict what the distributions
will look like. The first, at $y=0$, will be roughly gaussian, with a
mean centered around the expected value of the mixture fraction at that
location. Given that we expect the mixture fraction to be one half at that
location, the mean should be around that value as well. For the location
off-center, we expect a distribution that is skewed towards the side
with more fuel or oxidizer. This is the oxidizer side, so we expect the
mixture fraction pdf to have a mean less than zero. Furthermore, we note
from figure \ref{mean} that this is far away from the mixing layer. We
expect there to be essentially no mixing this far away, and therefore,
the distribution should be essentially completely oxidizer, e.g. a
distribution very sharply pushed up against zero.

  \begin{figure}[!htb]
   \begin{center}
    \includegraphics[width = 12 cm]{figs/pdf.pdf}
    \caption{The distribution of the mixture fraction, using the assumed
    pdf approach (with an assumed $\beta$ distribution). The green line
    on the right is at $x=30,y=0$, and the blue distribution is at $x=30,y=15$.}
    \label{pdf}
   \end{center}
  \end{figure}

The results of this when instantiated numerically are shown in figure
\ref{pdf}. The results are precisely what we expected. The distribution
at $x=30,y=0$ is not exactly at 0.5, but it is nearly so (0.53). The
distribution is not skewed to either the fuel or oxidizer side.
I expect that this is accurate.
One might note
that the beta distribution, despite how sharp it is near zero, is still
giving non-trivial weight to less than zero mixture
fractions. Personally, I am skeptical this is not an over-estimate, and
it is likely a weakness of the assumed beta distribution for this edge
case. However, note that assuming a Gaussian pdf would break down even
more severely in this case.

%
%
%
%
\subsection*{d) Plot the laminar and mean turbulent temperature
distributions at $x=30$ cm.}

We already know that the laminar profile will have a linear profile,
from the Burke-Schumann solution. This takes the form,
\begin{equation}
a z + b = T(z).
\label{eq}
\end{equation}
This is equivalent to saying that at each grid point, we expect the
temperature distribution to be a delta function around the temperature
predicted by the mixing fraction at that location.

The turbulent system is more complicated. Now, we expect the non-zero
variance in mixing fraction concentration to impact the temperature.
In order to account for the turbulent fluctuations, we need to integrate
over the probability density, e.g.
\begin{equation}
 \tilde T = \int P(\bar z) T(\bar z) dz
\end{equation}
Using equation \ref{eq}, this is equivalent to,
\begin{equation}
 \tilde T = \int P(\bar z) (a \bar z + b) dz
\end{equation}
Essentially, this ``blurs'' the temperature profile by averaging each
location with its neighboring temperatures.

  \begin{figure}[!htb]
   \begin{center}
    \includegraphics[width = 12 cm]{figs/temperature.pdf}
    \caption{The temperature profiles for the laminar (blue) and
    turbulent (green) simulations at $x=30$.}
    \label{temp}
   \end{center}
  \end{figure}

These results are plotted in figure \ref{temp}. These profiles are
qualitatively similar to what we expected. The peak is lower for the
turbulent profile, but the temperature peak is wider and the temperature
is elevated farther away from the mixing layer, due to the increased
mixing from the turbulence. I was surprised that the slope is
 not perfectly linear in the case of the laminar profile.

\subsection*{e) Discuss the results.}

The entire formulation utilized chemical
equilibrium models to find the long time stable solution. The model
cannot predict extinction or ignition. This also assumes that the
chemical time scales are much smaller than the turbulence time scales,
e.g. that the Damkohler number is large.

We are also ignoring instantaneous turbulence effects, on account of
using a Favre-Averaging scheme, instead of resolving the fine turbulence
scales. So these results are certainly not expected to be accurate
instantaneously, but only represent mean quantities. Furthermore, they may
be far from realistic for some time, as the flow transitions to
turbulence and large eddies form downstream of the splitter.

Finally, we either ``turned-on'' or ``turned-off'' the turbulence
(e.g. it was fully developed turbulence, or completely laminar). In
reality, the flow might be intermittent or laminar away from the mixing
layer at $y=0$ and turbulent near it. So a mixing of the models might be
more appropriate. Ideally, the flow would be fully turbulent near the
centerline, intermittent at the edges of the layer, and laminar
outside. This could be more accurately modeled using the ``composite PDF
approach for intermittency''.

Given these assumptions, we would have to be careful using the results
of this model in a predictive context. Those caveats aside, the results
have the correct qualitative character for a flame, and so are certainly
much more useful than only expert opinion or conjecture. This is not to be too
negative, this is an extremely complex system we are simulating, and I
am able to generate all the plot used in this report in a few seconds on
my computer.

\newpage
All the work contained in this report was entirely my own.

Thank you for the class!
\vspace{1in}
\newline
References:

``Turbulent Combustion'', Norbert Peters

``Combustion Physics'', Chung K. Law

\subsection*{Code}
I wrote these routines entire from scratch, using python 2.X. The only
libraries necessary to run these routines should be Numpy, SciPy and
Matplotlib.
\lstinputlisting{flow.py}

\end{document}


\section{Combinatorics}\label{sec:combinatorics}

Combinatorics originated as the study of problems related to counting, although this study is now referred to as \term{enumerative combinatorics} to distinguish it from more abstract subfields. A canonical example of a counting problem is given in \fullref{ex:fibonacci_rabbits}. On the other hand, \fullref{thm:gamma_function_interpolates_factorial} provides an example of how mathematical analysis can answer questions related to counting. The latter subfield is called \term{analytic combinatorics}.

Results in combinatorics are traditionally obtained for \hyperref[def:set_finiteness]{finite sets} and \hyperref[def:integer_signum]{positive integers}, however many of them can be easily generalized. For example, \fullref{def:pigeonhole_principle} is stated in terms of cardinals rather than positive integers and \hyperref[def:quiver/simple]{graphs} are not necessary finite.

Some basic definitions and theorems are stated in \fullref{subsec:enumerative_combinatorics} and \fullref{subsec:progressions}, however most of the section is concerned with graphs --- see \fullref{subsec:hypergraphs}, \fullref{subsec:graphs}, \fullref{subsec:trees}.

As usual, in this section \( \BbbK \) will refer to either the field \( \BbbR \) of \hyperref[def:set_of_real_numbers]{real numbers} or the field \( \BbbC \) of \hyperref[def:set_of_real_numbers]{complex numbers}. This restriction is justified by \fullref{rem:real_field_extensions}.

\begin{example}\label{ex:fibonacci_rabbits}
  A simple, but nontrivial counting problem is due to Fibonacci. In \cite{MacTutor:fibonacci}, the problem is formulated as follows:
  \begin{displayquote}
    A certain man put a pair of rabbits in a place surrounded on all sides by a wall. How many pairs of rabbits can be produced from that pair in a year if it is supposed that every month each pair begets a new pair which from the second month on becomes productive?
  \end{displayquote}

  The rabbit behavior described in ridiculously idealized. Pregnancy time, for example, seems to be nonexistent in this problem. We are interested in counting, however, and not in biology. Nonetheless, the problem as it is stated is still open to interpretations. To obtain Fibonacci's result, we must add some further assumptions:
  \begin{itemize}
    \item The goal is to find the cumulative rabbit count, including the first pair.
    \item No crossbreeding is assumed --- each rabbit is monogamous and is part of a predefined pair.
    \item The rabbits do not die, which is a realistic assumption for a short time period in case the rabbits are taken care of.
    \item During the first two months, no rabbit is born. That is, the original pair must also wait for two months prior to producing offspring.
  \end{itemize}

  Instead of trying to give a direct answer to the problem, the usual approach is to iteratively build a sequence \( \seq{ F_k }_{k=1}^\infty \), the \term{Fibonacci sequence}, indicating the cumulative number of pairs of rabbits each month.

  As mentioned, during the first two months no offspring is produced, so we only have one pair of rabbits. Thus, \( F_1 = F_2 = 1 \). In general, the number of rabbits on month \( n \) is the sum of:
  \begin{itemize}
    \item The number of existing pairs on month \( n - 1 \), which is \( F_{n - 1} \).
    \item The number of newborn pairs, which is precisely the number of mature pairs (those born at least two months ago). This is \( F_{n - 2} \).
  \end{itemize}

  The entire sequence can thus be built using the following recursive definition:
  \begin{equation*}
    F_k \coloneqq \begin{cases}
      1,                &k = 1 \T{or} k = 2, \\
      F_{k-1} + F_{k-2} &k > 2.
    \end{cases}
  \end{equation*}

  Just to give an answer to Fibonacci's question, we will list the first 12 Fibonacci numbers:
  \begin{equation*}
    1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233
  \end{equation*}

  It should also be noted that outside the rabbit problem, the Fibonacci sequence is often defined to start at the zeroth month with a value of zero --- this is how it is defined in \fullref{rem:natural_number_recursion} actually. So
  \begin{equation}\label{eq:ex:fibonacci_rabbits}
    F_k \coloneqq \begin{cases}
      0,                &k = 0, \\
      1,                &k = 1, \\
      F_{k-1} + F_{k-2} &k > 2.
    \end{cases}
  \end{equation}
  is actually a more conventional definition.
\end{example}

\begin{definition}\label{def:weighted_set}
  Let \( A \) be an arbitrary \hyperref[def:set]{set} in the sense of \hyperref[def:zfc]{\logic{ZFC}}. Suppose that for every member \( x \in A \) we are given a \term{weight} \( w_x \). This weight may be any other set (in \logic{ZFC}).

  The function \( W(x) \coloneqq w_x \) is called a \term{weighted set}. It is a function by the \hyperref[def:zfc/replacement]{axiom schema of replacement}.

  We call the set \( A \) the \term{universe} of \( W \). If \( x \in A \), we say that \( x \) belongs to \( W \) and denote this by \( x \in W \), although this is not actual set membership. We denote the weight of \( x \) using \( W(x) \).

  Weighted sets are also called \term{labeled sets}, in which case \( W(x) \) is called the \term{label} of \( x \) rather than the weight.

  We list several important special cases:
  \begin{thmenum}
    \thmitem{def:weighted_set/multiset} If the weights are \hyperref[def:cardinal]{cardinal numbers}, \( W \) is called a \term{multiset} and the weights are called \term{multiplicities}. The \term{multiset cardinality} of \( W \) is the sum of all multiplicities.

    \thmitem{def:weighted_set/fuzzy} If the weights are real numbers in \( [0, 1] \), \( W \) is called a \term{fuzzy set}.
  \end{thmenum}
\end{definition}

\begin{example}\label{ex:def:weighted_set}
  We list several examples of \hyperref[def:weighted_set]{weighted sets}.

  \begin{itemize}
    \thmitem{ex:def:weighted_set/weighted_graphs} If \( G = (V, E) \) is a \hyperref[def:quiver/simple]{directed graph}, either \( V \) or \( E \) may be a weighted set. Both occur frequently in applications.

    \thmitem{ex:def:weighted_set/polynomial_roots} The roots of any polynomial form a multiset with multiplicities given by \fullref{def:polynomial_algebra_root_multiplicity}.

    \thmitem{ex:def:weighted_set/factorization} Any \hyperref[def:irreducible_factorization]{factorization} in an \hyperref[def:integral_domain]{integral domain} produces a multiset.

    \thmitem{ex:def:weighted_set/eigenvalues} The \hyperref[def:eigenpair]{point spectrum} of a linear operator produces a multiset.
  \end{itemize}
\end{example}

\begin{remark}\label{rem:multiset_notation}
  If it is clear from the context that \( M \) is a \hyperref[def:weighted_set/multiset]{multiset}, we may write
  \begin{equation*}
    M = \set{ a, a, b, b, c }
  \end{equation*}
  to denote the function
  \begin{equation*}
    M = \set{ (a, 2), (b, 2), (c, 1) }.
  \end{equation*}

  Since the ordering of elements is irrelevant, we can also regard a multiset as an equivalence class of \hyperref[def:transfinite_sequence]{transfinite sequences}.
\end{remark}