math / data /lean /OAI /Probability /BinarySweep /Processes /AssignmentWeight.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
9.68 kB
import Mathlib
import OAI.Probability.BinarySweep.Processes.IndependentHistory
namespace OAI
noncomputable section
open scoped BigOperators
namespace BinaryCoordinateSweeps
section AssignmentWeights
attribute [local instance] Classical.propDecidable
variable {X I J : Type*} [Fintype X] [Fintype I] [Fintype J]
def assignmentWeight (p : Equiv.Perm X β†’ ℝ) (A B : I β†ͺ X) : ℝ :=
βˆ‘ Οƒ, if Assigns A B Οƒ then p Οƒ else 0
omit [Fintype I] in
lemma assignmentWeight_mono (p q : Equiv.Perm X β†’ ℝ)
(hpq : βˆ€ Οƒ, p Οƒ ≀ q Οƒ) (A B : I β†ͺ X) :
assignmentWeight p A B ≀ assignmentWeight q A B := by
apply Finset.sum_le_sum
intro Οƒ _
split_ifs
Β· exact hpq Οƒ
Β· exact le_rfl
omit [Fintype I] in
lemma assignmentWeight_nonneg {p : Equiv.Perm X β†’ ℝ}
(hp : βˆ€ Οƒ, 0 ≀ p Οƒ) (A B : I β†ͺ X) : 0 ≀ assignmentWeight p A B := by
apply Finset.sum_nonneg
intro Οƒ _
split_ifs
Β· exact hp Οƒ
Β· exact le_rfl
omit [Fintype I] in
lemma assignmentWeight_smul (p : Equiv.Perm X β†’ ℝ) (c : ℝ) (A B : I β†ͺ X) :
assignmentWeight (fun Οƒ => c * p Οƒ) A B = c * assignmentWeight p A B := by
simp only [assignmentWeight, Finset.mul_sum]
apply Finset.sum_congr rfl
intro Οƒ _
split_ifs <;> simp
lemma assignmentWeight_uniform (A B : I β†ͺ X) :
assignmentWeight (fun _ => (Fintype.card (Equiv.Perm X) : ℝ)⁻¹) A B =
(Nat.descFactorial (Fintype.card X) (Fintype.card I) : ℝ)⁻¹ :=
uniform_assignment_probability A B
lemma assignmentWeight_uniform_pos (A B : I β†ͺ X) :
0 < assignmentWeight (fun _ => (Fintype.card (Equiv.Perm X) : ℝ)⁻¹) A B := by
rw [assignmentWeight_uniform]
apply inv_pos.mpr
exact_mod_cast Nat.descFactorial_pos.mpr (Fintype.card_le_of_injective A A.injective)
lemma assignmentWeight_comparison {p : Equiv.Perm X β†’ ℝ}
(hl : βˆ€ Οƒ, (1 / 2 : ℝ) * (Fintype.card (Equiv.Perm X) : ℝ)⁻¹ ≀ p Οƒ)
(hu : βˆ€ Οƒ, p Οƒ ≀ 2 * (Fintype.card (Equiv.Perm X) : ℝ)⁻¹)
(A B : I β†ͺ X) :
(1 / 2 : ℝ) * (Nat.descFactorial (Fintype.card X) (Fintype.card I) : ℝ)⁻¹ ≀
assignmentWeight p A B ∧
assignmentWeight p A B ≀
2 * (Nat.descFactorial (Fintype.card X) (Fintype.card I) : ℝ)⁻¹ := by
constructor
Β· simpa [assignmentWeight_smul, assignmentWeight_uniform] using
assignmentWeight_mono (fun _ => (1 / 2 : ℝ) * (Fintype.card (Equiv.Perm X) : ℝ)⁻¹) p hl A B
Β· simpa [assignmentWeight_smul, assignmentWeight_uniform] using
assignmentWeight_mono p (fun _ => 2 * (Fintype.card (Equiv.Perm X) : ℝ)⁻¹) hu A B
lemma assignmentWeight_ratio_le {p : Equiv.Perm X β†’ ℝ}
(hl : βˆ€ Οƒ, (1 / 2 : ℝ) * (Fintype.card (Equiv.Perm X) : ℝ)⁻¹ ≀ p Οƒ)
(hu : βˆ€ Οƒ, p Οƒ ≀ 2 * (Fintype.card (Equiv.Perm X) : ℝ)⁻¹)
(A B : I β†ͺ X) (A' B' : J β†ͺ X) :
assignmentWeight p A' B' / assignmentWeight p A B ≀
4 * (Nat.descFactorial (Fintype.card X) (Fintype.card I) : ℝ) /
(Nat.descFactorial (Fintype.card X) (Fintype.card J) : ℝ) := by
have hi : (0 : ℝ) < Nat.descFactorial (Fintype.card X) (Fintype.card I) := by
exact_mod_cast Nat.descFactorial_pos.mpr (Fintype.card_le_of_injective A A.injective)
have hj : (0 : ℝ) < Nat.descFactorial (Fintype.card X) (Fintype.card J) := by
exact_mod_cast Nat.descFactorial_pos.mpr (Fintype.card_le_of_injective A' A'.injective)
have hden := (assignmentWeight_comparison hl hu A B).1
have hnum := (assignmentWeight_comparison hl hu A' B').2
have hdp : 0 < assignmentWeight p A B :=
lt_of_lt_of_le (mul_pos (by norm_num) (inv_pos.mpr hi)) hden
apply (div_le_iffβ‚€ hdp).mpr
calc
_ ≀ 2 * (Nat.descFactorial (Fintype.card X) (Fintype.card J) : ℝ)⁻¹ := hnum
_ = (4 * (Nat.descFactorial (Fintype.card X) (Fintype.card I) : ℝ) /
(Nat.descFactorial (Fintype.card X) (Fintype.card J) : ℝ)) *
((1 / 2 : ℝ) * (Nat.descFactorial (Fintype.card X) (Fintype.card I) : ℝ)⁻¹) := by
field_simp
ring
_ ≀ _ := mul_le_mul_of_nonneg_left hden (by positivity)
end AssignmentWeights
attribute [local instance] Classical.propDecidable
abbrev LinePaths {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h)
(j : Fin b) (y : GridOutside bits j) :=
{k : Fin h // (fun i : {i : Fin b // i β‰  j} => H.position j.castSucc k i) = y}
def lineInput {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h)
(j : Fin b) (y : GridOutside bits j) : LinePaths H j y β†ͺ Slot (bits j) where
toFun k := H.position j.castSucc k.val j
inj' k l he := by
apply Subtype.ext
apply H.disjoint j.castSucc
funext i
by_cases hi : i = j
Β· subst i; exact he
· exact (congrFun k.property ⟨i, hi⟩).trans (congrFun l.property ⟨i, hi⟩).symm
def lineOutput {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h)
(j : Fin b) (y : GridOutside bits j) : LinePaths H j y β†ͺ Slot (bits j) where
toFun k := H.position j.succ k.val j
inj' k l he := by
apply Subtype.ext
apply H.disjoint j.succ
funext i
by_cases hi : i = j
Β· subst i; exact he
Β· rw [H.changes_only_stage j k.val i hi, H.changes_only_stage j l.val i hi]
exact (congrFun k.property ⟨i, hi⟩).trans (congrFun l.property ⟨i, hi⟩).symm
lemma lineHoles_le {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h)
(j : Fin b) (y : GridOutside bits j) : lineHoles H j y ≀ 2 ^ bits j := by
simpa [lineHoles, Slot, Fintype.card_pi] using
Fintype.card_le_of_injective (lineInput H j y) (lineInput H j y).injective
lemma sum_lineHoles {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h)
(j : Fin b) : βˆ‘ y, lineHoles H j y = h := by
classical
have hh := Fintype.card_congr (Equiv.sigmaFiberEquiv
(fun k : Fin h => (fun i : {i : Fin b // i β‰  j} => H.position j.castSucc k i)))
simpa only [Fintype.card_sigma, Fintype.card_fin, lineHoles] using hh
lemma pathCost_nonneg {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h) :
0 ≀ pathCost H := by
apply Finset.sum_nonneg
intro j _
apply Finset.sum_nonneg
intro y _
exact fallingCost_nonneg (by positivity) (lineHoles_le H j y)
lemma pathCost_le {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h) :
pathCost H ≀ (b : ℝ) * h := by
calc
pathCost H ≀ βˆ‘ j : Fin b, βˆ‘ y, (lineHoles H j y : ℝ) := by
apply Finset.sum_le_sum
intro j _
apply Finset.sum_le_sum
intro y _
exact fallingCost_le (by positivity) (lineHoles_le H j y)
_ = _ := by simp only [← Nat.cast_sum, sum_lineHoles]; simp
lemma pathEvent_iff_assigns {b h : β„•} {bits : Fin b β†’ β„•} (H : PathFamily bits h)
(g : GridChoices bits) : pathEvent H g ↔
βˆ€ (j : Fin b) (y : GridOutside bits j), Assigns (lineInput H j y) (lineOutput H j y) (g j y) := by
constructor
Β· intro hg j y k
change g j y (H.position j.castSucc k.val j) = H.position j.succ k.val j
have he := congrArg (fun x : GridSlot bits => x j) (hg j k.val)
simpa only [gridLayer, Equiv.trans_apply, Equiv.piSplitAt_apply,
Equiv.prodCongrLeft_apply, Equiv.piSplitAt_symm_apply, dite_true, eq_self,
lineInput, lineOutput, Function.Embedding.coeFn_mk, k.property] using he
Β· intro hg j k
apply (Equiv.piSplitAt j (fun i => Slot (bits i))).injective
simp only [gridLayer, Equiv.trans_apply, Equiv.apply_symm_apply,
Equiv.piSplitAt_apply, Equiv.prodCongrLeft_apply]
apply Prod.ext
· exact hg j _ ⟨k, rfl⟩
Β· funext i
exact (H.changes_only_stage j k i.val i.property).symm
lemma finiteLaw_le_one {Ξ© G : Type*} [Fintype Ξ©] [Fintype G] [Nonempty Ξ©]
(f : Ξ© β†’ G) (g : G) : finiteLaw f g ≀ 1 := by
calc
_ ≀ βˆ‘ x, finiteLaw f x := Finset.single_le_sum (fun x _ => finiteLaw_nonneg f x) (Finset.mem_univ _)
_ = 1 := finiteLaw_sum f
def linePerturbationRadius (r : β„•) : ℝ := 1 / (2 * ((2 ^ (2 * r)).factorial : ℝ))
lemma linePerturbationRadius_pos (r : β„•) : 0 < linePerturbationRadius r := by
unfold linePerturbationRadius
positivity
lemma lineLaw_comparison (r d : β„•) (hd : d ≀ 2 * r) {z : ℝ}
(hz : 0 ≀ z) (hzr : z ≀ linePerturbationRadius r) (g : Equiv.Perm (Slot d)) :
(1 / 2 : ℝ) * uniformLaw (Equiv.Perm (Slot d)) g ≀ lineLaw d z g ∧
lineLaw d z g ≀ 2 * uniformLaw (Equiv.Perm (Slot d)) g := by
have hf1 : (1 : ℝ) ≀ ((2 ^ (2 * r)).factorial : ℝ) := by
exact_mod_cast Nat.factorial_pos (2 ^ (2 * r))
have hzp : z ≀ 1 / 2 := hzr.trans (by
unfold linePerturbationRadius
apply one_div_le_one_div_of_le (by norm_num)
linarith)
have hfd : (Fintype.card (Equiv.Perm (Slot d)) : ℝ) ≀ ((2 ^ (2 * r)).factorial : ℝ) := by
exact_mod_cast (show Fintype.card (Equiv.Perm (Slot d)) ≀ (2 ^ (2 * r)).factorial from by
simp only [Fintype.card_perm, Slot, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin]
exact Nat.factorial_le (Nat.pow_le_pow_right (by norm_num) hd))
have hup : 0 < uniformLaw (Equiv.Perm (Slot d)) g := by
unfold uniformLaw
have hp : (0 : ℝ) < Fintype.card (Equiv.Perm (Slot d)) := by exact_mod_cast Fintype.card_pos
positivity
have hzU : z ≀ uniformLaw (Equiv.Perm (Slot d)) g := hzr.trans (by
unfold linePerturbationRadius uniformLaw
rw [one_div]
apply inv_antiβ‚€ (by exact_mod_cast Fintype.card_pos)
linarith)
have hB0 : 0 ≀ binaryLaw d g := finiteLaw_nonneg _ _
have hB1 : binaryLaw d g ≀ 1 := finiteLaw_le_one _ _
constructor
Β· unfold lineLaw
nlinarith
Β· unfold lineLaw
nlinarith [mul_le_mul_of_nonneg_left hB1 hz]
end BinaryCoordinateSweeps
end
end OAI