\input{SingleAssignmentSetup.tex}
\input{../WeekTitles.tex}
\begin{document}

\begin{center}
\subsection*{MNTC P01 - Week \#4 - \WeekTitleFour}
\end{center}

\begin{enumerate}[1.]
\subsection*{Distance And Velocity}

\begin{multicols}{2}
%*****************
\item
  \begin{Question}
    The graph below shows the velocity, $v$, of an object (in
    meters/sec). Estimate the total distance the object traveled
    between $t = 0$ and $t = 6$.

\includegraphics[width=0.7\linewidth]{graphics/Week04_DistanceAndVelocity/Velocity_1}

  \end{Question}
  \begin{Solution}
    Just counting the squares (each of which has area representing 10
    (m/s)$\cdot$(s) = 10 m of distance), and allowing for the partial
    squares, we can see that the area under the curve from $t=0$ to
    $t=6$ is between 140 and 150 units.  Therefore the distance
    traveled is between 140 and 150 meters.
  \end{Solution}

%*****************
\item
  \begin{Question}
    The figure below shows the velocity of a particle, in cm/sec,
    along the $t$-axis for $-3 \le t \le 3$ ($t$ in seconds).
    \begin{enumerate}
    \item Describe the motion in words. Is the particle changing
      direction or always moving in the same direction? Is the
      particle speeding up or slowing down?
    \item Make over- and underestimates of the distance traveled for
      $-3 \le t \le 3$.
    \end{enumerate}

\includegraphics[width=0.7\linewidth]{graphics/Week04_DistanceAndVelocity/Velocity_2}
  \end{Question}
  \begin{Solution}
    \begin{enumerate}[(a)]
    \item The velocity is always positive, so the particle is moving
      in the same direction throughout.  However, the particle is
      speeding up until shortly before $t=0$, and slowing down
      thereafter.
    \item The distance traveled is represented by the area under the
      curve.  Using whole grid squares, we can overestimate the area
      as 3+3+3+3+2+1 = 15 squares, and we can underestimate the area
      as 1+2+2+1+0+0= 6 squares.  Each square represents 1
      (cm/sec)$\cdot$(s) = 1 cm, so the particle moved in one
      direction between 6 and 15 cm.

    \end{enumerate}

  \end{Solution}

%*****************
  \begin{Question}
For questions \ref{q:graph1_start} to \ref{q:graph1_end}, the graph
  shows the velocity, in cm/sec, of a particle moving along the
  $x$-axis. Compute the particle's change in position, left (negative)
  or right (positive), between times $t = 0$ and $t = 5$ seconds.
\end{Question}

\item ~\\\label{q:graph1_start}
  \begin{Question}

\includegraphics[width=0.4\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity1}
  \end{Question}

  \begin{Solution}
    The velocity is constant and negative, so the change in position is $-3 \cdot 5$ cm, that is 15 cm to the left.
  \end{Solution}

%*****************
\item ~\\
  \begin{Question}

\includegraphics[width=0.4\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity2}
  \end{Question}

  \begin{Solution}
    From $t = 0$ to $t = 3$, the velocity is constant and positive, so
    the change in position is $2 \cdot 3$ cm, that is 6 cm to the right. \\
    From $t = 3$ to $t = 5$, the velocity is negative and constant, so
    the
    change in position is $3 \cdot 2$ cm, that is 6 cm to the left.  \\
    Thus the total change in position is 0. The particle moves 6 cm to
    the right, followed by 6 cm to the left, and returns to where it
    started.
  \end{Solution}

%******************
\item ~ \\
  \begin{Question}
\includegraphics[width=0.4\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity3}
  \end{Question}

  \begin{Solution}
    From $t = 0$ to $t = 5$ the velocity is positive so the change in
    position is to the right. The area under the velocity graph gives
    the distance traveled. The region is a triangle, and so has area
    $(1/2)bh = (1/2)5 \cdot 10 = 25$. Thus the change in position is 25 cm
    to the right.
  \end{Solution}

%******************
\item  ~ \\\label{q:graph1_end}
  \begin{Question}
\includegraphics[width=0.4\linewidth]{graphics/Week04_DistanceAndVelocity/ParticleVelocity4}
  \end{Question}

  \begin{Solution}
    From $t = 0$ to $t = 4$ the velocity is positive so the change in
    position is to the right. The area under the velocity graph gives
    the distance traveled. The region is a triangle, and so has area
    $(1/2)bh = (1/2)4\cdot 8 = 16$. Thus the change in position is 16 cm
    to the right for$ t = 0$ to $t = 4$.

    From $t = 4$ to $t = 5$, the velocity is negative so the change in
    position is to the left. The distance traveled to the left is
    given by the area of the triangle, $(1/2)bh = (1/2)1\cdot 2 =
    1$.

    Thus the total change in position is $16-1= 15$ cm to the
    right.
  \end{Solution}

%*****************
\item
\begin{Question}
 A car going 80 ft/s ( about 90 km/h) brakes to a stop in five seconds. Assume the deceleration is constant.
 \begin{enumerate}
 \item Graph the velocity against time, $t$, for $0 \le t \le 5$ seconds.
 \item Represent, as an area on the graph, the total distance traveled
   from the time the brakes are applied until the car comes to a stop.
 \item Find this area and hence the distance traveled.
% \item Now find the total distance traveled using antidifferentiation.
 \end{enumerate}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}
    \item  ~\\
\includegraphics*[width=0.8\linewidth]{graphics/Week04_DistanceAndVelocity/graph_car_decel}
\item The total distance is represented by the shaded region $A$, the area under the graph of $v(t)$.
\item $A$ is a triangle, so its area is
$$A = \frac{1}{2} \mbox{(base)(height)} = \frac{1}{2} (5 \mbox{ sec})(80 \mbox{ ft/s}) = 200 \mbox{ ft}$$
%\item
    \end{enumerate}

  \end{Solution}

%******************
\item
  \begin{Question}
     A baseball thrown directly upward at 96 ft/sec has velocity $v(t) = 96 - 32t$ ft/ sec at time $t$ seconds.
     \begin{enumerate}[(a)]
\item Graph the velocity from $t = 0$ to $t = 6$.
\item When does the baseball reach the peak of its flight? How high does it go?
\item How high is the baseball at time $t = 5$?
     \end{enumerate}
  \end{Question}
  \begin{Solution}
    \begin{enumerate}[(a)]
    \item  See the figure below.

\includegraphics[width=0.7\linewidth]{graphics/Week04_DistanceAndVelocity/ChangeInPosition_2}

\item The peak of the flight is when the velocity is 0, namely $t =
  3$. The height at $t = 3$ is given by the area under the graph of
  the velocity from $t = 0$ to $t = 3$; see the figure above. The
  region is a triangle of base 3 seconds and altitude 96 ft/sec, so
  the height is $(1/2)3 \cdot 96 = 144$ feet.
\item The velocity is negative from $t = 3$ to $t = 5$, so the motion
  is downward then. The distance traveled downward can be calculated
  by the area of the triangular region which has base of 2 seconds and
  altitude of -64 ft/sec. Thus, the baseball travels $(1/2)2 \cdot 64
  = 64$ feet downward from its peak height of 144 feet at $t =
  3$. Thus, the height at time $t = 5$ is the total change in
  position, $144 - 64 = 80$ feet.
    \end{enumerate}
  \end{Solution}

%******************
\item
  \begin{Question}
    Two cars start at the same time and travel in the same direction
    along a straight road. The graph below gives the velocity, $v$, of
    each car as a function of time, $t$. Which car:
  \begin{enumerate}[(a)]
  \item Attains the larger maximum velocity?
  \item Stops first?
  \item Travels farther?
  \end{enumerate}
\includegraphics[width=0.7\linewidth]{graphics/Week04_DistanceAndVelocity/CarVelocity1}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item Car A has the largest maximum velocity because the peak of
      car A's velocity curve is higher than the peak of B's.
    \item Car A stops first because the curve representing its
      velocity hits zero (on the $t$-axis) first.
    \item Car B travels farther because the {\bf area} under car B's
      velocity curve is the larger, and area under the velocity graph
      reprsents distance.
    \end{enumerate}
  \end{Solution}

%******************
\item
  \begin{Question}
    Two cars travel in the same direction along a straight road. The graph below shows the velocity, $v$, of each car at time $t$. Car B starts 2 hours after car A and car B reaches a maximum velocity of 50 km/ hr.
    \begin{enumerate}[(a)]
    \item For approximately how long does each car travel? \item
      Estimate car A's maximum velocity. \item Approximately how far
      does each car travel?
    \end{enumerate}
\includegraphics[width=0.7\linewidth]{graphics/Week04_DistanceAndVelocity/CarVelocity2}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item Since car B starts at $t = 2$, the tick marks on the
      horizontal axis (which we assume are equally spaced) are 2 hours
      apart. Thus car B stops at $t = 6$ and travels for 4 hours.  Car
      A starts at $t = 0$ and stops at $t = 8$, so it travels for 8
      hours.
    \item Car A's maximum velocity is approximately twice that of car B (50 km/h), so A's max velocity is 100 km/hr.
    \item The distance traveled is given by the area of under the
      velocity graph. Using the formula for the area of a triangle,
      the distances are given by
\begin{align*}
\mbox{Car A travels} &=
\frac{1}{2} \cdot \mbox{Base }\cdot \mbox{Height} \\
& = \frac{1}{2} \cdot 8 \cdot 100 = 400 \mbox{ km} \\
\mbox{Car B travels} &=
\frac{1}{2} \cdot \mbox{Base }\cdot \mbox{Height}\\
& = \frac{1}{2} \cdot 4 \cdot 50 = 100 \mbox{ km}. \\
\end{align*}

    \end{enumerate}
  \end{Solution}

\end{multicols}
\hrulefill
\subsection*{The Definite Integral}

\begin{multicols}{2}
%*****************
\item
  \begin{Question}
    The figure below shows a Riemann sum approximation with $n$ subdivisions to $\ds \int_a^bf(x) dx$.
    \begin{enumerate}
    \item Is it a left- or right-hand approximation? Would the other one be larger or smaller?
    \item What are $a$, $b$, $n$ and $\D x$?
    \end{enumerate}
\includegraphics[width=0.4\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral1}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item Left-hand sum. Right-hand sum would be smaller.
    \item We have $a = 0$, $b = 2$, $n = 6$, $\Delta x = \frac{2}{6} = \frac{1}{3}$.
    \end{enumerate}
  \end{Solution}
%*****************
\item
  \begin{Question}
    Using the figure below, draw rectangles representing each of the
    following Riemann sums for the function $f$ on the interval $0 \le t \le
    8$. Calculate the value of each sum.

\includegraphics[width=0.5\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral2}
\begin{enumerate}[(a)]
\item Left-hand sum with $\D t = 4.$
\item Left-hand sum with $\D t = 2$.
\end{enumerate}
  \end{Question}

  \begin{Solution}
\begin{tabular}{cc}
\includegraphics[width=0.4\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral2_solutions1} &
\includegraphics[width=0.4\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral2_solutions3} \\
(a) & (b) \\
\end{tabular}

(a) The left-hand sum with $n=2$ intervals, or $\D t = 4$: $32 \cdot 4 + 24 \cdot 4$ = 224. \\
(b) Left-hand sum with $n=4$ intervals, or $\D t = 2$: $32 \cdot 2 + 30 \cdot 2 + 24 \cdot 2 + 14 \cdot 2 = 200$. \\

  \end{Solution}
%*****************
\item
  \begin{Question}
    The graph of a function $f(t)$ is given in the figure below.

\includegraphics[width=0.6\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral3}

Which of the following four numbers could be an estimate of $\ds \int_0^1f(t) ~dt$, accurate to two decimal places? Explain how you chose your answer.  \\
%\begin{tabular}{ll}
(a) -98.35   (b) 71.84
(c) 100.12   (d) 93.47
%\end{tabular}
  \end{Question}

  \begin{Solution}
    The graph given shows that $f$ is positive for $0 \le t \le
    1$, so the integral value must be positive: the answer cannot be -98.35.

    Since the graph is contained within a rectangle of height 100 and
    length 1, the answer 100.12 is too large.

    The graph of $f$ is well above the horizontal line y = 80 for
    $0\le t \le 0.95$, so the integral is likely much higher then
    71.84 $<$ 80, so out of the choices given the best estimate
    is 93.47: answer (d).
  \end{Solution}
%*****************
\item
  \begin{Question}
\begin{enumerate}[(a)]
\item What is the area between the graph of $f(x)$ shown below and
  the $x$-axis, between $x = 0$ and $x = 5$?
\item What is $\ds \int_0^5 f(x)~dx$?
\end{enumerate}
\includegraphics[width=0.6\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral4}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item The total area between $f(x)$ and the $x$-axis is the sum of
      the two given areas, so area = 7 + 6 = 13.
\item  To find the integral, we note that from $x = 3$ to $x = 5$, the function lies below the $x$-axis, and hence makes a negative
contribution to the integral. So
$$\ds \int_0^5 f(x)~dx = \int_0^3 f(x)~dx + \int_3^5 f(x)dx = 7 - 6 = 1$$
    \end{enumerate}
  \end{Solution}
%*****************
\item
  \begin{Question}
    \begin{enumerate}[(a)]
    \item On a sketch of $y =\ln(x)$, represent the left Riemann sum
      with $n = 2$ approximating $\ds \int_1^2 \ln(x)~dx$. Write out
      the terms in the sum, but do not evaluate it.
    \item Will this LEFT(4) estimate be an overestimate or an
      underestimate of $\ds \int_1^2 \ln(x)~dx$?
    \end{enumerate}
  \end{Question}
  \begin{enumerate}[(a)]
  \item Below are the left and right sums respectively. \\
\includegraphics[width=0.9\linewidth]{graphics/Week04_TheDefiniteIntegral/Ln_solutions} \\
\begin{align*}
\mbox{ Left sum} & = f(1) \Delta x + f(1.5) \Delta x  \\
& = \underbrace{(\ln1)}_{=0}0.5 + \ln(1.5)0.5 = (\ln 1.5)0.5
\end{align*}
\item Because the $y$ values on the left end of each interval are the
  smallest on that interval, the sum built on them will be an
  underestimate of the exact integral value.
  \end{enumerate}
  \begin{Solution}

  \end{Solution}
%*****************
\item
  \begin{Question}
    Estimate $\ds \int_1^2 x^2~ dx$ using left-hand sum with four
    subdivisions.
  \end{Question}

  \begin{Solution}
 Left-hand sum gives: \\$1^2(1/4) + (1.25)^2(1/4) + (1.5)^2(1/4) + (1.75)^2(1/4) = 1.96875.$

  \end{Solution}
%*****************
\item
  \begin{Question}
    Without computation, decide if
    $\ds \int_0^{2\pi} e^{-x} \sin x~dx$ is positive or
    negative. [Hint: use MATLAB to draw $e^{-x} \sin(x)$ over the
    given interval.]
  \end{Question}

  \begin{Solution}

\includegraphics[width=0.6\linewidth]{graphics/Week04_TheDefiniteIntegral/ExpSin_solutions} \\

Looking at the graph of $y = e^{-x} \sin x$ shown above for
$0 \le x \le 2\pi$, we see that the area, $A_1$, which contributes a
positive amount to the integral
$\ds \int_0^{2 \pi} e^{-x} \sin(x)~dx$, is much larger than the area
$A_2$, which contributes a negative amount to the integral.

Since the positive integral contributions are larger than the
negative, the overall integral $\ds \int_0^{\pi} e^{-x} \sin(x)~dx$ will be {\bf positive}.
  \end{Solution}
%*****************
\item
  \begin{Question}
    \begin{enumerate}[(a)]
    \item Graph $\ds f(x) = \begin{cases} 1-x & \text{ if $0 \le x\le 1$}  \\
x-1 & \text{ if $1 < x\le 2$}  \\
\end{cases}$
\item Find the {\em exact} value of $\ds \int_0^2 f(x)~ dx$ (hint: sketch and see what shapes you get).
\item Calculate the 4-term left Riemann sum approximation to the
  definite integral. How does the approximation compare to the exact
  value?
    \end{enumerate}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item  ~\\
\includegraphics[width=0.9\linewidth]{graphics/Week04_TheDefiniteIntegral/Piecewise_solutions} \\
\item The area is made up of two triangles, with total area of 2 $\times$ (1/2)(1)(1) = 1 square unit.
\item Using $\D x = 1/2$ in the 4-term Riemann sum shown in right-side
  graph above, we have
\begin{align*}
& \mbox{Left hand sum}  \\
&= f(0)\D x + f(0.5)\D x + f(1)\D x + f(1.5)\D x \\
& = 1 \left(\frac{1}{2} \right) + \frac{1}{2} \left(\frac{1}{2} \right) + 0 \left(\frac{1}{2} \right) + \frac{1}{2} \left(\frac{1}{2} \right) \\
&  = 1.
\end{align*} We notice that in this case the approximation is exactly
equal to the exact value of the integral.  This is mostly coincidence
due to the simple shape of $f(x)$.  In general, approximations will
not work out to be exactly the same as the value of the integral.
    \end{enumerate}
  \end{Solution}
%*****************
\item
  \begin{Question}
Using the figure below, find the values of

\begin{tabular}{ll}
(a) $\ds \int_a^b f(x)~dx$ & (b) $\ds  \int_b^c f(x)~dx$ \\
(c) $\ds \int_a^c f(x)~dx$ & (d) $\ds \int_a^c ~|f(x)|~dx$
\end{tabular}

\includegraphics[width=0.6\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral5}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item The area between the graph of $f(x)$ and the $x$-axis
      between $x = a$ and $x = b$ is 13, so $\ds \int_a^bf(x)~dx = 13$.
    \item Since the graph of $f(x)$ is below the x-axis for $b < x <
      c$, $\ds \int_b^c f(x)~ dx = -2$.
\item Since the graph of $f(x)$ is above the $x$-axis for $a < x < b$ and below for $b < x < c$,
$\ds \int_a^c f(x)~dx = 13 - 2 = 11$.
\item The graph of $|f(x)|$ is the same as the graph of $f(x)$, except
  that the part {\em below} the $x$-axis is reflected to be {\em
    above} it (see graph of $|f(x)|$ below).  Thus $\ds \int_a^c
  |f(x)|~ dx = 13 + 2 = 15$.

\includegraphics[width=0.6\linewidth]{graphics/Week04_TheDefiniteIntegral/AbsValue_solutions}
    \end{enumerate}
  \end{Solution}
%*****************
\item
  \begin{Question}
    Given the figure below, and the statement that $\ds \int_{-2}^0 f(x)~dx = 4$, estimate

\begin{tabular}{ll}
(a) $\ds \int_0^2 f(x)~dx$ & (b) $\ds  \int_{-2}^2 f(x)~dx$ \\
(c) The total shaded area.
\end{tabular}

\includegraphics[width=0.6\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral6}
  \end{Question}

  \begin{Solution}
    The region shaded between $x = 0$ and $x = 2$ appears to have
    approximately the same area as the region shaded between $x = -2$
    and $x = 0$, but it lies below the axis. Since $\ds \int_{-2}^0 f(x)~dx = 4$, we
    have the following results:
    \begin{enumerate}
    \item $\ds \int_0^2f(x)~dx \approx  \mbox{ negative of }\int_{-2}^0 f(x)~dx =-4$
    \item  $\ds \int_{-2}^2 f(x)~ dx \approx 4 - 4 = 0$.
    \item  The total area shaded is approximately 4 + 4 = 8.
    \end{enumerate}
  \end{Solution}
%*****************
\item
  \begin{Question}
    \begin{enumerate}[(a)]
    \item Using the graph below, find $\ds \int_{-3}^0 f(x)~dx$.
\item If the area of the shaded region is $A$, estimate $\ds \int_{-3}^4 f(x)~ dx$.
    \end{enumerate}
\includegraphics[width=0.9\linewidth]{graphics/Week04_TheDefiniteIntegral/DefiniteIntegral7}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}
    \item $\ds \int_{-3}^0 f(x)~dx = -2$: counting squares or
      computing areas of the triangles and rectangles in this region.
    \item We break the integral over the interval $x=-3\ldots 5$ into
      pieces, each of which we can find the areas of.
\begin{align*}
 \int_{-3}^4 f(x)~dx & = \int_{-3}^0 f(x)~dx + \int_{0}^3 f(x)~dx + \int_{3}^4 f(x)~dx \\
& = -2 + 2 - \frac{A}{2} \\
&= \frac{-A}{2}
\end{align*}
    \end{enumerate}
  \end{Solution}

%*****************
\item
  \begin{Question}
    Find the exact value of $\ds \int_0^{2\pi} \sin \theta d\theta$
    without calculation (i.e. from a sketch).
  \end{Question}

  \begin{Solution}
\includegraphics[width=0.6\linewidth]{graphics/Week04_TheDefiniteIntegral/Sine_solutions}

From the graph of sine above, and the fact that the integral includes
a complete $[0, 2\pi]$ cycle, it is clear from symmetry that the
positive and negative contributions to the integral must be equal, so
$$\int_0^{2 \pi} \sin(\theta)~d\theta = 0$$
  \end{Solution}
%*****************
\item
  \begin{Question}
    The width, in feet, at various points along the fairway of a hole
    on a golf course is given in the figure below. If one pound of
    fertilizer covers 200 square feet, use a LEFT estimate the amount
    of fertilizer needed to fertilize the fairway.

\includegraphics[width=0.9\linewidth]{graphics/Week04_TheDefiniteIntegral/GolfHole}
  \end{Question}

  \begin{Solution}
    We approximate the area of the playing field by using Riemann
    sums. On each 100 m horizontal interval, we use the width printed at the left end of the
interval as the other dimension.
\begin{align*}
 \mbox{LEFT}(10) = & (0)(100) + 80(100) +  \\
&85(100) +95(100) + \\
&110(100) + 105(100) + \\
&100(100) + 100(100) + \\
&105(100) + 110(100) \\
= & 89,000 \mbox{ sq feet}
\end{align*}

    Thus approximately
    $\ds \frac{89,000 \mbox{ sq. ft.}}{200 \mbox{ sq. ft./lb}} = 445$
    lbs. of fertilizer should be necessary.

  \end{Solution}

\end{multicols}

\hrulefill

\subsection*{Definite Integrals in Modeling}

\begin{multicols}{2}
%*****************
\item
  \begin{Question}
    The rate at which the world's oil is being consumed is
    continuously increasing. Suppose the rate of oil consumption (in
    billions of barrels per year) is given by the function $r = f(t)$,
    where $t$ is measured in years and $t = 0$ is the start of 2004.
    \begin{enumerate}[(a)]
    \item Write a definite integral which represents the total
      quantity of oil used between the start of 2004 and the start of
      2009.
    \item Suppose $r = 32e^{0.05t}$. Using a left-hand sum with five
    subdivisions, find an approximate value for the total quantity of
    oil used between the start of 2004 and the start of 2009.
  \item Interpret each of the five terms in the sum from part (b) in
    terms of oil consumption.
    \end{enumerate}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item Quantity used = $\ds \int^5_0 f(t)~dt$.
\item Using a left sum, our approximation is
\begin{align*}&32e^{0.05(0)}+ 32e^{0.05(1)}+ 32e^{0.05(2)}+ 32e^{0.05(3)}+ 32e^{0.05(4)}  \\
&= 177.270.
\end{align*}
Since $f$ is an increasing function, the left endpoint values of $f$
are lower than anywhere else on the subintervals, so this represents
an underestimate.
\item Each term is a lower estimate of one year's consumption of oil.
    \end{enumerate}
  \end{Solution}

%*****************
\item
  \begin{Question}
    As coal deposits are depleted, it becomes necessary to strip-mine
    larger areas for each ton of coal. The graph below shows the
    number of acres of land per million tons of coal that will be
    defaced during strip-mining as a function of the number of million
    tons removed, starting from the present day.
    \begin{enumerate}[(a)]
    \item Estimate the total number of acres defaced in extracting the
      next 4 million tons of coal (measured from the present
      day). Draw four rectangles under the curve, and compute their
      area.
    \item Re-estimate the number of acres defaced using rectangles
      above the curve.
    \item Combine your answers to parts (a) and (b) to get a better
      estimate of the actual number of acres defaced.
    \end{enumerate}
\includegraphics[width=0.8\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/Coal}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
\item ~\\
\includegraphics[width=1.0\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/Coal_solutions} \\
Using rectangles under the curve, we get
$$\mbox{Acres defaced} \approx (1)(0.2 + 0.4 + 1 + 2) = 3.6 \mbox{ acres.}$$
\item Using rectangles above the curve, we get
$$\mbox{Acres defaced} \approx (1)(0.4 + 1 + 2 + 3.5) = 6.9 \mbox{ acres.}$$
\item The number of acres defaced is between 3.6 and 6.9, so we
  estimate the average, 5.25 acres.
    \end{enumerate}
  \end{Solution}

%*****************
\item
  \begin{Question}
Coal gas is produced at a gasworks. Pollutants in the gas are removed by scrubbers, which become less and less efficient as time goes on. The following measurements, made at the start of each month, show the rate at which pollutants are escaping (in tons/ month) in the gas:
\begin{tabular}{lrrrrrrrr} \hline
Time (months)&0&1&2&3&4&5&6\\ \hline
 Rate pollutants escape&5&7&8&10&13&16&20 \\
(tons/month) & \\ \hline
\end{tabular}
\begin{enumerate}[(a)]
\item Make an overestimate and an underestimate of the total quantity
  of pollutants that escape during the {\bf first month}.
\item Make an overestimate and an underestimate of the total quantity
  of pollutants that escape during the {\bf six months} shown in the table.
\end{enumerate}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item An overestimate is (7 tons/month)$\cdot$ (1 month) = 7 tons. An underestimate is (5 tons/month)$\cdot$(1 month) = 5 tons.
    \item An overestimate is 7+8+10+13+16+20 = 74 tons. An
      underestimate is 5+7+8+10+13+16 = 59 tons.
    \end{enumerate}
  \end{Solution}

%*****************
\item
  \begin{Question}
    The graph below shows the rate of change of the quantity of water
    in a water tower, in liters per day, during the month of April. If
    the tower had 12,000 liters of water in it on April 1, estimate
    the quantity of water in the tower on April 30.

\includegraphics[width=0.8\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/WaterTower2}
  \end{Question}

  \begin{Solution}
    Suppose $V(t)$ represents the total quantity of water in the water
    tower at time $t$, where $t$ is in days since April 1. Then the
    graph shown in the problem is a graph of the volume's rate of
    change, or $\ddt{V}$ or $V'(t)$. By the Fundamental Theorem, the
    change in the volume over the 30 days of April is given by:
$$V(30) - V(0) = \int^{30}_0 V'(t)~dt.$$
This relationship means we can calculate the change in the volume of
water by calculating the area under the curve. Each box represents
about (50 l/d)$\cdot$(6 d) = 300 liters.

\includegraphics[width=0.8\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/WaterTower2_soln}

In the red region, from $t = 0$ to $t = 12$, the graph is below the
$t$ axis, indicating that water is being lost from the tower.  There
is a little more than one
box, but for simplicity we'll call it one square, so roughly $\approx 300$ liters were lost.  \\
From $t = 12$ to $t = 30$ (blue region), there are between 6 and 7
boxes in total
(let's say 6 for simplicity), or roughly +1800 liters. \\
Thus, $$\int^{30}_0 V'(t)~dt \approx 1800 - 300 = 1500$$ This is the
net {\em change} in the volume of water.  Solving for $V(30)$, the
{\em amount} of water on April 30th,
\begin{align*}
V(30) & = V(0) + \int^{30}_0 V'(t)~dt \\
& = 12,000 + 1500 = 13,500 \mbox{ liters.}
\end{align*}
  \end{Solution}

%*****************
\item
  \begin{Question}
    A bicyclist pedals along a straight road with velocity $v$ given
    in the graph below. She starts 5 miles from a lake; positive
    velocities take her away from the lake and negative velocities
    take her toward the lake. When is the cyclist farthest from the
    lake, and how far away is she then?

\includegraphics[width=0.8\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/LakeCyclist}
  \end{Question}

  \begin{Solution}
    Notice that the area of a square on the graph represents (10 mph)$
    \cdot$ (1/6) h = (5/3) miles.

\includegraphics[width=1.0\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/LakeCyclist_solutions}

At $t = 1/3$ hours, $v = 0$. The area between the curve $v$ and the
$t$-axis over the interval $0 \le t \le 1/3$ is $\ds -\int^{1/3}_0 v
~dt \approx \mbox{ one square} = 5/3$ miles.  Since $v$ is negative
here, she is moving toward the lake. Since she starts 5 miles from the
lake at time $t=0$, at $t = 1/3$ she is about 5 - 5/3 = 10/3 miles
from the lake (so closer than when she started).

For $1/3 \le t \le 1$, $v$ is positive, so she is moving away from the
lake.  Her {\em change} in distance from the lake between the times
$t=0$ and the end point $t=1$ is given by
\begin{align*}
\int^1_0 v ~dt & =
\int^{1/3}_0 v ~dt +
\int^1_{1/3} v ~dt \\
& \approx -
\frac{5}{3} + 8 \cdot
\frac{5}{3} =
\frac{35}{ 3} = 11.667 \mbox{ miles,}
\end{align*}
Relative to her starting point of 5 miles at $t=0$, the cyclist is
about 5 + 35/3 = 50/3 = 16.667 miles from the lake at $t=1$.  Since,
starting from the moment $t = 1/3$, she is always moving away from the
lake, the cyclist will be farthest from the lake at the latest
possible time, $t = 1$. The maximal distance at that time equals 50/3
= 16.667 miles.
  \end{Solution}

%*****************
\item
  \begin{Question}
    Height velocity graphs are used by endocrinologists (doctors
    specializing in the study of hormones) to follow the progress of
    children with growth deficiencies. The graph below shows the
    height velocity curves of an average boy and an average girl
    between ages 3 and 18.

\includegraphics[width=0.8\linewidth]{graphics/Week04_DefiniteIntegralsInModeling/HeightVelocity}
\begin{enumerate}[(a)]
\item Which curve is for girls and which is for boys?  Explain how
  you can tell.
\item About how much does the average boy grow between ages 3 and
    10?
  \item The growth spurt associated with adolescence and the onset of
    puberty occurs between ages 12 and 15 for the average boy and
    between ages 10 and 12.5 for the average girl. Estimate the height
    gained by each average child during this growth spurt.
  \item When fully grown, about how much taller is the average man
    than the average woman? (The average boy and girl are about the
    same height at age 3.)
\end{enumerate}

  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item Since men are generally taller than women, the curve with
      the larger area under it is the height velocity of the boys.
      The area under each curve represents the change in growth in
      centimeters.  Therefore, the black curve is for boys, the
      lighter grey one for girls.
    \item Each square below the height velocity curve has area (1 cm/yr) $\cdot$
       1 yr = 1 cm. Counting squares lying below the black curve
      gives about 43 cm. Thus, on average, boys grow about 43 cm
      between ages 3 and 10.
    \item Counting squares lying below the black curve gives about 23
      cm growth for boys during their growth spurt. Counting squares
      lying below the colored curve gives about 18 cm for girls during
      their growth spurt.
    \item We can measure the difference in growth by counting squares
      that lie between the two curves. Between ages 2 and 12.5, the
      average girl grows faster than the average boy. Counting squares
      yields about 5 cm between the colored and black curves for $2 \le
      x \le 12.5$. Counting squares between the curves for $12.5 \le x \le
      18$ gives about 18 squares.  Thus, there is a net increase of
      boys over girls by about 18 - 5 = 13 cm.
    \end{enumerate}
  \end{Solution}

\end{multicols}

\hrulefill

\subsection*{Properties of Definite Integrals}

\begin{multicols}{2}
%*****************
\item
  \begin{Question}
    Without integrating, show that $$2 \le \ds \int_0^2 \sqrt{1 + x^3}
    ~dx \le 6.$$
  \end{Question}

  \begin{Solution}
    Notice that $f(x) = \sqrt{1 + x^3}$ is increasing for $0 \le x \le
    2$, since $x^3$ gets bigger as $x$ increases. This means that,
    looking at the interval [0, 2] over which we are integrating,
    $f(0) \le f(x) \le f(2)$.

For this function, $f(0) = \sqrt{1 +0} = 1$ and $f(2) = \sqrt{1 + 8} = 3$. Thus, the area under
$f(x)$ lies between the area under the line $y = 1$ and the area under
the line $y = 3$ on the interval $0 \le x \le 2$. See the diagram
below.

\includegraphics[width=0.8\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/IntegralBound1_solutions}

That is,
$$\underbrace{1}_h\underbrace{(2 - 0)}_w \le \int^2_0 \sqrt{ 1 + x^3}~dx \le \underbrace{3}_h\underbrace{(2 - 0)}_w$$

  \end{Solution}
%*****************
\item
  \begin{Question}
   Without calculating  the integral, explain why the following statements are false.
   \begin{enumerate}[(a)]
   \item $\ds \int_{-2}^{-1} e^{x^2} ~dx = -3$
   \item $\ds \int_{-1}^{1} \left| \frac{\cos(x+2)}{1 + \tan^2x} \right| ~dx = 0$.
   \end{enumerate}
  \end{Question}

  \begin{Solution}
    (a) The integrand is always positive, so the integral (sum of positive $f(x)$ times positive $\D x$ values) cannot be negative. \\
    (b) The integrand is always $\ge 0$ because of the absolute value
    sign. If the integral = 0, then with a non-negative integrand, the
    integrand must be exactly 0 at every $x$ value on the interval,
    which is definitely not the case here.
  \end{Solution}
%*****************
\item
  \begin{Question}
    Using the graph of $f(x)$ shown below, arrange the following
    quantities in increasing order, from least to greatest.

\includegraphics[width=0.6\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/IntegralRanking}

\begin{tabular}{ll}
(i) $\ds \int_0^1 f(x)~dx $ &
(ii)$\ds \int_1^2  f(x)~dx $ \\
(iii)$\ds \int_0^2  f (x)~dx $ &
(iv) $\ds \int_2^3 f(x)~dx $ \\
(v) $-\ds \int_1^2  f(x)~dx $ &
(vi) The number 0  \\
(vii) The number 20  &
(viii) The number -10
\end{tabular}
  \end{Question}

  \begin{Solution}
    See the figure below.

\includegraphics[width=0.8\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/IntegralRanking_solutions}

Since $\ds \int^1_0 f(x)~dx = A_1$ and
$\ds \int^2_1 f(x)~dx = -A_2$ and
$\ds \int^3_2 f(x)~dx = A_3$, we know that
$$0 < \int^1_0 f(x)~dx < - \int^2_1 f(x)~dx < \int^3_2 f(x)~dx.$$
In addition,
$\ds \int^2_0 f(x)~dx = A_1 - A_2$, which is negative, but smaller in magnitude than
$\ds \int^2_1 f(x)~dx$. Thus
$$\int^2_1 f(x)~dx < \int^2_0 f(x)~dx < 0.$$
The area $A_3$ lies inside a rectangle of height 20 and base 1, so
$A_3 < 20$.   \\
The area $A_2$ lies inside a rectangle below the $x$-axis of
height 10 and width 1, so $-10 < A_2$. Thus:
\begin{center}
(viii) $<$ (ii) $<$ (iii) $<$ (vi) $<$ (i) $<$ (v) $<$ (iv) $<$ (vii).
\end{center}
  \end{Solution}
%*****************
\item
  \begin{Question}
    \begin{enumerate}[(a)]
    \item Use the graph of $y = x e^{-x^2}$ shown below to explain why $\ds \int_{-3}^3 x e^{-x^2} ~dx= 0$.
\begin{center}
\includegraphics[width=0.5\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/xexp_integral}
\end{center}

    \item Find the left-hand sum approximation with $n = 3$ to $\ds
      \int_{0}^3 x e^{-x^2}~dx$. Give your answer to four decimal
      places.
    \item Repeat part (b) for $\ds \int_{-3}^0 x e^{-x^2}~dx$.
    \item Do your answers to parts (b) and (c) add to 0? Explain.
    \end{enumerate}
  \end{Question}

  \begin{Solution}
    \begin{enumerate}[(a)]
    \item Since the function is symmetric around the origin, and the
      interval used is also symmetric across $x=0$, the areas above
      and below the x-axis cancel when we compute the integral. Thus,
$$\ds\int^0_{-3} xe^{-x^2} dx = -
\int^3_0 xe^{-x^2} dx,$$
 $$\mbox{ so } \ds \int^3_{-3} xe^{-x^2} dx =
\underbrace{\int^0_{-3} xe^{-x^2} dx +
\int^3_0 xe^{-x^2} dx}_{\mbox{equal magnitude, opposite signs}} = 0.$$
\item For $0 \le x \le 3$ with $n = 3$, we have $x_0 = 0, x_1 = 1, x_2 = 2, x_3 = 3$, and $\D x = 1$. See the figure below.

\includegraphics[width=0.8\linewidth]{graphics/Week04_PropertiesOfDefiniteIntegrals/xexp_integral_solutions}

\begin{align*}
\mbox{Left sum}& = f(x_0)\D x + f(x_1)\D x + f(x_2)\D x \\
& = 0e^{-0^2} \cdot 1 + 1e^{-(1^2)} \cdot 1 + 2e^{-(2^2)} \cdot 1 \\
& = 0.4045.
\end{align*}
\item For $-3 \le x \le 0$, with $n = 3$, we have $x_0 = -3, x_1 = -2, x_2 = -1, x_3 = 0$, and $\D x = 1$. (See the diagram again.)
\begin{align*}
\mbox{Left sum} & = f(x_0)\D x + f(x_1)\D x + f(x_2)\D x \\
& = -3e^{-(-3)^2}
\cdot 1 - 2e^{-(-2)^2}
\cdot 1 - 1e^{-(-1)^2}
\cdot 1 \\
& = -0.4049. \\
\end{align*}
\item No. The rectangles between $x=-3$ and 0 are not the same size as
  those between $x=0$ and 3. See the diagram.  There are three
  rectangles with nonzero height on [-3, 0] and only two on [0, 3], so
  the estimates computed must be different, so we won't get the exact
  result of zero using left sums.
    \end{enumerate}
  \end{Solution}

\end{multicols}
\hrulefill

\subsection*{Integration By Anti-Derivatives}

\begin{Question}
  To practice computing anti-derivatives, do as many of the
  problems from the following section as you need.

  These problems are a good start for practicing anti-derivatives or
  integration.  If you want more though, consult any calculus
  textbook.
\end{Question}

\begin{Question}
Evaluate the following integrals.
\end{Question}

\item \begin{Question}
  $\ds \int_{-1}^2 (x^3 - 2x) dx$
\end{Question}

\begin{Solution}
  $\ds \int_{-1}^2 (x^3 - 2x) dx = \left[ \frac{x^4}{4} - x^2
    \right]_{-1}^2 = \left( \frac{2^4}{4} - 2^2 \right) - \left( \
      \frac{(-1)^4}{4} - (-1)^2 \right) = (4 - 4) - (\frac{1}{4} - 1) = 0
    - (- \frac{3}{4}) = \frac{3}{4}$
\end{Solution}

\item \begin{Question}
  $\ds \int_{-1}^1 x^{100} dx$
\end{Question}

\begin{Solution}
  $\ds \int_{-1}^1 x^{100} dx = \left[ \frac{1}{101} x^{101}
    \right]_{-1}^{1} = \frac{1}{101} - (- \frac{1}{101}) =
    \frac{2}{101}$
\end{Solution}

\item \begin{Question}
  $\ds \int_{1}^4 (5 - 2t +3t^2) dt$
\end{Question}

\begin{Solution}
  $\ds \int_1^4 (5 - 2t - 3t^2) dt = [5t - t^2 + t^3]_1^4 =
    (20 - 16 + 64) - (5 - 1 + 1) = 68 - 5 = 63$
\end{Solution}

\item \begin{Question}
  $\ds \int_0^1 (1 + \frac{1}{2} u^4 - \frac{2}{5} u^9) du$
\end{Question}

\begin{Solution}
  $\int_0^1 (1 + \frac{1}{2} u^4 - \frac{2}{5} u^9) du =
    [u + \frac{1}{10} u^5 - \frac{1}{25} u^10]_0^1 =
    (1 + \frac{1}{10} - \frac{1}{25}) - 0 = \frac{50 + 5 - 2}{50} = \frac{53}{50}$
\end{Solution}

\item \begin{Question}
  $\ds \int_1^9 \sqrt{x} dx$
\end{Question}

\begin{Solution}
  $\ds \int_1^9 \sqrt{x} dx = \int_1^9 x^{1 / 2} dx =
    \left[ \frac{x^{3 / 2}}{3 / 2} \right]_1^9 =
    \frac{2}{3} \left[ x^{2 / 3} \right]_1^9 =
    \frac{2}{3} (9^{3 / 2} - 1^{3 / 2}) =
    \frac{2}{3} (27 - 1) = \frac{52}{3}$
\end{Solution}

\item \begin{Question}

  $\ds \int_1^8 x^{-2 / 3} dx$
\end{Question}

\begin{Solution}

  $\ds \int_1^8 x^{-2 / 3} dx =
    \left[ \frac{x^{1 / 3}}{1 / 3} \right]_1^8 =
    3 \left[ x^{1 / 3} \right]_1^8 =
    3(8^{1 / 3} - 1^{1 / 3}) = 3(2 - 1) = 3$

\end{Solution}

\item \begin{Question}

  $\ds \int_{\pi / 6}^{\pi} \sin \theta d \theta$
\end{Question}

\begin{Solution}
  $\ds \int_{\pi / 6}^{\pi} \sin \theta d \theta =
    \left[ - \cos \theta \right]_{\pi / 6}^{\pi} =
    - \cos \pi - ( - \cos \frac{\pi}{6} ) =
    -(-1) - (- \sqrt{3} / 2) = 1 + \sqrt{3} / 2$
\end{Solution}

\item \begin{Question}

  $\ds \int_{-5}^5 e~ dx$
\end{Question}

\begin{Solution}
  The number $e$ is just a constant.

    $\ds \int_{-5}^5 e ~dx = [e x]_{-5}^5 = 5e - (-5e) = 10e$

\end{Solution}

\item \begin{Question}

  $\ds \int_0^1 (u + 2)(u - 3) du$
\end{Question}

\begin{Solution}
  You need to expand the product before you can integrate.

    $\ds \int_0^1 (u + 2)(u - 3) du = \int_0^1 (u^2 - u - 6) du = \left[
      \frac{1}{3} u^3 - \frac{1}{2} u^2 - 6u \right]_0^1 =
    \left(\frac{1}{3} - \frac{1}{2} - 6 \right) - 0 = - \frac{37}{6}$
\end{Solution}

  \item \begin{Question}
  $\ds \int_0^4 (4 - t) \sqrt{t} ~dt$
\end{Question}

\begin{Solution}
To evaluate this integral, you need to expand the product first; you can't integrate the product $(4-t)\sqrt{t}$ as it is originally written.

  $\ds \int_0^4 (4 - t) \sqrt{t} dt = \int_0^4 (4 - t) t^{1 / 2} dt =
    \int_0^4 (4t^{1 / 2} - t^{3 / 2}) dt =
    \left[ \frac{8}{3} t^{3 / 2} - \frac{2}{5} t^{5 / 2} \right]_0^4 =
    \frac{8}{3} (8) - \frac{2}{5} (32) =
    \frac{320 - 192}{15} = \frac{128}{15}$
\end{Solution}

\item \begin{Question}

  $\ds \int_1^9 \frac{x - 1}{\sqrt{x}} dx$
\end{Question}

\begin{Solution}

  $\ds \int_1^9 \frac{x - 1}{\sqrt{x}} dx =
    \int_1^9 \left( \frac{x}{\sqrt{x}} - \frac{1}{\sqrt{x}} \right) dx
    = \int_1^9 (x^{1 / 2} - x^{-1 / 2}) dx =
    \left[\frac{2}{3} x^{3 / 2} - 2x^{1 / 2} \right]_1^9 =
    (\frac{2}{3} \cdot 27 - 2 \cdot 3) = (\frac{2}{3} - 2) =
    12 - (- \frac{4}{3}) = \frac{40}{3}$
\end{Solution}

\item \begin{Question}

  $\ds \int_0^2 (y - 1)(2y + 1) dy$
\end{Question}

\begin{Solution}

  $\ds \int_0^2 (y - 1)(2y + 1) dy = \int_0^2 (2y^2 - y - 1) dy =
    \left[ \frac{2}{3} y^3 - \frac{1}{2} y^2 - y \right]_0^2 =
    ( \frac{16}{3} - 2 - 2) - 0 = \frac{4}{3}$
\end{Solution}

\item \begin{Question}

  $\ds \int_0^{\pi / 4} \sec^2 t ~dt$
\end{Question}

\begin{Solution}

  $\ds \int_0^{\pi / 4} \sec^2 t ~dt = [\tan t]_0^{\pi / 4} =
    \tan \frac{\pi}{4} - \tan 0 = 1 - 0 = 1$

\end{Solution}

\item \begin{Question}

  $\ds \int_0^{\pi / 4} \sec \theta \tan \theta d \theta$
\end{Question}

\begin{Solution}
  $\ds \int_0^{\pi / 4} \sec \theta \tan \theta d \theta =
    [ \sec \theta ]_0^{\pi / 4} =
    \sec \frac{\pi}{4} - \sec 0 = \sqrt{2} - 1$
\end{Solution}

\item \begin{Question}

  $\ds \int_1^2 (1 + 2y)^2 dy$
\end{Question}

\begin{Solution}
  $\ds \int_1^2 (1 + 2y)^2 dy =
    \int_1^2 (1 + 4y + 4y^2) dy =
    [y + 2y^2 + \frac{4}{3} y^3]_1^2 =
    (2 + 8 + \frac{32}{3}) - (1 + 2 + \frac{4}{3}) =
    \frac{62}{3} - \frac{13}{3} = \frac{49}{3}$
\end{Solution}

\item \begin{Question}

  $\ds \int_0^3 (2 \sin x - e^x) dx$
\end{Question}

\begin{Solution}
  $\ds \int_0^3 (2 \sin x - e^x) dx =
    [-2 \cos 3 - e^3) - (-2 - 1) =
    3 - 2 \cos 3 - e^3$

\end{Solution}

\item \begin{Question}

  $\ds \int_1^2 \frac{v^3 + 3v^6}{v^4} dv$
\end{Question}

\begin{Solution}
  $\ds \int_1^2 \frac{v^3 + 3v^6}{v^4} =
    \int_1^2 \left( \frac{1}{v} + 3v^2 \right) dv =
    [ \ln |v| + v^3]_1^2 =
    ( \ln 2 + 8 ) - ( \ln 1 + 1) =
    \ln 2 + 7$
\end{Solution}

\item \begin{Question}

  $\ds \int_1^{18} \sqrt{\frac{3}{z}} dz$
\end{Question}

\begin{Solution}
  $\ds \int_1^{18} \sqrt{\frac{3}{z}} dz =
    \int_1^{18} \sqrt{3} z^{-1/2} dz =
    \sqrt{3} [ 2z^{1/2} ]_1^{18} =
    2 \sqrt{3} (18^{1/2} - 1^{1/2}) =
    2 \sqrt{3} (3 \sqrt{2} - 1)$
\end{Solution}

\item \begin{Question}

  $\ds \int_0^1 (x^e + e^x) dx$
\end{Question}

\begin{Solution}

  $\ds \int_0^1 (x^e e^x) dx =
    \left[ \frac{x^{e + 1}}{e + 1} + e^x \right]_0^1 =
    \left( \frac{1}{e + 1} + e \right) - (0 + 1) =
    \frac{1}{e + 1} + e - 1$
\end{Solution}

\item \begin{Question}

  $\ds \int_{1 / \sqrt{3}}^{\sqrt{3}} \frac{8}{1 + x^2} dx$
\end{Question}

\begin{Solution}
  $\ds \int_{1 / \sqrt{3}}^{\sqrt{3}} \frac{8}{1 + x^2} dx =
    \left[ 8 \arctan x \right]_{1 / \sqrt{3}}^{\sqrt{3}} =
    8 \left( \frac{\pi}{3} - \frac{\pi}{6} \right) =
    8 \left( \frac{\pi}{6} \right) = \frac{4 \pi}{3}$

\end{Solution}

\item \begin{Question}

  $\ds \int_1^2 \frac{4 + u^2}{u^3} du$
\end{Question}

\begin{Solution}
  $\ds \int_1^2 \frac{4 + u^2}{u^3} du =
    \int_1^2 (4u^{-3} + u^{-1}) du =
    \left[ \frac{4}{-2} u^{-2} + \ln |u| \right]_1^2 =
    \left[ \frac{-2}{u^2} + \ln u \right]_1^2 =
    (-\frac{1}{2} + \ln 2) - (-2 + \ln 1) =
    \frac{3}{2} + \ln 2$
\end{Solution}

\item \begin{Question}

  $\ds \int_{-1}^1 e^{u + 1} du$
\end{Question}

\begin{Solution}
  $\ds \int_{-1}^1 e^{u + 1} du =
    [e^{u + 1}]_{-1}^1 =
    e^2 - e^0 = e^2 - 1$ [or start with $e^{u + 1} = e^u e^1$]
\end{Solution}

\item \begin{Question}

  $\ds \int_{1 / 2}^{1 / \sqrt{2}} \frac{4}{\sqrt{1 - x^2}} dx$
\end{Question}

\begin{Solution}
  $\ds \int_{1/2}^{1 / \sqrt{2}} \frac{4}{\sqrt{1 - x^2}} dx =
    \left[ 4 \arcsin x \right]_{1/2}^{1 / \sqrt{2}} =
    4 \left( \frac{\pi}{4} - \frac{\pi}{6} \right) =
    4(\frac{\pi}{12}) = \frac{\pi}{3}$
\end{Solution}

\item \begin{Question}

$\ds    \int_0^{\pi} f(x) dx \text{ where } f(x) =
    \begin{cases}
      \sin x  & \text{ if } 0 \leq x < \pi / 2 \\
      \cos x  & \text{ if } \pi / 2 \leq x \leq \pi \\
    \end{cases}
   $

\end{Question}

\begin{Solution}
  $\ds \text{If } f(x) =
    \begin{cases}
      \sin x  & \text{ if } 0 \leq x < \pi / 2 \\
      \cos x  & \text{ if } \pi / 2 \leq x \leq \pi \\
    \end{cases}
    $ then

    $\ds \int_{0}^{\pi} f(x) dx =
    \int_0^{\pi/2} \sin x dx + \int_{\pi/2}^{\pi} \cos x dx =
    [ - \cos x]_0^{\pi/2} + [ \sin x ]_{\pi / 2}^{\pi} =
    - \cos \frac{\pi}{2} + \cos 0 + \sin \pi - \sin \frac{\pi}{2} =
    -0 + 1 + 0 - 1 = 0$
\end{Solution}

\item \begin{Question}

$\ds    \int_{-2}^2 f(x) dx \text{ where } f(x) =
    \begin{cases}
      2  & \text{ if } -2 \leq x \leq 0 \\
      4 - x^2 & \text{ if } 0 < x \leq 2 \\
    \end{cases}
  $
\end{Question}

\begin{Solution}
  $\ds \text{If } f(x) =
    \begin{cases}
      2  & \text{ if } -2 \leq x \leq 0 \\
      4 - x^2 & \text{ if } 0 < x \leq 2 \\
    \end{cases}
    $ then

    $\ds \int_{-2}^{2} f(x) dx =
    \int_{-2}^{0} 2 dx + \int_0^2 (4 - x^2) dx =
    [2x]_{-2}^{0} + [4x - \frac{1}{3} x^3 ]_0^2 =
    [0 - (-4)] + (\frac{16}{3} - 0) = \frac{28}{3}$

\end{Solution}

%*******************************
\item
\begin{Question}
    $\int (x^2 + x^{-2}) dx$
\end{Question}

\begin{Solution}
    $\int (x^2 + x^{-2})dx = \frac{x^3}{3} + \frac{x^{-1}}{-1} + C =
      \frac{1}{3} x^3 - \frac{1}{x} + C$

\end{Solution}

%*******************************
\item
\begin{Question}
$\int (\sqrt{x^3} + \sqrt[3]{x^2}) dx$
\end{Question}

\begin{Solution}
  $\int (\sqrt{x^3} + \sqrt[3]{x^2}) dx =
  \int (x^{3/2} + x^{2/3})dx =
  \frac{x^{5/2}}{5/2} + \frac{x^{5/3}}{5/3} + C =
  \frac{2}{5} x^{5/2} + \frac{3}{5} x^{5/3} + C$

\end{Solution}

%*******************************
\item
\begin{Question}
  $\int (x^4 - \frac{1}{2} x^3 + \frac{1}{4} x - 2) dx$
\end{Question}

\begin{Solution}
  $\int (x^4 - \frac{1}{2} x^3 + \frac{1}{4} x - 2) dx = \frac{x^5}{5}
  - \frac{1}{2} \frac{x^2}{4} + \frac{1}{4} \frac{x^2}{2} - 2x + C =
  \frac{1}{5} x^5 - \frac{1}{8} x^4 + \frac{1}{8} x^2 - 2x + C$

\end{Solution}

%*******************************
\item
\begin{Question}
  $\int (u + 4)(2u + 1) du$
\end{Question}

\begin{Solution}
  $\int (u + 4)(2u + 1) du =
  \int (2u^2 + 9u + 4)du =
  2 \frac{u^3}{3} + 9 \frac{u^2}{2} + 4u + C =
  \frac{2}{3} u^3 + \frac{9}{2} u^2 + 4u + c$
\end{Solution}

%*******************************
\item
\begin{Question}
    $\int v (v^2 + 2)^2 dv$

\end{Question}

\begin{Solution}
  $\int v (v^2 + 2)^2 dv = \int v(v^4 + 4v^2 + 4)dv = \int (v^5 + 4v^3
  + 4v)dv = \frac{v^6}{6} + 4 \frac{v^4}{4} + 4 \frac{v^2}{2} + C =
  \frac{1}{6} v^6 + v^4 + 2 v^2 + C$

\end{Solution}

%*******************************
\item
\begin{Question}
    $\int \frac{x^3 - 2 \sqrt{x}}{x} dx$

\end{Question}

\begin{Solution}
  $\int \frac{x^3 - 2 \sqrt{x}}{x} dx =
  \int \left( \frac{x^3}{x} - \frac{2x^{1/2}}{x} \right) dx =
  \int (x^2 - 2x^{-1/2})dx =
  \frac{x^3}{3} - 2 \frac{x^{1/2}}{1/2} + C =
  \frac{1}{3} x^3 - 4 \sqrt{x} + C$
\end{Solution}

%*******************************
\item
  \begin{Question}
    $\int \left( x^2 + 1 + \frac{1}{x^2 + 1} \right) dx$
  \end{Question}

  \begin{Solution}
    $\int \left( x^2 + 1 + \frac{1}{x^2 + 1} \right) dx =
    \frac{x^3}{3} + x + \tan^{-1} x + C$
  \end{Solution}

\hrulefill

\subsection*{Numerical Integration with MATLAB}

\begin{Question}
  In Questions \ref{qmat1}-\ref{qmat2}, consider the integrals which
  were evaluated earlier in the practice problems using anti-derivatives
and the Fundamental Theorem of Calculus.

For each integral, in MATLAB, now use the LEFT$(n)$ rule with $n=1000$
to approximate the value of the integral; this does {\bf not} require
using anti-derivatives.
\end{Question}
\item \begin{Question} \label{qmat1}
  $\ds \int_{-1}^2 (x^3 - 2x) dx$, which equals $\ds \frac{3}{4}$.
\end{Question}

\begin{Solution}
  See the file linked here: \\
  \href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT1.m}{W04LEFT1.m} \\
  Estimate with $n = 1000$ is $\approx 0.7455$.  Exact value is $\frac{3}{4} = 0.75$.
\end{Solution}
% ******************************
\item \begin{Question}
  $\ds \int_{-1}^1 x^{100} dx$, which equals $\ds \frac{2}{101}$.
\end{Question}

\begin{Solution}
See the file linked here: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT2.m}{W04LEFT2.m} \\
  Estimate with $n = 1000$ is $\approx 0.0199$.  Exact value is $\frac{2}{101} = 0.0198$.

\end{Solution}

% ******************************
\item \begin{Question}
  $\ds \int_{1}^4 (5 - 2t +3t^2) dt$, which equals 63.
\end{Question}

\begin{Solution}
See the file linked here: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT3.m}{W04LEFT3.m} \\
  Estimate with $n = 1000$ is $\approx 62.9415$.  Exact value is 63.0000.

\end{Solution}

% ******************************
\item \begin{Question} \label{qmat2}
    $\ds \int_0^1 (1 + \frac{1}{2} u^4 - \frac{2}{5} u^9) du$, which
    equals $\ds \frac{53}{50}$.
\end{Question}

\begin{Solution}
See the file linked here: \\
\href{http://www.mast.queensu.ca/~apsc171/MNTCP01/PracticeProblems/MATLAB/W04LEFT4.m}{W04LEFT4.m} \\
  Estimate with $n = 1000$ is $\approx 1.0599$.  Exact value is $\frac{53}{50} = 1.06$.
\end{Solution}

\end{enumerate}

\end{document}


%-------------------------------------------------------------------------------------------------------------------------------------------------
\section{Genetic Algorithm}
\label{section:GA}
%-------------------------------------------------------------------------------------------------------------------------------------------------
One of the drawbacks of using a Reinforcement Learning strategy is that the training schema can potentially lead to a localized solution space. Such a solution might not have evaluated all possible strategies. This drawback can be countered by using the robustness of methods such as Genetic Algorithms, which carry out more thorough search. We use such a method in order to evolve a Neural Network controller managing the bot in a 1 unit Vs 1 unit fight. This methodology is called \emph{Neuro Evolution} in general.

%-------------------------------------------------------------------------------------------------------------------------------------------------
\subsection{Representation}
Our objective for the neural network is to be able to make informed decisions by interpreting the game state. Hence, a representation for the game state needs to be formulated. This representation needs to be minimal since the number of inputs to the neural network directly correlate to the size of the chromosome to be evolved. In this approach, we use 8 inputs, 4 for each unit involved in the combat:
\begin{enumerate}
\item \emph{Shots to Death} - This heuristics utilizes the fact that all units in the game, at any given time, will be eliminated by a particular opponent unit in certain number of attack commands. This parameter can be used to represent several values at the same time - \emph{Hit-points}, \emph{Armor}, \emph{Opponent's Damage} and \emph{Damage Multiplier}, combined in equation:
\begin{equation}
\label{equation:nShots}
\text{shots}=\left \lceil\frac{\text{HP}}{(\text{damage}\times\text{times}-\text{armor}) \times\text{mul}} \right \rceil \text{,}
\end{equation}
This input is normalized over the maximum value of shots left to death when the game starts (maximum hot-points).
\item \emph{Distance} - This number signifies the distance of the unit from the opponent, which is normalized over its weapon range.
\item \emph{Cooldown Left} - The number of updates left before the unit can shoot again, which is normalized with the largest weapon cooldown time for the two units.
\item \emph{Speed} - The unit's top movement speed possible. This is again normalized by the maximum speed out of the two units.
\end{enumerate}
The neural network can provide 3 output values, each corresponding to an action's desirability ({\bf Move Towards Enemy}, {\bf Move Away from Enemy} or {\bf Attack}). The action with the maximum desirability is performed.

%-------------------------------------------------------------------------------------------------------------------------------------------------
\subsection{Algorithm Parameters}
\begin{enumerate}
\item \emph{Fitness}: The fitness of a particular chromosome is an integer value representing a Win ($1$) or a Loss ($-1$). To average out inaccuracy in fitness due to randomness, each chromosome is tested $20$ times and the fitness is averaged out. An alternate method to judge the fitness of a chromosome is to take an average of difference of hitpoints of the two units at the end of a match.
\item \emph{Choosing parents}: The natural selection method used in this project is Elite Selection. In a population of $N$ chromosomes, each reproduction cycle selects $\frac{N}{3}$ parents for breeding. However the selection method is modified in such a way that the chromosome with the best fitness is always selected (in order to not forget fitness comparison). The rest of the parents selected are uniformly distributed from the top portion of the population and bottom portion. This version is also comparable to the Roulette-Wheel selection methodology, where segments of the total population have certain selection probabilities.
\item \emph{Crossover}: The selected parents reproduce themselves by a simple one point crossover approach. The selection of the split point is normally distributed for each gene.
\item \emph{Mutation}: Each child gets mutated with a predefined mutation probability (standard value used in experiments is $0.2$). It is a recommended strategy to mutate a gene representing neural network connection weight by adding a Gaussian Random number. This enables the weight to be not bound within a particular range and enhance progression in the search space.
\item \emph{Population Refresh}: All newly produced children, two per parent (i.e. $\frac{N}{3}$ parents generate $\frac{N}{3}$ children), automatically replace the $\frac{N}{3}$ chromosomes at the bottom of the population (not replacing if a chromosome which was selected for parenting). The remaining $\frac{N}{3}$ part of the population is completely mutated, meaning that their each gene mutates with a probability of $1.0$.
\item \emph{Optimization}: Genetic Algorithms need a lot of fitness updates, especially in this case where a match to test fitness of a chromosome takes approximately 7 sec. Therefore one performance optimization made for the project is to preserve the fitness value of chromosomes that have not changed. In general, these are the chromosomes that were selected for parenting.
\end{enumerate}

%-------------------------------------------------------------------------------------------------------------------------------------------------
\subsection{Results}
%%%

\begin{table}
\caption{average winning rate}
\begin{center}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{tabular}{|r|r|r|r|}
\hline
       &       {\bf mean }&    {\bf stdev} &  {\bf p-value} \\
\hline
	\emph{8.8.4.3 (ref)} & $  0.025$ &  $ 0.099 $ &        --- \\
\hline
	\emph{ 8.8.3 }&   $0.019$ &  $  0.099 $ & $ 0.459 $ \\
\hline
 	\emph{8.1.3 }&  $ 0.014$ &   $ 0.104 $ & $ 0.094 $ \\
\hline
\end{tabular}
\label{table:winningRate}
\end{center}
\end{table}
% ---------

\begin{enumerate}
\item Neural Network Structure - While designing the agent, one of the things on our mind was for the neural network to be able to process the inputs efficiently and try to decipher the optimal output values. But there is no way to understand the relation of the input values to the playing strategy for the agent. To test what structure of the neural network can achieve the most efficient results for the bot, we run T-tests with $3$ different structures of the network:
\begin{itemize}
\item Inputs (8), Hidden Layer (1), Output Layer (3)
\item Inputs (8), Hidden Layer (8), Output Layer (3)
\item Inputs (8), Hidden Layer (8), Hidden Layer (4), Output Layer (3)
\end{itemize}
The agent is trained in each case for a certain number of iterations (in this case they were trained for $60$ iterations) and then the best chromosome in each pool plays the game to create a sample space to be tested. The results for the T-test carried out on the three samples are presented in Table \ref{table:winningRate}. The samples are compared with respect to the $8,8,4,3$ network. While comparing the network with the $8,8,3$ neural network, the relatively high p-value signifies that they are similar. This means that the using the larger network is an overkill as it provides relatively similar output quality as the smaller network. This, however is not the case with the $8,1,3$ network. The low p-value means that the samples are not similar. Then the decision to select a network falls on the which has a higher success-rate (which is already being measured by the average fitness value of the chromosomes).
\begin{figure}[htp]
\centerline{\includegraphics[width=1.0\columnwidth]{fig_GA_AverageFitness}}
\caption{Graph showing the progression of Average Fitness of population of size $10$, $20$ and $30$, respectively: NN configuration is $8,8,3$}
\label{fig:AverageFitness}
\end{figure}
\item Population Size - We are also interested in finding out the rate of convergence of the Genetic Algorithm, as well as its dependency on the population size. Generally a larger population size is preferred, since the high number of chromosomes provide a bigger search space for the algorithm to find a fit individual in. But this leads to a lot of overhead on the system to process individuals introduced on each iteration in the larger population. To assess this parameter, we look at a comparative Figure \ref{fig:AverageFitness} showing the progression of average fitness of the populations of sizes $10$, $20$ and $30$. The population with size 10 seems to be too small and has slow convergence to the other two populations. The other two populations are very close in average performance and hence a smaller and more efficient population size is selected.
\begin{figure}[htp]
\centerline{\includegraphics[width=1.0\columnwidth]{fig_GA_Fitness_MinAvgMax}}
\caption{Graph showing the minimum, average and maximum fitness of population of size $10$, NN configuration is $8,8,3$}
\label{fig:minAvgMaxFitness}
\end{figure}
\item Fitness Spread - In a genetic algorithm, the reproduction and discard rules are used to introduce new individuals to the population that can spread the solution in a much broader spectrum. This counters the problems provided by other computation intelligence algorithms to get stuck in local minima. A way to test the spread of the population is by graphing the minimum, average and maximum fitness of a population (size = $10$), as shown in Figure \ref{fig:minAvgMaxFitness}. A large distance between the minimum and maximum fitness points to the conclusion that the population is taking care of introducing diverse individuals.
\end{enumerate}

%%%
\begin{figure}[htp]
\centerline{\includegraphics[width=1.0\columnwidth]{fig_GA_Speciation_Top2}}
\caption{Graph of Specie difference between the top two chromosomes}
\label{fig:specieTop2}
\end{figure}
\begin{figure}[htp]
\centerline{\includegraphics[width=1.0\columnwidth]{fig_GA_Speciation_next2}}
\caption{Graph of Specie difference between $2^{nd}$ and $3^{rd}$ ranked chromosomes}
\label{fig:specieNext2}
\end{figure}

%-------------------------------------------------------------------------------------------------------------------------------------------------
\subsection{Discussion}
According to our tests with the network structure and the population size, the best solution for our one versus one approach is a network structure of 8,8,3 and a population size of $20$. Although the bigger network also evolved well, in terms of performance we clearly have to choose the smaller one.
According to the figure \ref{fig:AverageFitness}, the population size of $20$, roughly scores as good as the population size of $30$. When we take the fact, that a smaller population size will evolve $\frac{1}{3}$ faster, into account, we have to chose a population size of $20$.

If we measure the cumulative distance between each gene of the top two candidates in the populations which is depicted in Figure \ref{fig:specieTop2}, we can see that the larger populations in genetic evolution hamper the evolving chances because of higher preservation of the top candidates. This can be attributes to the elite selection methodology we have employed that gives increasingly higher probability to the $1^{st}$ and $2^{nd}$ chromosomes to be selected for parenting.
This pattern becomes much more varied if we calculate the distance between the $2^{nd}$ and $3^{rd}$ chromosomes (Figure \ref{fig:specieNext2}), which depicts the higher chances for the chromosomes on those positions to be mutated.
%%%


\documentclass{article}
\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}

\newtheorem{theorem}{Theorem}[section]
\begin{document}
\title{Eisenstein Triples: Connecting geometry and number theory}
\author{Dave Neary}

\maketitle

\section{A number theory problem}

We start with a number theory puzzle: Can you find positive integer triples $(a,b,c)$ such that:
\[ \frac{1}{a+c} + \frac{1}{b+c} = \frac{3}{a+b+c} \]

To get started with our exploration, let's clear denominators by multiplying across by
$(a+c)(b+c)(a+b+c)$ to get:
\begin{equation*}
\begin{split}
(b+c)(a+b+c) + (a+c)(a+b+c) & = 3(a+c)(b+c) \\
a^2 + b^2 + 2c^2 + 2ab + 3bc + 3ac & = 3ab + 3ac + 3bc + 3c^2 \\
a^2 - ab + b^2 &= c^2
\end{split}
\end{equation*}

Our goal will be to find positive integer solutions to this equation.

\section{A geometric aside}

This equation may look familiar to anyone who has come across the cosine rule in geometry.
For the sides of a triangle $(a,b,c)$ with opposite angles $(A,B,C)$:

\[ c^2 = a^2 + b^2 -2ab\cos(C) \]

with similar equations for $a^2, b^2$.

Rewriting the equation above in this form, we can see that the problem is equivalent to finding
triangles with integer sides $(a,b,c)$ such that $\cos(C) = \frac{1}{2}$ - that is,
$C = \frac{\pi}{3}$. In other words, our challenge is to find triangles with one angle measuring
$60^{\circ}$ which have integer side lengths.

This is a well known problem that has been explored by many number theorists in the past, and
triples of this form are known as Eisenstein triples, named after the mathematician Eisenstein.

By considering the problem as one of triangles with a certain constraint, perhaps we can approach
this problem the way we would approach finding Pythagorean triples.

\section{Factoring sums of squares}

One way to generate Pythagorean triples is to factor $a^2+b^2$ over the Gaussian integers - that is,
the subset of the complex numbers $a+ib$ with $a,b\in \mathbb{Z}$. In the Gaussian integers, we can
rewrite $ a^2 + b^2 = a^2 - b^2i^2$ as a difference of two squares - yielding a factorization:
\[ c^2 = a^2 + b^2 = (a+ib)(a-ib) \]

How does this help? Well, if we take an arbitrary Gaussian integer $z = a+ib$, the length of $z$ is
$|z| = \sqrt{a^2+b^2}$ - so if we take the length of $z^2$, we are guaranteed to get an integer
length, since $|z|^2 = |z^2|$. We will have:
\begin{equation*}
	\begin{split}
		z^2 &= (a+ib)^2 \\
		& = a^2-b^2 + i(2ab) \\
		|z^2| &= \sqrt{(a^2-b^2)^2 + (2ab)^2 }\\
		|z|^2 &= a^2 + b^2 \\
		|z^2| &= |z|^2 \\
		\Rightarrow (a^2-b^2)^2 + (2ab)^2 &= (a^2 + b^2)^2
	\end{split}
\end{equation*}

So if we take \textbf{any} positive integers $(a,b)$, we can generate a Pythagorean triple
$(a^2-b^2, 2ab, a^2+b^2)$ from them.

Can we use a similar approach with our puzzle? Indeed we can!

\section{Factoring the quadratic in $\mathbb{C}$}

We can factor $a^2 - ab + b^2$ in complex numbers too by setting it equal to zero and using
the quadratic formula:
\begin{equation*}
	\begin{split}
		a^2 - ab + b^2 &= 0 \\
		a &= \frac{1}{2}\left(b \pm \sqrt{b^2-4b^2}\right) \\
		&= \frac{b}{2}\left(1 \pm \sqrt{3}i\right)
	\end{split}
\end{equation*}

The factorization is:
\[ a^2 - ab + b^2 =
\left(a + \frac{b}{2}\left(-1 - \sqrt{3}i\right) \right)
\left(a + \frac{b}{2}\left(-1 + \sqrt{3}i\right) \right) \]

If you have done any complex analysis these roots might look familiar to you. Given
$z = \frac{1}{2}(-1+\sqrt{3}i)$ then:
\begin{equation*}
        \begin{split}
		z^2 & = \frac{1}{4}(-1+\sqrt{3}i)^2 \\
		& = \frac{1}{4}(1 - 2\sqrt{3}i - 3) \\
		& = \frac{1}{2}(-1 - \sqrt{3}i) \\
		& = \bar{z}
        \end{split}
\end{equation*}

and:

\begin{equation*}
        \begin{split}
                z^3 & = \frac{1}{8}(-1+\sqrt{3}i)^3 \\
		& = \frac{1}{8}(- 1 + 3\sqrt{3}i +9 -3\sqrt{3}i) \\
                & = 1
        \end{split}
\end{equation*}

These are the cube roots of unity, $\omega = \frac{1}{2}(-1+\sqrt{3}i), \omega^2 = \frac{1}{2}(-1-\sqrt{3}i)$.
One identity of the cube roots that we will use below is that $1 + \omega + \omega^2 = 0$, so
$\omega = -1 -\omega^2$ and $\omega^2 = -1 -\omega$.

We can rewrite our original problem expression as:
\[ c^2 = (a+\omega b)(a + \omega^2 b) \]

Let's try the same trick as we used with Pythagorean triples, and see what happens when we start with
$z = a + \omega b$ for $a,b\in \mathbb{Z}$.

\begin{equation*}
        \begin{split}
		|z| & = \sqrt{(a+\frac{b}{2})^2 + (\frac{\sqrt{3}b}{2})^2} \\
		    &= \sqrt{a^2-ab+b^2}
	\end{split}
\end{equation*}

In general, $|a+ \omega b| = |a + \omega^2 b| = \sqrt{a^2-ab+b^2}$.

\begin{equation*}
        \begin{split}
                z^2 & = a^2 + 2ab\omega +\omega^2 b^2 \\
		z^2 & = a^2 + 2ab\omega +(-1 - \omega) b^2 \\
		    & = (a^2 -b^2) + (2ab - b^2)\omega \\
		|z^2| &= \sqrt{(a^2-b^2)^2 - (a^2-b^2)(2ab-b^2) + (2ab-b^2)^2}
	\end{split}
\end{equation*}

And since $|z^2| = |z|^2$ we get:
\[ (a^2-ab+b^2)^2 = (a^2-b^2)^2 - (a^2-b^2)(2ab-b^2) + (2ab-b^2)^2 \]

So, given any positive integers $(a,b)$, we can generate triples satisfying the equation
$(a^2-b^2, 2ab-b^2, a^2-ab+b^2)$.

Trying some values we find:
\begin{equation*}
        \begin{split}
		(a,b) = (2,1) & \Rightarrow (a^2-b^2, 2ab-b^2, a^2-ab+b^2) = (3, 3, 3) \\
		(a,b) = (3,1) & \Rightarrow (a^2-b^2, 2ab-b^2, a^2-ab+b^2) = (8, 5, 7) \\
		(a,b) = (4,3) & \Rightarrow (a^2-b^2, 2ab-b^2, a^2-ab+b^2) = (7, 15, 13)
	\end{split}
\end{equation*}

We can easily check that $7^2 = 8^2 - (8)(5) + 5^2$ and $13^2 = 7^2 - (7)(15) + 15^2$.

We have a formula to generate an infinite number of triples satisfying our equation $a^2-ab+b^2=c^2$ - nice!
Let's check that they also solve our initial puzzle:

\begin{equation*}
        \begin{split}
		\frac{1}{7+13} + \frac{1}{15+13} & = \frac{1}{20} + \frac{1}{28} \\
		& = \frac{48}{560} \\
		& = \frac{3}{35} \\
		& = \frac{3}{7 + 13 + 15}
        \end{split}
\end{equation*}

\section{A geometric approach}

Does this method yield all possible triples? It is hard to tell, but we have other tools that we can
use to find that answer. Again, we are going to start with a search for Pythagorean triples to
explore this approach.

\begin{figure}[htb]
        \center{\includegraphics[width=0.9 \linewidth]{Pythagorean_circle.png}}
        \caption{Finding rational points with a line of rational slope}
        \label{fig:pyth_circle}
\end{figure}

Replacing $x = \frac{a}{c}, y = \frac{b}{c}$, we can see that finding integer solutions to $a^2 + b^2 = c^2$
is equivalent to finding rational solutions to $x^2 + y^2 = 1$. This is the equation of a circle of radius 1,
centered on the origin.

If we can find a way to find all rational points on the perimeter of the circle, then we will have found all
possible pythagrean triples, up to multiplication by a scalar (since if $a^2 + b^2 = c^2$, then
$(ka)^2 + (kb)^2 = (kc)^2$ for all $k \in \mathbb{Z}$). One way we can do that is to find one rational
point on the circle (say, $(0,-1)$, and draw lines through that point with a rational slope. We can show
that, since the slope of the line is rational, and the equation of the circle has integer coefficients, then
if one intersection point is rational (as it is by design), then the other point must also be rational.

Let's take an example to see how it happens. The line of slope $t$ through $(x,y) = (-1,0)$ is:
\[ y = tx +t\]

Clearly, $(-1,0)$ is on this line. Now, substituting this value of $y$ into the equation of the circle,
$x^2+y^2-1 = 0$, we get:
\[x^2 + (tx+t)^2 -1 = (1+t^2)x^2 +2t^2x + t^2 -1 = 0 \]
And solving for $x$ we get $x = -1$ or $x = \frac{1-t^2}{1+t^2}$. Substituting this value of $x$ back into
our line, we get $y = \frac{2t}{1+t^2}$. We can easily verify that for any value of $t$ that this satisfies
the equation of the circle, as expected. And since $t$ is rational, $x$ and $y$ are guaranteed to be
rational too.

Is it possible, though, that we would somehow miss rational points in the circle by this method?
No - given any rational point $(x,y)$ on the perimeter of the circle, the slope of the line through
$(x,y)$ and $(-1,0)$ is $\frac{y}{x+1}$, which is clearly rational. Since this would be a line with rational
slope which goes through the point $(-1,0)$, we are guaranteed that by enumerating all of the rational
numbers for line slopes, we are guaranteed to hit all of the rational points on the circle.

If we take the slope to be $t = \frac{m}{n}$ for $m,n \in \mathbb{Z}$ we can multiply across the
top and bottom by $n^2$ in the formulas for $x = \frac{1-t^2}{1+t^2}, y = \frac{2t}{1+t^2}$ to give
the Pythagorean triples $a = n^2-m^2, b = 2mn, c = n^2 + m^2$ for the familiar formula we found above.

Taking this approach with our problem, we substitute $x = \frac{a}{c}, y = \frac{b}{c}$ to get the equation:
\[ x^2 - xy + y^2 = 1 \]

\begin{figure}[htb]
        \center{\includegraphics[width=0.9 \linewidth]{Eisenstein_ellipse.png}}
        \caption{Finding rational points with a line of rational slope}
        \label{fig:eisen_ellipse}
\end{figure}

This is an ellipse, centered on the origin, which goes through the points $(0,-1), (0,1), (-1,0), (1,0)$
on the X and Y axis. There are also a few other "nice" rational points on the curve at $(-1,-1), (1,1)$.

Now taking the same approach, given any rational number $t$, we can find the intersection points of our
ellipse and the line $y = t(x+1)$ (which again goes through $(-1,0)$):

\begin{equation*}
        \begin{split}
		x^2 - xy + y^2 & = x^2 - tx(x+1)+t^2(x+1)^2 \\
		&= (1-t+t^2)x^2 +(2t^2-t)x + t^2 \\
		&= 1
	\end{split}
\end{equation*}

Now factoring to find the intersection points, we find, as expected, one of the points at $x=-1$, and
the other is a rational function of $t$:
\begin{equation*}
	\begin{split}
		(1-t+t^2)x^2 + (2t^2-t)x + (t^2-1) &= 0 \\
		(x + 1)((1-t+t^2)x + (t^2 - 1)) = 0
        \end{split}
\end{equation*}

So we have $x = -1$ or $x = \frac{1 - t^2}{1-t+t^2}$ for rational $t$.

Substituting the valie for $x$ back into the equation for the line:
\[ y = t(x+1) = \frac{2t - t^2}{1-t+t^2} \]

And replacing $t = \frac{m}{n}$ and multiplying through with $n^2$ above and below the line we get:
\[(x,y) = \left(\frac{n^2-m^2}{n^2-mn+m^2}, \frac{2nm - m^2}{n^2-mn+ m^2}\right) \]

And clearing a common denominator, we get an integer triple
$(a,b,c) = (n^2 - m^2, 2nm - m^2, m^2 - mn + n^2)$ as before.

A similar argument as before shows that this will find \textbf{all} rational points on the
ellipse, giving all integer solutions to the original problem (after dividing out any common factors
of $a, b, c$).

Interestingly, if we take a different rational point on the ellipse, we will get a different, but
equally valid, formula for generating Eisenstein triples from rational numbers. The equation of
a line through $(-1,-1)$, for example, is $y + 1 = t(x + 1)$. Isolating $y$, and substituting this
into the equation of the ellipse, we get:
\begin{equation*}
        \begin{split}
		x^2 - xy + y^2 - 1 & = x^2 - x(t(x+1)-1) + (t(x+1)-1)^2 - 1\\
		& = x^2 -tx^2 -tx + x + t^2(x^2+2x+1)-2t(x+1)+1 \\
		& = (1 - t + t^2)x^2 + (1 - 3t + 2t^2)x + (t^2-2t) \\
		& = (x+1)((1 - t + t^2)x + (t^2-2t)) = 0
	\end{split}
\end{equation*}

Giving the solutions $x = -1$ or $x = \frac{2t-t^2}{1-t+t^2}$.
Substituting this back into the equation for the line, we get:
\begin{equation*}
        \begin{split}
		y &= t\left(\frac{2t-t^2}{1-t+t^2} + 1\right) - 1 \\
		& = \frac{t^2 + t}{1-t+t^2} - 1 \\
		& = \frac{2t - 1}{1 - t + t^2}
	\end{split}
\end{equation*}

Replacing $t = \frac{m}{n}$, we get:
\[ x = \frac{2mn - m^2}{m^2 - mn + n^2}, y = \frac{2mn - n^2}{m^2 - mn + n^2} \]
Which gives an alternative form for triples of:
\[ (a,b,c) = (2mn - m^2, 2mn - n^2, m^2 -mn + n^2) \]

which, surprisingly perhaps, is exactly equivalent to the formula we found earlier.

\end{document}


\chapter{Acceptance Sampling}
\chaptermark{Acceptance}

% AQL
% LTPD
% RQL
% LQL
% Type A and Type B RO curves.

We can improve quality (read- conformance to specification) by introducing an inspection stage in our process.
Clearly, a full inspection is time consuming.
It may also be destructive (you don't want to re-package ice-cream after checking its texture \dots).
No-inspection may be appropriate if you don't particularly care about your brand, or if production has very high capability indices.
A reasonable, intermediate approach, is a partial random inspection, known as \emph{acceptance sampling}.
As the name suggests, in acceptance sampling, one samples, then checks, then accepts (or not).

Acceptance sampling can be seen as a control chart monitoring that triggers active intervention in the production. As such ,it is a crude type of \emph{engineering control} (Sec.~\ref{sec:terminology_statistical}).
The intervention is obvious. The monitoring is based on some continuous (variable) or discrete (attribute) of a sample of units from a \emph{batch}, \aka, a \emph{lot}.
Seen as a feedback control, it is not surprising that when designing an acceptance sampling scheme, we have similar decisions as when designing a control chart:
\begin{enumerate}
\item What is a batch? Just like choosing the sampling frequency in a Shewart chart.
We would like homogenous batches, i.e., with low inner variability. A box, a shipment, a day's production, are typical batches.
\item Within batch sampling scheme: just like rational grouping in Shewart chart. Typical approaches include \emph{single sampling plans}, \emph{double}, \emph{multiple}, and \emph{sequential sampling plans}.
This can be seen as the design of an experiment to be performed on each batch.
\item How many units? Just like choosing the sample size in a Shewart chart.
\item Decision cutoff: Just like setting control limits in a Shewart chart.
\end{enumerate}
We can readily see that the design of an acceptance sampling scheme is very similar to the design of a control chart.
We may construct an full blown economical optimization problem to design the sampling, as we did in Section~\ref{sec:economical_considerations}. Just like control charts, however, it is more common to design sampling schemes using ``first-order'' power considerations.
For this reason, the \emph{power function} will play a crucial role.

\section{Acceptance Sampling Terminology}
Adapted from \cite{natrella_nist/sematech_2010}.
\begin{description}
\item [LASP] A \emph{lot acceptance sampling plan}, ultimately, a statistical test at the end of which we either accept a batch. In this text we typically use the \emph{batch acceptance sampling scheme} for the same purpose.
\item [AQL] The \emph{acceptable quality level}, or \emph{acceptable quality limit}, is the highest proportion of defects acceptable to the producer.
\item [LTPD] The \emph{lot tolerance percent defective} is the highest proportion of defects acceptable to the consumer. Clearly, $AQL<LTPD$. LTPD is also known as \emph{rejectable quality level} (RQL), and \emph{ limiting quality level} (LQL).
\item [OC Curve] The \emph{operating characteristic curve} is the power function of an LSAP.
\item [Type-A and Type-B OC Curves] A \emph{Type-A OC curve} is one computed assuming sampling from batches is done without replacement. Conversely, a \emph{Type-B OC curve} is computed assuming sampling with replacement.
\item [Producer's Risk] The \emph{producer's risk} is throwing away good batches. Formally, this is the probability of rejecting a batch with less than AQL defects. We consider there type-I errors.
\item [Consumer's Risk] The \emph{consumer's risk} is accepting bad batches. Formally, this is the probability of accepting a batch with more than LTPD defects. We consider there type-II errors.
\item [Rectifying Inspection] An LASP where lots are not rejected but rather rectified.
\end{description}

\section{Single Sampling Scheme}
In the simplest LASP we base our decisions on a single random sample from each batch.
This obviously facilitates the statistical analysis of the properties of this LASP.

\subsubsection{Type-B Power Function}

When sampling $n$ units from a batch with a proportion of $p$ defects, then the number of defects $\x \sim Binom(n,p)$.
If we reject a batch when more than $c$ defects are found, then the power function of a type-B LASP is given by
\begin{align}
\label{eq:power_accpet}
	\pi_{n,c}(p)=P(\x \geq c)= \sum_{k=c}^n \binom{n}{k} p^k (1-p)^{1-k} .
\end{align}
Eq.(\ref{eq:power_accpet}) may be evaluated manually, or with the \rcode{pbinom()} \R function.

Just like any other hypothesis test, it is common practice to set $n,c$ so that control both the consumer's risk ($\beta_{n,c}=1-\pi_{n,c}$) and the producer's risk ($\alpha_{n,c}$).
By adopting a the hypothesis testing philosophy, we solve $n,c$ so that
\begin{align}
\label{eq:power_acceptance}
 \min \set{n : \pi_{n,c}\geq \pi_0 \quad and \quad \alpha_{n,c}\leq \alpha_0 }.
\end{align}
For relating the LASP terminology to this problem, we need to observe that $$\alpha_{n,c}=\pi_{n,c}(p=AQL)$$ and $$\pi_{n,c}=\pi_{n,c}(p=LTPD).$$
For a producer who does not want to reject batches where $AQL=10\%$ defects, with more than $\alpha_0=10\%$;
and a consumer who does not want to accept batches where $LTPD=30\%$, with less than $\pi_0=80\%$,
we have that their LASP would take $n=33$ samples, and reject a batch whenever the $\x>4$, when $n=21$.
\begin{remark}[Approximate Power Calculations]
The problem to solve in Eq.(\ref{eq:power_acceptance}) requires some non trivial iterations because of the discrete nature.
It is quite more convenient to replace the exact form of Eq.(\ref{eq:power_accpet}) with a normal approximation, so that Eq.(\ref{eq:power_acceptance}) has a closed form solution.
\end{remark}

\subsubsection{Type-A Power Function}
It is quite wired that we would sample with replacement from a batch.
It is quite more probable that we used the replacement assumption, only as an approximation because $n$ is small compared to the batch size $N$.
If this is not the case, the binomial distribution in Eq.(\ref{eq:power_accpet}) should be replaced with the Hypergeometric distribution.
For all practical purposes, this means using the \rcode{phyper()} \R function, instead of \rcode{pbinom()}.

\subsection{Double Sampling Scheme}
In a double sampling scheme, we first example $n_1$ units.
We may then decide to accept, reject, or sample another $n_2$ units.
After those $n_2$ samples, we can accept or reject.
The idea of a power function remains the same, even if calculations are slightly more cumbersome.
Here is our our policy:
For $x_1$ computed on the first $n_1$ samples:
If $x_1  < a_1$ then accept the batch;
If $x_1 \geq  c_1$ then reject the batch;
Otherwise, compute $x_2$ with $n_1+n_2$ samples.
If $x_2 < a_2$ accept the batch;
If $x_2 \geq c_2$ then reject the batch.

For brevity, we denote all the design parameters of the scheme by $\gamma:= (n_1,n_2,c_1,c_2,a_1,a_2)$.
The power function of such a scheme would thus be:
\begin{align}
	\pi_\gamma &:= P(\set{\x_1 \geq c_1} \union \set{\x_1 \in [a_1,c_1], \x_2 \geq c_2}) \\
	&= P(\x_1 \geq c_1) + \sum_{k=a_1}^{c_1} P(\x_1 =k, \x_2-\x_1 \geq c_2-k) \\
		&= P(\x_1 \geq c_1) + \sum_{k=a_1}^{c_1} P(\x_1 =k) P(\x_2-\x_1 \geq c_2-k).
\end{align}
We may now use the fact that $\x_1 \sim Binom(n_1,p)$ and that $\x_2-\x_1 \sim Binom(n_2,p)$, and quickly compute the power in \R.

\begin{remark}[Redundancy]
Unlike the single stage LASP, where we have two equations with two variables, in the two-stage case there are many $\gamma$ configurations that will achieve given consumer and producer risks ($\alpha_0,\pi_0$).
The choice of the particular configuration should depend on the type of signal we expect.
For quick detection of strong signal (large $p$), choose small $n_1$.
For sensitive detection of subtle signal, choose large $n_1$.
\end{remark}

\begin{remark}[No Free Lunch]
While it may seem that a two stage LASP is always better than a single stage LASP, this is not the case.
To see why, consider a weak signal ($p$ close to AQL). We may need all $n_1+n_2$ samples to get decent power. The first stage then add nothing except logistic complications.
\end{remark}

\section{Sequential Scheme}
At this point you should be thinking: why only two stages?
Clearly we may reject or accept a sample as each unit comes in.
This is exactly what Sequential LASPs are all about.
We will not give the details, except the observation that this is merely a type of sequential experiment as described in Section~\ref{sec:sequantial}.

\section{Bibliographic Notes}
[TODO]


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

\begin{document}

% --------------------------------------------------------------------------------------------
\section*{Exercise 3.8 Symmetry of $R_{ab}$}

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

   \partial{#}::PartialDerivative;

   g_{a b}::Metric;
   g^{a b}::InverseMetric;

   dgab := \partial_{c}{g^{a b}} -> - g^{a e} g^{b f} \partial_{c}{g_{e f}}.
                                                          # cdb (dgab.000,dgab)

   Gamma := \Gamma^{a}_{b c} -> (1/2) g^{a e} (   \partial_{b}{g_{e c}}
                                                + \partial_{c}{g_{b e}}
                                                - \partial_{e}{g_{b c}}).
                                                          # cdb (Gamma.000,Gamma)

   Rabcd := R^{a}_{b c d} ->
            \partial_{c}{\Gamma^{a}_{b d}} + \Gamma^{a}_{e c} \Gamma^{e}_{b d}
          - \partial_{d}{\Gamma^{a}_{b c}} - \Gamma^{a}_{e d} \Gamma^{e}_{b c}.
                                                          # cdb (Rabcd.000,Rabcd)

   Rab := R_{a b} -> R^{c}_{a c b}.                       # cdb (Rab.000,Rab)

   expr := 4 (R_{a b} - R_{b a}).                         # cdb (ex-0308.100,expr)

   substitute   (expr, Rab)                               # cdb (ex-0308.101,expr)
   substitute   (expr, Rabcd)                             # cdb (ex-0308.102,expr)
   substitute   (expr, Gamma)                             # cdb (ex-0308.103,expr)

   distribute   (expr)                                    # cdb (ex-0308.104,expr)
   product_rule (expr)                                    # cdb (ex-0308.105,expr)
   canonicalise (expr)                                    # cdb (ex-0308.106,expr)

   substitute   (expr, dgab)                              # cdb (ex-0308.107,expr)
   canonicalise (expr)                                    # cdb (ex-0308.108,expr)
\end{cadabra}

\clearpage

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0308.100} = \Cdb*{ex-0308.101}
                             = \Cdb*{ex-0308.102}
                             = \Cdb*{ex-0308.103}
                             = \Cdb*{ex-0308.104}
                             = \Cdb*[\hskip2.0cm\hfill]{ex-0308.105}
                             = \Cdb*{ex-0308.106}
                             = \Cdb*{ex-0308.107}
                             = \Cdb*{ex-0308.108}}
\end{dgroup*}

\clearpage

% --------------------------------------------------------------------------------------------
\section*{Exercise 3.8 Symmetry of $R_{ab}$ alternative solution}

This differs from the previous code by the inclusion of a call to \verb|canonicalise| immediately
after the first two substitutions and a declaration that $\Gamma^{a}{}_{bc}$ is symmetric in $bc$.
This pair of changes produces a more compact set of results than given above. Incidently, this also
shows that $\partial_{a}\Gamma^{c}{}_{bc} = \partial_{b}\Gamma^{c}{}_{ac}$.

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

   \partial{#}::PartialDerivative;

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

   g_{a b}::Metric;
   g^{a b}::InverseMetric;

   dgab := \partial_{c}{g^{a b}} -> - g^{a e} g^{b f} \partial_{c}{g_{e f}}.
                                                          # cdb (dgab.000,dgab)

   Gamma := \Gamma^{a}_{b c} -> (1/2) g^{a e} (   \partial_{b}{g_{e c}}
                                                + \partial_{c}{g_{b e}}
                                                - \partial_{e}{g_{b c}}).
                                                          # cdb (Gamma.000,Gamma)

   Rabcd := R^{a}_{b c d} ->
            \partial_{c}{\Gamma^{a}_{b d}} + \Gamma^{a}_{e c} \Gamma^{e}_{b d}
          - \partial_{d}{\Gamma^{a}_{b c}} - \Gamma^{a}_{e d} \Gamma^{e}_{b c}.
                                                          # cdb (Rabcd.000,Rabcd)

   Rab := R_{a b} -> R^{c}_{a c b}.                       # cdb (Rab.000,Rab)

   expr := 4 (R_{a b} - R_{b a}).                         # cdb (ex-0308.200,expr)

   substitute   (expr, Rab)                               # cdb (ex-0308.201,expr)
   substitute   (expr, Rabcd)                             # cdb (ex-0308.202,expr)
   canonicalise (expr)                                    # cdb (ex-0308.203,expr)
   substitute   (expr, Gamma)                             # cdb (ex-0308.204,expr)

   distribute   (expr)                                    # cdb (ex-0308.205,expr)
   product_rule (expr)                                    # cdb (ex-0308.206,expr)
   canonicalise (expr)                                    # cdb (ex-0308.207,expr)

   substitute   (expr, dgab)                              # cdb (ex-0308.208,expr)
   canonicalise (expr)                                    # cdb (ex-0308.209,expr)
\end{cadabra}

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0308.200} = \Cdb*{ex-0308.201}
                             = \Cdb*{ex-0308.202}
                             = \Cdb*{ex-0308.203}
                             = \Cdb*{ex-0308.204}
                             = \Cdb*{ex-0308.205}
                             = \Cdb*{ex-0308.206}
                             = \Cdb*{ex-0308.207}
                             = \Cdb*{ex-0308.208}
                             = \Cdb*{ex-0308.209}}
\end{dgroup*}

\end{document}


\section{Ambiguity}

A sentence $x$ of $G$ is ambiguous iff it admits different syntax trees. In that case $G$ is ambiguous. The degree of ambiguity of $x$ is the number of distinct trees of $x$, of $G$ is the maximum over its sentences.

\paragraph{RegExp ambiguity} given an r.e. f , we number its letters and we obtain a numbered r.e. is ambiguous if the language defined by the numbered r.e. contains two distinct strings x and y that become identical when the numbers are erased.

\paragraph{Bilateral Recursions} $E \rarr E + E | i$ becomes $E \rarr i + E | i$.

\paragraph{Left-Right Recurions in different rules} $A \rarr aA | Ab | c$. Remedies: generate using different rules or force an order of derivation.

\paragraph{Union of Languages} assume that the two non-terminal sets are disjoint, otherwise the union grammar would generate
a superlanguage that strictly contains both languages. If $L_1 \cap L_2 \ne \emptyset$ then $L_1 \cup L_2$ is ambiguous (the intersection has 2 derivations). Remedy: provide disjointed set of rules: $L_1 \cap L_2$, $L_1 \setminus L_2$ and $L_2 \setminus L_1$.

\paragraph{Concatenation of Languages} if a suffix of a sentence of language one is also a prefix of a sentence of language two $G_1 . G_2$ is ambiguous if $\exists x_1 \in L_1, x_2 \in L_2$ such that $x_1 = uv$ with $u \in L_1$ and $x_2 = vz$ with $z \in L_2$: $uvz$ can be $(uv)z$ or $u(vz)$.

\paragraph{Inherent Ambiguity} A language is inherently ambiguous if all its grammar are ambiguous, e.g. those where the intersection is not CF.

\paragraph{Lack of Order in Derivations} add a nonterminal to impose that one rule must follw the other $S \rarr bSc | bbSc | \epsilon$ becomes $S \rarr bSc | D$, $D \rarr bbDc | \epsilon$.


\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
%\usepackage{stix}
\usepackage{amsmath}
\newcommand\addtag{\refstepcounter{equation}\tag{\theequation}}
\begin{document}

\title{Diagnosed Particle Disaggregation}
\author{Jacob A. Cram}
\maketitle

\section{Definitions and Units}

\begin{equation}
  m = C_m r^\alpha %\addtag
  \label{eqn:m}
\end{equation}

As in DeVries et al. [2014] particle mass m is a function of radius r and scales with a fractal dimension $\alpha$. $C_m$ is a constant.

\begin{equation}
  w = C_wr^\gamma %\addtag
  \label{eqn:w}
\end{equation}

Sinking speed also scales with mass to another constant $\gamma$.
According to Guidi et al. [2008] $\gamma = \alpha - 1$, but we'll keep things in terms of $\gamma$ going forward.

\begin{equation}
  F = nmw = n C_m C_w r^{\alpha + \gamma}
\end{equation}

Flux F is a function of particle numbers, mass, and sinking speed.

%\includegraphics{ijFig2.png}

\begin{figure}[h]
  \includegraphics{ijFig2.png}
  %\includegraphics[natwidth=0.35\textwidth]{ijFig2.png}

  \centering
  \caption{Some number of particles $\Delta n_j$ of size ``j'' remineralize to size ``j-1'' as they sink from depth ``i-1'' to depth ``i''.}
  \label{fig:boxes}
\end{figure}

Going forward we will determine the calculations for how many particles of size j in shallow depth i-1 remineralize into smaller particles of size j-1 in deeper depth i. We will call this term $\Delta n_j$

\section{Conservation of particle number flux}

In the absence of disaggregation, the number of particles leaving a box of water is equal to the number of particles going into that box from above. In other words, particle "number-flux" is conserved. Thus the number of particles in the box is a function of the number of particles going into that box, and the difference in velocities between when the particle enters and when that particle leaves.

\begin{equation}
n_{i-1, j-1}  {{w_{j-1}}\over{w_j}} + n_{i-1,j} = n_{i,j-1} {{w_{j-1}}\over{w_j}} + n_{i,j}
\label{eqn:nfcons}
\end{equation}

Where $n_{i-1,j}$ is the number of particles of size j (the bigger size) at depth i-1 (the shallower depth). The subscripts correspond to locations in Figure \ref{fig:boxes}.

We can re-arrange equation \ref{eqn:nfcons}

\begin{equation}
n_{i-1, j-1} w_{j-1} + n_{i-1,j} w_j = n_{i,j-1} w_{j-1} + n_{i,j} w_j
\label{eqn:renfcons}
\end{equation}

Substitue in equation \ref{eqn:w} into equation \ref{eqn:renfcons}.

\begin{equation}
n_{i-1, j-1} r^\gamma_{j-1} + n_{i-1,j} r^\gamma_j = n_{i,j-1} r^\gamma_{j-1} + n_{i,j} r^\gamma_j
\label{eqn:nra}
\end{equation}

Rearrange equation \ref{eqn:nra}
\begin{equation}
r^\gamma_{j-1} (n_{i-1, j-1} - n_{i, j-1} ) = r^\gamma_{j} (n_{i, j} - n_{i-1, j} ) = \Phi
\label{eqn:phi}
\end{equation}

Where $\Phi$ is a placeholder standing for either side of equation \ref{eqn:phi}, which I will subsequently substitute into things.

\medskip

Solve for $\Delta n_j$
 \begin{equation}
\Delta n_j = n_{i, j} - n_{i-1, j} = {{r^\gamma_{j-1}}\over{r^\gamma_{j}}} (n_{i-1,j-1}-n_{i,j-1})
 \end{equation}

\section{Conservation of Mass Flux}

Total flux defined is the sum of flux in each (observed) particle size bin. Particles not in an observed bin don't count towards total flux.

\begin{equation}
\Delta F = \sum_{j = 2}^n \Delta f_j + \Delta f_1
\label{eqn:df}
\end{equation}

Here $\Delta f_j$ is the flux attenuation from bin of size j and $\Delta f_1$ is the loss that comes from particles in bin 1 becoming small enough that you can no longer see them with the UVP.

The flux attenuation in a bin is the product of the rate of flux attenuation with depth of each individual particle ${\partial f} \over {\partial z}$, the depth interval over which the particles attenuate $\Delta z$ and the number of particles in that bin at the top of the depth interval $n_{i-1,j}$

\begin{equation}
\Delta f_j = {{\partial f} \over {\partial z}} \Delta z n_{i-1,j}
\label{eqn:dfj}
\end{equation}

Furthermore, the rate of flux attenuation with respect to depth is the product of the rate of mass attenuation with respect to time ${{\partial m} \over {\partial t}}$ , the inverse of the sinking speed ${{\partial t} \over {\partial z}}$ , and the deriviative of the flux to mass relationship ${{\partial f} \over {\partial m}}$.

\begin{equation}
{{\partial f} \over {\partial z}} =
{{\partial m} \over {\partial z}} {{\partial f} \over {\partial m}} =
{{\partial m} \over {\partial t}}
{{\partial t} \over {\partial z}}
{{\partial f} \over {\partial m}}
\label{eqn:dfdz}
\end{equation}

In PRiSM, fractional mass loss as a function of time is the same for all particles of all sizes.

\medskip

Now we are going to come up with the values for each of these terms.

\medskip

The particle remineralization rate $C_r$ is the same for particles of all sizes.

\begin{equation}
{{\partial m} \over {\partial t}} = C_r * m = C_r  C_m r^\alpha
\label{eqn:dmdt}
\end{equation}

Sinking speed definition, substituting from equation \ref{eqn:w}
\begin{equation}
{{\partial t} \over {\partial z}} = {1 \over w} = {1 \over C_w r^\gamma}
\label{eqn:dtdz}
\end{equation}

Flux for a given size class, substituting eqation \ref{eqn:m}, and finally putting everything in terms of mass (rather than mass and radius, since the two are related)
\begin{equation}
f = m w = m * C_w r^\gamma = m * C_w ({m\over C_m})^{\gamma \over \alpha}
\label{eqn:f}
\end{equation}

Derriving equation \ref{eqn:f} with respect to mass, and substituting equation \ref{eqn:m}
\begin{equation}
{{\partial f} \over {\partial m}} =
Cw(1+{\gamma \over \alpha}) ({m \over C_m}) ^ {\gamma \over \alpha}=
C_w(1+{\gamma \over \alpha}) r ^ \gamma
\label{eqn:dfdm}
\end{equation}

Finally, we can construct our equation for flux attenuation by substituting equations \ref{eqn:dmdt}, \ref{eqn:dtdz} and \ref{eqn:dfdm} into equation \ref{eqn:dfdz}

\begin{equation}
{{\partial f} \over {\partial z}} = C_r C_m r^\alpha(1+{\gamma \over \alpha})
\end{equation}

And now we can solve for equation \ref{eqn:dfj}.

\begin{equation}
\Delta f_j = C_r C_m r^\alpha (1+{\gamma \over \alpha}) \Delta z * n_{i-1,j}
\label{eqn:dfj}
\end{equation}

We also need to solve for $\Delta f_1$ the flux ``attenuation'' that actually comes from particles leaving the smallest bin and escaping from what the UVP sees.

\begin{equation}
\Delta f_1 = \Delta n_1 m_1 w_1 =  \Delta n_1 C_m C_w r_1^{\alpha + \gamma}
\label{eqn:df0}
\end{equation}

Here, $\Delta n_1$ is the number of particles leaving bin j = 1, but we haven't solved for that yet.

\section{Solving for $\Delta n_j$}

Recall that $\Delta n_j$ is the number of particles that migrate between bin ``j'' and bin ``j-1'' as the particles sink from depth ``i-1'' to depth ``i''.

The flux at the shallower depth is equal to the flux at the deeper depth, plus the flux that attenuated between those two depths. Since $f = nmw$ and we know m and w

\begin{equation}
n_{i-1,j-1} C_m C_w r_{j-1}^{\alpha + \gamma} + n_{i-1,j} C_m C_w r_{j}^{\alpha + \gamma} =
n_{i,j-1} C_m C_w r_{j-1}^{\alpha + \gamma} + n_{i,j} C_m C_w r_{j}^{\alpha + \gamma} + \Delta f_j
\label{eqn:n4f}
\end{equation}

This equation can be re-arranged, and we can substitute in equation \ref{eqn:dfj} for $\Delta f_j$.

% \begin{equation}
% C_m C_w r_{j-1} ^{\alpha + \gamma} (n_{i-1,j-1}- n_{i,j-1}) =
% C_m C_w r_{j}^{\alpha + \gamma} (n_{i,j} - n_{i-1,j}) +  C_r C_m (1 + {\gamma \over \alpha}) \Delta z n_{i-1,j} r ^ \alpha
% \end{equation}

The $C_m$ cancel out.

\begin{equation}
 C_w r_{j-1} ^{\alpha + \gamma} (n_{i-1,j-1}- n_{i,j-1}) =
 C_w r_{j}^{\alpha + \gamma} (n_{i,j} - n_{i-1,j}) +  C_r  (1 + {\gamma \over \alpha}) \Delta z n_{i-1,j} r ^ \alpha
\end{equation}

We can then substitute in $\Phi$ from equation \ref{eqn:phi}.
\begin{equation}
C_w r_{j-1} ^{\alpha} \Phi =
 C_w r_{j}^{\alpha} \Phi +  C_r  (1 + {\gamma \over \alpha}) \Delta z n_{i-1,j} r ^ \alpha
\end{equation}

Rearrange
% C_w \Phi %(r_{j-1}^\alpha - r_j^\alpha)

\begin{equation}
C_w\Phi(r_{j-1}^\alpha - r_j^\alpha) = Cr(1 + {\gamma \over \alpha}) \Delta z r^{\alpha} n_{i-1,j}
\end{equation}

solve for $\Phi$

\begin{equation}
\Phi = {{{C_r \over C_w} \Delta z r^{\alpha} n_{i-1,j}(1 + {\gamma \over \alpha})} \over {r_{j-1}^\alpha - r_j^\alpha}}
\end{equation}

\begin{equation}
\Delta n_j = {\Phi \over r_j^\gamma} = {{{C_r \over C_w} \Delta z r^{\alpha} n_{i-1,j}(1 + {\gamma \over \alpha})} \over {r_j^\gamma(r_{j-1}^\alpha - r_j^\alpha})}
\label{eqn:dnj}
\end{equation}

\begin{equation}
\Delta n_{j-1} = {\Phi \over r_{j-1}^\gamma} = {{\Delta n_j r_j^\gamma} \over {r_{j-1}^\gamma}}
\end{equation}

At this point, the only unsolved variable is $C_r$, which we can now calculate.

\section{Solving for $C_r$}

We can calculate $\Delta F $, the attenuation of flux and can impose the size spectrum and all of the other constants. Here we find the $C_r$ that gives us the correct $\Delta F $

First, to solve equation \ref{eqn:df} by substituting in equaitons \ref{eqn:dfj} and \ref{eqn:df0}

\begin{equation}
\Delta F = \sum_{j = 2}^n \Delta f_j + \Delta f_1 =
\sum_{j = 2}^n \left\{C_r C_m r_j^\alpha(1+{\gamma \over \alpha}) \Delta z n_{i-1,j} \right\} +
\Delta n_1 C_m C_w r_1^{\alpha + \gamma}
\end{equation}

Substitute equation \ref{eqn:dnj} for $\Delta n_j$ when j = 1 for $\Delta n_1$

\begin{equation}
\Delta F = \sum_{j = 2}^n \Delta f_j + \Delta f_1 =
\sum_{j = 2}^n \left\{C_r C_m r_j^\alpha(1+{\gamma \over \alpha}) \Delta z n_{i-1,j} \right\} +
 {{{C_r \over C_w} \Delta z r_1^{\alpha} n_{i-1,1}(1 + {\gamma \over \alpha})} \over {r_1^{\gamma}(r_{0}^\alpha - r_1^\alpha})}
C_m C_w r_1^{\alpha + \gamma}
\end{equation}

In the above, $r_0$ is the effective size of the particles smaller than the UVP can see. In principle this is arbitrary. Numbers closer to zero result in fewer particles in the smallest bin disapearing, larger ones to more of those particles disapearing. As $r_0$ approaches $r_1$ Cr approaches zero. They cannot be equal or the math breaks.

Pull what I can out of the sum operation, and cancel out $r^{\gamma}$ and $C_w$ from the rightmost term
\begin{equation}
\Delta F =
C_r C_m \Delta z (1 + {\gamma \over \alpha}) \sum_{j = 2}^n \left\{r_j^\alpha n_{i-1,j} \right\}
+
 {{{C_r} \Delta z r_1^{2 \alpha} n_{i-1,1}(1 + {\gamma \over \alpha})} \over {(r_{0}^\alpha - r_1^\alpha})}
C_m
\end{equation}

Now we can solve for $C_r$

\begin{equation}
C_r = {
\Delta F \over
C_m \Delta z
(1 + {\gamma \over \alpha}) \big[ \sum_{j = 2}^n  \big\{
r_j^\alpha n_{i-1,j}
\big\} +
{{r_1^{2\alpha}n_{i-1,1}}\over{r_0^\alpha - r_1^\alpha}}
\big]
}
\end{equation}

Thus for a pair of profiles, we can estemate the flux attenuation, calculate Cr from that, and then plug Cr (and the profile) into the equation \ref{eqn:dnj} for $\Delta n_j$. We can thus compute $\Delta n_j$ for each size class to see how many particles from that bin move to the next bin smaller.

 \end{document}