[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"ubXasoBrPD":3},"# Complexitylib V1\n\n> **Current development takes place in\n> [Complexitylib](https://github.com/cslib-community/complexitylib).**\n> Please visit that repository for the latest work and contributions.\n\n[![CI](https://github.com/SamuelSchlesinger/complexitylib-v1/actions/workflows/lean_action_ci.yml/badge.svg)](https://github.com/SamuelSchlesinger/complexitylib-v1/actions/workflows/lean_action_ci.yml)\n\nThis repository preserves the original, API-incompatible V1 codebase and its\nhistory. Its Lake package is named `complexitylib-v1`, giving it the Reservoir\ncoordinate `@SamuelSchlesinger/complexitylib-v1`; its Lean imports remain\n`Complexitylib.*`. The current project is indexed as\n`@cslib-community/complexitylib`.\n\nA Lean 4 formalization of computational complexity theory, built on\n[Mathlib](https://github.com/leanprover-community/mathlib4). The machine\nmodel takes its shape from Arora and Barak's *Computational Complexity: A\nModern Approach*, but the library sets its own conventions — stated\nprecisely where they're used, with literature references where they help,\nand unafraid to diverge from any one text when a cleaner formalization\nexists.\n\n- 📖 **[API documentation](https://samuelschlesinger.github.io/complexitylib-v1/)** —\n  the full library, searchable, rebuilt on every merge to `dev`.\n- 🗺️ **[Blueprint](https://samuelschlesinger.github.io/complexitylib-v1/blueprint/)** —\n  what is formalized, what is planned, and how it all depends on each other.\n\n## Main results\n\nAll proved over a concrete multi-tape Turing-machine model; no declaration\ndepends on `sorry` or a custom axiom:\n\n- **Cook–Levin:** SAT and 3SAT are NP-complete.\n- **Cobham's theorem:** a machine-independent function algebra equals `FP`.\n- **Universal simulation:** one fixed machine simulates every machine through\n  the computable compiler `p ↦ ⟨α, p⟩`, reflecting halting and output, with\n  polynomial overhead.\n- **Deterministic time hierarchy** for clock-constructible bounds.\n- **Uniform circuits:** `P` equals logspace-uniform `P/poly`; `BPP ⊆ P/poly`.\n- **Space and interaction:** Savitch's theorem (`NPSPACE = PSPACE`),\n  `NL ⊆ P`, `PSPACE ⊆ EXP`, `IP ⊆ PSPACE`, `PH ⊆ PSPACE`, `PP ⊆ PSPACE`.\n- **The PCP theorem:** `NP = PCP(O(log n), O(1))`.\n- **Randomness:** Sipser–Lautemann (`BPP ⊆ Σ₂ᵖ ∩ Π₂ᵖ`), `BPP ⊆ PP`.\n- **Circuits:** Shannon's bounds, Schnorr's bound for parity, Valiant's depth\n  reduction, and Barrington's theorem (log-depth formulas and width-5\n  permutation branching programs decide the same families).\n- **Machine robustness:** the logarithmic-cost RAM and Turing machines define\n  the same `P`.\n- **CSLib interoperability:** our machines and CSLib's multi-tape machines\n  simulate each other with constant-factor time overhead, so `P` is exactly\n  CSLib's polynomial time. `DTIME`, `DTISP`, and `FP` transfer to CSLib's time\n  and space measures; the converse direction carries time only. CSLib's\n  regular languages are in `L`. Our circuits and CSLib's De Morgan circuits\n  translate into each other with linear overhead, which characterizes `P/poly`\n  in CSLib's model, shows it equal to the Boolean `P/poly` of the author's\n  CSLib circuit families (carried in `Complexitylib/Cslib` until they are\n  upstreamed), and brings Lupanov's `(1 + ε) 2ⁿ / n` upper bound into this\n  library.\n- **Algebraic circuits:** the algebraic-circuits library, imported as\n  `Complexitylib/Algebraic`, adds, in its own circuit and formula models, the\n  `3(n - 1)` De Morgan parity bound, parity ∉ AC⁰ by Håstad's switching lemma,\n  monotone CLIQUE, Nechiporuk's formula bound for rectangle-free families,\n  Karchmer–Wigderson, and a polynomial circuit-size hierarchy\n  ([guide](docs/algebraic/README.md)).\n\nThe blueprint links each result to its Lean statement and lists the\nconditional results (for example, `NL = coNL` from `NL ⊆ coNL`) separately\nfrom the unconditional ones.\n\n## Ethos\n\n**Statements you can audit, proofs you don't have to.** Every public theorem\nis stated so a reader can check it means what it claims — concrete machine\nmodel, explicit resource bounds, honest encodings — while the proof machinery\nlives out of sight in `Internal` modules whose correctness is the type\nchecker's job, not yours.\n\n**Concrete over abstract.** Machines, circuits, reductions, and encoders are\ngiven as concrete definitions rather than bare existence claims. Constructions\nparameterized by an abstract finite type may be noncomputable at Lean's\nmeta-level because choosing a canonical enumeration uses classical choice; the\nmachine or codec semantics remain explicit. Complexity is measured on real\nencodings; parsing, malformed inputs, and output conventions are explicit.\nConstructions expose an exact resource bound first and an asymptotic corollary\nsecond.\n\n**Nothing on faith.** No declaration depends on `sorry` or a custom axiom:\n`scripts/AxiomGuard.lean` mechanically audits every declaration compiled from\nComplexitylib modules for dependencies beyond Lean's three standard axioms,\nand CI enforces it — along with Mathlib's style and environment linters — on\nevery push. No declaration depends on `native_decide`: the executable\nvalidation modules, outside the public import graph, use it only in\n`example`s as regression tests, and the style linter rejects it everywhere\nelse. The audit trusts the compiled `.olean` files and allows\n`Classical.choice`, so claims that a function is computable rest on the\nmachine semantics; its header documents its scope.\n\n**AI-assisted development.** This project uses AI coding assistants for proof\ndevelopment, refactoring, documentation, and research exploration. AI-assisted\nchanges are held to the same standards as every other contribution: the public\nstatements must be auditable, Lean's kernel must check the proofs, and the full\nbuild, linter, validation, and axiom-audit gates must pass. No mathematical\nclaim is accepted on the authority of an AI system.\n\n## How to read the library\n\nEverything lives in the `Complexity` root namespace and splits into areas,\neach with its own entry module:\n\n| Area | Import | What it is |\n| --- | --- | --- |\n| Machine models | `Complexitylib.Models` | Arora–Barak multi-tape Turing machines — deterministic, nondeterministic, probabilistic — and everything built from them: combinators, simulations, universal machines |\n| Encodings | `Complexitylib.Encoding` | Machine-independent self-delimiting blocks, pairing, and rose-tree data encodings |\n| Asymptotics | `Complexitylib.Asymptotics` | `=O`/`=o` notation on `ℕ → ℕ`, bridging to Mathlib's asymptotics |\n| Time bounds | `Complexitylib.TimeConstructible` | Time-constructible bounds for hierarchy and separation results |\n| Complexity classes | `Complexitylib.Classes` | `P`, `NP`, `BPP`, `PSPACE`, and friends; containments, closure properties, reductions, and the time-hierarchy theorem |\n| SAT | `Complexitylib.SAT` | CNF semantics and encoding, a verified SAT verifier, and the Cook–Levin theorem: `SAT` is NP-complete |\n| Circuits | `Complexitylib.Circuits` | Boolean circuits with size and depth, circuit families, `P/poly`, normal forms, classical lower bounds, and frontier-method lower bounds from graph layouts over any alphabet, basis, and fan-in |\n| Boolean analysis | `Complexitylib.BooleanAnalysis` | Fourier expansion, noise stability, and influence for Boolean functions; exponential correlation bounds against low-degree binary polynomials; Korten's harmonic-mean transform and mirror sets for top-down lower bounds |\n| Descriptive complexity | `Complexitylib.DescriptiveComplexity` | Finite structures, first- and second-order logic, definability, and model checking |\n| Languages | `Complexitylib.Languages` | Concrete decidable languages exercising the machine API end to end |\n| Mathlib prelude | `Complexitylib.Mathlib` | Extensions to Mathlib types in their home namespaces; candidates for upstreaming |\n\nWithin an area, modules follow one discipline:\n\n- **`Foo/Defs.lean`** — definitions. Short, minimally-imported, auditable.\n- **`Foo.lean`** — the surface: theorem statements worth reading.\n- **`Foo/Internal…`** — proof machinery. Skip it; the type checker read it.\n\nSo: import `Complexitylib` (or one area), read `Defs` and surface files, and\ntrust the kernel for the rest. Headline results — Cook–Levin, universal-machine\nsimulation with explicit overhead, the deterministic time hierarchy — are\nindexed in the root module `Complexitylib.lean` and mechanically guarded in `scripts/AxiomGuard.lean`.\n\n## Building\n\nInstall [elan](https://github.com/leanprover/elan); Lean and Mathlib versions\nare pinned (currently Lean v4.35.0-rc3, tracking the [cslib](https://github.com/leanprover/cslib) toolchain).\n\n```bash\nlake build --wfail\n```\n\nCI additionally runs five executable regression suites and five quality gates;\nsee [CONTRIBUTING.md](CONTRIBUTING.md) for the full list and the style guide.\nAPI documentation builds with doc-gen4 from `docbuild/` and publishes to\n[GitHub Pages](https://samuelschlesinger.github.io/complexitylib-v1/) on every\nmerge to `dev` (and weekly, plus on demand via the workflow).\n\n## Contributing\n\nThe [blueprint](https://samuelschlesinger.github.io/complexitylib-v1/blueprint/)\nshows which planned results are ready to work on; its sources are in\n[`blueprint/`](blueprint/). [ROADMAP.md](ROADMAP.md) covers how to prove things\nhere and the infrastructure priorities. [CONTRIBUTING.md](CONTRIBUTING.md)\ncovers style, layering, naming, and commit conventions. Design notes for the\nlarger completed constructions live in `docs/`.\n\nTo cite Complexitylib, see [CITATION.cff](CITATION.cff).\n\n## License\n\nLicensed under the [Apache License, Version 2.0](LICENSE).\nThe imported algebraic-circuits library in `Complexitylib/Algebraic/` keeps\nits original [MIT license](Complexitylib/Algebraic/LICENSE).\n",1792957673566]