Probability & Applied Statistics · Lab 02

Addition Rules & Counting Principles

A computational manual covering mutually exclusive events, the general addition rule, table counts, factorials, permutations, and combinations in Python.

Warm-up — Lab 01 Assignment Solutions

Before proceeding with Chapter 3.3, we review and solve the practice problems assigned at the conclusion of Lab 01.

Problem 1 — Complementary Defect Model

Problem Statement

A production line has defective rate p=0.08p = 0.08. For a sample of n=4n = 4 items drawn independently, compute the probability of finding at least one defective item.

Mathematical Formulation

P(≥1 Defective)=1−P(No Defects)=1−(1−p)nP(\ge 1 \text{ Defective}) = 1 - P(\text{No Defects}) = 1 - (1 - p)^n

Step 1 — Calculate probability of a non-defective item:

q=1−p=1−0.08=0.92q = 1 - p = 1 - 0.08 = 0.92

Step 2 — Probability that all 4 are non-defective:

P(None defective)=(0.92)4≈0.71639P(\text{None defective}) = (0.92)^4 \approx 0.71639

Step 3 — Complement rule:

P(≥1 Defective)=1−0.71639=0.28361P(\ge 1 \text{ Defective}) = 1 - 0.71639 = 0.28361

Python Code

Python
p = 0.08
n = 4
p_none = (1 - p) ** n
p_at_least_one = 1 - p_none

print("P(At least 1 defective):", round(p_at_least_one, 5))

Expected Output

Output
P(At least 1 defective): 0.28361

Problem 2 — Security Badge Key Permutations

Problem Statement

A security access key has 7 positions: 2 uppercase letters (A–Z, repeats allowed) followed by 5 digits (0–9, no repetition). Find the total unique keys and the probability of cracking it on the 1st attempt.

Mathematical Formulation

Total Keys=(26×26)×(10×9×8×7×6)\text{Total Keys} = (26 \times 26) \times (10 \times 9 \times 8 \times 7 \times 6)

P(Crack)=1Total KeysP(\text{Crack}) = \frac{1}{\text{Total Keys}}

Step 1 — Letter combinations (repetition allowed):

262=67626^2 = 676

Step 2 — Digit permutations without repetition (10P5_{10}P_5):

10×9×8×7×6=30,24010 \times 9 \times 8 \times 7 \times 6 = 30,240

Step 3 — Total keys and cracking probability:

Total Keys=676×30,240=20,442,240\text{Total Keys} = 676 \times 30,240 = 20,442,240

P(Crack on 1st attempt)=120,442,240≈4.8918×10−8P(\text{Crack on 1st attempt}) = \frac{1}{20,442,240} \approx 4.8918 \times 10^{-8}

Python Code

Python
letters = 26 * 26
digits = 10 * 9 * 8 * 7 * 6
total_keys = letters * digits
p_crack = 1 / total_keys

print("Total Keys:", total_keys)
print(f"P(Crack): {p_crack:.8e}")

Expected Output

Output
Total Keys: 20442240
P(Crack): 4.89184566e-08

Problem 3 — Dependent 3-Card Sequence Draw

Problem Statement

From a standard shuffled 52-card deck, calculate the joint probability of drawing a King, then a Queen, then a Jack sequentially without replacement.

Mathematical Formulation

P(K→Q→J)=P(K)⋅P(Q∣K)⋅P(J∣K∩Q)P(K \to Q \to J) = P(K) \cdot P(Q \mid K) \cdot P(J \mid K \cap Q)

Step 1 — Sequential probabilities:

P(K)=452,P(Q∣K)=451,P(J∣K∩Q)=450P(K) = \frac{4}{52}, \quad P(Q \mid K) = \frac{4}{51}, \quad P(J \mid K \cap Q) = \frac{4}{50}

Step 2 — Multiply dependent probabilities:

P(K→Q→J)=452×451×450=64132,600≈0.00048265P(K \to Q \to J) = \frac{4}{52} \times \frac{4}{51} \times \frac{4}{50} = \frac{64}{132,600} \approx 0.00048265

Python Code

Python
p_sequence = (4 / 52) * (4 / 51) * (4 / 50)
print("P(K -> Q -> J):", round(p_sequence, 8))

Expected Output

Output
P(K -> Q -> J): 0.00048265

3.3 The Addition Rule

Case 3.3.1 — Mutually Exclusive Events

When do we use this?

When two events cannot occur on the same trial, add their probabilities.

Mathematical Equations

P(A or B)=P(A)+P(B)P(A \text{ or } B) = P(A) + P(B)

Worked Lecture Example

For one card drawn from a standard 52-card deck, find the probability of drawing a four OR an ace.

Step 1 — Find each probability

There are four fours and four aces in a standard deck:

P(4)=452P(4) = \frac{4}{52}

P(Ace)=452P(\text{Ace}) = \frac{4}{52}

Step 2 — Add the probabilities

The events are mutually exclusive because a single card cannot be both a four and an ace:

P(4 or Ace)=452+452=852≈0.15385P(4 \text{ or Ace}) = \frac{4}{52} + \frac{4}{52} = \frac{8}{52} \approx 0.15385

Final Result

Probability≈0.15385\text{Probability} \approx 0.15385

Simple Python Code

Python
probability = 4/52 + 4/52
print(round(probability, 5))

Expected Output

Output
0.15385

Case 3.3.2 — General Addition Rule

When do we use this?

Use the general addition rule when two events can overlap (are not mutually exclusive).

Mathematical Equations

P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B)

Worked Lecture Example

Roll one standard six-sided die. Let event A=below 3={1,2}A = \text{below } 3 = \{1, 2\}, and event B=odd={1,3,5}B = \text{odd} = \{1, 3, 5\}.

Step 1 — Find the overlap

AA and BB share the outcome 11:

A∩B={1}A \cap B = \{1\}

Step 2 — Apply the addition rule

Subtract the overlap once to avoid double counting:

P(A∪B)=26+36−16=46≈0.6667P(A \cup B) = \frac{2}{6} + \frac{3}{6} - \frac{1}{6} = \frac{4}{6} \approx 0.6667

Final Result

Probability≈0.6667\text{Probability} \approx 0.6667

Simple Python Code

Python
probability = 2/6 + 3/6 - 1/6
print(round(probability, 4))

Expected Output

Output
0.6667

Case 3.3.3 — Blood-Type Addition Example

When do we use this?

Use the addition rule with frequency table counts when categories overlap.

Mathematical Equations

P(A∪B)=n(A)+n(B)−n(A∩B)n(total)P(A \cup B) = \frac{n(A) + n(B) - n(A \cap B)}{n(\text{total})}

Worked Lecture Example

Lecture counts:

  • Type B = 4545
  • Rh-negative = 6565
  • Both Type B and Rh-negative = 88
  • Total sample = 409409

Step 1 — Substitute counts

Add the two category counts and subtract the overlap:

P(B or negative)=45+65−8409P(\text{B or negative}) = \frac{45 + 65 - 8}{409}

Step 2 — Calculate

The favorable count is 102102:

102409≈0.2494\frac{102}{409} \approx 0.2494

Final Result

Probability≈0.2494\text{Probability} \approx 0.2494

Simple Python Code

Python
probability = (45 + 65 - 8) / 409
print(round(probability, 4))

Expected Output

Output
0.2494

3.4 Additional Topics in Probability and Counting

Case 3.4.1 — Factorial and Permutations

When do we use this?

Use factorials and ordered multiplication when arrangements depend on order.

Mathematical Equations

n!=n(n−1)(n−2)…(2)(1)n! = n(n-1)(n-2)\dots(2)(1)

nPr=n!(n−r)!_{n}P_{r} = \frac{n!}{(n-r)!}

Worked Lecture Example

The lecture evaluates a Sudoku first row and a three-digit code without repeated digits.

Step 1 — Sudoku first row

Arrange 9 distinct digits in 9 positions:

9!=9×8×7×6×5×4×3×2×1=362,8809! = 9 \times 8 \times 7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1 = 362,880

Step 2 — Three-digit code

There are 10 choices for the first digit, 9 choices for the second, and 8 for the third. A leading zero is allowed because it is an identification code:

10×9×8=72010 \times 9 \times 8 = 720

Final Result

  • Sudoku arrangements = 362,880362,880
  • Three-digit codes = 720720

Simple Python Code

Python
sudoku = 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1
codes = 10 * 9 * 8

print("Sudoku:", sudoku)
print("Codes:", codes)

Expected Output

Output
Sudoku: 362880
Codes: 720

Case 3.4.2 — Combinations

When do we use this?

Use combinations when selecting items and the order of selection does not matter.

Mathematical Equations

C(n,r)=(nr)=n!r!(n−r)!C(n, r) = \binom{n}{r} = \frac{n!}{r!(n-r)!}

Worked Lecture Example

Lecture examples include arranging repeated house types and choosing 4 companies from 16.

Step 1 — Repeated house types

For 12 houses divided into types of 6, 4, and 2:

12!6! 4! 2!=13,860\frac{12!}{6! \, 4! \, 2!} = 13,860

Step 2 — Choose 4 companies from 16

Cancel factorials to simplify computation:

C(16,4)=16×15×14×134×3×2×1=1,820C(16, 4) = \frac{16 \times 15 \times 14 \times 13}{4 \times 3 \times 2 \times 1} = 1,820

Final Result

Number of 4-company selections=1,820\text{Number of 4-company selections} = 1,820

Simple Python Code

Python
groups = (16 * 15 * 14 * 13) // (4 * 3 * 2 * 1)
print(groups)

Expected Output

Output
1820

Case 3.4.3 — Combination Probability

When do we use this?

Use combinations when selecting several items simultaneously without regard to order.

Mathematical Equations

P(Target)=C(3,1)⋅C(397,3)C(400,4)P(\text{Target}) = \frac{C(3, 1) \cdot C(397, 3)}{C(400, 4)}

Worked Lecture Example

In the lecture corn-kernel problem, 3 of 400 kernels are affected. Four kernels are selected at random. Find the probability of selecting exactly one affected kernel.

Step 1 — Choose the affected kernel

Choose 1 from the 3 affected kernels:

C(3,1)=3C(3, 1) = 3

Step 2 — Choose the unaffected kernels

Choose 3 from the remaining 397 kernels:

C(397,3)=397×396×3953×2×1=10,349,790C(397, 3) = \frac{397 \times 396 \times 395}{3 \times 2 \times 1} = 10,349,790

Step 3 — Count favorable selections

Multiply the two combination counts:

3×10,349,790=31,049,3703 \times 10,349,790 = 31,049,370

Step 4 — Count all possible selections

Choose any 4 kernels from the 400 available:

C(400,4)=400×399×398×3974×3×2×1=1,050,739,900C(400, 4) = \frac{400 \times 399 \times 398 \times 397}{4 \times 3 \times 2 \times 1} = 1,050,739,900

Step 5 — Calculate the probability

Divide favorable outcomes by total possible outcomes:

P=31,049,3701,050,739,900≈0.02955P = \frac{31,049,370}{1,050,739,900} \approx 0.02955

Final Result

Probability≈0.02955\text{Probability} \approx 0.02955

Simple Python Code

Python
three_other = (397 * 396 * 395) // (3 * 2 * 1)
favourable = 3 * three_other
all_groups = (400 * 399 * 398 * 397) // (4 * 3 * 2 * 1)

probability = favourable / all_groups

print("Probability:", round(probability, 5))

Expected Output

Output
Probability: 0.02955