import Mathlib import OAI.Computability.DirectedFeedback.Machines.Label namespace OAI section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section section namespace DFVSGames.Foundations.Complexity.MachineRegularExecutionBounds open Turing MachineComposition PCP PCP.PreprocessingRegularTables PCP.PreprocessingCloudIndex open PCP.PreprocessingMachineBounds MachineRegularInternalRow theorem coreTimeBound_mono (q L R x v i k o m O L' R' x' v' i' k' o' m' O' : Nat) (hL : L ≤ L') (hR : R ≤ R') (hx : x ≤ x') (hv : v ≤ v') (hi : i ≤ i') (hk : k ≤ k') (ho : o ≤ o') (hm : m ≤ m') (hO : O ≤ O') : coreTimeBound q L R x v i k o m O ≤ coreTimeBound q L' R' x' v' i' k' o' m' O' := by unfold coreTimeBound gcongr noncomputable def corePolynomial (q : Nat) : Polynomial Nat := Polynomial.C (5*q+32) * rotorPolynomial q + 10 * Polynomial.X + 2 * (Polynomial.C ExpanderFamily.growth * Polynomial.X) + 13 * Polynomial.X + 5 * Polynomial.X + Polynomial.C (5*q+10) * (Polynomial.X + Polynomial.C ExpanderFamily.growth * Polynomial.X) + 4 * (Polynomial.C ExpanderFamily.growth * Polynomial.X) + 2 * regularPolynomial + Polynomial.C (8*q+41066) theorem corePolynomial_eval (q L : Nat) : (corePolynomial q).eval L = coreTimeBound q L ((rotorPolynomial q).eval L) (ExpanderFamily.growth*L) L (ExpanderFamily.growth*L) L (ExpanderFamily.growth*L) L (regularPolynomial.eval L) := by simp only [corePolynomial, coreTimeBound, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] omega theorem internal_steps_le (q : Nat) (positive : 0 < q) (t : GraphTables.Table) (tables : ∀ v, ExpanderTables.Table (cloudSize t v + padding t v) q) (v : Fin t.vertices) (x : PaddedCloud t (padding t) v) (p : Fin q) (outputLength : Nat) (houtput : outputLength ≤ regularPolynomial.eval (inputLength t)) : coreSteps t (padding t) tables v x p outputLength ≤ (corePolynomial q).eval (inputLength t) := by have hx : (vertexOrder t (padding t) x.val).val ≤ ExpanderFamily.growth * inputLength t := (vertexOrder t (padding t) x.val).isLt.le.trans (regularVertices_le_input t) have hi : (paddedCloudRank t (padding t) v x).val ≤ ExpanderFamily.growth * inputLength t := (paddedCloudRank t (padding t) v x).isLt.le.trans (cloudTotal_le_input t v) have hv : v.val ≤ inputLength t := v.isLt.le.trans (GraphTables.vertices_le_tableBits_length t) have hm : t.darts ≤ inputLength t := GraphTables.darts_le_tableBits_length t rw [corePolynomial_eval] exact (coreSteps_le q positive t (padding t) tables v x p outputLength).trans (coreTimeBound_mono q _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ le_rfl (cloudRotorBits_le t v (tables v)) hx hv hi (cloudSize_le_input t v) (prefix_le_input t v.val) hm houtput) noncomputable def familyPolynomial : Polynomial Nat := MachinePaddedExpanderFamilyBounds.timePolynomial.comp (Polynomial.X + 1) + Polynomial.C (2 * ExpanderFamily.growth) * (Polynomial.X + 1) + 7 theorem family_budget_le (t : GraphTables.Table) (v : Fin t.vertices) : MachinePaddedExpanderFamilyBounds.timePolynomial.eval (cloudSize t v + 1) + 2 * ExpanderFamily.growth * (cloudSize t v + 1) + 7 ≤ familyPolynomial.eval (inputLength t) := by have h := Nat.add_le_add_right (cloudSize_le_input t v) 1 have hp := natPolynomial_eval_mono MachinePaddedExpanderFamilyBounds.timePolynomial h have hm := Nat.mul_le_mul_left (2 * ExpanderFamily.growth) h simp only [familyPolynomial, Polynomial.eval_add, Polynomial.eval_comp, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_one, Polynomial.eval_ofNat] omega noncomputable def rowPolynomial (q : Nat) : Polynomial Nat := Polynomial.C ExpanderFamily.growth * Polynomial.X + (Polynomial.C ExpanderFamily.growth * Polynomial.X) * Polynomial.C (q + 1) + 8192 theorem rowPolynomial_eval (q L : Nat) : (rowPolynomial q).eval L = ExpanderFamily.growth * L + (ExpanderFamily.growth * L) * (q + 1) + 8192 := by simp only [rowPolynomial, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] theorem actual_row_bound_le (q : Nat) (t : GraphTables.Table) : vertexCount t (padding t) + vertexCount t (padding t) * (q + 1) + 8192 ≤ (rowPolynomial q).eval (inputLength t) := by rw [rowPolynomial_eval] have h := regularVertices_le_input t exact Nat.add_le_add_right (Nat.add_le_add h (Nat.mul_le_mul_right _ h)) _ noncomputable def blockCorePolynomial (q : Nat) : Polynomial Nat := corePolynomial q + Polynomial.C (2*q) * rowPolynomial q theorem coreTimeBound_add_output (q L R x v i k o m O A : Nat) : coreTimeBound q L R x v i k o m (O + A) = coreTimeBound q L R x v i k o m O + 2*A := by unfold coreTimeBound omega theorem block_core_bound_le (q : Nat) (t : GraphTables.Table) (tables : ∀ v, ExpanderTables.Table (cloudSize t v + padding t v) q) (v : Fin t.vertices) (x : PaddedCloud t (padding t) v) (initialOutput : Nat) (houtput : initialOutput ≤ regularPolynomial.eval (inputLength t)) : coreTimeBound q (GraphTables.tableBits t).length (encodeWords (ExpanderTableWords.rotationWords (tables v))).length (vertexOrder t (padding t) x.val).val v.val (paddedCloudRank t (padding t) v x).val (cloudSize t v) (PreprocessingPaddingOffsets.offset (padding t) v.val) t.darts (initialOutput + q * (vertexCount t (padding t) + vertexCount t (padding t) * (q + 1) + 8192)) ≤ (blockCorePolynomial q).eval (inputLength t) := by have hx : (vertexOrder t (padding t) x.val).val ≤ ExpanderFamily.growth * inputLength t := (vertexOrder t (padding t) x.val).isLt.le.trans (regularVertices_le_input t) have hi : (paddedCloudRank t (padding t) v x).val ≤ ExpanderFamily.growth * inputLength t := (paddedCloudRank t (padding t) v x).isLt.le.trans (cloudTotal_le_input t v) have hv : v.val ≤ inputLength t := v.isLt.le.trans (GraphTables.vertices_le_tableBits_length t) have hm : t.darts ≤ inputLength t := GraphTables.darts_le_tableBits_length t have hr := Nat.mul_le_mul_left q (actual_row_bound_le q t) have hO := Nat.add_le_add houtput hr have h := coreTimeBound_mono q (inputLength t) _ _ _ _ _ _ _ _ (inputLength t) _ _ _ _ _ _ _ _ le_rfl (cloudRotorBits_le t v (tables v)) hx hv hi (cloudSize_le_input t v) (prefix_le_input t v.val) hm hO simp only [coreTimeBound_add_output] at h ⊢ rw [← corePolynomial_eval] at h simpa only [inputLength, blockCorePolynomial, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Nat.mul_assoc] using h end DFVSGames.Foundations.Complexity.MachineRegularExecutionBounds end section namespace DFVSGames.Foundations.Complexity.MachineRegularOriginalBodyBounds open Turing MachineComposition PCP PreprocessingCloudIndex PreprocessingRegularTables open PreprocessingMachineBounds MachineRegularOriginalBody noncomputable def wide : Polynomial Nat := Polynomial.C (ExpanderFamily.growth + 1) * Polynomial.X noncomputable def rowPolynomial (q : Nat) : Polynomial Nat := wide + wide * Polynomial.C (q + 1) + 8192 noncomputable def outputPolynomial (q : Nat) : Polynomial Nat := wide + Polynomial.C q * rowPolynomial q noncomputable def corePolynomial (q : Nat) : Polynomial Nat := Polynomial.C (5*q+32) * rotorPolynomial q + 10*wide + 2*wide + 13*wide + 5*wide + Polynomial.C (5*q+10)*(wide+wide) + 4*wide + 2*outputPolynomial q + Polynomial.C (8*q+41066) noncomputable def blockPolynomial (q : Nat) : Polynomial Nat := Polynomial.C q * corePolynomial q + Polynomial.C (5*q+20)*wide + 2*outputPolynomial q + Polynomial.C (5*q+40995) noncomputable def cleanupPolynomial (q : Nat) : Polynomial Nat := 6*wide + rotorPolynomial q + 13 noncomputable def timePolynomial : Polynomial Nat := MachineRegularMetadata.timePolynomial + MachineRegularExecutionBounds.familyPolynomial + blockPolynomial internalDegree + cleanupPolynomial internalDegree def bodySize (t : GraphTables.Table) (output : List Bool) : Nat := inputLength t + output.length theorem blockPolynomial_eval (q L : Nat) : (blockPolynomial q).eval L = MachineRegularVertexBlock.originalTimeBound q ((ExpanderFamily.growth+1)*L) ((rotorPolynomial q).eval L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) := by simp only [blockPolynomial, corePolynomial, outputPolynomial, rowPolynomial, wide, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat, MachineRegularVertexBlock.originalTimeBound, MachineRegularVertexBlock.portTimeBound, MachineRegularInternalRow.coreTimeBound, MachineRegularOriginalClean.timeBound, MachineRegularVertexBlock.rowSizeBound] ring theorem originalTimeBound_le (q L R x v i k o m O V W R' : Nat) (hL : L ≤ W) (hR : R ≤ R') (hx : x ≤ W) (hv : v ≤ W) (hi : i ≤ W) (hk : k ≤ W) (ho : o ≤ W) (hm : m ≤ W) (hO : O ≤ W) (hV : V ≤ W) : MachineRegularVertexBlock.originalTimeBound q L R x v i k o m O V ≤ MachineRegularVertexBlock.originalTimeBound q W R' W W W W W W W W := by unfold MachineRegularVertexBlock.originalTimeBound MachineRegularVertexBlock.portTimeBound MachineRegularInternalRow.coreTimeBound MachineRegularOriginalClean.timeBound MachineRegularVertexBlock.rowSizeBound gcongr theorem wide_le (t : GraphTables.Table) (output : List Bool) : inputLength t ≤ (ExpanderFamily.growth+1)*bodySize t output ∧ ExpanderFamily.growth*inputLength t ≤ (ExpanderFamily.growth+1)*bodySize t output ∧ output.length ≤ (ExpanderFamily.growth+1)*bodySize t output := by have hN : inputLength t ≤ bodySize t output := Nat.le_add_right _ _ have hO : output.length ≤ bodySize t output := Nat.le_add_left _ _ have hg := Nat.mul_le_mul_left ExpanderFamily.growth hN rw [Nat.add_mul, Nat.one_mul] omega theorem vertexSteps_le (H : PreprocessingRegularTables.BaseTable) (t : GraphTables.Table) (e : Fin t.darts) (output : List Bool) : MachineRegularOriginalBody.vertexSteps H t e output ≤ (blockPolynomial internalDegree).eval (bodySize t output) := by let v := t.rows[e].tail let W := (ExpanderFamily.growth+1)*bodySize t output have bounds := wide_le t output have hx := e.isLt.le.trans (GraphTables.darts_le_tableBits_length t) have hv := v.isLt.le.trans (GraphTables.vertices_le_tableBits_length t) have hk := cloudSize_le_input t v have hi := (cloudRank t v (MachineRegularMetadata.originalMember t e)).isLt.le.trans hk have hm := GraphTables.darts_le_tableBits_length t have ho := prefix_le_input t v.val have hV := regularVertices_le_input t have hR := (cloudRotorBits_le t v (familyCloudTable H t v)).trans (natPolynomial_eval_mono (rotorPolynomial internalDegree) (Nat.le_add_right (inputLength t) output.length)) have raw := MachineRegularVertexBlock.originalSteps_le internalDegree degree_positive t (padding t) (familyCloudTable H t) e output.length have bound := originalTimeBound_le internalDegree _ _ _ _ _ _ _ _ _ _ W _ bounds.1 hR (hx.trans bounds.1) (hv.trans bounds.1) (hi.trans bounds.1) (hk.trans bounds.1) (ho.trans bounds.2.1) (hm.trans bounds.1) bounds.2.2 (hV.trans bounds.2.1) rw [blockPolynomial_eval] exact raw.trans bound theorem clearSteps_frame (data : Data) : clearSteps (frame data) 7 = data.owner.length + data.localRank.length + data.count.length + data.offset.length + data.rotor.length + data.padding.length + data.level.length + 7 := by simp [clearSteps, clearMemory, clearTape, frame, MachineRegularMetadata.frame] omega theorem cleanupSteps_le (H : PreprocessingRegularTables.BaseTable) (t : GraphTables.Table) (e : Fin t.darts) (output : List Bool) : clearSteps (frame (emittedData H t e output)) 7 ≤ (cleanupPolynomial internalDegree).eval (bodySize t output) := by let v := t.rows[e].tail have bounds := wide_le t output have hv := v.isLt.le.trans (GraphTables.vertices_le_tableBits_length t) have hk := cloudSize_le_input t v have hi := (cloudRank t v (MachineRegularMetadata.originalMember t e)).isLt.le.trans hk have ho := prefix_le_input t v.val have hp := cloudTotal_le_input t v have hl := level_le_input t v have hrotor := PreprocessingFamilyBridge.familyRotor_eq_familyCloudTable H t v (PreprocessingFamilyBridge.cloudSize_pos_of_dart t e) change MachineRegularFamily.rotor H (cloudSize t v) = _ at hrotor have hR := (cloudRotorBits_le t v (familyCloudTable H t v)).trans (natPolynomial_eval_mono (rotorPolynomial internalDegree) (Nat.le_add_right (inputLength t) output.length)) rw [← hrotor] at hR rw [clearSteps_frame] simp only [emittedData, familyData, metadataData, MachineRegularMetadata.originalData, MachineRegularMetadata.cloudData, MachineRegularMetadata.prefixData, MachineRegularMetadata.rankData, MachineRegularMetadata.ownerData, initialData, encodeWord_length, cleanupPolynomial, wide, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] change _ ≤ 6*((ExpanderFamily.growth+1)*bodySize t output) + (rotorPolynomial internalDegree).eval (bodySize t output)+13 change cloudSize t v + MachineCloudPadding.padding (cloudSize t v) ≤ _ at hp dsimp only [v, bodySize, inputLength] at * omega theorem totalSteps_le (H : PreprocessingRegularTables.BaseTable) (t : GraphTables.Table) (e : Fin t.darts) (output : List Bool) : totalSteps H t e output ≤ timePolynomial.eval (bodySize t output) := by have hsize : inputLength t ≤ bodySize t output := Nat.le_add_right _ _ have hm := (MachineRegularMetadata.totalTime_le t e).trans (natPolynomial_eval_mono MachineRegularMetadata.timePolynomial hsize) have hf := (familyExecution H t e output).steps_le_m have hfb := MachineRegularExecutionBounds.family_budget_le t t.rows[e].tail simp only [MachineRegularFamily.timePolynomial, encodeWord_length, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] at hf have hf' := (hf.trans hfb).trans (natPolynomial_eval_mono MachineRegularExecutionBounds.familyPolynomial hsize) have hv := vertexSteps_le H t e output have hc := cleanupSteps_le H t e output simp only [totalSteps, familySteps, timePolynomial, Polynomial.eval_add] omega noncomputable def originalInTime (H : PreprocessingRegularTables.BaseTable) (t : GraphTables.Table) (e : Fin t.darts) (output : List Bool) : StateTransition.EvalsToInTime (TM2.step (program H)) (cfg H (some entry) (initialData t e output)) (some (cfg H none (initialData t e (output ++ emittedBits H t e)))) (timePolynomial.eval (bodySize t output)) where steps := totalSteps H t e output evals_in_steps := originalTrace H t e output steps_le_m := totalSteps_le H t e output end DFVSGames.Foundations.Complexity.MachineRegularOriginalBodyBounds end section namespace DFVSGames.Foundations.Complexity.MachineRegularOwnerBodyBounds open Turing MachineComposition PCP PreprocessingCloudIndex PreprocessingRegularTables open PreprocessingMachineBounds PreprocessingRegularLoopWords def bodySize (t : GraphTables.Table) (output : List Bool) : Nat := inputLength t + output.length noncomputable def wide : Polynomial Nat := Polynomial.C (ExpanderFamily.growth + 1) * Polynomial.X noncomputable def rowPolynomial (q : Nat) : Polynomial Nat := wide + wide * Polynomial.C (q + 1) + 8192 noncomputable def outputPolynomial (q : Nat) : Polynomial Nat := wide + regularPolynomial + Polynomial.C q * rowPolynomial q noncomputable def corePolynomial (q : Nat) : Polynomial Nat := Polynomial.C (5*q+32) * rotorPolynomial q + 10*wide + 2*wide + 13*wide + 5*wide + Polynomial.C (5*q+10)*(wide+wide) + 4*wide + 2*outputPolynomial q + Polynomial.C (8*q+41066) noncomputable def blockPolynomial (q : Nat) : Polynomial Nat := Polynomial.C q * corePolynomial q + Polynomial.C (5*q+11)*wide + 2*outputPolynomial q + Polynomial.C (5*q+40986) theorem blockPolynomial_eval (q L : Nat) : (blockPolynomial q).eval L = MachineRegularVertexBlock.dummyTimeBound q ((ExpanderFamily.growth+1)*L) ((rotorPolynomial q).eval L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) ((ExpanderFamily.growth+1)*L) (((ExpanderFamily.growth+1)*L) + regularPolynomial.eval L) ((ExpanderFamily.growth+1)*L) := by simp only [blockPolynomial, corePolynomial, outputPolynomial, rowPolynomial, wide, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat, MachineRegularVertexBlock.dummyTimeBound, MachineRegularVertexBlock.portTimeBound, MachineRegularInternalRow.coreTimeBound, MachineRegularDummyRow.timeBound, MachineRegularVertexBlock.rowSizeBound] simp only [Nat.add_assoc] theorem dummyTimeBound_le (q L R x v i k o m O V W R' O' : Nat) (hL : L ≤ W) (hR : R ≤ R') (hx : x ≤ W) (hv : v ≤ W) (hi : i ≤ W) (hk : k ≤ W) (ho : o ≤ W) (hm : m ≤ W) (hO : O ≤ O') (hV : V ≤ W) : MachineRegularVertexBlock.dummyTimeBound q L R x v i k o m O V ≤ MachineRegularVertexBlock.dummyTimeBound q W R' W W W W W W O' W := by unfold MachineRegularVertexBlock.dummyTimeBound MachineRegularVertexBlock.portTimeBound MachineRegularInternalRow.coreTimeBound MachineRegularDummyRow.timeBound MachineRegularVertexBlock.rowSizeBound gcongr theorem wide_le (t : GraphTables.Table) (output : List Bool) : inputLength t ≤ (ExpanderFamily.growth+1)*bodySize t output ∧ ExpanderFamily.growth*inputLength t ≤ (ExpanderFamily.growth+1)*bodySize t output ∧ output.length ≤ (ExpanderFamily.growth+1)*bodySize t output := by have hN : inputLength t ≤ bodySize t output := Nat.le_add_right _ _ have hO : output.length ≤ bodySize t output := Nat.le_add_left _ _ have hg := Nat.mul_le_mul_left ExpanderFamily.growth hN rw [Nat.add_mul, Nat.one_mul] omega theorem ownerPrefix_length_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (n : Nat) : (blocksPrefix (PreprocessingRegularWords.dummyVertexBits t (padding t) (familyCloudTable H t) v) n).length ≤ regularPolynomial.eval (inputLength t) := by have h := PreprocessingRegularBounds.regular_dummyPrefix_le t H v n simp only [PreprocessingRegularBounds.dummyPrefix, List.length_append] at h omega theorem growingOutput_length_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (n : Nat) (output : List Bool) : (output ++ blocksPrefix (PreprocessingRegularWords.dummyVertexBits t (padding t) (familyCloudTable H t) v) n).length ≤ (ExpanderFamily.growth+1)*bodySize t output + regularPolynomial.eval (bodySize t output) := by have h := (ownerPrefix_length_le H t v n).trans (natPolynomial_eval_mono regularPolynomial (Nat.le_add_right (inputLength t) output.length)) have hO := (wide_le t output).2.2 rw [List.length_append] exact Nat.add_le_add hO h theorem dummySteps_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (j : Fin (padding t v)) (n : Nat) (output : List Bool) : MachineRegularVertexBlock.dummySteps t (padding t) (familyCloudTable H t) v j (output ++ blocksPrefix (PreprocessingRegularWords.dummyVertexBits t (padding t) (familyCloudTable H t) v) n).length ≤ (blockPolynomial internalDegree).eval (bodySize t output) := by let x := paddedNew t (padding t) v j let W := (ExpanderFamily.growth+1)*bodySize t output have bounds := wide_le t output have hx := (vertexOrder t (padding t) x.val).isLt.le.trans (regularVertices_le_input t) have hv := v.isLt.le.trans (GraphTables.vertices_le_tableBits_length t) have hi := (paddedCloudRank t (padding t) v x).isLt.le.trans (cloudTotal_le_input t v) have hk := cloudSize_le_input t v have hm := GraphTables.darts_le_tableBits_length t have ho := prefix_le_input t v.val have hV := regularVertices_le_input t have hR := (cloudRotorBits_le t v (familyCloudTable H t v)).trans (natPolynomial_eval_mono (rotorPolynomial internalDegree) (Nat.le_add_right (inputLength t) output.length)) have hO := growingOutput_length_le H t v n output have raw := MachineRegularVertexBlock.dummySteps_le internalDegree MachineRegularOriginalBody.degree_positive t (padding t) (familyCloudTable H t) v j (output ++ blocksPrefix (PreprocessingRegularWords.dummyVertexBits t (padding t) (familyCloudTable H t) v) n).length have bound := dummyTimeBound_le internalDegree _ _ _ _ _ _ _ _ _ _ W _ _ bounds.1 hR (hx.trans bounds.2.1) (hv.trans bounds.1) (hi.trans bounds.2.1) (hk.trans bounds.1) (ho.trans bounds.2.1) (hm.trans bounds.1) hO (hV.trans bounds.2.1) rw [blockPolynomial_eval] exact raw.trans bound noncomputable def prePolynomial : Polynomial Nat := MachineCloudPadding.timePolynomial.comp (2*Polynomial.X+1) + 4*wide + 6 noncomputable def loopPolynomial : Polynomial Nat := wide * (blockPolynomial internalDegree + 2) noncomputable def cleanupPolynomial : Polynomial Nat := 6*wide + rotorPolynomial internalDegree + 13 noncomputable def timePolynomial : Polynomial Nat := prePolynomial + MachineRegularExecutionBounds.familyPolynomial + loopPolynomial + cleanupPolynomial + 2 theorem preSteps_le (t : GraphTables.Table) (v : Fin t.vertices) (output : List Bool) : MachineRegularOwnerBody.preSteps t v ≤ prePolynomial.eval (bodySize t output) := by have bounds := wide_le t output have hk := cloudSize_le_input t v have hd := cloudTotal_le_input t v have hv := v.isLt.le.trans (GraphTables.vertices_le_tableBits_length t) change v.val ≤ inputLength t at hv have hN : inputLength t ≤ bodySize t output := Nat.le_add_right _ _ have hinput : MachineCloudPadding.inputLength t v [] ≤ 2*bodySize t output+1 := by simp only [MachineCloudPadding.inputLength, List.append_nil, encodeWord_length] change inputLength t + (v.val+1) ≤ _ omega have hm := (MachineCloudPadding.totalTime_le t v []).trans (natPolynomial_eval_mono MachineCloudPadding.timePolynomial hinput) simp only [MachineRegularOwnerBody.preSteps, prePolynomial, wide, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_comp, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat, Polynomial.eval_one] omega theorem loopSteps_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (output : List Bool) (n : Nat) (hn : n ≤ padding t v) : MachineRegularOwnerBody.loopSteps H t v output n hn ≤ n * ((blockPolynomial internalDegree).eval (bodySize t output) + 2) := by induction n with | zero => simp only [MachineRegularOwnerBody.loopSteps, Nat.zero_mul, le_refl] | succ n ih => have h : n < padding t v := by omega have first := ih (by omega) have second := dummySteps_le H t v ⟨n, h⟩ n output rw [MachineRegularOwnerBody.loopSteps, Nat.succ_mul] change MachineRegularOwnerBody.loopSteps H t v output n _ + (1 + MachineRegularVertexBlock.dummySteps t (padding t) (familyCloudTable H t) v ⟨n, h⟩ (output ++ blocksPrefix (PreprocessingRegularWords.dummyVertexBits t (padding t) (familyCloudTable H t) v) n).length + 1) ≤ _ omega theorem allLoopSteps_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (output : List Bool) : MachineRegularOwnerBody.loopSteps H t v output (padding t v) le_rfl ≤ loopPolynomial.eval (bodySize t output) := by have hd := (cloudTotal_le_input t v).trans (wide_le t output).2.1 have hp : padding t v ≤ (ExpanderFamily.growth+1)*bodySize t output := by omega have h := (loopSteps_le H t v output (padding t v) le_rfl).trans (Nat.mul_le_mul_right _ hp) simpa only [loopPolynomial, wide, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] using h theorem cleanupSteps_working (data : MachineRegularOwnerBody.Data) (fuel saved : List Bool) (d : Nat) : MachineRegularOwnerCleanup.steps (MachineRegularOwnerBody.working data fuel saved) d = 2*(d+1) + data.localRank.length + data.count.length + data.rotor.length + data.padding.length + data.level.length + fuel.length + 6 := by change 2*(d+1) + ((data.localRank.length+1) + ((data.count.length+1) + ((data.rotor.length+1) + ((data.padding.length+1) + ((data.level.length+1) + ((fuel.length+1)+0)))))) = _ omega theorem cleanupCost_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (output : List Bool) : MachineRegularOwnerBody.cleanupCost H t v output ≤ cleanupPolynomial.eval (bodySize t output) := by have bounds := wide_le t output have hk := (cloudSize_le_input t v).trans bounds.1 have htotal := (cloudTotal_le_input t v).trans bounds.2.1 have hl := (level_le_input t v).trans bounds.1 have hp : MachineCloudPadding.padding (cloudSize t v) = padding t v := rfl by_cases hd : padding t v = 0 · rw [MachineRegularOwnerBody.cleanupCost, ite_eq_left hd, cleanupSteps_working] simp only [MachineRegularOwnerBody.seededData, MachineRegularOwnerBody.metadataData, MachineRegularMetadata.cloudData, MachineRegularOwnerBody.initialData, hp, encodeWord_length, List.length_nil, cleanupPolynomial, wide, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] omega · have hpositive : 0 < padding t v := by omega have hkpos := PreprocessingFamilyBridge.cloudSize_pos_of_dummy t v ⟨0, hpositive⟩ have hrotor := PreprocessingFamilyBridge.familyRotor_eq_familyCloudTable H t v hkpos change MachineRegularFamily.rotor H (cloudSize t v) = _ at hrotor have hR := (cloudRotorBits_le t v (familyCloudTable H t v)).trans (natPolynomial_eval_mono (rotorPolynomial internalDegree) (Nat.le_add_right (inputLength t) output.length)) rw [← hrotor] at hR change (MachineRegularFamily.rotor H (cloudSize t v)).length ≤ (rotorPolynomial internalDegree).eval (bodySize t output) at hR rw [MachineRegularOwnerBody.cleanupCost, ite_eq_right hd, MachineRegularOwnerBody.loopFrame, cleanupSteps_working] simp only [MachineRegularOwnerBody.loopData, MachineRegularOwnerBody.vertexData, MachineRegularOwnerBody.seededData, MachineRegularOwnerBody.metadataData, MachineRegularMetadata.cloudData, MachineRegularOwnerBody.initialData, hp, encodeWord_length, Nat.sub_self, cleanupPolynomial, wide, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] omega theorem ownerTime_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (output : List Bool) : MachineRegularOwnerBody.ownerTime H t v output ≤ timePolynomial.eval (bodySize t output) := by have hp := preSteps_le t v output have hc := cleanupCost_le H t v output have hl := allLoopSteps_le H t v output have hf := (MachineRegularExecutionBounds.family_budget_le t v).trans (natPolynomial_eval_mono MachineRegularExecutionBounds.familyPolynomial (Nat.le_add_right (inputLength t) output.length)) have hfamily : MachineRegularFamily.timePolynomial.eval (encodeWord (cloudSize t v)).length ≤ MachineRegularExecutionBounds.familyPolynomial.eval (bodySize t output) := by simpa only [bodySize, MachineRegularFamily.timePolynomial, encodeWord_length, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat] using hf simp only [MachineRegularOwnerBody.ownerTime, timePolynomial, Polynomial.eval_add, Polynomial.eval_ofNat] split_ifs <;> omega theorem totalSteps_le (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (output : List Bool) : MachineRegularOwnerBody.totalSteps H t v output ≤ timePolynomial.eval (bodySize t output) := (MachineRegularOwnerBody.totalSteps_le H t v output).trans (ownerTime_le H t v output) noncomputable def ownerInTime (H : BaseTable) (t : GraphTables.Table) (v : Fin t.vertices) (output : List Bool) : StateTransition.EvalsToInTime (TM2.step (MachineRegularOwnerBody.program H)) (MachineRegularOwnerBody.cfg H (some MachineRegularOwnerBody.entry) (MachineRegularOwnerBody.initialData t v output)) (some (MachineRegularOwnerBody.cfg H none (MachineRegularOwnerBody.finalData H t v output))) (timePolynomial.eval (bodySize t output)) where steps := MachineRegularOwnerBody.totalSteps H t v output evals_in_steps := MachineRegularOwnerBody.ownerTrace H t v output steps_le_m := totalSteps_le H t v output end DFVSGames.Foundations.Complexity.MachineRegularOwnerBodyBounds end section namespace DFVSGames.Foundations.Complexity.MachineRegularTable.Top open Turing MachineComposition PCP PreprocessingRegularTables open PreprocessingRegularBounds PreprocessingMachineBounds noncomputable def oldLoopPolynomial : Polynomial Nat := Polynomial.X * (MachineRegularOriginalBodyBounds.timePolynomial.comp (Polynomial.X + regularPolynomial) + 2) noncomputable def ownerLoopPolynomial : Polynomial Nat := Polynomial.X * (MachineRegularOwnerBodyBounds.timePolynomial.comp (Polynomial.X + regularPolynomial) + 2) noncomputable def timePolynomial : Polynomial Nat := Header.timePolynomial internalDegree + oldLoopPolynomial + ownerLoopPolynomial + 4 * Polynomial.X + 12 + Polynomial.C (7 * (ExpanderFamily.growth * (internalDegree + 4) + 4)) * (Polynomial.X + 1) theorem oldElapsed_prefix_le (H : BaseTable) (t : GraphTables.Table) (k : Nat) : oldElapsed H t (Header.headerBits internalDegree t) k ≤ k * (MachineRegularOriginalBodyBounds.timePolynomial.eval (inputLength t + regularPolynomial.eval (inputLength t)) + 2) := by induction k with | zero => simp [oldElapsed] | succ k ih => simp only [oldElapsed] split_ifs with hk · have raw := MachineRegularOriginalBodyBounds.totalSteps_le H t ⟨k, hk⟩ (Header.headerBits internalDegree t ++ oldPrefix H t k) have hprefix : (Header.headerBits internalDegree t ++ oldPrefix H t k).length ≤ regularPolynomial.eval (inputLength t) := by exact regular_originalPrefix_le t H k have hcall := raw.trans (natPolynomial_eval_mono MachineRegularOriginalBodyBounds.timePolynomial (Nat.add_le_add_left hprefix _)) rw [Nat.succ_mul] omega · rw [Nat.succ_mul] omega theorem oldElapsed_le (H : BaseTable) (t : GraphTables.Table) : oldElapsed H t (Header.headerBits internalDegree t) t.darts ≤ oldLoopPolynomial.eval (inputLength t) := by have bound := (oldElapsed_prefix_le H t t.darts).trans (Nat.mul_le_mul_right _ (GraphTables.darts_le_tableBits_length t)) simpa only [oldLoopPolynomial, inputLength, Polynomial.eval_mul, Polynomial.eval_X, Polynomial.eval_add, Polynomial.eval_comp, Polynomial.eval_ofNat] using bound theorem ownerElapsed_prefix_le (H : BaseTable) (t : GraphTables.Table) (k : Nat) : ownerElapsed H t (Header.headerBits internalDegree t ++ oldPrefix H t t.darts) k ≤ k * (MachineRegularOwnerBodyBounds.timePolynomial.eval (inputLength t + regularPolynomial.eval (inputLength t)) + 2) := by induction k with | zero => simp [ownerElapsed] | succ k ih => simp only [ownerElapsed] split_ifs with hk · have raw := MachineRegularOwnerBodyBounds.totalSteps_le H t ⟨k, hk⟩ ((Header.headerBits internalDegree t ++ oldPrefix H t t.darts) ++ ownerPrefix H t k) have hprefix : ((Header.headerBits internalDegree t ++ oldPrefix H t t.darts) ++ ownerPrefix H t k).length ≤ regularPolynomial.eval (inputLength t) := by rw [owner_output_eq_ownerPrefix] exact regular_ownerPrefix_le t H k have hcall := raw.trans (natPolynomial_eval_mono MachineRegularOwnerBodyBounds.timePolynomial (Nat.add_le_add_left hprefix _)) rw [Nat.succ_mul] omega · rw [Nat.succ_mul] omega theorem ownerElapsed_le (H : BaseTable) (t : GraphTables.Table) : ownerElapsed H t (Header.headerBits internalDegree t ++ oldPrefix H t t.darts) t.vertices ≤ ownerLoopPolynomial.eval (inputLength t) := by have bound := (ownerElapsed_prefix_le H t t.vertices).trans (Nat.mul_le_mul_right _ (GraphTables.vertices_le_tableBits_length t)) simpa only [ownerLoopPolynomial, inputLength, Polynomial.eval_mul, Polynomial.eval_X, Polynomial.eval_add, Polynomial.eval_comp, Polynomial.eval_ofNat] using bound theorem totalTime_le (H : BaseTable) (t : GraphTables.Table) : totalTime H t ≤ timePolynomial.eval (inputLength t) := by have header := Header.totalTime_le internalDegree t [] simp only [List.length_nil, Nat.add_zero] at header change Header.totalTime internalDegree t [] ≤ (Header.timePolynomial internalDegree).eval (inputLength t) at header have old := oldElapsed_le H t have owners := ownerElapsed_le H t have cleanup := cleanupTime_final_le t (finalOutput H t) have hm : t.darts ≤ inputLength t := GraphTables.darts_le_tableBits_length t have hn : t.vertices ≤ inputLength t := GraphTables.vertices_le_tableBits_length t simp only [totalTime, headerOutput, oldOutput, timePolynomial, Polynomial.eval_add, Polynomial.eval_mul, Polynomial.eval_C, Polynomial.eval_X, Polynomial.eval_ofNat, Polynomial.eval_one] omega noncomputable def machineInTime (H : BaseTable) (t : GraphTables.Table) : StateTransition.EvalsToInTime (TM2.step (program H)) (initList (machine H) (GraphTables.tableBits t)) (some ⟨none, readyState H, Function.update (initList (machine H) (GraphTables.tableBits t)).stk (coreTape 8) (PortTables.tableBits (regularize H t))⟩) (timePolynomial.eval (inputLength t)) where steps := totalTime H t evals_in_steps := trace H t steps_le_m := totalTime_le H t end DFVSGames.Foundations.Complexity.MachineRegularTable.Top end section namespace DFVSGames.Foundations.Complexity.MachineCanonicalOutput open Turing MachineComposition structure Program (K Λ σ : Type) where input : K output : K main : Λ initial : σ code : Λ → TM2.Stmt (fun _ : K => Bool) Λ σ section Structural variable {K Λ Λ' σ : Type} [DecidableEq K] def extendedLabel (labels : Λ → Λ') (haltTarget : Option Λ') : Option Λ → Option Λ' | none => haltTarget | some label => some (labels label) def extendedCfg (labels : Λ → Λ') (haltTarget : Option Λ') (register : Option Bool) (cfg : TM2.Cfg (fun _ : K => Bool) Λ σ) : TM2.Cfg (fun _ : K => Bool) Λ' (σ × Option Bool) := ⟨extendedLabel labels haltTarget cfg.l, (cfg.var, register), cfg.stk⟩ def extendedStmt (labels : Λ → Λ') (haltTarget : Option Λ') : TM2.Stmt (fun _ : K => Bool) Λ σ → TM2.Stmt (fun _ : K => Bool) Λ' (σ × Option Bool) | .push k f next => .push k (fun state => f state.1) (extendedStmt labels haltTarget next) | .peek k f next => .peek k (fun state symbol => (f state.1 symbol, state.2)) (extendedStmt labels haltTarget next) | .pop k f next => .pop k (fun state symbol => (f state.1 symbol, state.2)) (extendedStmt labels haltTarget next) | .load f next => .load (fun state => (f state.1, state.2)) (extendedStmt labels haltTarget next) | .branch test yes no => .branch (fun state => test state.1) (extendedStmt labels haltTarget yes) (extendedStmt labels haltTarget no) | .goto label => .goto (fun state => labels (label state.1)) | .halt => match haltTarget with | none => .halt | some label => .goto (fun _ => label) theorem stepAux_extended (labels : Λ → Λ') (haltTarget : Option Λ') (stmt : TM2.Stmt (fun _ : K => Bool) Λ σ) (state : σ) (register : Option Bool) (tapes : K → List Bool) : TM2.stepAux (extendedStmt labels haltTarget stmt) (state, register) tapes = extendedCfg labels haltTarget register (TM2.stepAux stmt state tapes) := by induction stmt generalizing state tapes with | push k f next ih => exact ih state (Function.update tapes k (f state :: tapes k)) | peek k f next ih => exact ih (f state (tapes k).head?) tapes | pop k f next ih => exact ih (f state (tapes k).head?) (Function.update tapes k (tapes k).tail) | load f next ih => exact ih (f state) tapes | branch test yes no ihYes ihNo => cases h : test state with | false => simpa only [extendedStmt, TM2.stepAux, h, Bool.cond_false] using ihNo state tapes | true => simpa only [extendedStmt, TM2.stepAux, h, Bool.cond_true] using ihYes state tapes | goto label => rfl | halt => cases haltTarget <;> rfl end Structural section Machine variable {K Λ σ : Type} [DecidableEq K] [Fintype K] [Fintype Λ] [Fintype σ] def sourceMachine (P : Program K Λ σ) : FinTM2 where K := K k₀ := P.input k₁ := P.output Γ _ := Bool Λ := Λ main := P.main σ := σ initialState := P.initial m := P.code abbrev Label (Λ : Type) (chosen : List K) := Λ ⊕ (MachineDrainMany.Label chosen ⊕ Unit) def cleanupLabel (chosen : List K) : MachineDrainMany.Label chosen → Label Λ chosen := fun label => .inr (.inl label) def resetLabel (chosen : List K) : Label Λ chosen := .inr (.inr ()) def cleanupEntry (chosen : List K) : Option (Label Λ chosen) := MachineDrainMany.entry chosen (cleanupLabel chosen) (some (resetLabel chosen)) def completedProgram (P : Program K Λ σ) (chosen : List K) : Label Λ chosen → TM2.Stmt (fun _ : K => Bool) (Label Λ chosen) (σ × Option Bool) | .inl label => extendedStmt Sum.inl (cleanupEntry chosen) (P.code label) | .inr (.inl label) => MachineDrainMany.instruction chosen (cleanupLabel chosen) (some (resetLabel chosen)) label | .inr (.inr _) => .load (fun _ => (P.initial, none)) .halt def completedMachine (P : Program K Λ σ) (chosen : List K) : FinTM2 where K := K k₀ := P.input k₁ := P.output Γ _ := Bool Λ := Label Λ chosen main := .inl P.main σ := σ × Option Bool initialState := (P.initial, none) m := completedProgram P chosen theorem finiteAlphabet (P : Program K Λ σ) (chosen : List K) : MachineFiniteAlphabet.FiniteAlphabet (completedMachine P chosen) := by intro k exact inferInstanceAs (Finite Bool) def embeddedCfg (P : Program K Λ σ) (chosen : List K) (cfg : (sourceMachine P).Cfg) : (completedMachine P chosen).Cfg := extendedCfg Sum.inl (cleanupEntry chosen) none cfg theorem step_simulation (P : Program K Λ σ) (chosen : List K) (a b : (sourceMachine P).Cfg) (step : (sourceMachine P).step a = some b) : (completedMachine P chosen).step (embeddedCfg P chosen a) = some (embeddedCfg P chosen b) := by cases a with | mk label state tapes => cases label with | none => simp [FinTM2.step, TM2.step] at step | some label => have hb : TM2.stepAux (P.code label) state tapes = b := Option.some.inj step rw [← hb] change some (TM2.stepAux (extendedStmt Sum.inl (cleanupEntry chosen) (P.code label)) (state, none) tapes) = _ exact congrArg some (stepAux_extended Sum.inl (cleanupEntry chosen) (P.code label) state none tapes) @[simp] theorem embedded_init (P : Program K Λ σ) (chosen : List K) (input : List Bool) : embeddedCfg P chosen (initList (sourceMachine P) input) = initList (completedMachine P chosen) input := rfl omit [Fintype K] [Fintype Λ] [Fintype σ] in theorem finalTapes_eq (P : Program K Λ σ) (chosen : List K) (complete : ∀ k, k ∈ chosen ↔ k ≠ P.output) (base : K → List Bool) : MachineDrainMany.finalTapes chosen base = MachineDrainMany.haltTapes P.output (base P.output) := by funext k rw [MachineDrainMany.finalTapes_apply] by_cases h : k = P.output · subst k simp [MachineDrainMany.haltTapes, complete] · simp [MachineDrainMany.haltTapes, complete, h] theorem haltList_eq (P : Program K Λ σ) (chosen : List K) (output : List Bool) : haltList (completedMachine P chosen) output = ⟨none, (P.initial, none), MachineDrainMany.haltTapes P.output output⟩ := by congr 1 def cleanupExecution (P : Program K Λ σ) (chosen : List K) (complete : ∀ k, k ∈ chosen ↔ k ≠ P.output) (state : σ) (register : Option Bool) (base : K → List Bool) : StateTransition.EvalsToInTime (completedMachine P chosen).step ⟨cleanupEntry chosen, (state, register), base⟩ (some (haltList (completedMachine P chosen) (base P.output))) (MachineDrainMany.steps chosen base + 1) := by let after : (completedMachine P chosen).Cfg := ⟨some (resetLabel chosen), (state, MachineDrainMany.finalRegister chosen register), MachineDrainMany.finalTapes chosen base⟩ have drains : StateTransition.EvalsToInTime (completedMachine P chosen).step ⟨cleanupEntry chosen, (state, register), base⟩ (some after) (MachineDrainMany.steps chosen base) := { steps := MachineDrainMany.steps chosen base evals_in_steps := MachineDrainMany.trace chosen (cleanupLabel chosen) (some (resetLabel chosen)) (completedProgram P chosen) (fun _ => rfl) base state register steps_le_m := le_rfl } have reset : StateTransition.EvalsToInTime (completedMachine P chosen).step after (some (haltList (completedMachine P chosen) (base P.output))) 1 := { steps := 1 evals_in_steps := by change some (⟨none, (P.initial, none), MachineDrainMany.finalTapes chosen base⟩ : TM2.Cfg (fun _ : K => Bool) (Label Λ chosen) (σ × Option Bool)) = some (haltList (completedMachine P chosen) (base P.output)) rw [finalTapes_eq P chosen complete, haltList_eq] rfl steps_le_m := le_rfl } simpa only [Nat.add_comm] using StateTransition.EvalsToInTime.trans _ (MachineDrainMany.steps chosen base) 1 _ after _ drains reset def outputsInTime (P : Program K Λ σ) (chosen : List K) (complete : ∀ k, k ∈ chosen ↔ k ≠ P.output) (input output : List Bool) (state : σ) (base : K → List Bool) (budget : Nat) (raw : StateTransition.EvalsToInTime (sourceMachine P).step (initList (sourceMachine P) input) (some ⟨none, state, base⟩) budget) (correctOutput : base P.output = output) : TM2OutputsInTime (completedMachine P chosen) input (some output) (budget + chosen.length * (input.length + budget * Runtime.programPushBound (sourceMachine P) + 1) + 1) := by let lifted := liftExecutionInTime (sourceMachine P).step (completedMachine P chosen).step (embeddedCfg P chosen) (step_simulation P chosen) raw have joined := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ lifted (cleanupExecution P chosen complete state none base) have stackBound : ∀ k, (base k).length ≤ input.length + budget * Runtime.programPushBound (sourceMachine P) := by intro k have h := Runtime.executionSizeBound (sourceMachine P).step (fun cfg => (cfg.stk k).length) (Runtime.programPushBound (sourceMachine P)) (Runtime.stepStackLength (sourceMachine P) k) raw exact h.trans (Nat.add_le_add_right (Runtime.initialStackLength (sourceMachine P) input k) _) have cleanupBound := MachineDrainMany.steps_le_uniform chosen base _ stackBound rw [embedded_init, correctOutput] at joined exact { toEvalsTo := joined.toEvalsTo steps_le_m := joined.steps_le_m.trans (by omega) } noncomputable def completedTime (P : Program K Λ σ) (chosen : List K) (rawTime : Polynomial Nat) : Polynomial Nat := rawTime + Polynomial.C chosen.length * (Polynomial.X + rawTime * Polynomial.C (Runtime.programPushBound (sourceMachine P)) + 1) + 1 theorem completedTime_eval (P : Program K Λ σ) (chosen : List K) (rawTime : Polynomial Nat) (n : Nat) : (completedTime P chosen rawTime).eval n = rawTime.eval n + chosen.length * (n + rawTime.eval n * Runtime.programPushBound (sourceMachine P) + 1) + 1 := by simp [completedTime] structure TerminalRun (P : Program K Λ σ) (input output : List Bool) (budget : Nat) where state : σ tapes : K → List Bool execution : StateTransition.EvalsToInTime (sourceMachine P).step (initList (sourceMachine P) input) (some ⟨none, state, tapes⟩) budget output_eq : tapes P.output = output noncomputable def computableInPolyTime {α β : Type} (P : Program K Λ σ) (chosen : List K) (complete : ∀ k, k ∈ chosen ↔ k ≠ P.output) (encodeIn : α → List Bool) (encodeOut : β → List Bool) (f : α → β) (rawTime : Polynomial Nat) (run : ∀ a, TerminalRun P (encodeIn a) (encodeOut (f a)) (rawTime.eval (encodeIn a).length)) : TM2ComputableInPolyTime encodeIn encodeOut f where tm := completedMachine P chosen inputAlphabet := Equiv.refl Bool outputAlphabet := Equiv.refl Bool time := completedTime P chosen rawTime outputsFun a := by have execution : TM2OutputsInTime (completedMachine P chosen) (encodeIn a) (some (encodeOut (f a))) ((completedTime P chosen rawTime).eval (encodeIn a).length) := by simpa only [completedTime_eval] using outputsInTime P chosen complete _ _ (run a).state (run a).tapes _ (run a).execution (run a).output_eq exact (congrArg₂ (fun input output : List Bool => TM2OutputsInTime (completedMachine P chosen) input (some output) ((completedTime P chosen rawTime).eval (encodeIn a).length)) (List.map_id (encodeIn a)) (List.map_id (encodeOut (f a)))).mpr execution theorem computableInPolyTime_finite_alphabet {α β : Type} (P : Program K Λ σ) (chosen : List K) (complete : ∀ k, k ∈ chosen ↔ k ≠ P.output) (encodeIn : α → List Bool) (encodeOut : β → List Bool) (f : α → β) (rawTime : Polynomial Nat) (run : ∀ a, TerminalRun P (encodeIn a) (encodeOut (f a)) (rawTime.eval (encodeIn a).length)) : MachineFiniteAlphabet.FiniteAlphabet (computableInPolyTime P chosen complete encodeIn encodeOut f rawTime run).tm := finiteAlphabet P chosen noncomputable def computableInPolyTimeOfEnumeration {α β : Type} {N : Nat} (P : Program K Λ σ) (enumeration : Fin N ≃ K) (encodeIn : α → List Bool) (encodeOut : β → List Bool) (f : α → β) (rawTime : Polynomial Nat) (run : ∀ a, TerminalRun P (encodeIn a) (encodeOut (f a)) (rawTime.eval (encodeIn a).length)) : TM2ComputableInPolyTime encodeIn encodeOut f := computableInPolyTime P (MachineDrainMany.workTapes enumeration P.output) (fun k => MachineDrainMany.mem_workTapes enumeration P.output k) encodeIn encodeOut f rawTime run end Machine end DFVSGames.Foundations.Complexity.MachineCanonicalOutput end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end OAI