Wednesday, August 28, 2013

Real Root Isolation of Polynomials

Let's first list a few properties about polynomials. Given a polynomial \[    f(x) = \alpha_0 + \alpha_1 x + ... + \alpha_n x^n    \]
the Fundamental Theorem of Algebra tells us that there are $n$ complex roots (counted with multiplicity). A root $r$ has multiplicity $k$ if $f(r) = f'(r) = ... = f^{(k)}(r) = 0 \neq f^{(k+1)}(r)$. A root is simple if it has multiplicity one and a polynomial is square-free if all of its roots are simple. The complex roots must come in conjugate pairs and any rational roots must be of the form (factor of $a_0$) / (factor of $a_n$). Also, the ratio $(-1)^k \alpha_{n-k}/\alpha_n$ gives the sum of the products of all $k$-combinations of roots. Lastly, a result of Cauchy is that the magnitude of any root is bounded by $M = 1 +\max \left| a_i/a_n \right|$.

These properties as well as Descartes' rule of signs (stated below) and synthetic division can all be used to find the roots of a polynomial. Other methods include Newton's, Bisection, Secant, Regula Falsi, etc. Below describes two subdivision methods for isolating all the real roots of a square-free polynomial with real coefficients. They work by determining whether an interval contains zero roots, one root, or multiple roots, and then respectively discarding, storing, or subdividing the interval. The methods can be generalized but not without some effort.

Box Method and code
Descartes' Method


_________________________________________________________________________________


Pólya Enumeration

Pólya Counting enables you to count the equivalence classes of group acting on a set. For example, you might want to find the number of ways to color the corners of a square red or blue, respective of symmetry. The permutation group of symmetries is the dihedral group $D_4$. Pólya Counting gives the generating function $$P_{D_4}(r+b,r^2+b^2,r^3+b^3,r^4+b^4) =  r^4 +r^3b + 2r^2b^2 + rb^3 + b^4$$ where the coefficient in front of $r^pb^q$ tells you the number of nonequivalent colorings given that $p$ corners are colored red and $q$ are colored blue. Thus, the total number is of colorings is 6.

This method can be easily applied to PE 281: Pizza Toppings. It can also be used to count the number of non-isomorphic graphs. [code]

I've Tex'd up some notes for my own reference that are accessible in the link below. The proof is only outlined so it is a bit terse but the example problems should be enough to show how the method is used. Polya Counting Notes


_________________________________________________________________________________


Wednesday, April 3, 2013

Puzzler - Egg Drop



You are given two identical eggs and access to a 100-story building. You want to determine the highest floor from which an egg will not break when dropped. If an egg is dropped and does not break, it is undamaged and can be dropped again. However, once an egg is broken, that’s it for that egg.

If an egg breaks when dropped from floor n, then it would also have broken from any floor above that. If an egg survives a fall, then it will survive any fall shorter than that.

The question is: What strategy should you adopt to minimize the number egg drops it takes to find the solution? (And what is the worst case for the number of drops it will take?)


Solution: Suppose we start by dropping the first egg from floor 50 and it breaks. The only way to determine the correct floor is to then start with floor 1, then 2, 3, ... until our second egg breaks. If the highest floor is 49 then we get 50 total egg drops -- far from optimal. Generalizing, if our first drop is from floor n and the egg breaks, then in the worst case we require n total egg drops. We know that the solution is between 1 and n-1 inclusive. On the other hand, if the egg does not break, we know the solution is between n+1 and 100. Within this range we can use the same technique but instead drop from n-1 floors above floor n. If the egg then breaks, then in the worst case we still total n egg drops. If it doesn't break we continue by taking our third drop to be n-2 floors above the second drop, and so on.. So assuming the first egg does not break, our successive drops are n, 2n-1, 3n-3, 4n-6, ..., n(n+1)/2. -- given by n, n+(n-1), n+(n-1)+(n-2), ..., n+...+1. When the egg finally does break on the kth drop, we drop the second egg incrementally from the floor of the (k-1)th drop up to the floor of the kth drop and in the worst case we get n total drops. Now we simply need to minimize n, which is done by taking the smallest integer n such that n(n+1)/2 > 99. Our solution is thus 14 total drops.

_________________________________________________________________________________


Puzzler - Prisoners and Lightbulbs


There are 100 prisoners in solitary confinement. There's a central living room with one light bulb that is  initially off. No prisoner can see the light bulb from his or her own cell. Everyday, the warden picks a prisoner at random to visit the living room. While there, the prisoner can toggle the bulb if he or she wishes. The prisoner also has the option of asserting that all 100 prisoners have been to the living room by now. If this assertion is false, all 100 prisoners are shot. However, if it is indeed true, all prisoners are set free. So the assertion should only be made if the prisoner is 100% certain of its validity. The prisoners are allowed to get together one night in the courtyard, to discuss a plan. What plan should they agree on, so that eventually, someone will make a correct assertion?

Solution: Here is one sub-optimal solution: Suppose each of the prisoners are assigned a different number from 0-99. Each day is taken modulo 100 and if the prisoner is assigned the same number as the day he turns the light on (or keeps it on) and otherwise he turns the light off (or keeps it off). Whenever a prisoner is called to the room and sees that the light is on, he makes note that the previous days' prisoner has been to the room. Once any of the prisoners has tallied every other prisoner being in the room, he can declare so and they will be set free. For example, say prisoner 50 is called to the room on day 134=34 (mod 100) and sees that the light is on. He concludes that prisoner 33 was in the room the previous day and then proceeds to turn the light off.

There is a simple way to alter this solution to make it way better -- the expected wait goes from ~10,000 to ~1,500 days. Can you think of it?

_________________________________________________________________________________


Saturday, March 16, 2013

Puzzler - Hand Shakes


My wife and I attend a party with four other couples. When we arrive there’s a certain amount of hand-shaking, but no one shakes his own hand and no husband shakes his wife’s hand. I ask the nine other guests how many hands each shook, and I get nine different answers. How many hands did my wife shake?


Solution: There must be exactly one person who shook 0, 1, 2, ..., 8 hands. The person who shook 8 hands shook everyone's except his/her spouses'. So everyone shook atleast one hand except for the spouse, who therefore must have shaken 0 hands. So 8 is paired with 0. Similarly, 7 is paired with 1, 6 with 2, 5 with 3, and 4 is left alone. The only person who didn't have a spouse in the people you asked is your wife, so your wife shook 4 hands.
___________________________________________________________________________________

Friday, March 15, 2013

Discrete Fourier Transform


Suppose we have to multiply two degree polynomials together, $A(x)B(x) = C(x)$ where $A$ and $B$ are given, $C$ is unknown. Let $A,B,C$ be of degree $r,s,r+s$ respectively, and let $n$ be the smallest power of 2 larger than $r+s$.  \[    A(x) = a_0 + a_1x + a_2x^2 + ... + a_{n-1}x^{n-1}     \] \[    B(x) = b_0 + b_1x + b_2x^2 + ... + b_{n-1}x^{n-1}     \] \[    C(x) = c_0 + c_1x + c_2x^2 + ... + c_{2n-2}x^{2n-2}     \]
Note that the coefficients indexed larger than the respective degrees are simply zero. Then we can find our coefficients of $C$ in $\mathcal{O}(n^2)$ by multiplying the coefficients of $A$ and $B$ together in the convoluted sum \[    c_k = \sum_{j=0}^{k}a_j b_{k-j}    \]
But $n=2^{20}$ and $\mathcal{O}(n^2)$ is too costly, so we need a better method. Through the use of the FFT we can find coefficients $c_k$ in $\mathcal{O}(n\log n)$ time by
    1.     (FFT) Evaluate $A$ and $B$ at $n$th roots of unity $\omega^k, \;\;\;\; k=0,...,n-1$
    2.      Find $C(\omega^k) = A(\omega^k) B(\omega^k)$  
    3.      (iFFT) Find $C$ via polynomial interpolation  


Step (1) Suppose we write $A(x) = A_0(x^2) + xA_1(x^2)$ where \[   A_0(x) = a_0 + a_2x + a_4x^2 + ... + a_{n-2}x^{n/2-1} \] \[    A_1(x) = a_1 + a_3x + a_5x^2 + ... + a_{n-1}x^{n/2-1}  \]
To evaluate $A$ at the $n$th roots of unity, we need to evaluate $A_0$ and $A_1$ at the square of each of the roots. But this is the same as evaluating the $(n/2)$th roots of unity at two polynomials of degree $n/2-1$. We immediately get a recursive algorithm (Fast Fourier Transform) with complexity $T(n) = 2T(n/2) + 2n = \mathcal{O}(n\log n).$ We can easily generalize this to work for $n$ as a power of any prime by splitting $A$ into more parts (or any number provided you have its prime factorization).

Step (2) We evaluate $C(\omega^k )$ in $O(n)$ operations.

Step (3) We have formed a linear system $Mc^* = c$, where $M$ is the matrix $(\omega^{kj})$, $c^*$ is the vector of values $ c_k $, and $c$ is the vector of values $C(\omega^{km})$. $M$ is a Vandermonde matrix, so it has an inverse. Thus, we can find $c^{*}$ by applying $M^{-1}$ to both sides, $c^* = M^{-1} c$. It turns out $M^{-1} = (1/n (\omega^{-ij}))$ and applying this matrix to $c$ is the same as step 1, namely the inverse Fourier transform.



Python Code



    from cmath import exp, pi 

    def FFT(X):
       
        n = len(X)
        w = exp(-2*pi*1j/n)

        if n > 1
            X = FFT(X[::2]) + FFT(X[1::2])

            for k in xrange(n/2):
                xk = X[k]
                X[k] = xk + w**k*X[k+n/2]
                X[k+n/2] = xk - w**k*X[k+n/2]

        return X


___________________________________________________________________________________

Thursday, March 7, 2013

Gravity Toy


Recently found this fun program on the web that lets you create our solar system in 2D. Pretty fun to play with.




___________________________________________________________________________________

Wednesday, March 6, 2013

Lexicographic Index of Subsets


Suppose we have a set of $n$ items labelled $\{1,2,...,n\}$. We want to enumerate the subsets of $s$ items somehow. A natural way to do this is to use a lexicographic ordering of the sorted sets. So for example if $n=10$ and $s=4$, we would get the following assignments:

$\{1, 2, 3, 4 \} : 1$
$\{1, 2, 3, 5 \} : 2$
$\{1, 2, 3, 6 \} : 3$
...
$\{7, 8, 9, 10 \} : {10 \choose 4 }$

Solution 1 - Counting Above

The best way to show this is by example. The lexicographic index is the total number of subsets minus the number of subsets lexically larger. Suppose $n = 10$ and $s=4$ and our subset $u = \{2,4,5,9\}$. The subsets that are lexically larger than $u$ look like the following:

$ \#\{ > 2, ... \} = {8 \choose 4} $
$ \#\{ 2, >4, ... \} = {6 \choose 3} $
$ \#\{ 2, 4, >5, ... \} = {5 \choose 2} $
$ \#\{ 2, 4, 5, >9 \} = {1 \choose 1} $

It is easy to see the pattern and generalize. Our formula is then
\[ enum(u) = {n \choose s} - \sum_{j=1}^{s}{n-u_j \choose s-j+1} \]

Solution 2 - Counting Below

The lexicographic index is one plus the number of subsets lexically smaller. Suppose $n = 10$ and $s=4$ and our subset $u = \{2,4,5,9\}$. The subsets that are lexically smaller look like the following:

$ \# \{< 2, ... \} = \# \{ ... \} - \# \{ \geq 2, ... \} = { 10 \choose 4} - {9 \choose 4} $
$ \# \{2, < 4, ... \} = \# \{ 2, ... \} - \# \{ 2, \geq 4, ... \} = { 8 \choose 3} - {7 \choose 3} $
$\# \{2, 4, <5, ...\} = \# \{ 2, 4, ... \} - \# \{ 2, 4, \geq5, ... \} = { 6 \choose 2} - {6 \choose 2}$
$\# \{2, 4, 5, <9\} = \# \{ 2, 4, 5, ... \} - \# \{ 2,4,5, \geq 9 \} = { 5 \choose 1} - {2 \choose 1} $

It is easy to see the pattern and generalize. Defining $u_0 = 0$, our formula is then 
\[ enum(u) = 1 + \sum_{j=1}^{s} \left[ {n-u_{j-1} \choose s-j+1} - {n-u_j+1 \choose s-j+1} \right] \]
If you telescope this sum, you end up with formula given by Solution 1.
Exercise: How can we calculate the inverse? Given a number, what subset does it correspond to?



___________________________________________________________________________________

Friday, February 22, 2013

Brouwer Fixed-Point Theorem


Imagine you have two sheets of graph paper of the same size, one atop the other. Your friend takes one piece, crumples it into a ball, and tossies it onto the other sheet so that no piece of the ball extends beyond the edge of the bottom paper. Brouwer's Fixed-Point theorem tells us that there is atleast one point in the ball that lies directly above its corresponding point on the flat piece, in other words, there is atleast one point that is directly above its original position.

The theorem works in other dimensions too. Imagine a bowl of punch. The theorem insists that when your friend stirs the punch, atleast one liquid particle is in the same position as it was before stirring.

In more precise language, a continuous function from an $n$-ball to an $n$-ball (where $n$>0 is the dimension) must have a fixed point.

Short of a proof, it is easier to understand why it works if you think of a one dimensional line. To be concrete, suppose we map the real number line $[0,1]$ continuously to $[\frac{1}{3},\frac{5}{6}]$ via $f(x) = \frac{1}{2}x + \frac{1}{3}$. We get the following map:

0 _________________________ 1 $\rightarrow$
           $\frac{1}{3}$________________ $\frac{5}{6}$

We notice that $\frac{1}{3} = f(0) > 0$ and that $f(x)$ continues to be greater than $x$ for a while. Since $\frac{5}{6} = f(1) < 1$, it must flip, and thereafter $f(x) < x$. In this case, Brouwer's Fixed-Point theorem, that there must exist a point with $f(x)=x$, follows directly from the Intermediate Value theorem. In fact, it is easy to check that there is a fixed point at $x=\frac{2}{3}$.



___________________________________________________________________________________

Tuesday, February 19, 2013

Puzzler - Snow



It starts snowing in the morning and continues steadily throughout the day. A snowplow that removes snow at a constant rate starts plowing at noon. It plows 2 miles in the first hour, and 1 mile in the second. What time did it start snowing?

Solution: 11:23 am 
Solution Explanation


___________________________________________________________________________________

Friday, February 15, 2013

Happy Valentines Day


Here is a Java game I made. You need to have the latest Java installed. Works best in Safari on a Mac.
  • 'c' : change colors
  • "=" : speed up time
  • '-' : slow down time
  • '1': change movement type
  • [arrow keys]: move

Java Applet

Wednesday, February 13, 2013

Irrational^Irrational


In an earlier post I proved that $\sqrt{2}$ is an irrational number. What about $\sqrt{2}^{\sqrt{2}}$? We can actually use this number to prove that it's possible to have an irrational$^{\text{irrational}}$ = rational, without actually constructing an example.
    • Either $\sqrt{2}^{\sqrt{2}}$ is rational $\checkmark$
    • Or it is irrational and $\left(\sqrt{2}^{\sqrt{2}}\right)^{\sqrt{2}} = 2$ is rational $\checkmark$
The Gelfond Schneider Theorem tells us that $\sqrt{2}^{\sqrt{2}}$ is transcendental, and since it is real, it is irrational.
    • If $\alpha$ and $\beta$ are algebraic numbers with $\alpha \neq 0,1$ and if $\beta$ is not a rational number, then any value of $\alpha^{\beta} = e^{\beta \text{log} \alpha}$ is a transcendental number.
In fact, it's not too difficult to find examples for all of the 8 possible rational/irrational triples $\alpha^{\beta} = \gamma$. Let's explore a bit further and look at infinite tetrations. For your amusement I wrote some hackish code that prompts you for a number $n>1$, then outputs the infinite tetration that converges to it. It is a surprising result that $$ \sqrt{2}^{{\sqrt{2}}^{{\sqrt{2}}^{{\sqrt{2}}^{...}}}} = 2 $$


 from math import *
 LIMIT,em = 2,2**-52
 
 def tetration(b, LIMIT):
  a = 1
  for i in xrange(1000):
   try:
    a = b**a
    if a > LIMIT: return False
   except OverflowError:
    return False
  return a
 
 while LIMIT >= 1:
  LIMIT = input('\nTetration Limit: ')
  em = 2**-52
  lo, hi = 1.0,2.0
  
  while hi-lo > em:
   mid = (hi+lo)/2
   tetmid = tetration(mid, LIMIT)
   if tetmid: lo = mid
   else: hi = mid
   
  print lo, tetration(lo, LIMIT)



___________________________________________________________________________________

Sunday, February 10, 2013

Sylvester's Line


In 1893 Sylvester asked the mathematical community to prove that given a finite number of points in the plane, either, 1) A line exists that passes thru exactly two of the points or 2) All the points are collinear, that is they lie on the same straight line. His conjecture stumped mathematicians for nearly 50 years until it was correctly solved by Gallai in 1944. A simple and elegant book proof was given by Kelly four years later:

Proof Sketch:
Let $S$ be the given set of points (not all collinear). Consider the collection $C$ of pairs $(L,p)$, where $L$ is a line through at least two distinct points in $S$ and where $p \in S$ is a point not on $L$. Then $C$ is a nonempty finite set of pairs. Among those, pick $(L,p)$ such that the distance from $p$ to $L$ is minimal. We claim that $L$ harbors exactly two points from $S$.

Assume NOT, then $L$ contains 3 or more points. Let $q$ be the projection of $p$ onto $L$. In the figure below, on the horizontal line $L$ we label $q$ and the three points $a,b,c$ in $S$. Two of $a,b,c$ must be on either side of $q$, WLOG as in the figure. Consider $b$ and draw the line $L'$ through $p$ and $c$. In the figure, $L'$ is the slanted line. Then $(L',b)$ belongs to $C$ and the distance from $b$ to $L'$ is strictly less than the distance from $p$ to $L$, a CONTRADICTION.





___________________________________________________________________________________

Saturday, February 9, 2013

Gram Schmidt


Suppose we have a set of linearly independent vectors $V = \{v_1, v_2, ..., v_n\}$ and we want to find a new set of orthonormal vectors $Q = \{q_1, q_2, ..., q_n\}$ that span the same space. We can use the Gram Schmidt (GS) process, commonly implemented in three ways:

  • Initially let $Q = \{\emptyset\}$
  • Pivot: Find the vector $v_i$ not in $Q$ with the largest $\ell^2-$norm
    • Classical: Orthogonalize the next vector $v_i$ against all vectors previously added to $Q$. Then normalize $v$ and add it to $Q$.
    • Modified: Normalize $v$ and add it to $Q$. Then orthogonalize all vectors not in $Q$ against $v$ .
    • Complete: When adding $v$, do Classical twice, or Modified twice, or both once.

By orthogonalize v against u, I mean to subtract the $u$-component from $v$ ($v - $proj$_uv$). Each method is more numerically stable than the last, and the stability of complete Gram Schmidt is on par with the Householder reflections or Givens rotations. A good example is if you let your vectors be the columns of matrix $A_{i,j} = 1/(j+k^2) \;\; ; \;\; j = 1,2,...,100 \;\; , \;\; k = 1,2,...,50$. The maximum dot product of any two vectors in $Q$ for classical = $0.62$, modified $= 0.02$, and complete $= 3.47$e-16, found using the Matlab code below.

GS can be used to find the $QR$ decomposition of a matrix, $Q$ unitary and $R$ upper-triangular, which lets you solve the linear system $Ax=b$ more efficiently than directly computing $A^{-1}$.


    function [Q] = GramSchmidt(Q, type)
       
        EM = 2^-53;
        n = size(Q,2);

        for i = 1:n

            % PIVOT
            qdotq = sum(Q(:,i:n).^2,1);
            j = i-1 + find(qdotq == max(qdotq),1);
            Q(:,[i,j]) = Q(:,[j,i]);
            if norm(Q(:,i)) < EM, break, end

            % CLASSIC AND COMPLETE
            if ~strcmp(type,'modified')
                for j = 1:i-1
                    Q(:,i) = Q(:,i) - dot(Q(:,i),Q(:,j))*Q(:,j);
                end
                Q(:,i) = Q(:,i) / norm(Q(:,i));
            end

            % MODIFIED AND COMPLETE
            if ~strcmp(type,'classical')
                Q(:,i) = Q(:,i) / norm(Q(:,i));
                for j = i+1:n
                    Q(:,j) = Q(:,j) - dot(Q(:,j),Q(:,i))*Q(:,i);
                end
            end
        end
    end



___________________________________________________________________________________


Friday, February 8, 2013

Puzzler - Purgatory


Solution to Puzzler 1




Solution: While pointing at one door, ask, "is it true that you are a either a truthful bird and that door leads to heaven or a lying bird and that door leads to hell?" If the bird says yes or no, the door leads to heaven or hell, respectively.



___________________________________________________________________________________

Tuesday, February 5, 2013

Pascals Triangle

Pascals Triangle was originally discovered by the Chinese in the $11^{th}$ century, but was later studied in depth by the French mathematician Blaise Pascal in the 17th century. Pascals triangle has many interesting properties.


  • The $k^{th}$ number in the $n^{th}$ row is the binomial coefficient ${n \choose k} = \frac{n!}{k!(n-k)!}$
    • The number of ways to choose $k$ socks out of a drawer filled with $n$ different socks
    • The coefficient in front of $a^kb^{n-k}$ when $(a+b)^n$ is expanded
  • Each number is the sum of the two above it. ${n \choose k} = {n-1 \choose k-1} + {n-1 \choose k}$
  • The triangle is symmetric. ${n \choose k} = {n\choose n-k}$
  • The sum of the $n^{th}$ row is $2^n$. $\sum_{k}{n \choose k} = 2^n$
  • The sum of the squares of the values in the $n^{th}$ row is the middle of the $2n^{th}$ row. $\sum_{k}{n \choose k}^2 = {2n \choose n}$
  • The semi-diagonals sum to the Fibonacci Numbers
  • The third diagonal from the left gives the Triangular Numbers
  • On the third diagonal from the left, each subsequent pair of numbers sums to the next perfect square
  • If you squeeze together the $n^{th}$ row into one number you get $11^n$
  • The Hockey Stick identity
    • ${n+1 \choose k+1} = {k \choose k} + {k+1 \choose k} + ... + {n \choose k}$
    • ${n+k+1 \choose k} = {n \choose 0} + {n+1 \choose 1} + ... + {n+k \choose k}$


Modular Pascals Triangle

One of the cooler properties of Pascals triangle is how when you display the remainder of each value when divided by $n$ (mod $n$), it forms a Sierpinski Triangle in the limit. The following are for $n = 2,3,5,7$.





When $n$ is a prime number it is easy to see the recurrence for $R_p(n)$, the number of elements in the $n^{th}$ row not equivalent to 0 (mod p) and the recurrence for $T_p(n)$, the number of elements in the triangle up thru the $n^{th}$ row not equivalent to 0 (mod p). If $n$ written out in base $p$ is $\eta_k\eta_{k-1}...\eta_0$, then

$$R_p(\eta_k...\eta_0) = \prod_{k}(\eta_k + 1)$$
$$T_p(\eta_k...\eta_0) =  \frac{\eta_k(\eta_k+1)}{2} T_p(1_k00...0) +  (\eta_k+1)\,T_p(\eta_{k-1}...\eta_0)$$
$T_p(p^k) = T_p(1_k00...0) = \left(\frac{p(p+1)}{2}\right)^{k}$

Can we generalize this result to powers of primes, or numbers that are the product of two primes? You can play around with modular pascals triangle with this java applet, though you might need to use a browser other than Chrome. Here are some revealing pictures.



4: [0 = black, 1, 2, 3]               8: [0 = black, 1, 2, 3, 4, 5, 6, 7]



6: [0 = black, 1, 2, 3, 4, 5]               6 : [0 = black, 1, 2, 3, 4, 5]



10: [0 = black, 1, 2, 3, 4, 5, 6, 7, 8, 9]      10: [0 = black, 1,2,3,4,5,6,7,8,9]



___________________________________________________________________________________

Sunday, February 3, 2013

Powerball



The Powerball jackpot just broke 200 million. Is the ticket worth what we pay for it? Let's calculate the expected return of a ticket. Let $\mathcal{P}(n,m,q)$ be the probability of matching $q$ out of $m$ balls where each ball is selected from $[n]=\{1,2,\ldots,n\}$ (without replacement). This value is easily calculated:

$$\mathcal{P}(n,m,q) = \frac{\text{# winning tickets}}{\text{# total tickets}} = \frac{{m \choose q} {n-m \choose m-q}}{ {n \choose m} } $$

For the Powerball lottery we have $n = 59$ and $m=5$ and we have an extra powerball which is a number independently chosen from $[35]$. Let $P(\bullet^{\alpha} \circ^{q})$ be the probability of matching $\alpha \in \{0,1\}$ powerballs and $q \in \{0,1,2,3,4,5\}$ regular balls.

$$ P(\bullet^{\alpha} \circ^{q}) = {35}^{-\alpha} \, \mathcal{P}(59,5,q) $$

To calculate the expected return we need to sum over the 9 ways to win $\omega$, the probability $P(\omega)$ times the winnings $W(\omega)$. Let the jackpot be $X$ million.

$$ \sum_{\omega}P(\omega)W(\omega) \;\;\; = \;\;\; 4P(\bullet) + 4P(\bullet \circ) + 7P(\bullet \circ^2) + 7P(\circ^3) + ... \;\;\; = \;\;\; 0.37 + X/175 $$

The jackpot is currently 208 million, so the expected return is 1.56 dollars, 44 cents less than the 2 dollars you pay for the ticket -- and that's before taxes! In fact, your estimated jackpot winnings need to be 285 million before a ticket is worth buying.



_________________________________________________________________________________

Saturday, February 2, 2013

Irrationality of $\sqrt{2}$




A cool geometric proof first presented by Tom Apostol. If $\sqrt{2}$ is rational we can draw an isosceles right triangle with integer sides. Consider the smallest such triangle ABC -- that is with shortest hypotenuse. Let the apex be A and hypotenuse AC. Draw a circle centered at A with radius the length of AB and mark point D where it intersects the hypotenuse. Now draw the tangent to the circle at D and mark the point E where it cuts the base of the triangle. Then DEC is a smaller isosceles right triangle with integer sides. This is a contradiction.

Algebraically this leads to the proof that nonperfect squares have irrational roots. Suppose $p/q = \sqrt{n}$. Then $$ \frac{p'}{q'} = \frac{nq - \lfloor \sqrt{n} \rfloor p}{p - \lfloor \sqrt{n} \rfloor q} = \frac{p}{q}$$and $0 < p' < p$ and $0 < q' < q$ (You can follow the lines in the diagram). Exercise: what is the total area of the wedges? $(\sqrt{2}+1)\pi/16 = .47403$

Borwein and Bailey. Mathematics by Experiment. p73



___________________________________________________________________________________


Friday, February 1, 2013

Puzzler - Ants on a Stick


Ants on a Stick: 
One hundred ants are dropped on a meter stick. Each ant is traveling either to the left or the right with constant speed 1 meter per minute. When two ants meet, they bounce off each other and reverse direction. When an ant reaches an end of the stick, it falls off.

At some point all the ants will have fallen off. The time at which this happens will depend on the initial configuration of the ants. Over all the initial configurations, what is the longest time you have to wait for all the ants to fall off?


Hint (highlight to see): The answer is the same if there are only 10 ants.

Solution:
When two ants bump off each other it is equivalent to them crossing over. Therefore, the longest amount of time you have to wait for all the ants to fall off is the time it takes for one ant to travel the distance of the stick, 1 minute. If an ant is placed at each end, facing away from the edge, regardless of where the 98 other ants are placed, it will take exactly 1 minute for all the ants to fall off. 


___________________________________________________________________________________

Thursday, January 31, 2013

Mathematical Heart


Valentines Day is coming up, and you less artistic folk might want to make a nice heart picture to send to your girlfriend. A parametrization of a heart shape is the following: $$x = 16\text{sin}^3(t)$$ $$y = 13\text{cos}(t) - 5\text{cos}(2t) - 2\text{cos}(3t) - \text{cos}(4t)$$The heart is drawn as $t$ ranges from $0$ to $2\pi$. How you increment $t$ can alter the picture in cool ways. Interestingly, the area enclosed is exactly $180\pi$


Blue, scale = $\frac{3}{2}$,   $ t = 1, 2, 3, ...$
Red, scale = 1,    $ t = \frac{1}{2}, \frac{2}{2}, \frac{3}{2}, ...$
Black, scale = $\frac{3}{5}$,   $ t = \frac{1}{100}, \frac{2}{100}, \frac{3}{100}, ...$
Green, scale = $\frac{1}{5}$,    $t = k(\pi - .01), \; k = 0,1,2, ...$



___________________________________________________________________________________