Lean library · module TopologyByExample.Theorems.RectangleIVT

A two-dimensional intermediate value theorem

Source file

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

theorem sign_endpoints

TopologyByExample.RectangleIVT.sign_endpoints

The sign of a continuous nonzero real function agrees at the interval endpoints.

theorem sign_endpoints {f : unitInterval → ℝ} (hf : Continuous f)
    (hn : ∀ t, f t ≠ 0) : SignType.sign (f 0) = SignType.sign (f 1)
Proof
:=
  isPreconnected_univ.sign_eq_of_continuousOn hf.continuousOn
    (fun t _ ↦ hn t) (mem_univ 0) (mem_univ 1)

theorem exists_square_root

TopologyByExample.RectangleIVT.exists_square_root

A nonvanishing complex function on the closed square has a continuous square root.

theorem exists_square_root (f : C(unitInterval × unitInterval, ℂ))
    (hn : ∀ z, f z ≠ 0) :
    ∃ r : C(unitInterval × unitInterval, ℂ), ∀ z, r z ^ 2 = f z
Proof
:= by
  let : ContractibleSpace unitInterval :=
    (convex_Icc (0 : ℝ) 1).contractibleSpace ⟨0, by simp⟩
  let : LocallyPathConnectedSpace unitInterval :=
    (convex_Icc (0 : ℝ) 1).locallyPathConnectedSpace
  let : ContractibleSpace (univ : Set (unitInterval × unitInterval)) :=
    (Homeomorph.Set.univ _).contractibleSpace_iff.mpr inferInstance
  have hs : IsSimplyConnected (univ : Set (unitInterval × unitInterval)) := by
    unfold IsSimplyConnected
    infer_instance
  obtain ⟨r, hr, he⟩ := Complex.exists_continuousOn_pow_eq hs isOpen_univ
    f.continuous.continuousOn (by
      rintro ⟨z, _, hz⟩
      exact hn z hz) (n := 2) (by decide)
  exact ⟨⟨r, continuousOn_univ.mp hr⟩, he⟩

theorem exists_zero_of_strict_boundary_signs

TopologyByExample.RectangleIVT.exists_zero_of_strict_boundary_signs

Strict opposite signs of the real and imaginary parts on opposite square edges force a zero in the closed square.

theorem exists_zero_of_strict_boundary_signs (f : C(unitInterval × unitInterval, ℂ))
    (hleft : ∀ t, (f (0, t)).re < 0) (hright : ∀ t, 0 < (f (1, t)).re)
    (hbottom : ∀ t, (f (t, 0)).im < 0) (htop : ∀ t, 0 < (f (t, 1)).im) :
    ∃ z, f z = 0
Proof
:= by
  classical
  by_contra hn
  push Not at hn
  obtain ⟨r, hr⟩ := exists_square_root f hn
  have hre (z) : (r z).re ^ 2 - (r z).im ^ 2 = (f z).re := by
    simpa [pow_two, Complex.mul_re] using congrArg Complex.re (hr z)
  have him (z) : 2 * (r z).re * (r z).im = (f z).im := by
    have h := congrArg Complex.im (hr z)
    simp only [pow_two, Complex.mul_im] at h
    nlinarith
  have hb : ∀ t, (r (t, 0)).im ≠ 0 := by
    intro t he
    have := him (t, 0)
    have := hbottom t
    rw [he] at *
    linarith
  have hl : ∀ t, (r (0, t)).im ≠ 0 := by
    intro t he
    have := hre (0, t)
    have := hleft t
    rw [he] at *
    nlinarith [sq_nonneg (r (0, t)).re]
  have ht : ∀ t, (r (t, 1)).re ≠ 0 := by
    intro t he
    have := him (t, 1)
    have := htop t
    rw [he] at *
    linarith
  have hh : ∀ t, (r (1, t)).re ≠ 0 := by
    intro t he
    have := hre (1, t)
    have := hright t
    rw [he] at *
    nlinarith [sq_nonneg (r (1, t)).im]
  have sb := sign_endpoints (f := fun t ↦ (r (t, 0)).im) (by fun_prop) hb
  have sl := sign_endpoints (f := fun t ↦ (r (0, t)).im) (by fun_prop) hl
  have st := sign_endpoints (f := fun t ↦ (r (t, 1)).re) (by fun_prop) ht
  have sh := sign_endpoints (f := fun t ↦ (r (1, t)).re) (by fun_prop) hh
  have sr := sh.trans st.symm
  have si := sb.symm.trans sl
  have he : SignType.sign (f (1, 0)).im = SignType.sign (f (0, 1)).im := by
    rw [← him (1, 0), ← him (0, 1)]
    simp only [sign_mul, sr, si]
  rw [sign_neg (hbottom 1), sign_pos (htop 0)] at he
  contradiction

theorem not_totally_disconnected_zero_set

TopologyByExample.RectangleIVT.not_totally_disconnected_zero_set

A real function with opposite strict signs on the two vertical edges cannot have a totally disconnected zero set in the square.

theorem not_totally_disconnected_zero_set (f : C(unitInterval × unitInterval, ℝ))
    (hleft : ∀ t, f (0, t) < 0) (hright : ∀ t, 0 < f (1, t)) :
    ¬ IsTotallyDisconnected {z | f z = 0}
Proof
:= by
  intro ht
  have hK : IsClosed {z | f z = 0} := isClosed_eq f.continuous continuous_const
  have hA : IsClosed {z : unitInterval × unitInterval | z.2 = 0} :=
    isClosed_eq continuous_snd continuous_const
  have hB : IsClosed {z : unitInterval × unitInterval | z.2 = 1} :=
    isClosed_eq continuous_snd continuous_const
  have hd : Disjoint {z : unitInterval × unitInterval | z.2 = 0} {z | z.2 = 1} := by
    apply Set.disjoint_left.mpr
    intro z hz0 hz1
    exact zero_ne_one (hz0.symm.trans hz1)
  obtain ⟨g, hgA, hgB, hgn⟩ := PlaneSeparation.exists_continuous_nonzero_on_compact
    hK.isCompact ht hA hB hd
  let h : C(unitInterval × unitInterval, ℂ) := ⟨fun z ↦ ⟨f z, g z⟩, by
    have hc : Continuous (fun z ↦ (f z : ℂ) + (g z : ℂ) * Complex.I) := by fun_prop
    convert hc using 1
    funext z
    apply Complex.ext <;> simp⟩
  obtain ⟨z, hz⟩ := exists_zero_of_strict_boundary_signs h hleft hright
    (fun t ↦ by change g (t, 0) < 0; rw [hgA rfl]; norm_num)
    (fun t ↦ by change 0 < g (t, 1); rw [hgB rfl]; norm_num)
  have hfz : f z = 0 := congrArg Complex.re hz
  have hgz : g z = 0 := congrArg Complex.im hz
  exact hgn z hfz hgz

theorem exists_compact_connected_zeros

TopologyByExample.RectangleIVT.exists_compact_connected_zeros

Opposite strict signs on vertical edges force a nondegenerate compact connected subset of the zero set.

theorem exists_compact_connected_zeros (f : C(unitInterval × unitInterval, ℝ))
    (hleft : ∀ t, f (0, t) < 0) (hright : ∀ t, 0 < f (1, t)) :
    ∃ K : Set (unitInterval × unitInterval), IsCompact K ∧ IsPreconnected K ∧
      K.Nontrivial ∧ ∀ z ∈ K, f z = 0
Proof
:= by
  have hn := not_totally_disconnected_zero_set f hleft hright
  obtain ⟨K, hK⟩ := not_forall.mp hn
  obtain ⟨hs, hK⟩ := not_imp.mp hK
  obtain ⟨hc, hK⟩ := not_imp.mp hK
  have hnt := (Set.not_subsingleton_iff.mp hK).mono subset_closure
  refine ⟨closure K, isClosed_closure.isCompact, hc.closure, hnt, ?_⟩
  exact closure_minimal hs (isClosed_eq f.continuous continuous_const)