Skip to content
Caliko06Public

About

Open-source framework for pequalnp.com circuit-complexity units: 21 deterministic solvers (C/C++, Python) find minimum Boolean circuits and lower-bound certificates, emit Lean 4 proofs, check them with the Lean kernel and open the PR. Per-solver docs, templates, measured times.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Zama: deterministic Lean 4 proof engine for pequalnp.com circuit-complexity theorems

CI Release License: MIT Python 3.10+ Lean 4

Zama is an open-source framework for the Boolean circuit-complexity units of pequalnp.com. For each unit it finds the circuit or the lower-bound certificate, writes the Lean 4 proof, checks it with the Lean kernel on your machine and opens the pull request, without an LLM in the loop. It ships 21 solvers; docs/SOLVERS.md explains what each one proves, how, which Lean template it uses and how long it takes.

What Zama is (and is not)

pequalnp.com is an open, collaborative attack on circuit lower bounds related to P vs NP. Its desk splits the work into thousands of small Lean 4 units: "this 6-input function needs exactly k AND/OR/NOT gates", "no circuit of at most k gates computes this 5x5 table", and so on. Each accepted proof is merged into open-goat/pequalnp-proofs and earns points.

  • Zama is an exact-synthesis and certificate engine for those units: native C/C++ search (iterative deepening, CGP, frontier BFS, SAT where useful) finds the optimal circuit and the lower-bound certificate, a family template turns it into a Lean 4 file, and the official checker (tools/pnp.sh check) must accept it before anything is sent.
  • Zama is not a proof of P vs NP, and it does not prove arbitrary theorems. It covers the theorem families it has a solver for (21 today, listed below); everything else is skipped, never guessed.
  • No AI is required. Every solver is deterministic and runs offline at $0. An LLM adapter exists only as an optional helper for drafting a solver when a new family appears.

How a unit flows

desk board ──▶ match a solver ──▶ solve (C/C++) ──▶ emit .lean ──▶ prelint ──▶ Lean kernel check ──▶ PR
                     │ no match: skip                 │ fail: record, never send
                     └─ desk gate: skip units already proved, reserved or with an open PR

Details, failure modes and debug commands: docs/ARCHITECTURE.md.

Measured, reproducible

What Result Evidence
10 value6 units (exact 6-input circuit size) 10/10 solved and pre-linted in 12.0 s vs 501.1 s for the SAT baseline (0/10), 41.8x make bench on Apple M4, 2026-12-03
Lean kernel every proof is checked locally (lake env lean) before a PR; typical 10-25 s per unit ./zama verify --standalone
Clean clone build + 54 tests + one full Lean check from a fresh clone make verify
Token cost 0 tokens for every supported family no network call besides the desk and GitHub

Who Is Zama For?

  • pequalnp.com contributors who want to go from zero to verified, merged Lean 4 PRs in 3 minutes — on a single Mac/Linux machine or across an SSH fleet.
  • Lean 4 & formal verification engineers looking for reusable kernel-checked Boolean circuit lower-bound templates (LowU, ExactFront, bitLane DAGs, noptNB, rootFree_split).
  • AI + math researchers who want a reproducible, zero-dependency harness where deterministic math engines handle bulk proving and LLMs are reserved for discovering new solver families.

Quickstart (3 Minutes)

  1. Clone your fork of pequalnp and set up Lean 4 once:
    git clone https://github.com/<you>/pequalnp ../pequalnp
    (cd ../pequalnp && tools/pnp.sh setup)
  2. Initialize Zama, compile native solvers, and verify your setup:
    make init          # creates .env from .env.example — set PNP_REPO and PNP_HANDLE
    make build         # compiles all native C/C++20 solvers under solvers/
    make test          # runs the full 50-test unit & integration suite
    make bench         # runs the reproducible 10-unit value6 benchmark (~10.6s)
    make doctor        # checks python3, c++, lake, gh, upstream repo, and solvers
  3. Run a local Lean 4 verification on the included fixture (no account or lease needed):
    make verify-fixture
  4. Launch the full autonomous stack in one command:
    ./zama ship                  # dry-run + live TUI (verifies locally, no PRs)
    ./zama ship --submit         # live autonomous mode (verifies + opens PRs)
    ./zama ship --submit --detach # unattended overnight mode (auto-caffeinate on macOS)
  5. Control or inspect anytime:
    ./zama ui                    # attach live terminal dashboard (or --snapshot)
    ./zama stealth on|off        # pause/resume proving while monitors stay active
    ./zama vigia --once          # check board status and new waves
    ./zama fleet                 # check single-machine vs multi-node SSH fleet
    ./zama stop                  # stop detached supervisor cleanly

How It Works (Zero to Merged PRs)

pequalnp.com (/desk/board + tools/pnp.sh)
        │
        ├──▶ Autoprobe (tests new waves) ──▶ runs/auto_waves.json (hot-reloaded)
        ▼
  ┌───────────┐    match?    ┌──────────────────────────────┐
  │   Zama    │ ─── yes ───▶ │ Deterministic Solvers (0 tok)│
  │Race/Runner│              │  C/C++20 + Lean 4 Templates  │
  └───────────┘              └──────────────┬───────────────┘
        │ novel family                      │
        ▼                                   ▼
  ┌─────────────────────────┐      ┌────────────────────────┐
  │ Optional AI Fallback    │ ───▶ │ 0.1ms Pre-Lint +       │
  │ Ollama · OpenAI · CLI   │      │ Official Lean 4 Kernel │
  └─────────────────────────┘      └───────────┬────────────┘
                                               ▼
                                   ┌────────────────────────┐
                                   │ Zero-Dup PR Guard +    │
                                   │ Submit + SQLite Ledger │
                                   └────────────────────────┘

Included Deterministic Solvers (21 Plugins)

Solver Stack Theorem Family
value6 C/C++17 + Python + Lean 6-input exact AND/OR/NOT circuit size (HasCircuitSize 6): LB-first lowu_gen + multi-thread cgp6_fast + v6front chunked-BFS (k=12..14) + gen10_dev fallback
value7 C + Python + Lean 7-input exact AND/OR/NOT circuit size (HasCircuitSize 7, u128 CGP + cut oracle)
foud6 C++20 + Lean 6×6 circuits (≤1 NOT, ≤2 NOT, or unrestricted NOT) via foud6 → foud6nb → foud6split cascade
notcover6 Python 6-bit subcube non-coverability (pigeonhole clique + LP dual)
cover6 Python 6-bit exact minimum axis-aligned subcube cover
sixl C++20 + Lean 6×6 monotone one-active-row-and-column (LiveL+gkey DAG)
onerow C++20 + Lean 5×5 one-active-row-and-column exact circuit size
onerowl C++20 + Lean 5×5 one-active-row-and-column LiveL+gkey (k=2..12)
andcount Python + Lean Partial-function AND-gate lower bounds via MIS
oneside Python + Lean One-a-side bipartite graph AND/OR lower bounds via induced P4
twolit Python + Lean Two-literal monotone function refute certificates
hull Python Affine hull modulo k decision & certificates
sixrow C++17 + Python + Lean 6×6 monotone one-active-row-and-column value (homomorphic projection + BST DAG)
sixub Python + Lean 6-input AND/OR/NOT circuit upper bound via cgp6_fast
inc7 C + Lean-compiled C + Python Increasing 7-input function circuit size (gate elimination + monotone CGP + native kids search)
onenot8 Python + C + kissat 8-vertex edge function, one NOT saves nothing
t2b Python + C (sa6_dec, v4_gen) Table 2 monotone 6-input prove
foud6lb C++20 + Python + Lean 6×6 lower-bound child units (unrestricted or one NOT): foud6 lower-bound-only DAG split into ≤2,000-node kernel chunks
foud6ub C++17 + Python + Lean 6×6 upper-bound child units (one NOT, unrestricted NOT, monotone): 273-table cert6 cache, then CGP or kissat
mono6lb C++17 + Lean 6×6 monotone lower-bound child units (LiveL+gkey DAG, lower-bound fork of sixl)
side5 C++17 + Python + Lean Side-five table prove/refute units: exact minimum from minc, witness + decide

Measured Benchmark (value6 / HasCircuitSize 6)

Reproducible 10-unit benchmark from wave e2c6b99338 (benchmarks/corpus_value6.json):

make bench                                      # solve + pre-lint all 10 units (~12 s on Apple M4)
./zama bench --lean ../pequalnp-proofs/lean     # also run independent Lean 4 kernel checks

Measured on Apple M4 against the pre-refactor SAT (kissat + unpatched gen10) baseline:

  • Solved + pre-linted: 10/10 (baseline: 0/10)
  • Total wall time: 12.0 s vs 501.1 s baseline (41.8× faster, measured 2026-12-03 with another pipeline running; Zama v1.2 took 37.5 s, see benchmarks/results_value6.json)
  • Typical per-unit generation time: 0.04–0.43 s on 9 of 10 units via LB-first lowu_gen + multi-threaded cgp6_fast
  • Independent Lean 4 kernel checks (lake env lean, rc=0): verified on L-meta-125881 (16.2 s), L-meta-125860 (11.6 s), and L-meta-125861 (24.9 s).

Overnight Unattended Operation

Zama is built to run unattended all night without babysitting:

  • One-command detached mode: ./zama ship --submit --detach acquires an exclusive flock (runs/.supervisor.lock) and automatically wraps zama watch with caffeinate -is on macOS so your machine never sleeps mid-run.
  • Built-in mechanical self-healing (watch.py): clears stale .git/index.lock files (>60 s with no live git process), terminates hung tools/pnp.sh (>420 s) or runaway solver subprocesses (>240 s), and enforces a scoped 240 s Lean guard so Zama never touches unrelated processes.
  • OS service templates (templates/overnight/): ready-to-install macOS launchd agent (install-launchd.sh), Linux systemd user service (zama-ship.service), and zero-token night_watch.sh guardian.

Playbook, Templates, Ledger & Best Practices


Model-Agnostic AI Fallback (Optional)

Leave ZAMA_AI_PROVIDERS empty in .env for 100% deterministic, zero-token mode. To enable AI fallback only for genuinely new theorem families, set any combination in priority order:

  • ollama — local models via OLLAMA_HOST and OLLAMA_MODEL
  • openai — any OpenAI-compatible API (vLLM, LM Studio, OpenRouter, OpenAI)
  • claude — local claude CLI
  • codex — local codex CLI

FAQ

Does Zama require paid AI APIs or external Python packages? No. Zama uses only the Python 3.10+ standard library and C/C++20. All 12 built-in solvers run locally at $0 / 0 tokens.

How does Zama guarantee proofs are mathematically valid? Every generated .lean file passes local pre-linting and exact statement-signature checks, then is independently compiled by the official Lean 4 kernel (lake env lean / tools/pnp.sh check) before any PR is opened.

Can I run Zama on one laptop or across multiple machines? Both. By default it runs on one machine (ZAMA_FLEET empty). To scale across multiple Macs or Linux boxes, set ZAMA_FLEET="local:2,user@host:4" in .env — unreachable nodes enter cooldown automatically and fall back to local with zero stalls.

How do I add a solver for a new theorem family? Copy templates/solver_skeleton/ to solvers/<name>/, adapt the closest Lean template under solvers/, and run make build && make test. See docs/PLAYBOOK.md and CONTRIBUTING.md.


Contributing & Independent Verification

See CONTRIBUTING.md for the solver plugin contract, Lean 4 compliance rules, and PR checklist.

make build && make test
./zama verify <unit_id> <path/to/proof.lean> --standalone

License

MIT — see LICENSE.


Keywords: Lean 4 automated theorem prover · pequalnp.com autopilot · P vs NP formal verification · Boolean circuit complexity lower bounds · deterministic C++20 proof generator · zero-dependency Python CLI · overnight Lean 4 PR bot · local LLM theorem proving (Ollama, OpenAI, Claude, Codex) · reproducible open-science ledger.

About

Open-source framework for pequalnp.com circuit-complexity units: 21 deterministic solvers (C/C++, Python) find minimum Boolean circuits and lower-bound certificates, emit Lean 4 proofs, check them with the Lean kernel and open the PR. Per-solver docs, templates, measured times.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages