Download data/lean/OAI/Combinatorics/EditDistance/Cuts.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.42 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/Cuts.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditDistance/Cuts.lean
-
curl -L -o Cuts.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/Cuts.lean
6.42 kB
| import OAI.Combinatorics.EditDistance.Model | |
| namespace OAI | |
| /-! | |
| # Finite scalar and absolutely summable cut decompositions | |
| -/ | |
| namespace EditCuts | |
| open scoped BigOperators | |
| open Finset | |
| lemma top_clipping_distance (a b x y : β) (hba : b < a) | |
| (hx : x = a β¨ x β€ b) (hy : y = a β¨ y β€ b) : | |
| |x - y| = |min x b - min y b| + | |
| (a - b) * |(if x = a then (1 : β) else 0) - (if y = a then (1 : β) else 0)| := by | |
| rcases hx with hx | hx <;> rcases hy with hy | hy | |
| Β· subst x; subst y; simp | |
| Β· subst x | |
| have hya : y < a := hy.trans_lt hba | |
| simp [min_eq_right hba.le, min_eq_left hy, hya.ne, | |
| abs_of_nonneg (sub_nonneg.mpr hya.le), abs_of_nonneg (sub_nonneg.mpr hy)] | |
| Β· subst y | |
| have hxa : x < a := hx.trans_lt hba | |
| simp [min_eq_right hba.le, min_eq_left hx, hxa.ne, | |
| abs_of_nonpos (sub_nonpos.mpr hxa.le), abs_of_nonpos (sub_nonpos.mpr hx)] | |
| Β· have hxa : x < a := hx.trans_lt hba | |
| have hya : y < a := hy.trans_lt hba | |
| simp [min_eq_left hx, min_eq_left hy, hxa.ne, hya.ne] | |
| section Finite | |
| variable {X : Type*} [Fintype X] [DecidableEq X] | |
| def cut (A : Finset X) (x : X) : β := if x β A then 1 else 0 | |
| theorem scalar_decomposition_aux (s : Finset β) : | |
| β (f : X β β), (β x, f x β s) β | |
| β w : Finset X β β, (β A, 0 β€ w A) β§ | |
| β x y, |f x - f y| = β A : Finset X, w A * |cut A x - cut A y| := by | |
| classical | |
| induction s using Finset.induction_on_max with | |
| | empty => | |
| intro f hf | |
| refine β¨fun _ => 0, fun _ => le_rfl, ?_β© | |
| intro x | |
| simpa using hf x | |
| | insert a s hmax ih => | |
| intro f hf | |
| by_cases hse : s = β | |
| Β· have hfconst (x : X) : f x = a := by simpa [hse] using hf x | |
| refine β¨fun _ => 0, fun _ => le_rfl, ?_β© | |
| intro x y | |
| simp [hfconst] | |
| have hsn : s.Nonempty := nonempty_iff_ne_empty.mpr hse | |
| let b : β := s.max' hsn | |
| have hb : b β s := max'_mem s hsn | |
| have hba : b < a := hmax b hb | |
| have hfb (x : X) (hx : f x β a) : f x β€ b := by | |
| exact le_max' s (f x) ((mem_insert.mp (hf x)).resolve_left hx) | |
| let f' : X β β := fun x => min (f x) b | |
| have hf' (x : X) : f' x β s := by | |
| by_cases hx : f x = a | |
| Β· simpa only [f', hx, min_eq_right hba.le] using hb | |
| Β· simpa only [f', min_eq_left (hfb x hx)] using | |
| ((mem_insert.mp (hf x)).resolve_left hx) | |
| obtain β¨w, hw, hwdβ© := ih f' hf' | |
| let A : Finset X := univ.filter (fun x => f x = a) | |
| have hcut (x : X) : cut A x = if f x = a then 1 else 0 := by simp [cut, A] | |
| have hcase (x : X) : f x = a β¨ f x β€ b := by | |
| by_cases hx : f x = a | |
| Β· exact Or.inl hx | |
| Β· exact Or.inr (hfb x hx) | |
| have heq (x y : X) : |f x - f y| = |f' x - f' y| + | |
| (a - b) * |cut A x - cut A y| := by | |
| simpa only [f', hcut] using top_clipping_distance a b (f x) (f y) hba (hcase x) (hcase y) | |
| refine β¨fun B => w B + if B = A then a - b else 0, ?_, ?_β© | |
| Β· intro B | |
| apply add_nonneg (hw B) | |
| split_ifs | |
| Β· exact sub_nonneg.mpr hba.le | |
| Β· exact le_rfl | |
| Β· intro x y | |
| rw [heq, hwd] | |
| simp only [add_mul, sum_add_distrib, ite_mul, zero_mul, sum_ite_eq', mem_univ, ite_true] | |
| theorem scalar_decomposition (f : X β β) : | |
| β w : Finset X β β, (β A, 0 β€ w A) β§ | |
| β x y, |f x - f y| = β A : Finset X, w A * |cut A x - cut A y| := | |
| scalar_decomposition_aux (univ.image f) f (fun x => mem_image.mpr β¨x, mem_univ x, rflβ©) | |
| end Finite | |
| end EditCuts | |
| namespace EditCuts | |
| open scoped BigOperators | |
| open Finset | |
| abbrev RealL1 := lp (fun _ : β => β) 1 | |
| lemma l1_norm (f : RealL1) : βfβ = β' n, |f n| := by | |
| simpa using lp.norm_eq_tsum_rpow (by norm_num : 0 < (1 : ENNReal).toReal) f | |
| lemma l1_summable (f : RealL1) : Summable (fun n => |f n|) := by | |
| simpa using (lp.memβp f).summable (by norm_num : 0 < (1 : ENNReal).toReal) | |
| lemma l1_norm_sub (f g : RealL1) : βf - gβ = β' n, |f n - g n| := | |
| l1_norm (f - g) | |
| section Finite | |
| variable {X : Type*} [Fintype X] [DecidableEq X] | |
| omit [Fintype X] in | |
| lemma cut_empty (x : X) : cut β x = 0 := by simp [cut] | |
| lemma cut_univ (x : X) : cut univ x = 1 := by simp [cut] | |
| theorem scalar_decomposition_nontrivial (f : X β β) : | |
| β w : Finset X β β, (β A, 0 β€ w A) β§ w β = 0 β§ w univ = 0 β§ | |
| β x y, |f x - f y| = β A : Finset X, w A * |cut A x - cut A y| := by | |
| classical | |
| obtain β¨w, hw, hdβ© := scalar_decomposition f | |
| refine β¨fun A => if A = β β¨ A = univ then 0 else w A, ?_, by simp, by simp, ?_β© | |
| Β· intro A | |
| dsimp only | |
| split_ifs <;> simp_all | |
| Β· intro x y | |
| rw [hd] | |
| apply sum_congr rfl | |
| intro A _ | |
| by_cases hac : A = β β¨ A = univ | |
| Β· rcases hac with rfl | rfl <;> simp [cut_empty, cut_univ] | |
| Β· simp [hac] | |
| lemma weight_le_distance (f : X β β) (w : Finset X β β) | |
| (hw : β A, 0 β€ w A) | |
| (hd : β x y, |f x - f y| = β A : Finset X, w A * |cut A x - cut A y|) | |
| (A : Finset X) (x y : X) (hx : x β A) (hy : y β A) : | |
| w A β€ |f x - f y| := by | |
| rw [hd] | |
| calc | |
| w A = w A * |cut A x - cut A y| := by simp [cut, hx, hy] | |
| _ β€ _ := single_le_sum (fun B _ => mul_nonneg (hw B) (abs_nonneg (cut B x - cut B y))) (mem_univ A) | |
| theorem l1_decomposition (H : X β RealL1) : | |
| β c : Finset X β β, (β A, 0 β€ c A) β§ c β = 0 β§ c univ = 0 β§ | |
| β x y, βH x - H yβ = β A : Finset X, c A * |cut A x - cut A y| := by | |
| classical | |
| choose w hw he hu hd using fun n => scalar_decomposition_nontrivial (fun x => H x n) | |
| have hs (A : Finset X) : Summable (fun n => w n A) := by | |
| by_cases ha : A = β β¨ A = univ | |
| Β· rcases ha with rfl | rfl <;> simpa only [he, hu] using (summable_zero : Summable (fun _ : β => (0 : β))) | |
| obtain β¨x, hxβ© := nonempty_iff_ne_empty.mpr (not_or.mp ha).1 | |
| obtain β¨y, hyβ© : β y, y β A := by | |
| by_contra! hn | |
| exact (not_or.mp ha).2 (eq_univ_iff_forall.mpr hn) | |
| exact Summable.of_nonneg_of_le (fun n => hw n A) | |
| (fun n => weight_le_distance _ _ (hw n) (hd n) A x y hx hy) | |
| (l1_summable (H x - H y)) | |
| refine β¨fun A => β' n, w n A, fun A => tsum_nonneg (fun n => hw n A), | |
| by simp [he], by simp [hu], ?_β© | |
| intro x y | |
| rw [l1_norm_sub] | |
| simp_rw [hd] | |
| rw [Summable.tsum_finsetSum] | |
| Β· apply sum_congr rfl | |
| intro A _ | |
| exact (hs A).tsum_mul_right _ | |
| Β· intro A _ | |
| exact (hs A).mul_right _ | |
| end Finite | |
| end EditCuts | |
| end OAI | |