File size: 10,733 Bytes
cdec422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import OAI.LinearAlgebra.MatrixMultiplication.FieldHistory.TickCarry
import OAI.LinearAlgebra.MatrixMultiplication.FieldHistory.SourceAssignment
import OAI.LinearAlgebra.MatrixMultiplication.FieldHistory.Produced
import OAI.LinearAlgebra.MatrixMultiplication.FieldGroups.SelectionCore
import OAI.LinearAlgebra.MatrixMultiplication.FieldGroups.AssignmentRetention
import OAI.LinearAlgebra.MatrixMultiplication.FieldGroups.Assignments

namespace OAI

/-! Finite extraction histories, inherited masks and recovery bounds. -/

noncomputable section

namespace MatrixMultiplication.AllFieldHistoryTick

open MatrixMultiplication.Foundation AllFieldHistory AllFieldFiniteFamily
open AllFieldGroupSelection AllFieldHistoryGroupedRecovery
open scoped BigOperators Classical
attribute [local instance] Classical.propDecidable Classical.decEq

variable {K tick : ℕ} (allocation : Allocation) (m : ℕ) (ε slack : ℝ)

abbrev Choices := ∀ sigma : Placement,
  Selected (K := K) (tick := tick) allocation m ε sigma slack

abbrev AmbientTag (sigma : Placement) :=
  JointCoarseHashing.Triple
    (AllFieldGroupOrbitData.Pos (K := K) (tick := tick) allocation m sigma)

abbrev Tags (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :=
  ∀ sigma : Placement, {e // e ∈ (chosen sigma).targets}

local instance tagsDecidableEq (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    DecidableEq (Tags allocation m ε slack chosen) := Classical.decEq _

@[instance_reducible]
private def coarseTripleFintype (P : Type) [Fintype P] :
    Fintype (JointCoarseHashing.Triple P) := inferInstance

instance ambientTagFintype (sigma : Placement) :
    Fintype (AmbientTag (K := K) (tick := tick) allocation m sigma) :=
  coarseTripleFintype (AllFieldGroupOrbitData.Pos (K := K) (tick := tick) allocation m sigma)

instance ambientTagsFintype :
    Fintype (∀ sigma, AmbientTag (K := K) (tick := tick) allocation m sigma) := inferInstance

instance tagsFintype (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    Fintype (Tags allocation m ε slack chosen) := inferInstance

def select (chosen : Choices (K := K) (tick := tick) allocation m ε slack)
    (j : Tags allocation m ε slack chosen) :
    ∀ sigma, AmbientTag (K := K) (tick := tick) allocation m sigma :=
  fun sigma => AllFieldGroupOrbitData.coarse allocation m sigma (j sigma).val

theorem select_injective
    (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    Function.Injective (select allocation m ε slack chosen) := by
  intro _ _ hequal
  funext sigma
  apply Subtype.ext
  exact AllFieldGroupOrbitData.coarse_injective allocation m sigma (congrFun hequal sigma)

def targets (chosen : Choices (K := K) (tick := tick) allocation m ε slack)
    (j : Tags allocation m ε slack chosen) :
    AllFieldHistoryRecovery.Targets (K := K) (tick := tick) allocation m :=
  joinGroupTargets (activeCounts allocation m) (fun sigma => (j sigma).val)

def assignments (chosen : Choices (K := K) (tick := tick) allocation m ε slack)
    (sigma : Placement) :=
  AllFieldGroupAssignmentRetention.physicalAssignment allocation m ε sigma
    (JointOrdinarySelection.hashLevel
      (selectionHashRate (K := K) (tick := tick) allocation sigma slack) m)
    (JointOrdinarySelection.hashSet
      (selectionHashRate (K := K) (tick := tick) allocation sigma slack) m)
    (chosen sigma).sample

def assignment (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :=
  groupedAssignment allocation m (AmbientTag (K := K) (tick := tick) allocation m)
    (assignments allocation m ε slack chosen)

theorem coherent (F : Type*) [Field F]
    (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    JointExtraction.Coherent
      (AllFieldHistorySource.preparedSource (K := K) (tick := tick) allocation m F ε)
      (assignment allocation m ε slack chosen) := by
  apply AllFieldHistorySource.groupedAssignment_coherent allocation m F ε
  intro sigma
  exact AllFieldGroupAssignments.physicalAssignment_coherent F allocation m ε sigma
    _ _ (chosen sigma).sample

theorem repair (F : Type*) [Field F] (hε : 0 < ε)
    (hm : AllFieldHistoryRecovery.minimumDilation (K := K) (tick := tick) allocation ε ≤ m)
    (chosen : Choices (K := K) (tick := tick) allocation m ε slack)
    (j : Tags allocation m ε slack chosen) :
    InverseLinearRecovery.RecoveredBy
      (AllFieldHistoryRecovery.ideal F allocation m ε (targets allocation m ε slack chosen j))
      (JointExtraction.branch
        (AllFieldHistorySource.preparedSource (K := K) (tick := tick) allocation m F ε)
        (assignment allocation m ε slack chosen) (select allocation m ε slack chosen j))
      (AllFieldHistoryRecovery.shiftCount (K := K) (tick := tick) allocation ε m) := by
  rw [AllFieldHistorySource.preparedSource_eq_delete]
  apply repair_grouped F allocation hε hm
    (AmbientTag (K := K) (tick := tick) allocation m)
    (assignments allocation m ε slack chosen)
    (select allocation m ε slack chosen j) (fun sigma => (j sigma).val)
  · intro sigma w hw
    have hs := AllFieldGroupAssignmentRetention.assigned_some_idealSide
      allocation m ε sigma _ _ (chosen sigma).sample (j sigma).val (sigma.symm 0, w) hw
    simpa only [Equiv.apply_symm_apply] using hs
  · intro sigma w hw
    have hs := AllFieldGroupAssignmentRetention.assigned_some_idealSide
      allocation m ε sigma _ _ (chosen sigma).sample (j sigma).val (sigma.symm 1, w) hw
    simpa only [Equiv.apply_symm_apply] using hs
  · intro sigma w hw
    have hs := AllFieldGroupAssignmentRetention.assigned_some_idealSide
      allocation m ε sigma _ _ (chosen sigma).sample (j sigma).val (sigma.symm 2, w) hw
    simpa only [Equiv.apply_symm_apply] using hs
  · intro side w hw sigma
    have hg := (chosen sigma).good (j sigma).val (j sigma).property
    have hh := AllFieldGroupAssignmentRetention.good_projected_failure_le F
      allocation m ε sigma _ _
      (JointOrdinarySelection.hashSet_AP (selectionHashRate allocation sigma slack) m)
      (m : ℝ) (chosen sigma).sample (targets allocation m ε slack chosen j)
      (by simpa only [targets, project_joinGroupTargets] using hg) side w hw
    simp only [targets, project_joinGroupTargets] at hh
    rw [filter_eq_rejected] at hh ⊢
    dsimp only [assignments, select]
    exact hh

def canonicalMap (F : Type*) [Field F]
    (e : AllFieldHistoryRecovery.Targets (K := K) (tick := tick) allocation m) :
    LocalMap (AllFieldHistoryRecovery.ideal F allocation m ε e)
      (AllFieldHistoryRecovery.canonical (K := K) (tick := tick) F allocation m ε) := by
  apply LocalMap.ofExists
  refine ⟨_, _, _, (Tensor.pullback_eq_restrict
    (AllFieldHistoryRecovery.coordinates allocation m e).symm
    (AllFieldHistoryRecovery.coordinates allocation m e).symm
    (AllFieldHistoryRecovery.coordinates allocation m e).symm _).symm.trans ?_⟩
  funext x y z
  change AllFieldHistoryRecovery.ideal F allocation m ε e _ _ _ = _
  rw [AllFieldHistoryRecovery.ideal_coordinates]
  simp only [Equiv.apply_symm_apply]

def activeExecution (F : Type*) [Field F] (hε : 0 < ε)
    (hm : AllFieldHistoryRecovery.minimumDilation (K := K) (tick := tick) allocation ε ≤ m)
    (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    Execution
      (AllFieldHistoryRegrouping.activeTensor (K := K) (tick := tick) allocation m F ε)
      (Tensor.directSum (fun _ : Tags allocation m ε slack chosen =>
        AllFieldHistoryRegrouping.producedTensor (K := K) (tick := tick) allocation m F ε)) := by
  let prepared := (Execution.initial
    (AllFieldHistoryRegrouping.activeTensor (K := K) (tick := tick) allocation m F ε)).restrict _
      (AllFieldHistorySource.preparedMap (K := K) (tick := tick) allocation m F ε)
  let repaired := prepared.extractSelectedAndRepair
    (assignment allocation m ε slack chosen) (coherent allocation m ε slack F chosen)
    (select allocation m ε slack chosen) (select_injective allocation m ε slack chosen)
    (fun j => AllFieldHistoryRecovery.ideal F allocation m ε (targets allocation m ε slack chosen j))
    (AllFieldHistoryRecovery.shiftCount (K := K) (tick := tick) allocation ε m)
    (repair allocation m ε slack F hε hm chosen)
  let canonical := repaired.restrict _ (LocalMap.directSum _ _
    (fun j => canonicalMap allocation m ε F (targets allocation m ε slack chosen j)))
  exact canonical.restrict _
    ((AllFieldHistoryProduced.map (K := K) (tick := tick) allocation m F hε.le).parallelCopies _)

@[simp] theorem activeExecution_copies (F : Type*) [Field F] (hε : 0 < ε)
    (hm : AllFieldHistoryRecovery.minimumDilation (K := K) (tick := tick) allocation ε ≤ m)
    (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    Fintype.card (activeExecution allocation m ε slack F hε hm chosen).Copies =
      2 ^ (3 * AllFieldHistoryRecovery.shiftCount (K := K) (tick := tick) allocation ε m) := by
  change Fintype.card (InverseLinearRecovery.MaskRectangles
    (AllFieldHistoryRecovery.shiftCount (K := K) (tick := tick) allocation ε m) × PUnit) = _
  rw [Fintype.card_prod, ExactRecovery.card_mask_rectangles, Fintype.card_fin,
    Fintype.card_punit, mul_one]

theorem card_tags (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    Fintype.card (Tags allocation m ε slack chosen) =
      ∏ _sigma : Placement,
        ⌊Real.exp ((m : ℝ) * (nativeCapacity (K := K) (tick := tick) allocation - slack))⌋₊ := by
  rw [Fintype.card_pi]
  apply Finset.prod_congr rfl
  intro sigma _
  simpa only [Fintype.card_coe] using (chosen sigma).card_targets

def execution (F : Type*) [Field F] (hε : 0 < ε)
    (hm : AllFieldHistoryRecovery.minimumDilation (K := K) (tick := tick) allocation ε ≤ m)
    (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    Execution (stateTensor F (K := K) allocation m ε tick)
      (Tensor.directSum (fun _ : Tags allocation m ε slack chosen =>
        stateTensor F (K := K) allocation m ε (tick + 1))) :=
  AllFieldHistoryTickCarry.liftExecution (K := K) (tick := tick) allocation m F ε
    (activeExecution allocation m ε slack F hε hm chosen)

@[simp] theorem execution_copies (F : Type*) [Field F] (hε : 0 < ε)
    (hm : AllFieldHistoryRecovery.minimumDilation (K := K) (tick := tick) allocation ε ≤ m)
    (chosen : Choices (K := K) (tick := tick) allocation m ε slack) :
    Fintype.card (execution allocation m ε slack F hε hm chosen).Copies =
      2 ^ (3 * AllFieldHistoryRecovery.shiftCount (K := K) (tick := tick) allocation ε m) :=
  activeExecution_copies allocation m ε slack F hε hm chosen

end MatrixMultiplication.AllFieldHistoryTick

end

end OAI