项目 Lean 版本必须不低于 lean4:v4.3.0-rc2,且需与 mathlib 等依赖版本匹配;需先安装 Git LFS,并在 lakefile 中配置 moreLinkArgs 链接 ctranslate2;内置模型需运行 lake exe LeanCopilot/download 下载到 ~/.cache/lean_copilot/,否则无法使用。
lake update LeanCopilot
lake exe LeanCopilot/download支持 Linux、macOS、Windows 及 WSL;有 CUDA GPU 时推荐安装 CUDA 与 cuDNN,也可在无 GPU 的本地环境运行模型。README 未给出具体显存要求。
在 Lean 4 里直接调用大模型做战术建议、前提检索和证明搜索的证明自动化工具
把大模型接入 Lean 4 定理证明流程的推理服务,支持在证明环境中调用模型做前提检索、策略建议和自动补全。
核心能力
- 用 suggest_tactics 生成可点击套用的战术建议
- 用 search_proof 结合 aesop 搜索多步证明
- 用 select_premises 从 Lean 与 mathlib4 快照检索前提
- 支持本地 CTranslate2 推理或云端外部模型
- 提供 TextToText/TextToVec 接口接入自备模型
容易踩的坑
- v4.35.0最新正式版2026-10-13 · 2026-10-13 01:17 UTC
- v4.34.02026-09-15 · 2026-09-15 01:19 UTC
查看更新说明
What's Changed
- Bump to latest Lean v4.34.0 by @Peiyang-Song in https://github.com/lean-dojo/LeanCopilot/pull/199
Full Changelog: https://github.com/lean-dojo/LeanCopilot/compare/v4.33.0...v4.34.0
- v4.33.02026-08-19 · 2026-08-19 14:57 UTC
查看更新说明
What's Changed
- Bump to Lean v4.33.0; support prebuilt system libraries by @Peiyang-Song in https://github.com/lean-dojo/LeanCopilot/pull/198
Full Changelog: https://github.com/lean-dojo/LeanCopilot/compare/v4.32.0...v4.33.0
- v4.32.02026-08-19 · 2026-08-19 04:25 UTC
查看更新说明
What's Changed
- bump to Lean v4.32.0 & fix bugs by @Peiyang-Song in https://github.com/lean-dojo/LeanCopilot/pull/195
- bump Lean Copilot to stable version Lean v4.32.0, fix https://github.com/lean-dojo/LeanCopilot/issues/137, fix https://github.com/lean-dojo/LeanCopilot/issues/196, and supercedes https://github.com/lean-dojo/LeanCopilot/pull/197. Closing all three as a result
Full Changelog: https://github.com/lean-dojo/LeanCopilot/compare/v4.31.0...v4.32.0
- v4.31.02026-06-20 · 2026-06-20 22:39 UTC
查看更新说明
What's Changed
- Bump to latest & fix bugs by @Peiyang-Song in https://github.com/lean-dojo/LeanCopilot/pull/194
Note
Lean Copilot is incompatible with Lean versions between 4.28.0 and 4.32.0-rc1 due to a downstream bug (#193), which has now been fixed in the latest Lean version v4.32.0-rc1 (see details in https://github.com/leanprover-community/batteries/issues/1832). With this release, Lean Copilot works as expected on the latest Lean version. We recommend upgrading to this release or a later one. Alternatively, you can use Lean versions up to and including v4.28.0.
Full Changelog: https://github.com/lean-dojo/LeanCopilot/compare/v4.28.0...v4.31.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Lean Copilot: LLMs as Copilots for Theorem Proving in Lean
🚩News: Our paper is accepted to the International Conference on Neuro-symbolic Systems (NeuS), 2025. See you in Philadelphia!
Lean Copilot allows large language models (LLMs) to be used natively in Lean for proof automation, e.g., suggesting tactics/premises and searching for proofs. You can use our built-in models from LeanDojo or bring your own models that run either locally (w/ or w/o GPUs) or on the cloud.
https://github.com/lean-dojo/LeanCopilot/assets/114432581/ee0f56f8-849e-4099-9284-d8092cbd22a3
Table of Contents
- Requirements
- Using Lean Copilot in Your Project
- Advanced Usage
- Caveats
- Getting in Touch
- Acknowledgements
- Citation
Requirements
- Supported platforms: Linux (priority), macOS (priority), Windows and Windows WSL.
- Git LFS.
- Optional (recommended if you have a CUDA-enabled GPU): CUDA and cuDNN.
- Required for building Lean Copilot itself (rather than a downstream package): CMake >= 3.7 and a C++17 compatible compiler. A downstream package normally downloads a prebuilt release instead of needing these, except on a platform we don't publish a release for (e.g. Intel macOS), where it automatically falls back to building from source and so needs them too.
Using Lean Copilot in Your Project
:warning: Your project must use a Lean version of at least lean4:v4.3.0-rc2.
Adding Lean Copilot as a Dependency
- Add the package configuration option
moreLinkArgs := #["-L./.lake/packages/LeanCopilot/.lake/build/lib", "-lctranslate2"]to lakefile.lean. For example,
package «my-package» {
moreLinkArgs := #[
"-L./.lake/packages/LeanCopilot/.lake/build/lib",
"-lctranslate2"
]
}
Alternatively, if your project uses lakefile.toml, it should include:
moreLinkArgs = ["-L./.lake/packages/LeanCopilot/.lake/build/lib", "-lctranslate2"]
- Add the following line to lakefile.lean, including the quotation marks:
require LeanCopilot from git "https://github.com/lean-dojo/LeanCopilot.git" @ "LEAN_COPILOT_VERSION"
For stable Lean versions (e.g., v4.35.0), set LEAN_COPILOT_VERSION to be that version. For the latest unstable Lean versions (e.g., v4.36.0-rc1), set LEAN_COPILOT_VERSION to main. In either case, make sure the version is compatible with other dependencies such as mathlib. If your project uses lakefile.toml instead of lakefile.lean, it should include:
[[require]]
name = "LeanCopilot"
git = "https://github.com/lean-dojo/LeanCopilot.git"
rev = "LEAN_COPILOT_VERSION"
-
If you are using native Windows, add
<path_to_your_project>/.lake/packages/LeanCopilot/.lake/build/libto yourPathvariable in Advanced System Settings > Environment Variables... > System variables. -
Run
lake update LeanCopilot. -
Run
lake exe LeanCopilot/downloadto download the built-in models from Hugging Face to~/.cache/lean_copilot/. Alternatively, you can download the models from Hugging Face manually from
- ct2-leandojo-lean4-tacgen-byt5-small
- ct2-leandojo-lean4-retriever-byt5-small
- premise-embeddings-leandojo-lean4-retriever-byt5-small
- ct2-byt5-small
- Run
lake build. Note that this only builds your project's default targets. If none of them importsLeanCopilotyet, also runlake build LeanCopilot. (If you skip this, Lean Copilot and its dependencies are instead built the first time you open a file that imports it, which can take a few minutes.)
Here is an example of a Lean package depending on Lean Copilot. If you have problems building the project, our Dockerfile, build.sh or build_example.sh may be helpful.
Getting Started with Lean Copilot
Tactic Suggestion
After import LeanCopilot, you can use the tactic suggest_tactics to generate tactic suggestions. You can click on any of the suggested tactics to use it in the proof.
You can provide a prefix (e.g., simp) to constrain the generated tactics:
Proof Search
The tactic search_proof combines LLM-generated tactics with aesop to search for multi-tactic proofs. When a proof is found, you can click on it to insert it into the editor.
Premise Selection
The select_premises tactic retrieves a list of potentially useful premises. Currently, it uses the retriever in LeanDojo to select premises from a fixed snapshot of Lean and mathlib4.
Running LLMs
You can also run the inference of any LLMs in Lean, which can be used to build customized proof automation or other LLM-based applications (not limited to theorem proving). It's possible to run arbitrary models either locally or remotely (see Bring Your Own Model).
Advanced Usage
This section is only for advanced users who would like to change the default behavior of suggest_tactics, search_proof, or select_premises, e.g., to use different models or hyperparameters.
Tactic APIs
- Examples in TacticSuggestion.lean showcase how to configure
suggest_tactics, e.g., to use different models or generate different numbers of tactics. - Examples in ProofSearch.lean showcase how to configure
search_proofusing options provided by aesop. - Examples in PremiseSelection.lean showcase how to set the number of retrieved premises for
select_premises.
Model APIs
Examples in ModelAPIs.lean showcase how to run the inference of different models and configure their parameters (temperature, beam size, etc.).
Lean Copilot supports two kinds of models: generators and encoders. Generators must implement the TextToText interface:
class TextToText (τ : Type) where
generate (model : τ) (input : String) (targetPrefix : String) : IO $ Array (String × Float)
inputis the input stringtargetPrefixis used to constrain the generator's output.""means no constraint.generateshould return an array ofString × Float. EachStringis an output from the model, andFloatis the corresponding score.
We provide three types of Generators:
NativeGeneratorruns locally powered by CTranslate2 and is linked to Lean using Foreign Function Interface (FFI).ExternalGeneratoris hosted either locally or remotely. See Bring Your Own Model for details.GenericGeneratorcan be anything that implements thegeneratefunction in theTextToTexttypeclass.
Encoders must implement TextToVec:
class TextToVec (τ : Type) where
encode : τ → String → IO FloatArray
inputis the input stringencodeshould return a vector embedding produced by the model.
Similar to generators, we have NativeEncoder, ExternalEncoder, and GenericEncoder.
Bring Your Own Model
In principle, it is possible to run any model using Lean Copilot through ExternalGenerator or ExternalEncoder (examples in ModelAPIs.lean). To use a model, you need to wrap it properly to expose the APIs in external_model_api.yaml. As an example, we provide a Python API server and use it to run a few models.
Using Prebuilt System Libraries
By default, building Lean Copilot from source clones and compiles its native dependencies, OpenBLAS and CTranslate2, which can be slow or awkward on systems (e.g., Nix-based distros) that already package these libraries or make it difficult to compile them from source. If you already have compatible builds available, you can point Lean Copilot at them instead with lake's -K flag (add -R too if you already have a .lake/build from a previous build, so that the new options take effect):
-KsystemOpenblas=<path to your libopenblas.so/.dylib>skips cloning and building OpenBLAS (Linux/Windows only; macOS uses Apple's Accelerate framework instead of OpenBLAS).-KsystemCtranslate2Lib=<path to your libctranslate2.so/.dylib>together with-KsystemCtranslate2Include=<path to a directory containing the ctranslate2/, nlohmann/, and half_float/ header trees>skips cloning and building CTranslate2.
For example, on Linux:
lake -R -KsystemOpenblas=/usr/lib/libopenblas.so \
-KsystemCtranslate2Lib=/usr/lib/libctranslate2.so \
-KsystemCtranslate2Include=/usr/include \
build
Caveats
select_premisesalways retrieves the original form of a premise. For example,Nat.add_left_commis a result of the theorem below. In this case,select_premisesretrievesNat.mul_left_comminstead ofNat.add_left_comm.
@[to_additive]
theorem mul_left_comm : ∀ a b c : G, a * (b * c) = b * (a * c)
-
In some cases,
search_proofproduces an erroneous proof with error messages likefail to show termination for .... A temporary workaround is changing the theorem's name before applyingsearch_proof. You can change it back aftersearch_proofcompletes. -
On Linux, a downstream
lean_exetarget (as opposed to alean_lib) links against Lean's own bundled, statically-linkedlibc++, while Lean Copilot's native code (ct2.cpp) is compiled against the system'slibstdc++. Alean_libnever hits this (its.sotolerates undefined symbols, resolved later at load time), but a plain executable link requires every symbol resolved up front, so without extra configuration alean_exethat depends on Lean Copilot fails to link with undefinedlibstdc++symbols. Lean Copilot cannot fully paper over this on its own: statically bundling libstdc++ itself would collide with Lean's already-statically-linked libc++ (both define the same ABI-mangled symbols for types likestd::logic_error), so it can only be linked in dynamically, which downstream still has to opt into. If your project has alean_exetarget, add this to itslakefile.toml/lakefile.leanon Linux (adjust the-Lpath for your distro, e.g. viagcc -print-file-name=libstdc++.so):moreLinkArgs = [ "-L./.lake/packages/LeanCopilot/.lake/build/lib", "-lctranslate2", "-Wl,-L/usr/lib/gcc/x86_64-linux-gnu/13", "-Wl,-lstdc++" ](
-Wl,-lstdc++, not a plain-lstdc++: Lean's bundled clang driver silently rewrites a literal-lstdc++argument to linklibc++instead, so it must be passed through to the linker directly.)
Getting in Touch
- For general questions and discussions, please use GitHub Discussions.
- To report a potential bug, please open an issue. In the issue, please include your OS information, the exact steps to reproduce the error on the latest stable version of Lean Copilot, and complete logs preferrably in debug mode. Important: If your issue cannot be reproduced easily, it will be unlikely to receive help.
- Feature requests and contributions are warmly welcome. Please feel free to start a discussion or open a pull request.
Acknowledgements
- We thank Scott Morrison for suggestions on simplifying Lean Copilot's installation and Mac Malone for helping implement it. Both Scott and Mac work for the Lean FRO.
- We thank Jannis Limperg for supporting our LLM-generated tactics in Aesop (https://github.com/leanprover-community/aesop/pull/70).
Citation
If you find our work useful, please consider citing our paper:
@article{song2024leancopilot,
title={Lean copilot: Large language models as copilots for theorem proving in lean},
author={Song, Peiyang and Yang, Kaiyu and Anandkumar, Anima},
journal={arXiv preprint arXiv:2404.12534},
year={2024}
}