\newsection{Arrays}

\subsection{Motivation}
Arrays are a very powerful tool in a programmer's arsenal. They allow managing many variables at once without much hassle.

\subsection{Arrays}
The typical structure for creating an array is:
\begin{center}
$<type>[] <name> = new <type>[<integer>];$
\end{center}
where $<integer>$ is greater than 0. For example, if we want to create an array of \verb|int| variables with 10 elements, we can construct it like this:
\begin{lstlisting}
int[] array = new int[10]; // 10 elements
\end{lstlisting}
Now how do we access or modify elements of an array? Here are some code examples on how to do so:
\begin{lstlisting}
int[] array = new int[100]; // 100 elements
// By default, each element is 0 (primitives) or null (objects)
// indexes are same as in String, etc. 0 - 99 indexes in this array
array[0] = 10; // set first element to 10
array[1] = 9; // set second element to 9
array[99] = 255; // set last element to 255
// array[100] = 100; // ArrayIndexOutOfBoundsException, because index is larger than the highest addressable one
// array[-1] = -1; // Also an ArrayIndexOutOfBoundsException

// Cannot assign/get different types or non-integer indexes:
// String s = array[10]; // compiler error
// array[10] = new String(); // compiler error
// System.out.println(array[2.5]); // compiler error

// However there is a ".length" attribute we can use (no parentheses):
System.out.println(array.length); // 100
// Therefore, we can set to the last element without a hardcoded number:
array[array.length-1] = 100;
// Getting an element is the same:
int n = array[56]; // get index 56 element
// We can loop over elements:
for(int i = 0; i < array.length; i++) {
     System.out.print(array[i] + " ");
}
// Or equivalently, the range-based for loop:
for(int i : array) { // "for each i in array"
     System.out.print(i + " ");
}
\end{lstlisting}

\subsection{Written Exercises}

\begin{enumerate}

\item What are the indices for the first and last positions of any array?

\item Immediately after instantiating a new array of primitives (\verb|int|s, \verb|double|s, etc.), what fills the array? What about an array of objects?

\item What happens when you try to access an array element past the end of the array?

\item Use the following array \verb|x| to answer the following questions:
\begin{table}[h]
\begin{tabular}{lllllll}
4 & 8 & 5 & 1 & 6 & 3 & 2
\end{tabular}
\end{table}
\begin{enumerate}
\item[a)]What value is given by x[1]?
\item[b)]What value is given by x[6]?
\item[c)]What value is given by x[7]?
\item[d)]What value is given by x.length?
\end{enumerate}

\end{enumerate}

\subsection{Programming Exercises}

\begin{enumerate}

\item Instantiate three arrays called \verb|x|, \verb|y|, and \verb|z| of type \verb|int|, \verb|String|, and \verb|BankAccount| (respectively), all of size 10.

\item Write a \verb|for|-loop to sum all of the elements of an array \verb|x| of type \verb|int|.

\item Write a \verb|for|-loop to multiply by 2 each element in an array x of type \verb|int|.

\item Write code to store the largest number in an \verb|int| array \verb|x| into a variable called \verb|max|.

\item Write code to count how many numbers in an array \verb|x| are strictly larger than 4, and store that total in a variable called \verb|total|.

\item Write code to print out every other element in an array \verb|x| separated by tabs.

\item Write code to shift each number in an array \verb|x| one place to the right (Note: there will be 2 copies of the 1st element when the code finishes).

\item Write code to print the contents of an array \verb|x| in reverse order, one element for each line.

\item Write a method called \verb|append| that appends the two \verb|int| arrays passed as arguments and returns an array of type \verb|int| as the result. For example, if the first array argument was \{1, 2, 3\}, and the second was \{4, 5, 6, 7\}, append returns \{1, 2, 3, 4, 5, 6, 7\}.

\item Write a method called \verb|findMin| that returns the smallest element in an \verb|int| array that is passed as an argument. For example, if the array was \{4, 7, 9, 12, 8, 1, 5\}, the method would return 1 (Hint: use an earlier exercise for this).

\end{enumerate}


\subsection{Air Thermoregulation}
\label{sec:airthermoregulation}

\textbf{Purpose}: Maintaining desired leaf-zone air temperature and circulating air.

\textbf{Function}:
\begin{itemize}
    \item \textbf{Inputs}: Power, air temperature control signal (\ref{sec:automation}), air circulation control signal (\ref{sec:automation});
    \item \textbf{Outputs}: $\pm$Heat to environment, $\mp$heat to surroundings, internal air circulation, internal air temperature sensor signal (\ref{sec:automation});
\end{itemize}

\textbf{Method}:
\begin{enumerate}
    \item \textit{Testing}:
    \begin{itemize}
        \item Heat pump direction and magnitude respond to control signal as expected;
        \item Fans operate as expected;
        \item Heat pump power exceeds maximum heat loss (temperature extremes)\footnote{i.e. if X Watts leave the system at MAX$\degree$C internal, and Y Watts enter the system at MIN$\degree$C internal, the heat pump must transfer >X, >Y Watts.};
        \item Heat pump power exceeds that required to reach temperature extremes in under 120 seconds given the system's heat capacity;
    \end{itemize}
    \item \textit{Process}:
    \begin{enumerate}
        \item Air is circulated throughout the environment;
        \item Temperature is measured, sent to control module;
        \item Control module controls heat pump speed and direction (heating vs. cooling);
    \end{enumerate}
\end{enumerate}

\textbf{Calculations}:

Assuming an atmospheric pressure $P$ of 101.325kPa, a surroundings temperature range $T_{surr}$ of 22$\degree$C, a system target temperature range $T_{sys-min}$, $T_{sys-max}$ of 10-35$\degree$C, a molar mass of dry air\footnote{Water vapour has a maximum concentration of 30g/kg at 30$\degree$C, or 3\%, which is negligible for mass and heat capacity calculations.} $M$ of 28.97 $\frac g{mol}$, a specific heat capacity of dry air $c_p$ of $1.006 \frac{J}{g*\text{K}}$, a 4-unit (2x2 units, 16 faces) expanded configuration, and a face insulation RSI per mm of $0.0328\text{m}^2~  \degree \text{C}~\text{W}^{-1}~\text{mm}^{-1}$ (See Section \ref{sec:housing}):\\
\vspace{.05cm}
\begin{gather*}
    \label{eqn:heatloss}
    Q_{loss}=\frac{(T_{surr}-T_{sys-max}) * A}{\text{RSI per mm} * \ell}=\frac{(22\degree \text{C}-35\degree \text{C}) * (16 \text{ faces} * 0.5\text{m} * 0.5\text{m})}{0.0328 \text{m}^2~  \degree \text{C}~\text{W}^{-1}~\text{mm}^{-1} * 25.4 \text{mm}}=-62.42 W\\\vspace{.05cm}\\
    \label{eqn:heatgain}
    Q_{gain}=\frac{(T_{surr}-T_{sys-min}) * A}{\text{RSI per mm} * \ell}=\frac{(22\degree \text{C}-10\degree \text{C}) * (16 \text{ faces} * 0.5\text{m} * 0.5\text{m})}{0.0328 \text{m}^2~  \degree \text{C}~\text{W}^{-1}~\text{mm}^{-1} * 25.4 \text{mm}}=57.61 W\\\vspace{.05cm}\\
    \label{eqn:airmass}
    m_{air}=\frac{P*V*M}{R*T_{avg}}=\frac{101325\text{Pa}*(0.5\text{m}*0.5\text{m}*0.5\text{m}*4\text{ units})*28.97\frac g{mol}}{8.314\frac{J}{\text{mol}*K}*300\text{K}}=588.4g\\
    \vspace{1.5cm}\\
    \text{Continued on next page}
\end{gather*}
\vspace{1cm}

\begin{gather*}
  \label{eqn:heating}
  W_{heating}=\frac{m*c_p*(T_{surr}-T_{sys-max})}{t}=\frac{588.4g*1.006\frac{J}{g*\text{K}}*(22\degree \text{C}-35\degree \text{C})}{120\text{ sec}}=-64.13\text{W}\\
  \label{eqn:cooling}
  W_{cooling}=\frac{m*c_p*(T_{surr}-T_{sys-min})}{t}=\frac{588.4g*1.006\frac{J}{g*\text{K}}*(22\degree \text{C}-10\degree \text{C})}{120\text{ sec}}=59.19\text{W}
\end{gather*}

$\therefore$ A thermoelectric system able to transfer at least 70W (such as \cite{peltier}, which transfers up to 85W) will supply enough power to heat/cool the system from ambient to extremes in 120 seconds and maintain temperature.

\begin{gather*}
  \label{eqn:thermalresistance-hot}
  R_{\theta~Peltier-Surr}=R_{\theta~Peltier-Sink}+R_{\theta~Sink-Air}\le\frac{T_{h~max} - T_{surr}}{Q_{max}}=\frac{50\degree C - 22\degree C}{85W}=0.329\degree \text{C W}^{-1}\\
  \label{eqn:thermalresistance-cold}
  R_{\theta~Peltier-Sys}=R_{\theta~Peltier-Sink}+R_{\theta~Sink-Air}
\end{gather*}

\textbf{Features}:
\begin{itemize}
    \item \textit{Circulation Fans}: Located in growth environment to circulate air even temperature distribution.
    \item \textit{Temperature Sensors}: SHT31 \cite{sht31} sensors on breakout boards located throughout the growth environment to measure air temperature. Informs a \textbf{PID control loop} (\ref{sec:automation}).
    \item \textit{Heat Pump}: Pumps heat in or out of the growth environment. Is comprised of:
    \begin{itemize}
        \item \textit{Peltier Device}: 85W bidirectional solid-state \textbf{thermoelectric device} (aka Peltier tile) \cite{peltier} pumps heat from one face to the other. Better space efficiency, less complexity (no liquids, pressurized fluids, etc.), and more precise than other methods.
        \item \textit{Peltier Driver Circuit}: Controls magnitude and direction of Peltier device heat pump via a \textbf{dimmable voltage source} and \textbf{MOSFET H-bridge}, respectively. See Figure \ref{fig:peltierdriver}.
        \item \textit{Heat Sinks}: Aluminum blocks with fins hold and exchange heat between air and Peltier devices. One set on each side of the Peltier (inside and outside environment) builds "heat pump". Mating face coated with thermal compound for better transfer.
        \item \textit{Heat Sink Fans}: Located on both sets of heat sinks for better heat dissipation.
    \end{itemize}
\end{itemize}

\begin{figure}[h]
  \centering
  \includegraphics[width=0.8\textwidth]{images/thermosim.png}
  \hfill
  \caption{Peltier driver circuit simulation (live version: \cite{thermo-falstad})}
  \label{fig:peltierdriver}
\end{figure}


\documentclass[]{revtex4-2}
\usepackage{amsmath}

\begin{document}
    \title{Assignment 5: Physics of Compact Objects}
    \author{Md Arif Shaikh}
    \affiliation{International Centre for Theoretical Sciences, Bengaluru}
    \email{arifshaikh.astro@gmail.com}
    \date{\today}
    \maketitle
    \section*{Problem 1}
    Show that, in the white dwarf interior, the Coulomb energy per free electron is
    \begin{equation}
      \label{eq:coulomb-energy}
      \epsilon_C = - \frac{9}{10} \left(\frac{4\pi}{3}\right)^{1/3}Z^{2/3}e^2 n_e^{1/3},
    \end{equation}
    where $Z$ is the atomic number, $e$ is the elementary charge and $n_e$ is the number density of free electrons.

\vspace{0.5cm}

\noindent {\bfseries Answer:} As temperature decreases, $T\to0$, the ions are located in a lattice that maximizes the inter-ion separation. We can consider a spherical shell of the lattice of volume $4\pi r_0^3/3 = 1/n_N$, where $n_N$ is the number density of the nuclei. The total energy of any one sphere is the sum of potential energies due to electron-electron ($e-e$) interactions and electron-ion ($e-i$) interactions.

To assemble a uniform sphere of $Z$ electrons requires energy
\begin{equation}
  \label{eq:e-e}
  E_{e-e} = \int_0^{r_0} \frac{q dq}{r} = \int_0^{r_0} - \frac{Ze (r^3/r_0^3)d ( - Ze (r^3/r_0^3))}{r} = Z^2e^2 \frac{3}{r_0^6}\int_0^{r_0} r^4 dr = Z^2e^2 \frac{3}{r_0^6}\frac{r_0^5}{5} = \frac{3}{5}\frac{Z^2e^2}{r_0}.
\end{equation}
On the other hand, to assemble the electron sphere about the central nucleus of charge $Ze$ requires energy
\begin{equation}
  \label{eq:e-i}
  E_{e-i} = Ze \int_0^{r_0} \frac{dq}{r} = - Ze \int_0^{r_0} \frac{3 dr Z e r}{r_0^3} = - \frac{3}{2}\frac{Z^2e^2}{r_0}.
\end{equation}
So, the total Coulomb energy of the shell is
\begin{equation}
  \label{eq:E_tot}
  E_C = E_{e-e} + E_{e-i} =  \frac{3}{5}\frac{Z^2e^2}{r_0} - \frac{3}{2}\frac{Z^2e^2}{r_0} = - \frac{9}{10}\frac{Z^2e^2}{r_0}.
\end{equation}
So the Coulomb energy per electron is
\begin{equation}
  \label{eq:epsilon_c}
  \epsilon_C = \frac{E_C}{Z} = -\frac{9}{10}\frac{Z e^2}{r_0} = - \frac{9}{10}\frac{Z e^2}{(3 Z/4\pi n_e)^{1/3}} = - \frac{9}{10} \left(\frac{4\pi}{3}\right)^{1/3}Z^{2/3}e^2n_e^{1/3},
\end{equation}
where we have used
\begin{equation}
  \label{eq:n_e}
  \frac{4\pi}{3} r_0^3 n_e = Z.
\end{equation}
\end{document}


\include{config/config}

\begin{document}
% ========== Edit your name here
\title{MATH 2901 Basic Probability Lecture Notes 2}
\author{Instructor: Richard Kleeman}
\date{}
\maketitle

%\medskip

% ========== Contents begin here ==============
\section{Random variables}
\begin{definition}
\textbf{A random variable} is a function $X: \Omega \to \R$ with the property that $\{ \omega\in \Omega \spacevert X(\omega) \leq x\} \in \mathcal{F}$ for each $x \in \R$. Such a function is said to be $\mathbf{\mathcal{F}}$\textbf{-measurable}.
\end{definition}

\begin{example}
Tossing two dice. We define
\begin{equation*}
    X = \begin{cases} 1 & \text{get double ($i=j$)} \\ 0 & \text{not double $(i\neq j)$} \end{cases}.
\end{equation*}
Then $X = (i,j) \in \R$.
\end{example}

\begin{remark}
We are interested in $g(x) = \Prob\{ \omega \spacevert X(\omega) = x \}$. But sometimes it doesn't work very well. Probability triplet is defined as $\{ \Omega, \mathcal{F}, \Prob \}$. If $\Omega$ is countable, then $g(x)$ is okay. But if $\Omega$ is uncountable like intervals, then $\Prob(X=x)$ doesn't make much sense because the cardinality is too large.
\end{remark}

\begin{definition}
The \textbf{distribution function} of a random variable $X$ is the function $F: \R \to
[0, 1]$ given by $F(x) = \Prob(X \leq x)$.
\end{definition}

\begin{example}
The distribution function of preceeding example is
\begin{equation*}
    F(x) = \begin{cases} 0 & x \leq 0, \\ \frac{30}{36} & 0 < x \leq 1, \\ 1 & x > 1. \end{cases}
\end{equation*}
\end{example}

Notice that $\{ \omega \spacevert X(\omega) \leq x\}$ defines an event. It is an element in the corresponding $\sigma$-field. Denote $A(x) = \{ \omega \spacevert X(\omega) \leq x \}$. Along with $A(x)$, we can define
\begin{equation*}
    A^c(x) = \{ \omega \spacevert X(\omega) > x \}, \quad A(x, y) = A^c(x) \cap A(y) = \{ \omega \spacevert x < X(\omega) \leq y \}.
\end{equation*}
Tow points worth noting:
\begin{enumerate}[(a)]
    \item $F$ must be defined for \textbf{all} $x \in \R$.
    \item $A(x)$ should \textbf{belongs to} $\mathcal{F}$. Otherwise, we cannot talk about the probability of $\Prob(A(x))$. Then the definition of distribution function is meaningless.
\end{enumerate}

\begin{lemma}
A distribution function $F$ has the following properties:
\begin{enumerate}[(a)]
    \item $\lim_{x \to -\infty}F(x) = 0$, $\lim_{x\to\infty} F(x) = 1$,
    \item if $x < y$, then $F(x) \leq F(y)$,
    \item $F$ is right-continuous, that is $F(x+h) \to F(x)$ as $h \downarrow 0$. (left-continuous is not necessary)
\end{enumerate}
\end{lemma}

\begin{example}
\textbf{Indicator functions.} A particular class of Bernoulli variables is very useful in probability theory. Let $A$ be an event and let $I_A : \Omega \to \R$ be the indicator function of $A$; that is,
\begin{equation*}
    I_A(\omega) = \begin{cases} 1 & \text{if $\omega \in A$}, \\ 0 & \text{if $\omega \in A^c$}. \end{cases}
\end{equation*}
Then $I_A$ is a Bernoulli random variable taking the values 1 and 0 with probabilities $\Prob(A)$ and $\Prob(A^c)$ respectively. Suppose $\{B_i \spacevert i \in I\}$ is a family of disjoint events with $A \subseteq \bigcup_{i\in I} B_i$. Then
\begin{equation*}
    I_A = \sum_{i} = I_{A\cap B_i},
\end{equation*}
an identity which is often useful.
\end{example}

\begin{lemma}
Let $F$ be the distribution function of $X$. Then
\begin{enumerate}[(a)]
    \item $\Prob(X>x) = 1-F(x)$,
    \item $\Prob(x < X \leq y) = F(y) - F(x)$,
    \item $\Prob(X = x) = F(x) - \lim_{y \uparrow x} F(y)$.
\end{enumerate}
\end{lemma}

A random variable $X$ with distribution function $F$ is said to have two ``tails" given by
\begin{equation*}
    T_1 (X) = \Prob(X > x) = 1 - F(x), \quad T_2(X) = \Prob(X \leq -x) = F(-x),
\end{equation*}
where $x$ is large and positive. The rates at which the $T_i$ decay to zero as $x\to\infty$ have a substantial effect on the existence or non-existence of certain associated quantities called the ``moments" of the distribution.

\section{Different random variables}
\subsection{Discrete random variables}
\begin{definition}
The random variable $X$ is called \textbf{discrete} if it takes values in some \textbf{countable} subset $\{ x_1, x_2, \dots \}$, only, of $\R$. The discrete random variable $X$ has \textbf{(probability) mass function} $f : \R \to [0, 1]$ given by $f(x) = \Prob(X = x)$.
\end{definition}
We shall see that the distribution function of a discrete variable has jump discontinuities
at the values $x_1 , x_2, \dots$ and is constant in between; such a distribution is called \emph{atomic}.

\subsection{Continuous random variables}
\begin{definition}
The random variable $X$ is called \textbf{continuous} if its distribution function can
be expressed as
\begin{equation*}
    F(x) = \int_{-\infty}^x f(u) du \qquad x \in \R
\end{equation*}
for some \textbf{integrable} function $f : \R \to [0, \infty)$ called the \textbf{(probability) density function} of $X$.
\end{definition}
Some point worth noting:
\begin{enumerate}[(a)]
    \item The density function $f(x)$ is not unique. We can add some separate points to $f$, and it doesn't affect the integration.
    \item $F$ must be \textbf{absolutely continuous}. This implies $F$ is continuous. We can also deduce that the probability at certain point must be zero. \emph{i.e.}, $\Prob(X=x) = 0$.
\end{enumerate}

There is another sort of random variable, called ``singular".

\section{Random vectors}
\subsection{Definition}
The random vector is a function $X : \Omega \to \R^n$. For example, $\mathbf{X} = (X, Y)$ for $n=2$. We can also define the distribution function for such $X$. But we need to first introduce the ordering in $\R^n$.
\begin{center}
    By definition, $(x_1, y_1) < (x_2, y_2)$ if and only if $x_1 < x_2$  \textbf{AND}  $y_1 < y_2$.
\end{center}

\begin{definition}
The \textbf{joint distribution function} of a random vector $\mathbf{X} = (X_1, X_2 \dots, X_n)$ on the probability space $\{ \Omega, \mathcal{F}, \Prob \}$ is the function $F_{\mathbf{X}} : \R^n \to [0, 1]$ given by $F_{\mathbf{X}}(x) = \Prob(\mathbf{X} \leq \mathbf{x})$ for $\mathbf{x} \in \R^n$.
\end{definition}

\begin{remark}
The joint probability $\Prob(\mathbf{X} \leq \mathbf{x}) = \Prob(X_1 \leq x_1, \dots, X_n \leq x_n)$. $\{\mathbf{X} \leq \mathbf{x} \}$ is an abbreviation for the event $\{\omega \in \Omega \spacevert \mathbf{X}(w) \leq \mathbf{x}\}$.
\end{remark}

\begin{lemma}
The joint distribution function $F_{X, Y}$ of the random vector $(X, Y)$ has the following properties:
\begin{enumerate}[(a)]
    \item $\lim_{x, y\to -\infty} F_{X, Y}(x, y) = 0, \lim_{x,y\to\infty} F_{X, Y}(x,y) = 1$,
    \item if $(x_1, y_1) \leq (x_2, y_2)$, then $F_{X,Y}(x_1, y_1) \leq F_{X, Y}(x_2, y_2)$,
    \item $F_{X,Y}$ is continuous from above, in that
    \begin{equation*}
        F_{X,Y}(x+u, y+v) \to F_{X,Y}(x,y) \quad as \quad u, v \downarrow 0.
    \end{equation*}
\end{enumerate}
\end{lemma}

\subsection{Marginalization}
\begin{gather*}
    \lim_{y\to\infty} F_{X,Y} = F_X(x) = \Prob(X \leq x), \\
    \lim_{x\to\infty} F_{X,Y} = F_Y(y) = \Prob(Y \leq y).
\end{gather*}
The functions $F_X$ and $F_Y$ are called the ``marginal" distribution functions of $F_{X,Y}$. $F_{X,Y}$ can determine two marginals $F_X$ and $F_Y$, but \textbf{converse is NOT true}.

\subsection{Discrete and continuous distribution}
\begin{definition}
The random variables $X$ and $Y$ on the probability space $\{ \Omega, \mathcal{F}, \Prob \}$ are called \textbf{(jointly) discrete} if the vector $(X, Y)$ takes values in some \textbf{countable} subset of $\R^2$ only. The jointly discrete random variables $X, Y$ have \textbf{joint (probability) mass function} $f : \R^2 \to [0,1]$ given by $f(x, y) = \Prob(X = x, Y = y)$.
\end{definition}

\begin{definition}
The random variables $X$ and $Y$ on the probability space $\{ \Omega, \mathcal{F}, \Prob \}$ are called \textbf{(jointly) continuous} if their joint distribution function can be expressed as
\begin{equation*}
    F_{X,Y}(x,y) = \int_{u = -\infty}^x \int_{v = -\infty}^y f(u,v)du dv \qquad x, y\in\R,
\end{equation*}
for some \textbf{integrable} function $f : \R^2 \to [0, \infty)$ called the \textbf{joint (probability) density function} of the pair $(X, Y)$.
\end{definition}

\end{document}


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

\begin{document}

\setcounter{chapter}{7}

\chapter{The Einstein field equations}

\setcounter{section}{5}

\section{Exercises}

\textbf{3}

(a) Calculate in geometrized units:

(i) the Newtonian potential of the Sun at its surface
%
\begin{displaymath}
  \phi =
 -G M_\Sun / R_\Sun \approx
 -\SI{1.476e3}{m} / \SI{6.960e8}{m} \approx
  \num{-2.12e-6}
\end{displaymath}

(ii) the Newtonian potential of the Sun at the radius of Earth's orbit
%
\begin{displaymath}
  \phi =
 -G M_\Sun / \SI{1}{AU} \approx
 -\SI{1.476e3}{m} / \SI{1.496e11}{m} \approx
  \num{-9.866e-9}
\end{displaymath}

(iii) the Newtonian potential of the Earth at its surface
%
\begin{displaymath}
  \phi =
 -G M_\Earth / R_\Earth \approx
 -\SI{4.434e-3}{m} / \SI{6.371e6}{m} \approx
  \num{-9.660e-10}
\end{displaymath}

(iv) the Earth's orbital velocity

Here I use the result from part (c), and find that
%
\begin{displaymath}
  v =
  \sqrt{-\phi} \approx
  \num{9.933e-5}
\end{displaymath}

(b) If the potential due to the Sun at Earth's orbital radius is greater than the Earth's potential at its surface (as is shown above), then why do we feel the Earth's gravity more than the Sun's?

We don't feel the potential directly, we feel the gravitational acceleration it produces. Acceleration is obtained from the potential via $\vb{a} = -\grad\phi$, and in the case of a circular orbit in a Newtonian potential:
%
\begin{displaymath}
  a =
 -\grad\phi =
 -\pdv{r} (-G M / r) =
 -G m / r^2 =
  \phi / r.
\end{displaymath}
%
So in the two cases mentioned, we need to divide by the radius once more, to obtain the acceleration.
%
\begin{align*}
  a_\Sun &=
  \phi_\Sun / \SI{1}{AU} \approx
  \SI{-6.595e-20}{\per\meter}
  \\
  a_\Earth &=
  \phi_\Earth / R_\Earth \approx
  \SI{-1.092e-16}{\per\meter}
\end{align*}
%
As you can see, the acceleration due to the Earth is greater by a factor of $10^4$.

(c) Show that a circular orbit in a Newtonian potential has an orbital velocity $v^2 = -\phi$.

We saw above that $a = \phi / r$, and we also know that centripetal acceleration is given by $a = -v^2 / r$. Equating the two we get $v^2 = -\phi$.

\textbf{8}

(a) Show that $\tensor{R}{^\alpha_{\beta\mu\nu}} = \eta^{\alpha\sigma} R_{\alpha\beta\mu\nu} + \order*{[h_{\alpha\beta}]^2}$.

\begin{align*}
  \tensor{R}{^\alpha_{\beta\mu\nu}} &=
  g^{\alpha\sigma} R_{\sigma\beta\mu\nu} =
  (\eta^{\alpha\sigma} + h^{\alpha\sigma}) R_{\sigma\beta\mu\nu} =
  \eta^{\alpha\sigma} R_{\sigma\beta\mu\nu} + h^{\alpha\sigma} R_{\sigma\beta\mu\nu}
  \\
  h^{\alpha\sigma} R_{\sigma\beta\mu\nu} &=
  \frac{1}{2} h^{\alpha\sigma}
  (h_{\sigma\nu,\beta\mu} + h_{\beta\mu,\sigma\nu} -
   h_{\sigma\mu,\beta\nu} - h_{\beta\nu,\sigma\mu}) =
  \order*{[h_{\alpha\beta}]^2}
\end{align*}

(b) Find $R_{\alpha\beta}$ to first order in $h_{\mu\nu}$.

\begin{align*}
  \tensor{R}{^\alpha_{\beta\mu\nu}} &\approx
  \eta^{\alpha\sigma} R_{\sigma\beta\mu\nu}
  \\
  \tensor{\delta}{^\mu_\alpha} \tensor{R}{^\alpha_{\beta\mu\nu}} &\approx
  R_{\beta\nu} \approx
  \tensor{\delta}{^\mu_\alpha} \eta^{\alpha\sigma} R_{\sigma\beta\mu\nu} \approx
  \eta^{\mu\sigma} R_{\sigma\beta\mu\nu}
\end{align*}

(c) Show that $g_{\alpha\beta} R = \eta_{\alpha\beta} \eta^{\mu\nu} R_{\mu\nu} + \order*{[h_{\alpha\beta}]^2}$.

\begin{align*}
  R &=
  g^{\mu\nu} R_{\mu\nu} =
  (\eta^{\mu\nu} + h^{\mu\nu}) R_{\mu\nu} =
  \eta^{\mu\nu} R_{\mu\nu} + \eta^{\mu\gamma} \eta^{\nu\lambda} R_{\mu\nu} =
  \eta^{\mu\nu} R_{\mu\nu} + \order*{[h_{\alpha\beta}]^2}
  \\
  g_{\alpha\beta} R &=
  g_{\alpha\beta} \eta^{\mu\nu} R_{\mu\nu} + \order*{[h_{\alpha\beta}]^2} =
  (\eta_{\alpha\beta} + h_{\alpha\beta})
  \eta^{\mu\nu} R_{\mu\nu} + \order*{[h_{\alpha\beta}]^2} =
  \eta_{\alpha\beta} \eta^{\mu\nu} R_{\mu\nu} + \order*{[h_{\alpha\beta}]^2}
\end{align*}

(d) Use this to show that $G_{\alpha\beta} = R_{\alpha\beta} - \frac{1}{2} \eta_{\alpha\beta} R$.

\begin{displaymath}
  G_{\alpha\beta} =
  R_{\alpha\beta} - \frac{1}{2} g_{\alpha\beta} R =
  R_{\alpha\beta} - \frac{1}{2} (\eta_{\alpha\beta} \eta^{\mu\nu} R_{\mu\nu}) =
  R_{\alpha\beta} - \frac{1}{2} \eta_{\alpha\beta} R
\end{displaymath}

(e) Now use this to simplify the calculation of Equation 8.32.

I got stuck here. I began by expanding the expression in (d) using the results from previous sections, shown in Figure \ref{fig:ch8-problem8e-i}. Then I expanded Equation 8.32, to get it in a more similar form, in Figures \ref{fig:ch8-problem8e-ii} and \ref{fig:ch8-problem8e-iii}. I did this with the hope of matching terms in the two equations, but was only able to match one. I believe something that would help me get further is Equation 8.33, $\tensor{\bar{h}}{^{\mu\nu}_{,\nu}} = 0$.

\begin{figure}[ht]
  \centering
  \begin{subfigure}[b]{0.8\textwidth}
    \includegraphics[width=\textwidth]{img/ch8_problem_8e_part3}
    \caption{}
    \label{fig:ch8-problem8e-i}
  \end{subfigure}

  \begin{subfigure}[b]{0.5\textwidth}
    \includegraphics[width=\textwidth]{img/ch8_problem_8e_part1}
    \caption{}
    \label{fig:ch8-problem8e-ii}
  \end{subfigure}
  ~
  \begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{img/ch8_problem_8e_part2}
    \caption{}
    \label{fig:ch8-problem8e-iii}
  \end{subfigure}
  \caption{Incomplete solution to Problem 8.8 (e)}
\end{figure}

\textbf{9}

(a)

% I start this by making a simplification on Equation 8.32, by using Equation 8.33. In 8.32 we have the term $\tensor{\bar{h}}{_{\mu\nu}^{,\mu\nu}}$. If we can get this into the form of 8.33, we can cancel it out. This is easy to show
% %
% \begin{displaymath}
%   \tensor{\bar{h}}{_{\mu\nu}^{,\mu\nu}} =
%   \eta^{\mu\alpha} \eta^{\nu\beta} \tensor{\bar{h}}{_{\mu\nu,\mu\nu}} =
%   \tensor{\bar{h}}{^{\alpha\beta}_{,\alpha\beta}} = 0.
% \end{displaymath}
% %
% So Equation 8.32 then becomes
% %
% \begin{displaymath}
%   G_{\alpha\beta} =
%  -\frac{1}{2} [
%     \tensor{\bar{h}}{_{\alpha\beta,\mu}^{,\mu}} -
%     \tensor{\bar{h}}{_{\alpha\mu,\beta}^{,\mu}} -
%     \tensor{\bar{h}}{_{\beta\mu,\alpha}^{,\mu}} +
%     \order*{[h_{\alpha\beta}]^2}
%   ]
% \end{displaymath}

I start by making a slight rewrite of Equation 8.32, changing the second $\bar{h}$ term.
%
\begin{displaymath}
  \eta_{\alpha\beta} \tensor{\bar{h}}{_{\mu\nu}^{,\mu\nu}} =
  \eta_{\alpha\beta} \eta^{\mu\alpha} \tensor{\bar{h}}{_{\mu\nu,\alpha}^{,\nu}} =
  \tensor{\bar{h}}{_{\beta\nu,\alpha}^{,\nu}}
\end{displaymath}
%
So now the Einstein tensor can be written as
%
\begin{displaymath}
  G_{\alpha\beta} =
 -\frac{1}{2} [
    \tensor{\bar{h}}{_{\alpha\beta,\mu}^{,\mu}} +
    \tensor{\bar{h}}{_{\beta\nu,\alpha}^{,\nu}} -
    \tensor{\bar{h}}{_{\alpha\mu,\beta}^{,\mu}} -
    \tensor{\bar{h}}{_{\beta\mu,\alpha}^{,\mu}} +
    \order*{[h_{\alpha\beta}]^2}
  ].
\end{displaymath}
%
For $G_{00}$ we then have
%
\begin{align*}
  G_{00} &=
 -\frac{1}{2} [
    \tensor{\bar{h}}{_{00,\mu}^{,\mu}} +
    \tensor{\bar{h}}{_{0\nu,0}^{,\nu}} -
    \tensor{\bar{h}}{_{0\mu,0}^{,\mu}} -
    \tensor{\bar{h}}{_{0\mu,0}^{,\mu}} +
    \order*{[h_{00}]^2}
  ]
  \\ &=
 -\frac{1}{2} [
    \tensor{\bar{h}}{_{00,\mu}^{,\mu}} -
    \tensor{\bar{h}}{_{0\mu,0}^{,\mu}} +
    \order*{[h_{00}]^2}
  ]
  \\ &=
 -\frac{1}{2} [
    (\tensor{\bar{h}}{_{00,0}^{,0}} + \tensor{\bar{h}}{_{00,i}^{,i}}) -
    (\tensor{\bar{h}}{_{00,0}^{,0}} + \tensor{\bar{h}}{_{0i,0}^{,i}}) +
    \order*{[h_{00}]^2}
  ]
  \\ &=
 -\frac{1}{2} [
    \tensor{\bar{h}}{_{00,i}^{,i}} -
    \tensor{\bar{h}}{_{0i,0}^{,i}} +
    \order*{[h_{00}]^2}
  ],
\end{align*}
%
which contains no second time derivatives. For $G_{0i}$ I encountered a problem:
%
\begin{align*}
  G_{0i} &=
 -\frac{1}{2} [
    \tensor{\bar{h}}{_{0i,\mu}^{,\mu}} +
    \tensor{\bar{h}}{_{i\nu,0}^{,\nu}} -
    \tensor{\bar{h}}{_{0\mu,i}^{,\mu}} -
    \tensor{\bar{h}}{_{i\mu,0}^{,\mu}} +
    \order*{[h_{0i}]^2}
  ]
  \\ &=
 -\frac{1}{2} [
    \tensor{\bar{h}}{_{0i,\mu}^{,\mu}} -
    \tensor{\bar{h}}{_{0\mu,i}^{,\mu}} +
    \order*{[h_{0i}]^2}
  ]
  \\ &=
 -\frac{1}{2} [
    (\tensor{\bar{h}}{_{0i,0}^{,0}} + \tensor{\bar{h}}{_{0i,j}^{,j}}) -
    \tensor{\bar{h}}{_{0\mu,i}^{,\mu}} +
    \order*{[h_{0i}]^2}
  ],
\end{align*}
%
which retains a second time derivative in the $\tensor{\bar{h}}{_{0i,0}^{,0}}$ term.

(b)

According to Schutz's solution it is not a contradiction, due in part to Equation 8.33. I don't fully understand the reason, though.

\textbf{11}
Write the gauge transformation and Lorentz gauge condition in four-tensor notation for Maxwell's equations. Draw an analogy with linearized gravity.

First we rewrite $\phi \to \phi - \pdv*{f}{t}$ as $-A_0 \to -A_0 - f_{,0}$, and cancelling the negatives we get $A_0 \to A_0 + f_{,0}$. Combining this with $A_i \to A_i + f_{,i}$, it is obvious that the gauge transformation generalizes to $A_\alpha \to A_\alpha + f_{,\alpha}$.

The Lorentz gauge condition is just slightly less obvious. We start by noting that $A_0 = -\phi$, and therefore (in Minkowski space) $A^0 = \eta^{0\mu} A_\mu = g^{00} A_0 = (-1) (-\phi) = \phi$. Then the Lorentz gauge condition  becomes $\phi_{,0} + \grad_i A^i = \tensor{A}{^0_{,0}} + \tensor{A}{^i_{,i}} = \tensor{A}{^\alpha_{,\alpha}} = 0$. This is analogous to $\tensor{\bar{h}}{^{\mu\nu}_{,\nu}}$.

\textbf{13}
Give a physical justification for $\abs{T^{00}} \gg \abs{T^{0i}} \gg \abs{T^{ij}}$ in a Newtonian system.

The first inequality is easy to see. $T^{00} = E / V = p^0 / V$, and $T^{0i} = p^i / V$. In the Newtonian limit, $\abs{p^0} \gg \abs{p^i}$, and so it follows that $\abs{T^{00}} \gg \abs{T^{0i}}$.

The second inequality is less obvious. In the Newtonian limit, forces must be relatively small, or else objects would be accelerated to relativistic speeds. By this argument, the stresses must also be relatively small, and so $T^{0i} \gg T^{ij}$.

\textbf{17}

(a) First I need to convert the orbital period into meters.
%
\begin{displaymath}
  T =
  \SI{200}{days} \times
  \frac{\SI{24}{hours}}{\SI{1}{day}} \times
  \frac{\SI{3600}{seconds}}{\SI{1}{hour}} \times
  c \approx
  \SI{5.18e15}{\meter}
\end{displaymath}
%
Then I use the potential to find the speed, which I relate to the circumference and orbital period, and solve for the mass.
%
\begin{gather*}
  \phi = -G M / r
  \\
  v^2 = -\phi
\end{gather*}
\begin{align*}
  M &= v^2 r / G = C^3 / (2 \pi T^2 G) \approx
  (\SI{6e11}{\meter})^3 / (2 \pi (\SI{5.18e15}{\meter})^2 G)
  \\ &\approx
  \SI{1.281e3}{\meter} \times \frac{1 M_\Sun}{\SI{1.476e3}{m}} \approx
  0.868 M_\Sun
\end{align*}

(b)

Using the above formula, I get a distribution of mass estimates, shown in Figure \ref{fig:ch8-problem17b}. Closer to the black hole, the Newtonian approximation breaks down, and the ``effective mass'' blows up. Far from the black hole, we can see that the effective mass is in agreement for all of the sattelites, and so the Newtonian approximation is working again. Thus, I use the furthest sattelite to find that the black hole's mass is $68 M_\Sun$.

\begin{figure}[ht]
  \centering
  \includegraphics[width=0.6\textwidth]{img/ch8_problem_17b}
  \caption{Black hole mass estimates in Problem 8.17, as a function of sattelite circumference.}
  \label{fig:ch8-problem17b}
\end{figure}

\end{document}


\chapter{Cryptol prelude functions}

\commentout{
\begin{code}
primsPlaceHolder=1;
\end{code}
}

\paragraph*{Bitwise and logical operations}
\begin{Verbatim}
    True, False : Bit
    &&, ||, ^   : {a} (Logic a) => a -> a -> a
    ~           : {a} (Logic a) => a -> a
    ==>, /\, \/ : Bit -> Bit -> Bit
\end{Verbatim}
\paragraph*{Comparisons}
\begin{Verbatim}
    ==, !=           : {a} (Eq a) => a -> a -> Bit
    <, >, <=, >=     : {a} (Cmp a) => a -> a -> Bit
    <$, >$, <=$, >=$ : {a} (SignedCmp a) => a -> a -> Bit
    min, max         : {a} (Cmp a) => a -> a -> a
    ===, !==         : {a, b} (Eq b) => (a -> b) -> (a -> b) -> a -> Bit
\end{Verbatim}
\paragraph*{Arithmetic}
\begin{Verbatim}
    +, -, *           : {a} (Ring a) => a -> a -> a
    negate            : {a} (Ring a) => a -> a
    fromInteger       : {a} (Ring a) => Integer -> a
    ^^                : {a, e} (Ring a, Integral e) => a -> e -> a
    abs               : {a} (Cmp a, Ring a) => a -> a
    /, %              : {a} (Integral a) => a -> a -> a
    toInteger         : {a} (Integral a) => a -> Integer
    lg2               : {n} (fin n) => [n] -> [n]
    /$, %$            : {n} (fin n, n >= 1) => [n] -> [n] -> [n]
    carry             : {n} (fin n) => [n] -> [n] -> Bit
    scarry, sborrow   : {n} (fin n, n >= 1) => [n] -> [n] -> Bit
    zext              : {m, n} (fin m, m >= n) => [n] -> [m]
    sext              : {m, n} (fin m, m >= n, n >= 1) => [n] -> [m]
    ratio             : Integer -> Integer -> Rational
    /.                : {a} (Field a) => a -> a -> a
    recip             : {a} (Field a) => a -> a
    floor             : {a} (Round a) => a -> Integer
    ceiling           : {a} (Round a) => a -> Integer
    trunc             : {a} (Round a) => a -> Integer
    roundAway         : {a} (Round a) => a -> Integer
    roundToEven       : {a} (Round a) => a -> Integer
\end{Verbatim}
\paragraph*{GF(2) polynomial arithmetic}
\begin{Verbatim}
    pdiv  : {u, v} (fin u, fin v) => [u] -> [v] -> [u]
    pmod  : {u, v} (fin u, fin v) => [u] -> [1 + v] -> [v]
    pmult : {u, v} (fin u, fin v) => [1 + u] -> [1 + v] -> [1 + u + v]
\end{Verbatim}
\paragraph*{Sequences}
\begin{Verbatim}
    take      : {front, back, a} (fin front) => [front + back]a -> [front]a
    drop      : {front, back, a} (fin front) => [front + back]a -> [back]a
    #         : {front, back, a} (fin front) => [front]a -> [back]a -> [front + back]a
    join      : {parts, each, a} (fin each) => [parts][each]a -> [parts * each]a
    split     : {parts, each, a} (fin each) => [parts * each]a -> [parts][each]a
    groupBy   : {each, parts, a} (fin each) => [parts * each]a -> [parts][each]a
    transpose : {rows, cols, a} [rows][cols]a -> [cols][rows]a
    reverse   : {n, a} (fin n) => [n]a -> [n]a
    head      : {n, a} [1 + n]a -> a
    tail      : {n, a} [1 + n]a -> [n]a
    last      : {n, a} (fin n) => [1 + n]a -> a
\end{Verbatim}
\paragraph*{Indexing, updates}
\begin{Verbatim}
    @       : {n, a, ix} (Integral ix) => [n]a -> ix -> a
    !       : {n, a, ix} (fin n, Integral ix) => [n]a -> ix -> a
    @@      : {n, k, ix, a} (Integral ix) => [n]a -> [k]ix -> [k]a
    !!      : {n, k, ix, a} (fin n, Integral ix) => [n]a -> [k]ix -> [k]a
    update     : {n, a, ix} (fin ix) => [n]a -> [ix] -> a -> [n]a
    updateEnd  : {n, a, ix} (fin n, Integral ix) => [n]a -> ix -> a -> [n]a
    updates    : {n, k, ix, a} (Integral ix, fin k) => [n]a -> [k]ix -> [k]a -> [n]a
    updatesEnd : {n, k, ix, a} (fin n, Integral ix, fin k) => [n]a -> [k]ix -> [k]a -> [n]a
\end{Verbatim}
\paragraph*{Shifting, rotating}
\begin{Verbatim}
    >>>, <<< : {n, ix, a} (fin n, Integral ix) => [n]a -> ix -> [n]a
    >>, <<   : {n, ix, a} (Integral ix, Zero a) => [n]a -> ix -> [n]a
    >>$      : {n, ix} (fin n, n >= 1, Integral ix) => [n] -> ix -> [n]
\end{Verbatim}
\paragraph*{Functional programming}
\begin{Verbatim}
    iterate  : {a} (a -> a) -> a -> [inf]a
    repeat   : {n, a} a -> [n]a
    map      : {n, a, b} (a -> b) -> [n]a -> [n]b
    zip      : {n, a, b} [n]a -> [n]b -> [n](a, b)
    zipWith  : {n, a, b, c} (a -> b -> c) -> [n]a -> [n]b -> [n]c
    foldl    : {n, a, b} (fin n) => (a -> b -> a) -> a -> [n]b -> a
    foldl' : {n, a, b} (fin n, Eq a) => (a -> b -> a) -> a -> [n]b -> a
    foldr    : {n, a, b} (fin n) => (a -> b -> b) -> b -> [n]a -> b
    foldr' : {n, a, b} (fin n, Eq b) => (a -> b -> b) -> b -> [n]a -> b
    scanl    : {n, b, a} (b -> a -> b) -> b -> [n]a -> [1 + n]b
    scanr    : {n, a, b} (fin n) => (a -> b -> b) -> b -> [n]a -> [1 + n]b
    sum : {n, a} (fin n, Eq a, Ring a) => [n]a -> a
    product : {n, a} (fin n, Eq a, Ring a) => [n]a -> a
    and, or  : {n} (fin n) => [n] -> Bit
    all, any : {n, a} (fin n) => (a -> Bit) -> [n]a -> Bit
    curry    : {a, b, c} ((a, b) -> c) -> a -> b -> c
    uncurry  : {a, b, c} (a -> b -> c) -> (a, b) -> c
    elem     : {n, a} (fin n, Eq a) => a -> [n]a -> Bit
\end{Verbatim}
\paragraph*{Miscellaneous}
\begin{Verbatim}
    deepseq : {a, b} Eq a => a -> b -> b
    rnf : {a} Eq a => a -> a
    length : {n, a, b} (fin n, Literal n b) => [n]a -> b
    zero    : {a} (Zero a) => a
\end{Verbatim}
\paragraph*{Representing exceptions}
\begin{Verbatim}
    undefined : {a} a
    error     : {a, n} (fin n) => String n -> a
    assert    : {a, n} (fin n) => Bit -> String n -> a -> a
    trace     : {n, a, b} [n][8] -> a -> b -> b
    traceVal  : {n, a} [n][8] -> a -> a
\end{Verbatim}
\todo[inline]{\texttt{error} and \texttt{undefined} are not covered in
  the book at the moment.}

\todo[inline]{What is the state of debugging (\texttt{trace},
  \texttt{ASSERT}), randomness (\texttt{random}), and pretty-printing
  (\texttt{format}) built-ins?}
%\paragraph*{Debugging}
%\begin{Verbatim}
%    trace  : {a b c} ([a][8],b,c) -> c
%    ASSERT : {a b} (Bit,[a][8],b) -> b
%\end{Verbatim}
%\paragraph*{Generating random numbers}
%\begin{Verbatim}
%    random : {a b} (32 >= a) => [a] -> b
%\end{Verbatim}
%\paragraph*{Pretty printing}
%\begin{Verbatim}
%    format
%\end{Verbatim}

%    (%$) : {a} (Arith a) => a -> a -> a
%    (/$) : {a} (Arith a) => a -> a -> a
%    number : {val, rep} (Literal val rep) => rep
%    elem : {n, a} (fin n, Cmp a) => a -> [n]a -> Bit
%    fromThenTo :
%      {first, next, last, a, len} (fin first, fin next, fin last,
%                                   Literal first a, Literal next a, Literal last a, first != next,
%                                   lengthFromThenTo first next last == len) =>
%        [len]a
%    fromTo :
%      {first, last, a} (fin last, last >= first, Literal last a) =>
%        [1 + (last - first)]a
%    fromZ : {n} (fin n, n >= 1) => Z n -> Integer
%    infFrom : {a} (Arith a) => a -> [inf]a
%    infFromThen : {a} (Arith a) => a -> a -> [inf]a
%    splitAt :
%      {front, back, a} (fin front) =>
%        [front + back]a -> ([front]a, [back]a)
%    toInteger : {bits} (fin bits) => [bits] -> Integer
%    trace : {n, a, b} (fin n) => [n][8] -> a -> b -> b
%    traceVal : {n, a} (fin n) => [n][8] -> a -> a
%    undefined : {a} a
%    zext : {m, n} (fin m, m >= n) => [n] -> [m]
%    sext : {m, n} (fin m, m >= n, n >= 1) => [n] -> [m]
%    carry : {n} (fin n) => [n] -> [n] -> Bit
%    scarry : {n} (fin n, n >= 1) => [n] -> [n] -> Bit
%    sborrow : {n} (fin n, n >= 1) => [n] -> [n] -> Bit

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


\chapter{Complete UFC code for Poisson's equation}
\index{Poisson's equation}
\index{example code}

In this section, a simple example is given of UFC code generated by
the form compilers
FFC~\cite{www:ffc,logg:article:07,logg:article:09,logg:article:10,logg:article:11}
and SyFi~\cite{www:syfi} for Poisson's equation. The code presented
below is generated for the bilinear form of Poisson's equation for
standard continuous piecewise linear Lagrange finite elements on a
two-dimensional domain $\Omega$,
\begin{equation}
  a(v, u) = \int_{\Omega} \nabla v \cdot \nabla u \dx.
\end{equation}

Although FFC and SyFi are two different form compilers, with very
different approaches to code generation, both generate code that
conforms to the UFC specification and may thus be used interchangeably
within any UFC-based system.

In the generated code, we have omitted the two functions
\texttt{evaluate\_basis} and
\texttt{evaluate\_basis\_derivatives}\footnotemark{} to save space.

\footnotetext{For FFC, this may be done by using the compiler flags
  \texttt{-fno-evaluate\_basis} and
  \texttt{-fno-evaluate\_basis\_derivatives}.}

\section{Code generated by FFC}
\index{FFC}

\scriptsize
\VerbatimInput[frame=single,rulecolor=\color{blue}]{code/poisson_ffc.h}
\normalsize

\section{Code generated by SyFi}
\index{SyFi}

In the following we list the complete code for the finite element,
the dofmap and the variational form for computing a stiffness matrix
based on linear Lagrangian elements in 2D.

The code below is generated for the assembler in PyCC and it therefore
includes some PyCC files, since the option \texttt{SFC.options.include\_from = "pycc"} was used during the code generation. If PyCC is not present, the option \texttt{SFC.options.include\_from = "syfi"} can be used, and this will result in some additional files that define the numbering scheme.

\subsection{Header file for linear Lagrange element in 2D}

\scriptsize
\VerbatimInput[frame=single,rulecolor=\color{blue}]{code/stiffness_syfi/fe_Lagrange_1_2D.h}
\normalsize

\subsection{Source file for linear Lagrange element in 2D}
\scriptsize
\VerbatimInput[frame=single,rulecolor=\color{blue}]{code/stiffness_syfi/fe_Lagrange_1_2D.cpp}
\normalsize

\subsection{Header file for the dofmap}
\scriptsize
\VerbatimInput[frame=single,rulecolor=\color{blue}]{code/stiffness_syfi/dof_map_Lagrange_1_2D.h}
\normalsize

\subsection{Source file for the dofmap}
\scriptsize
\VerbatimInput[frame=single,rulecolor=\color{blue}]{code/stiffness_syfi/dof_map_Lagrange_1_2D.cpp}
\normalsize

\subsection{Header file for the stiffness matrix form}
\scriptsize
\VerbatimInput[frame=single,rulecolor=\color{blue}]{code/stiffness_syfi/form__stiffness_form__Lagrange_1_2D.h}
\normalsize

\subsection{Source file for the stiffness matrix form}
\scriptsize
\VerbatimInput[frame=single,rulecolor=\color{blue}]{code/stiffness_syfi/form__stiffness_form__Lagrange_1_2D.cpp}
\normalsize


\section{Monad's Approach}
\label{sec::solution}

Our monadic data structure operates as a wrapper which carries our extra behaviour and shrouds our original transformation's application $h(f(4, "test"), g("test", 4.0))$; the aforementioned technique holds beneficial features because it lets us to chain further operations, mixes them and later determines which calculation we evaluate at runtime.

\writecode{java}
    {__code/monad_solution.kt}
    {Monad's generic implementation in Kotlin}
\label{fig::solution::monad::example}

This approach provides us with adaptability at the expense of loquacity; we have to improve the method of applying our function h with a less convenient lambda nesting arrangement. Some functional languages permit us to manage this behaviour with syntactic sugar such as a do notation.

\writecode{haskell}
    {__code/better.hs}
    {Alternative calling method in with do notation in Haskell}
\label{fig::better::haskell}

We can also decorate our initial operation with another new behaviour by using a chain of bind function calls, or we can apply our initial computation multiple times.

\writecode{kotlin}
    {__code/composing_computation.kt}
    {Composing computations with bind function}
\label{fig::composition::monad}

Composing monads of different types with a map function will allow us to convert between the bind calls the type of additional computation we are expecting.

\begin{equation}
    map :: a \rightarrow b \rightarrow (M N a \rightarrow M N b)
\end{equation}

\begin{equation}
    map :: map_M \cdot map_N
\end{equation}

Flexibility is the primary advantage of using monads over aspects; we can easily extend our monads to generate new computation or add additional computations on top of our bind function.

Computer Science Research Methodologies/R03 MCSI Paper/sections/monad.tex


\documentclass{article}

\usepackage{mathrsfs,amssymb,amsmath,amsfonts}

\newcommand*\conj[1]{\overline{#1}}

\begin{document}

\section{Let $e_0, e_1, ...$ be an orthonormal basis for $\mathscr{H}$ and let $\alpha_0, \alpha_1, ...$ be complex numbers. Define $\mathscr{D} = \{ h \in \mathscr{H} :  \sum_{0}^{\infty} | \alpha_n \langle h, e_n \rangle |^2 < \infty \}$ and let $Ah= \sum_{0}^{\infty} \alpha_n \langle h, e_n \rangle e_n$ for $h$ in $\mathscr{D}$. Then $A \in \mathscr{C}(\mathscr{H})$ with dom $A=\mathscr{D}$. Also, dom $A^*=\mathscr{D}$ and $A^*h=\sum_{0}^{\infty} \conj{\alpha_n} \langle h, e_n \rangle e_n$ for all $h$ in $\mathscr{D}$}

Exercise X.1.2: Prove claims in X.1.9

Since Hilbert Spaces in the chapter are assumed to be separable, to show that $\mathscr{D}$ is dense we must show that for every $h \in \mathscr{H}$, there exists a sequence $h_{\bullet}$ in $\mathscr{D}$ that converges to $h$. Let $h = \sum_{0}^{\infty} \beta_n e_n$ where all but finite number of $\beta_n$ are 0. ???

Next we have to show that $A$ is closed, that is $\{ h \oplus Ah : h \in \mathscr{D}\}$ is closed in $\mathscr{H} \oplus \mathscr{H}$. Again since $\mathscr{H}$ is separable, this amounts to showing that the limit of an arbitrary sequence $h_{\bullet}$ of $\mathscr{D}$ is still in $h \oplus Ah$. Again not sure where to go from here.

To show that $A^*h=\sum_{0}^{\infty} \conj{\alpha_n} \langle h, e_n \rangle e_n$, start with $\langle Ah, k \rangle = \langle h, A^*k \rangle$.

$ \langle \sum_{0}^{\infty} \alpha_n \langle h, e_n \rangle e_n, k \rangle$

\end{document}


\documentclass{tufte-handout}

\usepackage{xcolor}
\usepackage{graphicx}

% set hyperlink attributes
\hypersetup{colorlinks}

\usepackage{amsmath}

% ============================================================

% define the title
\title{SOC 4930/5050: Week 10 Equations}
\author{Christopher Prener, Ph.D.}
\date{October 30\textsuperscript{th}, 2017}
% ============================================================
\begin{document}
% ============================================================
\maketitle % generates the title
% ============================================================

\vspace{5mm}
\section{Pearson's r}
\begin{subequations}
\paragraph{Calculating r}
\begin{equation}
\scalebox{2} {$ r =\frac { \sum _{ i=1 }^{ n }{ (x-\overline { x } )(y-\overline { y } ) }  }{ (n-1){s}_{x}{s}_{y} } $}
\end{equation}

\vspace{3mm}
\paragraph{Percent of Variance Explained}
\begin{equation}
\scalebox{2} {$ {r}^{2} $}
\end{equation}

\vspace{3mm}
\paragraph{Calculating Degrees of Freedom (v)}
\begin{equation}
\scalebox{2} {$ v=n-2 $}
\end{equation}

\vspace{3mm}
\paragraph{Calculating t}
\begin{equation}
\scalebox{2} {$ t=\frac{r}{\sqrt{\frac{1-{r}^{2}}{v}}} $}
\end{equation}
\end{subequations}

% ============================================================
\end{document}


\documentclass[12pt]{article}
\usepackage{amsmath}

\title {Jacobian Free Newton's Method for Non-Linear Systems with Composit Residual Functions via MAUD}

\begin{document}

\maketitle

\section{Problem Definition}

Composite resids arise when solving a non-linear system whos residual evaluation is a function of two
or more different components. For example, consider a non linear system with state variable vector, $u$, and
residual vector, $r$, computed via two components, $Y$ and $R$. Assume $u$ and $r$ are of size $n$.

\begin{equation}
  u \longrightarrow Y \longrightarrow y \longrightarrow R \longrightarrow r
\end{equation}

$y$ and $r$ are explicit functions of $u$ and $y$ respectively

\begin{align}
  y = & Y(u) \notag \\
  r = & R(y)
\end{align}

A composite residual function, $G$, is then defined

\begin{equation}
  G(u) = R(Y(u))
\end{equation}

The problem definition is then given as follows

\begin{align}
  Find &\  u \notag \\
  s.t. &\  G(u) = 0
\end{align}

\section{Traditional Newtons Method}

The Newton update, $\Delta u$, is computed via
\begin{equation}
  \frac{\partial G}{\partial u} \Delta u = -G(u)
\end{equation}

Expanding the partial derivative of $G$ out to account for the composite residual function
gives

\begin{equation}
  \frac{\partial R}{\partial y}  \frac{\partial Y}{\partial u} \Delta u = -R\left(Y(u)\right)
  \label{expanded_newton_iter}
\end{equation}

In order to compute $\Delta u$, the partial derivatives
$\frac{\partial R}{\partial y}$ and  $\frac{\partial Y}{\partial u}$ must first be computed.
Then a matrix multiplication is performed ($\mathcal{O}(n^3)$) to get $\frac{\partial G}{\partial u}$.
Lastly the solution to a size $n$ linear system is found.

\section{MAUD Formulation}

Representing the composite residual as a system of non linear equations using the MAUD yeilds
two separate, but coupled, residual functions with $y$ and $r$ as state variables
and $u$ as an input.

\begin{align}
  A(u,y,r) & = y - Y(u) \label{MAUD_y} \\
  B(u,y,r) & = r - R(y) \label{MAUD_r}
  \label{maud1}
\end{align}

The original problem formulation seeks to drive $r$ to 0. So we'll just assume
that $r$ is 0, then find values of $u$ and $y$ that drive
the remaining resids to 0. This gives a new system of equations:

\begin{align}
  C(u,y) & = y - Y(u) = 0 \label{y_resid} \\
  D(r,y) & = R(y) = 0 \label{r_resid}
  \label{maud2}
\end{align}

You can compute a Newton update for the non-linear system via

\begin{equation}
  \begin{bmatrix}
    \frac{\partial C}{\partial u} & \frac{\partial C}{\partial y} \\
    \frac{\partial D}{\partial u} & \frac{\partial D}{\partial y}
  \end{bmatrix}
  \begin{bmatrix}
    \Delta u \\
    \Delta y
  \end{bmatrix}
  =
  \begin{bmatrix}
    -C(u,y) \\
    -D(u,y)
  \end{bmatrix}
\end{equation}

\begin{equation}
  \begin{bmatrix}
    -\frac{\partial Y}{\partial u} & 1 \\
    0 & \frac{\partial R}{\partial y}
  \end{bmatrix}
  \begin{bmatrix}
    \Delta u \\
    \Delta y \\
  \end{bmatrix}
  =
  \begin{bmatrix}
    Y(u) - y \\
    - R(y)
  \end{bmatrix}
\end{equation}

Expanding out the linear system yields

\begin{align}
  -\frac{\partial Y}{\partial u} \Delta u + \Delta y & = Y(u) - y   \label{Delta_u} \\
  \frac{\partial R}{\partial y} \Delta y & = -R(y)   \label{Delta_y}
\end{align}

Multiplying both sides by of Eqn.~\ref{Delta_u} by $\frac{\partial R}{\partial y}$ yields

\begin{equation}
  -\frac{\partial R}{\partial y} \frac{\partial Y}{\partial u} \Delta u + \frac{\partial R}{\partial y} \Delta y = Y(u) - y
\end{equation}

Now, assuming that you always executed $Y$ first and then $R$, you know that $Y(u) - y$ will always be identically 0.

\begin{equation}
  -\frac{\partial R}{\partial y} \frac{\partial Y}{\partial u} \Delta u + \frac{\partial R}{\partial y} \Delta y = 0
  \label{newton_update_1}
\end{equation}

Finally, substituting Eqn.~\ref{Delta_y} into Eqn.~\ref{newton_update_1} yeilds

\begin{equation}
  \frac{\partial R}{\partial y} \frac{\partial Y}{\partial u} \Delta u = -R(y)
  \label{maud_Delta_u_update}
\end{equation}

We now note that Eqn.~\ref{maud_Delta_u_update} and Eqn.~\ref{expanded_newton_iter} are equivalent, hence
the resulting $\Delta u$ value computed via the traditional method and the MAUD method are also
equivalent.

However, the MAUD provides a computational savings. The partial derivatives $\frac{\partial R}{\partial y}$
and $\frac{\partial Y}{\partial u}$ must still be computed. But the newton update, $\Delta u$ can now be found
directly via a single solution to a linear system of size $n$ without the expensive matrix
multiplication step needed with the traditional method.

\end{document}