Module 6 · Probability and Random Variables Lesson 52 of 120

Probability Rules, Complements, Unions, and Intersections

Avoiding double-counting fraud rules.

2:25 clip2:47:23–2:49:49 in the full courseWatch on YouTube

Transcript

21 sentences · select one to jump there

Check your understanding

Why subtract the overlap exactly once?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

052-probability-rules-complements-unions-and-intersections.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 052 of 120
 * Probability Rules, Complements, Unions, and Intersections
 * Module 06: Probability and Random Variables
 *
 * Scenario: Avoiding double-counting fraud rules
 * Rule:     P(A∪B)=P(A)+P(B)−P(A∩B)
 *
 * Try it:   Why subtract the overlap exactly once?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/probability-and-random-variables/probability-rules-complements-unions-and-intersections/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson052() {
  const a=.30, b=.20, both=.08;
  if (both < Math.max(0,a+b-1) || both > Math.min(a,b))
    throw new Error("Impossible intersection");
  const result = {either:a+b-both, neither:1-(a+b-both),
    onlyA:a-both, onlyB:b-both};
  return result;
}

export const checkedResult = {"either":0.42,"neither":0.5800000000000001,"onlyA":0.21999999999999997,"onlyB":0.12000000000000001};

// Run this file directly: npx tsx lessons/06-probability-and-random-variables/052-probability-rules-complements-unions-and-intersections.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson052(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "either": 0.42,
  "neither": 0.5800000000000001,
  "onlyA": 0.21999999999999997,
  "onlyB": 0.12000000000000001
}

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

P(A∪B)=P(A)+P(B)−P(A∩B)