Lean library · module TopologyByExample.Theorems.DenseGeneralPosition
Dense subsets of the plane in general position
This file was written by Codex (OpenAI's AI model) working under the direction of David R. MacIver, who reviews it and is responsible for it.
Imports
definition planeDet
TopologyByExample.planeDet
The signed area determinant of three plane points.
def planeDet (a b c : ℝ × ℝ) : ℝ
:=
(b.1 - a.1) * (c.2 - a.2) - (b.2 - a.2) * (c.1 - a.1)
theorem exists_general_position_point
TopologyByExample.exists_general_position_point
A rectangle contains a point avoiding the first coordinates of a finite set and every nonvertical line through two points of that set.
theorem exists_general_position_point (s : Set (ℝ × ℝ)) (hs : s.Finite)
(a b c d : ℝ) (hab : a < b) (hcd : c < d) :
∃ p ∈ Ioo a b ×ˢ Ioo c d, p.1 ∉ Prod.fst '' s ∧
∀ q ∈ s, ∀ r ∈ s, q.1 ≠ r.1 → planeDet q r p ≠ 0
Proof
:= by
obtain ⟨x, hx, hxs⟩ := (Ioo_infinite hab).exists_notMem_finite (hs.image Prod.fst)
let H : (ℝ × ℝ) × (ℝ × ℝ) → ℝ := fun qr ↦
qr.1.2 + (x - qr.1.1) * (qr.2.2 - qr.1.2) / (qr.2.1 - qr.1.1)
obtain ⟨y, hy, hys⟩ := (Ioo_infinite hcd).exists_notMem_finite ((hs.prod hs).image H)
refine ⟨(x, y), ⟨hx, hy⟩, hxs, ?_⟩
intro q hq r hr hqr heq
apply hys
refine ⟨(q, r), ⟨hq, hr⟩, ?_⟩
dsimp [H]
have hn : r.1 - q.1 ≠ 0 := sub_ne_zero.mpr (Ne.symm hqr)
have he : (x - q.1) * (r.2 - q.2) / (r.1 - q.1) = y - q.2 := by
apply (div_eq_iff hn).mpr
dsimp [planeDet] at heq
nlinarith
rw [he]
ring
theorem exists_sequence_general_position
TopologyByExample.exists_sequence_general_position
A prescribed sequence of rectangles can be met by a sequence whose first coordinates are distinct and whose earlier pairs are noncollinear with each new point.
theorem exists_sequence_general_position
(a b c d : ℕ → ℝ) (hab : ∀ n, a n < b n) (hcd : ∀ n, c n < d n) :
∃ u : ℕ → ℝ × ℝ, Function.Injective (fun n ↦ (u n).1) ∧
(∀ n, u n ∈ Ioo (a n) (b n) ×ˢ Ioo (c n) (d n)) ∧
∀ k i j, i < k → j < k → i ≠ j → planeDet (u i) (u j) (u k) ≠ 0
Proof
:= by
classical
obtain ⟨u, hu⟩ := Set.seq_of_forall_finite_exists
(P := fun p s ↦ p ∈ Ioo (a s.ncard) (b s.ncard) ×ˢ
Ioo (c s.ncard) (d s.ncard) ∧ p.1 ∉ Prod.fst '' s ∧
∀ q ∈ s, ∀ r ∈ s, q.1 ≠ r.1 → planeDet q r p ≠ 0)
(fun s hs ↦ exists_general_position_point s hs _ _ _ _ (hab _) (hcd _))
have hinj : Function.Injective (fun n ↦ (u n).1) := by
intro i j hij
rcases lt_trichotomy i j with h | h | h
· exact False.elim ((hu j).2.1 ⟨u i, ⟨i, h, rfl⟩, hij⟩)
· exact h
· exact False.elim ((hu i).2.1 ⟨u j, ⟨j, h, rfl⟩, hij.symm⟩)
have hui : Function.Injective u := fun i j h ↦ hinj (congrArg Prod.fst h)
refine ⟨u, hinj, ?_, ?_⟩
· intro n
have hn : (u '' Iio n).ncard = n := by
rw [ncard_image_of_injective _ hui]
simp
simpa only [hn] using (hu n).1
· intro k i j hik hjk hij
exact (hu k).2.2 (u i) ⟨i, hik, rfl⟩ (u j) ⟨j, hjk, rfl⟩
(fun h ↦ hij (hinj h))
theorem exists_dense_sequence_general_position
TopologyByExample.exists_dense_sequence_general_position
There is a dense sequence of plane points with distinct first coordinates and no three collinear.
theorem exists_dense_sequence_general_position :
∃ u : ℕ → ℝ × ℝ, Function.Injective (fun n ↦ (u n).1) ∧ Dense (range u) ∧
∀ i j k, i ≠ j → j ≠ k → k ≠ i → planeDet (u i) (u j) (u k) ≠ 0
Proof
:= by
classical
let B := {q : (ℚ × ℚ) × (ℚ × ℚ) // q.1.1 < q.1.2 ∧ q.2.1 < q.2.2}
have : Nonempty B := ⟨⟨((0, 1), (0, 1)), by norm_num⟩⟩
obtain ⟨b, hb⟩ := exists_surjective_nat B
obtain ⟨u, hui, hu, hdet⟩ := exists_sequence_general_position
(fun n ↦ ((b n).val.1.1 : ℝ)) (fun n ↦ ((b n).val.1.2 : ℝ))
(fun n ↦ ((b n).val.2.1 : ℝ)) (fun n ↦ ((b n).val.2.2 : ℝ))
(fun n ↦ by exact_mod_cast (b n).property.1)
(fun n ↦ by exact_mod_cast (b n).property.2)
refine ⟨u, hui, ?_, ?_⟩
· apply dense_iff_inter_open.mpr
rintro U hU ⟨⟨x, y⟩, hxy⟩
obtain ⟨V, W, hV, hW, hx, hy, hVW⟩ := isOpen_prod_iff.mp hU x y hxy
obtain ⟨a, c, hac, hVac⟩ := exists_rat_Ioo_subset hV ⟨x, hx⟩
obtain ⟨d, f, hdf, hWdf⟩ := exists_rat_Ioo_subset hW ⟨y, hy⟩
obtain ⟨n, hn⟩ := hb ⟨((a, c), (d, f)), hac, hdf⟩
have hnU := hu n
rw [hn] at hnU
exact ⟨u n, hVW ⟨hVac hnU.1, hWdf hnU.2⟩, mem_range_self n⟩
· intro i j k hij hjk hki
have cyc (p q r : ℝ × ℝ) : planeDet p q r = planeDet q r p := by
dsimp [planeDet]
ring
by_cases hik : i < k
· by_cases hjk' : j < k
· exact hdet k i j hik hjk' hij
· rw [cyc, cyc]
exact hdet j k i (lt_of_le_of_ne (le_of_not_gt hjk') (Ne.symm hjk))
(hik.trans_le (le_of_not_gt hjk')) hki
· rw [cyc]
have hki' : k < i := lt_of_le_of_ne (le_of_not_gt hik) hki
by_cases hji : j < i
· exact hdet i j k hji hki' hjk
· rw [cyc]
exact hdet j k i (hki'.trans_le (le_of_not_gt hji))
(lt_of_le_of_ne (le_of_not_gt hji) hij) hki