openAI-math-dataset / lean /OAI /Computability /MinUncut /PCP /PortTableLookup.lean
roseking's picture
Add lean source and binary files (part 62)
2f887db verified
Raw History Blame Contribute Delete
5.21 kB
import Mathlib
import OAI.Computability.MinUncut.PCP.GraphTables
namespace OAI
section
namespace MinUncutGames.Foundations.PCP.PortTableLookup
theorem flatMap_word {α β : Type*} (f : α → List β)
(width j : Nat) (hj : j < width) :
∀ (rows : List α), (∀ a ∈ rows, (f a).length = width) →
∀ (i : Nat) (row : α), rows[i]? = some row →
(rows.flatMap f)[width * i + j]? = (f row)[j]? := by
intro rows
induction rows with
| nil =>
intro _ i row selected
simp at selected
| cons a rows ih =>
intro hwidth i row selected
have ha : (f a).length = width := hwidth a (by simp)
cases i with
| zero =>
have heq : a = row := by simpa using selected
subst row
simp only [Nat.mul_zero, Nat.zero_add, List.flatMap_cons]
exact List.getElem?_append_left (by omega)
| succ i =>
have selected' : rows[i]? = some row := by simpa using selected
have hskip : (f a).length ≤ width * (i + 1) + j := by
rw [ha, Nat.mul_add, Nat.mul_one]
omega
have hoff : width * (i + 1) + j - (f a).length = width * i + j := by
rw [ha, Nat.mul_add, Nat.mul_one]
omega
rw [List.flatMap_cons, List.getElem?_append_right hskip, hoff]
exact ih (fun b hb => hwidth b (by simp [hb])) i row selected'
variable {n d : Nat}
theorem vertices_word (table : PortTables.Table n d) :
(PortTables.tableWords table)[0]? = some n := rfl
theorem darts_word (table : PortTables.Table n d) :
(PortTables.tableWords table)[1]? = some (n * d) := rfl
private theorem row_word (table : PortTables.Table n d) (i : Fin (n * d))
(j : Nat) (hj : j < 4098) :
(PortTables.tableWords table)[2 + 4098 * i.val + j]? =
(GraphTables.rowWords (PortTables.flatRows table)[i])[j]? := by
rw [PortTables.tableWords_eq]
change (n :: n * d :: (PortTables.flatRows table).toList.flatMap
GraphTables.rowWords)[2 + 4098 * i.val + j]? = _
rw [show 2 + 4098 * i.val + j = (4098 * i.val + j + 1) + 1 by omega,
List.getElem?_cons_succ, List.getElem?_cons_succ]
apply flatMap_word GraphTables.rowWords 4098 j hj
(PortTables.flatRows table).toList
(fun row _ => GraphTables.rowWords_length row) i.val
((PortTables.flatRows table)[i])
simp only [Vector.getElem?_toList, Vector.getElem?_eq_getElem i.isLt,
Fin.getElem_fin]
theorem tail_word (table : PortTables.Table n d) (i : Fin (n * d)) :
(PortTables.tableWords table)[2 + 4098 * i.val]? =
some (((PortTables.rowIndex n d).symm i).1.val) := by
have h := row_word table i 0 (by decide)
simpa only [Nat.add_zero, GraphTables.rowWords, PortTables.flatRows,
Fin.getElem_fin, Vector.getElem_ofFn, Fin.eta, List.cons_append,
List.nil_append, List.getElem?_cons_zero] using h
theorem reverse_word (table : PortTables.Table n d) (i : Fin (n * d)) :
(PortTables.tableWords table)[3 + 4098 * i.val]? =
some (table.reverseIndex[i].val) := by
have h := row_word table i 1 (by decide)
rw [show 2 + 4098 * i.val + 1 = 3 + 4098 * i.val by omega] at h
simpa only [GraphTables.rowWords, PortTables.flatRows, Fin.getElem_fin,
Vector.getElem_ofFn, Fin.eta, List.cons_append, List.nil_append,
List.getElem?_cons_succ, List.getElem?_cons_zero] using h
theorem relation_word (table : PortTables.Table n d) (i : Fin (n * d))
(j : Fin 4096) :
(PortTables.tableWords table)[4 + 4098 * i.val + j.val]? =
some (GraphTables.bitWord table.relations[i][j]) := by
have h := row_word table i (j.val + 2) (by omega)
rw [show 2 + 4098 * i.val + (j.val + 2) = 4 + 4098 * i.val + j.val by omega] at h
simpa only [GraphTables.rowWords, GraphTables.relationWords,
PortTables.flatRows, Fin.getElem_fin, Vector.getElem_ofFn, Fin.eta,
List.cons_append, List.nil_append, List.getElem?_cons_succ,
List.getElem?_map, Vector.getElem?_toList,
Vector.getElem?_eq_getElem j.isLt, Option.map_some] using h
theorem accepts_word (table : PortTables.Table n d) (e : Fin n × Fin d)
(a b : PortTables.Label) :
(PortTables.tableWords table)[4 + 4098 * (PortTables.rowIndex n d e).val +
(GraphTables.relationIndex (a, b)).val]? =
some (GraphTables.bitWord (PortTables.accepts table e a b)) :=
relation_word table (PortTables.rowIndex n d e) (GraphTables.relationIndex (a, b))
theorem rotation_head_word (table : PortTables.Table n d) (e : Fin n × Fin d) :
(PortTables.tableWords table)[2 + 4098 * (table.reverseIndex[PortTables.rowIndex n d e]).val]? =
some ((PortTables.rotation table e).1.val) :=
tail_word table (table.reverseIndex[PortTables.rowIndex n d e])
theorem rotor_lookups (table : PortTables.Table n d) (e : Fin n × Fin d) :
(PortTables.tableWords table)[3 + 4098 * (PortTables.rowIndex n d e).val]? =
some (table.reverseIndex[PortTables.rowIndex n d e].val) ∧
(PortTables.tableWords table)[2 + 4098 * (table.reverseIndex[PortTables.rowIndex n d e]).val]? =
some ((PortTables.rotation table e).1.val) :=
⟨reverse_word table (PortTables.rowIndex n d e), rotation_head_word table e⟩
end MinUncutGames.Foundations.PCP.PortTableLookup
end
end OAI