Download data/lean/OAI/Combinatorics/EditDistance/DirectSums.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.32 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/DirectSums.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditDistance/DirectSums.lean
-
curl -L -o DirectSums.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditDistance/DirectSums.lean
5.32 kB
| import OAI.Combinatorics.EditDistance.PrimeDisplacement | |
| namespace OAI | |
| /-! | |
| # Weighted direct sums and normalized slice maps | |
| -/ | |
| namespace EditL1 | |
| open scoped BigOperators | |
| abbrev L1 := lp (fun _ : β => β) 1 | |
| abbrev L1On (I : Type*) := lp (fun _ : I => β) 1 | |
| lemma norm_eq_tsum {I : Type*} (f : L1On I) : βfβ = β' i, |f i| := by | |
| simpa using lp.norm_eq_tsum_rpow (by norm_num : 0 < (1 : ENNReal).toReal) f | |
| lemma summable_abs {I : Type*} (f : L1On I) : Summable (fun i => |f i|) := by | |
| simpa using (lp.memβp f).summable (by norm_num : 0 < (1 : ENNReal).toReal) | |
| noncomputable def reindex {I J : Type*} (e : I β J) (f : L1On I) : L1On J := | |
| β¨fun j => f (e.symm j), memβp_gen (by | |
| simpa only [ENNReal.toReal_one, Real.rpow_one, Real.norm_eq_abs, Function.comp_def] using! | |
| (e.symm.summable_iff).mpr (summable_abs f))β© | |
| lemma reindex_apply {I J : Type*} (e : I β J) (f : L1On I) (j : J) : | |
| reindex e f j = f (e.symm j) := rfl | |
| lemma reindex_norm {I J : Type*} (e : I β J) (f : L1On I) : | |
| βreindex e fβ = βfβ := by | |
| simp_rw [norm_eq_tsum, reindex_apply] | |
| exact e.symm.tsum_eq (fun i => |f i|) | |
| lemma reindex_sub {I J : Type*} (e : I β J) (f g : L1On I) : | |
| reindex e (f - g) = reindex e f - reindex e g := by | |
| ext j | |
| rfl | |
| section FiniteSum | |
| variable {I : Type*} [Fintype I] | |
| lemma family_summable (f : I β L1) : Summable (fun a : I Γ β => |f a.1 a.2|) := | |
| (summable_prod_of_nonneg (fun _ => abs_nonneg _)).mpr | |
| β¨fun i => summable_abs (f i), (hasSum_fintype _).summableβ© | |
| noncomputable def familyLp (f : I β L1) : L1On (I Γ β) := | |
| β¨fun a => f a.1 a.2, memβp_gen (by simpa using family_summable f)β© | |
| lemma familyLp_apply (f : I β L1) (i : I) (n : β) : familyLp f (i, n) = f i n := rfl | |
| lemma familyLp_norm (f : I β L1) : βfamilyLp fβ = β i, βf iβ := by | |
| rw [norm_eq_tsum] | |
| change (β' a : I Γ β, |f a.1 a.2|) = _ | |
| rw [(family_summable f).tsum_prod, tsum_fintype] | |
| exact Finset.sum_congr rfl (fun i _ => (norm_eq_tsum (f i)).symm) | |
| lemma familyLp_sub (f g : I β L1) : familyLp (f - g) = familyLp f - familyLp g := by | |
| ext β¨i, nβ© | |
| rfl | |
| variable [Nonempty I] | |
| noncomputable def indexEquiv : (I Γ β) β β := Classical.choice inferInstance | |
| noncomputable def pack (f : I β L1) : L1 := reindex indexEquiv (familyLp f) | |
| lemma pack_norm (f : I β L1) : βpack fβ = β i, βf iβ := by | |
| rw [pack, reindex_norm, familyLp_norm] | |
| lemma pack_sub (f g : I β L1) : pack (f - g) = pack f - pack g := by | |
| rw [pack, familyLp_sub, reindex_sub] | |
| rfl | |
| lemma pack_distance (f g : I β L1) : βpack f - pack gβ = β i, βf i - g iβ := by | |
| rw [β pack_sub, pack_norm] | |
| rfl | |
| lemma weighted_pack_distance (w : I β β) (hw : β i, 0 β€ w i) (f g : I β L1) : | |
| βpack (fun i => w i β’ f i) - pack (fun i => w i β’ g i)β = | |
| β i, w i * βf i - g iβ := by | |
| rw [pack_distance] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| rw [β smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg (hw i)] | |
| end FiniteSum | |
| end EditL1 | |
| namespace EditAverage | |
| lemma avg_prod {X Y : Type*} [Fintype X] [Fintype Y] (f : X β Y β β) : | |
| avg (fun z : X Γ Y => f z.1 z.2) = avg (fun x => avg (f x)) := by | |
| simp only [avg, Fintype.card_prod, Nat.cast_mul, Fintype.sum_prod_type, β Finset.sum_div, | |
| div_div] | |
| rw [mul_comm] | |
| end EditAverage | |
| namespace EditSlices | |
| open scoped BigOperators | |
| open EditAverage EditFourier | |
| variable {J : Type*} [Fintype J] [DecidableEq J] | |
| variable (G : J β Type*) [β j, AddCommGroup (G j)] [β j, Fintype (G j)] | |
| omit [Fintype J] [β j, Fintype (G j)] in | |
| lemma split_add_single (i : J) (x u : G i) (y : β j : {j // j β i}, G j) : | |
| (Equiv.piSplitAt i G).symm (x + u, y) = | |
| (Equiv.piSplitAt i G).symm (x, y) + Pi.single i u := by | |
| ext j | |
| by_cases h : j = i | |
| Β· subst j | |
| simp [Equiv.piSplitAt] | |
| Β· simp [Equiv.piSplitAt, h] | |
| noncomputable def slice (H : (β j, G j) β EditL1.L1) (i : J) (Ο : β) : G i β EditL1.L1 := | |
| fun x => EditL1.pack (fun y : (β j : {j // j β i}, G j) => | |
| (1 / (Ο * Fintype.card (β j : {j // j β i}, G j))) β’ | |
| H ((Equiv.piSplitAt i G).symm (x,y))) | |
| lemma variation_slice (H : (β j, G j) β EditL1.L1) (i : J) (Ο : β) (hΟ : 0 < Ο) | |
| (u : G i) : variation (slice G H i Ο) u = variation H (Pi.single i u) / Ο := by | |
| let Y := β j : {j // j β i}, G j | |
| let E := Equiv.piSplitAt i G | |
| have hY : 0 < (Fintype.card Y : β) := Nat.cast_pos.mpr Fintype.card_pos | |
| have hweight : 0 β€ 1 / (Ο * (Fintype.card Y : β)) := by positivity | |
| have hd (x : G i) : | |
| βslice G H i Ο (x + u) - slice G H i Ο xβ = | |
| (1 / Ο) * avg (fun y : Y => βH (E.symm (x,y) + Pi.single i u) - H (E.symm (x,y))β) := by | |
| rw [slice, slice, EditL1.weighted_pack_distance (fun _ => _) (fun _ => hweight)] | |
| simp_rw [split_add_single] | |
| rw [β Finset.mul_sum, avg] | |
| dsimp [E, Y] | |
| ring | |
| have he : variation H (Pi.single i u) = | |
| avg (fun x : G i => avg (fun y : Y => | |
| βH (E.symm (x,y) + Pi.single i u) - H (E.symm (x,y))β)) := by | |
| rw [β avg_prod] | |
| exact (avg_equiv E.symm (fun z => βH (z + Pi.single i u) - H zβ)).symm | |
| change avg (fun x => βslice G H i Ο (x + u) - slice G H i Ο xβ) = _ | |
| simp_rw [hd] | |
| rw [avg_mul, β he] | |
| ring | |
| end EditSlices | |
| end OAI | |