Development/AutomorphicArithmetic/DedekindLFunctions/LandauTheorems/LandauNearest.lean
51landau_finite hiso (by rw [hc₀re]; linarith)52set F := Z ∩ Metric.closedBall c₀ (D + ε) with hFdef53set B : Set ℝ := (fun p : ℂ × ℂ =>54((σ - p.1.re) ^ 2 + p.1.im ^ 2 - (σ - p.2.re) ^ 2 - p.2.im ^ 2) / (2 * (p.1.im - p.2.im))) ''55(F ×ˢ F) with hB56have hBfin : B.Finite := (hF.prod hF).image _57obtain ⟨γ, hγI, hγB⟩ := ((Set.Ioo_infinite (show ρ₁.im - ε < ρ₁.im + ε by linarith)).diff hBfin).nonempty58set c : ℂ := (σ : ℂ) + γ * I with hc59have hγε : |γ - ρ₁.im| < ε := abs_sub_lt_iff.mpr ⟨by linarith [hγI.2], by linarith [hγI.1]⟩60have hcc₀ : ‖c - c₀‖ = |γ - ρ₁.im| := by61have e : c - c₀ = ((γ - ρ₁.im : ℝ) : ℂ) * I := by62rw [hc, hc₀]63push_cast64ring65rw [e, norm_mul, Complex.norm_I, mul_one, Complex.norm_real, Real.norm_eq_abs]66have hc₀ρ₁ : ‖c₀ - ρ₁‖ = σ - ρ₁.re := by67have e : c₀ - ρ₁ = ((σ - ρ₁.re : ℝ) : ℂ) := by68apply Complex.ext <;> simp [hc₀]69rw [e, Complex.norm_real, Real.norm_eq_abs, abs_of_pos (sub_pos.mpr (hle ρ₁ h₁))]70have hρ₁F : ρ₁ ∈ F := by71refine ⟨h₁, ?_⟩72rw [Metric.mem_closedBall, dist_eq_norm, norm_sub_rev, hc₀ρ₁]73linarith74obtain ⟨ρ, hρF, hmin⟩ := Set.exists_min_image F (fun w => ‖c - w‖) hF ⟨ρ₁, hρ₁F⟩75have hρ₁c : ‖c - ρ₁‖ < D := by76have := norm_add_le (c - c₀) (c₀ - ρ₁)77rw [sub_add_sub_cancel, hcc₀, hc₀ρ₁] at this78linarith79have hm : ‖c - ρ‖ ≤ ‖c - ρ₁‖ := hmin ρ₁ hρ₁F80have hT : ∀ w ∈ F \ {ρ}, ‖c - ρ‖ < ‖c - w‖ := by81intro w hw82have hmw : ‖c - ρ‖ ≤ ‖c - w‖ := hmin w hw.183rcases lt_or_eq_of_le hmw with h | h84· exact h85· exfalso86apply hw.287exact landau_nearest_equi (hle w hw.1.1) (hle ρ hρF.1) h.symm88(fun hb => hγB ⟨(w, ρ), ⟨hw.1, hρF⟩, hb.symm⟩)89obtain ⟨r, hr, hrT⟩ : ∃ r, ‖c - ρ‖ < r ∧ ∀ t ∈ F \ {ρ}, r ≤ ‖c - t‖ := by90rcases (F \ {ρ}).eq_empty_or_nonempty with hTe | hTne91· refine ⟨‖c - ρ‖ + 1, by linarith, ?_⟩92intro t ht93rw [hTe] at ht94exact absurd ht (Set.notMem_empty t)95· obtain ⟨t₀, ht₀, htmin⟩ := Set.exists_min_image (F \ {ρ}) (fun w => ‖c - w‖)96(hF.subset Set.diff_subset) hTne97exact ⟨‖c - t₀‖, hT t₀ ht₀, htmin⟩98refine ⟨γ, ρ, hρF.1, min r D, lt_min hr (by linarith), min_le_right _ _, ?_⟩99intro w hw hb100rw [Metric.mem_ball, dist_eq_norm, norm_sub_rev] at hb