Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 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
fc8481b
feat(classes): add cryptographic primitives (BitEncodable, unpair, PP…
SamuelSchlesinger Mar 25, 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/
2 changes: 2 additions & 0 deletions Complexitylib/Classes.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ import Complexitylib.Classes.L
import Complexitylib.Classes.Exponential
import Complexitylib.Classes.DTISP
import Complexitylib.Classes.Containments
import Complexitylib.Classes.BitEncodable
import Complexitylib.Classes.PPTComputable
61 changes: 61 additions & 0 deletions Complexitylib/Classes/BitEncodable.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Complexitylib.Classes.Pairing

/-!
# Bit-string encoding typeclass

`BitEncodable α` provides a specification-level mapping between a type `α` and `List Bool`,
used to state that a Turing machine's bit-string I/O corresponds to a Lean function operating
on abstract types. The encoding carries **no computational obligation** — it is purely a
correspondence used in the *statements* of PPT predicates, not in any executed code.

## Main definitions

- `BitEncodable` — typeclass with `encode : α → List Bool`, `decode : List Bool → α`,
and a roundtrip proof
- Instances for `Unit`, `List Bool`, `Prod`, `Option`
-/

/-- Specification-level encoding of a type as bit strings.
Used to relate Turing machine I/O to Lean functions on abstract types.
The `decode` function is total: it returns a default value for invalid inputs.
Only the roundtrip property `decode (encode a) = a` is required. -/
class BitEncodable (α : Type) where
/-- Encode a value as a bit string. -/
encode : α → List Bool
/-- Decode a bit string to a value. Returns a default for invalid inputs. -/
decode : List Bool → α
/-- Decoding an encoded value recovers the original. -/
roundtrip : ∀ a, decode (encode a) = a

namespace BitEncodable

instance unit : BitEncodable Unit where
encode _ := []
decode _ := ()
roundtrip _ := rfl

instance listBool : BitEncodable (List Bool) where
encode := id
decode := id
roundtrip _ := rfl

/-- Encode `Option (List Bool)` as a bit string: `none ↦ [false]`,
`some x ↦ true :: x`. -/
instance optionListBool : BitEncodable (Option (List Bool)) where
encode
| none => [false]
| some x => true :: x
decode
| [] => none
| false :: _ => none
| true :: x => some x
roundtrip a := by cases a <;> simp

instance prod [BitEncodable α] [BitEncodable β] : BitEncodable (α × β) where
encode := fun (a, b) => pair (BitEncodable.encode a) (BitEncodable.encode b)
decode := fun bits =>
let (l, r) := unpair bits
(BitEncodable.decode l, BitEncodable.decode r)
roundtrip := fun (a, b) => by simp [unpair_pair, BitEncodable.roundtrip]

end BitEncodable
33 changes: 33 additions & 0 deletions Complexitylib/Classes/PPTComputable.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Complexitylib.Models.TuringMachine
import Complexitylib.Asymptotics
import Mathlib.Probability.ProbabilityMassFunction.Basic

/-!
# PPT-computable randomized functions

This file defines `PPTComputable`, a predicate asserting that a randomized function
`List Bool → PMF (List Bool)` is computable by a probabilistic polynomial-time
Turing machine. This bridges the gap between Lean-level probabilistic functions
(using `PMF`) and the NTM computation model (using `outputCount`).

## Main definitions

- `PPTComputable` — a randomized function is PPT-computable if there exists a PPT NTM
whose output distribution matches the function on all inputs
-/

open Complexity

/-- A randomized function `f : List Bool → PMF (List Bool)` is **PPT-computable**
if there exists a PPT NTM whose output distribution matches `f` on all inputs.

The output distribution of the NTM with time bound `T` is given by
`outputCount x T y / 2^T`, which must equal `(f x) y` for all inputs `x`
and outputs `y`. The time bound `T` must be polynomial: `T =O (· ^ d)`
for some degree `d`. -/
def PPTComputable (f : List Bool → PMF (List Bool)) : Prop :=
∃ (k : ℕ) (tm : NTM k) (T : ℕ → ℕ) (d : ℕ),
T =O (· ^ d) ∧
tm.AllPathsHaltIn T ∧
∀ x y,
(↑(tm.outputCount x (T x.length) y) : ENNReal) / ↑(2 ^ (T x.length)) = (f x) y
28 changes: 26 additions & 2 deletions Complexitylib/Classes/Pairing.lean
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,38 @@ search-problem classes.
def pair (x y : List Bool) : List Bool :=
(x.flatMap fun b => [b, b]) ++ [false, true] ++ y

private theorem pair_nil_eq (y : List Bool) :
@[simp]
theorem pair_nil_eq (y : List Bool) :
pair [] y = false :: true :: y := by
simp [pair]

private theorem pair_cons_eq (b : Bool) (x y : List Bool) :
@[simp]
theorem pair_cons_eq (b : Bool) (x y : List Bool) :
pair (b :: x) y = b :: b :: pair x y := by
simp [pair, List.append_assoc]

/-- Decode a paired binary string back into two components.
Left inverse of `pair`: `unpair (pair x y) = (x, y)`.
Returns `([], [])` for strings not in the image of `pair`. -/
def unpair : List Bool → List Bool × List Bool
| false :: false :: rest =>
let (x, y) := unpair rest
(false :: x, y)
| true :: true :: rest =>
let (x, y) := unpair rest
(true :: x, y)
| false :: true :: rest => ([], rest)
| _ => ([], [])

/-- `unpair` is a left inverse of `pair`. -/
@[simp]
theorem unpair_pair (x y : List Bool) : unpair (pair x y) = (x, y) := by
induction x with
| nil => rfl
| cons b x' ih =>
rw [pair_cons_eq]
cases b <;> simp only [unpair, ih]

/-- `pair` is injective: if `pair x₁ y₁ = pair x₂ y₂` then `x₁ = x₂` and `y₁ = y₂`. -/
theorem pair_injective {x₁ x₂ : List Bool} {y₁ y₂ : List Bool}
(h : pair x₁ y₁ = pair x₂ y₂) : x₁ = x₂ ∧ y₁ = y₂ := by
Expand Down
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
Loading
Loading