\documentclass{article}

\include{stddefs}
\include{imodefs}

\chapterno{2}

\begin{document}

\chapter{Linear equations}

Modern mathematical terminology may seem abstract, but a lot of it comes from
equation solving. We will talk about linear equations in this chapter to
motivate the concept of matrices in the next chapter.

Linear equations are equations, where the unknowns
only appear to the first power. For example,
$x^2 + x + 1 = 0$ is not a linear equation in the unknown $x$, since $x$ to the second power ($x^2$) appears in the equation,  whereas
$2 x - 3 = 1$ is.
We may also consider several linear equations with several unknowns, such as
\begin{align}
x + y + z &= 3\\
x - y + z &= 1\\ \label{eqstart}
x + y - z &= 1
\end{align}

consisting of three linear equations with the three unknowns $x$, $y$ and $z$.

\beginshex
Try to come up with a solution to \eqref{eqstart} i.e., find
numbers $x, y, z$ satisfying all three equations. Do not use a computer.
Is there more than one solution?

Write down two linear equations with two unknowns, which do not
have a solution.
\endshex

Do the exercise above, before you evaluate the Sage code below, which uses
the dreaded solve function. The solve function should always be used as a last resort.

\begin{sage}
x, y, z = var('x, y, z')
solve([x+y+z == 3, x - y + z == 1, x + y - z == 1],
x, y, z)
\end{sage}

\section{One linear equation with one unknown}

Very simple rules apply when solving linear equations.

Consider as an example the linear equation $2 x - 3 = 1$ in the unknown $x$.
Solving this equation amounts to reducing to an expression $x=$ a number. This
is called \emph{isolating} $x$. The process is very mechanical:
\begin{align*}
2 x - 3 &= 1\\
&\Updownarrow\\
2 x - 3 + 3 &= 1 + 3\\
&\Updownarrow\\
2 x &= 4\\
&\Updownarrow\\
\left(\frac{1}{2}\right) 2 x &= \left(\frac{1}{2}\right) 4\\
&\Updownarrow\\
x &= 2
\end{align*}
If you look closely, you will see that we have used the rules
\begin{align*}
&a=b\qquad \iff \qquad a + c = b + c\\
&a=b\qquad \iff \qquad t a = t b,
\end{align*}
where $a, b, c$ are numbers and $t$ is a number $\neq 0$.

\beginshex
Point out the mistake(s) in the \footnote{argument}{This teaser was presented at the workshop for new teaching assistants, August 2020.} below showing that $2 = 1$.
\begin{align*}
  a &= b \iff \\
  a^2 &= a b \iff\\
  a^2 - b^2 &= a b - b^2 \iff \\
  (a + b)(a - b) &= b (a - b) \iff\\
  a + b &= b \iff \\
  2 b &= b \iff \\
  2 &= 1.
\end{align*}
\endshex

\begin{quizexercise}[showhide]
\begin{quiz}
\question
A saline solution is a mixture of $0.9$\% sodium chloride in water. Suppose that you have
$2$ liters of water containing $9$\% sodium chloride. How many liters of
distilled water ($0$ percent sodium chloride)
do you need to add to get a saline solution.
\answer{F}
$4.5$ liter
\answer{F}
$10$ liter
\answer{T}
$18$ liter
\end{quiz}
\end{quizexercise}

\beginshex
Diophantus's youth lasted $1/6$ of his life. He grew a beard after $1/12$ more. After $1/7$ more
he got married. Five years later he had a son. The son lived half as long as the father
and Diophantus died four years after the son. At what age did Diophantus die?

\begin{hideinbutton}{Link/Hint}
  You can read about Diophantus and the solution to the puzzle in the \url{Wikipedia entry}{https://en.wikipedia.org/wiki/Diophantus} about him. Please
  try solving the problem on your own first.
\end{hideinbutton}
\endshex

\section{Several linear equations with several unknowns}

The linear equation $2 x - 3 = 1$ has only one unknown with the unique solution
$x=2$. \emph{If one linear equation has more than one unknown, then it has
  infinitely many solutions}. Consider as an example the linear equation
$2 x - 3 y = 1$ with the unknowns $x$ and $y$.
Using the procedure as before, we get
\begin{align*}
2 x - 3 y &= 1\\
&\Updownarrow\\
x &= \frac{1}{2} + \frac{3}{2} y
\end{align*}
Here we are free to choose $y$ in infinitely many ways giving
infinitely many solutions $(x, y)\in \RR^2$.

\subsection{Several equations}

Several equations with several unknowns also make sense. Consider
\begin{align*}
x + y &= 3\\
2 x - 3 y &= 1
\end{align*}
Two numbers $x$ and $y$ form a solution $(x, y)\in \RR^2$ if both equations are satisfied.
From the example above, we know that
\begin{equation}\label{isol}
x = \color{blue}{\frac{1}{2} + \frac{3}{2} y}.
\end{equation}
This can be inserted for $x$ in the first equation and we get
$$
3 = x + y = \color{blue}{\frac{1}{2} + \frac{3}{2} y} + y = \frac{1}{2} + \frac{5}{2} y.
$$
Here we end up with one linear equation in one variable $y$.
The solution is $y=1$, which is inserted in the equation \eqref{isol} giving
$x = 2$. Therefore the solution to the equations is $(x, y) = (2, 1)$.

\begin{quizexercise}[showhide]
\begin{quiz}
  \question
  \url{Kona coffee}{https://en.wikipedia.org/wiki/Kona_coffee} is a delicacy priced at $200$ kroner for $400$ grams.
  A standard $500$ gram bag of Arabica beans is priced at $60$ kroner.

  A merchant wishes to mix coffee beans of these sorts aiming for a price of
  $75$ kroner for $400$ grams. Which one of the percentages below
  comes closest to the content of Kona coffee in the mixture?

\answer{T}
$18\%$
\answer{F}
$5\%$
\answer{F}
$30\%$
\answer{F}
$12\%$
\end{quiz}
\end{quizexercise}

\section{Gauss elimination}

When solving systems of several linear equations, it is natural to
fix one of the equations, isolate an unknown and then insert
in the other equations.

Let us study this procedure focusing on an example with
two equations and three unknowns:
\begin{align*}
x + 2 y + z &= 8\\
2 x + y + z &= 7
\end{align*}
In the first equation we isolate $x = 8 - 2 y - z$, which is then inserted into the second
equation:
$$
2 x + y + z = 2(8 - 2 y - z) + y + z = - 3 y - z + 16 = 7 \implies -3 y - z = -9.
$$
It makes perfect sense to multiply the first equations by $2$ and subtract from the second
equations. This operation gives
$$
-3 y -  z = -9.
$$
It is not a coincidence that these two operations give the same result.

\begin{theorem}\index{Gauss elimination}
Suppose that
\begin{align*}
a_1 x_1 + a_2 x_2 + \cdots + a_n x_n &= c_1\\
b_1 x_1 + b_2 x_2 + \cdots + b_n x_n &= c_2
\end{align*}
are two linear equations in the unknowns $x_1, \dots, x_n$ with
$a_1\neq 0$. The equation gotten by first isolating
$x_1$ in the first equation and then inserting in the second equation
is identical to the equation you get by adding the first equation multiplied
by $-b_1/a_1$ to the second equation.
\end{theorem}
\begin{proof}[showhide]
  Isolating $x_1$ in the first equation inserted in the second equation gives
  the equation
\begin{equation}\label{equ1}
b_1\left(\frac{c_1}{a_1} - \frac{a_2}{a_1} x_2 - \cdots -\frac{a_n}{a_1} x_n\right) + b_2 x_2 + \cdots + b_n x_n = c_2
\end{equation}
Adding $-b_1/a_1$ multiplied to the first equation to the second equation gives
\begin{equation}\label{equ2}
\left(b_2 - \frac{b_1 a_2}{a_1}\right) x_2 + \cdots +
\left(b_n - \frac{b_1 a_n}{a_1}\right) x_n = c_2 - \frac{b_1}{a_1} c_1
\end{equation}
Using basic arithmetic you can see that \eqref{equ1} can be rewritten to
\eqref{equ2}.
\end{proof}

Multiplying an equation by a number and then adding to another equation
is easier to handle than the method of isolating and inserting. We have
showed above that they produce the same result. Below is
an extended example.

\begin{example}[showhide]
We wish to solve the system of equations

\begin{equation}\label{origlign}
\begin{matrix}
&2 x &+ &y &+ &z &= 7\\
&x &+ &2y &+ &z &= 8\\
&x &+ &y &+ &2 z &= 9
\end{matrix}.
\end{equation}

The first step is subtracting the third equation from the second:
$$
\begin{matrix}
&2 x &+ &y &+ &z &= 7\\
&x &+ &2y &+ &z &= 8\\
&x &+ &y &+ &2 z &= 9
\end{matrix}\quad\iff
\begin{matrix}
&2 x &+ &y &+ &z &= 7\\
& &  &y &- &z &= -1\\
&x &+  &y &+ &2 z &= 9
\end{matrix}
$$
Then we multiply the third equation by $2$ and subtract from the first:
$$
\begin{matrix}
&2 x &+ &y &+ &z &= 7\\
& &  &y &- &z &= -1\\
&x &+  &y &+ &2 z &= 9
\end{matrix}
\quad\iff
\begin{matrix}
& &-  &y &- &3 z &= -11\\
& &  &y &- &z &= -1\\
&x &+  &y &+ &2 z &= 9
\end{matrix}
$$
Finally we add the second equation to the first:
$$
\begin{matrix}
& &-  &y &- &3 z &= -11\\
& &  &y &- &z &= -1\\
&x &+  &y &+ &2 z &= 9
\end{matrix}\quad\iff
\begin{matrix}
& &  & &- &4 z &= -12\\
& &  &y &- &z &= -1\\
&x &+  &y &+ &2 z &= 9
\end{matrix}
$$
We have now reduced the original system of equations \eqref{origlign} to
$$
\begin{matrix}
& &  & &- &4 z &= -12\\
& &  &y &- &z &= -1\\
&x &+  &y &+ &2 z &= 9
\end{matrix},
$$
where the first equation shows that $z = 3$. Now $z = 3$ can be inserted into
the second equation, giving $y - 3 = -1$, which is solved by $y=2$.
Finally
$y = 2$ and $z=3$ are inserted into the third equations giving the equation
$x + 8 = 9$, which is solved by $x=1$.

One very important observation here is that $x=1, y=2$ and $z=3$ is the only
solution to  \eqref{origlign}. This is a logical consequence of the
bi-implication arrows $\iff$ throughout the above calculations.

\begin{sage}
x, y, z = var('x, y, z')
solve(
[2*x+y+z == 7,
x + 2*y + z == 8,
x + y + 2*z == 9],
x, y, z)
\end{sage}

\end{example}

The elimination or substitution method for solving systems of linear equations
is old and well known.
\url{Sir Isaac Newton}{https://en.wikipedia.org/wiki/Isaac_Newton} described in $1720$
the methods eloquently as follows.

\begin{quote}
  \emph{And you are to know, that by each Æquation one unknown Quantity may
  be taken away, and consequently, when there are as many Æquations
  and unknown Quantities, all at length may be reduc'd into one, in
  which there shall be only one Quantity unknown.}
\end{quote}

The mathematical rockstar \url{Carl Friedrich
  Gauss}{https://en.wikipedia.org/wiki/Carl_Friedrich_Gauss} used the method
to determine the orbit for the asteroid
\url{Pallas}{https://en.wikipedia.org/wiki/2_Pallas}. The mathematical analysis
of the observations lead him to the famous \url{least squares method}{https://en.wikipedia.org/wiki/Least_squares} and
a system of six linear equations with six unknowns.

The method is known today by the term \emph{Gaussian elimination} even though Gauss
was not the first to introduce it. In fact it appeared already in \emph{The Nine Chapters
  on the Mathematical Art}, which is an ancient Chinese mathematics book compiled over several
centuries from the 10th century BCE to the 2nd century CE. This book contains
several practical problems and their solutions. An example is
\begin{quote}
  There are three categories of corn. Three bundles of the first class,
  two of the second and one of the third make $39$ measures. Two of the
  first, three of the second, and one of the third make $34$ measures. Finally
  one of the first, two of the second and three of the third make $26$ measures.
  How many measures of graín are contained in one bundle of each class?
\end{quote}

\begin{quizexercise}[showhide]
 \begin{quiz}
\question
How many solutions does the system of equations below have?
\begin{align*}
x + y + z &= 0\\
x - y + z &= 0\\
x + y - z &= 0
\end{align*}
\answer{F}
None.
\answer{T}
Precisely one.
\answer{F}
Infinitely many.
\end{quiz}
\end{quizexercise}

\begin{quizexercise}[showhide]
How many solutions does the system of equations below have?
  \begin{quiz}
\question

\begin{align*}
x + y + z &= 0\\
x - y + z &= 0\\
5 x + y +5z &= 0
\end{align*}
\answer{F}
Precisely one.
\answer{F}
Precisely two.
\answer{T}
Infinitely many.
\end{quiz}
\end{quizexercise}

\beginshex
Find the solutions to
$$
\begin{matrix}
& x &+ &3 y &+ &z &= &2\\
&-2 x &- &5 y &+ &3 z &= &4.
\end{matrix}
$$
by expressing $x$ and $y$ in terms of $z$ i.e., isolate $x$ on the
left hand side, such that
\begin{align*}
  x &= \dots\\
  y &= \dots,
\end{align*}
where $\dots$ indicate an expression only in the unknown $z$.
\endshex

\beginshex
Your enemy transmits secret codes $(x_1, x_2, x_3, x_4)$ consisting of four integers $x_1, x_2, x_3, x_4$ over the internet. He does
not transmit the code itself but an encrypted version $(y_1, y_2, y_3, y_4)$ given by
\begin{equation*}
\begin{matrix}
  y_1 &= &2 x_1 &+ &x_2 &+ &3 x_3 &+  &4 x_4\\
  y_2 &= &x_1 &+ &2 x_2 &+ &3 x_3 &+  &4 x_4\\
  y_3 &= &3 x_1 &+ &3 x_2 &+ &x_3 &+  &x_4\\
  y_4 &= &4 x_1 &+ &4 x_2 &+ &2 x_3 &+  &3 x_4
\end{matrix}.
\end{equation*}
You have knowledge of the encryption method above and by listening in on
a recent communication, you learn that the encryption
$(15, 16, 12, 20)$ was sent. What was the original secret code before the encryption?

\begin{hideinbutton}{Extra credit}
  Suppose that you only know that the encryption scheme is
\begin{equation*}
\begin{matrix}
  y_1 &= &a_{11} x_1 &+ & a_{12} x_2 &+ &a_{13} x_3 &+  &a_{14} x_4\\
  y_2 &= &a_{21} x_1 &+ &a_{22} x_2 &+ &a_{23} x_3 &+  &a_{24} x_4\\
  y_3 &= &a_{31} x_1 &+ &a_{32} x_2 &+ &a_{33} x_3 &+  &a_{34} x_4\\
  y_4 &= &a_{41} x_1 &+ &a_{42} x_2 &+ &a_{43} x_3 &+  &a_{44} x_4
\end{matrix},
\end{equation*}
and that you have no knowledge of the numbers $a_{11}, \dots, a_{44}$.
How many transmissions do you need to know at the minimum to find
these encryption numbers?
\end{hideinbutton}

\endshex

\beginshex
The diagram below shows a network of roads and $6$ intersections.
Every road is labeled by a number indicating the average number
of cars per hour on the road. Some of these numbers
$f_1, \dots, f_7$ are unknowns. Write up a system of linear
equations for finding $f_1, \dots, f_7$.

\includegraphics{trafik.png}

Compute
$f_1, f_2, f_3, f_4, f_5, f_6$ supposing that $f_1=200$ and $f_7=100$.
\endshex

\begin{example}\label{Googleprlineqs}

This example relates to the famous Google page rank algorithm.

  \includegraphics{pagerankgraph.png}

  Suppose we have a very simple internet with only four webpages
  as depicted above with arrows indicating that a webpage links to another.

  We wish to study traffic in this network in the sense that we let a random
  websurfer jump from a given webpage to another by selecting a link randomly.

  If you look at the network without the punctured red arrow, it is almost clear
  the a random websurfer will spend $25$ \% of the time uniformly in each of the
  four nodes.

  However, if we introduce the puntured red arrow, then the percentages in
  each node are given by the linear equations above. Here it turns out that
  website $1$ only gets around $14$ \% of the time (the other websites get double this time each).

\end{example}

\begin{hideinbutton}{Simulation of page rank in python}
You may try out the python code below to simulate a random tour
of the small internet in Example \ref{Googleprlineqs}.

\begin{sage}
import random

# Incidence matrix

A = [[0,1,0,0], [0,0,0,1], [1,1,0,0], [0,0,1,0]]

def neighbors(n):
    return [i for i, e in enumerate(A[n]) if e != 0]

def simulate(n, num): # Simulate random walk num times from node n in matrix A
    count = [0] * len(A)
    node = n
    count[n] = 1
    for i in range(num):
        node = random.choice(neighbors(node))
        count[node] += 1
    return count

simulate(0, 1000)
\end{sage}

The list (or matrix)
\begin{code}
  A = [[0,1,0,0], [0,0,0,1], [1,1,0,0], [0,0,1,0]]
\end{code}
encodes the graph of links between the four nodes $0, 1, 2, 3$. From
$A$ you can see that $2$ links to $0$ and $1$ and that
$0$ links to $1$. The command

\begin{code}
  simulate(0, 1000)
\end{code}

simulates a random surf with $1.000$ clicks starting in node $0$.

The linear equations really seem to give the right result!
\end{hideinbutton}

\section{Polynomials}\label{section:polynomials}

Before going further into examples of linear equations we need to introduce (non-linear)
functions called \emph{polynomials}. A polynomial of degree $n$ is a function $f:\RR\rightarrow \RR$
of the form
\begin{equation}\label{poldef}
f(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0,
\end{equation}
where $a_0, \dots, a_n$ are real numbers and $a_n\neq 0$. We call $a_0, \dots, a_n$
the \emph{coefficients} of $f$.
The degree of the polynomial $f$ is denoted
$\deg(f)$. As an example,
$$
x^3 - 2 x + 17
$$
is a polynomial of degree $3$ with
\begin{align*}
  a_3 &= 1\\
  a_2 &= 0\\
  a_1 &= -2\\
  a_0 &= 17.
\end{align*}

In addition to the polynomials defined in \eqref{poldef} with $a_n\neq 0$,
we also view the function $f(x) = 0$ as a polynomial, called the \emph{zero polynomial}.
The zero polynomial does \footnote{not}{All its coefficients are zero!} have a degree.

The set of all polynomials is denoted
$\RR[x]$, so that for example it makes sense to write
$$
x^2 - 5 x + 6\in \RR[x].
$$
It is probably the most natural functions from $\RR$ to $\RR$ you can come up with.
If you look at \eqref{poldef}, you will see that the output is formed by using
addition and multiplication (by $x$ and selected real numbers).

You can compute with polynomials treating the \emph{variable} $x$ as
a number. For example,
$$
(3 x^2 + 2 x + 1) (2 x + 1) = 6 x^3 + 7 x^2 + 4 x + 1.
$$
In general a polynomial of degree $m$ times a polynomial of degree $n$ is a
polynomial of degree $m+n$.

In the sage window below we encounter for the first time the \texttt{sympy} library. The
input format and commands for handling polynomials should be clear from the context.

\begin{sage}
from sympy import expand
from sympy.abc import x
f = 3*x**2 + 2*x + 1
g = 2*x + 1
expand(f*g)
\end{sage}

You have already seen polynomials
of degree one. They have the form
$$
f(x) = a x + b,
$$
where $a$ and $b$ are real numbers and $a\neq 0$. Similarly
polynomials of degree two are called quadratic polynomials. They look
like
$$
f(x) = a x^2 + b x + c,
$$
where $a, b$ and $c$ are real numbers and $a\neq 0$.

To get a feeling for the behavior of polynomials you should experiment in the sage
window below. Try varying the degree and the coefficients of the polynomial in the plot.
Also adjust the plot interval for the right view.

\begin{sage}
  plot(x**4 - 10*x**3 + 35*x**2 - 50*x + 24, (x, 0.5, 4.5))
\end{sage}

\beginshex
Suppose that
$$
f(x) = a x^2 + b x + c.
$$
To compute $f(x)$ it seems that you need $3$ multiplications
($a\cdot x\cdot x$ and $b\cdot x$) and $2$ additions.
Can you compute $f(x)$ with only $2$ multiplications and $2$ additions?

Try to generalize to the computation of $f(x)$, where $f$ is a polynomial
$$
f(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0,
$$
of degree $n$ (you should only need $n$ multiplications and $n$ additions here).
\endshex

\subsection{Polynomial division}

Division is sometimes referred to as long division when
focusing on the method for division. Let us look
at the situation for integers first.

The remainder of
$14$ divided by $4$ is $2$, since
$$
14 = 3\cdot 4 + 2.
$$
Here the remainder $2$ is strictly less than the divisor $4$.

For polynomials we have a similar situation, where the degree
is taken into account. For example, the remainder of
$x^3 + x + 1$ divided by $x^2 + x + 1$ is $x+2$, since
\begin{equation}\label{poldiv}
x^3 + x + 1 = (x-1)(x^2 + x + 1) + (x+2).
\end{equation}
Here the degree of the remainder $1$ is strictly less
than the degree of the divisor $2$.

The Python library \url{\texttt{sympy}}{https://www.sympy.org/} contains a
wealth of functions for symbolic mathematics. In the window
below, it is shown how the polynomial division \eqref{poldiv}
is computed using the
\url{Polynomial Manipulaton}{https://docs.sympy.org/latest/modules/polys/index.html} section
of the \texttt{sympy} documentation.

\begin{sage}
from sympy import div
from sympy.abc import x
div(x**3+x+1, x**2+x+1)
\end{sage}

The (division) algorithm for carrying out (long) division of
polynomials is explained by an example in the video below.

\begin{video}
\youtube{SLIEUcOwVxA}
\end{video}

\beginshex
Watch the five minute video above and
carry out (do not use a computer) the polynomial division alluded to in \eqref{poldiv}.
\endshex

The general result about division of polynomials is given below.

\begin{theorem}[emph]\label{poldivthm}
Let $d(x)\in \RR[x]$ be a non-zero polynomial. Then
for every polynomial $f(x)\in \RR[x]$, there exists
polynomials $q(x), r(x)\in \RR[x]$, such that
\begin{equation}\label{identpol}
f(x) = q(x) d(x) + r(x),
\end{equation}
where $r(x) = 0$ or $\deg(r(x)) < \deg(d(x))$.
\end{theorem}
\begin{proof}[showhide]
We will prove this using induction on $n = \deg(f)$. Suppose that
$$
f(x) = a_n x^n + \cdots\qquad\text{and}\qquad d(x) = b_m x^m + \cdots
$$
In general if $\deg(d(x)) = m > n$, then
$$
f(x) = 0\cdot d(x) + f(x)
$$
satisfies the assumptions for the identity in \eqref{identpol} with
$ q(x) = 0$ and $r(x) = f(x)$.

If $m\leq n$, then $f(x) - a_n b_m^{-1} x^{n-m} d(x)$ is a polynomial of
degree $<n$. So by induction we may find polynomials $q_0(x)$ and $r_0(x)$, such that
$$
f(x) - a_n b_m^{-1} x^{n-m} d(x) = q_0(x) d(x) + r_0(x).
$$
Therefore
$$
f(x) = (q_0(x) + a_n b_m^{-1} x^{n-m})d(x) + r_0(x)
$$
giving the desired result with $q(x) = q_0(x) + a_n b_m^{-1} x^{n-m}$ and $r(x) = r_0(x)$.
\end{proof}

\subsection{Roots of polynomials}

A real number $\alpha\in \RR$ is called a \emph{root} of the polynomial $f(x)\in \RR[x]$ if
$f(\alpha) = 0$. This is a very fundamental definition. It is mirrored beautifully in the following
result.

\begin{proposition}\label{proproot}
A real number $\alpha$ is a root of the polynomial $f(x)\in \RR[x]$ if and only if
$$
f(x) = q(x) (x-\alpha),
$$
for some polynomial $q(x)\in \RR[x]$.
\end{proposition}
\begin{proof}[showhide]
By Theorem \ref{poldivthm}, we may write
\begin{equation}\label{degonediv}
f(x) = q(x)(x-\alpha) + r(x),
\end{equation}
where $r(x)= 0$ or $r(x)$ is a non-zero polynomial of degree zero i.e., a  non-zero
constant. Now the result follows, since $f(\alpha) = q(\alpha)(\alpha - \alpha) + r(\alpha) = r(\alpha)$
using \eqref{degonediv}.
\end{proof}

\beginshex
Is there an easy way of deciding if a polynomial $d(x) = a x + b$ of degree one divides
a polynomial $f(x)$ without performing the (long) division of $f(x)$ by
$d(x)$. Here divides means that $f(x) = q(x) d(x)$ for some polynomial $q(x)$.
\endshex

A quadratic polynomial
$$
a x^2 + b x + c
$$
has at most two roots given
by the formula (one root for $+$ and one for $-$ in $\pm$ below)
\begin{equation}\label{formulaqe}
\frac{-b\pm \sqrt{b^2 - 4 a c}}{2 a},
\end{equation}
if its \emph{discriminant} $b^2 - 4 a c$ is $\geq 0$.

\begin{frameit}
  Deriving the formula \eqref{formulaqe} comes from a classical algebraic trick called \emph{completing the square}. Looking
  at the quadratic equation $a x^2 + b x + c = 0$, what bothers us is the term $b x$. If $b=0$ we could solve the equation rewriting to
  $$
  x^2 = -\frac{c}{a}
  $$
  and then taking square roots. The first step in this direction is rewriting
  the equation
  $$
  a x^2 + b x + c = 0
  $$
  to
  \begin{equation}\label{eqi}
  x^2 + \frac{b}{a} x = -\frac{c}{a}.
  \end{equation}
  We would like to add a number $d^2$ to both sides of \eqref{eqi} so that the left hand side comes to look like
  \begin{equation}\label{eqii}
    (x + d)^2 = x^2 + 2 x d + d^2.
  \end{equation}
    This is what is called completing the square.

  Comparing the left hand side of \eqref{eqi} with the right hand side of \eqref{eqii}, we find that
  $$
  d = \frac{b}{2 a}
  $$
  works.
  Therefore \eqref{eqi} implies
  $$
  \left( x + \frac{b}{2a}\right)^2 = -\frac{c}{a} + \left(\frac{b}{2 a}\right)^2.
  $$
  This identity can be rewritten into the formula \eqref{formulaqe} for solving the
  quadratic equation.
  \end{frameit}

For polynomials of degree three (cubic
polynomials) there is a \url{formula}{https://en.wikipedia.org/wiki/Cubic_function#General_solution_to_the_cubic_equation_with_real_coefficients}, but these days nobody remembers it. Also for polynomials of
degree four (quartic polynomials) there is a \url{formula}{https://en.wikipedia.org/wiki/Quartic_function#Solution}. But for polynomials of degree five (quintic polynomials) and up, one can prove
that \url{a formula cannot exist}{https://en.wikipedia.org/wiki/Abel\%E2\%80\%93Ruffini_theorem}!

  An exceedingly important result is quoted and proved below: the degree of a polynomial is
  an upper bound for its number of roots.

\begin{theorem}[emph]\label{atmostn}
  A non-zero polynomial $f(x)\in \RR[x]$ of degree $n > 0$ can have at most $n$ roots.
\end{theorem}
\begin{proof}[showhide]
We will prove this by induction starting with $n = 1$. Here
$f(x) = a x + b$ for $a, b\in \RR[x]$ and
$$
f(\alpha) = 0\iff \alpha = - a^{-1} b.
$$
Therefore $f(x)$ has precisely one root. Suppose now that we have proved that
polynomials of degree $n$ has at most $n$ roots. Assume that
$f(x)$ is a polynomial of degree $n + 1$. If $f(x)$ has no roots,
we are done with the proof. Suppose that $f(\alpha) = 0$ i.e.,
$\alpha$ is a root in $f$. Then
$$
f(x) = q(x) (x-\alpha)
$$
by Proposition \ref{proproot}. Here $q(x)$ has to be a polynomial of degree $n$ and
therefore by induction, $q(x)$ has at most $n$ roots. However, if $f(\beta) = q(\beta) (\beta - \alpha) = 0$,
then either $\beta = \alpha$ or $q(\beta) = 0$. We have proved that
$f(x)$ cannot have more than $n+1$ roots.
\end{proof}

\begin{remark}\label{remarkatmostn}
  Theorem \ref{atmostn} has a few interesting consequences. First it implies that two
  identical polynomials i.e., $f(x) = g(x)$ for every $x\in \RR$ must have
  the same coefficients.

  Secondly if two polynomials $f(x)$ and $g(x)$ of degree $n$ satisfy
  $f(x_i) = g(x_i)$ for distinct points $x_1, \dots, x_{n+1}$, then
  $f(x) = g(x)$.
\end{remark}

\beginshex
In Remark \ref{remarkatmostn} it is stated that if two polynomials $f(x)$ and $g(x)$ of degree $n$ satisfy
  $f(x_i) = g(x_i)$ for distinct points $x_1, \dots, x_{n+1}$, then
  $f(x) = g(x)$. How does this follow from Theorem \ref{atmostn}?
\endshex

It might happen that a  polynomial of degree $n$ has precisely $n$ roots, but it could have less or
even no roots: the polynomials
$$
x^2 + 1, x^4 + 1, x^6 + 1, \dots
$$
have no roots, whereas for example
$$
x^2 - 2 x + 1
$$
is a quadratic polynomial with only one root. However polynomials of degree $1, 3, 5, \dots$ always have at
least one root.

\begin{theorem}[emph]
A polynomial of odd degree always has a root.
\end{theorem}

The proof of this result is beyond our scope now and will have to wait for tools from analysis.

\beginshex
Compute the roots of the quartic
$$
x^4 - 5x^2 + 6.
$$
\endshex

\beginshex
Give an example of a polynomial of degree $17$ with precisely one root.
\endshex

\beginshex
Suppose that $\alpha, \beta$ are two roots of the quadratic polynomial
$$
f(x) = x^2 + b x + c.
$$
How can $b$ and $c$ be computed in terms of $\alpha$ and $\beta$?
Show concretely how this can be applied to the polynomial
$g(x) = x^2 - 5 x + 6$: if you know that $g(2) = 0$ how can you easily
find the other root?

\begin{hint}
Show that $f(x) = (x-\alpha)(x-\beta)$ and use this.
\end{hint}
\endshex

\section{Applications to polynomials}

A line in the plane is given by its equation $y = a x + b$, where $a$ is the slope
and $b$ is the intersection with the $y$-axis. Two lines in the plane
are either parallel or intersect in a single point.

\beginshex
The two lines $y = x+1$ and $y=-x+2$ have a single point
of intersection. Compute this point.

Give an example of two parallel lines and their equations.
\endshex

Through two (distinct) points $(x_1, y_1)$ and $(x_2, y_2)$ with $x_1\neq x_2$ passes a unique line

\includegraphics[width="50\%"]{linje.svg}

You can find the equation for this line by solving
two equations with two unknowns $a$ and $b$:
\begin{align*}
x_1 a + b &= y_1\\
x_2 a + b &= y_2
\end{align*}
We might as well apply Gauss elimination to solve this system. First we
subtract the second equation from the first. This gives
$(x_1 - x_2) a = y_1 - y_2$. Therefore
$$
a = \frac{y_1 - y_2}{x_1 - x_2}.
$$
Inserting this $a$ in the first equation we get
$$
b = \frac{x_1 y_2 -x_2 y_1}{x_1 - x_2}.
$$
We can also in a quite explicit way just write
\begin{equation}\label{lagrlin}
y = f(x) = y_1 \frac{x - x_2}{x_1 - x_2} + y_2 \frac{x - x_1}{x_2 - x_1}.
\end{equation}
The function $f(x)$ in
\eqref{lagrlin} is a polynomial of degree one with
$f(x_1) = y_1$ and $f(x_2) = y_2$.

In almost the same way we may find a unique quadratic polynomial
$$
y = a x^2 + b x + c
$$
through three points $(x_1, y_1), (x_2, y_2)$ and $(x_3, y_3)$ with distinct $x$-values:

\includegraphics[width="50\%"]{parabel.svg}

Here we end up with three linear equations in the unknowns $a, b$ and $c$:
\begin{align}\label{lignpar}
x_1^2 a + x_1 b + c &= y_1\\
x_2^2 a + x_2 b + c &= y_2\\
x_3^2 a + x_3 b + c &= y_3
\end{align}
It is not immediately obvious that this system of equations has a solution. But watch the following trick evolve.

We may explicitly construct the quadratic polynomial passing through the three points as
\begin{align}\label{lagrpar}
  y = f(x) = &y_1 \frac{(x - x_2)(x-x_3)}{(x_1 - x_2)(x_1-x_3)} + y_2 \frac{(x - x_1)(x - x_3)}{(x_2 - x_1)(x_2-x_3)}\\
  &+ y_3 \frac{(x - x_1)(x - x_2)}{(x_3 - x_1)(x_3-x_2)}
\end{align}
Take a moment and verify that $f(x_1) = y_1, f(x_2) = y_2$ and $f(x_3)= y_3$. This also proves that
the system of equations in \eqref{lignpar} can be solved.

\begin{remark}
Notice in \eqref{lagrpar} that
$$
y = y_1 L_1(x) + y_2 L_2(x) + y_3 L_3(x),
$$
where (for example)  $L_1$ is a polynomial of degree two satisfying
$$
L_1(x_1)=1,\quad L_1(x_2)=0, \quad\text{and}\quad L_1(x_3)=0.
$$
What about $L_2$ and $L_3$ with respect to $x_1, x_2$ and $x_3$?
\end{remark}

\beginshex\label{lagrcol}
Compute the polynomial you get when you apply \eqref{lagrpar} to $x_1 = 1, x_2 = 2, x_3= 3$ and
$y_1 = 1, y_2 = 2, y_3 = 3$. How do you explain this result in terms of the
points $(x_1, y_1), (x_2, y_2)$ and $(x_3, y_3)$ plotted in plane?
\endshex

The natural generalization is that there exists a unique polynomial of degree $\leq n$ passing through $n+1$ points
$(x_1, y_1), \dots, (x_{n+1}, y_{n+1})$ with distinct $x$-values.

The rather miraculous trick above in \eqref{lagrpar} is called \url{Lagrange interpolation}{https://en.wikipedia.org/wiki/Lagrange_polynomial} and can be generalized to polynomials of arbitrary degree.
Below is an example of five points defining a unique polynomial of degree four.

\includegraphics[width="35\%"]{quartic.svg}

\subsection{The magic of Lagrange polynomials}

Let us study the remarkable polynomial in \eqref{lagrpar} a little deeper: suppose we have $n$ numbers
\begin{equation}\label{Lpts}
x_1, x_2, \dots, x_n.
\end{equation}
Then these numbers give $n$ polynomials each of degree $n-1$:
$$
L_i(x) = \frac{1}{C_i} (x-x_1) \cdots (x-x_{i-1})(x-x_{i+1}) \cdots (x - x_n),
$$
where
$C_i = (x_i-x_1) \cdots (x_i-x_{i-1})(x_i-x_{i+1}) \cdots (x_i - x_n)$ for
$i = 1, \dots, n$.

The polynomial $L_i(x)$ is called the $i$-th
\url{Lagrange basis polynomial}{https://en.wikipedia.org/wiki/Lagrange_polynomial}
associated to the $n$ numbers $x_1, \dots, x_n$.
It satisfies
$L_i(x_1) = \cdots = L_i(x_{i-1}) = 0$, $L_i(x_i) = 1$ and
$L_i(x_{i+1}) = \cdots = L_i(x_n) = 0$ i.e., $L_i(x)$ is equal to zero
evaluated at all of the numbers $x_1, \dots, x_n$ except at $x_i$
where it evaluates to $1$.

The Lagrange basis polynomials allow us to construct a polynomial $f$ of degree $\leq n$ through
$n+1$ points $(x_1, y_1), \dots, (x_{n+1}, y_{n+1})$ i.e., a polynomial $f$ such that
\begin{align*}
  f(x_1) &= y_1\\
         &\vdots\\
  f(x_{n+1}) &= y_{n+1}
\end{align*}
simply as
$$
f(x) = y_1 L_1(x) + \cdots + y_{n+1} L_{n+1}(x).
$$
However, $f(x)$ does not have to have degree $n$. For example, it could come out as a line through
three points $(x_1, y_1), (x_2, y_2)$ and $(x_3, y_3)$ (see Exercise \ref{lagrcol}).

\beginshex
Compute $a_0, a_1, a_2, a_3\in \RR$ so that
\begin{align*}
f(-2) &= -1\\
f(-1) &= 1\\
f(1) &= 1\\
f(2) &= 1,
\end{align*}
where
$$
f(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3.
$$
You can do this either by Lagrange interpolation or by solving linear equations. Which one
do you prefer?
\endshex

\begin{example}

Can you predict the next number in the sequence starting with
\begin{equation}\label{csseq}
15,\quad 34,\quad 65,\quad 111,\quad 175,\quad 260,\quad 369?
\end{equation}

This question \footnote{was posed}{Thanks to Tobias Bendsen Poulsen for notifying me about this.} by the tutors in a class session for new computer science students. Let us put the sequence \eqref{csseq} inside a table like

$$
\def\arraystretch{1.5}
\begin{array}{c|ccccccc}
n & 1 & 2 & 3 & 4 & 5 & 6 & 7\\ \hline
f(n) & 15 & 34 & 65 & 111 & 175 & 260 & 369
\end{array},
$$

where $f:\NN\rightarrow \NN$ is the secret function responsible for the sequence. We would like to compute $f(8)$. Assuming that the $f(n)$ is a polynomial function, we may simply compute the unique polynomial of  degree $\leq 6$ through the $7$ points
$$
(1, 15),\quad (2, 34),\quad (3, 65),\quad (4, 111),\quad (5, 175),\quad (6, 260),\quad (7, 369).
$$

We know how to do this either by solving linear equations or computing with Lagrange polynomials. It turns out that Sage has built in functions helping us here.

\begin{sage}
R = PolynomialRing(QQ, 'x')
f = R.lagrange_polynomial([(1, 15), (2, 34), (3, 65), (4, 111), (5, 175), (6, 260), (7, 369)])
f(8)
\end{sage}

Press the button to see what next number is in the sequence (computed using the secret polynomial). See also the
description of \url{Neville's algorithm}{https://en.wikipedia.org/wiki/Neville\%27s_algorithm} in Wikipedia for an easier approach to
computing $f(8)$.

\end{example}

\section{Shamir secret sharing}

Lagrange interpolation is used in cryptography in \url{Shamir's secret sharing}{https://en.wikipedia.org/wiki/Shamir\%27s_Secret_Sharing}. Secret sharing is important in many practical situations. Here is an example quoted from Wikipedia:
  \begin{quote}
    A company needs to secure their vault's passcode. They could
    encrypt it, but what if the beholder of the secret key is
    unavailable or turns rogue?

    One needs to distribute the secret. This is where SSS comes in. It
    can be used to encrypt the vault's passcode and generate a certain
    number of shares, where a certain number of shares can be
    allocated to each executive within the company. Now, only if they
    pool their shares can they unlock the vault. The threshold can be
    appropriately set for the number of executives, so the vault is
    always able to be accessed by the authorized individuals. Should a
    share or two fall into the wrong hands, they couldn't open the
    passcode unless the other executives cooperated.
  \end{quote}

  The mathematics that takes care of this is surprisingly simple. Suppose the secret is the
  number $a_0$. Then we construct the polynomial
  \begin{equation}\label{sss}
  f(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_m x^m
  \end{equation}
  for some other numbers $a_1, \dots, a_m$.  We know that this
  polynomial is uniquely given by its values in $m+1$ distinct numbers
  (see Remark \ref{remarkatmostn}). So if there are $n$ trusted people
  we could distribute the shares
  $$
  (1, f(1)), (2, f(2)), \dots, (n, f(n))
  $$
  to them. Here we suppose that $n > m$. In this setting, if there are less than $m+1$ of
  the people present they cannot open the vault. If $m+1$ or more people are present they
  can reconstruct the polynomial in \eqref{sss}, find the secret code $a_0$ and open
  the vault.

  \beginshex
  You are in a study group consisting of four people. The
  professor has decided that you submit your project using a
  secret code that is distributed to the group members with Shamir
  secret sharing. At least three group members need to agree on
  submission.

  On the day of the deadline three group members with shares
  $$
  (1, 7035),\quad (2, 19748)\quad\text{and}\quad (3, 39373)
  $$
  are present. What is the secret code they may use to submit their
  project?
  \endshex

\section{Fitting data}

Given a data set
$$
\mathcal{D} = \{ (x_1,y_1), (x_2,y_2), \dots, (x_n, y_n) \}
$$
one
would often like to find a model (i.e. some function) that describes
the data well. With Lagrange interpolation we can find a polynomial
$f$ fitting the sample data $\mathcal{D}$ perfectly, i.e. satisfying
$f(x_i) = y_i$ for $i = 1, 2, \dots n$. Is $ f $ an optimal model? For
the given data set it seems so, but we have been a bit imprecise in
formulating the goal of a model.

Actually, we are not very interested in modeling the data at hand
with extreme precision. What we want is a model that fits new data
well. Let us look at a concrete example.

  Consider the data set
  \begin{align*}
  \mathcal{D} = \{ {}& (0, 0.06), (0.5, 0.33), (1, 0.56), (1.5, 1.35), (2, 1.48),  (2.5, 1.15), \\
  &(3, 1.45), (3.5, 1.12), (4, 0.68), (4.5, 0.22), (5, -0.10) \}
  \end{align*}

  The data points $ (x_i,y_i) $, $ i=1,2,\dots,11 $, were generated as
  $ (x_i, p(x_i) + \epsilon_i) $ where $ p(x) = -0.2 x^2 + x$ is a
  quadratic polynomial and $ \epsilon_i \in [-0.4,0.4]$ is a random
  number to simulate noise. The polynomial $ p $ is the best possible
  model for unknown data as there will always by noise that can not be
  modeled. In real life $ p $ is what needs to be modeled based on
  the available data.

  In the figure below is a fit with a degree $2$ and degree $10$
  polynomial respectively. As we see, the degree $2$ polynomial is
  pretty close to the target $p$ compared to the degree 10 polynomial
  that nevertheless fits the data $\mathcal{D}$ perfectly. Generally a
  simple model is preferred over a complex, as the latter will have a
  tendency to fit noise. This phenomenon is called
  \url{overfitting}{https://en.wikipedia.org/wiki/Overfitting} and is
  an extremely important topic.

  An interactive version of this illustration with a little more bells and whistles can be found \url{here}{https://www.geogebra.org/m/hxwqrk4h}.

  \begin{figure}
  \label{overfitting}
  \includegraphics[width="50\%"]{overfitting.png}
    \caption{Fitting a degree $2$ polynomial (in red) and a degree $10$ polynomial (in blue) to the sample data $ \mathcal{D} $. The target function $p$ is the dashed curve. We see that the simple quadratic fit is much closer to the target function and hence performes better on new data.}
  \end{figure}

  In later chapters we will see how the degree $2$ polynomial fit was
  obtained. This is a nice example of a convex
  optimization problem.% called regression.

  \end{document}


\documentclass{homework}
\course{Math 5522H}
\author{Jim Fowler}
\input{preamble}

\begin{document}
\maketitle

\begin{inspiration}
In mathematics, existence is freedom from contradiction.
\byline{David Hilbert}
\end{inspiration}

\section{Terminology}

\begin{problem}
  What is the \textbf{Schwarz-Christoffel integral}?

    Be careful to discuss the choice of branches in the terms appearing
      in the integrand.
      \end{problem}
      \begin{solution}
      Let $\{a_1, \dots, a_N\}$ be a sequence of increasing real numbers and $\{b_1, \dots b_N\}$ a sequence of real numbers with $0<b_n<1$ for all $1\leq n\leq N$ such that $1 < \sum_{n=1}^N b_n$.
      \[
      S(z) = \int_0^z \left( \prod_{n=1}^N (\zeta - a_n)^{-b_n} \right) d\zeta
      \]
      The term $\zeta - a_n$ is defined using the log with a branch cut on the line $a_n - bi$ for $b\geq 0$. The cut is choosen so that $(\zeta - a_n)^{-b_n} = |\zeta - a_n|^{-b_n}$.
      \end{solution}
      \begin{problem}
        What is an elliptic integral?
        \end{problem}
        \begin{solution}
        An elliptic integral is a function $f:\R\to \R$ of the form
        \[
        f(y) = \int_0^y R(x, \sqrt{P(x)} dx
        \]
        with $R$ rational function and $P$ a polynomial of degree 3 or four.

        \end{solution}
        \begin{problem}
          What is the incomplete elliptic integral of the first kind?

            This integral is usually denoted by $F$, but confusingly the input
              to $F$ is sometimes called the ``parameter'' and other times called
                the ``modular angle'' and \textit{these are different}!
                \end{problem}
                \begin{solution}
                The incomplete elliptic integral of the first kind is a function
                \[
                F(\varphi, k) = \int_0^\varphi \frac{d\theta}{\sqrt{1- k^2\sin^2\theta}}
                \]

                \end{solution}
                \section{Computation}

                \begin{problem}
                  Find all solutions to
                    \[
                        \frac{1}{x} + \frac{1}{y} + \frac{1}{z} = 1
                          \]
                            for integers $x,y,z \in \Z$.
                            \end{problem}
                            \begin{solution}
                            WLOG let $x\leq y\leq z$. Then we must have $x\leq 3$ so the LHS is at least as big as 1. If $x=1,$ there is clearly no solution, and if $x=3$, then the only possible solution is $x=y=z.$

                            Finally we consider the case $x=2.$ In this case, we need to solve
                            \begin{align*}
                            \frac{1}{y} + \frac{1}{z} &= \frac{1}{2}\\
                            yz - 2z - 2y &= 0\\
                            (y - 2)(z - 2) &= 4\\
                            \end{align*}
                            From $1*4 = 4$ we get $y=3, z=6$ as a solution. From $2*2=4$ we get $y=z=4.$ There are no more factorizations of $4$ where the second term is bigger than the first, so these three are the only solutions up to permuting the variables.
                            \end{solution}
                            \begin{problem}
                              For $w$ in the upper half-plane, consider
                                \[
                                    f(w) = \int_0^w  \frac{dz}{\sqrt{1-z^2}}
                                      \]
                                        where $\sqrt{1-z^2}$ is holomorphic in the upper half-plane and positive when $w \in (-1,1)$.

                                          The function $f$ provides a conformal map from the upper half-plane to what region?

                                            What is a well-known name for the function $f$?
                                            \end{problem}
                                            \begin{solution}

                                            Let's rewrite this function
                                              \[
                                                  f(w) = \int_0^w  (1-z)^\frac{-1}{2}(1+z)^\frac{-1}{2} dz
                                                    \]
                                                    When $z\in (-1, 1),$ the integrand is strictly positive, so $f(w)$ and the image of is the real line on the interval with $x<R$ with $R$ given by
                                                    \[
                                                    \int_0^1 \frac{dz}{\sqrt{1-z^2}} = \arcsin(z)\bigg|_{z=0}^1 = \frac{\pi}{2}
                                                    \]
                                                    When $z\in (1, \infty)$, the integrand $(1-z)$ is purely imaginary, so the image is a vertical line starting at $\frac{\pi}{2}$ and going up. Since
                                                    \[
                                                    \lim_{w\to\infty} \int_0^w (1-z)^\frac{-1}{2}(1+z)^\frac{-1}{2} dz = \lim_{w\to\infty} \int_0^w O(\frac{1}{z}) = \infty
                                                    \]
                                                    the line goes all the way to $\oo.$ Similarly, the image of $(-\oo, -1)$ is a vertical line from $\frac{-\pi}{2}$ going straight up to $\oo.$

                                                    To decide which side of this box is the image of the interior of the half plane, notice that this is the integral of the derivative of the arcsin function, so this function is nothing but $\arcsin(z)$. $\arcsin$ will sends values into an injective domain of $\sin$, so it must send the upper half plane to the interior of this box rather than the exterior.
                                                    \end{solution}
                                                    \begin{problem}
                                                      Consider the function
                                                        \[
                                                            f(w) = \int_0^w  \frac{dz}{\sqrt{z} \sqrt{z+1} \sqrt{z-1}}
                                                              \]
                                                                which maps the upper half-plane to a square (after making appropriate branch cuts!).

                                                                  What is the side length of the square?

                                                                    \textit{Warning:} Your answer may still involve an integral.
                                                                    \end{problem}
                                                                    \begin{solution}
                                                                    Considering the derivative of this function, we see that it takes 3 right turns at the points $-1, 0, 1,$ and $\infty$ Using the branch cuts from the definition of the Schwarz-Christoffel integral, the integrand is real and positive when $z\in (1, \infty)$. So we can compute the side length of the square by integrating over this derivative from 1 to infinity. By the fundamental theorem of calculus, it is
                                                                    \[
                                                                    f(\oo) - f(1) = \int_1^\oo \frac{dz}{\sqrt{z}\sqrt{z+1}\sqrt{z-1}}
                                                                    \]
                                                                    Wolfram Alpha tells us that this is
                                                                    \[
                                                                    \frac{2\sqrt{\pi}\, \Gamma(\frac{5}{4})}{\Gamma(\frac{3}{4})} \approx 2.62206
                                                                    \]
                                                                    \end{solution}
                                                                    \begin{problem}
                                                                      Describe a biholomorphic map between the unit disk and the interior
                                                                        of an $n$-gon.
                                                                        \end{problem}
                                                                        \begin{solution}
                                                                        We can compose the Cayley transform with an appropriate Schwarz Christoffel integral to get such a biholomorphic map. The Cayley transform maps the unit disk to the upper half plane biholomorphically, and the integral will map the half plane into the interior of a polygon biholomorphically.

                                                                        % TODO why is it biholomorphic
                                                                        \end{solution}
                                                                        \section{Exploration}

                                                                        \begin{problem}
                                                                          When can a holomorphic map $f : B_1(0) \to B_1(0)$ have more than two fixed points?
                                                                          \end{problem}
                                                                          \begin{solution}
                                                                          The only time that $f$ can have two or more fixed points is when it is constant. Suppose, we have two points $a,b$ so that $f(a)=a$ and $f(b)=b.$

                                                                          We can find a biholomorphic map from the unit disk to itself swapping the point $a$ with the point $0$, call it $g$. Then it follows that
                                                                          \[
                                                                          (g^{-1}\circ f \circ g)(0) = (g^{-1}\circ f)(a) = g^{-1}(a) = 0
                                                                          \]
                                                                          Now we can apply the Schwarz lemma to the function $g^{-1}\circ f \circ g$ to conclude that if this function has a fixed point besides 0, then it must be constant.

                                                                          Since $g$ is bijective, there is a point $c$ so that $g(c)=b$ (hence $g^{-1}(b)= c$). Then
                                                                          \[
                                                                          (g^{-1}\circ f \circ g)(c) = (g^{-1}\circ f)(b) = g^{-1}(b) = c
                                                                          \]
                                                                          Using the Schwarz lemma as mentioned, we can conclude that $g^{-1}\circ f\circ g$ is constant, and hence $f$ is also constant.
                                                                          \end{solution}
                                                                          \begin{problem}
                                                                            Can a holomorphic map $f : \C \to \C$ which isn't the identity have
                                                                              more than two fixed points?
                                                                              \end{problem}
                                                                              \begin{solution}
                                                                              Yes, many do. Consider for example a cubic polynomial $p(z).$ At a fixed point, $p(z)=z$, and by the fundamental theorem of algebra, $p(z)-z$ has three roots. We can choose $p(z)$ so that there are no repeated roots and then find an example of such a function.
                                                                              \end{solution}
                                                                              \begin{problem}
                                                                                Does every holomorphic function $f : B_1(0) \to B_1(0)$ have a fixed point?
                                                                                \end{problem}
                                                                                \begin{solution}
                                                                                No. Consider the Cayley transform $g=\frac{z-i}{z+i}$ from the upper half plane to the unit disk. Then consider
                                                                                \[
                                                                                f = g\circ \left(z\to(z + 1)\right) \circ g^{-1}.
                                                                                \]
                                                                                $f$ has no fixed point, since if $f(z)=z,$ then
                                                                                \begin{align*}
                                                                                f(z) = z &= (g\circ \left(z\to(z + 1)\right) \circ g^{-1})(z)\\
                                                                                g^{-1}(z) &= g^{-1}(z) + 1
                                                                                \end{align*}

                                                                                Also, $f$ is a biholomorphism from $B_1(0)\to B_1(0)$ since adding $1$ is a biholomorphism from the upper half plane to itself.
                                                                                \end{solution}
                                                                                \begin{problem}
                                                                                For angles $\alpha, \beta, \gamma \in (0,2\pi)$ with $\alpha + \beta + \gamma = \pi$, the function
                                                                                \[
                                                                                f(z) = \int_0^z \frac{dw}{(w-A)^{1-\alpha/\pi} (w-B)^{1-\beta/\pi}}
                                                                                \]
                                                                                maps the upper half-plane to a triangle, and extends to a map $f : H \to T$ where $H$ is the closed half-space
                                                                                \[
                                                                                H = \{ x + iy \in \C : x, y \in \R \mbox{ and } y \geq 0 \},
                                                                                \]
                                                                                and $T$ is the (closed) triangle.

                                                                                Where does $f$ send the real line?
                                                                                \end{problem}
                                                                                \begin{solution}
                                                                                We are given that $f$ extends to a map $f:H\to T$ with $T$ the closed triangle, so $f$ sends the real line to the boundary of some triangle.

                                                                                To do find which one, we consider the derivative, easily computed with the fundamental theorem of calculus.
                                                                                \begin{align*}
                                                                                f'(z) &= (z - A)^{\alpha/\pi-1}(z - B)^{\beta/\pi-1}\\
                                                                                \arg(f'(z)) &= \arg((z - A)^{\alpha/\pi-1}(z - B)^{\beta/\pi-1})\\
                                                                                &= \arg\left(\begin{cases}
                                                                                0 & A > z \\
                                                                                \alpha/\pi - 1 & A < z \\
                                                                                \end{cases}
                                                                                \right)
                                                                                \arg\left(\begin{cases}
                                                                                0 & B > z \\
                                                                                \beta/\pi - 1 & B < z \\
                                                                                \end{cases}
                                                                                \right)
                                                                                \end{align*}
                                                                                Thus, the image of $f$ on the real line is a straight line with two curves at the points $f(A)$ and $f(B)$. At the point $A$, the curve takes a counterclockwise turn of exterior angle $\alpha - \pi$, hence interior angle $\alpha$. Similarly at the point $B$, the curve takes a counterclockwise turn of angle $\beta.$

                                                                                Finally, since $2 - \alpha + \beta > 1$, the integrand of $f(z)$ grows slower than $w^{-1}$ and hence the integral converges to some point $f(\infty),$ and this point is the same at both plus and minus infinity since $f$ is holomorphic. Thus the image of the real line line is the triangle with verticies $f(A), f(B),$ and $\lim_{z\to\infty} f(z).$
                                                                                \end{solution}
                                                                                \begin{problem}
                                                                                A M\"obius transformation $g(z) = (az + b)/(cz + d)$ with
                                                                                $a,b,c,d \in \R$ sends $H$ to itself.  Consider the composition
                                                                                \[
                                                                                f \circ g \circ f^{-1} : T \to T
                                                                                \]
                                                                                to describe a map from $T$ to itself, conformal on the interior of
                                                                                $T$, which permutes the vertices of $T$.
                                                                                \end{problem}
                                                                                \begin{solution}
                                                                                We consider the values $A$ and $B$ used in the last problem on the real line, and use a conformal mapping to scale and shift the plane with a function so that they go to $0$ and $1$. WLOG assume $B>A.$
                                                                                \[
                                                                                h(z) = (z - A)/(B - A)
                                                                                \]
                                                                                Then we can permute the locations of $0, 1, \oo$ on the real line by using this family of mobius tranformations. To send $0$ to $1$ , $1$ to $\oo$, and $\oo$ to $0$, the transformation
                                                                                \[
                                                                                g_1(z) = \frac{-1}{z-1}
                                                                                \]
                                                                                works. To swap the positions of $0$ and $\oo$, the tranformation
                                                                                \[
                                                                                g_2(z) = \frac{1}{z}
                                                                                \]
                                                                                works. By composing $g_1(z)$ and $g_2(z)$ in some ways, we can get a function $g$ that permutes the 3 points in any way that we may desire.

                                                                                Then we consider the transformation
                                                                                \[
                                                                                f\circ h^{-1}\circ g\circ h\circ f^{-1}
                                                                                \].

                                                                                $f^{-1}$ sends the triangle to the half plane, then $h^{-1}\circ g\circ h$ switches the locations of $A,B,$ and $\oo$, and finally, $f$ will send the half plane back to the triangle, but since the 3 points mapped to the corners have been permuted, the verticies of $T$ will be permuted by this transformation.
                                                                                \end{solution}
                                                                                \section{Prove or Disprove and Salvage if Possible}

                                                                                \begin{problem}
                                                                                A polygon's angles determine the polygon up to similarity.
                                                                                \end{problem}
                                                                                \begin{solution}
                                                                                Considering polygonal regions of the plane, this is false, since we can scale, shift, and rotate a polygon to change it. However, up to scaling and shifting, it is True. Given two polygons $P_1=[c_{1,1}, c_{1,2},\dots c_{1,n}]$ and $P_2 = [c_{2,1}, c_{2,2},\dots c_{2,n}]$ so that $c_{1,i}$ is the corner of $P_1$ with the same interior angle as $c_{2,i}$, we scale, shift, and rotate so that $c_{1,1}=c_{2,1}$ and $c_{1,2}=c_{2,2}$.

                                                                                Now assume that for $1, 2, \dots k$, $c_{1,k}=c_{2,k}$ with $k\geq 2.$ Then consider the triangle with corners
                                                                                \[
                                                                                \triangle(c_{1,k-1}, c_{1,k}, c_{1, k+1}) =
                                                                                \triangle(c_{2,k-1}, c_{2,k}, c_{1, k+1})
                                                                                \]
                                                                                Now, since this triangle has two of the same verticies as $\triangle(c_{2,k-1}, c_{2,k}, c_{2, k+1})$, and the angles associated with the two verticies are the same, these two triangles are the same by ASA triangle similarity. Thus $c_{2, k+1} = c_{1, k+1}.$

                                                                                By induction, all of the corners of $P_1$ and $P_2$ are in the same place and so the two polygons are equal.

                                                                                \end{solution}
                                                                                \begin{problem}
                                                                                Suppose $f : B_{1+\epsilon}(0) \to \C$ and if $|z| \leq 1$ then
                                                                                $|f(z)| \leq 1$.  Then $f$ has a fixed point in the unit disk
                                                                                $B_1(0)$.
                                                                                \end{problem}
                                                                                \begin{solution}
                                                                                True. Let $g(z) = (1 + \frac{\epsilon}{n})z$. Then on the unit circle, $\abs{g(z)}>\abs{f(z)}$. Since $g(z)$ has one zero contained in the unit circle, Rouche's theorem, tells us that $g(z) + f(z)$ has exactly one zero in the unit cirlce. Let $z_{n}$ be the point where
                                                                                \[
                                                                                g(z_n) + f(z_n) = 0.
                                                                                \]
                                                                                Expanding out g,
                                                                                \[
                                                                                z_n - f(z_n) = -z_{n}\frac{\epsilon}{n}
                                                                                \]
                                                                                Now consider the sequence $\{z_i\}_{1\leq i \leq\infty}.$ Each element in the sequence is an element of the compact set given by the unit disk $B_1(0).$ Therefore, there exists a subsequence $z_{a_i}$ approaching some accumulation point $A$, and on this subsequence, $z-f(z)$ gets arbitrarily close to 0. Since $f(z) - z$ is continuous and every open ball around $A$ contains points arbitrarily close to $0$, it follows that $f(A) - A = 0.$ Thus $A$ is a fixed point of $f$.
                                                                                \end{solution}
                                                                                \begin{problem}
                                                                                There exists a surjective holomorphic function
                                                                                $f : B_1(0) \to B_1(0)$ which is not injective.
                                                                                \end{problem}
                                                                                \begin{solution}
                                                                                True, $z^2$ is such a function. Any point in the ball has a square root with magnitude less than 1, and it's not injective since $\pm z$ map to the same point.
                                                                                \end{solution}
                                                                                \begin{problem}
                                                                                There exists a surjective holomorphic function $f : B_1(0) \to \C$.
                                                                                \end{problem}
                                                                                \begin{solution}
                                                                                True. Let $g_1$ be the Cayley transform mapping the disk to the upper half plane, $g_2(z) = z-i$, and $g_3(z) = z^2.$ Then $g_2\circ g_1$ maps the unit disk to a set containing the closed half plane, and $g_3$ maps the closed half plane to all of $\C$, so $g_3\circ g_2 \circ g_1$ is surjective onto $\C.$
                                                                                \end{solution}
                                                                                \end{document}


\section{Complexity Analysis}
\label{sec:analysis}

For the formal analysis, we assume a synchronous communication message-passing model with no faults. Thus, all nodes start executing the algorithm simultaneously and the time is divided into synchronous rounds, i.e., when a message is sent from node $v$ to its neighbor $u$ in time-slot $t$, it must arrive at $u$ before time-slot $t + 1$, and $d(v,u)$ is the shortest path length between $v$ and $u$ in $Ctree \cup IPtree \cup RCtree$. The performance of $\mu$Matrix in faulty scenarios is analyzed through simulations in Section \ref{sec:evaluation}.

\subsection{Memory footprint}
\label{subsec:memory-footprint}

As described in Section~\ref{sec:design}, the temporary routing information needed to maintain mobility is stored in the $Mtable$ data structure of some nodes. Each entry is kept for at most $TTL_{max}$ seconds, a time interval pre-configured by the network operator, and is deleted unless a \texttt{keepRoute} beacon is received. In the following theorem, we bound the total number of $Mtable$ entries in the network, necessary to manage routing of each mobile node $\mu \in CTree$.

\begin{theorem}\label{thm:memOneNode}
The memory footprint to manage the mobility of one node $\mu \in Ctree$ with $\mu$Matrix is $\mathcal{M}(\mu)=O(depth(Ctree))$.
\end{theorem}

\begin{proof}
Consider a node $\mu \in Ctree$ that has moved from its home location in time-slot $t_0$ and returned in time-slot $t_f$. Consider the (permanent) $IPparent(\mu)$ and the (temporary) $CTparent_{i}(\mu)$ in time-slot $t_0 < t_i < t_f$. A routing entry for the temporary location of $\mu$ will be stored in the $Mtable$ of every node comprising the shortest path between $IPparent(\mu)$ and $CTparent_{i}(\mu)$. Moreover, if $\mu$ has descendants in the IPtree, i.e, $k(\mu)=|IPchildren(\mu)|>0$, then each node $c\in IPchildre(\mu)$ will send a temporary (bi-directional) route request to their respective $CTparent_{i}(c)$, and a (temporary) routing entry will be stored in the Mtable of every node comprising the shortest path between $CTparent_{i}(c)$ and $IPparent(\mu)$. Therefore, the total memory footprint to manage the mobility of a node $\mu$ is:
\begin{eqnarray*}
    \mathcal{M}(\mu) & = &  d(CTparent_{i}(\mu), IPparent(\mu)) + 1 \nonumber \\
                     & + & \sum_{c \in IPchildren(\mu)} (d(CTparent_{i}(c), IPparent(\mu))+1) \nonumber \\
                    & \leq & (k(\mu)+1) \times (depth(Ctree)+1) \nonumber \\
                    &=& O(depth(Ctree)) \qedhere \nonumber
\end{eqnarray*}
\end{proof}

Theorem~\ref{thm:memOneNode} implies that the total memory footprint to manage the mobility of $m$ nodes is $O(m \times depth(Ctree))$. Note that $\mu$Matrix preserves locality when managing mobile routing information of a node $\mu$, since no $Mtable$ needs to be updated at nodes above the $LCA(IPparent(\mu),CTparent(\mu))$.

\subsection{Control message overhead}
\label{subsec:control-message-overhead}

Control messages used by $\mu$Matrix are comprised of three types: (1) those used by Matrix to set up the initial IPtree and address allocation; (2) \texttt{hasMoved} beacons, defined in Section~\ref{subsec:reverse-tt}; and (3) \texttt{keepRoute} beacons, defined in Section \ref{subsubsec:controlDataStructures}.

For any network of size $n$ with a spanning collection tree Ctree rooted at node $r$, the message and time complexity of Matrix protocol in the address allocation phase is $\mathcal{M}sg(Matrix^{IP}$ $(Ctree))$ = $O(n)$ and $\mathcal{T}(Matrix^{IP}$ $(Ctree))$ = $O(depth(Ctree))$, respectively, which is asymptotically optimal, as proved in \cite{Peres:2016}. Next we bound the number of control messages of type (2) and (3).

\begin{theorem}\label{thm:costOverOneNode}
Consider a network with $n$ nodes, with a spanning collection tree $Ctree$ rooted at node $r$, and $m$ mobility events, consisting of $m$ nodes $\mu_i$, changing location during time intervals $\Delta_i \leq \Delta$ time-slots.
Moreover, consider the \texttt{hasMoved} beacon parameters $I_{min}$, $I_{max}$ and $I_k$ and the \texttt{keepRoute} beacon interval of $\delta$ time-slots. The control message complexity of $\mu$Matrix to perform
routing under mobility of $m$ nodes is
\begin{eqnarray}
\mathcal{M}sg(\mu Matrix(Ctree)) &=&O\left(\frac{m\times I_k}{I_{min}} + \frac{n}{I_{max}}\right) \nonumber\\
&+& O\left(\frac{m \times \Delta}{\delta} depth(Ctree)\right).\nonumber
\end{eqnarray}
\end{theorem}
\begin{proof}
Firstly, we bound the number of \texttt{hasMoved} beacons, which are sent periodically by all nodes in order to detect mobility events. As described in Section~\ref{subsec:reverse-tt}, when there is no mobility, the periodicity of \texttt{hasMoved} beacons is $1/I_{max}$. If some node $\mu$ has moved (an ack is lost), then $I_k$ messages are sent in intervals of $I_{min}$ time-slots. Using the fact that the network is a tree and the number of edges is $O(n)$, this gives a total of messages $$Msg(\mu Matrix^{\texttt{hM}}(Ctree)) = O\left(\frac{m\times I_k}{I_{min}} + \frac{n}{I_{max}}\right).$$

Now, we bound the number of \texttt{keepRoute} beacons. As described in Section~\ref{sec:design}, mobile nodes send periodic \texttt{keepRoute} beacons at a frequency of $\delta$ to keep the $Mtable$s up-to-date. Consider a node $\mu \in Ctree$ that has moved from its home location in time-slot $t_0$ and returned in time-slot $t_f$. Consider the $IPparent(\mu)$, $CTparent_i(\mu)$ in time-slot $t_0 < t_i < t_f$, and $\Delta = t_f - t_0$. When $\mu$ is attached to a $CTparent_i(\mu)$, $\mu$ sends \texttt{keepRoute} beacons at a rate of $\delta$ for at most $\Delta$ time-slots, such beacons travel the shortest path $|(CTparent_i(\mu),$ $IPparent(\mu))|$ $\leq $ $2 \times depth(Ctree)$. Furthermore, if $\mu$ has descendants, i.e., $k(\mu) = $ $|IPchildren(\mu)|$ $ > 0$, then each node $c \in IPchildren(\mu)$ will also send \texttt{keepRoute} beacons at a rate of $\delta$ for at most $\Delta$ time-slots, such beacons will travel the shortest path $|(CTparent_i(c),$ $IPparent(\mu))|$ $\leq $ $2 \times depth(Ctree)$. Therefore, the total control overhead to manage the mobility of a node $\mu$ is $ \leq 2$ $\times depth(Ctree) (k(\mu) + 1) \Delta/\delta$, which results in $$\mathcal{M}sg(\mu Matrix^{\texttt{kR}}(Ctree))=O\left(\frac{m \times \Delta}{\delta} depth(Ctree)\right).$$ Finally, the total control overhead is bounded by: $$\mathcal{M}sg(\mu Matrix) = \mathcal{M}sg(\mu Matrix^{\texttt{hM}}) + \mathcal{M}sg(\mu Matrix^{\texttt{kR}})\qedhere$$
\end{proof}

Once again $\mu$Matrix preserves locality when managing mobile routing state of a node $\mu$ since no messages need to be sent to nodes above the $LCA(IPparent(\mu),CTparent(\mu))$.

\subsection{Routing path distortion}
\label{subsec:path-distortion}

We analyze the route length of messages, addressed to mobile nodes. Consider the underlying collection protocol (e.g. CTP or RPL), which dynamically optimizes the (bottom-up, or upwards) links in the collection tree $CTree$, according to some metric, such as ETX. We define an \textit{optimal route} length as the distance of the shortest path between $(s,d)$, comprised of the upwards links of the collection tree $CTree$ and the downwards links of the union of the IPv6 address tree and the reverse-collection tree, i.e., $IPtree \cup RCtree$.

\begin{theorem}
\label{theo:optimal-routing} $\mu$Matrix presents optimal path distortion under mobility, i.e., all messages are routed along shortest paths towards mobile destination nodes.
\end{theorem}

\begin{proof}
Consider a mobile node $\mu \in CTree$, which has moved from its home location in time-slot $t_0$. Messages addressed to $\mu$ and originated by some node $\eta \in Ctree$ in time-slot $t_i > t_0$ can belong to traffic flows of three kinds: (1) bottom-up: $LCA_i(\mu,\eta)=\mu$; (2) top-down: $LCA_i(\mu,\eta)=\eta$; and (3) any-to-any: $LCA_i(\mu,\eta)$ $\neq \mu $ $\neq \eta$. In case (1), messages are forwarded using the underlying collection protocol, using the upwards links of the collection tree CTree, which is optimal. In case (2), messages are forwarded using Mtables of $\eta$ and its descendents, until reaching the mobile location of $\mu$ in some time-slot $t_f>t_0$. This path is comprised of the downwards links of $IPtree \cup RCtree$ in time-slot $t_0 < t_i \leq t_f$, which is the optimal route from $\eta$ to the mobile location of $\mu$ in that time-slot. In case (3), the route between $\eta$ and $LCA_i(\mu,\eta)$ falls into the case (1) and the route between $LCA_j(\mu,\eta)$ and $\mu$ falls into the case (2), for some $t_0 < t_i \leq t_j \leq t_f$, which is optimal.
\end{proof}


\subsection{Example}\label{sec:sample-example}

The set-based approach to solving inverse problems can lead to errors in approximating measures, particularly around the boundaries of the solution set.
By contrast, the sample-based approach we introduced above more accurately approximates a uniform density over a subset of the initial parameter space at a given sample size $\nsamps$.
The reason for this is that the approach has a different source of error, involving estimating to push forward of the initial density.
The sample-based approach does not rely on a Voronoi-cell approximation of contour events, and instead assigns probability to random samples drawn from an initial density.

We are interested in studying how our ability to estimate a uniform density is impacted by the number of samples drawn from the initial density.
We form an inverse problem with the identity map an standard uniform initial densities, with observed densities being uniform over $[0.4, 0.6]^2$, representing a hundred-fold reduction in uncertainty when the problem is solved

We solve the same problem as in the set-valued example \ref{sec:set-example}, but use a uniform initial density in place of a uniform ansatz.
We sample $N=1E2$, $1E3$ and $1E4$ samples from the initial density and use Gaussian kernel density estimation to approximate the denominator in Eq [TK - eq], and show the resulting updated densities in Figure~\ref{fig:ex:identity_sampling_1E2} and \ref{fig:ex:identity_sampling_1E3_1E4} alongside the analytical solution.

The jagged edges of the shapes that we saw in \ref{fig:ex:identity_set_1E3_1E4} are replaced by unambiguous squares.
The relative probability that is assigned within the support is also more uniform, visually represented by the uniformity of color in the density plot.

\begin{figure}
\begin{minipage}{.975\textwidth}
\includegraphics[width=\linewidth]{./examples/identity/samp/N100_N100-vs-Analytical_N100.png}
\end{minipage}
\caption{
(Left): $\nsamps=100$ were used to construct the predicted distribution $\predicted$.
(Right): By specifying an analytical $\predicted$, the effect of using $\nsamps$ to approximate a pushforward distribution disappears. The problem can be fully specified in BET without any random sampling.
}
\label{fig:ex:identity_sampling_1E2}
\end{figure}

\begin{figure}
\begin{minipage}{.975\textwidth}
\includegraphics[width=\linewidth]{./examples/identity/samp/N1000_N1000-vs-N10000_N10000.png}
\end{minipage}
\caption{
$\nsamps=1,000$ (left) and $\nsamps=10,000$(right) were used to construct the predicted distribution $\predicted$.
There is no signficant error in estimating the support of the distribution, only the density approximation itself.
}
\label{fig:ex:identity_sampling_1E3_1E4}
\end{figure}

The sample-based method trades one source of accuracy for another.
The sample-based method provides a compelling alternative to be set-based method when estimating boundaries of a set (which represents an equivalent class of solutions), is important.
When few model evaluations are available and the observed distribution is non-uniform, the lack of need to use nearest-neighbor sampling (discretizing with $\ndiscs$), also provides a benefit.
However, we know that this is not without its pitfalls, as density estimation in high dimensions can become prohibitively prone to error \cite{Silverman}.


% Preamble.
\documentclass[12pt]{article}
\usepackage[margin=1.25in]{geometry}
\usepackage[fleqn]{amsmath}
\usepackage{textcomp}
\usepackage{gensymb}
\usepackage{amsfonts}
\usepackage{enumitem}
%\usepackage{tikz}  % Include for figures.
%\usepackage{subfiles}  % Include for subfiles.

%% Title macros.
\newcommand{\HOMEWORKNUM}{9}
\newcommand{\NAME}{D. Choi}
\newcommand{\DATE}{2020-06-03}

\title{\vspace{-2\baselineskip}MATH 225 - Homework \#\HOMEWORKNUM}
\author{\NAME}
\date{\DATE}

%% Formatting options.
%\pagenumbering{gobble}  % Include for single-page document.

% Document.
\begin{document}
\maketitle

\section*{1.}
\textit{Find the $2 \times 2$ projection matrix that projects vectors
orthogonally onto $y = -5x$.} \\[\baselineskip]
Let $\phi = \tan^{-1}(-5)$, so that $y = \tan(\phi)x$. \\
Let $\hat u(\theta)$ be the unit vector at an angle of $\theta$ to the
positive x-axis:
\begin{equation*}
	\hat u(\theta) = \begin{pmatrix} \cos \theta \\ \sin \theta \end{pmatrix}
	.
\end{equation*}
Let $M$ be the orthographic projection matrix onto $y = \tan(\phi)x$ with
elements $a$, $b$, $c$, and $d$:
\begin{equation*}
	M = \begin{pmatrix} a & b \\ c & d \end{pmatrix}
	.
\end{equation*}
The vectors $(a, c)$ and $(b, d)$ can be found by computing geometrically
where the standard unit basis vectors $(1, 0)$ and $(0, 1)$ respectively will
land upon being transformed by $M$. $M$ can be considered as the vector
projection onto $\hat u(\phi)$:
\footnotesize
\begin{gather*}
	\begin{pmatrix} a \\ c \end{pmatrix}
	=
	M \begin{pmatrix} 1 \\ 0 \end{pmatrix}
	=
	\text{proj}_{\hat u(\phi)} \hat u(0)
	=
	\cos(\phi) \hat u(\phi)
	=
	\cos(\phi)
	\begin{pmatrix}
		\cos(\phi) \\
		\sin(\phi)
	\end{pmatrix}
	=
	\begin{pmatrix}
		\cos^2(\phi) \\
		\frac{1}{2}\sin(2\phi)
	\end{pmatrix}
	\\
	\begin{pmatrix} b \\ d \end{pmatrix}
	=
	M \begin{pmatrix} 0 \\ 1 \end{pmatrix}
	=
	\text{proj}_{\hat u(\phi)} \hat u(\frac{\pi}{2})
	=
	\cos(\phi - \frac{\pi}{2}) \hat u(\phi)
	=
	\sin(\phi)
	\begin{pmatrix}
		\cos(\phi) \\
		\sin(\phi)
	\end{pmatrix}
	=
	\begin{pmatrix}
		\frac{1}{2}\sin(2\phi) \\
		\sin^2(\phi)
	\end{pmatrix}
	.
\end{gather*}
Note that
$\cos(\theta - \frac{\pi}{2})$ = $\sin(\theta)$ and
$\sin(\theta)\cos(\theta) = \frac{1}{2}\sin(2\theta)$.
\normalsize
\\[\baselineskip]
Thus,
\begin{equation*}
	M
	=
	\begin{pmatrix}
		\cos^2(\phi) & \frac{1}{2}\sin(2\phi) \\
		\frac{1}{2}\sin(2\phi) & \sin^2(\phi)
	\end{pmatrix}
	=
	\boxed{
		\begin{pmatrix}
			\frac{1}{26} & -\frac{5}{26} \\
			-\frac{5}{26} & \frac{25}{26}
		\end{pmatrix}
	}
	.
\end{equation*}
To verify,
\begin{gather*}
	\begin{pmatrix}
		\frac{1}{26} & -\frac{5}{26} \\
		-\frac{5}{26} & \frac{25}{26}
	\end{pmatrix}
	\begin{pmatrix} 1 \\ -5 \end{pmatrix}
	=
	\begin{pmatrix} 1 \\ -5 \end{pmatrix}
	\\
	\begin{pmatrix}
		\frac{1}{26} & -\frac{5}{26} \\
		-\frac{5}{26} & \frac{25}{26}
	\end{pmatrix}
	\begin{pmatrix} 5 \\ 1 \end{pmatrix}
	=
	\begin{pmatrix} 0 \\ 0 \end{pmatrix}
	.
\end{gather*}

\section*{2.}
\textit{Calculate the dot product of $c = (-4, -9)$ and $d = (-1, 2)$. Do the
vectors form an acute angle, right angle, or obtuse angle?}\\[\baselineskip]
Note that algebraically $a \cdot b = a^T b$, and that geometrically
$a \cdot b =
\left\lVert a \right\rVert \left\lVert b \right\rVert \cos(\theta)$
where $\theta$ is the angle between
$a$ and $b$.
\\[\baselineskip]
The dot product can be computed algebraically:
\begin{equation*}
	c \cdot d = c^T d
	=
	\begin{pmatrix} -4 & -9 \end{pmatrix}
	\begin{pmatrix} -1 \\ 2 \end{pmatrix}
	=
	\boxed{-14}
	.
\end{equation*}
Because $c \cdot d$ is negative while
$c \cdot d =
\left\lVert c \right\rVert \left\lVert d \right\rVert \cos(\theta)$, \\
\boxed{\text{the vectors form an obtuse angle}}.

\section*{3.}
\textit{If $a = (6, -1, 3)$, for what value of $c$ is the vector
$b = (4, c, -2)$ perpendicular to $a$?}\\[\baselineskip]
By the geometric definition of the dot product, the dot product of two
perpendicular vectors must equal $0$. \\[\baselineskip]
Thus,
\begin{equation*}
	c \cdot d = c^T d =
	\begin{pmatrix} 6 & -1 & 3 \end{pmatrix}
	\begin{pmatrix} 4 \\ c \\ -2 \end{pmatrix}
	= 18 - c = 0.
\end{equation*}
Solving for $c$, \boxed{$\textit{c} = 18$}.

\section*{4.}
\textit{Find the angle between the vector $(1, 1, 1)$ and the vector
$(-1, -2, 0)$. Explain before you find it whether you think the answer should
be positive, negative, or $0$.} \\[\baselineskip]
Because the vectors are in approximately opposite directions (note that
``approximately opposite'' is very rigorous), the angle should be obtuse.
\begin{equation*}
	(1, 1, 1) \cdot (-1, -2, 0)
	=
	-3
	=
	\sqrt{15} \cos(\theta)
\end{equation*}
Solving for $\theta$,
$\boxed{\theta = \cos^{-1}(-\sqrt{\frac{3}{5}}) \approx 140.8 \degree}$.

\end{document}


\documentclass[11pt]{article}
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage{amsmath}
\begin{document}
\title{MAT1830 --- Assignment 4}
\author{Dylan Pinn --- 24160547}
\maketitle

\section*{Question 1}
Let $a_1,a_2,a_3,\dots$ be the sequence of integers defined by
$$a_1=3,a_2=9,\text{ and } a_i=12a_{i-1}-9a_{i-2} \text{ for each integer } i \geq 3$$
Prove by strong induction that $3^n$ divides $a_n$ for all integers $n \geq1$.

\textbf{Proof:} Let $P(n)$ be the statement "$3^n$ divides $a_n$".

\textbf{Base Steps:}
\begin{align*}
	a_1 &= 3 = 3^1 \times 1 \\
	a_2 &= 9 = 3^2 \times 1
\end{align*}

As $3^n$ divides both $P(1)$ and $P(2)$ are true.

\textbf{Induction Step:}
Suppose that $P(1),P(2),\dots,P(k)$ are true for some integer $k < n$. We want to prove that $P(k)$ is true when $k = n$.

\begin{align*}
	P(n) &= 12a_{n-1} - 9a_{n-2} \text{ (from above) } \\
	P(n-1) &= 3^{n-1}b \text{ (for some integer b)} \\
	P(n-2) &= 3^{n-2}c \text{ (for some integer c)} \\
	P(n) &= 12(3^{n-1}b) - 9(3^{n-2}c) \text{ (substituting)} \\
	&= 3^n(\frac{12b}{3^1} - \frac{9b}{3^2}) \\
	&= 3^n(4a - b)
\end{align*}

As $a$ and $b$ are integers then $4a-b$ is an integer and therefore $3^n(4a-b)$ is divisible by $3^n$.

\break
\section*{Question 2}
Let $R,S$ and $T$ be sets defined as follows.

\begin{align*}
	R &= \{ x: x \in \mathbb{Z} \text{ and either } x \leq -2 \text{ or } x \geq 5 \} \\
	S &= \{ -3,-2,4,5,6 \} \\
	T &= \{ x: x \in \mathbb{Z} \text{ and } x \geq 2 \}
\end{align*}

Find the following.

\begin{enumerate}[label=(\roman*)]
	\item $R \cap S$
	$$= \{ -3,-2,5,6 \}$$
	\item $R - T$
	$$= \{x: x \in \mathbb{Z} \text{ and } x \leq -2 \} $$
	\item $R \triangle S$
	$$= \{x: x \in \mathbb{Z} \text{ and } x < -3 \text{ or } x > 6 \}$$
	\item $\mathcal{P} (R) \cap \{ \{-6,-3,5\},\{4,5\},\{7\},\{\},\{-3,1,7\}\}$
	$$= \{\{7\},\{\}\}$$
	\item $|\mathcal{P}(\mathcal{P}(S \cap T))|$
	\begin{align*}
		U &= S \cap T = \{4,5,6\} \\
		Y &= |\mathcal{P}(U)| = 2^3 = 8 \\
		|\mathcal{P}(Y)| &= 2^8 = 256
	\end{align*}
	Therefore $|\mathcal{P}(\mathcal{P}(S \cap T))| = 256$
\end{enumerate}

\break
\section*{Question 3}

\begin{enumerate}[label=(\roman*)]
	\item Is $(A\cap B) \times C = (A \times C) \cap (B \times C)$ true for all sets $A,B$ and $C$? If, so prove it. If not, give an example of sets $A,B$ and $C$ for which it is false.

	$(A\cap B) \times C = (A \times C) \cap (B \times C)$

	\begin{enumerate}[label=\arabic*]
		\item So, $(x,y) \in (C\times A)$ and $(x,y)\in(C\times B)$,
		same as

		$(x,y)\in(C\times A) \cap (C \times B)$, so

		$C \times (A \times B) \subseteq (C \times A)\cap (C \times B)$

		\item So, $(x,y) \in (C \times A) \cap (C \times B)$ and need to show that

		$(x,y) \in C \times (A \cap B)$

		We know that $(x,y)\in (C \times A)$ and $(x,y)\in (C \times B)$.

		Definition of cartesian product gives us $x \in A$ and $x \in B$ and $x \in C$.

		Therefore, $y \in A \cap C$ and $(x,y)\in C \times (A \cap B)$, so

		$(C \times A)\cap(C \times B) \subseteq C \times (A \times B)$
	\end{enumerate}

	As both equations in 1 and 2 are subsets of each other they are equal.

	\item Is $\mathcal{P}(A)\cup \mathcal{P}(B) = \mathcal{P}(A \cup B)$ true for all sets $A$ and $B$? If, so prove it. If not, give an example of sets $A$ and $B$ for which it is false.

	Not true. For example $A = \{1\}$ and $B=\{2,3\}$

	\begin{align*}
		\mathcal{P}(A) &= \{\emptyset,\{1\}\} \\
		\mathcal{P}(B) &= \{\emptyset,\{2\},\{3\},\{2,3\}\} \\
		\mathcal{P}(A) \cup \mathcal{P}(B) &= \{\emptyset,\{1\},\{2\},\{3\},\{2,3\}\} \\
		\mathcal{P}(A \cup B) &= \{\emptyset,\{1\},\{2\},\{3\},\{1,2\},\{1,3\},\{2,3\},\{1,2,3\}\}
	\end{align*}

	Therefore $\mathcal{P}(A)\cup \mathcal{P}(B) \not= \mathcal{P}(A \cup B)$.
\end{enumerate}

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\title{CW13}
\author{Jacob Anabi and Gage Kizzar }
\date{December 2018}

\begin{document}

\maketitle

\section{Abstract}
In this paper, we attempt to solve, plot, and interpret a two coupled set of ODES, also known as the 'Duffing oscillator':

$$\dot{x}(t) = y(t)$$
$$m\dot{y}(t) = -\nu y(t) + x(t) - x^3(t) + F\cos(\omega t)$$

We will solve these equations numerically, for $m=1$, $\nu = 0.25$, and $\omega = 1$, using a time-step size of $\Delta t = 0.001$ with the 4th-order Runge-Kutta integration method. We will be adjusting $x_0$, $y_0$, $F$, and the domain $t$.

\section{Introduction}
Let's consider a ball of mass $m$ with horizontal coordinate $x$ rolling in a double-well potential $V(x) = x^4/4 - x^2/2$. We will jiggle the ball at the bottom of the well. Thus, the ball, according to Newton's Second Law of Motion, must satisfy the following equation:

$$m\ddot{x} = f_{\text{hat}}(x) + f_{\text{drag}}(\dot{x}) + f_{\text{drive}}(t) = x - x^3 - \nu \dot{x} + F\cos(\omega t)$$

We can split this into two coupled first-order ODEs:

$$\dot{x}(t) = y(t)$$
$$m\dot{y}(t) = -\nu y(t) + x(t) - x^3(t) + F\cos(\omega t)$$

\section{Plots and Interpretation}

$F=0.18$, $x(0)=-0.9$, and $y(0)=0$

\begin{figure}[h!]
\centering
\includegraphics[scale=0.4]{x(t)1.png}
\includegraphics[scale=0.4]{y(t)1.png}
\includegraphics[scale=0.4]{parametriccurve1.png}
\includegraphics[scale=0.4]{poincare1.png}
\end{figure}

By examining our $t\,\, vs.\,\, x(t)$ and $t\,\, vs.\,\, y(t)$ graph, we can see some sort of oscillation, which is expected from our system. The system appears periodic. The Poincare section shows the system clustering at a single point.

$F = 0.18$, $x(0) = 0.9$, and $y(0) = 0$

\begin{figure}[h!]
\centering
\includegraphics[scale=0.4]{x(t)2.png}
\includegraphics[scale=0.4]{y(t)2.png}
\includegraphics[scale=0.4]{parametriccurve2.png}
\includegraphics[scale=0.4]{poincare2.png}
\end{figure}

Changing our initial $x-value$ has led to our system clustering at a different point in the well.

$F = 0.25$, $x(0) = 0.2$, and $y(0) = 0.1$

\begin{figure}[h!]
\includegraphics[scale=0.4]{x(t)3.png}
\includegraphics[scale=0.4]{y(t)3.png}
\includegraphics[scale=0.4]{parametriccurve3.png}
\includegraphics[scale=0.4]{poincare3.png}
\end{figure}

Changing our $F-value$ and initial $x-value$ and $y-value$ seems to create a slightly chaotic system; it is getting harder to examine a pattern in Poincare section compared to our previous plots. Additionaly, the object seems to attract more to the right side of the well. We will test this by tweaking the initial condition very slightly.

$F = 0.25$, $x(0) = 0.201$, and $y(0) = 0.1$

\begin{figure}[h!]
\includegraphics[scale=0.4]{x(t)4.png}
\includegraphics[scale=0.4]{y(t)4.png}
\includegraphics[scale=0.4]{parametriccurve4.png}
\includegraphics[scale=0.4]{poincare4.png}
\end{figure}

As we can see, changing our initial condition resulted in a wildly different outcome. The object nows seems more attracted to the left side of the will. This seems to be an indication of a chaotic system.

$F = 0.4$, $x(0) = 0$, and $y(0) = 0$

\begin{figure}[h!]
\includegraphics[scale=0.4]{x(t)5.png}
\includegraphics[scale=0.4]{y(t)5.png}
\includegraphics[scale=0.4]{parametriccurve5.png}
\includegraphics[scale=0.4]{poincare5.png}
\end{figure}

We can now clearly see chaotic behavior. We cannot discern a clear pattern in our Poincare section. Let's try tweaking our initial conditions slightly.

$F = 0.4$, $x(0) = 0.001$, and $y(0) = 0$

\begin{figure}[h!]
\includegraphics[scale=0.4]{x(t)6.png}
\includegraphics[scale=0.4]{y(t)6.png}
\includegraphics[scale=0.4]{parametriccurve6.png}
\includegraphics[scale=0.4]{poincare6.png}
\end{figure}

$F = 0.4$, $x(0) = 0.002$, and $y(0) = 0$

\begin{figure}[h!]
\includegraphics[scale=0.4]{x(t)7.png}
\includegraphics[scale=0.4]{y(t)7.png}
\includegraphics[scale=0.4]{parametriccurve7.png}
\includegraphics[scale=0.4]{poincare7.png}
\end{figure}

As we can see, the system is very sensitive to a tweak in initial conditions, a prime characteristic of chaos. Let's repeat the values $F = 0.4$, $x(0) = 0$, and $y(0) = 0$, with a time range $t\in[0,2\pi\, 1000]$ for a better examination of our Poincare section.

$t\in[0,2\pi\, 1000]$
$F = 0.4$, $x(0) = 0$, and $y(0) = 0$

\begin{figure}[h!]
\includegraphics[scale=0.4]{x(t)8.png}
\includegraphics[scale=0.4]{y(t)8.png}
\includegraphics[scale=0.4]{parametriccurve8.png}
\includegraphics[scale=0.4]{poincare8.png}
\end{figure}

Now the Poincare section seems to be a great indication of a chaotic system.

\section{Conclusion}
As we can see, changing our driving force $F$ lead to a more chaotic system.
\end{document}