\section{Introduction to the Riemann Integral}
We introduce integration in many variables, starting with functions $f(x,y)$ of two real variables.

\medskip

\subsection{The Riemann integral on rectangles}
Let 
$$D : = \{(x,y) \in \mathbb{R}^2 :\ a \leq x \leq b,\  c \leq y \leq d\},$$
a closed and bounded rectangle in the plane. The purpose of this subsection is to define the integral of $f(x,y)$ over $D$, denoted by
$
\iint_{D} f(x,y) dA
$
(where $A$ stands for area). 
We will refer to the following figure extensively in our construction.

\begin{figure}[h]
\centering
\includegraphics[width = .7\linewidth]{51fig1.pdf}
\end{figure}

To begin, we partition the rectangle using the grid as shown above. Here,  each of the variables $x$ and $y$ is partitioned as
$$
a = x_0 < x_1 < \cdots < x_m = b
$$
$$
c = y_0 < y_1 < \cdots < y_n = d
$$
The intervals in our partitions need not have equal length. Let $\Delta x_i = x_i - x_{i-1}$, $\Delta y_j = y_j - y_{j-1}$ and $\Delta A_{ij} = \Delta x_{i} \Delta y_{j}$.  With this notation, $\Delta A_{ij}$ is the area of the small rectangle with left bottom corner at the point $(x_{i-1}, y_{j-1})$. We then let $P_{ij}^{*}$ be any point of this small rectangle (these are the dots appearing in the previous figure). Note that $P_{ij}^*$ may lie on the boundary of its small rectangle, for example it could be one of its vertices. We use $\mathscr{P}$ to denote this collection of sub-rectangles together with the choice of points $P_{ij}^{*}$.

The \textbf{Riemann sum} associated with $f(x,y)$ and the partition $\mathscr{P}$ is defined as
$$
\mathcal{R}(f, \mathscr{P}) : = \sum\limits_{i = 0}^{m} \sum\limits_{j=0}^{n} f(P_{ij}^{*}) \Delta A_{ij}.
$$
We say that the function $f(x,y)$ is \textbf{Riemann integrable} on $D$ if $\mathcal{R}(f, \mathscr{P})$ converges to a limit as the \textbf{norm of the partition}
$$
\| \mathscr{P} \| := \max_{i,j} \sqrt{(\Delta x_i)^2 + (\Delta y_j)^2} .
$$
approaches 0. This limit (if it exists) is the \textbf{Riemann integral} of $f$ on $D$, and we use $\iint_{D} f(x,y) dA$ to denote it. To make sense of the limit ``as $\| \mathscr{P} \|$ approaches $0$", we use the epsilon-delta machinery as follows.


\begin{definition}\label{Jordan-thm}
Let $f(x,y)$ be a function defined on a closed and bounded rectangle $D$. 
We say that 
$$\iint_{D} f(x,y) dA=L$$
 if the following holds: for every $\epsilon>0$ there is a $\delta>0$ such that if $\mathscr{P}$ is any partition of $D$ with $\| \mathscr{P} \| <\delta$, then
$$
\left| \mathcal{R}(f, \mathscr{P}) -L\right| <\epsilon.
$$
\end{definition}


\medskip




In this course, we will only use Riemann integrals (defined above), so from now on we will refer to them simply as integrals. Similarly, when we say that a function is integrable, we will mean it to say that it is Riemann integrable. However, you should be aware that there are also other types of integrals, notably Lebesgue integrals in $\RR^n$ and more general integrals associated with abstract measure spaces. These integrals are studied in much more depth in higher level analysis courses.


\subsection{Sufficient conditions for integrability, and integration on more general domains}
Many functions encountered in calculus are Riemann integrable. 
This includes the following important special cases. 

\begin{itemize}
\item 
Let $D$ be a bounded and closed rectangle in $\RR^2$.
If $f(x,y)$ is continuous on $D$ (including its boundary!), it is integrable on $D$.

\medskip

\item If $f(x,y)$ is continuous on a compact domain $X \subset \mathbb{R}^2$, we let $D$ be a bounded and closed rectangle containing $X$. We then \textit{extend} $f$ to a function $\tilde{f}$ on $D$ by setting
$$
\tilde{f}(x,y)
=
\begin{cases}
f(x,y) &\hbox{ if } (x,y) \in X \\
0 & \hbox{ if } (x,y) \in D \setminus X
\end{cases}
$$
If we then assume that the boundary of $X$ is a union of finitely many curves of finite length, then
$$
\iint_{X} f(x,y) d A : = \iint_{D} \tilde{f}(x,y) d A
$$
exists. 
\end{itemize}

The second bullet point above allows us to integrate functions on domains $X$ that are \underline{not} rectangles, provided that $X$ satisfies the conditions above and $f$ is continuous on $X$. A further extension (improper integrals, in cases when $X$ is not compact and/or $f$ is not continuous on $X$) will be considered later on. We do not provide proofs of the above statements (see your textbook for proofs and/or more details), but see Section \ref{subsec-Jordan} for a taste of what is involved.



\begin{figure}[h]
\centering
\includegraphics[width =0.7\linewidth]{51fig2.png}
\caption{The function $f(x,y)$, originally defined on the compact domain $X$, can be extended to a function $\tilde{f}(x,y)$ defined on the whole rectangular region $D$.}
\end{figure}


What is ``a curve of finite length"? We will actually study this in detail in MATH 227 (among other things, we will define the length of a curve and derive a formula to compute it). For now, the following will suffice. Suppose that the curve $\mathcal{C}$ is given by an equation of the form $g(x,y)=c$, where $g$ is a $C^1$ function such that $\nabla g(x,y)\neq{\bf 0}$ for all $(x,y)\in\mathcal{C}$. (This is the same condition that allows us to apply the Implicit Function Theorem and solve, locally, either for $y$ as a $C^1$ function of $x$ or the other way around. See Section 3.4.) Then any bounded piece of $\mathcal{C}$ has finite length. For example:

\begin{itemize}
\item The circle $x^2+y^2=4$ has finite length (and you should already know the formula for it!). Note that it can be represented by the equation $g(x,y)=4$ with $g(x,y)=x^2+y^2$, and $\nabla g(x,y)=2x\ii+2y\jj$ is never zero on the circle.

\item The parabola $y=x^2$ has infinite length, but if we only consider a bounded segment of it (for example, from $(0,0)$ to $(1,1)$), then this part has finite length.

\item Many fractal curves are bounded but have infinite length, for instance the Koch snowflake curve. (We encourage you to look it up.)

\end{itemize}




\subsection{A More General Theorem on Integrability}\label{subsec-Jordan} This section is, perhaps, more thorough than necessary for this course. However, we include it to make more sense of the two ``special cases'' listed above.

Suppose that $D \subset \mathbb{R}^2$ is, again, a closed and bounded rectangle and assume that $f(x,y)$ is bounded on $D$. That is, there is a constant $M > 0$ such that $|f(x,y)| \leq M$ for all $(x,y) \in D$.  Then we have the following theorem.

\begin{theorem}\label{Jordan-thm2}
Let $f(x,y)$ be a bounded function on a closed and bounded rectangle $D$. Then $f$ is integrable on $D$ if and only if the set 
$$\{(x,y) \in D : f \textrm{ is discontinuous at } (x,y) \}$$ has \textbf{Jordan area} zero.
\end{theorem}


\medskip

We will not prove this here, but we will define the Jordan area of a planar set $X$ and explain how the special cases above fit in this picture.  Our starting point is to try to approximate $X$ by unions of squares on a grid. We divide the plane into congruent squares $R_{ij}$ (with the obvious notation) as shown below. Let
$$
S^* : = \textrm{sum of areas of } R_{ij} \textrm{ intersecting } X
$$
$$
S_* : = \textrm{sum of areas of } R_{ij} \textrm{ contained within } X
$$
We will use $S^*$ and $S_*$ as the upper and lower approximations for the area of $X$. By definition, we know that
$$
S_* \leq \, (\textrm{Area of } X) \, \leq S^*
$$



\begin{figure}[h]
\centering
\includegraphics[width = .55\linewidth]{51fig3.pdf}
\caption{An approximation of $X$ by grids. The solid colouring indicates squares contained entirely in $X$; the starred squares are those that intersect $X$ (but are not necessarily contained entirely in it).}
\end{figure}


We say that $X$ is \textbf{Jordan measurable} if $\lim S^* = \lim S_*$ as the diameter of the grid goes to zero. We then define the area of $X$ to be equal to this common limit. In other words, for a Jordan-measurable $X$, both the upper and lower approximations converge to the actual area of $X$ as the grid diameter goes to 0. 
Further, we say that $X$ has \textbf{Jordan area zero} if $\lim S^* = 0$. 

\medskip
We now revisit the special cases mentioned above:

\begin{itemize}

\item If a function $f(x,y)$ is continuous on a bounded rectangle $D$ including its boundary, then $f(x,y)$ is bounded and its set of discontinuities is empty (therefore has Jordan area 0).

\smallskip

\item Suppose that $f(x,y)$ is continuous on a compact domain $X$ contained in a bounded rectangle $D$. Define the extension $\tilde{f}$ of $f$ to $D$ as in the second special case. Then the set of discontinuities of $\tilde f$ is contained in the boundary of $X$ (why?). If the boundary of $X$ is a union of finitely many curves of finite length, it must have Jordan area zero\footnote{This does require a proof. As an exercise, can you prove that the circle $x^2+y^2=4$ has Jordan area zero?}, so that Theorem \ref{Jordan-thm2} again applies.

\smallskip

\item Theorem \ref{Jordan-thm2} also covers many cases that are \underline{not} included in our special cases. For example, $X$ could be bounded by fractal curves that have infinite length but still have Jordan area zero.

\end{itemize}


As an example of a set that does not have a well-defined Jordan area, consider
$$
X : = \{(x,y) \in [0,1]^2 : x \textrm{ and } y \textrm{ are both rational}. \}
$$
Then $S^* = 1$ and $S_* = 0$ for any grid.  Why? Because any rectangle contains both points with rational coordinates and also points with irrational coordinates!

\begin{figure}[h]
\centering
\includegraphics[width = .55\linewidth]{51fig4.pdf}
\caption{A set $X$ that cannot be well approximated by grid squares.}
\end{figure}

 
 
 
\section*{Worked Problems}

\begin{enumerate}[1.]


\item {\it Let $f(x,y)$ be a function on the domain $D=\{(x,y):0\leq x\leq 1,0\leq y\leq 1\}$, defined by
$$
f(x,y)=\begin{cases}
1&\hbox{ if }x<y,\\
0&\hbox{ if }x\geq y.
\end{cases}
$$
Prove \textbf{directly from the definition} (using Riemann sums) that $\iint_D f(x,y)=1/2$, by following the procedure below.

\medskip

(a) Let $\mathcal{P}$ be a partition of $D$, with partition rectangles 
$D_{ij}=\{(x,y):x_{i-1}\leq x\leq x_i,y_{j-1}\leq y\leq y_j\}$.
Let $\mathcal{R}$ be the Riemann sum associated with this partition.
 Let $d_{ij}=\sqrt{(x_i-x_{i-1})^2+(y_i-y_{i-1})^2}$ be the length of the diagonal of $D_{ij}$.  
 Assume that $0<d_{ij}<\epsilon$ for all $i,j$, and for some $\epsilon<0.001$.
 Prove that 
$$
\frac{1}{2}-100\epsilon < \mathcal{R} < \frac{1}{2} + 100 \epsilon.
$$
(The constant 100 is not optimal and you may be able to get a better one.)}


\medskip

{\it (b) What happens when $\epsilon\to 0$?}




\bigskip


We start with (a). Let $X$ be the union of those rectangles of $\mathcal{P}$ that intersect the diagonal $\{(x,x):\ 0\leq x\leq 1\}$. We claim that $X\subset Y$, where 
$$
Y:=\{(x,y)\in D: \ x-2\epsilon\leq y\leq x+2\epsilon\}.
$$
To prove this, let $D_{ij}$ be a rectangle of $\mathcal{P}$ that intersects the diagonal. Then there is an $x$ such that  $0\leq x\leq 1$ and $(x,x)\in D_{ij}$. The diagonal of $D_{ij}$ has length at most $\epsilon$, so that for any other point $(x',y')\in D_{ij}$ we have $|x'-x|\leq \epsilon$ and $|y'-x|\leq\epsilon$. Therefore
$$
|x'-y'|=|(x'-x)+(x-y')|\leq |x-x'|+|y-y'|\leq 2\epsilon.
$$
This means that $D_{ij}$ is contained in  $Y$. 

%

Now we bound the Riemann sum $\mathcal{R}$. For an upper bound, we choose sampling points $P_{ij}$ with $f(P_{ij})=1$ where possible. That choice can only be made for all rectangles $D_{ij}$ either contained in the triangle below the line $y=x$ or intersecting that line. In both cases, $D_{ij}$ lies below the line $y=x+2\epsilon$.
Therefore $\mathcal{R}$ is bounded from above by the area of $Y_+:=\{(x,y)\in D:\ y\leq x+2\epsilon\}$. The complement of $Y_+$ in $D$ is a right triangle of area $\frac{1}{2}(1-2\epsilon)^2$. Therefore
\begin{align*}
\mathcal{R}& \leq (\hbox{Area of }Y_+)\\
&=1-\frac{1}{2}(1-2\epsilon)^2=1-\frac{1}{2}(1-4\epsilon+4\epsilon^2)=\frac{1}{2}+ 2\epsilon-2\epsilon^2
<\frac{1}{2}+2\epsilon.
\end{align*}

For a lower bound, we choose sampling points $P_{ij}$ with $f(P_{ij})=0$ where possible. That choice can only be made for all rectangles $D_{ij}$ either contained in the triangle above the line $y=x$ or intersecting that line -- in both cases, above the line $y=x-2\epsilon$. For every rectangle $D_{ij}$ intersecting the triangle $Y_-:=\{(x,y)\in D:\ y\leq x-2\epsilon\}$, we have to choose $f(P_{ij})=1$. Therefore $\mathcal{R}$ is bounded from below by the area of $Y_-$. This is a right triangle of area $\frac{1}{2}(1-2\epsilon)^2$. Therefore
\begin{align*}
\mathcal{R}&\geq (\hbox{Area of }Y_-)\\
&=\frac{1}{2}(1-2\epsilon)^2=\frac{1}{2}(1-4\epsilon+4\epsilon^2)=\frac{1}{2}- 2\epsilon+2\epsilon^2
>\frac{1}{2}-2\epsilon.
\end{align*}


Now we can answer the question in (b). As $\epsilon\to 0$, both $\frac{1}{2}-2\epsilon$ and $\frac{1}{2}-2\epsilon$ approach $\frac{1}{2}$, so that $\mathcal{R}\to\frac{1}{2}$.






\end{enumerate}


\section*{Practice Problems}

\begin{enumerate}[1.]

\item  
Let $f(x,y)=x+y$, and let $D=\{(x,y):0\leq x\leq 1,0\leq y\leq 1\}$. Prove that for any $\epsilon>0$, there is a $\delta>0$ such that the following holds:
\begin{quote}
 Let $\mathscr{P}_1$, $\mathscr{P}_2$ be two partitions of $D$ together with choices of sampling points. If $\| \mathscr{P}_1 \| <\delta$ and $\| \mathscr{P}_2 \| <\delta$, then 
 $$
 \left| \mathcal{R}(f, \mathscr{P}_1) -  \mathcal{R}(f, \mathscr{P}_2) \right| <\epsilon.
 $$
 \end{quote}

(This property is used in the proof that $f$ is integrable on $D$.)

\medskip

Hint: let $\mathscr{P}$ be a common refinement of $\mathscr{P}_1$ and $\mathscr{P}_2$ -- that is, a partition that includes all the partition points of both $\mathscr{P}_1$ and $\mathscr{P}_2$. What can you say about
$\mathcal{R}(f, \mathscr{P}_1) -  \mathcal{R}(f, \mathscr{P})$ and $\mathcal{R}(f, \mathscr{P}_2) -  \mathcal{R}(f, \mathscr{P})$?


\medskip


\item 
Let $D=\{(x,y):0\leq x\leq 1,0\leq y\leq 1\}$, and let $S=\{P_1,\dots,P_n\}\subset D$ be a set of finitely many points. Lef $f(x,y)$ be a function such that $f(P_1)=c_1$, ... , $f(P_n)=c_n$ for some arbitrary (but finite) values $c_1,\dots,c_n\in\rr$, and $f(x,y)=0$ for all $(x,y)\not\in S$.

Let $\mathcal{P}$ be a partition of $D$, with partition rectangles 
$D_{ij}=\{(x,y):x_{i-1}\leq x\leq x_i,y_{j-1}\leq y\leq y_j\}$.
Let $\mathcal{R}$ be the Riemann sum for $f$ associated with this partition.
 Let $d_{ij}=\sqrt{(x_i-x_{i-1})^2+(y_j-y_{j-1})^2}$ be the length of the diagonal of $D_{ij}$.  
 Assume that $0<d_{ij}<\epsilon$ for all $i,j$.
 Prove that 
$$
|\mathcal{R} |< C \epsilon^2
$$
for some constant $C$ that may depend on $n,c_1,\dots,c_n$, but is independent of $\epsilon$. What does this say about the integral $\iint_D f(x,y) \,dA$?












\end{enumerate}
