353 - Topic 02 - Enumeration

709 days ago by Professor353

John Travis

Mississippi College

MATH 353 - Introduction to Mathematical Probability and Statistics

Textbook:  Tanis and Hogg, A Brief Course in Mathematical Statistics

Methods of Enumeration

Now, let's consider a standard deck of cards.  We will consider each card as an ordered pair (value, suit).  Therefore, by the multiplication principle there are $13 \times 4 = 52$ cards in a standard deck with $13$ values and $4$ suits.

 

       
[(2, S), (3, S), (4, S), (5, S), (6, S), (7, S), (8, S), (9, S), (10,
S), (J, S), (Q, S), (K, S), (A, S), (2, D), (3, D), (4, D), (5, D), (6,
D), (7, D), (8, D), (9, D), (10, D), (J, D), (Q, D), (K, D), (A, D), (2,
C), (3, C), (4, C), (5, C), (6, C), (7, C), (8, C), (9, C), (10, C), (J,
C), (Q, C), (K, C), (A, C), (2, H), (3, H), (4, H), (5, H), (6, H), (7,
H), (8, H), (9, H), (10, H), (J, H), (Q, H), (K, H), (A, H)]
[(2, S), (3, S), (4, S), (5, S), (6, S), (7, S), (8, S), (9, S), (10, S), (J, S), (Q, S), (K, S), (A, S), (2, D), (3, D), (4, D), (5, D), (6, D), (7, D), (8, D), (9, D), (10, D), (J, D), (Q, D), (K, D), (A, D), (2, C), (3, C), (4, C), (5, C), (6, C), (7, C), (8, C), (9, C), (10, C), (J, C), (Q, C), (K, C), (A, C), (2, H), (3, H), (4, H), (5, H), (6, H), (7, H), (8, H), (9, H), (10, H), (J, H), (Q, H), (K, H), (A, H)]

Before we can pick some cards, we need to shuffle the deck of course.  In real life you might need to perform several shuffles in order to get a random arrangment of the cards.  We'll just shuffle once and hope for the best.  If you are leary of the shuffle, then just re-evaluate the cell and watch a new arrangment emerge.  Note that the cards are all there but now in a different order.

shuffle(deck) print deck print 'The number of cards in the deck is ',Set(deck).cardinality() 
       
[(8, D), (J, H), (3, D), (A, C), (Q, D), (7, D), (10, H), (Q, C), (2,
D), (2, H), (6, S), (6, D), (10, C), (K, D), (4, D), (4, S), (5, H), (2,
S), (K, S), (7, C), (6, H), (A, D), (A, S), (K, H), (2, C), (5, C), (10,
S), (9, S), (3, H), (A, H), (5, D), (4, H), (K, C), (J, S), (Q, S), (3,
S), (6, C), (J, D), (9, D), (5, S), (8, H), (8, C), (10, D), (4, C), (7,
S), (J, C), (9, H), (Q, H), (7, H), (3, C), (8, S), (9, C)]
The number of cards in the deck is  52
[(8, D), (J, H), (3, D), (A, C), (Q, D), (7, D), (10, H), (Q, C), (2, D), (2, H), (6, S), (6, D), (10, C), (K, D), (4, D), (4, S), (5, H), (2, S), (K, S), (7, C), (6, H), (A, D), (A, S), (K, H), (2, C), (5, C), (10, S), (9, S), (3, H), (A, H), (5, D), (4, H), (K, C), (J, S), (Q, S), (3, S), (6, C), (J, D), (9, D), (5, S), (8, H), (8, C), (10, D), (4, C), (7, S), (J, C), (9, H), (Q, H), (7, H), (3, C), (8, S), (9, C)]
The number of cards in the deck is  52

Often, one doles out the cards one at a time into "hands".  Let's get 5...

%auto print html('<font size=+2 color=green><p>Click on "Update" to deal 5 more cards</font>') deck1 = copy(full_deck) shuffle(deck1) @interact def _(auto_update=False): global deck1 shuffle(deck1) if (Set(deck1).cardinality()<5): print html('<font size=+2 color=red>Deck is too small...getting a new deck</font>') deck1 = copy(full_deck) else: hand = [deck1.pop() for card in range(5)] print html("<p><p>The cards dealt:") show(hand) print html("The remaining cards in the deck:") print(deck1) print(html("\nThe number of remaining cards in the deck = %s"%str(Set(deck1).cardinality()))) 
       

Click to the left again to hide and once more to show the dynamic interactive window

Notice, now that these cards have been dealt, the deck has fewer cards left.  If you go back up and reevaluate the previous cell for "hand", you will have 5 fewer cards again left below.  Don't try to deal yourself more than 10 hands!  Otherwise, you will need to go back up and create a new deck.

 

Empirical Card Probabilities - Poker

Finally, we want to experimentally develop a guess for the probability of the various poker hands.  If you do not know the various poker hands, you can check out a brief explanation in the textbook or browse check it out on the web .  It is easy to understand that the corresponding probabilities for determining a particular hand must use conditional probability.

Below, we deal out an increasingly large number of 5-card hands and count the resulting types of poker hands.   As then number of hands increases, the corresponding relative frequencies should approach the theoretical values.  Please note that for large numbers of hands, the results make take a while to arrive.

       
num_hands 

Click to the left again to hide and once more to show the dynamic interactive window

Now, some playing around with binomial coefficients...

# How about Pascal's triangle n=10 for row in range(n+1): binoms = sorted(binomial_coefficients(row).items()) given_n = [] for k in range(row+1): given_n.append(binoms[k][1]) html('<center>%s</center>'%given_n) 
       
[1]

[1, 1]

[1, 2, 1]

[1, 3, 3, 1]

[1, 4, 6, 4, 1]

[1, 5, 10, 10, 5, 1]

[1, 6, 15, 20, 15, 6, 1]

[1, 7, 21, 35, 35, 21, 7, 1]

[1, 8, 28, 56, 70, 56, 28, 8, 1]

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

[1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1]
[1]

[1, 1]

[1, 2, 1]

[1, 3, 3, 1]

[1, 4, 6, 4, 1]

[1, 5, 10, 10, 5, 1]

[1, 6, 15, 20, 15, 6, 1]

[1, 7, 21, 35, 35, 21, 7, 1]

[1, 8, 28, 56, 70, 56, 28, 8, 1]

[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

[1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1]
# or perhaps how about the number of unordered vs ordered arrangements for a given n n=20 binoms = sorted(binomial_coefficients(n).items()) for r in range(n+1): html('For (n,r)=%s'%str((n,r))+', unordered arrangements=%s'%str(binoms[r][1])+' and ordered arrangements=%s'%str(binoms[r][1]*factorial(r))) 
       
For (n,r)=(20, 0), unordered arrangements=1 and ordered arrangements=1

For (n,r)=(20, 1), unordered arrangements=20 and ordered arrangements=20

For (n,r)=(20, 2), unordered arrangements=190 and ordered arrangements=380

For (n,r)=(20, 3), unordered arrangements=1140 and ordered arrangements=6840

For (n,r)=(20, 4), unordered arrangements=4845 and ordered arrangements=116280

For (n,r)=(20, 5), unordered arrangements=15504 and ordered arrangements=1860480

For (n,r)=(20, 6), unordered arrangements=38760 and ordered arrangements=27907200

For (n,r)=(20, 7), unordered arrangements=77520 and ordered arrangements=390700800

For (n,r)=(20, 8), unordered arrangements=125970 and ordered arrangements=5079110400

For (n,r)=(20, 9), unordered arrangements=167960 and ordered arrangements=60949324800

For (n,r)=(20, 10), unordered arrangements=184756 and ordered arrangements=670442572800

For (n,r)=(20, 11), unordered arrangements=167960 and ordered arrangements=6704425728000

For (n,r)=(20, 12), unordered arrangements=125970 and ordered arrangements=60339831552000

For (n,r)=(20, 13), unordered arrangements=77520 and ordered arrangements=482718652416000

For (n,r)=(20, 14), unordered arrangements=38760 and ordered arrangements=3379030566912000

For (n,r)=(20, 15), unordered arrangements=15504 and ordered arrangements=20274183401472000

For (n,r)=(20, 16), unordered arrangements=4845 and ordered arrangements=101370917007360000

For (n,r)=(20, 17), unordered arrangements=1140 and ordered arrangements=405483668029440000

For (n,r)=(20, 18), unordered arrangements=190 and ordered arrangements=1216451004088320000

For (n,r)=(20, 19), unordered arrangements=20 and ordered arrangements=2432902008176640000

For (n,r)=(20, 20), unordered arrangements=1 and ordered arrangements=2432902008176640000
For (n,r)=(20, 0), unordered arrangements=1 and ordered arrangements=1

For (n,r)=(20, 1), unordered arrangements=20 and ordered arrangements=20

For (n,r)=(20, 2), unordered arrangements=190 and ordered arrangements=380

For (n,r)=(20, 3), unordered arrangements=1140 and ordered arrangements=6840

For (n,r)=(20, 4), unordered arrangements=4845 and ordered arrangements=116280

For (n,r)=(20, 5), unordered arrangements=15504 and ordered arrangements=1860480

For (n,r)=(20, 6), unordered arrangements=38760 and ordered arrangements=27907200

For (n,r)=(20, 7), unordered arrangements=77520 and ordered arrangements=390700800

For (n,r)=(20, 8), unordered arrangements=125970 and ordered arrangements=5079110400

For (n,r)=(20, 9), unordered arrangements=167960 and ordered arrangements=60949324800

For (n,r)=(20, 10), unordered arrangements=184756 and ordered arrangements=670442572800

For (n,r)=(20, 11), unordered arrangements=167960 and ordered arrangements=6704425728000

For (n,r)=(20, 12), unordered arrangements=125970 and ordered arrangements=60339831552000

For (n,r)=(20, 13), unordered arrangements=77520 and ordered arrangements=482718652416000

For (n,r)=(20, 14), unordered arrangements=38760 and ordered arrangements=3379030566912000

For (n,r)=(20, 15), unordered arrangements=15504 and ordered arrangements=20274183401472000

For (n,r)=(20, 16), unordered arrangements=4845 and ordered arrangements=101370917007360000

For (n,r)=(20, 17), unordered arrangements=1140 and ordered arrangements=405483668029440000

For (n,r)=(20, 18), unordered arrangements=190 and ordered arrangements=1216451004088320000

For (n,r)=(20, 19), unordered arrangements=20 and ordered arrangements=2432902008176640000

For (n,r)=(20, 20), unordered arrangements=1 and ordered arrangements=2432902008176640000