Basic operations of Zermelo–Fraenkel set theory

We first import propositional logic and first-order logic.  import (CLASSICAL Interface:Classical_propositional_calculus ) import (FIRSTORDER Interface:First-order_logic_with_quantifiability (CLASSICAL) ) 

We also import Interface:First steps in set theory, which defines operations for singletons, unordered pairs, and the like, but contains few theorems expanding on those concepts.  import (BASIC Interface:First_steps_in_set_theory (CLASSICAL FIRSTORDER) ) 

As usual, capital letters starting from  are set expressions (that is, objects or "classes") and lowercase letters starting with   are set variables.  var (object A B C D A0 A1 B0 B1 Z) var (variable a b x y z w a′ b′ x′ y′ z′) var (formula φ ψ φx φy antecedent) 

A set is an element of its singleton
Here we show.  thm (SingletonMembership  (A ∈ (singleton A)) ( A EqualityReflexivity

A A Singleton eliminateBiconditionalForward

applyModusPonens )) 

An unordered pair contains its first member
Here we show that.  thm (UnorderedPairLeftMembership  (A ∈ (unorderedPair A B)) ( A EqualityReflexivity (A = B) introduceRightDisjunction

A A B UnorderedPair eliminateBiconditionalForward

applyModusPonens )) 

A similar result holds, of course, for the second member.

 thm (UnorderedPairRightMembership  (B ∈ (unorderedPair A B)) ( B EqualityReflexivity (B = A) introduceLeftDisjunction

B A B UnorderedPair eliminateBiconditionalForward

applyModusPonens )) 

Unordered pair commutativity
Unordered pairs are unordered:.  thm (UnorderedPairCommutativity ((x A) (x B)) ((unorderedPair A B) = (unorderedPair B A)) ( (value x) A B UnorderedPair

((value x) = A) ((value x) = B) DisjunctionCommutativity applyBiconditionalTransitivity

(value x) B A UnorderedPair swapBiconditional applyBiconditionalTransitivity

applyExtensionality )) 

Unordered pair equality can imply equality of members
Here we prove.

First we prove a lemma,  thm (UnorderedPairFirstMembersEqual-1  (((unorderedPair A C) = (unorderedPair B C)) → ((A = B) ∨ (A = C))) ( A C UnorderedPairLeftMembership

(unorderedPair A C) (unorderedPair B C) A MembershipBuilderLL

detachImplicationBiconditional  That gives us.  A B C UnorderedPair eliminateBiconditionalReverse applySyllogism ))

thm (UnorderedPairFirstMembersEqual  (((unorderedPair A C) = (unorderedPair B C)) → (A = B)) ( </jh> We apply our lemma once to get  A C B UnorderedPairFirstMembersEqual-1

</jh> Applying the lemma a second time, with some commutations, gives us  (unorderedPair A C) (unorderedPair B C) EqualitySymmetry eliminateBiconditionalReverse B C A UnorderedPairFirstMembersEqual-1 applySyllogism

B A EqualitySymmetry transformImplicationDisjunctionLeft </jh> We now combine the two results to get, and apply distributivity to the right hand side to turn it into.  composeConjunction (A = B) (A = C) (B = C) DisjunctionLeftDistribution eliminateBiconditionalForward applySyllogism </jh> We turn  into , and after a bit more rearrangement, we are done.  B C EqualitySymmetry eliminateBiconditionalReverse (A = C) conjoinLL A C B EqualityTransitivity applySyllogism

(A = B) disjoinLL applySyllogism

(A = B) DisjunctionIdempotence eliminateBiconditionalForward applySyllogism )) </jh>

Here is a commuted version:.  thm (UnorderedPairSecondMembersEqual  (((unorderedPair C A) = (unorderedPair C B)) → (A = B)) ( C A UnorderedPairCommutativity C B UnorderedPairCommutativity buildEquality eliminateBiconditionalReverse

A C B UnorderedPairFirstMembersEqual applySyllogism )) </jh>

A singleton as an unordered pair
A singleton is equal to an unordered pair where the two elements are the same. That is,.  thm (SingletonUnorderedPair ( (x A))  ((singleton A) = (unorderedPair A A)) ( (value x) A Singleton

((value x) = A) DisjunctionIdempotence applyBiconditionalTransitivity

(value x) A A UnorderedPair swapBiconditional applyBiconditionalTransitivity

applyExtensionality )) </jh>

Builder
Here we provide a builder for separation.

 thm (SeparationBuilder ((x A) (x B) (y x) (y A) (y φ) (y B) (y ψ))   (((A = B) ∧ (∀ x (φ ↔ ψ))) → ((separate x A φ) = (separate x B ψ))) ( </jh> To apply extensionality, we want. The first step in that direction will be.  (A = B) (∀ x (φ ↔ ψ)) ConjunctionRightElimination A B (value y) MembershipBuilderLL applySyllogism </jh> Next is  (A = B) (∀ x (φ ↔ ψ)) ConjunctionLeftElimination x φ ψ (value y) SubstBuilder applySyllogism </jh> Combining those gives, and it is only necessary to apply   to both sides.  buildConjunctionInConsequent

(value y) x A φ Separation (value y) x B ψ Separation buildBiconditional eliminateBiconditionalForward applySyllogism

y addForAllToConsequent y (separate x A φ) (separate x B ψ) Extensionality applySyllogism )) </jh>

A rule
Here's a rule form for one case of the above separation builder: from  we can deduce.  thm (buildSeparation ((x A)) ((H (φ ↔ ψ))) ((separate x A φ) = (separate x A ψ)) ( H       x generalize

A EqualityReflexivity A A x φ ψ SeparationBuilder detach1of2

applyModusPonens )) </jh>

A formula which defines a set
Although, in general, we cannot specify a set by a formula ("the set of all x for which φ holds") and expect it to exist, such a definition does specify a set in the case in which the formula φ implies that x is part of some set which is known to exist. There might be a few ways to formalize this notion; the one here is particularly aimed at helping us make a definition of the form  and then prove a statement about membership in that defined set. In symbols, given  we conclude.  thm (FormulaBoundLemma ((z A) (z B)) ((H (φ → ((value z) ∈ A)))) (((B ∈ A) ∧ (subst B z φ)) ↔ (subst B z φ)) ( </jh> The forward direction is trivial.  (B ∈ A) (subst B z φ) ConjunctionLeftElimination </jh> To prove the reverse direction we start by adding a substitution to our hypothesis to get.  H       B z addSubst </jh> Now we perform the latter subsitution, starting with, and then combining with the previous step to get.  (value z) B A MembershipBuilderRR makeSubstExplicit eliminateBiconditionalReverse applySyllogism </jh> We now just need to add  and combine the two directions. <jh> (subst B z φ) ImplicationReflexivity composeConjunction

introduceBiconditionalFromImplications ))

thm (FormulaBound ((z A) (z B)) ((H (φ → ((value z) ∈ A)))) ((B ∈ (separate z A φ)) ↔ (subst B z φ)) ( B z A φ Separation H       B FormulaBoundLemma applyBiconditionalTransitivity )) </jh>

Change variable
As with a quantifier, we can make an equivalent formula by changing the variable which is bound by  and making an according change to that variable in the formula inside. That is, given, we can conclude.

We first prove  as a lemma. <jh> thm (ChangeVariableSeparation-1 ((y φx) (x φy) (x y A) (C x) (C y)) ((H (((value x) = (value y)) → (φx ↔ φy))))  ((C ∈ (separate x A φx)) ↔ (C ∈ (separate y A φy))) ( </jh> We start by rewriting  as. <jh> C x A φx Separation </jh> But  is equivalent to. <jh> H       C ChangeVariableSubstitution

(C ∈ A) buildConjunctionLL

applyBiconditionalTransitivity </jh> That gives us, which is equivalent to. <jh> C y A φy Separation swapBiconditional applyBiconditionalTransitivity ))

thm (ChangeVariableSeparation ((y φx) (x φy) (x y A)  (z y) (z x) (z A) (z φx) (z φy))  ((H (((value x) = (value y)) → (φx ↔ φy))))  ((separate x A φx) = (separate y A φy)) ( H       (value z) A ChangeVariableSeparation-1 applyExtensionality )) </jh>

Unions
The union of two sets is just a special case of the union of a set:  is defined to be. <jh> def ((∪ A B) (⋃ (unorderedPair A B))) </jh>

A lemma involving substitution
Here we prove. This only holds because of the Interface:Axiom of quantifiability; a treatment of set theory which does not have that axiom (for example, because it allows proper classes) will handle things differently. <jh> thm (IsElementThereExists ((x A) (x B))  ((A ∈ B) ↔ (∃ x ((A ∈ (value x)) ∧ ((value x) = B)))) ( </jh> We start with the forward direction. First we prove. <jh> (A ∈ B) ImplicationReflexivity x B Quantifiability introduceLeftConjunctToConsequent

x ((value x) = B) (A ∈ B) ThereExistsConjunctionRightMovement eliminateBiconditionalForward applySyllogism </jh> Next is the substitution, which we then rearrange to. <jh> (value x) B A MembershipBuilderLL eliminateBiconditionalForwardInConsequent import </jh> Combining this with  we get , and adding in the quantifier we finish the forward direction. <jh> ((value x) = B) (A ∈ B) ConjunctionRightElimination composeConjunction

x addThereExists applySyllogism </jh> The reverse direction is just a substitution. We start with  and rearrange it to. <jh> (value x) B A MembershipBuilderLL eliminateBiconditionalReverseInConsequent applyComm import </jh> Adding in the quantifier finishes the reverse direction, and we combine the two directions. <jh> x addThereExists removeThereExistsInConsequent

introduceBiconditionalFromImplications )) </jh>

Membership in a union related to membership in one of the two sets
The next theorem,, is another way of stating what the union of two sets means. <jh> thm (BinaryUnion ( (x A) (x B) (x C)) ((A ∈ (B ∪ C)) ↔ ((A ∈ B) ∨ (A ∈ C))) ( </jh> We apply the definition of the union of two sets, and the  theorem to get <jh> A (unorderedPair B C) x Union </jh> Expanding the unordered pair turns that into. <jh> (value x) B C UnorderedPair (A ∈ (value x)) buildConjunctionLL x buildThereExists applyBiconditionalTransitivity </jh> Distributivity gives us  and splitting the quantifier turns that into. <jh> (A ∈ (value x)) ((value x) = B) ((value x) = C) ConjunctionLeftDistribution x buildThereExists applyBiconditionalTransitivity

x         ((A ∈ (value x)) ∧ ((value x) = B)) ((A ∈ (value x)) ∧ ((value x) = C)) ThereExistsDisjunction applyBiconditionalTransitivity </jh> Now we can apply the lemma from the previous section to get. <jh> A B x IsElementThereExists

A C x IsElementThereExists

buildDisjunction swapBiconditional applyBiconditionalTransitivity )) </jh>

An easy corollary is that membership in one of the two sets of a union implies membership in the union. <jh> thm (MembershipUnionRightIntroduction   ((A ∈ B) → (A ∈ (B ∪ C))) ( (A ∈ B) (A ∈ C) DisjunctionRightIntroduction

A B C BinaryUnion eliminateBiconditionalForward applySyllogism ))

thm (MembershipUnionLeftIntroduction  ((A ∈ C) → (A ∈ (B ∪ C))) ( (A ∈ C) (A ∈ B) DisjunctionLeftIntroduction

A B C BinaryUnion eliminateBiconditionalForward applySyllogism )) </jh>

Unordered pair as the union of two singletons
An unordered pair equals the union of singletons for each of its elements. That is,. <jh> thm (UnorderedPairSingleton ( (x A) (x B))  ((unorderedPair A B) = ((singleton A) ∪ (singleton B))) ( </jh> The proof starts with. <jh> (value x) A B UnorderedPair </jh> The right hand side is equivalent to , <jh> (value x) A Singleton (value x) B Singleton buildDisjunction swapBiconditional applyBiconditionalTransitivity </jh> which is equivalent to. <jh> (value x) (singleton A) (singleton B) BinaryUnion swapBiconditional applyBiconditionalTransitivity

applyExtensionality )) </jh>

Union builder
Equals can be substituted for equals, in the context of the union of a set. <jh> thm (UnionBuilder ( (x A) (x B) (y x) (y A) (y B))  ((A = B) → ((⋃ A) = (⋃ B))) ( </jh> We need, or expanding the unions according to  ,. The first step is, followed by applying builders for the conjunction and the quantifier. <jh> A B (value y) MembershipBuilderLL ((value x) ∈ (value y)) buildConjunctionLLInConsequent y buildThereExistsInConsequent

(value x) A y Union (value x) B y Union buildBiconditional eliminateBiconditionalForward applySyllogism

x addForAllToConsequent x (⋃ A) (⋃ B) Extensionality applySyllogism ))

thm (buildUnion ((H (A = B)))  ((⋃ A) = (⋃ B)) ( H       A B UnionBuilder applyModusPonens )) </jh>

Union idempotence
The binary union operation is idempotent:. <jh> thm (UnionIdempotence ( (x A)) ((A ∪ A) = A) ( (value x) A A BinaryUnion

((value x) ∈ A) DisjunctionIdempotence swapBiconditional applyBiconditionalTransitivity

applyExtensionality )) </jh>

Union of a singleton
We don't directly have a notation for the (unique) set for which a formula holds. However, we have the machinery to define it. First we form the set of all x for which the formula holds, which will be a singleton. Then we can apply the next theorem, which is.

The proof is. <jh> thm (UnionSingleton  ((⋃ (singleton A)) = A) ( A SingletonUnorderedPair buildUnion

A UnionIdempotence applyEqualityTransitivity )) </jh>

Singleton and subset
Here we prove.

<jh> thm (SingletonSubset ( (x A) (x B))  ((A ∈ B) ↔ ((singleton A) ⊆ B)) ( </jh> We start from the  side, first expanding it to. <jh> (singleton A) B x Subset </jh> Then we transform the  into <jh> (value x) A Singleton ((value x) ∈ B) buildImplicationConsequent x buildForAll applyBiconditionalTransitivity </jh> That gives us, which is equivalent to   via the substitution. <jh> (value x) A B MembershipBuilderRR ImplicitForAll applyBiconditionalTransitivity

swapBiconditional )) </jh>

Subset and membership
If one set is a subset of another, then being an element of the subset implies being an element of the containing set. That is,. This resembles, but it is not biconditional because it does not make a statement about all potential elements, but just about one particular one. <jh> thm (SubsetMembership ( (x A) (x B) (x C))  ((A ⊆ B) → ((C ∈ A) → (C ∈ B))) ( </jh> First we expand  to. <jh> A B x Subset eliminateBiconditionalReverse </jh> Then we conjoin  to both sides of the implication to get <jh> ((value x) ∈ A) ((value x) ∈ B) ((value x) = C) ConjunctionMultiplicationLL x addForAll applySyllogism </jh> Next we distribute the quantifier across the implication to get. <jh> x         (((value x) = C) ∧ ((value x) ∈ A)) (((value x) = C) ∧ ((value x) ∈ B)) ForAllImplicationThereExists applySyllogism </jh> But the two halves of that are equivalent to  and , respectively, thanks to. <jh> C A x MembershipThereExists C B x MembershipThereExists buildImplication eliminateBiconditionalForward applySyllogism )) </jh>

Elements and subsets of unions
The first theorem in this section is. To sketch out the proof, we first expand the subsets and union so that the antecedent reads, and the consequent would follow from. So we need a choice for  in the consequent, and it turns out that   does the trick (with that substitution made, there is only minor rearrangment to derive the consequent from the antecedent). <jh> thm (SubsetUnion ( (x B) (x C) (x A) (y x) (y B) (y C))  (((A ⊆ B) ∧ (B ∈ C)) → (A ⊆ (⋃ C))) ( A B x Subset (B ∈ C) buildConjunctionRR eliminateBiconditionalReverse </jh> So far we have. Now we move  inside the quantifier. <jh> (B ∈ C) x Generalization (∀ x (((value x) ∈ A) → ((value x) ∈ B))) conjoinLL applySyllogism

x (((value x) ∈ A) → ((value x) ∈ B)) (B ∈ C) ForAllConjunction eliminateBiconditionalForward applySyllogism </jh> That gives us. Since  holds irrespective of , we can also make the weaker statement that it holds assuming. In other words, we can rewrite our formula to. <jh> (B ∈ C) ((value x) ∈ A) AntecedentIntroduction (((value x) ∈ A) → ((value x) ∈ B)) conjoinLL x addForAll applySyllogism

((value x) ∈ A) ((value x) ∈ B) (B ∈ C) ConjunctionComposition eliminateBiconditionalReverse x addForAll applySyllogism </jh> Now we turn  into first   and then. <jh> (value y) B (value x) MembershipBuilderLL (value y) B C MembershipBuilderRR buildConjunctionInConsequent

makeSubstExplicit eliminateBiconditionalForward

B y (((value x) ∈ (value y)) ∧ ((value y) ∈ C)) ThereExistsIntroductionFromObject applySyllogism

((value x) ∈ A) addCommonAntecedent x addForAll applySyllogism </jh> That gives us, which we first turn into  , <jh> (value x) C y Union eliminateBiconditionalForward ((value x) ∈ A) addCommonAntecedent x addForAll applySyllogism </jh> and then. <jh> A (⋃ C) x Subset eliminateBiconditionalForward applySyllogism )) </jh>

An easy corollary is. <jh> thm (MembershipSubsetUnion  ((A ∈ B) → (A ⊆ (⋃ B))) ( A SubsetReflexivity A A B SubsetUnion detach1of2 )) </jh>

Binary union and subset
The left side of a union is a subset of the union. <jh> thm (SubsetUnionLeft ( (x A) (x B))  (A ⊆ (A ∪ B)) ( ((value x) ∈ A) ((value x) ∈ B) DisjunctionRightIntroduction

(value x) A B BinaryUnion eliminateBiconditionalForward applySyllogism

x generalize

A (A ∪ B) x Subset eliminateBiconditionalForward applyModusPonens )) </jh>

Being a subset of a set implies being a subset of the union of set and any other. <jh> thm (SubsetUnionRightIntroduction   ((A ⊆ B) → (A ⊆ (B ∪ C))) ( B C SubsetUnionLeft A B (B ∪ C) SubsetTransitivity detach2of2 )) </jh>

Unordered pair and subset
Analogous to the result we already proved which relates a singleton being a subset to the singleton's element being an element, here is a similar result for unordered pairs:. <jh> thm (UnorderedPairSubsetForward ( (x A) (x B) (x C))  (((A ∈ C) ∧ (B ∈ C)) → ((unorderedPair A B) ⊆ C)) ( </jh> We begin with  and likewise for <jh> (value x) A C MembershipBuilderRR eliminateBiconditionalForwardInConsequent applyComm

(value x) B C MembershipBuilderRR eliminateBiconditionalForwardInConsequent applyComm </jh> We combine the two implications with conjunctions to get, but the consequent of that simplifies to. <jh> conjoin

((value x) = A)         ((value x) ∈ C)          ((value x) = B)          DisjunctionComposition eliminateBiconditionalReverse applySyllogism </jh> Now we transform  into. <jh> (value x) A B UnorderedPair swapBiconditional transformImplicationImplicationAntecedent </jh> That gives. But the consequent simplifies to just. <jh> x addForAllToConsequent

(unorderedPair A B) C x Subset eliminateBiconditionalForward applySyllogism ))

thm (UnorderedPairSubsetReverse ( (x A) (x B) (x C))  (((unorderedPair A B) ⊆ C) → ((A ∈ C) ∧ (B ∈ C))) ( A B UnorderedPairLeftMembership (unorderedPair A B) C A SubsetMembership applyComm applyModusPonens

B A UnorderedPairRightMembership (unorderedPair A B) C B SubsetMembership applyComm applyModusPonens

composeConjunction ))

thm (UnorderedPairSubset   (((A ∈ C) ∧ (B ∈ C)) ↔ ((unorderedPair A B) ⊆ C)) ( A C B UnorderedPairSubsetForward A B C UnorderedPairSubsetReverse introduceBiconditionalFromImplications )) </jh>

Export
We export to Interface:Basic operations of Zermelo–Fraenkel set theory. <jh> export (SETS Interface:Basic_operations_of_Zermelo–Fraenkel_set_theory (CLASSICAL FIRSTORDER) ) </jh>