math / data /lean /OAI /Probability /SKGap /Localization /Character.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
18.3 kB
import Mathlib
import OAI.Probability.SKGap.Terminal.Spin
namespace OAI
section
open scoped BigOperators
namespace SKGapCutoff
theorem exp_apply_hasSum {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[CompleteSpace E] (A : E β†’L[ℝ] E) (f : E) :
HasSum (fun k : β„• => (k.factorial : ℝ)⁻¹ β€’ ((A ^ k) f))
(NormedSpace.exp A f) := by
simpa only [NormedSpace.expSeries_apply_eq, ContinuousLinearMap.apply_apply,
smul_apply] using
(ContinuousLinearMap.apply ℝ E f).hasSum
(NormedSpace.expSeries_hasSum_exp (𝕂 := ℝ) A)
theorem exp_apply_of_apply_eq_zero {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E] (A : E β†’L[ℝ] E) (f : E)
(h : A f = 0) : NormedSpace.exp A f = f := by
have hp (k : β„•) : (A ^ (k + 1)) f = 0 := by
induction k with
| zero => simpa using h
| succ k ih => rw [pow_succ', mul_apply_eq_comp, ih, map_zero]
have hs : HasSum (fun k : β„• => (k.factorial : ℝ)⁻¹ β€’ ((A ^ k) f)) f := by
convert hasSum_ite_eq 0 f using 1
funext k
cases k with
| zero => simp
| succ k => simp [hp]
exact (exp_apply_hasSum A f).unique hs
@[simp] theorem semigroup_const {n : β„•} (J : Interaction n) (t a : ℝ) :
semigroup J t (fun _ => a) = fun _ => a := by
apply exp_apply_of_apply_eq_zero
funext x
change t * generator J (fun _ => a) x = 0
simp
theorem exp_smul_identity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[CompleteSpace E] (a : ℝ) :
NormedSpace.exp (a β€’ (1 : E β†’L[ℝ] E)) = Real.exp a β€’ (1 : E β†’L[ℝ] E) := by
simpa only [Algebra.algebraMap_eq_smul_one, ← Real.exp_eq_exp_ℝ] using
(NormedSpace.algebraMap_exp_comm (𝔸 := E β†’L[ℝ] E) a).symm
theorem semigroup_uniformization {n : β„•} (hn : 0 < n) (J : Interaction n) (t : ℝ) :
semigroup J t = Real.exp (-(n : ℝ) * t) β€’
NormedSpace.exp (((n : ℝ) * t) β€’ attemptLM J) := by
have hn' : (n : ℝ) β‰  0 := by exact_mod_cast ne_of_gt hn
have heq : t β€’ generatorCLM J =
(-(n : ℝ) * t) β€’ (1 : Observables n β†’L[ℝ] Observables n) +
((n : ℝ) * t) β€’ attemptLM J := by
unfold attemptLM
simp only [smul_add, smul_smul]
have hc : ((n : ℝ) * t) * (n : ℝ)⁻¹ = t := by field_simp
rw [hc]
module
let : NormedAlgebra β„š (Observables n β†’L[ℝ] Observables n) :=
NormedAlgebra.restrictScalars β„š ℝ _
unfold semigroup
rw [heq, NormedSpace.exp_add_of_commute
(((Commute.one_left (attemptLM J)).smul_left _).smul_right _),
exp_smul_identity, smul_mul_assoc, one_mul]
theorem semigroup_nonneg {n : β„•} (J : Interaction n) (t : ℝ) (ht : 0 ≀ t)
(f : Observables n) (hf : βˆ€ x, 0 ≀ f x) (x : Spin n) :
0 ≀ semigroup J t f x := by
by_cases hn : n = 0
Β· subst n
have hL : generatorCLM J = 0 := by
ext f x
simp [generatorCLM, generatorLM, generator]
simp only [semigroup, hL, smul_zero, NormedSpace.exp_zero,
one_apply_eq_self]
exact hf x
Β· rw [semigroup_uniformization (Nat.pos_of_ne_zero hn)]
simp only [smul_apply, Pi.smul_apply, smul_eq_mul]
apply mul_nonneg (le_of_lt (Real.exp_pos _))
have hs := Pi.hasSum.mp (exp_apply_hasSum (((n : ℝ) * t) β€’ attemptLM J) f) x
apply HasSum.nonneg _ hs
intro k
simp only [smul_pow, smul_apply, Pi.smul_apply, smul_eq_mul]
exact mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _))
(mul_nonneg (pow_nonneg (mul_nonneg (Nat.cast_nonneg _) ht) _)
(attempt_pow_nonneg J k f hf x))
theorem continuousKernel_nonneg {n : β„•} (J : Interaction n) (t : ℝ) (ht : 0 ≀ t)
(x y : Spin n) : 0 ≀ continuousKernel J t x y := by
exact semigroup_nonneg J t ht _ (fun _ => by split_ifs <;> norm_num) x
theorem continuousKernel_sum {n : β„•} (J : Interaction n) (t : ℝ) (x : Spin n) :
βˆ‘ y, continuousKernel J t x y = 1 := by
have eq_one : (βˆ‘ y : Spin n, fun z => if z = y then (1 : ℝ) else 0) =
fun _ : Spin n => (1 : ℝ) := by
funext z
simp
unfold continuousKernel
rw [← Finset.sum_apply, ← map_sum, eq_one, semigroup_const]
@[simp] theorem spin_sq {n : β„•} (x : Spin n) (i : Fin n) : spin x i ^ 2 = 1 := by
unfold spin
cases x i <;> norm_num
@[simp] theorem spin_mul_self {n : β„•} (x : Spin n) (i : Fin n) :
spin x i * spin x i = 1 := by simpa only [pow_two] using spin_sq x i
@[simp] theorem field_zero {n : β„•} (x : Spin n) (i : Fin n) :
field (0 : Interaction n) x i = 0 := by simp [field]
@[simp] theorem mean_zero {n : β„•} (x : Spin n) (i : Fin n) :
mean (0 : Interaction n) x i = 0 := by simp [mean]
@[simp] theorem energy_zero {n : β„•} (x : Spin n) :
energy (0 : Interaction n) x = 0 := by simp [energy]
@[simp] theorem card_spin (n : β„•) : Fintype.card (Spin n) = 2 ^ n := by
simp [Spin]
@[simp] theorem partition_zero (n : β„•) : partition (0 : Interaction n) = (2 : ℝ) ^ n := by
simp [partition]
@[simp] theorem gibbs_zero {n : β„•} (x : Spin n) :
gibbs (0 : Interaction n) x = ((2 : ℝ) ^ n)⁻¹ := by simp [gibbs]
noncomputable def character {n : β„•} (s : Finset (Fin n)) (x : Spin n) : ℝ :=
∏ i ∈ s, spin x i
@[simp] theorem character_empty {n : β„•} (x : Spin n) : character βˆ… x = 1 := by
simp [character]
@[simp] theorem character_sq {n : β„•} (s : Finset (Fin n)) (x : Spin n) :
character s x ^ 2 = 1 := by simp [character, ← Finset.prod_pow]
lemma character_erase {n : β„•} (s : Finset (Fin n)) (x : Spin n) (i : Fin n)
(hi : i ∈ s) : spin x i * character (s.erase i) x = character s x := by
exact Finset.mul_prod_erase s (fun j => spin x j) hi
lemma spin_replace_of_ne {n : β„•} (x : Spin n) {i j : Fin n} (h : j β‰  i) (b : Bool) :
spin (replace x i b) j = spin x j := by
simp [spin, replace, Function.update_of_ne h]
lemma character_replace_of_not_mem {n : β„•} (s : Finset (Fin n)) (x : Spin n)
(i : Fin n) (hi : i βˆ‰ s) (b : Bool) : character s (replace x i b) = character s x := by
apply Finset.prod_congr rfl
intro j hj
exact spin_replace_of_ne x (ne_of_mem_of_not_mem hj hi) b
lemma character_replace_of_mem {n : β„•} (s : Finset (Fin n)) (x : Spin n)
(i : Fin n) (hi : i ∈ s) (b : Bool) :
character s (replace x i b) = (if b then 1 else -1) * character (s.erase i) x := by
rw [← character_erase s (replace x i b) i hi,
character_replace_of_not_mem _ x i (Finset.notMem_erase i s)]
simp [spin]
lemma halfDiff_character {n : β„•} (s : Finset (Fin n)) (x : Spin n) (i : Fin n) :
halfDiff i (character s) x = if i ∈ s then character (s.erase i) x else 0 := by
by_cases hi : i ∈ s
Β· simp only [halfDiff, character_replace_of_mem s x i hi, Bool.false_eq_true, ↓reduceIte, hi]
ring
Β· simp [halfDiff, character_replace_of_not_mem s x i hi, hi]
lemma spin_mul_halfDiff_character {n : β„•} (s : Finset (Fin n)) (x : Spin n) (i : Fin n) :
spin x i * halfDiff i (character s) x = if i ∈ s then character s x else 0 := by
rw [halfDiff_character]
split_ifs with hi
Β· exact character_erase s x i hi
Β· ring
lemma generator_zero_character {n : β„•} (s : Finset (Fin n)) :
generatorCLM (0 : Interaction n) (character s) = -(s.card : ℝ) β€’ character s := by
funext x
change generator (0 : Interaction n) (character s) x = -(s.card : ℝ) * character s x
simp only [generator, mean_zero, zero_sub, neg_mul, spin_mul_halfDiff_character,
Finset.sum_neg_distrib]
simp
theorem exp_apply_of_eigenvector {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E] (A : E β†’L[ℝ] E) (f : E) (a : ℝ)
(h : A f = a β€’ f) : NormedSpace.exp A f = Real.exp a β€’ f := by
have hp (k : β„•) : (A ^ k) f = a ^ k β€’ f := by
induction k with
| zero => simp
| succ k ih =>
rw [pow_succ', mul_apply_eq_comp, ih, map_smul, h, smul_smul, pow_succ]
have hs : HasSum (fun k : β„• => (k.factorial : ℝ)⁻¹ * a ^ k) (Real.exp a) := by
simpa only [smul_eq_mul, Real.exp_eq_exp_ℝ] using
(NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) a)
apply (exp_apply_hasSum A f).unique
simpa only [hp, smul_smul] using hs.smul_const f
lemma semigroup_zero_character {n : β„•} (s : Finset (Fin n)) (t : ℝ) :
semigroup (0 : Interaction n) t (character s) =
Real.exp (-t * (s.card : ℝ)) β€’ character s := by
apply exp_apply_of_eigenvector
rw [smul_apply, generator_zero_character, smul_smul]
congr 1
ring
lemma attempt_zero_character {n : β„•} (s : Finset (Fin n)) :
attemptLM (0 : Interaction n) (character s) =
(1 - (s.card : ℝ) / n) β€’ character s := by
change character s + (n : ℝ)⁻¹ β€’ generatorCLM (0 : Interaction n) (character s) = _
rw [generator_zero_character, smul_smul]
module
lemma attempt_pow_zero_character {n : β„•} (s : Finset (Fin n)) (k : β„•) :
(attemptLM (0 : Interaction n) ^ k) (character s) =
(1 - (s.card : ℝ) / n) ^ k β€’ character s := by
induction k with
| zero => simp
| succ k ih =>
rw [pow_succ', mul_apply_eq_comp, ih, map_smul, attempt_zero_character,
smul_smul, pow_succ]
lemma character_eq_prod_univ {n : β„•} (s : Finset (Fin n)) (x : Spin n) :
character s x = ∏ i : Fin n, if i ∈ s then spin x i else 1 := by
simp [character, Finset.prod_ite_mem]
lemma character_inner {n : β„•} (s r : Finset (Fin n)) :
βˆ‘ x : Spin n, character s x * character r x =
if s = r then (2 : ℝ) ^ n else 0 := by
by_cases h : s = r
Β· subst r
simp only [← pow_two, character_sq, ↓reduceIte, Finset.sum_const,
Finset.card_univ, card_spin, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat]
Β· rw [ite_eq_right h]
have hp : (βˆ‘ x : Spin n, character s x * character r x) =
∏ i : Fin n, βˆ‘ b : Bool,
(if i ∈ s then (if b then (1 : ℝ) else -1) else 1) *
(if i ∈ r then (if b then (1 : ℝ) else -1) else 1) := by
rw [Fintype.prod_sum]
apply Finset.sum_congr rfl
intro x _
rw [character_eq_prod_univ, character_eq_prod_univ, ← Finset.prod_mul_distrib]
rfl
rw [hp]
obtain ⟨i, hi⟩ : βˆƒ i, Β¬ (i ∈ s ↔ i ∈ r) := by
by_contra! hc
exact h (Finset.ext hc)
apply Finset.prod_eq_zero (Finset.mem_univ i)
by_cases hs : i ∈ s <;> by_cases hr : i ∈ r
Β· exact (hi (by simp [hs, hr])).elim
Β· simp [hs, hr]
Β· simp [hs, hr]
Β· exact (hi (by simp [hs, hr])).elim
lemma character_sum {n : β„•} (s : Finset (Fin n)) :
βˆ‘ x : Spin n, character s x = if s = βˆ… then (2 : ℝ) ^ n else 0 := by
simpa only [character_empty, mul_one] using character_inner s βˆ…
lemma character_delta_sum {n : β„•} (x y : Spin n) :
βˆ‘ s : Finset (Fin n), character s x * character s y =
if x = y then (2 : ℝ) ^ n else 0 := by
have hsum : (βˆ‘ s : Finset (Fin n), character s x * character s y) =
∏ i : Fin n, (spin x i * spin y i + 1) := by
rw [Finset.prod_add_one]
simp only [Finset.powerset_univ]
apply Finset.sum_congr rfl
intro s _
exact (Finset.prod_mul_distrib (f := spin x) (g := spin y)).symm
rw [hsum]
by_cases h : x = y
Β· subst y
simp only [spin_mul_self, ↓reduceIte, Finset.prod_const, Finset.card_univ,
Fintype.card_fin]
norm_num
Β· rw [ite_eq_right h]
obtain ⟨i, hi⟩ : βˆƒ i, x i β‰  y i := Function.ne_iff.mp h
apply Finset.prod_eq_zero (Finset.mem_univ i)
unfold spin
cases hx : x i <;> cases hy : y i <;> simp_all
lemma delta_character_expansion {n : β„•} (y : Spin n) :
(fun x : Spin n => if x = y then (1 : ℝ) else 0) =
((2 : ℝ) ^ n)⁻¹ β€’ βˆ‘ s : Finset (Fin n), character s y β€’ character s := by
funext x
simp only [Pi.smul_apply, Finset.sum_apply, smul_eq_mul]
simp_rw [mul_comm (character _ y)]
rw [character_delta_sum]
split_ifs <;> simp
lemma character_parseval {n : β„•} (a : Finset (Fin n) β†’ ℝ) :
(βˆ‘ x : Spin n, (βˆ‘ s : Finset (Fin n), a s * character s x) ^ 2) =
(2 : ℝ) ^ n * βˆ‘ s : Finset (Fin n), a s ^ 2 := by
simp only [pow_two, Finset.sum_mul_sum]
rw [Finset.sum_comm]
apply Eq.trans _ (Finset.mul_sum ..).symm
apply Finset.sum_congr rfl
intro s _
rw [Finset.sum_comm]
simp_rw [show βˆ€ r x, a s * character s x * (a r * character r x) =
(a s * a r) * (character s x * character r x) by intros; ring,
← Finset.mul_sum, character_inner]
simp only [mul_ite, mul_zero, Fintype.sum_ite_eq]
ring
noncomputable def fourierKernel {n : β„•} (a : Finset (Fin n) β†’ ℝ)
(x y : Spin n) : ℝ :=
((2 : ℝ) ^ n)⁻¹ * βˆ‘ s : Finset (Fin n), a s * character s x * character s y
lemma continuousKernel_zero_fourier {n : β„•} (t : ℝ) (x y : Spin n) :
continuousKernel (0 : Interaction n) t x y =
fourierKernel (fun s => Real.exp (-t * (s.card : ℝ))) x y := by
unfold continuousKernel
rw [delta_character_expansion y, map_smul, map_sum]
simp_rw [map_smul, semigroup_zero_character]
simp only [Pi.smul_apply, Finset.sum_apply, smul_eq_mul, fourierKernel]
congr 1
apply Finset.sum_congr rfl
intro s _
ring
lemma discreteKernel_zero_fourier {n : β„•} (k : β„•) (x y : Spin n) :
discreteKernel (0 : Interaction n) k x y =
fourierKernel (fun s => (1 - (s.card : ℝ) / n) ^ k) x y := by
unfold discreteKernel
rw [delta_character_expansion y, map_smul, map_sum]
simp_rw [map_smul, attempt_pow_zero_character]
simp only [Pi.smul_apply, Finset.sum_apply, smul_eq_mul, fourierKernel]
congr 1
apply Finset.sum_congr rfl
intro s _
ring
noncomputable def centeredFourier {n : β„•} (a : Finset (Fin n) β†’ ℝ)
(s : Finset (Fin n)) : ℝ := a s - if s = βˆ… then 1 else 0
lemma centeredFourier_sum_sq {n : β„•} (a : Finset (Fin n) β†’ ℝ) (ha : a βˆ… = 1) :
βˆ‘ s, centeredFourier a s ^ 2 = (βˆ‘ s, a s ^ 2) - 1 := by
have h (s : Finset (Fin n)) : centeredFourier a s ^ 2 =
a s ^ 2 - if s = βˆ… then 1 else 0 := by
by_cases hs : s = βˆ… <;> simp [centeredFourier, hs, ha]
simp_rw [h, Finset.sum_sub_distrib]
simp
lemma centeredFourier_expansion {n : β„•} (a : Finset (Fin n) β†’ ℝ) (x y : Spin n) :
βˆ‘ s, centeredFourier a s * character s x * character s y =
(βˆ‘ s, a s * character s x * character s y) - 1 := by
simp only [centeredFourier, sub_mul, Finset.sum_sub_distrib]
simp
lemma fourierKernel_sub_uniform {n : β„•} (a : Finset (Fin n) β†’ ℝ) (x y : Spin n) :
fourierKernel a x y - ((2 : ℝ) ^ n)⁻¹ =
((2 : ℝ) ^ n)⁻¹ * βˆ‘ s, centeredFourier a s * character s x * character s y := by
rw [centeredFourier_expansion]
unfold fourierKernel
ring
lemma fourierKernel_chiSquare {n : β„•} (a : Finset (Fin n) β†’ ℝ) (ha : a βˆ… = 1)
(x : Spin n) :
(2 : ℝ) ^ n * βˆ‘ y, (fourierKernel a x y - ((2 : ℝ) ^ n)⁻¹) ^ 2 =
(βˆ‘ s, a s ^ 2) - 1 := by
simp_rw [fourierKernel_sub_uniform, mul_pow]
rw [← Finset.mul_sum, character_parseval]
simp only [mul_pow, character_sq, mul_one]
rw [centeredFourier_sum_sq a ha]
field_simp
lemma totalVariation_fourier_sq_le {n : β„•} (a : Finset (Fin n) β†’ ℝ)
(ha : a βˆ… = 1) (x : Spin n) :
4 * totalVariation (fourierKernel a x) (gibbs (0 : Interaction n)) ^ 2 ≀
(βˆ‘ s, a s ^ 2) - 1 := by
have hc := Finset.sum_mul_sq_le_sq_mul_sq (R := ℝ) Finset.univ
(fun y : Spin n => |fourierKernel a x y - ((2 : ℝ) ^ n)⁻¹|) (fun _ => 1)
simp only [mul_one, one_pow, Finset.sum_const, Finset.card_univ, card_spin,
nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat, mul_one, sq_abs] at hc
rw [mul_comm, fourierKernel_chiSquare a ha x] at hc
simp only [totalVariation, gibbs_zero]
nlinarith
lemma sum_pow_card {n : β„•} (q : ℝ) :
βˆ‘ s : Finset (Fin n), q ^ s.card = (1 + q) ^ n := by
simpa only [Finset.powerset_univ, one_pow, mul_one, Finset.card_univ,
Fintype.card_fin, add_comm] using
(Finset.sum_pow_mul_eq_add_pow q 1 (Finset.univ : Finset (Fin n)))
lemma exp_card_sq (t : ℝ) (k : β„•) :
Real.exp (-t * (k : ℝ)) ^ 2 = Real.exp (-2 * t) ^ k := by
rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]
congr 1
push_cast
ring
lemma continuous_zero_tv_sq_le {n : β„•} (t : ℝ) (x : Spin n) :
4 * totalVariation (continuousKernel (0 : Interaction n) t x)
(gibbs (0 : Interaction n)) ^ 2 ≀ (1 + Real.exp (-2 * t)) ^ n - 1 := by
have hkernel : continuousKernel (0 : Interaction n) t x =
fourierKernel (fun s => Real.exp (-t * (s.card : ℝ))) x := by
funext y; exact continuousKernel_zero_fourier t x y
rw [hkernel]
have h := totalVariation_fourier_sq_le (fun s => Real.exp (-t * (s.card : ℝ)))
(by simp) x
simpa only [exp_card_sq, sum_pow_card] using h
lemma discrete_character_sq_le {n : β„•} (hn : 0 < n) (k : β„•)
(s : Finset (Fin n)) :
((1 - (s.card : ℝ) / n) ^ k) ^ 2 ≀ Real.exp (-2 * (k : ℝ) / n) ^ s.card := by
have hn' : (0 : ℝ) < n := by exact_mod_cast hn
have hc : (s.card : ℝ) ≀ n := by
exact_mod_cast (show s.card ≀ n by simpa using Finset.card_le_univ s)
have hnonneg : 0 ≀ 1 - (s.card : ℝ) / n := sub_nonneg.mpr ((div_le_one hn').mpr hc)
have hle : 1 - (s.card : ℝ) / n ≀ Real.exp (-(s.card : ℝ) / n) := by
simpa only [neg_div, sub_eq_add_neg, add_comm] using
Real.add_one_le_exp (-(s.card : ℝ) / n)
calc
((1 - (s.card : ℝ) / n) ^ k) ^ 2 =
(1 - (s.card : ℝ) / n) ^ (2 * k) := by rw [← pow_mul, Nat.mul_comm]
_ ≀ Real.exp (-(s.card : ℝ) / n) ^ (2 * k) := pow_le_pow_leftβ‚€ hnonneg hle _
_ = Real.exp (-2 * (k : ℝ) / n) ^ s.card := by
rw [← Real.exp_nat_mul, ← Real.exp_nat_mul]
congr 1
push_cast
ring
lemma discrete_zero_tv_sq_le {n : β„•} (hn : 0 < n) (k : β„•) (x : Spin n) :
4 * totalVariation (discreteKernel (0 : Interaction n) k x)
(gibbs (0 : Interaction n)) ^ 2 ≀
(1 + Real.exp (-2 * (k : ℝ) / n)) ^ n - 1 := by
have hkernel : discreteKernel (0 : Interaction n) k x =
fourierKernel (fun s => (1 - (s.card : ℝ) / n) ^ k) x := by
funext y; exact discreteKernel_zero_fourier k x y
rw [hkernel]
apply (totalVariation_fourier_sq_le (fun s => (1 - (s.card : ℝ) / n) ^ k)
(by simp) x).trans
apply sub_le_sub_right _ 1
rw [← sum_pow_card]
exact Finset.sum_le_sum (fun s _ => discrete_character_sq_le hn k s)
end SKGapCutoff
end
end OAI