Download data/lean/OAI/Probability/BinarySweep/TensorBounds/EmpiricalTensor.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.36 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/TensorBounds/EmpiricalTensor.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/BinarySweep/TensorBounds/EmpiricalTensor.lean
-
curl -L -o EmpiricalTensor.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/BinarySweep/TensorBounds/EmpiricalTensor.lean
7.36 kB
| import Mathlib | |
| import OAI.Probability.BinarySweep.TensorBounds.TensorPhases | |
| namespace OAI | |
| noncomputable section | |
| section | |
| open scoped BigOperators Classical ComplexOrder | |
| open Matrix | |
| namespace BinaryCoordinateSweeps.Density | |
| variable {A : Type*} [Fintype A] [DecidableEq A] | |
| def tensorAmplitude (n : β) (r : A β β) (w : Fin n β A) : β := β i, Real.sqrt (r (w i)) | |
| def tensorProductVector (n : β) (v : A β β) : (Fin n β A) β β := fun w => β i, v (w i) | |
| def phasedVector (n : β) (r : A β β) (ΞΈ : A β ZMod (n+1)) : A β β := | |
| fun a => (Real.sqrt (r a) : β) * ZMod.stdAddChar (ΞΈ a) | |
| omit [Fintype A] [DecidableEq A] in | |
| lemma tensorProductVector_phased (n : β) (r : A β β) (ΞΈ : A β ZMod (n+1)) (w : Fin n β A) : | |
| tensorProductVector n (phasedVector n r ΞΈ) w = | |
| (tensorAmplitude n r w : β) * tensorPhase n ΞΈ w := by | |
| simp only [tensorProductVector, phasedVector, tensorAmplitude, tensorPhase, | |
| Finset.prod_mul_distrib, Complex.ofReal_prod] | |
| lemma tensorAmplitude_counts (n : β) (r : A β β) (w : Fin n β A) : | |
| tensorAmplitude n r w = β a, Real.sqrt (r a)^wordCounts w a := | |
| prod_wordCounts (fun a => Real.sqrt (r a)) w | |
| lemma tensorAmplitude_sq (n : β) (r : A β β) (hr : β a, 0 β€ r a) (w : Fin n β A) : | |
| tensorAmplitude n r w * tensorAmplitude n r w = β a, (r a)^wordCounts w a := by | |
| rw [tensorAmplitude_counts, β Finset.prod_mul_distrib] | |
| apply Finset.prod_congr rfl | |
| intro a ha | |
| rw [β mul_pow, Real.mul_self_sqrt (hr a)] | |
| def phaseAverage (n : β) (r : A β β) : Matrix (Fin n β A) (Fin n β A) β := | |
| (((n+1 : β) : β)^Fintype.card A)β»ΒΉ β’ | |
| β ΞΈ : A β ZMod (n+1), rankOne (tensorProductVector n (phasedVector n r ΞΈ)) | |
| lemma phaseAverage_psd (n : β) (r : A β β) : (phaseAverage n r).PosSemidef := by | |
| apply Matrix.PosSemidef.smul (Matrix.posSemidef_sum _ (fun ΞΈ _ => rankOne_psd _)) | |
| exact inv_nonneg.mpr (pow_nonneg (by exact_mod_cast Nat.zero_le (n+1)) _) | |
| lemma phaseAverage_apply (n : β) (r : A β β) (hr : β a, 0 β€ r a) | |
| (w v : Fin n β A) : | |
| phaseAverage n r w v = if wordCounts w = wordCounts v then | |
| ((β a, r a^wordCounts w a : β) : β) else 0 := by | |
| simp only [phaseAverage, Matrix.smul_apply, Matrix.sum_apply, rankOne, vecMulVec, | |
| Matrix.of_apply, Pi.star_apply, tensorProductVector_phased, star_mul, Complex.star_def, | |
| Complex.conj_ofReal] | |
| have hfactor : (β ΞΈ : A β ZMod (n+1), | |
| ((tensorAmplitude n r w : β) * tensorPhase n ΞΈ w) * | |
| (star (tensorPhase n ΞΈ v) * (tensorAmplitude n r v : β))) = | |
| ((tensorAmplitude n r w : β) * (tensorAmplitude n r v : β)) * | |
| β ΞΈ : A β ZMod (n+1), tensorPhase n ΞΈ w * star (tensorPhase n ΞΈ v) := by | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro ΞΈ hΞΈ | |
| ring | |
| change (((n+1 : β) : β)^Fintype.card A)β»ΒΉ * _ = _ | |
| simp only [Complex.star_def] at hfactor | |
| rw [hfactor] | |
| change _ * (_ * β ΞΈ : A β ZMod (n+1), tensorPhase n ΞΈ w * star (tensorPhase n ΞΈ v)) = _ | |
| rw [phase_pair_sum] | |
| by_cases h : wordCounts w = wordCounts v | |
| Β· rw [ite_eq_left h, ite_eq_left h] | |
| have ha : tensorAmplitude n r w = tensorAmplitude n r v := by | |
| simp only [tensorAmplitude_counts, h] | |
| rw [β ha, β Complex.ofReal_mul, tensorAmplitude_sq n r hr w] | |
| have hp : (((n+1 : β) : β)^Fintype.card A) β 0 := pow_ne_zero _ (by exact_mod_cast Nat.succ_ne_zero n) | |
| field_simp | |
| Β· simp [h] | |
| lemma phaseAverage_kernel (n : β) (r : A β β) (hr : β a, 0 β€ r a) : | |
| phaseAverage n r = β c : WordType A n, | |
| ((β a, r a ^ c.val a : β) : β) β’ typeOnes (wordType n) c := by | |
| ext w v | |
| rw [phaseAverage_apply n r hr, sum_typeOnes] | |
| simp only [wordType_eq_iff] | |
| rfl | |
| omit [Fintype A] [DecidableEq A] in | |
| lemma phasedVector_norm (n : β) (r : A β β) (hr : β a, 0 β€ r a) | |
| (ΞΈ : A β ZMod (n+1)) (a : A) : | |
| phasedVector n r ΞΈ a * star (phasedVector n r ΞΈ a) = (r a : β) := by | |
| have he : ZMod.stdAddChar (ΞΈ a) * star (ZMod.stdAddChar (ΞΈ a)) = 1 := by | |
| rw [phase_star, β AddChar.map_add_eq_mul, add_neg_cancel, AddChar.map_zero_eq_one] | |
| simp only [phasedVector, star_mul, Complex.star_def, Complex.conj_ofReal] | |
| calc | |
| _ = ((Real.sqrt (r a) : β) * Real.sqrt (r a)) * | |
| (ZMod.stdAddChar (ΞΈ a) * star (ZMod.stdAddChar (ΞΈ a))) := by simp only [Complex.star_def]; ring | |
| _ = _ := by rw [he, mul_one, β Complex.ofReal_mul, Real.mul_self_sqrt (hr a)] | |
| omit [DecidableEq A] in | |
| lemma phasedVector_trace (n : β) (r : A β β) (hr : β a, 0 β€ r a) | |
| (hs : β a, r a = 1) (ΞΈ : A β ZMod (n+1)) : | |
| Matrix.trace (rankOne (phasedVector n r ΞΈ)) = 1 := by | |
| simp only [Matrix.trace, Matrix.diag, rankOne, vecMulVec, Matrix.of_apply, Pi.star_apply, | |
| phasedVector_norm n r hr, β Complex.ofReal_sum, hs, Complex.ofReal_one] | |
| end BinaryCoordinateSweeps.Density | |
| end | |
| open scoped BigOperators Classical ComplexOrder | |
| open Matrix | |
| namespace BinaryCoordinateSweeps.Density | |
| variable {A : Type*} [Fintype A] [DecidableEq A] | |
| def empirical (n : β) (c : WordType A n) : A β β := fun a => c.val a / (n : β) | |
| lemma empirical_nonneg (n : β) (c : WordType A n) (a : A) : 0 β€ empirical n c a := | |
| div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) | |
| lemma empirical_sum (n : β) (hn : 0 < n) (c : WordType A n) : β a, empirical n c a = 1 := by | |
| simp only [empirical, β Finset.sum_div, β Nat.cast_sum, wordType_total, | |
| div_self (by exact_mod_cast Nat.ne_of_gt hn : (n : β) β 0)] | |
| lemma type_mass_inv (n : β) (hn : 0 < n) (c : WordType A n) : | |
| (Nat.multinomial Finset.univ c.val : β)β»ΒΉ β€ | |
| ((n+1 : β) : β)^Fintype.card A * β a, empirical n c a ^ c.val a := by | |
| have hm : 0 < (Nat.multinomial Finset.univ c.val : β) := by exact_mod_cast Nat.multinomial_pos _ _ | |
| rw [inv_eq_one_div] | |
| apply (div_le_iffβ hm).mpr | |
| have hh := type_mass_lower n hn c.val (wordType_total n c) | |
| simpa only [empirical, mul_assoc, mul_left_comm, mul_comm] using hh | |
| theorem finite_postselection (n : β) (hn : 0 < n) : | |
| ((((n+1 : β) : β)^Fintype.card A) β’ | |
| (β c : WordType A n, phaseAverage n (empirical n c)) - symmetricProjector n).PosSemidef := by | |
| let d : WordType A n β β := fun t => ((n+1 : β) : β)^Fintype.card A * | |
| β c : WordType A n, β a, empirical n c a ^ t.val a | |
| have hd (t : WordType A n) : (Nat.multinomial Finset.univ t.val : β)β»ΒΉ β€ d t := by | |
| refine (type_mass_inv n hn t).trans ?_ | |
| apply mul_le_mul_of_nonneg_left _ (pow_nonneg (Nat.cast_nonneg _) _) | |
| exact Finset.single_le_sum (f := fun c : WordType A n => β a, empirical n c a ^ t.val a) | |
| (fun c _ => Finset.prod_nonneg | |
| (fun a _ => pow_nonneg (empirical_nonneg n c a) _)) (Finset.mem_univ t) | |
| convert typeKernel_mono (wordType (A := A) n) | |
| (fun t => (Nat.multinomial Finset.univ t.val : β)β»ΒΉ) d hd using 1 | |
| apply Iff.of_eq | |
| congr 1 | |
| ext w v | |
| simp only [Matrix.sub_apply, Matrix.smul_apply, Matrix.sum_apply, | |
| phaseAverage_apply n _ (empirical_nonneg n _), symmetricProjector, smul_eq_mul, | |
| wordType_eq_iff, Pi.sub_apply] | |
| split_ifs with h | |
| Β· simp only [d, Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_natCast, | |
| Complex.ofReal_sum, Complex.ofReal_inv] | |
| rfl | |
| Β· simp | |
| end BinaryCoordinateSweeps.Density | |
| end | |
| end OAI | |