% -*- mode: latex; TeX-master: "Vorbis_I_spec"; -*-
%!TEX root = Vorbis_I_spec.tex
% $Id$
\section{Floor type 1 setup and decode} \label{vorbis:spec:floor1}

\subsection{Overview}

Vorbis floor type one uses a piecewise straight-line representation to
encode a spectral envelope curve. The representation plots this curve
mechanically on a linear frequency axis and a logarithmic (dB)
amplitude axis. The integer plotting algorithm used is similar to
Bresenham's algorithm.

\subsection{Floor 1 format}

\subsubsection{model}

Floor type one represents a spectral curve as a series of
line segments.  Synthesis constructs a floor curve using iterative
prediction in a process roughly equivalent to the following simplified
description:

\begin{itemize}
 \item  the first line segment (base case) is a logical line spanning
from x_0,y_0 to x_1,y_1 where in the base case x_0=0 and x_1=[n], the
full range of the spectral floor to be computed.

\item the induction step chooses a point x_new within an existing
logical line segment and produces a y_new value at that point computed
from the existing line's y value at x_new (as plotted by the line) and
a difference value decoded from the bitstream packet.

\item floor computation produces two new line segments, one running from
x_0,y_0 to x_new,y_new and from x_new,y_new to x_1,y_1. This step is
performed logically even if y_new represents no change to the
amplitude value at x_new so that later refinement is additionally
bounded at x_new.

\item the induction step repeats, using a list of x values specified in
the codec setup header at floor 1 initialization time.  Computation
is completed at the end of the x value list.

\end{itemize}

Consider the following example, with values chosen for ease of
understanding rather than representing typical configuration:

For the below example, we assume a floor setup with an [n] of 128.
The list of selected X values in increasing order is
0,16,32,48,64,80,96,112 and 128.  In list order, the values interleave
as 0, 128, 64, 32, 96, 16, 48, 80 and 112.  The corresponding
list-order Y values as decoded from an example packet are 110, 20, -5,
-45, 0, -25, -10, 30 and -10.  We compute the floor in the following
way, beginning with the first line:

\begin{center}
\includegraphics[width=8cm]{floor1-1}
\captionof{figure}{graph of example floor}
\end{center}

We now draw new logical lines to reflect the correction to new_Y, and
iterate for X positions 32 and 96:

\begin{center}
\includegraphics[width=8cm]{floor1-2}
\captionof{figure}{graph of example floor}
\end{center}

Although the new Y value at X position 96 is unchanged, it is still
used later as an endpoint for further refinement.  From here on, the
pattern should be clear; we complete the floor computation as follows:

\begin{center}
\includegraphics[width=8cm]{floor1-3}
\captionof{figure}{graph of example floor}
\end{center}

\begin{center}
\includegraphics[width=8cm]{floor1-4}
\captionof{figure}{graph of example floor}
\end{center}

A more efficient algorithm with carefully defined integer rounding
behavior is used for actual decode, as described later.  The actual
algorithm splits Y value computation and line plotting into two steps
with modifications to the above algorithm to eliminate noise
accumulation through integer roundoff/truncation.

\subsubsection{header decode}

A list of floor X values is stored in the packet header in interleaved
format (used in list order during packet decode and synthesis).  This
list is split into partitions, and each partition is assigned to a
partition class.  X positions 0 and [n] are implicit and do not belong
to an explicit partition or partition class.

A partition class consists of a representation vector width (the
number of Y values which the partition class encodes at once), a
'subclass' value representing the number of alternate entropy books
the partition class may use in representing Y values, the list of
[subclass] books and a master book used to encode which alternate
books were chosen for representation in a given packet.  The
master/subclass mechanism is meant to be used as a flexible
representation cascade while still using codebooks only in a scalar
context.

\begin{Verbatim}[commandchars=\\\{\}]

  1) [floor1\_partitions] = read 5 bits as unsigned integer
  2) [maximum\_class] = -1
  3) iterate [i] over the range 0 ... [floor1\_partitions]-1 \{

        4) vector [floor1\_partition\_class\_list] element [i] = read 4 bits as unsigned integer

     \}

  5) [maximum\_class] = largest integer scalar value in vector [floor1\_partition\_class\_list]
  6) iterate [i] over the range 0 ... [maximum\_class] \{

        7) vector [floor1\_class\_dimensions] element [i] = read 3 bits as unsigned integer and add 1
	8) vector [floor1\_class\_subclasses] element [i] = read 2 bits as unsigned integer
        9) if ( vector [floor1\_class\_subclasses] element [i] is nonzero ) \{

             10) vector [floor1\_class\_masterbooks] element [i] = read 8 bits as unsigned integer

           \}

       11) iterate [j] over the range 0 ... (2 exponent [floor1\_class\_subclasses] element [i]) - 1 \{

             12) array [floor1\_subclass\_books] element [i],[j] =
                 read 8 bits as unsigned integer and subtract one
           \}
      \}

 13) [floor1\_multiplier] = read 2 bits as unsigned integer and add one
 14) [rangebits] = read 4 bits as unsigned integer
 15) vector [floor1\_X\_list] element [0] = 0
 16) vector [floor1\_X\_list] element [1] = 2 exponent [rangebits];
 17) [floor1\_values] = 2
 18) iterate [i] over the range 0 ... [floor1\_partitions]-1 \{

       19) [current\_class\_number] = vector [floor1\_partition\_class\_list] element [i]
       20) iterate [j] over the range 0 ... ([floor1\_class\_dimensions] element [current\_class\_number])-1 \{
             21) vector [floor1\_X\_list] element ([floor1\_values]) =
                 read [rangebits] bits as unsigned integer
             22) increment [floor1\_values] by one
           \}
     \}

 23) done
\end{Verbatim}

An end-of-packet condition while reading any aspect of a floor 1
configuration during setup renders a stream undecodable.  In addition,
a \varname{[floor1\_class\_masterbooks]} or
\varname{[floor1\_subclass\_books]} scalar element greater than the
highest numbered codebook configured in this stream is an error
condition that renders the stream undecodable.  Vector
[floor1\_x\_list] is limited to a maximum length of 65 elements; a
setup indicating more than 65 total elements (including elements 0 and
1 set prior to the read loop) renders the stream undecodable.  All
vector [floor1\_x\_list] element values must be unique within the
vector; a non-unique value renders the stream undecodable.

\subsubsection{packet decode} \label{vorbis:spec:floor1-decode}

Packet decode begins by checking the \varname{[nonzero]} flag:

\begin{Verbatim}[commandchars=\\\{\}]
  1) [nonzero] = read 1 bit as boolean
\end{Verbatim}

If \varname{[nonzero]} is unset, that indicates this channel contained
no audio energy in this frame.  Decode immediately returns a status
indicating this floor curve (and thus this channel) is unused this
frame.  (A return status of 'unused' is different from decoding a
floor that has all points set to minimum representation amplitude,
which happens to be approximately -140dB).

Assuming \varname{[nonzero]} is set, decode proceeds as follows:

\begin{Verbatim}[commandchars=\\\{\}]
  1) [range] = vector \{ 256, 128, 86, 64 \} element ([floor1\_multiplier]-1)
  2) vector [floor1\_Y] element [0] = read \link{vorbis:spec:ilog}{ilog}([range]-1) bits as unsigned integer
  3) vector [floor1\_Y] element [1] = read \link{vorbis:spec:ilog}{ilog}([range]-1) bits as unsigned integer
  4) [offset] = 2;
  5) iterate [i] over the range 0 ... [floor1\_partitions]-1 \{

       6) [class] = vector [floor1\_partition\_class]  element [i]
       7) [cdim]  = vector [floor1\_class\_dimensions] element [class]
       8) [cbits] = vector [floor1\_class\_subclasses] element [class]
       9) [csub]  = (2 exponent [cbits])-1
      10) [cval]  = 0
      11) if ( [cbits] is greater than zero ) \{

             12) [cval] = read from packet using codebook number
                 (vector [floor1\_class\_masterbooks] element [class]) in scalar context
          \}

      13) iterate [j] over the range 0 ... [cdim]-1 \{

             14) [book] = array [floor1\_subclass\_books] element [class],([cval] bitwise AND [csub])
             15) [cval] = [cval] right shifted [cbits] bits
	     16) if ( [book] is not less than zero ) \{

	           17) vector [floor1\_Y] element ([j]+[offset]) = read from packet using codebook
                       [book] in scalar context

                 \} else [book] is less than zero \{

	           18) vector [floor1\_Y] element ([j]+[offset]) = 0

                 \}
          \}

      19) [offset] = [offset] + [cdim]

     \}

 20) done
\end{Verbatim}

An end-of-packet condition during curve decode should be considered a
nominal occurrence; if end-of-packet is reached during any read
operation above, floor decode is to return 'unused' status as if the
\varname{[nonzero]} flag had been unset at the beginning of decode.

Vector \varname{[floor1\_Y]} contains the values from packet decode
needed for floor 1 synthesis.

\subsubsection{curve computation} \label{vorbis:spec:floor1-synth}

Curve computation is split into two logical steps; the first step
derives final Y amplitude values from the encoded, wrapped difference
values taken from the bitstream.  The second step plots the curve
lines.  Also, although zero-difference values are used in the
iterative prediction to find final Y values, these points are
conditionally skipped during final line computation in step two.
Skipping zero-difference values allows a smoother line fit.

Although some aspects of the below algorithm look like inconsequential
optimizations, implementors are warned to follow the details closely.
Deviation from implementing a strictly equivalent algorithm can result
in serious decoding errors.

{\em Additional note:} Although \varname{[floor1\_final\_Y]} values in
the prediction loop and at the end of step 1 are inherently limited by
the prediction algorithm to [0, \varname{[range]}), it is possible to
  abuse the setup and codebook machinery to produce negative or
  over-range results.  We suggest that decoder implementations guard
  the values in vector \varname{[floor1\_final\_Y]} by clamping each
  element to [0, \varname{[range]}) after step 1.  Variants of this
    suggestion are acceptable as valid floor1 setups cannot produce
    out of range values.

\begin{description}
\item[step 1: amplitude value synthesis]

Unwrap the always-positive-or-zero values read from the packet into
+/- difference values, then apply to line prediction.

\begin{Verbatim}[commandchars=\\\{\}]
  1) [range] = vector \{ 256, 128, 86, 64 \} element ([floor1\_multiplier]-1)
  2) vector [floor1\_step2\_flag] element [0] = set
  3) vector [floor1\_step2\_flag] element [1] = set
  4) vector [floor1\_final\_Y] element [0] = vector [floor1\_Y] element [0]
  5) vector [floor1\_final\_Y] element [1] = vector [floor1\_Y] element [1]
  6) iterate [i] over the range 2 ... [floor1\_values]-1 \{

       7) [low\_neighbor\_offset] = \link{vorbis:spec:low:neighbor}{low\_neighbor}([floor1\_X\_list],[i])
       8) [high\_neighbor\_offset] = \link{vorbis:spec:high:neighbor}{high\_neighbor}([floor1\_X\_list],[i])

       9) [predicted] = \link{vorbis:spec:render:point}{render\_point}( vector [floor1\_X\_list] element [low\_neighbor\_offset],
				      vector [floor1\_final\_Y] element [low\_neighbor\_offset],
                                      vector [floor1\_X\_list] element [high\_neighbor\_offset],
				      vector [floor1\_final\_Y] element [high\_neighbor\_offset],
                                      vector [floor1\_X\_list] element [i] )

      10) [val] = vector [floor1\_Y] element [i]
      11) [highroom] = [range] - [predicted]
      12) [lowroom]  = [predicted]
      13) if ( [highroom] is less than [lowroom] ) \{

            14) [room] = [highroom] * 2

          \} else [highroom] is not less than [lowroom] \{

            15) [room] = [lowroom] * 2

          \}

      16) if ( [val] is nonzero ) \{

            17) vector [floor1\_step2\_flag] element [low\_neighbor\_offset] = set
            18) vector [floor1\_step2\_flag] element [high\_neighbor\_offset] = set
            19) vector [floor1\_step2\_flag] element [i] = set
            20) if ( [val] is greater than or equal to [room] ) \{

                  21) if ( [highroom] is greater than [lowroom] ) \{

                        22) vector [floor1\_final\_Y] element [i] = [val] - [lowroom] + [predicted]

		      \} else [highroom] is not greater than [lowroom] \{

                        23) vector [floor1\_final\_Y] element [i] = [predicted] - [val] + [highroom] - 1

                      \}

                \} else [val] is less than [room] \{

                    24) if ([val] is odd) \{

                        25) vector [floor1\_final\_Y] element [i] =
                            [predicted] - (([val] + 1) divided by  2 using integer division)

                      \} else [val] is even \{

                        26) vector [floor1\_final\_Y] element [i] =
                            [predicted] + ([val] / 2 using integer division)

                      \}

                \}

          \} else [val] is zero \{

            27) vector [floor1\_step2\_flag] element [i] = unset
            28) vector [floor1\_final\_Y] element [i] = [predicted]

          \}

     \}

 29) done

\end{Verbatim}

\item[step 2: curve synthesis]

Curve synthesis generates a return vector \varname{[floor]} of length
\varname{[n]} (where \varname{[n]} is provided by the decode process
calling to floor decode).  Floor 1 curve synthesis makes use of the
\varname{[floor1\_X\_list]}, \varname{[floor1\_final\_Y]} and
\varname{[floor1\_step2\_flag]} vectors, as well as [floor1\_multiplier]
and [floor1\_values] values.

Decode begins by sorting the scalars from vectors
\varname{[floor1\_X\_list]}, \varname{[floor1\_final\_Y]} and
\varname{[floor1\_step2\_flag]} together into new vectors
\varname{[floor1\_X\_list]'}, \varname{[floor1\_final\_Y]'} and
\varname{[floor1\_step2\_flag]'} according to ascending sort order of the
values in \varname{[floor1\_X\_list]}.  That is, sort the values of
\varname{[floor1\_X\_list]} and then apply the same permutation to
elements of the other two vectors so that the X, Y and step2\_flag
values still match.

Then compute the final curve in one pass:

\begin{Verbatim}[commandchars=\\\{\}]
  1) [hx] = 0
  2) [lx] = 0
  3) [ly] = vector [floor1\_final\_Y]' element [0] * [floor1\_multiplier]
  4) iterate [i] over the range 1 ... [floor1\_values]-1 \{

       5) if ( [floor1\_step2\_flag]' element [i] is set ) \{

             6) [hy] = [floor1\_final\_Y]' element [i] * [floor1\_multiplier]
 	     7) [hx] = [floor1\_X\_list]' element [i]
             8) \link{vorbis:spec:render:line}{render\_line}( [lx], [ly], [hx], [hy], [floor] )
             9) [lx] = [hx]
	    10) [ly] = [hy]
          \}
     \}

 11) if ( [hx] is less than [n] ) \{

        12) \link{vorbis:spec:render:line}{render\_line}( [hx], [hy], [n], [hy], [floor] )

     \}

 13) if ( [hx] is greater than [n] ) \{

            14) truncate vector [floor] to [n] elements

     \}

 15) for each scalar in vector [floor], perform a lookup substitution using
     the scalar value from [floor] as an offset into the vector \link{vorbis:spec:floor1:inverse:dB:table}{[floor1\_inverse\_dB\_static\_table]}

 16) done

\end{Verbatim}

\end{description}


\documentclass{article}

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

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

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

\linespread{1.1}

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

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

\setlength\parindent{0pt}

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

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

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

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

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

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

\newcommand{\hmwkTitle}{Assignment\ \#2}
\newcommand{\hmwkDueDate}{Due on 20th September, 2018}
\newcommand{\hmwkClass}{Advanced Quantum Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

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

\author{\hmwkAuthorName}
\date{}

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

%
% Various Helper Commands
%

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

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

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

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

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

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

\begin{document}

\maketitle

\textit{\textbf{Acknowledgements} - I would like to thank Chandramouli Chowdhury and Junaid Bhat for discussions in this assignment.}
\begin{homeworkProblem}
Before we start looking at the the actual problem itself, let's consider a simpler problem - that of proving $ e^x e^{-x} = 1$. Lets Taylor expand the same and look at terms order by order,
\begin{align*}
e^x e^{-x} &= \qty(1 + x + \dfrac{x^2 }{2!} + \dfrac{x^3}{3!} + \ldots)\qty(1 - x + \dfrac{x^2 }{2!} - \dfrac{x^3}{3!} + \ldots)\\
&= 1 + (x -x) + \qty(\dfrac{x^2 }{2} + \dfrac{x^2 }{2} - x^2) + \qty(\dfrac{x^3 }{6} -  \dfrac{x^3 }{6} + \dfrac{x^3}{2} - \dfrac{x^3}{2} ) + \ldots
\end{align*}
We note that terms cancel out order by order.
\begin{align*}
U &= \sum_n \dfrac{(-i)^n}{n!} \int_{0}^{t} dt_1 \ldots \int_{0}^{t} dt_n \mathcal{T}[H(t_1)\ldots H(t_2)]\\
&= 1 - i \int_0^t dt_1 H(t_1) - \dfrac{1}{2} \int_0^t \int_0^t dt_1 dt_2 \qty[\theta(t_1 - t_2)H(t_1)H(t_2) + \theta(t_2 - t_1)H(t_2)H(t_1)] + \ldots\\
U^\dagger &= 1 + i \int_0^t dt_1 H(t_1) - \dfrac{1}{2} \int_0^t \int_0^t dt_1 dt_2 \qty[\theta(t_2 - t_1)H(t_1)H(t_2) + \theta(t_1 - t_2)H(t_2)H(t_1)] + \ldots\\
\therefore U^\dagger U &= 1 + \qty(- i \int_0^t dt_1 H(t_1) + i \int_0^t dt'_1 H(t'_1) ) + \int_0^t \int_0^t dt_1 dt_2 \qty[H(t_1) H(t_2)]\\
&\qty(- \dfrac{1}{2} \int_0^t \int_0^t dt_1 dt_2 \qty[\theta_{12}H(t_1)H(t_2) + \theta_{21}H(t_2)H(t_1)] - \dfrac{1}{2} \int_0^t \int_0^t dt'_1 dt'_2 \qty[\theta_{2'1'}H(t'_1)H(t'_2) + \theta_{1'2'}H(t'_2)H(t'_1)] )\\&+ \ldots
%&+ \dfrac{1}{4} \int_0^t \int_0^t \int_0^t \int_0^t dt_1 dt_2  dt'_1 dt'_2 \qty[\theta_{12}\theta_{1'2'}H(t_1)H(t_2)H(t_1)H(t_2) + \theta_{21}H(t_2)H(t_1)]
\end{align*}
The terms in the first parenthesis just cancel each other. As the primed variables are just dummies one can ignore the primes and write the terms in the second parenthesis in terms of $ t_1 $ and $ t_2 $. We can rewrite that particular term as follows (using the fact that $ \theta_{12} + \theta_{21} = 1 $),
\begin{align*}
- \dfrac{1}{2} \int_0^t \int_0^t dt_1 dt_2 \qty[\theta_{12}H(t_1)H(t_2) + \theta_{21}H(t_2)H(t_1) + \theta_{21}H(t_1)H(t_2) + \theta_{12}H(t_2)H(t_1)]\\
= - \dfrac{1}{2} \int_0^t \int_0^t dt_1 dt_2 \qty[H(t_1)H(t_2) + H(t_2)H(t_1)] = - \int_0^t \int_0^t dt_1 dt_2 \qty[H(t_1)H(t_2)]
\end{align*}
This shows that the terms cancel. This will hold at higher orders too, albeit with more complicated $ \theta $ functions.
\end{homeworkProblem}

\begin{homeworkProblem}
	We know that the energy eigenstates of the harmonic oscillator form a basis. Hence, the required coherent state $ \ket{z} $ can be written in terms of these eigenstates as,
	\begin{equation*}
	\ket{z} = \sum_{n=0}^{\infty} c_n \ket{n} = \sum_{n=0}^{\infty} c_n \frac{(a^\dagger)^n}{\sqrt{n!}}\ket{0}
	\end{equation*}
	Substituting this in the equation for coherent state $ a\ket{z} = z \ket{z} $,
	\begin{align*}
	 \sum_{n=0}^{\infty} c_n a \ket{n} &=  \sum_{n=0}^{\infty} z c_n \ket{n}\\
	 \sum_{n=1}^{\infty} c_n \sqrt{n} \ket{n-1} &=  \sum_{n=0}^{\infty} z c_n \ket{n}\\
	 \sum_{n=0}^{\infty} c_{n+1} \sqrt{n+1} \ket{n} &=  \sum_{n=0}^{\infty} z c_n \ket{n}\\
	 \therefore c_{n+1} \sqrt{n+1} &= z c_n
	\end{align*}

	We have effectively derived a recursion relation for the coefficients $ c_n $. If we start off with $ c_n = \alpha $,
	\begin{equation*}
	c_1 = {z \alpha} \qq{,} c_2 = \frac{z^2 \alpha}{\sqrt{2}} \qq{,} c_3 = \dfrac{z^3 \alpha}{\sqrt{3\vdot 2}} \qq{,} \ldots \qq{,} c_n = \dfrac{z^n \alpha}{\sqrt{n!}}
	\end{equation*}
	So, our coherent state can now be written as,
	\begin{align*}
	\ket{z} &= \alpha \sum_{n=0}^{\infty}  \frac{(za^\dagger)^n}{n!}\ket{0}\\
	&= \alpha e^{a^\dagger z}\ket{0}
	\end{align*}
\end{homeworkProblem}
\begin{homeworkProblem}
	We know that,
	\begin{equation*}
	{x}(0) = \frac{{a} + {a}^\dagger}{\sqrt{2m\omega}} \qq{,} {p}(0) = \frac{\sqrt{m\omega} ({a} - {a}^\dagger)}{\sqrt{2}i} \qq{,} x(t) = e^{iHt}x(0)e^{-iHt} \qq{,} p(t) = e^{iHt}p(0)e^{-iHt}
	\end{equation*}
	From this, we note the following,
	\begin{align*}
	 x(t)\ket{0} &= e^{iHt}x(0)e^{-iHt}\ket{0}\\
	 &=  e^{-i\omega t/2}e^{iHt}x(0)\ket{0}\\
	 &=  \frac{e^{-i\omega t/2}}{\sqrt{2m\omega}}e^{iHt}\ket{1}\\
	 x(t)\ket{0} &=  \frac{e^{i\omega t}}{\sqrt{2m\omega}}\ket{1} \implies \bra{0}x(t)=\frac{e^{-i\omega t}}{\sqrt{2m\omega}} \bra{1}
	\end{align*}
	\begin{align*}
	\qq{Similarly, }	 p(t)\ket{0} &= e^{iHt}p(0)e^{-iHt}\ket{0}\\
	&=  e^{-i\omega t/2}e^{iHt}p(0)\ket{0}\\
	&=  -\frac{e^{-i\omega t/2}\sqrt{m\omega}}{\sqrt{2}i}e^{iHt}\ket{1}\\
	p(t)\ket{0} &=  -\frac{e^{i\omega t}\sqrt{m\omega}}{\sqrt{2}i}\ket{1} \implies \bra{0}p(t) =  \frac{e^{-i\omega t}\sqrt{m\omega}}{\sqrt{2}i}\bra{1}
	\end{align*}

	Now consider the quantities to be calculated,
	\begin{equation*}
	C_1(t) = \ev{x(t)x(0)}{0} = \frac{e^{-i\omega t}}{\sqrt{2m\omega}} \frac{1}{\sqrt{2m\omega}} = \boxed{\frac{e^{-i\omega t}}{2m\omega}}
	\end{equation*}
	\begin{equation*}
	C_2(t) = \ev{x(t)p(0)}{0} - \ev{p(0)x(t)}{0}= -\dfrac{e^{-i\omega t}}{2i} - \dfrac{e^{i\omega t}}{2i}= \boxed{i \cos \omega t}
	\end{equation*}
	\begin{equation*}
	C_3(t) = \ev{p(t)x(0)}{0} - \ev{x(0)p(t)}{0}= \dfrac{e^{-i\omega t}}{2i} + \dfrac{e^{i\omega t}}{2i}= \boxed{-i \cos \omega t}
	\end{equation*}
\end{homeworkProblem}

\begin{homeworkProblem}
	\textbf{Part (a)}
	\begin{align*}
	Z(\beta) = \Tr e^{-\beta H} &= \sum_{n=0}^{\infty} \expval{e^{-\beta H}}{n}\\
	&= \sum_{n=0}^{\infty} e^{-\beta(n+\frac{1}{2})\omega}\\
	&= \frac{e^{-\beta \omega /2}}{1-e^{-\beta \omega}} = \dfrac{2}{\sinh \dfrac{\beta \omega}{2}}
	\end{align*}

	\textbf{Part (b)}\\
	Given that,
	\begin{equation*}
	x(\tau) = \sum_n x_n e^{\frac{2\pi i n \tau}{\beta}}
	\end{equation*}
	As we require $ x(\tau) $ to be real, it follows from above that $ x_n = x_n^* $. Taking $ \omega_n = \frac{2\pi n}{\beta} $
	\begin{equation*}
	S_E = \int_{0}^{\beta} d \tau \qty(\frac{m\dot{x}^2}{2} + \frac{m\omega^2 x^2}{2})
	\end{equation*}
	\begin{align*}
	&=  \sum_{p,q} \qty(-\frac{m x_p x_q \omega_p \omega_q}{2} + \frac{m\omega^2 x_p x_q }{2}) \int_{0}^{\beta} e^{i (\omega_q + \omega_p)\tau} d \tau\\
	&=  \sum_{p,q} \qty(-\frac{m x_p x_q \omega_p \omega_q}{2} + \frac{m\omega^2 x_p x_q }{2}) \beta \delta_{p,-q}\\
	&=  \sum_{q} \qty(-\frac{m x_{-q} x_q \omega_{-q} \omega_q}{2} + \frac{m\omega^2 x_{-q} x_q }{2}) \beta \\
	&=  \frac{m}{2}\sum_{q} \beta\qty(x_{q}^* x_q  \omega_q^2 + \omega^2 x_{q}^* x_q)\\
	-S_E&=  -\frac{m\beta}{2}\sum_{q}x_{q}^* x_q   \qty(\omega_q^2 + \omega^2 )
	\end{align*}
	The required path integral to be done is,
	\begin{align*}
	Z(\beta) &= N \int \mathcal{D}x \exp - \frac{m\beta}{2}\sum_{q}x_{q}^* x_q   \qty(\omega_q^2 + \omega^2 ) \qq{where $ N $ is some normalization}\\
	&= N \int \mathcal{D}x \exp( - m\beta \sum_{q=1}^{\infty} x_{q}^* x_q   \qty(\omega_q^2 + \omega^2 ) - \frac{m\beta x_0^2\omega^2}{2}) \\
	&= N \int dx_0  \exp(-\frac{m\beta x_0^2\omega^2}{2}) \cross \prod_{q=1}^{\infty} \int d x_q d x_q^* \exp -  m\beta x_{q}^* x_q   \qty(\omega_q^2 + \omega^2 ) \\
	&= N \sqrt{\frac{2\pi}{m \beta \omega^2}} \cross \prod_{q=1}^\infty \frac{2\pi}{m \beta (\omega_q^2 + \omega^2 )}\\
	&= N \sqrt{\frac{2\pi}{m \beta \omega^2}} \cross \prod_{q=1}^\infty \frac{2\pi}{m \beta \dfrac{4 q^2 \pi^2}{\beta^2}\qty(1 + \qty(\frac{\beta \omega}{2q\pi})^2)}\\
	&= N \sqrt{\frac{2\pi}{m \beta \omega^2}} \cross \dfrac{\beta \omega}{2 \pi \sinh \dfrac{\beta \omega}{2}} \cross \prod_{q=1}^\infty \frac{\beta}{2 \pi m q^2} \\
	&= N \sqrt{\frac{\beta}{2 \pi m}}  \cross \prod_{q=1}^\infty \frac{\beta}{2 \pi m q^2} \cross \dfrac{1}{\sinh \dfrac{\beta \omega}{2}} \\
	&= N'  \cross \dfrac{1}{\sinh \dfrac{\beta \omega}{2}}
	\end{align*}
	As $ N' $ does not depend on $ \omega $, we can drop it altogether for computation purposes. This gives us the required result.

\end{homeworkProblem}
%\pagebreak

\end{document}


\section{Cartoon of Algorithm}
\label{AlgCartoon}

Refer to Fig. \ref{fig:cartoon}.

\begin{figure}
\begin{center}
\scalebox{1}{\includegraphics[width=1.0\textwidth]{../AlgorithmFigure}}
\end{center}
\caption{A cartoon of the algorithm.  $a):$ The initial two models with approximately the same loss, $L_0$. $b):$ The interpolated loss curve, in red, and its global maximum, occuring at $t=t^*$. $c):$ The interpolated model $\Theta(\theta_i, \theta_j, t^*)$ is added and labeled $\theta_{i,j}$.  $d):$ Stochastic gradient descent is performed on the interpolated model until its loss is below $\alpha L_0$. $e):$ New interpolated loss curves are calculated between the models, pairwise on a chain.  $f):$ As in step $c)$, a new model is inserted at the maxima of the interpolated loss curve between $\theta_i$ and $\theta_{i,j}$.  $g):$  As in step $d)$, gradient descent is performed until the model has low enough loss.}
\label{fig:cartoon}
\end{figure}

\section{Visualization of Connection}
\label{visualization}

 Because the weight matrices are anywhere from high to extremely high dimensional, for the purposes of visualization we projected the models on the connecting path into a three dimensionsal subspace.  Snapshots of the algorithm in progress for the quadratic regression task are indicated in Fig. \ref{connfigs}.  This was done by vectorizing all of the weight matrices for all the beads for a given connecting path, and then performing principal component analysis to find the three highest weight projections for the collection of models that define the endpoints of segments for a connecting path---i.e., the $\theta_i$ discussed in the algorithm.  We then projected the connecting string of models onto these three directions.

 The color of the strings was chosen to be representative of the test loss under a log mapping, so that extremely high test loss mapped to red, whereas test loss near the threshold mapped to blue.  An animation of the connecting path can be seen on our \href{github.com/danielfreeman11/convex-nets/blob/master/Writeup/Plots/quadratic.pathinterp.errorvis.gif}{Github page}.

 Finally, projections onto pairs of principal components are indicated by the black curves.

\begin{figure}
\centering
\includegraphics[width=.4\textwidth]{../Plots/conn1}
\includegraphics[width=.4\textwidth]{../Plots/conn2}
\includegraphics[width=.4\textwidth]{../Plots/conn3}
\includegraphics[width=.4\textwidth]{../Plots/conn4}
\caption{Snapshots of Dynamic String Sampling in action for the quadratic regression task.  The string's coordinates are its projections onto the three most important principal axes of the fully converged string.  (Top Left) One step into the algorithm, note the high loss between all of the vertices of the path. (Top Right) An intermediate step of the algorithm.  Portions of the string have converged, but there are still regions with high interpolated loss. (Bottom Left) Near the end of the algorithm.  Almost the entire string has converged to low loss.  (Bottom Right) The algorithm has finished.  A continuous path between the models has been found with low loss.}
\label{connfigs}
\end{figure}

\section{A Disconnection}
\label{sec:disconnect}

%%%%%%%%%%%%%%%%%%%%%%
\subsection{A Disconnection}
%%%%%%%%%%%%%%%%%%%%%%
\label{symdisc}

 As a sanity check for the algorithm, we also applied it to a problem for which we know that it is not possible to connect models of equivalent power by the arguments of section \ref{disconnect}.  The input data is 3 points in $\mathbb{R}^2$, and the task is to permute the datapoints, i.e. map $\{x_1,x_2,x_3\} \to \{x_2,x_3,x_1\}$.  This map requires at least 12 parameters in general for the three linear maps which take $x_i\to x_j$ for $i,j \in \{\{1,2\},\{2,3\},\{3,1\}\}$.  Our archticture was a 2-3-2 fully connected neural network with a single relu nonlinearity after the hidden layer---a model which clearly has 12 free parameters by construction.  The two models we tried to connect were a single model, $\theta$, and a copy of $\theta$ with the first two neurons in the hidden layer permuted, $\tilde{\theta_{\sigma}}$.  The algorithm fails to converge when initialized with these two models.  We provide a visualization of the string of models produced by the algorithm in Fig. \ref{discfigs}.

 In general, a persistent high interpolated loss between two neighboring beads on the string of models could arise from either a slowly converging, connected pair of models or from a truly disconnected pair of models.  ``Proving'' a disconnection at the level of numerical experiments is intractable in general, but a collection of negative results---i.e., failures to converge---are highly suggestive of a true disconnection.

\begin{figure}
\centering
\includegraphics[width=.4\textwidth]{../Plots/disc1}
\includegraphics[width=.4\textwidth]{../Plots/disc2}
\includegraphics[width=.4\textwidth]{../Plots/disc3}
\caption{These three figures are projections of the components of the 12-dimensional weight matrices which comprise the models on the string produced by the DSS algorithm.  The axes are the principal components of the weight matrices, and the colors indicate test error for the model.  For more details on the figure generation, see Appendix \ref{visualization}. (Left) The string of models after 1 step.  Note the high error at all points except the middle and the endpoints.  (Middle) An intermediate stage of the algorithm.  Part of the string has converged, but a persistent high-error segment still exists.  (Right) Even after running for many steps, the error persists, and the algorithm does not converge.}
\label{discfigs}
\end{figure}


\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/genGamma.json'
   cdblib.create (checkpoint_file)
   checkpoint = []
\end{cadabra}
\egroup

% =================================================================================================
\section*{The generalised connections}

The generalised connections may be computed recursively using
\begin{align}
   \label{eq:GenGamma}
\Gamma^{a}{}_{b\uc d} = \Gamma^{a}{}_{(b\uc,d)}
                - (n+1) \Gamma^{a}{}_{p(\uc}
                        \Gamma^{p}{}_{bd)}
\end{align}
where $\uc$ contains $n>0$ indices. The sequence begins with the standard metric compatible connection
\begin{align}
   \Gamma^{d}_{ab} = \frac{1}{2} g^{dc}\left( g_{cb,a} + g_{ac,b} - g_{ab,c} \right)
\end{align}

Here we will use the results of {\tt metric.tex} and {\tt metric-inv.tex} to compute the metric connection
$\Gamma^{d}_{ab}$. But since the $g_{ab}$ and $g^{ab}$ provided by those codes are truncated at a
particular order in the curvatures (and thus are only approximations to the $g_{ab}$ and $g^{ab}$) similar
truncations will arise in the $\Gamma^{a}{}_{b\uc d}$.

Approximations will be denoted by the addition of an overbar to an object. In this notation the metric
$g$ can be written as
\begin{align}
   g = {\bar g} + \BigO{\eps^n}
\end{align}
in which ${\bar g}$ is the truncated polynomial approximation to $g$ and $\BigO{\eps^n}$ is the error term
(containing terms no smaller than $\eps^n$). The polynomial structure of ${\bar g}$ can be expressed as
\begin{align}
   \gabBar = \ngabBar{0}
           + \ngabBar{1}
           + \ngabBar{2}
           + \dots
           + \ngabBar{p}
\end{align}
in which each terms like $\overset{m}{\bar g}$ contains only terms of order $m$. This notation will be applied
to other quantities in particular the generalised connections.

The notation $\BigO{\eps^n}$ denotes terms in the curvatures that are of order $\eps^n$. What does this actually mean?
Each term in $R$ is of order $\eps^2$ while each derivative of $R$ carries an extra power of $\eps$.
Thus $R\cdot R = \BigO{\eps^4}$, $R\cdot R\cdot\nabla R = \BigO{\eps^7}$ and $R\cdot R\cdot\nabla^2R = \BigO{\eps^8}$.

We will also adopt the convention that an object is said to be an $\BigO{\eps^{m}}$ approximation when the corresponding error term is $\BigO{\eps^{m+1}}$.

Consider the $\BigO{\eps^{m}}$ approximation of the generalised connection, namely,
\begin{align}
   \GammaBar^{a}{}_{b\ucn d}
      = \nGammaBar{0}^{a}{}_{b\ucn d}
      + \nGammaBar{1}^{a}{}_{b\ucn d}
      + \nGammaBar{2}^{a}{}_{b\ucn d}
      + \dots
      + \nGammaBar{m}^{a}{}_{b\ucn d}
\end{align}
where $\ucn$ denotes a set of indices such as $c_1c_2c_3\dots c_n$.

The first thing to note is that
\begin{align}
   0 = \nGammaBar{1+n}^{a}{}_{(b\ucn,d)}
\end{align}

There are two proofs of this claim. For the first proof, note (by inspection) that the order $\BigO{\eps^p}$
approximation for $\GammaBar^{a}{}_{b\ucn d}$ is a polynomial in $x$ of degree $p-n-1$. Thus
$\nGammaBar{1+n}^{a}{}_{(b\ucn,d)}$ is a polynomial in $x$ of degree
zero, i.e., a constant. However, we know that all generalised connections vanish at the origin of the RNC frame.
Thus this constant must be zero. The second proof makes explicit use of the first (and second?) Bianchi identity,
that is $0=R_{a(bcd)}$. The term $\nGammaBar{1+n}^{a}{}_{(b\ucn,d)}$ will
itself consist of a sum of terms built from combinations of $x$, $R$, $\nabla R$ etc. The $x^{a}$ will always
appear in a contraction with one of the indices on $R_{abcd}$ or one of its derivatives. Consider any one of
these terms, denoted by $A$, and assume for the moment that $1+n$ is an even number, say $1+n=2p$. The indices
$(b\ucn,d)$ must somehow be assigned to the factors that comprise $A$. Our aim is to show that at least one $R$
factor in $A$ will receive 3 of these indices and thus by the Bianchi identities will be zero. If there are too
many $R$ factors then the Bianchi identities will not come into play. So how many $R$ factors can we expect?
Since $A$ is a term in an $\BigO{\eps^{(n+1)}}$ approximation there can be no more than $(n+1)/2=p$ Riemann
factors. There will be at least one $x$ term contracted with one of the $p$ Riemann factors. However, we have
$n+2=2p+1$ indices to distribute amongst the $x$ term and $p$ Riemann factors. One of the indices is a derivative
index and will have nett effect of transferring that index from $x$ to one of the Riemann factors. The remaining
$2p$ indices must be distributed amongst the $p$ Riemann factors. It is not possible to avoid assigning three
indices to at least one of the Riemann factors. Thus, by the Bianchi identity, this $A$ term must vanish. Similar
arguments can be applied to the other cases where the $A$ terms consists of products of $R$ and its derivatives
and in the case where $n+1$ is an odd number. The analysis always comes down to the distribution of the indices
$(b\ucn,d)$ amongst the factors of a typical $A$ term. In all cases the Bianchi identity will enter the play and
force $A$ to be zero.

A corollary of the second proof is that for all $m<n+2$
\begin{align}
   0 = \nGammaBar{m}^{a}{}_{b\ucn d}
\end{align}
The proof follows exactly that of the second proof given above.

We can use the above results to streamline the computation of the generalised connections.
We begin with the formal expression for the $\BigO{\eps^m}$ approximations
\begin{align}
   \Gamma^{a}{}_{bc}
      &= \nGammaBar{2}^{a}{}_{bc}
       + \nGammaBar{3}^{a}{}_{bc}
       + \nGammaBar{4}^{a}{}_{bc}
       + \dots
       + \nGammaBar{m}^{a}{}_{bc}\\
   \Gamma^{a}{}_{b\uc}
      &= \nGammaBar{n+1}^{a}{}_{b\uc}
       + \nGammaBar{n+2}^{a}{}_{b\uc}
       + \nGammaBar{n+3}^{a}{}_{b\uc}
       + \dots
       + \nGammaBar{m}^{a}{}_{b\uc}\\
   \Gamma^{a}{}_{b\uc d}
      &= \nGammaBar{n+2}^{a}{}_{b\uc d}
       + \nGammaBar{n+3}^{a}{}_{b\uc d}
       + \nGammaBar{n+4}^{a}{}_{b\uc d}
       + \dots
       + \nGammaBar{m}^{a}{}_{b\uc d}\label{eq:GenGammaA}
\end{align}
These can be substituted into equation (\ref{eq:GenGamma}) with the result
\def\m{\hskip 4pt}
\begin{align}
   \Gamma^{a}{}_{b\uc d}
      &= \nGammaBar{n+1}^{a}{}_{(b\uc,d)}
       + \nGammaBar{n+2}^{a}{}_{(b\uc,d)}
       + \nGammaBar{n+3}^{a}{}_{(b\uc,d)}
       + \dots
       + \nGammaBar{m}^{a}{}_{(b\uc,d)}
       -(n+1)\left(\m \nGammaBar{n+1}^{a}{}_{p\uc}
                    + \nGammaBar{n+2}^{a}{}_{p\uc}
                    + \nGammaBar{n+3}^{a}{}_{p\uc}
                    + \dots
                    + \nGammaBar{m}^{a}{}_{p\uc}\right)
             \left(   \nGammaBar{2}^{p}{}_{bd}
                    + \nGammaBar{3}^{p}{}_{bd}
                    + \nGammaBar{4}^{p}{}_{bd}
                    + \dots
                    + \nGammaBar{m}^{p}{}_{bd}\right)\label{eq:GenGammaB}
\end{align}
where it is understood that in expanding the pair of bracketed terms in the last result the terms should be
symmetrised over $b\uc d$ and also truncated to terms of order $\BigO{\eps^m}$. Note that the first term
on the right hand side of this equation vanishes by way of the results described above.

Comparing the order $m$ terms in equation (\ref{eq:GenGammaA}) and (\ref{eq:GenGammaB}) leads to the
following equation
\begin{align}
   \nGammaBar{m}^{a}{}_{b\uc d}
   = \nGammaBar{m}^{a}{}_{(b\uc,d)}
   - (n+1)\left(\m \nGammaBar{m-2}^{a}{}_{p(\uc}
                   \nGammaBar{  2}^{p}{}_{bd)}
                  +\nGammaBar{m-3}^{a}{}_{p(\uc}
                   \nGammaBar{  3}^{p}{}_{bd)}
                  +\nGammaBar{m-4}^{a}{}_{p(\uc}
                   \nGammaBar{  4}^{p}{}_{bd)}
                  + \dots
                  + \nGammaBar{  n+1}^{a}{}_{p(\uc}
                    \nGammaBar{m-n-1}^{p}{}_{bd)}
   \right)
   \label{eq:GenGammaC}
\end{align}
This one equation is all that is needed to compute all of the
$\nGammaBar{p}^{a}{}_{b\uc d}$ for $p=3,4,5,\dots m$ given just
the $\nGammaBar{p}^{a}{}_{bd}$ for $p=2,3,4,\dots m$. For example,
suppose $m=5$ and suppose that we are given
$\nGammaBar{p}^{a}{}_{bd}$ for $p=2,3,4,5$. Then with $n=1$ we can
use equation (\ref{eq:GenGammaC}) to compute in turn,
$\nGammaBar{p}^{a}{}_{bc_1d}$ for $p=3,4,5$. Then with $n=2$ we
compute
$\nGammaBar{p}^{a}{}_{bc_1c_2d}$ for $p=4,5$ and finally with $n=3$
we compute $\nGammaBar{p}^{a}{}_{bc_1c_2c_3d}$ for $p=5$. There
are no terms like
$\nGammaBar{p}^{a}{}_{bc_1c_2c_3c_4d}$ for $p\le5$ due to the
corollary given earlier.

\clearpage

The explicit computations for $m=5$ are as follows.

For $n=1$,
\begin{align}
   \nGammaBar{3}^{a}{}_{bc_1d}
   &=
   \nGammaBar{3}^{a}{}_{(bc_1,d)}\\
   %-----------------------------------------------------------------------
   \nGammaBar{4}^{a}{}_{bc_1d}
   &=
   \nGammaBar{4}^{a}{}_{(bc_1,d)}
   - 2 \nGammaBar{2}^{a}{}_{p(c_1}
       \nGammaBar{2}^{p}{}_{bd)}\\
   %-----------------------------------------------------------------------
   \nGammaBar{5}^{a}{}_{bc_1d}
   &=
   \nGammaBar{5}^{a}{}_{(bc_1,d)}
   - 2 \nGammaBar{3}^{a}{}_{p(c_1}
       \nGammaBar{2}^{p}{}_{bd)}
   - 2 \nGammaBar{2}^{a}{}_{p(c_1}
       \nGammaBar{3}^{p}{}_{bd)}
\end{align}

For $n=2$,
\begin{align}
   \nGammaBar{4}^{a}{}_{bc_1c_2d}
   &=
   \nGammaBar{4}^{a}{}_{(bc_1c_2,d)}\\
   %-----------------------------------------------------------------------
   \nGammaBar{5}^{a}{}_{bc_1c_2d}
   &=
   \nGammaBar{5}^{a}{}_{(bc_1c_2,d)}
   - 3 \nGammaBar{2}^{a}{}_{p(c_1c_2}
       \nGammaBar{2}^{p}{}_{bd)}
\end{align}

For $n=3$,
\begin{align}
   \nGammaBar{5}^{a}{}_{bc_1c_2c_3d}
   &=
   \nGammaBar{5}^{a}{}_{(bc_1c_2c_3,d)}
\end{align}

\clearpage

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

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

   g_{a b}::Metric.
   g^{a b}::InverseMetric.
   g_{a}^{b}::KroneckerDelta.
   g^{a}_{b}::KroneckerDelta.
   \delta^{a}_{b}::KroneckerDelta.
   \delta_{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}).

   x^{a}::Depends(D{#}).

   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{#}).

   import cdblib

   term0 = cdblib.get ('GammaRterm0','connection.json')
   term1 = cdblib.get ('GammaRterm2','connection.json')
   term2 = cdblib.get ('GammaRterm3','connection.json')
   term3 = cdblib.get ('GammaRterm4','connection.json')
   term4 = cdblib.get ('GammaRterm5','connection.json')

   # LCB: these terms were not computed in connection.tex so set them to zero
   #      maybe in the future I will compute down to term6.

   term5 := 0.
   term6 := 0.

   # genGmn : m = eps order of Rabcd terms
   #          n = number of c indices

   # --------------------------------------------------------------------------
   # rules for building the genGmn

   # note: after applying each rule, must symmetrise over (b c1 c2 ... cn d)

   # n = 0

   genG20 := genG2^{a}_{b d}.
   genG30 := genG3^{a}_{b d}.
   genG40 := genG4^{a}_{b d}.
   genG50 := genG5^{a}_{b d}.

   defG20 := genG2^{d}_{a b} -> @(term1).
   defG30 := genG3^{d}_{a b} -> @(term2).
   defG40 := genG4^{d}_{a b} -> @(term3).
   defG50 := genG5^{d}_{a b} -> @(term4).

   # LCB: rncGamma in connection.json limited to "term4" (ie. to 4th order in x)
   #      so can only compute genG3*, genG4* and genG5* (at this stage)
   #      but it doesn't hurt to provide the definitions for genG6*, genG7* etc. we just won't use them (at this atage)

   defG60 := genG6^{d}_{a b} -> @(term5).
   defG70 := genG7^{d}_{a b} -> @(term6).

   # n = 1

   defG31 := genG3^{a}_{b c1 d} -> D_{d}{genG3^{a}_{b c1}}.

   defG41 := genG4^{a}_{b c1 d} -> D_{d}{genG4^{a}_{b c1}}
                                   - 2 genG2^{a}_{p c1} genG2^{p}_{b d}.

   defG51 := genG5^{a}_{b c1 d} -> D_{d}{genG5^{a}_{b c1}}
                                   - 2 genG3^{a}_{p c1} genG2^{p}_{b d}
                                   - 2 genG2^{a}_{p c1} genG3^{p}_{b d}.

   defG61 := genG6^{a}_{b c1 d} -> D_{d}{genG6^{a}_{b c1}}
                                   - 2 genG4^{a}_{p c1} genG2^{p}_{b d}
                                   - 2 genG3^{a}_{p c1} genG3^{p}_{b d}
                                   - 2 genG3^{a}_{p c1} genG4^{p}_{b d}.

   defG71 := genG7^{a}_{b c1 d} -> D_{d}{genG7^{a}_{b c1}}
                                   - 2 genG5^{a}_{p c1} genG2^{p}_{b d}
                                   - 2 genG4^{a}_{p c1} genG3^{p}_{b d}
                                   - 2 genG3^{a}_{p c1} genG4^{p}_{b d}
                                   - 2 genG2^{a}_{p c1} genG5^{p}_{b d}.

   # n = 2

   defG42 := genG4^{a}_{b c1 c2 d} -> D_{d}{genG4^{a}_{b c1 c2}}.

   defG52 := genG5^{a}_{b c1 c2 d} -> D_{d}{genG5^{a}_{b c1 c2}}
                                      - 3 genG3^{a}_{p c1 c2} genG2^{p}_{b d}.

   defG62 := genG6^{a}_{b c1 c2 d} -> D_{d}{genG6^{a}_{b c1 c2}}
                                      - 3 genG4^{a}_{p c1 c2} genG2^{p}_{b d}
                                      - 3 genG3^{a}_{p c1 c2} genG3^{p}_{b d}.

   defG72 := genG7^{a}_{b c1 c2 d} -> D_{d}{genG7^{a}_{b c1 c2}}
                                      - 3 genG5^{a}_{p c1 c2} genG2^{p}_{b d}
                                      - 3 genG4^{a}_{p c1 c2} genG3^{p}_{b d}
                                      - 3 genG3^{a}_{p c1 c2} genG4^{p}_{b d}.

   # n = 3

   defG53 := genG5^{a}_{b c1 c2 c3 d} -> D_{d}{genG5^{a}_{b c1 c2 c3}}.

   defG63 := genG6^{a}_{b c1 c2 c3 d} -> D_{d}{genG6^{a}_{b c1 c2 c3}}
                                         - 4 genG3^{a}_{p c1 c2 c3} genG3^{p}_{b d}.

   defG73 := genG7^{a}_{b c1 c2 c3 d} -> D_{d}{genG7^{a}_{b c1 c2 c3}}
                                         - 4 genG4^{a}_{p c1 c2 c3} genG3^{p}_{b d}
                                         - 4 genG3^{a}_{p c1 c2 c3} genG4^{p}_{b d}.

   # n = 4

   defG64 := genG6^{a}_{b c1 c2 c3 c4 d} -> D_{d}{genG6^{a}_{b c1 c2 c3 c4}}.

   defG74 := genG7^{a}_{b c1 c2 c3 c4 d} -> D_{d}{genG7^{a}_{b c1 c2 c3 c4}}
                                            - 5 genG5^{a}_{p c1 c2 c3 c4} genG2^{p}_{b d}.

   # n = 5

   defG75 := genG7^{a}_{b c1 c2 c3 c4 c5 d} -> D_{d}{genG7^{a}_{b c1 c2 c3 c4 c5}}.

   # --------------------------------------------------------------------------
   # build the genGmn

   # ==========================================================================
   # n = 1

   genG31 := genG3^{a}_{b c1 d}.                              # cdb (genG31.000,genG31)
   genG41 := genG4^{a}_{b c1 d}.                              # cdb (genG41.000,genG41)
   genG51 := genG5^{a}_{b c1 d}.
   # genG61 := genG6^{a}_{b c1 d}.
   # genG71 := genG7^{a}_{b c1 d}.

   # --------------------------------------------------------------------------
   substitute     (genG20,defG20)                             # cdb (genG20.001,genG20)
   substitute     (genG30,defG30)                             # cdb (genG30.001,genG30)
   substitute     (genG40,defG40)                             # cdb (genG40.001,genG40)
   substitute     (genG50,defG50)                             # cdb (genG50.001,genG50)

   # --------------------------------------------------------------------------
   substitute     (genG31,defG31)                             # cdb (genG31.001,genG31)
   substitute     (genG31,defG30)                             # cdb (genG31.002,genG31)

   distribute     (genG31)                                    # cdb (genG31.002,genG31)
   unwrap         (genG31)                                    # cdb (genG31.003,genG31)
   product_rule   (genG31)                                    # cdb (genG31.004,genG31)
   distribute     (genG31)                                    # cdb (genG31.005,genG31)
   substitute     (genG31,$D_{a}{x^b}->\delta_{a}^{b}$)       # cdb (genG31.006,genG31)
   eliminate_kronecker (genG31)                               # cdb (genG31.007,genG31)
   sym            (genG31,$_{b}, _{c1}, _{d}$)
   sort_product   (genG31)                                    # cdb (genG31.008,genG31)
   rename_dummies (genG31)                                    # cdb (genG31.009,genG31)
   canonicalise   (genG31)                                    # cdb (genG31.010,genG31)

   # --------------------------------------------------------------------------
   substitute     (genG41,defG41)                             # cdb (genG41.001,genG41)
   substitute     (genG41,defG40)                             # cdb (genG41.002,genG41)
   substitute     (genG41,defG20,repeat=True)                 # cdb (genG41.003,genG41)

   distribute     (genG41)                                    # cdb (genG41.004,genG41)
   unwrap         (genG41)                                    # cdb (genG41.005,genG41)
   product_rule   (genG41)                                    # cdb (genG41.006,genG41)
   distribute     (genG41)                                    # cdb (genG41.007,genG41)
   substitute     (genG41,$D_{a}{x^b}->\delta_{a}^{b}$)       # cdb (genG41.008,genG41)
   eliminate_kronecker (genG41)                               # cdb (genG41.009,genG41)
   sym            (genG41,$_{b}, _{c1}, _{d}$)
   sort_product   (genG41)                                    # cdb (genG41.010,genG41)
   rename_dummies (genG41)                                    # cdb (genG41.011,genG41)
   canonicalise   (genG41)                                    # cdb (genG41.012,genG41)

   # --------------------------------------------------------------------------
   substitute     (genG51,defG51)
   substitute     (genG51,defG50)
   substitute     (genG51,defG30,repeat=True)
   substitute     (genG51,defG20,repeat=True)

   distribute     (genG51)
   unwrap         (genG51)
   product_rule   (genG51)
   distribute     (genG51)
   substitute     (genG51,$D_{a}{x^b}->\delta_{a}^{b}$)
   eliminate_kronecker (genG51)
   sym            (genG51,$_{b}, _{c1}, _{d}$)
   sort_product   (genG51)
   rename_dummies (genG51)
   canonicalise   (genG51)

   # update the rules

   defG31 := genG3^{a}_{b c1 d} -> @(genG31).
   defG41 := genG4^{a}_{b c1 d} -> @(genG41).
   defG51 := genG5^{a}_{b c1 d} -> @(genG51).

   # ==========================================================================
   # n = 2

   genG42 := genG4^{a}_{b c1 c2 d}.                           # cdb (genG42.000,genG42)
   genG52 := genG5^{a}_{b c1 c2 d}.
   # genG62 := genG6^{a}_{b c1 c2 d}.
   # genG72 := genG7^{a}_{b c1 c2 d}.

   # --------------------------------------------------------------------------
   substitute     (genG42,defG42)                             # cdb (genG42.001,genG42)
   substitute     (genG42,defG41)                             # cdb (genG42.002,genG42)

   distribute     (genG42)                                    # cdb (genG42.003,genG42)
   unwrap         (genG42)                                    # cdb (genG42.004,genG42)
   product_rule   (genG42)                                    # cdb (genG42.005,genG42)
   distribute     (genG42)                                    # cdb (genG42.006,genG42)
   substitute     (genG42,$D_{a}{x^b}->\delta_{a}^{b}$)       # cdb (genG42.007,genG42)
   eliminate_kronecker (genG42)                               # cdb (genG42.008,genG42)
   sym            (genG42,$_{b}, _{c1}, _{c2}, _{d}$)
   sort_product   (genG42)                                    # cdb (genG42.009,genG42)
   rename_dummies (genG42)                                    # cdb (genG42.010,genG42)
   canonicalise   (genG42)                                    # cdb (genG42.011,genG42)

   # --------------------------------------------------------------------------
   substitute     (genG52,defG52)
   substitute     (genG52,defG51)
   substitute     (genG52,defG31,repeat=True)
   substitute     (genG52,defG20,repeat=True)

   distribute     (genG52)
   unwrap         (genG52)
   product_rule   (genG52)
   distribute     (genG52)
   substitute     (genG52,$D_{a}{x^b}->\delta_{a}^{b}$)
   eliminate_kronecker (genG52)
   sym            (genG52,$_{b}, _{c1}, _{c2}, _{d}$)
   sort_product   (genG52)
   rename_dummies (genG52)
   canonicalise   (genG52)                                    # cdb (genG52.001,genG52)

   # update the rules

   defG42 := genG4^{a}_{b c1 c2 d} -> @(genG42).
   defG52 := genG5^{a}_{b c1 c2 d} -> @(genG52).

   # ==========================================================================
   # n = 3

   genG53 := genG5^{a}_{b c1 c2 c3 d}.
   # genG63 := genG6^{a}_{b c1 c2 c3 d}.
   # genG73 := genG7^{a}_{b c1 c2 c3 d}.

   # --------------------------------------------------------------------------
   substitute     (genG53,defG53)
   substitute     (genG53,defG52)

   distribute     (genG53)
   unwrap         (genG53)
   product_rule   (genG53)
   distribute     (genG53)
   substitute     (genG53,$D_{a}{x^b}->\delta_{a}^{b}$)
   eliminate_kronecker (genG53)
   sym            (genG53,$_{b}, _{c1}, _{c2}, _{c3}, _{d}$)
   sort_product   (genG53)
   rename_dummies (genG53)
   canonicalise   (genG53)                                    # cdb (genG53.001,genG53)

   # update the rules

   defG53 := genG5^{a}_{b c1 c2 c3 d} -> @(genG53).

\end{cadabra}

\clearpage

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{genG31.000} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.001} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.002} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.003} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.004} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.005} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.006} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.007} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.008} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.009} \end{dmath*}
   \begin{dmath*} \cdb*{genG31.010} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{genG41.000} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.001} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.002} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.003} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.004} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.005} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.006} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.007} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.008} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.009} \end{dmath*}
   % \begin{dmath*} \cdb*{genG41.010} \end{dmath*}
   % \begin{dmath*} \cdb*{genG41.011} \end{dmath*}
   \begin{dmath*} \cdb*{genG41.012} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{genG42.000} \end{dmath*}
   \begin{dmath*} \cdb*{genG42.001} \end{dmath*}
   \begin{dmath*} \cdb*{genG42.002} \end{dmath*}
   \begin{dmath*} \cdb*{genG42.003} \end{dmath*}
   \begin{dmath*} \cdb*{genG42.004} \end{dmath*}
   \begin{dmath*} \cdb*{genG42.005} \end{dmath*}
   % \begin{dmath*} \cdb*{genG42.006} \end{dmath*}
   % \begin{dmath*} \cdb*{genG42.007} \end{dmath*}
   % \begin{dmath*} \cdb*{genG42.008} \end{dmath*}
   % \begin{dmath*} \cdb*{genG42.009} \end{dmath*}
   % \begin{dmath*} \cdb*{genG42.010} \end{dmath*}
   \begin{dmath*} \cdb*{genG42.011} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{cadabra}
   # 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,$ \nabla_{e f g h}{R_{a b c d}}    -> A008_{a b c d e f g h} $)
       substitute (obj,$ \nabla_{e f g}{R_{a b c d}}      -> A007_{a b c d e f g}   $)
       substitute (obj,$ \nabla_{e f}{R_{a b c d}}        -> A006_{a b c d e f}     $)
       substitute (obj,$ \nabla_{e}{R_{a b c d}}          -> A005_{a b c d e}       $)
       substitute (obj,$ R_{a b c d}                      -> A004_{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 c d}            -> R_{a b c d}                   $)
       substitute (obj,$ A005_{a b c d e}          -> \nabla_{e}{R_{a b c d}}       $)
       substitute (obj,$ A006_{a b c d e f}        -> \nabla_{e f}{R_{a b c d}}     $)
       substitute (obj,$ A007_{a b c d e f g}      -> \nabla_{e f g}{R_{a b c d}}   $)
       substitute (obj,$ A008_{a b c d e f g h}    -> \nabla_{e f g h}{R_{a b c d}} $)

       return obj

   # --------------------------------------------------------------------------
   symG20 := @(genG20) A^{b} A^{d}.                           # cdb (symG20.100,symG20)

   distribute            (symG20)                             # cdb (symG20.101,symG20)
   symG20 = product_sort (symG20)                             # cdb (symG20.102,symG20)
   rename_dummies        (symG20)                             # cdb (symG20.103,symG20)
   canonicalise          (symG20)                             # cdb (symG20.104,symG20)

   # --------------------------------------------------------------------------
   symG30 := @(genG30) A^{b} A^{d}.                           # cdb (symG30.100,symG30)

   distribute            (symG30)                             # cdb (symG30.101,symG30)
   symG30 = product_sort (symG30)                             # cdb (symG30.102,symG30)
   rename_dummies        (symG30)                             # cdb (symG30.103,symG30)
   canonicalise          (symG30)                             # cdb (symG30.104,symG30)

   # --------------------------------------------------------------------------
   symG40 := @(genG40) A^{b} A^{d}.                           # cdb (symG40.100,symG40)

   distribute            (symG40)                             # cdb (symG40.101,symG40)
   symG40 = product_sort (symG40)                             # cdb (symG40.102,symG40)
   rename_dummies        (symG40)                             # cdb (symG40.103,symG40)
   canonicalise          (symG40)                             # cdb (symG40.104,symG40)

   # --------------------------------------------------------------------------
   symG50 := @(genG50) A^{b} A^{d}.                           # cdb (symG50.100,symG50)

   distribute            (symG50)                             # cdb (symG50.101,symG50)
   symG50 = product_sort (symG50)                             # cdb (symG50.102,symG50)
   rename_dummies        (symG50)                             # cdb (symG50.103,symG50)
   canonicalise          (symG50)                             # cdb (symG50.104,symG50)

   # --------------------------------------------------------------------------
   symG31 := @(genG31) A^{b} A^{c1} A^{d}.                    # cdb (symG31.100,symG31)

   distribute            (symG31)                             # cdb (symG31.101,symG31)
   symG31 = product_sort (symG31)                             # cdb (symG31.102,symG31)
   rename_dummies        (symG31)                             # cdb (symG31.103,symG31)
   canonicalise          (symG31)                             # cdb (symG31.104,symG31)

   # --------------------------------------------------------------------------
   symG41 := @(genG41) A^{b} A^{c1} A^{d}.                    # cdb (symG41.100,symG41)

   distribute            (symG41)                             # cdb (symG41.101,symG41)
   symG41 = product_sort (symG41)                             # cdb (symG41.102,symG41)
   rename_dummies        (symG41)                             # cdb (symG41.103,symG41)
   canonicalise          (symG41)                             # cdb (symG41.104,symG41)

   # --------------------------------------------------------------------------
   symG51 := @(genG51) A^{b} A^{c1} A^{d}.                    # cdb (symG51.100,symG51)

   distribute            (symG51)                             # cdb (symG51.101,symG51)
   symG51 = product_sort (symG51)                             # cdb (symG51.102,symG51)
   rename_dummies        (symG51)                             # cdb (symG51.103,symG51)
   canonicalise          (symG51)                             # cdb (symG51.104,symG51)

   # --------------------------------------------------------------------------
   symG42 := @(genG42) A^{b} A^{c1} A^{c2} A^{d}.             # cdb (symG42.100,symG42)

   distribute            (symG42)                             # cdb (symG42.101,symG42)
   symG42 = product_sort (symG42)                             # cdb (symG42.102,symG42)
   rename_dummies        (symG42)                             # cdb (symG42.103,symG42)
   canonicalise          (symG42)                             # cdb (symG42.104,symG42)

   # --------------------------------------------------------------------------
   symG52 := @(genG52) A^{b} A^{c1} A^{c2} A^{d}.             # cdb (symG52.100,symG52)

   distribute            (symG52)                             # cdb (symG52.101,symG52)
   symG52 = product_sort (symG52)                             # cdb (symG52.102,symG52)
   rename_dummies        (symG52)                             # cdb (symG52.103,symG52)
   canonicalise          (symG52)                             # cdb (symG52.104,symG52)

   # --------------------------------------------------------------------------
   symG53 := @(genG53) A^{b} A^{c1} A^{c2} A^{c3} A^{d}.      # cdb (symG53.100,symG53)

   distribute            (symG53)                             # cdb (symG53.101,symG53)
   symG53 = product_sort (symG53)                             # cdb (symG53.102,symG53)
   rename_dummies        (symG53)                             # cdb (symG53.103,symG53)
   canonicalise          (symG53)                             # cdb (symG53.104,symG53)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{symG31.100} \end{dmath*}
   \begin{dmath*} \cdb*{symG31.101} \end{dmath*}
   \begin{dmath*} \cdb*{symG31.102} \end{dmath*}
   \begin{dmath*} \cdb*{symG31.103} \end{dmath*}
   \begin{dmath*} \cdb*{symG31.104} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{symG41.100} \end{dmath*}
   \begin{dmath*} \cdb*{symG41.101} \end{dmath*}
   \begin{dmath*} \cdb*{symG41.102} \end{dmath*}
   \begin{dmath*} \cdb*{symG41.103} \end{dmath*}
   \begin{dmath*} \cdb*{symG41.104} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{symG51.104} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{symG42.104} \end{dmath*}
   \begin{dmath*} \cdb*{symG52.104} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{symG53.104} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{cadabra}
   def reformat (obj,scale):
       foo  = Ex(str(scale))
       bah := @(foo) @(obj).
       distribute (bah)
       factor_out (bah,$A^{a?},x^{b?}$)
       ans := @(bah) / @(foo).
       return ans

   fooG20 = reformat (symG20,3)
   fooG30 = reformat (symG30,12)
   fooG40 = reformat (symG40,360)
   fooG50 = reformat (symG50,180)

   fooG31 = reformat (symG31,2)
   fooG41 = reformat (symG41,120)
   fooG51 = reformat (symG51,180)

   fooG42 = reformat (symG42,15)
   fooG52 = reformat (symG52,90)

   fooG53 = reformat (symG53,3)

   genGamma0 := @(fooG20) + @(fooG30) + @(fooG40) + @(fooG50).  # cdb (genGamma0.000,genGamma0)
   genGamma1 := @(fooG31) + @(fooG41) + @(fooG51).              # cdb (genGamma1.000,genGamma1)
   genGamma2 := @(fooG42) + @(fooG52).                          # cdb (genGamma2.000,genGamma2)
   genGamma3 := @(fooG53).                                      # cdb (genGamma3.000,genGamma3)

   cdblib.create ('genGamma.json')

   cdblib.put ('genGamma0',genGamma0,'genGamma.json')
   cdblib.put ('genGamma1',genGamma1,'genGamma.json')
   cdblib.put ('genGamma2',genGamma2,'genGamma.json')
   cdblib.put ('genGamma3',genGamma3,'genGamma.json')

   cdblib.put ('genGamma01',fooG20,'genGamma.json')
   cdblib.put ('genGamma02',fooG30,'genGamma.json')
   cdblib.put ('genGamma03',fooG40,'genGamma.json')
   cdblib.put ('genGamma04',fooG50,'genGamma.json')

   cdblib.put ('genGamma11',fooG31,'genGamma.json')
   cdblib.put ('genGamma12',fooG41,'genGamma.json')
   cdblib.put ('genGamma13',fooG51,'genGamma.json')

   cdblib.put ('genGamma21',fooG42,'genGamma.json')
   cdblib.put ('genGamma22',fooG52,'genGamma.json')

   cdblib.put ('genGamma31',fooG53,'genGamma.json')

\end{cadabra}

\clearpage

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

\begin{dgroup*}
   \begin{dmath*} A^b A^c \Gamma^{a}_{b c}(x) = \cdb{genGamma0.000} \end{dmath*}
   \begin{dmath*} A^b A^c A^d \Gamma^{a}_{b c d}(x) = \cdb{genGamma1.000} \end{dmath*}
   \begin{dmath*} A^b A^c A^d A^e \Gamma^{a}_{b c d e}(x) = \cdb{genGamma2.000} \end{dmath*}
   \begin{dmath*} A^b A^c A^d A^e A^f \Gamma^{a}_{b c d e f}(x) = \cdb{genGamma3.000} \end{dmath*}
\end{dgroup*}

\clearpage

\begin{cadabra}
   scaledGamma0 := 360 @(genGamma0).  # cdb (scaledGamma0.001,scaledGamma0)
   scaledGamma1 := 360 @(genGamma1).  # cdb (scaledGamma1.001,scaledGamma1)
   scaledGamma2 :=  90 @(genGamma2).  # cdb (scaledGamma2.001,scaledGamma2)
   scaledGamma3 :=   3 @(genGamma3).  # cdb (scaledGamma3.001,scaledGamma3)

\end{cadabra}

\clearpage

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

This is the same as the previous page but with a small change in the format to avoid fractions.

\begin{dgroup*}
   \begin{dmath*} 360 A^b A^c \Gamma^{a}_{b c}(x) = \cdb{scaledGamma0.001} \end{dmath*}
   \begin{dmath*} 360 A^b A^c A^d \Gamma^{a}_{b c d}(x) = \cdb{scaledGamma1.001} \end{dmath*}
   \begin{dmath*}  90 A^b A^c A^d A^e \Gamma^{a}_{b c d e}(x) = \cdb{scaledGamma2.001} \end{dmath*}
   \begin{dmath*}   3 A^b A^c A^d A^e A^f \Gamma^{a}_{b c d e f}(x) = \cdb{scaledGamma3.001} \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}
   tmp0 := @(fooG20) + @(fooG30).
   tmp1 := @(fooG31).

   alt0 := @(genGamma0).
   alt1 := @(genGamma1).
   alt2 := @(genGamma2).
   alt3 := @(genGamma3).

   alt0scaled := @(scaledGamma0).
   alt1scaled := @(scaledGamma1).
   alt2scaled := @(scaledGamma2).
   alt3scaled := @(scaledGamma3).

   substitute (tmp0, $A^{a}->1$)
   substitute (tmp1, $A^{a}->1$)

   substitute (alt0, $A^{a}->1$)
   substitute (alt1, $A^{a}->1$)
   substitute (alt2, $A^{a}->1$)
   substitute (alt3, $A^{a}->1$)

   substitute (alt0scaled, $A^{a}->1$)
   substitute (alt1scaled, $A^{a}->1$)
   substitute (alt2scaled, $A^{a}->1$)
   substitute (alt3scaled, $A^{a}->1$)

   cdblib.create ('genGamma.export')

   # 4th order gen gamma
   cdblib.put ('gen_gamma_0_4th',tmp0,'genGamma.export')
   cdblib.put ('gen_gamma_1_4th',tmp1,'genGamma.export')

   # 6th order gen gamma
   cdblib.put ('gen_gamma_0',alt0,'genGamma.export')
   cdblib.put ('gen_gamma_1',alt1,'genGamma.export')
   cdblib.put ('gen_gamma_2',alt2,'genGamma.export')
   cdblib.put ('gen_gamma_3',alt3,'genGamma.export')

   # 6th order gen gamma scaled
   cdblib.put ('gen_gamma_0_scaled',alt0scaled,'genGamma.export')
   cdblib.put ('gen_gamma_1_scaled',alt1scaled,'genGamma.export')
   cdblib.put ('gen_gamma_2_scaled',alt2scaled,'genGamma.export')
   cdblib.put ('gen_gamma_3_scaled',alt3scaled,'genGamma.export')

   checkpoint.append (tmp0)
   checkpoint.append (tmp1)

   checkpoint.append (alt0)
   checkpoint.append (alt1)
   checkpoint.append (alt2)
   checkpoint.append (alt3)

   checkpoint.append (alt0scaled)
   checkpoint.append (alt1scaled)
   checkpoint.append (alt2scaled)
   checkpoint.append (alt3scaled)

\end{cadabra}

% =================================================================================================
% 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}


\newpage\section{Problems}

		\prob{https://artofproblemsolving.com/community/c6h1291293p6832329}{IRAN 3rd Round 2016 P2}{E}{Let $ABC$ be an arbitrary triangle. Let $E,F$ be two points on $AB,AC$ respectively such that their distance to the midpoint of $BC$ is equal. Let $P$ be the second intersection of the triangles $ABC,AEF$ circumcircles . The tangents from $E,F$ to the circumcircle of $AEF$ intersect each other at $K$. Prove that : $\angle KPA = 90$}

		\prob{https://artofproblemsolving.com/community/c6h1434843p8120660}{IRAN 2nd Round 2016 P6}{E}{Let $ABC$ be a triangle and $X$ be a point on its circumcircle. $Q,P$ lie on a line $BC$ such that $XQ\perp AC , XP\perp AB$. Let $Y$ be the circumcenter of $\triangle XQP$. Prove that $ABC$ is equilateral triangle if and if only $Y$ moves on a circle when $X$ varies on the circumcircle of $ABC$}

		\prob{https://artofproblemsolving.com/community/c6h1460735p8471885}{AoPS}{E}{Consider $ABC$ with orthic triangle $A'B'C'$, let $AA'\cap B'C' = E$ and $E'$ be reflection of $E$ wrt $BC$. Let $M$ be midpoint of $BC$ and $O$ be circumcenter of $E'B'C'$. Let $M'$ be projection of $O$ on $BC$ and $N$ be the intersection of a perpendicular to $B'C'$ through $E$ with $BC$. Prove that $MM' = 1/4MN$.}

		\prob{https://artofproblemsolving.com/community/c6h360730p1973873}{IRAN 3rd Round 2010 D3, P5}{M}{In a triangle $ABC$, $I$ is the incenter. $D$ is the reflection of $A$ to $I$. the incircle is tangent to $BC$ at point $E$. $DE$ cuts $IG$ at $P$ ($G$ is centroid). $M$ is the midpoint of $BC$. Prove that $AP||DM$ and $AP=2DM$.}

		\prob{https://artofproblemsolving.com/community/c6h429226p2428694}{IRAN 3rd Round 2011 G5}{M}{Given triangle $ABC$, $D$ is the foot of the external angle bisector of $A$, $I$ its incenter and $I_a$ its $A$-excenter. Perpendicular from $I$ to $DI_a$ intersects the circumcircle of triangle in $A'$. Define $B'$ and $C'$ similarly. Prove that $AA',BB'$ and $CC'$ are concurrent.}

		\prob{https://artofproblemsolving.com/community/c6t48f6h1519616_geometry}{AoPS3}{E}{$I$ is the incenter of $ABC$,  $PI,QI{\perp}BC$, $PA,QA$ intersect $BC$ at $DE$. Prove: $IADE$ is on a circle.}

			\fig{1}{AoPS3}{AoPS3}

		\prob{https://artofproblemsolving.com/community/c6t48f6h1523774_nice_property}{AoPS4}{E}{Given a triangle $ABC$, the incircle $(I)$ touch $BC,CA,AB$ at $D,E,F$ respectively. Let $AA_1,BB_1,CC_1$ be $A,B,C-altitude$ respectively. Let $N$ be the orthocenter of the triangle $AEF$. Prove that $N$ is the incenter of $AB_1C_1$}

			\fig{1}{AoPS4}{AoPS4}

		\prob{https://artofproblemsolving.com/community/c6h1087613p4817114}{IRAN TST 2015 Day 2, P3}{M}{$ABCD$ is a circumscribed and inscribed quadrilateral. $O$ is the circumcenter of the quadrilateral. $E,\ F$ and $S$ are the intersections of $AB,\ CD$; $AD,\ BC$ and $AC,\ BD$ respectively. $E'$ and $F'$ are points on $AD$ and $AB$ such that $\angle AEE'=\angle E'ED$ and $\angle AFF'=\angle F'FB$. $X$ and $Y$ are points on $OE'$ and $OF'$ such that $\frac{XA}{XD}=\frac{EA}{ED}$ and $\frac{YA}{YB}=\frac{FA}{FB}$. $M$ is the midpoint of arc $BD$ of $(O)$ which contains $A$. Prove that the circumcircles of triangles $OXY$ and $OAM$ are coaxial with the circle with diameter $OS$.}

			\fig{1}{ITST2015D3P3i}{Actual Prob}
			\fig{1}{ITST2015D3P3ii}{Inverted}

		\prob{https://artofproblemsolving.com/community/c6h1352164p7389108}{USA TST 2017 P2}{M}{Let $ABC$ be an acute scalene triangle with circumcenter $O$, and let $T$ be on line $BC$ such that $\angle TAO = 90^{\circ}$. The circle with diameter $\overline{AT}$ intersects the circumcircle of $\triangle BOC$ at two points $A_1$ and $A_2$, where $OA_1 < OA_2$. Points $B_1$, $B_2$, $C_1$, $C_2$ are defined analogously.

			\begin{enumerate}
				\item Prove that $\overline{AA_1}$, $\overline{BB_1}$, $\overline{CC_1}$ are concurrent.
				\item Prove that $\overline{AA_2}$, $\overline{BB_2}$, $\overline{CC_2}$ are concurrent on the Euler line of triangle $ABC$.
			\end{enumerate}}

		\prob{https://artofproblemsolving.com/community/c6t48f6h1522766_tangent_circles}{AoPS2}{}{Let $ABC$ be a triangle with circumcenter $O$ and altitude $AH.$ $AO$ meets $BC$ at $M$ and meets the circle $(BOC)$ again at $N.$ $P$ is the midpoint of $MN.$ $K$ is the projection of $P$ on line $AH.$ Prove that the circle $(K,KH)$ is tangent to the circle $(BOC).$}

			\fig{1}{AoPS2}{AoPS2}

			\solu{Inversion all the way...}

		\prob{https://artofproblemsolving.com/community/c6h46718}{AoPS5}{}{Let $ABC$ be a triangle inscribed in $(O)$ and $P$ be a point. Call $P'$ be the isogonal conjugate point of $P$. Let $A'$ be the second intersection of $AP'$ and $(O)$. Denote by $M$ the intersection of $BC$ and $A'P$. Prove that $P'M \parallel AP$.}

			\fig{1}{AoPS5}{AoPS5}

		\prob{https://artofproblemsolving.com/community/c6h283185}{AoPS}{E}{$I$ is the incenter of a non-isosceles triangle $\triangle ABC$. If the incircle touches $BC, CA, AB$ at $A_1, B_1, C_1$ respectively, prove that the circumcentres of the triangles $\triangle AIA_1$, $\triangle BIB_1$, $\triangle CIC_1$ are collinear.}

		\prob{https://artofproblemsolving.com/community/c6h1501095p8898504}{AoPS}{M}{Given $\triangle ABC$ and a point $P$ inside. $AP$ cuts $BC$ at $M.$ Let $M', A'$ be the reflection of $M, A$ in the perpendicular bisector of $BC.$ $A'P$ cuts the perpendicular bisector of $BC$ at $N.$ Let $Q$ be the isogonal conjugate of $P$ in triangle $ABC.$ Prove that $QM'\parallel AN$.}

		\prob{https://artofproblemsolving.com/community/c6h1301365p6934249}{IRAN 3rd Round 2016 G6}{E}{Given triangle $\triangle ABC$ and let $D,E,F$ be the foot of angle bisectors of $A,B,C$ ,respectively. $M,N$ lie on $EF$ such that $AM=AN$. Let $H$ be the foot of $A$-altitude on $BC$.\\
		Points $K,L$ lie on $EF$ such that triangles $\triangle AKL, \triangle HMN$ are correspondingly similar (with the given order of vertices's) such that $AK \not\parallel HM$ and $AK \not\parallel HN$. Show that: $DK=DL$.}

			\fig{1}{IRAN3rd2016G6}{IRAN 3rd Round 2016 G6}

		\prob{https://artofproblemsolving.com/community/c6h1438017p8160421}{Iran TST 2017 T3 P6}{H}{In triangle $ABC$ let $O$ and $H$ be the circumcenter and the orthocenter. The point $P$ is the reflection of $A$ with respect to $OH$. Assume that $P$ is not on the same side of $BC$ as $A$. Points $E,F$ lie on $AB,AC$ respectively such that $BE=PC \ ,  CF=PB$. Let $K$ be the intersection point of $AP,OH$. Prove that $\angle EKF = 90 ^{\circ}$.}

		\tr{Spiral Similarity (points on $AB, AC$ with some properties)}

			\figdf{1}{ITST2017T3P6}{Iran TST 2017 T3 P6}

		\prob{https://artofproblemsolving.com/community/c6h360732p1973876}{IRAN 3rd Round 2010 D3, P6}{M}{In a triangle $ABC$, $\angle C=45^{\circ}$. $AD$ is the altitude of the triangle. $X$ is on $AD$ such that $\angle XBC=90-\angle B$ ($X$ is inside of the triangle). $AD$ and $CX$ cut the circumcircle of $ABC$ in $M$ and $N$ respectively. Ff the tangent to $\odot ABC$ at $M$ cuts $AN$ at $P$, prove that $P, B$ and $O$ are collinear.}

		\tr{Cross-Ratio}

		\prob{https://artofproblemsolving.com/community/c6h585433p3462669}{Iran TST 2014 T1P6}{M}{$I$ is the incenter of triangle $ABC$. perpendicular from $I$ to $AI$ meet $AB$ and $AC$ at ${B}'$ and ${C}'$ respectively. Suppose that ${B}''$ and ${C}''$ are points on half-line $BC$ and $CB$ such that $B{B}''=BA$ and $C{C}''=CA$. Suppose that the second intersection of circumcircles of $A{B}'{B}''$ and $A{C}'{C}''$ is $T$. Prove that the circumcenter of $AIT$ is on the $BC$.} \tg{projective, inversion}

			\solu{Too many collinearity, need to prove concurrency, what else can come into mind except projective approach.}

			\solu{Too many incenter related things, $\sqrt{bc}$-inversion :o}

		\prob{https://artofproblemsolving.com/community/c6h582820p3444910}{APMO 2014 P5}{M}{Circles $\omega$ and $\Omega$ meet at points $A$ and $B$. Let $M$ be the midpoint of the arc $AB$ of circle $\omega$ ($M$ lies inside $\Omega$). A chord $MP$ of circle $\omega$ intersects $\Omega$ at $Q$ ($Q$ lies inside $\omega$). Let $\ell_P$ be the tangent line to $\omega$ at $P$, and let $\ell_Q$ be the tangent line to $\Omega$ at $Q$. Prove that the circumcircle of the triangle formed by the lines $\ell_P$, $\ell_Q$ and $AB$ is tangent to $\Omega$.}

			\fig{1}{APMO2014P5}{APMO 2014 P5}

		\prob{}{}{E}{Let $ABC$ be a triangle, $D, E, F$ are the feet of the altitudes, $DF\cap BE\equiv P, DE\cap CF\equiv Q$. Prove that the perpendicular from $A$ to $PQ$ goes through the reflection of $O$ on $BC$.}  \tg{projective}

			\solu{Projective approach.}

		\prob{https://artofproblemsolving.com/community/c6h1598147p9931685}{RMM 2018 P6}{H}{Fix a circle $\Gamma$, a line $\ell$ to tangent $\Gamma$, and another circle $\Omega$ disjoint from $\ell$ such that $\Gamma$ and $\Omega$ lie on opposite sides of $\ell$. The tangents to $\Gamma$ from a variable point $X$ on $\Omega$ meet $\ell$ at $Y$ and $Z$. Prove that, as $X$ varies over $\Omega$, the circumcircle of $XYZ$ is tangent to two fixed circles.} \tg{inversion}

			\solu{Too many circles, plus tangency, what else other than inversion? After the inversion the problem turns into a pretty obvious work-around problem.}

		\prob{https://artofproblemsolving.com/community/c6h1573301p9738624}{AoPS6}{H but Beautiful}{Let $O$ and $I$ be the circumcenter and incenter of $\Delta ABC$. Draw circle $\omega$ so that $B,C \in \omega$ and $\omega$ touches $(I)$ internally at $P$. $AI$ intersects $BC$ at $X$. Tangent at $X$ to $(I)$ which is different from $BC$, intersects tangent at $P$ to $(I)$ at $S$. $SA \cap (O)=T \neq A$. Prove that $\angle ATI=90^{\circ}$}

			\figdf{1}{AoPS6_1}{Solution 1}
			\figdf{1}{AoPS6_2}{Solution 2}

		\prob{https://artofproblemsolving.com/community/c6h1618875_cute_radical_axis}{AoPS7}{E}{Let $ABC$ be a triangle with incenter $I$ and circumcircle $\Gamma$. Let the line through $I$ perpendicular to $AI$ meet $AB$ at $E$ and $AC$ at $F$. Let the circumcircles of triangles $AIB$ and $AIC$ intersect the circumcircle of triangle $AEF$ $\omega$ again at points $M$ and $N$, and let $\omega$ intersect $\Gamma$ again at $Q$. Prove that $AQ$, $MN$, and $BC$ are concurrent.}

		\prob{https://artofproblemsolving.com/community/q2h514889p2893347}{AoPS}{E}{Given a circle $ (O) $ with center $ O $ and $ A,B $ are $ 2 $ fixed points on $ (O) $. $ E $ lies on $ AB $. $ C,D $ are on $ (O) $ and $ CD $ pass through $ E $. $ P $ lies on the ray $ DA $, $ Q $ lies on the ray $ DB $ such that $ E $ is the midpoint of $ PQ $. Prove that the circle passing through $ C $ and touch $ PQ $ at $ E $ also pass through the midpoint of $ AB $}

		\prob{https://artofproblemsolving.com/community/c6h514252p2889096}{WenWuGuangHua Mathematics Workshop}{E}{$ O_B, O_C $ are the $ B $ and $ C $ mixtilinear centers respectively. $ (O_B) $ touches $ BC, AB $ at $ X_B, Y_B $ respectively, and $ X_BY_B\cap O_BO_C $ at $ Z_B $. Define $ X_C, Y_C, Z_C $ similarly. Prove that if $ BZ_C\cap CZ_B = T $, then $ AT $ is the $ A $-angle bisector.}

		\prob{https://artofproblemsolving.com/community/c6h514371p2889823}{All Russia 1999 P9.3}{E}{A triangle $ABC$ is inscribed in a circle $S$. Let $A_0$ and $C_0$ be the midpoints of the arcs $BC$ and $AB$ on $S$, not containing the opposite vertex, respectively. The circle $S_1$ centered at $A_0$ is tangent to $BC$, and the circle $S_2$ centered at $C_0$ is tangent to $AB$. Prove that the incenter $I$ of $\triangle ABC$ lies on a common tangent to $S_1$ and $S_2$.}

		\prob{https://artofproblemsolving.com/community/c6h514303p2889241}{All Russia 2000 P11.7}{E}{ A quadrilateral $ABCD$ is circumscribed about a circle $\omega$. The lines $AB$ and $CD$ meet at $O$. A circle $\omega_1$ is tangent to side $BC$ at $K$ and to the extensions of sides $AB$ and $CD$, and a circle $\omega_2$ is tangent to side $AD$ at $L$ and to the extensions of sides $AB$ and $CD$. Suppose that points $O$, $K$, $L$ lie on a line. Prove that the midpoints of $BC$ and $AD$ and the center of $\omega$ also lie on a line.}

		\prob{https://artofproblemsolving.com/community/c6h514286p2889224}{All Russia 2000 P9.3}{E}{Let $O$ be the center of the circumcircle $\omega$ of an acute-angle triangle $ABC$. A circle $\omega_1$ with center $K$ passes through $A$, $O$, $C$ and intersects $AB$ at $M$ and $BC$ at $N$. Point $L$ is symmetric to $K$ with respect to line $NM$. Prove that $BL \perp AC$.}

		\prob{https://artofproblemsolving.com/community/q1h512017p2874889}{WenWuGuangHua Mathematics Workshop}{M}{

			\begin{enumerate}

				\item $ AD, BE, CF $ are concurrent cevians. Angle bisectors of $ \angle ADB $ and $ \angle AEB $ meet at $ C_0 $. Again the angle bisectors of $ \angle ADC $ and $ \angle AFC $ meet at $ B_0 $. And bisectors of $ \angle BEC $ and $ \angle BFC $ meet at $ A_0 $. Prove that $ AA_0, BB_0, CC_0 $ are concurrent.

				\item Angle bisectors of $ \angle AEB $ and $ \angle AFC $ meet at $ D_0 $, of $ \angle BFC $ and $ BDA $ meet at $ E_0 $, and of $ \angle CEB $ and $ \angle CDA $ meet at $ F_0 $. Prove that $ DD_0, EE_0, FF_0 $ are concurrent.

			\end{enumerate}}

			\solu{As this problem is purely made up with lines, we can do a projective transformation to simplify the problem. And as there are perpendicularity at $ D, E, F $, we make $ D, E, F $ the feet of the altitudes of $ \triangle ABC $. Then the angle bisector properties get replaced by simpler properties wrt $ DEF $.}

		\prob{https://artofproblemsolving.com/community/c6h359172}{WenWuGuangHua Mathematics Workshop}{E}{Generalization: Let $ AD, BE, CF $ be any cevians concurrent at $ T $. $ AD\cap EF=A',\ BE\cap DF=B',\ CF\cap DE=C',\ B'A'\cap AC= X,\ B'A'\cap BC= Y,\ C'X\cap EF=Z $. Prove that $ T, Y, Z $ are collinear.}

		\prob{https://artofproblemsolving.com/community/q1h512618p2878013}{AoPS}{E}{On circumcircle of triangle $ABC$, $T$ and $K$ are midpoints of arcs $BC$ and $BAC$ respectively . And $E$ is foot of altitude from $C$ on $AB$ . Point $P$ is on extension of $AK$ such that $PE$ is perpendicular to $ET$ . Prove that $PC=CK$.}

		\prob{https://artofproblemsolving.com/community/c5t256599f5h1629606_geo_3_equals_freak_out}{USJMO 2018 P3}{E}{Let $ABCD$ be a quadrilateral inscribed in circle $\omega$ with $\overline{AC} \perp \overline{BD}$. Let $E$ and $F$ be the reflections of $D$ over lines $BA$ and $BC$, respectively, and let $P$ be the intersection of lines $BD$ and $EF$. Suppose that the circumcircle of $\triangle EPD$ meets $\omega$ at $D$ and $Q$, and the circumcircle of $\triangle FPD$ meets $\omega$ at $D$ and $R$. Show that $EQ = FR$.}

		\prob{https://artofproblemsolving.com/community/c6h181312p996629}{All Russia 2002 P11.6}{M}{The diagonals $AC$ and $BD$ of a cyclic quadrilateral $ABCD$ meet at $O$. The circumcircles of triangles $AOB$ and $COD$ intersect again at $K$. Point $L$ is such that the triangles $BLC$ and $AKD$ are similar and equally oriented. Prove that if the quadrilateral $BLCK$ is convex, then it has an incircle.}

		\prob{https://artofproblemsolving.com/community/q3h511494p2873290}{WenWuGuangHua Mathematics Workshop}{M}{Let $ O_B, O_C $ be the $ B, C $ mixtilinear excircles. $ O $ meet $ CA, CB $ at $ X_C, Y_C $ and $ O_B $ meet $ BA, BC $ at $ X_B, Y_B $. Let $ I_C $ be the $ C $-excircle. $ I_CY_B $ meet $ O_BO_C $ at $ T $. Prove that $ BT\perp O_BO_C $}

			\solu{From what we have to prove, we find two circles, from where we get another circle. This circle suggests that we try power of point. }

		\prob{https://artofproblemsolving.com/community/c6h1623012p10163453}{Iran TST 2018 T1P3}{M}{In triangle $ABC$ let $M$ be the midpoint of $BC$. Let $\omega$ be a circle inside of $ABC$ and is tangent to $AB,AC$ at $E,F$, respectively. The tangents from $M$ to $\omega$ meet $\omega$ at $P,Q$ such that $P$ and $B$ lie on the same side of $AM$. Let $X \equiv PM \cap BF $ and $Y \equiv QM \cap CE $. If $2PM=BC$ prove that $XY$ is tangent to $\omega$.}

		\prob{https://artofproblemsolving.com/community/c6h1623417p10167655}{Iran TST 2018 T1P4}{E}{Let $ABC$ be a triangle ($\angle A\neq 90^\circ$). $BE,CF$ are the altitudes of the triangle. The bisector of $\angle A$ intersects $EF,BC$ at $M,N$. Let $P$ be a point such that $MP\perp EF$ and $NP\perp BC$. Prove that $AP$ passes through the midpoint of $BC$.}

			\solu{:'3 kala para na  T\_T }

		\prob{https://artofproblemsolving.com/community/6h1629942p10229160}{Iran TST 2018 T3P6}{H}{Consider quadrilateral $ ABCD $ inscribed in circle $ \omega $. $ AC\cap BD = P $. $ E, F $ lie on sides $ AB, CD $, respectively such that $ \angle APE=\angle DPF $. Circles $ \omega_1, \omega_2 $ are tangent to $ \omega $ at $ X, Y $ respectively and also both tangent to the circumcircle of $ PEF $ at $ P $. Prove that: \[\frac{EX}{EY}=\frac{FX}{FY}\]}

			\solu{fucking beautiful.}

		\prob{}{ISL 2006 G6}{E}{Circles $ \omega_1 $ and $ \omega_2 $ with centres $ O_1 $ and $ O_2 $ are externally tangent at point $ D $ and internally tangent to a circle $ \omega $ at points $ E $ and $ F $ respectively. Line $ t $ is the common tangent of $ \omega_1 $ and $ \omega_2 $ at $ D $. Let $ AB $ be the diameter of $ \omega $ perpendicular to $ t $, so that $ A, E, O_1 $ are on the same side of $ t $. Prove that lines $ AO_1, BO_2, EF $ and $ t $ are concurrent.}

		\prob{}{ISL 2006 G7}{E}{In a triangle $ ABC $, let $ M_a, M_b, M_c $ be the midpoints of the sides $ BC, CA, AB $, respectively, and $ T_a, T_b, T_c $ be the midpoints of the arcs $BC, CA, AB$ of the circumcircle of $ABC$, not containing the vertices's $A, B, C$, respectively. For $i \in {a, b, c}$, let $w_i$ be the circle with $M_iT_i$ as diameter. Let $p_i$ be the common external common tangent to the circles $w_j$ and $w_k$ (for all ${i, j, k} = {a, b, c}$) such that $w_i$ lies on the opposite side of $p_i$ than $w_j$ and $w_k$ do.

		Prove that the lines $p_a, p_b, p_c$ form a triangle similar to $ABC$ and find the ratio of similitude}

		\prob{}{ISL 2006 G9}{H}{Points $A_1, B_1, C_1$ are chosen on the sides $BC, CA, AB$ of a triangle $ABC$, respectively. The circumcircles of triangles $AB_1C_1,\ BC_1A_1,\ CA_1B_1$ intersect the circumcircle of triangle $ABC$ again at points $A_2, B_2, C_2$, respectively ($A_2 \not= A, B_2 \not= B, C_2 \not= C$). Points $A_3, B_3, C_3$ are symmetric to $A_1, B_1, C_1$ with respect to the midpoints of the sides $BC, CA, AB$ respectively. Prove that the triangles $A_2B_2C_2$ and $A_3B_3C_3$ are similar.}

			\solu{In this type of ``Miquel's Point and the intersections of the circumcircles'' related problems, it is useful to think about the second intersections of the lines joining the first intersections and the Miquel's Point with the main circle.}

			\figdf{1}{ISL2006G9}{IMO Shortlist G9}

		\prob{https://artofproblemsolving.com/community/c6h1423742p8012536}{Iran TST 2017 P5}{}{In triangle $ABC$, arbitrary points $P,Q$ lie on side $BC$ such that $BP=CQ$ and $P$ lies between $B,Q$. The circumcircle of triangle $APQ$ intersects sides $AB,AC$ at $E,F$ respectively. The point $T$ is the intersection of $EP,FQ$. Two lines passing through the midpoint of $BC$ and parallel to $AB$ and $AC$, intersect $EP$ and $FQ$ at points $X,Y$ respectively. Prove that the circumcircle of triangle $TXY$ and triangle $APQ$ are tangent to each other.}

		\prob{}{}{E}{Let $ X $  be the touchpoint of the incircle with $ BC $ and let $ AX $ meet $ \cdot ABC $ at $ D $. The tangents from $ D $ to the incircle meet $ \cdot ABC $ at $ E, F $. Prove that the tangent to the circumcircle at $ A $, $ EF $ and $ BC $ are concurrent.}

		\prob{https://artofproblemsolving.com/community/c6h546185p3160596}{ISL 2012 G8}{M}{Let $ABC$ be a triangle with circumcircle $\omega$ and $\ell$ a line without common points with $\omega$. Denote by $P$ the foot of the perpendicular from the center of $\omega$ to $\ell$. The side-lines $BC,CA,AB$ intersect $\ell$ at the points $X,Y,Z$ different from $P$. Prove that the circumcircles of the triangles $AXP$, $BYP$ and $CZP$ have a common point different from $P$ or are mutually tangent at $P$.}

			\solu{Using Cross ratio and Desergaus's Involution Theorem.}

		\prob{}{}{E}{Suppose an involution on a line $ l $ sending $ X, Y, Z $ to $ X', Y', Z' $. Let $ l_x, l_y, l_z $ be three lines passing through $ X, Y, Z $ respectively. And let $ X_0=l_y\cap l_z,\ Y_0=l_x\cap l_z,\ Z_0=l_x\cap l_y $. Then $ X_0X', Y_0Y', Z_0Z' $ are concurrent.}

		\prob{}{USAMO 2018 P5}{E}{In convex cyclic quadrilateral $ABCD$, we know that lines $AC$ and $BD$ intersect at $E$, lines $AB$ and $CD$ intersect at $F$, and lines $BC$ and $DA$ intersect at $G$. Suppose that the circumcircle of $\triangle ABE$ intersects line $CB$ at $B$ and $P$, and the circumcircle of $\triangle ADE$ intersects line $CD$ at $D$ and $Q$, where $C,B,P,G$ and $C,Q,D,F$ are collinear in that order. Prove that if lines $FP$ and $GQ$ intersect at $M$, then $\angle MAC = 90^\circ$.}

		\prob{https://artofproblemsolving.com/community/c6h1381506p7662154}{Japan MO 2017 P3}{E}{Let $ABC$ be an acute-angled triangle with the circumcenter $O$. Let $D,E$ and $F$ be the feet of the altitudes from $A,B$ and $C$, respectively, and let $M$ be the midpoint of $BC$. $AD$ and $EF$ meet at $X$, $AO$ and $BC$ meet at $Y$, and let $Z$ be the midpoint of $XY$. Prove that $A,Z,M$ are collinear.}

		\prob{https://artofproblemsolving.com/community/c6h17316p118667}{ISL 2002 G1}{E}{Let $B$ be a point on a circle $S_1$, and let $A$ be a point distinct from $B$ on the tangent at $B$ to $S_1$. Let $C$ be a point not on $S_1$ such that the line segment $AC$ meets $S_1$ at two distinct points. Let $S_2$ be the circle touching $AC$ at $C$ and touching $S_1$ at a point $D$ on the opposite side of $AC$ from $B$. Prove that the circumcenter of triangle $BCD$ lies on the circumcircle of triangle $ABC$.}

		\prob{https://artofproblemsolving.com/community/c6h17317p118668}{ISL 2002 G2}{M}{Let $ABC$ be a triangle for which there exists an interior point $F$ such that $\angle AFB=\angle BFC=\angle CFA$. Let the lines $BF$ and $CF$ meet the sides $AC$ and $AB$ at $D$ and $E$ respectively. Prove that \[ AB+AC\geq4DE. \]}

			\solu{Pari nai.}

		\prob{https://artofproblemsolving.com/community/c6h17318p118672}{ISL 2002 G3}{E}{The circle $S$ has center $O$, and $BC$ is a diameter of $S$. Let $A$ be a point of $S$ such that $\angle AOB<120{{}^\circ}$. Let $D$ be the midpoint of the arc $AB$ which does not contain $C$. The line through $O$ parallel to $DA$ meets the line $AC$ at $I$. The perpendicular bisector of $OA$ meets $S$ at $E$ and at $F$. Prove that $I$ is the incenter of the triangle $CEF.$}

		\prob{https://artofproblemsolving.com/community/c6h17319p118673}{ISL 2002 G4}{E}{Circles $S_1$ and $S_2$ intersect at points $P$ and $Q$. Distinct points $A_1$ and $B_1$ (not at $P$ or $Q$) are selected on $S_1$. The lines $A_1P$ and $B_1P$ meet $S_2$ again at $A_2$ and $B_2$ respectively, and the lines $A_1B_1$ and $A_2B_2$ meet at $C$. Prove that, as $A_1$ and $B_1$ vary, the circumcentres of triangles $A_1A_2C$ all lie on one fixed circle.}

		\prob{https://artofproblemsolving.com/community/c6h17323p118682}{ISL 2002 G7}{E}{The incircle $ \Omega$ of the acute-angled triangle $ ABC$ is tangent to its side $ BC$ at a point $ K$. Let $ AD$ be an altitude of triangle $ ABC$, and let $ M$ be the midpoint of the segment $ AD$. If $ N$ is the common point of the circle $ \Omega$ and the line $ KM$ (distinct from $ K$), then prove that the incircle $ \Omega$ and the circumcircle of triangle $ BCN$ are tangent to each other at the point $ N$.}

		\prob{https://artofproblemsolving.com/community/c6h1381506p7662154}{Japan MO 2017 P3}{E}{Let $ABC$ be an acute-angled triangle with the circumcenter $O$. Let $D,E$ and $F$ be the feet of the altitudes from $A,B$ and $C$, respectively, and let $M$ be the midpoint of $BC$. $AD$ and $EF$ meet at $X$, $AO$ and $BC$ meet at $Y$, and let $Z$ be the midpoint of $XY$. Prove that $A,Z,M$ are collinear.}

		\prob{}{India TST}{E}{$ ABC $ triangle, $ D, E, F $ touchpoints, $ M $ midpoint of $ BC $, $ K $ orthocenter of $ \triangle AIC $, prove that $ MI \perp KD $}

		\prob{https://artofproblemsolving.com/community/c6h355790p1932935}{ISL 2009 G3}{E}{Let $ABC$ be a triangle. The incircle of $ABC$ touches the sides $AB$ and $AC$ at the points $Z$ and $Y$, respectively. Let $G$ be the point where the lines $BY$ and $CZ$ meet, and let $R$ and $S$ be points such that the two quadrilaterals $BCYR$ and $BCSZ$ are parallelogram. Prove that $GR=GS$.}

			\solu{Point Circle, distance same means Power same wrt point circles.}

		\prob{https://artofproblemsolving.com/community/c6h1634974p10278638}{ARO 2018 P11.6}{E}{Three diagonals of a regular $n$-gon prism intersect at an interior point $O$. Show that $O$ is the center of the prism.

		(The diagonal of the prism is a segment joining two vertices's not lying on the same face of the prism.)}

		\vspace{8mm}

		\prob{https://artofproblemsolving.com/community/c6h488829p2739327}{ISL 2011 G4}{EM}{Let $ABC$ be an acute triangle with circumcircle $\Omega$. Let $B_0$ be the midpoint of $AC$ and let $C_0$ be the midpoint of $AB$. Let $D$ be the foot of the altitude from $A$ and let $G$ be the centroid of the triangle $ABC$. Let $\omega$ be a circle through $B_0$ and $C_0$ that is tangent to the circle $\Omega$ at a point $X\not= A$. Prove that the points $D,G$ and $X$ are collinear.}

			\vspace{8mm}

		\prob{}{}{Constructing a forth circle tangent}{Given 3 circle, construct another circle that is tangent to these three circles.}

			\solu{A trick to remember: decreasing the radius's of some circles doesn't effect much.}

		\prob{}{}{H}{Let $ ABCD $ be a convex quadrilateral, let $ AD\cap BC = P $. Let $ O, O';\ H, H' $ be the circumcentres and orthocenter of $ \triangle PCD, \triangle PAB $. $ \odot DOC $ is tangent to $ \odot AD'B $, if and only if $ \odot DHC $ is tangent to $ \odot AH'B $}

		\prob{https://artofproblemsolving.com/community/c6h1493342p8776187}{Iran MO 3rd round 2017 mid-terms Geometry P3}{M}{Let $ABC$ be an acute-angle triangle. Suppose that $M$ be the midpoint of $BC$ and $H$ be the orthocenter of $ABC$. Let $F\equiv BH\cap AC$ and $E\equiv CH\cap AB$. Suppose that $X$ be a point on $EF$ such that $\angle XMH=\angle HAM$ and $A,X$ are in the distinct side of $MH$. Prove that $AH$ bisects $MX$.}

%todo: curvilinear incircle prob