Set operations: union, intersection, difference and complement in an explicit universe

On this page
  1. Goal and scope
  2. Givens and symbols
  3. Rules and sources
  4. Main derivation
  5. Substeps and lemmas
  6. Reverse audits
  7. Error controls and negative controls
  8. Result and limitations
  9. Verification and source binding

← Guide index · Original MKO

derivation-mko-set-operations-01 · production-20261019-adopted-96

Goal and scope

Universe U={1,2,3,4,5,6,7,8}, A={2,4,6,8}, B={3,4,5,6}. Compute A∪B, A∩B, A∖B, B∖A, U∖A and U∖B element by element; show A∖B≠B∖A; show that the complement of A changes when the universe is U′={1,2,3,4,5,6,7,8,9,10}; prove U∖(A∪B)=(U∖A)∩(U∖B) for arbitrary sets and check it on this example; and use A∪B=A∪(B∖A) to explain why the union has 6 elements, not 8.

Treats finite sets in one explicit universe (MKO assumptions a1 and a2). The operations are defined by membership conditions and computed element by element; De Morgan's law is proved by a general argument, and the example only checks it. It does not bind Lean declarations such as Set.mem_union, and does not change the canonical MKO or its English edition.

Givens and symbols

  • set_operations_def
  • set_extensionality
  • subset_def
  • finite_set_listing
  • finite_counting_basics
  • de_morgan_logic
  • G1 — Universe U={1,2,3,4,5,6,7,8} (MKO assumption a2: the universe is stated before any complement is used).
  • G2 — A={2,4,6,8} and B={3,4,5,6}.
  • G3 — A second universe for comparison: U′={1,2,3,4,5,6,7,8,9,10}.
  • U,\ U' — two explicit universes
  • A\cup B — union: in at least one of the sets
  • A\cap B — intersection: in both sets
  • A\setminus B — difference: in A but not in B
  • U\setminus A — the complement of A relative to U
  • |X| — the number of elements of a finite set X
  • (T,F) — a row of the membership table: x∈A true, x∈B false

Rules and sources

  • set_operations_def · prerequisite — Set operations: x∈A∪B ⇔ x∈A or x∈B; x∈A∩B ⇔ x∈A and x∈B; x∈A∖B ⇔ x∈A and x∉B; in a universe U, Aᶜ=U∖A.
  • set_extensionality · prerequisite — Set equality: A=B if and only if A⊆B and B⊆A, i.e. they have the same elements.
  • subset_def · prerequisite — Subset: A⊆B means every element of A is an element of B, i.e. ∀x (x∈A⇒x∈B).
  • finite_counting_basics · prerequisite — Finite counting: for disjoint finite sets A, B, |A∪B|=|A|+|B|; |A×B|=|A|·|B|; there is a bijection between finite sets ⇔ they have the same number of elements.
  • de_morgan_logic · prerequisite — De Morgan's laws for logic: ¬(P∧Q) ⇔ ¬P∨¬Q and ¬(P∨Q) ⇔ ¬P∧¬Q.
  • def_intro · prerequisite — Introducing a definition: a statement, expression or object may be given a name, after which the name and what it stands for are interchangeable.
  • forall_intro · prerequisite — ∀-introduction (generalization): if a statement is proved for an arbitrary element x, with no extra assumption on x, it holds for every x in the domain.
  • case_analysis · prerequisite — Proof by cases: if P∨Q holds and both P⇒R and Q⇒R are proved, then R holds. The cases must cover every possibility.
  • forall_elim · prerequisite — ∀-elimination (instantiation): if ∀x∈D, P(x) holds and a∈D, then P(a) holds.
  • and_intro_elim · prerequisite — Conjunction: from P and Q infer P∧Q; from P∧Q infer P and infer Q.
  • numeric_evaluation · prerequisite — Exact evaluation of an explicit integer or rational expression; independently recomputable.
  • def_unfold · prerequisite — Unfolding a definition: replacing a defined term by its definition (or folding it back) does not change whether a statement is true.
  • contradiction · prerequisite — Proof by contradiction: if assuming ¬P leads to a contradiction (a statement and its negation both hold), then P holds.
  • quantifier_negation · prerequisite — Negating quantifiers: ¬(∀x, P(x)) is equivalent to ∃x, ¬P(x), and ¬(∃x, P(x)) is equivalent to ∀x, ¬P(x).
  • mko_set_ops · cited — For sets A and B in one domain, the union contains elements belonging to at least one set, the intersection contains elements belonging to both, and A∖B contains elements belonging to A but not B. A complement must be relative to an explicit universe U and is written U∖A. · mko-set-operations
  • finite_set_listing · prerequisite — Listed sets: x belongs to a finite set given by a list exactly when x equals one of the listed objects; the order and repetitions of the list do not change the set, for example {4,4,6}={4,6}.
  • L_ops_in_U · lemma — If A⊆U and B⊆U, then A∪B, A∩B, A∖B and B∖A are subsets of U.
  • L_de_morgan_set · lemma — For any sets U, A, B: U∖(A∪B)=(U∖A)∩(U∖B).
  • L_union_split · lemma — For any sets A, B: A∪B=A∪(B∖A), and A∩(B∖A)=∅.

Main derivation

S01 · definition

Before

\text{a universe and two sets}

After

U=\{1,2,3,4,5,6,7,8\},\ A=\{2,4,6,8\},\ B=\{3,4,5,6\}

Conditions: none

Rule: def_intro · Uses: G1, G2

Leaf basis: def_intro + finite_set_listing

State the universe U first, then A and B. By the MKO, a complement must be relative to an explicit universe, so the universe is fixed before any complement is computed. The sets are given by lists, so by finite_set_listing, x∈A means exactly that x is one of 2, 4, 6, 8.

S02 · implies

Before

A=\{2,4,6,8\},\ B=\{3,4,5,6\},\ U=\{1,2,3,4,5,6,7,8\}

After

A\subseteq U,\ B\subseteq U

Conditions: none

Rule: subset_def · Uses: S01

Leaf basis: subset_def + finite_set_listing + forall_intro

The elements of A are exactly 2, 4, 6, 8, and each appears in the list of U; the elements 3, 4, 5, 6 of B are also in U. Since A and B are finite lists, checking all their listed elements is a complete check of 'every element', so by the subset definition A⊆U and B⊆U, as assumption a1 requires: A and B lie in one universe.

S03 · implies

Before

A\subseteq U,\ B\subseteq U

After

A\cup B,\ A\cap B,\ A\setminus B,\ B\setminus A\subseteq U

Conditions: A\subseteq U; B\subseteq U

Rule: L_ops_in_U · Uses: S02

Leaf basis: set_operations_def + subset_def + case_analysis

By Lemma L_ops_in_U (proved in S03.1 and S03.2), all four resulting sets are subsets of U. So no object outside U belongs to them, and to list them it suffices to test the eight elements of U one by one.

S04 · implies

Before

x\in U

After

1{:}(F,F),\ 2{:}(T,F),\ 3{:}(F,T),\ 4{:}(T,T),\ 5{:}(F,T),\ 6{:}(T,T),\ 7{:}(F,F),\ 8{:}(T,F)

Conditions: none

Rule: finite_set_listing · Uses: S01, S03

Leaf basis: finite_set_listing + numeric_evaluation

For each element of U record a pair of truth values (x∈A, x∈B): for example 2 is in the list of A and not in that of B, recorded as (T,F); 4 is in both, (T,T); 1 is in neither, (F,F). The eight rows cover all of U, and by S03 every operation below only needs this table.

S05 · equivalent

Before

A\cup B

After

\{2,3,4,5,6,8\}

Conditions: none

Rule: set_operations_def · Uses: S03, S04

Leaf basis: set_operations_def + set_extensionality + finite_set_listing

x∈A∪B ⇔ x∈A or x∈B. The rows with at least one T are 2, 3, 4, 5, 6, 8, so A∪B={2,3,4,5,6,8}. 4 and 6 belong to both sets but each counts as one element of the union.

S06 · equivalent

Before

A\cap B

After

\{4,6\}

Conditions: none

Rule: set_operations_def · Uses: S03, S04

Leaf basis: set_operations_def + set_extensionality + finite_set_listing

x∈A∩B ⇔ x∈A and x∈B. The only rows with T in both places are 4 and 6, so A∩B={4,6}. Compare with S05: 2 is in A∪B but not in A∩B, so 'or' and 'and' give different sets.

S07 · equivalent

Before

A\setminus B

After

\{2,8\}

Conditions: none

Rule: set_operations_def · Uses: S03, S04

Leaf basis: set_operations_def + set_extensionality + finite_set_listing

x∈A∖B ⇔ x∈A and x∉B, that is the rows (T,F): 2 and 8. So A∖B={2,8}.

S08 · equivalent

Before

B\setminus A

After

\{3,5\}

Conditions: none

Rule: set_operations_def · Uses: S03, S04

Leaf basis: set_operations_def + set_extensionality + finite_set_listing

x∈B∖A ⇔ x∈B and x∉A, that is the rows (F,T): 3 and 5. So B∖A={3,5}. The rows read here have F first and T second, the opposite direction to S07.

S09 · implies

Before

A\setminus B=\{2,8\},\ B\setminus A=\{3,5\}

After

A\setminus B\neq B\setminus A

Conditions: none

Rule: set_extensionality · Uses: S07, S08

Leaf basis: set_extensionality + finite_set_listing

2∈A∖B but 2∉B∖A, so the sets have different elements and by the criterion for equality A∖B≠B∖A. In this example they have no common element at all. Set difference has a direction.

S10 · equivalent

Before

U\setminus A,\ U\setminus B

After

U\setminus A=\{1,3,5,7\},\ U\setminus B=\{1,2,7,8\}

Conditions: U\ \text{explicit}

Rule: mko_set_ops · Uses: S01, S04

Leaf basis: set_operations_def + set_extensionality + finite_set_listing + finite_counting_basics

By the MKO, the complement of A is U∖A, relative to the explicit universe U. x∈U∖A ⇔ x∈U and x∉A: the rows with F in the first place are 1, 3, 5, 7. Likewise U∖B consists of the rows with F in the second place, 1, 2, 7, 8. Count check: U is the disjoint union of A and U∖A, so |U∖A|=8−4=4.

S11 · implies

Before

U'\setminus A

After

U'\setminus A=\{1,3,5,7,9,10\}\neq U\setminus A

Conditions: A\subseteq U'

Rule: set_extensionality · Uses: G3, S01, S10

Leaf basis: set_operations_def + set_extensionality + finite_set_listing

Switch to the universe U′: A⊆U′ still holds, and x∈U′∖A ⇔ x∈U′ and x∉A, giving U′∖A={1,3,5,7,9,10}, with 10−4=6 elements. 9 belongs to U′∖A but not to U∖A (9∉U), so the two 'complements' differ. The list of A did not change, only the universe did; writing 'the complement of A' without a universe has no determinate answer.

S12 · equivalent

Before

U\setminus(A\cup B)

After

(U\setminus A)\cap(U\setminus B)

Conditions: none

Rule: L_de_morgan_set · Uses: set_operations_def

Leaf basis: set_operations_def + de_morgan_logic + and_intro_elim + set_extensionality

By Lemma L_de_morgan_set (proved for arbitrary sets in S12.1 to S12.3), the two are the same set. This is a general argument and does not depend on the numbers of this example.

S13 · implies

Before

U\setminus\{2,3,4,5,6,8\},\quad \{1,3,5,7\}\cap\{1,2,7,8\}

After

\{1,7\}=\{1,7\}

Conditions: none

Rule: set_operations_def · Uses: S05, S10, S12

Leaf basis: set_operations_def + finite_set_listing + numeric_evaluation

Check the lemma on this example: by S05, U∖(A∪B) consists of the elements of U not in {2,3,4,5,6,8}, namely {1,7}; by S10, (U∖A)∩(U∖B) consists of the common elements of {1,3,5,7} and {1,2,7,8}, also {1,7}. The two agree, consistent with S12.

S14 · equivalent

Before

A\cup B

After

A\cup(B\setminus A)\ \text{with}\ A\cap(B\setminus A)=\varnothing

Conditions: none

Rule: L_union_split · Uses: S05, S08

Leaf basis: set_operations_def + case_analysis + set_extensionality + contradiction

By Lemma L_union_split (proved in S14.1 and S14.2), A∪B splits into the two disjoint parts A and B∖A. In this example {2,4,6,8}∪{3,5}={2,3,4,5,6,8}, in agreement with S05.

S15 · implies

Before

|A\cup B|=|A\cup(B\setminus A)|

After

|A\cup B|=|A|+|B\setminus A|=4+2=6

Conditions: A\cap(B\setminus A)=\varnothing

Rule: finite_counting_basics · Uses: S08, S14

Leaf basis: finite_counting_basics + numeric_evaluation

A and B∖A are disjoint (S14), so finite counting gives |A∪(B∖A)|=|A|+|B∖A|=4+2=6. Taking |A|+|B|=8 as the size of the union would count 4 and 6 twice; the difference 8−6=2 is exactly |A∩B|.

S16 · implies

Before

\text{membership table of }U

After

A\cup B=\{2,3,4,5,6,8\},\ A\cap B=\{4,6\},\ A\setminus B=\{2,8\},\ B\setminus A=\{3,5\},\ U\setminus A=\{1,3,5,7\},\ U\setminus B=\{1,2,7,8\}

Conditions: none

Rule: and_intro_elim · Uses: S05, S06, S07, S08, S09, S10, S11, S13, S15

Leaf basis: and_intro_elim

Collect the results of S05 to S15: the six results are as shown; A∖B≠B∖A; U′∖A≠U∖A; De Morgan's law holds in this example; |A∪B|=6.

Substeps and lemmas

S03.1 · implies

Before

x\in A\cup B

After

x\in U

Conditions: A\subseteq U; B\subseteq U

Rule: case_analysis · Uses: set_operations_def, subset_def

Leaf basis: set_operations_def + case_analysis + subset_def + forall_elim

Let x∈A∪B; by the definition of union, x∈A or x∈B. Case 1, x∈A: A⊆U gives x∈U. Case 2, x∈B: B⊆U gives x∈U. Both cases give x∈U, so A∪B⊆U.

S03.2 · implies

Before

x\in A\cap B\ \lor\ x\in A\setminus B\ \lor\ x\in B\setminus A

After

x\in U

Conditions: A\subseteq U; B\subseteq U

Rule: and_intro_elim · Uses: set_operations_def, subset_def

Leaf basis: set_operations_def + and_intro_elim + subset_def + forall_elim

Both x∈A∩B and x∈A∖B contain the conjunct x∈A; extracting it and using A⊆U gives x∈U. x∈B∖A contains x∈B, and B⊆U gives x∈U. S03.1 and S03.2 together prove Lemma L_ops_in_U.

S12.1 · equivalent

Before

x\in U\setminus(A\cup B)

After

x\in U\land\neg(x\in A\lor x\in B)

Conditions: none

Rule: set_operations_def · Uses: set_operations_def

Leaf basis: set_operations_def + def_unfold

By the definition of difference, x∈U∖(A∪B) ⇔ x∈U and x∉A∪B; by the definition of union, x∉A∪B is ¬(x∈A or x∈B).

S12.2 · equivalent

Before

x\in U\land\neg(x\in A\lor x\in B)

After

x\in U\land x\notin A\land x\notin B

Conditions: none

Rule: de_morgan_logic · Uses: S12.1, de_morgan_logic

Leaf basis: de_morgan_logic

By De Morgan's law for logic, ¬(P∨Q) ⇔ ¬P∧¬Q, with P the statement x∈A and Q the statement x∈B. Negation turns 'or' into 'and'.

S12.3 · equivalent

Before

x\in U\land x\notin A\land x\notin B

After

x\in(U\setminus A)\cap(U\setminus B)

Conditions: none

Rule: and_intro_elim · Uses: S12.2, set_operations_def

Leaf basis: and_intro_elim + set_operations_def + forall_intro + set_extensionality

Duplicate x∈U (P ⇔ P∧P) and regroup the conjunction: (x∈U and x∉A) and (x∈U and x∉B), that is x∈U∖A and x∈U∖B, which is x∈(U∖A)∩(U∖B). Since x was arbitrary, set equality applies, and S12.1 to S12.3 together prove Lemma L_de_morgan_set.

S14.1 · equivalent

Before

x\in A\lor(x\in B\land x\notin A)

After

x\in A\lor x\in B

Conditions: none

Rule: case_analysis · Uses: set_operations_def

Leaf basis: case_analysis + set_operations_def + set_extensionality

The left side unfolds x∈A∪(B∖A). Split on x∈A: if x∈A, both sides hold; if x∉A, the left side reduces to x∈B∧x∉A, that is x∈B, and the right side also reduces to x∈B. In both cases the two sides agree, so A∪(B∖A)=A∪B.

S14.2 · implies

Before

x\in A\cap(B\setminus A)

After

A\cap(B\setminus A)=\varnothing

Conditions: none

Rule: contradiction · Uses: set_operations_def

Leaf basis: set_operations_def + contradiction + quantifier_negation

If x∈A∩(B∖A), then x∈A and x∈B and x∉A, a contradiction. So there is no such x, and A∩(B∖A)=∅. S14.1 and S14.2 together prove Lemma L_union_split.

Reverse audits

  • S16 · sufficient_goal_reduction · S05, S06, S07, S08, S09, S10, S11, S13, S15, and_intro_elim — Goal G is the conjunction of the problem's conclusions; each conjunct is obtained forwards from the givens by the listed steps, and this step only forms the conjunction; G is never used as a premise.
  • S15 · premise_audit · S14, finite_counting_basics — The addition rule applies only to disjoint sets, so S14.2's A∩(B∖A)=∅ is needed first; adding the sizes of A and B directly is not allowed, because A∩B≠∅.
  • S14.2 · premise_audit · set_operations_def, contradiction — Only the two unfoldings and the contradiction are needed; it is not claimed that A∩B=∅ (here A∩B={4,6}).
  • S14.1 · inverse_equivalence · case_analysis, set_operations_def — In each case the two sides are equivalent, and the cases are exhaustive, so the equivalence holds both ways.
  • S14 · inverse_equivalence · L_union_split — The lemma gives an equality of sets, so the step holds both ways; disjointness is given separately by S14.2.
  • S13 · premise_audit · S05, S10, S12, set_operations_def — This is a check on one example and can be recomputed independently; it does not replace the general proof in S12, and one example could not prove De Morgan's law.
  • S12.3 · inverse_equivalence · and_intro_elim, set_operations_def, set_extensionality — Regrouping and duplicating conjuncts are two-way; for each x both sides are true or false together, so the sets are equal.
  • S12.2 · inverse_equivalence · de_morgan_logic — De Morgan's law is itself an equivalence, so the step holds both ways.
  • S12.1 · inverse_equivalence · set_operations_def — Both unfoldings of definitions are two-way.
  • S12 · inverse_equivalence · L_de_morgan_set — The lemma proves an equality of sets, obtained from an element-wise two-way equivalence.
  • S11 · premise_audit · G3, set_operations_def, set_extensionality — U′ must be explicit; the single witness 9 is enough to refute equality of the two complements.
  • S10 · inverse_equivalence · mko_set_ops, set_operations_def, set_extensionality — U∖A is decided element by element by its membership condition, compared both ways; no object outside U belongs to U∖A.
  • S09 · premise_audit · S07, S08, set_extensionality — One element in only one of the sets is enough to refute equality. It is not claimed that A∖B and B∖A differ for all sets: when A=B both are ∅.
  • S08 · inverse_equivalence · set_operations_def, set_extensionality, S03 — As in S05, membership is compared element by element in both directions.
  • S07 · inverse_equivalence · set_operations_def, set_extensionality, S03 — As in S05, membership is compared element by element in both directions.
  • S06 · inverse_equivalence · set_operations_def, set_extensionality, S03 — As in S05, membership is compared element by element in both directions.
  • S05 · inverse_equivalence · set_operations_def, set_extensionality, S03 — Both sides decide membership the same way for every object: row by row in U, and outside U neither contains it (S03); by set equality the step holds both ways.
  • S04 · premise_audit · finite_set_listing, S03 — Each row can be rechecked against the lists; the table covers all of U, so no element is missed.
  • S03.2 · premise_audit · set_operations_def, and_intro_elim, subset_def — It only extracts one conjunct; no converse is claimed (elements of U need not lie in these sets).
  • S03.1 · premise_audit · set_operations_def, subset_def, case_analysis — The two cases cover every possibility of the 'or'; each case uses one of the inclusion hypotheses.
  • S03 · premise_audit · S02, L_ops_in_U — It needs A⊆U and B⊆U (S02); if A had an element outside U, testing only U would miss elements of the union.
  • S02 · premise_audit · subset_def, finite_set_listing — This is a complete enumeration, not a sample: every element of A and of B is checked. The converse U⊆A is not claimed (1∈U but 1∉A).
  • S01 · premise_audit · G1, G2, def_intro, finite_set_listing — This step only records the data and derives no new fact; the universe is explicit, as assumption a2 requires.

Error controls and negative controls

Swapping union and intersection

The MKO names the mistake of swapping union and intersection. Union corresponds to 'or' (in at least one set), intersection to 'and' (in both). Here 2∈A∪B but 2∉A∩B; the union has 6 elements and the intersection only 2. To catch the error, go back to the membership table and check whether the rule reads 'at least one T' or 'both T'.

Difference has a direction

The MKO warns that A∖B and B∖A usually differ. Here A∖B={2,8} while B∖A={3,5} (S07 to S09), and they are even disjoint. They are equal only in special cases (for example A=B, when both are ∅).

A complement needs a universe first

The MKO warns against listing a complement without a specified universe. The same A={2,4,6,8} has complement {1,3,5,7} in U but {1,3,5,7,9,10} in U′ (S10, S11). So one must write U∖A and list U first.

  • A∖B=B∖A → reject — 2∈A∖B but 2∉B∖A (S09).
  • A∩B={2,3,4,5,6,8} → reject — That is the union; 2∉B, so 2∉A∩B, and the correct answer is {4,6}.
  • A∪B has |A|+|B|=8 elements → reject — 4 and 6 belong to both sets but count once; |A∪B|=6 (S15).
  • Without naming a universe, the complement of A={2,4,6,8} is {1,3,5,7} → reject — In U′ the complement is {1,3,5,7,9,10} (S11); the complement depends on the universe.
  • U∖(A∪B)=(U∖A)∪(U∖B) → reject — The right side is {1,2,3,5,7,8} and the left side is {1,7}; the correct De Morgan law has an intersection on the right (S12).

Result and limitations

In the universe U={1,2,3,4,5,6,7,8}: A∪B={2,3,4,5,6,8}, A∩B={4,6}, A∖B={2,8}, B∖A={3,5}, U∖A={1,3,5,7}, U∖B={1,2,7,8}. A∖B≠B∖A; with the universe U′ the complement of A becomes {1,3,5,7,9,10}; U∖(A∪B)=(U∖A)∩(U∖B) holds for all sets, and both sides are {1,7} here; |A∪B|=|A|+|B∖A|=6.

  • The count checks in S10 and S11 use that U is the disjoint union of A and U∖A when A⊆U; this follows by the same argument as S14, and no separate lemma is stated here.

Verification and source binding

8 declared checks for this guide; only the listed expressions are covered.

  • source commit: b28a5edbd46279b1db2a3f3f48bb3f447e18899f
  • adopted source SHA-256: c42753a14041612b07055d8ace7c5c9df4c243cd4ab72e79efd18921fc2f0b46
  • original source SHA-256: c42753a14041612b07055d8ace7c5c9df4c243cd4ab72e79efd18921fc2f0b46
  • Lean: NOT_RUN · independent AI: NOT_MEASURED

Same-source full JSON (formulas, ASTs, controls and revision log)