Analysis I, Section 3.1

In this section we set up a version of Zermelo-Frankel set theory (with atoms) that tries to be as faithful as possible to the original text of Analysis I, Section 3.1. All numbering refers to the original text.

I have attempted to make the translation as faithful a paraphrasing as possible of the original text. When there is a choice between a more idiomatic Lean solution and a more faithful translation, I have generally chosen the latter. In particular, there will be places where the Lean code could be "golfed" to be more elegant and idiomatic, but I have consciously avoided doing so.

Main constructions and results of this section:

The other axioms of Zermelo-Frankel set theory are discussed in later sections.

Some technical notes:

namespace Chapter3

Some of the axioms of Zermelo-Frankel theory with atoms

class SetTheory where Set : Type Object : Type set_to_object : Set ↪ Object mem : Object → Set → Prop emptyset: Set emptyset_mem x : ¬ mem x emptyset extensionality X Y : (∀ x, mem x X ↔ mem x Y) → X = Y singleton : Object → Set singleton_axiom x y : mem x (singleton y) ↔ x = y union_pair : Set → Set → Set union_pair_axiom X Y x : mem x (union_pair X Y) ↔ (mem x X ∨ mem x Y) specify A (P: Subtype (fun x ↦ mem x A) → Prop) : Set specification_axiom A (P: Subtype (fun x ↦ mem x A) → Prop) : (∀ x, mem x (specify A P) → mem x A) ∧ ∀ x, mem x.val (specify A P) ↔ P x replace A (P: Subtype (fun x ↦ mem x A) → Object → Prop) (hP: ∀ x y y', P x y ∧ P x y' → y = y') : Set replacement_axiom A (P: Subtype (fun x ↦ mem x A) → Object → Prop) (hP: ∀ x y y', P x y ∧ P x y' → y = y') : ∀ y, mem y (replace A P hP) ↔ ∃ x, P x y nat : Set nat_equiv : ℕ ≃ Subtype (fun x ↦ mem x nat)export SetTheory (Set Object)-- This instance implicitly imposes (some of) the axioms of Zermelo-Frankel set theory with atoms. variable [SetTheory]

Definition 3.1.1 (objects can be elements of sets)

instance objects_mem_sets : Membership Object Set where mem X x := SetTheory.mem x X

Axiom 3.1 (Sets are objects)

instance sets_are_objects : Coe Set Object where coe X := SetTheory.set_to_object Xabbrev SetTheory.Set.toObject (X:Set) : Object := X

Axiom 3.1 (Sets are objects)

theorem SetTheory.Set.coe_eq {X Y:Set} (h: X.toObject = Y.toObject) : X = Y := SetTheory.set_to_object.inj' h

Axiom 3.1 (Sets are objects)

@[simp] theorem SetTheory.Set.coe_eq_iff (X Y:Set) : X.toObject = Y.toObject ↔ X = Y := inst✝:SetTheoryX:SetY:Set⊢ X.toObject = Y.toObject ↔ X = Y inst✝:SetTheoryX:SetY:Set⊢ X.toObject = Y.toObject → X = Yinst✝:SetTheoryX:SetY:Set⊢ X = Y → X.toObject = Y.toObject inst✝:SetTheoryX:SetY:Set⊢ X.toObject = Y.toObject → X = Y All goals completed! 🐙 inst✝:SetTheoryX:SetY:Seth:X = Y⊢ X.toObject = Y.toObject; inst✝:SetTheoryX:Set⊢ X.toObject = X.toObject; All goals completed! 🐙

Axiom 3.2 (Equality of sets)

abbrev SetTheory.Set.ext {X Y:Set} (h: ∀ x, x ∈ X ↔ x ∈ Y) : X = Y := SetTheory.extensionality _ _ h

Axiom 3.2 (Equality of sets)

theorem SetTheory.Set.ext_iff (X Y: Set) : X = Y ↔ ∀ x, x ∈ X ↔ x ∈ Y := inst✝:SetTheoryX:SetY:Set⊢ X = Y ↔ ∀ (x : Object), x ∈ X ↔ x ∈ Y inst✝:SetTheoryX:SetY:Set⊢ X = Y → ∀ (x : Object), x ∈ X ↔ x ∈ Yinst✝:SetTheoryX:SetY:Set⊢ (∀ (x : Object), x ∈ X ↔ x ∈ Y) → X = Y inst✝:SetTheoryX:SetY:Set⊢ X = Y → ∀ (x : Object), x ∈ X ↔ x ∈ Y inst✝:SetTheoryX:SetY:Seth:X = Y⊢ ∀ (x : Object), x ∈ X ↔ x ∈ Y; inst✝:SetTheoryX:Set⊢ ∀ (x : Object), x ∈ X ↔ x ∈ X; All goals completed! 🐙 inst✝:SetTheoryX:SetY:Set⊢ (∀ (x : Object), x ∈ X ↔ x ∈ Y) → X = Y inst✝:SetTheoryX:SetY:Seth:∀ (x : Object), x ∈ X ↔ x ∈ Y⊢ X = Y; inst✝:SetTheoryX:SetY:Seth:∀ (x : Object), x ∈ X ↔ x ∈ Y⊢ ∀ (x : Object), x ∈ X ↔ x ∈ Y; All goals completed! 🐙instance SetTheory.Set.instEmpty : EmptyCollection Set where emptyCollection := SetTheory.emptyset

Axiom 3.3 (empty set). Note: one may have to explicitly cast ∅ to Set due to Mathlib's existing set theory notation.

theorem SetTheory.Set.not_mem_empty : ∀ x, x ∉ (∅:Set) := SetTheory.emptyset_mem

Empty set is unique

theorem declaration uses 'sorry'SetTheory.Set.eq_empty_iff_forall_notMem {X:Set} : X = ∅ ↔ (∀ x, ¬ x ∈ X) := inst✝:SetTheoryX:Set⊢ X = ∅ ↔ ∀ (x : Object), x ∉ X All goals completed! 🐙

Empty set is unique

theorem declaration uses 'sorry'SetTheory.Set.empty_unique : ∃! (X:Set), ∀ x, ¬ x ∈ X := inst✝:SetTheory⊢ ∃! X, ∀ (x : Object), x ∉ X All goals completed! 🐙/-- Lemma 3.1.5 (Single choice) -/ lemma SetTheory.Set.nonempty_def {X:Set} (h: X ≠ ∅) : ∃ x, x ∈ X := inst✝:SetTheoryX:Seth:X ≠ ∅⊢ ∃ x, x ∈ X -- This proof is written to follow the structure of the original text. inst✝:SetTheoryX:Seth:X ≠ ∅this:∀ (x : Object), x ∉ X⊢ False have claim (x:Object) : x ∈ X ↔ x ∈ (∅:Set) := inst✝:SetTheoryX:Seth:X ≠ ∅⊢ ∃ x, x ∈ X All goals completed! 🐙 inst✝:SetTheoryX:Seth:X ≠ ∅this:∀ (x : Object), x ∉ Xclaim:X = ∅⊢ False All goals completed! 🐙instance SetTheory.Set.instSingleton : Singleton Object Set where singleton := SetTheory.singleton

Axiom 3.3(a) (singleton). Note one may have to explicitly cast {a} to Set due to Mathlib's existing set theory notation.

theorem SetTheory.Set.mem_singleton (x a:Object) : x ∈ ({a}:Set) ↔ x = a := inst✝:SetTheoryx:Objecta:Object⊢ x ∈ {a} ↔ x = a All goals completed! 🐙instance SetTheory.Set.instUnion : Union Set where union := SetTheory.union_pair

Axiom 3.4 (Pairwise union)

theorem SetTheory.Set.mem_union (x:Object) (X Y:Set) : x ∈ (X ∪ Y) ↔ (x ∈ X ∨ x ∈ Y) := SetTheory.union_pair_axiom X Y xinstance SetTheory.Set.instInsert : Insert Object Set where insert x X := {x} ∪ X

Axiom 3.3(b) (pair). Note that one often has to cast {a,b} to Set

theorem SetTheory.Set.pair_eq (a b:Object) : ({a,b}:Set) = {a} ∪ {b} := inst✝:SetTheorya:Objectb:Object⊢ {a, b} = {a} ∪ {b} All goals completed! 🐙

Axiom 3.3(b) (pair). Note that one often has to cast {a,b} to Set

theorem SetTheory.Set.mem_pair (x a b:Object) : x ∈ ({a,b}:Set) ↔ (x = a ∨ x = b) := inst✝:SetTheoryx:Objecta:Objectb:Object⊢ x ∈ {a, b} ↔ x = a ∨ x = b All goals completed! 🐙

Remark 3.1.8

theorem declaration uses 'sorry'SetTheory.Set.singleton_uniq (a:Object) : ∃! (X:Set), ∀ x, x ∈ X ↔ x = a := inst✝:SetTheorya:Object⊢ ∃! X, ∀ (x : Object), x ∈ X ↔ x = a All goals completed! 🐙

Remark 3.1.8

theorem declaration uses 'sorry'SetTheory.Set.pair_uniq (a b:Object) : ∃! (X:Set), ∀ x, x ∈ X ↔ x = a ∨ x = b := inst✝:SetTheorya:Objectb:Object⊢ ∃! X, ∀ (x : Object), x ∈ X ↔ x = a ∨ x = b All goals completed! 🐙

Remark 3.1.8

theorem declaration uses 'sorry'SetTheory.Set.pair_comm (a b:Object) : ({a,b}:Set) = {b,a} := inst✝:SetTheorya:Objectb:Object⊢ {a, b} = {b, a} All goals completed! 🐙

Remark 3.1.8

theorem declaration uses 'sorry'SetTheory.Set.pair_self (a:Object) : ({a,a}:Set) = {a} := inst✝:SetTheorya:Object⊢ {a, a} = {a} All goals completed! 🐙

Exercise 3.1.1

theorem declaration uses 'sorry'SetTheory.Set.pair_eq_pair {a b c d:Object} (h: ({a,b}:Set) = {c,d}) : a = c ∧ b = d ∨ a = d ∧ b = c := inst✝:SetTheorya:Objectb:Objectc:Objectd:Objecth:{a, b} = {c, d}⊢ a = c ∧ b = d ∨ a = d ∧ b = c All goals completed! 🐙abbrev SetTheory.Set.empty : Set := ∅abbrev SetTheory.Set.singleton_empty : Set := {empty.toObject}abbrev SetTheory.Set.pair_empty : Set := {empty.toObject, singleton_empty.toObject}

Exercise 3.1.2

theorem declaration uses 'sorry'SetTheory.Set.emptyset_neq_singleton : empty ≠ singleton_empty := inst✝:SetTheory⊢ empty ≠ singleton_empty All goals completed! 🐙

Exercise 3.1.2

theorem declaration uses 'sorry'SetTheory.Set.emptyset_neq_pair : empty ≠ pair_empty := inst✝:SetTheory⊢ empty ≠ pair_empty All goals completed! 🐙

Exercise 3.1.2

theorem declaration uses 'sorry'SetTheory.Set.singleton_empty_neq_pair : singleton_empty ≠ pair_empty := inst✝:SetTheory⊢ singleton_empty ≠ pair_empty All goals completed! 🐙

Remark 3.1.11. (These results can be proven either by a direct rewrite, or by using extensionality.)

theorem declaration uses 'sorry'SetTheory.Set.union_congr_left (A A' B:Set) (h: A = A') : A ∪ B = A' ∪ B := inst✝:SetTheoryA:SetA':SetB:Seth:A = A'⊢ A ∪ B = A' ∪ B All goals completed! 🐙

Remark 3.1.11. (These results can be proven either by a direct rewrite, or by using extensionality.)

theorem declaration uses 'sorry'SetTheory.Set.union_congr_right (A B B':Set) (h: B = B') : A ∪ B = A ∪ B' := inst✝:SetTheoryA:SetB:SetB':Seth:B = B'⊢ A ∪ B = A ∪ B' All goals completed! 🐙

Lemma 3.1.12 (Basic properties of unions) / Exercise 3.1.3

theorem declaration uses 'sorry'SetTheory.Set.singleton_union_singleton (a b:Object) : ({a}:Set) ∪ ({b}:Set) = {a,b} := inst✝:SetTheorya:Objectb:Object⊢ {a} ∪ {b} = {a, b} All goals completed! 🐙

Lemma 3.1.12 (Basic properties of unions) / Exercise 3.1.3

theorem declaration uses 'sorry'SetTheory.Set.union_comm (A B:Set) : A ∪ B = B ∪ A := inst✝:SetTheoryA:SetB:Set⊢ A ∪ B = B ∪ A All goals completed! 🐙

Lemma 3.1.12 (Basic properties of unions) / Exercise 3.1.3

theorem declaration uses 'sorry'SetTheory.Set.union_assoc (A B C:Set) : (A ∪ B) ∪ C = A ∪ (B ∪ C) := inst✝:SetTheoryA:SetB:SetC:Set⊢ A ∪ B ∪ C = A ∪ (B ∪ C) -- this proof is written to follow the structure of the original text. inst✝:SetTheoryA:SetB:SetC:Set⊢ ∀ (x : Object), x ∈ A ∪ B ∪ C ↔ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Object⊢ x ∈ A ∪ B ∪ C ↔ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Object⊢ x ∈ A ∪ B ∪ C → x ∈ A ∪ (B ∪ C)inst✝:SetTheoryA:SetB:SetC:Setx:Object⊢ x ∈ A ∪ (B ∪ C) → x ∈ A ∪ B ∪ C inst✝:SetTheoryA:SetB:SetC:Setx:Object⊢ x ∈ A ∪ B ∪ C → x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objecthx:x ∈ A ∪ B ∪ C⊢ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objecthx:x ∈ A ∪ B ∨ x ∈ C⊢ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1:x ∈ A ∪ B⊢ x ∈ A ∪ (B ∪ C)inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase2:x ∈ C⊢ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1:x ∈ A ∪ B⊢ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1:x ∈ A ∨ x ∈ B⊢ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1a:x ∈ A⊢ x ∈ A ∪ (B ∪ C)inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1b:x ∈ B⊢ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1a:x ∈ A⊢ x ∈ A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1a:x ∈ A⊢ x ∈ A ∨ x ∈ B ∪ C; All goals completed! 🐙 have : x ∈ B ∪ C := inst✝:SetTheoryA:SetB:SetC:Set⊢ A ∪ B ∪ C = A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1b:x ∈ B⊢ x ∈ B ∨ x ∈ C; All goals completed! 🐙 inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase1b:x ∈ Bthis:x ∈ B ∪ C⊢ x ∈ A ∨ x ∈ B ∪ C; All goals completed! 🐙 have : x ∈ B ∪ C := inst✝:SetTheoryA:SetB:SetC:Set⊢ A ∪ B ∪ C = A ∪ (B ∪ C) inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase2:x ∈ C⊢ x ∈ B ∨ x ∈ C; All goals completed! 🐙 inst✝:SetTheoryA:SetB:SetC:Setx:Objectcase2:x ∈ Cthis:x ∈ B ∪ C⊢ x ∈ A ∨ x ∈ B ∪ C; All goals completed! 🐙 All goals completed! 🐙

Proposition 3.1.27(c)

theorem declaration uses 'sorry'SetTheory.Set.union_self (A:Set) : A ∪ A = A := inst✝:SetTheoryA:Set⊢ A ∪ A = A All goals completed! 🐙

Proposition 3.1.27(a)

theorem declaration uses 'sorry'SetTheory.Set.union_empty (A:Set) : A ∪ ∅ = A := inst✝:SetTheoryA:Set⊢ A ∪ ∅ = A All goals completed! 🐙

Proposition 3.1.27(a)

theorem declaration uses 'sorry'SetTheory.Set.empty_union (A:Set) : ∅ ∪ A = A := inst✝:SetTheoryA:Set⊢ ∅ ∪ A = A All goals completed! 🐙theorem SetTheory.Set.triple_eq (a b c:Object) : {a,b,c} = ({a}:Set) ∪ {b,c} := inst✝:SetTheorya:Objectb:Objectc:Object⊢ {a, b, c} = {a} ∪ {b, c} All goals completed! 🐙

Example 3.1.10

theorem declaration uses 'sorry'SetTheory.Set.pair_union_pair (a b c:Object) : ({a,b}:Set) ∪ {b,c} = {a,b,c} := sorry

Definition 3.1.14.

instance SetTheory.Set.uinstSubset : HasSubset Set where Subset X Y := ∀ x, x ∈ X → x ∈ Y

Definition 3.1.14. Note that the strict subset operation in Mathlib is denoted ⊂ rather than ⊊.

instance SetTheory.Set.instSSubset : HasSSubset Set where SSubset X Y := X ⊆ Y ∧ X ≠ Y

Definition 3.1.14.

theorem SetTheory.Set.subset_def (X Y:Set) : X ⊆ Y ↔ ∀ x, x ∈ X → x ∈ Y := inst✝:SetTheoryX:SetY:Set⊢ X ⊆ Y ↔ ∀ x ∈ X, x ∈ Y All goals completed! 🐙

Definition 3.1.14. Note that the strict subset operation in Mathlib is denoted ⊂ rather than ⊊.

theorem SetTheory.Set.ssubset_def (X Y:Set) : X ⊂ Y ↔ (X ⊆ Y ∧ X ≠ Y) := inst✝:SetTheoryX:SetY:Set⊢ X ⊂ Y ↔ X ⊆ Y ∧ X ≠ Y All goals completed! 🐙

Remark 3.1.15

theorem declaration uses 'sorry'SetTheory.Set.subset_congr_left {A A' B:Set} (hAA':A = A') (hAB: A ⊆ B) : A' ⊆ B := inst✝:SetTheoryA:SetA':SetB:SethAA':A = A'hAB:A ⊆ B⊢ A' ⊆ B All goals completed! 🐙

Examples 3.1.16

theorem declaration uses 'sorry'SetTheory.Set.subset_self (A:Set) : A ⊆ A := inst✝:SetTheoryA:Set⊢ A ⊆ A All goals completed! 🐙

Examples 3.1.16

theorem declaration uses 'sorry'SetTheory.Set.empty_subset (A:Set) : ∅ ⊆ A := inst✝:SetTheoryA:Set⊢ ∅ ⊆ A All goals completed! 🐙

Proposition 3.1.17 (Partial ordering by set inclusion)

theorem SetTheory.Set.subset_trans (A B C:Set) (hAB:A ⊆ B) (hBC:B ⊆ C) : A ⊆ C := inst✝:SetTheoryA:SetB:SetC:SethAB:A ⊆ BhBC:B ⊆ C⊢ A ⊆ C -- this proof is written to follow the structure of the original text. inst✝:SetTheoryA:SetB:SetC:SethAB:A ⊆ BhBC:B ⊆ C⊢ ∀ x ∈ A, x ∈ C inst✝:SetTheoryA:SetB:SetC:SethAB:A ⊆ BhBC:B ⊆ Cx:Objecthx:x ∈ A⊢ x ∈ C inst✝:SetTheoryA:SetB:SetC:SethAB:∀ x ∈ A, x ∈ BhBC:B ⊆ Cx:Objecthx:x ∈ A⊢ x ∈ C inst✝:SetTheoryA:SetB:SetC:SethAB:∀ x ∈ A, x ∈ BhBC:B ⊆ Cx:Objecthx:x ∈ B⊢ x ∈ C inst✝:SetTheoryA:SetB:SetC:SethAB:∀ x ∈ A, x ∈ BhBC:B ⊆ Cx:Objecthx:x ∈ C⊢ x ∈ C All goals completed! 🐙

Proposition 3.1.17 (Partial ordering by set inclusion)

theorem declaration uses 'sorry'SetTheory.Set.subset_antisymm (A B:Set) (hAB:A ⊆ B) (hBA:B ⊆ A) : A = B := inst✝:SetTheoryA:SetB:SethAB:A ⊆ BhBA:B ⊆ A⊢ A = B All goals completed! 🐙

Proposition 3.1.17 (Partial ordering by set inclusion)

theorem declaration uses 'sorry'SetTheory.Set.ssubset_trans (A B C:Set) (hAB:A ⊂ B) (hBC:B ⊂ C) : A ⊂ C := inst✝:SetTheoryA:SetB:SetC:SethAB:A ⊂ BhBC:B ⊂ C⊢ A ⊂ C All goals completed! 🐙

This defines the subtype A.toSubtype for any A:Set. To produce an element x' of this subtype, use ⟨ x, hx ⟩, where x:Object and hx:x ∈ A. The object x associated to a subtype element x' is recovered as x.val, and the property hx that x belongs to A is recovered as x.property

abbrev SetTheory.Set.toSubtype (A:Set) := Subtype (fun x ↦ x ∈ A)instance : CoeSort (Set) (Type) where coe A := A.toSubtype/-- Elements of a set (implicitly coerced to a subtype) are also elements of the set (with respect to the membership operation of the set theory). -/ lemma SetTheory.Set.subtype_property (A:Set) (x:A) : x.val ∈ A := x.propertylemma SetTheory.Set.subtype_coe (A:Set) (x:A) : x.val = x := rfllemma SetTheory.Set.coe_inj (A:Set) (x y:A) : x.val = y.val ↔ x = y := Subtype.coe_inj

If one has a proof hx of x ∈ A, then A.subtype_mk hx will then make the element of A (viewed as a subtype) corresponding to x.

def SetTheory.Set.subtype_mk (A:Set) {x:Object} (hx:x ∈ A) : A := ⟨ x, hx ⟩lemma SetTheory.Set.subtype_mk_coe {A:Set} {x:Object} (hx:x ∈ A) : A.subtype_mk hx = x := inst✝:SetTheoryA:Setx:Objecthx:x ∈ A⊢ ↑(A.subtype_mk hx) = x All goals completed! 🐙abbrev SetTheory.Set.specify (A:Set) (P: A → Prop) : Set := SetTheory.specify A P

Axiom 3.6 (axiom of specification)

theorem SetTheory.Set.specification_axiom {A:Set} {P: A → Prop} {x:Object} (h: x ∈ A.specify P) : x ∈ A := (SetTheory.specification_axiom A P).1 x h

Axiom 3.6 (axiom of specification)

theorem SetTheory.Set.specification_axiom' {A:Set} (P: A → Prop) (x:A.toSubtype) : x.val ∈ A.specify P ↔ P x := (SetTheory.specification_axiom A P).2 xtheorem declaration uses 'sorry'SetTheory.Set.specify_subset {A:Set} (P: A → Prop) : A.specify P ⊆ A := inst✝:SetTheoryA:SetP:A.toSubtype → Prop⊢ A.specify P ⊆ A All goals completed! 🐙

This exercise may require some understanding of how subtypes are implemented in Lean.

theorem declaration uses 'sorry'SetTheory.Set.specify_congr {A A':Set} (hAA':A = A') {P: A → Prop} {P': A' → Prop} (hPP': (x:Object) → (h:x ∈ A) → (h':x ∈ A') → P ⟨ x, h⟩ ↔ P' ⟨ x, h'⟩ ) : A.specify P = A'.specify P' := inst✝:SetTheoryA:SetA':SethAA':A = A'P:A.toSubtype → PropP':A'.toSubtype → ProphPP':∀ (x : Object) (h : x ∈ A) (h' : x ∈ A'), P ⟨x, h⟩ ↔ P' ⟨x, h'⟩⊢ A.specify P = A'.specify P' All goals completed! 🐙instance SetTheory.Set.instIntersection : Inter Set where inter X Y := X.specify (fun x ↦ x.val ∈ Y)

Definition 3.1.22 (Intersections)

theorem SetTheory.Set.mem_inter (x:Object) (X Y:Set) : x ∈ (X ∩ Y) ↔ (x ∈ X ∧ x ∈ Y) := inst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X ∩ Y ↔ x ∈ X ∧ x ∈ Y inst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X ∩ Y → x ∈ X ∧ x ∈ Yinst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X ∧ x ∈ Y → x ∈ X ∩ Y inst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X ∩ Y → x ∈ X ∧ x ∈ Y inst✝:SetTheoryx:ObjectX:SetY:Seth:x ∈ X ∩ Y⊢ x ∈ X ∧ x ∈ Y inst✝:SetTheoryx:ObjectX:SetY:Seth:x ∈ X ∩ Yh':x ∈ X⊢ x ∈ X ∧ x ∈ Y inst✝:SetTheoryx:ObjectX:SetY:Seth:x ∈ X ∩ Yh':x ∈ X⊢ x ∈ Y All goals completed! 🐙 inst✝:SetTheoryx:ObjectX:SetY:SethX:x ∈ XhY:x ∈ Y⊢ x ∈ X ∩ Y All goals completed! 🐙instance SetTheory.Set.instSDiff : SDiff Set where sdiff X Y := X.specify (fun x ↦ x.val ∉ Y)

Definition 3.1.26 (Difference sets)

theorem SetTheory.Set.mem_sdiff (x:Object) (X Y:Set) : x ∈ (X \ Y) ↔ (x ∈ X ∧ x ∉ Y) := inst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X \ Y ↔ x ∈ X ∧ x ∉ Y inst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X \ Y → x ∈ X ∧ x ∉ Yinst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X ∧ x ∉ Y → x ∈ X \ Y inst✝:SetTheoryx:ObjectX:SetY:Set⊢ x ∈ X \ Y → x ∈ X ∧ x ∉ Y inst✝:SetTheoryx:ObjectX:SetY:Seth:x ∈ X \ Y⊢ x ∈ X ∧ x ∉ Y inst✝:SetTheoryx:ObjectX:SetY:Seth:x ∈ X \ Yh':x ∈ X⊢ x ∈ X ∧ x ∉ Y inst✝:SetTheoryx:ObjectX:SetY:Seth:x ∈ X \ Yh':x ∈ X⊢ x ∉ Y All goals completed! 🐙 inst✝:SetTheoryx:ObjectX:SetY:SethX:x ∈ XhY:x ∉ Y⊢ x ∈ X \ Y All goals completed! 🐙

Proposition 3.1.27(d) / Exercise 3.1.6

theorem declaration uses 'sorry'SetTheory.Set.inter_comm (A B:Set) : A ∩ B = B ∩ A := inst✝:SetTheoryA:SetB:Set⊢ A ∩ B = B ∩ A All goals completed! 🐙

Proposition 3.1.27(b)

theorem declaration uses 'sorry'SetTheory.Set.subset_union {A X: Set} (hAX: A ⊆ X) : A ∪ X = X := inst✝:SetTheoryA:SetX:SethAX:A ⊆ X⊢ A ∪ X = X All goals completed! 🐙

Proposition 3.1.27(b)

theorem declaration uses 'sorry'SetTheory.Set.union_subset {A X: Set} (hAX: A ⊆ X) : X ∪ A = X := inst✝:SetTheoryA:SetX:SethAX:A ⊆ X⊢ X ∪ A = X All goals completed! 🐙

Proposition 3.1.27(c)

theorem declaration uses 'sorry'SetTheory.Set.inter_self (A:Set) : A ∩ A = A := inst✝:SetTheoryA:Set⊢ A ∩ A = A All goals completed! 🐙

Proposition 3.1.27(e)

theorem declaration uses 'sorry'SetTheory.Set.inter_assoc (A B C:Set) : (A ∩ B) ∩ C = A ∩ (B ∩ C) := inst✝:SetTheoryA:SetB:SetC:Set⊢ A ∩ B ∩ C = A ∩ (B ∩ C) All goals completed! 🐙

Proposition 3.1.27(f)

theorem declaration uses 'sorry'SetTheory.Set.inter_union_distrib_left (A B C:Set) : A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) := sorry

Proposition 3.1.27(f)

theorem declaration uses 'sorry'SetTheory.Set.union_inter_distrib_left (A B C:Set) : A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) := sorry

Proposition 3.1.27(f)

theorem declaration uses 'sorry'SetTheory.Set.union_compl {A X:Set} (hAX: A ⊆ X) : A ∪ (X \ A) = X := inst✝:SetTheoryA:SetX:SethAX:A ⊆ X⊢ A ∪ X \ A = X All goals completed! 🐙

Proposition 3.1.27(f)

theorem declaration uses 'sorry'SetTheory.Set.inter_compl {A X:Set} (hAX: A ⊆ X) : A ∩ (X \ A) = ∅ := inst✝:SetTheoryA:SetX:SethAX:A ⊆ X⊢ A ∩ (X \ A) = ∅ All goals completed! 🐙

Proposition 3.1.27(g)

theorem declaration uses 'sorry'SetTheory.Set.compl_union {A B X:Set} (hAX: A ⊆ X) (hBX: B ⊆ X) : X \ (A ∪ B) = (X \ A) ∩ (X \ B) := inst✝:SetTheoryA:SetB:SetX:SethAX:A ⊆ XhBX:B ⊆ X⊢ X \ (A ∪ B) = X \ A ∩ (X \ B) All goals completed! 🐙

Proposition 3.1.27(g)

theorem declaration uses 'sorry'SetTheory.Set.compl_inter {A B X:Set} (hAX: A ⊆ X) (hBX: B ⊆ X) : X \ (A ∩ B) = (X \ A) ∪ (X \ B) := inst✝:SetTheoryA:SetB:SetX:SethAX:A ⊆ XhBX:B ⊆ X⊢ X \ (A ∩ B) = X \ A ∪ X \ B All goals completed! 🐙

Not from textbook: sets form a distributive lattice.

instance declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'declaration uses 'sorry'SetTheory.Set.instDistribLattice : DistribLattice Set where le := (· ⊆ ·) le_refl := subset_self le_trans := subset_trans le_antisymm := subset_antisymm inf := (· ∩ ·) sup := (· ∪ ·) le_sup_left := inst✝:SetTheory⊢ ∀ (a b : Set), a ⊆ a ∪ b All goals completed! 🐙 le_sup_right := inst✝:SetTheory⊢ ∀ (a b : Set), b ⊆ a ∪ b All goals completed! 🐙 sup_le := inst✝:SetTheory⊢ ∀ (a b c : Set), a ⊆ c → b ⊆ c → a ∪ b ⊆ c All goals completed! 🐙 inf_le_left := inst✝:SetTheory⊢ ∀ (a b : Set), a ∩ b ⊆ a All goals completed! 🐙 inf_le_right := inst✝:SetTheory⊢ ∀ (a b : Set), a ∩ b ⊆ b All goals completed! 🐙 le_inf := inst✝:SetTheory⊢ ∀ (a b c : Set), a ⊆ b → a ⊆ c → a ⊆ b ∩ c All goals completed! 🐙 le_sup_inf := inst✝:SetTheory⊢ ∀ (x y z : Set), (x ⊔ y) ⊓ (x ⊔ z) ⊆ x ⊔ y ⊓ z inst✝:SetTheoryX:SetY:SetZ:Set⊢ (X ⊔ Y) ⊓ (X ⊔ Z) ⊆ X ⊔ Y ⊓ Z inst✝:SetTheoryX:SetY:SetZ:Set⊢ (X ∪ Y) ∩ (X ∪ Z) ⊆ X ∪ Y ∩ Z inst✝:SetTheoryX:SetY:SetZ:Set⊢ X ∪ Y ∩ Z ⊆ X ∪ Y ∩ Z All goals completed! 🐙

Sets have a minimal element.

instance SetTheory.Set.instOrderBot : OrderBot Set where bot := ∅ bot_le := empty_subset

Definition of disjointness (using the previous instances)

theorem SetTheory.Set.disjoint_iff (A B:Set) : Disjoint A B ↔ A ∩ B = ∅ := inst✝:SetTheoryA:SetB:Set⊢ Disjoint A B ↔ A ∩ B = ∅ All goals completed! 🐙abbrev SetTheory.Set.replace (A:Set) {P: A → Object → Prop} (hP : ∀ x y y', P x y ∧ P x y' → y = y') : Set := SetTheory.replace A P hP

Axiom 3.7 (Axiom of replacement)

theorem SetTheory.Set.replacement_axiom {A:Set} {P: A → Object → Prop} (hP: ∀ x y y', P x y ∧ P x y' → y = y') (y:Object) : y ∈ A.replace hP ↔ ∃ x, P x y := SetTheory.replacement_axiom A P hP yabbrev Nat := SetTheory.nat

Axiom 3.8 (Axiom of infinity)

def SetTheory.Set.nat_equiv : ℕ ≃ Nat := SetTheory.nat_equiv-- Below are some API for handling coercions. This may not be the optimal way to set things up. instance SetTheory.Set.instOfNat {n:ℕ} : OfNat Nat n where ofNat := nat_equiv ninstance SetTheory.Set.instNatCast : NatCast Nat where natCast n := nat_equiv ninstance SetTheory.Set.toNat : Coe Nat ℕ where coe n := nat_equiv.symm ninstance SetTheory.Object.instNatCast : NatCast Object where natCast n := (n:Nat).valinstance SetTheory.Object.instOfNat {n:ℕ} : OfNat Object n where ofNat := ((n:Nat):Object)@[simp] lemma SetTheory.Object.ofnat_eq {n:ℕ} : ((n:Nat):Object) = (n:Object) := rfllemma SetTheory.Object.ofnat_eq' {n:ℕ} : (ofNat(n):Object) = (n:Object) := rfllemma SetTheory.Set.nat_coe_eq {n:ℕ} : (n:Nat) = OfNat.ofNat n := rfl@[simp] lemma SetTheory.Set.nat_equiv_inj (n m:ℕ) : (n:Nat) = (m:Nat) ↔ n=m := Equiv.apply_eq_iff_eq nat_equiv@[simp] lemma SetTheory.Set.nat_equiv_symm_inj (n m:Nat) : (n:ℕ) = (m:ℕ) ↔ n = m := Equiv.apply_eq_iff_eq nat_equiv.symm@[simp] theorem SetTheory.Set.ofNat_inj (n m:ℕ) : (ofNat(n) : Nat) = (ofNat(m) : Nat) ↔ ofNat(n) = ofNat(m) := inst✝:SetTheoryn:ℕm:ℕ⊢ OfNat.ofNat n = OfNat.ofNat m ↔ OfNat.ofNat n = OfNat.ofNat m All goals completed! 🐙@[simp] theorem SetTheory.Set.ofNat_inj' (n m:ℕ) : (ofNat(n) : Object) = (ofNat(m) : Object) ↔ ofNat(n) = ofNat(m) := inst✝:SetTheoryn:ℕm:ℕ⊢ OfNat.ofNat n = OfNat.ofNat m ↔ OfNat.ofNat n = OfNat.ofNat m inst✝:SetTheoryn:ℕm:ℕ⊢ n = m ↔ OfNat.ofNat n = OfNat.ofNat m All goals completed! 🐙@[simp] lemma SetTheory.Set.nat_equiv_coe_of_coe (n:ℕ) : ((n:Nat):ℕ) = n := Equiv.symm_apply_apply nat_equiv n@[simp] lemma SetTheory.Set.nat_equiv_coe_of_coe' (n:Nat) : ((n:ℕ):Nat) = n := Equiv.symm_apply_apply nat_equiv.symm nexample : (5:Nat) ≠ (3:Nat) := inst✝:SetTheory⊢ 5 ≠ 3 All goals completed! 🐙example : (5:Object) ≠ (3:Object) := inst✝:SetTheory⊢ 5 ≠ 3 All goals completed! 🐙

Example 3.1.16 (simplified).

declaration uses 'sorry'example : ({3, 5}:Set) ⊆ {1, 3, 5} := inst✝:SetTheory⊢ {3, 5} ⊆ {1, 3, 5} All goals completed! 🐙

Example 3.1.17 (simplified).

declaration uses 'sorry'example : ({3, 5}:Set).specify (fun x ↦ x.val ≠ 3) = {(5:Object)} := inst✝:SetTheory⊢ ({3, 5}.specify fun x => ↑x ≠ 3) = {5} All goals completed! 🐙

Example 3.1.24

declaration uses 'sorry'example : ({1, 2, 4}:Set) ∩ {2,3,4} = {2, 4} := inst✝:SetTheory⊢ {1, 2, 4} ∩ {2, 3, 4} = {2, 4} All goals completed! 🐙

Example 3.1.24

declaration uses 'sorry'example : ({1, 2}:Set) ∩ {3,4} = ∅ := inst✝:SetTheory⊢ {1, 2} ∩ {3, 4} = ∅ All goals completed! 🐙declaration uses 'sorry'example : ¬ Disjoint ({1, 2, 3}:Set) {2,3,4} := inst✝:SetTheory⊢ ¬Disjoint {1, 2, 3} {2, 3, 4} All goals completed! 🐙declaration uses 'sorry'example : Disjoint (∅:Set) ∅ := inst✝:SetTheory⊢ Disjoint ∅ ∅ All goals completed! 🐙

Definition 3.1.26 example

declaration uses 'sorry'example : ({1, 2, 3, 4}:Set) \ {2,4,6} = {1, 3} := inst✝:SetTheory⊢ {1, 2, 3, 4} \ {2, 4, 6} = {1, 3} All goals completed! 🐙

Example 3.1.30

declaration uses 'sorry'example : ({3,5,9}:Set).replace (P := fun x y ↦ ∃ (n:ℕ), x.val = n ∧ y = (n+1:ℕ)) (inst✝:SetTheory⊢ ∀ (x : {3, 5, 9}.toSubtype) (y y' : Object), (fun x y => ∃ n, ↑x = ↑n ∧ y = ↑(n + 1)) x y ∧ (fun x y => ∃ n, ↑x = ↑n ∧ y = ↑(n + 1)) x y' → y = y' All goals completed! 🐙) = {4,6,10} := inst✝:SetTheory⊢ {3, 5, 9}.replace ⋯ = {4, 6, 10} All goals completed! 🐙

Example 3.1.31

declaration uses 'sorry'example : ({3,5,9}:Set).replace (P := fun x y ↦ y=1) (inst✝:SetTheory⊢ ∀ (x : {3, 5, 9}.toSubtype) (y y' : Object), (fun x y => y = 1) x y ∧ (fun x y => y = 1) x y' → y = y' All goals completed! 🐙) = {1} := inst✝:SetTheory⊢ {3, 5, 9}.replace ⋯ = {1} All goals completed! 🐙

Exercise 3.1.5. One can use the tfae_have and tfae_finish tactics here.

theorem declaration uses 'sorry'SetTheory.Set.subset_tfae (A B C:Set) : [A ⊆ B, A ∪ B = B, A ∩ B = A].TFAE := inst✝:SetTheoryA:SetB:SetC:Set⊢ [A ⊆ B, A ∪ B = B, A ∩ B = A].TFAE All goals completed! 🐙

Exercise 3.1.7

theorem declaration uses 'sorry'SetTheory.Set.inter_subset_left (A B:Set) : A ∩ B ⊆ A := inst✝:SetTheoryA:SetB:Set⊢ A ∩ B ⊆ A All goals completed! 🐙

Exercise 3.1.7

theorem declaration uses 'sorry'SetTheory.Set.inter_subset_right (A B:Set) : A ∩ B ⊆ B := inst✝:SetTheoryA:SetB:Set⊢ A ∩ B ⊆ B All goals completed! 🐙

Exercise 3.1.7

theorem declaration uses 'sorry'SetTheory.Set.subset_inter_iff (A B C:Set) : C ⊆ A ∩ B ↔ C ⊆ A ∧ C ⊆ B := inst✝:SetTheoryA:SetB:SetC:Set⊢ C ⊆ A ∩ B ↔ C ⊆ A ∧ C ⊆ B All goals completed! 🐙

Exercise 3.1.7

theorem declaration uses 'sorry'SetTheory.Set.subset_union_left (A B:Set) : A ⊆ A ∪ B := inst✝:SetTheoryA:SetB:Set⊢ A ⊆ A ∪ B All goals completed! 🐙

Exercise 3.1.7

theorem declaration uses 'sorry'SetTheory.Set.subset_union_right (A B:Set) : B ⊆ A ∪ B := inst✝:SetTheoryA:SetB:Set⊢ B ⊆ A ∪ B All goals completed! 🐙

Exercise 3.1.7

theorem declaration uses 'sorry'SetTheory.Set.union_subset_iff (A B C:Set) : A ∪ B ⊆ C ↔ A ⊆ C ∧ B ⊆ C := inst✝:SetTheoryA:SetB:SetC:Set⊢ A ∪ B ⊆ C ↔ A ⊆ C ∧ B ⊆ C All goals completed! 🐙

Exercise 3.1.8

theorem declaration uses 'sorry'SetTheory.Set.inter_union_cancel (A B:Set) : A ∩ (A ∪ B) = A := inst✝:SetTheoryA:SetB:Set⊢ A ∩ (A ∪ B) = A All goals completed! 🐙

Exercise 3.1.8

theorem declaration uses 'sorry'SetTheory.Set.union_inter_cancel (A B:Set) : A ∪ (A ∩ B) = A := inst✝:SetTheoryA:SetB:Set⊢ A ∪ A ∩ B = A All goals completed! 🐙

Exercise 3.1.9

theorem declaration uses 'sorry'SetTheory.Set.partition_left {A B X:Set} (h_union: A ∪ B = X) (h_inter: A ∩ B = ∅) : A = X \ B := inst✝:SetTheoryA:SetB:SetX:Seth_union:A ∪ B = Xh_inter:A ∩ B = ∅⊢ A = X \ B All goals completed! 🐙

Exercise 3.1.9

theorem declaration uses 'sorry'SetTheory.Set.partition_right {A B X:Set} (h_union: A ∪ B = X) (h_inter: A ∩ B = ∅) : B = X \ A := inst✝:SetTheoryA:SetB:SetX:Seth_union:A ∪ B = Xh_inter:A ∩ B = ∅⊢ B = X \ A All goals completed! 🐙

Exercise 3.1.10

theorem declaration uses 'sorry'Set.pairwise_disjoint (A B:Set) : Pairwise (Function.onFun Disjoint ![A \ B, A ∩ B, B \ A]) := inst✝:SetTheoryA:SetB:Set⊢ Pairwise (Function.onFun Disjoint ![A \ B, A ∩ B, B \ A]) All goals completed! 🐙

Exercise 3.1.10

theorem declaration uses 'sorry'Set.union_eq_partition (A B:Set) : A ∪ B = (A \ B) ∪ (A ∩ B) ∪ (B \ A) := inst✝:SetTheoryA:SetB:Set⊢ A ∪ B = A \ B ∪ A ∩ B ∪ B \ A All goals completed! 🐙

Exercise 3.1.11. The challenge is to prove this without using Set.specify, Set.specification_axiom, or Set.specification_axiom'.

theorem declaration uses 'sorry'SetTheory.Set.specification_from_replacement {A:Set} {P: A → Prop} : ∃ B, A ⊆ B ∧ ∀ x, x.val ∈ B ↔ P x := inst✝:SetTheoryA:SetP:A.toSubtype → Prop⊢ ∃ B, A ⊆ B ∧ ∀ (x : A.toSubtype), ↑x ∈ B ↔ P x All goals completed! 🐙

Exercise 3.1.12.

theorem declaration uses 'sorry'SetTheory.Set.subset_union_subset {A B A' B':Set} (hA'A: A' ⊆ A) (hB'B: B' ⊆ B) : A ∪ A' ⊆ A ∪ B := inst✝:SetTheoryA:SetB:SetA':SetB':SethA'A:A' ⊆ AhB'B:B' ⊆ B⊢ A ∪ A' ⊆ A ∪ B All goals completed! 🐙

Exercise 3.1.12.

theorem declaration uses 'sorry'SetTheory.Set.subset_inter_subset {A B A' B':Set} (hA'A: A' ⊆ A) (hB'B: B' ⊆ B) : A ∩ A' ⊆ A ∩ B := inst✝:SetTheoryA:SetB:SetA':SetB':SethA'A:A' ⊆ AhB'B:B' ⊆ B⊢ A ∩ A' ⊆ A ∩ B All goals completed! 🐙

Exercise 3.1.12.

theorem declaration uses 'sorry'SetTheory.Set.subset_diff_subset_counter : ∃ (A B A' B':Set), (A' ⊆ A) ∧ (B' ⊆ B) ∧ ¬ (A \ A') ⊆ (B ∩ B') := inst✝:SetTheory⊢ ∃ A B A' B', A' ⊆ A ∧ B' ⊆ B ∧ ¬A \ A' ⊆ B ∩ B' All goals completed! 🐙/- Final part of Exercise 3.1.12: state and prove a reasonable substitute positive result for the above theorem that involves set differences . -/

Exercise 3.1.13

theorem declaration uses 'sorry'SetTheory.Set.singleton_iff (A:Set) (hA: A ≠ ∅) : ¬ ∃ B, B ⊂ A ↔ ∃ x, A = {x} := inst✝:SetTheoryA:SethA:A ≠ ∅⊢ ¬∃ B, B ⊂ A ↔ ∃ x, A = {x} All goals completed! 🐙end Chapter3