mathematics_in_lean

My solutions for this book

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
  131. 131
  132. 132
  133. 133
  134. 134
  135. 135
  136. 136
  137. 137
  138. 138
  139. 139
  140. 140
  141. 141
  142. 142
  143. 143
  144. 144
  145. 145
  146. 146
  147. 147
  148. 148
  149. 149
  150. 150
  151. 151
  152. 152
  153. 153
  154. 154
  155. 155
  156. 156
  157. 157
  158. 158
  159. 159
  160. 160
  161. 161
  162. 162
  163. 163
  164. 164
  165. 165
  166. 166
  167. 167
  168. 168
  169. 169
  170. 170
  171. 171
  172. 172
  173. 173
  174. 174
  175. 175
  176. 176
  177. 177
  178. 178
  179. 179
  180. 180
  181. 181
  182. 182
import MIL.Common
import Mathlib.Topology.Instances.Real
import Mathlib.Analysis.NormedSpace.BanachSteinhaus

open Set Filter Topology

section
variable {X : Type*} [TopologicalSpace X]

example : IsOpen (univ : Set X) :=
  isOpen_univ

example : IsOpen ( : Set X) :=
  isOpen_empty

example {ι : Type*} {s : ι  Set X} (hs :  i, IsOpen (s i)) : IsOpen ( i, s i) :=
  isOpen_iUnion hs

example {ι : Type*} [Fintype ι] {s : ι  Set X} (hs :  i, IsOpen (s i)) :
    IsOpen ( i, s i) :=
  isOpen_iInter_of_finite hs

variable {Y : Type*} [TopologicalSpace Y]

example {f : X  Y} : Continuous f   s, IsOpen s  IsOpen (f ⁻¹' s) :=
  continuous_def

example {f : X  Y} {x : X} : ContinuousAt f x  map f (𝓝 x)  𝓝 (f x) :=
  Iff.rfl

example {f : X  Y} {x : X} : ContinuousAt f x   U  𝓝 (f x),  x in 𝓝 x, f x  U :=
  Iff.rfl

example {x : X} {s : Set X} : s  𝓝 x   t, t  s  IsOpen t  x  t :=
  mem_nhds_iff

example (x : X) : pure x  𝓝 x :=
  pure_le_nhds x

example (x : X) (P : X  Prop) (h :  y in 𝓝 x, P y) : P x :=
  h.self_of_nhds

example {P : X  Prop} {x : X} (h :  y in 𝓝 x, P y) :  y in 𝓝 x,  z in 𝓝 y, P z :=
  eventually_eventually_nhds.mpr h

#check TopologicalSpace.mkOfNhds

#check TopologicalSpace.nhds_mkOfNhds

example {α : Type*} (n : α  Filter α) (H₀ :  a, pure a  n a)
    (H :  a : α,  p : α  Prop, ( x in n a, p x)   y in n a,  x in n y, p x) :
     a,  s  n a,  t  n a, t  s   a'  t, s  n a' :=
  sorry

example {α : Type*} (n : α  Filter α) (H₀ :  a, pure a  n a)
    (H :  a : α,  p : α  Prop, ( x in n a, p x)   y in n a,  x in n y, p x) :
     a,  s  n a,  t  n a, t  s   a'  t, s  n a' := by
  intro a s s_in
  refine' { y | s  n y }, H a (fun x  x  s) s_in, _, by tauto
  rintro y (hy : s  n y)
  exact H₀ y hy

end

-- BOTH.
variable {X Y : Type*}

example (f : X  Y) : TopologicalSpace X  TopologicalSpace Y :=
  TopologicalSpace.coinduced f

example (f : X  Y) : TopologicalSpace Y  TopologicalSpace X :=
  TopologicalSpace.induced f

example (f : X  Y) (T_X : TopologicalSpace X) (T_Y : TopologicalSpace Y) :
    TopologicalSpace.coinduced f T_X  T_Y  T_X  TopologicalSpace.induced f T_Y :=
  coinduced_le_iff_le_induced

#check coinduced_compose

#check induced_compose

example {T T' : TopologicalSpace X} : T  T'   s, T'.IsOpen s  T.IsOpen s :=
  Iff.rfl

example (T_X : TopologicalSpace X) (T_Y : TopologicalSpace Y) (f : X  Y) :
    Continuous f  TopologicalSpace.coinduced f T_X  T_Y :=
  continuous_iff_coinduced_le

example {Z : Type*} (f : X  Y) (T_X : TopologicalSpace X) (T_Z : TopologicalSpace Z)
      (g : Y  Z) :
    @Continuous Y Z (TopologicalSpace.coinduced f T_X) T_Z g 
      @Continuous X Z T_X T_Z (g  f) := by
  rw [continuous_iff_coinduced_le, coinduced_compose, continuous_iff_coinduced_le]

example (ι : Type*) (X : ι  Type*) (T_X :  i, TopologicalSpace (X i)) :
    (Pi.topologicalSpace : TopologicalSpace ( i, X i)) =
       i, TopologicalSpace.induced (fun x  x i) (T_X i) :=
  rfl

example [TopologicalSpace X] [T2Space X] {u :   X} {a b : X} (ha : Tendsto u atTop (𝓝 a))
    (hb : Tendsto u atTop (𝓝 b)) : a = b :=
  tendsto_nhds_unique ha hb

example [TopologicalSpace X] [RegularSpace X] (a : X) :
    (𝓝 a).HasBasis (fun s : Set X  s  𝓝 a  IsClosed s) id :=
  closed_nhds_basis a

example [TopologicalSpace X] {x : X} :
    (𝓝 x).HasBasis (fun t : Set X  t  𝓝 x  IsOpen t) id :=
  nhds_basis_opens' x

theorem aux {X Y A : Type*} [TopologicalSpace X] {c : A  X}
      {f : A  Y} {x : X} {F : Filter Y}
      (h : Tendsto f (comap c (𝓝 x)) F) {V' : Set Y} (V'_in : V'  F) :
     V  𝓝 x, IsOpen V  c ⁻¹' V  f ⁻¹' V' := by
  simpa [and_assoc] using ((nhds_basis_opens' x).comap c).tendsto_left_iff.mp h V' V'_in

example [TopologicalSpace X] [TopologicalSpace Y] [T3Space Y] {A : Set X}
    (hA :  x, x  closure A) {f : A  Y} (f_cont : Continuous f)
    (hf :  x : X,  c : Y, Tendsto f (comap () (𝓝 x)) (𝓝 c)) :
     φ : X  Y, Continuous φ   a : A, φ a = f a := by
  choose φ  using hf
  use φ
  constructor
  · rw [continuous_iff_continuousAt]
    intro x
    suffices  V'  𝓝 (φ x), IsClosed V'  φ ⁻¹' V'  𝓝 x by
      simpa [ContinuousAt, (closed_nhds_basis (φ x)).tendsto_right_iff]
    intro V' V'_in V'_closed
    obtain V, V_in, V_op, hV :  V  𝓝 x, IsOpen V  () ⁻¹' V  f ⁻¹' V' := aux ( x) V'_in
    suffices :  y  V, φ y  V'
    exact mem_of_superset V_in this
    intro y y_in
    have hVx : V  𝓝 y := V_op.mem_nhds y_in
    haveI : (comap (() : A  X) (𝓝 y)).NeBot := by simpa [mem_closure_iff_comap_neBot] using hA y
    apply V'_closed.mem_of_tendsto ( y)
    exact mem_of_superset (preimage_mem_comap hVx) hV
  · intro a
    have lim : Tendsto f (𝓝 a) (𝓝 (φ a)) := by simpa [nhds_induced] using  a
    exact tendsto_nhds_unique lim f_cont.continuousAt

example [TopologicalSpace X] [FirstCountableTopology X]
      {s : Set X} {a : X} :
    a  closure s   u :   X, ( n, u n  s)  Tendsto u atTop (𝓝 a) :=
  mem_closure_iff_seq_limit

variable [TopologicalSpace X]

example {F : Filter X} {x : X} : ClusterPt x F  NeBot (𝓝 x  F) :=
  Iff.rfl

example {s : Set X} :
    IsCompact s   (F : Filter X) [NeBot F], F  𝓟 s   a  s, ClusterPt a F :=
  Iff.rfl

example [FirstCountableTopology X] {s : Set X} {u :   X} (hs : IsCompact s)
    (hu :  n, u n  s) :  a  s,  φ :   , StrictMono φ  Tendsto (u  φ) atTop (𝓝 a) :=
  hs.tendsto_subseq hu

variable [TopologicalSpace Y]

example {x : X} {F : Filter X} {G : Filter Y} (H : ClusterPt x F) {f : X  Y}
    (hfx : ContinuousAt f x) (hf : Tendsto f F G) : ClusterPt (f x) G :=
  ClusterPt.map H hfx hf

example [TopologicalSpace Y] {f : X  Y} (hf : Continuous f) {s : Set X} (hs : IsCompact s) :
    IsCompact (f '' s) := by
  intro F F_ne F_le
  have map_eq : map f (𝓟 s  comap f F) = 𝓟 (f '' s)  F := by rw [Filter.push_pull, map_principal]
  have Hne : (𝓟 s  comap f F).NeBot := by
    apply NeBot.of_map
    rwa [map_eq, inf_of_le_right F_le]
  have Hle : 𝓟 s  comap f F  𝓟 s := inf_le_left
  rcases hs Hle with x, x_in, hx
  refine' f x, mem_image_of_mem f x_in, _
  apply hx.map hf.continuousAt
  rw [Tendsto, map_eq]
  exact inf_le_right

example {ι : Type*} {s : Set X} (hs : IsCompact s) (U : ι  Set X) (hUo :  i, IsOpen (U i))
    (hsU : s   i, U i) :  t : Finset ι, s   i  t, U i :=
  hs.elim_finite_subcover U hUo hsU