\section{The Mixed Weighted Straight Skeleton}
\label{sec:mwss}

% Do we want to say that the PWSS may not grow (if all theta zero),?

The final variation of the SS we will introduce is the \emph{mixed weighted straight skeleton} (MWSS). This new structure allows the angle of the direction planes, $\theta$, to be positive or negative over edges in a single plan. Thus regions of the active plan can shrink inwards or grow outwards. Once again the increased degrees of freedom introduce new types of degeneracy. This section introduces some of the issues surrounding these \emph{point degeneracies}, presents an algorithm for simplifying them, and introduces one theorem as to the solution of such cases.

%: $-\frac{\pi}{2} < \theta < \frac{\pi}{2}$. Inititively this allows the edges of the active plan to move towards the interior or exterior at the same time.
As in the PWSS case, $\theta$ is limited in the MWSS to avoid infinitely fast edges on the active plan, allowing only  $-\frac{\pi}{2} < \theta < \frac{\pi}{2}$. Therefore a $\theta < 0$ implies that an active plan edge is moving away from the interior of the polygon, a $\theta = 0$ implies an edge that does not move, and a $\theta > 0$ implies an edge is moving towards to interior of the polygon. Fig.~\ref{fig:wss_strange} gives an example of both a PWSS and MWSS.
%The angle defines the slope of the face associated with that edge of the input plan. That is, $\theta$ defines the speed of the edge on the active plan as the sweep plan rises.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_strange}
  \caption[Degenerate events in the PWSS and MWSS]{\label{fig:wss_strange}. Left: A complex event in a PWSS, over a plan (green). Right: A MWSS in which four areas merge to become one. Note that the 3D models are the resulting terrains of a skeleton as some MWS skeletons are difficult to illustrate in 2D.}
\end{figure}

The MWSS enables a wider variety of 3D terrains to be defined; the set of skeletons definable are a superset of the SS, PWSS and NWSS schemes. For example the active plan can grow, as well as shrink, or can be a mixture of both. Therefore certain MWSSs may not terminate after the final event; the enclosed area may continue growing indefinitely as the sweep plane rises. It is an open problem to determine if a given MWSS will terminate if it contains any values of $\theta < 0$, without executing the skeleton algorithm itself. Fig.~\ref{fig:wss_unbounded} gives an example in which the resolution of a borderline case differentiates between an non-terminating skeleton, and a terminating one.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_unbounded}
  \caption[Unbounded MWSS]{\label{fig:wss_unbounded}MWSS that are bounded (left) and unbounded (right). The red face grows to an infinite area as the sweep plane rises. A small perturbation to the input plans is the only difference between the input plans, all $\theta$ value are equal. The PCE event which occurs along the orange line determines the behaviour of the skeleton. }
\end{figure}

As with the PWSS, the active plan can split as the sweep plane rises. But as Fig.~\ref{fig:wss_strange} shows, like the NWSS, MWSS regions can merge.

We note in passing that MWSS events exist in which no resolution is necessary. The edges intersect only at the event, but not after it. We disregard these \emph{grazing} events in what follows, as they are trivial to test for and may be simply ignored.

Given the additional degrees of freedom available in the MWSS we expect to encounter the degenerate situations observed in the SS and PWSS cases. In addition there are are a new class of \emph{point degeneracies} observable

\FloatBarrier
\subsection{Point degeneracies}

Given the additional degrees of freedom available in the MWSS, it is unsurprising that the GIE solution no longer solves all situations. Fig.~\ref{fig:pwss_gie_failure} gives one simple example event in which the GIE causes the active plan to become badly formed.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/pwss_gie_failure}
  \caption[The GIE doesn't work on the PWSS]{\label{fig:pwss_gie_failure}A MWSS topology at (left) and after (middle, right) an event (orange) that is not suitable for the GIE. The GIE output (middle, purple) is self-intersecting, and thus badly formed. A non-intersecting solution does exist (right).}
\end{figure}

Indeed every edge of an arbitrary input plan may be coerced to collide at single point by altering the values of $\theta$. A more complex example of a simple event is introduced in Fig.~\ref{fig:wss_example_topology}, which shows a possible event with many edges colliding. Here we can see chains of edges representing bounded, as well as unbounded areas, loops, and chains surrounding other chains, colliding at a simple event.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_example_topology}
  \caption[A point degeneracy]{\label{fig:wss_example_topology} Left: The active plan just before an event. A complex set of chains collide at a single event (orange). Right: after the intra-chain step and one-chain step of the GIE the topology is simplified. Note that the curved edges marked with an asterisk represent the topology of two colinear straight edges.}
\end{figure}

\begin{figure}
  \centering
  \def\svgwidth{0.4\columnwidth}
  \includesvg{12-skeleton/images/wss_enclosing_chain}
  \caption[Enclosing chains]{\label{fig:wss_enclosing_chain} We describe the chain \emph{a} as enclosing chain \emph{b}, as \emph{b} lies inside \emph{a}, and therefore $\phi < \gamma$, $\phi < \pi$ radians. The chains are shown here before a collision at the orange point.}
\end{figure}

If all the edges are moving inwards or outwards, as with the PWSS or NWSS, the SS GIE introduced in Sec.~\ref{s:gie} is still suitable. However in the complex degenerate events that may occur with some angles of $\theta > 0$ and some $\theta < 0$, another algorithm is needed. Fig.~\ref{fig:wss_options} gives one such situation and a number of plausible solutions.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_options}
  \caption[Several solutions to the MWSS]{\label{fig:wss_options}Above: Four chains collide at an event (orange point). The desired plan topology after the event is unclear. We must keep the interface edges (above, right: bold green arrows) in the same locations to remain compatible with the remainder of the plan. Below: There are many possible options for the topology change at the event. (Note that we show the active plan a time after the event). Some solutions use existing edges, others create new zero length edges (below: red shadows). During the event these edges have zero length, but subsequently grow).}
\end{figure}

\FloatBarrier

Characteristics that are logical in an algorithm for such events include:

\begin{enumerate}
\item{The plan remains well formed.}
\item{Consistency with the SS when all angles are a positive constant.}
\item{Consistency with the PWSS when all angles are positive.}
\item{Consistency with the NWSS when all angles are negative.}
\item{Invariance to rotation of the plan. As with the the straight skeleton the result of an event should not depend on the orientation of the plan.}
\item\label{enum:tmp}{No creation of new zero length edges during the event. The SS, PWSS and NWSS do not introduce additional edges; for consistency, neither should the MWSS.}
\end{enumerate}

We have been unable to find a elegant general solution to this problem!

\begin{figure}
  \centering
  \def\svgwidth{0.8\columnwidth}
  \includesvg{12-skeleton/images/wss_hand_examples}
  \caption[Manual examples of good MWSS solutions]{\label{fig:wss_hand_examples} Several example events and solutions that do not require 0-length edges to be introduced into the active plan. The geometry (green area) is shown after the event, and consists of length 2 chains colliding. A good solution for each topology is shown in purple. All examples except that in top, middle, fail when the GIE is used.}
\end{figure}

We hypothesise that it is always possible to find a solution in the events we encounter. Fig.~\ref{fig:wss_hand_examples} shows several events and potential solutions, however an algorithm to compute these events has not been discovered. In particular it is condition \ref{enum:tmp}, finding solutions that do not introduce zero length edges, that rules out many obvious algorithms.

We continue by introducing one further processing step that simplifies these point degeneracies by removing parallel edges. Finally we conclude by introducing a concise description of the unsolved problem, given this simplified event.

\subsection{Removing Parallel Adjacent Edges}

As per the GIE introduced in Sec.~\ref{s:gie} the topology of the event can be simplified by the intra chain and one chain steps. These steps simulate the plan as the sweep plan reaches the height of the event. Zero length edges, including chains that form a closed loop are removed and chains of length 1 are split, leaving a homogeneous topology of chains of length 2.

At an event all the edges involved in the collision approach the location in an ordering defined by the edge's orientation. Fig.~\ref{fig:wss_ordered_point}, left, shows the orientation-ordered points for Fig.~\ref{fig:wss_example_topology}. Any edges that do not approach according to their angle must have been removed by an earlier collision, Fig.~\ref{fig:wss_ordered_point}, right. This property is known as the \emph{$\ge$ approaching edges} property. This refers to the fact that the angle between consecutive edges around an intersection is equal to, or greater than, zero.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_ordered_point}
  \caption[Ordering chains around the event]{\label{fig:wss_ordered_point} As the chains of edges in the MWSS approach the event (orange) they become ordered (left). If this were not the case (right), they would have intersected during an separate earlier event (red).}
\end{figure}

The simplification we would like to perform is the removal of edges which are adjacent and parallel as they approach the event. That is when two parallel edges separated by $0^{\circ}$ approach an event from the same side. The area between these edges approaches zero near the event. If we connect these adjacent edges together, the event at the other end of the parallel lines will remove the loop in its intra chain stage. Therefore it can be ignored for the purposes of this event. After we remove these lines, we can say that the event has the \emph{$>$ approaching edges property} as all the angles between adjacent approaching edges are greater than zero.

This basic approach is hampered by the fact that more than two parallel edges may be adjacent at an event. If there are an even number of such edges at one event, the adjacent pairs of edges can be connected together to enclose a region under the sweep plane, as in Fig.~\ref{fig:wss_linear_align}. However if there are an odd number of edges, one edge must be chosen that is not connected to another and remains. This decision should be independent of the order co-heighted events are processed in, and must discard the same edge globally. Here we present two resolutions:
\begin{itemize}
\item{\emph{interior bias:} The pairs of lines surrounding an interior region of the plan are always connected.}
\item{\emph{exterior bias:} The pairs of lines surrounding an exterior region of the plan are always connected.}
\end{itemize}

\begin{figure}
  \centering
  \def\svgwidth{0.7\columnwidth}
  \includesvg{12-skeleton/images/wss_linear_align}
  \caption[Global coordination of a solution with parallel edges]{\label{fig:wss_linear_align} Given a plan before the event (top left) that leads to a number of events with parallel adjacent edges at the same height (top right, red blue and yellow circles), a deterministic and reproducible decision must be made as to which of the parallel edges are connected. The solutions given are to connect the parallel adjacent lines with an interior bias (bottom left) or exterior bias (bottom right). The areas v, w, x and y are all removed by subsequent events.}
\end{figure}

The earlier example in Fig.~\ref{fig:wss_example_topology}, is resolved using these two resolutions as shown in Fig.~\ref{fig:wss_equal_approach_killer}. Note that although the edges remaining have the same orientation, they may have different speeds. A consequence of the necessity of choosing an interior or exterior bias is that otherwise symmetrical plans may produce an asymmetrical outcome after an event. For example Fig~\ref{fig:skel_impossible} shows a plan that before the event is not changing area, but after will either be gaining, or losing area if the interior or exterior biases are chosen respectively.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_equal_approach_killer}
  \caption[Removing zero area chains]{\label{fig:wss_equal_approach_killer} After the intra chain step and one chain steps, we have a simplified topology (top, left). The chains are shown just before the event for clarity. The black lines connect (asterisked) edges which would become adjacent and parallel at the event. We convert these pairs of edges into single chains as shown. We either use the interior bias (top right) or exterior bias (bottom left). After any subsequent events at the same height are processed we are left with simplified topology (bottom right, for exterior bias).
}
\end{figure}

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/skel_impossible}
  \caption[A MWSS event that cannot be fairly solved]{\label{fig:skel_impossible}A MWSS event that has unchanging area before the event, but will either grow or shrink after, depending on the resolution strategy.}
\end{figure}

\FloatBarrier
\subsection{The Pincushion Problem}
\label{sec:pincushion}

Once an event has been prepared in the above way, we wish to process it in such a way that the plan remains well formed after the event. This is an unsolved problem; this section makes only definitions and observations.

Given a valid event that has been pre-processed such that it has the $>$ approaching edges property, the \emph{pincushion problem} is to devise an algorithm that always finds a solution that does not introduce new zero length edges in to the active plan. First we will show that the plan remains topologically invariant after an event, and then that we can draw a circle around all possible intersections of edges involved in the event. This ``pincushion'' circle, with ``pin'' edges leading into it encapsulates the problem of solving a general MWSS event.

As the sweep plane rises towards an event, after it has processed any previous events, the topology of the edges does not change. By definition the plan is well-formed before the event, with no self-intersections. Furthermore we can note that there are no topological changes as the sweep plane approaches the height; such changes would be witnessed by other events. Of more consequence is that topological invariance may also be observed after the event. That is, if we do not handle the event, the geometry after the event only scales, rather than changing topology.
We call this the \emph{sector property} of SS events, and is introduced in Fig~\ref{fig:wss_sector}. The sector property is summarised in the trivial statement ``between events, no events occur''.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/wss_sector}
  \caption[The sector property]{\label{fig:wss_sector}The plan (green triangles) undergoes an event (orange). The sector property states that topology of the edges remains unchanged after the event if we make no attempts at solving it (after 1, 2).}
\end{figure}

%\begin{figure}
%  \centering
%  \def\svgwidth{0.5\columnwidth}
%  \includesvg{12-skeleton/images/wss_sector_2}
%  \caption[The sector property]{\label{fig:skel_sector_2}After an event (orange), any intersection %between two edges, such as a corner, remains at constant angle, $\gamma$, relative to the event %location. This gives rise to the sector property.}
%\end{figure}

The sector property follows from two previous definitions:
\begin{itemize}
\item{The edges move over the plan in a self-parallel manner, at a constant speed.}
\item{The edges involved in an event pass through the event's location at the event}
\end{itemize}
Applying these two definitions allows us to make the trivial observation that all intersections between any pairs of edges move directly away from the intersection point after the event, each with constant speed. Therefore the order of crossings of any subset of involved edges remains invariant, along with the topology.

We may note in passing that there are three topologies of the edges involved in the event - before, at and after. The topology at the event only occurs for a single sweep-plane height, at an instant in time. We define the pincushion problem on the topology after the event.

To find solutions in the MWSS case it is necessary to extend some of the edges. An example where this is required is shown in Fig.~\ref{fig:pwss_extenstions_required}.

\begin{figure}
  \centering
  \def\svgwidth{0.7\columnwidth}
  \includesvg{12-skeleton/images/pwss_extensions_required}
  \caption[Edges become rays in the pincushion problem]{\label{fig:pwss_extenstions_required}A PWSS event in which the only solution requires the extension of edges (dashed line) from their unmodified post-event topology.}
\end{figure}

Given the invariant topology at some time after the event in question, there are only a finite number of edges involved. If we intersect all the edges we obtain a finite number of possible intersection points that may make up the solution. We discount non-intersections between parallel edges. Therefore we may attempt to encapsulate our problem by drawing a circle that encompasses all these possible intersection points. An example of the resulting \emph{pincushion} diagram is given in Fig.~\ref{fig:pincushion}. From the edge of the circle, an even number of unbounded edge-rays are ordered by angle around the perimeter. Rays are used since we may have to extend some of the line segments. There are an even number of rays, for each edge of the active plan that enters and leaves the circle.

A trivial observation is that for any successful solution only odd-numbered rays may intersect even number rays and vice versa (for any ordering around the perimeter of the pincushion). This matches the intuition that the orientation of the edges within the active plan determines which other edges they may intersect with. To this end we may colour the rays in the diagram with alternating colours; rays may only connect with other rays of the other colour, but may not cross any other rays as in Fig.~\ref{fig:pincushion} bottom row.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/pincushion}
  \caption[The Pincushion diagram]{\label{fig:pincushion}Top Left: It is possible to draw a circle around all possible edges that intersect at an event. Top Middle, Right: Given the sector property, we may summarise the topology as rays entering the pincushion circle. Bottom Left: We may assign alternating colours to rays around the circle. Bottom Middle: A pincushion diagram coloured in this way. Bottom Right: A solution to this pincushion consisting of the intersections $\{(m_2,f_1), (m_1,f_2), (f_3, m_4), (m_3, f_4), (m_6, f_5) (m_5, f_6)\}$}
\end{figure}

In a valid solution all pairs of rays in the pincushion diagram are connected to form chains of length 2, in such a way that the chains do not cross. We hypothesise that it is \emph{always possible to solve the pincushion problem}. Given a such a solution we can update the active plan in all situations.

The solution is not unique, as in Fig.~\ref{fig:mwss_multiple_solns}. Given a number of solutions we may chose to use the criteria of Sec.~\ref{sec:mwss} to determine which solution is most suitable for our application.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/mwss_multiple_solns}
  \caption[PWSS events may not have unique solutions]{\label{fig:mwss_multiple_solns}Given the post-event topology (top left), and the corresponding pincushion diagram (top right), there are three different solutions that do not introduce zero length lines (bottom).}
\end{figure}

A brute force search program has been written to search for valid edge pairs to intersect. Fig.~\ref{code:brute_force_pincushion} details an algorithm that applies the intra-chain stage of the GIE to all allowable subsets of edges in the event. This algorithm, together with a visual interface, as in Fig.~\ref{fig:bute_app_screenies}, never failed to find a solution to a valid pincushion arrangement. However, without a proof that there is always a solution to the pincushion problem we can not be certain that the brute force approach will always return a valid active plan.

\begin{algorithm} [htb]
\begin{footnotesize}
  BruteForceEvent ( Event $event$ ) \Begin{

    $pincusion$ = preprocess( $event$ )\;

    Set$<$Set$<$Set$<$Chain$>>>$ $combinations$ = all covering combinations of $pincushion$.chains()\;

    \ForEach{ Set $<$Set$<$Chain$>>$ $GIEChains$ in $combinations$} {
        Set$<$Chain$>$ $resolvedChains$ = new emptySet()\;

        \ForEach { Set$<$Chain$>$ $chain$ in $GIEChains$ }{
          $resolvedChains$.add( interChainStage ( $chains$ ) )\;
        }

        \If { noChainsIntersect( $resolvedChains$ )  } {
            return $resolvedChains$\;
          }
        }

    return $null$\;
}
\end{footnotesize}
  \caption[A brute force approach to the pincusion problem]{A brute force approach to the pincusion problem. We hypothesise that it will never return $null$.}
  \label{code:brute_force_pincushion}
\end{algorithm}

\begin{figure}
  \centering
  \def\svgwidth{0.7\columnwidth}
  \includesvg{12-skeleton/images/bute_app_screenies}
  \caption[Brute force application]{\label{fig:bute_app_screenies}A user interface to the pincusion event solver. Top Left: The users selects a resolution algorithm (a), draws the edges involved in the event around the event location (b), and selects the time relative to the event (c). Top Right: The system simulates the topology at the event. Bottom: The system shows the solutions given by the GIE (Left) and brute force algorithms (Right) in purple after the event.}
\end{figure}

Another approach is a constructive methodology to incrementally add the next pair of rays to an already valid solution, given some arbitrary order of rays. Since we theorise that all such arrangements have a valid solution, such a solution should be possible. However a counter example was found in the ``5-star'' structure of Fig.~\ref{fig:epp_5_cycle}. Attempting to incrementally add rays around the circumference, always keeping a valid solution with those lines already processed, either is not possible, or does not terminate; it is necessary to solve the system globally. In this case the GIE provides such a solution. We therefore believe that a global solution must be found, rather than an iteratively constructed one.

\begin{figure}
  \centering
  \def\svgwidth{1.0\columnwidth}
  \includesvg{12-skeleton/images/epp_5_cycle}
  \caption[The 5 Star Pincushion]{\label{fig:epp_5_cycle} The ``5 star'' event arrangement of edges, shown after the event (a), and the corresponding pincushion diagram (b). A constructive approach, which takes an arbitrary ordering of edges  (c, grey lines) and attempts to maintain a valid solution with each additional line (d), runs into problems when it cannot alter a past result (e). The correct solution in this case (f,g) must be found globally, and happens to be the same as the GIE solution.}
\end{figure}

The failures of the GIE, brute force, and incremental approaches to the pincushion problem are disappointing. Ultimately the lack of proof that the events of the MWSS have well formed solutions is problematic to the definition of the MWSS. However we may take solace that these are very degenerate situations and solutions that do introduce zero length edges are common.

\greybox{The pincushion problem was discussed with David Eppstein, author of \cite{Epp:98} and Antoine Vigneron, author of \cite{Cheng02}.}

\FloatBarrier
\section{Summary}

In this chapter we have explored a certain class of skeletons, formed by allowing the edges of a 2D shape to move in a self-parallel manner. By observing intersection events as the edges collapse we are able to trace out the arcs of the skeletons. Indeed it is by the simulation of the edge movements that we are able to evaluation skeletons. We may go so far as to describe the skeleton as a ``procedural geometric construct''. However the fact that we will use such a construct for ``procedural modeling'' would make such a description less than helpful.

By specifying different constraints over the speed of these edges, distinct classes of behaviour can be witnessed. Four varieties of the straight skeleton have been introduced -- the unweighted straight skeleton, the positively weighted skeleton, the negatively weighted straight skeleton, and the mixed weighted straight skeleton. These skeletons form a tree of generalisation as the requirements on the angle of the direction planes are relaxed; SS $\subseteq$ PWSS $\subseteq$ MWSS and NWSS $\subseteq$ MWSS. Of these different geometric constructs only the SS was well previously well described in the literature.

In the non-degenerate case of the of SS, PWSS and NWSS we have simplified existing algorithms by introducing a GIE that specifies a general behaviour given an arbitrary topology of collapsing edges. However each additional generalisation has also brought with it new degenerate cases which we have presented, and found resolution strategies for. These have included the parallel consecutive edge event, many edge degeneracy, point degeneracy and parallel adjcent edges.
However in the deepest, most unlikely, degenerate cases we were unable to suggest a general solution for the MWSS, managing only to formulate the pincushion description. Although we tried, we were unable to create either a proof that the pincushion problem was solvable or not.

The skeletons studied here also contain interesting properties, such as the SS splitting faces into two, the PWSS introducing holes into faces, and the MWSS allowing faces to merge together and split apart. We may also observe that many of the skeletons output resemble fragments of man made structures. The arcs between the faces of the output, the skeleton itself, serves as a polygonal partition of the polygon, influenced by a distance field. We take insipration from this fact in the following Chapter 4, where we use the arcs to partition city blocks into parcels. The offset 2D polygons generated in the shrinking process are reminsicent of man made arches or frames, while the 3D terrain model resembles building's roofs. In addition we find that it is possible to halt the evaluation of the MWSS at any point, creating a new form of extrusion between two plans. It is this observation that will lead us to the ideas in Chapter 5, using the MWSS for solid building modeling.

%We now define several features of the MWSS that help us. The major axis, approaching edges and the sector properties.

%The \emph{major axis} defines the direction that all chains of length one take. There may be more than one chain of length one in the MWSS, Fig.~\ref{fig:wss_example_topology}. However it is impossible for these chains to have more than one orientation in a single event as it occurs at a single point.

%\begin{figure}
%  \centering
%  \def\svgwidth{0.5\columnwidth}
%  \includesvg{12-skeleton/images/wss_major_axis}
%  \caption{\label{fig:wss_major_axis}At an event (orange) we may not have more than one orientation of chains of length one. %If this were the case (above), there would be a point (red) which the 1-chains (green and blue) arrived at before the event. There would, therefore, have been another (red) event which combines these edges before they arrive at the first event (orange).}
%\end{figure}


\subsection{Graphics.ChalkBoard.Shapes}

\subsubsection{Description}

\hspace{0.05\textwidth}\begin{minipage}{0.9\textwidth}This module contains some basic shape generators, expressed as {\tt Board Bool}.\end{minipage}

\subsubsection{Synopsis}

\begin{tabular}{p{0.95\linewidth}}{straightLine :: (Point, Point) -{\tt >} R -{\tt >} Board Bool}\\ % (61)

{pointsToLine :: [Point] -{\tt >} R -{\tt >} Board Bool}\\ % (54)

{dotAt :: Point -{\tt >} R -{\tt >} Board Bool}\\ % (45)

{functionLine :: (R -{\tt >} Point) -{\tt >} R -{\tt >} Int -{\tt >} Board Bool}\\ % (78)

\end{tabular}

\subsubsection{Documentation}

{{\bf straightLine} :: (Point, Point) -{\tt >} R -{\tt >} Board Bool}

\hspace{0.05\textwidth}\begin{minipage}{0.9\textwidth}A straight line, of a given width, between two points.\end{minipage}

{{\bf pointsToLine} :: [Point] -{\tt >} R -{\tt >} Board Bool}

{{\bf dotAt} :: Point -{\tt >} R -{\tt >} Board Bool}

\hspace{0.05\textwidth}\begin{minipage}{0.9\textwidth}place dot at this location, with given diameter.\end{minipage}

{{\bf functionLine} :: (R -{\tt >} Point) -{\tt >} R -{\tt >} Int -{\tt >} Board Bool}

\hspace{0.05\textwidth}\begin{minipage}{0.9\textwidth}A line generated by sampling a function from {\tt R} to {\tt Point}s, with a specific width. There needs to be at least 2 sample points.
\end{minipage}


\section{Cluster dissimilarity}

\subsection{Dissimilarity by gene expression}

The distances between the clusters was assessed using the ``BuildClusterTree'' function in the Seurat package, which ``constructs a phylogenetic tree relating the ``average'' cell from each identity class''.

\begin{figure}[H]
\includegraphics[width=1.0\textwidth,height=0.9\textheight,keepaspectratio]{{{\clusterDir/cluster.dendrogram}}}
\caption{Visualisation of inter-cluster distances (cluster average, gene-based)}
\end{figure}

\subsection{Dissimilarity by cell pair-wise correlation (in reduced dimensions)}

An alternative distance metric is the median pairwise pearson correlation between the cells of each cluster in reduced dimension space (e.g. PCA).

\begin{figure}[H]
\includegraphics[width=1.0\textwidth,height=0.9\textheight,keepaspectratio]{{{\clusterDir/cluster.correlation.dendrogram}}}
\caption{Visualisation of inter-cluster distances (median pairwise pearson correlation in reduced dimension space)}
\end{figure}

The median pairwise pearson correlations between the cells of each cluster (reduced dimension space) are shown in the table below.

\input{\clusterDir/cluster.pairwise.correlations.tex}

\clearpage


\documentclass[a4paper,12pt]{scrartcl}

\usepackage{bm,amsmath,url,graphicx}
\usepackage{palatino}
\usepackage{color, xcolor}
\usepackage{listings}

\newcommand{\n}{{\bf n}}
\newcommand{\h}{{\bf h}}
\newcommand{\x}{{\bf x}}
\newcommand{\HH}{{\bf H}}
\newcommand{\thb}{{\boldsymbol{\theta}}}
\newcommand{\python}{{\fbox{\texttt{\bfseries python}}\quad}}

\renewcommand{\familydefault}{\rmdefault}

\begin{document}
\section*{\bf SGN-41007 Pattern Recognition and Machine Learning}
\emph{Exercise Set 1: January 11 - 12, 2017}
\bigskip
\sloppy

\lstdefinestyle{mystyle}{
  belowcaptionskip=1\baselineskip,
  breaklines=true,
  frame=single,
  xleftmargin=\parindent,
  language=Python,
  showstringspaces=false,
  basicstyle=\ttfamily,
  keywordstyle=\bfseries\color{green!40!black},
  commentstyle=\itshape\color{purple!40!black},
  identifierstyle=\color{blue},
  stringstyle=\color{orange},
  moredelim=**[is][\color{red}]{@}{@},
}

\lstset{language=Python,style=mystyle}

\noindent
Exercises consist of both pen\&paper and computer assignments.
Pen\&paper questions are solved at home before exercises, while
computer assignments are solved during exercise hours. The
computer assignments are marked by text \python

\begin{enumerate}

\item \python \emph{Load CSV file into Python.}

Download the following file and extract the contents:
{\small
\begin{verbatim}
http://www.cs.tut.fi/courses/SGN-41007/exercises/locationData.zip
\end{verbatim}
}
\label{ex1}

\begin{enumerate}
	\item Read the file into numpy array using \verb|numpy.loadtxt| function.
Search for instructions using Google.
\item When loaded, check the array shape using \verb|numpy.shape|. It should be $600\times 3$.
\end{enumerate}

\item \python \emph{Plot the contents of the loaded matrix.}
\begin{enumerate}
\item Create a 2D plot of the first two columns of the matrix.
You need to import \verb+matplotlib.pyplot+ and state something like
\begin{verbatim}
plt.plot(<column 1>, <column 2>)
\end{verbatim}
\item Create a 3D plot of all 3 columns. You will need to create a special subplot
for this purpose with
\begin{verbatim}
ax = plt.subplot(1, 1, 1, projection = "3d")
\end{verbatim}
After this, the plotting is done as
\begin{verbatim}
plt.plot(<column 1>, <column 2>, <column 3>)
\end{verbatim}
\end{enumerate}

\item \python \emph{Basic image manipulation routines in Python.}
\begin{enumerate}
\item Download the following file to your local folder:
{\small
\begin{verbatim}
http://www.cs.tut.fi/courses/SGN-41007/exercises/oulu.jpg
\end{verbatim}
}
\item Load the image into numpy array using the \verb+imread+ function
of \verb+matplotlib.image+.
\footnote{Note: There are several other ways of doing this, such as:
\texttt{matplotlib.image.imread}, \texttt{scipy.ndimage.imread},\quad
\texttt{PIL.Image.open} \quad or \quad \texttt{cv2.imread}}

\item Show the image on screen (\verb|matplotlib.pyplot.imshow|).
\item Print the image shape.
\item Compute the mean of the whole image.
\item Compute the means of the three color channels (R, G, B).
\item Apply the white tophat operator to the image (\verb|scipy.ndimage.morphology.white_tophat|)
and show the result on screen.

\end{enumerate}

\item \python \emph{Load Matlab data into Python.}
\label{ex4}
\begin{enumerate}
\item Download the following file to your local folder:
{\small
\begin{verbatim}
http://www.cs.tut.fi/courses/SGN-41007/exercises/twoClassData.mat
\end{verbatim}
}
\item Load the file contents into Python. This can be done as follows.
\begin{lstlisting}
>>> from scipy.io import loadmat
>>> mat = loadmat("twoClassData.mat")
\end{lstlisting}
This generates a \lstinline|dict| structure, whose elements can be accessed through their names.
\begin{lstlisting}
>>> print(mat.keys()) # Which variables mat contains?
['y', 'X', '__version__', '__header__', '__globals__']
>>> X = mat["X"] # Collect the two variables.
>>> y = mat["y"].ravel()
\end{lstlisting}
The function \verb+ravel()+ transforms y from $400\times 1$ matrix into a 400-length array.
In Python these are different things unlike Matlab.

\item The matrix X contains two-dimensional samples from two
classes, as defined by y. Plot the data as a scatter plot
like the picture below.
Hints:
\begin{itemize}
	\item You can access all class 0 samples from X as: \verb+X[y == 0, :]+.
	\item The samples can be plotted like: \verb+plt.plot(X[:, 0], X[:, 1], 'ro')+
\end{itemize}
\centerline{\includegraphics[width=0.6\textwidth]{twoClasses.pdf}}

\end{enumerate}
\eject

\item \python \emph{Define a function.}
\begin{enumerate}
\item Implement a function that normalizes the data of question \ref{ex4} by
subtracting the mean and dividing by the standard deviation for each
column separately. The function call should be:
\begin{verbatim}
X_norm = normalize_data(X)
\end{verbatim}
\item Test your code with the following lines
\begin{verbatim}
X_norm = normalize_data(X)
np.mean(X_norm, axis = 0) # Should be 0
np.std(X_norm, axis = 0)  # Should be 1
\end{verbatim}

\end{enumerate}

\end{enumerate}

\end{document}


\documentclass{article}

\usepackage{graphicx}
\usepackage{amsmath}

\usepackage[margin=1in]{geometry}

\def\hwtitle{Computational Physics HW1}
\def\hwauthor{Ethan Rooney}
\def\hwdate{2020-01-29}

\usepackage{fancyhdr}
\lhead{\hwauthor}
\chead{\hwtitle}
\rhead{\hwdate}
\lfoot{\hwauthor}
\cfoot{}
\rfoot{\thepage}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}

\author{\hwauthor}
\title{\hwtitle}
\date{\hwdate}

\begin{document}

\maketitle
\thispagestyle{fancy}

\section{Introduction}

A harmonic occilator is defined by a system that experiances a restoritive force proportional to its displacement from it's rest location. This is known as Hook's Law and the mathematical form is seen in \( F_{x} \eq \minus kx \). \( F_x \) is the force on the object. \( k \) is an arbitrary constant determined by the physical properties of a system (i.e. for a spring k would be determined by the stiffness of the material).  \( x \) is the displacement of an object from its "rest" position.

This Homework deals with a special case where an object follows this law in X and Y independantly.
As such it is governed by the following  \ref{eq:2}. \( A \) is the maximum amplitude reached by the system in a particular direction. \( omega \eq \sqrt{k/m} \).
\( m \) is the mass of the object occelating. \( phi \) is the inital phase position of the system.

\begin{equation} \label{eq:2}
	x(t)\eq A_x\sin(\omega_xt+\phi_x)
	y(t)\eq A_y\sin(\omega_{y}t+\phi_{y})
\end{equation}

The first part of the homework deals with cases when \( \omega_x \) and \( \omega_y \) are equal.

For the Bonus Problems I will explore some of the possibilites when \( \omega_x \) and \( \omega_y \)
are varied independently.

\section{Results}

\bigskip
\noindent{\bf Question 1}
\medskip

Code submitted on Blackboard

\bigskip
\noindent{\bf Question 2}
\medskip

See attached \ref{plots}

\bigskip
\noindent{\bf Question 3}
\medskip

If \( \omega_x \eq \omega_y \) then the range of shapes possible are rather limited. The variation is from perfectly circular to a line. As \( \Delta\phi \) grows from \( 0 \) to \( \pi \) the shape transitions from a line, of \( y \eq A_x / A_yx \), through an eliptical shape to a circle, at \( \Delta\phi \eq \pi \), then back to a line, of \( y \eq -A_x / A_y \times x \).

\bigskip
\noindent{\bf Bonus 1}
\medskip

For small ratios of \( \omega_x \) and \( \omega_y \) a closed loop was formed and the pattern would repeat like the center plot in \ref{lissa}, so long as \( \Delta\phi \neq n\pi \) where \( \n \) is an integer. If \( n \) is an integer, then instead of "looping" the system will occilate back and forth along a single path like scene in the first plot in \ref{lissa}.

\bigskip
\noindent{\bf Bonus 2}
\medskip

If the ratios of \( \omega_x \) and \( \omega_{y} \) are irrational numbers i.e. \( \sqrt{5} \) like seen in the right most plot of \ref{lissa}, then the system cannot repeat. This leads to what appears to be random dots. But if you look carefully you can see a structure to the dot. The system can almost, but not quite loop bak over itself and leave a series of nearly parallel paths.

\section{Conclusions}

Main challenges faced in this coding project were discovering the "-lm" flag for gcc. It also served a good refresher on how to work with c.
Furthermore, I had never worked with Mathematica before, discovering some of its' features for the first time was fun.

\section{Plots} \label{plots}
\begin{figure}[b]
\begin{center}
\includegraphics[width=0.25\textwidth]{plot1.pdf}
\includegraphics[width=0.25\textwidth]{plot2.pdf}
\includegraphics[width=0.25\textwidth]{plot3.pdf}
\includegraphics[width=0.25\textwidth]{plot4.pdf}
\end{center}
\caption{These plots above show the types of shapes possible to make using this system of harmonic occilaters.}
\end{figure}

\begin{figure}[b]
\begin{center}
\includegraphics[width=0.25\textwidth]{plot5.pdf}
\includegraphics[width=0.25\textwidth]{plot6.pdf}
\includegraphics[width=0.25\textwidth]{plot7.pdf}
\includegraphics[width=0.25\textwidth]{plot8.pdf}
\end{center}
\caption{These plots are nearly identical to the plots above, with the exception that in the amplitude in the y direction is twice what it would be in the corrisponding picture above.}
\end{figure}

\begin{figure}[b]
\begin{center}
\includegraphics[width=0.33\textwidth]{plot9.pdf}
\includegraphics[width=0.33\textwidth]{plot10.pdf}
\includegraphics[width=0.33\textwidth]{plot11.pdf}
\end{center}
\caption{Seen above are some of the patterns formed by Lassajous figures}
\label{lissa}
\end{figure}

\end{document}


\graphicspath{ {./img/intro/} }

\chapter{Introduction}

In an introductory graduate course in the Finite Element Method (FEM), the purpose is to develop a basic understanding of the discrete or numerical strategy of Finite Element-(FE) Algorithms when a closed form solution to a Boundary Value Problem (BVP) is not possible due to complexities existing probably: in the boundary conditions, material behavior or in the kinematic description used in the model. In such a course, in order to master and identify the main mathematical and algorithmic aspects of the method at the beginners level, the studied problem is kept lineal. In this sense 4 key aspects make the core of the introductory course (at least for the case of the linearized theory of elasticity boundary value problem):

\begin{itemize}

\item Formulation and identification of the strong form of the Boundary Value Problem (BVP) where the continuum mechanics governing equations are revisited and particularized to the case of linear elastic material behavior. The BVP is completed by identifying the correct prescription of boundary conditions for a well posed mathematical problem.

\item Formulation and identification of the weak form of the BVP where the governing equations and natural boundary conditions representing equilibrium at the material point level are replaced by an equivalent but weaker form of equilibrium now valid at the global level.  In the case of a Continuum Mechanics problem this so-called weak form can be shown to be equivalent to the principle of virtual power and lends itself for the partition of the problem into sub-domains or finite size elements.

\item Introduction of the idea of discretization dividing the problem into subdomains and using interpolation theory within each subdomain-In the context of the FE method this is the subject of shape functions. Once the computational specimen has been divided into subdomains (or a mesh of finite elements) the selected primary variable is approximated within each element via interpolation of the known response at selected predefined points or nodes.

\item Computational aspects grouped also into 5 points:
	\begin{itemize}
	\item Formulation of elemental matrices in the physical space.
	\item Formulation of elemental matrices in the natural domain-Isoparametric transformation.
	\item Numerical integration: Gauss quadrature.
	\item Assembly of system matrices and imposition of boundary conditions.
	\item Solution of the discrete equilibrium statement and calculation of elemental results.
	\end{itemize}
\end{itemize}

These 4 key points are perfectly well documented in numerous nicely written textbooks and it could be argued that is not even worth to register for an introductory course since a moderately dedicated student can accomplish the task via self-study. Unfortunately, linearity is scarce--although useful to grasp the basic understanding of the problem--and the real world is full of non-linear behavior and understanding the needed algorithms can be easily justified. In this Introduction to the Finite Element Method course the goal is then to understand the basic aspects of non-linear finite element analysis.  Like in the linear case there is also a vast amount of literature for the non-linear problem.  However, in the non-linear case the kinematic problem itself may take different routes leading to a wide variety of FEM formulations that will difficult a self-study strategy.  Considering the above this brief set of class notes is intended as a guide for self-study and more important represents a help towards the implementation of the algorithm for the consideration of Material and Geometric Non-linearities in Solids.

The basic reference is Professor Bathe's textbook \cite{book:bathe} but we will also follow closely Abaqus Theory Manual \cite{abaqus_theory}. Abaqus is a multi-physics oriented commercially available finite element analysis tool. Its strength resides in the effective non-linear algorithms and on the capability of taking user subroutines written in Fortran or in \CPP.  The possibility of implementing user subroutines makes it a very powerful research tool.  In the particular case of a stress/displacement analysis problem with non-linearities these are considered through the kinematics contribution or through the material contribution.  In the first case the non-linear behavior must be considered at the element level while in the second it corresponds to the response of a material point which in the context of the FEM algorithm corresponds to an integration point. In Abaqus those two sources of non-linearity can be independently controlled by the user via user subroutines UEL and UMAT.  In both cases the non-linearity is primarily solved by the classical Newton-Raphson scheme and that will be the approached followed herein.  Although the notes are mainly written for an advanced course the specific problem of a linear solid usually studied in the introductory course can be derived like a particular case of the most general non-linear algorithm.

The current set of Class Notes is organized as follows.  First and since we will be dealing with history dependent non-linear problems the most powerful (at least when it works) solution algorithm, namely the Newton-Raphson iteration is studied.  The technique is first illustrated for the simple 1D-case and then generalized into the multi-degree of freedom system.  In both cases pseudo-codes will be presented preparing the way for the Finite Element Algorithm.  The presentation however is not exhaustive in mathematical terms and the reader is referred to excellent treatments like Burden \cite{book:burden2011} and Press et al. \cite{book:numerical_recipes} for the mathematical aspects of the Newton method.

In the next section the briefly introduced Newton-Raphson technique is contextualized to the case of a system of equations representing equilibrium between internal and external forces as typically found in a finite element model.  Moreover, the non-linearities come into play through a dependence of the internal forces into displacements.  At this stage the details of the formulation of the finite element equations via discretization into nodal variables is not presented but emphasis is laid down into the solution algorithm.  Interest is then given to the particular form taken by the Newton-Raphson algorithm into the commercial finite element code Abaqus.  That code can be used as a powerful non-linear equation solver where the coefficient matrix and the excitation can be directly controlled by the user.  Moreover the solver can be used into a multi-physics context in terms of generalized forces and fluxes.  In the particular case of the stress analysis finite element method the user can control the elemental contribution to the coefficient matrix and the contribution of each material point to obtain that element contribution.  This is achieved through the so-called user subroutines UEL  for element and UMAT  for material.  Having introduced the Newton-Raphson method the notes concentrate next on general discretization aspects starting from the physical strong form of the equations in the deformed configuration and passing to an arbitrary weak form in the reference configuration.  The resulting algorithm is therefore a Total Lagrangian (TL) method.  Once the general equations are introduced a particular work conjugate stress-strain pair is chosen and the discrete equations, including kinematic interpolators, are described.

\section*{Notation}
In a non-linear algorithm the bookkeeping is involved since we have to simultaneously record 4 different fields as follows:
\begin{itemize}
	\item The physical fields in terms of tensor descriptions.
	\item The time field since the problem is solved incrementally 	and time may appear as an artificial chronological variable 	or as a real quantity in a dynamic problem.
	\item The interpolation field.  Since all the involved variables will be interpolated we will need to keep track of the way this interpolation is being performed.
	\item The iterations field needed in the solution of the non-linear problem.
\end{itemize}
In order to keep this bookkeeping simple we use the following index notation with subscripts and superscripts
\begin{figure}[h]
\centering
\includegraphics[width=4cm]{index_notation.pdf}
\caption{General notation to study non-linear finite element problems}
\label{fig:notation}
\end{figure}

\todo{Review notation.}Capital superscripts will be reserved for the incremental time description and for the interpolation scheme.  For instance an expression like   refers to the time instant   while   refers to . Similarly a variable   refers to interpolation over the node. Left and right subscripts will be used to make reference to the iteration being performed and the order of the tensor variable.  For instance   refers to a second order tensor corresponding to the iteration.


% !TeX root = main.tex
\section{回归结果} \label{sec:results}
\subsection{北京市回归结果}
\begin{table}[H]
  \centering
  \begin{tabular}{lclc}
    \toprule
    \textbf{Dep. Variable:}    & price            & \textbf{  R-squared:         } & 0.732     \\
    \textbf{Model:}            & OLS              & \textbf{  Adj. R-squared:    } & 0.731     \\
    \textbf{Method:}           & Least Squares    & \textbf{  F-statistic:       } & 863.3     \\
    \textbf{Date:}             & Sun, 16 Jan 2022 & \textbf{  Prob (F-statistic):} & 0.00      \\
    \textbf{Time:}             & 23:05:17         & \textbf{  Log-Likelihood:    } & -80268.   \\
    \textbf{No. Observations:} & 7284             & \textbf{  AIC:               } & 1.606e+05 \\
    \textbf{Df Residuals:}     & 7260             & \textbf{  BIC:               } & 1.607e+05 \\
    \textbf{Df Model:}         & 23               & \textbf{                     } &           \\
    \textbf{Covariance Type:}  & nonrobust        & \textbf{                     } &           \\
    \bottomrule
  \end{tabular}
\end{table}

\begin{longtable}{lcccccc}
  \caption{Beijing OLS Regression Results}
  \label{tab:beijing_result}                                                                                \\
  \toprule
                     & \textbf{coef}         & \textbf{std err}    & \textbf{t}        & \textbf{P$> |$t$|$} & \textbf{[0.025}      & \textbf{0.975]}      \\
  \midrule
  \endfirsthead
  \caption[]{Beijing OLS Regression Results (续)}                                                                                \\
  \toprule
                     & \textbf{coef}         & \textbf{std err}    & \textbf{t}        & \textbf{P$> |$t$|$} & \textbf{[0.025}      & \textbf{0.975]}      \\
  \midrule
  \endhead
  \textbf{Intercept} & \tablenum{1.815e+04}  & \tablenum{1144.337} & \tablenum{15.862} & \tablenum{0.000}    & \tablenum{1.59e+04}  & \tablenum{2.04e+04}  \\
  \textbf{0}         & \tablenum{-318.2477}  & \tablenum{180.670}  & \tablenum{-1.761} & \tablenum{0.078}    & \tablenum{-672.413}  & \tablenum{35.918}    \\
  \textbf{1}         & \tablenum{2235.4543}  & \tablenum{229.650}  & \tablenum{9.734}  & \tablenum{0.000}    & \tablenum{1785.273}  & \tablenum{2685.636}  \\
  \textbf{2}         & \tablenum{-1534.4204} & \tablenum{236.678}  & \tablenum{-6.483} & \tablenum{0.000}    & \tablenum{-1998.378} & \tablenum{-1070.463} \\
  \textbf{3}         & \tablenum{23.2936}    & \tablenum{73.607}   & \tablenum{0.316}  & \tablenum{0.752}    & \tablenum{-120.997}  & \tablenum{167.584}   \\
  \textbf{4}         & \tablenum{-644.9779}  & \tablenum{125.628}  & \tablenum{-5.134} & \tablenum{0.000}    & \tablenum{-891.244}  & \tablenum{-398.711}  \\
  \textbf{5}         & \tablenum{82.6199}    & \tablenum{172.075}  & \tablenum{0.480}  & \tablenum{0.631}    & \tablenum{-254.698}  & \tablenum{419.938}   \\
  \textbf{6}         & \tablenum{-614.9914}  & \tablenum{160.017}  & \tablenum{-3.843} & \tablenum{0.000}    & \tablenum{-928.671}  & \tablenum{-301.312}  \\
  \textbf{7}         & \tablenum{-487.5924}  & \tablenum{158.244}  & \tablenum{-3.081} & \tablenum{0.002}    & \tablenum{-797.797}  & \tablenum{-177.388}  \\
  \textbf{8}         & \tablenum{-142.9470}  & \tablenum{161.561}  & \tablenum{-0.885} & \tablenum{0.376}    & \tablenum{-459.654}  & \tablenum{173.760}   \\
  \textbf{9}         & \tablenum{312.4724}   & \tablenum{116.548}  & \tablenum{2.681}  & \tablenum{0.007}    & \tablenum{84.003}    & \tablenum{540.941}   \\
  \textbf{10}        & \tablenum{1270.1086}  & \tablenum{116.237}  & \tablenum{10.927} & \tablenum{0.000}    & \tablenum{1042.251}  & \tablenum{1497.967}  \\
  \textbf{11}        & \tablenum{-26.1004}   & \tablenum{103.495}  & \tablenum{-0.252} & \tablenum{0.801}    & \tablenum{-228.980}  & \tablenum{176.779}   \\
  \textbf{12}        & \tablenum{763.8384}   & \tablenum{98.091}   & \tablenum{7.787}  & \tablenum{0.000}    & \tablenum{571.551}   & \tablenum{956.126}   \\
  \textbf{13}        & \tablenum{563.2973}   & \tablenum{99.021}   & \tablenum{5.689}  & \tablenum{0.000}    & \tablenum{369.187}   & \tablenum{757.408}   \\
  \textbf{14}        & \tablenum{-583.0906}  & \tablenum{113.205}  & \tablenum{-5.151} & \tablenum{0.000}    & \tablenum{-805.006}  & \tablenum{-361.175}  \\
  \textbf{15}        & \tablenum{605.8885}   & \tablenum{121.843}  & \tablenum{4.973}  & \tablenum{0.000}    & \tablenum{367.040}   & \tablenum{844.737}   \\
  \textbf{16}        & \tablenum{279.9137}   & \tablenum{95.020}   & \tablenum{2.946}  & \tablenum{0.003}    & \tablenum{93.647}    & \tablenum{466.181}   \\
  \textbf{17}        & \tablenum{-697.0469}  & \tablenum{132.489}  & \tablenum{-5.261} & \tablenum{0.000}    & \tablenum{-956.763}  & \tablenum{-437.330}  \\
  \textbf{18}        & \tablenum{103.6793}   & \tablenum{149.566}  & \tablenum{0.693}  & \tablenum{0.488}    & \tablenum{-189.514}  & \tablenum{396.872}   \\
  \textbf{19}        & \tablenum{-499.3558}  & \tablenum{139.606}  & \tablenum{-3.577} & \tablenum{0.000}    & \tablenum{-773.024}  & \tablenum{-225.688}  \\
  \textbf{20}        & \tablenum{3109.6958}  & \tablenum{489.380}  & \tablenum{6.354}  & \tablenum{0.000}    & \tablenum{2150.368}  & \tablenum{4069.024}  \\
  \textbf{21}        & \tablenum{-55.7886}   & \tablenum{19.411}   & \tablenum{-2.874} & \tablenum{0.004}    & \tablenum{-93.841}   & \tablenum{-17.737}   \\
  \textbf{22}        & \tablenum{-114.4076}  & \tablenum{120.922}  & \tablenum{-0.946} & \tablenum{0.344}    & \tablenum{-351.449}  & \tablenum{122.634}   \\
  \bottomrule
\end{longtable}
\begin{table}[H]
  \centering
  \begin{tabular}{lclc}
    \toprule
    \textbf{Omnibus:}       & 2542.377 & \textbf{  Durbin-Watson:     } & 1.210     \\
    \textbf{Prob(Omnibus):} & 0.000    & \textbf{  Jarque-Bera (JB):  } & 31068.689 \\
    \textbf{Skew:}          & 1.319    & \textbf{  Prob(JB):          } & 0.00      \\
    \textbf{Kurtosis:}      & 12.768   & \textbf{  Cond. No.          } & 2.02e+03  \\
    \bottomrule
  \end{tabular}
\end{table}

Notes: \newline
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified. \newline
[2] The condition number is large, 2.02e+03. This might indicate that there are \newline
strong multicollinearity or other numerical problems.

\subsection{上海市回归结果}
\begin{table}[H]
  \centering
  \begin{tabular}{lclc}
    \toprule
    \textbf{Dep. Variable:}    & price            & \textbf{  R-squared:         } & 0.669       \\
    \textbf{Model:}            & OLS              & \textbf{  Adj. R-squared:    } & 0.669       \\
    \textbf{Method:}           & Least Squares    & \textbf{  F-statistic:       } & 1026.       \\
    \textbf{Date:}             & Sun, 16 Jan 2022 & \textbf{  Prob (F-statistic):} & 0.00        \\
    \textbf{Time:}             & 23:12:51         & \textbf{  Log-Likelihood:    } & -1.2861e+05 \\
    \textbf{No. Observations:} & 11681            & \textbf{  AIC:               } & 2.573e+05   \\
    \textbf{Df Residuals:}     & 11657            & \textbf{  BIC:               } & 2.574e+05   \\
    \textbf{Df Model:}         & 23               & \textbf{                     } &             \\
    \textbf{Covariance Type:}  & nonrobust        & \textbf{                     } &             \\
    \bottomrule
  \end{tabular}
\end{table}
\begin{longtable}{lcccccc}
  \caption{Shanghai OLS Regression Results}
  \label{tab:shanghai_result}                                                                                \\
  \toprule
                     & \textbf{coef}        & \textbf{std err}    & \textbf{t}        & \textbf{P$> |$t$|$} & \textbf{[0.025}      & \textbf{0.975]}     \\
  \midrule
  \endfirsthead
  \caption[]{Shanghai OLS Regression Results (续)}                                                                                \\
  \toprule
                     & \textbf{coef}        & \textbf{std err}    & \textbf{t}        & \textbf{P$> |$t$|$} & \textbf{[0.025}      & \textbf{0.975]}     \\
  \midrule
  \endhead
  \textbf{Intercept} & \tablenum{1.213e+04} & \tablenum{1104.216} & \tablenum{10.982} & \tablenum{0.000}    & \tablenum{9962.140}  & \tablenum{1.43e+04} \\
  \textbf{0}         & \tablenum{208.1793}  & \tablenum{137.317}  & \tablenum{1.516}  & \tablenum{0.130}    & \tablenum{-60.984}   & \tablenum{477.343}  \\
  \textbf{1}         & \tablenum{-620.6409} & \tablenum{160.637}  & \tablenum{-3.864} & \tablenum{0.000}    & \tablenum{-935.517}  & \tablenum{-305.765} \\
  \textbf{2}         & \tablenum{1154.0144} & \tablenum{166.506}  & \tablenum{6.931}  & \tablenum{0.000}    & \tablenum{827.634}   & \tablenum{1480.395} \\
  \textbf{3}         & \tablenum{-328.8537} & \tablenum{110.295}  & \tablenum{-2.982} & \tablenum{0.003}    & \tablenum{-545.050}  & \tablenum{-112.657} \\
  \textbf{4}         & \tablenum{377.6965}  & \tablenum{116.365}  & \tablenum{3.246}  & \tablenum{0.001}    & \tablenum{149.601}   & \tablenum{605.792}  \\
  \textbf{5}         & \tablenum{-489.5849} & \tablenum{118.257}  & \tablenum{-4.140} & \tablenum{0.000}    & \tablenum{-721.388}  & \tablenum{-257.782} \\
  \textbf{6}         & \tablenum{-941.0288} & \tablenum{143.450}  & \tablenum{-6.560} & \tablenum{0.000}    & \tablenum{-1222.215} & \tablenum{-659.843} \\
  \textbf{7}         & \tablenum{769.1201}  & \tablenum{129.818}  & \tablenum{5.925}  & \tablenum{0.000}    & \tablenum{514.655}   & \tablenum{1023.585} \\
  \textbf{8}         & \tablenum{-711.9080} & \tablenum{92.832}   & \tablenum{-7.669} & \tablenum{0.000}    & \tablenum{-893.875}  & \tablenum{-529.941} \\
  \textbf{9}         & \tablenum{560.3915}  & \tablenum{129.874}  & \tablenum{4.315}  & \tablenum{0.000}    & \tablenum{305.818}   & \tablenum{814.965}  \\
  \textbf{10}        & \tablenum{869.9834}  & \tablenum{127.214}  & \tablenum{6.839}  & \tablenum{0.000}    & \tablenum{620.622}   & \tablenum{1119.344} \\
  \textbf{11}        & \tablenum{645.5831}  & \tablenum{92.588}   & \tablenum{6.973}  & \tablenum{0.000}    & \tablenum{464.095}   & \tablenum{827.071}  \\
  \textbf{12}        & \tablenum{-95.8444}  & \tablenum{136.095}  & \tablenum{-0.704} & \tablenum{0.481}    & \tablenum{-362.613}  & \tablenum{170.924}  \\
  \textbf{13}        & \tablenum{301.4136}  & \tablenum{98.198}   & \tablenum{3.069}  & \tablenum{0.002}    & \tablenum{108.929}   & \tablenum{493.899}  \\
  \textbf{14}        & \tablenum{-253.1105} & \tablenum{69.496}   & \tablenum{-3.642} & \tablenum{0.000}    & \tablenum{-389.335}  & \tablenum{-116.886} \\
  \textbf{15}        & \tablenum{-183.6645} & \tablenum{99.961}   & \tablenum{-1.837} & \tablenum{0.066}    & \tablenum{-379.604}  & \tablenum{12.275}   \\
  \textbf{16}        & \tablenum{-215.7938} & \tablenum{82.412}   & \tablenum{-2.618} & \tablenum{0.009}    & \tablenum{-377.335}  & \tablenum{-54.253}  \\
  \textbf{17}        & \tablenum{400.7241}  & \tablenum{124.958}  & \tablenum{3.207}  & \tablenum{0.001}    & \tablenum{155.785}   & \tablenum{645.663}  \\
  \textbf{18}        & \tablenum{-262.7602} & \tablenum{30.338}   & \tablenum{-8.661} & \tablenum{0.000}    & \tablenum{-322.228}  & \tablenum{-203.292} \\
  \textbf{19}        & \tablenum{-448.9212} & \tablenum{75.897}   & \tablenum{-5.915} & \tablenum{0.000}    & \tablenum{-597.692}  & \tablenum{-300.150} \\
  \textbf{20}        & \tablenum{4231.6910} & \tablenum{3216.305} & \tablenum{1.316}  & \tablenum{0.188}    & \tablenum{-2072.805} & \tablenum{1.05e+04} \\
  \textbf{21}        & \tablenum{-15.9718}  & \tablenum{12.171}   & \tablenum{-1.312} & \tablenum{0.189}    & \tablenum{-39.830}   & \tablenum{7.886}    \\
  \textbf{22}        & \tablenum{308.3106}  & \tablenum{138.158}  & \tablenum{2.232}  & \tablenum{0.026}    & \tablenum{37.498}    & \tablenum{579.123}  \\
  \bottomrule
\end{longtable}
\begin{table}[H]
  \centering
  \begin{tabular}{lclc}
    \toprule
    \textbf{Omnibus:}       & 5219.570 & \textbf{  Durbin-Watson:     } & 1.042      \\
    \textbf{Prob(Omnibus):} & 0.000    & \textbf{  Jarque-Bera (JB):  } & 144950.970 \\
    \textbf{Skew:}          & 1.561    & \textbf{  Prob(JB):          } & 0.00       \\
    \textbf{Kurtosis:}      & 19.973   & \textbf{  Cond. No.          } & 8.12e+03   \\
    \bottomrule
  \end{tabular}
\end{table}

Notes: \newline
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified. \newline
[2] The condition number is large, 8.12e+03. This might indicate that there are \newline
strong multicollinearity or other numerical problems.


\documentclass{article}

\usepackage[margin=0.5in]{geometry}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\usepackage{cleveref}

\title{CE EN 507: Coding Assignment 2}
\author{ Jared J.~Thomas}

\begin{document}
\maketitle

\section{Part 1}
Please see attached file, fem.py, for my nD FEM code.

\section{Part 2}
\subsection{}
The parameters chosen for this problem are shown in \cref{tab:parameters}. For Part 2, $A_S$ was used for $A$.

\begin{table}
	\centering
	\begin{tabular}{| r | r |}
		\hline
		$L$ & 1.0 \\
		$N$ & 10.0 \\
		$E$ & 200E9 \\
		$A_{S}$ & 2.5E-5\\
		$A_{L}$ & 100 \\
		$I_1$ & 5.21e-11\\
		$I_2$ & 5.21e-11\\
		$J$ & 1.04e-10\\
		$\nu$ & 0.3 \\
		$G$ & 76.9E9 \\
		\hline
	\end{tabular}
	\caption{Parameters and other relevant values}
	\label{tab:parameters}
\end{table}

\subsection{}
The maximum displacement at the right end of the beam using an analytic approach was 9.99999333611E-7.

\subsection{}
Please refer to \cref{fig:part2} for a plot of computed displacements for Part 2.

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.75\textwidth]{beam1_deflection_prob2_dof2}
	\caption{Deflection plot for Part 2}
	\label{fig:part2}
\end{figure}

\subsection{}
The maximum displacement at the right end of the beam using my FEM code was 1E-6, which is essentially equal to the analytic solution (9.99999333611E-7).

\section{Part 3}

\subsection{}
Refer to \cref{tab:parameters} for parameter and other values used in this section.

\subsection{}
Please see \cref{fig:31,fig:32} for plots of $u^h(x)$ and $\theta^h(x)$ versus the exact solution $u(x)$ and $\theta(x)$.

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.75\textwidth]{beam1_deflection_prob3_dof0}
	\caption{$u^h(x)$ versus $u(x)$ for Part 3}
	\label{fig:31}
\end{figure}

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.75\textwidth]{beam1_deflection_prob3_dof4}
	\caption{$\theta^h(x)$ and $\theta(x)$ for Part 3. For p=1 and N=10, the FEM deflection is essentially zero}
	\label{fig:32}
\end{figure}

\subsection{}
For this part, $A_S$ was used for the thin beam, and $A_L$ was used for the thick beam. (See \cref{tab:parameters}. Results for the thin beam were as follows: $u^h_{max} = 0.118403120283$, $u_{max} = 0.1232000064$, $\theta^h_{max} =  0.15999984117 $, and $\theta_{max} = 0.16000128$. Results for the thick beam were as follows: $u^h_{max} = $7.87322000026E-13, $u_{max} = $7.7000004E-15, $\theta^h_{max} = $9.99999E-15, and $\theta_{max} = $1.000008E-14. It can be easily seen that the results for the thick beam for FEM and the analytic solution differed by an order of magnitude. This discrepency is due to the thin beam assumptions made to solve the problem as a beam problem.

\section{Part 4}

\subsection{}
Refer to \cref{tab:parameters} for parameter and other values used in this section.

\subsection{}
Please see \cref{fig:41,fig:42} for plots of $u^h(x)$ and $\theta^h(x)$ versus the exact solution $u(x)$ and $\theta(x)$.

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.75\textwidth]{beam1_deflection_prob4_dof0}
	\caption{$u^h(x)$ versus $u(x)$ for Part 4}
	\label{fig:41}
\end{figure}

\begin{figure}[ht]
	\centering
	\includegraphics[width=0.75\textwidth]{beam1_deflection_prob4_dof4}
	\caption{$\theta^h(x)$ and $\theta(x)$ for Part 4}
	\label{fig:42}
\end{figure}

\end{document}


\subsubsection{Spline form}
\label{sec:onebodyjastrowspline}

The one-body spline Jastrow function is the most commonly used one-body Jastrow for solids. This form
was first described and used in \cite{EslerKimCeperleyShulenburger2012}.
Here $u_{ab}$ is an interpolating 1D Bspline (tricublc spline on a linear grid) between zero distance and $r_{cut}$. In 3D periodic systems
the default cutoff distance is the Wigner Seitz cell radius. For other periodicities including isolated
molecules the $r_{cut}$ must be specified. The cusp can be set.   $r_i$
and $R_I$ are most commonly the electron and ion positions, but any particlesets that can provide the
needed centers can be used.

\paragraph{Input Specification}
\begin{table}[h]
\begin{center}
\begin{tabular}{l c c c l }
\hline
\multicolumn{5}{l}{Correlation element} \\
\hline
\bfseries name & \bfseries datatype & \bfseries values & \bfseries defaults & \bfseries description \\
\hline
elementType & text & name & see below & Classical particle target  \\
speciesA & text & name & see below & Classical particle target \\
speciesB & text & name & see below & Quantum species target \\
size & integer & $> 0$ & (required) & Number of coefficients \\
rcut & real & $> 0$ & see below & Distance at which the correlation goes to 0 \\
cusp & real & $\ge 0$ & 0 & Value for use in Kato cusp condition \\
spin & text & yes or no & no & Spin dependent jastrow factor \\
\hline
\multicolumn{5}{l}{elements}\\ \hline
& Coefficients & & & \\ \hline
\multicolumn{5}{l}{Contents}\\ \hline
& (None)  & & &  \\ \hline
\end{tabular}
%\end{tabular*}
\end{center}
\end{table}

Additional information:

 \begin{itemize}
 \item \texttt{elementType, speciesA, speciesB, spin}.  For a spin independent Jastrow factor (spin = ``no'')
elementType should be the name of the group of ions in the classical particleset to which the quantum
particles should be correlated.  For a spin dependent Jastrow factor (spin = ``yes'') set speciesA to the
group name in the classical particleset and speciesB to the group name in the quantum particleset.
 \item \texttt{rcut}. The cutoff distance for the function in atomic units (bohr).
For 3D fully periodic systems this parameter is optional and a default of the Wigner
Seitz cell radius is used. Otherwise this parameter is required.
 \item \texttt{cusp}. The one body jastrow factor can be used to make the wavefunction
satisfy the electron-ion cusp condition\cite{kato}.  In this case, the derivative of the jastrow
factor as the electron approaches the nucleus will be given by:
\begin{equation}
\left(\frac{\partial J}{\partial r_{iI}}\right)_{r_{iI} = 0} = -Z
\end{equation}
Note that if the antisymmetric part of the wavefunction satisfies the electron-ion cusp
condition (for instance by using single particle orbitals that respect the cusp condition)
or if a non-divergent pseudopotential is used that the Jastrow should be cuspless at the
nucleus and this value should be kept at its default of 0.
 \end{itemize}

\begin{table}[h]
\begin{center}
\begin{tabular}{l c c c l }
\hline
\multicolumn{5}{l}{Coefficients element} \\
\hline
\bfseries name & \bfseries datatype & \bfseries values & \bfseries defaults & \bfseries description \\
\hline
id & text & & (required) & Unique identifier \\
type & text & Array & (required) & \\
optimize & text & yes or no & yes & if no, values are fixed in optimizations \\
\hline
\multicolumn{5}{l}{elements}\\ \hline
(None) & & & \\ \hline
\multicolumn{5}{l}{Contents}\\ \hline
 (no name) & real array & & zeros & Jastrow coefficients \\ \hline
\end{tabular}
%\end{tabular*}
\end{center}
\end{table}

\paragraph{Example use cases}
\label{sec:1bjsplineexamples}

Specify a spin-independent function with four parameters. Because rcut  is not
specified, the default cutoff of the Wigner Seitz cell radius is used; this
Jastrow must be used with a 3D periodic system such as a bulk solid. The name of
the particleset holding the ionic positions is "i".
\begin{lstlisting}[language=xml]
<jastrow name="J1" type="One-Body" function="Bspline" print="yes" source="i">
 <correlation elementType="C" cusp="0.0" size="4">
   <coefficients id="C" type="Array"> 0  0  0  0  </coefficients>
 </correlation>
</jastrow>
\end{lstlisting}

Specify a spin-dependent function with seven upspin and seven downspin parameters.
The cutoff distance is set to 6 atomic units.  Note here that the particleset holding
the ions is labeled as ion0 rather than ``i'' in the other example.  Also in this case
the ion is Lithium with a coulomb potential, so the cusp condition is satisfied by
setting cusp="d".
\begin{lstlisting}[language=xml]
<jastrow name="J1" type="One-Body" function="Bspline" source="ion0" spin="yes">
  <correlation speciesA="Li" speciesB="u" size="7" rcut="6">
    <coefficients id="eLiu" cusp="3.0" type="Array">
    0.0 0.0 0.0 0.0 0.0 0.0 0.0
    </coefficients>
  </correlation>
  <correlation speciesA="C" speciesB="d" size="7" rcut="6">
    <coefficients id="eLid" cusp="3.0" type="Array">
    0.0 0.0 0.0 0.0 0.0 0.0 0.0
    </coefficients>
  </correlation>
</jastrow>
\end{lstlisting}


\section{Non-malleability of \plonk{}, omitted protocol descriptions}
\label{sec:plonk_supp_mat}

\newcommand{\vql}{\vec{q_{L}}}
\newcommand{\vqr}{\vec{q_{R}}}
\newcommand{\vqm}{\vec{q_{M}}}
\newcommand{\vqo}{\vec{q_{O}}}
\newcommand{\vx}{\vec{x}}
\newcommand{\vqc}{\vec{q_{C}}}
\subsection{Plonk protocol description}
\label{sec:plonk_explained}
\oursubsub{The constrain system}
Assume $\CRKT$ is a fan-in two arithmetic circuit,
which fan-out is unlimited and has $\numberofconstrains$ gates and $\noofw$ wires
($\numberofconstrains \leq \noofw \leq 2\numberofconstrains$). \plonk's constraint
system is defined as follows:
\begin{itemize}
\item Let $\vec{V} = (\va, \vb, \vc)$, where $\va, \vb, \vc
  \in \range{1}{\noofw}^\numberofconstrains$. Entries $\va_i, \vb_i, \vc_i$ represent indices of left,
  right and output wires of circuits $i$-th gate.
\item Vectors $\vec{Q} = (\vql, \vqr, \vqo, \vqm, \vqc) \in
  (\FF^\numberofconstrains)^5$ are called \emph{selector vectors}:
  \begin{itemize}
  \item If the $i$-th gate is a multiplicative gate then $\vql_i = \vqr_i = 0$,
    $\vqm_i = 1$, and $\vqo_i = -1$.
  \item If the $i$-th gate is an addition gate then $\vql_i = \vqr_i  = 1$, $\vqm_i =
    0$, and $\vqo_i = -1$.
  \item $\vqc_i = 0$ always.
  \end{itemize}
\end{itemize}

We say that vector $\vx \in \FF^\noofw$ satisfies constraint system if for all $i
\in \range{1}{\numberofconstrains}$
\[
  \vql_i \cdot \vx_{\va_i} + \vqr_i \cdot \vx_{\vb_i} + \vqo \cdot \vx_{\vc_i} +
  \vqm_i \cdot (\vx_{\va_i} \vx_{\vb_i}) + \vqc_i = 0.
\]

\oursubsub{Algorithms rolled out}
\label{sec:plonk_explained}
\plonk{} argument system is universal. That is, it allows to verify computation
of any arithmetic circuit which has no more than $\numberofconstrains$
gates using a single SRS. However, to make computation efficient, for each
circuit there is allowed a preprocessing phase which extend the SRS with
circuit-related polynomial evaluations.

For the sake of simplicity of the security reductions presented in this paper, we
include in the SRS only these elements that cannot be computed without knowing
the secret trapdoor $\chi$. The rest of the SRS---the preprocessed input---can
be computed using these SRS elements thus we leave them to be computed by the
prover, verifier, and simulator.

\ourpar{$\plonk$ SRS generating algorithm $\kgen(\REL)$:}
The SRS generating algorithm picks at random $\chi \sample \FF_p$, computes
and outputs
\[
	\srs = \left(\gone{\smallset{\chi^i}_{i = 0}^{\numberofconstrains + 2}},
	\gtwo{\chi} \right).
\]

\ourpar{Preprocessing:}
Let $H = \smallset{\omega^i}_{i = 1}^{\numberofconstrains }$ be a
(multiplicative) $\numberofconstrains$-element subgroup of a field $\FF$
compound of $\numberofconstrains$-th roots of unity in $\FF$. Let $\lag_i(X)$ be
the $i$-th element of an $\numberofconstrains$-elements Lagrange basis. During
the preprocessing phase polynomials $\p{S_{id j}}, \p{S_{\sigma j}}$, for
$\p{j} \in \range{1}{3}$, are computed:
\begin{equation*}
  \begin{aligned}
    \p{S_{id 1}}(X) & = X,\vphantom{\sum_{i = 1}^{\noofc} \sigma(i) \lag_i(X),}\\
    \p{S_{id 2}}(X) & = k_1 \cdot X,\vphantom{\sum_{i = 1}^{\noofc} \sigma(i) \lag_i(X),}\\
    \p{S_{id 3}}(X) & = k_2 \cdot X,\vphantom{\sum_{i = 1}^{\noofc} \sigma(i) \lag_i(X),}
  \end{aligned}
  \qquad
\begin{aligned}
  \p{S_{\sigma 1}}(X) & = \sum_{i = 1}^{\noofc} \sigma(i) \lag_i(X),\\
  \p{S_{\sigma 2}}(X) & = \sum_{i = 1}^{\noofc}
  \sigma(\noofc + i) \lag_i(X),\\
  \p{S_{\sigma 3}}(X) & =\sum_{i = 1}^{\noofc} \sigma(2 \noofc + i) \lag_i(X).
\end{aligned}
\end{equation*}
Coefficients $k_1$, $k_2$ are such that $H, k_1 \cdot H, k_2 \cdot H$ are
different cosets of $\FF^*$, thus they define $3 \cdot \noofc$
different elements. \cite{EPRINT:GabWilCio19} notes that it is enough to set
$k_1$ to a quadratic residue and $k_2$ to a quadratic non-residue.

Furthermore, we define polynomials $\p{q_L}, \p{q_R}, \p{q_O}, \p{q_M}, \p{q_C}$
such that
\begin{equation*}
  \begin{aligned}
  \p{q_L}(X) & = \sum_{i = 1}^{\noofc} \vql_i \lag_i(X), \\
  \p{q_R}(X) & = \sum_{i = 1}^{\noofc} \vqr_i \lag_i(X), \\
  \p{q_M}(X) & = \sum_{i = 1}^{\noofc} \vqm_i \lag_i(X),
\end{aligned}
\qquad
\begin{aligned}
  \p{q_O}(X) & = \sum_{i = 1}^{\noofc} \vqo_i \lag_i(X), \\
  \p{q_C}(X) & = \sum_{i = 1}^{\noofc} \vqc_i \lag_i(X). \\
  \vphantom{\p{q_M}(X)  = \sum_{i = 1}^{\noofc} \vqm_i \lag_i(X),}
\end{aligned}
\end{equation*}

\ourpar{$\plonk$ prover
  $\prover(\srs, \inp, \wit = (\wit_i)_{i \in \range{1}{3 \cdot
      \noofc}})$.}
\begin{description}
\item[Round 1] Sample $b_1, \ldots, b_9 \sample \FF_p$; compute
  $\p{a}(X), \p{b}(X), \p{c}(X)$ as
	\begin{align*}
		\p{a}(X) &= (b_1 X + b_2)\p{Z_H}(X) + \sum_{i = 1}^{\noofc} \wit_i \lag_i(X) \\
		\p{b}(X) &= (b_3 X + b_4)\p{Z_H}(X) + \sum_{i = 1}^{\noofc} \wit_{\noofc + i} \lag_i(X) \\
		\p{c}(X) &= (b_5 X + b_6)\p{Z_H}(X) + \sum_{i = 1}^{\noofc} \wit_{2 \cdot \noofc + i} \lag_i(X)
	\end{align*}
	Output polynomial commitments $\gone{\p{a}(\chi), \p{b}(\chi), \p{c}(\chi)}$.

	\item[Round 2]
	Get challenges $\beta, \gamma \in \FF_p$
	\[
		\beta = \ro(\tzkproof[0..1], 0)\,, \qquad \gamma = \ro(\tzkproof[0..1], 1)\,.
	\]
	Compute permutation polynomial $\p{z}(X)$
	\begin{multline*}
		\p{z}(X) = (b_7 X^2 + b_8 X + b_9)\p{Z_H}(X) + \lag_1(X) + \\
			+ \sum_{i = 1}^{\noofc - 1}
			\left(\lag_{i + 1} (X) \prod_{j = 1}^{i}
			\frac{
			(\wit_j +\beta \omega^{j - 1} + \gamma)(\wit_{\noofc + j} + \beta k_1 \omega^{j - 1} + \gamma)(\wit_{2 \noofc + j} +\beta k_2 \omega^{j- 1} + \gamma)}
			{(\wit_j+\sigma(j) \beta + \gamma)(\wit_{\noofc + j} + \sigma(\noofc + j)\beta + \gamma)(\wit_{2 \noofc + j} + \sigma(2 \noofc + j)\beta + \gamma)}\right)
	\end{multline*}
	Output polynomial commitment $\gone{\p{z}(\chi)}$

	\item[Round 3]
	Get the challenge $\alpha = \ro(\tzkproof[0..2])$, compute the quotient polynomial
	\begin{align*}
	& \p{t}(X)  = \\
	& (\p{a}(X) \p{b}(X) \selmulti(X) + \p{a}(X) \selleft(X) +
	\p{b}(X)\selright(X) + \p{c}(X)\seloutput(X) + \pubinppoly(X) + \selconst(X))
	\frac{1}{\p{Z_H}(X)} +\\
	& + ((\p{a}(X) + \beta X + \gamma) (\p{b}(X) + \beta k_1 X + \gamma)(\p{c}(X)
	+ \beta k_2 X + \gamma)\p{z}(X)) \frac{\alpha}{\p{Z_H}(X)} \\
	& - (\p{a}(X) + \beta \p{S_{\sigma 1}}(X) + \gamma)(\p{b}(X) + \beta
	\p{S_{\sigma 2}}(X) + \gamma)(\p{c}(X) + \beta \p{S_{\sigma 3}}(X) +
	\gamma)\p{z}(X \omega))  \frac{\alpha}{\p{Z_H}(X)} \\
	& + (\p{z}(X) - 1) \lag_1(X) \frac{\alpha^2}{\p{Z_H}(X)}
	\end{align*}
	Split $\p{t}(X)$ into degree less then $\noofc$ polynomials $\p{t_{lo}}(X), \p{t_{mid}}(X), \p{t_{hi}}(X)$, such that
	\[
		\p{t}(X) = \p{t_{lo}}(X) + X^{\noofc} \p{t_{mid}}(X) + X^{2 \noofc} \p{t_{hi}}(X)\,.
	\]
	Output $\gone{\p{t_{lo}}(\chi), \p{t_{mid}}(\chi), \p{t_{hi}}(\chi)}$.

	\item[Round 4]
	Get the challenge $\chz \in \FF_p$, $\chz = \ro(\tzkproof[0..3])$.
	Compute opening evaluations
	\begin{align*}
      \p{a}(\chz), \p{b}(\chz), \p{c}(\chz), \p{S_{\sigma 1}}(\chz), \p{S_{\sigma 2}}(\chz), \p{t}(\chz), \p{z}(\chz \omega),
	\end{align*}
	Compute the linearisation polynomial
	\[
		\p{r}(X) =
		\begin{aligned}
      & \p{a}(\chz) \p{b}(\chz) \selmulti(X) + \p{a}(\chz) \selleft(X) + \p{b}(\chz) \selright(X) + \p{c}(\chz) \seloutput(X) + \selconst(X) \\
      & + \alpha \cdot \left( (\p{a}(\chz) + \beta \chz + \gamma) (\p{b}(\chz) + \beta k_1 \chz + \gamma)(\p{c}(\chz) + \beta k_2 \chz + \gamma) \cdot \p{z}(X)\right) \\
      & - \alpha \cdot \left( (\p{a}(\chz) + \beta \p{S_{\sigma 1}}(\chz) + \gamma) (\p{b}(\chz) + \beta \p{S_{\sigma 2}}(\chz) + \gamma)\beta \p{z}(\chz\omega) \cdot \p{S_{\sigma 3}}(X)\right) \\
      & + \alpha^2 \cdot \lag_1(\chz) \cdot \p{z}(X)
		\end{aligned}
	\]
	Output $\p{a}(\chz), \p{b}(\chz), \p{c}(\chz), \p{S_{\sigma 1}}(\chz), \p{S_{\sigma 2}}(\chz), \p{t}(\chz), \p{z}(\chz \omega), \p{r}(\chz).$

	\item[Round 5]
	Compute the opening challenge $v \in \FF_p$, $v = \ro(\tzkproof[0..4])$.
	Compute the openings for the polynomial commitment scheme
	\begin{align*}
	& \p{W_\chz}(X) = \frac{1}{X - \chz} \left(
	\begin{aligned}
		& \p{t_{lo}}(X) + \chz^\noofc \p{t_{mid}}(X) + \chz^{2 \noofc} \p{t_{hi}}(X) - \p{t}(\chz)\\
		& + v(\p{r}(X) - \p{r}(\chz)) \\
		& + v^2 (\p{a}(X) - \p{a}(\chz))\\
		& + v^3 (\p{b}(X) - \p{b}(\chz))\\
		& + v^4 (\p{c}(X) - \p{c}(\chz))\\
		& + v^5 (\p{S_{\sigma 1}}(X) - \p{S_{\sigma 1}}(\chz))\\
		& + v^6 (\p{S_{\sigma 2}}(X) - \p{S_{\sigma 2}}(\chz))
	\end{aligned}
	\right)\\
	& \p{W_{\chz \omega}}(X) = \frac{\p{z}(X) - \p{z}(\chz \omega)}{X - \chz \omega}
\end{align*}
	Output $\gone{\p{W_{\chz}}(\chi), \p{W_{\chz \omega}}(\chi)}$.
\end{description}

\ncase{$\plonk$ verifier $\verifier(\srs, \inp, \zkproof)$}\ \newline
The \plonk{} verifier works as follows
\begin{description}
	\item[Step 1] Validate all obtained group elements.
	\item[Step 2] Validate all obtained field elements.
	\item[Step 3] Validate the instance
      $\inp = \smallset{\wit_i}_{i = 1}^\instsize$.
	\item[Step 4] Compute challenges $\beta, \gamma, \alpha, \chz, v,
      u$ from the transcript.
	\item[Step 5] Compute zero polynomial evaluation
      $\p{Z_H} (\chz) =\chz^\noofc - 1$.
	\item[Step 6] Compute Lagrange polynomial evaluation
      $\lag_1 (\chz) = \frac{\chz^\noofc -1}{\noofc (\chz - 1)}$.
	\item[Step 7] Compute public input polynomial evaluation
      $\pubinppoly (\chz) = \sum_{i \in \range{1}{\instsize}} \wit_i
      \lag_i(\chz)$.
	\item[Step 8] Compute quotient polynomials evaluations
	\begin{multline*}
    \p{t} (\chz) = \frac{1}{\p{Z_H}(\chz)} \Big(
    \p{r} (\chz) + \pubinppoly(\chz) - (\p{a}(\chz) + \beta \p{S_{\sigma 1}}(\chz) + \gamma) (\p{b}(\chz) + \beta \p{S_{\sigma 2}}(\chz) + \gamma) \\
    (\p{c}(\chz) + \gamma)\p{z}(\chz \omega) \alpha - \lag_1 (\chz) \alpha^2
    \Big) \,.
	\end{multline*}
	\item[Step 9] Compute batched polynomial commitment
	$\gone{D} = v \gone{r} + u \gone {z}$ that is
	\begin{align*}
		\gone{D} & = v
		\left(
		\begin{aligned}
          & \p{a}(\chz)\p{b}(\chz) \cdot \gone{\selmulti} + \p{a}(\chz)  \gone{\selleft} + \p{b}  \gone{\selright} + \p{c}  \gone{\seloutput} + \\
          & + (	(\p{a}(\chz) + \beta \chz + \gamma) (\p{b}(\chz) + \beta k_1 \chz + \gamma) (\p{c} + \beta k_2 \chz + \gamma) \alpha  + \lag_1(\chz) \alpha^2)  + \\
			% &   \\
          & - (\p{a}(\chz) + \beta \p{S_{\sigma 1}}(\chz) + \gamma) (\p{b}(\chz)
          + \beta \p{S_{\sigma 2}}(\chz) + \gamma) \alpha \beta \p{z}(\chz
          \omega) \gone{\p{S_{\sigma 3}}(\chi)})
		\end{aligned}
		\right) + \\
		& + u \gone{\p{z}(\chi)}\,.
	\end{align*}
	\item[Step 10] Computes full batched polynomial commitment $\gone{F}$:
	\begin{align*}
      \gone{F} & = \left(\gone{\p{t_{lo}}(\chi)} + \chz^\noofc \gone{\p{t_{mid}}(\chi)} + \chz^{2 \noofc} \gone{\p{t_{hi}}(\chi)}\right) + u \gone{\p{z}(\chi)} + \\
               & + v
                 \left(
		\begin{aligned}
			& \p{a}(\chz)\p{b}(\chz) \cdot \gone{\selmulti} + \p{a}(\chz)  \gone{\selleft} + \p{b}(\chz)   \gone{\selright} + \p{c}(\chz)  \gone{\seloutput} + \\
			& + (	(\p{a}(\chz) + \beta \chz + \gamma) (\p{b}(\chz) + \beta k_1 \chz + \gamma) (\p{c}(\chz)  + \beta k_2 \chz + \gamma) \alpha  + \lag_1(\chz) \alpha^2)  + \\
			% &   \\
			& - (\p{a}(\chz) + \beta \p{S_{\sigma 1}}(\chz) + \gamma) (\p{b}(\chz) + \beta \p{S_{\sigma 2}}(\chz) + \gamma) \alpha  \beta \p{z}(\chz \omega) \gone{\p{S_{\sigma 3}}(\chi)})
		\end{aligned}
		\right) \\
		& + v^2 \gone{\p{a}(\chi)} + v^3 \gone{\p{b}(\chi)} + v^4 \gone{\p{c}(\chi)} + v^5 \gone{\p{S_{\sigma 1}(\chi)}} + v^6 \gone{\p{S_{\sigma 2}}(\chi)}\,.
	\end{align*}
	\item[Step 11] Compute group-encoded batch evaluation $\gone{E}$
	\begin{align*}
		\gone{E}  = \frac{1}{\p{Z_H}(\chz)} & \gone{
		\begin{aligned}
			& \p{r}(\chz) + \pubinppoly(\chz) +  \alpha^2  \lag_1 (\chz) + \\
			& - \alpha \left( (\p{a}(\chz) + \beta \p{S_{\sigma 1}} (\chz) + \gamma) (\p{b}(\chz) + \beta \p{S_{\sigma 2}} (\chz) + \gamma) (\p{c}(\chz) + \gamma) \p{z}(\chz \omega) \right)
		\end{aligned}
           }\\
      + & \gone{v \p{r}(\chz) + v^2 \p{a}(\chz) + v^3 \p{b}(\chz) + v^4 \p{c}(\chz) + v^5 \p{S_{\sigma 1}}(\chz) + v^6 \p{S_{\sigma 2}}(\chz) + u \p{z}(\chz \omega) }\,.
	\end{align*}
\item[Step 12] Check whether the verification
 % $\vereq_\zkproof(\chi)$
  equation holds
	\begin{multline}
		\label{eq:ver_eq}
		\left( \gone{\p{W_{\chz}}(\chi)} + u \cdot \gone{\p{W_{\chz
                \omega}}(\chi)} \right) \bullet
		\gtwo{\chi} - %\\
		\left( \chz \cdot \gone{\p{W_{\chz}}(\chi)} + u \chz \omega \cdot
          \gone{\p{W_{\chz \omega}}(\chi)} + \gone{F} - \gone{E} \right) \bullet
        \gtwo{1} = 0\,.
	\end{multline}
  The verification equation is a batched version of the verification equation
  from \cite{AC:KatZavGol10} which allows the verifier to check openings of
  multiple polynomials in two points (instead of checking an opening of a single
  polynomial at one point).
\end{description}

\ncase{$\plonk$ simulator $\simulator_\chi(\srs, \td= \chi, \inp)$}\ \newline
The \plonk{} simulator proceeds as an honest prover would, except:
\begin{enumerate}
  \item In the first round, it sets $\wit = (\wit_i)_{i \in \range{1}{3 \noofc}}
    = \vec{0}$, and at random picks $b_1, \ldots, b_9$. Then it proceeds with
    that all-zero witness.
  \item In Round 3, it computes polynomial $\pt(X)$ honestly, however uses
    trapdoor $\chi$ to compute commitments
    $\p{t_{lo}}(\chi), \p{t_{mid}}(\chi), \p{t_{hi}}(\chi)$.
  \end{enumerate}

%  \subsection{Trapdoor-less simulatability of Plonk}
%\label{sec:plonk-TLZK-proof}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


% --------------------------------------------------------------
% This is all preamble stuff that you don't have to worry about.
% Head down to where it says "Start here"
% --------------------------------------------------------------

\documentclass[12pt,answers]{exam}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{float}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{verbatim}
\usepackage{listings}
\usepackage[comma, authoryear]{natbib}
\bibliographystyle{plainnat}
\usepackage{mathtools}
\usepackage[shortlabels]{enumitem}
\usepackage{pythontex}
\usepackage[makeroom]{cancel}

\usepackage{listings}
\usepackage{xcolor}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{darkblue}{rgb}{0.1,0.1,1}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{darkblue},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=1pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
}

\lstset{style=mystyle}

\graphicspath{{../figures/}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\N}{\mathbb{N}}
\newcommand\tab[1][1cm]{\hspace*{#1}}
\newcommand{\K}{\mathbb{K}}
\newcommand{\zero}{\mathbb{O}}

\newenvironment{theorem}[2][Theorem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{lemma}[2][Lemma]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{exercise}[2][Exercise]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{reflection}[2][Reflection]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{proposition}[2][Proposition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{corollary}[2][Corollary]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}

\begin{document}

% --------------------------------------------------------------
%                         Start here
% --------------------------------------------------------------

%\renewcommand{\qedsymbol}{\filledbox}

\title{\textbf{Advanced Numerical Methods for PDEs}\\ \Large{Homework 2}}%replace X with the appropriate number
\author{Francisco Castillo}

\maketitle
Solve the advection-diffusion equation
\begin{align}\label{eq:PDE}
\partial_tu(x,t)+\partial_x\left[vu(x,t)-d\partial_xu(x,t)\right]=0,~~~
u(x,t=0)=u^I(x),~~~
x\in[0, L],~
t\in[0, T],
\end{align}
with periodic boundary conditions $u(x + L, t) = u(x, t),~~ \forall x, t$.

\section*{Problem 1}
\input{problem1}
\newpage
\section*{Problem 2}
\input{problem2}
\newpage

Consider an ensemble of cars, distributed on a circular course of length $L$ (so $x\in[0, L]$), trying to travel at a desired speed $v_0(x)$. Assume that there is a minimal distance $d$ between cars and a corresponding congestion density $c$. Simulate for a time $t\in[0,T]$.
Plot a solution of the congestion backward wave and the
distribution of cars at $t = T$.

\section*{Problem 3}
\input{problem3}
\newpage
\section*{Problem 4}
\input{problem4}

\end{document}


We have a scalable simulation platform with for \rbc flows through capillaries using boundary integral equations.
We first presented a robust solver for elliptic \pdes on \threed rigid geometries.
We thoroughly studied the behavior and performance of this solver on a variety of geometries and compared it with a competitive state-of-the-art solver.
We then parallelized the solver, combined it with boundary integral-based vesicle simulation algorithms and adapted collision-free time stepping to include rigid boundaries.
We have scaled our simulations and the parallel solver to thousands of cores and demonstrated the practicality of using such simulations to reproduce qualitatively representative physical \rbcs flows.

\section{Future Work}
The comparison between \qbkix and \cite{YBZ} in \cref{sec:results-compare} demonstrated the efficiency of a local quadrature scheme compared to a global one.
Moreover, the scaling results in \cref{ss:scalability} demonstrate that parallel \qbkix is the dominant cost of the simulation.
In order to scale \rbc simulations beyond the regime explored here, the parallel boundary solver needs to be improved.
A key improvement will be the adpotion of a \textit{local} singular quadrature approach.
Parallel scaling is largely determined by communication costs and \qbkix performs parallel communication entirely through \pvfmm.
Reducing the number of total points passed to \pvfmm is the best way to improve parallel scaling, since this reduces the overall size of the distributed octree.
The local corrections to an inaccurate \fmm evaluation can be highly vectorized and require no additional parallel communication.
Moreover, the local corrections can be precomputed when solving the integral equation with \gmres.
These two facts will dramatically increase the performance of \qbkix.

Another area for improvement is in extrapolation procedure of \qbkix.
Equally spaced points serve as a fairly bad interpolant, but we have shown that we're able to use low order polynomials to extrapolate reliably.
An important question in the future of \qbkix is how to construct an optimal \oned extrapolation procedure for harmonic functions.
An equally important concern is the scheme's inability to resolve oscillatory \pdes such as the Helmholtz equation\edit{.}{, due to the difference in resolution achieved on the boundary by $q^2$ quadrature points and the $p$ check points.}
A trigonometric extrapolation procedure, coupled with a sampling rate comensurate with the solution's underlying frequency, is one possible approach.

\cite[Section 3.3.1]{wala20183d} \edit{}{ has shown that \qbx truncation error is influenced by surface curvature; \qbkix experiences a similar phenomenon.
An adaptive placement of check points, determined by surface curvature and overall extrapolation error, would further increase accuracy without increasing cost.
Additionally, an approach like Richardson extrapolation could further improve accuracy.
Placing several sets of check points for decreasing values of $r$ and evaluating them with a single \fmm call would allow for better approximate extrapolation by merging the individual results.
}
Several algorithms in \cref{sec:algo} can be improved.
The closest point algorithm in \cref{app:closest_point} can be dramatically improved by leveraging subdivision properties of the B\'ezier surface representation.
We can compute the closest point to the control points of a patch, subdivide the patch, and recursively repeat the process to arrive at more accurate initial guess for the closest point for the \twod Newton method in \cref{app:closest_point}.
This guess can further cull the \oned optimizations based on the quadrant of the initial guess.
Preliminary investigation shows that this outperforms the method detailed in \cref{app:point_marking}.

The point marking algorithm in \cref{app:point_marking} and the upsampling algorithm in \cref{sec:adaptive_upsampling_algo} are based on near-zone bounding boxes.
A proper quadrature error heuristic similar to \cite{aT2} would dramatically reduce the amount of upsampling required to guarantee the accuracy of \qbkix.
This would improve the third plot in \cref{fig:full-algo-perf} by more accurately determine which points require evaluation via \qbkix, both of which will reduce overall cost.
The approach taken in \cite{klinteberg2020quadrature} shows exceptional promise toward this end.

The refinement algorithms in \cref{sec:adaptive_upsampling_algo,sec:admissible_algo} require parallelization for \qbkix to be a useful computational tool.
This requires minor changes to the parallel closest point algorithm in \cref{sec:closest_point} and the parallel near-pair algorithm in \cref{sec:parallel-contact}.

Recent work \cite{wang2021benchmark} has demonstrated that the collision detection scheme in \cite{Harmon2011} used in \cref{chp:bloodflow} and \cite{lu2019scalable,lu2018parallel} seems to miss collisions with large separation distances.
It appears from \cite[Section 6]{wang2021benchmark} that \cite{Harmon2011} entirely misses a relatively large number of collisions across all datasets.
The collision geometries in \cref{chp:bloodflow} are quite benign compared to the datasets in \cite{wang2021benchmark}, since \rbcs and vessels are represented by spherical harmonics and high order polynomials, respectively.
Though we verify a collision-free state at each time step in \cref{chp:bloodflow}, addressing this shortcoming is crucial.
\cite{li2020incremental,ferguson2021RigidIPC} presents a viable approach, but currently only operates on a single compute node.
Implementing a scalable parallel version of \cite{ferguson2021RigidIPC} is a key step in simulating more complex geometries or sharp rigid particulates.

Finally, incorporating in-plane shear forces into the \rbc model will dramatically improve the overall model accuracy in \cref{chp:bloodflow}.
Recent optical tweezer exerpiments \cite{mills2004nonlinear,li2005spectrin} have shown that the cytoskeletal structure of \rbcs can withstand surprisingly large amounts of shear force in extreme circumstances.
\cite{fai2017image} could serve as an effective approach.
Moreover, quantifying the impact of cytoskeletal modeling on overall \rbc flows would be of great interest.


\newpage\section{Cevian and Circumcevian Triangles}

	\subsection{Circumcevian Triangle}

		\theo{https://nguyenvanlinh.files.wordpress.com/2011/12/hagge-circles-revisited.pdf}{Hagge's circles}{Let $ P $ be a point on the plane of $ \triangle ABC $, let $ \Omega $ be the circumcircle. Let $ A_1, B_1, C_1 $ be the intersections of $ AP, BP, CP $ with $ \Omega $ for the second time. Let $ A_2, B_2, C_2 $ be the reflections of $ A_1, B_1, C_1 $ wrt $ BC, CA, AB $. Prove that $ H, A_2, B_2, C_2 $ lie on a circle. This circle is called the \textbf{$ \boldsymbol{P} $-Hagge's Circle}.}

			\solu{Either using the dual of Hagge's Circle, or using the reflection points of $ A, B, C $ wrt the isogonal conjugate of $ P $. And using Lemma 1.1 to finish.}

			\fig{.6}{P-HaggeCircle}{P-Hagge Circle}

		\coro{$ \triangle A_1B_1C_1 \sim \triangle A_2B_2C_2 $.}

			\solu{Straightforward use of Lemma 1.2.}

		\coro{If $ AH, BH, CH $ meet $ \odot A_2B_2C_2H $ at $ A_3, B_3, C_3 $, then $ A_2A_3, B_2B_3, C_2B_3 $ meet at $ P $.}

			\solu{Simple angle chase and similarity transformation.}

		\coro{If $ I $ is the incenter of $ \odot A_2B_2C_2 $, $ K $ is the reflection of $ H $ over $ I $, $ AK, BK, CK $ meet $ \odot A_2B_2C_2 $ at $ A_4, B_4, C_4 $, then $ A_4A_3, B_4B_3, C_4B_3 $ are concurrent.}

			\solu{Simple angle chasing and trig-ceva.}

		\prob{https://artofproblemsolving.com/community/c6h97484p550561}{China TST D2P2, Dual of the Hagge's Circle theorem}{M}{Let $\omega$ be the circumcircle of $\triangle{ABC}$. $P$ is an interior point of $\triangle{ABC}$. $A_{1}, B_{1}, C_{1}$ are the intersections of $AP, BP, CP$ respectively and $A_{2}, B_{2}, C_{2}$ are the symmetrical points of $A_{1}, B_{1}, C_{1}$ with respect to the midpoints of side $BC, CA, AB$. Show that the circumcircle of $\triangle{A_{2}B_{2}C_{2}}$ passes through the orthocenter of $\triangle{ABC}$. Further proof that if this circle's center is $ O_1 $, then $ HOPO_1 $ is a parallelogram.}

			\solu{Construct Parallelograms. You have to prove two angles are equal. Reflection the smaller trig wrt one of the midpoints.}

		\prob{https://artofproblemsolving.com/community/c6h407514p2276387}{China TST 2011, Quiz 2, D2, P1}{E}{Let $AA',BB',CC'$ be three diameters of the circumcircle of an acute triangle $ABC$. Let $P$ be an arbitrary point in the interior of $\triangle ABC$, and let $D,E,F$ be the orthogonal projection of $P$ on $BC,CA,AB$, respectively. Let $X$ be the point such that $D$ is the midpoint of $A'X$, let $Y$ be the point such that $E$ is the midpoint of $B'Y$, and similarly let $Z$ be the point such that $F$ is the midpoint of $C'Z$. Prove that triangle $XYZ$ is similar to triangle $ABC$.}

			\solu{A straightforward application of Lemma 6.1 using the $ O $-Hagge's Circle.}

	\newpage\subsection{Cevian Triangle}

		\lem{Isogonal Conjugate Lemma}{Let a circle $ \omega $ meet the sides of triangle $ ABC $ at $ A_1, A_2;\ B_1, B_2;\ C_1, C_2 $. Let $ P_1, P_2 $ be the miquel points of $ ABC $ wrt $ A_1B_1C_1, A_2B_2C_2 $ resp. Then $ P_1, P_2 $ are isogonal conjugates.}

			\fig{1}{IsoConjuCirclesLemma1}{The two round points are isogonal conjugates.}

		\theo{}{Terquem's Cevian Theorem}{Let a circle $ \omega $ meet the sides of triangle $ ABC $ at $ A_1, A_2;\ B_1, B_2;\ C_1, C_2 $. If $ AA_1, BB_1, CC_1 $ are concurrent, then so are $ AA_2, BB_2, CC_2 $}.

		\theo{https://artofproblemsolving.com/community/c3103h1052426_mannheim_circles}{Mannheim's Theorem}{Let $ABC$ be a triangle, and let $L,M,N$ be points on $BC,CA,AB$ respectively. Let $A', B', C'$ be points on $(AMN), (BNL), (CLM)$, and denote $K \equiv AA' \cap BB'$. Then if $K \in CC'$, $A',B',C',K$ are concyclic.}\label{mannheim_theorem}

			\fig{1}{MannheimTheorem}{Mannheim's Theorem}

		\theo{mannheim_theorem}{Mannheim's Theorem's Converse}{Let $ABC$ be a triangle, and let $L,M,N$ be points on $BC,CA,AB$ respectively. Let $A', B', C'$ be points on $(AMN), (BNL), (CLM)$, and denote $K \equiv AA' \cap BB'$. Then if $A',B',C',K$ are concyclic, $C' \in CK$.}

		\theo{}{Brocard Points}{Brocard Points are points inside a triangle such that \[ \angle PAB=\angle PBC=\angle PCA=\omega \] and \[ \angle QCB=\angle QBA=\angle QAC = \omega. \]}

			\fig{1}{BrocardPoints}{Brocard Points}

		\prob{http://www.artofproblemsolving.com/Forum/blog.php?u=214539&b=106944}{Rioplatense Olympiad 2013 Problem 6}{E}{Let $ABC$ be an acute-angled scalene triangle, with centroid $G$ and orthocenter $H$. The circle with diameter $AH$ cuts the circumcircle of $BHC$ at $A'$, distinct from $H$. Analogously define $B', C'$. Prove that $A', B', C', G$ are concyclic.}

		\prob{https://artofproblemsolving.com/community/c6h1274755p6680026}{Iran 3rd Round Training 2016}{E}{$ABC$ is an acute triangle and $H,O$ are its orthocenter and circumcenter respectively. If $AO,BO,CO$ intersect $BH,CH,AH$ at $X,Y,Z$ respectively,then prove that $H,X,Y,Z$ lie on a circle}

			\solu{Using Brocard Point}
			\solu{Using Mannheim's Theorem}

		\theo{https://en.wikipedia.org/wiki/Jacobi's_theorem_(geometry)}{Jacobi's Theorem}{Suppose that $ D, E, F $ are points such that $ AE, AF $ are isogonal wrt $ \angle BAC $. Similarly with $ D, E, F $. Then $ AD, BE, CF $ are concurrent.}