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 Ω\Omega is the set of all possible outcomes of a random experiment.

Examples:

  • Coin flip: Ω={H,T}\Omega = \{H, T\}
  • Die roll: Ω={1,2,3,4,5,6}\Omega = \{1, 2, 3, 4, 5, 6\}
  • Two coin flips: Ω={HH,HT,TH,TT}\Omega = \{HH, HT, TH, TT\}

Example 1: Card Draw

Drawing one card from a standard deck:

Ω={A♠,2♠,...,K♠,A♥,...,K♣}\Omega = \{\text{A♠}, \text{2♠}, ..., \text{K♠}, \text{A♥}, ..., \text{K♣}\}

Ω=52|\Omega| = 52 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: AΩA \subseteq \Omega.

An event occurs if the outcome of the experiment is in AA.

Example 2: Die Roll Events

Sample space: Ω={1,2,3,4,5,6}\Omega = \{1, 2, 3, 4, 5, 6\}

Events:

  • AA = "roll is even" = {2,4,6}\{2, 4, 6\}
  • BB = "roll is prime" = {2,3,5}\{2, 3, 5\}
  • CC = "roll exceeds 4" = {5,6}\{5, 6\}
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 ABA \cup B: "AA or BB occurs"
  • Intersection ABA \cap B: "AA and BB occur"
  • Complement AcA^c: "AA does not occur"
  • Difference ABA \setminus B: "AA but not BB"

Example 3: Operations

For die roll: A={2,4,6}A = \{2, 4, 6\}, B={2,3,5}B = \{2, 3, 5\}

  • AB={2,3,4,5,6}A \cup B = \{2, 3, 4, 5, 6\} (even OR prime)
  • AB={2}A \cap B = \{2\} (even AND prime)
  • Ac={1,3,5}A^c = \{1, 3, 5\} (NOT even = odd)
  • AB={4,6}A \setminus B = \{4, 6\} (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

  1. Sample space Ω\Omega: All possible outcomes
  2. Event AA: Subset of sample space
  3. Operations: \cup (or), \cap (and), c^c (not)
  4. Simulation: Python sets for event algebra

Next Lesson: Probability axioms and basic properties!