Buckets:
| import Mathlib | |
| import OAI.Computability.MaxCut.Machines.MachineCopy | |
| import OAI.Computability.MaxCut.Machines.Machine | |
| import OAI.Computability.MaxCut.Machines.MachineFieldTemplate | |
| namespace OAI | |
| namespace MaxCutGames.Foundations.Complexity.MachineUnaryAffineAt | |
| open Turing | |
| open MachineComposition | |
| open Reduction.MachineSubstitution | |
| variable {K Λ σ : Type} [DecidableEq K] | |
| abbrev Alphabet (_ : K) := Bool | |
| def finish (restoreLabel : Λ) : TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool) := | |
| .load (fun s => (s.1,none)) (.goto (fun _ => restoreLabel)) | |
| def scan (source scratch destination : K) (coefficient : Nat) (scanLabel restoreLabel : Λ) : | |
| TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool) := | |
| .pop source (fun s head => (s.1,head)) | |
| (.branch (fun s => s.2.getD false) | |
| (.push scratch (fun _ => true) | |
| (pushWord destination (List.replicate coefficient true) (.goto (fun _ => scanLabel)))) | |
| (.branch (fun s => s.2.isSome) | |
| (.push source (fun _ => false) (finish restoreLabel)) | |
| (finish restoreLabel))) | |
| def seed (destination : K) (offset : Nat) (scanLabel : Λ) : | |
| TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool) := | |
| pushWord destination (encodeWord offset).reverse (.goto (fun _ => scanLabel)) | |
| def tapes (source scratch destination : K) (base : K → List Bool) | |
| (input saved output : List Bool) : K → List Bool := | |
| MachineCopy.forkTapes source scratch destination base input saved output | |
| @[simp] theorem tapes_source (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) | |
| (base : K → List Bool) (input saved output : List Bool) : | |
| tapes source scratch destination base input saved output source = input := | |
| MachineCopy.forkTapes_source source scratch destination hs hd base input saved output | |
| @[simp] theorem tapes_scratch (source scratch destination : K) (hsd : scratch ≠ destination) | |
| (base : K → List Bool) (input saved output : List Bool) : | |
| tapes source scratch destination base input saved output scratch = saved := | |
| MachineCopy.forkTapes_left source scratch destination hsd base input saved output | |
| @[simp] theorem tapes_destination (source scratch destination : K) | |
| (base : K → List Bool) (input saved output : List Bool) : | |
| tapes source scratch destination base input saved output destination = output := | |
| MachineCopy.forkTapes_right source scratch destination base input saved output | |
| private theorem update_source_inline_MachineUnaryAffineAt (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (base : K → List Bool) (input saved output replacement : List Bool) : | |
| Function.update (tapes source scratch destination base input saved output) source replacement = | |
| tapes source scratch destination base replacement saved output := by | |
| funext k | |
| by_cases h₀ : k = source | |
| · subst k; simp [tapes, MachineCopy.forkTapes, hs, hd] | |
| · by_cases h₁ : k = scratch | |
| · subst k; simp [tapes, MachineCopy.forkTapes, h₀, hsd] | |
| · by_cases h₂ : k = destination | |
| · subst k; simp [tapes, MachineCopy.forkTapes, h₀] | |
| · simp [tapes, MachineCopy.forkTapes, h₀, h₁, h₂] | |
| private theorem update_scratch_inline_MachineUnaryAffineAt (source scratch destination : K) (hsd : scratch ≠ destination) | |
| (base : K → List Bool) (input saved output replacement : List Bool) : | |
| Function.update (tapes source scratch destination base input saved output) scratch replacement = | |
| tapes source scratch destination base input replacement output := by | |
| funext k | |
| by_cases h : k = scratch | |
| · subst k; simp [tapes, MachineCopy.forkTapes, hsd] | |
| · by_cases h' : k = destination | |
| · subst k; simp [tapes, MachineCopy.forkTapes, h] | |
| · simp [tapes, MachineCopy.forkTapes, h, h'] | |
| private theorem update_destination_inline_MachineUnaryAffineAt (source scratch destination : K) | |
| (base : K → List Bool) (input saved output replacement : List Bool) : | |
| Function.update (tapes source scratch destination base input saved output) destination replacement = | |
| tapes source scratch destination base input saved replacement := by | |
| simp [tapes, MachineCopy.forkTapes] | |
| theorem prepend_replicate_word (c b : Nat) (suffix : List Bool) : | |
| List.replicate c true ++ (encodeWord b ++ suffix) = | |
| encodeWord (c + b) ++ suffix := by | |
| simp only [encodeWord, List.replicate_add, List.append_assoc] | |
| theorem scan_step_succ (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (coefficient : Nat) (scanLabel restoreLabel : Λ) | |
| (program : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (atScan : program scanLabel = scan source scratch destination coefficient scanLabel restoreLabel) | |
| (base : K → List Bool) (a b : Nat) (suffix saved output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| TM2.step program ⟨some scanLabel, (ambient,register), tapes source scratch destination base | |
| (encodeWord (a + 1) ++ suffix) saved (encodeWord b ++ output)⟩ = | |
| some ⟨some scanLabel, (ambient,some true), tapes source scratch destination base | |
| (encodeWord a ++ suffix) (true :: saved) (encodeWord (coefficient + b) ++ output)⟩ := by | |
| change some (TM2.stepAux (program scanLabel) _ _) = _ | |
| rw [atScan] | |
| rw [show encodeWord (a + 1) ++ suffix = true :: (encodeWord a ++ suffix) by | |
| simp [encodeWord, List.replicate_succ]] | |
| simp [scan, TM2.stepAux, tapes_source _ _ _ hs hd, | |
| update_source_inline_MachineUnaryAffineAt source scratch destination hs hd hsd, tapes_scratch _ _ _ hsd, | |
| update_scratch_inline_MachineUnaryAffineAt _ _ _ hsd, stepAux_pushWord, tapes_destination, | |
| prepend_replicate_word, update_destination_inline_MachineUnaryAffineAt] | |
| theorem scan_step_zero (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (coefficient : Nat) (scanLabel restoreLabel : Λ) | |
| (program : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (atScan : program scanLabel = scan source scratch destination coefficient scanLabel restoreLabel) | |
| (base : K → List Bool) (b : Nat) (suffix saved output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| TM2.step program ⟨some scanLabel, (ambient,register), tapes source scratch destination base | |
| (encodeWord 0 ++ suffix) saved (encodeWord b ++ output)⟩ = | |
| some ⟨some restoreLabel, (ambient,none), tapes source scratch destination base | |
| (encodeWord 0 ++ suffix) saved (encodeWord b ++ output)⟩ := by | |
| change some (TM2.stepAux (program scanLabel) _ _) = _ | |
| rw [atScan] | |
| rw [show encodeWord 0 ++ suffix = false :: suffix from rfl] | |
| simp [scan, finish, TM2.stepAux, tapes_source _ _ _ hs hd, | |
| update_source_inline_MachineUnaryAffineAt source scratch destination hs hd hsd] | |
| theorem scanTrace (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (coefficient : Nat) (scanLabel restoreLabel : Λ) | |
| (program : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (atScan : program scanLabel = scan source scratch destination coefficient scanLabel restoreLabel) | |
| (base : K → List Bool) (a b : Nat) (suffix saved output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| (advance (TM2.step program))^[a + 1] | |
| (some ⟨some scanLabel, (ambient,register), tapes source scratch destination base | |
| (encodeWord a ++ suffix) saved (encodeWord b ++ output)⟩) = | |
| some ⟨some restoreLabel, (ambient,none), tapes source scratch destination base | |
| (encodeWord 0 ++ suffix) (List.replicate a true ++ saved) | |
| (encodeWord (coefficient * a + b) ++ output)⟩ := by | |
| induction a generalizing b saved register with | |
| | zero => | |
| simpa using scan_step_zero source scratch destination hs hd hsd coefficient scanLabel | |
| restoreLabel program atScan base b suffix saved output ambient register | |
| | succ a ih => | |
| rw [Function.iterate_succ_apply] | |
| simp only [advance_some] | |
| rw [scan_step_succ source scratch destination hs hd hsd coefficient scanLabel restoreLabel | |
| program atScan] | |
| rw [ih] | |
| have hval : coefficient * a + (coefficient + b) = coefficient * (a + 1) + b := by | |
| rw [Nat.mul_succ]; omega | |
| rw [hval] | |
| have hsave : List.replicate a true ++ true :: saved = List.replicate (a + 1) true ++ saved := by | |
| simp only [List.replicate_add, List.replicate_one, List.append_assoc, List.singleton_append] | |
| rw [hsave] | |
| theorem restoreTapes (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (base : K → List Bool) (a value : Nat) (suffix output : List Bool) : | |
| Reduction.MachineTransfer.tapesAt scratch source | |
| (tapes source scratch destination base (encodeWord 0 ++ suffix) | |
| (List.replicate a true) (encodeWord value ++ output)) | |
| [] (encodeWord a ++ suffix) = | |
| tapes source scratch destination base (encodeWord a ++ suffix) [] (encodeWord value ++ output) := by | |
| funext k | |
| by_cases h₀ : k = source | |
| · subst k; simp [tapes, MachineCopy.forkTapes, Reduction.MachineTransfer.tapesAt, hs, hd] | |
| · by_cases h₁ : k = scratch | |
| · subst k | |
| simp [tapes, MachineCopy.forkTapes, Reduction.MachineTransfer.tapesAt, Ne.symm hs, hsd] | |
| · by_cases h₂ : k = destination | |
| · subst k | |
| simp [tapes, MachineCopy.forkTapes, Reduction.MachineTransfer.tapesAt, Ne.symm hd, Ne.symm hsd] | |
| · simp [tapes, MachineCopy.forkTapes, Reduction.MachineTransfer.tapesAt, h₀, h₁, h₂] | |
| theorem affineTrace (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (coefficient : Nat) (scanLabel restoreLabel : Λ) (exit : Option Λ) | |
| (program : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (atScan : program scanLabel = scan source scratch destination coefficient scanLabel restoreLabel) | |
| (atRestore : program restoreLabel = Reduction.MachineTransfer.loopAt | |
| scratch source id false restoreLabel exit) | |
| (base : K → List Bool) (a b : Nat) (suffix output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| (advance (TM2.step program))^[2 * (a + 1)] | |
| (some ⟨some scanLabel, (ambient,register), tapes source scratch destination base | |
| (encodeWord a ++ suffix) [] (encodeWord b ++ output)⟩) = | |
| some ⟨exit, (ambient,none), tapes source scratch destination base | |
| (encodeWord a ++ suffix) [] (encodeWord (coefficient * a + b) ++ output)⟩ := by | |
| have hscan := scanTrace source scratch destination hs hd hsd coefficient scanLabel restoreLabel | |
| program atScan base a b suffix [] output ambient register | |
| simp only [List.append_nil] at hscan | |
| let mid := tapes source scratch destination base (encodeWord 0 ++ suffix) | |
| (List.replicate a true) (encodeWord (coefficient * a + b) ++ output) | |
| have hrestore := Reduction.MachineTransfer.transferAt_fromTapes scratch source (Ne.symm hs) | |
| id false restoreLabel exit program atRestore mid ambient none | |
| change (advance (TM2.step program))^[(mid scratch).length + 1] | |
| (some ⟨some restoreLabel,(ambient,none),mid⟩) = _ at hrestore | |
| have hsaved : mid scratch = List.replicate a true := by | |
| simp [mid, tapes, hsd] | |
| have hsource : mid source = encodeWord 0 ++ suffix := by | |
| simp [mid, tapes, hs, hd] | |
| rw [hsaved, hsource] at hrestore | |
| simp only [List.length_replicate, List.reverse_replicate, List.map_id] at hrestore | |
| have hword : List.replicate a true ++ (encodeWord 0 ++ suffix) = encodeWord a ++ suffix := by | |
| simp [encodeWord, List.append_assoc] | |
| rw [hword] at hrestore | |
| simp only [mid, restoreTapes source scratch destination hs hd hsd] at hrestore | |
| rw [show 2 * (a + 1) = (a + 1) + (a + 1) by omega, Function.iterate_add_apply, hscan] | |
| exact hrestore | |
| def affineInTime (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (coefficient : Nat) (scanLabel restoreLabel : Λ) (exit : Option Λ) | |
| (program : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (atScan : program scanLabel = scan source scratch destination coefficient scanLabel restoreLabel) | |
| (atRestore : program restoreLabel = Reduction.MachineTransfer.loopAt | |
| scratch source id false restoreLabel exit) | |
| (base : K → List Bool) (a b : Nat) (suffix output : List Bool) | |
| (ambient : σ) (register : Option Bool) : | |
| StateTransition.EvalsToInTime (TM2.step program) | |
| ⟨some scanLabel, (ambient,register), tapes source scratch destination base | |
| (encodeWord a ++ suffix) [] (encodeWord b ++ output)⟩ | |
| (some ⟨exit, (ambient,none), tapes source scratch destination base | |
| (encodeWord a ++ suffix) [] (encodeWord (coefficient * a + b) ++ output)⟩) | |
| (2 * (a + 1)) where | |
| steps := 2 * (a + 1) | |
| evals_in_steps := affineTrace source scratch destination hs hd hsd coefficient scanLabel | |
| restoreLabel exit program atScan atRestore base a b suffix output ambient register | |
| steps_le_m := Nat.le_refl _ | |
| /-- Include the literal offset prefix. The caller supplies an arbitrary output | |
| suffix, not a precomputed address; all runtime arithmetic occurs on the tapes. -/ | |
| theorem seededAffineTrace (source scratch destination : K) | |
| (hs : source ≠ scratch) (hd : source ≠ destination) (hsd : scratch ≠ destination) | |
| (coefficient offset : Nat) (seedLabel scanLabel restoreLabel : Λ) (exit : Option Λ) | |
| (program : Λ → TM2.Stmt (Alphabet (K := K)) Λ (σ × Option Bool)) | |
| (atSeed : program seedLabel = seed destination offset scanLabel) | |
| (atScan : program scanLabel = scan source scratch destination coefficient scanLabel restoreLabel) | |
| (atRestore : program restoreLabel = Reduction.MachineTransfer.loopAt | |
| scratch source id false restoreLabel exit) | |
| (base : K → List Bool) (a : Nat) (suffix : List Bool) | |
| (sourceWord : base source = encodeWord a ++ suffix) (scratchEmpty : base scratch = []) | |
| (ambient : σ) (register : Option Bool) : | |
| (advance (TM2.step program))^[2 * (a + 1) + 1] | |
| (some ⟨some seedLabel, (ambient,register), base⟩) = | |
| some ⟨exit, (ambient,none), | |
| Function.update base destination (encodeWord (coefficient * a + offset) ++ base destination)⟩ := by | |
| have hseed : TM2.step program ⟨some seedLabel,(ambient,register),base⟩ = | |
| some ⟨some scanLabel,(ambient,register), | |
| Function.update base destination (encodeWord offset ++ base destination)⟩ := by | |
| change some (TM2.stepAux (program seedLabel) _ _) = _ | |
| rw [atSeed, seed, stepAux_pushWord] | |
| simp only [List.reverse_reverse, TM2.stepAux] | |
| have hrun := affineTrace source scratch destination hs hd hsd coefficient scanLabel restoreLabel | |
| exit program atScan atRestore base a offset suffix (base destination) ambient register | |
| have hframe (word : List Bool) : | |
| tapes source scratch destination base (encodeWord a ++ suffix) [] word = | |
| Function.update base destination word := by | |
| rw [← sourceWord, ← scratchEmpty] | |
| simp only [tapes, MachineCopy.forkTapes, Function.update_eq_self] | |
| rw [hframe, hframe] at hrun | |
| rw [Function.iterate_succ_apply] | |
| simp only [advance_some] | |
| rw [hseed] | |
| exact hrun | |
| inductive Label | |
| | seed | scan | restore | |
| deriving DecidableEq | |
| protected abbrev Label.enumList : List Label := [.seed, .scan, .restore] | |
| protected theorem Label.enumList_getElem?_ctorIdx_eq (x : Label) : | |
| Label.enumList[x.ctorIdx]? = some x := by | |
| cases x <;> rfl | |
| protected theorem Label.enumList_nodup : Label.enumList.Nodup := by decide | |
| instance : Fintype Label where | |
| elems := ⟨Label.enumList, Label.enumList_nodup⟩ | |
| complete x := by cases x <;> decide | |
| def program (source scratch destination : K) (coefficient offset : Nat) : | |
| Label → TM2.Stmt (Alphabet (K := K)) Label (σ × Option Bool) | |
| | .seed => seed destination offset .scan | |
| | .scan => scan source scratch destination coefficient .scan .restore | |
| | .restore => Reduction.MachineTransfer.loopAt scratch source id false .restore none | |
| def machine (coefficient offset : Nat) : FinTM2 where | |
| K := Fin 3 | |
| k₀ := 0 | |
| k₁ := 2 | |
| Γ _ := Bool | |
| Λ := Label | |
| main := .seed | |
| σ := Unit × Option Bool | |
| initialState := ((),none) | |
| m := program 0 1 2 coefficient offset | |
| end MaxCutGames.Foundations.Complexity.MachineUnaryAffineAt | |
| /-! A real finite program for uniform whole-instance copying. It reads three | |
| headers, physically multiplies the occurrence count by the fixed constant, | |
| copies the header-free body the same fixed number of times, and clears all | |
| working tapes. No input-dependent data are placed in finite control. -/ | |
| namespace MaxCutGames.Explicit.MachineUniformProgram | |
| open Turing MaxCutGames.Reduction | |
| open MaxCutGames.Foundations.Complexity MaxCutGames.Foundations.Hastad | |
| inductive Tape | |
| | input | vertices | alphabet | occurrences | newOccurrences | |
| | affineScratch | copyScratch | accumulator | output | |
| deriving DecidableEq | |
| protected abbrev Tape.enumList : List Tape := [.input, .vertices, .alphabet, .occurrences, | |
| .newOccurrences, .affineScratch, .copyScratch, .accumulator, .output] | |
| 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 | |
| abbrev State := MachineFieldTemplate.State Unit | |
| def initialState : State := (((), ()), none) | |
| def headerField : Fin 3 → Tape | |
| | 0 => .vertices | |
| | 1 => .alphabet | |
| | 2 => .occurrences | |
| def emitField : Fin 4 → Tape | |
| | 0 => .vertices | |
| | 1 => .alphabet | |
| | 2 => .newOccurrences | |
| | 3 => .input | |
| def tokens (C : Nat) : List (MachineFieldTemplate.Token 4) := | |
| [.copy 0, .copy 1, .copy 2] ++ List.replicate C (.copy 3) | |
| def clearKeys : List Tape := | |
| [.input, .vertices, .alphabet, .occurrences, .newOccurrences, | |
| .affineScratch, .copyScratch] | |
| inductive Label (C : Nat) | |
| | headerStart (i : Fin 3) | |
| | headerRead (i : Fin 3) | |
| | scale (phase : Fin 3) | |
| | emit (label : MachineFieldTemplate.Label (tokens C).length) | |
| | finishStart | |
| | finish (label : SourceRuntimeFinish.Label clearKeys) | |
| deriving DecidableEq, Fintype | |
| def headerNext {C : Nat} (i : Fin 3) : Label C := | |
| if h : i.val + 1 < 3 then .headerStart ⟨i.val + 1, h⟩ else .scale 0 | |
| def emitEntry (C : Nat) : Label C := | |
| .emit (MachineFieldTemplate.startAt (tokens C).length 0) | |
| def program (C : Nat) : Label C → TM2.Stmt (fun _ : Tape => Bool) (Label C) State | |
| | .headerStart i => SourceMachine.fieldStart (headerField i) (.headerRead i) | |
| | .headerRead i => SourceMachine.fieldLoop .input (headerField i) | |
| (.headerRead i) (some (headerNext i)) | |
| | .scale 0 => MachineUnaryAffineAt.seed .newOccurrences 0 (.scale 1) | |
| | .scale 1 => MachineUnaryAffineAt.scan .occurrences .affineScratch | |
| .newOccurrences C (.scale 1) (.scale 2) | |
| | .scale 2 => MachineTransfer.loopAt .affineScratch .occurrences id false | |
| (.scale 2) (some (emitEntry C)) | |
| | .emit label => MachineFieldTemplate.instruction (tokens C) emitField | |
| .copyScratch .accumulator Label.emit (some .finishStart) label | |
| | .finishStart => .load (fun _ => initialState) | |
| (MachineTransfer.exitAt .output (SourceRuntimeFinish.entry clearKeys Label.finish)) | |
| | .finish label => SourceRuntimeFinish.statement clearKeys .accumulator .output | |
| ((), ()) Label.finish none label | |
| def machine (C : Nat) : FinTM2 where | |
| K := Tape | |
| k₀ := .input | |
| k₁ := .output | |
| Γ _ := Bool | |
| Λ := Label C | |
| main := .headerStart 0 | |
| σ := State | |
| initialState := initialState | |
| m := program C | |
| theorem covers (k : Tape) (ha : k ≠ .accumulator) (ho : k ≠ .output) : | |
| k ∈ clearKeys := by | |
| cases k <;> simp_all [clearKeys] | |
| theorem accumulator_not_mem_clearKeys : Tape.accumulator ∉ clearKeys := by decide | |
| theorem output_not_mem_clearKeys : Tape.output ∉ clearKeys := by decide | |
| end MaxCutGames.Explicit.MachineUniformProgram | |
| /-! Exact execution of the three input-header reads of uniform copying. -/ | |
| namespace MaxCutGames.Explicit.MachineUniformHeaders | |
| open Turing | |
| open MaxCutGames.Foundations MaxCutGames.Foundations.Complexity | |
| open MaxCutGames.Foundations.Hastad | |
| open MachineUniformProgram | |
| def inputTapes (bits : List Bool) : Tape → List Bool := | |
| fun k => if k = .input then bits else [] | |
| def afterVertices (n : Nat) (rest : List Bool) : Tape → List Bool := | |
| fun k => if k = .input then rest else if k = .vertices then encodeWord n else [] | |
| def afterAlphabet (n q : Nat) (rest : List Bool) : Tape → List Bool := | |
| fun k => if k = .input then rest else if k = .vertices then encodeWord n | |
| else if k = .alphabet then encodeWord q else [] | |
| def resultTapes (n q Q : Nat) (body : List Bool) : Tape → List Bool := | |
| fun k => if k = .input then body else if k = .vertices then encodeWord n | |
| else if k = .alphabet then encodeWord q | |
| else if k = .occurrences then encodeWord Q else [] | |
| theorem initList_eq (C : Nat) (bits : List Bool) : | |
| initList (machine C) bits = | |
| ⟨some (.headerStart 0), initialState, inputTapes bits⟩ := by | |
| unfold initList | |
| congr 1 | |
| theorem first_result (n : Nat) (rest : List Bool) : | |
| SourceMachine.fieldTapes Tape.input .vertices | |
| (inputTapes (encodeWord n ++ rest)) rest | |
| (encodeWord n ++ inputTapes (encodeWord n ++ rest) .vertices) = | |
| afterVertices n rest := by | |
| funext k | |
| cases k <;> simp [SourceMachine.fieldTapes, inputTapes, afterVertices] | |
| theorem second_result (n q : Nat) (rest : List Bool) : | |
| SourceMachine.fieldTapes Tape.input .alphabet | |
| (afterVertices n (encodeWord q ++ rest)) rest | |
| (encodeWord q ++ afterVertices n (encodeWord q ++ rest) .alphabet) = | |
| afterAlphabet n q rest := by | |
| funext k | |
| cases k <;> simp [SourceMachine.fieldTapes, afterVertices, afterAlphabet] | |
| theorem third_result (n q Q : Nat) (body : List Bool) : | |
| SourceMachine.fieldTapes Tape.input .occurrences | |
| (afterAlphabet n q (encodeWord Q ++ body)) body | |
| (encodeWord Q ++ afterAlphabet n q (encodeWord Q ++ body) .occurrences) = | |
| resultTapes n q Q body := by | |
| funext k | |
| cases k <;> simp [SourceMachine.fieldTapes, afterAlphabet, resultTapes] | |
| /-- The input headers are consumed literally; all unread constraint bits retain | |
| their original order and no tape contains an implicit runtime number. -/ | |
| def headersInTime (C q n Q : Nat) (body : List Bool) : | |
| StateTransition.EvalsToInTime (machine C).step | |
| (initList (machine C) (encodeWords [n, q, Q] ++ body)) | |
| (some ⟨some (.scale 0), initialState, resultTapes n q Q body⟩) | |
| (n + q + Q + 6) := by | |
| have first := SourceMachine.fieldInTime Tape.input .vertices (by decide) | |
| (.headerStart 0 : Label C) (.headerRead 0) (some (.headerStart 1)) | |
| (program C) rfl rfl | |
| (inputTapes (encodeWord n ++ (encodeWord q ++ (encodeWord Q ++ body)))) n | |
| (encodeWord q ++ (encodeWord Q ++ body)) rfl ((), ()) none | |
| rw [first_result] at first | |
| have second := SourceMachine.fieldInTime Tape.input .alphabet (by decide) | |
| (.headerStart 1 : Label C) (.headerRead 1) (some (.headerStart 2)) | |
| (program C) rfl rfl (afterVertices n (encodeWord q ++ (encodeWord Q ++ body))) q | |
| (encodeWord Q ++ body) rfl ((), ()) none | |
| rw [second_result] at second | |
| have third := SourceMachine.fieldInTime Tape.input .occurrences (by decide) | |
| (.headerStart 2 : Label C) (.headerRead 2) (some (.scale 0)) | |
| (program C) rfl rfl (afterAlphabet n q (encodeWord Q ++ body)) Q body rfl ((), ()) none | |
| rw [third_result] at third | |
| have firstSecond := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ first second | |
| have whole := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ firstSecond third | |
| rw [initList_eq] | |
| simpa only [encodeWords, List.nil_append, List.append_assoc, machine, FinTM2.step, | |
| FinTM2.Cfg, initialState] | |
| using! ({ | |
| toEvalsTo := whole.toEvalsTo | |
| steps_le_m := by | |
| have bound := whole.steps_le_m | |
| omega } : StateTransition.EvalsToInTime (TM2.step (program C)) | |
| ⟨some (.headerStart 0), initialState, | |
| inputTapes (encodeWord n ++ (encodeWord q ++ (encodeWord Q ++ body)))⟩ | |
| (some ⟨some (.scale 0), initialState, resultTapes n q Q body⟩) | |
| (n + q + Q + 6)) | |
| theorem headers_budget (q n Q : Nat) (body : List Bool) : | |
| n + q + Q + 6 ≤ (encodeWords [n, q, Q] ++ body).length + 3 := by | |
| simp only [List.length_append, encodeWords_length, List.sum_cons, List.sum_nil, | |
| List.length_cons, List.length_nil] | |
| omega | |
| end MaxCutGames.Explicit.MachineUniformHeaders | |
| end OAI | |
Xet Storage Details
- Size:
- 24.8 kB
- Xet hash:
- 0ae5168dafea93dd8e738e3a55157e41273d5a309fad5ca70377581461df9686
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.