Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0cd989d
feat(Classes): define the polynomial hierarchy
BoltonBailey Jul 24, 2026
25c40dc
Merge remote-tracking branch 'origin/dev' into feat/polynomial-hierarchy
BoltonBailey Jul 25, 2026
4668c03
Merge remote-tracking branch 'origin/dev' into feat/polynomial-hierarchy
BoltonBailey Jul 25, 2026
8d5fb7e
Merge branch 'feat/bitstring-encoding' into feat/polynomial-hierarchy
BoltonBailey Aug 1, 2026
d2f939f
Merge branch 'feat/bitstring-encoding' (with dev) into feat/polynomia…
BoltonBailey Aug 14, 2026
f1c96d4
Merge branch 'feat/bitstring-encoding' (with dev) into feat/polynomia…
BoltonBailey Aug 14, 2026
e88f6f8
Merge branch 'feat/bitstring-encoding' into feat/polynomial-hierarchy
BoltonBailey Aug 14, 2026
5fa3dbb
Merge branch 'feat/bitstring-encoding' into feat/polynomial-hierarchy
BoltonBailey Aug 16, 2026
da19dcf
Merge branch 'feat/bitstring-encoding' into feat/polynomial-hierarchy
BoltonBailey Aug 16, 2026
0b2b8e2
feat(PH): state the Sipser-Lautemann theorem
BoltonBailey Aug 19, 2026
064579a
feat(PH): prove Sipser-Lautemann from one simulation interface
BoltonBailey Aug 19, 2026
1c3f232
feat(models): run one nondeterministic path from a choice tape
BoltonBailey Aug 19, 2026
1a677f7
feat(P): decide a language by a polynomial-time verdict function
BoltonBailey Aug 19, 2026
dd01f04
docs(roadmap): record the sharpened Sipser-Lautemann obligation
BoltonBailey Aug 19, 2026
1af04f8
feat(cobham): encode and iterate a nondeterministic path in the algebra
BoltonBailey Aug 19, 2026
0733312
feat(cobham): compute a nondeterministic path's verdict in the algebra
BoltonBailey Aug 19, 2026
8a53f56
feat(PH): close the pairFst seam, making the level inclusions uncondi…
BoltonBailey Aug 19, 2026
de8993f
feat(cobham): polynomial lengths, length tests, and exclusive-or in t…
BoltonBailey Aug 19, 2026
0f1f3be
feat(cobham): block loops for the amplified verdict
BoltonBailey Aug 19, 2026
dd35c35
feat(PH): prove the Sipser-Lautemann theorem
BoltonBailey Aug 19, 2026
af6a8d9
docs(PH): flag the Sipser-Lautemann development as unreviewed
BoltonBailey Aug 19, 2026
e511e68
Merge remote-tracking branch 'origin/dev' into boltonbailey-dev
BoltonBailey Aug 19, 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
2 changes: 2 additions & 0 deletions Complexitylib/Classes.lean
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public import Complexitylib.Classes.Randomized.PPoly
public import Complexitylib.Classes.Pairing
public import Complexitylib.Classes.FNP
public import Complexitylib.Classes.NP.Witness
public import Complexitylib.Classes.PH
public import Complexitylib.Classes.PH.SipserLautemann
public import Complexitylib.Classes.NP.Reduction
public import Complexitylib.Classes.NP.CoNP
public import Complexitylib.Classes.NP.Closure
Expand Down
4 changes: 4 additions & 0 deletions Complexitylib/Classes/P/Cobham/Internal.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ public import Complexitylib.Classes.P.Cobham.Internal.ConsBit
public import Complexitylib.Classes.P.Cobham.Internal.Reorder
public import Complexitylib.Classes.P.Cobham.Internal.Vec
public import Complexitylib.Classes.P.Cobham.Internal.Algebra
public import Complexitylib.Classes.P.Cobham.Internal.PolyLen
public import Complexitylib.Classes.P.Cobham.Internal.StringOps
public import Complexitylib.Classes.P.Cobham.Internal.Encoding
public import Complexitylib.Classes.P.Cobham.Internal.StepAlgebra
public import Complexitylib.Classes.P.Cobham.Internal.Simulate
public import Complexitylib.Classes.P.Cobham.Internal.ChoiceSim
public import Complexitylib.Classes.P.Cobham.Internal.BlockLoop
public import Complexitylib.Classes.P.Cobham.Internal.IterateLayout
public import Complexitylib.Classes.P.Cobham.Internal.Iterate
public import Complexitylib.Classes.P.Cobham.Internal.TakeLen
Expand Down
386 changes: 386 additions & 0 deletions Complexitylib/Classes/P/Cobham/Internal/BlockLoop.lean

Large diffs are not rendered by default.

594 changes: 594 additions & 0 deletions Complexitylib/Classes/P/Cobham/Internal/ChoiceSim.lean

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions Complexitylib/Classes/P/Cobham/Internal/PolyLen.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/-
Copyright (c) 2026 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey
-/
module
public import Complexitylib.Classes.P.Cobham.Internal.Algebra
public import Mathlib.Algebra.Polynomial.Eval.Degree

/-!
# Polynomial lengths inside the algebra

A computation in Cobham's algebra measures sizes by string lengths, so a
polynomial time or space bound has to be available as a *string of that
length*. `smash` multiplies lengths and concatenation adds them, so Horner's
scheme builds, for any polynomial with natural coefficients, a member of the
algebra whose output has exactly the polynomial's value as its length.

## Main definitions

- `Cobham.hornerEval` — Horner evaluation of a coefficient list
- `Cobham.lenOfCoeffs` — the string realizing that value as its length
- `Cobham.polyLen` — the same for a `Polynomial ℕ`

## Main results

- `Cobham.lenOfCoeffs_mem`, `Cobham.polyLen_mem` — both are in the algebra
- `Cobham.polyLen_length` — `polyLen q s` has length exactly `q.eval |s|`
-/

@[expose] public section

namespace Complexity

namespace Cobham

/-- Horner evaluation of a coefficient list, lowest coefficient first. -/
def hornerEval : List ℕ → ℕ → ℕ
| [], _ => 0
| a :: as, n => a + n * hornerEval as n

/-- The string whose length is the Horner value of the coefficient list at
`|s|`: constants contribute blocks of that many bits, and each multiplication
by `|s|` is one `smash`. -/
def lenOfCoeffs : List ℕ → List Bool → List Bool
| [], _ => []
| a :: as, s => List.replicate a false ++ Complexity.smash s (lenOfCoeffs as s)

@[simp] theorem lenOfCoeffs_length (as : List ℕ) (s : List Bool) :
(lenOfCoeffs as s).length = hornerEval as s.length := by
induction as with
| nil => rfl
| cons a as ih =>
rw [lenOfCoeffs, hornerEval, List.length_append, List.length_replicate,
smash_length, ih]

/-- **The Horner string is in the algebra.** -/
theorem lenOfCoeffs_mem {n : ℕ} (as : List ℕ)
{g : (Fin n → List Bool) → List Bool} (hg : Cobham g) :
Cobham fun v : Fin n → List Bool => lenOfCoeffs as (g v) := by
induction as with
| nil => exact (Cobham.const []).of_eq fun _ => rfl
| cons a as ih =>
exact (appendFn (Cobham.const (List.replicate a false))
(comp₂ Cobham.smash hg ih)).of_eq fun _ => by simp [lenOfCoeffs]

/-- Horner evaluation of a truncated coefficient sequence is the truncated
power sum. -/
theorem hornerEval_map_range (f : ℕ → ℕ) (d n : ℕ) :
hornerEval ((List.range d).map f) n = ∑ i ∈ Finset.range d, f i * n ^ i := by
induction d generalizing f with
| zero => rfl
| succ d ih =>
rw [List.range_succ_eq_map, List.map_cons, List.map_map, hornerEval,
ih (f ∘ Nat.succ), Finset.sum_range_succ' (fun i => f i * n ^ i) d]
simp only [Function.comp_apply, pow_zero, mul_one]
have hmul : n * ∑ i ∈ Finset.range d, f (i + 1) * n ^ i
= ∑ i ∈ Finset.range d, f (i + 1) * n ^ (i + 1) := by
rw [Finset.mul_sum]
exact Finset.sum_congr rfl fun i _ => by ring
rw [hmul]
omega

/-- The string realizing a polynomial's value as its length. -/
noncomputable def polyLen (q : Polynomial ℕ) (s : List Bool) : List Bool :=
lenOfCoeffs ((List.range (q.natDegree + 1)).map q.coeff) s

/-- **The polynomial's value is the string's length.** -/
@[simp] theorem polyLen_length (q : Polynomial ℕ) (s : List Bool) :
(polyLen q s).length = q.eval s.length := by
rw [polyLen, lenOfCoeffs_length, hornerEval_map_range, Polynomial.eval_eq_sum_range]

/-- **The polynomial-length string is in the algebra.** -/
theorem polyLen_mem {n : ℕ} (q : Polynomial ℕ)
{g : (Fin n → List Bool) → List Bool} (hg : Cobham g) :
Cobham fun v : Fin n → List Bool => polyLen q (g v) :=
lenOfCoeffs_mem _ hg

end Cobham

end Complexity
Loading