Download data/lean/OAI/Probability/MatroidSecretary/Sampling/UniformPermutationImage.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.06 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/MatroidSecretary/Sampling/UniformPermutationImage.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/MatroidSecretary/Sampling/UniformPermutationImage.lean
-
curl -L -o UniformPermutationImage.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/MatroidSecretary/Sampling/UniformPermutationImage.lean
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 | |