File size: 16,723 Bytes
e320e82 | 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | import Mathlib
import OAI.Combinatorics.IndependentSets.Expansion.PoweringTables
import OAI.Combinatorics.IndependentSets.Machines.Block
namespace OAI
namespace IndependentSetsGames.Foundations.PCP.PoweringRowData
open IndependentSetsGames.Foundations.Complexity
open Turing
open PoweringMachineRow MachineFixedBlockMap
open PoweringWalks PoweringLabels PoweringAddresses PoweringReach
open PoweringOpinionTables PoweringEnumeration
variable {vertices d : Nat}
theorem firstMatch_of_first {S : Nat} (mask : Fin S → Bool) (i : Fin S)
(hi : mask i = true) (hfirst : ∀ j : Fin S, j.val < i.val → mask j = false) :
firstMatch mask = some i := by
unfold firstMatch
apply List.find?_ofFn_eq_some.mpr
refine ⟨hi, i, rfl, ?_⟩
intro j hj
change ¬mask j = true
simp [hfirst j hj]
theorem firstMatch_firstIndex {X : Type*} (p : X → Prop) [DecidablePred p]
(xs : List X) (h : ∃ a ∈ xs, p a) :
firstMatch (fun i : Fin xs.length => decide (p (xs.get i))) =
some (firstIndex p xs h) := by
apply firstMatch_of_first
· exact decide_eq_true (firstIndex_matches p xs h)
· intro j hj
exact decide_eq_false (firstIndex_is_first p xs h j hj)
def endpointMask (G : PortGraph (Fin vertices) (Fin d)) (t : Nat)
(center target : Fin vertices) (i : AddressIndex d t) : Bool :=
decide ((wordToBall G t center ((allAddresses d t).get i)).val = target)
theorem firstMatch_endpointMask (G : PortGraph (Fin vertices) (Fin d)) (t : Nat)
(center : Fin vertices) (u : Ball G t center) :
firstMatch (endpointMask G t center u.val) = some (addressIndex G t center u) := by
unfold endpointMask addressIndex
exact firstMatch_firstIndex
(fun w : PortWords (Fin d) t => (wordToBall G t center w).val = u.val)
(allAddresses d t) (by
obtain ⟨w, hw⟩ := wordToBall_surjective G t center u
exact ⟨w, mem_allAddresses d t w, congrArg Subtype.val hw⟩)
def slotCount (d n : Nat) : Nat := (allAddresses d (n + 1)).length
abbrev RowBuffer (d n : Nat) := Buffer (inputSize (n + 1) (slotCount d n))
def fixedLabelAt (d n : Nat) (a : Fin (PoweringTables.labelCount d n))
(i : Fin (slotCount d n)) : GraphTables.Label :=
decodeLabel d (n + 1) 64 a ((allAddresses d (n + 1)).get i)
theorem fixedLabelAt_addressIndex (G : PortGraph (Fin vertices) (Fin d)) (n : Nat)
(center : Fin vertices) (u : Ball G (n + 1) center)
(a : Fin (PoweringTables.labelCount d n)) :
fixedLabelAt d n a (addressIndex G (n + 1) center u) =
decode (finitePortSelector G (n + 1) center) (decodeLabel d (n + 1) 64 a) u := by
simpa only [fixedLabelAt, labelTable_get] using
labelTable_addressIndex G (n + 1) center u (decodeLabel d (n + 1) 64 a)
def walkData (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1))
(k : Fin (n + 1)) : Field (slotCount d n) → Bool
| .inl (a, b) => PortTables.accepts input (edgeAt (PortTables.portGraph input) n w k) a b
| .inr (.inl i) => endpointMask (PortTables.portGraph input) (n + 1) w.1
(edgeAt (PortTables.portGraph input) n w k).1 i
| .inr (.inr i) => endpointMask (PortTables.portGraph input) (n + 1)
(endpoint (PortTables.portGraph input) w)
((PortTables.portGraph input).rot (edgeAt (PortTables.portGraph input) n w k)).1 i
def walkBits (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1)) : RowBuffer d n :=
packData (walkData input n w)
@[simp] theorem basePredicate_walkBits (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1))
(a b : GraphTables.Label) :
basePredicate (walkBits input n w) k a b =
PortTables.accepts input (edgeAt (PortTables.portGraph input) n w k) a b := by
simp [basePredicate, walkBits, walkData]
@[simp] theorem leftMatches_walkBits (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1)) :
leftMatches (walkBits input n w) k = endpointMask (PortTables.portGraph input)
(n + 1) w.1 (edgeAt (PortTables.portGraph input) n w k).1 := by
funext i
simp [leftMatches, walkBits, walkData]
@[simp] theorem rightMatches_walkBits (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1)) :
rightMatches (walkBits input n w) k = endpointMask (PortTables.portGraph input)
(n + 1) (endpoint (PortTables.portGraph input) w)
((PortTables.portGraph input).rot (edgeAt (PortTables.portGraph input) n w k)).1 := by
funext i
simp [rightMatches, walkBits, walkData]
theorem firstMatch_walkBits_left (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1)) :
firstMatch (leftMatches (walkBits input n w) k) = some
(addressIndex (PortTables.portGraph input) (n + 1) w.1
(tailFromStart (PortTables.portGraph input) n w k)) := by
rw [leftMatches_walkBits]
simpa only [tailFromStart_val, slotCount] using
firstMatch_endpointMask (PortTables.portGraph input) (n + 1) w.1
(tailFromStart (PortTables.portGraph input) n w k)
theorem firstMatch_walkBits_right (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1)) :
firstMatch (rightMatches (walkBits input n w) k) = some
(addressIndex (PortTables.portGraph input) (n + 1)
(endpoint (PortTables.portGraph input) w)
(headFromEnd (PortTables.portGraph input) n w k)) := by
rw [rightMatches_walkBits]
simpa only [headFromEnd_val, slotCount] using
firstMatch_endpointMask (PortTables.portGraph input) (n + 1)
(endpoint (PortTables.portGraph input) w) (headFromEnd (PortTables.portGraph input) n w k)
theorem edgeAccept_walkBits (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1)) (k : Fin (n + 1))
(a b : Fin (PoweringTables.labelCount d n)) :
edgeAccept (fixedLabelAt d n) (walkBits input n w) k a b =
PortTables.accepts input (edgeAt (PortTables.portGraph input) n w k)
(decode (finitePortSelector (PortTables.portGraph input) (n + 1) w.1)
(decodeLabel d (n + 1) 64 a) (tailFromStart (PortTables.portGraph input) n w k))
(decode (finitePortSelector (PortTables.portGraph input) (n + 1)
(endpoint (PortTables.portGraph input) w))
(decodeLabel d (n + 1) 64 b) (headFromEnd (PortTables.portGraph input) n w k)) := by
simp only [edgeAccept, firstMatch_walkBits_left, firstMatch_walkBits_right,
basePredicate_walkBits, fixedLabelAt_addressIndex]
theorem rowAccept_walkBits (input : PortTables.Table vertices d) (n : Nat)
(w : Walk (Fin vertices) (Fin d) (n + 1))
(a b : Fin (PoweringTables.labelCount d n)) :
rowAccept (fixedLabelAt d n) (walkBits input n w) a b =
rowsAccepts (PortTables.accepts input) (walkRows (PortTables.portGraph input) n w)
(labelTable (decodeLabel d (n + 1) 64 a))
(labelTable (decodeLabel d (n + 1) 64 b)) := by
rw [rowsAccepts_walkRows]
apply Bool.eq_iff_iff.mpr
simp only [rowAccept_eq_true, PoweringTest.pathAccepts_eq_true_iff, edgeAccept_walkBits]
def transposeField {S : Nat} : Field S → Field S
| .inl (a, b) => .inl (b, a)
| .inr (.inl i) => .inr (.inr i)
| .inr (.inr i) => .inr (.inl i)
def transposeBits {t S : Nat} (bits : Buffer (inputSize t S)) : Buffer (inputSize t S) :=
packData fun k field => bits (inputEquiv t S (k, transposeField field))
@[simp] theorem basePredicate_transposeBits {t S : Nat}
(bits : Buffer (inputSize t S)) (k : Fin t) (a b : GraphTables.Label) :
basePredicate (transposeBits bits) k a b = basePredicate bits k b a := by
simp [basePredicate, transposeBits, transposeField]
@[simp] theorem leftMatches_transposeBits {t S : Nat}
(bits : Buffer (inputSize t S)) (k : Fin t) :
leftMatches (transposeBits bits) k = rightMatches bits k := by
funext i
simp [leftMatches, rightMatches, transposeBits, transposeField]
@[simp] theorem rightMatches_transposeBits {t S : Nat}
(bits : Buffer (inputSize t S)) (k : Fin t) :
rightMatches (transposeBits bits) k = leftMatches bits k := by
funext i
simp [leftMatches, rightMatches, transposeBits, transposeField]
theorem edgeAccept_transposeBits {t S q : Nat}
(labelAt : Fin q → Fin S → GraphTables.Label)
(bits : Buffer (inputSize t S)) (k : Fin t) (a b : Fin q) :
edgeAccept labelAt (transposeBits bits) k a b = edgeAccept labelAt bits k b a := by
simp only [edgeAccept, leftMatches_transposeBits, rightMatches_transposeBits]
cases firstMatch (leftMatches bits k) <;>
cases firstMatch (rightMatches bits k) <;>
simp
theorem rowAccept_transposeBits {t S q : Nat}
(labelAt : Fin q → Fin S → GraphTables.Label)
(bits : Buffer (inputSize t S)) (a b : Fin q) :
rowAccept labelAt (transposeBits bits) a b = rowAccept labelAt bits b a := by
apply Bool.eq_iff_iff.mpr
simp only [rowAccept_eq_true, edgeAccept_transposeBits]
def rowBits (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) : RowBuffer d n :=
if e.1 then transposeBits (walkBits input n e.2) else walkBits input n e.2
def rowData (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n)
(k : Fin (n + 1)) (field : Field (slotCount d n)) : Bool :=
walkData input n e.2 k (if e.1 then transposeField field else field)
theorem rowBits_packData (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) :
rowBits input n e = packData (rowData input n e) := by
rcases e with ⟨direction, w⟩
cases direction <;> funext i <;>
simp [rowBits, rowData, transposeBits, walkBits, packData]
@[simp] theorem rowBits_field (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n)
(k : Fin (n + 1)) (field : Field (slotCount d n)) :
rowBits input n e (inputEquiv (n + 1) (slotCount d n) (k, field)) =
rowData input n e k field := by
rw [rowBits_packData, packData_inputEquiv]
theorem rowAccept_rowBits (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n)
(a b : Fin (PoweringTables.labelCount d n)) :
rowAccept (fixedLabelAt d n) (rowBits input n e) a b =
PoweringTables.rowAccepts input n e a b := by
rcases e with ⟨direction, w⟩
cases direction <;>
simp only [rowBits, Bool.false_eq_true, ite_false, ite_true,
rowAccept_transposeBits, rowAccept_walkBits, PoweringTables.rowAccepts]
theorem rowBlock_at_rowBits (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n)
(a b : Fin (PoweringTables.labelCount d n)) :
rowBlock (fixedLabelAt d n) (rowBits input n e)
(GenericGraphTables.relationIndex (PoweringTables.labelCount d n) (a, b)) =
PoweringTables.rowAccepts input n e a b := by
rw [rowBlock_at, rowAccept_rowBits]
def dataWords (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) : List Nat :=
(List.ofFn (rowBits input n e)).map GraphTables.bitWord
def dataTape (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) : List Bool :=
encodeWords (dataWords input n e)
theorem dataTape_eq (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) :
dataTape input n e = encodeBits (List.ofFn (rowBits input n e)) :=
(encodeBits_graphWords _).symm
theorem dataWords_length (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) :
(dataWords input n e).length = (n + 1) * (4096 + (slotCount d n + slotCount d n)) := by
rw [dataWords, List.length_map]
simpa only [inputSize] using (List.length_ofFn (f := rowBits input n e))
theorem dataTape_length_le (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) :
(dataTape input n e).length ≤ 2 * inputSize (n + 1) (slotCount d n) := by
rw [dataTape_eq]
simpa only [List.length_ofFn] using encodeBits_length_le (List.ofFn (rowBits input n e))
def emittedRelation (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) :
GenericGraphTables.RelationTable (PoweringTables.labelCount d n) :=
Vector.ofFn (rowBlock (fixedLabelAt d n) (rowBits input n e))
theorem emittedRelation_eq (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) :
emittedRelation input n e = GenericGraphTables.relationOf (PoweringTables.rowAccepts input n e) := by
unfold emittedRelation GenericGraphTables.relationOf
apply congrArg Vector.ofFn
funext i
exact rowAccept_rowBits input n e _ _
theorem rowBlock_unary (input : PortTables.Table vertices d) (n : Nat)
(e : PoweringTest.Dart (Fin vertices) (Fin d) n) :
encodeBits (List.ofFn (rowBlock (fixedLabelAt d n) (rowBits input n e))) =
encodeWords (GenericGraphTables.relationWords (emittedRelation input n e)) := by
have hbit : GraphTables.bitWord = GenericGraphTables.bitWord := by
funext b
cases b <;> rfl
have h := encodeBits_graphWords
(List.ofFn (rowBlock (fixedLabelAt d n) (rowBits input n e)))
rw [hbit] at h
simpa only [emittedRelation, GenericGraphTables.relationWords, Vector.toList_ofFn] using h
theorem emittedRelation_table (input : PortTables.Table vertices d) (n : Nat)
(i : Fin (PoweringTables.dartCount vertices d n)) :
emittedRelation input n (decodeDart vertices d n i) =
(PoweringTables.table input n).rows[i].relation := by
apply Vector.ext
intro j hj
have h := PoweringTables.table_accepts input n i
((GenericGraphTables.relationIndex (PoweringTables.labelCount d n)).symm ⟨j, hj⟩).1
((GenericGraphTables.relationIndex (PoweringTables.labelCount d n)).symm ⟨j, hj⟩).2
have hindex : GenericGraphTables.relationIndex (PoweringTables.labelCount d n)
(((GenericGraphTables.relationIndex (PoweringTables.labelCount d n)).symm ⟨j, hj⟩).1,
((GenericGraphTables.relationIndex (PoweringTables.labelCount d n)).symm ⟨j, hj⟩).2) =
⟨j, hj⟩ := by
change GenericGraphTables.relationIndex (PoweringTables.labelCount d n)
((GenericGraphTables.relationIndex (PoweringTables.labelCount d n)).symm ⟨j, hj⟩) = _
exact Equiv.apply_symm_apply _ _
simp only [GenericGraphTables.acceptsAt, GenericGraphTables.relationAt, hindex,
Fin.getElem_fin] at h
simp only [emittedRelation, Vector.getElem_ofFn]
change rowBlock (fixedLabelAt d n) (rowBits input n (decodeDart vertices d n i)) ⟨j, hj⟩ =
(PoweringTables.table input n).rows[i].relation[j]
change rowAccept (fixedLabelAt d n) (rowBits input n (decodeDart vertices d n i))
((GenericGraphTables.relationIndex (PoweringTables.labelCount d n)).symm ⟨j, hj⟩).1
((GenericGraphTables.relationIndex (PoweringTables.labelCount d n)).symm ⟨j, hj⟩).2 = _
rw [rowAccept_rowBits]
exact h.symm
theorem rowBlock_unary_table (input : PortTables.Table vertices d) (n : Nat)
(i : Fin (PoweringTables.dartCount vertices d n)) :
encodeBits (List.ofFn (rowBlock (fixedLabelAt d n)
(rowBits input n (decodeDart vertices d n i)))) =
encodeWords (GenericGraphTables.relationWords (PoweringTables.table input n).rows[i].relation) := by
rw [rowBlock_unary, emittedRelation_table]
def tableRowMachineInTime (input : PortTables.Table vertices d) (n : Nat)
(i : Fin (PoweringTables.dartCount vertices d n)) (suffix : List Bool)
(register : RowBuffer d n) (tapes : Bool → List Bool)
(hinput : tapes false = dataTape input n (decodeDart vertices d n i) ++ suffix) :
StateTransition.EvalsToInTime (PoweringMachineRow.machine (t := n + 1) (fixedLabelAt d n)).step
⟨some (), ((), register), tapes⟩
(some ⟨none, ((), emptyBuffer (inputSize (n + 1) (slotCount d n))),
Function.update (Function.update tapes false suffix) true
(encodeWords (GenericGraphTables.relationWords
(PoweringTables.table input n).rows[i].relation) ++ tapes true)⟩) 1 := by
have hinput' : tapes false =
encodeBits (List.ofFn (rowBits input n (decodeDart vertices d n i))) ++ suffix := by
simpa only [dataTape_eq] using hinput
have h := PoweringMachineRow.machineInTime (fixedLabelAt d n)
(rowBits input n (decodeDart vertices d n i)) suffix register tapes hinput'
simpa only [rowBlock_unary_table] using h
end IndependentSetsGames.Foundations.PCP.PoweringRowData
end OAI
|