cfahlgren1/math / lean /OAI /Computability /MaxCut /Machines /RawInitialMachineModel.lean
cfahlgren1's picture
download
raw
50.1 kB
import Mathlib
import OAI.Computability.MaxCut.Machines.MachineInitialHeaders
import OAI.Computability.MaxCut.PCP.RawInitialPredicate
namespace OAI
namespace MaxCutGames.Foundations.PCP.RawInitialMachineModel
open Turing Complexity Hastad
inductive Tape
| input | «variables» | counter | index | field (slot : Fin 6)
| scratch | reversed | output
deriving DecidableEq, Fintype
abbrev Signs := Bool × Bool × Bool
abbrev State := Signs × Option Bool
abbrev Alphabet (_ : Tape) := Bool
inductive CopyPhase
| tailVariables (slot : Fin 3)
| tailIndex (slot : Fin 3)
| variableName (slot : Fin 3)
| reverseIndex (slot : Fin 3) (orientation : Bool)
| dummyVariables | dummyIndex | dummyReverse
deriving DecidableEq, Fintype
inductive Label
| headerStart (slot : Fin 2) | headerLoop (slot : Fin 2)
| scanN | restoreN | scanM1 | restoreM1 | closeFirst
| scanM6 | restoreM6 | closeSecond | initializeIndex | guard
| fieldStart (slot : Fin 6) | fieldLoop (slot : Fin 6) | loadSigns
| scan (phase : CopyPhase) | restore (phase : CopyPhase)
| closeTail (slot : Fin 3) (orientation : Bool)
| closeReverse (slot : Fin 3) (orientation : Bool)
| relation (slot : Fin 3) (orientation : Bool)
| cleanupField (slot : Fin 6) | incrementIndex
| closeDummyTail | closeDummyReverse | dummyRelation
| cleanupFinal (slot : Fin 3) | reset | finalReverse
deriving DecidableEq, Fintype
def initialState : State := ((false, false, false), none)
def stateKeys : List State :=
[false, true].flatMap fun a => [false, true].flatMap fun b =>
[false, true].flatMap fun c =>
[none, some false, some true].map fun register => ((a, b, c), register)
theorem stateKeys_complete (state : State) : state ∈ stateKeys := by
rcases state with ⟨⟨a, b, c⟩, register⟩
cases a <;> cases b <;> cases c <;> cases register with
| none => simp [stateKeys]
| some bit => cases bit <;> simp [stateKeys]
def nameField (slot : Fin 3) : Fin 6 := ⟨2 * slot.val, by omega⟩
def copySource : CopyPhase → Tape
| .tailVariables _ | .dummyVariables => .«variables»
| .variableName slot => .field (nameField slot)
| _ => .index
def copyScale : CopyPhase → Nat
| .reverseIndex _ _ | .dummyReverse => 6
| _ => 1
def copyNext : CopyPhase → Label
| .tailVariables slot => .scan (.tailIndex slot)
| .tailIndex slot => .closeTail slot false
| .variableName slot => .closeTail slot true
| .reverseIndex slot orientation => .closeReverse slot orientation
| .dummyVariables => .scan .dummyIndex
| .dummyIndex => .closeDummyTail
| .dummyReverse => .closeDummyReverse
def relationNext (slot : Fin 3) (orientation : Bool) : Label :=
if orientation then
if h : slot.val + 1 < 3 then .scan (.tailVariables ⟨slot.val + 1, h⟩)
else .cleanupField 0
else .scan (.variableName slot)
def finalTape (slot : Fin 3) : Tape :=
if slot.val = 0 then .«variables» else if slot.val = 1 then .counter else .index
def drain (tape : Tape) (again next : Label) : TM2.Stmt Alphabet Label State :=
MachineDrain.drain tape again (some next)
def headerTape (slot : Fin 2) : Tape := if slot.val = 0 then .«variables» else .counter
def relationOutput (slot : Fin 3) (orientation : Bool) (state : State) : List Bool :=
(encodeWords (RawInitialRows.relationWordsFor state.1
(RawInitialTables.slotOrder.symm slot) orientation)).reverse
def program : Label → TM2.Stmt Alphabet Label State
| .headerStart slot => SourceMachine.fieldStart (headerTape slot) (.headerLoop slot)
| .headerLoop slot => SourceMachine.fieldLoop .input (headerTape slot) (.headerLoop slot)
(if slot.val = 0 then some (.headerStart 1) else some .scanN)
| .scanN => MachineInitialHeaders.prefixScan .«variables» .scratch .reversed 1 .scanN .restoreN
| .restoreN => Reduction.MachineTransfer.loopAt .scratch .«variables» id false .restoreN (some .scanM1)
| .scanM1 => MachineInitialHeaders.prefixScan .counter .scratch .reversed 1 .scanM1 .restoreM1
| .restoreM1 => Reduction.MachineTransfer.loopAt .scratch .counter id false .restoreM1 (some .closeFirst)
| .closeFirst => Reduction.MachineSubstitution.pushWord .reversed [true, false]
(.goto fun _ => .scanM6)
| .scanM6 => MachineInitialHeaders.prefixScan .counter .scratch .reversed 6 .scanM6 .restoreM6
| .restoreM6 => Reduction.MachineTransfer.loopAt .scratch .counter id false .restoreM6 (some .closeSecond)
| .closeSecond => Reduction.MachineSubstitution.pushWord .reversed [true, false]
(.goto fun _ => .initializeIndex)
| .initializeIndex => .push .index (fun _ => false) (.goto fun _ => .guard)
| .guard => MachineUnaryCounter.guard .counter (.fieldStart 0) (.scan .dummyVariables)
| .fieldStart slot => SourceMachine.fieldStart (.field slot) (.fieldLoop slot)
| .fieldLoop slot => SourceMachine.fieldLoop .input (.field slot) (.fieldLoop slot)
(if h : slot.val + 1 < 6 then some (.fieldStart ⟨slot.val + 1, h⟩)
else some .loadSigns)
| .loadSigns =>
.peek (.field 1) (fun state head => ((head.getD false, state.1.2), state.2))
(.peek (.field 3) (fun state head => ((state.1.1, head.getD false, state.1.2.2), state.2))
(.peek (.field 5) (fun state head => ((state.1.1, state.1.2.1, head.getD false), state.2))
(.load (fun state => (state.1, none)) (.goto fun _ => .scan (.tailVariables 0)))))
| .scan phase => MachineInitialHeaders.prefixScan (copySource phase) .scratch .reversed
(copyScale phase) (.scan phase) (.restore phase)
| .restore phase => Reduction.MachineTransfer.loopAt .scratch (copySource phase) id false
(.restore phase) (some (copyNext phase))
| .closeTail slot orientation => .push .reversed (fun _ => false)
(.goto fun _ => .scan (.reverseIndex slot orientation))
| .closeReverse slot orientation => Reduction.MachineSubstitution.pushWord .reversed
(encodeWord (2 * slot.val + if orientation then 0 else 1))
(.goto fun _ => .relation slot orientation)
| .relation slot orientation => MachineFiniteTable.emit .reversed
(relationOutput slot orientation)
stateKeys (.goto fun _ => relationNext slot orientation)
| .cleanupField slot => drain (.field slot) (.cleanupField slot)
(if h : slot.val + 1 < 6 then .cleanupField ⟨slot.val + 1, h⟩ else .incrementIndex)
| .incrementIndex => .push .index (fun _ => true) (.goto fun _ => .guard)
| .closeDummyTail => .push .reversed (fun _ => false) (.goto fun _ => .scan .dummyReverse)
| .closeDummyReverse => .push .reversed (fun _ => false) (.goto fun _ => .dummyRelation)
| .dummyRelation => Reduction.MachineSubstitution.pushWord .reversed
(encodeWords (GraphTables.relationWords (GraphTables.relationOf (fun _ _ => true))))
(.goto fun _ => .cleanupFinal 0)
| .cleanupFinal slot => drain (finalTape slot) (.cleanupFinal slot)
(if h : slot.val + 1 < 3 then .cleanupFinal ⟨slot.val + 1, h⟩ else .reset)
| .reset => .load (fun _ => initialState) (.goto fun _ => .finalReverse)
| .finalReverse => Reduction.MachineTransfer.loopAt .reversed .output id false .finalReverse none
def machine : FinTM2 where
K := Tape
k₀ := .input
k₁ := .output
Γ := Alphabet
Λ := Label
main := .headerStart 0
σ := State
initialState := initialState
m := program
end MaxCutGames.Foundations.PCP.RawInitialMachineModel
/-!
Actual execution of the raw initial graph machine from its standard input
configuration to the first clause-loop guard. The unread clause bits are
preserved verbatim, and all tape contents at the boundary are explicit.
-/
namespace MaxCutGames.Foundations.PCP.RawInitialMachineStart
open Turing Complexity Hastad RawInitialMachineModel
def inputTapes (bits : List Bool) : Tape → List Bool
| .input => bits
| _ => []
private def firstTapes_inline_RawInitialMachineStart (n m : ℕ) (clauseBits : List Bool) : Tape → List Bool
| .input => encodeWord m ++ clauseBits
| .«variables» => encodeWord n
| _ => []
def counterTapes (n m : ℕ) (clauseBits : List Bool) : Tape → List Bool
| .input => clauseBits
| .«variables» => encodeWord n
| .counter => encodeWord m
| _ => []
private def headerTapes_inline_RawInitialMachineStart (n m : ℕ) (clauseBits : List Bool) : Tape → List Bool
| .input => clauseBits
| .«variables» => encodeWord n
| .counter => encodeWord m
| .reversed => (encodeWords [n + m + 1, 6 * m + 1]).reverse
| _ => []
/-- Complete machine frame at the first clause-loop guard. -/
def startTapes (n m : ℕ) (clauseBits : List Bool) : Tape → List Bool
| .input => clauseBits
| .«variables» => encodeWord n
| .counter => encodeWord m
| .index => [false]
| .reversed => (encodeWords [n + m + 1, 6 * m + 1]).reverse
| _ => []
theorem initList_eq (bits : List Bool) :
initList machine bits =
⟨some (.headerStart 0), initialState, inputTapes bits⟩ := by
unfold initList
congr 1
funext k
change Tape at k
cases k <;> rfl
private theorem trace_trans_inline_RawInitialMachineStart {α : Type*} (f : α → α) {a b : ℕ} {x y z : α}
(first : f^[a] x = y) (second : f^[b] y = z) : f^[a + b] x = z := by
rw [Nat.add_comm, Function.iterate_add_apply, first, second]
/-- The two actual header-field readers reach the prepared counter boundary. -/
theorem readCountersTrace (n m : ℕ) (clauseBits : List Bool) :
(MachineComposition.advance (TM2.step program))^[n + m + 4]
(some (initList machine (encodeWords [n, m] ++ clauseBits))) =
some ⟨some .scanN, initialState, counterTapes n m clauseBits⟩ := by
let t0 := inputTapes (encodeWords [n, m] ++ clauseBits)
have first := (SourceMachine.fieldInTime .input .«variables» (by decide)
(.headerStart 0) (.headerLoop 0) (some (.headerStart 1)) program rfl rfl
t0 n (encodeWord m ++ clauseBits)
(by simp [t0, inputTapes, encodeWords, List.append_assoc])
(false, false, false) none).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[n + 2]
(some ⟨some (.headerStart 0), initialState, t0⟩) = _ at first
have firstFrame : SourceMachine.fieldTapes .input .«variables» t0
(encodeWord m ++ clauseBits) (encodeWord n ++ t0 .«variables») =
firstTapes_inline_RawInitialMachineStart n m clauseBits := by
funext k
cases k <;> simp [SourceMachine.fieldTapes, t0, inputTapes, firstTapes_inline_RawInitialMachineStart]
rw [firstFrame] at first
have second := (SourceMachine.fieldInTime .input .counter (by decide)
(.headerStart 1) (.headerLoop 1) (some .scanN) program rfl rfl
(firstTapes_inline_RawInitialMachineStart n m clauseBits) m clauseBits rfl (false, false, false) none).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[m + 2]
(some ⟨some (.headerStart 1), initialState, firstTapes_inline_RawInitialMachineStart n m clauseBits⟩) = _ at second
have secondFrame : SourceMachine.fieldTapes .input .counter (firstTapes_inline_RawInitialMachineStart n m clauseBits)
clauseBits (encodeWord m ++ firstTapes_inline_RawInitialMachineStart n m clauseBits .counter) =
counterTapes n m clauseBits := by
funext k
cases k <;> simp [SourceMachine.fieldTapes, firstTapes_inline_RawInitialMachineStart, counterTapes]
rw [secondFrame] at second
have total := trace_trans_inline_RawInitialMachineStart _ first second
rw [show (n + 2) + (m + 2) = n + m + 4 by omega] at total
simpa only [initList_eq, t0, initialState] using! total
/-- Instantiation of the checked arithmetic phase in the actual global program. -/
theorem headersTrace (n m : ℕ) (clauseBits : List Bool) :
(MachineComposition.advance (TM2.step program))^[2 * n + 4 * m + 8]
(some ⟨some .scanN, initialState, counterTapes n m clauseBits⟩) =
some ⟨some .initializeIndex, initialState, headerTapes_inline_RawInitialMachineStart n m clauseBits⟩ := by
have h := MachineInitialHeaders.headerTrace .«variables» .counter .scratch .reversed
(by decide) (by decide) (by decide) (by decide) (by decide) (by decide)
.scanN .restoreN .scanM1 .restoreM1 .closeFirst .scanM6 .restoreM6 .closeSecond
(some .initializeIndex) program rfl rfl rfl rfl rfl rfl rfl rfl
(counterTapes n m clauseBits) n m [] []
(by simp [counterTapes]) (by simp [counterTapes]) rfl
(false, false, false) none
have frame : Function.update (counterTapes n m clauseBits) .reversed
((encodeWords [n + m + 1, 6 * m + 1]).reverse ++
counterTapes n m clauseBits .reversed) = headerTapes_inline_RawInitialMachineStart n m clauseBits := by
funext k
cases k <;> simp [counterTapes, headerTapes_inline_RawInitialMachineStart]
rw [frame] at h
exact h
theorem initializeIndexTrace (n m : ℕ) (clauseBits : List Bool) :
(MachineComposition.advance (TM2.step program))^[1]
(some ⟨some .initializeIndex, initialState, headerTapes_inline_RawInitialMachineStart n m clauseBits⟩) =
some ⟨some .guard, initialState, startTapes n m clauseBits⟩ := by
simp only [Function.iterate_one, MachineComposition.advance_some]
change some (TM2.stepAux (program .initializeIndex) initialState
(headerTapes_inline_RawInitialMachineStart n m clauseBits)) = _
simp only [program, TM2.stepAux]
congr 2
funext k
cases k <;> simp [headerTapes_inline_RawInitialMachineStart, startTapes]
/-- Exact startup trace for arbitrary encoded clause-tail data. -/
theorem startTrace (n m : ℕ) (clauseBits : List Bool) :
(MachineComposition.advance (TM2.step program))^[3 * n + 5 * m + 13]
(some (initList machine (encodeWords [n, m] ++ clauseBits))) =
some ⟨some .guard, initialState, startTapes n m clauseBits⟩ := by
have total := trace_trans_inline_RawInitialMachineStart _
(trace_trans_inline_RawInitialMachineStart _ (readCountersTrace n m clauseBits) (headersTrace n m clauseBits))
(initializeIndexTrace n m clauseBits)
simpa only [show (n + m + 4) + (2 * n + 4 * m + 8) + 1 =
3 * n + 5 * m + 13 by omega] using total
/-- Startup from the actual serialized CNF, with its untouched clause tail. -/
theorem formulaStartTrace (F : Target.Formula) :
(MachineComposition.advance (TM2.step program))^[
3 * F.«variables» + 5 * F.clauses.length + 13]
(some (initList machine (formulaBits F))) =
some ⟨some .guard, initialState,
startTapes F.«variables» F.clauses.length
(encodeWords (F.clauses.flatMap clauseWords))⟩ := by
simpa only [formulaBits, formulaWords, encodeWords_append] using
startTrace F.«variables» F.clauses.length (encodeWords (F.clauses.flatMap clauseWords))
def startInTime (n m : ℕ) (clauseBits : List Bool) :
StateTransition.EvalsToInTime (TM2.step program)
(initList machine (encodeWords [n, m] ++ clauseBits))
(some ⟨some .guard, initialState, startTapes n m clauseBits⟩)
(3 * n + 5 * m + 13) where
steps := 3 * n + 5 * m + 13
evals_in_steps := startTrace n m clauseBits
steps_le_m := Nat.le_refl _
def formulaStartInTime (F : Target.Formula) :
StateTransition.EvalsToInTime (TM2.step program) (initList machine (formulaBits F))
(some ⟨some .guard, initialState,
startTapes F.«variables» F.clauses.length
(encodeWords (F.clauses.flatMap clauseWords))⟩)
(3 * F.«variables» + 5 * F.clauses.length + 13) where
steps := 3 * F.«variables» + 5 * F.clauses.length + 13
evals_in_steps := formulaStartTrace F
steps_le_m := Nat.le_refl _
end MaxCutGames.Foundations.PCP.RawInitialMachineStart
/-! The exact input and output streams at successive clause-loop iterations.
These tape invariants use the actual word codecs and clause occurrence order. -/
namespace MaxCutGames.Foundations.PCP.RawInitialMachineLoopData
open Target Complexity RawInitialMachineModel
def clauseInput {n : Nat} (clauses : List (Clause n)) : List Bool :=
encodeWords (clauses.flatMap Complexity.clauseWords)
@[simp] theorem clauseInput_nil (n : Nat) : clauseInput ([] : List (Clause n)) = [] := rfl
@[simp] theorem clauseInput_cons {n : Nat} (c : Clause n) (cs : List (Clause n)) :
clauseInput (c :: cs) = encodeWords (Complexity.clauseWords c) ++ clauseInput cs := by
simp only [clauseInput, List.flatMap_cons, encodeWords_append]
def clauseOutput (n i : Nat) (clauses : List (Clause n)) : List Nat :=
(clauses.mapIdx fun offset c => RawInitialRows.clauseWords n (i + offset)
(RawInitialRows.clauseNames c) (RawInitialRows.clauseSigns c)).flatten
private theorem mapIdx_ofFn_inline_RawInitialMachineLoopData {α β : Type} (xs : List α) (f : Nat → α → β) :
xs.mapIdx f = List.ofFn (fun i : Fin xs.length => f i.val (xs.get i)) := by
induction xs generalizing f with
| nil => simp
| cons x xs ih => simp [ih]
@[simp] theorem clauseOutput_nil (n i : Nat) : clauseOutput n i [] = [] := rfl
@[simp] theorem clauseOutput_cons (n i : Nat) (c : Clause n) (cs : List (Clause n)) :
clauseOutput n i (c :: cs) =
RawInitialRows.clauseWords n i (RawInitialRows.clauseNames c)
(RawInitialRows.clauseSigns c) ++ clauseOutput n (i + 1) cs := by
simp only [clauseOutput, List.mapIdx_cons, Nat.add_zero, List.flatten_cons,
Nat.add_comm, Nat.add_left_comm]
theorem clauseOutput_numbered (F : Formula) :
clauseOutput F.«variables» 0 F.clauses =
(List.finRange F.clauses.length).flatMap (fun i =>
RawInitialRows.clauseWords F.«variables» i.val
(RawInitialRows.clauseNames (clauseAt F i))
(RawInitialRows.clauseSigns (clauseAt F i))) := by
simp only [clauseOutput, mapIdx_ofFn_inline_RawInitialMachineLoopData, List.ofFn_eq_map,
Nat.zero_add, clauseAt]
rfl
theorem tableWords_decomposition (F : Formula) :
GraphTables.tableWords (RawInitialTables.table F) =
[F.«variables» + F.clauses.length + 1, 6 * F.clauses.length + 1] ++
clauseOutput F.«variables» 0 F.clauses ++
RawInitialRows.dummyWords F.«variables» F.clauses.length := by
rw [RawInitialRows.tableWords_eq, clauseOutput_numbered]
def loopTapes (n i remaining : Nat) (input reversed : List Bool) : Tape → List Bool
| .input => input
| .«variables» => encodeWord n
| .counter => encodeWord remaining
| .index => encodeWord i
| .reversed => reversed
| _ => []
theorem startTapes_eq (n m : Nat) (input : List Bool) :
RawInitialMachineStart.startTapes n m input =
loopTapes n 0 m input (encodeWords [n + m + 1, 6 * m + 1]).reverse := by
funext tape
cases tape <;> rfl
theorem decrement_counter (n i remaining : Nat) (input reversed : List Bool) :
Function.update (loopTapes n i (remaining + 1) input reversed)
Tape.counter (encodeWord remaining) = loopTapes n i remaining input reversed := by
funext tape
cases tape <;> simp [loopTapes]
theorem increment_index (n i remaining : Nat) (input reversed : List Bool) :
Function.update (loopTapes n i remaining input reversed)
Tape.index (true :: encodeWord i) = loopTapes n (i + 1) remaining input reversed := by
funext tape
cases tape <;> simp [loopTapes, encodeWord, List.replicate_succ]
end MaxCutGames.Foundations.PCP.RawInitialMachineLoopData
/-! Actual execution of the raw initial graph program's reusable phases. -/
namespace MaxCutGames.Foundations.PCP.RawInitialMachinePhases
open Turing Complexity RawInitialMachineModel
theorem copySource_ne_scratch (phase : CopyPhase) : copySource phase ≠ Tape.scratch := by
cases phase <;> simp [copySource]
theorem copySource_ne_reversed (phase : CopyPhase) : copySource phase ≠ Tape.reversed := by
cases phase <;> simp [copySource]
def copyInTime (phase : CopyPhase) (base : Tape → List Bool)
(n : Nat) (suffix : List Bool)
(hsource : base (copySource phase) = encodeWord n ++ suffix)
(hscratch : base .scratch = []) (state : State) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some (.scan phase), state, base⟩
(some ⟨some (copyNext phase), (state.1, none),
Function.update base .reversed
(List.replicate (copyScale phase * n) true ++ base .reversed)⟩)
(2 * n + 2) :=
MachineInitialHeaders.prefixInTime (copySource phase) Tape.scratch Tape.reversed
(copySource_ne_scratch phase) (copySource_ne_reversed phase) (by decide)
(copyScale phase) (.scan phase) (.restore phase) (some (copyNext phase))
program rfl rfl base n suffix hsource hscratch state.1 state.2
def relationInTime (slot : Fin 3) (orientation : Bool)
(base : Tape → List Bool) (state : State) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some (.relation slot orientation), state, base⟩
(some ⟨some (relationNext slot orientation), state,
Function.update base .reversed
(relationOutput slot orientation state ++ base .reversed)⟩) 1 :=
MachineFiniteTable.emitInTime (K := Tape) (Λ := Label) (σ := State) (Γ := Alphabet)
Tape.reversed
(relationOutput slot orientation)
stateKeys stateKeys_complete program (.relation slot orientation)
(relationNext slot orientation) rfl state base
private theorem bitWord_head_inline_RawInitialMachinePhases (b : Bool) :
(encodeWord (if b then 1 else 0)).head? = some b := by
cases b <;> rfl
theorem loadSigns_step (base : Tape → List Bool) (a b c : Bool)
(ha : base (.field 1) = encodeWord (if a then 1 else 0))
(hb : base (.field 3) = encodeWord (if b then 1 else 0))
(hc : base (.field 5) = encodeWord (if c then 1 else 0)) (state : State) :
(TM2.step program) ⟨some .loadSigns, state, base⟩ =
some ⟨some (.scan (.tailVariables 0)), ((a, b, c), none), base⟩ := by
change some (TM2.stepAux (program .loadSigns) state base) = _
simp only [program, TM2.stepAux, ha, hb, hc, bitWord_head_inline_RawInitialMachinePhases, Option.getD_some]
def loadSignsInTime (base : Tape → List Bool) (a b c : Bool)
(ha : base (.field 1) = encodeWord (if a then 1 else 0))
(hb : base (.field 3) = encodeWord (if b then 1 else 0))
(hc : base (.field 5) = encodeWord (if c then 1 else 0)) (state : State) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some .loadSigns, state, base⟩
(some ⟨some (.scan (.tailVariables 0)), ((a, b, c), none), base⟩) 1 where
steps := 1
evals_in_steps := loadSigns_step base a b c ha hb hc state
steps_le_m := Nat.le_refl _
def cleanupFieldInTime (slot : Fin 6) (base : Tape → List Bool) (state : State) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some (.cleanupField slot), state, base⟩
(some ⟨some (if h : slot.val + 1 < 6 then .cleanupField ⟨slot.val + 1, h⟩
else .incrementIndex), (state.1, none), Function.update base (.field slot) []⟩)
((base (.field slot)).length + 1) :=
MachineDrain.drainInTime (.field slot) (.cleanupField slot) _ program rfl base state.1 state.2
def cleanupFinalInTime (slot : Fin 3) (base : Tape → List Bool) (state : State) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some (.cleanupFinal slot), state, base⟩
(some ⟨some (if h : slot.val + 1 < 3 then .cleanupFinal ⟨slot.val + 1, h⟩
else .reset), (state.1, none), Function.update base (finalTape slot) []⟩)
((base (finalTape slot)).length + 1) :=
MachineDrain.drainInTime (finalTape slot) (.cleanupFinal slot) _ program rfl base state.1 state.2
end MaxCutGames.Foundations.PCP.RawInitialMachinePhases
/-!
Read exactly one concrete six-field CNF clause in the actual global machine,
then execute its real sign-loading instruction. No extra finish transition
is inserted. Every unrelated tape and the unread input suffix are preserved.
-/
namespace MaxCutGames.Foundations.PCP.RawInitialMachineReadClause
open Turing Complexity Hastad RawInitialMachineModel
/-- The six actual serialized fields, in name/sign/name/sign/name/sign order. -/
def fieldValue {n : ℕ} (c : Target.Clause n) (j : Fin 6) : ℕ :=
(Complexity.clauseWords c)[j.val]'(by
rw [Complexity.clauseWords_length]
exact j.isLt)
/-- Full caller frame after the clause fields have been consumed. -/
def recordTapes {n : ℕ} (base : Tape → List Bool) (c : Target.Clause n)
(suffix : List Bool) : Tape → List Bool
| .input => suffix
| .field j => encodeWord (fieldValue c j)
| k => base k
@[simp] theorem recordTapes_input {n : ℕ} (base : Tape → List Bool)
(c : Target.Clause n) (suffix : List Bool) :
recordTapes base c suffix .input = suffix := rfl
@[simp] theorem recordTapes_field {n : ℕ} (base : Tape → List Bool)
(c : Target.Clause n) (suffix : List Bool) (j : Fin 6) :
recordTapes base c suffix (.field j) = encodeWord (fieldValue c j) := rfl
theorem recordTapes_other {n : ℕ} (base : Tape → List Bool)
(c : Target.Clause n) (suffix : List Bool) (k : Tape)
(hi : k ≠ .input) (hf : ∀ j, k ≠ .field j) :
recordTapes base c suffix k = base k := by
cases k <;> try rfl
· exact (hi rfl).elim
· exact (hf _ rfl).elim
@[simp] theorem recordTapes_name {n : ℕ} (base : Tape → List Bool)
(c : Target.Clause n) (suffix : List Bool) (j : Fin 3) :
recordTapes base c suffix (.field (nameField j)) =
encodeWord ((c)[j].variableIndex.val) := by
fin_cases j <;> rfl
private theorem trace_trans_inline_RawInitialMachineReadClause {α : Type*} (f : α → α) {a b : ℕ} {x y z : α}
(first : f^[a] x = y) (second : f^[b] y = z) : f^[a + b] x = z := by
rw [Nat.add_comm, Function.iterate_add_apply, first, second]
/-- Six actual field routines, stopping directly at the global sign loader. -/
theorem fieldsTrace {n : ℕ} (base : Tape → List Bool) (c : Target.Clause n)
(suffix : List Bool)
(hinput : base .input = encodeWords (Complexity.clauseWords c) ++ suffix)
(hempty : ∀ j, base (.field j) = []) (state : State) :
(MachineComposition.advance (TM2.step program))^[
(encodeWords (Complexity.clauseWords c)).length + 6]
(some ⟨some (.fieldStart 0), state, base⟩) =
some ⟨some .loadSigns, (state.1, none), recordTapes base c suffix⟩ := by
let a := fieldValue c 0
let b := fieldValue c 1
let d := fieldValue c 2
let e := fieldValue c 3
let f := fieldValue c 4
let g := fieldValue c 5
have hwords : Complexity.clauseWords c = [a, b, d, e, f, g] := rfl
have hin : base .input = encodeWord a ++ (encodeWords [b, d, e, f, g] ++ suffix) := by
rw [hinput, hwords]
simp only [encodeWords, List.append_assoc]
let t1 := SourceMachine.afterField .input (.field 0) base a
(encodeWords [b, d, e, f, g] ++ suffix)
let t2 := SourceMachine.afterField .input (.field 1) t1 b
(encodeWords [d, e, f, g] ++ suffix)
let t3 := SourceMachine.afterField .input (.field 2) t2 d
(encodeWords [e, f, g] ++ suffix)
let t4 := SourceMachine.afterField .input (.field 3) t3 e
(encodeWords [f, g] ++ suffix)
let t5 := SourceMachine.afterField .input (.field 4) t4 f
(encodeWords [g] ++ suffix)
let t6 := SourceMachine.afterField .input (.field 5) t5 g suffix
have h1 := (SourceMachine.fieldInTime .input (.field 0) (by decide)
(.fieldStart 0) (.fieldLoop 0) (some (.fieldStart 1)) program rfl rfl
base a (encodeWords [b, d, e, f, g] ++ suffix) hin state.1 state.2).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[a + 2]
(some ⟨some (.fieldStart 0), state, base⟩) =
some ⟨some (.fieldStart 1), (state.1, none), t1⟩ at h1
have h2 := (SourceMachine.fieldInTime .input (.field 1) (by decide)
(.fieldStart 1) (.fieldLoop 1) (some (.fieldStart 2)) program rfl rfl
t1 b (encodeWords [d, e, f, g] ++ suffix)
(by simp [t1, SourceMachine.afterField, encodeWords, List.append_assoc])
state.1 none).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[b + 2]
(some ⟨some (.fieldStart 1), (state.1, none), t1⟩) =
some ⟨some (.fieldStart 2), (state.1, none), t2⟩ at h2
have h3 := (SourceMachine.fieldInTime .input (.field 2) (by decide)
(.fieldStart 2) (.fieldLoop 2) (some (.fieldStart 3)) program rfl rfl
t2 d (encodeWords [e, f, g] ++ suffix)
(by simp [t2, SourceMachine.afterField, encodeWords, List.append_assoc])
state.1 none).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[d + 2]
(some ⟨some (.fieldStart 2), (state.1, none), t2⟩) =
some ⟨some (.fieldStart 3), (state.1, none), t3⟩ at h3
have h4 := (SourceMachine.fieldInTime .input (.field 3) (by decide)
(.fieldStart 3) (.fieldLoop 3) (some (.fieldStart 4)) program rfl rfl
t3 e (encodeWords [f, g] ++ suffix)
(by simp [t3, SourceMachine.afterField, encodeWords, List.append_assoc])
state.1 none).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[e + 2]
(some ⟨some (.fieldStart 3), (state.1, none), t3⟩) =
some ⟨some (.fieldStart 4), (state.1, none), t4⟩ at h4
have h5 := (SourceMachine.fieldInTime .input (.field 4) (by decide)
(.fieldStart 4) (.fieldLoop 4) (some (.fieldStart 5)) program rfl rfl
t4 f (encodeWords [g] ++ suffix)
(by simp [t4, SourceMachine.afterField, encodeWords, List.append_assoc])
state.1 none).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[f + 2]
(some ⟨some (.fieldStart 4), (state.1, none), t4⟩) =
some ⟨some (.fieldStart 5), (state.1, none), t5⟩ at h5
have h6 := (SourceMachine.fieldInTime .input (.field 5) (by decide)
(.fieldStart 5) (.fieldLoop 5) (some .loadSigns) program rfl rfl
t5 g suffix
(by simp [t5, SourceMachine.afterField, encodeWords])
state.1 none).evals_in_steps
change (MachineComposition.advance (TM2.step program))^[g + 2]
(some ⟨some (.fieldStart 5), (state.1, none), t5⟩) =
some ⟨some .loadSigns, (state.1, none), t6⟩ at h6
have total := trace_trans_inline_RawInitialMachineReadClause _ (trace_trans_inline_RawInitialMachineReadClause _ (trace_trans_inline_RawInitialMachineReadClause _
(trace_trans_inline_RawInitialMachineReadClause _ (trace_trans_inline_RawInitialMachineReadClause _ h1 h2) h3) h4) h5) h6
have htime : (((((a + 2) + (b + 2)) + (d + 2)) + (e + 2)) + (f + 2)) + (g + 2) =
(encodeWords (Complexity.clauseWords c)).length + 6 := by
rw [hwords, encodeWords_length]
simp
omega
rw [htime] at total
have frame : t6 = recordTapes base c suffix := by
funext k
cases k with
| field j =>
fin_cases j <;>
simp [t6, t5, t4, t3, t2, t1, SourceMachine.afterField, SourceMachine.fieldTapes,
recordTapes, hempty, a, b, d, e, f, g]
| _ =>
simp [t6, t5, t4, t3, t2, t1, SourceMachine.afterField, SourceMachine.fieldTapes,
recordTapes]
rw [frame] at total
exact total
theorem readClauseTrace {n : ℕ} (base : Tape → List Bool) (c : Target.Clause n)
(suffix : List Bool)
(hinput : base .input = encodeWords (Complexity.clauseWords c) ++ suffix)
(hempty : ∀ j, base (.field j) = []) (state : State) :
(MachineComposition.advance (TM2.step program))^[
(encodeWords (Complexity.clauseWords c)).length + 7]
(some ⟨some (.fieldStart 0), state, base⟩) =
some ⟨some (.scan (.tailVariables 0)), (RawInitialRows.clauseSigns c, none),
recordTapes base c suffix⟩ := by
have first := fieldsTrace base c suffix hinput hempty state
have last := RawInitialMachinePhases.loadSigns_step (recordTapes base c suffix)
(c)[0].positive (c)[1].positive (c)[2].positive rfl rfl rfl (state.1, none)
have lastTrace : (MachineComposition.advance (TM2.step program))^[1]
(some ⟨some .loadSigns, (state.1, none), recordTapes base c suffix⟩) =
some ⟨some (.scan (.tailVariables 0)), (RawInitialRows.clauseSigns c, none),
recordTapes base c suffix⟩ := last
have total := trace_trans_inline_RawInitialMachineReadClause _ first lastTrace
simpa only [show (encodeWords (Complexity.clauseWords c)).length + 6 + 1 =
(encodeWords (Complexity.clauseWords c)).length + 7 by omega] using total
def readClauseInTime {n : ℕ} (base : Tape → List Bool) (c : Target.Clause n)
(suffix : List Bool)
(hinput : base .input = encodeWords (Complexity.clauseWords c) ++ suffix)
(hempty : ∀ j, base (.field j) = []) (state : State) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some (.fieldStart 0), state, base⟩
(some ⟨some (.scan (.tailVariables 0)), (RawInitialRows.clauseSigns c, none),
recordTapes base c suffix⟩)
((encodeWords (Complexity.clauseWords c)).length + 7) where
steps := (encodeWords (Complexity.clauseWords c)).length + 7
evals_in_steps := readClauseTrace base c suffix hinput hempty state
steps_le_m := Nat.le_refl _
end MaxCutGames.Foundations.PCP.RawInitialMachineReadClause
/-! The six incidence rows are emitted by the actual finite program, with
their exact order, full relation lists, transition count, and tape frame. -/
namespace MaxCutGames.Foundations.PCP.RawInitialMachineRows
open Turing Complexity RawInitialMachineModel RawInitialMachinePhases
attribute [local irreducible] relationOutput RawInitialRows.relationWordsFor
private abbrev advance_inline_RawInitialMachineRows := MachineComposition.advance (TM2.step program)
def outputTapes (base : Tape → List Bool) (bits : List Bool) : Tape → List Bool :=
Function.update base .reversed (bits ++ base .reversed)
@[simp] theorem outputTapes_reversed (base : Tape → List Bool) (bits : List Bool) :
outputTapes base bits .reversed = bits ++ base .reversed := by simp [outputTapes]
theorem outputTapes_other (base : Tape → List Bool) (bits : List Bool)
(tape : Tape) (h : tape ≠ .reversed) : outputTapes base bits tape = base tape := by
simp [outputTapes, h]
@[simp] theorem outputTapes_twice (base : Tape → List Bool) (first second : List Bool) :
outputTapes (outputTapes base first) second = outputTapes base (second ++ first) := by
funext tape
by_cases h : tape = .reversed
· subst tape; simp [List.append_assoc]
· simp [outputTapes, h]
private theorem trace_trans_inline_RawInitialMachineRows {α : Type*} (f : α → α) {a b : ℕ} {x y z : α}
(first : f^[a] x = y) (second : f^[b] y = z) : f^[a + b] x = z := by
rw [Nat.add_comm, Function.iterate_add_apply, first, second]
private theorem copyTrace_inline_RawInitialMachineRows (phase : CopyPhase) (base : Tape → List Bool)
(n : ℕ) (hsource : base (copySource phase) = encodeWord n)
(hscratch : base .scratch = []) (signs : Signs) :
advance_inline_RawInitialMachineRows^[2 * n + 2] (some ⟨some (.scan phase), (signs, none), base⟩) =
some ⟨some (copyNext phase), (signs, none),
outputTapes base (List.replicate (copyScale phase * n) true)⟩ :=
(copyInTime phase base n [] (by simpa using hsource) hscratch (signs, none)).evals_in_steps
private theorem closeTailTrace_inline_RawInitialMachineRows (slot : Fin 3) (orientation : Bool)
(base : Tape → List Bool) (signs : Signs) :
advance_inline_RawInitialMachineRows^[1] (some ⟨some (.closeTail slot orientation), (signs, none), base⟩) =
some ⟨some (.scan (.reverseIndex slot orientation)), (signs, none),
outputTapes base [false]⟩ := by
change some (TM2.stepAux (program (.closeTail slot orientation)) (signs, none) base) = _
rfl
private theorem closeReverseTrace_inline_RawInitialMachineRows (slot : Fin 3) (orientation : Bool)
(base : Tape → List Bool) (signs : Signs) :
advance_inline_RawInitialMachineRows^[1] (some ⟨some (.closeReverse slot orientation), (signs, none), base⟩) =
some ⟨some (.relation slot orientation), (signs, none),
outputTapes base (encodeWord (2 * slot.val + if orientation then 0 else 1)).reverse⟩ :=
MachineInitialHeaders.literalTrace .reversed
(encodeWord (2 * slot.val + if orientation then 0 else 1))
(.closeReverse slot orientation) (some (.relation slot orientation))
program rfl base signs none
private theorem reverse_encodeWord_add_inline_RawInitialMachineRows (a b : ℕ) :
(encodeWord b).reverse ++ List.replicate a true = (encodeWord (a + b)).reverse := by
simp only [encodeWord, List.reverse_append, List.reverse_replicate, List.reverse_singleton]
rw [Nat.add_comm a b, List.replicate_add]
simp only [List.append_assoc]
def rowEndBits (slot : Fin 3) (orientation : Bool) (i : ℕ) (signs : Signs) : List Bool :=
relationOutput slot orientation (signs, none) ++
(encodeWord (6 * i + 2 * slot.val + if orientation then 0 else 1)).reverse ++ [false]
private theorem rowEndTrace_inline_RawInitialMachineRows (slot : Fin 3) (orientation : Bool) (base : Tape → List Bool)
(i : ℕ) (hindex : base .index = encodeWord i) (hscratch : base .scratch = [])
(signs : Signs) :
advance_inline_RawInitialMachineRows^[2 * i + 5] (some ⟨some (.closeTail slot orientation), (signs, none), base⟩) =
some ⟨some (relationNext slot orientation), (signs, none),
outputTapes base (rowEndBits slot orientation i signs)⟩ := by
let first := outputTapes base [false]
let second := outputTapes first (List.replicate (6 * i) true)
let third := outputTapes second
(encodeWord (2 * slot.val + if orientation then 0 else 1)).reverse
have h1 := closeTailTrace_inline_RawInitialMachineRows slot orientation base signs
have h2 := copyTrace_inline_RawInitialMachineRows (.reverseIndex slot orientation) first i
(by simpa [first, outputTapes, copySource] using hindex)
(by simpa [first, outputTapes] using hscratch) signs
change advance_inline_RawInitialMachineRows^[2 * i + 2]
(some ⟨some (.scan (.reverseIndex slot orientation)), (signs, none), first⟩) =
some ⟨some (.closeReverse slot orientation), (signs, none), second⟩ at h2
have h3 := closeReverseTrace_inline_RawInitialMachineRows slot orientation second signs
have h4 := (relationInTime slot orientation third (signs, none)).evals_in_steps
change advance_inline_RawInitialMachineRows^[1] (some ⟨some (.relation slot orientation), (signs, none), third⟩) =
some ⟨some (relationNext slot orientation), (signs, none),
outputTapes third (relationOutput slot orientation (signs, none))⟩ at h4
have total := trace_trans_inline_RawInitialMachineRows _ (trace_trans_inline_RawInitialMachineRows _ (trace_trans_inline_RawInitialMachineRows _ h1 h2) h3) h4
have hout : outputTapes third (relationOutput slot orientation (signs, none)) =
outputTapes base (rowEndBits slot orientation i signs) := by
simp only [third, second, first, outputTapes_twice]
apply congrArg (outputTapes base)
rw [reverse_encodeWord_add_inline_RawInitialMachineRows]
simp only [rowEndBits, Nat.add_assoc, List.append_assoc]
rw [hout] at total
simpa only [show 1 + (2 * i + 2) + 1 + 1 = 2 * i + 5 by omega] using total
private theorem rowEndBits_append_inline_RawInitialMachineRows (slot : Fin 3) (orientation : Bool)
(tail i : ℕ) (signs : Signs) :
rowEndBits slot orientation i signs ++ List.replicate tail true =
(encodeWords ([tail, 6 * i + 2 * slot.val + if orientation then 0 else 1] ++
RawInitialRows.relationWordsFor signs (RawInitialTables.slotOrder.symm slot) orientation)).reverse := by
simp only [rowEndBits, relationOutput, encodeWords_append, encodeWords,
List.append_nil, List.reverse_append, encodeWord,
List.reverse_replicate, List.reverse_singleton, List.append_assoc]
theorem falseRowTrace (slot : Fin 3) (base : Tape → List Bool) (n i : ℕ)
(names : RawInitialRows.Names) (signs : Signs)
(hvariables : base .«variables» = encodeWord n) (hindex : base .index = encodeWord i)
(hscratch : base .scratch = []) :
advance_inline_RawInitialMachineRows^[2 * n + 4 * i + 9]
(some ⟨some (.scan (.tailVariables slot)), (signs, none), base⟩) =
some ⟨some (.scan (.variableName slot)), (signs, none),
outputTapes base (encodeWords (RawInitialRows.incidenceWords n i names signs
(RawInitialTables.slotOrder.symm slot) false)).reverse⟩ := by
let first := outputTapes base (List.replicate n true)
let second := outputTapes first (List.replicate i true)
have h1 := copyTrace_inline_RawInitialMachineRows (.tailVariables slot) base n hvariables hscratch signs
have h2 := copyTrace_inline_RawInitialMachineRows (.tailIndex slot) first i
(by simpa [first, outputTapes, copySource] using hindex)
(by simpa [first, outputTapes] using hscratch) signs
simp only [copyScale, Nat.one_mul, copyNext] at h1 h2
change advance_inline_RawInitialMachineRows^[2 * n + 2]
(some ⟨some (.scan (.tailVariables slot)), (signs, none), base⟩) =
some ⟨some (.scan (.tailIndex slot)), (signs, none), first⟩ at h1
change advance_inline_RawInitialMachineRows^[2 * i + 2]
(some ⟨some (.scan (.tailIndex slot)), (signs, none), first⟩) =
some ⟨some (.closeTail slot false), (signs, none), second⟩ at h2
have h3 := rowEndTrace_inline_RawInitialMachineRows slot false second i
(by simpa [second, first, outputTapes] using hindex)
(by simpa [second, first, outputTapes] using hscratch) signs
have total := trace_trans_inline_RawInitialMachineRows _ (trace_trans_inline_RawInitialMachineRows _ h1 h2) h3
have hout : outputTapes second (rowEndBits slot false i signs) =
outputTapes base (encodeWords (RawInitialRows.incidenceWords n i names signs
(RawInitialTables.slotOrder.symm slot) false)).reverse := by
simp only [second, first, outputTapes_twice]
apply congrArg (outputTapes base)
rw [← List.replicate_add, Nat.add_comm i n, rowEndBits_append_inline_RawInitialMachineRows]
simp only [RawInitialRows.incidenceWords, Bool.false_eq_true, ↓reduceIte,
Equiv.apply_symm_apply]
rw [hout] at total
simpa only [relationNext, Bool.false_eq_true, ↓reduceIte,
show (2 * n + 2) + (2 * i + 2) + (2 * i + 5) = 2 * n + 4 * i + 9 by omega] using total
theorem trueRowTrace (slot : Fin 3) (base : Tape → List Bool) (n i : ℕ)
(names : RawInitialRows.Names) (signs : Signs)
(hname : base (.field (nameField slot)) =
encodeWord (RawInitialRows.nameWord names (RawInitialTables.slotOrder.symm slot)))
(hindex : base .index = encodeWord i) (hscratch : base .scratch = []) :
advance_inline_RawInitialMachineRows^[2 * RawInitialRows.nameWord names (RawInitialTables.slotOrder.symm slot) + 2 * i + 7]
(some ⟨some (.scan (.variableName slot)), (signs, none), base⟩) =
some ⟨some (relationNext slot true), (signs, none),
outputTapes base (encodeWords (RawInitialRows.incidenceWords n i names signs
(RawInitialTables.slotOrder.symm slot) true)).reverse⟩ := by
let value := RawInitialRows.nameWord names (RawInitialTables.slotOrder.symm slot)
let first := outputTapes base (List.replicate value true)
have h1 := copyTrace_inline_RawInitialMachineRows (.variableName slot) base value hname hscratch signs
simp only [copyScale, Nat.one_mul, copyNext] at h1
change advance_inline_RawInitialMachineRows^[2 * value + 2]
(some ⟨some (.scan (.variableName slot)), (signs, none), base⟩) =
some ⟨some (.closeTail slot true), (signs, none), first⟩ at h1
have h2 := rowEndTrace_inline_RawInitialMachineRows slot true first i
(by simpa [first, outputTapes] using hindex)
(by simpa [first, outputTapes] using hscratch) signs
have total := trace_trans_inline_RawInitialMachineRows _ h1 h2
have hout : outputTapes first (rowEndBits slot true i signs) =
outputTapes base (encodeWords (RawInitialRows.incidenceWords n i names signs
(RawInitialTables.slotOrder.symm slot) true)).reverse := by
simp only [first, outputTapes_twice, rowEndBits_append_inline_RawInitialMachineRows, value,
RawInitialRows.incidenceWords, ↓reduceIte, Equiv.apply_symm_apply]
rw [hout] at total
simpa only [value, show (2 * value + 2) + (2 * i + 5) = 2 * value + 2 * i + 7 by omega] using total
def pairWords (slot : Fin 3) (n i : ℕ) (names : RawInitialRows.Names)
(signs : Signs) : List ℕ :=
RawInitialRows.incidenceWords n i names signs (RawInitialTables.slotOrder.symm slot) false ++
RawInitialRows.incidenceWords n i names signs (RawInitialTables.slotOrder.symm slot) true
theorem pairTrace (slot : Fin 3) (base : Tape → List Bool) (n i : ℕ)
(names : RawInitialRows.Names) (signs : Signs)
(hvariables : base .«variables» = encodeWord n) (hindex : base .index = encodeWord i)
(hname : base (.field (nameField slot)) =
encodeWord (RawInitialRows.nameWord names (RawInitialTables.slotOrder.symm slot)))
(hscratch : base .scratch = []) :
advance_inline_RawInitialMachineRows^[2 * n + 6 * i +
2 * RawInitialRows.nameWord names (RawInitialTables.slotOrder.symm slot) + 16]
(some ⟨some (.scan (.tailVariables slot)), (signs, none), base⟩) =
some ⟨some (relationNext slot true), (signs, none),
outputTapes base (encodeWords (pairWords slot n i names signs)).reverse⟩ := by
let first := outputTapes base (encodeWords (RawInitialRows.incidenceWords n i names signs
(RawInitialTables.slotOrder.symm slot) false)).reverse
have h1 := falseRowTrace slot base n i names signs hvariables hindex hscratch
have h2 := trueRowTrace slot first n i names signs
(by simpa [first, outputTapes] using hname)
(by simpa [first, outputTapes] using hindex)
(by simpa [first, outputTapes] using hscratch)
have total := trace_trans_inline_RawInitialMachineRows _ h1 h2
simpa only [first, outputTapes_twice, pairWords, encodeWords_append, List.reverse_append,
show (2 * n + 4 * i + 9) +
(2 * RawInitialRows.nameWord names (RawInitialTables.slotOrder.symm slot) + 2 * i + 7) =
2 * n + 6 * i +
2 * RawInitialRows.nameWord names (RawInitialTables.slotOrder.symm slot) + 16 by omega]
using total
/-- Exact execution of all six incidence rows. Relation tables stay symbolic;
no entry is discarded and every non-output tape is preserved. -/
theorem rowsTrace (base : Tape → List Bool) (n i : ℕ)
(names : RawInitialRows.Names) (signs : Signs)
(hvariables : base .«variables» = encodeWord n) (hindex : base .index = encodeWord i)
(hname0 : base (.field 0) = encodeWord names.1)
(hname2 : base (.field 2) = encodeWord names.2.1)
(hname4 : base (.field 4) = encodeWord names.2.2)
(hscratch : base .scratch = []) :
advance_inline_RawInitialMachineRows^[6 * n + 18 * i + 2 * (names.1 + names.2.1 + names.2.2) + 48]
(some ⟨some (.scan (.tailVariables 0)), (signs, none), base⟩) =
some ⟨some (.cleanupField 0), (signs, none),
outputTapes base (encodeWords (RawInitialRows.clauseWords n i names signs)).reverse⟩ := by
let first := outputTapes base (encodeWords (pairWords 0 n i names signs)).reverse
let second := outputTapes first (encodeWords (pairWords 1 n i names signs)).reverse
have h0 := pairTrace 0 base n i names signs hvariables hindex hname0 hscratch
have h1 := pairTrace 1 first n i names signs
(by simpa [first, outputTapes] using hvariables)
(by simpa [first, outputTapes] using hindex)
(by simpa [first, outputTapes, nameField, RawInitialRows.nameWord,
RawInitialTables.slotOrder] using hname2)
(by simpa [first, outputTapes] using hscratch)
have h2 := pairTrace 2 second n i names signs
(by simpa [second, first, outputTapes] using hvariables)
(by simpa [second, first, outputTapes] using hindex)
(by simpa [second, first, outputTapes, nameField, RawInitialRows.nameWord,
RawInitialTables.slotOrder] using hname4)
(by simpa [second, first, outputTapes] using hscratch)
change advance_inline_RawInitialMachineRows^[2 * n + 6 * i + 2 * names.1 + 16]
(some ⟨some (.scan (.tailVariables 0)), (signs, none), base⟩) =
some ⟨some (.scan (.tailVariables 1)), (signs, none), first⟩ at h0
change advance_inline_RawInitialMachineRows^[2 * n + 6 * i + 2 * names.2.1 + 16]
(some ⟨some (.scan (.tailVariables 1)), (signs, none), first⟩) =
some ⟨some (.scan (.tailVariables 2)), (signs, none), second⟩ at h1
change advance_inline_RawInitialMachineRows^[2 * n + 6 * i + 2 * names.2.2 + 16]
(some ⟨some (.scan (.tailVariables 2)), (signs, none), second⟩) =
some ⟨some (.cleanupField 0), (signs, none),
outputTapes second (encodeWords (pairWords 2 n i names signs)).reverse⟩ at h2
have total := trace_trans_inline_RawInitialMachineRows _ (trace_trans_inline_RawInitialMachineRows _ h0 h1) h2
have hout : outputTapes second (encodeWords (pairWords 2 n i names signs)).reverse =
outputTapes base (encodeWords (RawInitialRows.clauseWords n i names signs)).reverse := by
simp only [second, first, outputTapes_twice, RawInitialRows.clauseWords,
encodeWords_append, List.reverse_append, pairWords, List.append_assoc]
rfl
rw [hout] at total
simpa only [show (2 * n + 6 * i + 2 * names.1 + 16) +
(2 * n + 6 * i + 2 * names.2.1 + 16) + (2 * n + 6 * i + 2 * names.2.2 + 16) =
6 * n + 18 * i + 2 * (names.1 + names.2.1 + names.2.2) + 48 by omega] using total
def rowsInTime (base : Tape → List Bool) (n i : ℕ)
(names : RawInitialRows.Names) (signs : Signs)
(hvariables : base .«variables» = encodeWord n) (hindex : base .index = encodeWord i)
(hname0 : base (.field 0) = encodeWord names.1)
(hname2 : base (.field 2) = encodeWord names.2.1)
(hname4 : base (.field 4) = encodeWord names.2.2)
(hscratch : base .scratch = []) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some (.scan (.tailVariables 0)), (signs, none), base⟩
(some ⟨some (.cleanupField 0), (signs, none),
outputTapes base (encodeWords (RawInitialRows.clauseWords n i names signs)).reverse⟩)
(6 * n + 18 * i + 2 * (names.1 + names.2.1 + names.2.2) + 48) where
steps := 6 * n + 18 * i + 2 * (names.1 + names.2.1 + names.2.2) + 48
evals_in_steps := rowsTrace base n i names signs hvariables hindex hname0 hname2 hname4 hscratch
steps_le_m := Nat.le_refl _
end MaxCutGames.Foundations.PCP.RawInitialMachineRows
end OAI

Xet Storage Details

Size:
50.1 kB
·
Xet hash:
52d1da5b144f9d6c6a78117a39288a362ffaedce19d5f57a30ecc2a09f4b5380

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.