math / data /lean /OAI /Combinatorics /ContingencyTables /Dense /DenseBooleanTrial.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
3.48 kB
import OAI.Combinatorics.ContingencyTables.Dense.DenseBooleanWalk
import OAI.Combinatorics.ContingencyTables.Dense.DenseBooleanOffsets
namespace OAI
/-! # The full dense trial as one bounded unbiased Boolean word -/
namespace ContingencyTables.GridBoundary
open scoped BigOperators Classical
open ResidualMixture FirstSuccess FairBits
noncomputable section
def dependentWordEquiv {q : β„•} (k : Fin q β†’ β„•) :
(Fin (βˆ‘ j, k j) β†’ Bool) ≃ (βˆ€ j, Fin (k j) β†’ Bool) :=
(Equiv.arrowCongr finSigmaFinEquiv.symm (Equiv.refl Bool)).trans (Equiv.piCurry (fun _ _ => Bool))
variable {I J : Type*} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J]
variable {q : β„•}
def denseTrialBits (R : Option I β†’ β„•) (P : Option J β†’ β„•) (d : β„•)
(e : I Γ— J ≃ Fin q) (h : β„•) : β„• :=
(d ^ 50 * (h + 1) ^ 2) * denseStepBits d +
βˆ‘ j : Fin q, offsetBitLength (integerWidth R P d (e.symm j)) h d
def trialWordEquiv (R : Option I β†’ β„•) (P : Option J β†’ β„•) (d : β„•)
(e : I Γ— J ≃ Fin q) (h : β„•) : (Fin (denseTrialBits R P d e h) β†’ Bool) ≃
((Fin ((d ^ 50 * (h + 1) ^ 2) * denseStepBits d) β†’ Bool) Γ—
OffsetWords e (integerWidth R P d) h d) :=
(splitWordEquiv _ _).trans (Equiv.prodCongr (Equiv.refl _)
(dependentWordEquiv (fun j => offsetBitLength (integerWidth R P d (e.symm j)) h d)))
def denseBooleanTrial (R : Option I β†’ β„•) (P : Option J β†’ β„•) (d : β„•)
(hd : 14 ≀ d) (hR : βˆ€ i, d ^ 12 ≀ R i) (hP : βˆ€ j, d ^ 12 ≀ P j)
(e : I Γ— J ≃ Fin q) (h : β„•) (a : Grid (I := Fin q) (4 * d ^ 8))
(bits : Fin (denseTrialBits R P d e h) β†’ Bool) : DenseTrial R P d q :=
let z := trialWordEquiv R P d e h bits
(denseBooleanWalk R P d e a (d ^ 50 * (h + 1) ^ 2) z.1,
drawOffsetWords e (integerWidth R P d) (integerWidth_pos R P d hd hR hP) h d z.2)
/-- This is the exact law of the full declared Boolean trial, including
all independent quotient offsets, before its integer acceptance test. -/
theorem denseBooleanTrialLaw_eq (R : Option I β†’ β„•) (P : Option J β†’ β„•)
(d : β„•) (hd : 14 ≀ d) (hR : βˆ€ i, d ^ 12 ≀ R i) (hP : βˆ€ j, d ^ 12 ≀ P j)
(hRmax : βˆ€ i, R (some i) ≀ R none) (hPmax : βˆ€ j, P (some j) ≀ P none)
(hdimR : Fintype.card (Option I) ≀ d) (hdimP : Fintype.card (Option J) ≀ d)
(hfree : Fintype.card (I Γ— J) ≀ d) (htotal : βˆ‘ i, R i = βˆ‘ j, P j)
(e : I Γ— J ≃ Fin q) (h : β„•) (a : Grid (I := Fin q) (4 * d ^ 8)) :
mapLaw (uniformLaw (Ξ± := Fin (denseTrialBits R P d e h) β†’ Bool))
(denseBooleanTrial R P d hd hR hP e h a) = boundedTrialLaw R P d hd hR hP hfree e h a := by
unfold denseBooleanTrial
rw [← map_equiv (trialWordEquiv R P d e h)
(uniformLaw (Ξ± := Fin (denseTrialBits R P d e h) β†’ Bool))
(fun z => (denseBooleanWalk R P d e a (d ^ 50 * (h+1)^2) z.1,
drawOffsetWords e (integerWidth R P d) (integerWidth_pos R P d hd hR hP) h d z.2)),
uniform_equiv, ← uniform_product, mapLaw_product]
rw [show mapLaw (uniformLaw (Ξ± := Fin ((d ^ 50 * (h + 1) ^ 2) * denseStepBits d) β†’ Bool))
(denseBooleanWalk R P d e a (d ^ 50 * (h + 1) ^ 2)) =
rationalWalkLaw R P d hd hfree e (d ^ 50 * (h + 1) ^ 2) a from
denseBooleanWalkLaw_eq R P d hd hR hP hRmax hPmax hdimR hdimP hfree htotal e a _]
unfold boundedTrialLaw
congr 1
exact drawOffsetWordsLaw_eq e (integerWidth R P d) (integerWidth_pos R P d hd hR hP) h d
end
end ContingencyTables.GridBoundary
end OAI