math / data /lean /OAI /Combinatorics /ContingencyTables /Machines /FiniteWordPadding.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.52 kB
import OAI.Combinatorics.ContingencyTables.Transport.RationalMapProducts
namespace OAI
/-! # Reserving a common word length for adaptive bounded draws -/
namespace ContingencyTables.FirstSuccess
open scoped BigOperators Classical
open ResidualMixture FairBits
noncomputable section
variable {A B : Type*} [Fintype A] [Fintype B] [DecidableEq A]
lemma mapLaw_product_fst (p : RationalLaw A) (q : RationalLaw B) :
mapLaw (productLaw p q) Prod.fst=p := by
apply RationalLaw.ext
funext x
simp only [mapLaw, productLaw, Fintype.sum_prod_type]
change (βˆ‘ a,βˆ‘ b,if a=x then p.mass a*q.mass b else 0)=p.mass x
have hs (a : A) : (βˆ‘ b,if a=x then p.mass a*q.mass b else 0)=if a=x then p.mass a else 0 := by
by_cases ha : a=x
Β· simp only [ha,ite_true,←Finset.mul_sum,q.total,mul_one]
Β· simp only [ha,ite_false,Finset.sum_const_zero]
simp_rw [hs]
simp
def prefixWord {k N : β„•} (hk : k ≀ N) (bits : Fin N β†’ Bool) : Fin k β†’ Bool :=
fun i => bits (Fin.castLE hk i)
def paddingWordEquiv {k N : β„•} (hk : k ≀ N) :
(Fin N β†’ Bool) ≃ ((Fin k β†’ Bool) Γ— (Fin (N-k) β†’ Bool)) :=
(Equiv.arrowCongr (finCongr (Nat.add_sub_of_le hk)).symm (Equiv.refl Bool)).trans
(splitWordEquiv k (N-k))
lemma paddingWordEquiv_fst {k N : β„•} (hk : k ≀ N) (bits : Fin N β†’ Bool) :
(paddingWordEquiv hk bits).1=prefixWord hk bits := by
funext i
change bits _=bits _
apply congrArg bits
apply Fin.ext
rfl
/-- Taking the needed prefix of a larger uniform word preserves the exact
law, so unused bits can be reserved even after the current state is known. -/
theorem prefixWord_uniform {k N : β„•} (hk : k ≀ N) :
mapLaw (uniformLaw (Ξ± := Fin N β†’ Bool)) (prefixWord hk)=uniformLaw (Ξ± := Fin k β†’ Bool) := by
have hf : prefixWord hk=fun bits => (paddingWordEquiv hk bits).1 := by
funext bits
exact (paddingWordEquiv_fst hk bits).symm
rw [hf,←map_equiv (paddingWordEquiv hk),uniform_equiv,←uniform_product,mapLaw_product_fst]
variable {Y : Type*} [Fintype Y] [DecidableEq Y]
/-- An arbitrary finite draw keeps its law when padded to the common
bound; this applies separately at every state of an adaptive walk. -/
theorem padded_draw_law {k N : β„•} (hk : k ≀ N) (draw : (Fin k β†’ Bool) β†’ Y) :
mapLaw (uniformLaw (Ξ± := Fin N β†’ Bool)) (fun bits => draw (prefixWord hk bits))=
mapLaw (uniformLaw (Ξ± := Fin k β†’ Bool)) draw := by
rw [←mapLaw_comp,prefixWord_uniform]
end
end ContingencyTables.FirstSuccess
end OAI