File size: 5,483 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import OAI.Combinatorics.ContingencyTables.Dense.DenseBooleanTrial
import OAI.Combinatorics.ContingencyTables.Dense.DenseBoundedRejection
import OAI.Combinatorics.ContingencyTables.Machines.FiniteWordRejection
import OAI.Combinatorics.ContingencyTables.Dense.DenseBitBudget

namespace OAI

/-! # A bounded unbiased Boolean-word dense table draw -/

namespace ContingencyTables.GridBoundary

open scoped BigOperators Classical
open ResidualMixture FirstSuccess FairBits

noncomputable section

variable {I J : Type*} [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J]
variable {q : ℕ}

def denseDrawBits (R : Option I → ℕ) (P : Option J → ℕ) (d : ℕ)
    (e : I × J ≃ Fin q) (h : ℕ) : ℕ :=
  (d ^ 4 * (h + 1)) * denseTrialBits R P d e h

def denseBooleanDraw (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) (htotal : ∑ i, R i = ∑ j, P j) (h : ℕ)
    (a : Grid (I := Fin q) (4 * d ^ 8)) (fallback : Table R P)
    (bits : Fin (denseDrawBits R P d e h) → Bool) : Table R P :=
  wordRetry (fun word => trialSuccess R P d e htotal (denseBooleanTrial R P d hd hR hP e h a word))
    fallback (d ^ 4 * (h + 1)) (gridWordEquiv (d ^ 4 * (h + 1)) (denseTrialBits R P d e h) bits)

def denseBooleanDrawLaw (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) (htotal : ∑ i, R i = ∑ j, P j) (h : ℕ)
    (a : Grid (I := Fin q) (4 * d ^ 8)) (fallback : Table R P) : RationalLaw (Table R P) :=
  mapLaw (uniformLaw (α := Fin (denseDrawBits R P d e h) → Bool))
    (denseBooleanDraw R P d hd hR hP e htotal h a fallback)

theorem denseBooleanDrawLaw_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)) (fallback : Table R P) :
    denseBooleanDrawLaw R P d hd hR hP e htotal h a fallback =
      denseBoundedLaw R P d hd hR hP hfree e htotal h a fallback := by
  unfold denseBooleanDrawLaw denseBooleanDraw
  change mapLaw (uniformLaw (α := Fin ((d^4*(h+1))*denseTrialBits R P d e h) → Bool))
    (fun bits => wordRetry
      (fun word => trialSuccess R P d e htotal (denseBooleanTrial R P d hd hR hP e h a word))
      fallback (d^4*(h+1)) (gridWordEquiv (d^4*(h+1)) (denseTrialBits R P d e h) bits)) = _
  rw [← map_equiv (gridWordEquiv (d ^ 4 * (h + 1)) (denseTrialBits R P d e h)), uniform_equiv]
  change wordRetryLaw
    (fun word => trialSuccess R P d e htotal (denseBooleanTrial R P d hd hR hP e h a word))
    fallback (d ^ 4 * (h + 1)) = _
  rw [wordRetryLaw_eq, ← retryLaw_map,
    denseBooleanTrialLaw_eq R P d hd hR hP hRmax hPmax hdimR hdimP hfree htotal e h a]
  rfl

/-- The actual finite Boolean draw always has codomain the feasible tables
and its law satisfies the desired dense approximation guarantee. -/
theorem denseBooleanDraw_variation (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) (hPL : PublishedInputs.FiniteBoxPrekopaLeindler q)
    (hCheeger : PublishedInputs.FiniteCheeger (Grid (I := Fin q) (4 * d ^ 8)))
    (h : ℕ) (a : Grid (I := Fin q) (4 * d ^ 8)) (fallback : Table R P) :
    let _ : Nonempty (Table R P) := ⟨fallback⟩
    (variation (denseBooleanDrawLaw R P d hd hR hP e htotal h a fallback)
      (uniformLaw (α := Table R P)) : ℝ) ≤ (2 : ℝ) ^ (-(h : ℝ)) := by
  let : Nonempty (Table R P) := ⟨fallback⟩
  rw [denseBooleanDrawLaw_eq R P d hd hR hP hRmax hPmax hdimR hdimP hfree htotal e h a fallback]
  exact denseBoundedLaw_variation R P d hd hR hP hRmax hPmax hdimR hdimP hfree htotal
    e hPL hCheeger h a fallback

omit [Fintype I] [Fintype J] [DecidableEq I] [DecidableEq J] in
/-- The full Boolean source has polynomial length in the declared dense
parameters. -/
theorem denseDrawBits_polynomial (R : Option I → ℕ) (P : Option J → ℕ)
    (d C b h : ℕ) (e : I × J ≃ Fin q) (hq : q ≤ d)
    (hwidth : ∀ p, integerWidth R P d p ≤ C) (hb : Nat.clog 2 (C + 2) ≤ b) :
    denseDrawBits R P d e h ≤ 25 * (d + b + h + 1) ^ 62 := by
  have hoff : (∑ j : Fin q, offsetBitLength (integerWidth R P d (e.symm j)) h d) ≤
      d * (b + 1 + 4 * (h + d)) := by
    calc
      _ ≤ ∑ _j : Fin q, (b + 1 + 4 * (h + d)) :=
        Finset.sum_le_sum (fun j _ => denseOffsetBits_upper _ C b h d (hwidth _) hb)
      _ = q * (b + 1 + 4 * (h + d)) := by simp
      _ ≤ _ := Nat.mul_le_mul_right _ hq
  apply (show denseDrawBits R P d e h ≤ denseRandomBitBudget d b h from ?_).trans
    (denseRandomBitBudget_polynomial d b h)
  unfold denseDrawBits denseTrialBits denseRandomBitBudget
  exact Nat.mul_le_mul_left _ (Nat.add_le_add_left hoff _)

end

end ContingencyTables.GridBoundary

end OAI