Sample Spaces and Events
Understand the foundations of probability: sample spaces, events, and event algebra.
20 min read
Beginner
Introduction
We now transition from combinatorics (counting) to probability (measuring uncertainty). Probability theory provides the mathematical framework for reasoning about random phenomena.
Learning Objectives:
- Understand sample spaces and events
- Perform set operations on events
- Simulate random experiments in Python
Sample Spaces
The sample space is the set of all possible outcomes of a random experiment.
Examples:
- Coin flip:
- Die roll:
- Two coin flips:
Example 1: Card Draw
Drawing one card from a standard deck:
outcomes
python
import random
# Define sample space for card draw
suits = ['♠', '♥', '♦', '♣']
ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
sample_space = [f"{rank}{suit}" for suit in suits for rank in ranks]
print(f"Sample space size: |Ω| = {len(sample_space)}")
print(f"\nFirst 10 outcomes: {sample_space[:10]}")
print(f"Last 10 outcomes: {sample_space[-10:]}")
# Simulate random draws
print(f"\n5 random draws:")
for i in range(5):
card = random.choice(sample_space)
print(f" Draw {i+1}: {card}")Events
An event is a subset of the sample space: .
An event occurs if the outcome of the experiment is in .
Example 2: Die Roll Events
Sample space:
Events:
- = "roll is even" =
- = "roll is prime" =
- = "roll exceeds 4" =
python
import random
# Sample space
omega = {1, 2, 3, 4, 5, 6}
# Define events
A = {2, 4, 6} # even
B = {2, 3, 5} # prime
C = {5, 6} # exceeds 4
print("Sample space:", omega)
print("\nEvents:")
print(f" A (even): {A}")
print(f" B (prime): {B}")
print(f" C (>4): {C}")
# Simulate 10 rolls and check which events occur
print(f"\n10 random rolls:")
for i in range(10):
roll = random.choice(list(omega))
events = []
if roll in A:
events.append('A')
if roll in B:
events.append('B')
if roll in C:
events.append('C')
print(f" Roll {i+1}: {roll} → Events: {events if events else 'none'}")Set Operations on Events
Events are sets, so we use set operations:
- Union : " or occurs"
- Intersection : " and occur"
- Complement : " does not occur"
- Difference : " but not "
Example 3: Operations
For die roll: ,
- (even OR prime)
- (even AND prime)
- (NOT even = odd)
- (even but NOT prime)
python
# Set operations on events
A = {2, 4, 6} # even
B = {2, 3, 5} # prime
omega = {1, 2, 3, 4, 5, 6}
print("Set operations:")
print(f"\nA = {A}")
print(f"B = {B}")
print(f"\nA ∪ B (union) = {A | B}")
print(f"A ∩ B (intersection) = {A & B}")
print(f"A^c (complement) = {omega - A}")
print(f"A \ B (difference) = {A - B}")
print(f"B \ A (difference) = {B - A}")
# Check if events are disjoint
C = {5, 6}
D = {1, 2, 3}
print(f"\nAre C={C} and D={D} disjoint? {len(C & D) == 0}")Key Takeaways
- Sample space : All possible outcomes
- Event : Subset of sample space
- Operations: (or), (and), (not)
- Simulation: Python sets for event algebra
Next Lesson: Probability axioms and basic properties!