Skip to content

feat: Lean 4 + mathlib portfolio backend#549

Merged
TSavo merged 1 commit into
mainfrom
ts-lean-backend
May 10, 2026
Merged

feat: Lean 4 + mathlib portfolio backend#549
TSavo merged 1 commit into
mainfrom
ts-lean-backend

Conversation

@TSavo
Copy link
Copy Markdown
Owner

@TSavo TSavo commented May 10, 2026

Summary

Adds Lean 4 + mathlib as a prove-portfolio backend, parallel to the existing Coq backend.

  • provekit-ir-compiler-lean (new crate): lowers an obligation to a Lean 4 theorem with the IrFormula as the goal, plus a mathlib-automation tactic block (or a sorry-flagged scaffold when no automation applies, which yields Unknown, never Discharged). Byte-deterministic output; declares coverage for dependent_type and categorical_structure opacity positions plus general higher-order goals mathlib can close.
  • solvers/lean.rs: invokes lake env lean. Exit 0, no errors, no sorry/sorryAx in #print axioms => Discharged; otherwise Unknown. The discharge receipt records the Lean toolchain version, the mathlib commit (from lake-manifest.json), the emitted .lean file CID, and the #print axioms axiom set as the proof's trust base.
  • Registered in the portfolio (config/dispatch/registry/plan/mod); .provekit/config.toml portfolio now includes lean.
  • Spec doc protocol/specs/2026-05-10-lean-backend.md; install appendix tools/portfolio/lean-mathlib-install.md (elan + pinned Lean 4 + lake exe cache get for the prebuilt mathlib oleans; the Dockerfile is not modified here).

Why Lean and not just Coq: mathlib already contains most of the categorical machinery paper 13 references (CategoryTheory, Algebra.Category, FreeAlgebra), so morphism-composition functoriality and initial-algebra universality become "cite the mathlib lemma" rather than reproving in Coq from scratch.

Verification (local): cargo build -p provekit-ir-compiler-lean -p provekit-verifier clean; cargo test -p provekit-ir-compiler-lean 6 pass; cargo test -p provekit-verifier --test lean_solver 5 pass + 1 ignored (binary-dependent); cargo test -p provekit-verifier --lib 44 pass; cargo test -p provekit-verifier --test multi_solver_modes 12 pass; cargo clippy -p provekit-ir-compiler-lean -- -D warnings clean.

Test plan

  • cargo test -p provekit-ir-compiler-lean and cargo test -p provekit-verifier green
  • cargo clippy -p provekit-ir-compiler-lean -- -D warnings clean
  • With elan + Lean 4 + mathlib cache installed: a known mathlib theorem lowered as an obligation discharges and #print axioms shows no sorryAx

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 10, 2026 03:59
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 10, 2026

Warning

Rate limit exceeded

@TSavo has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 43 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2e5207e8-9b43-427f-844f-626dbc17243a

📥 Commits

Reviewing files that changed from the base of the PR and between 1db9799 and 3f84b2a.

⛔ Files ignored due to path filters (1)
  • implementations/rust/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • .provekit/config.toml
  • implementations/rust/Cargo.toml
  • implementations/rust/provekit-ir-compiler-lean/Cargo.toml
  • implementations/rust/provekit-ir-compiler-lean/src/lib.rs
  • implementations/rust/provekit-ir-compiler-lean/src/main.rs
  • implementations/rust/provekit-ir-compiler-lean/tests/byte_for_byte.rs
  • implementations/rust/provekit-ir-compiler-lean/tests/fixtures/reflexivity.lean
  • implementations/rust/provekit-ir-compiler-lean/tests/lowering.rs
  • implementations/rust/provekit-verifier/Cargo.toml
  • implementations/rust/provekit-verifier/src/solvers/config.rs
  • implementations/rust/provekit-verifier/src/solvers/dispatch.rs
  • implementations/rust/provekit-verifier/src/solvers/lean.rs
  • implementations/rust/provekit-verifier/src/solvers/mod.rs
  • implementations/rust/provekit-verifier/src/solvers/plan.rs
  • implementations/rust/provekit-verifier/src/solvers/registry.rs
  • implementations/rust/provekit-verifier/tests/lean_solver.rs
  • protocol/specs/2026-05-10-lean-backend.md
  • tools/portfolio/lean-mathlib-install.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ts-lean-backend

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba684683a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Term::Let { bindings, body } => {
for binding in bindings {
collect_term(&binding.bound_term, ctx, bound, None)?;
bound.insert(lean_ident(&binding.name), "Int".to_string());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Infer let-binding sort from bound term

The collector hard-codes every let binding to Int, which corrupts signature inference for non-Int bindings used later in predicates/functions. For example, let b := true; P b will register P as Int -> Prop even though b is Bool, causing Lean type errors and turning otherwise solvable obligations into Undecidable. This affects any obligation that uses Term::Let with non-integer values.

Useful? React with 👍 / 👎.

}

pub fn uses_sorry_or_sorry_ax(source: &str, output: &str) -> bool {
source.contains("sorry")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Detect sorry as a token, not any substring

The discharge check marks proofs as undecidable when the generated source merely contains the substring "sorry", even if Lean succeeded and no sorry/sorryAx was used. A benign identifier like sorry_count in IR names will trigger this path and force Undecidable, creating false negatives for valid proofs.

Useful? React with 👍 / 👎.

New IR compiler crate parallel to the Coq compiler: lowers an obligation
to a Lean 4 theorem with mathlib automation. New lean.rs solver adapter.
Verdict is Discharged only if kernel-checked with no sorryAx; receipt
records Lean version + mathlib commit + #print axioms trust base. Registered
in the multi-solver portfolio (config/dispatch/registry/plan). Spec doc and
install appendix included; Dockerfile not modified.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TSavo TSavo force-pushed the ts-lean-backend branch from ba68468 to 3f84b2a Compare May 10, 2026 04:10
@TSavo TSavo merged commit 06af8a7 into main May 10, 2026
TSavo added a commit that referenced this pull request May 10, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TSavo TSavo review requested due to automatic review settings May 10, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant