math / data /lean /OAI /Probability /MatroidSecretary /Sampling /UniformPermutationImage.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.06 kB
import Mathlib.Data.Fintype.Perm
import Mathlib.Logic.Equiv.Fintype
import Mathlib.Data.Finset.Powerset
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Basic.Real.Basic
import Mathlib.Tactic
namespace OAI
/-! Counting core for the secretary random-prefix law: a uniformly random
permutation sends each fixed finite set uniformly onto sets of the same size.
No conditioning on the complete secretary seed is asserted here.
Source: `sections/secretary.tex`, equation `eq:secretary-prefix-mask`,
lines 54--66 of the pinned manuscript; SHA256
`3554fe0f7296782edf63cc7f1305c377e7a7b9d8f8948b9510ea4ad02a702d63`.
These are supporting counting lemmas, not the complete secretary endpoint.
The empty ambient type and empty/full fixed subsets are included. -/
namespace MatroidProphet.Secretary
open Finset
variable {Ξ± : Type*} [Fintype Ξ±] [DecidableEq Ξ±]
/-- Equal-cardinality target sets have equally many permutation preimages. -/
theorem permutation_image_count_eq (s t u : Finset Ξ±) (htu : t.card = u.card) :
(βˆ‘ Οƒ : Equiv.Perm Ξ±, if s.map Οƒ.toEmbedding = t then (1 : ℝ) else 0) =
βˆ‘ Οƒ : Equiv.Perm Ξ±, if s.map Οƒ.toEmbedding = u then (1 : ℝ) else 0 := by
classical
obtain ⟨ρ, hρ⟩ := Equiv.Perm.exists_map_finset_eq t u htu
let e : Equiv.Perm Ξ± ≃ Equiv.Perm Ξ± :=
{ toFun := fun Οƒ => Οƒ.trans ρ
invFun := fun Οƒ => Οƒ.trans ρ.symm
left_inv := fun Οƒ => by ext a; simp
right_inv := fun Οƒ => by ext a; simp }
have he (Οƒ : Equiv.Perm Ξ±) :
s.map (e Οƒ).toEmbedding = u ↔ s.map Οƒ.toEmbedding = t := by
have hmap : s.map (e Οƒ).toEmbedding = (s.map Οƒ.toEmbedding).map ρ.toEmbedding := by
simp [e, Finset.map_map, Function.Embedding.trans]
rw [hmap, ← hρ]
exact Finset.map_injective ρ.toEmbedding |>.eq_iff
calc
_ = βˆ‘ Οƒ : Equiv.Perm Ξ±, if s.map (e Οƒ).toEmbedding = u then (1 : ℝ) else 0 := by
apply Finset.sum_congr rfl
intro Οƒ _
simp only [he]
_ = _ := e.sum_comp (fun Οƒ => if s.map Οƒ.toEmbedding = u then (1 : ℝ) else 0)
/-- Exact probability numerator for a prescribed image of a fixed set. -/
theorem permutation_image_count (s t : Finset Ξ±) (hst : s.card = t.card) :
(βˆ‘ Οƒ : Equiv.Perm Ξ±, if s.map Οƒ.toEmbedding = t then (1 : ℝ) else 0) =
(Fintype.card (Equiv.Perm Ξ±) : ℝ) / (Fintype.card Ξ±).choose s.card := by
classical
let C : ℝ := βˆ‘ Οƒ : Equiv.Perm Ξ±, if s.map Οƒ.toEmbedding = t then (1 : ℝ) else 0
let T := (Finset.univ : Finset Ξ±).powersetCard s.card
have hT (u : Finset Ξ±) : u ∈ T ↔ u.card = s.card := by
simp [T]
have hsum : (Nat.choose (Fintype.card Ξ±) s.card : ℝ) * C =
Fintype.card (Equiv.Perm Ξ±) := by
calc
_ = βˆ‘ u ∈ T, C := by simp [T, Finset.card_powersetCard]
_ = βˆ‘ u ∈ T, βˆ‘ Οƒ : Equiv.Perm Ξ±,
if s.map Οƒ.toEmbedding = u then (1 : ℝ) else 0 := by
apply Finset.sum_congr rfl
intro u hu
exact permutation_image_count_eq s t u (hst.symm.trans (hT u |>.mp hu).symm)
_ = βˆ‘ Οƒ : Equiv.Perm Ξ±, βˆ‘ u ∈ T,
if s.map Οƒ.toEmbedding = u then (1 : ℝ) else 0 := by
rw [Finset.sum_comm]
_ = βˆ‘ _ : Equiv.Perm Ξ±, (1 : ℝ) := by
apply Finset.sum_congr rfl
intro Οƒ _
have hmem : s.map Οƒ.toEmbedding ∈ T := (hT _).2 (Finset.card_map _)
simp [hmem]
_ = _ := by simp
have hc : (Nat.choose (Fintype.card Ξ±) s.card : ℝ) β‰  0 := by
exact_mod_cast (Nat.choose_pos (Finset.card_le_univ s)).ne'
apply (eq_div_iff hc).2
simpa only [mul_comm] using hsum
/-- A prescribed image has probability the reciprocal of the number of
sets of that size, and probability zero if its cardinality is different. -/
theorem uniform_permutation_image_atom (s t : Finset Ξ±) :
(βˆ‘ Οƒ : Equiv.Perm Ξ±, if s.map Οƒ.toEmbedding = t then (1 : ℝ) else 0) /
Fintype.card (Equiv.Perm Ξ±) =
if s.card = t.card then ((Fintype.card Ξ±).choose s.card : ℝ)⁻¹ else 0 := by
classical
by_cases hst : s.card = t.card
Β· rw [ite_eq_left hst, permutation_image_count s t hst]
have hc : (Fintype.card (Equiv.Perm Ξ±) : ℝ) β‰  0 := by
exact_mod_cast (Fintype.card_ne_zero : Fintype.card (Equiv.Perm Ξ±) β‰  0)
field_simp
Β· rw [ite_eq_right hst]
have hne (Οƒ : Equiv.Perm Ξ±) : s.map Οƒ.toEmbedding β‰  t := by
intro h
apply hst
simpa using congrArg Finset.card h
simp [hne]
/-- Averaging over all permutations equals averaging over all possible
images of the fixed set. This form can be mixed over a random prefix length. -/
theorem uniform_permutation_image_average (s : Finset Ξ±) (f : Finset Ξ± β†’ ℝ) :
(βˆ‘ Οƒ : Equiv.Perm Ξ±, f (s.map Οƒ.toEmbedding)) /
Fintype.card (Equiv.Perm Ξ±) =
(βˆ‘ t ∈ (Finset.univ : Finset Ξ±).powersetCard s.card, f t) /
(Fintype.card Ξ±).choose s.card := by
classical
let T := (Finset.univ : Finset Ξ±).powersetCard s.card
have hT (t : Finset Ξ±) : t ∈ T ↔ t.card = s.card := by simp [T]
calc
_ = (βˆ‘ Οƒ : Equiv.Perm Ξ±, βˆ‘ t ∈ T,
(if s.map Οƒ.toEmbedding = t then (1 : ℝ) else 0) * f t) /
Fintype.card (Equiv.Perm Ξ±) := by
congr 1
apply Finset.sum_congr rfl
intro Οƒ _
have hmem : s.map Οƒ.toEmbedding ∈ T := (hT _).2 (Finset.card_map _)
simp [hmem]
_ = βˆ‘ t ∈ T, ((βˆ‘ Οƒ : Equiv.Perm Ξ±,
if s.map Οƒ.toEmbedding = t then (1 : ℝ) else 0) /
Fintype.card (Equiv.Perm Ξ±)) * f t := by
rw [Finset.sum_comm, Finset.sum_div]
apply Finset.sum_congr rfl
intro t _
rw [← Finset.sum_mul]
ring
_ = βˆ‘ t ∈ T, (((Fintype.card Ξ±).choose s.card : ℝ)⁻¹ * f t) := by
apply Finset.sum_congr rfl
intro t ht
rw [uniform_permutation_image_atom, ite_eq_left ((hT t).1 ht).symm]
_ = _ := by
rw [← Finset.mul_sum]
change _ = (βˆ‘ t ∈ T, f t) / _
rw [div_eq_mul_inv, mul_comm]
end MatroidProphet.Secretary
end OAI