···34343535/-- Alternate definition of image using axiom of specification -/
3636theorem SetTheory.Set.image_eq_specify {X Y:Set} (f:X → Y) (S: Set) :
3737- image f S = Y.specify (fun y ↦ ∃ x:X, x.val ∈ S ∧ f x = y) := by sorry
3737+ image f S = Y.specify (fun y ↦ ∃ x:X, x.val ∈ S ∧ f x = y) := by
3838+ ext y
3939+ constructor
4040+ · intro h
4141+ rw [mem_image] at h
4242+ obtain ⟨x, hx, hxy⟩ := h
4343+ rw [specification_axiom'', ←hxy]
4444+ use (f x).property, x
4545+ intro h
4646+ rw [mem_image]
4747+ rw [specification_axiom''] at h
4848+ obtain ⟨hy, ⟨x, hx, hxy⟩⟩ := h
4949+ use x, hx
5050+ rw [hxy]
38513952/--
4053 Connection with Mathlib's notion of image. Note the need to utilize the `Subtype.val` coercion
···6982example : (fun n:ℤ ↦ n^2) '' {-1,0,1,2} = {0,1,4} := by aesop
70837184theorem SetTheory.Set.mem_image_of_eval {X Y:Set} (f:X → Y) (S: Set) (x:X) :
7272- x.val ∈ S → (f x).val ∈ image f S := by sorry
8585+ x.val ∈ S → (f x).val ∈ image f S := by
8686+ intro h
8787+ rw [mem_image]
8888+ use x
73897490theorem SetTheory.Set.mem_image_of_eval_counter :
7575- ∃ (X Y:Set) (f:X → Y) (S: Set) (x:X), ¬((f x).val ∈ image f S → x.val ∈ S) := by sorry
9191+ ∃ (X Y:Set) (f:X → Y) (S: Set) (x:X), ¬((f x).val ∈ image f S → x.val ∈ S) := by
9292+ use Nat, Nat, fun x ↦ 0, {((0:Nat):Object)}, 1
9393+ push_neg
9494+ simp only [mem_image, mem_singleton, and_true]
9595+ constructor
9696+ · use 0
9797+ simp [Subtype.coe_ne_coe]
76987799/--
78100 Definition 3.4.4 (inverse images).
···119141 all_goals simp
120142121143theorem SetTheory.Set.image_preimage_f_3_4_2 :
122122- image f_3_4_2 (preimage f_3_4_2 {1,2,3}) ≠ {1,2,3} := by sorry
144144+ image f_3_4_2 (preimage f_3_4_2 {1,2,3}) ≠ {1,2,3} := by
145145+ intro h
146146+ have : 1 ∉ image f_3_4_2 (preimage f_3_4_2 {1, 2, 3}) := by simp
147147+ simp_all
123148124149/-- Example 3.4.7 (using the Mathlib notion of preimage) -/
125150example : (fun n:ℤ ↦ n^2) ⁻¹' {0,1,4} = {-2,-1,0,1,2} := by
···129154 on_goal 3 => have : 2 ^ 2 = (4:ℤ) := (by norm_num); rw [←h, sq_eq_sq_iff_eq_or_eq_neg] at this
130155 all_goals aesop
131156132132-example : (fun n:ℤ ↦ n^2) ⁻¹' ((fun n:ℤ ↦ n^2) '' {-1,0,1,2}) ≠ {-1,0,1,2} := by sorry
157157+example : (fun n:ℤ ↦ n^2) ⁻¹' ((fun n:ℤ ↦ n^2) '' {-1,0,1,2}) ≠ {-1,0,1,2} := by
158158+ intro h
159159+ rw [Set.ext_iff] at h
160160+ specialize h (-2)
161161+ have : -2 ∉ ({-1, 0, 1, 2}: _root_.Set ℤ) := by simp
162162+ apply h.not.mpr this
163163+ simp
133164134165instance SetTheory.Set.inst_pow : Pow Set Set where
135166 pow := SetTheory.pow
···181212182213/-- Exercise 3.4.6 (i). One needs to provide a suitable definition of the power set here. -/
183214def SetTheory.Set.powerset (X:Set) : Set :=
184184- (({0,1} ^ X): Set).replace (P := sorry) (by sorry)
215215+ (({0,1} ^ X): Set).replace (P := fun F Y ↦
216216+ ∃ f : X → ({0,1}: Set), F = (f : Object) ∧ Y = (preimage f {1})
217217+ ) (by aesop)
185218186219open Classical in
187220/-- Exercise 3.4.6 (i) -/
188221@[simp]
189222theorem SetTheory.Set.mem_powerset {X:Set} (x:Object) :
190190- x ∈ powerset X ↔ ∃ Y:Set, x = Y ∧ Y ⊆ X := by sorry
223223+ x ∈ powerset X ↔ ∃ Y:Set, x = Y ∧ Y ⊆ X := by
224224+ rw [powerset, replacement_axiom]
225225+ constructor
226226+ · rintro ⟨_, ⟨f, _, hfx⟩⟩
227227+ use preimage f {1}, hfx
228228+ simp only [subset_def, mem_preimage']
229229+ rintro _ ⟨a, ⟨rfl, _⟩⟩
230230+ use a.property
231231+ intro h
232232+ obtain ⟨Y, rfl, _⟩ := h
233233+ let f : X → ({0,1}: Set) := fun x ↦
234234+ if x.val ∈ Y then ⟨1, by simp⟩
235235+ else ⟨0, by simp⟩
236236+ have hf := (powerset_axiom _).mpr (by use f)
237237+ use ⟨_, hf⟩, f
238238+ constructor
239239+ · rfl
240240+ congr
241241+ apply Set.ext
242242+ simp only [mem_preimage']
243243+ aesop
191244192245/-- Lemma 3.4.10 -/
193246theorem SetTheory.Set.exists_powerset (X:Set) :
···227280/-- Example 3.4.12 -/
228281theorem SetTheory.Set.example_3_4_12 :
229282 union { (({2,3}:Set):Object), (({3,4}:Set):Object), (({4,5}:Set):Object) } = {2,3,4,5} := by
230230- sorry
283283+ apply Set.ext
284284+ simp only [union_axiom, Insert.insert]
285285+ aesop
231286232287/-- Connection with Mathlib union -/
233288theorem SetTheory.Set.union_eq (A: Set) :
···265320 (iUnion I A : _root_.Set Object) = ⋃ α, (A α: _root_.Set Object) := by
266321 ext; simp only [mem_iUnion, _root_.Set.mem_setOf_eq, _root_.Set.mem_iUnion]
267322268268-theorem SetTheory.Set.iUnion_of_empty (A: (∅:Set) → Set) : iUnion (∅:Set) A = ∅ := by sorry
323323+theorem SetTheory.Set.iUnion_of_empty (A: (∅:Set) → Set) : iUnion (∅:Set) A = ∅ := by
324324+ ext
325325+ simp only [not_mem_empty, iff_false, mem_iUnion]
326326+ push_neg
327327+ intro α
328328+ have := α.property
329329+ aesop
269330270331/-- Indexed intersection -/
271332noncomputable abbrev SetTheory.Set.nonempty_choose {I:Set} (hI: I ≠ ∅) : I :=
···279340280341theorem SetTheory.Set.mem_iInter {I:Set} (hI: I ≠ ∅) (A: I → Set) (x:Object) :
281342 x ∈ iInter I hI A ↔ ∀ α:I, x ∈ A α := by
282282- sorry
343343+ constructor
344344+ · intro h
345345+ rw [specification_axiom''] at h
346346+ exact h.2
347347+ intro h
348348+ rw [specification_axiom'']
349349+ use h (nonempty_choose hI)
283350284351/-- Exercise 3.4.1 -/
285352theorem SetTheory.Set.preimage_eq_image_of_inv {X Y V:Set} (f:X → Y) (f_inv: Y → X)
286353 (hf: Function.LeftInverse f_inv f ∧ Function.RightInverse f_inv f) (hV: V ⊆ Y) :
287287- image f_inv V = preimage f V := by sorry
354354+ image f_inv V = preimage f V := by
355355+ ext
356356+ simp only [mem_image, mem_preimage']
357357+ constructor
358358+ · rintro ⟨y, hy, rfl⟩
359359+ use (f_inv y), rfl
360360+ rwa [hf.2]
361361+ rintro ⟨x, rfl, hx⟩
362362+ use (f x), hx
363363+ rw [hf.1]
288364289365/- Exercise 3.4.2. State and prove an assertion connecting `preimage f (image f S)` and `S`. -/
290290--- theorem SetTheory.Set.preimage_of_image {X Y:Set} (f:X → Y) (S: Set) (hS: S ⊆ X) : sorry := by sorry
366366+theorem SetTheory.Set.preimage_of_image {X Y:Set} (f:X → Y) (S: Set) (hS: S ⊆ X) :
367367+ S ⊆ preimage f (image f S) := by
368368+ simp only [subset_def, mem_preimage', mem_image] at *
369369+ intro x xs
370370+ let x': X := ⟨x, hS x xs⟩
371371+ use x', rfl, x'
291372292373/- Exercise 3.4.2. State and prove an assertion connecting `image f (preimage f U)` and `U`.
293374Interestingly, it is not needed for U to be a subset of Y. -/
294294--- theorem SetTheory.Set.image_of_preimage {X Y:Set} (f:X → Y) (U: Set) : sorry := by sorry
375375+theorem SetTheory.Set.image_of_preimage {X Y:Set} (f:X → Y) (U: Set) :
376376+ image f (preimage f U) ⊆ U := by
377377+ simp only [subset_def, mem_image]
378378+ rintro y ⟨x, hx, rfl⟩
379379+ rwa [mem_preimage] at hx
295380296381/- Exercise 3.4.2. State and prove an assertion connecting `preimage f (image f (preimage f U))` and `preimage f U`.
297382Interestingly, it is not needed for U to be a subset of Y.-/
298298--- theorem SetTheory.Set.preimage_of_image_of_preimage {X Y:Set} (f:X → Y) (U: Set) : sorry := by sorry
383383+theorem SetTheory.Set.preimage_of_image_of_preimage {X Y:Set} (f:X → Y) (U: Set) :
384384+ preimage f (image f (preimage f U)) = preimage f U := by
385385+ aesop
299386300387/--
301388 Exercise 3.4.3.
302389-/
303390theorem SetTheory.Set.image_of_inter {X Y:Set} (f:X → Y) (A B: Set) :
304304- image f (A ∩ B) ⊆ (image f A) ∩ (image f B) := by sorry
391391+ image f (A ∩ B) ⊆ (image f A) ∩ (image f B) := by
392392+ simp only [subset_def]
393393+ aesop
305394306395theorem SetTheory.Set.image_of_diff {X Y:Set} (f:X → Y) (A B: Set) :
307307- (image f A) \ (image f B) ⊆ image f (A \ B) := by sorry
396396+ (image f A) \ (image f B) ⊆ image f (A \ B) := by
397397+ simp only [subset_def, mem_image, mem_inter, mem_sdiff]
398398+ rintro y ⟨⟨x, ⟨h1, h2⟩⟩, h'⟩
399399+ have : (x: Object) ∉ B := by contrapose! h'; use x
400400+ use x, ⟨h1, this⟩
308401309402theorem SetTheory.Set.image_of_union {X Y:Set} (f:X → Y) (A B: Set) :
310310- image f (A ∪ B) = (image f A) ∪ (image f B) := by sorry
403403+ image f (A ∪ B) = (image f A) ∪ (image f B) := by
404404+ aesop
311405312406def SetTheory.Set.image_of_inter' : Decidable (∀ X Y:Set, ∀ f:X → Y, ∀ A B: Set, image f (A ∩ B) = (image f A) ∩ (image f B)) := by
313407 -- The first line of this construction should be either `apply isTrue` or `apply isFalse`
314314- sorry
408408+ apply isFalse
409409+ push_neg
410410+ let f : nat → nat := fun x ↦ 0
411411+ use nat, nat, f, {1}, {2}
412412+ intro h
413413+ rw [show ({1} ∩ {2}: Set) = ∅ by apply ext; simp] at h
414414+ rw [show (image f ∅) = ∅ by apply ext; simp [mem_image]] at h
415415+ symm at h
416416+ rw [eq_empty_iff_forall_notMem] at h
417417+ contrapose! h
418418+ simp only [mem_inter, mem_image, f]
419419+ use 0
420420+ constructor
421421+ · use 1
422422+ norm_num
423423+ use 2
424424+ norm_num
315425316426def SetTheory.Set.image_of_diff' : Decidable (∀ X Y:Set, ∀ f:X → Y, ∀ A B: Set, image f (A \ B) = (image f A) \ (image f B)) := by
317427 -- The first line of this construction should be either `apply isTrue` or `apply isFalse`
318318- sorry
428428+ apply isFalse
429429+ push_neg
430430+ let f : nat → nat := fun x ↦ 0
431431+ use nat, nat, f, {1, 2}, {2}
432432+ rw [show ({1, 2}: Set) \ {2} = {1} by apply ext; aesop]
433433+ intro h
434434+ rw [Set.ext_iff] at h
435435+ specialize h 0
436436+ have : 0 ∈ image f {1} := by rw [mem_image]; use 1; simp [f]
437437+ have : 0 ∈ image f {2} := by rw [mem_image]; use 2; simp [f]
438438+ simp_all [f]
319439320440/-- Exercise 3.4.4 -/
321441theorem SetTheory.Set.preimage_of_inter {X Y:Set} (f:X → Y) (A B: Set) :
322322- preimage f (A ∩ B) = (preimage f A) ∩ (preimage f B) := by sorry
442442+ preimage f (A ∩ B) = (preimage f A) ∩ (preimage f B) := by
443443+ aesop
323444324445theorem SetTheory.Set.preimage_of_union {X Y:Set} (f:X → Y) (A B: Set) :
325325- preimage f (A ∪ B) = (preimage f A) ∪ (preimage f B) := by sorry
446446+ preimage f (A ∪ B) = (preimage f A) ∪ (preimage f B) := by
447447+ aesop
326448327449theorem SetTheory.Set.preimage_of_diff {X Y:Set} (f:X → Y) (A B: Set) :
328328- preimage f (A \ B) = (preimage f A) \ (preimage f B) := by sorry
450450+ preimage f (A \ B) = (preimage f A) \ (preimage f B) := by
451451+ aesop
329452330453/-- Exercise 3.4.5 -/
331454theorem SetTheory.Set.image_preimage_of_surj {X Y:Set} (f:X → Y) :
332332- (∀ S, S ⊆ Y → image f (preimage f S) = S) ↔ Function.Surjective f := by sorry
455455+ (∀ S, S ⊆ Y → image f (preimage f S) = S) ↔ Function.Surjective f := by
456456+ constructor
457457+ · intro h y
458458+ simp only [subset_def, Set.ext_iff, mem_singleton, mem_image] at h
459459+ specialize h _ (by aesop) y
460460+ obtain ⟨x, ⟨_, hx⟩⟩ := h.mpr (by aesop)
461461+ use x, by rwa [coe_inj] at hx
462462+ intro h S hS
463463+ apply ext
464464+ intro y
465465+ simp only [mem_image, mem_preimage]
466466+ constructor
467467+ · rintro ⟨x, ⟨hx, rfl⟩⟩
468468+ exact hx
469469+ intro hy
470470+ obtain ⟨x, hx⟩ := h ⟨y, hS y hy⟩
471471+ use x, by rwa [hx], by rw [hx]
333472334473/-- Exercise 3.4.5 -/
335474theorem SetTheory.Set.preimage_image_of_inj {X Y:Set} (f:X → Y) :
336336- (∀ S, S ⊆ X → preimage f (image f S) = S) ↔ Function.Injective f := by sorry
475475+ (∀ S, S ⊆ X → preimage f (image f S) = S) ↔ Function.Injective f := by
476476+ constructor
477477+ · intro h x1 x2 hf
478478+ simp only [subset_def] at h
479479+ have hx: ((f x2): Object) ∈ image f {(x2: Object)} := by rw [mem_image]; aesop
480480+ rwa [←hf, ←mem_preimage, h _ (by aesop), mem_singleton, coe_inj] at hx
481481+ intro h S hS
482482+ ext x
483483+ constructor
484484+ · simp only [mem_preimage', mem_image]
485485+ rintro ⟨x1, rfl, x2, hx2, heq⟩
486486+ rw [coe_inj] at heq
487487+ rwa [←h heq]
488488+ intro hx
489489+ simp only [mem_preimage', mem_image]
490490+ use ⟨x, hS x hx⟩, rfl, ⟨x, hS x hx⟩
337491338492/-- Helper lemma for Exercise 3.4.7. -/
339493@[simp]
···349503/-- Exercise 3.4.7 -/
350504theorem SetTheory.Set.partial_functions {X Y:Set} :
351505 ∃ Z:Set, ∀ F:Object, F ∈ Z ↔ ∃ X' Y':Set, X' ⊆ X ∧ Y' ⊆ Y ∧ ∃ f: X' → Y', F = f := by
352352- sorry
506506+ use union (Y.powerset.replace (P := fun oY' outer ↦
507507+ outer = union (X.powerset.replace (P := fun oX' inner ↦
508508+ ∃ (X' Y' : Set),
509509+ oX'.val = X' ∧
510510+ oY'.val = Y' ∧
511511+ inner = (Y' ^ X': Set)
512512+ ) (by simp_all))
513513+ ) (by simp_all))
514514+ intro F
515515+ constructor
516516+ · intro hF
517517+ simp only [mem_union_powerset_replace_iff, EmbeddingLike.apply_eq_iff_eq] at hF
518518+ obtain ⟨⟨oY', hY'⟩, _, rfl, hF⟩ := hF
519519+ simp only [mem_union_powerset_replace_iff, EmbeddingLike.apply_eq_iff_eq] at hF
520520+ obtain ⟨⟨oX', hX'⟩, Y'X', hF, hF'⟩ := hF
521521+ simp only [EmbeddingLike.apply_eq_iff_eq] at hF
522522+ obtain ⟨X', Y', rfl, rfl, rfl⟩ := hF
523523+ simp_all only [mem_powerset', powerset_axiom]
524524+ obtain ⟨f, hF⟩ := hF'
525525+ use X', Y'
526526+ use hX', hY'
527527+ use f, hF.symm
528528+ rintro ⟨X', Y', hX', hY', f, rfl⟩
529529+ simp_all [mem_union_powerset_replace_iff, EmbeddingLike.apply_eq_iff_eq,
530530+ exists_eq_left, Subtype.exists]
531531+ use Y', by simp_all
532532+ use X', by simp_all
533533+ use Y' ^ X', by simp_all
534534+ rw [powerset_axiom]
535535+ use f
353536354537/--
355538 Exercise 3.4.8. The point of this exercise is to prove it without using the
356539 pairwise union operation `∪`.
357540-/
358541theorem SetTheory.Set.union_pair_exists (X Y:Set) : ∃ Z:Set, ∀ x, x ∈ Z ↔ (x ∈ X ∨ x ∈ Y) := by
359359- sorry
542542+ use union {(X: Object), (Y: Object)}
543543+ simp [union_axiom]
544544+ aesop
360545361546/-- Exercise 3.4.9 -/
362547theorem SetTheory.Set.iInter'_insensitive {I:Set} (β β':I) (A: I → Set) :
363363- iInter' I β A = iInter' I β' A := by sorry
548548+ iInter' I β A = iInter' I β' A := by
549549+ ext
550550+ simp_all
364551365552/-- Exercise 3.4.10 -/
366553theorem SetTheory.Set.union_iUnion {I J:Set} (A: (I ∪ J:Set) → Set) :
367554 iUnion I (fun α ↦ A ⟨ α.val, by simp [α.property]⟩)
368555 ∪ iUnion J (fun α ↦ A ⟨ α.val, by simp [α.property]⟩)
369369- = iUnion (I ∪ J) A := by sorry
556556+ = iUnion (I ∪ J) A := by
557557+ ext
558558+ simp only [mem_iUnion, mem_union]
559559+ aesop
370560371561/-- Exercise 3.4.10 -/
372372-theorem SetTheory.Set.union_of_nonempty {I J:Set} (hI: I ≠ ∅) (hJ: J ≠ ∅) : I ∪ J ≠ ∅ := by sorry
562562+theorem SetTheory.Set.union_of_nonempty {I J:Set} (hI: I ≠ ∅) (hJ: J ≠ ∅) : I ∪ J ≠ ∅ := by
563563+ intro h
564564+ simp_all [Set.ext_iff]
373565374566/-- Exercise 3.4.10 -/
375567theorem SetTheory.Set.inter_iInter {I J:Set} (hI: I ≠ ∅) (hJ: J ≠ ∅) (A: (I ∪ J:Set) → Set) :
376568 iInter I hI (fun α ↦ A ⟨ α.val, by simp [α.property]⟩)
377569 ∩ iInter J hJ (fun α ↦ A ⟨ α.val, by simp [α.property]⟩)
378378- = iInter (I ∪ J) (union_of_nonempty hI hJ) A := by sorry
570570+ = iInter (I ∪ J) (union_of_nonempty hI hJ) A := by
571571+ ext x
572572+ simp only [mem_iInter, mem_inter]
573573+ aesop
379574380575/-- Exercise 3.4.11 -/
381576theorem SetTheory.Set.compl_iUnion {X I: Set} (hI: I ≠ ∅) (A: I → Set) :
382382- X \ iUnion I A = iInter I hI (fun α ↦ X \ A α) := by sorry
577577+ X \ iUnion I A = iInter I hI (fun α ↦ X \ A α) := by
578578+ apply ext; intro x
579579+ simp only [mem_sdiff, mem_iUnion]
580580+ aesop
383581384582/-- Exercise 3.4.11 -/
385583theorem SetTheory.Set.compl_iInter {X I: Set} (hI: I ≠ ∅) (A: I → Set) :
386386- X \ iInter I hI A = iUnion I (fun α ↦ X \ A α) := by sorry
584584+ X \ iInter I hI A = iUnion I (fun α ↦ X \ A α) := by
585585+ ext
586586+ simp only [mem_sdiff, mem_iInter, mem_iUnion]
587587+ aesop
387588388589end Chapter3