Set Theory & Venn Diagram Calculator
Calculate union, intersection, complement, and Venn diagram regions for 2 or 3 sets using inclusion-exclusion.
Set Theory Guide
Set Operations
Union (∪): elements in A or B (or both). |A ∪ B| = |A| + |B| − |A ∩ B|. Intersection (∩): elements in both A and B. Complement (A'): elements NOT in A. |A'| = |U| − |A| where U is universal set. Difference (A − B): in A but not in B. |A − B| = |A| − |A ∩ B|. Example: in a class of 30, 18 study Maths (M), 15 study Physics (P), 10 study both. |M ∪ P| = 18 + 15 − 10 = 23 study at least one subject. Neither subject: 30 − 23 = 7.
Inclusion-Exclusion (3 sets)
For 3 sets: |A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|. Each pairwise intersection is subtracted (because it was double-counted). The triple intersection is added back (because it was subtracted three times and counted three times — net zero, but should appear once). Example: 100 students, 50 study A, 40 study B, 30 study C, 15 in A∩B, 10 in A∩C, 8 in B∩C, 3 in all three. |A∪B∪C| = 50+40+30 − 15−10−8 + 3 = 90 study at least one. 10 study none. Drawing a 3-set Venn
Probability and Venn Diagrams
P(A ∪ B) = P(A) + P(B) − P(A ∩ B). For mutually exclusive events (A and B cannot both occur): P(A ∩ B) = 0, so P(A ∪ B) = P(A) + P(B). For independent events: P(A ∩ B) = P(A) × P(B). Example: roll a die. P(even or > 4) = P(even) + P(>4) − P(both) = 3/6 + 2/6 − 1/6 = 4/6 = 2/3. Conditional probability: P(A|B) = P(A ∩ B) / P(B). Read as 'probability of A given B'. Example: P(student plays football | studies maths) = students playing both ÷ students studying maths. Used in medical testing — Bayes'
Set Theory in Computer Science
Set theory underlies many computer science concepts. Database queries: SQL JOIN operations are set operations. INNER JOIN = intersection. UNION = set union (removing duplicates). LEFT JOIN = A minus (A ∩ B) plus the matched pairs. Search engines: keyword search uses Boolean set operations. 'A AND B' = intersection. 'A OR B' = union. 'A NOT B' = set difference. Programming: Python and JavaScript have built-in set types with operations including union, intersection, difference, symmetric differenc
Recommended for this calculator