My solutions to Tao's Analysis I, formalized in Lean

Section 3.3 solutions (#6)

Changed files
+321 -32
analysis
Analysis
+321 -32
analysis/Analysis/Section_3_3.lean
··· 216 216 abbrev SetTheory.Set.f_3_3_11 (X:Set) : Function (∅:Set) X := 217 217 Function.mk (fun _ _ ↦ True) (by intro ⟨ x,hx ⟩; simp at hx) 218 218 219 - theorem SetTheory.Set.empty_function_unique {X: Set} (f g: Function (∅:Set) X) : f = g := by sorry 219 + theorem SetTheory.Set.empty_function_unique {X: Set} (f g: Function (∅:Set) X) : f = g := by 220 + ext xe 221 + have := xe.property 222 + have := not_mem_empty xe 223 + contradiction 220 224 221 225 /-- Definition 3.3.13 (Composition) -/ 222 226 noncomputable abbrev Function.comp {X Y Z: Set} (g: Function Y Z) (f: Function X Y) : ··· 409 413 Exercise 3.3.1. Although a proof operating directly on functions would be shorter, 410 414 the spirit of the exercise is to show these using the `Function.eq_iff` definition. 411 415 -/ 412 - theorem Function.refl {X Y:Set} (f: Function X Y) : f = f := by sorry 416 + theorem Function.refl {X Y:Set} (f: Function X Y) : f = f := by 417 + rw [Function.eq_iff] 418 + intro x 419 + rfl 413 420 414 - theorem Function.symm {X Y:Set} (f g: Function X Y) : f = g ↔ g = f := by sorry 421 + theorem Function.symm {X Y:Set} (f g: Function X Y) : f = g ↔ g = f := by 422 + repeat rw [Function.eq_iff] 423 + constructor 424 + · intro h x 425 + exact (h x).symm 426 + intro h x 427 + exact (h x).symm 415 428 416 - theorem Function.trans {X Y:Set} {f g h: Function X Y} (hfg: f = g) (hgh: g = h) : f = h := by sorry 429 + theorem Function.trans {X Y:Set} {f g h: Function X Y} (hfg: f = g) (hgh: g = h) : f = h := by 430 + rw [Function.eq_iff] at * 431 + intro x 432 + specialize_all x 433 + rw [hfg, hgh] 417 434 418 435 theorem Function.comp_congr {X Y Z:Set} {f f': Function X Y} (hff': f = f') {g g': Function Y Z} 419 - (hgg': g = g') : g ○ f = g' ○ f' := by sorry 436 + (hgg': g = g') : g ○ f = g' ○ f' := by 437 + rw [Function.eq_iff] at * 438 + intro x 439 + specialize_all x 440 + simp only [comp_eval, hgg', hff'] 420 441 421 442 /-- Exercise 3.3.2 -/ 422 443 theorem Function.comp_of_inj {X Y Z:Set} {f: Function X Y} {g : Function Y Z} (hf: f.one_to_one) 423 - (hg: g.one_to_one) : (g ○ f).one_to_one := by sorry 444 + (hg: g.one_to_one) : (g ○ f).one_to_one := by 445 + rw [one_to_one_iff] at * 446 + intro x x' 447 + simp only [comp_eval] 448 + intro h 449 + apply hf 450 + apply hg 451 + exact h 424 452 425 453 theorem Function.comp_of_surj {X Y Z:Set} {f: Function X Y} {g : Function Y Z} (hf: f.onto) 426 - (hg: g.onto) : (g ○ f).onto := by sorry 454 + (hg: g.onto) : (g ○ f).onto := by 455 + rw [onto] at * 456 + intro x 457 + simp only [comp_eval] 458 + have ⟨z, hz⟩ := hg x 459 + have ⟨y, hy⟩ := hf z 460 + use y 461 + rw [hy, hz] 427 462 428 463 /-- 429 464 Exercise 3.3.3 - fill in the sorrys in the statements in a reasonable fashion. 430 465 -/ 431 - example (X: Set) : (SetTheory.Set.f_3_3_11 X).one_to_one ↔ sorry := by sorry 466 + example (X: Set) : (SetTheory.Set.f_3_3_11 X).one_to_one ↔ True := by 467 + rw [iff_true] 468 + intro x 469 + have := x.property 470 + have := SetTheory.Set.not_mem_empty x 471 + contradiction 432 472 433 - example (X: Set) : (SetTheory.Set.f_3_3_11 X).onto ↔ sorry := by sorry 473 + example (X: Set) : (SetTheory.Set.f_3_3_11 X).onto ↔ X = ∅ := by 474 + constructor 475 + · intro h 476 + by_contra h' 477 + rw [SetTheory.Set.eq_empty_iff_forall_notMem] at h' 478 + push_neg at h' 479 + obtain ⟨x, hx⟩ := h' 480 + rw [Function.onto] at h 481 + obtain ⟨y, hy⟩ := h ⟨x, hx⟩ 482 + have := y.property 483 + have := SetTheory.Set.not_mem_empty y 484 + contradiction 485 + intro h 486 + rw [Function.onto] 487 + intro x 488 + have := x.property 489 + simp only [h] at this 490 + have := SetTheory.Set.not_mem_empty x 491 + contradiction 434 492 435 - example (X: Set) : (SetTheory.Set.f_3_3_11 X).bijective ↔ sorry := by sorry 493 + example (X: Set) : (SetTheory.Set.f_3_3_11 X).bijective ↔ X = ∅ := by 494 + constructor 495 + · intro ⟨h1, h2⟩ 496 + rw [SetTheory.Set.eq_empty_iff_forall_notMem] 497 + by_contra h 498 + push_neg at h 499 + obtain ⟨x, hx⟩ := h 500 + rw [Function.onto] at h2 501 + have ⟨y, hy⟩ := h2 ⟨x, hx⟩ 502 + have := y.property 503 + have := SetTheory.Set.not_mem_empty y 504 + contradiction 505 + intro h 506 + constructor 507 + · rw [Function.one_to_one_iff] 508 + intro x 509 + have := x.property 510 + have := SetTheory.Set.not_mem_empty x 511 + contradiction 512 + rw [SetTheory.Set.eq_empty_iff_forall_notMem] at h 513 + rw [Function.onto] 514 + intro x 515 + have := x.property 516 + have := h x 517 + contradiction 436 518 437 519 /-- 438 520 Exercise 3.3.4. 439 521 -/ 440 522 theorem Function.comp_cancel_left {X Y Z:Set} {f f': Function X Y} {g : Function Y Z} 441 - (heq : g ○ f = g ○ f') (hg: g.one_to_one) : f = f' := by sorry 523 + (heq : g ○ f = g ○ f') (hg: g.one_to_one) : f = f' := by 524 + simp only [Function.eq_iff, Function.comp_eval, Function.one_to_one_iff] at * 525 + intro x 526 + specialize heq x 527 + apply hg at heq 528 + exact heq 529 + 530 + example : ∃ (X Y Z:Set) (f f' : Function X Y) (g : Function Y Z), g ○ f = g ○ f' ∧ f ≠ f' := by 531 + use Nat, Nat, Nat 532 + use Function.mk_fn (fun x ↦ 0), Function.mk_fn (fun x ↦ 1), Function.mk_fn (fun x ↦ 2) 533 + constructor 534 + · simp 535 + intro h 536 + simp [Function.eq_iff] at h 442 537 443 538 theorem Function.comp_cancel_right {X Y Z:Set} {f: Function X Y} {g g': Function Y Z} 444 - (heq : g ○ f = g' ○ f) (hf: f.onto) : g = g' := by sorry 539 + (heq : g ○ f = g' ○ f) (hf: f.onto) : g = g' := by 540 + simp only [Function.eq_iff, Function.comp_eval, Function.one_to_one_iff] at * 541 + intro y 542 + obtain ⟨x, hx⟩ := hf y 543 + specialize heq x 544 + rw [hx] at heq 545 + rw [heq] 546 + 547 + example : ∃ (X Y Z:Set) (f : Function X Y) (g g' : Function Y Z), g ○ f = g' ○ f ∧ g ≠ g' := by 548 + use Nat, Nat, Nat 549 + use Function.mk_fn (fun x ↦ 0), Function.mk_fn (fun x ↦ x), Function.mk_fn (fun x ↦ 0) 550 + constructor 551 + · simp 552 + intro h 553 + simp [Function.eq_iff] at h 554 + specialize h (1:Nat) (1:Nat).property 555 + norm_num at h 445 556 446 557 def Function.comp_cancel_left_without_hg : Decidable (∀ (X Y Z:Set) (f f': Function X Y) (g : Function Y Z) (heq : g ○ f = g ○ f'), f = f') := by 447 558 -- the first line of this construction should be either `apply isTrue` or `apply isFalse`. 448 - sorry 559 + apply isFalse 560 + push_neg 561 + use Nat, Nat, Nat 562 + use Function.mk_fn (fun x ↦ 1), Function.mk_fn (fun x ↦ 2), Function.mk_fn (fun x ↦ 0) 563 + simp [Function.eq_iff] 449 564 450 565 def Function.comp_cancel_right_without_hg : Decidable (∀ (X Y Z:Set) (f: Function X Y) (g g': Function Y Z) (heq : g ○ f = g' ○ f), g = g') := by 451 566 -- the first line of this construction should be either `apply isTrue` or `apply isFalse`. 452 - sorry 567 + apply isFalse 568 + push_neg 569 + use Nat, Nat, Nat 570 + use Function.mk_fn (fun x ↦ 0), Function.mk_fn (fun x ↦ x), Function.mk_fn (fun x ↦ 0) 571 + simp [Function.eq_iff] 572 + use (1:Nat), (1:Nat).property 573 + norm_num 453 574 454 575 /-- 455 576 Exercise 3.3.5. 456 577 -/ 457 578 theorem Function.comp_injective {X Y Z:Set} {f: Function X Y} {g : Function Y Z} (hinj : 458 - (g ○ f).one_to_one) : f.one_to_one := by sorry 579 + (g ○ f).one_to_one) : f.one_to_one := by 580 + simp only [Function.one_to_one_iff, Function.comp_eval] at * 581 + intro x x' h 582 + specialize hinj x x' 583 + apply hinj 584 + rw [h] 585 + 586 + example : ∃ (X Y Z:Set) (f: Function X Y) (g : Function Y Z), 587 + (g ○ f).one_to_one ∧ ¬g.one_to_one := by 588 + use Nat, Nat, Nat 589 + use Function.mk_fn (fun x ↦ (x:ℕ) * (2:ℕ)) 590 + use Function.mk_fn (fun x ↦ (x:ℕ) / (2:ℕ)) 591 + constructor 592 + · simp 593 + rw [Function.one_to_one_iff] 594 + push_neg 595 + use 0, 1 596 + simp 459 597 460 598 theorem Function.comp_surjective {X Y Z:Set} {f: Function X Y} {g : Function Y Z} 461 - (hinj : (g ○ f).onto) : g.onto := by sorry 599 + (hinj : (g ○ f).onto) : g.onto := by 600 + simp only [Function.onto, Function.comp_eval] at * 601 + intro z 602 + obtain ⟨x, hx⟩ := hinj z 603 + use f.to_fn x 604 + 605 + example : ∃ (X Y Z:Set) (f: Function X Y) (g : Function Y Z), 606 + (g ○ f).onto ∧ ¬f.onto := by 607 + use Nat, Nat, {0} 608 + use Function.mk_fn (fun x ↦ (x:ℕ) + (1:ℕ)) 609 + use Function.mk_fn (fun x ↦ ⟨0, by simp⟩) 610 + constructor 611 + · simp 612 + rw [Function.onto] 613 + push_neg 614 + use (0: ℕ) 615 + simp 462 616 463 617 def Function.comp_injective' : Decidable (∀ (X Y Z:Set) (f: Function X Y) (g : Function Y Z) (hinj : 464 618 (g ○ f).one_to_one), g.one_to_one) := by 465 619 -- the first line of this construction should be either `apply isTrue` or `apply isFalse`. 466 - sorry 620 + apply isFalse 621 + push_neg 622 + use {0}, Nat, Nat 623 + use Function.mk_fn (fun x ↦ 0), Function.mk_fn (fun x ↦ 0) 624 + simp only [one_to_one_iff] 625 + constructor 626 + · simp 627 + push_neg 628 + use 0, 1 629 + simp 467 630 468 631 def Function.comp_surjective' : Decidable (∀ (X Y Z:Set) (f: Function X Y) (g : Function Y Z) (hinj : 469 632 (g ○ f).onto), f.onto) := by 470 633 -- the first line of this construction should be either `apply isTrue` or `apply isFalse`. 471 - sorry 634 + apply isFalse 635 + push_neg 636 + use Nat, Nat, {0} 637 + use Function.mk_fn (fun x ↦ 0), Function.mk_fn (fun x ↦ ⟨0, by simp⟩) 638 + simp only [onto, eval_of, exists_const, Subtype.forall, SetTheory.Set.mem_singleton, Subtype.mk.injEq, 639 + forall_eq, not_forall, true_and] 640 + use (1: Nat), (1: Nat).property 641 + simp 472 642 473 643 /-- Exercise 3.3.6 -/ 474 644 theorem Function.inverse_comp_self {X Y: Set} {f: Function X Y} (h: f.bijective) (x: X) : 475 - (f.inverse h) (f x) = x := by sorry 645 + (f.inverse h) (f x) = x := by 646 + symm 647 + rw [Function.inverse_eval] 476 648 477 649 theorem Function.self_comp_inverse {X Y: Set} {f: Function X Y} (h: f.bijective) (y: Y) : 478 - f ((f.inverse h) y) = y := by sorry 650 + f ((f.inverse h) y) = y := by 651 + rw [←Function.inverse_eval] 479 652 480 653 theorem Function.inverse_bijective {X Y: Set} {f: Function X Y} (h: f.bijective) : 481 - (f.inverse h).bijective := by sorry 654 + (f.inverse h).bijective := by 655 + constructor 656 + · rw [one_to_one_iff] 657 + intro x x' hinj 658 + rwa [inverse_eval, self_comp_inverse] at hinj 659 + rw [onto] 660 + intro x 661 + use (f x) 662 + rw [inverse_comp_self] 482 663 483 664 theorem Function.inverse_inverse {X Y: Set} {f: Function X Y} (h: f.bijective) : 484 - (f.inverse h).inverse (f.inverse_bijective h) = f := by sorry 665 + (f.inverse h).inverse (f.inverse_bijective h) = f := by 666 + rw [eq_iff] 667 + intro x 668 + symm 669 + rw [inverse_eval, inverse_comp_self] 485 670 486 671 theorem Function.comp_bijective {X Y Z:Set} {f: Function X Y} {g : Function Y Z} (hf: f.bijective) 487 - (hg: g.bijective) : (g ○ f).bijective := by sorry 672 + (hg: g.bijective) : (g ○ f).bijective := by 673 + constructor 674 + · replace hf := hf.1 675 + replace hg := hg.1 676 + rw [one_to_one_iff] at * 677 + intro x x' h 678 + apply hf 679 + apply hg 680 + simp only [comp_eval] at h 681 + exact h 682 + replace hf := hf.2 683 + replace hg := hg.2 684 + rw [onto] at * 685 + intro z 686 + simp only [comp_eval] 687 + obtain ⟨y, hy⟩ := hg z 688 + obtain ⟨x, hx⟩ := hf y 689 + use x 690 + rw [hx, hy] 488 691 489 692 /-- Exercise 3.3.7 -/ 490 693 theorem Function.inv_of_comp {X Y Z:Set} {f: Function X Y} {g : Function Y Z} 491 694 (hf: f.bijective) (hg: g.bijective) : 492 - (g ○ f).inverse (Function.comp_bijective hf hg) = (f.inverse hf) ○ (g.inverse hg) := by sorry 695 + (g ○ f).inverse (Function.comp_bijective hf hg) = (f.inverse hf) ○ (g.inverse hg) := by 696 + rw [eq_iff] 697 + intro z 698 + simp only [eval, inverse_eval, comp_eval] 699 + rw [←comp_eval, self_comp_inverse] 493 700 494 701 /-- Exercise 3.3.8 -/ 495 702 abbrev Function.inclusion {X Y:Set} (h: X ⊆ Y) : ··· 498 705 abbrev Function.id (X:Set) : Function X X := Function.mk_fn (fun x ↦ x) 499 706 500 707 theorem Function.inclusion_id (X:Set) : 501 - Function.inclusion (SetTheory.Set.subset_self X) = Function.id X := by sorry 708 + Function.inclusion (SetTheory.Set.subset_self X) = Function.id X := by 709 + rw [eq_iff] 710 + intro x 711 + rfl 502 712 503 713 theorem Function.inclusion_comp (X Y Z:Set) (hXY: X ⊆ Y) (hYZ: Y ⊆ Z) : 504 - Function.inclusion hYZ ○ Function.inclusion hXY = Function.inclusion (SetTheory.Set.subset_trans hXY hYZ) := by sorry 714 + Function.inclusion hYZ ○ Function.inclusion hXY = Function.inclusion (SetTheory.Set.subset_trans hXY hYZ) := by 715 + rw [eq_iff] 716 + intro x 717 + simp only [eval_of] 505 718 506 - theorem Function.comp_id {A B:Set} (f: Function A B) : f ○ Function.id A = f := by sorry 719 + theorem Function.comp_id {A B:Set} (f: Function A B) : f ○ Function.id A = f := by 720 + rw [eq_iff] 721 + intro x 722 + simp only [eval_of] 507 723 508 - theorem Function.id_comp {A B:Set} (f: Function A B) : Function.id B ○ f = f := by sorry 724 + theorem Function.id_comp {A B:Set} (f: Function A B) : Function.id B ○ f = f := by 725 + rw [eq_iff] 726 + intro x 727 + simp only [eval_of] 509 728 510 729 theorem Function.comp_inv {A B:Set} (f: Function A B) (hf: f.bijective) : 511 - f ○ f.inverse hf = Function.id B := by sorry 730 + f ○ f.inverse hf = Function.id B := by 731 + rw [eq_iff] 732 + intro x 733 + simp only [eval_of] 734 + apply self_comp_inverse 512 735 513 736 theorem Function.inv_comp {A B:Set} (f: Function A B) (hf: f.bijective) : 514 - f.inverse hf ○ f = Function.id A := by sorry 737 + f.inverse hf ○ f = Function.id A := by 738 + rw [eq_iff] 739 + intro x 740 + simp only [eval_of] 741 + apply inverse_comp_self 515 742 516 743 open Classical in 517 744 theorem Function.glue {X Y Z:Set} (hXY: Disjoint X Y) (f: Function X Z) (g: Function Y Z) : 518 745 ∃! h: Function (X ∪ Y) Z, (h ○ Function.inclusion (SetTheory.Set.subset_union_left X Y) = f) 519 - ∧ (h ○ Function.inclusion (SetTheory.Set.subset_union_right X Y) = g) := by sorry 746 + ∧ (h ○ Function.inclusion (SetTheory.Set.subset_union_right X Y) = g) := by 747 + apply existsUnique_of_exists_of_unique 748 + · set fg: Function (X ∪ Y) Z := Function.mk_fn (fun xy ↦ 749 + if hxy : xy.val ∈ X then f ⟨xy.val, hxy⟩ 750 + else g ⟨xy.val, by aesop⟩) 751 + use fg 752 + constructor 753 + · rw [eq_iff] 754 + intro x 755 + have := x.property 756 + aesop 757 + rw [eq_iff] 758 + rw [disjoint_iff] at hXY 759 + change X ∩ Y = ∅ at hXY 760 + rw [SetTheory.Set.eq_empty_iff_forall_notMem] at hXY 761 + intro y 762 + specialize hXY y 763 + aesop 764 + intro fg1 fg2 ⟨hf1, hf2⟩ ⟨hg1, hg2⟩ 765 + rw [eq_iff] 766 + intro xy 767 + have hX : X ⊆ (X ∪ Y) := by apply SetTheory.Set.subset_union_left 768 + have hY : Y ⊆ (X ∪ Y) := by apply SetTheory.Set.subset_union_right 769 + simp only [eq_iff, comp_eval] at * 770 + by_cases hxy : xy.val ∈ X 771 + · set x : X := ⟨xy.val, hxy⟩ 772 + have : xy = inclusion hX x := by rw [Function.eval] 773 + rw [this, hf1, hg1] 774 + by_cases hxy : xy.val ∈ Y 775 + · set y : Y := ⟨xy.val, hxy⟩ 776 + have : xy = inclusion hY y := by rw [Function.eval] 777 + rw [this, hf2, hg2] 778 + have := xy.property 779 + aesop 520 780 521 781 open Classical in 522 782 theorem Function.glue' {X Y Z:Set} (f: Function X Z) (g: Function Y Z) 523 783 (hfg : ∀ x : ((X ∩ Y): Set), f ⟨x.val, by aesop⟩ = g ⟨x.val, by aesop⟩) : 524 784 ∃! h: Function (X ∪ Y) Z, (h ○ Function.inclusion (SetTheory.Set.subset_union_left X Y) = f) 525 - ∧ (h ○ Function.inclusion (SetTheory.Set.subset_union_right X Y) = g) := by sorry 785 + ∧ (h ○ Function.inclusion (SetTheory.Set.subset_union_right X Y) = g) := by 786 + apply existsUnique_of_exists_of_unique 787 + · set fg: Function (X ∪ Y) Z := Function.mk_fn (fun xy ↦ 788 + if hxy : xy.val ∈ X then f ⟨xy.val, hxy⟩ 789 + else g ⟨xy.val, by aesop⟩) 790 + use fg 791 + constructor 792 + · rw [eq_iff] 793 + intro x 794 + have := x.property 795 + aesop 796 + rw [eq_iff] 797 + intro y 798 + aesop 799 + intro fg1 fg2 ⟨hf1, hf2⟩ ⟨hg1, hg2⟩ 800 + rw [eq_iff] 801 + intro xy 802 + have hX : X ⊆ (X ∪ Y) := by apply SetTheory.Set.subset_union_left 803 + have hY : Y ⊆ (X ∪ Y) := by apply SetTheory.Set.subset_union_right 804 + simp only [eq_iff, comp_eval] at * 805 + by_cases hxy : xy.val ∈ X 806 + · set x : X := ⟨xy.val, hxy⟩ 807 + have : xy = inclusion hX x := by rw [Function.eval] 808 + rw [this, hf1, hg1] 809 + by_cases hxy : xy.val ∈ Y 810 + · set y : Y := ⟨xy.val, hxy⟩ 811 + have : xy = inclusion hY y := by rw [Function.eval] 812 + rw [this, hf2, hg2] 813 + have := xy.property 814 + aesop 526 815 527 816 end Chapter3