cfahlgren1/math / lean /OAI /Combinatorics /IndependentSets /Expansion /PreprocessingPaddingWords.lean
cfahlgren1's picture
download
raw
6.74 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Expansion.PreprocessingPaddingTables
import OAI.Combinatorics.IndependentSets.Machines.MachinePaddingRows
namespace OAI
namespace IndependentSetsGames.Foundations.PCP.PreprocessingPaddingWords
open Complexity PortTables
variable {n m d : Nat}
theorem encodeWords_flatMap {α : Type*} (xs : List α) (words : α → List Nat) :
encodeWords (xs.flatMap words) = xs.flatMap (fun x => encodeWords (words x)) := by
induction xs with
| nil => rfl
| cons x xs ih => simp only [List.flatMap_cons, encodeWords_append, ih]
theorem ofFn_split {α : Type*} (h : n ≤ m) (f : Fin m → α) :
List.ofFn f =
List.ofFn (fun v : Fin n => f (v.castLE h)) ++
List.ofFn (fun v : Fin (m - n) => f (PreprocessingPaddingTables.vertexEquiv h (.inr v))) := by
calc
List.ofFn f = List.ofFn
(fun v : Fin (n + (m - n)) => f (Fin.cast (Nat.add_sub_of_le h) v)) :=
List.ofFn_congr (Nat.add_sub_of_le h).symm f
_ = _ := by rw [List.ofFn_add]; rfl
theorem flatten_ofFn_rowIndex {α : Type*} (f : Fin (n * d) → List α) :
(List.ofFn f).flatten =
(List.ofFn (fun v : Fin n =>
(List.ofFn (fun p : Fin d => f (rowIndex n d (v, p)))).flatten)).flatten := by
rw [List.ofFn_mul, List.flatten_flatten, List.map_ofFn]
apply congrArg List.flatten
apply congrArg List.ofFn
funext v
apply congrArg List.flatten
apply congrArg List.ofFn
funext p
apply congrArg f
apply Fin.ext
simp only [rowIndex_val, Nat.mul_comm, Nat.add_comm]
def rowBits (table : Table n d) (v : Fin n) (p : Fin d) : List Bool :=
encodeWord v.val ++ encodeWord (table.reverseIndex[rowIndex n d (v, p)]).val ++
encodeWords (GraphTables.relationWords table.relations[rowIndex n d (v, p)])
def vertexBits (table : Table n d) (v : Fin n) : List Bool :=
(List.ofFn (fun p : Fin d => rowBits table v p)).flatten
def rowsBits (table : Table n d) : List Bool :=
encodeWords ((flatRows table).toList.flatMap GraphTables.rowWords)
theorem rowBits_flat (table : Table n d) (i : Fin (n * d)) :
encodeWords (GraphTables.rowWords ((flatRows table)[i])) =
rowBits table ((rowIndex n d).symm i).1 ((rowIndex n d).symm i).2 := by
simp only [flatRows, Vector.getElem_ofFn, Fin.getElem_fin,
MachineTableRows.rowBits_eq, rowBits, Prod.eta, Equiv.apply_symm_apply]
theorem rowsBits_eq_vertices (table : Table n d) :
rowsBits table = (List.ofFn (fun v : Fin n => vertexBits table v)).flatten := by
have hflat : (flatRows table).toList =
List.ofFn (fun i : Fin (n * d) => (flatRows table)[i]) := by
simp only [flatRows, Vector.toList_ofFn, Vector.getElem_ofFn, Fin.getElem_fin]
unfold rowsBits
rw [hflat, encodeWords_flatMap, List.flatMap_def, List.map_ofFn]
change (List.ofFn (fun i : Fin (n * d) =>
encodeWords (GraphTables.rowWords ((flatRows table)[i])))).flatten = _
simp_rw [rowBits_flat]
simpa only [Equiv.symm_apply_apply, vertexBits] using
flatten_ofFn_rowIndex (fun i : Fin (n * d) =>
rowBits table ((rowIndex n d).symm i).1 ((rowIndex n d).symm i).2)
theorem rowBits_pad_old (table : Table n d) (h : n ≤ m) (v : Fin n) (p : Fin d) :
rowBits (PreprocessingPaddingTables.pad table h) (v.castLE h) p = rowBits table v p := by
unfold rowBits
rw [PreprocessingPaddingTables.reverseIndex_pad_old,
PreprocessingPaddingTables.relations_pad_old]
have he : (rowIndex m d ((rotation table (v, p)).1.castLE h,
(rotation table (v, p)).2)).val = (table.reverseIndex[rowIndex n d (v, p)]).val := by
rw [← rowIndex_rotation]
rfl
rw [he]
rfl
theorem rowBits_pad_new (table : Table n d) (h : n ≤ m)
(v : Fin (m - n)) (p : Fin d) :
rowBits (PreprocessingPaddingTables.pad table h)
(PreprocessingPaddingTables.vertexEquiv h (.inr v)) p =
MachineDummyRows.rowBits (n + v.val) (p.val + d * (n + v.val)) := by
unfold rowBits
rw [PreprocessingPaddingTables.reverseIndex_pad_new,
PreprocessingPaddingTables.relations_pad_new]
rfl
theorem dummy_rowsBits_eq_ofFn (v e count : Nat) :
MachineDummyRows.rowsBits v e count =
(List.ofFn (fun p : Fin count => MachineDummyRows.rowBits v (e + p.val))).flatten := by
induction count generalizing e with
| zero => rfl
| succ count ih =>
rw [MachineDummyRows.rowsBits, List.ofFn_succ, List.flatten_cons, ih]
simp only [Fin.val_zero, Nat.add_zero, Fin.val_succ]
congr 1
apply congrArg (fun f : Fin count → List Bool => (List.ofFn f).flatten)
funext p
congr 1
omega
theorem paddingBits_eq_ofFn (d v e count : Nat) :
MachinePaddingRows.paddingBits d v e count =
(List.ofFn (fun k : Fin count =>
MachineDummyRows.rowsBits (v + k.val) (e + k.val * d) d)).flatten := by
induction count generalizing v e with
| zero => rfl
| succ count ih =>
rw [MachinePaddingRows.paddingBits, List.ofFn_succ, List.flatten_cons, ih]
simp only [Fin.val_zero, Nat.zero_mul, Nat.add_zero, Fin.val_succ, Nat.add_mul, Nat.one_mul]
congr 1
apply congrArg (fun f : Fin count → List Bool => (List.ofFn f).flatten)
funext k
congr 1 <;> omega
@[simp] theorem vertexBits_pad_old (table : Table n d) (h : n ≤ m) (v : Fin n) :
vertexBits (PreprocessingPaddingTables.pad table h) (v.castLE h) = vertexBits table v := by
simp only [vertexBits, rowBits_pad_old]
theorem vertexBits_pad_new (table : Table n d) (h : n ≤ m) (v : Fin (m - n)) :
vertexBits (PreprocessingPaddingTables.pad table h)
(PreprocessingPaddingTables.vertexEquiv h (.inr v)) =
MachineDummyRows.rowsBits (n + v.val) (n * d + v.val * d) d := by
unfold vertexBits
simp_rw [rowBits_pad_new]
rw [dummy_rowsBits_eq_ofFn]
apply congrArg (fun f : Fin d → List Bool => (List.ofFn f).flatten)
funext p
congr 1
ring
theorem rowsBits_pad (table : Table n d) (h : n ≤ m) :
rowsBits (PreprocessingPaddingTables.pad table h) =
rowsBits table ++ MachinePaddingRows.paddingBits d n (n * d) (m - n) := by
rw [rowsBits_eq_vertices, ofFn_split h, List.flatten_append]
simp_rw [vertexBits_pad_old, vertexBits_pad_new]
rw [← rowsBits_eq_vertices, ← paddingBits_eq_ofFn]
theorem tableBits_pad (table : Table n d) (h : n ≤ m) :
tableBits (PreprocessingPaddingTables.pad table h) =
encodeWords [m, m * d] ++ rowsBits table ++
MachinePaddingRows.paddingBits d n (n * d) (m - n) := by
change encodeWords (PortTables.tableWords (PreprocessingPaddingTables.pad table h)) = _
rw [tableWords_eq, encodeWords_append]
change encodeWords [m, m * d] ++ rowsBits (PreprocessingPaddingTables.pad table h) = _
rw [rowsBits_pad, List.append_assoc]
end IndependentSetsGames.Foundations.PCP.PreprocessingPaddingWords
end OAI

Xet Storage Details

Size:
6.74 kB
·
Xet hash:
e066bb2dd26da12e429a131e4a55cb2dcc079db96625e6d79c5b7c5e64b9d611

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.