math / data /lean /OAI /Probability /BinarySweep /Processes /SupportTimeBoundBounds.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
8.12 kB
import Mathlib
import OAI.Probability.BinarySweep.Processes.Basic
namespace OAI
noncomputable section
open scoped BigOperators
namespace BinaryCoordinateSweeps
theorem supportTimeBound_bounds (d : β„•) :
(2 : ℝ) * (d + 1) - 6 ≀ supportTimeBound d ∧
supportTimeBound d ≀ (2 : ℝ) * (d + 1) := by
let N : β„• := 2 ^ (d + 1)
have hN : (2 : ℝ) ≀ N := by
dsimp [N]
rw [Nat.cast_pow, Nat.cast_ofNat, pow_succ]
have : (1 : ℝ) ≀ (2 : ℝ) ^ d := one_le_powβ‚€ (by norm_num)
linarith
have hNp : (0 : ℝ) < N := by linarith
have hNne : N β‰  0 := by exact_mod_cast hNp.ne'
have hfac : (0 : ℝ) < N.factorial := by positivity
have hlog : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num)
have hhalf : (1 / 2 : ℝ) ≀ Real.log 2 := by
have := Real.one_sub_inv_le_log_of_pos (x := (2 : ℝ)) (by norm_num)
norm_num at this ⊒
exact this
have hlogN : Real.log (N : ℝ) = ((d : ℝ) + 1) * Real.log 2 := by
simp [N, Real.log_pow]
have hlogNN : 0 ≀ Real.log (N : ℝ) := Real.log_nonneg (by linarith)
have hpi : 0 ≀ Real.log (2 * Real.pi) :=
Real.log_nonneg (by linarith [Real.pi_gt_three])
have hst := Stirling.le_log_factorial_stirling hNne
have hfaclow : (N : ℝ) * Real.log N - N ≀ Real.log (N.factorial : ℝ) := by
linarith
have hfacup : Real.log (N.factorial : ℝ) ≀ (N : ℝ) * Real.log N := by
have h := Real.log_le_log hfac (show (N.factorial : ℝ) ≀ (N : ℝ) ^ N by
exact_mod_cast Nat.factorial_le_pow N)
rwa [Real.log_pow] at h
have hconstlow : -(1 : ℝ) ≀ Real.log (3 / 4 : ℝ) := by
have := Real.one_sub_inv_le_log_of_pos (x := (3 / 4 : ℝ)) (by norm_num)
norm_num at this
linarith
have hconstup : Real.log (3 / 4 : ℝ) ≀ 0 := Real.log_nonpos (by norm_num) (by norm_num)
have hL : Real.log (3 * (N.factorial : ℝ) / 4) =
Real.log (N.factorial : ℝ) + Real.log (3 / 4 : ℝ) := by
rw [show 3 * (N.factorial : ℝ) / 4 = (N.factorial : ℝ) * (3 / 4) by ring]
exact Real.log_mul hfac.ne' (by norm_num)
have hlow : (N : ℝ) * (((d : ℝ) + 1) * Real.log 2) - N - 1 ≀
Real.log (3 * (N.factorial : ℝ) / 4) := by
rw [hL]
rw [hlogN] at hfaclow
linarith
have hup : Real.log (3 * (N.factorial : ℝ) / 4) ≀
(N : ℝ) * (((d : ℝ) + 1) * Real.log 2) := by
rw [hL]
rw [hlogN] at hfacup
linarith
have hrewrite : supportTimeBound d =
2 * Real.log (3 * (N.factorial : ℝ) / 4) / ((N : ℝ) * Real.log 2) := by
simp only [supportTimeBound, Real.logb]
have hcast : (N : ℝ) = (2 : ℝ) ^ (d + 1) := by simp [N]
rw [← hcast]
ring
rw [hrewrite]
constructor
Β· apply (le_div_iffβ‚€ (mul_pos hNp hlog)).mpr
have hprod : (N : ℝ) / 2 ≀ (N : ℝ) * Real.log 2 := by
nlinarith [mul_nonneg hNp.le (sub_nonneg.mpr hhalf)]
nlinarith
Β· apply (div_le_iffβ‚€ (mul_pos hNp hlog)).mpr
nlinarith
theorem support_ceiling_asymptotic (d : β„•) :
|(⌈supportTimeBound dβŒ‰ : ℝ) - 2 * (d + 1)| ≀ 6 := by
obtain ⟨hlow, hupp⟩ := supportTimeBound_bounds d
have hceilow := Int.le_ceil (supportTimeBound d)
have hup : ⌈supportTimeBound dβŒ‰ ≀ (2 * (d + 1) : β„€) := by
apply Int.ceil_le.mpr
push_cast
exact hupp
have hupR : (⌈supportTimeBound dβŒ‰ : ℝ) ≀ 2 * ((d : ℝ) + 1) := by
exact_mod_cast hup
exact abs_le.mpr ⟨by linarith, by linarith⟩
def boolSwitch (c : Bool) : Equiv.Perm Bool where
toFun x := x ^^ c
invFun x := x ^^ c
left_inv x := by simp
right_inv x := by simp
lemma sign_boolSwitch (c : Bool) :
Equiv.Perm.sign (boolSwitch c) = if c then (-1 : β„€Λ£) else 1 := by
cases c
Β· have : boolSwitch false = 1 := by ext x; cases x <;> rfl
rw [this]; rfl
Β· have : boolSwitch true = Equiv.swap false true := by
ext x; cases x <;> simp [boolSwitch]
rw [this, Equiv.Perm.sign_swap (by decide)]; rfl
lemma realSign_coordinateLayer (d : β„•) (j : Fin d)
(c : ({i : Fin d // i β‰  j} β†’ Bool) β†’ Bool) :
realSign (coordinateLayer d j c) = ∏ y, (if c y then (-1 : ℝ) else 1) := by
classical
have he : coordinateLayer d j c =
(Equiv.piSplitAt j (fun _ : Fin d => Bool)).trans
((Equiv.prodCongrLeft (fun y => boolSwitch (c y))).trans
(Equiv.piSplitAt j (fun _ : Fin d => Bool)).symm) := rfl
rw [he]
simp [realSign, Equiv.Perm.sign_prodCongrLeft, sign_boolSwitch, apply_ite]
lemma sum_realSign_coordinateLayer (d : β„•) (j : Fin d) :
βˆ‘ c : ({i : Fin d // i β‰  j} β†’ Bool) β†’ Bool,
realSign (coordinateLayer d j c) = 0 := by
classical
simp_rw [realSign_coordinateLayer]
rw [← Fintype.prod_sum (fun (_ : {i : Fin d // i β‰  j} β†’ Bool) (b : Bool) =>
if b then (-1 : ℝ) else 1)]
simp
lemma realSign_binarySweep (d : β„•) (c : SweepCoins d) :
realSign (binarySweep d c) = ∏ j, realSign (coordinateLayer d j (c j)) := by
classical
simp [binarySweep, map_list_prod, List.map_reverse, List.prod_reverse,
List.map_ofFn, List.prod_ofFn]
lemma sum_realSign_binarySweep (d : β„•) (hd : 0 < d) :
βˆ‘ c : SweepCoins d, realSign (binarySweep d c) = 0 := by
classical
simp_rw [realSign_binarySweep]
rw [← Fintype.prod_sum (fun (j : Fin d) (c : ({i : Fin d // i β‰  j} β†’ Bool) β†’ Bool) =>
realSign (coordinateLayer d j c))]
apply Finset.prod_eq_zero (i := ⟨0, hd⟩) (Finset.mem_univ _)
exact sum_realSign_coordinateLayer d ⟨0, hd⟩
lemma finiteLaw_expectation {Ξ© G : Type*} [Fintype Ξ©] [Fintype G]
(f : Ξ© β†’ G) (a : G β†’ ℝ) :
βˆ‘ g, finiteLaw f g * a g = (Fintype.card Ξ© : ℝ)⁻¹ * βˆ‘ Ο‰, a (f Ο‰) := by
classical
simp only [finiteLaw, Finset.sum_mul]
rw [Finset.sum_comm]
simp [ite_mul, Finset.mul_sum]
theorem binary_sign_annihilated (d : β„•) (hd : 0 < d) :
βˆ‘ g : Equiv.Perm (Slot d), binaryLaw d g * realSign g = 0 := by
rw [binaryLaw, finiteLaw_expectation, sum_realSign_binarySweep d hd, mul_zero]
lemma coordinateLayer_zero (d : β„•) (j : Fin d) :
coordinateLayer d j (fun _ => false) = 1 := by
ext x i
simp [coordinateLayer, Equiv.piSplitAt_symm_apply]
intro h
rw [h]
lemma prod_reverse_ofFn_single {G : Type*} [Monoid G] (n : β„•) (j : Fin n) (g : G) :
(List.ofFn (fun i : Fin n => if i = j then g else 1)).reverse.prod = g := by
induction n with
| zero => exact Fin.elim0 j
| succ n ih =>
refine Fin.cases ?_ (fun j => ?_) j
Β· simp [List.ofFn_succ, List.ofFn_const]
Β· simpa [List.ofFn_succ, (Fin.succ_ne_zero j).symm] using ih j
lemma binarySweep_zero (d : β„•) : binarySweep d (fun _ _ => false) = 1 := by
simp [binarySweep, coordinateLayer_zero, List.ofFn_const]
lemma binarySweep_singleLayer (d : β„•) (j : Fin d)
(c : ({i : Fin d // i β‰  j} β†’ Bool) β†’ Bool) :
binarySweep d (Function.update ((fun _ _ => false) : SweepCoins d) j c) = coordinateLayer d j c := by
classical
have h (i : Fin d) :
coordinateLayer d i ((Function.update ((fun _ _ => false) : SweepCoins d) j c) i) =
if i = j then coordinateLayer d j c else 1 := by
by_cases hi : i = j
Β· subst i; simp
Β· simp [coordinateLayer_zero, hi]
simp only [binarySweep, h]
exact prod_reverse_ofFn_single d j _
def sweepReachable (d : β„•) : Submonoid (Equiv.Perm (Slot d)) where
carrier := {g | βˆƒ l : List (SweepCoins d), (l.map (binarySweep d)).prod = g}
one_mem' := ⟨[], rfl⟩
mul_mem' := by
rintro g h ⟨l, rfl⟩ ⟨k, rfl⟩
exact ⟨l ++ k, by simp⟩
lemma coordinateLayer_mem_reachable (d : β„•) (j : Fin d)
(c : ({i : Fin d // i β‰  j} β†’ Bool) β†’ Bool) :
coordinateLayer d j c ∈ sweepReachable d := by
refine ⟨[Function.update ((fun _ _ => false) : SweepCoins d) j c], ?_⟩
simp [binarySweep_singleLayer]
lemma fiber_boolSwitch_eq_swap {Y : Type*} [DecidableEq Y] (y : Y) (a : Bool) :
Equiv.prodCongrLeft (fun z => boolSwitch (decide (z = y))) =
Equiv.swap (a, y) (!a, y) := by
ext ⟨b, z⟩ <;> cases a <;> cases b <;> by_cases h : z = y <;>
simp [boolSwitch, Equiv.swap_apply_def, h]
end BinaryCoordinateSweeps
end
end OAI