Download data/lean/OAI/Probability/LatticeSurface/Geometry/StrictFilling.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/LatticeSurface/Geometry/StrictFilling.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/LatticeSurface/Geometry/StrictFilling.lean
-
curl -L -o StrictFilling.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/LatticeSurface/Geometry/StrictFilling.lean
15.7 kB
| import Mathlib | |
| namespace OAI | |
| namespace StrictFilling | |
| def clip (lo hi t : β) : β := max lo (min t hi) | |
| lemma clip_eq_self {lo hi t : β} (hl : lo β€ t) (hu : t β€ hi) : | |
| clip lo hi t = t := by | |
| simp [clip, min_eq_left hu, max_eq_right hl] | |
| lemma clip_same (c t : β) : clip c c t = c := by | |
| exact max_eq_left (min_le_right _ _) | |
| lemma clip_between_zero {lo hi t : β} | |
| (hl : lo β€ max 0 t) (hu : min 0 t β€ hi) : | |
| clip lo hi t β Set.uIcc 0 t := by | |
| change min 0 t β€ max lo (min t hi) β§ max lo (min t hi) β€ max 0 t | |
| constructor | |
| Β· exact (le_min (min_le_right _ _) hu).trans (le_max_right _ _) | |
| Β· exact max_le hl ((min_le_left _ _).trans (le_max_right _ _)) | |
| def medianZero (a b : β) : β := max (min a b) (min (max a b) 0) | |
| lemma medianZero_properties (a b : β) : | |
| medianZero a b β Set.uIcc 0 a β§ | |
| medianZero a b β Set.uIcc 0 b β§ | |
| |medianZero a b - a| β€ |a - b| β§ | |
| |medianZero a b - b| β€ |a - b| := by | |
| unfold medianZero | |
| change (min 0 a β€ _ β§ _ β€ max 0 a) β§ | |
| (min 0 b β€ _ β§ _ β€ max 0 b) β§ _ | |
| simp only [min_def, max_def] | |
| split_ifs <;> simp_all only [abs_le] <;> | |
| and_intros <;> first | trivial | linarith [le_abs_self (a-b), neg_le_abs (a-b)] | |
| section Metric | |
| variable {X : Type*} [PseudoMetricSpace X] | |
| lemma lipschitz_add_const {f : X β β} (hf : LipschitzWith 1 f) (c : β) : | |
| LipschitzWith 1 (fun x => c + f x) := by | |
| apply LipschitzWith.mk_one | |
| intro x y | |
| simpa only [Real.dist_eq, add_sub_add_left_eq_sub, NNReal.coe_one, one_mul] using | |
| hf.dist_le_mul x y | |
| lemma lipschitz_const_sub {f : X β β} (hf : LipschitzWith 1 f) (c : β) : | |
| LipschitzWith 1 (fun x => c - f x) := by | |
| simpa only [sub_eq_add_neg, Pi.neg_apply] using lipschitz_add_const hf.neg c | |
| lemma lipschitz_clip {h r : X β β} (hh : LipschitzWith 1 h) | |
| (hr : LipschitzWith 1 r) (c : β) : | |
| LipschitzWith 1 (fun x => clip (c - r x) (c + r x) (h x)) := by | |
| simpa only [clip, max_self] using | |
| (lipschitz_const_sub hr c).max (hh.min (lipschitz_add_const hr c)) | |
| lemma endpoint_lower {h : X β β} (hh : LipschitzWith 1 h) | |
| {u : X} {c : β} (hc : c β Set.uIcc 0 (h u)) (x : X) : | |
| c - dist x u β€ max 0 (h x) := by | |
| have hc' : c β€ max 0 (h u) := hc.2 | |
| have hd := hh.dist_le_mul u x | |
| simp only [Real.dist_eq, NNReal.coe_one, one_mul, abs_le] at hd | |
| have hd0 : 0 β€ dist x u := dist_nonneg | |
| rw [dist_comm u x] at hd | |
| rcases le_total 0 (h u) with hu | hu | |
| Β· rw [max_eq_right hu] at hc' | |
| exact (show c - dist x u β€ h x by linarith).trans (le_max_right _ _) | |
| Β· rw [max_eq_left hu] at hc' | |
| exact (show c - dist x u β€ 0 by linarith).trans (le_max_left _ _) | |
| lemma endpoint_upper {h : X β β} (hh : LipschitzWith 1 h) | |
| {u : X} {c : β} (hc : c β Set.uIcc 0 (h u)) (x : X) : | |
| min 0 (h x) β€ c + dist x u := by | |
| have hc' : min 0 (h u) β€ c := hc.1 | |
| have hd := hh.dist_le_mul u x | |
| simp only [Real.dist_eq, NNReal.coe_one, one_mul, abs_le] at hd | |
| have hd0 : 0 β€ dist x u := dist_nonneg | |
| rw [dist_comm u x] at hd | |
| rcases le_total 0 (h u) with hu | hu | |
| Β· rw [min_eq_left hu] at hc' | |
| exact (min_le_left _ _).trans (by linarith) | |
| Β· rw [min_eq_right hu] at hc' | |
| exact (min_le_right _ _).trans (show h x β€ c + dist x u by linarith) | |
| lemma cone_preserves_interval {h : X β β} (hh : LipschitzWith 1 h) | |
| {u : X} {c : β} (hc : c β Set.uIcc 0 (h u)) (x : X) : | |
| clip (c - dist x u) (c + dist x u) (h x) β Set.uIcc 0 (h x) := | |
| clip_between_zero (endpoint_lower hh hc x) (endpoint_upper hh hc x) | |
| def twoRadius (u v x : X) : β := min (dist x u) (dist x v) | |
| def twoClip (h : X β β) (u v : X) (c : β) (x : X) : β := | |
| clip (c - twoRadius u v x) (c + twoRadius u v x) (h x) | |
| lemma twoRadius_lipschitz (u v : X) : LipschitzWith 1 (twoRadius u v) := by | |
| change LipschitzWith 1 (fun x => min (dist x u) (dist x v)) | |
| simpa only [max_self] using | |
| (LipschitzWith.dist_left u).min (LipschitzWith.dist_left v) | |
| lemma twoClip_lipschitz {h : X β β} (hh : LipschitzWith 1 h) | |
| (u v : X) (c : β) : LipschitzWith 1 (twoClip h u v c) := | |
| lipschitz_clip hh (twoRadius_lipschitz u v) c | |
| lemma twoClip_between_zero {h : X β β} (hh : LipschitzWith 1 h) | |
| {u v : X} {c : β} | |
| (hcu : c β Set.uIcc 0 (h u)) (hcv : c β Set.uIcc 0 (h v)) (x : X) : | |
| twoClip h u v c x β Set.uIcc 0 (h x) := by | |
| unfold twoClip twoRadius | |
| rcases le_total (dist x u) (dist x v) with hd | hd | |
| Β· rw [min_eq_left hd] | |
| exact cone_preserves_interval hh hcu x | |
| Β· rw [min_eq_right hd] | |
| exact cone_preserves_interval hh hcv x | |
| lemma twoClip_endpoints (h : X β β) (u v : X) (c : β) : | |
| twoClip h u v c u = c β§ twoClip h u v c v = c := by | |
| simp only [twoClip, twoRadius, dist_self, min_eq_left dist_nonneg, | |
| min_eq_right dist_nonneg, sub_zero, add_zero, clip_same, and_self] | |
| lemma cone_eq_self_of_dist {h : X β β} {u : X} {c : β} (x : X) | |
| (hc : |c - h x| β€ dist x u) : | |
| clip (c - dist x u) (c + dist x u) (h x) = h x := by | |
| apply clip_eq_self <;> have := (abs_le.mp hc) <;> linarith | |
| lemma twoClip_eq_self {h : X β β} {u v : X} {c : β} (x : X) | |
| (hcu : |c - h x| β€ dist x u) (hcv : |c - h x| β€ dist x v) : | |
| twoClip h u v c x = h x := by | |
| apply clip_eq_self <;> | |
| have hl := (abs_le.mp hcu) <;> have hr := (abs_le.mp hcv) <;> | |
| unfold twoRadius <;> rw [min_def] <;> split_ifs <;> linarith | |
| lemma pin_compatible {h : X β β} (hh : LipschitzWith 1 h) | |
| {u s : X} {c : β} (hc : c β Set.uIcc 0 (h u)) | |
| (hs : |h s| β€ 1 / 2) (hsep : 1 β€ dist s u) : | |
| |c - h s| β€ dist s u := by | |
| have hd := hh.dist_le_mul u s | |
| rw [dist_comm u s] at hd | |
| simp only [Real.dist_eq, NNReal.coe_one, one_mul, abs_le] at hd | |
| have hs' := abs_le.mp hs | |
| rcases Set.mem_uIcc.mp hc with h | h <;> | |
| apply abs_le.mpr <;> constructor <;> linarith | |
| lemma room_compatible {h : X β β} {u s : X} {c : β} | |
| (hc : |c - h u| β€ 2) | |
| (hroom : |h u - h s| β€ dist u s - 2) : | |
| |c - h s| β€ dist s u := by | |
| rw [dist_comm s u] | |
| calc | |
| |c - h s| β€ |c - h u| + |h u - h s| := abs_sub_le c (h u) (h s) | |
| _ β€ 2 + (dist u s - 2) := add_le_add hc hroom | |
| _ = dist u s := by ring | |
| theorem strict_filling_movable_first | |
| (h : X β β) (shell pins : Set X) (I : X β Set β) (u v : X) | |
| (hsep : β x y : X, x β y β 1 β€ dist x y) | |
| (hedge : dist u v = 1) (hh : LipschitzWith 1 h) | |
| (hpin : β s β pins, |h s| β€ 1 / 2) | |
| (hI : β x β shell βͺ pins, (I x).OrdConnected β§ 0 β I x β§ h x β I x) | |
| (hu : u β shell βͺ pins) | |
| (hroom : β x, (x = u β¨ x = v) β x β shell βͺ pins β | |
| β s β shell, |h x - h s| β€ dist x s - 2) : | |
| β g : X β β, LipschitzWith 1 g β§ | |
| (β s β shell βͺ pins, g s = h s) β§ | |
| (β x β shell βͺ pins, g x β I x) β§ |g u - g v| β€ 1 / 2 := by | |
| have hdist : |h u - h v| β€ 1 := by | |
| simpa only [Real.dist_eq, NNReal.coe_one, one_mul, hedge] using hh.dist_le_mul u v | |
| have hsep_u : β s β shell βͺ pins, 1 β€ dist s u := by | |
| intro s hs | |
| exact hsep s u (by intro hsu; subst s; exact hu hs) | |
| by_cases hv : v β shell βͺ pins | |
| Β· have hvshell : v β shell := by | |
| intro hvs | |
| have hr := hroom u (Or.inl rfl) hu v hvs | |
| rw [hedge] at hr | |
| linarith [abs_nonneg (h u - h v)] | |
| have hvpin : v β pins := hv.resolve_left hvshell | |
| have hvbound := hpin v hvpin | |
| have hubound : |0 - h u| β€ 2 := by | |
| have ht := abs_sub_le (h u) (h v) 0 | |
| rw [sub_zero, sub_zero] at ht | |
| simpa only [zero_sub, abs_neg] using | |
| (show |h u| β€ 2 by linarith) | |
| let g := twoClip h u u 0 | |
| refine β¨g, twoClip_lipschitz hh u u 0, ?_, ?_, ?_β© | |
| Β· intro s hs | |
| change twoClip h u u 0 s = h s | |
| have hc : |0 - h s| β€ dist s u := by | |
| rcases hs with hss | hsp | |
| Β· exact room_compatible hubound (hroom u (Or.inl rfl) hu s hss) | |
| Β· simpa only [zero_sub, abs_neg] using | |
| (hpin s hsp).trans (by linarith [hsep_u s (Or.inr hsp)]) | |
| exact twoClip_eq_self s hc hc | |
| Β· intro x hx | |
| exact (hI x hx).1.uIcc_subset (hI x hx).2.1 (hI x hx).2.2 | |
| (twoClip_between_zero hh (Set.left_mem_uIcc) (Set.left_mem_uIcc) x) | |
| Β· have hgu : g u = 0 := (twoClip_endpoints h u u 0).1 | |
| have hgv : g v = h v := by | |
| apply twoClip_eq_self | |
| all_goals simpa only [zero_sub, abs_neg] using | |
| hvbound.trans (by linarith [hsep_u v hv]) | |
| rw [hgu, hgv, zero_sub, abs_neg] | |
| exact hvbound | |
| Β· let c := medianZero (h u) (h v) | |
| have hc := medianZero_properties (h u) (h v) | |
| have hcu : c β Set.uIcc 0 (h u) := hc.1 | |
| have hcv : c β Set.uIcc 0 (h v) := hc.2.1 | |
| have hcu2 : |c - h u| β€ 2 := (hc.2.2.1.trans hdist).trans (by norm_num) | |
| have hcv2 : |c - h v| β€ 2 := (hc.2.2.2.trans hdist).trans (by norm_num) | |
| let g := twoClip h u v c | |
| refine β¨g, twoClip_lipschitz hh u v c, ?_, ?_, ?_β© | |
| Β· intro s hs | |
| have hc1 : |c - h s| β€ dist s u := by | |
| rcases hs with hss | hsp | |
| Β· exact room_compatible hcu2 (hroom u (Or.inl rfl) hu s hss) | |
| Β· exact pin_compatible hh hcu (hpin s hsp) (hsep_u s (Or.inr hsp)) | |
| have hc2 : |c - h s| β€ dist s v := by | |
| rcases hs with hss | hsp | |
| Β· exact room_compatible hcv2 (hroom v (Or.inr rfl) hv s hss) | |
| Β· exact pin_compatible hh hcv (hpin s hsp) | |
| (hsep s v (by intro hsv; subst s; exact hv (Or.inr hsp))) | |
| exact twoClip_eq_self s hc1 hc2 | |
| Β· intro x hx | |
| exact (hI x hx).1.uIcc_subset (hI x hx).2.1 (hI x hx).2.2 | |
| (twoClip_between_zero hh hcu hcv x) | |
| Β· have he := twoClip_endpoints h u v c | |
| change |twoClip h u v c u - twoClip h u v c v| β€ _ | |
| rw [he.1, he.2, sub_self, abs_zero] | |
| norm_num | |
| theorem strict_filling | |
| (h : X β β) (shell pins : Set X) (I : X β Set β) (u v : X) | |
| (hsep : β x y : X, x β y β 1 β€ dist x y) | |
| (hedge : dist u v = 1) (hh : LipschitzWith 1 h) | |
| (hpin : β s β pins, |h s| β€ 1 / 2) | |
| (hI : β x β shell βͺ pins, (I x).OrdConnected β§ 0 β I x β§ h x β I x) | |
| (hnotfixed : Β¬ (u β shell βͺ pins β§ v β shell βͺ pins)) | |
| (hroom : β x, (x = u β¨ x = v) β x β shell βͺ pins β | |
| β s β shell, |h x - h s| β€ dist x s - 2) : | |
| β g : X β β, LipschitzWith 1 g β§ | |
| (β s β shell βͺ pins, g s = h s) β§ | |
| (β x β shell βͺ pins, g x β I x) β§ |g u - g v| β€ 1 / 2 := by | |
| by_cases hu : u β shell βͺ pins | |
| Β· have hv : v β shell βͺ pins := fun hv => hnotfixed β¨hu, hvβ© | |
| obtain β¨g, hg, hgf, hgi, hgeβ© := strict_filling_movable_first h shell pins I v u | |
| hsep (by rw [dist_comm]; exact hedge) hh hpin hI hv | |
| (fun x hx => hroom x hx.symm) | |
| refine β¨g, hg, hgf, hgi, ?_β© | |
| simpa only [abs_sub_comm] using hge | |
| Β· exact strict_filling_movable_first h shell pins I u v hsep hedge hh hpin hI hu hroom | |
| end Metric | |
| abbrev Component {V : Type*} (G : SimpleGraph V) (u : V) := {x : V // G.Reachable u x} | |
| noncomputable instance componentMetric {V : Type*} (G : SimpleGraph V) (u : V) : | |
| MetricSpace (Component G u) where | |
| dist x y := (G.dist x.val y.val : β) | |
| dist_self x := by simp | |
| dist_comm x y := by rw [G.dist_comm] | |
| dist_triangle x y z := by | |
| exact_mod_cast (x.property.symm.trans y.property).dist_triangle_left z.val | |
| eq_of_dist_eq_zero := by | |
| intro x y h | |
| apply Subtype.ext | |
| exact (x.property.symm.trans y.property).dist_eq_zero_iff.mp (by exact_mod_cast h) | |
| lemma edge_bound_walk {V : Type*} {G : SimpleGraph V} {h : V β β} | |
| (hh : β x y, G.Adj x y β |h x - h y| β€ 1) | |
| {x y : V} (p : G.Walk x y) : |h x - h y| β€ (p.length : β) := by | |
| induction p with | |
| | nil => simp | |
| | @cons x y z hxy p ih => | |
| calc | |
| |h x - h z| β€ |h x - h y| + |h y - h z| := abs_sub_le _ _ _ | |
| _ β€ 1 + (p.length : β) := add_le_add (hh _ _ hxy) ih | |
| _ = ((SimpleGraph.Walk.cons hxy p).length : β) := by simp; ring | |
| lemma edge_bound_dist {V : Type*} {G : SimpleGraph V} {h : V β β} | |
| (hh : β x y, G.Adj x y β |h x - h y| β€ 1) | |
| {x y : V} (hr : G.Reachable x y) : |h x - h y| β€ (G.dist x y : β) := by | |
| obtain β¨p, hpβ© := hr.exists_walk_length_eq_dist | |
| simpa only [hp] using edge_bound_walk hh p | |
| lemma component_lipschitz {V : Type*} {G : SimpleGraph V} {h : V β β} | |
| (hh : β x y, G.Adj x y β |h x - h y| β€ 1) (u : V) : | |
| LipschitzWith 1 (fun x : Component G u => h x.val) := by | |
| apply LipschitzWith.mk_one | |
| intro x y | |
| exact edge_bound_dist hh (x.property.symm.trans y.property) | |
| lemma component_separated {V : Type*} {G : SimpleGraph V} {u : V} | |
| (x y : Component G u) (hxy : x β y) : 1 β€ dist x y := by | |
| change (1 : β) β€ (G.dist x.val y.val : β) | |
| exact_mod_cast (x.property.symm.trans y.property).pos_dist_of_ne | |
| (by intro h; exact hxy (Subtype.ext h)) | |
| theorem graph_strict_filling {V : Type*} [Finite V] | |
| (G : SimpleGraph V) (h : V β β) (shell pins : Set V) (I : V β Set β) | |
| (u v : V) (hedge : G.Adj u v) | |
| (hh : β x y, G.Adj x y β |h x - h y| β€ 1) | |
| (hpin : β s β pins, |h s| β€ 1 / 2) | |
| (hI : β x β shell βͺ pins, (I x).OrdConnected β§ 0 β I x β§ h x β I x) | |
| (hnotfixed : Β¬ (u β shell βͺ pins β§ v β shell βͺ pins)) | |
| (hroom : β x, (x = u β¨ x = v) β x β shell βͺ pins β | |
| β s β shell, G.Reachable x s β |h x - h s| β€ (G.dist x s : β) - 2) : | |
| β g : V β β, | |
| (β x y, G.Adj x y β |g x - g y| β€ 1) β§ | |
| (β s β shell βͺ pins, g s = h s) β§ | |
| (β x β shell βͺ pins, g x β I x) β§ |g u - g v| β€ 1 / 2 := by | |
| classical | |
| let C := Component G u | |
| let uC : C := β¨u, .refl uβ© | |
| let vC : C := β¨v, hedge.reachableβ© | |
| let shellC : Set C := {x | x.val β shell} | |
| let pinsC : Set C := {x | x.val β pins} | |
| have hedgeC : dist uC vC = 1 := by | |
| change (G.dist u v : β) = 1 | |
| exact_mod_cast SimpleGraph.dist_eq_one_iff_adj.mpr hedge | |
| obtain β¨gc, hgclip, hgcf, hgci, hgceβ© := | |
| strict_filling (fun x : C => h x.val) shellC pinsC (fun x => I x.val) uC vC | |
| (fun x y hxy => component_separated x y hxy) hedgeC (component_lipschitz hh u) | |
| (fun s hs => hpin s.val hs) (fun x hx => hI x.val hx) hnotfixed | |
| (by | |
| intro x hx hxnot s hs | |
| change |h x.val - h s.val| β€ (G.dist x.val s.val : β) - 2 | |
| apply hroom x.val _ hxnot s.val hs (x.property.symm.trans s.property) | |
| rcases hx with hx | hx | |
| Β· exact Or.inl (congrArg Subtype.val hx) | |
| Β· exact Or.inr (congrArg Subtype.val hx)) | |
| let g : V β β := fun x => if hx : G.Reachable u x then gc β¨x, hxβ© else h x | |
| refine β¨g, ?_, ?_, ?_, ?_β© | |
| Β· intro x y hxy | |
| by_cases hx : G.Reachable u x | |
| Β· have hy := hx.trans hxy.reachable | |
| have hc := hgclip.dist_le_mul (β¨x, hxβ© : C) (β¨y, hyβ© : C) | |
| change |gc β¨x, hxβ© - gc β¨y, hyβ©| β€ 1 * (G.dist x y : β) at hc | |
| simpa only [g, dite_eq_left hx, dite_eq_left hy, one_mul, | |
| SimpleGraph.dist_eq_one_iff_adj.mpr hxy, Nat.cast_one] using hc | |
| Β· have hy : Β¬ G.Reachable u y := fun hy => hx (hy.trans hxy.symm.reachable) | |
| simpa only [g, dite_eq_right hx, dite_eq_right hy] using hh x y hxy | |
| Β· intro s hs | |
| by_cases hx : G.Reachable u s | |
| Β· exact (dite_eq_left hx).trans (hgcf β¨s, hxβ© hs) | |
| Β· exact dite_eq_right hx | |
| Β· intro x hx | |
| by_cases hr : G.Reachable u x | |
| Β· simpa only [g, dite_eq_left hr] using hgci β¨x, hrβ© hx | |
| Β· simpa only [g, dite_eq_right hr] using (hI x hx).2.2 | |
| Β· simpa only [g, dite_eq_left (SimpleGraph.Reachable.refl u), | |
| dite_eq_left hedge.reachable] using hgce | |
| end StrictFilling | |
| end OAI | |