from edumath.probability import conditional_probability, is_independent
sample_space = {1, 2, 3, 4, 5, 6}
even = {2, 4, 6}
at_least_four = {4, 5, 6}
conditional_probability(even, at_least_four, sample_space)0.6666666666666666
P(A | B)Conditional probability answers questions like “What is the probability of A if we already know B happened?” This is the mathematics of updating. A weather forecast changes after seeing clouds, a medical risk changes after a test result, and a card probability changes after you learn the suit.
After this lesson you should be able to:
P(A | B) in words;P(A | B) from P(B | A);The notation P(A | B) means:
probability of A given that B has happened
The event after the vertical bar is the information we already know. It restricts the sample space to B.
For a fair die, suppose we know the roll is greater than 3. The possible outcomes are no longer {1,2,3,4,5,6}. They are only:
{4, 5, 6}
If A is “roll even,” then inside this smaller universe the favorable outcomes are {4,6}. So
P(even | greater than 3) = 2/3
P(A | B)When P(B) > 0,
P(A | B) = P(A and B) / P(B)
This formula says: among the cases where B happened, what fraction also have A?
Two-way tables are useful because they organize counts. Suppose 100 students are classified by whether they studied and whether they passed.
| Passed | Did not pass | Total | |
|---|---|---|---|
| Studied | 54 | 6 | 60 |
| Did not study | 20 | 20 | 40 |
| Total | 74 | 26 | 100 |
To find P(passed | studied), restrict to the studied row:
P(passed | studied) = 54 / 60 = 0.9
To find P(studied | passed), restrict to the passed column:
P(studied | passed) = 54 / 74
These are different questions.
Events A and B are independent if knowing B happened does not change the probability of A:
P(A | B) = P(A)
Equivalently:
P(A and B) = P(A)P(B)
Independence is not the same as “cannot happen together.” If two events cannot happen together, then knowing one happened usually changes the probability of the other to zero.
The conditional formula can be rearranged:
P(A and B) = P(A | B)P(B)
Also:
P(A and B) = P(B | A)P(A)
This is useful for multi-stage probability problems.
Bayes’ rule reverses conditional probability:
P(A | B) = P(B | A)P(A) / P(B)
A beginner-friendly way to use Bayes’ rule is with natural frequencies. Imagine 1000 people:
Then 108 people test positive total, and 9 of those actually have the condition:
P(condition | positive) = 9 / 108 = 1 / 12
A standard deck has 52 cards. Suppose a card is known to be a face card: jack, queen, or king. What is the probability that it is a king?
P(king | face card) = 4/12 = 1/3
Suppose P(A)=0.4, P(B)=0.5, and P(A and B)=0.2. Are A and B independent?
Check the product:
P(A)P(B) = 0.4 * 0.5 = 0.2
This matches P(A and B), so the events are independent.
P(A | B) with P(B | A).P(A | B) mean in words?P(roll 5 | odd)?P(studied | passed).P(A)=0.3, P(B)=0.2, and P(A and B)=0.06, are the events independent?P(test positive | disease) be very different from P(disease | test positive)?A happens given that B has happened.{1,3,5}. Only one is 5, so the probability is 1/3.54/74.0.3 * 0.2 = 0.06.The most important habit is to identify the condition first. The condition tells you the denominator.
Guess first. In P(A | B), which event becomes the smaller universe?
Guided exercise.
The event after the bar, B, is the condition. If the problem says “given that B occurred,” you count only outcomes in B.
Checkpoint. In P(rain | cloudy), which event is the condition? What does the probability mean in words?
Guess first. If the condition has 4 outcomes and 3 also satisfy A, what is P(A | condition)?
Guided exercise.
For a die, let A = even = {2,4,6} and B = at least 4 = {4,5,6}. Inside B, the outcomes that are also in A are {4,6}.
P(A | B) = 2/3
Checkpoint. For a die, compute P(greater than 2 | even).
Guess first. To find P(passed | studied), do you divide by the studied total or the passed total?
Guided exercise.
The condition is “studied,” so use the studied total as the denominator:
P(passed | studied) = 54 / 60
Checkpoint. Using the table above, compute P(did not study | did not pass).
Guess first. If P(A | B) is different from P(A), are the events independent?
Guided exercise.
If P(A)=0.5 but P(A | B)=0.8, knowing B changes the probability of A. Therefore the events are not independent.
Checkpoint. If P(A)=0.2, P(B)=0.5, and P(A and B)=0.1, are A and B independent?
Guess first. If a test has false positives, does every positive result mean the condition is likely?
Guided exercise.
Use counts. If 100 people test positive and 20 of those truly have the condition, then
P(condition | positive) = 20/100 = 0.2
The denominator is all positive tests, not all people with the condition.
Checkpoint. In 500 people, 25 have a condition. A test catches 20 of them and falsely flags 45 people without the condition. What is P(condition | positive)?
{2,4,6}. Greater than 2 inside that set is {4,6}, so the probability is 2/3.20/26 = 10/13.P(A)P(B)=0.2*0.5=0.1, matching P(A and B).20+45=65 positive tests. The probability is 20/65 = 4/13.Use this checkpoint to practice conditions, independence, and Bayes direction.
Use edumath for finite conditional probabilities.
0.6666666666666666
Check independence using the product rule.
Use SymPy for exact Bayes-rule arithmetic.