Skip to content

The difference law: A ∖ B = A ∩ B′

Level: 101 · one law of the algebra of sets, on its own page

One line: Set difference is not a new operation but intersection with a complement, which is why it inherits no law of its own and why every identity about ∖ is proved by rewriting it away.

The law

Sets Logic Python
A ∖ B = A ∩ B′ p ∧ ¬q a - b == a & (U - b)

Why it is true

x ∈ A ∖ B means x ∈ A and x ∉ B, which is x ∈ A and x ∈ B′, which is x ∈ A ∩ B′. One definition, read twice. A law of sets is decided one member at a time, so checking it on every subset of a four-element universe, every pattern of membership there is, proves it; the program does that and prints the matching truth table.

Where it is used, and the trap

Rewrite ∖ as ∩ B′ and the laws above do the rest: (A ∖ B) ∖ C = A ∩ B′ ∩ C′ = A ∖ (B ∪ C), and A ∖ (B ∖ C) = A ∩ (B ∩ C′)′ = A ∩ (B′ ∪ C) = (A ∖ B) ∪ (A ∩ C), two identities that look unlikely until the rewriting makes them routine. Python's a - b is this law, and it needs no U, because A ∩ B′ never looks outside A. The trap, found by search on the parent page: ∖ is neither commutative nor associative.

What the program prints

Verified output of law_difference.py — regenerated by tools/run_examples.py, never hand-typed.

1. THE LAW: A ∖ B = A ∩ B′
   checked on all 256 choices of 2 subset(s) of U = {1, 2, 3, 4}: True

2. ONE INSTANCE, WORKED
   A = {1, 2}, B = {2, 3}, C = {3, 4}, A' = {3, 4}, B' = {1, 4}
   A ∖ B = {1} = A ∩ B' = {1}

3. THE SAME LAW IN LOGIC: p ∧ ¬q
   every row of the truth table agrees, which is why the member-by-member check is a proof:
   p  q   left  right
   T  T   F     F
   T  F   T     T
   F  T   F     F
   F  F   F     F

Po polsku, w skrócie

Prawo różnicy: A ∖ B to A ∩ B′, więc różnica nie jest nowym działaniem i nie ma własnych praw; każdą tożsamość z ∖ dowodzi się, zamieniając ją na przekrój z dopełnieniem. Python pisze a - b i nie potrzebuje U.

Auf Deutsch: Stichwörter

Differenzgesetz: A ∖ B = A ∩ B′, die Differenz ist ein Schnitt mit einem Komplement.

Stichwörter: Mengendifferenz, relatives Komplement, Schnitt, Umschreibung.

See also