import OAI.Geometry.RuledCovering.HyperbolicLattice namespace OAI noncomputable section open Set MeasureTheory Filter Metric open scoped Topology ContDiff Pointwise namespace RuledApproximation lemma HasFiniteCover.of_fintype {ι : Type*} [Fintype ι] {shape : Cylinder → Prop} {S : Set Space} {A : ℝ} (C : ι → Cylinder) (hshape : ∀ i, shape (C i)) (hcover : S ⊆ ⋃ i, (C i).carrier) (hcost : (∑ i, (C i).area) ≤ A) : HasFiniteCover shape S A := by classical let e := Fintype.equivFin ι refine ⟨Fintype.card ι, C ∘ e.symm, fun i => hshape _, ?_, ?_⟩ · intro x hx obtain ⟨i, hi⟩ := mem_iUnion.mp (hcover hx) exact mem_iUnion.mpr ⟨e i, by simpa using hi⟩ · change (∑ i : Fin (Fintype.card ι), (C (e.symm i)).area) ≤ A rw [e.symm.sum_comp (fun j => (C j).area)] exact hcost /-- Convert the finite weighted lattice certificate into actual perpendicular Euclidean cylinders. The factor is the exact area inflation caused by the derivative remainder. -/ theorem framed_local_cover (M : Coordinates ≃L[ℝ] Plane) {h L R delta : ℝ} (hh : 0 < h) (hL : 0 ≤ L) (hR : 0 ≤ R) (hd : 0 ≤ delta) {K U : Set Coordinates} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) (v : Plane → Plane) (A : Coordinates →L[ℝ] Coordinates) (hmodel : LatticeModel A L R) (hrem : ∀ p ∈ U, ∀ b ∈ U, ‖M.symm (v (M p)) - M.symm (v (M b)) - A (p - b)‖ ≤ delta * ‖p - b‖) {F : Coordinates → ℝ} (hF : Continuous F) (hFpos : ∀ p, 0 ≤ F p) (hFval : ∀ p ∈ U, F p = physicalWeight h (v (M p))) {eps : ℝ} (heps : 0 < eps) : HasFiniteCover Cylinder.parallelogram (physicalRuled h (M '' K) v L) (h * (1 + 2 * L * delta * R) ^ 2 * (∫ p in M '' K, physicalWeight h (v p)) + eps) := by classical let B : ℝ := (1 + 2 * L * delta * R) ^ 2 have hB : 0 < B := by dsimp [B]; positivity have hscale : 0 < h * frameJacobian M * B := mul_pos (mul_pos hh (frameJacobian_pos M)) hB obtain ⟨n, hn, S, hS, hSU, hcov, hcost⟩ := local_finite_certificate hK hU hKU (fun p => M.symm (v (M p))) A hL hd hmodel hrem hF hFpos (div_pos heps hscale) let : Fintype S := hS.fintype let a : ℝ := (1 / 2 + L * delta * R) / n have hnR : 0 < (n : ℝ) := by exact_mod_cast hn have ha : 0 < a := by dsimp [a]; positivity let C : S → Cylinder := fun b => projectedCylinder h (v (M b)) (M '' closedBall (b : Coordinates) a) have harea (b : S) : (C b).area = h * frameJacobian M * (2 * a) ^ 2 * F b := by dsimp only [C] rw [projectedCylinder_area hh, frame_volume_image M isClosed_closedBall.measurableSet, coordinates_closedBall_volume b ha.le, hFval b (hSU b.property)] ring have hBrel : (2 * a) ^ 2 = B / (n : ℝ) ^ 2 := by dsimp [a, B] ring have hintegral : (∫ p in M '' K, physicalWeight h (v p)) = frameJacobian M * ∫ x in K, F x := by rw [frame_integral_image M hK.measurableSet] congr 1 apply setIntegral_congr_fun hK.measurableSet intro x hx exact (hFval x (hKU hx)).symm apply HasFiniteCover.of_fintype C · intro b apply projectedCylinder_parallelogram hh exact (coordinates_closedBall_parallelogram (b : Coordinates) ha).linear_image M.toLinearMap M.injective · rintro x ⟨_, ⟨p, hp, rfl⟩, s, hs, rfl⟩ obtain ⟨b, hb, hc⟩ := hcov p hp s hs apply mem_iUnion.mpr refine ⟨⟨b, hb⟩, ?_⟩ apply physicalRuled_mem_projectedCylinder refine ⟨p + s • (M.symm (v (M p)) - M.symm (v (M b))), ?_, ?_⟩ · rw [mem_closedBall, dist_eq_norm] convert hc using 1 congr 1 module · simp · have hsum : (∑ b : S, (C b).area) = (h * frameJacobian M * B) * ((∑' b : S, F b) / (n : ℝ) ^ 2) := by simp_rw [harea, hBrel] rw [tsum_fintype, ← Finset.mul_sum] ring rw [hsum, hintegral] have hc := (mul_lt_mul_of_pos_left hcost hscale).le calc _ ≤ (h * frameJacobian M * B) * ((∫ x in K, F x) + eps / (h * frameJacobian M * B)) := hc _ = _ := by rw [mul_add, mul_div_cancel₀ _ hscale.ne'] dsimp [B] ring end RuledApproximation end end OAI