File size: 5,662 Bytes
d5b7741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import OAI.Combinatorics.ContingencyTables.Dense.DenseTabulationScalarBounds
import OAI.Combinatorics.ContingencyTables.Sampling.ProfileMatrixEntryRuntime

namespace OAI

/-! # The finite boxes controlling one cached transition entry -/

namespace ContingencyTables.DensePrograms
open MatchingFPRAS MatchingFPRAS.TreeTyped ProfilePrograms Polynomial

def completionBoxMeasure (z : CanonicalParameters) : ℕ :=
  rawBoxMeasure (canonicalCountInput z).1+
    gridStateCount (completionEnumerationData z.1)+weight z

theorem completionWeightMeasure_polynomial : ∃ p : Polynomial ℕ,∀ z,
    completionWeightMeasure z ≤ p.eval (completionBoxMeasure z) := by
  obtain ⟨p,hp⟩ := polynomial_canonicalCountInput
  obtain ⟨q,hq⟩ := rawTabulationMeasure_polynomial
  refine ⟨q+p+2*X,?_⟩
  intro z
  let M := completionBoxMeasure z
  have hz : weight z ≤ M := by unfold M completionBoxMeasure; omega
  have hw : weight (canonicalCountInput z) ≤ p.eval M :=
    (Nat.le_add_left _ _).trans ((hp z).trans (polynomial_eval_monotone p hz))
  have hb : rawBoxMeasure (canonicalCountInput z).1 ≤ M := by
    unfold M completionBoxMeasure; omega
  have hr : rawTabulationMeasure (canonicalCountInput z).1 ≤ q.eval M :=
    (hq (canonicalCountInput z).1).trans (polynomial_eval_monotone q hb)
  have hc : gridStateCount (completionEnumerationData z.1)+weight z.1 ≤ M := by
    have := weight_fst z
    unfold M completionBoxMeasure
    omega
  change rawTabulationMeasure (canonicalCountInput z).1+weight (canonicalCountInput z)+
    weight z+(gridStateCount (completionEnumerationData z.1)+weight z.1) ≤ _
  change _ ≤ (q+p+2*X).eval M
  simp only [eval_add,eval_mul,eval_ofNat,eval_X]
  omega

end ContingencyTables.DensePrograms

namespace ContingencyTables.ProfilePrograms
open MatchingFPRAS MatchingFPRAS.TreeTyped DensePrograms Polynomial

def matrixEntryBox (z : MatrixEntryInput) : ℕ :=
  completionBoxMeasure (residualParameters (entryCacheParameters z).1)+
    (entryCacheParameters z).2+gridStateCount (z.1.2,2)+weight z

def entryResidualParameters (z : MatrixEntryInput) : CanonicalParameters :=
  residualParameters (entryCacheParameters z).1

def entryResidualRealizer : Realizer entryResidualParameters :=
  composition (f := fun z : MatrixEntryInput => (entryCacheParameters z).1)
    (g := residualParameters)
    (composition (f := entryCacheParameters) (g := Prod.fst) entryCacheParametersRealizer first)
    residualParametersRealizer

lemma polynomial_entryResidual : PolynomialTime entryResidualRealizer :=
  polynomial_composition (polynomial_composition polynomial_entryCacheParameters polynomial_first)
    polynomial_residualParameters

/-- Separating binary preparation size from the four enumerated boxes. -/
theorem matrixEntryBox_bound : ∃ p : Polynomial ℕ,∀ z,
    let r := entryResidualParameters z
    let a := (canonicalCountInput r).1
    matrixEntryBox z ≤ (4*a.2.1^8)^tabulationDimension a+
      gridStateCount (completionEnumerationData a.1)+
      gridStateCount (completionEnumerationData r.1)+gridStateCount (z.1.2,2)+
      r.2.1+r.2.2+(entryCacheParameters z).2+p.eval (weight z) := by
  obtain ⟨p,hp⟩ := polynomial_entryResidual
  obtain ⟨q,hq⟩ := polynomial_canonicalCountInput
  refine ⟨q.comp p+p+X,?_⟩
  intro z
  dsimp only
  have hr : weight (entryResidualParameters z) ≤ p.eval (weight z) :=
    (Nat.le_add_left _ _).trans (hp z)
  have ha : weight (canonicalCountInput (entryResidualParameters z)) ≤
      q.eval (p.eval (weight z)) :=
    (Nat.le_add_left _ _).trans ((hq _).trans (polynomial_eval_monotone q hr))
  have hf := (weight_fst (canonicalCountInput (entryResidualParameters z))).trans ha
  change weight (canonicalCountInput (entryResidualParameters z)).1 ≤
    q.eval (p.eval (weight z)) at hf
  simp only [eval_add,eval_comp,eval_X]
  change (4*((canonicalCountInput (entryResidualParameters z)).1).2.1^8)^
      tabulationDimension (canonicalCountInput (entryResidualParameters z)).1+
      gridStateCount (completionEnumerationData (canonicalCountInput (entryResidualParameters z)).1.1)+
      ((entryResidualParameters z).2.1+(entryResidualParameters z).2.2+
        weight (canonicalCountInput (entryResidualParameters z)).1)+
      gridStateCount (completionEnumerationData (entryResidualParameters z).1)+
      weight (entryResidualParameters z)+(entryCacheParameters z).2+
      gridStateCount (z.1.2,2)+weight z ≤ _
  omega

theorem matrixEntryMeasure_polynomial : ∃ p : Polynomial ℕ,∀ z,
    matrixEntryMeasure z ≤ p.eval (matrixEntryBox z) := by
  obtain ⟨p,hp⟩ := polynomial_entryCacheParameters
  obtain ⟨q,hq⟩ := completionWeightMeasure_polynomial
  refine ⟨q+p+X,?_⟩
  intro z
  let M := matrixEntryBox z
  have hz : weight z ≤ M := by unfold M matrixEntryBox; omega
  have hw : weight (entryCacheParameters z) ≤ p.eval M :=
    (Nat.le_add_left _ _).trans ((hp z).trans (polynomial_eval_monotone p hz))
  have hc : completionBoxMeasure (residualParameters (entryCacheParameters z).1) ≤ M := by
    unfold M matrixEntryBox; omega
  have hq' : completionWeightMeasure (residualParameters (entryCacheParameters z).1) ≤
      q.eval M := (hq _).trans (polynomial_eval_monotone q hc)
  have hs : (entryCacheParameters z).2+gridStateCount (z.1.2,2)+weight z ≤ M := by
    unfold M matrixEntryBox; omega
  change (entryCacheParameters z).2+
    completionWeightMeasure (residualParameters (entryCacheParameters z).1)+
    weight (entryCacheParameters z)+gridStateCount (z.1.2,2)+weight z ≤ _
  change _ ≤ (q+p+X).eval M
  simp only [eval_add,eval_X]
  omega

end ContingencyTables.ProfilePrograms

end OAI