from edumath.probability import combinations, factorial, permutations
factorial(5), permutations(6, 2), combinations(6, 2)(120, 30, 15)
Many probability questions are counting questions in disguise. If all outcomes are equally likely, then
probability = favorable outcomes / total outcomes
So before computing a probability, we often need to count how many outcomes are possible and how many satisfy the event.
After this lesson you should be able to:
Suppose a class has 10 students and 3 students will be chosen for a committee. If every committee is equally likely, a probability about the committee requires knowing how many committees are possible. Listing all committees by hand would be slow, so we use counting principles.
Use the product rule when a process has stages and each choice is combined with each later choice.
If there are 3 shirt choices and 2 pants choices, then there are
3 * 2 = 6
outfits.
Ask: “Do I choose one thing from group A and one thing from group B?” If yes, multiply.
Use the sum rule when choices are separate alternatives that cannot happen at the same time.
If a snack is either one of 4 fruits or one of 3 crackers, then there are
4 + 3 = 7
snack choices.
A factorial counts arrangements of all items in a list:
n! = n * (n-1) * (n-2) * ... * 2 * 1
For example:
4! = 4 * 3 * 2 * 1 = 24
There are 24 ways to arrange 4 different books on a shelf.
A permutation counts ordered selections. If you choose 2 winners from 5 people for first place and second place, order matters. Alice then Bob is different from Bob then Alice.
The formula is
P(n,k) = n! / (n-k)!
For 2 ordered winners from 5 people:
P(5,2) = 5 * 4 = 20
A combination counts unordered selections. If you choose 2 people from 5 for a committee, Alice-Bob is the same committee as Bob-Alice.
The formula is
C(n,k) = n! / (k!(n-k)!)
For 2 people from 5:
C(5,2) = (5 * 4) / (2 * 1) = 10
With replacement means the same item can be chosen again. Example: rolling a die three times.
Without replacement means once an item is chosen, it is removed. Example: dealing cards from a deck.
This difference changes the count. With replacement, options may stay constant. Without replacement, the number of options usually decreases.
A password has 2 letters followed by 1 digit. Suppose letters can repeat and the digit can be 0 through 9. How many passwords are possible?
26 * 26 * 10 = 6760
A group has 6 students. A 2-person committee is chosen at random. What is the probability that students Ana and Ben are both chosen?
Count all possible committees:
C(6,2) = 15Count favorable committees. There is only one committee containing exactly Ana and Ben together:
{Ana, Ben}Compute probability:
1 / 155!.P(6,2).C(6,2).5! = 120.4 * 3 = 12.P(6,2) = 6 * 5 = 30.C(6,2) = (6 * 5)/(2 * 1) = 15.1234 and 4321 are different PINs.Counting becomes easier when you first decide what kind of counting problem you have.
Guess first. If you choose one shirt and one pair of pants, should you add or multiply?
Guided exercise.
You choose one item from each category. If there are 5 shirts and 4 pants, then
5 * 4 = 20
outfits are possible.
Checkpoint. A lunch is one sandwich and one drink. There are 3 sandwiches and 5 drinks. How many lunches are possible?
Guess first. Is 6! equal to 6 * 5!?
Guided exercise.
6! = 6 * 5 * 4 * 3 * 2 * 1
= 720
Also:
6! = 6 * 5!
This shortcut helps simplify formulas.
Checkpoint. Compute 3! and 6!/4!.
Guess first. Does a gold-silver-bronze race result care about order?
Guided exercise.
Yes. If Ana wins gold and Ben wins silver, that is different from Ben winning gold and Ana winning silver. Ordered awards use permutations.
Checkpoint. Decide whether each situation uses permutations or combinations: choosing a 3-person committee; arranging 3 books; choosing first and second place.
Guess first. Should C(7,2) be smaller than P(7,2)?
Guided exercise.
C(7,2) = 7! / (2!5!)
= (7 * 6) / (2 * 1)
= 21
It is smaller than P(7,2)=42 because combinations ignore order.
Checkpoint. Compute C(8,3).
Guess first. If there are 10 equally likely outcomes and 4 favorable outcomes, what is the probability?
Guided exercise.
P(event) = favorable / total = 4 / 10 = 2 / 5
Counting is not the final step; it gives the numerator and denominator.
Checkpoint. From 5 students, 2 are chosen for a committee. What is the probability that a particular pair is chosen?
3 * 5 = 15 lunches.3! = 6. Also 6!/4! = 6 * 5 = 30.C(8,3) = (8 * 7 * 6)/(3 * 2 * 1) = 56.C(5,2)=10 committees and one particular pair, so the probability is 1/10.Use this checkpoint to decide which counting idea applies.
Use edumath counting helpers.
(120, 30, 15)
Python’s standard library has similar tools.
Use SymPy to keep formulas symbolic.