Interface:Zermelo–Fraenkel set theory

First, we adopt the axioms of propositional logic and first-order logic (including equality):

 param (CLASSICAL Interface:Classical_propositional_calculus ) param (FIRSTORDER Interface:First-order_logic_with_quantifiability (CLASSICAL) ) 

First-order logic provides us with two kinds:  is a variable, which represents a set and can be quantified over, and   is an expression which represents a set. For example, a variable might be,  , or  , but an object could be the singleton  , the unordered pair  , the ordered pair  , the union  , etc. To some extent the concepts of variable and object correspond to set and class in some theories (like metamath's set.mm), but one key difference is that we have no proper classes thanks to the axiom of quantifiability.

 var (variable x y z w) var (formula φ) 

We define one key predicate. The formula  means "A is an element of B".

 term (formula (∈ object object)) 

Our first axiom, the axiom of extensionality, states that if two sets have the same elements, they are equal. In symbols this is. Versions with fewer distinct variable constaints also hold, but they can be proved from this version and other axioms, so we assume the weakest version (the one with the most distinct variable constraints).

 stmt (ExtensionalityVariable ((x y z)) ((∀ z (((value z) ∈ (value x)) ↔ ((value z) ∈ (value y)))) → ((value x) = (value y)))) 

The principle that equals can be substituted for equals in JHilbert must be adopted as an axiom for each non-logical predicate (in this case ∈), which we do now.

 var (object A B A0 A1 B0 B1) stmt (MembershipBuilderLL  ((B0 = B1) → ((A ∈ B0) ↔ (A ∈ B1)))) stmt (MembershipBuilderRR  ((A0 = A1) → ((A0 ∈ B) ↔ (A1 ∈ B)))) 

The axiom of separation is. Given a set  and a formula   this asserts the existence of a set   which contains the elements of   which satisfy. The distinct variable constraint between  and   is needed and is part of textbook statements of this axiom. Most of the other distinct variable constraints are implicit in the notation in many textbooks, and not all of them are necessary, but as with extensionality we include them.

TODO: Prove this from the axiom of replacement and then we won't need it as an axiom here.  stmt (SeparationThereExists ((x y z) (φ y z)) (∃ y (∀ x (((value x) ∈ (value y)) ↔ (((value x) ∈ (value z)) ∧ φ))))) 

Axiom of replacement. Metamath has a number of variants of this axiom, but at least for now we choose this one, which has an odd feature of the apparently pointless  (whose function is in fact to reduce the number of distinct variable constraints needed).  stmt (Replacement ((x y z w)) ((∀ w (∃ y (∀ z ((∀ y φ) → ((value z) = (value y)))))) → (∃ y (∀ z (((value z) ∈ (value y)) ↔ (∃ w (((value w) ∈ (value x)) ∧ (∀ y φ)))))))) 

Axiom of pairing. There exists a set whose elements are two given sets. Although pairing can be proved by applying the axiom of replacement to any set with two elements (the existence of which can be proved using the power set axiom), for now we omit that proof by assuming pairing as an axiom. Some formulations, such as the one in metamath, merely assert the existence of a set containing the pair, not the pair itself.  stmt (Pairing ((x z w) (y z w)) (∃ z (∀ w (((value w) ∈ (value z)) ↔ (((value w) = (value x)) ∨ ((value w) = (value y))))))) 

Axiom of power sets. As with pairing, the metamath version asserts a set which contains the power set but we assert the power set itself.  stmt (PowerSetAxiom ((x y z w)) (∃ y (∀ z (((value z) ∈ (value y)) ↔ (∀ w (((value w) ∈ (value z)) → ((value w) ∈ (value x)))))))) </jh>

Axiom of union. As with pairing, the metamath version asserts a set which contains the union but we assert the union itself.  stmt (UnionAxiom ((x y z w)) (∃ y (∀ z (((value z) ∈ (value y)) ↔ (∃ w (((value z) ∈ (value w)) ∧ ((value w) ∈ (value x)))))))) </jh>

Axiom of regularity.  stmt (Regularity ((x y z)) ((∃ y ((value y) ∈ (value x))) → (∃ y (((value y) ∈ (value x)) ∧ (∀ z (((value z) ∈ (value y)) → (¬ ((value z) ∈ (value x))))))))) </jh>

Axiom of infinity.  stmt (Infinity ((x y z w)) (∃ y (((value x) ∈ (value y)) ∧ (∀ z (((value z) ∈ (value y)) → (∃ w (((value z) ∈ (value w)) ∧ ((value w) ∈ (value y))))))))) </jh>

Not an element is just an abbreviation for negation and element-of.  def ((∉ A B) (¬ (A ∈ B))) </jh>

Defining sets
What we have presented so far provides the ideas of set theory, but there is one important notational detail to attend to. The above axioms let us conclude that there is a set with no elements, or a set whose only element is a set, but they do not provide any way to introduce notation such as   or   for those concepts.

We want to define  (the set of all   for which   holds), of kind , but we need to tread carefully to avoid Russell's paradox and related problems. Metamath's set.mm uses the definition, which allows   to be a proper class rather than a set. As long as we assume the axiom of quantifiability, this avenue is not open to us. Instead, we provide a version of the metamath definition which has a hypothesis stating that the resulting set exists. This closely parallels the idiom of proving that something exists, and only then introducing a notation for it.

The syntax  is not available in JHilbert, so we will write it as.  term (object (abstract variable formula)) </jh>

Our restricted version of the metamath definition follows. The hypothesis is, which can be paraphrased as "  is a set". We adopt an axiom that this hypothesis lets us conclude. All variables are distinct except that  can (and typically does) appear in.  var (variable result) stmt (Abstraction ((result x φ) (result x y)) ((∃ result (∀ x (((value x) ∈ (value result)) ↔ (subst (value x) y φ)))))  (((value x) ∈ (abstract y φ)) ↔ (subst (value x) y φ))) </jh>