Buckets:
| import Mathlib | |
| import OAI.Computability.MinUncut.Games.PoweringInitializeFrame | |
| import OAI.Computability.MinUncut.Machines.PoweringRuntimeBudget | |
| import OAI.Computability.MinUncut.Games.PoweringPolynomialBudget | |
| namespace OAI | |
| section | |
| namespace MinUncutGames.Foundations.Complexity.PoweringMachineRuntime | |
| open Turing MachineComposition PCP PoweringMachineGlobal | |
| variable {vertices d : Nat} | |
| def beforeFinish (graph : PortTables.Table vertices d) (n : Nat) : Tape n → List Bool := | |
| PoweringMachineOuterLoop.finalTapes graph n (placement n) (outputTape n) | |
| vertices (Nat.le_refl _) (PoweringInitializeFrame.preparedTapes graph n) | |
| def finishConfiguration (graph : PortTables.Table vertices d) (n : Nat) : (machine d n).Cfg := | |
| ⟨some (finishEntry d n), PoweringMasterState.clean (PoweringMachineRowBody.bufferSize d n), | |
| beforeFinish graph n⟩ | |
| def beforeFinishBudget (graph : PortTables.Table vertices d) (n : Nat) : Nat := | |
| (3 * vertices + 5) + (vertices * | |
| (PoweringMachineVertex.budget d n (PortTables.tableBits graph).length + 2) + 1) | |
| theorem beforeFinish_ready (graph : PortTables.Table vertices d) (n : Nat) : | |
| PoweringMachineOuterLoop.Ready graph n (placement n) (beforeFinish graph n) := | |
| PoweringMachineOuterLoop.finalTapes_ready graph n (placement n) | |
| (PoweringMachineInitialize.commonPlacement_injective _) | |
| (outputTape n) (fun i => Ne.symm (PoweringMachineInitialize.commonPlacement_ne_finalOutput _ i)) | |
| vertices (Nat.le_refl _) (PoweringInitializeFrame.preparedTapes graph n) | |
| (PoweringInitializeFrame.prepared_ready graph n) | |
| theorem beforeFinish_output (graph : PortTables.Table vertices d) (n : Nat) : | |
| beforeFinish graph n (outputTape n) = | |
| (List.finRange vertices).flatMap (PoweringTableLayout.vertexRowBits graph n) := by | |
| rw [beforeFinish, PoweringMachineOuterLoop.finalTapes_output graph n (placement n) | |
| (PoweringMachineInitialize.commonPlacement_injective _) (outputTape n) | |
| (fun i => Ne.symm (PoweringMachineInitialize.commonPlacement_ne_finalOutput _ i)) | |
| vertices (Nat.le_refl _) (PoweringInitializeFrame.preparedTapes graph n) | |
| (PoweringInitializeFrame.prepared_ready graph n), | |
| PoweringMachineOuterLoop.prefixRows_all, PoweringInitializeFrame.prepared_output, | |
| List.append_nil] | |
| theorem beforeFinish_vertices (graph : PortTables.Table vertices d) (n : Nat) : | |
| beforeFinish graph n (headerVertices n) = encodeWord vertices := by | |
| rw [beforeFinish, PoweringMachineOuterLoop.finalTapes_other graph n (placement n) | |
| (outputTape n) vertices (Nat.le_refl _) (PoweringInitializeFrame.preparedTapes graph n) | |
| (headerVertices n) (PoweringGlobalConfiguration.headerVertices_ne_output n) | |
| (fun i => Ne.symm (PoweringMachineInitialize.commonPlacement_ne_header _ i .vertices (by decide)))] | |
| exact PoweringInitializeFrame.prepared_vertices graph n | |
| theorem beforeFinish_darts (graph : PortTables.Table vertices d) (n : Nat) : | |
| beforeFinish graph n (headerDarts n) = | |
| encodeWord (PoweringTableLayout.blockSize d n * vertices) := by | |
| rw [beforeFinish, PoweringMachineOuterLoop.finalTapes_other graph n (placement n) | |
| (outputTape n) vertices (Nat.le_refl _) (PoweringInitializeFrame.preparedTapes graph n) | |
| (headerDarts n) (PoweringGlobalConfiguration.headerDarts_ne_output n) | |
| (fun i => Ne.symm (PoweringMachineInitialize.commonPlacement_ne_header _ i .darts (by decide)))] | |
| exact PoweringInitializeFrame.prepared_darts graph n | |
| theorem serialized_eq (graph : PortTables.Table vertices d) (n : Nat) : | |
| encodeWords [vertices, PoweringTableLayout.blockSize d n * vertices] ++ | |
| beforeFinish graph n (outputTape n) = PoweringTables.outputBits graph n := by | |
| rw [beforeFinish_output, PoweringTableLayout.outputBits_vertexRows] | |
| congr 2 | |
| rw [PoweringTableLayout.dartCount_eq_vertex_blocks, Nat.mul_comm] | |
| def beforeFinishExecution (graph : PortTables.Table vertices d) (n : Nat) : | |
| StateTransition.EvalsToInTime (machine d n).step | |
| (initList (machine d n) (PortTables.tableBits graph)) | |
| (some (finishConfiguration graph n)) (beforeFinishBudget graph n) := by | |
| have initialRun := PoweringInitializeFrame.initializeInTime graph n | |
| have loop := PoweringMachineOuterLoop.loopInTime graph n (placement n) | |
| (PoweringMachineInitialize.commonPlacement_injective _) (outputTape n) | |
| (fun i => Ne.symm (PoweringMachineInitialize.commonPlacement_ne_finalOutput _ i)) | |
| (guardLabel d n) (bridgeLabel d n) (finishEntry d n) (vertexLabels d n) | |
| (program d n) (atGuard d n) (atBridge d n) (atVertex d n) | |
| vertices (Nat.le_refl _) (PoweringInitializeFrame.preparedTapes graph n) | |
| (PoweringInitializeFrame.prepared_ready graph n) | |
| rw [PoweringInitializeFrame.prepared_counter] at loop | |
| simpa only [beforeFinishBudget, Nat.add_comm] using | |
| (StateTransition.EvalsToInTime.trans (machine d n).step | |
| (3 * vertices + 5) | |
| (vertices * (PoweringMachineVertex.budget d n (PortTables.tableBits graph).length + 2) + 1) | |
| (initList (machine d n) (PortTables.tableBits graph)) | |
| (PoweringInitializeFrame.preparedCfg graph n) (some (finishConfiguration graph n)) | |
| initialRun loop) | |
| def finishSteps (graph : PortTables.Table vertices d) (n : Nat) : Nat := | |
| PoweringMachineFinish.steps (enumeration n) (outputTape n) (beforeFinish graph n) | |
| vertices (PoweringTableLayout.blockSize d n * vertices) | |
| def finishExecution (graph : PortTables.Table vertices d) (n : Nat) : | |
| StateTransition.EvalsToInTime (machine d n).step (finishConfiguration graph n) | |
| (some (haltList (machine d n) (PoweringTables.outputBits graph n))) | |
| (finishSteps graph n) := by | |
| have run := PoweringMachineFinish.traceAt (enumeration n) | |
| (headerVertices n) (headerDarts n) (outputTape n) | |
| (placement n (PoweringMachineTapes.scratch (PoweringMachineRowBody.capacity n))) | |
| (PoweringGlobalConfiguration.headerVertices_ne_scratch n) | |
| (PoweringGlobalConfiguration.headerVertices_ne_output n) | |
| (PoweringGlobalConfiguration.headerDarts_ne_scratch n) | |
| (PoweringGlobalConfiguration.headerDarts_ne_output n) | |
| (PoweringMachineInitialize.commonPlacement_ne_finalOutput _ _) | |
| (finishLabels d n) (program d n) (atFinish d n) | |
| (beforeFinish graph n) vertices (PoweringTableLayout.blockSize d n * vertices) [] [] | |
| (by simpa only [List.append_nil] using beforeFinish_vertices graph n) | |
| (by simpa only [List.append_nil] using beforeFinish_darts graph n) | |
| (beforeFinish_ready graph n).scratch | |
| (PoweringMasterState.clean (PoweringMachineRowBody.bufferSize d n)).1 none | |
| rw [serialized_eq] at run | |
| refine { steps := finishSteps graph n, evals_in_steps := ?_, steps_le_m := Nat.le_refl _ } | |
| change (advance (TM2.step (program d n)))^[finishSteps graph n] | |
| (some (finishConfiguration graph n)) = _ | |
| rw [PoweringGlobalConfiguration.haltList_eq] | |
| simpa only [finishConfiguration, finishEntry, finishSteps, PoweringMasterState.clean, | |
| PoweringMasterState.withBuffer] using! run | |
| def execution (graph : PortTables.Table vertices d) (n : Nat) : | |
| TM2OutputsInTime (machine d n) (PortTables.tableBits graph) | |
| (some (PoweringTables.outputBits graph n)) | |
| (beforeFinishBudget graph n + finishSteps graph n) := by | |
| simpa only [TM2OutputsInTime, Option.map_some, Nat.add_comm] using! | |
| (StateTransition.EvalsToInTime.trans (machine d n).step | |
| (beforeFinishBudget graph n) (finishSteps graph n) | |
| (initList (machine d n) (PortTables.tableBits graph)) | |
| (finishConfiguration graph n) | |
| (some (haltList (machine d n) (PoweringTables.outputBits graph n))) | |
| (beforeFinishExecution graph n) (finishExecution graph n)) | |
| theorem finishSteps_le (graph : PortTables.Table vertices d) (n : Nat) : | |
| finishSteps graph n ≤ | |
| 2 * (vertices + PoweringTableLayout.blockSize d n * vertices) + 6 + | |
| PoweringRuntimeBudget.tapeCount n * | |
| ((PortTables.tableBits graph).length + beforeFinishBudget graph n * | |
| Runtime.programPushBound (machine d n) + vertices + | |
| PoweringTableLayout.blockSize d n * vertices + 3) := | |
| PoweringRuntimeBudget.finish_steps_le_of_execution d n (PortTables.tableBits graph) | |
| (finishConfiguration graph n) (beforeFinishBudget graph n) vertices | |
| (PoweringTableLayout.blockSize d n * vertices) (beforeFinishExecution graph n) | |
| theorem execution_budget_le (graph : PortTables.Table vertices d) (n : Nat) : | |
| beforeFinishBudget graph n + finishSteps graph n ≤ | |
| (PoweringPolynomialBudget.time d n (Runtime.programPushBound (machine d n)) | |
| (PoweringRuntimeBudget.tapeCount n)).eval (PortTables.tableBits graph).length := by | |
| exact PoweringPolynomialBudget.execution_budget_le_time d n | |
| (Runtime.programPushBound (machine d n)) (PoweringRuntimeBudget.tapeCount n) | |
| vertices (PortTables.tableBits graph).length (PortTables.vertices_le_tableBits_length graph) | |
| (Nat.le_refl _) (finishSteps_le graph n) | |
| noncomputable def computableInPolyTime (d n : Nat) : | |
| TM2ComputableInPolyTime (@PortTables.inputBits d) GenericGraphTables.tableBits | |
| (PoweringTables.transform d n) where | |
| tm := machine d n | |
| inputAlphabet := Equiv.refl Bool | |
| outputAlphabet := Equiv.refl Bool | |
| time := PoweringPolynomialBudget.time d n (Runtime.programPushBound (machine d n)) | |
| (PoweringRuntimeBudget.tapeCount n) | |
| outputsFun input := by | |
| rcases input with ⟨vertices, graph⟩ | |
| have run := execution graph n | |
| let bounded : TM2OutputsInTime (machine d n) (PortTables.tableBits graph) | |
| (some (PoweringTables.outputBits graph n)) | |
| ((PoweringPolynomialBudget.time d n (Runtime.programPushBound (machine d n)) | |
| (PoweringRuntimeBudget.tapeCount n)).eval (PortTables.tableBits graph).length) := | |
| ⟨run.toEvalsTo, run.steps_le_m.trans (execution_budget_le graph n)⟩ | |
| change TM2OutputsInTime (machine d n) ((PortTables.tableBits graph).map id) | |
| (some ((PoweringTables.outputBits graph n).map id)) _ | |
| have input_eq : @List.map ((machine d n).Γ (machine d n).k₀) | |
| ((machine d n).Γ (machine d n).k₀) id (PortTables.tableBits graph) = | |
| PortTables.tableBits graph := List.map_id _ | |
| have output_eq : @List.map ((machine d n).Γ (machine d n).k₁) | |
| ((machine d n).Γ (machine d n).k₁) id (PoweringTables.outputBits graph n) = | |
| PoweringTables.outputBits graph n := List.map_id _ | |
| simpa only [input_eq, output_eq, PortTables.inputBits] using bounded | |
| theorem computableInPolyTime_finite_alphabet (d n : Nat) : | |
| ∀ k, Finite ((computableInPolyTime d n).tm.Γ k) := by | |
| intro k | |
| change Finite Bool | |
| infer_instance | |
| end MinUncutGames.Foundations.Complexity.PoweringMachineRuntime | |
| end | |
| end OAI | |
Xet Storage Details
- Size:
- 10.6 kB
- Xet hash:
- 0ee86d8df5d285a921b7989dd5016905909ad190d0cdfbbfa19662fa60ce92bc
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.