Saturday, 30 May 2015

Asymptotic notations

Introduction
Let's start with some motivating examples showing how these notations are used.

Using Taylor series expansions, we have

$\begin{align} e^x &=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\frac{x^4}{4!}+\cdots\:\: \text{for all x}\\
&=1+x+O(x^2)\:\:\text{as}\: x \to 0 \end{align}\\
\Rightarrow e^x \sim 1+x$

$\begin{align}\log(1+x)&=x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+\cdots\\
&=x+O(x^2) \end{align}\\
\Rightarrow \log(1+x) \sim x$

The symbol $O(x^2)$ means that the remainder is bounded by $Ax^2$ as $x$ tends to $0$ for some finite $A$.

Big O notation is a symbolism used in complexity theory, computer science, and mathematics to describe the asymptotic behavior of functions. It tells you how fast a function grows or declines. The letter O is used because the rate of growth of a function is also called its order.

If $x_n=3n^2-2n+3$, then $x_n=o(n^3)$, $x_n=O(n^2)$ and $x_n \sim 3n^2\: \text{as}\: n \to \infty$.

o-order is less useful than O-order. For example, $\sin z = z + o(z^2)$ as $z \to 0$ tells us that $\sin z - z \to 0$ faster than $z^2$, however $\sin z = z + O(z^3)$, tells us specifically that $\sin z - z \to 0$ like $z^3$.

Definitions
The symbols $O$, $o$ and $\sim$ were first used by E. Landau and P. Du Bois- Reymond.
Suppose $f(z)$ and $g(z)$ are functions of the continuous complex variable $z$ defined on some domain $D \subset \mathbb{C}$ and possess limits as $z \to z_0$ in $D$.

Asymptotically bounded
$f(z)=O(g(z))$ $\: \text{as}\:$ $z \to z_0$ means that there exists constants $K \geq 0$ and $\delta >0$ such that, for $0<|x-x_0|<\delta$, $|f(z)| \leq K |g(z)|$.

Asymptotically smaller
$f(z)=o(g(z))$ $\: \text{as}\:$ $z \to z_0$ means that for all $\epsilon >0$ such that, for $0<|z-z_0|<\epsilon$, $|f(z)|\leq \epsilon |g(z)|$
Equivalently this means that for non-zero $g(z)$ in a neighbourhood of $z_0$ except possibly at $z_0$, then as $z \to z_0$: $\large \frac{f(z)}{g(z)} \to 0$.

Asymptotically equal
$f(z) \sim g(z)$ $\: \text{as}\:$ $z \to z_0$ means that for non-zero $g(z)$ in a neighbourhood of $z_0$ except possibly at $z_0$, then as $z \to z_0$: $\large \frac{f(z)}{g(z)} \to 1$.

Applications
Approximations & finding limits
This notation saves us the trouble of computing many arithmetic operations. Meanwhile, it avoids the ambiguity of using "the three dots".
$f(x) \sim g(x)$ when $x \to \infty \Rightarrow \large\lim\limits_{x \to \infty} \frac{f(x)}{g(x)}=1$
This is why we can use the following approximations in multiplicative situations.



Computer science -- Analysis of algorithms [later]

Monday, 18 May 2015

Methods to find probability II

Methods to find probability I

Tree diagram, tables

Conditional probability
$P(A|B)=P(AB)/P(B)$

Rule of total probability
$P(A)=P(A|B)+P(A|B^c)$
Sometimes P(A) itself is hard to find, we can use the rule of total probability to find P(A) indirectly.

Reduced sample space
"In the card game bridge, the 52 cards are dealt out equally to 4 players—called East, West, North, and South. If North and South have a total of 8 spades among them, what is the probability that East has 3 of the remaining 5 spades?"

Since we know that North and South have 8 spades among their 26 cards, East and West together have 26 cards, 5 of them being spades. Therefore, the probability that East has 3 of the 5 spades is given by
$\large \binom{5}{3} \binom{21}{10} / \binom{26}{13}$.

Note that this is actually a hypergeometric distribution, which we will introduce in our next post.
Further note that this problem looks very much like a conditional probability problem in the form "Given that ..., find the probability that ..." We will show you the calculations using conditional probability, but the method of reduced sample space would be far more straightforward.

Let B denote the event North and South have a total of 8 spades and 18 non-spades.
$\large P(B)=\binom{13}{8} \binom{39}{18}/ \binom{52}{26}\\$
Let A denote the event East has a total of 3 spades and 10 non-spades.
$\large P(AB)=\binom{13}{8} \binom{39}{18} \binom{5}{3} \binom{21}{10} / [\binom{52}{26}\binom{26}{13}]\\
\large P(A|B)=P(AB)/P(B)=\binom{5}{3} \binom{21}{10}/ \binom{26}{13}$

Bayes' formula
$P(A|B)=P(B|A)P(A)/P(B)$

Inclusion-exclusion principle
Let's say you toss a dice for four times. What is the probability that there is at least one 3 in the four tosses? We can make use of complement to simplify our calculations. The required probability is just $1-\text{P(no 3s)}=1-(5/6)^4=671/1296$. What about calculating the probability directly? We use the inclusion-exclusion principle. $P(\bigcup\limits_{i=1}^n A_i)=\sum\limits_{i=1}^nP(A_i)-\sum\limits_{i<j}P(A_iA_j)+\sum\limits_{i<j<k}P(A_iA_jA_k)-\cdots+(-1)^{n-1}P(\bigcap\limits_{i=1}^n A_i)$

Let $A_i$ denote the event ith dice is a 3.
Thus we need to find $P(\bigcup\limits_{i=1}^4 A_i)$. By the inclusion-exclusion principle, it is $\sum\limits_{i=1}^4 P(A_i)-\sum\limits_{1<i<j<4}P(A_iA_j)+\sum\limits_{i<j<k}P(A_iA_jA_k)-\cdots-P(A_1A_2A_3A_4)$
$=4(1/6)-6(1/6)^2+4(1/6)^3-(1/6)^4=671/1296$.

Permutations and combinations

Thursday, 30 April 2015

Interesting proof of Heron's formula

Area of $\triangle ABC=\sqrt{s(s-a)(s-b)(s-c)}$, $s=\frac{1}{2}(a+b+c)$

$2s=2t+2(c-t)+2(b-t)$
$\begin{cases} s=b+c-t\:\:\:(1)\\2s=b+c+a\:\:\:(2)\end{cases}$
$(2)-(1), s=a+t \Rightarrow t=s-a$
$\text{From (1)}, s-b=c-t\:\text{and}\: s-c=b-t$

$\begin{cases}\tan \frac{A}{2}=\frac{R}{s-a} \\ \tan \frac{B}{2}=\frac{R}{s-b}\end{cases}\\
\Rightarrow \large \tan \frac{A}{2} \tan \frac{B}{2}=\frac{R^2}{(s-a)(s-b)}$

Similarly,
$\large{\tan \frac{A}{2} \tan \frac{C}{2}=\frac{R^2}{(s-a)(s-c)}\\
\tan \frac{B}{2} \tan \frac{C}{2}=\frac{R^2}{(s-b)(s-c)}}$

Adding all the three results,
$\large{\tan \frac{A}{2} \tan \frac{B}{2}+\tan \frac{A}{2} \tan \frac{C}{2}+\tan \frac{B}{2} \tan \frac{C}{2}\\
=R^2[\frac{1}{(s-a)(s-b)}+\frac{1}{(s-a)(s-c)}+\frac{1}{(s-b)(s-c)}]\\
=R^2[\frac{s-c+s-b+s-a}{(s-a)(s-b)(s-c)}]\\
=\frac{R^2s}{(s-a)(s-b)(s-c)}}$

Now, $A+B=\pi-C$.
$\frac{A}{2}+\frac{B}{2}=\frac{\pi}{2}-\frac{C}{2}\\
\large{\tan (\frac{A}{2}+\frac{B}{2})=\frac{1}{\tan \frac{C}{2}}\\
\frac{\tan \frac{A}{2}+\tan \frac{B}{2}}{1-\tan \frac{A}{2} \tan \frac{B}{2}}=\frac{1}{\tan \frac{C}{2}}\\
\tan \frac{A}{2} \tan \frac{C}{2}+\tan \frac{B}{2} \tan \frac{C}{2}=1-\tan \frac{A}{2} \tan \frac{B}{2}\\
\tan \frac{A}{2} \tan \frac{B}{2}+\tan \frac{A}{2} \tan \frac{C}{2}+\tan \frac{B}{2} \tan \frac{C}{2}=1}$
$\large{\therefore 1=\frac{R^2s}{(s-a)(s-b)(s-c)}\\
R=\sqrt{\frac{(s-a)(s-b)(s-c)}{s}}}$

Area of $\triangle ABC=\frac{1}{2}(aR+bR+cR)=sR=\sqrt{s(s-a)(s-b)(s-c)}\:\Box$

Wednesday, 22 April 2015

Interesting probability problems

Birthday problem
"Find the probability that, in a group of n people, there is at least one pair of people who have the same birthday."
In a leap year, there are 366 days. By the pigeonhole principle, the probability that there is at least two people sharing the same birthday will be 1 when there are 367 people. [If we have more than one people having the same birthday among those 367 people, then of course the probability is one. If the 366 people each has a different birthday, the last person (367th person) will have a birthday coinciding one of those 366, hence the result.]
In fact, the probability reaches 0.99 in a group of 70 people, whereas in a group of 23, the probability becomes 0.5. The calculations are as follows:
Let's say there are 365 days in a year.
In a room of n people,
$\text{P(no two people share the same birthday)}$
$\large =365/365\cdot 364/365\cdot 363/365\cdot \ldots \cdot[365-(n-1)]/365\\
\Large =\frac{365\:\cdot\:364\:\cdot\:363\:\cdot\: \ldots \:\cdot\: [365-(n-1)]}{365^n}\\
\Large =\frac{P^{365}_n}{365^n}$

Monty Hall problem
"Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?"
The answer is you should always swap because doing so doubles the probability of winning the car.
If you do not swap, you have 1/3 chance of winning the car and 2/3 chance of winning a goat.
What if you swap? If at first you pick a goat door (2/3 chance) and you swap, you have 1/2 chance of wining the car. And if at first you pick a car door and swap, you get a goat. So overall, the probability of winning the car if you swap is $2/3\cdot 1/2 + 2/3\cdot 1/2 = 2/3$, which is twice the probability of winning the car if you do not swap.

A similar counterintuitive probability problem

Sock Drawer
"A drawer contains red socks and black socks. When two socks are drawn at random, the probability that both are red is $\frac{1}{2}$. (a) How small can the number of socks in the drawer be? (b) How small if the number of black socks is even?"
Let there be r red and b black socks.
P(first sock is red) = $\Large \frac{r}{r+b}$
P(two socks are both red) = $\frac{1}{2}$, which means $\Large \frac{r}{r+b}\cdot \frac{r-1}{r+b-1}=\frac{1}{2}$.
We can plug in different values of r and b to get the answers, but that is not a wise way of approaching this problem.
It turns out we can reach the answers by using inequalities.
Notice that $\Large \frac{r}{r+b}>\frac{r-1}{r+b-1}$ for $b>0$.
So we can create the inequalities
$\Large (\frac{r-1}{r+b-1})^2 < \frac{1}{2} < (\frac{r}{r+b})^2$
$\Large \frac{r-1}{r+b-1} < \frac{1}{\sqrt{2}} < \frac{r}{r+b}$ --(*)
From the first inequality of (*), $(\sqrt{2}+1)b>r-1$.
From the second, $r>\frac{1}{\sqrt{2}}(r+b)$ or $r>\frac{1}{\sqrt{2}-1}b=(\sqrt{2}+1)b$
Finally, $(\sqrt{2}+1)b<r<(\sqrt{2}+1)b+1$
For $b=1$, $r>2.414$ and $r<3.414$, so the candidate is $r=3$. For $r=3$ and $b=1$, $\text{P(2 red socks)}=3/4\cdot 2/3=1/2$, thus the smallest number of socks is 4.
Now for even values of b,
$\begin{array}{c|c|c|c} b & \text{r is between} & \text{eligible r} & \text{P(2 red socks)} \\ \hline 2 & 4.8,\:\:5.8 & 5 & \frac{5\cdot 4}{7\cdot 6} \neq \frac{1}{2}\\ 4 & 9.7,\:\:10.7 & 10 & \frac{10\cdot 9}{14\cdot 13} \neq \frac{1}{2} \\ 6 & 14.5,\:\:15.5 & 15 & \frac{15\cdot 14}{21\cdot 20}=\frac{1}{2} \end{array}$
So 15+6=21 socks is the smallest number when b is even.
Related: Number Theory -- Diophantine Analysis

Geometric distribution
A brilliant proof of its expected value:
When the first outcome is a failure (with probability $1-p=q$), the mean number of trials required is $1+E(X)$, and when the first outcome is a success (with probability $p$), the mean number is $1$. $\therefore E(X)=p(1)+q[1+E(X)] \Rightarrow E(X)=1+qE(X) \Rightarrow E(X)=\frac{1}{1-q}=\frac{1}{p}$

More:
http://www.quora.com/What-are-the-most-interesting-or-popular-probability-puzzles-in-which-the-intuition-is-contrary-to-the-solution

Reference:
Fifty challenging problems in probability by F. Mosteller

Saturday, 18 April 2015

Geometry of lines and planes II

Equation of a line through a line with position vector $\vec{a}$ parallel to $\vec{b}$



Vector form
$\vec{r}=\vec{a}+\lambda\vec{b},\lambda \in \mathbb{R}$

Cartesian form
$\vec{r}=(x,y,z), \vec{a}=(a_1,a_2,a_3), \vec{b}=(b_1,b_2,b_3)$
$(x,y,z)=(a_1+\lambda b_1,a_2+\lambda b_2,a_3+\lambda b_3)$
$\Rightarrow x=a_1+\lambda b_1, y=a_2+\lambda b_2, z=a_3+\lambda b_3$

If $b_1,b_2,b_3 \neq 0$, then eliminating $\lambda$ from these equations yields
$\frac{x-a_1}{b_1}=\frac{y-a_2}{b_2}=\frac{z-a_3}{b_3}(=\lambda)$

Example:
Equation of line through $(-2,0,5)$ parallel to $(1,2,-3)$
$\frac{x+2}{1}=\frac{y}{2}=\frac{z-5}{-3} \Rightarrow 3y=6x+12=10-2z$

Example:
Equation of line through $(1,2,3)$ parallel to $(-2,0,5)$
Note that $b_2=0$ in this case.
$x=1-2\lambda, y=2+0\lambda, z=3+5\lambda$
Eliminating $\lambda \Rightarrow y=2, \frac{1-x}{2}=\frac{z-3}{5}$
Thus, the equations are $y=2, 5x+2z=11$.

Remark: Both equations are needed to describe the line. Each equation on its own describes a plane. The required line is the intersection of these two planes.



Equation of a line through two points



$\vec{AB}=\vec{b}-\vec{a}$

Vector form
$\vec{r}=\vec{a}+\lambda(\vec{b}-\vec{a})=(1-\lambda)\vec{a}+\lambda\vec{b}, \lambda \in \mathbb{R}$

Cartesian form
$x=a_1+\lambda(b_1-a_1), y=a_2+\lambda(b_2-a_2), z=a_3+\lambda(b_3-a_3)$
or $\Large \frac{x-a_1}{b_1-a_1}=\frac{y-a_2}{b_2-a_2}=\frac{z-a_3}{b_3-a_3}$ if the denominators are non-zero.

Example:
Prove that medians of a triangle are concurrent.



Proof:
Let $\vec{a}$ be the position vector from the origin to A, $\vec{b}$ be the position vector from the origin to B, and so on.
Then $\vec{f}=\frac{1}{2}(\vec{a}+\vec{b}),\vec{e}=\frac{1}{2}(\vec{b}+\vec{c}),\vec{e}=\frac{1}{2}(\vec{a}+\vec{c})$
Any point on the line BE is given by $(1-\lambda)\vec{b}+\lambda\frac{1}{2}(\vec{a}+\vec{c})$.
Similarly, any point on AD is $(1-\mu)\vec{a}+\mu\frac{1}{2}(\vec{b}+\vec{c})$.
Since $G$ lies on both of these lines, we have $(1-\lambda)\vec{b}+\lambda\frac{1}{2}(\vec{a}+\vec{c})=(1-\mu)\vec{a}+\mu\frac{1}{2}(\vec{b}+\vec{c})$.
$\Rightarrow 1-\lambda=\frac{\mu}{2}$ and $\frac{\lambda}{2}=1-\mu$
$\Rightarrow \lambda=\mu=\frac{2}{3}$
Therefore $G=\frac{1}{3}(\vec{a}+\vec{b}+\vec{c})$.
Finally, check that G lies on CF.



Equation of plane through the origin and parallel to $\vec{a}$ and $\vec{b}$



$\vec{r}=\lambda\vec{a}+\mu\vec{b}, \lambda, \mu \in \mathbb{R}$



Equation of plane through C parallel to $\vec{a}$ and $\vec{b}$

A general plane can be specified by giving two vectors which lie on the plane and the position vector of a point lying on the plane.



$\vec{r}=\vec{OP}=\vec{OC}+\vec{CP}=\vec{c}+\lambda\vec{a}+\mu\vec{b}, \lambda, \mu \in \mathbb{R}$



Equation of plane through points $\vec{a},\vec{b},\vec{c}$

We can also specify a plane uniquely by giving 3 non-collinear points which lie on it.


$\vec{r}=\vec{a}+\lambda(\vec{b}-\vec{a})+\mu(\vec{c}-\vec{a})=(1-\lambda-\mu)\vec{a}+\lambda\vec{b}+\mu\vec{c}, \lambda, \mu \in \mathbb{R}$



Equation of plane in terms of normal to the plane


Projection of $OP$ onto $ON=\vec{r}\cdot\hat{n}=p$
Let $\hat{n}=(a,b,c), \vec{r}=(x,y,z)$
$ax+by+cz=p$

Key point:
One parameter is needed to write the equation of a line and two parameters are needed for that of a plane.

More