Download data/lean/OAI/Probability/BinarySweep/TensorBounds/TensorReduction.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.77 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/TensorBounds/TensorReduction.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/BinarySweep/TensorBounds/TensorReduction.lean
-
curl -L -o TensorReduction.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/TensorBounds/TensorReduction.lean
8.77 kB
| import Mathlib | |
| import OAI.Probability.BinarySweep.MatrixBounds.SymmetricDensity | |
| namespace OAI | |
| noncomputable section | |
| section | |
| open scoped BigOperators Classical ComplexOrder | |
| open Matrix | |
| namespace BinaryCoordinateSweeps.Density | |
| variable {K A B : Type*} [Fintype K] [DecidableEq K] [Fintype A] [DecidableEq A] | |
| [Fintype B] [DecidableEq B] | |
| def reshape (e : K β A Γ B) (v : K β β) : Matrix A B β := | |
| fun a b => β k, if e k = (a,b) then v k else 0 | |
| def kraus (e : K β A Γ B) (b : B) : Matrix A K β := | |
| fun a k => if e k = (a,b) then 1 else 0 | |
| def densityChannel (e : K β A Γ B) (M : Matrix K K β) : Matrix A A β := | |
| β b, kraus e b * M * (kraus e b).conjTranspose | |
| omit [DecidableEq K] in | |
| lemma densityChannel_psd (e : K β A Γ B) {M : Matrix K K β} (hM : M.PosSemidef) : | |
| (densityChannel e M).PosSemidef := | |
| Matrix.posSemidef_sum _ (fun _ _ => hM.mul_mul_conjTranspose_same _) | |
| omit [DecidableEq K] [Fintype A] in | |
| lemma densityChannel_sub (e : K β A Γ B) (M N : Matrix K K β) : | |
| densityChannel e (M-N) = densityChannel e M - densityChannel e N := by | |
| simp only [densityChannel, Matrix.mul_sub, Matrix.sub_mul, Finset.sum_sub_distrib] | |
| omit [DecidableEq K] [Fintype A] in | |
| lemma densityChannel_smul (e : K β A Γ B) (c : β) (M : Matrix K K β) : | |
| densityChannel e (c β’ M) = c β’ densityChannel e M := by | |
| simp only [densityChannel, Matrix.mul_smul, Matrix.smul_mul, Finset.smul_sum] | |
| omit [DecidableEq K] [Fintype A] in | |
| lemma densityChannel_sum {T : Type*} [Fintype T] (e : K β A Γ B) (M : T β Matrix K K β) : | |
| densityChannel e (β t, M t) = β t, densityChannel e (M t) := by | |
| simp only [densityChannel, Matrix.mul_sum, Matrix.sum_mul] | |
| exact Finset.sum_comm | |
| omit [DecidableEq K] [Fintype A] [Fintype B] in | |
| lemma kraus_mulVec (e : K β A Γ B) (v : K β β) (b : B) : | |
| (kraus e b).mulVec v = fun a => reshape e v a b := by | |
| ext a | |
| simp only [Matrix.mulVec, dotProduct, kraus, reshape, ite_mul, one_mul, zero_mul] | |
| omit [DecidableEq K] in | |
| lemma densityChannel_rankOne (e : K β A Γ B) (v : K β β) : | |
| densityChannel e (rankOne v) = reshape e v * (reshape e v).conjTranspose := by | |
| simp only [densityChannel, rankOne_conjugate, kraus_mulVec] | |
| ext a b | |
| simp only [Matrix.sum_apply, rankOne, vecMulVec_apply, Pi.star_apply, | |
| Matrix.mul_apply, Matrix.conjTranspose_apply] | |
| omit [Fintype A] [Fintype B] in | |
| lemma reshape_injective_apply (e : K β A Γ B) (he : Function.Injective e) (v : K β β) (k : K) : | |
| reshape e v (e k).1 (e k).2 = v k := by | |
| simp only [reshape, Prod.mk.eta, he.eq_iff, Finset.sum_ite_eq', Finset.mem_univ, ite_true] | |
| omit [DecidableEq K] [Fintype A] [Fintype B] in | |
| lemma reshape_outside (e : K β A Γ B) (v : K β β) (a : A) (b : B) | |
| (h : (a,b) β Set.range e) : reshape e v a b = 0 := by | |
| apply Finset.sum_eq_zero | |
| intro k hk | |
| exact ite_eq_right (fun hh => h β¨k,hhβ©) | |
| def wordPair (n : β) (e : K β A Γ B) : (Fin n β K) β (Fin n β A) Γ (Fin n β B) := | |
| fun w => (fun i => (e (w i)).1, fun i => (e (w i)).2) | |
| omit [Fintype K] [DecidableEq K] [Fintype A] [DecidableEq A] [Fintype B] [DecidableEq B] in | |
| lemma wordPair_eq_iff (n : β) (e : K β A Γ B) (w : Fin n β K) | |
| (x : Fin n β A) (y : Fin n β B) : wordPair n e w = (x,y) β β i, e (w i) = (x i,y i) := by | |
| simp only [wordPair, funext_iff, Prod.ext_iff] | |
| exact β¨fun h i => β¨h.1 i,h.2 iβ©, fun h => β¨fun i => (h i).1, fun i => (h i).2β©β© | |
| omit [Fintype K] [DecidableEq K] [Fintype A] [DecidableEq A] [Fintype B] [DecidableEq B] in | |
| lemma wordPair_injective (n : β) (e : K β A Γ B) (he : Function.Injective e) : | |
| Function.Injective (wordPair n e) := by | |
| intro w v h | |
| funext i | |
| apply he | |
| exact Prod.ext (congrFun (congrArg Prod.fst h) i) (congrFun (congrArg Prod.snd h) i) | |
| omit [DecidableEq K] [Fintype A] [Fintype B] in | |
| lemma reshape_tensor (n : β) (e : K β A Γ B) (u : K β β) | |
| (x : Fin n β A) (y : Fin n β B) : | |
| reshape (wordPair n e) (tensorProductVector n u) x y = β i, reshape e u (x i) (y i) := by | |
| simp only [reshape, tensorProductVector, wordPair_eq_iff] | |
| rw [Fintype.prod_sum (fun i k => if e k = (x i,y i) then u k else 0)] | |
| apply Finset.sum_congr rfl | |
| intro w hw | |
| by_cases h : β i, e (w i) = (x i,y i) | |
| Β· simp only [ite_eq_left h] | |
| apply Finset.prod_congr rfl | |
| intro i hi | |
| rw [ite_eq_left (h i)] | |
| Β· rw [ite_eq_right h] | |
| obtain β¨i,hiβ© := not_forall.mp h | |
| exact (Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi)).symm | |
| def matrixTensorPower (n : β) (M : Matrix A A β) : Matrix (Fin n β A) (Fin n β A) β := | |
| fun x y => β i, M (x i) (y i) | |
| def matrixTensorRect (n : β) (U : Matrix A B β) : Matrix (Fin n β A) (Fin n β B) β := | |
| fun x y => β i, U (x i) (y i) | |
| omit [Fintype A] [DecidableEq A] [DecidableEq B] in | |
| lemma tensor_gram (n : β) (U : Matrix A B β) : | |
| matrixTensorRect n U * (matrixTensorRect n U).conjTranspose = | |
| matrixTensorPower n (U * U.conjTranspose) := by | |
| ext x z | |
| simp only [Matrix.mul_apply, Matrix.conjTranspose_apply, matrixTensorPower, matrixTensorRect, star_prod, | |
| β Finset.prod_mul_distrib] | |
| exact (Fintype.prod_sum (fun i b => U (x i) b * star (U (z i) b))).symm | |
| omit [DecidableEq K] in | |
| lemma densityChannel_tensorRankOne (n : β) (e : K β A Γ B) (u : K β β) : | |
| densityChannel (wordPair n e) (rankOne (tensorProductVector n u)) = | |
| matrixTensorPower n (reshape e u * (reshape e u).conjTranspose) := by | |
| rw [densityChannel_rankOne] | |
| have he : reshape (wordPair n e) (tensorProductVector n u) = | |
| matrixTensorRect n (reshape e u) := by | |
| ext x y | |
| exact reshape_tensor n e u x y | |
| rw [he, tensor_gram] | |
| end BinaryCoordinateSweeps.Density | |
| end | |
| open scoped BigOperators Classical ComplexOrder | |
| open Matrix | |
| namespace BinaryCoordinateSweeps.Density | |
| variable {K A B : Type*} [Fintype K] [DecidableEq K] [Fintype A] [DecidableEq A] | |
| [Fintype B] [DecidableEq B] | |
| lemma reshape_trace (e : K β A Γ B) (he : Function.Injective e) (v : K β β) : | |
| (reshape e v * (reshape e v).conjTranspose).trace = (rankOne v).trace := by | |
| simp only [Matrix.trace, Matrix.diag, Matrix.mul_apply, Matrix.conjTranspose_apply, | |
| rankOne, Matrix.vecMulVec_apply, Pi.star_apply] | |
| symm | |
| calc | |
| _ = β x : A Γ B, reshape e v x.1 x.2 * star (reshape e v x.1 x.2) := | |
| Fintype.sum_of_injective e he (fun k => v k * star (v k)) | |
| (fun x : A Γ B => reshape e v x.1 x.2 * star (reshape e v x.1 x.2)) | |
| (by rintro β¨a,bβ© h; rw [reshape_outside e v a b h]; simp) | |
| (by intro k; rw [reshape_injective_apply e he]) | |
| _ = _ := Fintype.sum_prod_type _ | |
| omit [DecidableEq A] in | |
| lemma gram_psd (U : Matrix A B β) : (U * U.conjTranspose).PosSemidef := by | |
| simpa only [Matrix.mul_one] using | |
| (Matrix.PosSemidef.one : (1 : Matrix B B β).PosSemidef).mul_mul_conjTranspose_same U | |
| omit [DecidableEq K] [Fintype A] in | |
| lemma reshape_even {P : Type*} (pa : A β P) (pb : B β P) (e : K β A Γ B) | |
| (he : β k, pa (e k).1 = pb (e k).2) (v : K β β) (a a' : A) | |
| (haa : pa a β pa a') : (reshape e v * (reshape e v).conjTranspose) a a' = 0 := by | |
| apply Finset.sum_eq_zero | |
| intro b hb | |
| change reshape e v a b * star (reshape e v a' b) = 0 | |
| by_cases ha : pa a = pb b | |
| Β· have hn : (a', b) β Set.range e := by | |
| rintro β¨k,hkβ© | |
| have hh := he k | |
| rw [hk] at hh | |
| exact haa (ha.trans hh.symm) | |
| rw [reshape_outside e v a' b hn, star_zero, mul_zero] | |
| Β· have hn : (a,b) β Set.range e := by | |
| rintro β¨k,hkβ© | |
| have hh := he k | |
| rw [hk] at hh | |
| exact ha hh | |
| rw [reshape_outside e v a b hn, zero_mul] | |
| def reducedPhaseDensity (n : β) (e : K β A Γ B) (c : WordType K n) | |
| (t : K β ZMod (n+1)) : Matrix A A β := | |
| reshape e (phasedVector n (empirical n c) t) * | |
| (reshape e (phasedVector n (empirical n c) t)).conjTranspose | |
| lemma reducedPhaseDensity_psd (n : β) (e : K β A Γ B) (c : WordType K n) | |
| (t : K β ZMod (n+1)) : (reducedPhaseDensity n e c t).PosSemidef := gram_psd _ | |
| lemma reducedPhaseDensity_trace (n : β) (hn : 0 < n) (e : K β A Γ B) | |
| (he : Function.Injective e) (c : WordType K n) (t : K β ZMod (n+1)) : | |
| (reducedPhaseDensity n e c t).trace = 1 := by | |
| rw [reducedPhaseDensity, reshape_trace e he] | |
| exact phasedVector_trace n (empirical n c) (empirical_nonneg n c) (empirical_sum n hn c) t | |
| omit [Fintype A] in | |
| lemma reducedPhaseDensity_even {P : Type*} (n : β) (pa : A β P) (pb : B β P) | |
| (e : K β A Γ B) (he : β k, pa (e k).1 = pb (e k).2) | |
| (c : WordType K n) (t : K β ZMod (n+1)) (a a' : A) (haa : pa a β pa a') : | |
| reducedPhaseDensity n e c t a a' = 0 := reshape_even pa pb e he _ a a' haa | |
| end BinaryCoordinateSweeps.Density | |
| end | |
| end OAI | |