File size: 3,478 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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