Download data/lean/OAI/Probability/BinarySweep/MatrixBounds/SparsePinching.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.79 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/MatrixBounds/SparsePinching.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/BinarySweep/MatrixBounds/SparsePinching.lean
-
curl -L -o SparsePinching.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/MatrixBounds/SparsePinching.lean
8.79 kB
| import Mathlib | |
| namespace OAI | |
| noncomputable section | |
| section | |
| open scoped BigOperators ComplexOrder | |
| open Matrix | |
| namespace BinaryCoordinateSweeps.Density | |
| variable {I J : Type*} [Fintype I] [Fintype J] [DecidableEq J] | |
| def blockVec (f : I β J) (a : J) (x : I β β) : I β β := | |
| fun i => if f i = a then x i else 0 | |
| def pinch (f : I β J) (A : Matrix I I β) : Matrix I I β := | |
| fun i j => if f i = f j then A i j else 0 | |
| omit [Fintype I] in | |
| lemma sum_blockVec (f : I β J) (x : I β β) : β a, blockVec f a x = x := by | |
| ext i | |
| simp [blockVec] | |
| omit [Fintype I] [Fintype J] in | |
| lemma pinch_hermitian (f : I β J) {A : Matrix I I β} (hA : A.IsHermitian) : | |
| (pinch f A).IsHermitian := by | |
| ext i j | |
| change star (if f j = f i then A j i else 0) = if f i = f j then A i j else 0 | |
| by_cases h : f i = f j | |
| Β· rw [ite_eq_left h, ite_eq_left h.symm] | |
| exact congrFun (congrFun hA i) j | |
| Β· rw [ite_eq_right h, ite_eq_right (Ne.symm h), star_zero] | |
| lemma pinch_form (f : I β J) (A : Matrix I I β) (x : I β β) : | |
| star x β¬α΅₯ (pinch f A).mulVec x = | |
| β a, star (blockVec f a x) β¬α΅₯ A.mulVec (blockVec f a x) := by | |
| simp only [dotProduct, mulVec, blockVec, pinch, Pi.star_apply, apply_ite, star_zero, | |
| Finset.mul_sum] | |
| conv_rhs => rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro i hi | |
| conv_rhs => rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro j hj | |
| simp only [ite_mul, zero_mul, mul_ite, mul_zero] | |
| by_cases h : f i = f j | |
| Β· rw [h] | |
| simp | |
| Β· simp [h] | |
| lemma pinch_posSemidef (f : I β J) {A : Matrix I I β} (hA : A.PosSemidef) : | |
| (pinch f A).PosSemidef := by | |
| refine .of_dotProduct_mulVec_nonneg (pinch_hermitian f hA.1) (fun x => ?_) | |
| rw [pinch_form] | |
| exact Finset.sum_nonneg (fun a _ => hA.dotProduct_mulVec_nonneg _) | |
| lemma form_cross_le {A : Matrix I I β} (hA : A.PosSemidef) (x y : I β β) : | |
| star x β¬α΅₯ A.mulVec y + star y β¬α΅₯ A.mulVec x β€ | |
| star x β¬α΅₯ A.mulVec x + star y β¬α΅₯ A.mulVec y := by | |
| have h := hA.dotProduct_mulVec_nonneg (x-y) | |
| rw [star_sub, mulVec_sub, sub_dotProduct, dotProduct_sub, dotProduct_sub] at h | |
| exact sub_nonneg.mp (by convert h using 1; abel) | |
| omit [Fintype J] in | |
| lemma block_form_zero (f : I β J) (A : Matrix I I β) (a b : J) | |
| (h : β i j, f i = a β f j = b β A i j = 0) (x : I β β) : | |
| star (blockVec f a x) β¬α΅₯ A.mulVec (blockVec f b x) = 0 := by | |
| simp only [dotProduct, mulVec, blockVec, Pi.star_apply, apply_ite, star_zero, | |
| Finset.mul_sum] | |
| apply Finset.sum_eq_zero | |
| intro i hi | |
| apply Finset.sum_eq_zero | |
| intro j hj | |
| by_cases ha : f i = a | |
| Β· by_cases hb : f j = b | |
| Β· simp [ha, hb, h i j ha hb] | |
| Β· simp [hb] | |
| Β· simp [ha] | |
| theorem sparse_pinching (f : I β J) (R : J β J β Prop) [DecidableRel R] | |
| (hR : β β¦left rightβ¦, R left right β R right left) | |
| (D : β) (hD : β a, (Finset.univ.filter (R a)).card β€ D) | |
| {A : Matrix I I β} (hA : A.PosSemidef) | |
| (hz : β i j, Β¬ R (f i) (f j) β A i j = 0) : | |
| ((D : β) β’ pinch f A - A).PosSemidef := by | |
| have hp := pinch_hermitian f hA.1 | |
| refine .of_dotProduct_mulVec_nonneg ((hp.smul (by simp)).sub hA.1) (fun x => ?_) | |
| let t : J β J β β := fun a b => star (blockVec f a x) β¬α΅₯ A.mulVec (blockVec f b x) | |
| have hdiag (a : J) : 0 β€ t a a := hA.dotProduct_mulVec_nonneg _ | |
| have ht (a b : J) (hab : Β¬R a b) : t a b = 0 := by | |
| apply block_form_zero | |
| intro i j hi hj | |
| exact hz i j (by simpa [hi, hj] using hab) | |
| have hsum : β a, β b β Finset.univ.filter (R a), t a b = star x β¬α΅₯ A.mulVec x := by | |
| simp_rw [Finset.sum_filter] | |
| have ht' : β a b, (if R a b then t a b else 0) = t a b := by | |
| intro a b | |
| split_ifs with h | |
| Β· rfl | |
| Β· exact (ht a b h).symm | |
| simp_rw [ht'] | |
| dsimp [t] | |
| simp_rw [β dotProduct_sum, β mulVec_sum, sum_blockVec] | |
| rw [β sum_dotProduct, β star_sum, sum_blockVec] | |
| have hswap : β a, β b β Finset.univ.filter (R a), t b a = | |
| β a, β b β Finset.univ.filter (R a), t a b := by | |
| simp only [Finset.sum_filter] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro a ha | |
| apply Finset.sum_congr rfl | |
| intro b hb | |
| have he : R b a β R a b := β¨fun h => hR h, fun h => hR hβ© | |
| simp only [he] | |
| have hdeg : β a, β b β Finset.univ.filter (R a), (t a a + t b b) = | |
| 2 * β a, ((Finset.univ.filter (R a)).card : β) * t a a := by | |
| simp only [Finset.sum_add_distrib] | |
| have hs : β a, β b β Finset.univ.filter (R a), t b b = | |
| β a, β b β Finset.univ.filter (R a), t a a := by | |
| simp only [Finset.sum_filter] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro a ha | |
| apply Finset.sum_congr rfl | |
| intro b hb | |
| simp only [show R b a β R a b from β¨fun h => hR h, fun h => hR hβ©] | |
| rw [hs] | |
| simp [two_mul] | |
| have hle := Finset.sum_le_sum (fun a (_ : a β (Finset.univ : Finset J)) => | |
| Finset.sum_le_sum (fun b (_ : b β Finset.univ.filter (R a)) => | |
| form_cross_le hA (blockVec f a x) (blockVec f b x))) | |
| change (β a, β b β Finset.univ.filter (R a), (t a b + t b a)) β€ _ at hle | |
| simp only [Finset.sum_add_distrib] at hle | |
| rw [hswap, hsum] at hle | |
| have hc : star x β¬α΅₯ A.mulVec x β€ β a, ((Finset.univ.filter (R a)).card : β) * t a a := by | |
| have hh := hdeg | |
| simp only [Finset.sum_add_distrib] at hh | |
| rw [hh] at hle | |
| simp only [two_mul, Complex.le_def, Complex.add_re, Complex.add_im] at hle | |
| exact Complex.le_def.mpr β¨by linarith [hle.1], by linarith [hle.2]β© | |
| have hd : β a, ((Finset.univ.filter (R a)).card : β) * t a a β€ | |
| (D : β) * β a, t a a := by | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_le_sum | |
| intro a ha | |
| exact mul_le_mul_of_nonneg_right (by exact_mod_cast hD a) (hdiag a) | |
| have hf := hc.trans hd | |
| rw [sub_mulVec, dotProduct_sub, smul_mulVec, dotProduct_smul, smul_eq_mul] | |
| apply sub_nonneg.mpr | |
| simpa only [pinch_form, t] using hf | |
| end BinaryCoordinateSweeps.Density | |
| end | |
| open scoped BigOperators Classical | |
| namespace BinaryCoordinateSweeps.Density | |
| variable {I : Type*} [Fintype I] [LinearOrder I] | |
| def subsetCode (k : β) (s : Finset I) : Fin k β Option I := | |
| fun i => if h : i.val < s.card then some (s.orderEmbOfFin rfl β¨i.val,hβ©) else none | |
| omit [Fintype I] in | |
| lemma subsetCode_range (k : β) (s : Finset I) (hs : s.card β€ k) (j : I) : | |
| some j β Set.range (subsetCode k s) β j β s := by | |
| constructor | |
| Β· rintro β¨i,hiβ© | |
| dsimp only [subsetCode] at hi | |
| split_ifs at hi with h | |
| Β· have hj := Option.some.inj hi | |
| rw [β hj] | |
| exact Finset.orderEmbOfFin_mem s rfl _ | |
| Β· intro hj | |
| have hr : j β Set.range (s.orderEmbOfFin rfl) := by | |
| rw [Finset.range_orderEmbOfFin]; exact hj | |
| obtain β¨i,hiβ© := hr | |
| refine β¨β¨i.val, i.isLt.trans_le hsβ©, ?_β© | |
| simp only [subsetCode, dite_eq_left i.isLt] | |
| exact congrArg some hi | |
| lemma card_small_subsets_le (k : β) : | |
| Fintype.card {s : Finset I // s.card β€ k} β€ (Fintype.card I + 1)^k := by | |
| let f : {s : Finset I // s.card β€ k} β (Fin k β Option I) := fun s => subsetCode k s.val | |
| have hf : Function.Injective f := by | |
| intro s t h | |
| apply Subtype.ext | |
| ext j | |
| rw [β subsetCode_range k s.val s.property j, β subsetCode_range k t.val t.property j] | |
| rw [show Set.range (subsetCode k s.val) = Set.range (subsetCode k t.val) from | |
| congrArg Set.range h] | |
| have hc := Fintype.card_le_of_injective f hf | |
| simpa only [Fintype.card_fun, Fintype.card_fin, Fintype.card_option] using hc | |
| def hamming (a b : I β Bool) : β := (Finset.univ.filter (fun i => a i β b i)).card | |
| omit [LinearOrder I] in | |
| lemma hamming_symm (a b : I β Bool) : hamming a b = hamming b a := by | |
| unfold hamming | |
| congr 1 | |
| ext i | |
| simp only [Finset.mem_filter, Finset.mem_univ, true_and, ne_comm] | |
| lemma hamming_degree (a : I β Bool) (k : β) : | |
| (Finset.univ.filter (fun b => hamming a b β€ k)).card β€ (Fintype.card I + 1)^k := by | |
| let f : {b : I β Bool // hamming a b β€ k} β {s : Finset I // s.card β€ k} := | |
| fun b => β¨Finset.univ.filter (fun i => a i β b.val i), b.propertyβ© | |
| have hf : Function.Injective f := by | |
| intro b c h | |
| apply Subtype.ext | |
| funext i | |
| have hi := Finset.ext_iff.mp (congrArg Subtype.val h) i | |
| simp only [f, Finset.mem_filter, Finset.mem_univ, true_and] at hi | |
| cases ha : a i <;> cases hb : b.val i <;> cases hc : c.val i <;> | |
| simp_all only [Bool.false_eq_true, Bool.true_eq_false, not_false_eq_true, ne_eq, | |
| not_true_eq_false, iff_false, iff_true] | |
| have hh := (Fintype.card_le_of_injective f hf).trans (card_small_subsets_le (I := I) k) | |
| simpa only [Fintype.card_subtype] using hh | |
| end BinaryCoordinateSweeps.Density | |
| end | |
| end OAI | |