Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
0c49ad9
feat(Combinators,Hoare,UTM): add seqTM, ifTM, loopTM combinators, Hoa…
SamuelSchlesinger Mar 14, 2026
6ed0592
feat(Hoare): add loopTM_hoareTime loop invariant rule
SamuelSchlesinger Mar 16, 2026
9f1d024
feat(Hoare): add complementTM and ifTM Hoare rules
SamuelSchlesinger Mar 16, 2026
82294a5
feat(Hoare): make ifTM_hoareTime fully compositional
SamuelSchlesinger Mar 16, 2026
01c8b8e
refactor(Combinators,Hoare): extract generic simulation and rewind in…
SamuelSchlesinger Mar 16, 2026
d849681
feat(UTM): add readCurrentTM scan proof and UTM scaffolding
SamuelSchlesinger Mar 17, 2026
b7a6857
feat(UTM): add initTM internals and fix lint warnings
SamuelSchlesinger Mar 18, 2026
1b7050d
added .claude/ to .gitignore
SamuelSchlesinger Mar 21, 2026
eb21acd
wip(UTM): partial phase1_loop proof with helpers and signature fixes
SamuelSchlesinger Mar 21, 2026
9a5df99
feat(UTM): complete phase1_loop proof for setupSim
SamuelSchlesinger Mar 21, 2026
d790ac3
feat(UTM): complete setupSim_phase12 proof
SamuelSchlesinger Mar 21, 2026
793bce3
fix(UTM): revert to clean phase1_loop baseline
SamuelSchlesinger Mar 21, 2026
7013468
feat(UTM): complete setupSim_phase12 proof (verified with lake)
SamuelSchlesinger Mar 22, 2026
d257e14
wip(UTM): rewindScratch_loop proved, phase3 helpers + suffices skeleton
SamuelSchlesinger Mar 22, 2026
0e1b3fd
prove stride_loop in SetupSim
CharlesCNorton Mar 22, 2026
5c61ea2
prove setupSim_phase3 nil case
CharlesCNorton Mar 22, 2026
fbf50ad
fix pre-existing omega bugs in suffices type, fix nil case
CharlesCNorton Mar 22, 2026
41677d5
fix suffices type omega bugs, streamline nil case
CharlesCNorton Mar 22, 2026
7ca02e8
prove cons case IH composition, factor one-bit cycle as hcycle sorry
CharlesCNorton Mar 22, 2026
ac84e74
factor one_bit_cycle theorem, prove cons case using it
CharlesCNorton Mar 22, 2026
ddf469f
add simTapeOffset_ne_of helper for nonlinear arithmetic
CharlesCNorton Mar 22, 2026
c632109
one_bit_cycle: prove all postconditions except bounce step and nonlin…
CharlesCNorton Mar 22, 2026
0fcadd8
one_bit_cycle: all postconditions proved, 3 mechanical step sorrys re…
CharlesCNorton Mar 22, 2026
3b8527a
prove bounce step, 2 mechanical step sorrys remain in one_bit_cycle
CharlesCNorton Mar 22, 2026
a2e1853
prove strideExtra steps, only hreach_a (3 write steps) and setupSimTM…
CharlesCNorton Mar 22, 2026
b7689ab
prove hreach_a (3 write steps), one_bit_cycle complete
CharlesCNorton Mar 22, 2026
852ba18
setupSimTM_hoareTime: fix precondition, prove core, 3 minor sorrys (I…
CharlesCNorton Mar 22, 2026
3285b3c
add head bounds to phase3/full_execution, 1 sorry remains (InitEnvelope)
CharlesCNorton Mar 22, 2026
e425592
SetupSim.lean: zero sorrys. All theorems fully proved.
CharlesCNorton Mar 22, 2026
5bc16f1
fix setupSimTM_hoareTime delegation after precondition change; initTM…
CharlesCNorton Mar 22, 2026
53135a1
initTM_hoareTime': fix precondition and bound, make copyInputToWorkTM…
CharlesCNorton Mar 22, 2026
c3271bf
initTM_hoareTime': fix type (existential bound, initTM_pre), make cop…
CharlesCNorton Mar 22, 2026
a66c8f9
initTM_hoareTime': begin seqTM composition, need invariant threading
CharlesCNorton Mar 22, 2026
e9a164d
initTM_hoareTime': working on composition
CharlesCNorton Mar 22, 2026
9985684
Merge pull request #4 from CharlesCNorton/feat/utm-sorry-elimination
SamuelSchlesinger Mar 23, 2026
2e7ea20
feat(utm): add rewindWorkTM_rich_hoareTime, fix readCurrentTM_hoareTi…
SamuelSchlesinger Mar 23, 2026
d94809f
feat(utm): prove extract_sim_conditions and all_tapes_simulation
SamuelSchlesinger Mar 23, 2026
d2b72d7
feat(utm): prove extract_sim_conditions, all_tapes_simulation, add he…
SamuelSchlesinger Mar 24, 2026
cd74731
feat(utm): add initTM composition infrastructure, fix initTM_hoareTim…
SamuelSchlesinger Mar 24, 2026
f8cb46f
feat(utm): prove rewind3_setupStateData_hoareTime, setupStateData_pre…
SamuelSchlesinger Mar 24, 2026
a4000dc
feat(utm): prove copyDataHead1_to_setupStatePre, close more sorry's
SamuelSchlesinger Mar 24, 2026
f1d8cae
feat(utm): fully prove rewind0_copyData_hoareTime, copyDataHead1_to_s…
SamuelSchlesinger Mar 24, 2026
933ef6f
feat(utm): fully prove rewind0_copyData_hoareTime with initTape cell …
SamuelSchlesinger Mar 24, 2026
666cee1
feat(utm): close h_copyData_env, prove setupStateDataHead1 bridge str…
SamuelSchlesinger Mar 24, 2026
b21ac06
feat(utm): close encodeUTMInput layout sorry's, add state head bound
SamuelSchlesinger Mar 24, 2026
7eb8a4b
feat(utm): close ALL sorry's in InitInternal.lean
SamuelSchlesinger Mar 24, 2026
19976af
feat(utm): close ALL sorry's in SetupState.lean idle tape preservation
SamuelSchlesinger Mar 24, 2026
b08fce0
feat(utm): strengthen all_tapes_simulation with per-cell values, expa…
SamuelSchlesinger Mar 24, 2026
c169050
feat(utm): close ALL sorry's in ExtractOutput.lean, expand Lookup/App…
SamuelSchlesinger Mar 24, 2026
322c969
fix(utm): correct lookupTM δ to preserve tape data via readBackWrite
SamuelSchlesinger Mar 24, 2026
0addc9c
feat(utm): add LookupInternal.lean with phase simulation framework
SamuelSchlesinger Mar 24, 2026
4e041b1
feat(utm): prove rewind loops and matchRewindR_step in LookupInternal
SamuelSchlesinger Mar 25, 2026
1677b75
feat(utm): close rewind loops and matchRewindR_step, fix scratch post…
SamuelSchlesinger Mar 25, 2026
773ed64
feat(utm): fix compare step verification with split_ifs
SamuelSchlesinger Mar 25, 2026
7f5bfab
feat(utm): close compare_match_loop, compare_mismatch, entry scan proofs
SamuelSchlesinger Mar 25, 2026
ebabcff
feat(utm): close ALL sorry's in LookupInternal.lean (2034 lines)
SamuelSchlesinger Mar 25, 2026
50f6100
feat(utm): add lookupTM_hoareTime composition scaffold with encoding …
SamuelSchlesinger Mar 25, 2026
1b105cd
feat(utm): close 3 mechanical sorry's, extend copyOutput_loop postcon…
SamuelSchlesinger Mar 25, 2026
4b3a13d
feat(utm): close matching entry and output bits encoding sorry's
SamuelSchlesinger Mar 25, 2026
2ac3e74
feat(utm): add allTuples_nodup scaffold, encoding helper infrastructure
SamuelSchlesinger Mar 25, 2026
da4f9a1
feat(utm): close all Phase 1 sorry's in ApplyTransitionInternal.lean
SamuelSchlesinger Mar 25, 2026
5cc5ab7
feat(utm): reconstruct Phase 2 proof, strengthen Phase 1 exports, wea…
SamuelSchlesinger Mar 25, 2026
a4840a6
feat(utm): strengthen Phase 1/2 exports, add super-cell encoding helpers
SamuelSchlesinger Mar 26, 2026
58f5fd5
feat(utm): strengthen lookup and applyTransition postconditions for c…
SamuelSchlesinger Mar 26, 2026
1fa8b4a
feat(utm): strengthen checkHalt postcondition with all-heads, inp, ou…
SamuelSchlesinger Mar 26, 2026
499fed0
feat: change initTape to head := 1, fix cascading proofs
SamuelSchlesinger Mar 26, 2026
34bafd2
Revert "feat: change initTape to head := 1, fix cascading proofs"
SamuelSchlesinger Mar 26, 2026
5aa3b12
feat(utm): add SimHeadsGe1 hypothesis to utm_simulates/utm_correct
SamuelSchlesinger Mar 26, 2026
5dbc142
feat(utm): fix checkHalt sorry, strengthen sub-machine postconditions
SamuelSchlesinger Mar 26, 2026
a9a28af
docs(utm): add proof strategy comments to utm_simulates/utm_correct
SamuelSchlesinger Mar 26, 2026
4300b6e
feat(utm): prove utm_body_step, utm_one_iteration, add scratch sentinels
SamuelSchlesinger Apr 3, 2026
143f1b4
feat(utm): add position-0 write skip to applyTransitionTM (WIP)
SamuelSchlesinger Apr 4, 2026
ae09e50
feat(utm): fix position-0 write skip in applyTransition proofs (WIP)
SamuelSchlesinger Apr 4, 2026
ff733bf
feat(utm): fix position-0 write skip in applyTransition, eliminate sorry
SamuelSchlesinger Apr 4, 2026
06a155f
feat(utm): remove simWork/simOut heads ≥ 1 precondition
SamuelSchlesinger Apr 4, 2026
4241ee7
feat(utm): prove utm_simulates, remove SimHeadsGe1 (1 sorry remains)
SamuelSchlesinger Apr 4, 2026
de5318f
chore(utm): clean up stale sorry references in comments
SamuelSchlesinger Apr 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.lake
arora-barak-draft.pdf
.claude/
23 changes: 23 additions & 0 deletions Complexitylib/Models.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,26 @@ import Complexitylib.Models.TuringMachine.Internal
import Complexitylib.Models.TuringMachine.Combinators
import Complexitylib.Models.TuringMachine.Combinators.Internal
import Complexitylib.Models.TuringMachine.Combinators.ComplementInternal
import Complexitylib.Models.TuringMachine.Combinators.SeqInternal
import Complexitylib.Models.TuringMachine.Combinators.IfInternal
import Complexitylib.Models.TuringMachine.Combinators.LoopInternal
import Complexitylib.Models.TuringMachine.Hoare
import Complexitylib.Models.TuringMachine.UTM.Defs
import Complexitylib.Models.TuringMachine.UTM.Helpers
import Complexitylib.Models.TuringMachine.UTM.HelpersInternal
import Complexitylib.Models.TuringMachine.UTM.SimConfig.Defs
import Complexitylib.Models.TuringMachine.UTM.Init.Defs
import Complexitylib.Models.TuringMachine.UTM.Init
import Complexitylib.Models.TuringMachine.UTM.InitInternal
import Complexitylib.Models.TuringMachine.UTM.InitInternal.Copy
import Complexitylib.Models.TuringMachine.UTM.InitInternal.Rewind
import Complexitylib.Models.TuringMachine.UTM.InitInternal.SetupState
import Complexitylib.Models.TuringMachine.UTM.InitInternal.SetupSim
import Complexitylib.Models.TuringMachine.UTM.ReadCurrent
import Complexitylib.Models.TuringMachine.UTM.ReadCurrentInternal
import Complexitylib.Models.TuringMachine.UTM.Lookup
import Complexitylib.Models.TuringMachine.UTM.ApplyTransition
import Complexitylib.Models.TuringMachine.UTM.CheckHalt
import Complexitylib.Models.TuringMachine.UTM.CheckHaltInternal
import Complexitylib.Models.TuringMachine.UTM.ExtractOutput
import Complexitylib.Models.TuringMachine.UTM.UTM
392 changes: 392 additions & 0 deletions Complexitylib/Models/TuringMachine/Combinators.lean

Large diffs are not rendered by default.

142 changes: 61 additions & 81 deletions Complexitylib/Models/TuringMachine/Combinators/ComplementInternal.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,22 @@ variable {n : ℕ}

namespace TM

-- ════════════════════════════════════════════════════════════════════════
-- Tape helpers
-- ════════════════════════════════════════════════════════════════════════

private theorem tape_move_cells (t : Tape) (d : Dir3) :
(t.move d).cells = t.cells := by cases d <;> rfl

private theorem readBackWrite_toΓ_eq' {g : Γ} (h : g ≠ Γ.start) :
(readBackWrite g).toΓ = g := by cases g <;> simp_all [readBackWrite, Γw.toΓ]

private theorem tape_write_head (t : Tape) (s : Γ) : (t.write s).head = t.head := by
simp only [Tape.write]; split <;> rfl

private theorem tape_head_writeAndMove_le (t : Tape) (s : Γ) (d : Dir3) :
(t.writeAndMove s d).head ≤ t.head + 1 := by
cases d <;> simp only [Tape.writeAndMove, Tape.move, tape_write_head] <;> omega

-- ════════════════════════════════════════════════════════════════════════
-- Configuration embedding
-- ════════════════════════════════════════════════════════════════════════

private def compCfg (tm : TM n) (c : Cfg n tm.Q) : Cfg n (tm.complementTM.Q) :=
def compCfg (tm : TM n) (c : Cfg n tm.Q) : Cfg n (tm.complementTM.Q) :=
{ state := Sum.inl c.state, input := c.input, work := c.work, output := c.output }

private theorem compCfg_initCfg (tm : TM n) (x : List Bool) :
theorem compCfg_initCfg (tm : TM n) (x : List Bool) :
compCfg tm (tm.initCfg x) = tm.complementTM.initCfg x := rfl

theorem compCfg_qstart (tm : TM n) (inp : Tape) (work : Fin n → Tape) (out : Tape) :
compCfg tm ⟨tm.qstart, inp, work, out⟩ =
⟨tm.complementTM.qstart, inp, work, out⟩ := rfl

-- ════════════════════════════════════════════════════════════════════════
-- Phase 1: Simulation
-- Phase 1: Simulation (via generic simulation lifting)
-- ════════════════════════════════════════════════════════════════════════

private theorem complementTM_step_sim (tm : TM n) {c c' : Cfg n tm.Q}
Expand All @@ -52,17 +39,57 @@ private theorem complementTM_step_sim (tm : TM n) {c c' : Cfg n tm.Q}
simp only [hne, hne2, ↓reduceIte, Option.some.injEq] at hstep ⊢
rw [← hstep]

private theorem complementTM_simulation (tm : TM n) {c c' : Cfg n tm.Q} {t : ℕ}
theorem complementTM_simulation (tm : TM n) {c c' : Cfg n tm.Q} {t : ℕ}
(hreach : tm.reachesIn t c c') :
tm.complementTM.reachesIn t (compCfg tm c) (compCfg tm c') := by
induction hreach with
| zero => exact .zero
| @step _ _ _ _ hstep _ ih => exact .step (complementTM_step_sim tm hstep) ih
tm.complementTM.reachesIn t (compCfg tm c) (compCfg tm c') :=
simulation_reachesIn (tm' := tm.complementTM) (compCfg tm)
(fun _ _ => complementTM_step_sim tm) hreach

-- ════════════════════════════════════════════════════════════════════════
-- Rewind loop (property-based, by induction on head position)
-- Rewind loop (via generic rewind)
-- ════════════════════════════════════════════════════════════════════════

/-- One rewind step: at head > 0, move left, preserve cells. -/
private theorem complement_rewind_step_left (tm : TM n) (c : Cfg n tm.complementTM.Q)
(hstate : c.state = Sum.inr ComplementPhase.rewind)
(hread_ne : c.output.read ≠ Γ.start)
(_ : c.output.cells 0 = Γ.start) (_ : ∀ j, j ≥ 1 → c.output.cells j ≠ Γ.start) :
∃ c', tm.complementTM.step c = some c' ∧
c'.state = Sum.inr ComplementPhase.rewind ∧
c'.output.head = c.output.head - 1 ∧
c'.output.cells = c.output.cells := by
simp only [TM.step, ↓reduceIte, hstate, complementTM, hread_ne]
refine ⟨_, rfl, rfl, ?_, ?_⟩
· simp only [Tape.writeAndMove, Tape.move]
rw [readBackWrite_toΓ_eq hread_ne]
simp only [Tape.write, Tape.read]; split
· omega
· simp
· simp only [Tape.writeAndMove, tape_move_cells]
rw [readBackWrite_toΓ_eq hread_ne]
simp only [Tape.write, Tape.read]; split
· rfl
· exact Function.update_eq_self _ _

/-- Base rewind step: at head = 0 (reading ▷), move right to cell 1, enter flip. -/
private theorem complement_rewind_step_base (tm : TM n) (c : Cfg n tm.complementTM.Q)
(hstate : c.state = Sum.inr ComplementPhase.rewind)
(hread : c.output.read = Γ.start)
(_ : c.output.cells 0 = Γ.start)
(hnostart : ∀ j, j ≥ 1 → c.output.cells j ≠ Γ.start) :
∃ c', tm.complementTM.step c = some c' ∧
c'.state = Sum.inr ComplementPhase.flip ∧
c'.output.head = 1 ∧
c'.output.cells = c.output.cells := by
have hhead : c.output.head = 0 := by
by_contra hne
have hge : c.output.head ≥ 1 := by omega
exact hnostart c.output.head hge (by simp only [Tape.read] at hread; exact hread)
simp only [TM.step, ↓reduceIte, hstate, complementTM, hread]
refine ⟨_, rfl, rfl, ?_, ?_⟩
· simp [Tape.writeAndMove, Tape.move, Tape.write, hhead]
· simp [Tape.writeAndMove, tape_move_cells, Tape.write, hhead]

/-- From rewind state with output head at position `h`, reach flip state
at cell 1 with output cells preserved, in `h + 1` steps. -/
private theorem rewind_loop (tm : TM n) :
Expand All @@ -75,62 +102,18 @@ private theorem rewind_loop (tm : TM n) :
tm.complementTM.reachesIn (h + 1) c c_flip ∧
c_flip.state = Sum.inr ComplementPhase.flip ∧
c_flip.output.head = 1 ∧
c_flip.output.cells = c.output.cells := by
intro h
induction h with
| zero =>
intro c hstate hcell0 _ hhead
-- Head at 0: output reads ▷ → rewind sees start → move right, enter flip
have hne : c.state ≠ Sum.inr ComplementPhase.done := by rw [hstate]; nofun
have hread : c.output.read = Γ.start := by simp [Tape.read, hhead, hcell0]
-- Compute step
have hstep : ∃ c', tm.complementTM.step c = some c' ∧
c'.state = Sum.inr ComplementPhase.flip ∧
c'.output.head = 1 ∧
c'.output.cells = c.output.cells := by
simp only [TM.step, ↓reduceIte, hstate, complementTM, hread]
refine ⟨_, rfl, rfl, ?_, ?_⟩
· simp [Tape.writeAndMove, Tape.move, Tape.write, hhead]
· simp [Tape.writeAndMove, tape_move_cells, Tape.write, hhead]
obtain ⟨c', hstep', hst', hh', hc'⟩ := hstep
exact ⟨c', .step hstep' .zero, hst', hh', hc'⟩
| succ h ih =>
intro c hstate hcell0 hnostart hhead
have hne : c.state ≠ Sum.inr ComplementPhase.done := by rw [hstate]; nofun
-- Head at h+1 ≥ 1: output reads non-▷ → move left
have hread_ne : c.output.read ≠ Γ.start := by
simp [Tape.read, hhead]; exact hnostart (h + 1) (by omega)
-- One step: state stays rewind, output head decreases, cells preserved
have hstep : ∃ c', tm.complementTM.step c = some c' ∧
c'.state = Sum.inr ComplementPhase.rewind ∧
c'.output.head = h ∧
c'.output.cells = c.output.cells := by
simp only [TM.step, ↓reduceIte, hstate, complementTM, hread_ne]
refine ⟨_, rfl, rfl, ?_, ?_⟩
· -- head: writeAndMove ... left → head - 1
simp only [Tape.writeAndMove, Tape.move]
rw [readBackWrite_toΓ_eq' hread_ne]
simp only [Tape.write]; split
· omega -- head = 0 contradicts hhead
· simp [hhead]
· -- cells preserved: writeAndMove readBackWrite left
simp only [Tape.writeAndMove, tape_move_cells]
rw [readBackWrite_toΓ_eq' hread_ne]
simp only [Tape.write]; split
· rfl -- head = 0: no-op
· exact Function.update_eq_self _ _
obtain ⟨c', hstep', hst', hh', hc'⟩ := hstep
obtain ⟨c_flip, hreach, hst_flip, hh_flip, hc_flip⟩ := ih c' hst'
(by rw [hc']; exact hcell0) (by intro j hj; rw [hc']; exact hnostart j hj) hh'
exact ⟨c_flip, .step hstep' hreach, hst_flip, hh_flip, by rw [hc_flip, hc']⟩
c_flip.output.cells = c.output.cells :=
generic_rewind_loop tm.complementTM
(fun c hst hread hc0 hns => complement_rewind_step_left tm c hst hread hc0 hns)
(fun c hst hread hc0 hns => complement_rewind_step_base tm c hst hread hc0 hns)

-- ════════════════════════════════════════════════════════════════════════
-- Combined: halt → rewind → flip → done
-- ════════════════════════════════════════════════════════════════════════

/-- From halted compCfg, reach done state with flipped output.
Takes ≤ `output.head + 4` steps. -/
private theorem complementTM_rewind_and_flip (tm : TM n)
theorem complementTM_rewind_and_flip (tm : TM n)
(c_halt : Cfg n tm.Q)
(hhalt : tm.halted c_halt)
(hcell0 : c_halt.output.cells 0 = Γ.start)
Expand All @@ -149,20 +132,18 @@ private theorem complementTM_rewind_and_flip (tm : TM n)
simp only [TM.step, ↓reduceIte, show (compCfg tm c_halt).state = Sum.inl c_halt.state from rfl,
complementTM, hhalt]
refine ⟨_, rfl, rfl, ?_, ?_⟩
· -- cells preserved
dsimp only [compCfg]
· dsimp only [compCfg]
simp only [Tape.writeAndMove, tape_move_cells]
by_cases hread : c_halt.output.read = Γ.start
· have hh0 : c_halt.output.head = 0 := by
have h := hread; simp only [Tape.read] at h
by_contra hne; exact hnostart _ (by omega) h
simp [Tape.write, hh0]
· rw [readBackWrite_toΓ_eq' hread]
· rw [readBackWrite_toΓ_eq hread]
simp only [Tape.write]; split
· rfl
· exact Function.update_eq_self _ _
· -- head ≤ original + 1
dsimp only [compCfg]
· dsimp only [compCfg]
exact tape_head_writeAndMove_le _ _ _
obtain ⟨c_rw, hstep1', hst_rw, hcells_rw, hhead_rw⟩ := hstep1
-- Step 2: rewind loop (c_rw.output.head + 1 steps)
Expand All @@ -188,7 +169,6 @@ private theorem complementTM_rewind_and_flip (tm : TM n)
simp [idleDir, hne1]
simp [hdir2, Function.update_self]
obtain ⟨c_done, hstep3', hst_done, hflip⟩ := hstep3
-- Compose: (head_rw + 1 + 1) + 1 ≤ (head + 1 + 1) + 1 = head + 3 + 1 ≤ head + 4
refine ⟨c_done, ((c_rw.output.head + 1) + 1) + 1,
reachesIn_trans tm.complementTM (.step hstep1' hreach_rw) (.step hstep3' .zero),
hst_done, hflip, by omega⟩
Expand Down
Loading
Loading