\chapter{$\mathcal{N} = 4$ SYM}

Consider the action of a $d$-dimensional Yang-Mills (YM) theory
with a massless spin-$\frac{1}{2}$ field $\Psi$ in the adjoint representation of the gauge group $U(N)$:
% (we will consider $SU(N)$)
\begin{equation}
 S = - \dfrac{1}{g_{YM}^2} \int d^d x \, \text{tr}
     \left(
         \dfrac{1}{2}F_{M N}F^{M N}
       - \bar{\Psi} \Gamma^M D_M \Psi
     \right),
\end{equation}
where $F_{M N} =\sum_{a=1}^{N^2} F_{M N}^a T^a_{ij}$, so that the trace is over the matrix indices $i, j=1, \ldots, N$.
$T^a$ are the generators of the gauge group.
More explicitly, the field-strength and the covariant derivative are
\begin{eqnarray}
 F_{MN} &=& \partial_M A_N - \partial_N A_M + [A_M, A_N],\\
 D_M &=& \partial_M  + [A_M, \cdot].
\end{eqnarray}

% \begin{eqnarray}
%  F_{MN}^a &=& \partial_M A_N^a - \partial_N A_M^a + f_{abc} A_M^b A_N^c,\\
%  D_M \Psi^a &=& \partial_M \Psi^a + f_{abc} A_M^b \Psi^c,
% \end{eqnarray}
% where the structure constants $f_{abc}$ are defined by the commutation relation $[T^a, T^b]=f_{abc} T^c$.

In Minkowski spacetime $\mathbb{R}^{9,1}$,
this action turns out to be invariant under the supersymmetry transformation:
\begin{eqnarray}
 \delta_\epsilon A_M  & = & \epsilon \Gamma_M \Psi,\\
 \delta_\epsilon \Psi & = & \dfrac{1}{2} F_{M N} \Gamma^{M N} \epsilon,
\end{eqnarray}
where $\epsilon$ is a constant Majorana-Weyl spinor that parametrizes the transformation.
% The bosonic and the fermionic degrees of freedom indeed match,
% \begin{itemize}
%  \item Bosonic: $D-2 = 8$
%  \item Fermionic: $2^{D/2}/2/2 = 8$
% \end{itemize}
% which is a necessary condition for supersymmetry.

Lower dimensional supersymmetric theories can actually be obtained by
dimensional reduction from the above theory \cite{Brink:1976bc}.
Let us review how we can derive the action for the maximally supersymmetric
$\mathcal{N}=4$ SYM on $\mathbb{R}^{4}$.

\section{Action on $\mathbb{R}^{4}$}
The dimensional reduction consists of restricting the dependence of the fields only to 4 dimensions: $(x_1, \ldots, x_4)$.
The original Lorentz symmetry group $Spin(9,1)$ is then broken to $Spin(4) \times Spin(5,1)^R$,
that is the Lorentz group in 4d and an internal symmetry group called R-symmetry (hence the superindex $R$).
These groups are isomorphic to:
\begin{eqnarray}
Spin(4)      &=& SU(2)_L \times SU(2)_R \\
Spin(5, 1)^R &=& Spin(4)^R \times SO(1,1)^R \\
	     &=& SU(2)^R_L \times SU(2)^R_R \times SO(1,1)^R.
\end{eqnarray}
% where the subindexes $L, R$ refers to left and right.

The gauge field $A_M$ is reduced to the 4d gauge field and scalars:
\begin{eqnarray}
 Spin(4):     & \,& A_\mu, \quad \mu = 1, 2, 3, 4 \\
%  Spin(5,1)^R: & \,& \Phi_I, \quad I = 0, 5, 6, 7, 8, 9
 Spin(4)^R: & \,& \Phi_I, \quad I = 5, 6, 7, 8 \\
 SO(1,1)^R: & \,& \Phi_I, \quad I = 0, 9
\end{eqnarray}
where we wrote down the group they transform under.

The fermionic field, which is a Majorana-Weyl spinor,
can be decomposed to 4 Majorana spinors (each having 2 degrees of freedom):
\begin{equation}
 \Psi=\begin{bmatrix}
       \psi_L\\
       \chi_R\\
       \psi_R\\
       \chi_L
      \end{bmatrix}
\end{equation}
where the spinors with the subindex $L$ (or $R$) transform in the spin-$\frac{1}{2}$ representation of
$SU(2)_L$ (or $SU(2)_R$).
Also, spinors with the name $\psi$ and $\chi$ transform in the spin-$\frac{1}{2}$ representation of
$SU(2)_L^R$ and $SU(2)_R^R$ from the R-symmetry subgroup, respectively.

The $\mathcal{N}=4$ SYM action explicitly written in terms of the 4d bosonic fields is:
\begin{equation}\label{SR4}
  \begin{split}
    S_{\mathbb{R}^4} = - \dfrac{1}{g_{YM}^2} \int d^4 x \, \text{tr}
    (
         \dfrac{1}{2}F_{\mu \nu}F^{\mu \nu}
       + D_\mu \Phi_I D^\mu \Phi^I
       + \dfrac{1}{2} [\Phi_I, \Phi_J]\, [\Phi^I, \Phi^J]
    \\
       \qquad
       - \bar{\Psi} \Gamma^\mu D_\mu \Psi
       - \bar{\Psi} \Gamma^I [ \Phi_I, \Psi ]
    ),
   \end{split}
\end{equation}
where we decomposed the 10d gamma matrices as $\Gamma^M=\Gamma^\mu \otimes \Gamma^I$.

The action has no mass scale, and it is in fact conformal invariant even at quantum level \cite{MANDELSTAM1983149, BRINK1983323}.
The conformal group extends the Poincar\'e group (translation, rotations and boosts)
to include scaling (dilatation),
and special conformal transformation, which is a composition of inversion, translation and inversion.
The conformal symmetry, the four copies of supersymmetry and the internal R-symmetry
are part of the larger $\mathcal{N}=4$ superconformal group $PSU(2,2|4)$.
Its Lie algebra is generated by the generators of the conformal algebra,
16 supercharges (that commute with momentum generators),
and 16 superconformal charges (that commute with special conformal generators).
Details of the algebra can be found for example in \cite{Minahan:2010js}.

\section{Action on $S^4$}
In order to apply supersymmetric localization to $\mathcal{N}=4$ SYM,
we shall put this theory on a hypersphere $S^4$.
% , which can be done using conformal invariance.
Conformal invariance implies an additional conformal coupling of the scalars to the scalar curvature $\mathcal{R}$,
namely,
\begin{equation}\label{conformalCoupling}
 \dfrac{\mathcal{R}}{6} \Phi^I \Phi_I, \quad I=0,5,6,7,8,9
\end{equation}
where for $S^d$ with radius $R$, the scalar curvature is $\mathcal{R} = d(d-1)/R^2 $.
Then, there will be also a metric factor $\sqrt{g}$ coming from the curved background.
The action on $S^4$ is hence
\begin{equation}\label{SS4}
  \begin{split}
    S_{S^4} = - \dfrac{1}{g_{YM}^2} \int d^4 x \, \sqrt{g} \text{tr}
    \left(
        \dfrac{1}{2}F_{\mu \nu}F^{\mu \nu}
       + D_\mu \Phi_I D^\mu \Phi^I
       + \dfrac{1}{2} [\Phi_I, \Phi_J]\, [\Phi^I, \Phi^J]
    \right. \\
    \left.
       \qquad
       - \bar{\Psi} \Gamma^\mu D_\mu \Psi
       - \bar{\Psi} \Gamma^I [ \Phi_I, \Psi ]
       + \dfrac{2}{R^2} \Phi^I \Phi_I
    \right).
   \end{split}
\end{equation}
Localization also requires the existence of an off-shell supersymmetry.
To fulfill this condition, additional auxiliary field terms are added to the above action, see \cite{Pestun:2007rz, Festuccia:2011ws}.
Then, on the localization locus, the action will effectively be $3/2$ times the conformal coupling \eqref{conformalCoupling},
see also \cite{Russo:2013qaa}.
Naturally, at the decompactification limit $R \rightarrow \infty$, we recover the flat space version.
% We shall see this limit is important for many of our results.

\chapter{$\mathcal{N} = 2^*$ SYM}

The fields of $\mathcal{N}=4$ SYM form a $\mathcal{N}=4$ vector (or gauge) multiplet,
but the latter can be decomposed into two $\mathcal{N}=2$ massless supermultiplets, namely
\begin{eqnarray}
 \text{Vector multiplet:} & & \{A_1, A_2, A_3, A_4, \Phi_0, \Phi_9, \psi_L, \psi_R\},  \\
 \text{Matter hypermultiplet:} & &\{\Phi_5, \Phi_6, \Phi_7, \Phi_8, \chi_L, \chi_R\}.
\end{eqnarray}

$\mathcal{N}=2^*$ SYM is the unique massive deformation of $\mathcal{N}=4$ SYM that breaks half of its supersymmetries.
This is achieved by giving mass to the matter hypermultiplet,
either via the $\mathcal{N}=1$ superpotential \cite{Buchel:2000cn, Bobev:2013cja},
or using Scherk-Schwarz reduction of $\mathcal{N}=1$ SYM \cite{Pestun:2007rz, Scherk:1979zr}.
The latter prescribes the following replacement rules in the action \eqref{SR4}:
\begin{eqnarray}
D_0 \Phi_i &\rightarrow & D_0 \Phi_i + M_{ij} \Phi_j, \quad i,j =5,\ldots 8 \\
D_0 \chi &\rightarrow & D_0 \chi + \dfrac{1}{4}\Gamma_{ij} M_{ij} \chi,
\end{eqnarray}
where $M_{ij}$, a $4 \times 4$ matrix, is a generator of $SU(2)^R_R$,
and is normalized as $M_{ij} M^{ij} = 4 M^2$, where $M$ is the mass scale. All the repeated indices are summed over.
These replacements will give the standard mass term to the bosons and the fermions,
and a cubic coupling term for the scalars.
In its infinite-mass limit, the matter hypermultiplet can be integrated out,
and the resulting theory is the pure $\mathcal{N}=2$ SYM.

% The full mass term to be added to the massless theory is:
% \begin{equation}
%  S_\text{mass} = \dfrac{1}{2 g_{YM}^2} \int d^4 x \, \sqrt{g}
%  \text{tr} \left( m^2 \Phi_i \Phi^i + m (\chi_1 \chi_1 + \chi_2 \chi_2 + h.c.)
%            -\dfrac{1}{4 r} R_{ki} M_{kj} \Phi^i \Phi^j
%            \right)
% \end{equation}
In order to apply the localization method to the partition function of $\mathcal{N}=2^*$ SYM,
we need to put it on $S^4$.
Since the theory is no longer conformal due to the hypermultiplet mass scale,
an additional curvature correction term to the mass is required in order to preserve supersymmetry,
besides the conformal coupling discussed in \eqref{SS4}.
% Moreover, localization requires off-shell supersymmetry, and that is fixed by an auxiliary field term to the action.
The full action can be found in \cite{Pestun:2007rz}, with the details of the localization procedure therein.
We are interested in the final localized result, that we will discuss next.

% In the limit of infinitely heavy hypermultiplet, these fields possess no dynamic degrees of freedom,
% hence we can integrate them out and then the resulting theory is the pure $\mathcal{N}=2$ SYM.

\input{Chapters/PartitionFunctions.tex}

% \section{Action }

% Let us first review how to obtain the actions of our theories.
% We will start with the action of $\mathcal{N}=4$ SYM on $\mathbb{R}^{3,1}$.
% It is convenient to use the language of $\mathcal{N}=1$ SYM in $\mathbb{R}^{9,1}$,
% from which all supersymmetric actions for lower dimensional Yang-Mills theory can be obtained from (cite someone).
%
% The action is
% \begin{equation}
%  S = \int d^4 x\, \sqrt{g} \mathcal{L}.
% \end{equation}
%
% The Lagrangian density for $\mathcal{N}=4$ SYM on $S^4$:
% \begin{equation}
%  \mathcal{L}_{$\mathcal{N}=4$} = -\dfrac{1}{g_{YM}^2}
%     \text{tr}\left(
%       \frac{1}{2}F_{MN}F^{MN} - \Psi \Gamma^M D_M \Psi  + \dfrac{2}{r^2} \Phi_A \Phi^A
%     \right).
% \end{equation}
% For $\mathcal{N}=2^*$ SYM, we add mass to the hypermultiplet (in the covariant derivatives),
% \begin{equation}
%  \mathcal{L}_{$\mathcal{N}=2$^*} =
% 		     -\dfrac{1}{g_{YM}^2}
% 			   \text{tr} \left(
% 			      \frac{1}{2}F_{MN}F^{MN} - \Psi \Gamma^M D_M \Psi  + \dfrac{2}{r^2} \Phi_A \Phi^A
% 			      -\dfrac{1}{4 r} R_{ki} M_{kj} \Phi^i \Phi^j - K_i K^i
% 			    \right).
% \end{equation}
% where the last term is added in order to have an off-shell susy so that the localization can be applied.


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{September 22, 2014}
\maketitle
\section*{cont'd example from last time}
$a_{n+1}=1+\frac{1}{a_n}$ and is fibanocci sequence. terms are back and forth but converging. it is clear that $a_n>1\forall n$.
\begin{align*}
  \left\lvert a_{n+1}-a_n\right\rvert&=\left\lvert 1+\frac{1}{a_n}-\left(1+\frac{1}{a_{n-1}}\right)\right\rvert\\
  &=\left\lvert\frac{1}{a_n}-\frac{1}{a_{n-1}}\right\rvert\\
  &=\frac{\left\lvert a_n-a_{n-1}\right\rvert}{a_n\cdot a_{n-1}}\text{with $a_n>1$ so}\\
  \left\lvert a_{n+1}-a_n\right\rvert&<\left\lvert a_{n}-a_{n-1}\right\rvert\\
\end{align*}
does this mean we have a limit?
contractive sequence has the property
$|a_{n+1}-a_n|<r|a_n-a_{n-1}|$ wher $r\in(0,1)$

no, it is possible in principle that $\lim|a_{n+1}-a_n|=b>0$ and that would mean that $\{a_n\}$ is not convergent

\begin{align*}
  a_na_{n+1}&=a_n(1+\frac{1}{a_n}=a_n+1>2\\
  \left\lvert a_{n+1}-a_n\right\rvert&<\frac{1}{2}\left\lvert a_{n}-a_{n-1}\right\rvert\\
\end{align*}
so it is convergent because $\frac{1}{2}\in(0,1)$

\section*{2.8.D}
pick a sequence of $\varepsilon$, $\varepsilon_n=\{\frac{1}{2^n}\}$. given $\varepsilon_1=\frac{1}{2}$ there exists $N+1\in\mathbb{N}$ such that $|a_m-a_n<\varepsilon_1$ if $m,n\ge N_1$, $\varepsilon_2=\frac{1}{4}, \exists N_2$ st $\left\lvert a_m-a_n\right\rvert<\varepsilon_2$ and so on.

so $|a_{\mathbb{N}_{n+1}}-a_{N_{n}}|<\frac{1}{2^n}$ and so the sum is less than 1 and we win.
\section*{convergent series}
given $(a_n)$ we consider the series $\sum\limits_{n=1}^\infty{a_n}$ let $s_n=\sum\limits_{k=1}^n{a_k}$ be the $n$th partial sum of the series. if $\lim s_n$ exists, we say that the series $\sum\limits_{k=1}^\infty{a_k}$is convergent

the following are equivalent
\begin{itemize}
\item
$\sum a_n$ is convergent
\item
$\forall\varepsilon>0\exists N$ st if $n\ge N, \left\lvert\sum\limits_{k=n+1}^\infty{a_k}\right\rvert<\varepsilon$
\item
$\forall\varepsilon>0\exists N$ st if $m,n\ge N, \left\lvert\sum\limits_{k=n+1}^m{a_k}\right\rvert<\varepsilon$
\end{itemize}
proofs are in the book

\section*{note}
if $\sum a_k<\infty$ then $\lim a_k=0$ but the converse is false, as shown by the harmonic series.

telescoping and geometric series are basically the only ones where we know how to find the sums

\section*{3.1.c}
if $\sum t_k$ is a convergent series of positive terms and $p>1$ show that $\sum t_k^p$ is convergent

the necessary condition is that $\lim t_k=0$. by the necessary condition $\exists N$ st $0\le t_k\le1\forall k\ge N$. Therefore $\sum\limits_{k=N}^\infty{t_k^p}\le\sum\limits_{k=N}^\infty{t_k}<\infty$
\section*{3.1.d}
if $\lim |a_n|=0$ then there exists $\sum a_{n_k}<\infty$

example argument: harmonic series
\end{document}


\section{Introduction to Functions}\label{sec:Functions}
A \dfont{function} $y=f(x)$ is a rule for determining
$y$ when we're given a value of $x$.  For example, the rule
$y=f(x)=2x+1$ is a function.  Any line $y=mx+b$ is called a \dfont{linear}
function.  The graph of a function looks like a curve
above (or below) the $x$-axis, where for any value
of $x$ the rule $y=f(x)$ tells us how far to go above (or below) the
$x$-axis to reach the curve.

\begin{definition}{FUNCTION}
	AA {\bf{function}} is a relation between a set of inputs and a set of permissible outputs with the property that each input is related to exactly one output. That is, a function $f$ assigns to each element $x$ in a set $D$ exactly one element, called $f(x)$ in a set $E$.
\end{definition}

A function $f$ is defined by its set of inputs, called the {\bf{domain}} of $f$. The inputs are also referred to as the {\bf{independent variable}} of the function. The set of permissible outputs is called the {\bf{range}} of $f$ (or image of the function). Since outputs depend on the inputs, the output is referred to as the {\bf{dependent variable}}. For a function written in the form, $\displaystyle{f(x)}$, $x$ is also referred to as the {\bf{argument}} of the function. Thus, for $g(4+h)$ the input $4+h$ is the argument for the function $g$.  \\

\begin{figure}[H]
	$$\includegraphics[width=4.5in]{images/Domain1}$$
	\caption{Arrow diagrams showing (a) function and (b) non-function. \label{fig:arrowDiagrams}}
\end{figure}

The diagram in Figure~\xrefn{fig:arrowDiagrams} (a) represents a function with domain $\{1, 2, 3\}$ and set of ordered pairs $\{(1,D), \,\,(2,C), \,\,(3,C)\}$. The range of $f$ is $\{C, \,\,D\}$. However, this second diagram (Figure~\xrefn{fig:arrowDiagrams} (b)) does not represent a function. One reason is that $x=2$ corresponds to two values of $y$, $y=B$ and $y=C$.  \\

A useful way to visualize a function is by sketching its graph. If $f$ is a function with domain $D$, then its graph is the set of ordered pairs $\ds{(x,f(x))}$. Since the y-coordinate of ant point $(x,y)$ on the graph is $y=f(x)$, we can read the value of $f(x)$ from the graph as being the height of the graph corresponding to $x$. The graph of $f$ also allows us to see visualize the domain and range of the function. \\

Functions can be defined in various ways: by an algebraic formula or several
algebraic formulas, by a graph, or by an experimentally determined
table of values. In the latter case, the table gives a bunch of
points in the plane, which we might then
interpolate with a smooth curve, if that makes sense.

\vspace{3mm}
Given a value of $x$, a function must give
at most one value of $y$.  Thus, vertical lines are not functions.
%For example, the line $x=1$ has infinitely many values of $y$ if $x=1$. It
%is also true that
%if $x$ is any number (not 1) there is no $y$ which corresponds to $x$,
%but that is not a problem---only multiple $y$ values is a problem.

One test to identify whether or not a curve in the $(x,y)$ coordinate
system is a function is the following.

\begin{theorem}{The Vertical Line Test}{Vertical Line Test}
	\label{VertLineTest}
A curve in the $(x,y)$ coordinate system represents a function if and only if no vertical line intersects the curve more than once.
\end{theorem}

\begin{figure}[H]
	$$\includegraphics[width=5in]{images/VerticalLines1}$$

	\caption{(a) Vertical line intersects curve once for all $x$, therefore the curve represents a function. (b) Vertical Line intersects curve more than once for $x$, therefore this curve does not represent a function. }
\end{figure}

\begin{example}{Identifying Functions}{IDFunctions}
	Determine which equations represent $y$ as a function of $x$.  \\

\hspace{4mm} (a) \hspace{2mm} $x^3 + y^2 = 1$ \hspace{1.5cm} (b) \hspace{2mm} $x^2 + y^3 = 1$
	\hspace{1.5cm} (c) \hspace{2mm} $x^2y = 1 - 3y$
\end{example}
\begin{solution}
For each of these equations, we solve for $y$ and determine whether each choice of $x$ will determine only one corresponding value of $y$.

(a)
 \[ \begin{array}{rclr}
		x^3 + y^2 & = & 1 & \\
		y^2 & = & 1 - x^3 & \\
		\sqrt{y^2} & = & \sqrt{1 - x^3} & \mbox{extract square roots} \\
		y & = & \pm \sqrt{1 - x^3} & \\
		\end{array} \]

If we substitute $x=0$ into our equation for $y$, we get  $y = \pm \sqrt{1 - 0^3} = \pm 1$, so that $(0,1)$ and $(0,-1)$ are on the graph of this equation. Hence, this equation does not represent $y$ as a function of $x$. As predicted, the graph of $x^3+y^2=1$, shown in Figure~\xrefn{fig:graphFT}(a), clearly fails the Vertical Line Test (Theorem \ref{VertLineTest}), so the equation does not represent $y$ as a function of $x$.\\

\vspace{3mm}

(b)
  \[ \begin{array}{rclr}
		x^2 + y^3 & = & 1 & \\
		y^3 & = & 1 - x^2 & \\
		\sqrt[3]{y^3} & = & \sqrt[3]{1 - x^2} & \\
		y & = & \sqrt[3]{1 - x^2} & \\
		\end{array} \]

For every choice of $x$, the equation $y =  \sqrt[3]{1 - x^2}$ returns only \textbf{one} value of $y$.  Hence, this equation describes $y$ as a function of $x$. As predicted, the graph of $x^2+y^3=1$, shown in Figure~\xrefn{fig:graphFT}(b), clearly passes the Vertical Line Test (Theorem \ref{VertLineTest}), so the equation does represent $y$ as a function of $x$.\\

(c)
  \[ \begin{array}{rclr}
		x^2y & = & 1 - 3y & \\
		x^2y + 3y & = & 1 & \\
		y \left(x^2 + 3\right) & = & 1 & \mbox{factor} \\
		y & = & \dfrac{1}{x^2 + 3} & \\
		\end{array} \]
     For each choice of $x$, there is only one value for $y$, so this equation describes $y$ as a function of~$x$.
     As predicted, the graph of $x^2y=1-3y$, shown in Figure~\xrefn{fig:graphFT}(c), clearly passes the Vertical Line Test (Theorem \ref{VertLineTest}), so the equation does represent $y$ as a function of $x$.\\

\begin{figure}[H]
$$\includegraphics[scale=0.38]{images/TestFunction-ex1}$$
\caption{\label{fig:graphFT}}
\end{figure}
\end{solution}

\subsection{Function Notation and Domain}

 In this section, we focus more on the \textbf{process} \index{function ! as a process} by which the $x$ is matched with the $y$.  If we think of the domain of a function as a set of \textbf{inputs} and the range as a set of \textbf{outputs}, we can think of a function $f$ as a process by which each input $x$ is matched with only one output $y$.  Since the output is completely determined by the input $x$ and the process $f$, we symbolize the output with \index{function ! notation} \textbf{function notation}: `$f(x)$', read `$f$ \textbf{of} $x$.' In other words, $f(x)$ is the output which results by applying the process $f$ to the input $x$.  In this case, the parentheses here do not indicate multiplication, as they do elsewhere in Algebra.  This can cause confusion if the context is not clear, so you must read carefully. \\

 The value of $y$ is completely dependent on the choice of $x$.  For this reason,  $x$ is often called the \index{variable ! independent} \index{independent variable} \index{function ! independent variable of} \textbf{independent variable}, or \index{function ! argument} \index{argument ! of a function} \textbf{argument} of $f$, whereas $y$ is often called the \index{variable ! dependent} \index{dependent variable} \index{function ! dependent variable of} \textbf{dependent variable}.

 \medskip

 As we shall see, the process of a function $f$ is usually described using an algebraic formula. For example, suppose a function $f$ takes a real number and performs the following two steps, in sequence

 \begin{enumerate}

 	\item  multiply by 3

 	\item  add 4

 \end{enumerate}

 If we choose $5$ as our input,  in step 1 we multiply by $3$ to get $(5)(3) = 15$.  In step 2, we add 4 to our result from step 1 which yields $15 + 4 = 19$.  Using function notation, we would write  $f(5) = 19$ to indicate that the result of applying the process $f$ to the input $5$ gives the output $19$.  In general, if we use $x$ for the input, applying step 1 produces $3x$.  Following with step 2 produces $3x+4$ as our final output.  Hence for an input $x$, we get the output $f(x) = 3x + 4$.  Notice that to check our formula for the case $x=5$, we replace the occurrence of $x$ in the formula for $f(x)$ with $5$ to get $f(5) = 3(5) + 4 = 15 + 4 = 19$, as required.

\begin{minipage}{0.4\textwidth}
In addition to lines, another familiar example of a
function is the parabola $f(x)=x^2$.  We can draw the graph of this
function by taking various values of $x$ (say, at regular intervals) and
plotting the points $(x,f(x))=(x,x^2)$.  Then connect the points with a
smooth curve.  (See Figure~\xrefn{fig:graphx2}.)\\
\end{minipage}
\begin{minipage}{0.3\textwidth}
	$$\begin{array}{r|r}
		x & y=x^{2}\\ \hline
	\vdots & \vdots \\
	-3 & (-3)^{2} = 9 \\
	-2 & (-2)^{2} = 4 \\
	-1 & (-1)^{2} = 1 \\
	0 & (0)^{2} = 0 \\
	1 & (1)^{2} = 1 \\
	2 & (2)^{2} = 4 \\
	3 & (3)^{2} = 9 \\
	\vdots & \vdots \\
\end{array} $$
\end{minipage}
\begin{minipage}{0.3\textwidth}
	\begin{figure}[H]
	$$\includegraphics[scale=0.25]{images/Plotx2}$$
	\caption{ \label{fig:graphx2}}
	\end{figure}
\end{minipage}

The two examples $f(x)=2x+1$ and $f(x)=x^2$ are both functions which
can be evaluated at {\it any} value of $x$ from negative infinity to
positive infinity.  For many functions, however, it only makes sense to
take $x$ in some interval or outside of some ``forbidden'' region.  The
interval of $x$-values at which we're allowed to evaluate the function is
called the \dfont{domain} of the function.

\begin{minipage}{0.6\textwidth}
	\begin{example}{Graph of a function}{GraphFunction}
		Given the graph of $f$ shown in Figure~\xrefn{fig:graphF}\\
		(a)  Find the values of $f(-2)\, , \,\, f(3) \, , \,$ and $\, f(5)$. \\
		(b) What are the domain and range of $f$?\\
	\end{example}
	\vspace{2.5cm}
\end{minipage}
\begin{minipage}{0.4\textwidth}
	\begin{figure}[H]
		$$\includegraphics[width=2.2in]{images/graphFunction1}$$
		\caption{ \label{fig:graphF}}
	\end{figure}
\end{minipage}

\vspace{-2.5cm}
\begin{minipage}{0.6\textwidth}
	\begin{solution}
		(a) We see from the Figure  that the point $(-2, \,-3)$ lies on the graph of $f$, so the value of $f$ at $x=-2$ is $f(-2)=-3$. From the graph, when $x=3$, $f(3)=-1$ and when $x=5$, $f(5)=4$. \\
		(b) The graph of $f(x)$ is defined for $\displaystyle{-6 \leq x \leq 6}$, so the domain of $f$ is the closed interval $[-6, \, 6]$. The range of $f$ is the set of all $y$ -values obtained from evaluating the function on its domain. Therefore, the range of $f$ is the  closed interval from $[-3, \, 6]$.
	\end{solution}
\end{minipage}

\begin{example}{Evaluating a function}
	IIf $\,\,\displaystyle{f(x)=x^{2}-3x+5}$, \hspace{2mm} find  $\displaystyle{f(-1)} \,$ , \hspace{2mm}  $\displaystyle{f(0)} \, $ , \hspace{2mm}  $\displaystyle{f(11)}$
\end{example}
\begin{solution}
	We first evaluate $f(-1)$ by replacing $x$ with the argument $-1$ in the expression \\ $\displaystyle{f(x)=x^{2}-3x+5}$. This yields \hspace{2mm} $\displaystyle{f(-1)=(-1)^{2}-3(-1)+5= 9}$. \\

	Similarily,   \hspace{2mm} $\displaystyle{f(0)=(0)^{2}-3(0)+5= 5}$ \hspace{2mm} and  \hspace{2mm}  $\displaystyle{f(11)=(11)^{2}-3(11)+5= 9}$ \\
\end{solution}

\begin{example}{Evaluating a function}{EvalFn}
	Find and simplify the following.

	\begin{enumerate}

		\item $f(-1)$, $f(0)$, $f(2)$

		\item  $f(2x)$, $2 f(x)$

		\item $f(x+2)$, $f(x)+2$, $f(x) + f(2)$

	\end{enumerate}
\end{example}
\begin{solution}

	 \begin{enumerate} \item  To find $f(-1)$, we replace every occurrence of $x$ in the expression $f(x)$ with $-1$

			\[ \begin{array}{rclr}
			f(-1) & = & -(-1)^2 + 3(-1) + 4 & \\
			& = & -(1) + (-3) + 4 & \\
			& = & 0 & \\
			\end{array} \]

			Similarly, $f(0) = -(0)^2 + 3(0) + 4 = 4$, \\

			and \hspace{9mm} $f(2) = -(2)^2 + 3(2) + 4 = -4+6+4 = 6$.

			\item To find $f(2x)$, we replace every occurrence of $x$ with the quantity $2x$

			\[ \begin{array}{rclr}
			f(2x) & = & -(2x)^2 + 3(2x) + 4 & \\
			& = & -(4x^2) + (6x) + 4 & \\
			& = & -4x^2+6x+4 & \\
			\end{array} \]

			The expression $2f(x)$ means we multiply the expression $f(x)$ by $2$

			\[ \begin{array}{rclr}
			2f(x) & = & 2\left(-x^2 + 3x + 4\right) & \\
			& = & -2x^2 + 6x + 8 \\
			\end{array} \]

			\item  To find $f(x+2)$, we replace every occurrence of $x$ with the quantity $x+2$

			\[ \begin{array}{rclr}
			f(x+2) & = & -(x+2)^2 + 3(x+2) + 4 & \\
			& = & -\left(x^2 + 4x + 4\right) + (3x+6) + 4 & \\
			& = & -x^2-4x-4+3x+6+4 &  \\
			& = & -x^2-x+6 &
			\end{array} \]

			To find $f(x)+2$, we add $2$ to the expression for $f(x)$

			\[ \begin{array}{rclr}
			f(x) + 2 & = & \left(-x^2 + 3x + 4\right) + 2  & \\
			& = & -x^2 + 3x + 6 \\
			\end{array} \]

			From our work above, we see $f(2) = 6$ so that

			\[ \begin{array}{rclr}
			f(x) + f(2) & = & \left(-x^2 + 3x + 4\right) + 6  & \\
			& = & -x^2 + 3x + 10 \\
			\end{array} \]

		\end{enumerate}

A few notes about the previous example are in order.  First note the difference between the answers for $f(2x)$ and $2f(x)$.  For $f(2x)$, we are multiplying the \textit{input} by $2$;  for $2 f(x)$, we are multiplying the \textit{output} by $2$.  As we see, we get entirely different results.  Along these lines, note that $f(x+2)$, $f(x) + 2$ and $f(x) + f(2)$ are three \textit{different} expressions as well.  Even though function notation uses parentheses, as does multiplication, there is \textit{no} general `distributive property' of function notation. Finally, note the practice of using parentheses when substituting one algebraic expression into another;  we highly recommend this practice as it will reduce careless errors.
\end{solution}

\begin{example}{Evaluating a function}
	IIf $\,\,\displaystyle{f(x)=\sqrt{x^{2}+1}-\frac{3}{5-x}}$, \hspace{2mm} evaluate $f(-x)\,$  \hspace{2mm} and  \hspace{2mm}  $f(a+h)$.
\end{example}
\begin{solution}

	$$\begin{array}{rclrcl }
	f(-x) & = & \displaystyle{\sqrt{(-x)^{2}+1}-\frac{3}{5-(-x)}}  & \hspace{1.5cm} f(a+h) & = & \displaystyle{\sqrt{(a+h)^{2}+1}-\frac{3}{5-(a+h)}} \\
	&&&&& \\
	& = & \displaystyle{\sqrt{x^{2}+1}-\frac{3}{5+x}}         && = & \displaystyle{\sqrt{a^{2}+2ah+h^{2}+1}-\frac{3}{5-a-h}} \\
	\end{array}$$
\end{solution}

%\begin{figure}[h]
%%\centerline{
%\hbox to \hsize{\vbox{\beginpicture
%\normalgraphs
%%\ninepoint
%\setcoordinatesystem units <0.7truecm,0.7truecm>
%\setplotarea x from -3 to 3, y from -3 to 3
%\axis left shiftedto x=0 /
%\axis bottom shiftedto y=0 /
%\setquadratic
%\plot -2.5 3 0 0 2.5 3 /
%\put {$f(x)=x^2$} [t] <0pt,-5pt> at 0 -3
%\endpicture }\hfill
%\vbox{\beginpicture
%\normalgraphs
%%\ninepoint
%\setcoordinatesystem units <0.7truecm,0.7truecm>
%\setplotarea x from -3 to 3, y from -3 to 3
%\axis left shiftedto x=0 /
%\axis bottom shiftedto y=0 /
%\setquadratic
%\plot 0 0 1 1 3 1.732 /
%\put {$f(x)=\sqrt{x}$} [t] <0pt,-5pt> at 0 -3
%\endpicture }\hfill
%\vbox{\beginpicture
%\normalgraphs
%%\ninepoint
%\setcoordinatesystem units <0.7truecm,0.7truecm>
%\setplotarea x from -3 to 3, y from -3 to 3
%\axis left shiftedto x=0 /
%\axis bottom shiftedto y=0 /
%\setquadratic
%\plot -3.000 -0.333 -2.867 -0.349 -2.733 -0.366 -2.600 -0.385 -2.467 -0.405
%-2.333 -0.429 -2.200 -0.455 -2.067 -0.484 -1.933 -0.517 -1.800 -0.556
%-1.667 -0.600 -1.533 -0.652 -1.400 -0.714 -1.267 -0.789 -1.133 -0.882
%-1.000 -1.000 -0.867 -1.154 -0.733 -1.364 -0.600 -1.667 -0.467 -2.143
%-0.333 -3.000 /
%\plot 0.333 3.000 0.467 2.143 0.600 1.667 0.733 1.364 0.867 1.154
%1.000 1.000 1.133 0.882 1.267 0.789 1.400 0.714 1.533 0.652
%1.667 0.600 1.800 0.556 1.933 0.517 2.067 0.484 2.200 0.455
%2.333 0.429 2.467 0.405 2.600 0.385 2.733 0.366 2.867 0.349
%3.000 0.333 /
%\put {$f(x)=1/x$} [t] <0pt,-5pt> at 0 -3
%\endpicture}}
%%}
%\caption{Some graphs. \label{fig:some graphs}}
%
%\end{figure}

\begin{example}{Domain of an a quadratic function}{FindDomain}
	Find the domain and range of $\ds{f(x)=x^{2}}$.
\end{example}

\begin{minipage}{0.6\textwidth}
	\begin{solution}
		The domain of $\ds{f(x)=x^{2}}$ is the set of all real numbers, $\ds{\R }$, where the graph of $f$ consists of all pairs of real numbers $\ds{(x, \,x^{2})}$. The graph of $f$ represents a parabola. The range of $f$ consists of all values of $f(x)=x^{2}$, or more precisely, the set of non-negative real numbers. So the range of $f$ is $\ds{\{y \in \mathbb{R} \, \ssep \, y \geq 0 \} = [0,\infty)}$.   \\
	\end{solution}
\end{minipage}
\begin{minipage}{0.4\textwidth}
	$$\includegraphics[width=1.5in]{images/x2}$$
\end{minipage}

\begin{example}{Domain of the Square-Root Function}{DomainofSquare-RootFunction}
	Find the domain of $\ds{f(x)=\sqrt{x}}$.
\end{example}

\begin{solution}
The square-root function $(x)=\sqrt{x}$ is the rule
which says, given an $x$-value, take the non-negative number whose
square is $x$.  This rule only makes sense if $x\ge 0$. % is positive or zero.
We say that the domain of this function is $x\ge 0$, or more formally
$\left\{x\in\mathbb{R}\, \ssep \,x\ge 0\right\}$.  Alternately, we
can use interval notation, and write that the domain is $[0,\infty)$.
The fact that the domain of $y=\sqrt{x}$ is $[0,\infty)$ means that in the
graph of this function (see Table~\ref{tab:elemfns})
we have points $(x,y)$ only above $x$-values on the right side of the
$x$-axis.
\end{solution}

\begin{example}{Domain of the Identity Function}{DomainofSquare-RootFunction}
	Find the domain of $\ds{f(x)=\frac{1}{x} }$.
\end{example}

\begin{solution}
Another example of a function whose domain is not the entire $x$-axis
is: $f(x)=1/x$, the reciprocal function. (See Table~\ref{tab:elemfns}.)  We cannot substitute $x=0$
in this formula.  The function makes sense, however, for any nonzero
$x$, so we take the domain to be: $\{x\in\mathbb{R}\, \ssep \,x\ne 0\}$.  The graph
of this function does not have any point $(x,y)$ with $x=0$.  As $x$
gets close to 0 from either side, the graph goes off toward $\pm$ infinity.
We call the vertical line $x=0$ an \dfont{asymptote}.
\end{solution}

To summarize, two reasons why certain $x$-values are excluded from the
domain of a function are the following.

\begin{formulabox}[Restrictions for the Domain of a Function]

1.  Division by zero is not allowed. That is, if $\ds{\,\,f(x)=\frac{P(x)}{Q(x)}\,\,}$ then $\ds{\,\, Q(x) \neq 0}$. \\
2.  Real square roots of a negative number do not exist. That is, if $\ds{\,\, f(x) = \sqrt{D(x)} \,\,}$ \\
then $\ds{\,\, D(x) \geq 0}$.  \\
\\
We will encounter some other ways in which functions might be undefined later.
\end{formulabox}

\begin{example}{Finding domain of a rational function with a square root}{domain}
	Find the domain of
	$$f(x)={\frac{1}{\sqrt{4x-x^2}}}$$
	\vspace{-0.5cm}
\end{example}

\begin{solution}
	To answer this question, we must rule out the $x\,$-values that make
	$4x-x^2$ negative (because we cannot take the square root of a
	negative number)
	and also the $x\,$-values that make $4x-x^2$ zero (because if $4x-x^2=0$, then
	when we take the square root we get 0, and we cannot divide by 0).
	In other words, the domain consists of all $x$ for which $4x-x^2$ is
	strictly positive.  That is, \\
	$$\begin{array}{rcl}
	4x-x^{2} & > & 0 \\
	x (4-x) & > & 0 \hspace{5mm} \longrightarrow \,\,0 < x < 4 \\
	\end{array}$$

	In interval notation, the domain is the interval $(0,4)$.
\end{solution}

\subsection{Modeling with Functions}\label{sec:ModelingFn}

The importance of Mathematics to our society lies in its value to approximate, or \textbf{model}\index{mathematical model}\index{model ! mathematical} real-world phenomenon.  Whether it be used to predict the high temperature on a given day, determine the hours of daylight on a given day, or predict population trends of various and sundry real and mythical beasts, Mathematics is second only to literacy in the importance humanity's development.

\medskip

It is important to keep in mind that anytime Mathematics is used to approximate reality, there are always limitations to the model.  For example, suppose grapes are on sale at the local market for $\$1.50$ per pound. Then one pound of grapes costs $\$1.50$, two pounds of grapes cost $\$3.00$, and so forth.  Suppose we want to develop a formula which relates the cost of buying grapes to the amount of grapes being purchased.  Since these two quantities vary from situation to situation, we assign them variables.  Let $c$ denote the cost of the grapes and let $g$ denote the amount of grapes purchased. To find the cost $c$ of the grapes, we multiply the amount of grapes $g$ by the price $\$1.50$ dollars per pound to get \[c = 1.5 g\]  In order for the units to be correct in the formula, $g$ must be measured in \textit{pounds} of grapes in which case the computed value of $c$ is measured in \textit{dollars}.  Since we're interested in finding the cost $c$ given an amount $g$, we think of $g$ as the independent variable and $c$ as the dependent variable.  Using the language of function notation, we write \[c(g) = 1.5 g\] where $g$ is the amount of grapes purchased (in pounds) and $c(g)$ is the cost (in dollars).  For example, $c(5)$ represents the cost, in dollars, to purchase $5$ pounds of grapes. In this case, $c(5) = 1.5(5) = 7.5$, so it would cost $\$ 7.50$. If, on the other hand, we wanted to find the \textit{amount} of grapes we can purchase for $\$5$, we would need to set $c(g) = 5$ and solve for $g$.  In this case, $c(g)=1.5g$, so solving  $c(g) = 5$ is equivalent to solving $1.5g = 5$  Doing so gives $g = \frac{5}{1.5} = 3.\overline{3}$. This means we can purchase exactly $3.\overline{3}$ pounds of grapes for $\$5$.  Of course, you would be hard-pressed to buy exactly $3.\overline{3}$ pounds of grapes, and this leads us to our next topic of discussion, the \index{domain ! applied}\index{applied domain of a function}\textbf{applied domain} of a function.

\medskip

Even though, mathematically, $c(g) = 1.5g$ has no domain restrictions (there are no denominators and no even-indexed radicals), there are certain values of $g$ that don't make any physical sense.  For example, $g = -1$ corresponds to `purchasing' $-1$ pounds of grapes. Also, unless the `local market' mentioned is the State of California (or some other exporter of grapes), it also doesn't make much sense for $g = 500,000,000$, either. So the reality of the situation limits what $g$ can be, and these limits determine the applied domain of $g$.  Typically, an applied domain is stated explicitly.  In this case, it would be common to see something like $c(g) = 1.5g$, $0 \leq g \leq 100$, meaning the number of pounds of grapes purchased is limited from $0$ up to $100$. The upper bound here, $100$ may represent the inventory of the market, or some other limit as set by local policy or law.  Even with this restriction, our model has its limitations.  As we saw above, it is virtually impossible to buy exactly  $3.\overline{3}$ pounds of grapes so that our cost is exactly $\$5$.  In this case, being sensible shoppers, we would most likely `round down' and purchase $3$ pounds of grapes or however close the market scale can read to $3.\overline{3}$ without being over.  It is time for a more sophisticated example.

\begin{example}{Application}{Application}
	The height $h$ in feet of a model rocket above the ground $t$ seconds after lift-off is given by \[ h(t) = \left\{ \begin{array}{rcl} -5t^2 + 100t, & \mbox{if} & 0 \leq t \leq 20 \\ 0, & \mbox{if} & t > 20 \\ \end{array} \right.\]
	\begin{enumerate}

		\item Find and interpret $h(10)$ and $h(60)$.

		\item Solve $h(t) = 375$ and interpret your answers.
	\end{enumerate}
\end{example}
\begin{solution}
	\begin{enumerate}
\item We first note that the independent variable here is $t$, chosen because it represents time.  Secondly, the function is broken up into two rules:  one formula for values of $t$ between $0$ and $20$ inclusive, and another for values of $t$ greater than 20. Since $t=10$ satisfies the inequality $0 \leq t \leq 20$,  we use the first formula listed,  $h(t) = -5t^2 + 100t$, to find $h(10)$.  We get $h(10) = -5(10)^2 + 100(10) = 500$.  Since $t$ represents the number of seconds since lift-off and $h(t)$ is the height above the ground in feet, the equation $h(10) = 500$ means that $10$ seconds after lift-off, the model rocket is $500$ feet above the ground. To find $h(60)$, we note that $t=60$ satisfies $t > 20$, so we use the rule $h(t) = 0$.  This function returns a value of $0$ regardless of what value is substituted in for $t$, so $h(60) = 0$.  This means that $60$ seconds after lift-off, the rocket is $0$ feet above the ground;  in other words, a minute after lift-off, the rocket has already returned to Earth.

\item Since the function $h$ is defined in pieces, we need to solve $h(t) = 375$ in pieces.  For $0 \leq t \leq 20$, $h(t) =  -5t^2 + 100t$, so for these values of $t$, we solve $-5t^2 + 100t = 375$.  Rearranging terms, we get $5t^2 - 100t + 375 = 0$, and factoring gives $5(t-5)(t-15) = 0$. Our answers are  $t=5$ and $t=15$, and since both of these values of $t$ lie between $0$ and $20$, we keep both solutions.  For $t>20$, $h(t) = 0$, and in this case, there are no solutions to $0=375$.  In terms of the model rocket,  solving $h(t) = 375$ corresponds to finding when, if ever, the rocket reaches $375$ feet above the ground. Our two answers, $t=5$ and $t=15$ correspond to the rocket reaching this altitude \textit{twice} -- once $5$ seconds after launch, and again $15$ seconds after launch.
\end{enumerate}
\end{solution}

The type of function in the previous example is called a \textbf{piecewise-defined} function, or `piecewise' function for short.  Many real-world phenomena (e.g. postal rates, income tax formulas are modeled by such functions.

Here is another example where the domain of a function is restricted. For example, if $y$ is the area of a
square of side $x$, then we can write $f(x)=x^2$.  In a purely
mathematical context the domain of the function $y=x^2$ is all of
$\mathbb{R}$. However, in the story-problem context of finding areas of squares,
we restrict the domain to positive values of $x$, because a square
with negative or zero side makes no sense.

In pure mathematics, we usually take the domain to be all
values of $x$ at which the formulas can be evaluated. However, in
a physical application problem there might be further restrictions on the domain
because only certain values of $x$ are of interest or make practical
physical sense. For example, the volume $V$ of a sphere is given by the formula $V(r)=\frac{4}{3}\pi r^3$ where $r$ is the radius of the sphere. The domain of $V$ is all $r \geq 0$, since it makes no sense to have a negative radius.\\

%Also, letters different from $f$ may be used.  For example, if $y$ is
%the velocity of something at time $t$, we may write $y=v(t)$ with
%the letter $v$ (instead of $f$) standing for the velocity function (and
%$t$ playing the role of $x$).
%
%The letter playing the role of $x$ is called the \dfont{independent
%variable}, and the letter playing the role of $y$ is called the
%\dfont{dependent variable} (because its
%value ``depends on'' the value of the independent
%variable).  In story problems, when one has to translate from English
%into mathematics, a crucial step is to
%determine what letters stand for variables.  If only words and no
%letters are given, then we have to decide which letters to use.  Some
%letters are traditional.  For example, almost always, $t$ stands for
%time.
%
\begin{example}{Open Box}{openbox}
An open-top box is made from an $a\times b$ rectangular piece of
cardboard by cutting out a square of side $x$ from each of the four
corners, and then folding the sides up and sealing them with duct
tape.  Find a formula for the volume $V$ of the box as a function of
$x$, and find the domain of this function.
\end{example}

\begin{solution}

\begin{wrapfigure}{r}{0.4\textwidth}
	\begin{center}
		\includegraphics[width=0.38\textwidth]{images/openbox}
	\end{center}
	\caption{}
\end{wrapfigure}

The box we get will have height $x$ and rectangular base of
dimensions $a-2x$ by $b-2x$.  Thus,
$$V(x)=x(a-2x)(b-2x)$$
Here $a$ and $b$ are constants, and $V$ is the variable that depends
on $x$, i.e., $V$ is playing the role of $y$.

This formula makes mathematical sense for any $x$, but in the physical
problem the domain is much less.  In the first place, $x$ must be
positive.  In the second place, it must be less than half the length
of either of the sides of the cardboard.  Thus, the domain is
$$\left\{x\in\mathbb{R}\,\ssep\,0<x<{\frac{1}{2}}(\hbox{minimum~of~$a$~and~$b$})\right\}.$$
In interval notation we write: the domain is the interval
$(0,\min(a,b)/2)$. You might think about whether we could allow 0 or
(the minimum~of~$a$~and~$b$) to be in the domain. They make a certain
physical sense, though we normally would not call the result a box. If we
were to allow these values, what would be the corresponding volumes?
Does that volume make sense?

\end{solution}

\begin{example}{Circles and function}{circle}
	Can a circle of radius $r$ centered at the origin be expressed as a function?

\end{example}

\begin{solution}
	The equation of a circle of radius $r$ centered at the origin is usually given in the form
	$x^2+y^2=r^2$.  To write the equation in the form $y=f(x)$ we solve
	for $y$, obtaining $y=\pm\sqrt{r^2-x^2}$.  But {\it this is not a
		function}, because when we substitute a value in $(-r,r)$ for $x$
	there are two corresponding values of $y$.  To get a function, we must
	choose one of the two signs in front of the square root.  If we choose
	the positive sign, for example, we get the upper semicircle
	$f(x)=\sqrt{r^2- x^2}$ (see Figure~\ref{fig:upper semicircle}).  The
	domain of this function is the interval $[-r,r]$, i.e., $x$ must be
	between $-r$ and $r$ (including the endpoints).
	If $x$ is outside of
	that interval, then $r^2-x^2$ is negative, and we cannot take the
	square root.  In terms of the graph, this just means that there are no
	points on the curve whose $x$-coordinate is greater than $r$ or less
	than $-r$.

	\figure[!ht]
	\centerline{\vbox{\beginpicture
			\normalgraphs
			%\ninepoint
			\setcoordinatesystem units <0.5truein,0.5truein>
			\setplotarea x from -3.1 to 3.1, y from 0 to 3.1
			\axis bottom ticks withvalues {$-r$} {$r$} / at -3 3 / /
			\axis left shiftedto x=0 /
			\circulararc 180 degrees from 3 0 center at 0 0
			\endpicture}}
	\caption{Upper semicircle $f(x)=\sqrt{r^2- x^2}$. \label{fig:upper semicircle}}
	\endfigure

\end{solution}

A function does not always have to be given by a single formula as the next example demonstrates.

\begin{example}{Piecewise Velocity}{PiecewiseVelocityExample}
Suppose that $v(t)$ is the velocity function for a car
which starts out from rest (zero velocity) at time $t=0$; then
increases its speed steadily to 20 m/sec, taking 10 seconds to do
this; then travels at constant speed 20 m/sec for 15 seconds; and
finally applies the brakes to decrease speed steadily to 0, taking 5
seconds to do this. Express the velocity of the car as a function of time $t$.
\end{example}

\begin{solution}
	The formula for $v(t)$ is different in each of
	the three time intervals.  \\

\begin{minipage}{0.3\textwidth}
	For $0 \leq t \leq 10$: \\

	\vspace{-4mm}
\hspace{1cm} 	$\begin{array}{c|c}
		t & v \\ \hline
		0 & 0 \\
		10 & 20 \\
\end{array}$

represented by $v(t)=2t$
\end{minipage}
\begin{minipage}{0.3\textwidth}
For $10 \leq t \leq 25$: \\

\vspace{-4mm}
\hspace{1cm} $\begin{array}{c|c}
t & v \\ \hline
10 & 20 \\
25 & 20 \\
\end{array}$

represented by $v(t)=20$
\end{minipage}
\begin{minipage}{0.35\textwidth}
	For $25 \leq t \leq 30$: \\

	\vspace{-4mm}
\hspace{1cm}	$\begin{array}{c|c}
	t & v \\ \hline
	25 & 20 \\
	30 & 0 \\
	\end{array}$

represented by $v(t)=-4t+120$
	\end{minipage}

\vspace{2mm}
 The velocity of the car  can be expressed as the following piecewise function

\vspace{-0.5cm}
\begin{minipage}{0.5\textwidth}
\hspace{1cm} $\displaystyle{ v(t) = \left\{ \begin{array}{cl}
	2t, & 0 \leq t \leq 10 \\
	20, & 10 \leq t \leq 25 \\
	-4t+120, & 25 \leq t \leq 30 \\
	\end{array} \right.}$	\\

The graph of this function is shown in Figure~\ref{fig:piecewise velocity}.

\vspace{5mm}
\end{minipage}
\begin{minipage}{0.5\textwidth}

\begin{figure}[H]
	$$\includegraphics[scale=0.3]{images/Velocity}$$
	\caption{ \label{fig:piecewise velocity} }
\end{figure}

%\figure[!h]
%\centerline{\vbox{\beginpicture
%\normalgraphs
%%\ninepoint
%\setcoordinatesystem units <4truemm,2truemm>
%\setplotarea x from 0 to 31, y from 0 to 22
%\axis bottom ticks withvalues {$10$} {$25$} {$30$} / at 10 25 30 / /
%\axis left ticks numbered from 0 to 20 by 10 /
%\plot 0 0 10 20 25 20 30 0 /
%\put {$t$} [l] <3pt,0pt> at 31 0
%\put {$v$} [b] <0pt,3pt> at 0 22
%\endpicture}}
%\caption{A velocity function. \label{fig:piecewise velocity}}
%\endfigure

\end{minipage}

\end{solution}

\pagebreak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:Functions}}

\begin{enumialphparenastyle}

\begin{multicols}{2}
%%%%%%%%%
\begin{ex}
Determine whether each curve represents a function. \\

\vspace{-1.3cm}
$$\includegraphics[scale=0.25]{images/ExFN3}$$

\begin{sol}
	Using the Vertical Line Test,
	(A) function, \hspace{3mm} (B) not a function, \hspace{3mm} (C) not a function, \hspace{3mm} (D) function, \hspace{3mm} (E) function, \hspace{3mm} (F) not a function.
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Determine whether or not the equation represents $y$ as a function of $x$.\\

\begin{multicols}{2}
	\begin{enumerate}
		\item $y = x^{3} - x$
		\item $y = \sqrt{x - 2}$
		\item $x^{3}y = -4$
		\item $x^{2} - y^{2} = 1$
		\item $y = \dfrac{x}{x^{2} - 9}$
		\item $x = -6$
		\item  $x = y^2 + 4$
		\item $y = x^2 + 4$
		\item $x^2 + y^2 = 4$
		\item $y = \sqrt{4-x^2}$
		\item $x^2 - y^2 = 4$
		\item $x^3 + y^3 = 4$
		\item $2x + 3y = 4$
		\item $2xy = 4$
		\item $x^2 = y^2$
		\end{enumerate}
\end{multicols}
\begin{sol}
\begin{multicols}{2}
	\begin{enumerate}
		\item $y = x^{3} - x$  function
		\item $y = \sqrt{x - 2}$ function
		\item $x^{3}y = -4$  function
		\item $x^{2} - y^{2} = 1$ not a function
		\item $y = \dfrac{x}{x^{2} - 9}$ function
		\item $x = -6$ not a function
		\item  $x = y^2 + 4$ not a function
		\item $y = x^2 + 4$ function
		\item $x^2 + y^2 = 4$ not a function
		\item $y = \sqrt{4-x^2}$ function
		\item $x^2 - y^2 = 4$not a function
		\item $x^3 + y^3 = 4$ function
		\item $2x + 3y = 4$ function
		\item $2xy = 4$ function
		\item $x^2 = y^2$ not a function
	\end{enumerate}
\end{multicols}
\end{sol}
\end{ex}

%%%%%%%%%%%%%%%
\begin{ex}
If $\,\, f(x) = \sqrt{x-4}-3x \,\,$, find \\
$f(-4)\, , \,\, f(4) \, , \, \text{and} \,\, f(8)$.

\begin{sol}
	$f(-4)$ is undefined, \hspace{3mm} $f(4)=-12$, \hspace{3mm} $f(8)=-22$
\end{sol}
\end{ex}

\begin{ex}
If $\displaystyle{f(x)=2x^{2}-3x+2}$, find the following. \\

\begin{tabular}{lll}
(a) $f(2)$ & \hspace{2mm} (b) $f(-2)$ & \hspace{2mm} (c) $f(a)$  \\
&& \\
(d)  $f(-a)$ & \hspace{2mm} (e) $f(a+1)$ & \hspace{2mm} (f) $f(2a)$ \\
&& \\
(g) $2f(a)$ & \hspace{2mm} (h) $\displaystyle{\left[ f(a) \right]^{2}}$ & \hspace{2mm} (i) $f(a+h)$ \\
\end{tabular}

\begin{sol}
\begin{tabular}{ll}
(a) $f(2)=6$ & (b) $f(-2)=16$ \\
(c) $f(a)=2a^{2}-3a+2$  & (d)  $f(-a)=2a^{2}+3a+2$ \\
(e) $f(a+1)=2a^{2}+a+1$ & (f) $f(2a)=8a^{2}-6x+2$ \\
(g) $2f(a)=4x^{2}-6x+4$ & (h) $\displaystyle{\left[ f(a) \right]^{2}=4x^{4}-12x^{3}+17x^{2}-12x+4}$ \\
(i) $f(a+h)=2a^{2}+4ah+2h^{2}-3a-3h+2$ & \\
\end{tabular}
\end{sol}
\end{ex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{ex}
Use the given function $f$ to find and simplify the following:\\
 \begin{multicols}{3}
	\begin{itemize}
		\item  $f(2)$
		\item  $f(-2)$
		\item  $f(2a)$
		\item  $2 f(a)$
		\item $f(a+2)$
		\item  $\displaystyle{f \left( \frac{2}{a} \right)}$
		\item $\displaystyle{\frac{f(a)}{2}}$
		\item  $f(a + h)$
		\item $\displaystyle{f(a) + f(2)}$
	\end{itemize}
\end{multicols}

\begin{multicols}{2}
	(a) \hspace{2mm}  $f(x) = 2x-5$ \\
	\\
    (b) \hspace{2mm} $f(x) = 5-2x$	\\
    \\
    (c) \hspace{2mm} $f(x) = 2x^2 - 1$\\
    \\
    (d) \hspace{2mm} $f(x) = \dfrac{2}{x}$ \\
    \\
	(e) \hspace{2mm} $\displaystyle{f(x) = 3x^2+3x-2}$\\
	\\
	(f) \hspace{2mm}  $f(x) = \sqrt{2x+1}$\\
	\\
	(g) \hspace{2mm} $f(x) = -7$\\
	\\
	(h) \hspace{2mm}  $f(x) = \dfrac{x}{2}$\\
\end{multicols}
\begin{sol}
(a) \hspace{2mm} For $f(x) = 2x-5$ \\
$f(2) = -1$\\
$f(-2) = -9$\\
$f(2a) = 4a-5$	\\
$2 f(a) = 4a-10$\\
$f(a+2) = 2a-1$\\
$f(a) + f(2) = 2a-6$\\
$f \left( \frac{2}{a} \right) = \frac{4}{a} - 5$ \\
$\hphantom{f \left( \frac{2}{a} \right)} = \frac{4-5a}{a}$\\
$\frac{f(a)}{2} =\frac{2a-5}{2}$\\
$f(a + h) = 2a + 2h - 5$\\

\vspace{3mm}

(b) \space{2mm} For $f(x) = 5-2x$\\
$f(2) = 1$\\
$f(-2) = 9$\\
$f(2a) = 5-4a$	\\
$2 f(a) = 10-4a$\\
$f(a+2) = 1-2a$\\
$f(a) + f(2) = 6-2a$\\
$f \left( \frac{2}{a} \right) = 5 - \frac{4}{a}$ \\
$\hphantom{f \left( \frac{2}{a} \right)} = \frac{5a-4}{a}$\\
$\frac{f(a)}{2} = \frac{5-2a}{2}$\\
$f(a + h) = 5-2a-2h$\\

\vspace{3mm}

(c) \hspace{2mm} For $f(x) = 2x^2-1$\\
$f(2) = 7$\\
$f(-2) = 7$\\
$2 f(a) = 4a^2-2$\\
$f(a+2) = 2a^2+8a+7$\\
$f(a) + f(2) = 2a^2+6$\\
$f \left( \frac{2}{a} \right) = \frac{8}{a^2} - 1$ \\
$\hphantom{f \left( \frac{2}{a} \right)} = \frac{8-a^2}{a^2}$\\
$\frac{f(a)}{2} =  \frac{2a^2-1}{2}$\\
$f(a + h) = 2a^2+4ah+2h^2-1$\\

\vspace{2mm}

(d) \hspace{2mm} For $f(x) = 3x^2+3x-2$\\
$f(2) = 16$\\
$f(-2) = 4$\\
$f(2a) = 12a^2+6a-2$\\
$2 f(a) = 6a^2+6a-4$\\
$f(a+2) = 3a^2+15a+16$\\
\small $f(a) + f(2) = 3a^2+3a+14$ \normalsize\\
$f \left( \frac{2}{a} \right) = \frac{12}{a^2} + \frac{6}{a} - 2$ \\
$\hphantom{f \left( \frac{2}{a} \right)} = \frac{12+6a-2a^2}{a^2}$\\
$\frac{f(a)}{2} =  \frac{3a^2+3a-2}{2}$\\
$f(a + h) = 3a^2 + 6ah + 3h^2+3a+3h-2$\\

\vspace{3mm}

(e) \hspace{2mm} For $f(x) = \sqrt{2x+1}$\\
$f(2) = \sqrt{5}$\\
$f(-2)$ is not real \\
$f(2a) = \sqrt{4a+1}$\\
$2 f(a) = 2\sqrt{2a+1}$\\
$f(a+2) = \sqrt{2a+5}$\\
\small $f(a) + f(2) =\sqrt{2a+1} + \sqrt{5}$ \normalsize\\
$f \left( \frac{2}{a} \right) = \sqrt{\frac{4}{a} + 1}$ \\
$\hphantom{f \left( \frac{2}{a} \right)} = \sqrt{\frac{a+4}{a}}$\\
$\frac{f(a)}{2} = \frac{\sqrt{2a+1}}{2}$\\
$f(a + h) = \sqrt{2a+2h+1}$\\

\vspace{3mm}

(f) \hspace{2mm}  For $f(x) = -7$\\
$f(2) = -7$\\
$f(-2) = -7$\\
$f(2a) = -7$\\
$2 f(a) = -14$\\
$f(a+2) = -7$\\
$f(a) + f(2) = -14$\\
$f \left( \frac{2}{a} \right) = -7$ \\
$\frac{f(a)}{2} = \frac{-7}{2}$\\
$f(a + h) = -7$\\

\vspace{3mm}

For $f(x) = \frac{x}{2}$\\
$f(2) = 1$\\
$f(-2) = -1$\\
$f(2a) = a$\\
$2 f(a) = a$\\
$f(a+2) = \frac{a+2}{2}$\\
$f(a) + f(2) = \frac{a}{2}+ 1$ \\
$\hphantom{f(a) + f(2)} = \frac{a+2}{2}$\\
$f \left( \frac{2}{a} \right) = \frac{1}{a}$\\
$\frac{f(a)}{2} =  \frac{a}{4}$\\
$f(a + h) = \frac{a+h}{2}$\\

\vspace{3mm}

(g) For $f(x) = \frac{2}{x}$\\
$f(2) = 1$\\
$f(-2) = -1$\\
$f(2a) = \frac{1}{a}$\\
$2 f(a) = \frac{4}{a}$\\
$f(a+2) = \frac{2}{a+2}$\\
$f(a) + f(2) = \frac{2}{a}+1$ \\
$\hphantom{f(a)+f(2)}=\frac{a+2}{2}$\\
$f \left( \frac{2}{a} \right) = a$\\
$\frac{f(a)}{2} =  \frac{1}{a}$\\
$f(a + h) = \frac{2}{a+h}$\\

\end{sol}
\end{ex}

%%%%%%%%%%%%%%%%%%%%%%
\begin{ex}
An on-line comic book retailer charges shipping costs according to the following formula \[{\displaystyle S(n) = \left\{ \begin{array}{rcl}  1.5 n + 2.,5 &  & 1 \leq n \leq 14  \\
	0,  & & n \geq 15
	\end{array} \right. }\]

where $n$ is the number of  comic books purchased and $S(n)$ is the shipping cost in dollars.

\begin{enumerate}

	\item  What is the cost to ship 10 comic books?  %  Ans:  $S(10) = 17.5$, $\$ 17.50$.

	\item  What is the significance of the formula $S(n) = 0$ for $n \geq 15$?   % Ans:  There is free shipping on orders of $15$ or more comic books.
\end{enumerate}

\begin{sol}
(a) \hspace{2mm} $S(10) = 17.5$, so it costs $\$ 17.50$ to ship 10 comic books. \\
(b) \hspace{2mm} There is free shipping on orders of $15$ or more comic books. \\

\end{sol}
\end{ex}

%%%%%%%%%%%%%%%%%%%%%%%
\begin{ex}
The cost $C$ (in dollars) to talk $m$ minutes a month on a mobile phone plan is modeled by   \[{\displaystyle C(m) = \left\{ \begin{array}{rcl} 25, & & 0 \leq m \leq 1000 \\
	25+0.1(m-1000), &  & m > 1000
	\end{array} \right. }\]

\begin{enumerate}

	\item  How much does it cost to talk $750$ minutes per month with this plan?  % Ans:  $C(750) = 25$, $\$ 25$.

	\item  How much does it cost to talk $20$ hours a month with this plan?  % Ans:  $C(1200) = 45$, $\$ 45$.

	\item  Explain the terms of the plan verbally.  % Ans:  It costs $\$25$ for up to $1000$ minutes and $10$ cents per minute for each minute over $1000$ minutes.

\end{enumerate}
\begin{sol}

(a) \hspace{2mm} $C(750) = 25$, so it costs $\$ 25$ to talk 750 minutes per month with this plan. \\

(b) \hspace{2mm} Since $20 \, \text{hours} = 1200 \, \text{minutes}$, we substitute $m = 1200$ and get  $C(1200) = 45$.  It costs $\$ 45$ to talk 20 hours per month with this plan. \\

(c) \hspace{2mm}  It costs $\$25$ for up to $1000$ minutes and $10$ cents per minute for each minute over $1000$ minutes.

\end{sol}
\end{ex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{ex}
Find the domain of each of the following functions:

\begin{tabular}{ll}
	(a)	$\ds f(x)=x^2+1$ & (b)	$\ds f(x)=\sqrt{2x-3}$ \\
	& \\ [0em]
	(c) $\ds g(x)=\frac{1}{x+1}$ & (d) $\ds y=\frac{1}{x^2-1}$ \\
	& \\ [0em]
	(e) $\ds f(x)=\sqrt{\frac{-1}{x}}$ & (f) $\ds g(t)={\root 3 \of t}$ \\
	& \\ [0em]
	(g) $\ds f(x)=\frac{x+4}{x^{2}-9}$ & (h) $\ds y=\sqrt{1-x^2}$ \\
	& \\ [0em]
	(i) $\ds y=\sqrt{1-\frac{1}{x} }$ & (j) $\ds h(x)=\frac{1}{\sqrt{1-(3x)^2}}$ \\
	& \\ [0em]
	(k) $\ds f(s)=\sqrt{s}+\frac{1}{s-1}$ & (l) $\ds f(x)=\frac{1}{\sqrt{x}-1}$ \\
	& \\ [0em]
	(m) $\ds y=\frac{\sqrt{2x-1}}{x^{2}-x}$ & (n)  $\ds y=\frac{\sin x}{\sqrt{2x-1}}$
\end{tabular}

\begin{sol}
\begin{enumerate}
	\item	$\ds \{x\mid x\in \R\}$, i.e., all $x$
	\item	$\ds \{x\mid x\ge 3/2\}$
	\item	$\ds \{x\mid x\not=-1\}$
	\item	$\ds \{x\mid x\not=1 \hbox{ and } x\not=-1\}$
	\item	$\ds \{x\mid x<0\}$
	\item	$\ds \{t\mid t\in \R\}$, i.e., all $t$
	\item	$\ds \{x\mid x\not \pm 3\}$
	\item	$\ds \{x\mid -1\le x\le 1\}$
	\item	$\ds \{x\mid x\ge 1\}$
	\item	$\ds \{x\mid -1/3< x< 1/3\}$
	\item	$\ds \{s\mid s\ge0  \hbox{ and } s\not=1\}$
	\item	$\ds \{x\mid x\ge0  \hbox{ and } x\not=1\}$
	\item  $\ds \{x\mid x\not=0,\, 1\}$
	\item  $\ds \{x\mid x> 1/2\}$
\end{enumerate}
\end{sol}
\end{ex}

%%%%%%%%%%%%%%%%%%%%%%
\begin{ex}
Find the (implied) domain of the function.

%\begin{multicols}{2}
(a) \hspace{2mm}  $f(x) = x^{4} - 13x^{3}  - 19$ \\
\\
(b) \hspace{2mm}  $f(x) = x^2 + 4$\\
	\\
(c) \hspace{2mm}	$f(x) = \dfrac{x-2}{x+1}$\\
\\
(d) \hspace{2mm} $f(x) = \dfrac{3x}{x^2+x-2}$\\
\\
(e) \hspace{2mm}  $f(x) = \dfrac{2x}{x^2+3}$\\
\\
(f) \hspace{2mm} $f(x) = \dfrac{2x}{x^2-3}$\\
\\
(g) \hspace{2mm}  $f(x) = \dfrac{x+4}{x^2 - 36}$\\
\\
(h) \hspace{2mm} $f(x) = \dfrac{x-2}{x-2}$  \\
\\
(i) \hspace{2mm}  $f(x) = \sqrt{3-x}$\\
\\
(j) \hspace{2mm} $f(x) = \sqrt{2x+5}$  \\
\\
(k) \hspace{2mm} $f(x) = 9x\sqrt{x+3}$\\
\\
(l) \hspace{2mm} $f(x) = \dfrac{\sqrt{7-x}}{x^2+1}$  \\
\\
(m) \hspace{2mm} $f(x) = \sqrt{6x-2}$\\
\\
(n) \hspace{2mm} $f(x) = \dfrac{6}{\sqrt{6x-2}}$\\
\\
(o) \hspace{2mm}  $f(x) = \sqrt[3]{6x-2}$\\
\\
(p) \hspace{2mm} $f(x) = \dfrac{6}{4 - \sqrt{6x-2}}$\\
\\
(q) \hspace{2mm}  $f(x) = \dfrac{\sqrt{6x-2}}{x^2-36}$\\
\\
(r) \hspace{2mm} $f(x) = \dfrac{\sqrt[3]{6x-2}}{x^2+36}$\\
\\
(s) \hspace{2mm}  $s(t) = \dfrac{t}{t - 8}$\\
\\
(t) \hspace{2mm} $Q(r) = \dfrac{\sqrt{r}}{r - 8}$\\
\\
(u) \hspace{2mm}  $b(\theta) = \dfrac{\theta}{\sqrt{\theta - 8}}$\\
\\
(v) \hspace{2mm} $A(x) = \sqrt{x - 7} + \sqrt{9 - x}$\\
\\
(w) \hspace{2mm} $\alpha(y) = \sqrt[3]{\dfrac{y}{y - 8}}$\\
\\
(x) \hspace{2mm} $g(v) = \dfrac{1}{4 - \dfrac{1}{v^{2}}}$\\
\\
(y) \hspace{2mm}  $T(t) = \dfrac{\sqrt{t} - 8}{5-t}$ \\
\\
(z) \hspace{2mm} $u(w) = \dfrac{w - 8}{5 - \sqrt{w}}$ \\
%\end{multicols}
\begin{sol}
\begin{multicols}{2}
	\begin{enumerate}
		\item $(-\infty, \infty)$
		\item  $(-\infty, \infty)$
		\item $(-\infty, -1) \cup (-1, \infty)$
		\item  $(-\infty,-2) \cup (-2,1) \cup (1, \infty)$
		\item $(-\infty, \infty)$
		\item  $(-\infty, -\sqrt{3}) \cup (-\sqrt{3}, \sqrt{3}) \cup (\sqrt{3}, \infty)$
		\item  $(-\infty, -6) \cup (-6,6) \cup (6, \infty)$
		\item $(-\infty, 2) \cup (2, \infty)$
		\item  $(-\infty, 3]$
		\item $\left[-\frac{5}{2}, \infty \right)$
		\item  $[-3, \infty)$
		\item $(-\infty, 7]$
		\item    $\left[ \frac{1}{3}, \infty \right)$
		\item   $\left( \frac{1}{3}, \infty \right)$
		\item   $(-\infty, \infty)$
		\item   $\left[ \frac{1}{3}, 3 \right) \cup (3, \infty)$
		\item  $\left[ \frac{1}{3}, 6 \right) \cup (6, \infty)$
		\item   $(-\infty, \infty)$
		\item $(-\infty, 8) \cup (8, \infty)$
		\item $[0, 8) \cup (8, \infty)$
		\item $(8, \infty)$
		\item $[7, 9]$
		\item $(-\infty, 8) \cup (8, \infty)$
		\item $\left( -\infty, -\frac{1}{2} \right) \cup \left( -\frac{1}{2}, 0 \right) \cup \left(0, \frac{1}{2}$
		\item $[0, 5) \cup (5,\infty)$
		\item $[0, 25) \cup (25, \infty)$
\end{enumerate}
\end{multicols}

\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A farmer wants to build a fence along a river.  He has
500 feet of fencing and wants to enclose a rectangular pen on three
sides (with the river providing the fourth side).  If $x$ is the
length of the side perpendicular to the river, determine the area of
the pen as a function of $x$.  What is the domain of this function?
\begin{sol}
$A=x(500-2x)$, $\ds \{x\mid 0\le x\le 250\}$
\end{sol}
\end{ex}

%%%%%%%%%
\begin{ex}
A can in the shape of a cylinder is to be made with a total
of 100 square centimeters of material in the side, top, and bottom;
the manufacturer wants the can to hold the maximum possible
volume. Write the volume as a function of the radius $r$ of the can;
find the domain of the function.
\begin{sol}
$\ds V=r(50-\pi r^2)$, $\ds \{r\mid 0< r\le \sqrt{50/\pi}\}$
\end{sol}
\end{ex}

%%%%%%%%%
\begin{ex}
A can in the shape of a cylinder is to be made to hold a
volume of one liter (1000 cubic centimeters). The manufacturer wants
to use the least possible material for the can. Write the surface area
of the can (total of the top, bottom, and side) as a function of the
radius $r$ of the can; find the domain of the function.
\begin{sol}
$\ds A=2\pi r^2+2000/r$, $\ds \{r\mid 0<r<\infty\}$
\end{sol}
\end{ex}

\begin{ex}
Suppose that it cost $\displaystyle{5 \cents \,}$ per minute to park at the airport with the rate dropping to $\displaystyle{3 \cents \,}$ after $9$ $\textsc{P.M.}$ Find and graph the cost function $c(t)$ for values of $t$ satisfying $0 \leq t \leq 120$. Assume that $t$ is the number of minutes after $8 \, \textsc{P.M.}$.
\end{ex}

\begin{ex}
The Canadian Federal tax rates for 2017 are shown in the following Table. \\

(a) Write a piecewise definition for the tax due $T(x)$ on an income of $x$ dollars. 	\\
(b) Find the tax due on a taxable income of $\$100,000$. \\

\vspace{-1cm}
$$\includegraphics[scale=0.45]{images/piecwiseTaxBracket}$$
\end{ex}

\end{multicols}

\end{enumialphparenastyle}

\pagebreak


\subsection{Average Precision}
\label{chp:fundamentals:sec:metrics:subsec:average_precision}

Due to the previously mentioned trade-off between recall and precision both of those metrics should be considered when optimizing a model for a task.
One metric which considers recall as well as precision is \ac{AP}.

\subsubsection{Definition}
\label{chp:fundamentals:sec:metrics:subsec:average_precision:definition}

\Textcite{Zhu:2004} defines it as the following:

\begin{equation}\label{eq:average_precision}
    AP = \sum_{i=1}^n {p(i)\Delta r(i)}
\end{equation}

Where $p(i)$ is the precision taking into account the first $i$ elements and $\Delta r(i)$ indicates the the recall change from the $i-1$th to the $i$th item.
With this metric the order of the sequence is crucial.
An algorithm which manages to sort a sequence of elements in a way that all relevant items are listed first achieves higher AP than an algorithm which performs poorly on the sorting task.

Let us consider the following example.
An algorithm was trained to return all relevant items from a dataset.
Given an unseen dataset of five items the model returns the following sorted sequence given in \cref{fig:metrics:average_precision:sample}.
The sequence is sorted in descending order, meaning the elements which the algorithm classifies as relevant with most confidence, are inserted first.
Consequently, in the example below the algorithm falsely classifies the second and fifth item as relevant.

\begin{figure}[htpb]
    \centering
    \def\svgwidth{\columnwidth}
    \input{figures/metrics/Average_Precision.pdf_tex}
    \caption[Example Sequence]{A sorted example sequence returned by some algorithm.}\label{fig:metrics:average_precision:sample}
\end{figure}

The sequence shown in \cref{fig:metrics:average_precision:sample} contains a total of three relevant items.
Following \textcite{Zhu:2004}, this yields a recall change $\Delta r(i)=\frac{1}{3}$ for a relevant item $i$ and $\Delta r(i)=0$ for an irrelevant one.
Now we can calculate the \ac{AP} according to \cref{eq:average_precision}:
\begin{equation}
    \begin{aligned}
        AP &= \sum_{i=1}^n {p(i)\Delta r(i)}\\
        &= \frac{1}{1} \cdot \frac{1}{3} + \frac{1}{2} \cdot 0 + \frac{2}{3} \cdot \frac{1}{3} + \frac{3}{4} \cdot \frac{1}{3} + \frac{3}{5} \cdot 0\\
        &=  (\frac{1}{1} + \frac{2}{3}  + \frac{3}{4}) \cdot \frac{1}{3}\\
        &\approx 0.81
    \end{aligned}
\end{equation}

\subsubsection{Interpretation}
\label{chp:fundamentals:sec:metrics:subsec:average_precision:interpretation}
The overall interpretation of \ac{AP} is intuitive: The more relevant items are ranked at the top of the returned sequence the higher is the \ac{AP} value.
However, in contrast to precision and recall, it is more difficult to judge whether the retrieved value for \ac{AP} is "good" or "bad".
Should we consider a system which yields $\ac{AP}=0.66$ as good?
In this part we want to address this issue and provide a tangible interpretation of the \ac{AP} value.

First we want to take a look at different example sequences and their corresponding \ac{AP} values.
We then derive an intuitive explanation for these example sequences which helps to judge \ac{AP} in general.
Let us consider two example sequences \textit{sequence 1} and \textit{sequence 2} shown in \cref{fig:metrics:average_precision:interpreation:sample}.

\begin{figure}[htpb]
    \centering
    \def\svgwidth{\columnwidth}
    \input{figures/metrics/Average_Precision_Example.pdf_tex}
    \caption[Two Example Sequences]{Two example sequences taken from \textcite{Tapaswi:2012}.}\label{fig:metrics:average_precision:interpreation:sample}
\end{figure}

For the first sequence we observe that \textit{every third} top ranked item is relevant whereas in the second sequence \textit{every second} item is.
We can now calculate the \ac{AP} for both sequences according to \cref{eq:average_precision} which yields $\ac{AP}_1= \frac{1}{3}$ for the first sequence and $\ac{AP}_2= \frac{1}{2}$ for the second one.
With the sequences above and their corresponding \acp{AP} $\ac{AP}_1$ and $\ac{AP}_2$ we can now conclude that an $\ac{AP}=\frac{1}{j}$ indicates that every $j$th item is relevant \parencite{Tapaswi:2012}.
With this in mind an $\ac{AP}=0.66$ is rather good, because approximately every $1.5$th item of the top ranked ones is relevant, whereas with an example $\ac{AP}=0.2$ only every fifth item is relevant.


\section{Application: Perspective rendering}

As an application of linear transformations, we consider the problem
of perspective rendering. Imagine some object has been described by
coordinates in 3-dimensional space, and we wish to make an image of
the object as it would be seen by a human eye or by a camera. The
process of computing such an image is known as \textbf{rendering}%
\index{rendering}.

Conceptually, the rendering process makes use of a \textbf{camera}%
\index{camera}, which we will assume is located at the origin of a
3-dimensional coordinate system called the \textbf{camera coordinate
  system}%
\index{camera coordinates}%
\index{coordinate system!camera coordinates}, and an \textbf{image
  plane}%
\index{image plane}%
\index{plane!image plane}, which we will assume is the plane $z=1$ in
camera coordinates. The 3-dimensional space also contains one or more
objects that we wish to render. We can consider the object to be
described by a set of points. For each point $\vect{p}$ on the object,
we draw a straight line from $\vect{p}$ to the camera, and let
$\vect{p}'$ be the point where this line intersects the image
plane. The point $\vect{p}$ of the object is rendered as the point
$\vect{p}'$ in the image. This process is illustrated in the following
figure:
\begin{equation*}
  \includegraphics[width=0.6\textwidth]{figures/perspective-chair}
\end{equation*}

% ----------------------------------------------------------------------
\subsection*{Object coordinates}

It is convenient to describe each object in its own coordinate system,
called the \textbf{object coordinate system}%
\index{object coordinates}%
\index{coordinate system!object coordinates}. To illustrate this
concept, we will consider a cube of side length 2, centered at the
origin. The 8 corners of this cube have the following coordinates in
the object coordinate system:
\begin{equation*}
  \begin{mymatrix}{r}  1 \\ 1 \\ 1 \end{mymatrix},~
  \begin{mymatrix}{r}  1 \\ 1 \\ -1 \end{mymatrix},~
  \begin{mymatrix}{r}  1 \\ -1 \\ 1 \end{mymatrix},~
  \begin{mymatrix}{r}  1 \\ -1 \\ -1 \end{mymatrix},~
  \begin{mymatrix}{r} -1 \\ 1 \\ 1 \end{mymatrix},~
  \begin{mymatrix}{r} -1 \\ 1 \\ -1 \end{mymatrix},~
  \begin{mymatrix}{r} -1 \\ -1 \\ 1 \end{mymatrix},~
  \begin{mymatrix}{r} -1 \\ -1 \\ -1 \end{mymatrix}.
\end{equation*}
For later reference, let us call this the \textbf{standard cube}%
\index{standard cube}. The following picture shows the standard cube
within its object coordinate system:
\begin{equation*}
  \begin{tikzpicture}[x={(0.8cm,-0.45cm)},y={(1cm,0.3cm)},z={(0cm,1.1cm)},scale=0.7]
    \draw[->] (-3,0,0) -- (3,0,0) node[right]{$y$};
    \draw[->] (0,3,0) -- (0,-3,0) node[left]{$x$};
    \draw[->] (0,0,-2.5) -- (0,0,2.5) node[right]{$z$};
    \begin{scope}
      \clip (1,1,1) -- (1,1,-1) -- (1,-1,-1) -- (-1,-1,-1)
      -- (-1,-1,1) -- (-1,1,1) -- cycle;
      \fill[blue!3] (1,1,1) -- (1,1,-1) -- (1,-1,-1) -- (-1,-1,-1)
      -- (-1,-1,1) -- (-1,1,1) -- cycle;
      \draw[black!30,->] (-3,0,0) -- (3,0,0);
      \draw[black!30,->] (0,-3,0) -- (0,3,0);
      \draw[black!30,->] (0,0,-2.5) -- (0,0,2.5);
    \end{scope}
    \draw[thick] ( 1, 1, 1) -- ( 1, 1,-1) -- ( 1,-1,-1) -- ( 1,-1, 1) -- cycle;
    \draw[thick] ( 1,-1, 1) -- (-1,-1, 1) -- (-1,-1,-1) -- ( 1,-1,-1) -- cycle;
    \draw[thick] ( 1, 1, 1) -- ( 1,-1, 1) -- (-1,-1, 1) -- (-1, 1, 1) -- cycle;
    \draw (1,0,0) -- (3,0,0);
    \draw (0,-3,0) -- (0,-1,0);
    \draw (0,0,1) -- (0,0,2.5);
  \end{tikzpicture}
\end{equation*}

% ----------------------------------------------------------------------
\subsection*{Conversion to camera coordinates}

Before we render an object, we need to place it in some appropriate
location relative to the camera. We do this by specifying four vectors
$\vect{q}$, $\vect{a}_x$, $\vect{a}_y$, and $\vect{a}_z$ in
$\R^3$. Here, $\vect{q}$ is the origin of the object coordinate
system, relative to the camera coordinate system. The vectors
$\vect{a}_x$, $\vect{a}_y$, and $\vect{a}_z$ are the axes of the
object coordinate system, relative to the camera coordinate system, as
shown in the following illustration:
\begin{equation*}
  \begin{tikzpicture}
    \fill (0,0) circle (0.1) node[below] {Camera};
    \begin{scope}[x={(-0.8cm,0.45cm)},z={(1cm,0.3cm)},y={(0cm,1.1cm)}]
      \draw[->] (0,0,0) -- (2,0,0) node[left]{$x$};
      \draw[->] (0,0,0) -- (0,2,0) node[left]{$y$};
      \draw[->] (0,0,0) -- (0,0,5) node[right]{$z$};
    \end{scope}
    \begin{scope}[shift={(4,3)}]
      \begin{scope}[x={(-1cm,-0.14cm)},y={(1.1cm,-0.35cm)},z={(0.2cm,1.3cm)},scale=0.7]
        \begin{scope}
          \clip (1,-1,1) -- (1,-1,-1) -- (1,1,-1) -- (-1,1,-1)
          -- (-1,1,1) -- (-1,-1,1) -- cycle;
          \fill[blue!3] (1,-1,1) -- (1,-1,-1) -- (1,1,-1) -- (-1,1,-1)
          -- (-1,1,1) -- (-1,-1,1) -- cycle;
        \end{scope}
        \draw[thick] ( 1, 1, 1) -- ( 1, 1,-1) -- ( 1,-1,-1) -- ( 1,-1, 1) -- cycle;
        \draw[thick] ( 1, 1, 1) -- (-1, 1, 1) -- (-1, 1,-1) -- ( 1, 1,-1) -- cycle;
        \draw[thick] ( 1, 1, 1) -- ( 1,-1, 1) -- (-1,-1, 1) -- (-1, 1, 1) -- cycle;
        \draw[thick,blue,->] (0,0,0) -- (1,0,0) node[left]{$\vect{a}_x$};
        \draw[thick,blue,->] (0,0,0) -- (0,1,0) node[right]{$\vect{a}_y$};
        \draw[thick,blue,->] (0,0,0) -- (0,0,1) node[right]{$\vect{a}_z$};
      \end{scope}
    \end{scope}
    \draw[thick,blue,->] (0,0) -- node[above=1ex]{$\vect{q}$}(4,3);
  \end{tikzpicture}
\end{equation*}
Thus, given a point with object coordinates
$\vect{v}=\begin{mymatrix}{c}x\\y\\z\end{mymatrix}$, we can find its
camera coordinates
$\vect{p} = \begin{mymatrix}{c} p_x \\ p_y \\ p_z \end{mymatrix}$ by
the following formula:
\begin{equation*}
  \vect{p} = \vect{q} + x\vect{a}_x + y\vect{a}_y + z\vect{a}_z.
\end{equation*}
If we write $A$ for the $3\times 3$-matrix whose columns are $\vect{a}_x$,
$\vect{a}_y$, and $\vect{a}_z$, we can also write this formula more succinctly as
\begin{equation*}
  \vect{p} = \vect{q} + A\vect{v}.
\end{equation*}

\begin{example}{Converting object coordinates to camera coordinates}{object-to-camera}
  Let
  \begin{equation*}
    \vect{q} = \begin{mymatrix}{c} 0 \\ 0.5 \\ 5 \end{mymatrix},\quad
    A = \begin{mymatrix}{ccc}
      0.8 & 0.6 & 0 \\
      0 & 0 & 1 \\
      0.6 & -0.8 & 0 \\
    \end{mymatrix}.
  \end{equation*}
  Convert each of the 8 corners of the standard cube from object
  coordinates to camera coordinates.
\end{example}

\begin{solution}
  Let $\vect{v}_1,\ldots,\vect{v}_8$ be the object coordinates of the
  8 corners of the cube:
  \begin{equation*}
    \begin{mymatrix}{r}  1 \\ 1 \\ 1 \end{mymatrix},~
    \begin{mymatrix}{r}  1 \\ 1 \\ -1 \end{mymatrix},~
    \begin{mymatrix}{r}  1 \\ -1 \\ 1 \end{mymatrix},~
    \begin{mymatrix}{r}  1 \\ -1 \\ -1 \end{mymatrix},~
    \begin{mymatrix}{r} -1 \\ 1 \\ 1 \end{mymatrix},~
    \begin{mymatrix}{r} -1 \\ 1 \\ -1 \end{mymatrix},~
    \begin{mymatrix}{r} -1 \\ -1 \\ 1 \end{mymatrix},~
    \begin{mymatrix}{r} -1 \\ -1 \\ -1 \end{mymatrix}.
  \end{equation*}
  We convert each of them to camera coordinates using the formula
  $\vect{p}_i = \vect{q} + A\vect{v}_i$:
  \begin{eqnarray*}
    \vect{p}_1 &=&
    \begin{mymatrix}{c} 0 \\ 0.5 \\ 5 \end{mymatrix}
    + \begin{mymatrix}{ccc}
      0.8 & 0.6 & 0 \\
      0 & 0 & 1 \\
      0.6 & -0.8 & 0 \\
    \end{mymatrix}
    \begin{mymatrix}{r}  1 \\ 1 \\ 1 \end{mymatrix}
    ~=~
    \begin{mymatrix}{r}  1.4 \\ 1.5 \\ 4.8 \end{mymatrix}, \\
    \vect{p}_2 &=&
    \begin{mymatrix}{c} 0 \\ 0.5 \\ 5 \end{mymatrix}
    + \begin{mymatrix}{ccc}
      0.8 & 0.6 & 0 \\
      0 & 0 & 1 \\
      0.6 & -0.8 & 0 \\
    \end{mymatrix}
    \begin{mymatrix}{r}  1 \\ 1 \\ -1 \end{mymatrix}
    ~=~
    \begin{mymatrix}{r}  1.4 \\ -0.5 \\ 4.8 \end{mymatrix}, \\
    \vect{p}_3 &=&
    \begin{mymatrix}{c} 0 \\ 0.5 \\ 5 \end{mymatrix}
    + \begin{mymatrix}{ccc}
      0.8 & 0.6 & 0 \\
      0 & 0 & 1 \\
      0.6 & -0.8 & 0 \\
    \end{mymatrix}
    \begin{mymatrix}{r}  1 \\ -1 \\ 1 \end{mymatrix}
    ~=~
    \begin{mymatrix}{r}  0.2 \\ 1.5 \\ 6.4 \end{mymatrix},
  \end{eqnarray*}
  and so on. Continuing in the same fashion, we find
  $\vect{p}_1,\ldots,\vect{p}_8$:
  \begin{equation}\label{eqn:object-to-camera}
    \begin{mymatrix}{r}  1.4 \\ 1.5 \\ 4.8 \end{mymatrix},
    \begin{mymatrix}{r}  1.4 \\ -0.5 \\ 4.8 \end{mymatrix},
    \begin{mymatrix}{r}  0.2 \\ 1.5 \\ 6.4 \end{mymatrix},
    \begin{mymatrix}{r}  0.2 \\ -0.5 \\ 6.4 \end{mymatrix},
    \begin{mymatrix}{r} -0.2 \\ 1.5 \\ 3.6 \end{mymatrix},
    \begin{mymatrix}{r} -0.2 \\ -0.5 \\ 3.6 \end{mymatrix},
    \begin{mymatrix}{r} -1.4 \\ 1.5 \\ 5.2 \end{mymatrix},
    \begin{mymatrix}{r} -1.4 \\ -0.5 \\ 5.2 \end{mymatrix}.
  \end{equation}
\end{solution}

We can also write $f:\R^3 \to \R^3$ for the function that converts
object coordinates to camera coordinates, i.e.,
\begin{equation*}
  f(\vect{v}) = \vect{q} + A\vect{v}.
\end{equation*}
We note that this is not a linear function, because
$f(\vect{0})\neq \vect{0}$. The function $f$ is called an
\textbf{affine function}%
\index{function!affine}%
\index{affine function}, which means that it is a linear function
$\vect{v}\mapsto A\vect{v}$ followed by a translation
$\vect{v}\mapsto \vect{q}+\vect{v}$.

% ----------------------------------------------------------------------
\subsection*{Rendering}

Once we know the camera coordinates
$\vect{p}=\begin{mymatrix}{c} p_x \\ p_y \\ p_z \end{mymatrix}$ of a point,
we need to render the point, i.e., find its coordinates in the image plane.
\begin{equation*}
  \begin{tikzpicture}
    \fill (0,0) circle (0.1) node[below] {Camera};
    \begin{scope}[x={(-0.8cm,0.45cm)},z={(1cm,0.3cm)},y={(0cm,1.1cm)}]
      \draw[->] (0,0,0) -- (2,0,0) node[left]{$x$};
      \draw[->] (0,0,0) -- (0,2,0) node[left]{$y$};
      \draw[->] (0,0,0) -- (0,0,5) node[right]{$z$};
      \draw[dashed,blue] (0,0,0) -- (1,2,5);
      \draw[fill=white] (-1.5,-1.5,2) -- (-1.5,1.5,2) -- (1.5,1.5,2) -- (1.5,-1.5,2) -- cycle;
      \draw[thin,black!20] (-1.5,-0.75,2) -- (1.5,-0.75,2);
      \draw[thin,black!20] (-1.5,0,2) -- (1.5,0,2);
      \draw[thin,black!20] (-1.5,0.75,2) -- (1.5,0.75,2);
      \draw[thin,black!20] (-0.75,-1.5,2) -- (-0.75,1.5,2);
      \draw[thin,black!20] (0,-1.5,2) -- (0,1.5,2);
      \draw[thin,black!20] (0.75,-1.5,2) -- (0.75,1.5,2);
      \fill[blue] (1,2,5) circle (0.06) +(0,0.1,0) node[left] {$\vect{p}$};
      \fill[blue] (0.4,0.8,2) circle (0.06) +(0,0.1,0) node[left] {$\vect{p}'$};
      \draw (0,0,0) -- (0,0,2);
      \draw[dashed,blue] (0,0,0) -- (0.4,0.8,2);
      \path (0,-1.9,2) node[below] {Image plane};
    \end{scope}
  \end{tikzpicture}
\end{equation*}
Since the camera is located at the origin, the line that passes
through the camera and the point $\vect{p}$ has the parametric equation
\begin{equation*}
  \vect{r} = t\vect{p} = \begin{mymatrix}{c} tp_x \\ tp_y \\ tp_z \end{mymatrix}.
\end{equation*}
Since the image plane is the plane $z=1$, we must set $t$ such that
$tp_z = 1$, i.e., $t=\frac{1}{p_z}$. Therefore, the coordinates of the
rendered point are
\begin{equation*}
  \vect{p}' = \frac{1}{p_z}\vect{p} =
  \begin{mymatrix}{c} p_x/p_z \\ p_y/p_z \\ 1 \end{mymatrix}.
\end{equation*}
Finally, since the image plane is $2$-dimensional, we can forget the
now useless $z$-coordinate, and render the point at the coordinates
$\begin{mymatrix}{c} p_x/p_z \\ p_y/p_z \end{mymatrix}$ in the
$2$-dimensional image plane.

\begin{example}{Rendering}{rendering}
  Render the cube from Example~\ref{exa:object-to-camera}.
\end{example}

\begin{solution}
  We must apply the rendering function
  \begin{equation*}
    g\paren{\begin{mymatrix}{c} p_x \\ p_y \\ p_z \end{mymatrix}}
    = \begin{mymatrix}{c} p_x/p_z \\ p_y/p_z \end{mymatrix}
  \end{equation*}
  to each of the corners of the cube from
  {\eqref{eqn:object-to-camera}}.
  We have
  \begin{eqnarray*}
    g\paren{\begin{mymatrix}{r}  1.4 \\ 1.5 \\ 4.8 \end{mymatrix}}
    &=& \begin{mymatrix}{r} 1.4/4.8 \\ 1.5/4.8 \end{mymatrix}
    ~=~ \begin{mymatrix}{r} 0.292 \\ 0.312 \end{mymatrix}, \\
    g\paren{\begin{mymatrix}{r}  1.4 \\ -0.5 \\ 4.8 \end{mymatrix}}
    &=& \begin{mymatrix}{r} 1.4/4.8 \\ -0.5/4.8 \end{mymatrix}
    ~=~ \begin{mymatrix}{r} 0.292 \\ -0.104 \end{mymatrix}, \\
    g\paren{\begin{mymatrix}{r}  0.2 \\ 1.5 \\ 6.4 \end{mymatrix}}
    &=& \begin{mymatrix}{r} 0.2/6.4 \\ 1.5/6.4 \end{mymatrix}
    ~=~ \begin{mymatrix}{r} 0.031 \\ 0.234 \end{mymatrix},
  \end{eqnarray*}
  and so on. The 8 rendered points are:
  \begin{equation*}
    \begin{mymatrix}{r} 0.292 \\ 0.312 \end{mymatrix}\!,\,
    \begin{mymatrix}{r} 0.292 \\ -0.104 \end{mymatrix}\!,\,
    \begin{mymatrix}{r} 0.031 \\ 0.234 \end{mymatrix}\!,\,
    \begin{mymatrix}{r} 0.031 \\ -0.078 \end{mymatrix}\!,\,
    \begin{mymatrix}{r} -0.056 \\ 0.417 \end{mymatrix}\!,\,
    \begin{mymatrix}{r} -0.056 \\ -0.139 \end{mymatrix}\!,\,
    \begin{mymatrix}{r} -0.269 \\ 0.288 \end{mymatrix}\!,\,
    \begin{mymatrix}{r} -0.269 \\ -0.096 \end{mymatrix}\!.
  \end{equation*}
  Drawing these in the 2-dimensional image plane, we get the following
  picture, which is the final perspective-rendered image of the cube:
  \begin{equation*}
    \begin{tikzpicture}[scale=10, thick]
      \draw[black!20, fill=blue!3] (0.292,0.312) -- (0.292,-0.104) -- (0.031,-0.078) -- (0.031,0.234) -- cycle;
      \draw[black!20, fill=blue!3] (0.031,0.234) -- (0.031,-0.078) -- (-0.269,-0.096) -- (-0.269,0.288) -- cycle;
      \draw[black!20, fill=blue!3] (0.292,0.312) -- (0.031,0.234) -- (-0.269,0.288) -- (-0.056,0.417) -- cycle;
      \draw[black!20, fill=blue!3] (0.292,-0.104) -- (0.031,-0.078) -- (-0.269,-0.096) -- (-0.056,-0.139) -- cycle;
      \draw (-0.056,0.417) -- (-0.056,-0.139) -- (-0.269,-0.096) -- (-0.269,0.288) -- cycle;
      \draw (0.292,0.312) -- (0.292,-0.104) -- (-0.056,-0.139) -- (-0.056,0.417) -- cycle;
    \end{tikzpicture}
  \end{equation*}
\end{solution}

% ----------------------------------------------------------------------
\subsection*{Animation}

We placed our object in the camera coordinate system using a
coordinate transformation function
\begin{equation*}
  f(\vect{v}) = \vect{q} + A\vect{v}.
\end{equation*}
One of the advantages of using such a coordinate transformation (as
opposed to specifying the object points directly in the camera
coordinate system) is that this makes it very easy to move the objects
around, rotate them, scale and shrink them, etc. For example:
\begin{enumerate}
\item To move the object to a different location, we only have to
  change the vector $\vect{q}$.
\item To rotate the object about its own $z$-axis, we only have to
  replace $\vect{v}$ by $R_{\theta}\vect{v}$, where $R_{\theta}$ is the matrix for a
  rotation about the $z$-axis by angle $\theta$:
  \begin{equation*}
    R_{\theta} = \begin{mymatrix}{ccc}
      \cos\theta & -\sin\theta & 0 \\
      \sin\theta & \cos\theta & 0 \\
      0 & 0 & 1 \\
    \end{mymatrix}.
  \end{equation*}
\end{enumerate}
Similarly to $R_{\theta}$, we can also insert other transformation
matrices (for example, we could rotate the object about its $x$-axis
instead of its $z$-axis, scale the object, etc).  We can even make an
animation by rendering the object repeatedly for different values of
these parameters.

\begin{example}{An animated cube}{animation}
  Make an animation of a rotating, moving cube. The animation is 5
  seconds long (i.e., time $t$ ranges from $0$ to $5$). The location
  of the cube at time $t$, in camera coordinates, is given by
  \begin{equation*}
    \vect{q}(t) =
    \begin{mymatrix}{c} -3+3t \\ -3 \\ 8+3t \end{mymatrix}.
  \end{equation*}
  The transformation matrix $A$ is as in
  Example~\ref{exa:object-to-camera}. Moreover, the cube should make
  one quarter rotation about its $z$-axis during the time of the
  animation, i.e., it should be transformed by $R_{\theta}$, where
  $\theta=\frac{\pi}{10}t$. Compute $6$ frames of the animation, for
  $t=0$, $t=1$, \ldots, $t=5$.
\end{example}

\begin{solution}
  For each of the animation frames $t\in\set{0,1,2,3,4,5}$, we do a
  calculation very similar to that of
  Examples~\ref{exa:object-to-camera} to convert the cube coordinates
  to camera coordinates, using the coordinate transformation
  \begin{equation*}
    f(\vect{v}) = \vect{q}(t) + AR_{\theta}\vect{v},
  \end{equation*}
  where $\theta=\frac{\pi}{10}t$. We then render each of the frames
  using the same method as in Example~\ref{exa:rendering}. We skip the
  detailed calculations, which are best done by computer (though they
  could be done by hand, of course, as we did in
  Examples~\ref{exa:object-to-camera} and {\ref{exa:rendering}}). The
  final rendered frames look like this:
  \begin{equation*}
    \begin{tikzpicture}[scale=12, thick]
      % Background:
      \draw[black!20,fill=blue!3] (-0.2979,-0.2128) -- (-0.5366,-0.2439) -- (-0.5366,-0.4878) -- (-0.2979,-0.4255) -- cycle;
      \draw[black!20,fill=blue!3] (-0.2051,-0.5128) -- (-0.2979,-0.4255) -- (-0.5366,-0.4878) -- (-0.4848,-0.6061) -- cycle;
      \draw[black!20,fill=blue!3] (-0.2051,-0.2564) -- (-0.2979,-0.2128) -- (-0.2979,-0.4255) -- (-0.2051,-0.5128) -- cycle;

      \draw[black!20,fill=blue!3] (0.0508,-0.1630) -- (-0.1092,-0.1721) -- (-0.1092,-0.3442) -- (0.0508,-0.3260) -- cycle;
      \draw[black!20,fill=blue!3] (0.1224,-0.3855) -- (0.0508,-0.3260) -- (-0.1092,-0.3442) -- (-0.0640,-0.4111) -- cycle;
      \draw[black!20,fill=blue!3] (0.1224,-0.1927) -- (0.0508,-0.1630) -- (0.0508,-0.3260) -- (0.1224,-0.3855) -- cycle;

      \draw[black!20,fill=blue!3] (0.2654,-0.1332) -- (0.1325,-0.1335) -- (0.1325,-0.2669) -- (0.2654,-0.2664) -- cycle;
      \draw[black!20,fill=blue!3] (0.3085,-0.3073) -- (0.2654,-0.2664) -- (0.1325,-0.2669) -- (0.1552,-0.3080) -- cycle;
      \draw[black!20,fill=blue!3] (0.3085,-0.1537) -- (0.2654,-0.1332) -- (0.2654,-0.2664) -- (0.3085,-0.3073) -- cycle;

      \draw[black!20,fill=blue!3] (0.2907,-0.1224) -- (0.2907,-0.2448) -- (0.2925,-0.2192) -- (0.2925,-0.1096) -- cycle;
      \draw[black!20,fill=blue!3] (0.4105,-0.1132) -- (0.2925,-0.1096) -- (0.2925,-0.2192) -- (0.4105,-0.2265) -- cycle;
      \draw[black!20,fill=blue!3] (0.4229,-0.2540) -- (0.4105,-0.2265) -- (0.2925,-0.2192) -- (0.2907,-0.2448) -- cycle;
      \draw[black!20,fill=blue!3] (0.4229,-0.1270) -- (0.4105,-0.1132) -- (0.4105,-0.2265) -- (0.4229,-0.2540) -- cycle;

      \draw[black!20,fill=blue!3] (0.3850,-0.1012) -- (0.3850,-0.2025) -- (0.4094,-0.1870) -- (0.4094,-0.0935) -- cycle;
      \draw[black!20,fill=blue!3] (0.5134,-0.0988) -- (0.4094,-0.0935) -- (0.4094,-0.1870) -- (0.5134,-0.1976) -- cycle;
      \draw[black!20,fill=blue!3] (0.4967,-0.2150) -- (0.5134,-0.1976) -- (0.4094,-0.1870) -- (0.3850,-0.2025) -- cycle;

      \draw[black!20,fill=blue!3] (0.4569,-0.0862) -- (0.4569,-0.1724) -- (0.5000,-0.1639) -- (0.5000,-0.0820) -- cycle;
      \draw[black!20,fill=blue!3] (0.5877,-0.0877) -- (0.5000,-0.0820) -- (0.5000,-0.1639) -- (0.5877,-0.1754) -- cycle;
      \draw[black!20,fill=blue!3] (0.5463,-0.1852) -- (0.5877,-0.1754) -- (0.5000,-0.1639) -- (0.4569,-0.1724) -- cycle;

      % Foreground:
      \draw (-0.4848,-0.3030) -- (-0.4848,-0.6061) -- (-0.5366,-0.4878) -- (-0.5366,-0.2439) -- cycle;
      \draw (-0.2051,-0.2564) -- (-0.2051,-0.5128) -- (-0.4848,-0.6061) -- (-0.4848,-0.3030) -- cycle;
      \draw (-0.2051,-0.2564) -- (-0.4848,-0.3030) -- (-0.5366,-0.2439) -- (-0.2979,-0.2128) -- cycle;

      \draw (-0.0640,-0.2055) -- (-0.0640,-0.4111) -- (-0.1092,-0.3442) -- (-0.1092,-0.1721) -- cycle;
      \draw (0.1224,-0.1927) -- (0.1224,-0.3855) -- (-0.0640,-0.4111) -- (-0.0640,-0.2055) -- cycle;
      \draw (0.1224,-0.1927) -- (-0.0640,-0.2055) -- (-0.1092,-0.1721) -- (0.0508,-0.1630) -- cycle;

      \draw (0.1552,-0.1540) -- (0.1552,-0.3080) -- (0.1325,-0.2669) -- (0.1325,-0.1335) -- cycle;
      \draw (0.3085,-0.1537) -- (0.3085,-0.3073) -- (0.1552,-0.3080) -- (0.1552,-0.1540) -- cycle;
      \draw (0.3085,-0.1537) -- (0.1552,-0.1540) -- (0.1325,-0.1335) -- (0.2654,-0.1332) -- cycle;

      \draw (0.4229,-0.1270) -- (0.4229,-0.2540) -- (0.2907,-0.2448) -- (0.2907,-0.1224) -- cycle;
      \draw (0.4229,-0.1270) -- (0.2907,-0.1224) -- (0.2925,-0.1096) -- (0.4105,-0.1132) -- cycle;

      \draw (0.4967,-0.1075) -- (0.5134,-0.0988) -- (0.5134,-0.1976) -- (0.4967,-0.2150) -- cycle;
      \draw (0.4967,-0.1075) -- (0.4967,-0.2150) -- (0.3850,-0.2025) -- (0.3850,-0.1012) -- cycle;
      \draw (0.4967,-0.1075) -- (0.3850,-0.1012) -- (0.4094,-0.0935) -- (0.5134,-0.0988) -- cycle;

      \draw (0.5463,-0.0926) -- (0.5877,-0.0877) -- (0.5877,-0.1754) -- (0.5463,-0.1852) -- cycle;
      \draw (0.5463,-0.0926) -- (0.5463,-0.1852) -- (0.4569,-0.1724) -- (0.4569,-0.0862) -- cycle;
      \draw (0.5463,-0.0926) -- (0.4569,-0.0862) -- (0.5000,-0.0820) -- (0.5877,-0.0877) -- cycle;

      % Labels:
      \path (-0.3750,-0.1250) node {$t=0$};
      \path (0.0000,-0.0909) node {$t=1$};
      \path (0.2143,-0.0714) node {$t=2$};
      \path (0.3529,-0.0588) node {$t=3$};
      \path (0.4500,-0.0500) node {$t=4$};
      \path (0.5217,-0.0435) node {$t=5$};
    \end{tikzpicture}
  \end{equation*}
  Note that there is a bit of distortion in the first and last cubes.
  This is because the camera is very close to the image plane (the
  scene has been ``filmed'' with a wide-angle camera). The distortion
  goes away if you close one eye and bring the other eye very close to
  the page.
\end{solution}


\section{World to image plane}
\label{sec:wrd2cam}
Accordingly with what we reported in Section \ref{sec:pinhole_camera}, the second step is to determine the 3D point coordinates in a reference system concordant with the image plane. The plane of interest $S$ is a plane parallel with lens plane and passing through the plane parallel to the sensor.  This choice is due to the possibility to tilt the lens with respect to the sensor, accordingly with the Scheimpflug principle, described above. If we consider the image plane parallel to the sensor directly, some issue arises. Tilting the lens changes the focal length of the camera, that varies point by point, resulting in a distorted image. This problem can be simplified observing that if we tilt the lens, we add an image plane rotated with respect to the classical image plane. In this way, the transformation between the two planes is a simple projection between planes. So we decided to split the problem in two subproblems: the first, described in this section, requires to change coordinates reference system; the second, described in Section \ref{sec:scheimflug}, needs to project the point on a different plane. Furthermore, this choice allows to simplify the mathematical model. \\

Let's focus on the Figure \ref{fig:laser-triang-a}.
  \begin{figure}[t!]
    \centering
    \includegraphics[width=0.7\textwidth]{./images/model/laser_triang_alpha.png}
    \caption{World to image plane}
    \label{fig:laser-triang-a}
  \end{figure}
As we can see, a change in the 3D point coordinates causes a variation in the image plane. However this alterations deals with the angle $\alpha$, estimated as offset from the triangulation angle $\phi$. Furthermore, laser plane and image plane are not parallel: this means that the two variations are different. What we are interested in, is the variation on the image plane, not in the world, so we can formulate this problem, accordingly with \cite{th:quattrini}, as:
  \begin{equation}
  	\alpha_i = \arctan\left( \frac{y_{s_i}}{f} \right)
    \label{eq:model:alpha}
  \end{equation}
where $y_{s_i}$ is the $i^{th}$ points in the image plane $S$. Being careful, it is simple to observe that the same relation is valid when determining the error due evaluating the $x$ coordinate, but with respect to the optical axis:
  \begin{equation*}
  	\beta_i = \arctan\left( \frac{x_{s_i}}{f} \right)
  \end{equation*}
Note that this step is important also to determine the natural camera resolution, in fact it allows to define the minimum variation appreciated by the sensor while it is observing the world.

So we can conclude writing that:
  \begin{equation}
    \label{eq:det_a}
  	\sigma_{\alpha_i} = \sqrt{
  	  \left( \frac{\partial \alpha_i}{\partial y_{s_i}} \right)^2 \sigma_{y_{s_i}}^2
  	  + \left( \frac{\partial \alpha_i}{\partial f} \right)^2 \sigma_f^2
  	}
  \end{equation} \\

Also in this case, $f$ is a parameter estimated thanks to the calibration processes, so we can consider it as negligible. Then, we can simplify Equation \ref{eq:det_a} as
  \begin{equation*}
  	\sigma_{\alpha_i} = \sqrt{
  	  \left( \frac{\partial \alpha_i}{\partial y_{s_i}} \right)^2 \sigma_{y_{s_i}}^2
  	}
  \end{equation*}
The same conclusions can be applied to $\beta_i$. \\

As we will see later, this transformation is the most delicate one, probably because of the change of reference system. In fact we can consider it as a passage from 3D to 2D reference system.


\documentclass[11pt]{article}

\usepackage{amsmath}

\title{Hello, World!}
\author{your name goes here}
\date{\today}

\begin{document}
    \maketitle

    Hello, world!

    \section{Inline Math}
    % Here we use \( and \) to write math inline with normal text.
    One of the trigonometric sum identities is
    \( \sin (x) + \sin (y) = 2 \sin (\frac{x+y}{2}) \cos (\frac{x-y}{2}) \).

    \section{Separate Math}
    % Here we use \[ and \] to write math separate from normal text.
    \[ \forall x \in X, \quad \exists y \leq \epsilon  \]

    \subsection{Product Rule}
    % Here we use both techniques
    If \(f\) and \(g\) are differentiable at \(x\), then

    \[ \frac{d}{dx}(f(x)g(x)) = f'(x)g(x) + f(x)g'(x) \]

\end{document}


\subsection{Representing integers}

We can expand the natural numbers to the integers.

Consider a byte representing the natural numbers. Previously this would have gone from \(0\) to \(255\), with a series of all \(1\)s representing \(255\).

To introduce integers all numbers with a \(1\) in the leftmost bit are considered to be negative.

\subsection{Two's complement}

We represent the value of these negative numbers with two’s complement. With two’s complement the number “after” \(127\) is \(-128\). Note that this does not just use the first bit as a sign. The use of two’s complement allows us to use the arithmetical logical units for the integers.


%---------------------------Shape---------------------------
\section{Shape\label{s:hex-shape}}

The shape metric is 3 divided by the minimum mean ratio
of the Jacobian matrix evaluated at the element corners:
\[
  q = 3\min_{i\in\{0,1,\ldots,8\}}
  \left\{
    \frac{{\alpha_i}^{\frac {2}{3}}} {|A_i|^2},
  \right\}.
\]

Note that if $\alpha_i \leq DBL\_MIN$ or $|A_i|^2 \leq DBL\_MIN$ for any $i$, we set $q = 0$.

\hexmetrictable{shape}%
{$1$}%                                        Dimension
{$[0.3,1]$}%                                  Acceptable range
{$[0,1]$}%                                    Normal range
{$[0,1]$}%                                    Full range
{$1$}%                                        Cube
{\cite{knu:03}}%                              Citation
{v\_hex\_shape}%                              Verdict function name


\section{Generative models}
\subsection*{Variational AEs}
$\mathbb{E}_x[f(x)]=\mathbb{E}_z[f(F_\theta(z))]$ law of the unconscious stat. \\
$\textbf{ELBO}(\phi, \theta)=\mathbb{E}_{z\sim q_\phi(z\vert x)}[log p_\theta (x\vert z)] - D_{\textbf{KL}}(q_\phi (z \vert x) \| p_\theta (z))$, $p_\theta (z)$ chosen prior. \\
$\nabla_\theta \mathbb{E}_{q_\phi}[log p_\theta (x\vert z)] \stackrel{\textit{Leibniz}}{=}  \mathbb{E}_{q_\phi}[\nabla_\theta log p_\theta (x\vert z)] \approx \frac{1}{N}\sum_{n\leq N} \nabla_\theta log p_\theta (x\vert z^{(n)}), z^{(n)} \sim q_\phi(.\vert x)$ \\
$\nabla_\phi \mathbb{E}_{q_\phi}[L(x,z)] =  \mathbb{E}_{q_\phi}[L(x,z)\nabla_\phi q_\phi(z\vert x)]$, (reinforcement trick) but high variance! $\rightarrow$ reparam.\\
$\nabla_\phi \mathbb{E}_{q_\phi}[L(x,z)] =  \mathbb{E}_{\epsilon}[\nabla_\phi L(x, g_\phi(\epsilon))]$ estimated via MC sampling \\
$z\sim \mathcal{N}(\mu, C),\, \nabla_\mu \mathbb{E}[f(z)] = \mathbb{E}[\nabla_z f(z)]$, (Bonnet)\\
$\nabla_U \mathbb{E}[f(z)] = \mathbb{E}_\epsilon[\epsilon^\top g], g := \nabla_\xi f(\xi) \vert_{\xi + U\epsilon + \mu} $

\subsection*{GANs}
Baye's optimal classifier: $q_\theta(x) = p / (p + p_\theta)$
Objective: $\mathbb{E}_{\tilde p_\theta}[y ln(q_\theta(x) + (1-y)ln(1-q_\theta(x)))]$ \\
\textbf{Optimizing GANs}: saddle-points problem, mode-collapse, unstability,... WIP