NapkinCalc

Discrete Mathematics — Logic & Number Theory

Counting sets — inclusion–exclusion

continues from lesson 1 — values defined earlier in the course stay live here

ELI5: to count how many things are in A or B, add the two sizes — but you double-counted the overlap, so subtract it back: |A ∪ B| = |A| + |B| − |A ∩ B|. In a class of 30, if 18 play soccer and 15 play basketball and 7 play both, how many play at least one?

onlycount=18+157only_{count} = 18 + 15 - 7 = 2626 inclusion–exclusion: 26 play a sport
✓ pass onlycount==26only_{count} == 26 subtract the 7 double-counted

Real-world hook: inclusion–exclusion deduplicates mailing lists, sizes database joins, and counts search results matching any of several tags.

Try it yourself: of 40 people, 22 like tea, 18 like coffee, and 9 like both. How many like at least one?

eitheryou=22+189either_{you} = 22 + 18 - 9 = 3131 ✏️ Your turn: use |A ∪ B| = |A| + |B| − |A ∩ B| with 22, 18, and 9.
✓ pass eitheryou==22+189either_{you} == 22 + 18 - 9 green when you subtract the overlap correctly