Saturday, April 15, 2023

DM42, Free42, HP 42S: Birthday Probability Function

DM42, Free42, HP 42S:  Birthday Probability Function



The Age Old Birthday Question


You probably have read or heard about when there is 23 random people in a room, half of the time someone shares a birthday.   This is the classic birthday problem.   


Consider a room with 3 people and assume a 365 day year calendar.   What are are the odds that no one shares a birthday?


For the first person, they clearly have any day of the calendar.

For the second person, they only have 364 days out of the calendar.

For the third person, they only have 363 days available.


The probability that no one shares a birthday is:


P = 365/365 * 364/365 * 363/365

= (365 * 364 * 363) / (365^3)

≈ 0.99180


About 99.180% chance none of the three people share a birthday. 


Note that:

365/365 * 364/365 * 363/365

= (365/365) * (365 - 1)/365 * (365 - 2)/365

=  1 *  (365/365 - 1/365) * (365/365 - 2/365)

=  1 *  (1 - 1/365) * (1 - 2/365)


The derivation above leads to the formula stated by Persi Diaconis and Brain Skyrms (pg. 20 from Ten Great ideas About Chance): 


P = 1 * (N - 1)/C * (N - 2)/C * ...  =  Π( 1 - m/C, m = 1 to N-1)


C = number of categories (examples: days in a calendar year, minutes in an hour, number of places, etc...)

N = sample population

P = probability that sample population does not share a category (examples:  number of people that don't share the same birthday, number of people from a city that are not in the same location, etc...)

Π is the product function.


In our example above, C is the number of days in a 365 day calendar and N is the number of people.  The program BDAY makes the product calculation.



DM42/HP 42S/Free42/Plus42 Program:  BDAY


N and C are prompted.  


00 { 58-Byte Prgm }

01▸LBL "BDAY"

02 "CATEGORIES?"

03 PROMPT

04 STO 02

05 1

06 STO 01

07 "N?"

08 PROMPT

09 1

10 -

11 STO 03

12▸LBL 00

13 1

14 RCL 03

15 RCL÷ 02

16 -

17 STO× 01

18 DSE 03

19 GTO 00

20 "PROB= "

21 ARCL 01

22 AVIEW

23 RCL 01

24 .END.



A Quicker Calculation


Gratitude to Thomas Klemm, this next program is listed here by permission.


A shorter way to calculate this probability (only limited to how large a calculator can handle numbers) is:


P = PERM(C,N) / (C^N)  =  C! / ( (C - N)! * C^N )



DM42/HP 42S/Free42/Plus42 Program:  BDAYC  (compact)


Enter C on the Y stack and N on the X stack before running the program.


00 { 9-Byte Prgm }

01 RCL ST Y

02 X<>Y

03 PERM

04 X<>Y

05 LASTX

06 Y↑X

07 ÷

08 END



Examples


1.  Probability that 40 people do not share a birthday (assume a 365 day calendar):


C =  365, N =  40

Probability: 0.10877


Only about 10.877% chance no one in 40 people share a birthday.  



2.  Probability that 3 cards drawn do not share the same suit:


C = 4  (4 suits in a deck of cards), N =  3

Probability:  0.37500


About 37.5% chance no three cards share the same suit.



3.  A bowl has 50 numbered balls.   16 people draw a ball from the bowl and then places the ball back in the bowl.


C = 50, N = 16

Probability:  0.06751


Only about 6.751% of the time all 16 people draw different numbered balls.  



Sources


Diaconis, Persi and Brian Skyrms  Ten Great Ideas About Chance  Princeton University Press:  Princeton, New Jersey.  2018.  ISBN 978-0-691-19639-8


"(42S/DM42/Free42/Plus42) Birthday Probability Function"  The Museum of HP Calculators.   https://www.hpmuseum.org/forum/thread-19535.html.  Retrieved February 11, 2023.  


This blog turns 12 tomorrow, so excited!



Eddie 


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...