Buckets:
| import OAI.Computability.UniqueGames.Machines.MachineExpanderRowCleanup | |
| import OAI.Computability.UniqueGames.Machines.MachineExpanderRowDivision | |
| import OAI.Computability.UniqueGames.Machines.MachineExpanderRowEmitLemmas | |
| namespace OAI | |
| section | |
| /-! | |
| # Concrete data and tape frames for an actual expander-row computation | |
| Only the five actual row inputs are stored. Every address, table return and | |
| finite control value below is computed from those inputs. The thirteen tape | |
| frames use the existing phase-output functions. These are data identities and | |
| size bounds, not assumed machine executions. Kernel-checked with Lean 4.33.1. | |
| -/ | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachineExpanderRow | |
| open PCP.ExpanderTables PCP.ExpanderRowControl PCP.ExpanderTableWords | |
| structure RowData (v d : Nat) where | |
| oldTable : Table v (degree d) | |
| smallTable : Table (cloudSize d) d | |
| inputVertex : Fin v | |
| inputCloud : Fin (cloudSize d) | |
| inputPort : Fin (degree d) | |
| def rowData {v d : Nat} (G : Table v (degree d)) (H : Table (cloudSize d) d) | |
| (vertex : Fin v) (cloud : Fin (cloudSize d)) (port : Fin (degree d)) : RowData v d := | |
| ⟨G, H, vertex, cloud, port⟩ | |
| namespace RowData | |
| variable {v d : Nat} (r : RowData v d) | |
| def control0 : Control d := start r.smallTable r.inputCloud r.inputPort | |
| def firstRow : Fin (v * degree d) := rowIndex v (degree d) (r.inputVertex, firstOffset r.control0) | |
| def firstValue : Nat := (reverseIndex r.oldTable r.firstRow).val | |
| def firstPair : Fin v × Fin (degree d) := lookup r.oldTable (r.inputVertex, firstOffset r.control0) | |
| def firstVertex : Fin v := r.firstPair.1 | |
| def firstReturn : Fin (degree d) := r.firstPair.2 | |
| def control1 : Control d := receiveFirst r.control0 r.firstReturn | |
| def secondRow : Fin (v * degree d) := rowIndex v (degree d) (r.firstVertex, secondOffset r.control1) | |
| def secondValue : Nat := (reverseIndex r.oldTable r.secondRow).val | |
| def secondPair : Fin v × Fin (degree d) := lookup r.oldTable (r.firstVertex, secondOffset r.control1) | |
| def secondVertex : Fin v := r.secondPair.1 | |
| def secondReturn : Fin (degree d) := r.secondPair.2 | |
| def control2 : Control d := receiveSecond r.smallTable r.control1 r.secondReturn | |
| def query1 : Nat := firstAddress r.inputVertex.val r.control0 | |
| def query2 : Nat := secondAddress r.firstVertex.val r.control1 | |
| def finalValue : Nat := outputAddress r.secondVertex.val r.control2 | |
| def tableLength : Nat := (encodeWords (rotationWords r.oldTable)).length | |
| theorem query1_eq_firstRow : r.query1 = r.firstRow.val := | |
| firstAddress_eq_rowIndex r.inputVertex r.control0 | |
| theorem query2_eq_secondRow : r.query2 = r.secondRow.val := | |
| secondAddress_eq_rowIndex r.firstVertex r.control1 | |
| @[simp] theorem firstValue_div_degree : r.firstValue / degree d = r.firstVertex.val := rfl | |
| @[simp] theorem firstValue_mod_degree : r.firstValue % degree d = r.firstReturn.val := rfl | |
| @[simp] theorem secondValue_div_degree : r.secondValue / degree d = r.secondVertex.val := rfl | |
| @[simp] theorem secondValue_mod_degree : r.secondValue % degree d = r.secondReturn.val := rfl | |
| theorem firstReturn_eq_residue (positive : 0 < d) : | |
| r.firstReturn = MachineFixedDivMod.residue (degree d) (Nat.mul_pos positive positive) | |
| r.firstValue := Fin.ext rfl | |
| theorem secondReturn_eq_residue (positive : 0 < d) : | |
| r.secondReturn = MachineFixedDivMod.residue (degree d) (Nat.mul_pos positive positive) | |
| r.secondValue := Fin.ext rfl | |
| theorem receiveFirst_residue_eq_control1 (positive : 0 < d) : | |
| receiveFirst r.control0 (MachineFixedDivMod.residue (degree d) | |
| (Nat.mul_pos positive positive) r.firstValue) = r.control1 := by | |
| rw [← r.firstReturn_eq_residue positive] | |
| rfl | |
| theorem receiveSecond_residue_eq_control2 (positive : 0 < d) : | |
| receiveSecond r.smallTable r.control1 (MachineFixedDivMod.residue (degree d) | |
| (Nat.mul_pos positive positive) r.secondValue) = r.control2 := by | |
| rw [← r.secondReturn_eq_residue positive] | |
| rfl | |
| theorem firstSelected : (rotationWords r.oldTable)[r.query1]? = some r.firstValue := by | |
| rw [query1_eq_firstRow] | |
| exact rotationWords_getElem? r.oldTable r.firstRow | |
| theorem secondSelected : (rotationWords r.oldTable)[r.query2]? = some r.secondValue := by | |
| rw [query2_eq_secondRow] | |
| exact rotationWords_getElem? r.oldTable r.secondRow | |
| theorem evaluateRow_eq : evaluateRow r.oldTable r.smallTable r.inputVertex r.inputCloud r.inputPort = | |
| (r.secondVertex, r.control2) := rfl | |
| theorem finalValue_eq_step_reverseIndex : | |
| r.finalValue = (reverseIndex (step r.oldTable r.smallTable) | |
| (rowIndex (v * cloudSize d) (degree d) | |
| (rowIndex v (cloudSize d) (r.inputVertex, r.inputCloud), r.inputPort))).val := by | |
| simpa only [evaluateRow_eq, finalValue] using outputAddress_eq_step_reverseIndex | |
| r.oldTable r.smallTable r.inputVertex r.inputCloud r.inputPort | |
| theorem rows_le_tableLength : v * degree d ≤ r.tableLength := by | |
| simp only [tableLength, encodeWords_length, rotationWords_length] | |
| omega | |
| theorem query1_le_tableLength : r.query1 ≤ r.tableLength := by | |
| rw [query1_eq_firstRow] | |
| exact r.firstRow.isLt.le.trans r.rows_le_tableLength | |
| theorem query2_le_tableLength : r.query2 ≤ r.tableLength := by | |
| rw [query2_eq_secondRow] | |
| exact r.secondRow.isLt.le.trans r.rows_le_tableLength | |
| theorem firstValue_le_tableLength : r.firstValue ≤ r.tableLength := | |
| (reverseIndex r.oldTable r.firstRow).isLt.le.trans r.rows_le_tableLength | |
| theorem secondValue_le_tableLength : r.secondValue ≤ r.tableLength := | |
| (reverseIndex r.oldTable r.secondRow).isLt.le.trans r.rows_le_tableLength | |
| theorem inputVertex_le_tableLength : r.inputVertex.val ≤ r.tableLength := by | |
| have hq : 1 ≤ degree d := Nat.zero_lt_of_lt r.inputPort.isLt | |
| have hv : v ≤ v * degree d := by simpa using Nat.mul_le_mul_left v hq | |
| exact r.inputVertex.isLt.le.trans (hv.trans r.rows_le_tableLength) | |
| theorem firstVertex_le_tableLength : r.firstVertex.val ≤ r.tableLength := by | |
| rw [← firstValue_div_degree] | |
| exact (Nat.div_le_self r.firstValue (degree d)).trans r.firstValue_le_tableLength | |
| theorem secondVertex_le_tableLength : r.secondVertex.val ≤ r.tableLength := by | |
| rw [← secondValue_div_degree] | |
| exact (Nat.div_le_self r.secondValue (degree d)).trans r.secondValue_le_tableLength | |
| theorem firstReturn_le_tableLength : r.firstReturn.val ≤ r.tableLength := by | |
| rw [← firstValue_mod_degree] | |
| exact (Nat.mod_le r.firstValue (degree d)).trans r.firstValue_le_tableLength | |
| theorem secondReturn_le_tableLength : r.secondReturn.val ≤ r.tableLength := by | |
| rw [← secondValue_mod_degree] | |
| exact (Nat.mod_le r.secondValue (degree d)).trans r.secondValue_le_tableLength | |
| end RowData | |
| variable {v d : Nat} | |
| /-- Complete explicit tape contents; all three scratch roles omitted here are empty. -/ | |
| def frameContents (r : RowData v d) (output : List Bool) | |
| (qr qi lo q1 q2 r1 r2 : List Bool) : Tape → List Bool | |
| | .inputVertex => encodeWord r.inputVertex.val | |
| | .table => encodeWords (rotationWords r.oldTable) | |
| | .output => output | |
| | .queryReverse => qr | |
| | .queryIndex => qi | |
| | .lookupOutput => lo | |
| | .quotientFirst => q1 | |
| | .quotientSecond => q2 | |
| | .remainderFirst => r1 | |
| | .remainderSecond => r2 | |
| | _ => [] | |
| def frame0 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| frameContents r output [] [] [] [] [] [] [] | |
| def frame1 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| initializedTapes id (frame0 r output) | |
| def frame2 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| emittedWord .queryReverse (frame1 r output) r.query1 | |
| def frame3 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| Reduction.MachineTransfer.tapesAt .queryReverse .queryIndex (frame2 r output) [] | |
| (encodeWord r.query1) | |
| def frame4 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| lookupResultTapes id (frame3 r output) r.firstValue [] | |
| def frame5 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| divisionOutput d id .quotientFirst .remainderFirst (frame4 r output) r.firstValue [] [] [] | |
| def frame6 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| clearedQueryTapes id (frame5 r output) | |
| def frame7 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| emittedWord .queryReverse (frame6 r output) r.query2 | |
| def frame8 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| Reduction.MachineTransfer.tapesAt .queryReverse .queryIndex (frame7 r output) [] | |
| (encodeWord r.query2) | |
| def frame9 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| lookupResultTapes id (frame8 r output) r.secondValue [] | |
| def frame10 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| divisionOutput d id .quotientSecond .remainderSecond (frame9 r output) r.secondValue [] [] [] | |
| def frame11 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| emittedWord .output (frame10 r output) r.finalValue | |
| def frame12 (r : RowData v d) (output : List Bool) : Tape → List Bool := | |
| cleanupTapes id (frame11 r output) | |
| private theorem lookupResultTapes_id_eq (base : Tape → List Bool) | |
| (value : Nat) (suffix : List Bool) : | |
| lookupResultTapes id base value suffix = | |
| Function.update | |
| (Function.update (Function.update base .queryIndex (encodeWord 0 ++ suffix)) | |
| .lookupWork []) | |
| .lookupOutput (encodeWord value ++ base .lookupOutput) := rfl | |
| @[simp] theorem frame1_eq (r : RowData v d) (output : List Bool) : | |
| frame1 r output = frameContents r output [] [] [] | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame1, frame0, frameContents, initializedTapes, encodeWord] | |
| @[simp] theorem frame2_eq (r : RowData v d) (output : List Bool) : | |
| frame2 r output = frameContents r output (encodeWord r.query1).reverse [] [] | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame2, frameContents, emittedWord] | |
| @[simp] theorem frame3_eq (r : RowData v d) (output : List Bool) : | |
| frame3 r output = frameContents r output [] (encodeWord r.query1) [] | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame3, frameContents, Reduction.MachineTransfer.tapesAt] | |
| @[simp] theorem frame4_eq (r : RowData v d) (output : List Bool) : | |
| frame4 r output = frameContents r output [] (encodeWord 0) (encodeWord r.firstValue) | |
| (encodeWord 0) (encodeWord 0) (encodeWord 0) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame4, lookupResultTapes_id_eq, frameContents] | |
| @[simp] theorem frame5_eq (r : RowData v d) (output : List Bool) : | |
| frame5 r output = frameContents r output [] (encodeWord 0) (encodeWord 0) | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame5, divisionOutput, MachineFixedDivMod.unaryTapes, | |
| MachineFixedDivMod.tapes, MachineCopy.forkTapes, frameContents] | |
| @[simp] theorem frame6_eq (r : RowData v d) (output : List Bool) : | |
| frame6 r output = frameContents r output [] [] [] (encodeWord r.firstVertex.val) | |
| (encodeWord 0) (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame6, clearedQueryTapes, frameContents, encodeWord] | |
| @[simp] theorem frame7_eq (r : RowData v d) (output : List Bool) : | |
| frame7 r output = frameContents r output (encodeWord r.query2).reverse [] [] | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame7, emittedWord, frameContents] | |
| @[simp] theorem frame8_eq (r : RowData v d) (output : List Bool) : | |
| frame8 r output = frameContents r output [] (encodeWord r.query2) [] | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame8, Reduction.MachineTransfer.tapesAt, frameContents] | |
| @[simp] theorem frame9_eq (r : RowData v d) (output : List Bool) : | |
| frame9 r output = frameContents r output [] (encodeWord 0) (encodeWord r.secondValue) | |
| (encodeWord r.firstVertex.val) (encodeWord 0) | |
| (encodeWord r.firstReturn.val) (encodeWord 0) := by | |
| funext tape | |
| cases tape <;> simp [frame9, lookupResultTapes_id_eq, frameContents] | |
| @[simp] theorem frame10_eq (r : RowData v d) (output : List Bool) : | |
| frame10 r output = frameContents r output [] (encodeWord 0) (encodeWord 0) | |
| (encodeWord r.firstVertex.val) (encodeWord r.secondVertex.val) | |
| (encodeWord r.firstReturn.val) (encodeWord r.secondReturn.val) := by | |
| funext tape | |
| cases tape <;> simp [frame10, divisionOutput, MachineFixedDivMod.unaryTapes, | |
| MachineFixedDivMod.tapes, MachineCopy.forkTapes, frameContents] | |
| @[simp] theorem frame11_eq (r : RowData v d) (output : List Bool) : | |
| frame11 r output = frameContents r ((encodeWord r.finalValue).reverse ++ output) | |
| [] (encodeWord 0) (encodeWord 0) | |
| (encodeWord r.firstVertex.val) (encodeWord r.secondVertex.val) | |
| (encodeWord r.firstReturn.val) (encodeWord r.secondReturn.val) := by | |
| funext tape | |
| cases tape <;> simp [frame11, emittedWord, frameContents] | |
| @[simp] theorem frame12_eq (r : RowData v d) (output : List Bool) : | |
| frame12 r output = frameContents r ((encodeWord r.finalValue).reverse ++ output) | |
| [] [] [] [] [] [] [] := by | |
| funext tape | |
| cases tape <;> simp [frame12, cleanupTapes, frameContents] | |
| theorem final_frame_eq (r : RowData v d) (output : List Bool) : | |
| frame12 r output = emittedWord .output (frame0 r output) r.finalValue := by | |
| funext tape | |
| cases tape <;> simp [frame0, emittedWord, frameContents] | |
| /-! Direct input facts for the individual checked phase traces. -/ | |
| @[simp] theorem frame0_inputVertex (r : RowData v d) (output : List Bool) : | |
| frame0 r output .inputVertex = encodeWord r.inputVertex.val := rfl | |
| @[simp] theorem frame0_table (r : RowData v d) (output : List Bool) : | |
| frame0 r output .table = encodeWords (rotationWords r.oldTable) := rfl | |
| @[simp] theorem frame0_output (r : RowData v d) (output : List Bool) : | |
| frame0 r output .output = output := rfl | |
| @[simp] theorem frame1_inputVertex (r : RowData v d) (output : List Bool) : | |
| frame1 r output .inputVertex = encodeWord r.inputVertex.val := by simp [frameContents] | |
| @[simp] theorem frame1_emitScratch (r : RowData v d) (output : List Bool) : | |
| frame1 r output .emitScratch = [] := by simp [frameContents] | |
| @[simp] theorem frame2_queryReverse (r : RowData v d) (output : List Bool) : | |
| frame2 r output .queryReverse = (encodeWord r.query1).reverse := by simp [frameContents] | |
| @[simp] theorem frame2_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame2 r output .queryIndex = [] := by simp [frameContents] | |
| @[simp] theorem frame3_table (r : RowData v d) (output : List Bool) : | |
| frame3 r output .table = encodeWords (rotationWords r.oldTable) := by simp [frameContents] | |
| @[simp] theorem frame3_lookupRestore (r : RowData v d) (output : List Bool) : | |
| frame3 r output .lookupRestore = [] := by simp [frameContents] | |
| @[simp] theorem frame3_lookupWork (r : RowData v d) (output : List Bool) : | |
| frame3 r output .lookupWork = [] := by simp [frameContents] | |
| @[simp] theorem frame3_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame3 r output .lookupOutput = [] := by simp [frameContents] | |
| @[simp] theorem frame3_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame3 r output .queryIndex = encodeWord r.query1 := by simp [frameContents] | |
| @[simp] theorem frame4_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame4 r output .lookupOutput = encodeWord r.firstValue := by simp [frameContents] | |
| @[simp] theorem frame4_quotientFirst (r : RowData v d) (output : List Bool) : | |
| frame4 r output .quotientFirst = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame4_remainderFirst (r : RowData v d) (output : List Bool) : | |
| frame4 r output .remainderFirst = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame6_quotientFirst (r : RowData v d) (output : List Bool) : | |
| frame6 r output .quotientFirst = encodeWord r.firstVertex.val := by simp [frameContents] | |
| @[simp] theorem frame6_emitScratch (r : RowData v d) (output : List Bool) : | |
| frame6 r output .emitScratch = [] := by simp [frameContents] | |
| @[simp] theorem frame7_queryReverse (r : RowData v d) (output : List Bool) : | |
| frame7 r output .queryReverse = (encodeWord r.query2).reverse := by simp [frameContents] | |
| @[simp] theorem frame7_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame7 r output .queryIndex = [] := by simp [frameContents] | |
| @[simp] theorem frame8_table (r : RowData v d) (output : List Bool) : | |
| frame8 r output .table = encodeWords (rotationWords r.oldTable) := by simp [frameContents] | |
| @[simp] theorem frame8_lookupRestore (r : RowData v d) (output : List Bool) : | |
| frame8 r output .lookupRestore = [] := by simp [frameContents] | |
| @[simp] theorem frame8_lookupWork (r : RowData v d) (output : List Bool) : | |
| frame8 r output .lookupWork = [] := by simp [frameContents] | |
| @[simp] theorem frame8_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame8 r output .lookupOutput = [] := by simp [frameContents] | |
| @[simp] theorem frame8_queryIndex (r : RowData v d) (output : List Bool) : | |
| frame8 r output .queryIndex = encodeWord r.query2 := by simp [frameContents] | |
| @[simp] theorem frame9_lookupOutput (r : RowData v d) (output : List Bool) : | |
| frame9 r output .lookupOutput = encodeWord r.secondValue := by simp [frameContents] | |
| @[simp] theorem frame9_quotientSecond (r : RowData v d) (output : List Bool) : | |
| frame9 r output .quotientSecond = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame9_remainderSecond (r : RowData v d) (output : List Bool) : | |
| frame9 r output .remainderSecond = encodeWord 0 := by simp [frameContents] | |
| @[simp] theorem frame10_quotientSecond (r : RowData v d) (output : List Bool) : | |
| frame10 r output .quotientSecond = encodeWord r.secondVertex.val := by simp [frameContents] | |
| @[simp] theorem frame10_emitScratch (r : RowData v d) (output : List Bool) : | |
| frame10 r output .emitScratch = [] := by simp [frameContents] | |
| @[simp] theorem frame10_output (r : RowData v d) (output : List Bool) : | |
| frame10 r output .output = output := by simp [frameContents] | |
| theorem final_dirty_word_length_le (r : RowData v d) (output : List Bool) (i : Fin 6) : | |
| ((frame11 r output) (dirtyTape i)).length ≤ r.tableLength + 1 := by | |
| have h1 := r.firstVertex_le_tableLength | |
| have h2 := r.secondVertex_le_tableLength | |
| have h3 := r.firstReturn_le_tableLength | |
| have h4 := r.secondReturn_le_tableLength | |
| fin_cases i <;> simp only [frame11_eq, dirtyTape, frameContents, encodeWord_length] <;> omega | |
| theorem cleanupSteps_le_tableLength (r : RowData v d) (output : List Bool) : | |
| cleanupSteps id (frame11 r output) ≤ 6 * (r.tableLength + 1) + 6 := by | |
| have h1 := r.firstVertex_le_tableLength | |
| have h2 := r.secondVertex_le_tableLength | |
| have h3 := r.firstReturn_le_tableLength | |
| have h4 := r.secondReturn_le_tableLength | |
| simp only [cleanupSteps, frame11_eq, id_eq, frameContents, encodeWord_length] | |
| omega | |
| end UniqueGamesTheorem.Foundations.Complexity.MachineExpanderRow | |
| end | |
| end OAI | |
Xet Storage Details
- Size:
- 19.2 kB
- Xet hash:
- f109b519db9564dd310d41cb5c9c9305a00c16db6e5c229fe50bdd4b263032c9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.