openAI-math-dataset / lean /OAI /Computability /BinPacking /PCP /RawInitialMachineLoop.lean
roseking's picture
Add lean source and binary files (part 59)
8df23f4 verified
Raw History Blame Contribute Delete
2.91 kB
import OAI.Computability.BinPacking.PCP.RawInitialMachineBody
import OAI.Computability.BinPacking.PCP.RawInitialMachineFinish
namespace OAI
namespace BinPackingGames.Foundations.PCP.RawInitialMachineLoop
open Turing Target Complexity RawInitialMachineModel RawInitialMachineLoopData
open RawInitialMachineBudget RawInitialMachineBody RawInitialMachineFinish
def finalSigns {n : Nat} (incoming : RawInitialMachineModel.Signs) :
List (Clause n) → RawInitialMachineModel.Signs
| [] => incoming
| c :: cs => finalSigns (RawInitialRows.clauseSigns c) cs
private theorem trace_trans {α : Type*} (f : α → α) {a b : Nat} {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]
theorem empty_loopTapes (n i : Nat) (rev : List Bool) :
loopTapes n i 0 [] rev = finishTapes n i rev := by
funext tape
cases tape <;> rfl
theorem loopTrace {n : Nat} (i : Nat) (cs : List (Clause n))
(rev : List Bool) (state : State) :
(MachineComposition.advance (TM2.step program))^[loopTime i cs]
(some ⟨some .guard, state, loopTapes n i cs.length (clauseInput cs) rev⟩) =
some ⟨some (.scan .dummyVariables), (finalSigns state.1 cs, none),
finishTapes n (i + cs.length) ((encodeWords (clauseOutput n i cs)).reverse ++ rev)⟩ := by
induction cs generalizing i rev state with
| nil =>
have h := RawInitialMachineBody.guardTrace_zero n i [] rev state
rw [empty_loopTapes] at h
simpa only [loopTime, List.length_nil, clauseInput_nil, clauseOutput_nil,
finalSigns, encodeWords, List.reverse_nil, List.nil_append, Nat.add_zero,
empty_loopTapes] using h
| cons c cs ih =>
have first := bodyTrace i cs.length c (clauseInput cs) rev state
have rest := ih (i + 1)
((encodeWords (RawInitialRows.clauseWords n i
(RawInitialRows.clauseNames c) (RawInitialRows.clauseSigns c))).reverse ++ rev)
(RawInitialRows.clauseSigns c, none)
have total := trace_trans _ first rest
have hi : i + 1 + cs.length = i + (cs.length + 1) := by omega
simpa only [loopTime, List.length_cons, clauseInput_cons, clauseOutput_cons,
encodeWords_append, List.reverse_append, List.append_assoc, finalSigns, hi] using total
def loopInTime {n : Nat} (i : Nat) (cs : List (Clause n))
(rev : List Bool) (state : State) :
StateTransition.EvalsToInTime (TM2.step program)
⟨some .guard, state, loopTapes n i cs.length (clauseInput cs) rev⟩
(some ⟨some (.scan .dummyVariables), (finalSigns state.1 cs, none),
finishTapes n (i + cs.length) ((encodeWords (clauseOutput n i cs)).reverse ++ rev)⟩)
(loopTime i cs) where
steps := loopTime i cs
evals_in_steps := loopTrace i cs rev state
steps_le_m := Nat.le_refl _
end BinPackingGames.Foundations.PCP.RawInitialMachineLoop
end OAI