Friday, March 6, 2015

Pascal's Pyramids

As mentioned in a previous blog, Pascal’s Triangle is a famous triangular array of numbers that has applications for the expansion of binomials, powers of two, sequences of numbers, statistics, and properties of simplexes.  Each line of the triangle starts and ends with the number 1, and the numbers in between can be obtained by finding the sum of the two numbers above it.  The triangle can then be continued indefinitely.


A similar method can be extended in three dimensions to make an array of numbers in the shape of a pyramid with either a triangular base or a square base.  Both of these pyramids also have amazing properties.

Triangular-Based Pascal’s Pyramid

The triangular-based Pascal’s Pyramid can be formed by layers of expanding equilateral triangles.  This means the first layer has one number (a triangle with one number per side), the second layer has three numbers (a triangle with two numbers per side), the third layer has six numbers (a triangle with three numbers per side), and so on. 

Expanding a Pyramid by Adding Equilateral Triangle Layers

The numbers in this pyramid can be obtained by finding the sum of the three numbers in the layer above it.  For example, the center number 6 in the fourth layer was obtained by adding the three 2’s in the third layer.  The pyramid can also be continued indefinitely.

Steps for Finding a New Triangular Layer

Layers in a Triangular-Based Pascal’s Pyramid

The triangular-based Pascal’s Pyramid has several interesting properties.  The numbers along the edges are the same numbers as Pascal’s Triangle, and therefore all of the interesting properties of Pascal’s Triangle also apply to Pascal’s Pyramid.  In addition to this, the coefficients for the expanded form of the trinomial (x + y + z)n match up with the numbers in the triangular layers of Pascal’s Pyramid.  For example, (x + y + z)2 = x2 + y2 + z2 + 2xy + 2xz + 2yz (1, 1, 1, 2, 2, 2), and (x + y + z)3 = x3 + y3 + z3 + 3x2y + 3x2z + 3xy2 + 3xz2 + 3y2z + 3yz2 + 6xyz (1, 1, 1, 3, 3, 3, 3, 3, 3, 6).  (Recall that the coefficients for the expanded form of the binomial (x + y)n match up with the numbers in Pascal’s Triangle.)  Finally, the numbers of each triangular layer of Pascal’s Pyramid add up to a power of 3.  For example, the numbers in the third layer (1, 2, 1, 2, 2, 1) add up to 9 which is 32, and the numbers in the fourth layer (1, 3, 3, 1, 3, 6, 3, 3, 3, 1) add up to 27 which is 33. (Recall that the numbers of each row of Pascal’s Triangle adds up to a power of 2.)

Square-Based Pascal’s Pyramid

The square-based Pascal’s Pyramid can be formed by layers of expanding squares instead of triangles.  This means the first layer has one number (a square with one number per side), the second layer has four numbers (a square with two numbers per side), the third layer has nine numbers (a square with three numbers per side), and so on. 

Expanding a Pyramid by Adding Square Layers

The numbers in this pyramid can be obtained by finding the sum of the four numbers in the layer above it.  For example, one of the 9’s in the fourth layer was obtained by adding the 1, 2, 2, and 4 in the third layer.  This pyramid can also be continued indefinitely.

Steps for Finding a New Square Layer

Layers in a Square-Based Pascal’s Pyramid

The square-based Pascal’s Pyramid also has several interesting properties.  Like the triangular-based Pascal’s Triangle, the numbers along the edges of the square-based Pascal’s Pyramid are the same numbers as Pascal’s Triangle, and therefore all of the interesting properties of Pascal’s Triangle also apply.  In addition, just as the numbers of each row of Pascal’s Triangle adds up to a power of 2, and just as the numbers of each triangular layer of the triangular-based Pascal’s Pyramid add up to a power of 3, the numbers of each square layer of Pascal’s Pyramid add up to a power of 4.  For example, the numbers in the third layer (1, 2, 1, 2, 4, 2, 1, 2, 1) add up to 16 which is 42, and the numbers in the fourth layer (1, 3, 3, 1, 3, 9, 9, 3, 3, 9, 9, 3, 1, 3, 3, 1) add up to 64 which is 43. Finally, each square layer of Pascal’s Pyramid represents a multiplication table, in which any number in the square is the product of the row header and column header.  For example, any of the 9’s in the fourth layer is can be found by multiplying the row header of 3 by the column header of 3.  Because the numbers in each square layer are symmetrical, all numbers in the diagonals are square numbers.

Variations of Pascal’s Pyramid

There are a few other variations of Pascal’s Pyramid.  In the triangular-based pyramid, the next layer can be obtained by adding a triangle of numbers that is upside-down from the usual triangle of numbers.  The result is a new hexagonal layer that still holds the property that the numbers along the edges are the same as the numbers in Pascal’s Triangle, and also the property that the sum of the numbers in each layer is a power of 3.

Usual Way of Obtaining a New Layer

Alternate Way of Obtaining a New Layer

A hexagonal-based pyramid can also be made by numbers in a honeycomb pattern.  Each new number can be obtained by finding the sum of the three numbers in the layer above it.  Once again, this pyramid still holds the property that the numbers along the edges are the same as the numbers in Pascal’s Triangle, but also has the additional property that the sum of the numbers in each layer is a power of 6.

Steps for Finding a New Hexagonal Layer

Layers in a Hexagonal-Based Pascal’s Pyramid

Conclusion

Extending Pascal’s Triangle into three dimensions reveals even more unique properties.  The edges of each pyramid have the same numbers as Pascal’s Triangle, and the sum of the numbers in each layer can be represented as a power between two integers.  Each layer in a triangular-based Pascal’s Pyramid has application in expanding trinomials, and each layer in a square-based Pascal’s Pyramid is a multiplication table.  All of these properties are truly amazing!

Thursday, February 26, 2015

The Howie Mandel Problem

Now imagine you are on Deal or No Deal, a television show in which there are 26 cases filled with different amounts of cash ranging from a penny to a million dollars.  You start out by picking one case.  Then for each round, the host, Howie Mandel, asks you to eliminate one of the leftover cases, which is opened to reveal the amount inside, after which a mysterious banker offers to buy your case for an amount that varies based on the amounts that are leftover.  You then decide on either taking the money (deal) or playing another round in hopes of getting a better offer from the banker (no deal).


On the rare occasion that you actually get it down to just two cases left in which one of those two cases has the million dollars, Howie will offer you the chance to switch cases.  What should you do?

This problem is similar to the “Monty Hall Problem”, where you are a contestant on Let’s Make a Deal and Monty Hall shows you three doors.  Behind one door is a brand new car, but behind the other two doors are two goats.  You pick a door, but just before it is opened, Monty says he will open a different door other than the door that you picked that has a goat behind it, and then offers you the chance to switch doors.  As proved in a previous blog, you should switch doors because switching gives you a 2 in 3 chance of winning (since your original choice was a 1 in 3 chance, it leaves you with a 2 in 3 chance for the remaining doors, in which one choice is eliminated).


So is the “Howie Mandel Problem” similar enough to the “Monty Hall Problem” that you should switch cases?  Or are the problems different enough so that it doesn’t matter if you switch cases or not, because either case has a 1 in 2 chance of winning?  Once again, I wrote a small computer program in Python that simulated the scenario one million times and kept track of how many times you would win by switching cases out of how many times you would actually be in a situation where you only have two cases left.  The computer program is as follows:

01
#The Howie Mandel Solution
02
#Python 2.7.3
03

04
#Be able to pick a random number later.
05
import random
06

07
#Total number of trials to calculate.  The higher the number, the
08
#  more accurate the probability solution.
09
trials = 1000000
10

11
#Total number of cases
12
cases = 26
13

14
#Keep track of the number of trials which get down to having two
15
#  cases at the end, originally starting at zero.
16
trials_down_to_two_cases = 0
17

18
#Keep track of the number of wins if you switch cases at the end,
19
#  originally starting at zero.
20
trials_won_by_switching = 0
21

22
#Go through each trial one by one.
23
for trial in range(1, trials + 1):
24

25
    #Randomly pick a number between 1 and the number of cases
26
    #  for the case with the million dollars.
27
    case_with_big_money = random.choice(range(1, cases))
28

29
    #Randomly pick a number between 1 and the number of cases
30
    #  for the case you choose first.
31
    case_you_choose_first = random.choice(range(1, cases))
32

33
    #Randomly pick a number between 1 and the number of cases
34
    #  (excluding the case you already chose) for the case
35
    #  you leave for last.
36
    case_you_leave_for_last = random.choice(range(
37
        1, case_you_choose_first - 1) + range(
38
        case_you_choose_first + 1, cases))
39

40
    #If the case with the million dollars is in either the case
41
    #  you choose first or the case you save for last,
42
    #  then the game will get down to only two cases left, so add
43
    #  one to the number of trials down to two cases.
44
    if (case_with_big_money == 1 or case_with_big_money == 2):
45
        trials_down_to_two_cases += 1
46

47
    #If case with the million dollars is in the case you save for
48
    #  last, then add one to the number of trials won by switching cases.
49
    if (case_you_leave_for_last == case_with_big_money):
50
        trials_won_by_switching += 1
51

52
#When all trials have been run, print the number of trials won
53
#  by switching and give the percent.
54
print "Total number of times it will get down to two cases: " + str(
55
    trials_down_to_two_cases) + " out of " + str(trials) + " (" + str(
56
    int(round(trials_down_to_two_cases * 100.0 / trials))) + "%)"
57
print "Total number of wins by switching: " + str(
58
    trials_won_by_switching) + " out of " + str(
59
    trials_down_to_two_cases) + " (" + str(int(round(
60
    trials_won_by_switching * 100.0 / trials_down_to_two_cases))) + "%)"

The outcome after running the computer program is as follows:

>> 
Total number of times it will get down to two cases: 80083 out of 1000000 (8%)
>> 
Total number of wins by switching: 39989 out of 80083 (50%)

Therefore, it makes no difference whether you switch cases or not, because either case has a 1 in 2 chance of winning.  The difference between the “Howie Mandel Problem” and the “Monty Hall Problem” is that in the “Howie Mandel Problem”, the options are being randomly eliminated by the contestant, but in the “Monty Hall Problem”, the options are knowingly eliminated by the host.  That tiny detail makes all the difference! 

Wednesday, February 25, 2015

The Monty Hall Problem

Imagine you are on a television game show and the host shows you three doors.  Behind one door is a brand new car, but behind the other two doors are two goats.  You pick Door #1, but just before it is opened, the host says he will open a different door other than the door that you picked that has a goat behind it, and opens Door #3 which reveals one of the two goats.  The host then offers you the chance to stay with Door #1 or to switch to Door #2.  What should you do?


This problem is called the “Monty Hall Problem” in honor of Monty Hall, the host of Let’s Make a Deal, a television game show which had similar games such as this one.  The “Monty Hall Problem” gained popularity in 1990 when vos Savant, a columnist for Parade Magazine, wrote about the problem and asserted that you should switch doors for a 2 in 3 chance of winning, since your original choice for Door #1 was a 1 in 3 chance, leaving you a 2 in 3 chance for the remaining doors, in which one choice (Door #3) was eliminated.  Her solution and explanation was heavily criticized by many of her readers, including PhD professors, who asserted that it makes no difference whether you switch doors or not, because either way there is a 1 in 2 chance of winning since there is one winning door out of the two leftover door options.

Both solutions seem to make sense, but obviously only one can be correct.  So I wrote a small computer program in Python that simulated the scenario one million times and kept track of how many times you would win by switching doors.  The computer program is as follows:

01
#The Monty Hall Solution
02
#Python 2.7.3
03

04
#Be able to pick a random number for the door with the car.
05
from random import randint
06

07
#Total number of trials to calculate.  The higher the number, the more
08
# accurate the probability solution.
09
trials = 1000000
10

11
#Keep track of the number of wins when you switch doors, originally
12
# starting at zero.
13
trials_won_by_switching = 0
14

15
#Go through each trial one by one.
16
for trial in range(1, trials + 1):
17

18
    #Randomly pick a number between 1 and 3 for the door with the car.
19
    door_with_car = randint(1,3)
20

21
    #If the car is behind Door #1, then the goats are behind Door #2 and #3
22
    if (door_with_car == 1):
23
        door_with_goat_1 = 2
24
        door_with_goat_2 = 3
25

26
    #If the car is behind Door #2, then the goats are behind Door #1 and #3
27
    elif (door_with_car == 2):
28
        door_with_goat_1 = 1
29
        door_with_goat_2 = 3
30

31
    #If the car is behind Door #3, then the goats are behind Door #1 and #2
32
    elif (door_with_car == 3):
33
        door_with_goat_1 = 1
34
        door_with_goat_2 = 2
35

36
    #You choose Door #1
37
    door_you_choose_first = 1
38

39
    #Monty Hall picks a different door other than Door #1 that has a goat
40
    #If Door #3 has no car behind it, Monty Hall opens Door #3 to reveal
41
    #  the goat, which makes Door #2 the door to switch to.
42
    if (door_with_car != 3):
43
        door_revealed_with_goat = 3
44
        door_to_switch_to = 2
45

46
    #If Door #3 has the car behind it, Monty Hall opens Door #2 to reveal
47
    #  the goat, which makes Door #3 the door to switch to.
48
    else:
49
        door_revealed_with_goat = 2
50
        door_to_switch_to = 3
51

52
    #If the door to switch to is the door with the car, then add one the
53
    #  number of trials won by switching doors.
54
    if (door_to_switch_to == door_with_car):
55
        trials_won_by_switching += 1
56

57
#When all trials have been run, print the number of trials won by switching
58
#  and give the percent.
59
print "Total number of wins by switching: " + str(trials_won_by_switching) + (
60
    " out of " + str(trials) + " (" + str(
61
    int(round(trials_won_by_switching * 100.0 / trials)))) + "%)"

If there is a 2 in 3 chance of winning by switching doors, then the above computer program should produce a probability of about 67%.  If there is a 1 in 2 chance of winning by switching doors, then the above computer program should produce a probability of about 50%.  So what are the chances?  The computer program produces the following:

>> 
Total number of wins by switching: 666501 out of 1000000 (67%)

The total number of wins varies slightly when the computer program is run again, but the percentage is the same each time: 67%.  There is a 2 in 3 chance of winning by switching doors.  Vos Savant was correct.  If your original choice for Door #1 was a 1 in 3 chance, this leaves a 2 in 3 chance for the remaining doors, in which one choice (Door #3) was eliminated.  So switching doors gives you a 2 in 3 chance of winning.

Scenario
Door #1
Door #2
Door #3
Result If You Switch Doors
Car is behind Door #1
car
goat
goat
You pick Door #1.
Monty shows the goat behind Door #3.
You switch to Door #2 which has a goat.
You Lose!
Car is behind Door #2
goat
car
goat
You pick Door #1.
Monty shows the goat behind Door #3.
You switch to Door #2 which has a car.
You Win!
Car is behind Door #3
goat
goat
car
You pick Door #1.
Monty shows a goat behind Door #2.
You switch to Door #3 which has a car.
You Win!

There are many different problems related to probability in which the “common sense” answer is actually incorrect.  The Monty Hall problem is one of the most famous ones.  At first glance it seems that there should be no difference between picking between the leftover two doors, but in reality there is a 2 in 3 chance of winning if you switch.  For some reason, human intuition fails at many statistical problems like this one.