Buckets:
| import OAI.Computability.UniqueGames.Machines.FinalCNFStream | |
| import OAI.Computability.UniqueGames.Machines.MachineControlLemmas | |
| import OAI.Computability.UniqueGames.Machines.MachineDrain | |
| import OAI.Computability.UniqueGames.Machines.MachineFixedDivMod | |
| import OAI.Computability.UniqueGames.Machines.MachineProductGatherBoundsLemmas | |
| import OAI.Computability.UniqueGames.PCP.Emitter | |
| import OAI.Computability.UniqueGames.PCP.ExpanderRowControlLemmas | |
| namespace OAI | |
| namespace UniqueGamesTheorem.Foundations.Complexity.FinalCNFMachine.Program | |
| section | |
| open Turing PCP PCP.AlphabetTable | |
| structure LoopInvariant (table : GraphTables.Table) (r : Nat) (base : Tape → List Bool) : Prop where | |
| input : base .input = inputStream table (remainingEvents table r) | |
| archive : base .archive = GraphTables.tableBits table | |
| vertices : base .vertices = encodeWord table.vertices | |
| darts : base .darts = encodeWord table.darts | |
| index : base .rowIndex = encodeWord r | |
| tail : base .tail = [] | |
| head : base .head = [] | |
| reverse : base .reverseIndex = [] | |
| scratch : base .scratch = [] | |
| structure LoopRun (headerPlan plan : Plan) (table : GraphTables.Table) (r remaining : Nat) | |
| (base : Tape → List Bool) (ambient : Ambient) where | |
| finalAmbient : Ambient | |
| finalTapes : Tape → List Bool | |
| execution : StateTransition.EvalsToInTime (TM2.step (program headerPlan plan)) | |
| ⟨some .guard, ((ambient, ()), none), base⟩ | |
| (some ⟨some .reverseOutput, ((finalAmbient, ()), none), finalTapes⟩) | |
| (remaining * (rowTime plan (GraphTables.tableBits table).length + 1) + 1) | |
| accumulator : finalTapes .accumulator = | |
| (outputStream plan table (remainingEvents table r)).reverse ++ base .accumulator | |
| output : finalTapes .output = base .output | |
| theorem rowInvariant_succ (plan : Plan) (table : GraphTables.Table) (r : Nat) | |
| (hr : r < table.darts) (base : Tape → List Bool) (invariant : LoopInvariant table r base) : | |
| LoopInvariant table (r + 1) | |
| (rowResultTapes plan base table ⟨r, hr⟩ | |
| (inputStream table (remainingEvents table (r + 1)))) := by | |
| constructor | |
| · exact rowResult_input _ _ _ _ _ | |
| · exact (rowResult_frame _ _ _ _ _ .archive (by decide) (by decide) (by decide) | |
| (by decide) (by decide) (by decide) (by decide) (by decide)).trans invariant.archive | |
| · exact (rowResult_frame _ _ _ _ _ .vertices (by decide) (by decide) (by decide) | |
| (by decide) (by decide) (by decide) (by decide) (by decide)).trans invariant.vertices | |
| · exact (rowResult_frame _ _ _ _ _ .darts (by decide) (by decide) (by decide) | |
| (by decide) (by decide) (by decide) (by decide) (by decide)).trans invariant.darts | |
| · exact rowResult_index _ _ _ _ _ | |
| · exact rowResult_tail _ _ _ _ _ | |
| · exact rowResult_head _ _ _ _ _ | |
| · exact rowResult_reverse _ _ _ _ _ | |
| · exact (rowResult_frame _ _ _ _ _ .scratch (by decide) (by decide) (by decide) | |
| (by decide) (by decide) (by decide) (by decide) (by decide)).trans invariant.scratch | |
| theorem rowWords_nonempty (table : GraphTables.Table) (e : Fin table.darts) : | |
| encodeWords (GraphTables.rowWords table.rows[e]) ≠ [] := by | |
| simp [GraphTables.rowWords, encodeWords, encodeWord] | |
| /-- Induction follows the actual unary row counter and the actual unconsumed | |
| input suffix. Every iteration invokes the checked row program. -/ | |
| noncomputable def loopInTime (headerPlan plan : Plan) (table : GraphTables.Table) | |
| (remaining : Nat) : | |
| ∀ (r : Nat), r + remaining = table.darts → ∀ (base : Tape → List Bool) | |
| (ambient : Ambient), LoopInvariant table r base → | |
| LoopRun headerPlan plan table r remaining base ambient := by | |
| induction remaining with | |
| | zero => | |
| intro r hcount base ambient invariant | |
| have hr : r = table.darts := by omega | |
| have hinput : base .input = [] := by | |
| simpa only [hr, remainingEvents_done, inputStream_nil] using invariant.input | |
| refine { | |
| finalAmbient := ambient | |
| finalTapes := base | |
| execution := ?_ | |
| accumulator := ?_ | |
| output := rfl } | |
| · simpa only [Nat.zero_mul, Nat.zero_add] using | |
| guardEndInTime headerPlan plan base ambient hinput | |
| · simp only [hr, remainingEvents_done, outputStream_nil, List.reverse_nil, List.nil_append] | |
| | succ remaining ih => | |
| intro r hcount base ambient invariant | |
| have hr : r < table.darts := by omega | |
| let e : Fin table.darts := ⟨r, hr⟩ | |
| let rest := inputStream table (remainingEvents table (r + 1)) | |
| let next := rowResultTapes plan base table e rest | |
| have hinput : base .input = encodeWords (GraphTables.rowWords table.rows[e]) ++ rest := by | |
| rw [invariant.input, inputStream_remaining_cons table r hr] | |
| have hnonempty : base .input ≠ [] := by | |
| rw [hinput] | |
| exact List.append_ne_nil_of_left_ne_nil (rowWords_nonempty table e) rest | |
| let guardRun := guardRowInTime headerPlan plan base ambient hnonempty | |
| let rowRun := rowInTime headerPlan plan base table e rest hinput invariant.archive | |
| invariant.vertices invariant.darts invariant.index invariant.tail invariant.head | |
| invariant.reverse invariant.scratch ambient | |
| let first := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ guardRun rowRun | |
| let later := ih (r + 1) (by omega) next (rowRelation table e) | |
| (rowInvariant_succ plan table r hr base invariant) | |
| let run := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ first later.execution | |
| refine { | |
| finalAmbient := later.finalAmbient | |
| finalTapes := later.finalTapes | |
| execution := { toEvalsTo := run.toEvalsTo, steps_le_m := ?_ } | |
| accumulator := ?_ | |
| output := ?_ } | |
| · have hb := run.steps_le_m | |
| rw [Nat.succ_mul] | |
| omega | |
| · rw [later.accumulator, outputStream_remaining_cons plan table r hr] | |
| simp only [next, rowResult_accumulator, List.reverse_append, List.append_assoc] | |
| rfl | |
| · rw [later.output] | |
| exact rowResult_frame _ _ _ _ _ .output (by decide) (by decide) (by decide) | |
| (by decide) (by decide) (by decide) (by decide) (by decide) | |
| end | |
| /-! | |
| The complete actual output-producing trace of the final CNF machine. Its | |
| terminal configuration still contains private work tapes; FinalCNFCleanup | |
| supplies the subsequent canonical halt required by the machine interface. | |
| -/ | |
| open Turing PCP PCP.AlphabetTable FinalCNFTableAdapter | |
| def emittedBytes (plan : Plan) (table : GraphTables.Table) : List Bool := | |
| encodeWords [6 * table.vertices + 36864 * table.darts, 40960 * table.darts] ++ | |
| outputStream plan table (List.finRange table.darts) | |
| noncomputable def rawBudget (plan : Plan) (table : GraphTables.Table) : Nat := | |
| headerTimePolynomial.eval (GraphTables.tableBits table).length + | |
| table.darts * (rowTime plan (GraphTables.tableBits table).length + 1) + 1 + | |
| (emittedBytes plan table).length + 1 | |
| structure RawRun (plan : Plan) (table : GraphTables.Table) where | |
| finalAmbient : Ambient | |
| finalTapes : Tape → List Bool | |
| execution : StateTransition.EvalsToInTime (machine headerPlan plan).step | |
| (initList (machine headerPlan plan) (GraphTables.tableBits table)) | |
| (some ⟨none, ((finalAmbient, ()), none), finalTapes⟩) (rawBudget plan table) | |
| output : finalTapes .output = emittedBytes plan table | |
| theorem header_loopInvariant (table : GraphTables.Table) : | |
| LoopInvariant table 0 (headerResultTapes table.vertices table.darts | |
| (tableRowsBits (genericTable table))) := by | |
| constructor | |
| · rw [headerResultTapes_input, inputStream_remaining_zero] | |
| · rw [headerResultTapes_archive] | |
| exact (tableBits_header_rows (genericTable table)).symm.trans (genericTable_tableBits table) | |
| · rfl | |
| · rfl | |
| · exact headerResultTapes_rowIndex _ _ _ | |
| · rfl | |
| · rfl | |
| · rfl | |
| · rfl | |
| /-- The input is read from the genuine `initList` configuration. Header, every | |
| row, final guard, and reversal are all actual transitions of this one program. -/ | |
| noncomputable def rawRun (plan : Plan) (table : GraphTables.Table) : RawRun plan table := by | |
| let base := headerResultTapes table.vertices table.darts (tableRowsBits (genericTable table)) | |
| let ambient : Ambient := ((), fun _ => false) | |
| have headerRun : StateTransition.EvalsToInTime (machine headerPlan plan).step | |
| (initList (machine headerPlan plan) (GraphTables.tableBits table)) | |
| (some ⟨some .guard, ((ambient, ()), none), base⟩) | |
| (headerTimePolynomial.eval (GraphTables.tableBits table).length) := by | |
| simpa only [genericTable_tableBits, genericTable_vertices, genericTable_darts, base, ambient] | |
| using initializedTableHeaderInTime plan (genericTable table) | |
| let loop := loopInTime headerPlan plan table table.darts 0 (by omega) | |
| base ambient (header_loopInvariant table) | |
| have acc : loop.finalTapes .accumulator = (emittedBytes plan table).reverse := by | |
| rw [loop.accumulator] | |
| simp only [remainingEvents_zero, base, headerResultTapes_accumulator, emittedBytes, | |
| List.reverse_append] | |
| have out : loop.finalTapes .output = [] := by | |
| rw [loop.output] | |
| rfl | |
| let finalTapes := Reduction.MachineTransfer.tapesAt Tape.accumulator Tape.output | |
| loop.finalTapes [] (emittedBytes plan table) | |
| have finish : StateTransition.EvalsToInTime (machine headerPlan plan).step | |
| ⟨some .reverseOutput, ((loop.finalAmbient, ()), none), loop.finalTapes⟩ | |
| (some ⟨none, ((loop.finalAmbient, ()), none), finalTapes⟩) | |
| ((emittedBytes plan table).length + 1) := by | |
| have run := Reduction.MachineTransfer.transferAtInTime Tape.accumulator Tape.output | |
| (by decide) id false .reverseOutput none (program headerPlan plan) rfl | |
| loop.finalTapes (loop.finalAmbient, ()) none | |
| simpa only [acc, out, List.reverse_reverse, List.length_reverse, List.map_id, | |
| List.append_nil, finalTapes, machine, FinTM2.step] using! run | |
| let first := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ headerRun loop.execution | |
| let run := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ first finish | |
| exact { | |
| finalAmbient := loop.finalAmbient | |
| finalTapes := finalTapes | |
| execution := { | |
| toEvalsTo := run.toEvalsTo | |
| steps_le_m := by | |
| have hb := run.steps_le_m | |
| unfold rawBudget | |
| omega } | |
| output := by simp [finalTapes, Reduction.MachineTransfer.tapesAt] } | |
| end UniqueGamesTheorem.Foundations.Complexity.FinalCNFMachine.Program | |
| namespace UniqueGamesTheorem.Foundations.Complexity.MachineExpanderRow | |
| open Turing | |
| open PCP.ExpanderTables PCP.ExpanderRowControl | |
| inductive Tape | |
| | inputVertex | table | output | |
| | emitScratch | queryReverse | queryIndex | |
| | lookupOutput | lookupWork | lookupRestore | |
| | quotientFirst | quotientSecond | remainderFirst | remainderSecond | |
| deriving DecidableEq | |
| protected abbrev Tape.enumList : List Tape := [.inputVertex, .table, .output, .emitScratch, | |
| .queryReverse, .queryIndex, .lookupOutput, .lookupWork, .lookupRestore, .quotientFirst, | |
| .quotientSecond, .remainderFirst, .remainderSecond] | |
| protected theorem Tape.enumList_getElem?_ctorIdx_eq (x : Tape) : | |
| Tape.enumList[x.ctorIdx]? = some x := by | |
| cases x <;> rfl | |
| protected theorem Tape.enumList_nodup : Tape.enumList.Nodup := by decide | |
| instance : Fintype Tape where | |
| elems := ⟨Tape.enumList, Tape.enumList_nodup⟩ | |
| complete x := by cases x <;> decide | |
| inductive Label (d : Nat) | |
| | initialize | |
| | firstEmit (label : PCP.AlphabetTable.Emitter.Label 3 (degree d)) | |
| | firstReverse | |
| | firstLookup (label : MachinePreservingLookupClean.Label) | |
| | firstScan | |
| | firstResidue (r : Fin (degree d)) | |
| | clearQuery | |
| | secondEmit (label : PCP.AlphabetTable.Emitter.Label 3 (degree d)) | |
| | secondReverse | |
| | secondLookup (label : MachinePreservingLookupClean.Label) | |
| | secondScan | |
| | secondResidue (r : Fin (degree d)) | |
| | outputEmit (label : PCP.AlphabetTable.Emitter.Label 3 (rowFactor d)) | |
| | cleanup (i : Fin 6) | |
| | done | |
| deriving DecidableEq, Fintype | |
| abbrev Ambient (ρ : Type) (d : Nat) := ρ × Control d | |
| abbrev State (ρ : Type) (d : Nat) := | |
| PCP.AlphabetTable.Emitter.State (Ambient ρ d × Fin (degree d)) | |
| /-- The residue and the emitter's unit field are just permuted; no tape is | |
| read or written by this static change of finite state coordinates. -/ | |
| def divisionStates (ρ : Type) (d : Nat) : | |
| MachineFixedDivMod.State (Ambient ρ d × Unit) (degree d) ≃ State ρ d where | |
| toFun s := (((s.1.1.1, s.1.2), ()), s.2) | |
| invFun s := (((s.1.1.1, ()), s.1.1.2), s.2) | |
| left_inv := by rintro ⟨⟨⟨a, u⟩, r⟩, b⟩; cases u; rfl | |
| right_inv := by rintro ⟨⟨⟨a, r⟩, u⟩, b⟩; cases u; rfl | |
| def firstFinish {ρ : Type} {d : Nat} (s : Ambient ρ d × Unit) | |
| (r : Fin (degree d)) : Ambient ρ d × Unit := | |
| ((s.1.1, receiveFirst s.1.2 r), ()) | |
| def secondFinish {ρ : Type} {d : Nat} (H : Table (cloudSize d) d) | |
| (s : Ambient ρ d × Unit) (r : Fin (degree d)) : Ambient ρ d × Unit := | |
| ((s.1.1, receiveSecond H s.1.2 r), ()) | |
| def affinePlan {σ : Type} {bound : Nat} (coefficient : Nat) (offset : σ → Fin bound) : | |
| Fin 3 → PCP.AlphabetTable.Emitter.Command 1 σ bound := | |
| PCP.AlphabetTable.Emitter.listCommands | |
| (PCP.AlphabetTable.Emitter.affineCommands [(0, coefficient)] offset) | |
| def firstPlan (ρ : Type) (d : Nat) : | |
| Fin 3 → PCP.AlphabetTable.Emitter.Command 1 (Ambient ρ d × Fin (degree d)) (degree d) := | |
| affinePlan (degree d) (fun s => firstOffset s.1.2) | |
| def secondPlan (ρ : Type) (d : Nat) : | |
| Fin 3 → PCP.AlphabetTable.Emitter.Command 1 (Ambient ρ d × Fin (degree d)) (degree d) := | |
| affinePlan (degree d) (fun s => secondOffset s.1.2) | |
| def outputPlan (ρ : Type) (d : Nat) : | |
| Fin 3 → PCP.AlphabetTable.Emitter.Command 1 (Ambient ρ d × Fin (degree d)) (rowFactor d) := | |
| affinePlan (rowFactor d) (fun s => outputOffset s.1.2) | |
| def lookupTape : Fin 5 → Tape | |
| | ⟨0, _⟩ => .table | |
| | ⟨1, _⟩ => .queryIndex | |
| | ⟨2, _⟩ => .lookupWork | |
| | ⟨3, _⟩ => .lookupOutput | |
| | _ => .lookupRestore | |
| def dirtyTape : Fin 6 → Tape | |
| | ⟨0, _⟩ => .queryIndex | |
| | ⟨1, _⟩ => .lookupOutput | |
| | ⟨2, _⟩ => .quotientFirst | |
| | ⟨3, _⟩ => .quotientSecond | |
| | ⟨4, _⟩ => .remainderFirst | |
| | _ => .remainderSecond | |
| variable {K Λ ρ : Type} [DecidableEq K] [Fintype ρ] | |
| /-- Every branch is a concrete finite TM2 statement. The fixed table `H` | |
| is evaluated only on finite control values, never on an unbounded tape value. -/ | |
| def statement {d : Nat} (positive : 0 < d) (H : Table (cloudSize d) d) | |
| (ports : Tape → K) (labels : Label d → Λ) (exit : Option Λ) : | |
| Label d → TM2.Stmt (fun _ : K => Bool) Λ (State ρ d) | |
| | .initialize => | |
| .push (ports .quotientFirst) (fun _ => false) | |
| (.push (ports .quotientSecond) (fun _ => false) | |
| (.push (ports .remainderFirst) (fun _ => false) | |
| (.push (ports .remainderSecond) (fun _ => false) | |
| (.load (fun s => (s.1, none)) | |
| (.goto fun _ => labels (.firstEmit (PCP.AlphabetTable.Emitter.labelAt 3 _ 0 .entry))))))) | |
| | .firstEmit l => | |
| PCP.AlphabetTable.Emitter.statement (firstPlan ρ d) (fun _ => ports .inputVertex) | |
| (ports .emitScratch) (ports .queryReverse) (fun k => labels (.firstEmit k)) | |
| (some (labels .firstReverse)) l | |
| | .firstReverse => | |
| Reduction.MachineTransfer.loopAt (ports .queryReverse) (ports .queryIndex) | |
| id false (labels .firstReverse) | |
| (some (labels (.firstLookup (.run .copyFirst)))) | |
| | .firstLookup l => | |
| MachinePreservingLookupClean.statement (ports ∘ lookupTape) | |
| (fun k => labels (.firstLookup k)) (some (labels .firstScan)) l | |
| | .firstScan => | |
| MachineControl.statement id (divisionStates ρ d) | |
| (MachineFixedDivMod.scanLoop (degree d) (Nat.mul_pos positive positive) | |
| (ports .lookupOutput) (ports .quotientFirst) (labels .firstScan) | |
| (fun r => labels (.firstResidue r))) | |
| | .firstResidue r => | |
| MachineControl.statement id (divisionStates ρ d) | |
| (MachineFixedDivMod.emitterWithFinish (degree d) (Nat.mul_pos positive positive) | |
| (ports .remainderFirst) (some (labels .clearQuery)) firstFinish r) | |
| | .clearQuery => | |
| .pop (ports .queryIndex) (fun s _ => s) | |
| (.pop (ports .lookupOutput) (fun s _ => s) | |
| (.goto fun _ => labels (.secondEmit (PCP.AlphabetTable.Emitter.labelAt 3 _ 0 .entry)))) | |
| | .secondEmit l => | |
| PCP.AlphabetTable.Emitter.statement (secondPlan ρ d) (fun _ => ports .quotientFirst) | |
| (ports .emitScratch) (ports .queryReverse) (fun k => labels (.secondEmit k)) | |
| (some (labels .secondReverse)) l | |
| | .secondReverse => | |
| Reduction.MachineTransfer.loopAt (ports .queryReverse) (ports .queryIndex) | |
| id false (labels .secondReverse) | |
| (some (labels (.secondLookup (.run .copyFirst)))) | |
| | .secondLookup l => | |
| MachinePreservingLookupClean.statement (ports ∘ lookupTape) | |
| (fun k => labels (.secondLookup k)) (some (labels .secondScan)) l | |
| | .secondScan => | |
| MachineControl.statement id (divisionStates ρ d) | |
| (MachineFixedDivMod.scanLoop (degree d) (Nat.mul_pos positive positive) | |
| (ports .lookupOutput) (ports .quotientSecond) (labels .secondScan) | |
| (fun r => labels (.secondResidue r))) | |
| | .secondResidue r => | |
| MachineControl.statement id (divisionStates ρ d) | |
| (MachineFixedDivMod.emitterWithFinish (degree d) (Nat.mul_pos positive positive) | |
| (ports .remainderSecond) | |
| (some (labels (.outputEmit (PCP.AlphabetTable.Emitter.labelAt 3 _ 0 .entry)))) | |
| (secondFinish H) r) | |
| | .outputEmit l => | |
| PCP.AlphabetTable.Emitter.statement (outputPlan ρ d) (fun _ => ports .quotientSecond) | |
| (ports .emitScratch) (ports .output) (fun k => labels (.outputEmit k)) | |
| (some (labels (.cleanup 0))) l | |
| | .cleanup i => | |
| MachineDrain.drain (ports (dirtyTape i)) (labels (.cleanup i)) | |
| (some (if hi : i.val + 1 < 6 then labels (.cleanup ⟨i.val + 1, hi⟩) else labels .done)) | |
| | .done => Reduction.MachineTransfer.exitAt (ports .output) exit | |
| def program {d : Nat} (positive : 0 < d) (H : Table (cloudSize d) d) : | |
| Label d → TM2.Stmt (fun _ : Tape => Bool) (Label d) (State ρ d) := | |
| statement positive H id id none | |
| end UniqueGamesTheorem.Foundations.Complexity.MachineExpanderRow | |
| end OAI | |
Xet Storage Details
- Size:
- 18.1 kB
- Xet hash:
- c98f26233f482481f32a81e95871e37ab3c42162ddf0a17a41061bcc1a41d2fd
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.