Download lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringRowData.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 16.7 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringRowData.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringRowData.lean
-
curl -L -o PoweringRowData.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Expansion/PoweringRowData.lean
16.7 kB
| 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 | |