File size: 3,478 Bytes
97c3405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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