\section{Direct synthesis}
\subsection{}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{as usual...}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Consider the control loop we know, with $H(z)=1$ for simplicity:
       \begin{center}
        \includegraphics[width=0.50\columnwidth]{./Unit-04/img/ControlLoop-H1.pdf}
       \end{center}
 \item Take as process and controller, respectively,
       \begin{displaymath}
        P(z) = \frac{\mu}{z-p}, \qquad
        C(z) = \frac{1-\alpha}{\mu} \, \frac{z-p}{z-1},
       \end{displaymath}
 \item and analyse the obtained system.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item We have a \TC{zero/pole cancellation} between controller and process, as the loop transfer function is
       \begin{displaymath}
        L(z) = P(z)C(z)
             = \frac{\cbcancel[gray]{\mu}}{\ccancel[red]{z-p}} \,
               \frac{1-\alpha}{\cbcancel[gray]{\mu}} \, \frac{\ccancel[red]{z-p}}{z-1}
             = \frac{1-\alpha}{z-1}
       \end{displaymath}
 \item Hence
       \begin{displaymath}
        G_{yw}(z) = \frac{L(z)}{1+L(z)}
                  = \frac{\frac{1-\alpha}{z-1}}{1+\frac{1-\alpha}{z-1}}
                  = \frac{1-\alpha}{\ccancel[green!80!black]{z-1}} \,
                    \frac{\ccancel[green!80!black]{z-1}}{z-1+1-\alpha}
                  = \frac{1-\alpha}{z-\alpha}.
       \end{displaymath}
 \item NOTE: the \textcolor{green!80!black}{simplification} in computing $G_{yw}$ is NOT a cancellation.
 \item[] \vspace{-0.75mm}To have a cancellation you need a system (block) with a zero say\\
       in $\overline{z}$, and \TC{\underline{ANOTHER}} system (block) with a pole in the same  $\overline{z}$\\
 \item[] \vspace{-0.75mm} --- as is the case with the \textcolor{red}{cancellation} in $L$ above.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Furthermore, as $H(z)=1$,
       \begin{displaymath}
        G_{yd}(z) = \frac{1}{1+L(z)}
                  = \frac{1}{1+\frac{1-\alpha}{z-1}}
                  = \frac{z-1}{z-1+1-\alpha}
                  = \frac{z-1}{z-\alpha}.
       \end{displaymath}
 \item You may -- should \smiley$\,$ -- remember that cancellations entail hidden parts for the affected system.
 \item Let us evidence and discuss the implications of this in the present\\
       case, by going through a state space analysis.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{State space formulation of the closed-loop system}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item First we express the process in state space form:
       \begin{displaymath}
        \left\{\begin{array}{rcl}
         x_P(k) &=& p x_P(k-1) + \mu u(k-1) \\
         y(k)   &=& x_P(k) + d(k)
        \end{array}\right.
       \end{displaymath}
 \item Then we rewrite the controller transfer function as a constant plus a term with numerator degree
       strictly less than denominator degree (check out the wxMaxima \texttt{divide} function):
       \begin{displaymath}
        C(z) = \frac{1-\alpha}{\mu} \, \frac{z-p}{z-1}
             = \frac{1-\alpha}{\mu} \left( 1 + \textcolor{red}{\frac{1-p}{z-1}} \right)
       \end{displaymath}
 \item Then we treat the \textcolor{red}{strictly proper} term like $P(z)$ above, obtaining
       \begin{displaymath}
        \left\{\begin{array}{rcl}
         x_C(k) &=& x_C(k-1) + (1-p) e(k-1) \\
         u(k)   &=& \frac{1-\alpha}{\mu} x_C(k) + \frac{1-\alpha}{\mu} e(k)
        \end{array}\right.
       \end{displaymath}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{State space formulation of the closed-loop system}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Joining the equations for $P$ and $C$ and those for the node that produces $e$, gives\\
       for the overall closed-loop system the scalar (not yet reduced to minimal) description
       \begin{displaymath}
        \left\{\begin{array}{rcl}
         x_P(k) &=& p x_P(k-1) + \mu u(k-1) \\
         x_C(k) &=& x_C(k-1) + (1-p) e(k-1) \\
         y(k)   &=& x_P(k) + d(k) \\
         u(k)   &=& \frac{1-\alpha}{\mu} x_C(k) + \frac{1-\alpha}{\mu} e(k) \\
         e(k)   &=& w(k) - y(k)
        \end{array}\right.
       \end{displaymath}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{State space formulation of the closed-loop system}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item For the process state we have
       \begin{displaymath}
        \begin{array}{rcl}
         x_P(k) &=& p x_P(k-1) + \mu u(k-1) \\
                &=& p x_P(k-1) + \mu \left( \frac{1-\alpha}{\mu} x_C(k-1) + \frac{1-\alpha}{\mu} e(k-1) \right) \\
                &=& p x_P(k-1) + (1-\alpha)x_C(k-1) + (1-\alpha) \left( w(k-1)-y(k-1) \right) \\
                &=& p x_P(k-1) + (1-\alpha)x_C(k-1) + (1-\alpha) w(k-1)\\
                & & - (1-\alpha) \left( x_P(k-1)+d(k-1) \right) \\
                &=& \left( p+\alpha-1 \right) x_P(k-1)
                    +(1-\alpha) x_C(k-1)\\
                & & +(1-\alpha) w(k-1)
                    -(1-\alpha) d(k-1)
        \end{array}
       \end{displaymath}
 \item while the controller state evolves according to
       \begin{displaymath}
        \begin{array}{rcl}
         x_C(k) &=& x_C(k-1) + (1-p) e(k-1) \\
                &=& x_C(k-1)\\
                & & + (1-p) \left( w(k-1)-x_P(k-1)-d(k-1) \right)\\
                &=& (p-1) x_P(k-1) + x_C(k-1)\\
                & & +(1-p) w(k-1)
                    -(1-p) d(k-1)
        \end{array}
       \end{displaymath}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{State space formulation of the closed-loop system}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Putting it all together, the closed-loop system in state space form reads
       \begin{displaymath}
        \left\{\begin{array}{rcl}
         \begin{bmatrix} x_P(k) \\ x_C(k) \end{bmatrix}
         &=&
         \begin{bmatrix} p+\alpha-1 & 1-\alpha \\ p-1 & 1  \end{bmatrix}
         \begin{bmatrix} x_P(k-1) \\ x_C(k-1) \end{bmatrix}
         +
         \begin{bmatrix} 1-\alpha & \alpha-1 \\ 1-p & p-1  \end{bmatrix}
         \begin{bmatrix} w(k-1) \\ d(k-1) \end{bmatrix} \\
         \begin{bmatrix} y(k) \\ u(k) \end{bmatrix}
         &=&
         \begin{bmatrix} 1 & 0 \\ \frac{\alpha-1}{\mu} & \frac{1-\alpha}{\mu} \end{bmatrix}
         \begin{bmatrix} x_P(k) \\ x_C(k) \end{bmatrix}
         +
         \begin{bmatrix} 0 & 1 \\ \frac{1-\alpha}{\mu} & \frac{\alpha-1}{\mu} \end{bmatrix}
         \begin{bmatrix} w(k) \\ d(k) \end{bmatrix} \\
        \end{array}\right.
       \end{displaymath}
 \item[] with input $[w\,d]'$, output $[y\,u]'$ and
       \begin{displaymath}
        \begin{array}{c}
         A = \begin{bmatrix} p+\alpha-1 & 1-\alpha \\ p-1 & 1  \end{bmatrix},\quad
         B = \begin{bmatrix} 1-\alpha & \alpha-1 \\ 1-p & p-1  \end{bmatrix},\\
         C = \begin{bmatrix} 1 & 0 \\ \frac{\alpha-1}{\mu} & \frac{1-\alpha}{\mu} \end{bmatrix},\quad
         D = \begin{bmatrix} 0 & 1 \\ \frac{1-\alpha}{\mu} & \frac{\alpha-1}{\mu} \end{bmatrix}.
        \end{array}
       \end{displaymath}
 \end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitleTC{Introductory example}
\framesubtitleTC{State space formulation of the closed-loop system}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item To verify, we express the same system as a \TC{transfer matrix}, i.e.
       \begin{displaymath}
        \begin{bmatrix} y(k) \\ u(k) \end{bmatrix}
        = G(z)
        \begin{bmatrix} w(k) \\ d(k) \end{bmatrix}, \qquad
        G(z) =
        \begin{bmatrix} G_{yw}(z) & G_{yd}(z) \\ G_{uw}(z) & G_{ud}(z) \end{bmatrix}
       \end{displaymath}
 \item Since $G(z) = C(zI-A)^{-1}B+D$, we can compute it in wxMaxima with
       \begin{verbatim}
A : matrix([p+alpha-1,1-alpha],[p-1,1]);
B : matrix([1-alpha,alpha-1],[1-p,p-1]);
C : matrix([1,0],[(alpha-1)/mu,(1-alpha)/mu]);
D : matrix([0,1],[(1-alpha)/mu,(alpha-1)/mu]);
G : factor(C.invert(z*ident(2)-A).B+D);
       \end{verbatim}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Introductory example}
\framesubtitleTC{State space formulation of the closed-loop system}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Doing so we obtain
       \begin{displaymath}
        G(z) =
        \begin{bmatrix}
         \cfrac{1-\alpha}{z-\alpha}                   & \cfrac{z-1}{z-\alpha} \\
         \cfrac{1-\alpha}{\mu}\,\cfrac{z-p}{z-\alpha} & \cfrac{\alpha-1}{\mu}\,\cfrac{z-p}{z-\alpha}
        \end{bmatrix}
       \end{displaymath}
 \item The first row contains the transfer functions we already computed.
 \item The second says that the effects of $w$ and $d$ on $u$ are the opposite\\
       of one another (consistent with the loop scheme).
 \item \vfill Now, for some remarks to generalise.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Remarks}
\framesubtitleTC{and lessons learnt (1/2)}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item We took a first-order process.
 \item We took a controller that cancels the process pole with its zero, and has\\
       a pole in $z=1$.
 \item We obtained a reference-to-output transfer function $G_{yw}(z)$
       \begin{itemize}[<+-| alert@+>]
       \item with unity gain, hence for constant $w$ the error vanishes,
       \item and with a prescribed pole $\alpha$ (i.e., a prescribed set point tracking speed).
       \end{itemize}
 \item We also obtained a disturbance-to-output transfer function $G_{yd}(z)$
       \begin{itemize}[<+-| alert@+>]
       \item with zero gain, hence for constant $d$ the error vanishes as well,
       \item and with the same pole $\alpha$ (i.e., a prescribed disturbance rejection\\
             speed as well).
       \end{itemize}
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Remarks}
\framesubtitleTC{and lessons learnt (2/2)}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Most important, the eigenvalues of the closed-loop dynamic matrix $A$\\
       are $\alpha$ and $p$, i.e., \TC{the one we prescribed and the one we cancelled}.
 \item The latter eigenvalue apparently ends up in a hidden part --- the transfer matrix
       contains elements with a denominator of degree one and root $p$, while the order\\
       of the system is two (one state variable for $P$ and one for $C$).
 \item Thus we can use this technique only if $|p|<1$, otherwise the\\
       closed-loop system has a hidden part that is not asymptotically stable.
 \item \vfill We are now ready to address the \TC{direct synthesis} technique\\
       in general, at the level we need for our activity.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Direct synthesis}
\framesubtitleTC{The general idea}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item Assume a process model $P(z)$ is available.
 \item Choose a closed-loop transfer function -- name it here generically $O(z)$, specialisations
       in the following -- to represent your control objectives.
 \item Choose a desired expression $O^{\circ}(z)$ for $O(z)$.
 \item Express $O$ as a function of $P$ and the controller $C$ and set it equal to $O^{\circ}$,\\
       i.e., write the equation
       \begin{displaymath}
       O \left( P(z),C(z) \right) = O^{\circ}(z).
       \end{displaymath}
 \item Solve for $C(z)$. Voil\`{a} \smiley.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Direct synthesis}
\framesubtitleTC{The general idea}
\myPause
 \begin{itemize}[<+-| alert@+>]
 \item \emph{CAVEAT 1:} no exhaustiveness claim. We are only scratching the surface,\\
       there is a myriad of things we cannot stuff in this course. Categorised\\
       references for the interested at the end.
 \item \emph{CAVEAT 2:} no magic either. There is potential but also pitfalls\\
       to be aware of.
 \item Some facts we anticipate right from the start:
       \begin{itemize}[<+-| alert@+>]
       \item direct synthesis inherently involves zero/pole cancellations,
       \item and an improper choice of $O^{\circ}$ may give a non realisable controller,
       \item thus overall not all desired dynamics can be obtained.
       \end{itemize}
 \item \vfill An important by-product of a system-theoretical approach, is that\\
       such limits can be set and discussed objectively.
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Direct synthesis for set point tracking}
\framesubtitleTC{}
\myPause
 \begin{center}
  \includegraphics[width=0.50\columnwidth]{./Unit-04/img/ControlLoop-H1.pdf}
 \end{center}
 \begin{itemize}[<+-| alert@+>]
 \item The target transfer function is $G_{yw}(z)$, that we set equal to a desired $G_{yw}^{\circ}(z)$ writing
       \begin{displaymath}
       \frac{P(z)C(z)}{1+P(z)C(z)} = G_{yw}^{\circ}(z).
       \end{displaymath}
 \item Solving for $C(z)$ we get
       \begin{displaymath}
        C(z) = \frac{1}{P(z)} \, \frac{G_{yw}^{\circ}(z)}{1-G_{yw}^{\circ}(z)}.
       \end{displaymath}
 \item Note the cancellation (the $1/P$ factor in $C$).
 \end{itemize}
\end{frame}

\begin{frame}
\frametitleTC{Direct synthesis for disturbance rejection}
\framesubtitleTC{}
\myPause
 \begin{center}
  \includegraphics[width=0.50\columnwidth]{./Unit-04/img/ControlLoop-H1.pdf}
 \end{center}
 \begin{itemize}[<+-| alert@+>]
 \item The target transfer function is $G_{yd}(z)$, that we set equal to a desired $G_{yd}^{\circ}(z)$ writing
       \begin{displaymath}
       \frac{1}{1+P(z)C(z)} = G_{yd}^{\circ}(z).
       \end{displaymath}
 \item Solving for $C(z)$ we get
       \begin{displaymath}
        C(z) = \frac{1}{P(z)} \, \frac{1-G_{yd}^{\circ}(z)}{G_{yd}^{\circ}(z)}.
       \end{displaymath}
 \item Note the cancellation (the $1/P$ factor in $C$).
 \end{itemize}
\end{frame}

\begin{frame}\mccz
\frametitleTC{Direct synthesis}
\framesubtitleTC{Why ``PIDs on the horizon''?}
\myPause
 \begin{columns}
  \column[T]{0.35\textwidth}
   \only<2->{\includegraphics[height=6cm]{./Unit-04/img/PIDsOnTheHorizon_cc0.jpg}}
  \column[T]{0.65\textwidth}
   \begin{itemize}[<+-| alert@+>]
   \item Because applying direct synthesis to the versatile\\
         model we used to generate a variety of responses,\\
         with a sensible target transfer function, naturally\\
         leads to a controller with two zeroes and two\\
         poles, one of which in $z=1$.
   \item This is a PID controller.
   \item However we introduced a lot of material\\
         in this lecture.
   \item Better take a breath, recap, ad go\\
         through a practice session.
   \end{itemize}
 \end{columns}
\end{frame}


\graphicspath{{Pics/combi/graph/}}

\newpage
\section{Graph Theory}

\begin{take_note*}{Turning grids into graphs}
    \begin{itemize}
        \item One common way to turn a grid into graphs is to create a
            bipartite graph between the columns and rows such that $ c_i $ and
            $ r_j $ are connected iff $ (i, j) $ is marked. This way we can
            find cycles alternating row and column.
        \item Creating a bipartite graph between all rows and columns and
            particular objects. This helps to prove matching.
    \end{itemize}
\end{take_note*}

\lem{Bipartite Graph}{
    Any graph having only even cycles are \emph{Bipartite}.

    \index[strat]{Graph!Bipartite}
}

\begin{multicols}{2}
    \begin{enumerate}[wide=0em, label=\arabic*, itemsep=0pt, parsep=0pt,
        font=\footnotesize\bfseries]
        \iref{problem:bipartite_graph_1}{AoPS}{}
        \iref{problem:bipartite_graph_2}{ISL 2004 C3}{}
        \iref{problem:bipartite_graph_3}{Problem}{}
        \iref{problem:bipartite_graph_4}{Problem}{}
    \end{enumerate}
\end{multicols}

\theo{http://www.ams.org/samplings/feature-column/fcarc-eulers-formula}
{Euler's Polyhedron Formula}{
    For any polyhedron with $ E, V, F $ edges, vertices's and faces resp. the
    following relation holds \[V+F=E+2\]\label{lemma:planar_graph_polyhedron}

    In a planar graph with $ V $ vertices, $ E $ edges and $ C $ cycles, the
    following condition is always satisfied:
    \[V+C=E+1\]\label{theorem:planar_graph_theorem}
}

\lem{Criteria of partitioning a graph into disconnected sub-graphs}{
    If there exist no three vertices, $u, v, w$ that $uv\in E(G)$ also $uw,
    vw\in E(G)$, the graph can be partitioned into equivalence classes based
    on their non-neighbors.

    \index[thm]{Non-Neighbor Equivalence Class}
    \label{lemma:criteria_of_partition_equiv}
}

\prob{https://artofproblemsolving.com/community/c6h1063060p4609322}
{China TST 2015 T1 D2 P3}{E}{
    There are some players in a Ping Pong tournament, where
    every $2$ players play with each other at most once. Given: \vspace{-.9em}
    \begin{enumerate}
        \item Each player wins against at least $a$ players, and loses to at
            least $b$ players. ($a,b\geq 1$)
        \item For any two players $A,B$, there exist some players
            $P_1,...,P_k$ ($k\geq 2$) (where $P_1=A$,$P_k=B$), such that $P_i$
            wins against $P_{i+1}$ ($i=1,2...,k-1$)
    \end{enumerate}
    \vspace{-.9em}

    Prove that there exist $a+b+1$ distinct players $Q_1,...Q_{a+b+1}$, such that
    $Q_i$ wins against $Q_{i+1}$ ($i=1,...,a+b$).

    \index[strat]{Extremal!Longest Path!ChTST 2015 P3}
}

\rem{Typical largest path, some workaround with given constraints problem.}

\solu{Take the largest path starting from $ a_1 $ to $ a_n $.
    \begin{soldef}
        Assume that $ n\le a+b $. Since this is the largest
        path, $ a $ edges coming out of $ a_n $ are all in $ S=\{a_1, a_2,
        \dots a_n\} $, and $ b $ edges going in $ a_1 $ are all in $ S $. Let
        $ S_1 $ be the set of vertices that $ a_n $ wins against, and $ S_2 $
        be the set of vertices that $ a_1 $ loses against. Moreover, let $ a_l
        $ be the smallest element of $ S_1 $, and $ a_{n-k} $ be the largest
        element of $ S_2 $ (smallest means leftmost in the part, and largest
        means rightmost).\\

        Let $ S'=\{a_l, a_{l+1}, \dots a_{n-k-1}, a_{n-k}\} $. Since $ n\le
        a+b $, we have $ S'\ne \varnothing $. \\

        We also define: \[ S_1'=\{a_i\mid a_i \text{ defeats } a_{i+1} \text{
                where } a_{i+1} \in S_1\cap S' \}\] \[S_2'=\{a_i\mid a_{i-1}
        \text{ defeats } a_{i} \text{ where } a_{i-1} \in S_2\cap S'\}\]
    \end{soldef}

    \figdf{.4}{China_TST_2015_T1_D2_P3_1}{}

    Now, note that for any $ x\in S_2' $, $ y\in S_1' $, there is a path
    between $ x, y $ with $ n $ vertices. So for all $ x\in S_2' $, there does
    not exist a vertex outside of $ S $ that defeats $ x $. And for all $ y\in
    S_1' $, there doesn't exist a vertex outside of $ S $ that loses to $ y $,
    because of the maximality of $ n $. \\

    We show that, $ S_1'\cap S_2' \ne \varnothing $. Then there would exist a
    vertex that doesn't have any edge outside of $ S $, meaning it has at
    least $ a+b $ games inside $ S $, proving the result.\\

    We have, $ S_1', S_2' \subset S'\cup\{a_{l-1}, a_{n-k+1}\} $. We have,
    \begin{align*}
        |S_1'| &\ge a-k+2\quad [\because a_n \text{ has at most } k-2 \text{
        vertices in } \{a_{n-k+1}, \dots a_n\}]\\ |S_2'| &\ge b-l+3
    \end{align*}

    But $ |S'|=n-(l-1)-(k)+2 \le a+b-l-k+3 < |S_1'|+|S_2'| $. So $
    S_1'\cap S_2' \ne \varnothing $, and we are done.
}

\prob{https://artofproblemsolving.com/community/c6h35315p220222}
{ARO 2005 P10.8}{E}{
    A white plane is partitioned in to cells (in a usual way). A finite
    number of cells are coloured black. Each black cell has an even (0, 2 or 4)
    number of adjacent (by the side) white cells. Prove that one may colour each
    white cell in green or red such that every black cell will have equal number
    of red and green adjacent cells.

    \index[strat]{Graph!Grid $ \to $ Graph!ARO 2005 P10.8}
    \index[strat]{Graph!Bipartite!ARO 2005 P10.8}
}

\solu{
    First we join the white cells like this:
    \figdf{.8}{ARO_2005_P10_8}{}
    Now, notice that the plane have been divided into some cycles (a black
    cell that has no adjacent black cells is a cycle itself). So we can color
    the plane blue and yellow in a way that no region has the same color as
    its neighbors. We can do this because at any junction, there are an even
    number of regions connected because of the problem condition.\\

    Now we focus on our graph that we created connected the white cells. Take
    any cycle on it. If we have a ``slanted'' edge, then both of the nodes are
    inside a region of either blue or yellow. But in a ``straight'' edge, the
    two nodes are in different colored region.\\

    We know that there are an even number of slanted edges, which is trivial
    to prove (using the fact that any cycle on a grid system has even number
    of nodes, and on these cycles, most of the edges (the straight ones) have
    even lenght, but only the slanted one has odd lenghts on the sides). It is
    also easy to see that there are an even number of straight edges, because
    of going in and out of the regions of a fixed color.\\

    So our cycle has an even number of nodes and thus bipartite. We can color the
    graph with two colors, so that along each edge, the two nodes are of different
    color.
}

\rem{
    There is a simple coloring using this solution. After we color the
    regions of the plane with blue and yellow, we number each column with
    integers. Then on the odd numbered columns, we color all the white cells that
    are in yellow region green and blue region red. And on the even numbered
    columns, we do the opposite. It is easy to check that this coloring works
    using the graph we created before.
}

\prob{https://atcoder.jp/contests/agc033/tasks/agc033_c}
{AtCoder GC033 C}{E}{
    Takahashi and Aoki will play a game on a tree. The tree has $ N $
    vertices numbered $ 1 $ to $ N $, and the $ i $-th of the $ N-1 $ edges
    connects Vertex $ a_i $ and Vertex $ b_i $

    At the beginning of the game, each vertex contains a coin. Starting from
    Takahashi, he and Aoki will alternately perform the following operation:

    \begin{itemize}
        \item Choose a vertex $ v $ that contains one or more
            coins, and remove all the coins from $ v $.
        \item Then, move each coin remaining on the tree to the vertex that is
            nearest to $v$ among the adjacent vertices of the coin's current vertex.
    \end{itemize}

    The player who becomes unable to play, loses the game. That is, the player who
    takes his turn when there is no coin remaining on the tree, loses the game.
    Determine the winner of the game when both players play
    optimally.

    \index[strat]{Extremal!Longest Path!AtCoder GC033 C}
    \index[strat]{Invariant!Monovariant!AtCoder GC033 C}
}

\solu{
    First transform the game by removing the idea of coins, and replacing it
    with deleting vertices. Now, notice that the longest path in this tree (i.e.
    the diameter) strictly decreases by $ 1 $ or $ 2 $ each turn depending on the
    move. So it's just a basic predetermined game.
}

\prob{https://artofproblemsolving.com/community/c6h514375p2889828}
{ARO 1999 P9.8}{M}{
    There are $2000$ components in a circuit, every two of which were
    initially joined by a wire. The hooligans Vasya and Petya cut the wires one
    after another. Vasya, who starts, cuts one wire on his turn, while Petya cuts
    one or three. The hooligan who cuts the last wire from some component loses.
    Who has the winning strategy?

    \index[strat]{Algorithm!Copycat!ARO 1999 P9.8}
}

\solu{[Copycat]
    The P-Hooligan Petya has a winning strategy, for he can be
    follow the old cunning trick of never losing. How does he do it?

    He starts by secretly partitioning the vertices in two $ 1000 $ degree
    subsets. He calls them $ A= \{a_1, a_2\dots a_{1000}\} $ and $ B=\{b_1,
    b_2 \dots b_{1000}\} $. He then connects $ a_i $ with $ b_i $ with an edge
    with an invisible marker that only he can see.

    Now the game begins. Petya copies Vasyas moves following these rules:
    \begin{enumerate}
        \item If Vasya removes an edge $ a_i$ -- $a_j $, where $ i\ne j $,
            then Patya removes the edges $ a_i$ -- $b_j,\ a_j$ -- $b_i$ and $
            b_i$ -- $b_j $.
        \item If Vasya removes $a_j$ -- $b_i$, where $ i\ne j $, then Patya
            removes the other three edges from the above rule.
        \item If Vasya removes $ a_i $--$ b_i $, then Patya looks for another
            $ b_j $, such that $ a_i $--$ b_j $ exists. Then by the symmetry
            so far maintanined, $ a_j $--$ b_i $ and $ a_j $--$ b_j $ exist
            too. And Patya can remove $ a_j$--$ b_j $, and swap the names of $
            b_j $ and $ b_i $.

            But if he can't, then that would mean after Vasya's move $ a_i $
            would become isolated, and Patya would win.
    \end{enumerate}

    It is easy to see that the above moves are possible since Patya is always
    maintaining symmetry between $ A, B $. So he can't move means Vasya has
    already disconnected one of the vertices.
}

\rem{
    The case with $ 4 $ vertices and $ 6 $ vertices give an idea to copy the
    opponent's moves.
}

\prob{https://artofproblemsolving.com/community/c6h17455p119177}
{ISL 2001 C3}{E}{
    Define a $ k $-clique to be a set of $ k $ people such that every pair
    of them are acquainted with each other. At a certain party, every pair of $ 3
    $-cliques has at least one person in common, and there are no $ 5 $-cliques.
    Prove that there are two or fewer people at the party whose departure leaves
    no $ 3 $-clique remaining.

    \index[strat]{Extremal!Object!ISL 2001 C3}
}\label{problem:extreme_object_16}

\solu{Casework with the point where most of the triangles are joined.}

\prob{https://artofproblemsolving.com/community/c6h1441121p8200413}
{ARO 2017 P9.1}{E}{
    In a country some cities are connected by one-way flights (there is
    at most one flight between two cities). City $ A $ is called ``available" from
    city $B$, if there is a flight from $ B $ to $ A $, maybe with some
    transits. It is known, that for every $2$ cities $P$ and $Q$, there
    exists a city $R$, such that $P$ and $Q$ are both available from $R$.
    Prove, that exist city $A$, such that every city is available from $A$.

    \index[strat]{Induction!ARO 2017 P9.1}
}\label{problem:induction_type1_3}

\solu{Basic induction exercise.}

\prob{https://artofproblemsolving.com/community/c4h365024p2006499}{Tournament
    of Towns 2009 S6}{M}{
    Anna and Ben decided to visit a country with $2009$ islands. Some pairs of
    islands are connected by boats which run both ways. Anna and Ben are playing
    during the trip:

    Anna chooses the first island on which they arrive by plane. Then Ben chooses
    the next island which they could visit. Thereafter, the two take turns
    choosing an island which they have not yet visited. When they arrive at an
    island which is connected only to islands they had already visited, whoever's
    turn to choose next would be the loser. Prove that Anna could always win,
    regardless of the way Ben played and regardless of the way the islands were
    connected.

    \index[strat]{CopyCat!ToT 2009 S6}
}

\begin{solution}
    The copycat idea, as always in games. How can Anna make sure she gets a
    move after Ben? Maybe she can ``pair'' vertices and follow them along.
    What happens if she tries this strategy?
\end{solution}

\prob{https://artofproblemsolving.com/community/c6h598165p3549412}{USA TST 2014 P5}{M}{Find the maximum number $E$ such that the following holds: there is an edge-colored graph with $60$ vertices and $E$ edges, with each edge colored either red or blue, such that in that coloring, there is no monochromatic cycles of length $3$ and no monochromatic cycles of length $5$.}

\input{combi/sec5_1_counting_in_graph}
\input{combi/sec5_2_graph_alogrithm}


\documentclass[a4paper, 11pt]{article}

% declare packages
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{amssymb}
\usepackage{array}   % write arrays in math mode
\usepackage[margin=10pt,font=small,labelfont=bf]{caption}
% \usepackage[onehalfspacing]{setspace} %[nosep] [noitemsep] [singlespacing] [doublespacing] (also can do /singlespacing within doc)
\usepackage{color}
\usepackage{comment} % enables the use of multi-line comments (\ifx \fi)
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage{footmisc} %  formatting for footnotes
\usepackage{fullpage} %  changes the margin
\usepackage{geometry} %  change length & layout of elements
\usepackage{graphicx} % embed graphics
\usepackage{hyperref}
\usepackage{mathtools}
\usepackage{multirow}
\usepackage[round,sort,comma]{natbib}   % citation formatting
\usepackage{pdflscape} % make pages landscape in pdf
\usepackage{pdfpages}
% \usepackage{subcaption}
\usepackage{subfigure}
\usepackage{subfloat}   %figure 1a 1b with \begin{subfigures}
\usepackage{ulem} %underlining and strikethroughs
\usepackage[yyyymmdd,hhmmss]{datetime}

% declare extra commands
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%
\DeclareMathOperator*{\argmin}{\arg\!\min}
\DeclareMathOperator*{\argmax}{\arg\!\max}

% Other formatting options
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\rfoot{Compiled on \today\ at \currenttime}
\cfoot{}
\lfoot{Page \thepage}
\newcolumntype{L}[1]{>{\raggedright\let\newline\arraybackslash\hspace{0pt}}m{#1}} %used for array package
\newcolumntype{C}[1]{>{\centering\let\newline\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\arraybackslash\hspace{0pt}}m{#1}}
\geometry{left=1.0in,right=1.0in,top=1.0in,bottom=1.0in}

\begin{document}
% puts extra whitespace at top of first page
% \begin{tabbing}
% \end{tabbing}

\normalsize  \strut\hfill \textbf{John Stromme} \\
\normalsize  \strut\hfill  Date: 07/21 \\

\noindent
\huge \textbf{Do the Bucks actually `play random'?} \\
\textit{An empirical analysis} \\

\normalsize

During halftime in games 1 and 2 of the Finals coach Bud implored his players to `play random'\footnote{\url{https://www.reddit.com/r/nba/comments/ogm608/highlight_mike_budenholzers_game_2_nba_finals/}}. Many internet commentators found this advice to be quite strange and atypical---`play random' is not usually in the wheelhouse of advice that coaches give in rousing halftime speeches. This naturally leads us to two questions: Are the Bud-coached Bucks indeed more likely to `play random' than the other 29 teams in the league? Do teams who `play random' tend to win more games?

To answer these questions, I created a measure of `randomness' of play along two-dimensions using data from the 2019--20 and 2020--21 seasons. On one dimension, teams can be `random' in how far they are from the basket when they have a shot-attempt. A team with more varied shot selection by distance will be much more `random' and unpredictable. On the second dimension, teams can be `random' on \textit{when} they choose to shoot during a possession. Again, a team that is more varied in when they take there shots during a possession will be more `random' and unpredictable than a team who always shoots at a similar point in the shot clock.

Figure \ref{fig:randomgini} shows where each team falls along both dimensions of `randomness': Teams towards the top-right play more `randomly', whereas teams towards the bottom-left play more `predictably'. The bucks play more randomly on both measures than an the nba average. They rank more highly in playing randomly in shot distance, but are closer to the average in shot timing.

\begin{figure}[!htpb]
  \centering \includegraphics[width=0.6\textwidth]{../plots_tables/randomginiplot.jpg}
  \caption{}\label{fig:randomgini}
\end{figure}

\section*{Is `playing random' correlated with winning?}
It may or may not be a good idea to play `randomly' given that each game a team should exploit opportunities based on matchup. It seems likely there is a tradeoff between exploiting opponent's weaknesses and playing random---more strategic play would be less random. To investigate this I look at the correlation between wins and the above measures of randomness. I find that correlation for each measure is negative: -0.182 for shot distance and -0.235 for shot timing. This implies playing random is associated with losing more games, albeit this correlation is somewhat weak, and no causality is implied.

\section*{Methodology}
For each dimension of randomness, we can think of there being $n$ possible outcomes. For example, a team can choose to shoot at any of the 24 seconds in the shot clock ($n=24$), or at any distance from the basket i.e., between 0--40 feet ($n=40$). If a team is perfectly predictable, they will shoot every shot at the same distance, at the same time in the shot clock. On the opposite end, teams that are most `random' will have an even distribution of shots across distance and time.

A natural measure for this definition of `randomness' is the Gini Coefficient. The Gini coefficient is traditionally used as a measure of income inequality across a population, but can be repurposed anywhere we care about how evenly distributed some piece of data is among some categories or options.

In this application, I'll use what I call the `inverse-Gini Coefficient': the higher the inverse-Gini, the more `random' the team's play is. When the inverse-Gini Coefficient is equal to one, there is an even distribution across possibilities, which, as described in the previous paragraph, is most `random'. At the other extreme, if a team were to only shoot at one distance from the basket (least `random') the inverse-Gini Coefficient would be zero. For the math nerds the formula is further below. %For this analysis, the inverse-Gini Coefficient is multiplied by 100 for easier reading.

\subsection*{The Nitty Gritty}
\noindent\textbf{A note on notation:} For each measure we can use $n$ to represent the number of `options' a team has, and $x_i$ to represent the number of times a team chose option $i$.\\

\noindent \textbf{Shot distance randomness:} Teams can choose to shoot from one of $n=28$ discrete shot distances, either shooting between 0--26 feet, or from `deep' which is a single category for any shot between 27--40 feet. Any shot over 40 feet is dropped from the data. Using the notation defined above, this means that $x_0$ would measure the number of times over a season a team shot from 0-feet.\\

\noindent\textbf{Shot timing randomness:} Teams can choose to shoot from one of $n=20$ times during the shot clock, i.e., at any point between 19--0 seconds left on the shot clock. The first 5 seconds of the shot clock, 24--20, are dropped as a standard length of time to get the ball over halfcourt. Again using the above notation, in this case $x_0$ would measure the number of times over a season a team made a shot attempt with zero seconds left on the shot clock. To keep the analysis simpler, and also due to shot clock data limitation, I only include shot attempts which are the first attempt during a team's possession that started with a fresh 24 on the clock. It does not matter what the outcome of the shot is---make, miss, foul---this is a measure of randomness in attempt.\\

\noindent\textbf{The fine print:}
Formula for inverse-Gini Coefficient:
$$G= 1-\frac{\sum_i \sum_j |x_i - x_j|}{2 n^2 \bar{x}} $$

When we use this version of the Gini coefficient, i.e., when we have discrete outcomes, technically the maximum value the Gini can take on is $\frac{n-1}{n}$ which is only equal to 1 at the limit. Therefore, in our finite settings the Gini range of possibilities will actually be 0--$\frac{n-1}{n}$, rather than 0--1.

I use the `inverse'-Gini rather than the typical Gini coefficient, because I want a measure of `randomness' where higher values mean there is more randomness. To do this, we need to tack on a $1-$ to invert the values of the Gini Coefficient.

\newpage
\input{../plots_tables/ginitable.tex}

% \bibliographystyle{authordate1} %uncomment if using bibliography
\setlength\bibsep{0pt}
\nocite{*}
\bibliography{Placeholder} %don't forget need to run bibtex after latex compilation...

\end{document}


\documentclass[a4paper,english]{article}

\usepackage{fullpage}

%%%%%%%%%%%%%%%%%%%%%%%% TEX FONTS AND LANGUAGE
% This is the new Latin Modern fonts (by Knuth)
\usepackage{lmodern}
% All the above merge well (IMHO) with the Euler family of
% mathematical fonts (by H. Zapf)
\usepackage{amsfonts}
%to best use the above, you have to switch to T1
\usepackage[T1]{fontenc}
% (Note that LaTeX still defaults to OT1, to be compatible with
%  old files; but nowadays you definitively want to use T1.)
\usepackage[utf8]{inputenc}
\usepackage{babel}

\usepackage{amsmath,amssymb,amsthm}

\usepackage{graphicx,color,hyperref}

\begin{document}

\begin{center}\Large
  Non-destructive encoder flushing for ``arithmetic coding''\\
  Andrea C. G. Mennucci
  \footnote{Scuola Normale Superiore, Pisa, Italy}
  \\
  \today
\end{center}

\section{Introduction}

In this short essay we discuss \emph{arithmetic coding}, as described in
\cite{witten1987arithmetic}.
(The reference implementation is the code in \texttt{ArithCodeTut}
\footnote{\url{https://github.com/mennucc/ArithCodeTut.git}} in \texttt{github.com}).

In particular we discuss the problem of \emph{flushing}: a method implemented
in the encoder that makes sure that the decoder has received all previously
encoded symbols.

In \cite{witten1987arithmetic}, in the section \emph{``Termination''}, the authors write
\footnote{Rephrased for clarity}:
\emph{To finish the transmission, it is necessary to send
  [\ldots]  enough bits to ensure that the encoded string falls
  within the finale range. [\ldots] The encoder  need only transmit 01 if
\texttt{Low} < \texttt{First\_qtr}, or 10 otherwise.}

\smallskip

While this approach  works, it has a defect: after that sequence
is emitted, it is unclear how the encoder could encode more symbols
and send more bits to the decoder.

This may property may be of interest in some cases: indeed the Decoder
can have an arbitrarily large delay in decoding the symbols
that the encoder has already seen.
(See next section). So a periodic flushing may be desirable
--- as long as encoding/decoding can proceed after flushing.

\medskip

In the following a \emph{Bernoulli symbol} is a symbol that has two choices, such as $0,1$ or
$a,b$, each choice with probability 1/2 (unless otherwise stated).

\medskip

The questions now is: can we justify the flushing output of the
encoder as result of an input, let's say as iid Bernoulli symbols?

\section{Example}

We model the encoder as follows.

Let $[\alpha_j,\beta_j)$ the symbol interval
stored in the Encoder after inserting  the j-th symbol using \texttt{input\_symbol()}:
the encoder is in \emph{dirty state}.
Let $[\tilde \alpha_j,\tilde \beta_j]$
the symbol interval after the Encoder has emitted all bits (either by callback, or by polling),
so the Encoder is in \emph{clean state}: at this point
either
\[ 0\le \tilde \alpha_j< 1/4 \land 1/2\le \tilde \beta_j\le 1\]
(condition (1a) in \cite{witten1987arithmetic})
or
\[0\le \tilde \alpha_j< 1/2 \land 3/4\le\tilde \beta_j\le 1\]
(condition (1b) in \cite{witten1987arithmetic})
%(up to some equalities)

Now suppose this happens.

The encoder receives many symbols, say $N$, but it does not emit any bit,
neither store any virtual bits in \texttt{bits\_to\_follow},
because
\[ 0\le \alpha_j< 1/4\land 1/2\le \beta_j\le 1\] at all $j\le N$;
so $\tilde\alpha_j=\alpha_j$, $\tilde\beta_j=\beta_j$.
(A symmetric situation is possible)

At that time the decoder is still at the pristine state $[0,1]$.

\smallskip

We suppose that the decoder knows that it will be flushed after receiving N symbols;
either because this number was passed in a header of the encoded
file, or because the N-th symbol is a special \texttt{WILL\_FLUSH} symbol
(similarly to the \texttt{EOF} symbol in  \cite{witten1987arithmetic}).

\smallskip

The encoder is then flushed, so that it emits enough bits so that the
decoder can decode the N symbols. Since $\alpha_N< 1/4$, then the
encoder sends a 0 and then a 1 (and would send
\texttt{bits\_to\_follow} other ones, but in this example there are no
virtual bits, for simplicity).

The decoder bit interval is now
\[ [1/4, \, 1/2) = [ 0.01000\ldots 0 , \, 0.0111\ldots 1] \]
(where on the right we express the binary representation of the interval in the algorithm);
the decoder understands all symbols up to symbol $N$:
indeed there is only one string of symbols such that $[\alpha_N,\beta_N]\supseteq [1/4,\, 1/2]$

\section{Non-destructive flushing}

\subsection{Low case}
We consider the case
\[ 0\le \alpha_N< 1/4\land 1/2\le \beta_N\le 1\quad.\]

We wish explain the sequence ``01'' that the Encoder has sent for flushing,
as the encoding of 3 i.i.d Bernoulli symbols.
For simplicity though we express it as the sending of one symbol $s$ uniformly
distributed in $\{0,1,2,3,4,5,6,7\}$: this symbol indeed is equivalent
to ``3 input bits''
(up to numerical approximation).

So
\[\alpha_{N+1}= \alpha_N+\frac{7-s}{8}(\beta_N-\alpha_N)  \quad,\quad
  \beta_{N+1}=\alpha_N+\frac{8-s}{8}(\beta_N-\alpha_N)\]
(we follow the convention of  \cite{witten1987arithmetic}, that
subintervals are in decreasing order as $s$ increases --- this is also
the convention used in the reference code).

Since the width of $[\alpha_N,\beta_N]$ is at most 1,
then the width of any subinterval  $[\alpha_{N+1},\beta_{N+1}]$
is at most $1/8$;
so there must exist a choice of $s$ such that  $[\alpha_{N+1},\beta_{N+1}]$
is contained in
\[ [1/4, \, 1/2) = [ 0.01000\ldots 0 , \, 0.0111\ldots 1] \]
(that has width $1/4$).

We will show that a possible choice is
\[s = \left\lfloor \frac{8 \beta_N - 2}{(\beta_N-\alpha_N) }\right\rfloor - 1 \]

Hence, if we input that symbol in the encoder after the $N$-th symbol,
we will obtain two important results:
\begin{itemize}
\item the Encoder will emit $01$, that will flush the system
  (it may emit a further bit; we skip the discussion);
\item the Decoder will be able to decode the symbol,
  and Encoding/Decoding may proceed behind the flush.
\end{itemize}

\begin{proof}
To be consistent with what the decoder is receiving
\begin{align}
  1/4\le   \alpha_{N+1} \quad,\quad \beta_{N+1}< 1/2
\end{align}
that is
\begin{align*}
  1/4\le   \alpha_{N+1}
  \iff \\
  1/4\le  \alpha_N+\frac{7-s}{8}(\beta_N-\alpha_N)
  \iff \\
  \frac{2- 8 \alpha_N}{(\beta_N-\alpha_N) } \le  7-s
  \iff \\
  \frac{2-  \alpha_N - 7 \beta_N}{(\beta_N-\alpha_N) } \le  -s
  \iff \\
  s\le  \frac{-2+  \alpha_N + 7 \beta_N}{(\beta_N-\alpha_N) } =  \frac{8 \beta_N - 2}{(\beta_N-\alpha_N) } - 1
\end{align*}
whereas
\begin{align*}
  \beta_{N+1}< 1/2
  \iff \\
  \alpha_N+\frac{8-s}{8}(\beta_N-\alpha_N) < 1/2
  \iff\\
  8 -s < \frac{{4 - 8 \alpha_N}}{(\beta_N-\alpha_N)}
  \iff \\
   -s < \frac{{4 - 8 \beta_N}}{(\beta_N-\alpha_N)}
  \iff \\
   s > \frac{{8 \beta_N - 4}}{(\beta_N-\alpha_N)}
\end{align*}
summarizing
\begin{equation}
  \frac{{8 \beta_N - 4}}{(\beta_N-\alpha_N)} <  s\le  \frac{8 \beta_N - 2}{(\beta_N-\alpha_N) } - 1\label{eq:low_s_ineq}
\end{equation}

We double-check that the interval contains an integer, indeed the difference of the extremes is
\[    \frac{2}{(\beta_N-\alpha_N) } - 1 \ge  1 \]
\end{proof}

\subsection{Examples}

Some examples of
possible values of
\[s = \left\lfloor \frac{8 \beta_N - 2}{(\beta_N-\alpha_N) }\right\rfloor - 1 \]
\begin{itemize}
\item If $\alpha_N=1/4$ then
  \[ \frac{8 \beta_N - 2}{(\beta_N-1/4) } = 8\]
  so $s=7$, regardless of $\beta_N$.

\item If $\alpha_N=0$
  \[ \frac{8 \beta_N - 2}{\beta_N } = 8 - \frac{2}{\beta_N }\]
  so
  \[s = 7 - \left\lceil \frac{2}{\beta_N }\right\rceil \quad, \]
  so $s\in\{5,6,7\}$;
\item in particular if if $\beta_N=1, \alpha_N=0$ then $s=5$.
\end{itemize}

\subsection{High case}
We consider the case
\[ 0\le \alpha_N< 1/2\land 3/4\le  \beta_N\le 1\quad.\]
In this case the encoder emits $10$; a good choice is
\[s = \left\lfloor \frac{8 \beta_N - 4}{(\beta_N-\alpha_N) }\right\rfloor - 1 \]
\begin{proof}
To be consistent with what the decoder is receiving
\begin{align}
  1/2\le   \alpha_{N+1} \quad,\quad \beta_{N+1}< 3/4
\end{align}
that is
\begin{align*}
  1/2\le   \alpha_{N+1}
  \iff \\
  1/2\le  \alpha_N+\frac{7-s}{8}(\beta_N-\alpha_N)
  \iff \\
  \frac{4- 8 \alpha_N}{(\beta_N-\alpha_N) } \le  7-s
  \iff \\
  \frac{4-  \alpha_N - 7 \beta_N}{(\beta_N-\alpha_N) } \le  -s
  \iff \\
  s\le  \frac{-4+  \alpha_N + 7 \beta_N}{(\beta_N-\alpha_N) } =  \frac{8 \beta_N - 4}{(\beta_N-\alpha_N) } - 1
\end{align*}
whereas
\begin{align*}
  \beta_{N+1}< 3/4
  \iff \\
  \alpha_N+\frac{8-s}{8}(\beta_N-\alpha_N) < 3/4
  \iff\\
  8 -s < \frac{{6 - 8 \alpha_N}}{(\beta_N-\alpha_N)}
  \iff \\
   -s < \frac{{6 - 8 \beta_N}}{(\beta_N-\alpha_N)}
  \iff \\
   s > \frac{{8 \beta_N - 6}}{(\beta_N-\alpha_N)}
\end{align*}
summarizing
\begin{equation}
  \frac{{8 \beta_N - 6}}{(\beta_N-\alpha_N)} <  s\le  \frac{8 \beta_N - 4}{(\beta_N-\alpha_N) } - 1\label{eq:high_s_ineq}
\end{equation}

We double-check that the interval contains an integer, indeed the difference of the extremes is
\[    \frac{2}{(\beta_N-\alpha_N) } - 1 \ge  1 \]
\end{proof}

\subsection{Remark on symmetry}
Suppose
\[ 0\le \hat \alpha_N< 1/2\land 3/4\le \hat \beta_N\le 1\quad.\]
This is symmetric of the ``low'' case, up to defining
\[\hat\alpha_j=1-\beta_j\quad,\quad \hat \beta_j = 1 - \alpha_j \]
by defining $\hat s=8-s$
the inequality
\eqref{eq:low_s_ineq}
becomes  the inequality
\eqref{eq:high_s_ineq};
but the role of $\le$ and $<$ is inverted.

\providecommand{\bysame}{\leavevmode\hbox to3em{\hrulefill}\thinspace}
\begin{thebibliography}{1}
\bibitem{witten1987arithmetic}
Ian~H Witten, Radford~M Neal, and John~G Cleary.
\newblock Arithmetic coding for data compression.
\newblock {\em Communications of the ACM}, 30(6):520--540, 1987.

\end{thebibliography}

\end{document}


\par
\vfill \eject
\section{MPI Solution of $A X = Y$ using an $LU$ factorization}
\label{section:LU-MPI}
\par
Unlike the serial and multithreaded environments where the data
structures are global, existing under one address space,
in the MPI environment, data is local, each process or processor
has its own distinct address space.
The MPI step-by-step process to solve a linear system is exactly
the same as the multithreaded case, with the additional trouble
that the data structures are distributed and need to be
re-distributed as needed.
\par
The ownership of the factor matrices during the factorization and
solves is exactly the same as for the multithreaded case -- the
map from fronts to processors and map from submatrices to
processors are identical to their counterparts in the multithreaded
program.
What is different is the explicit message passing of data
structures between processors.
Luckily, most of this is hidden to the user code.
\par
We will now begin to work our way through the program
found in Section~\ref{section:LU-MPI-driver}
to illustrate the use of {\bf SPOOLES} to solve a system
of linear equations in the MPI environment.
\par
\subsection{Reading the input parameters}
\label{subsection:MPI:input-data}
\par
This step is identical to the serial code, as described in
Section~\ref{subsection:serial:input-data}, with the exception
that the file names for $A$ and $Y$ are hardcoded in the driver,
and so are not part of the input parameters.
\par
\subsection{Communicating the data for the problem}
\label{subsection:MPI:communicating-data}
\par
This step is identical to the serial code, as described in
Section~\ref{subsection:serial:communicating-data}
In the serial and multithreaded codes, the entire matrix $A$ was
read in from one file and placed into one {\tt InpMtx} object.
In the MPI environment, this need not be the case that one
processor holds the entire matrix $A$.
(In fact, $A$ must be distributed across processors during the
factorization.)
\par
Each processor opens a matrix file, (possibly) reads in matrix
entries, and creates its {\it local} {\tt InpMtx} object that holds
the matrix entries it has read in.
We have hardcoded the file names: processor $q$ reads
its matrix entries from file {\tt matrix.}$q${\tt .input}
and
its right hand side entries from file {\tt rhs.}$q${\tt .input}.
The file formats are the same as for the serial and multithreaded
drivers.
\par
The entries needed not be partitioned over the files.
For example, each processor could read in entries for disjoint sets
of finite elements.
Naturally some degrees of freedom will have support on elements
that are found on different processors.
When the entries in $A$ and $Y$ are mapped to processors, an
assembly of the matrix entries will be done automatically.
\par
It could be the case that the matrix $A$ and right hand side $Y$
are read in by one processor. (This was the approach we took with
the {\tt LinSol} wrapper objects.)
There still need to be input files for the other processors
with zeroes on their first (and only) line,
to specify that no entries are to be read.
\par
\subsection{Reordering the linear system}
\label{subsection:MPI:reordering}
\par
The first part is very similar to the serial code, as described in
Section~\ref{subsection:serial:reordering}.
\begin{verbatim}
graph = Graph_new() ;
adjIVL = InpMtx_MPI_fullAdjacency(mtxA, stats, msglvl, msgFile, MPI_COMM_WORLD) ;
nedges = IVL_tsize(adjIVL) ;
Graph_init2(graph, 0, neqns, 0, nedges, neqns, nedges, adjIVL, NULL, NULL) ;
frontETree = orderViaMMD(graph, seed + myid, msglvl, msgFile) ;
\end{verbatim}
While the data and computations are distributed across the
processors, the ordering process is not.
Therefore we need a global graph on each processor.
Since the matrix $A$ is distributed across the processors,
we use the distributed {\tt InpMtx\_MPI\_fullAdjacency()} method
to construct the {\tt IVL} object of the graph of $A + A^T$.
\par
At this point, each processor has computed its own minimum degree
ordering and created a front tree object.
The orderings will likely be different, because each processors
input a different random number seed to the ordering method.
Only one ordering can be used for the factorization, so the
processors collectively determine which of the orderings is best,
which is then broadcast to all the processors, as the code fragment
below illustrates.
\begin{verbatim}
opcounts = DVinit(nproc, 0.0) ;
opcounts[myid] = ETree_nFactorOps(frontETree, type, symmetryflag) ;
MPI_Allgather((void *) &opcounts[myid], 1, MPI_DOUBLE,
              (void *) opcounts, 1, MPI_DOUBLE, MPI_COMM_WORLD) ;
minops = DVmin(nproc, opcounts, &root) ;
DVfree(opcounts) ;
frontETree = ETree_MPI_Bcast(frontETree, root, msglvl, msgFile, MPI_COMM_WORLD) ;
\end{verbatim}
\par
\subsection{Non-numeric work}
\label{subsection:MPI:non-numeric}
\par
Once the front tree is replicated across the processors, we obtain
the permutation vectors and permute the vertices in the front tree.
The local matrices for $A$ and $Y$ are also permuted.
These steps are identical to the serial and multithreaded drivers,
except the fact local instead of global $A$ and $Y$ matrices
are permuted.
\begin{verbatim}
oldToNewIV = ETree_oldToNewVtxPerm(frontETree) ;
newToOldIV = ETree_newToOldVtxPerm(frontETree) ;
ETree_permuteVertices(frontETree, oldToNewIV) ;
InpMtx_permute(mtxA, IV_entries(oldToNewIV),
IV_entries(oldToNewIV)) ;
if (  symmetryflag == SPOOLES_SYMMETRIC || symmetryflag == SPOOLES_HERMITIAN ) {
   InpMtx_mapToUpperTriangle(mtxA) ;
}
InpMtx_changeCoordType(mtxA, INPMTX_BY_CHEVRONS) ;
InpMtx_changeStorageMode(mtxA, INPMTX_BY_VECTORS) ;
DenseMtx_permuteRows(mtxY, oldToNewIV) ;
\end{verbatim}
\par
The next step is to obtain the map from fronts to processors,
just as was done in the multithreaded driver.
In addition, we need a map from vertices to processors to be able
to distribute the matrix $A$ and right hand side $Y$ as necessary.
Since we have the map from vertices to fronts inside the front tree
object, the vertex map is easy to determine.
\begin{verbatim}
cutoff   = 1./(2*nproc) ;
cumopsDV = DV_new() ;
DV_init(cumopsDV, nproc, NULL) ;
ownersIV = ETree_ddMap(frontETree, type, symmetryflag, cumopsDV, cutoff) ;
DV_free(cumopsDV) ;
vtxmapIV = IV_new() ;
IV_init(vtxmapIV, neqns, NULL) ;
IVgather(neqns, IV_entries(vtxmapIV), IV_entries(ownersIV), ETree_vtxToFront(frontETree)) ;
\end{verbatim}
At this point we are ready to assemble and distribute the entries
of $A$ and $Y$.
\begin{verbatim}
firsttag = 0 ;
newA = InpMtx_MPI_split(mtxA, vtxmapIV, stats, msglvl, msgFile, firsttag,
MPI_COMM_WORLD) ;
InpMtx_free(mtxA) ;
mtxA = newA ;
InpMtx_changeStorageMode(mtxA, INPMTX_BY_VECTORS) ;
newY = DenseMtx_MPI_splitByRows(mtxY, vtxmapIV, stats, msglvl,
                                msgFile, firsttag, MPI_COMM_WORLD) ;
DenseMtx_free(mtxY) ;
mtxY = newY ;
\end{verbatim}
The {\tt InpMtx\_MPI\_split()} method assembles and redistributes
the matrix entries by the vectors of the local matrix.
Recall above that the coordinate type was set to chevrons, as is
needed for the assembly of the entries into the front matrices.
The method returns a new {\tt InpMtx} object that contains the part
of $A$ that is needed by the processor.
The old {\tt InpMtx} object is free'd and the new one takes its place.
\par
Now we are ready to compute the symbolic factorization, but it too
much be done in a distributed manner.
\begin{verbatim}
symbfacIVL = SymbFac_MPI_initFromInpMtx(frontETree, ownersIV, mtxA,
                    stats, msglvl, msgFile, firsttag, MPI_COMM_WORLD) ;
\end{verbatim}
The {\tt symbfacIVL} object on a particular processor is only a
subset of the global symbolic factorization, containing only what
it needs to know for it to compute its part of the factorization.
\par
\subsection{The Matrix Factorization}
\label{subsection:MPI:factor}
\par
In contrast the the multithreaded environment, data structures are
local to a processor, and so locks are not needed to manage access
to critical regions of code.
The initialization of the front matrix and submatrix manager
objects is much like the serial case, with one exception.
\par
\begin{verbatim}
mtxmanager = SubMtxManager_new() ;
SubMtxManager_init(mtxmanager, NO_LOCK, 0) ;
frontmtx = FrontMtx_new() ;
FrontMtx_init(frontmtx, frontETree, symbfacIVL, type, symmetryflag,
              FRONTMTX_DENSE_FRONTS, pivotingflag, NO_LOCK, myid,
              ownersIV, mtxmanager, msglvl, msgFile) ;
\end{verbatim}
Note that the nineth and tenth arguments are {\tt myid} and {\tt
ownersIV}, not {\tt 0} and {\tt NULL} as for the serial and
multithreaded drivers.
These arguments tell the front matrix object
that it needs to initialize only
those parts of the factor matrices that it ``owns'',
which are given by the map from fronts to processors
and the processor id.
\par
The numeric factorization is performed by the
{\tt FrontMtx\_MPI\_factorInpMtx()} method.
The code segment from the sample program for the numerical
factorization step is found below.
\begin{verbatim}
chvmanager = ChvManager_new() ;
ChvManager_init(chvmanager, NO_LOCK, 0) ;
rootchv = FrontMtx_MPI_factorInpMtx(frontmtx, mtxA, tau, droptol,
                     chvmanager, ownersIV, lookahead, &error, cpus,
                     stats, msglvl, msgFile, firsttag, MPI_COMM_WORLD) ;
ChvManager_free(chvmanager) ;
\end{verbatim}
Note that the {\tt ChvManager} is not locked.
The calling sequence is identical to that of
the multithreaded factorization except for the addition of the {\tt
firsttag} and MPI communicator at the end.
\par
The post-processing of the factorization is the same in principle
as in the serial code but differs in that is uses the distributed
data structures.
\begin{verbatim}
FrontMtx_MPI_postProcess(frontmtx, ownersIV, stats, msglvl,
                         msgFile, firsttag, MPI_COMM_WORLD) ;
\end{verbatim}
After the post-processing step, each local {\tt FrontMtx} object
contains the $L_{J,I}$, $D_{I,I}$ and $U_{I,J}$ submatrices
for the fronts that were owned by the particular processor.
However, the parallel solve is based on the submatrices being
distributed across the processors, not just the fronts.
\par
We must specify which threads own which submatrices,
and so perform computations with them.
This is done by constructing a {\it ``solve--map''} object,
as we see below.
\begin{verbatim}
solvemap = SolveMap_new() ;
SolveMap_ddMap(solvemap, symmetryflag, FrontMtx_upperBlockIVL(frontmtx),
               FrontMtx_lowerBlockIVL(frontmtx), nproc, ownersIV,
               FrontMtx_frontTree(frontmtx), seed, msglvl, msgFile) ;
\end{verbatim}
This object also uses a domain decomposition map, the only solve map
that presently found in the {\bf SPOOLES} library.
\par
Once the solve map has been created, (and note that it is identical
across all the processors), we redistribute the submatrices
with the following code fragment.
\begin{verbatim}
FrontMtx_MPI_split(frontmtx, solvemap, stats, msglvl, msgFile, firsttag, MPI_COMM_WORLD) ;
\end{verbatim}
At this point in time,
the submatrices that a processor owns are local to that processor.
\par
\subsection{The Forward and Backsolves}
\label{subsection:MPI:solve}
\par
If pivoting has been performed for numerical stability, then the
rows of $PY$ may not be located on the processor that needs them.
We must perform an additional redistribution of the local
{\tt DenseMtx} objects that hold $PY$, as the code fragment below
illustrates.
\begin{verbatim}
if ( FRONTMTX_IS_PIVOTING(frontmtx) ) {
   IV   *rowmapIV ;
/*
   ----------------------------------------------------------
   pivoting has taken place, redistribute the right hand side
   to match the final rows and columns in the fronts
   ----------------------------------------------------------
*/
   rowmapIV = FrontMtx_MPI_rowmapIV(frontmtx, ownersIV, msglvl,
                                    msgFile, MPI_COMM_WORLD) ;
   newY = DenseMtx_MPI_splitByRows(mtxY, rowmapIV, stats, msglvl,
                                   msgFile, firsttag, MPI_COMM_WORLD) ;
   DenseMtx_free(mtxY) ;
   mtxY = newY ;
   IV_free(rowmapIV) ;
}
\end{verbatim}
\par
Each processor now must create a local {\tt DenseMtx} object
to hold the rows of $PX$ that it owns.
\begin{verbatim}
ownedColumnsIV = FrontMtx_ownedColumnsIV(frontmtx, myid, ownersIV,
                                         msglvl, msgFile) ;
nmycol = IV_size(ownedColumnsIV) ;
mtxX = DenseMtx_new() ;
if ( nmycol > 0 ) {
   DenseMtx_init(mtxX, type, 0, 0, nmycol, nrhs, 1, nmycol) ;
   DenseMtx_rowIndices(mtxX, &nrow, &rowind) ;
   IVcopy(nmycol, rowind, IV_entries(ownedColumnsIV)) ;
}
\end{verbatim}
If $A$ is symmetric, or if pivoting for stability was not used,
then {\tt mtxX} can just be a pointer to {\tt mtxY}, i.e.,
$PX$ could overwrite $PY$.
\par
The parallel solve is remarkably similar to the serial solve,
as we see with the code fragment below.
\begin{verbatim}
solvemanager = SubMtxManager_new() ;
SubMtxManager_init(solvemanager, NO_LOCK, 0) ;
FrontMtx_MPI_solve(frontmtx, mtxX, mtxY, solvemanager, solvemap, cpus,
                   stats, msglvl, msgFile, firsttag, MPI_COMM_WORLD) ;
SubMtxManager_free(solvemanager) ;
\end{verbatim}
The only difference between the multithreaded and MPI solve
methods is the presence of the first tag and MPI communicator
in the latter.
\par
The last step is to permute the rows of the local solution matrix
into the original matrix ordering.
We also gather all the solution entries into one {\tt DenseMtx}
object on processor zero.
\begin{verbatim}
DenseMtx_permuteRows(mtxX, newToOldIV) ;
IV_fill(vtxmapIV, 0) ;
firsttag++ ;
mtxX = DenseMtx_MPI_splitByRows(mtxX, vtxmapIV, stats, msglvl, msgFile,
                                firsttag, MPI_COMM_WORLD) ;
\end{verbatim}
\par
\subsection{Sample Matrix and Right Hand Side Files}
\label{subsection:MPI:input-files}
\par
\begin{center}
\begin{tabular}{|l||l||l||l||}
\hline
{\tt matrix.0.input} &
{\tt matrix.1.input} &
{\tt matrix.2.input} &
{\tt matrix.3.input} \\
\begin{minipage}[t]{1 in}
\begin{verbatim}
9 9 6
0 0  4.0
0 1 -1.0
0 3 -1.0
1 1  4.0
1 2 -1.0
1 4 -1.0
\end{verbatim}
\end{minipage}
&
\begin{minipage}[t]{1 in}
\begin{verbatim}
9 9 5
2 2  4.0
2 5 -1.0
3 3  4.0
3 4 -1.0
3 6 -1.0
\end{verbatim}
\end{minipage}
&
\begin{minipage}[t]{1 in}
\begin{verbatim}
9 9 7
4 4  4.0
4 5 -1.0
4 7 -1.0
5 5  4.0
5 8 -1.0
6 6  4.0
6 7 -1.0

\end{verbatim}
\end{minipage}
&
\begin{minipage}[t]{1 in}
\begin{verbatim}
9 9 3
7 7  4.0
7 8 -1.0
8 8  4.0
\end{verbatim}
\end{minipage}
\\
\hline
\hline
{\tt rhs.0.input} &
{\tt rhs.1.input} &
{\tt rhs.2.input} &
{\tt rhs.3.input} \\
\begin{minipage}[t]{1 in}
\begin{verbatim}
2 1
0 0.0
1 0.0
\end{verbatim}
\end{minipage}
&
\begin{minipage}[t]{1 in}
\begin{verbatim}
2 1
2 0.0
3 0.0
\end{verbatim}
\end{minipage}
&
\begin{minipage}[t]{1 in}
\begin{verbatim}
2 1
4  1.0
5  0.0
\end{verbatim}
\end{minipage}
&
\begin{minipage}[t]{1 in}
\begin{verbatim}
3 1
6  0.0
7  0.0
8  0.0

\end{verbatim}
\end{minipage}
\\
\hline
\end{tabular}
\end{center}


%\section{Makespan as a Bound}
% To guarantee that our model will yield a solution that is \emph{sum-of-costs} optimal we need to provide a maximum $makespan$ $T$ big enough.

% In figure , we show an example where the increase of the \emph{makespan} returns better \emph{sum-of-costs} solutions. The problem has 3 agents:  $a_1$ needs to go from $(0,1)$ to $(3,1)$. The agents $a_2$ and $a_3$ are already at the goal on the positions $(1,1)$ and $(2,1)$ respectively. We compare the minimum \emph{sum-of-costs} solution with two different \emph{makespans}:

% \begin{itemize}
%     \item $\mu=3$. The optimal \emph{sum-of-costs} solution involves moving $a_2$ and $a_3$ out of their goal. The costs for each agent are: $cost(a_1) = 3$, $cost(a_2) = 2$ and $cost(a_3) = 3$, which gives us \emph{sum-of-costs} $=8$.
%     \item $\mu=5$. The optimal \emph{sum-of-costs} solution only needs to move $a_1$, dodging the locations occupied by the other agents: \emph{sum-of-costs} $=cost(a_1) = 5$
% \end{itemize}

% \emph{makespan} $m_{opt}$ that guarantees a cost-optimal solution given an initial solution.

% \begin{lemma}
% Given an initial solution with cost $\sigma$. We can bound $m_{opt}$ as:
% \[
%     m_{opt} \leq  \sigma - \min\limits_{i=\{1..k\} }{\sum_{\substack{j=1 \\ j \neq i}}^{k} c^*(a_j)}
% \]
% Where $c^*(a_j)$ is the optimal cost of the path $a_j$ ignoring the conflicts with other agents.
% \end{lemma}

\subsection{Finding Cost-Optimal Solutions}
The encoding proposed so far can find the minimum sum-of-cost solution for a given makespan. We still need to define how to find a true cost-optimal solution.

Following the approach used for SAT encodings for planning \cite{KautzS92}, in our approach we attempt to solve instances for increasing makespan $\mathtt{T}$, until a solution, say $sol_{min}$, is found. Two observations with this process are important. First, we do not need to start increasing $\mathtt{T}$ from 1. As mentioned above, at preprocessing time, for each agent we compute cost the cost $c^*_a$ which ignores other agents. The makespan of any solution must be at least $\max_{a\in\mathcal{A}} c^*_a$ so this can be the inferior limit of our iteration.

Second, let $sol_{min}$ be the solution that is found first. Unfortunately, $sol_{min}$ is a makespan-optimal solution but not necessarily a cost-optimal solution. Now we can compute a bound for the largest makespan $\mathtt{T}_{max}$ at which the cost-optimal solution is found, using the following theoretical result first proposed by \acite{SurynekFSB16}:
\begin{theorem}[\nbcite{SurynekFSB16}]\label{thm:optimal}
Let $sol_{min}$ be the makespan-optimal solution for MAPF problem $P$, let $sol^-$ denote a solution to $P$ that ignores all conflicts, and let $\mathtt{T}^-$ denote its makespan. Then the makespan of the cost-optimal solution is at most at $\mathtt{T}_{max}=\mathtt{T}^- + c(sol_{min})-c(sol^-)-1$.
\end{theorem}
Thus after we find the first solution $sol_{min}$, we run the solver again for makespan $\mathtt{T}_{max}$ given by Theorem~\ref{thm:optimal}. The approach described in this section was recently evaluated by \acite{BartakS19} for their Picat-based MAPF solver.

%First we calculate the shortest path for each agent ignoring the conflicts with other agents. The maximum cost and sum of costs of these paths provide a lower bound for the makespan $\mathtt{T}_{min}$ and \emph{sum-of-costs} respectively. Then we define and start solving an ASP program with one of the encodings defined before using $\mathtt{T}=\mathtt{T}_{min}$ as the makespan. If there's no solution we increase $\mathtt{T}$ by 1 and repeat the process.

%If the program returns a valid solution then as it was shown in Figure ~\ref{fig:makespancost} it's not guaranteed that is \emph{sum-of-cost} optimal.

%The using (bartak)

%So we run the program one last time using $\mathtt{T}=C(M) - 1 - C^-$ and return that solution.

% \begin{algorithm}
% \DontPrintSemicolon
% \KwIn{A MAPF problem}
% $\mathtt{T} \gets \max\limits_{i=\{1..K\} }{c^*(a_i)}$\;
% $C^- \gets \sum_{\substack{i=1}}^{k} c^*(a_i)$\;
% $P(\mathtt{T}) \gets$ Create an ASP program from input problem with makespan T\;% $M \gets \{\}$\;
%  \While{$M$ is empty}{%
%   $M \gets$ Solve $P(T)$\;
%   \If{$M$ is not empty}{
%     $C(M) \gets$ cost of the solution of model $M$\;
%     $\Delta \gets C(M) - 1 - C^-$\;
%     $M^* \gets$ Solve $P(\mathtt{T}+\Delta)$\;
%     \Return{M}\;
%   }
%   $\mathtt{T} \gets \mathtt{T}+1$\;
 %}

%\end{algorithm}


\documentclass[12pt,letterpaper]{article}
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage{textcomp}
\usepackage{multicol}
\usepackage{cancel}
\usepackage{enumitem}
\usepackage{graphicx}
% \renewcommand{\labelenumi}{\theparagraph.\arabic{enumi}}
\usepackage[top=1in, bottom=1in, left=0.75in, right=0.75in]{geometry}
\setlength{\parindent}{0pt}
\title{Physics Club Handout Soultions}
\begin{document}
\begin{multicols}{2}
\section{Motion}

\paragraph{Beginner problems:}
\begin{enumerate}
\item \[
\begin{aligned}
\Delta x &= \frac{v_o+v}{2}\,t\\
         &= \frac{10+20}{2}\left(10\right)\ \text{m}\\
         &= \fbox{150 m}
\end{aligned}
\]

\item \[
\begin{aligned}
\Delta r &= \sum r_i = 200\,\hat{i}\ +\\
         &  \left(135\cos{30.0\degree}\,\hat{i} + 135\sin{30.0\degree}\,\hat{j}\right) +\\
         &  \left(135\cos{-40.0\degree}\,\hat{i} + 135\sin{-40.0\degree}\,\hat{j}\right)\,\text{ft}\\
         &= \fbox{$\left(420.3\,\hat{i} - 19.28\,\hat{j}\right)$ ft}
\end{aligned}
\]

\item \[
\begin{aligned}
v_y^2&=v_{0y}+2a_y\Delta y\\
\Delta y&=\frac{v_y^2-v_{0y}^2}{2a_y}=\frac{v_0^2\sin^2 \theta}{2g}\\
v_y&=v_{0y}+a_yt\\
t&=\frac{v_y-v_{0y}}{a}=\frac{v\sin \theta}{g}\\
\Delta x &= v_{0x}t = v_0\cos \theta \frac{v_0\sin \theta}{g}
\end{aligned}
\] \[
\begin{aligned}
3 \Delta x &= \Delta y\\
3 v_0\cos \theta \frac{v_0\sin \theta}{g} &= \frac{v_0^2\sin^2 \theta}{2g}
\end{aligned}
\] \[
\begin{aligned}
\tan \theta &= 6\\
\theta &= \tan^{-1} 6 = \fbox{80.5$\degree$}
\end{aligned}
\]

\item
This question doesn't make sense.
\end{enumerate}
\paragraph{Intermediate problems:}
\begin{enumerate}
\setcounter{enumi}{4}
\item See problem 1.3.
\[
\begin{aligned}
h &= \frac{v_0^2\sin^2 \theta}{2g}\\
d &= v_0\cos \theta \frac{v_0\sin \theta}{g}\\
\frac{h}{d} &= \frac{\frac{v_0^2\sin^2 \theta}{2g}}{v_0\cos \theta \frac{v_0\sin \theta}{g}}\\
            &= \fbox{$\displaystyle \frac{\tan \theta}{2}$}
\end{aligned}
\]

\item \[
\begin{aligned}
|\vec{R}| &= \sqrt{x^2+y^2+z^2}\\
          &= \sqrt{2^2+1^2+3^2} = \fbox{3.74}
\end{aligned}
\] \[
\begin{aligned}
\cos \theta_r &= \frac{\vec{R}\,\hat{r}}{|\vec{R}|}\\
\theta_x &= \cos^{-1} \frac{\vec{R}\,\hat{i}}{|\vec{R}|} = \cos^{-1} \frac{2}{3.74} = \fbox{57.7$\degree$}\\
\theta_y &= \cos^{-1} \frac{\vec{R}\,\hat{j}}{|\vec{R}|} = \cos^{-1} \frac{1}{3.74} = \fbox{74.5$\degree$}\\
\theta_z &= \cos^{-1} \frac{\vec{R}\,\hat{k}}{|\vec{R}|} = \cos^{-1} \frac{3}{3.74} = \fbox{36.7$\degree$}
\end{aligned}
\]

\item
\vspace{-5pt}
\[
\begin{aligned}
\Delta x &= v_{0x}t\\
t &= \frac{\Delta x}{v_0\cos \theta}\\
\Delta y &= v_{0y}t + \frac{1}{2}at^2\\
\Delta y &= v_0\sin \theta \frac{\Delta x}{v_0\cos \theta} + \frac{1}{2}g\left(\frac{\Delta x}{v_0\cos \theta}\right)^2\\
\Delta y &= \tan \theta \sqrt{\left(\Delta r\right)^2 - \left(\Delta y\right)^2} +\\
         &  \frac{g\left(\left(\Delta r\right)^2 - \left(\Delta y\right)^2\right)}{2v_0^2\cos^2 \theta}\\
2.15 \times 10^3 &= \tan \theta\\
         &  \sqrt{\left(4 \times 10^3\right)^2 - \left(2.15 \times 10^3\right)^2} +\\
         &  \frac{9.81 \left(\left(4 \times 10^3\right)^2 - \left(2.15 \times 10^3\right)^2\right)}{2\cdot 280^2\cos^2 \theta}\\
\theta &= \fbox{21.5\degree}
\end{aligned}
\]
\end{enumerate}
\paragraph{Advanced problems:}
\begin{enumerate}
\setcounter{enumi}{7}
\item
$$\left(v\sin \theta\right)^2-\left(v\sin \theta\right)_0^2=2ah$$
$$\left(v\sin \theta\right)^2\propto h$$
$$v\sin\theta\propto\sqrt{h}$$
$$v_0 \cos \theta = \sqrt{\frac{6}{7}}\sqrt{\left(\frac{v_o\sin\theta}{\sqrt{2}}\right)^2+\left(v_0\cos\theta\right)^2}$$
$$cos^2 \theta = \frac{6}{7}\left(\frac{\sin^2 \theta}{2}+cos^2 \theta\right)$$
$$7cos^2 \theta = 3\sin^2 \theta + 6\cos^2 \theta$$
$$\tan \theta = \frac{1}{\sqrt{3}}$$
$$\theta = \tan^{-1} \frac{1}{\sqrt{3}} = \fbox{30$\degree$}$$

\item See problem 1.8.
$$v\sin\theta\propto\sqrt{h}$$
$$v_0 \cos \theta = m\sqrt{\left(\sqrt{n}v_o\sin\theta\right)^2+\left(v_0\cos\theta\right)^2}$$
$$cos^2 \theta = m^2\left(n\sin^2 \theta+cos^2 \theta\right)$$
$$\left(1-m^2\right)cos^2 \theta = nm^2\sin^2 \theta$$
$$\theta = \fbox{$\displaystyle \tan^{-1} \frac{1}{m}\sqrt{\frac{1-m^2}{n}}$}$$

\item \[
\begin{aligned}
x &= \left(v_0\cos \theta\right)t = d\cos \psi\\
y &= \left(v_0\sin \theta\right)t-\frac{1}{2}gt^2 = -d\sin \psi
\end{aligned}
\]
$$\left(v_0\sin \theta\right)\frac{d\cos \psi}{v_0\cos \theta}-\frac{1}{2}g\left(\frac{d\cos \psi}{v_0\cos \theta}\right)^2 = -d\sin \psi$$
$$\tan \theta \cos \psi-\frac{gd\cos^2 \psi}{2v_0^2\cos^2 \theta} = -\sin \psi$$
$$d = \frac{v_0^2}{g}\left(\sin 2\theta \sec \psi+2\cos^2 \theta\sec \psi \tan \psi\right)$$
Taking the derivative with respect to $\theta$:
$$\frac{dd}{d\theta} = \frac{2 v_0^2 \sec^2 \psi \cos\left(2 \theta+\psi\right)}{g}$$
Next, we equate this to 0 to find where $d$ is maximized. As an exercise, confirm that $d$ is at a maximum and not a minimum by computing $d^2d$\slash $d\theta^2$.
$$\frac{2 v_0^2 \sec^2 \psi \cos\left(2 \theta+\psi\right)}{g} = 0$$
$$2 \theta+\psi = \pi$$
$$\fbox{$\displaystyle \theta = \frac{\pi-\psi}{2}$}$$

\item\[
\begin{aligned}
R &= \frac{1}{2}gt^2\\
t &= \sqrt{\frac{2R}{g}}\\
\Delta x &= vt = \fbox{$\displaystyle v \sqrt{\frac{2R}{g}}$}\\
\Delta x &> R\\
v \sqrt{\frac{2R}{g}} &> R\\
v &> \sqrt{\frac{gR}{2}}
\end{aligned}
\]
\end{enumerate}

\section{Newton's Laws}

\paragraph{Beginner problems:}
\begin{enumerate}
\item
$$\sum \vec{F} = m\vec{a} = 0$$
$$\vec{F}_{air} = -\vec{v}^{\,2}*0.3141\frac{\text{kg}}{\text{m}} = mg$$
\[
\begin{aligned}
\vec{v} &= \sqrt{\frac{50\cdot 9.81}{0.3141}}\ \text{m\slash s}\\
        &= \fbox{39.5 m\slash s}
\end{aligned}
\]

\item
$$a_c = \frac{v^2}{r} = \frac{4^2}{12}\ \frac{\text{m}}{\text{s}^2} = \fbox{1.33 m\slash s$^2$}$$
\[
\begin{aligned}
a &= a_c + a_\perp = \left(1.33\,\hat{r} + 1.2\,\hat{t}\right)\,\text{m\slash s}^2\\
  &= \fbox{1.67 m\slash s$^2$ at $\theta = 48\degree$}
\end{aligned}
\]

\item \[
\begin{aligned}
F     &= ma\\
2T-mg &= m\frac{v^2}{R}
\end{aligned}
\] \[
\begin{aligned}
v &= \sqrt{R\left(\frac{2T}{m}-g\right)}\\
  &= \sqrt{3.00\left(\frac{2\cdot 350}{40.0}-9.81\right)}\ \text{m\slash s}\\
  &= \fbox{4.80 m\slash s}
\end{aligned}
\] \[
\begin{aligned}
            E_i &= E_f + W_{nc}\\
\frac{1}{2}mv^2 &= mgh
\end{aligned}
\]
$$h = \frac{v^2}{2g} = \frac{4.80^2}{2\cdot 9.81}\ \text{m} = \fbox{1.18 m}$$
\end{enumerate}

\paragraph{Intermediate problems:}
\begin{enumerate}
\setcounter{enumi}{3}
\item This question doesn't make sense.

\item
An amusement park ride is set up as a giant swing that starts at an angle of 80\degree\ to the vertical, and allows the swing to fall freely. For legal reasons, the maximum g-force a rider can experience is 5 g's (where 1 g = 9.81 m\slash s$^2$). Assuming no air resistance, what is the largest they can make the swing and still avoid litigation?

\item
A plumb bob (a weight hanging from a string) usually does not hang perfectly vertically (i.e. along a line directed towards the center of the earth). By how much does a plumb bob deviate from vertical here in Palo Alto (latitude of 37.4\degree\,N), assuming the earth is spherical and has radius 6380 km?
\end{enumerate}

\paragraph{Advanced problems:}
\begin{enumerate}
\setcounter{enumi}{6}
\item
An object moving througha a fluid experiences a force $\vec{F}_{drag} = -(ar\vec{v} + br^2\vec{v}^2)$ exerted on a sphere of radius $r$ moving through a fluid at speed $v$, where $a$ and $b$ are constants based on the shape of the object and the surrounding atmosphere. For spherical objects in air at sea level, $a = 3.10 \times 10^{-4}\,\text{Pa}\cdot \text{s}$ and $b = 0.870$ g\slash L.
Find the velocity of a water droplet of 100 \textmu m freefalling at time $t$, where $t$ is the time elapsed since it was released from rest.

% $$m\vec{g} - \vec{F}_{drag} = m\vec{a}$$
% $$v = \int a\,dt = \int \frac{F}{m}\,dt = \int_0^t \frac{m\vec{g} - (ar\vec{v} + br^2\vec{v}^2)}{m} \,dt = gt$$

\item \[
\begin{aligned}
\sum F = ma\\
F_n + F\sin \theta - mg = 0\\
F\cos \theta - f = 0\\
F\cos \theta - \mu_s\left(mg - F\sin \theta\right) = 0\\
F = \frac{\mu_s mg}{\cos \theta + \mu_s \sin \theta}
\end{aligned}
\]
In order to minimize $F$, we maximize the denominator on the right hand side by taking a derivative:
\[
\begin{aligned}
& -\sin \theta + \mu_s \cos \theta = 0\\
\theta &= \tan^{-1} \mu_s = \tan^{-1} 0.4 = \fbox{21.8$\degree$}\\
F &= \frac{\mu_s mg}{\cos \theta + \mu_s \sin \theta}\\
  &= \frac{0.4\cdot 1\cdot 9.81}{\cos 21.8\degree + 0.4 \sin 21.8\degree}\ \text{N}\\
  &= \fbox{3.64 N}
\end{aligned}
\]

\item \[
\begin{aligned}
\vec{F} &= (8.00\,\hat{i}-4.00\,t\,\hat{j})\ \text{N}\\
\vec{F} &= m\vec{a}\\
\vec{a} &= (4.00\,\hat{i}-2.00\,t\,\hat{j})\ \text{m\slash s}^2
\end{aligned}
\] \[
\begin{aligned}
\vec{v} = \int \vec{a}\,dt &= \int (4.00\,\hat{i}-2.00\,t\,\hat{j})\ \text{m\slash s}^2\,dt\\
                           &= (4.00\,t\,\hat{i}-1.00\,t^2\,\hat{j}+\cancel{C})\ \text{m\slash s}\\
|\vec{v}| = 15\ \text{m\slash s} &= \sqrt{\left(4.00\,t\right)^2+\left(-1.00\,t^2\right)^2}\\
t &= \fbox{3 s}\\
\vec{x} = \int \vec{v}\,dt &= \int (4.00\,t\,\hat{i}-1.00\,t^2\,\hat{j})\ \text{m\slash s}\, dt\\
                            &= (2.00\,t^2\,\hat{i}-0.33\,t^3\,\hat{j})\ \text{m}\\
\vec{x}\,(3\ \text{s}) &= (2.00\cdot 3^2\,\hat{i}-0.33\cdot 3^3\,\hat{j})\ \text{m}\\
&= \fbox{$18.0\,\hat{i}-9.00\,\hat{j}$ m}
\end{aligned}
\]
\end{enumerate}

\section{Energy}

\paragraph{Beginner problems:}
\begin{enumerate}
\item
\begin{enumerate}[label=(\alph*)]
\item
$\displaystyle W = F \Delta x \cos \theta$
$$W = 16.0 \cdot 2.20 \cos -25.0\degree\ \text{J} = \fbox{31.9 J}$$

\item The normal force is perpendicular to the direction of movement so the dot product $W = F \cdot \Delta x$ is \fbox{0}.

\item Similarly, the gravitational force is perpendicular to the direction of movement so the work done is \fbox{0}.

\item \(
\begin{aligned}
\displaystyle W_{\text{net}} &= W_F + W_{F_n} + W_g\\
               &= 31.9 + 0 + 0\ \text{J} = \fbox{31.9 J}
\end{aligned}
\)
\end{enumerate}

\item \[
\begin{aligned}
W &= \int F\,dx\\
  &= \int_{x = 0}^{0.600\ \text{m}} \left(5000+10000x-25000x^2\right)\,dx\\
  &= 5000x+5000x^2-8333x^3\Biggr|_{x = 0}^{0.600\ \text{m}}\ \text{J}\\
  &= \fbox{3000 J}
\end{aligned}
\]
$$\sum W = \Delta K = \frac{1}{2}mv^2$$
$$v =\sqrt{\frac{2W}{m}}=\sqrt{\frac{2\cdot 3000}{100 \times 10^{-3}}}\ \text{J} = \fbox{60000 J}$$

\item
$$E_i=E_f$$
$$\frac{1}{2}mv_0^2 + mgh = \frac{1}{2}mv^2$$
\[
\begin{aligned}
v &= \sqrt{v_0^2 + 2gh}\\
  &= \sqrt{42^2 + 2\cdot 9.81\cdot 100}\ \text{m\slash s} = \fbox{3726 m\slash s}
\end{aligned}
\]
\end{enumerate}
\paragraph{Intermediate problems:}
\begin{enumerate}
\setcounter{enumi}{3}
\item
$$W = F\,dx = -U$$
\[
\begin{aligned}
F = -U \frac{d}{dx} &= -\left(-x^3+2x^2+3x\right) \frac{d}{dx}\\
                    &= \fbox{$\displaystyle 3x^2-4x-3$}
\end{aligned}
\]
To find the stable and unstable equilibria, take the derivative of $U$ with respect to $x$:
$$U \frac{d}{dx} = -3x^2+4x+3 = 0$$
$$x = \frac{2 \pm \sqrt{13}}{3}$$
To determine whether each root is at a stable, unstable, or neutral equilibrium, we take the second derivative of $u$ with respect to $x$, $d^2U$\slash $dx^2$:
$$U \frac{d^2}{dx^2} = -6x+4$$
At $x = \frac{1}{3}\left(2 + \sqrt{13}\right)$, $d^2U$\slash $dx^2 = -\sqrt{13}$. At $x = \frac{1}{3}\left(2 - \sqrt{13}\right)$, $d^2U$\slash $dx^2 = \sqrt{13}$.
$x = \frac{1}{3}\left(2 + \sqrt{13}\right)$ is at a local maximum so it is at an unstable equilibrium.\\
$x = \frac{1}{3}\left(2 - \sqrt{13}\right)$ is at a local minimum so it is at a stable equilibrium.

\item
$$\sum F = ma_c$$
$$F_{n,\text{bot}}-mg=m\frac{v^2}{r}$$
$$F_{n,\text{bot}} = \fbox{$\displaystyle m\left(\frac{v^2}{r}+g\right)$}$$
$$E_i=E_f$$
$$\frac{1}{2}mv^2=\frac{1}{2}mv_{\text{top}}^2+mg\left(2r\right)$$
$$v_{\text{top}}^2=v^2-4gr$$
$$\sum F = ma_c$$
$$F_{n,\text{top}}+mg=m\frac{v_{\text{top}}^2}{r}$$
\[
\begin{aligned}
F_{n,\text{top}} &= m\left(\frac{v^2-4gr}{r}-g\right)\\
&= \fbox{$\displaystyle m\left(\frac{v^2}{r}-5g\right)$}
\end{aligned}
\]

\item
A block of mass $M$ rests on a table. It is fastened to the lower end of a light, vertical spring with spring constant $k$. The upper end of the spring is fastened to a block of mass $m$. The spring is then compressed a distance $d$ (relative to its unstretched state) by pushing down on the upper block. In this configuration, the upper block is released from rest. The spring lifts the lower block off the table. In terms of $m$, what is the greatest possible value for $M$?
\end{enumerate}
\paragraph{Advanced problems:}
\begin{enumerate}
\setcounter{enumi}{6}
\item The problem requires knowledge of techniques in multivaribale calculus. Compute when $z' = 0$ to find equilibria, and compute the sign of $z''$ to find the type of equilibrium. You should get infinite solutions since $\cos$ is periodic. Some solutions include $(-3.78416, -25.736)$ and $(1.77245, 1.77245)$.\\
\includegraphics[width=2.5in]{3-7.png}
\item
A ball of mass 300 g is connected by a strong string of length 80.0 cm to a pivot and held in place with the string vertical. A sudden gust of wind exerts constant force $F$ to the right on the ball. The ball is released from rest. The wind makes it swing up to attain maximum height $H$ above its starting point before it swings down again. Find $H$ as a function of $F$.

\item
Two stars of mass $M$ are separated by a distance $d$. One star is moving at a velocity $v$ relative to the other star, in a direction perpendicular to the line connecting the two stars. As time approaches infinity, how will the stars behave? (Will they enter a stable orbit with one another, will they collide, will they fly apart and never meet again?)
\end{enumerate}

\section{Momentum \& Impulse}

\paragraph{Beginner problems:}
\begin{enumerate}
\item \[
\begin{aligned}
p_i&=p_f\\
\left(m_{\text{man}}+m_{\text{box}}\right)v_i&=m_{\text{man}}v+m_{\text{box}}v_{\text{box}}\\
\end{aligned}
\] \[
\begin{aligned}
v&=\frac{\left(m_{\text{man}}+m_{\text{box}}\right)v_i-m_{\text{box}}v_{\text{box}}}{m_{\text{man}}}\\
 &=\frac{\left(60+20\right)7-20\cdot 5}{60}\ \text{m\slash s}\\
 &=\fbox{7.67 m\slash s}
\end{aligned}
\]

\item \[
m = m \cdot \frac{\left(mv\right)^2}{m^2v^2} = \frac{p^2}{2K} = \frac{40^2}{2\cdot 100}\ \text{kg} = \fbox{8 kg}
\]

\item Assume your mass $m=50$ kg.
\[
\begin{aligned}
E_i &= E_f\\
\frac{1}{2}mv^2 &= mgh\\
v &= \sqrt{2gh}\\
p_i &= p_f\\
m\sqrt{2gh} &= M_EV_E
\end{aligned}
\] \[
\begin{aligned}
V_E &= \frac{m}{M_E}\sqrt{2gh}\\
&= \frac{50\sqrt{2\cdot 9.81\cdot 0.75}}{5.97\times 10^{24}}\ \text{m\slash s} = \fbox{3.22 m\slash s}
\end{aligned}
\]
\end{enumerate}
\paragraph{Intermediate problems:}
\begin{enumerate}
\setcounter{enumi}{3}
\item
$$J = \Delta p = mv = \int F\,dt$$
\[
\begin{aligned}v &= \frac{1}{m} \int F\,dt = \frac{1}{50} \int_0^4 10\, t^2\, dt\\
    &= \frac{1}{50} \frac{10}{3}\, t^3\Biggr|_0^4\ \text{m\slash s} = \fbox{4.27 m\slash s}
\end{aligned}
\]

\item \[
\begin{aligned}
\sum F &= ma\\
F_n - mg &= 0
\end{aligned}
\] \[
\begin{aligned}
E_i &= E_f+W_{nc}\\
\frac{1}{2}mv_0^2 &= \frac{1}{2}mv_1^2+\mu_k mgd_1
\end{aligned}
\]
$$v_1 = \sqrt{v_0^2-2\mu_k gd_1}$$
\[
\begin{aligned}
p_i &= p_f\\
mv_1 &= Mv_2
\end{aligned}
\]
$$v_2 = \frac{m}{M}v_1 = \frac{m}{M}\sqrt{v_0^2-2\mu_k gd_1}$$
\[
\begin{aligned}
E_i &= E_f+W_{nc}\\
\frac{1}{2}mv_2^2 &= \mu_k mgd_2
\end{aligned}
\] \[
\begin{aligned}
d_2 &= \frac{v_2^2}{2\mu_k g} = \frac{\left(\frac{m}{M}\sqrt{v_0^2-2\mu_k gd_1}\right)^2}{2\mu_k g}\\
&= \left(\frac{m}{M}\right)^2\left(\frac{v_0^2}{2\mu_k g} - d_1\right)\\
&= \left(\frac{5.0}{15.0}\right)^2\left(\frac{8.0^2}{2\cdot 0.35\cdot 9.81} - 2.0\right)\ \text{m}\\
&= \fbox{2.44 m}
\end{aligned}
\]

\item \[
\begin{aligned}
p_i &= p_f\\
mv_{1i} &= mv_{1f} + mv_{2f}\\
v_{1i} &= v_{1f} + v_{2f}\\
E_i &= E_f\\
\frac{1}{2}mv_{1i}^2 &= \frac{1}{2}mv_{1f}^2 + \frac{1}{2}mv_{2f}^2\\
v_{1i}^2 &= v_{1f}^2 + v_{2f}^2\\
\left(v_{1f} + v_{2f}\right)^2 &= v_{1f}^2 + v_{2f}^2\\
v_{1f}^2 + v_{1f} \cdot v_{2f} + v_{2f}^2 &= v_{1f}^2 + v_{2f}^2\\
v_{1f} \cdot v_{2f} &= 0
\end{aligned}
\]
$$v_{1f} \perp v_{2f}$$
\end{enumerate}
\paragraph{Advanced problems:}
\begin{enumerate}
\setcounter{enumi}{6}
\item
$$F = \frac{dp}{dt} = \frac{d\left(mv\right)}{dt} = v\,\frac{dm}{dt} + m\,\frac{dv}{dt}$$
$$dm = \frac{M}{L}\,dx$$
$$F = v\,\frac{dm}{dt}=v\left(\frac{M}{L}\right)\frac{dx}{dt} = \left(\frac{M}{L}\right)v^2$$
$$F = \frac{2Mgx}{L}$$
$$F_g = \frac{Mgx}{L}$$
$$x = \frac{1}{2}gt^2$$
$$F_{\text{net}} = F + F_g = \frac{3Mgx}{L} = \frac{3Mgx}{L} = \fbox{$\displaystyle \frac{3Mg^2t^2}{2L}$}$$

\item
Two objects of mass $m_1$ and $m_2$ are traveling at velocities $\vec{v}_1$ and $\vec{v}_2$, respectively. They undergo a completely elastic collision. Find, in terms of these quantities, the final velocities of each mass.

\item
A tennis ball of mass $m_1$ is on top of a basketball of mass $m_2$ and radius $r$. If they are dropped from a height $h$, to what height does the tennis ball bounce, assuming all collisions are elastic?

Now consider a stack of $N$ balls, where the bottom ball has mass $m$, radius $r$, and each subsequent ball has mass 1/27 that of the previous ball, and radius 1/3 that of the previous ball. Assuming all collisions are elastic and without air resistance (which is completely absurd), and the stack of balls is dropped from height $h$, what is the highest ball's velocity?

\end{enumerate}
\end{multicols}
\end{document}


\section{\label{sec:sphericalgravity} Modifications for a Spherical Self-Gravitating Star}

In papers II and III, we calculated the hydrostatic expansion of the base state
in plane-parallel geometry under the assumption that the weight of the
material above (or below) any given fluid parcel does not change
during hydrostatic expansion.  This assumption holds when the
gravitational acceleration is independent of location.  Here we discuss the
modifications to the algorithm in paper III required to treat a spherical
self-gravitating star.

\subsection{One-dimensional Results}

To test the spherical base state expansions, we inject heat at a
steady rate into a one-dimensional white dwarf model.  This is similar
to the first test in paper II, except now in spherical coordinates.
As in that test, the compressible method with which we compare the low Mach number method
is the FLASH code's implementation of the
piecewise-parabolic method (PPM) in a one-dimensional spherical geometry.
The initial conditions for the white dwarf are those described in
Section 4.1 of paper III for the central region.

%A simple initial model for a white dwarf was constructed by specifying
%a central density of $2.6\times 10^9~\gcc$, a central temperature of
%$7\times 10^8$~K, and a composition of 30\% carbon and 70\% oxygen,
%and integrating the equation of hydrostatic equilibrium outward (using
%spherically symmetric self-gravity) while constraining the entropy to
%be constant.  Once the temperature of the model falls to $10^7$~K, it
%is held constant---this happens only at the very outer region of the
%star.  Together with the equation of state, this completely determines
%the density, temperature, and pressure structure of the star.

In the expansion of a plane-parallel atmosphere, heating at a
height $r$ above the base does not affect the pressure or density
below that height.  By contrast, in a spherical symmetric
self-gravitating star, heating at a radius $r$ will lead to a pressure
and density decrease at the center in addition to the expansion of the
outer layers (see Schwarzchild \& Harm, 1965, ApJ, 146, 855).

We apply a heating function of the form:
\begin{equation}
\Hext = H_0 \exp \left [-(r-r_0)^2 / W^2 \right ] \enskip ,
\end{equation}
with $r_0 = 4\times 10^7$~cm, $W = 10^7$~cm, and $H_0 = 1\times
10^{16}$~erg~g$^{-1}$~s$^{-1}$. This is the same functional form as used
in the first test of paper II, but with a lower amplitude.  Still, this
heating rate is far higher than what is expected during the convective
phase of Type Ia SNe.  The heating term is added to the enthalpy
equation in the low Mach number equations in the same fashion as
described in paper II.  In this test, we do not consider reactions.
Since this is a one-dimensional test all perturbational quantities,
as well as $\Ubt,$ are zero, so we are directly testing the computation of
$w_0$ as and the base state update as described in
the {\bf Advect Base} procedure defined above.
Both the PPM and low Mach calculation use 768 zones in a domain $5\times
10^8$~cm high.

Figure~\ref{fig:spherical768} shows the structure of the star after
heating for 10~s.  The gray line is the initial star before any
heating.
%The solid black line is the PPM result and the dotted and
%dashed lines are the low Mach number model with advective CFL numbers
%of $0.5$ and $0.1$ respectively (the PPM calculation used a CFL number
%of $0.5$).
We see that the compressible and low Mach number models
agree extremely well.  Both capture the decrease in the density and
pressure at the center of the star and the considerable expansion in
radius.  Only at the surface of the star do the temperatures differ slightly.
In all calculations, we set the minimum temperature to $5\times
10^6$~K.  The PPM simulation required 13488 steps and the low Mach
(CFL $=0.5$) calculation needed 203.  Over the course of the
simulation, the Mach number of the flow remained less than $0.35$, with the
maximum Mach number occurring at the surface of the star.  This Mach
number pushes the limits of validity of the low Mach number model;  a
smaller perturbation amplitude would result in a smaller Mach number.

Future improvements to the overall spherical base-state adjustment
algorithm will address the expansion in a simulation where the medium
outside the star is not brought down to arbitrarily low densities, but
instead a ``cutoff density'' is applied, as in the case of the
plane-parallel results presented in this paper. However, we expect
the changes to the overall method shown here to be small. \MarginPar{new}

{\color{red} Add a figure showing that we retain the correct solution
even when we place higher density material outside the star.}

\clearpage

\begin{figure*}
\begin{center}
\includegraphics[width=5.0in]{\sphericalfigpath/spherical_adjust_768}
\end{center}
\caption[Spherical hydrostatic adjustment]
{\label{fig:spherical768} Hydrostatic adjustment of a
spherically symmetric white dwarf with self-gravity.  The gray line
represents the initial model;  all other lines are after 10~s of heating.
The solid black line is the fully compressible solution, the dotted line is the
low Mach number solution with a CFL number of 0.5,  and the dashed line is
the low Mach number solution with a CFL number of 0.1.  All
simulations used 768 equally spaced zones.  We see excellent agreement
between the compressible and low Mach number models.  The only
differences appear at the top of the atmosphere, where the outer
boundary condition can influence the results.}
\end{figure*}


\chapter{Introduction}
\label{Introduction}

	Differential equations, ordinary or partial, allow modeling phenomena that evolve with respect to space and time. They are commonly used to describe the propagation of sound or heat and appear frequently in models related to electrostatics, electrodynamics, fluid dynamics, elasticity, quantum mechanics, and among other more related areas. \\

	However, their analytical solutions cannot always be easily obtained and in many cases, it will be necessary to resort to very complex techniques that tend to give solutions with very impractical mathematical expressions to use. In particular, problems characterized as non-linear present these difficulties, and considering a different alternative to find solutions may be a more reasonable option. \\

	There are alternatives to find solutions to differential equations, which depend on the nature of the problem to be solved. For example, computational fluid dynamics is one of the branches of fluid mechanics that uses numerical methods and algorithms to solve and analyze fluid flow problems that perform millions of calculations to simulate the interaction of liquids and gases through complex surfaces. However, even with simplified equations and high-performance supercomputers, in many cases, only approximate results can be achieved. \\

	The resolution of differential equations related to the characterization of fluids, and in general, for those that occur in the field of complex systems, are considered of utmost importance since they allow studying problems of great interest such as the turbulence phenomenon that allows understanding with precision its dynamics. Understanding these phenomena through differential equations is not enough, it is also necessary to characterize their nature, which in some cases is possible if the dimensionless value of the Reynolds number ($Re$) that indicates whether a fluid follows a laminar flow is known or turbulent. However, it is not always possible to predict with this information those phenomena that present turbulence in a combination of convection or combustion processes, and that therefore require greater attention in their dynamics. \\

	Spectral methods have recently emerged as a viable alternative for the numerical solution of partial differential equations. They have proved particularly useful in fluid dynamics simulation where are now regularly used large spectral hydrodynamics codes to study turbulence, numerical weather prediction, ocean dynamics, and any other problems where high accuracy is desired. \\

	Due to the above, he has motivated the development of this thesis by studying spectral methods extensively to acquire the ability to use this tool and understand them from the point of view of mathematical analysis. To develop this study we will focus first on the elementary theory of these methods, encompassing enough knowledge to allow us to develop, implement and analyze under this approach a wide variety of problems that arise in the partial differential equations that evolve. \\

	To understand the application of these methods, the well-known Burgers' equation has been considered, since it is an ideal problem for understanding these methods because, in addition to being a non-linear problem that presents interesting characteristics, it can be useful to develop the ability to attack more complex problems. Furthermore, in order to extend the study of the implementation of spectral methods, we are going to work with the stochastic version of this equation that will be very useful for us to know in general terms trying to solve problems of this type, which are considered of great importance for its wide field of applications and that it is still an area that is in full development due to the great difficulty in obtaining solutions. \\

	To carry out this study, we will divide the work into six parts organized as follows
	\begin{enumerate}
		\item[1.] In chapter \ref{Introduction}, a brief history of Burgers' equation will be presented in its deterministic version, and we will also present how to obtain the analytical solution for an initial value problem of this equation, transforming it into another linear one that can be solved using the Fourier transform. Later, the origin of the stochastic version will be discussed, in addition to its importance within mathematics and physics.

		\item[2.] In chapter \ref{Chapter_2}, we will study the theoretical bases of spectral methods using the well-known Fourier series as the main tool, which will allow us to study a theory of approximation of functions under two approaches, using orthogonal projections and another using interpolation techniques. These two approaches will be examined independently, studying their implementation and some theoretical results that will be useful in chapter \ref{Chapter_3}.

		\item[3.] In chapter \ref{Chapter_3}, the spectral methods known as Fourier-Galerkin and Fourier-Collocation will be developed using the tools examined in chapter \ref{Chapter_2}, verifying their convergence theory. For this, the deterministic Burgers' equation will be used, taking advantage of its linearized form to describe the methods, which will then be applied to the original nonlinear equation to describe the algorithms of its computational implementation that will allow us to perform numerical experiments and to be able to observe some characteristics interesting for your discussion.

		\item[4.] In chapter \ref{Chapter_4}, a spectral method used to solve stochastic partial differential equations that was studied in \cite{Delgado2016} will be disclosed in as much detail as possible. We will see that this method, which is built based on the well-known Hermite polynomials, will allow us to obtain solutions of stochastic problems by solving a deterministic type problem, and will be illustrated using the stochastic Burgers' equation developing its implementation and also numerical simulations.

		\item[5.] In this last chapter, we will discuss the most relevant of each chapter, and we will give some observations of the obtained numerical results to conclude with some ideas that can be considered to extend this work.

		\item[6.] At the end of this work, an appendix \ref{Appendix_A} was added, which will be useful to understand in more detail the spectral method developed in chapter \ref{Chapter_4}.
	\end{enumerate}

	\input{introduction/Burgers_Deterministic}
	\newpage
	\input{introduction/Burgers_Stochastic}


\documentclass{article}
\usepackage{arxiv}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{natbib}

\makeatletter
\theoremstyle{plain}
\newtheorem{thm}{\protect\theoremname}
\theoremstyle{plain}
\newtheorem{prop}[thm]{\protect\propositionname}
\ifx\proof\undefined
\newenvironment{proof}[1][\protect\proofname]{\par
	\normalfont\topsep6\p@\@plus6\p@\relax
	\trivlist
	\itemindent\parindent
	\item[\hskip\labelsep\scshape #1]\ignorespaces
}{%
	\endtrivlist\@endpefalse
}
\providecommand{\proofname}{Proof}
\fi

\makeatother

\usepackage{babel}
\providecommand{\propositionname}{Proposition}
\providecommand{\theoremname}{Theorem}

\begin{document}

\section{Identifiability of mixtures}
Recall that a density $f(x;\theta)$ is identified if $f(x;\theta_{1})=f(x;\theta_{2})$
for all $x$ implies that $\theta_{1}=\theta_{2}.$ Call a density
$f(x;\theta)$ \textit{strongly identified} if $f(x;\theta_{1})/f(x;\theta_{2})$
being constant for all $x$ in an open interval $I$ implies that
$\theta_{1}=\theta_{2}$.
\begin{prop}\label{prop:identified}
Let $f(x;\theta)$ be a family of densities on $\mathbb{R}$, $-\infty=a_{1}<a_{2}<\ldots<a_{k+1}=\infty$
a sequence of cutoffs, and $f_{[a_{i},a_{i+1}]}(x;\theta)$ the density
$f$ truncated to $[a_{i},a_{i+1}]$. Let $\lambda_{i},k=1,\ldots k$
be positive numbers satisfying $\sum_{i=1}^{k}\lambda_{i}=1$. Then
the mixture
\[
g(x;\lambda,\theta)=\sum_{i=1}^{k}\lambda_{i}f_{[a_{i},a_{i+1})}(x;\theta)
\]
is identified in $(\lambda,\theta)$ if $f(x;\theta)$ is strongly
identified in $\theta$.
\end{prop}
\begin{proof}
Assume that $g(x;\lambda_{1},\theta_{1})=g(x;\lambda_{2},\theta_{2})$.
Then $$\lambda_{1i}f_{[a_{i},a_{i+1}]}(x;\theta_{1})=\lambda_{2i}f_{[a_{i},a_{i+1}]}(x;\theta_{2})$$
for all $i$, thus
\[
\frac{\lambda_{1i}}{\lambda_{2i}}=\frac{f_{[a_{i},a_{i+1})}(x;\theta_{1})}{f_{[a_{i},a_{i+1})}(x;\theta_{2})}.
\]
This implies that $f(x;\theta_{1})/f(x;\theta_{2})$ is constant for
$x\in[a_{i},a_{i+1}]$. But since $f(x;\theta)$ is strongly identifiable,
$\theta_{1}=\theta_{2}$, and, consequently, $\lambda_1 = \lambda_2$.
\end{proof}
If $f(x;\theta)$ is real analytic and nowhere zero, $f(x;\theta_{1})/f(x;\theta_{2})$
is also real analytic and nowhere zero. By the Identity Theorem \citep[Corollary 1.2.6]{Krantz2002-bt}, if
$f(x;\theta_{1})/f(x;\theta_{2})$ is constant on some interval $I$,
then $f(x;\theta_{1})/f(x;\theta_{2})$ is constant everywhere, hence
$f(x;\theta_{1})=f(x;\theta_{2})$ everywhere. Thus a family of real
analytic nowhere zero densities is identified if and only if it is
strongly identified. Every exponential family of densities on the form
\[
f(x;\theta)=h(x)\exp(\eta(\theta)^{T}T(x)-A(\theta))
\]
satisfies this property, provided only that $h$ is nowhere zero real analytic
and $T$ is real analytic. In particular, the normal family satisfies
the properties.

Not every density is strongly identified. For instance, mixtures of uniforms are not strongly identified. And indeed, Proposition \ref{prop:identified} fails when $f$ is a mixture of uniforms.
\bibliographystyle{biom}
\bibliography{edited.bib}
\end{document}


    \filetitle{VAR}{Return a VAR object describing the factor dynamics}{FAVAR/VAR}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
v = VAR(a)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\texttt{a} {[} FAVAR {]} - FAVAR object.

\paragraph{Output arguments}\label{output-arguments}

\texttt{v} {[} VAR {]} - VAR object describing the dynamic system of the
FAVAR factors.

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}