Sets & Logic

Difficulty
Importance

The problem

Humans reason about collections of things and about statements that are true or false, but informal language is ambiguous. Sets and propositional logic give us a precise, unambiguous vocabulary for grouping things and reasoning about truth — the vocabulary every later formalism is written in.

Why now

There is nothing before this to fall back on: natural language cannot express 'for all inputs' or 'there exists a case where this fails' without ambiguity. Every bug report that says 'it sometimes breaks' is a failure to speak this language.

Mental model

A set is a bag with no duplicates and no order — membership is the only question it answers. Logic is algebra over true/false: AND, OR, NOT, and implication compose small certain statements into large certain ones. Types are sets; conditions are propositions; a database query is set operations spoken with a different accent.

Unlocks

Parallel

Used in

Projects

  • Write a truth-table generator for arbitrary boolean expressions
  • Model your music library as sets and express three real questions as unions/intersections/differences

Examples

  • 'User can edit' = (isOwner OR isAdmin) AND NOT isBanned — a proposition built from atoms
  • TypeScript: type A = string | number is the union of two value sets

Resources

Mastery checklist