Sets & Logic
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
- The Relational Model & SQLDatabase Engineering
- Functions & RelationsMathematical Thinking
- Proof TechniquesMathematical Thinking
- Combinatorics & CountingMathematical Thinking
- Graph Theory BasicsMathematical Thinking
- Probability BasicsMathematical Thinking
- Algebraic StructuresMathematical Thinking
- Types & ValuesProgramming Fundamentals
- Control FlowProgramming Fundamentals
Parallel
Used in
- TypeScript union & intersection types (set operations over value sets)
- SQL WHERE clauses and JOINs (predicate logic over row sets)
- Boolean short-circuit evaluation in every programming language
- Firewall / access-control rules (predicates over request sets)
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
- I can translate an English requirement into a precise proposition with AND/OR/NOT/implies
- I can explain why ¬(A ∧ B) equals ¬A ∨ ¬B and spot this rewrite in real code
- I can express a filtering problem as set union, intersection, and difference
- I can identify the ambiguity in an informally stated requirement