lean-interact 0.10.4__tar.gz → 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lean_interact-0.10.4 → lean_interact-0.11.0}/.github/workflows/ci.yml +12 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/PKG-INFO +3 -2
- {lean_interact-0.10.4 → lean_interact-0.11.0}/README.md +1 -1
- lean_interact-0.11.0/docs/api/pool.md +7 -0
- lean_interact-0.11.0/docs/api/server.md +20 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/contributing.md +4 -4
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/index.md +2 -2
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/basic-usage.md +14 -14
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/custom-lean-configuration.md +23 -23
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/data-extraction.md +4 -5
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/examples.md +6 -3
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/getting-started.md +8 -8
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/installation.md +9 -9
- lean_interact-0.11.0/docs/user-guide/performance.md +225 -0
- lean_interact-0.11.0/docs/user-guide/set-options.md +26 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/tactic-mode.md +10 -10
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/user-guide/troubleshooting.md +10 -10
- lean_interact-0.11.0/examples/parallelization.py +162 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/mkdocs.yml +2 -1
- {lean_interact-0.10.4 → lean_interact-0.11.0}/pyproject.toml +3 -2
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/__init__.py +2 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/interface.py +2 -1
- lean_interact-0.11.0/src/lean_interact/pool.py +314 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/server.py +19 -5
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/utils.py +1 -1
- {lean_interact-0.10.4 → lean_interact-0.11.0}/tests/test_server.py +35 -3
- lean_interact-0.10.4/docs/api/server.md +0 -20
- lean_interact-0.10.4/docs/user-guide/performance.md +0 -224
- lean_interact-0.10.4/docs/user-guide/set-options.md +0 -26
- lean_interact-0.10.4/examples/parallelization.py +0 -125
- {lean_interact-0.10.4 → lean_interact-0.11.0}/.devcontainer/devcontainer.json +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/.github/copilot-instructions.md +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/.github/workflows/docs.yml +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/.github/workflows/publish-to-pypi.yml +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/.gitignore +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/LICENSE +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/.nojekyll +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/api/config.md +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/api/interface.md +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/api/project.md +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/api/sessioncache.md +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/api/utils.md +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/generate_changelog.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/docs/theme/main.html +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/examples/beq_plus.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/examples/extract_mathlib_decls.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/examples/proof_generation_and_autoformalization.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/examples/type_check.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/config.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/project.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/py.typed +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/src/lean_interact/sessioncache.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/tests/test_concurrency.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/tests/test_git_functionality.py +0 -0
- {lean_interact-0.10.4 → lean_interact-0.11.0}/tests/test_utils.py +0 -0
|
@@ -25,6 +25,18 @@ jobs:
|
|
|
25
25
|
- name: Checkout
|
|
26
26
|
uses: actions/checkout@v3
|
|
27
27
|
|
|
28
|
+
- name: Free Disk Space (Ubuntu)
|
|
29
|
+
if: runner.os == 'Linux'
|
|
30
|
+
uses: jlumbroso/free-disk-space@main
|
|
31
|
+
with:
|
|
32
|
+
tool-cache: false
|
|
33
|
+
android: true
|
|
34
|
+
dotnet: true
|
|
35
|
+
haskell: true
|
|
36
|
+
large-packages: true
|
|
37
|
+
docker-images: true
|
|
38
|
+
swap-storage: true
|
|
39
|
+
|
|
28
40
|
- name: Set up Python ${{ matrix.python-version }}
|
|
29
41
|
uses: actions/setup-python@v4
|
|
30
42
|
with:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lean-interact
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: LeanInteract is a Python package that allows you to interact with the Lean theorem prover.
|
|
5
5
|
Author-email: Auguste Poiroux <auguste.poiroux@epfl.ch>
|
|
6
6
|
License: MIT License
|
|
@@ -34,6 +34,7 @@ Requires-Dist: psutil>=6.1.0
|
|
|
34
34
|
Requires-Dist: pydantic>=2.11.1
|
|
35
35
|
Requires-Dist: requests>=2.32.3
|
|
36
36
|
Requires-Dist: rich>=13.9.4
|
|
37
|
+
Requires-Dist: tqdm>=4.67.1
|
|
37
38
|
Description-Content-Type: text/markdown
|
|
38
39
|
|
|
39
40
|
# LeanInteract
|
|
@@ -53,7 +54,7 @@ Check the [documentation](https://augustepoiroux.github.io/LeanInteract/) for de
|
|
|
53
54
|
- **🔗 Interactivity**: Execute Lean code and files directly from Python.
|
|
54
55
|
- **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
|
|
55
56
|
- **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems.
|
|
56
|
-
- **🔧 Compatibility**: Supports all Lean versions between `v4.8.0-rc1` and `v4.
|
|
57
|
+
- **🔧 Compatibility**: Supports all Lean versions between `v4.8.0-rc1` and `v4.28.0-rc1`.
|
|
57
58
|
- We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
|
|
58
59
|
- **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
|
|
59
60
|
- Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4).
|
|
@@ -15,7 +15,7 @@ Check the [documentation](https://augustepoiroux.github.io/LeanInteract/) for de
|
|
|
15
15
|
- **🔗 Interactivity**: Execute Lean code and files directly from Python.
|
|
16
16
|
- **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
|
|
17
17
|
- **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems.
|
|
18
|
-
- **🔧 Compatibility**: Supports all Lean versions between `v4.8.0-rc1` and `v4.
|
|
18
|
+
- **🔧 Compatibility**: Supports all Lean versions between `v4.8.0-rc1` and `v4.28.0-rc1`.
|
|
19
19
|
- We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
|
|
20
20
|
- **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
|
|
21
21
|
- Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
::: lean_interact.server
|
|
2
|
+
options:
|
|
3
|
+
heading_level: 1
|
|
4
|
+
heading: "Lean Servers"
|
|
5
|
+
show_symbol_type_heading: false
|
|
6
|
+
members:
|
|
7
|
+
- LeanServer
|
|
8
|
+
- AutoLeanServer
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Notes on performance features
|
|
13
|
+
|
|
14
|
+
LeanInteract automatically augments [`Command`](interface.md#lean_interact.interface.Command) and [`FileCommand`](interface.md#lean_interact.interface.FileCommand) requests to speed up elaboration and processing of files:
|
|
15
|
+
|
|
16
|
+
- Incremental elaboration is enabled by default
|
|
17
|
+
- Parallel elaboration is enabled via `set_option Elab.async true` by default when supported (Lean >= v4.19.0)
|
|
18
|
+
|
|
19
|
+
These behaviors can be disabled in [`LeanREPLConfig`](config.md#lean_interact.config.LeanREPLConfig) by setting
|
|
20
|
+
[`enable_incremental_optimization`](config.md#lean_interact.config.LeanREPLConfig.enable_incremental_optimization) to `False` and/or [`enable_parallel_elaboration`](config.md#lean_interact.config.LeanREPLConfig.enable_parallel_elaboration) to `False`.
|
|
@@ -5,19 +5,19 @@ hide:
|
|
|
5
5
|
|
|
6
6
|
# Contributing to LeanInteract
|
|
7
7
|
|
|
8
|
-
Thank you for
|
|
8
|
+
Thank you for contributing to LeanInteract! This guide will help getting started, following best practices, and making contributions easy to review.
|
|
9
9
|
|
|
10
10
|
## Pull Request Guidelines
|
|
11
11
|
|
|
12
|
-
- **Describe
|
|
12
|
+
- **Describe changes** clearly and concisely in the PR description.
|
|
13
13
|
- **Link to relevant issues** using `#` (e.g., #42).
|
|
14
14
|
- **Include tests** for new features or bug fixes.
|
|
15
|
-
- **Update documentation** if
|
|
15
|
+
- **Update documentation** if changes affect usage or APIs.
|
|
16
16
|
- **Ensure all tests pass** before requesting review.
|
|
17
17
|
|
|
18
18
|
## Getting Started
|
|
19
19
|
|
|
20
|
-
1. **Fork the repository** on GitHub and clone
|
|
20
|
+
1. **Fork the repository** on GitHub and clone the fork locally.
|
|
21
21
|
|
|
22
22
|
2. **Install development dependencies**: we recommend using [uv](https://docs.astral.sh/uv/).
|
|
23
23
|
|
|
@@ -17,7 +17,7 @@ hide:
|
|
|
17
17
|
- **🔗 Interactivity**: Execute Lean code and files directly from Python
|
|
18
18
|
- **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction
|
|
19
19
|
- **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems
|
|
20
|
-
- **🔧 Compatibility**: Supports all Lean versions between `v4.8.0-rc1` and `v4.
|
|
20
|
+
- **🔧 Compatibility**: Supports all Lean versions between `v4.8.0-rc1` and `v4.28.0-rc1`
|
|
21
21
|
- We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
|
|
22
22
|
- **📦 Temporary Projects**: Easily instantiate temporary Lean environments
|
|
23
23
|
- Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4)
|
|
@@ -38,7 +38,7 @@ Install Lean 4 (if not already installed) using the following command coming wit
|
|
|
38
38
|
install-lean
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
### Start using it in
|
|
41
|
+
### Start using it in Python scripts
|
|
42
42
|
|
|
43
43
|
```python
|
|
44
44
|
from lean_interact import LeanREPLConfig, LeanServer, Command
|
|
@@ -4,7 +4,7 @@ This guide covers the fundamental operations and command types in LeanInteract.
|
|
|
4
4
|
|
|
5
5
|
## Basic Command Execution
|
|
6
6
|
|
|
7
|
-
The most common operation in LeanInteract is executing Lean code directly using the `Command` class:
|
|
7
|
+
The most common operation in LeanInteract is executing Lean code directly using the [`Command`](../api/interface.md#lean_interact.interface.Command) class:
|
|
8
8
|
|
|
9
9
|
```python exec="on" source="above" session="base" result="python"
|
|
10
10
|
from lean_interact import LeanREPLConfig, LeanServer, Command
|
|
@@ -20,11 +20,11 @@ print(server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := id")))
|
|
|
20
20
|
The response contains:
|
|
21
21
|
|
|
22
22
|
- Messages returned by Lean if any (errors, information, etc.)
|
|
23
|
-
- An environment state (`env`) that can be used for subsequent commands.
|
|
23
|
+
- An environment state ([`env`](../api/interface.md#lean_interact.interface.CommandResponse.env)) that can be used for subsequent commands.
|
|
24
24
|
|
|
25
25
|
### Working with Environment States
|
|
26
26
|
|
|
27
|
-
Each command execution creates a new environment state.
|
|
27
|
+
Each command execution creates a new environment state. Use this state in subsequent commands:
|
|
28
28
|
|
|
29
29
|
```python exec="on" source="above" session="base" result="python"
|
|
30
30
|
# First command creates environment state
|
|
@@ -36,7 +36,7 @@ print(server.run(Command(cmd="#check x", env=response1.env)))
|
|
|
36
36
|
|
|
37
37
|
## Processing Lean Files
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Process entire Lean files using the [`FileCommand`](../api/interface.md#lean_interact.interface.FileCommand) class:
|
|
40
40
|
|
|
41
41
|
```python
|
|
42
42
|
from lean_interact import FileCommand
|
|
@@ -50,15 +50,15 @@ response = server.run(FileCommand(path="myfile.lean", root_goals=True))
|
|
|
50
50
|
|
|
51
51
|
## Available Options
|
|
52
52
|
|
|
53
|
-
Both `Command` and `FileCommand` support several options:
|
|
53
|
+
Both [`Command`](../api/interface.md#lean_interact.interface.Command) and [`FileCommand`](../api/interface.md#lean_interact.interface.FileCommand) support several options:
|
|
54
54
|
|
|
55
|
-
- `all_tactics
|
|
56
|
-
- `declarations
|
|
57
|
-
- `root_goals
|
|
58
|
-
- `infotree
|
|
59
|
-
- `incrementality
|
|
60
|
-
- `set_options
|
|
61
|
-
- `env
|
|
55
|
+
- [`all_tactics`](../api/interface.md#lean_interact.interface.Command.all_tactics): Get information about tactics used
|
|
56
|
+
- [`declarations`](../api/interface.md#lean_interact.interface.Command.declarations): Extract fine-grained information about declarations in the code
|
|
57
|
+
- [`root_goals`](../api/interface.md#lean_interact.interface.Command.root_goals): Get information about goals in theorems and definitions
|
|
58
|
+
- [`infotree`](../api/interface.md#lean_interact.interface.Command.infotree): Get Lean infotree containing various informations from the Lean syntax tree
|
|
59
|
+
- [`incrementality`](../api/interface.md#lean_interact.interface.Command.incrementality): Enable or disable incremental elaboration for this specific command.
|
|
60
|
+
- [`set_options`](../api/interface.md#lean_interact.interface.Command.set_options): Set Lean options for this command (see [Set Options](set-options.md))
|
|
61
|
+
- [`env`](../api/interface.md#lean_interact.interface.Command.env): The environment from a previous command to be used as context. If `env = None`, starts from scratch.
|
|
62
62
|
|
|
63
63
|
Example with options:
|
|
64
64
|
|
|
@@ -79,11 +79,11 @@ response = server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := sor
|
|
|
79
79
|
print(response.sorries[0])
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
This response will include a list of `Sorry` objects, each containing:
|
|
82
|
+
This response will include a list of [`Sorry`](../api/interface.md#lean_interact.interface.Sorry) objects, each containing:
|
|
83
83
|
|
|
84
84
|
- Position in the code
|
|
85
85
|
- Goal to be proven
|
|
86
|
-
- Proof state ID (can be used with `ProofStep` commands)
|
|
86
|
+
- Proof state ID ([`proof_state`](../api/interface.md#lean_interact.interface.Sorry.proof_state)) (can be used with [`ProofStep`](../api/interface.md#lean_interact.interface.ProofStep) commands)
|
|
87
87
|
|
|
88
88
|
## Error Handling
|
|
89
89
|
|
|
@@ -4,7 +4,7 @@ LeanInteract provides flexible ways to configure the Lean environment to suit di
|
|
|
4
4
|
|
|
5
5
|
## Specifying Lean Versions
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Specify which version of Lean 4 to use when no project is specified:
|
|
8
8
|
|
|
9
9
|
```python
|
|
10
10
|
from lean_interact import LeanREPLConfig, LeanServer
|
|
@@ -17,18 +17,18 @@ server = LeanServer(config)
|
|
|
17
17
|
## Working with Existing Projects
|
|
18
18
|
|
|
19
19
|
!!! note
|
|
20
|
-
When using a project through the `project` attribute, the Lean version is automatically inferred from the project.
|
|
20
|
+
When using a project through the [`project`](../api/config.md#lean_interact.config.LeanREPLConfig.project) attribute, the Lean version is automatically inferred from the project. Both [`lean_version`](../api/config.md#lean_interact.config.LeanREPLConfig.lean_version) and [`project`](../api/config.md#lean_interact.config.LeanREPLConfig.project) parameters cannot be specified simultaneously.
|
|
21
21
|
|
|
22
22
|
### Local Lean Projects
|
|
23
23
|
|
|
24
|
-
To work with a local Lean project, create a `LocalProject` instance:
|
|
24
|
+
To work with a local Lean project, create a [`LocalProject`](../api/project.md#lean_interact.project.LocalProject) instance:
|
|
25
25
|
|
|
26
26
|
```python
|
|
27
27
|
from lean_interact import LeanREPLConfig, LocalProject, LeanServer
|
|
28
28
|
|
|
29
29
|
# Configure with a local project
|
|
30
30
|
project = LocalProject(
|
|
31
|
-
directory="path/to/
|
|
31
|
+
directory="path/to/project",
|
|
32
32
|
auto_build=True # Automatically build the project (default is True)
|
|
33
33
|
)
|
|
34
34
|
config = LeanREPLConfig(project=project)
|
|
@@ -39,11 +39,11 @@ server = LeanServer(config)
|
|
|
39
39
|
Ensure the project can be successfully built with `lake build` before using it with LeanInteract.
|
|
40
40
|
|
|
41
41
|
!!! tip
|
|
42
|
-
Setting `auto_build
|
|
42
|
+
Setting [`auto_build`](../api/project.md#lean_interact.project.LocalProject.auto_build) to `False` will skip building the project, which can be useful if the project has already been built.
|
|
43
43
|
|
|
44
44
|
### Git-Based Projects
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Work with projects hosted on Git repositories:
|
|
47
47
|
|
|
48
48
|
```python
|
|
49
49
|
from lean_interact import LeanREPLConfig, GitProject, LeanServer
|
|
@@ -53,24 +53,24 @@ project = GitProject(
|
|
|
53
53
|
url="https://github.com/yangky11/lean4-example",
|
|
54
54
|
rev="main", # Optional: specific branch, tag, or commit
|
|
55
55
|
directory="/custom/cache/path", # Optional: custom directory where the project will be cloned
|
|
56
|
-
force_pull=False # Optional: force update from remote. Useful
|
|
56
|
+
force_pull=False # Optional: force update from remote. Useful when the project is already cloned and the branch has been updated.
|
|
57
57
|
)
|
|
58
58
|
config = LeanREPLConfig(project=project)
|
|
59
59
|
server = LeanServer(config)
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
The `GitProject` will automatically:
|
|
62
|
+
The [`GitProject`](../api/project.md#lean_interact.project.GitProject) will automatically:
|
|
63
63
|
|
|
64
64
|
- Clone the repository if it doesn't exist (including submodules if present)
|
|
65
65
|
- Update to the specified revision
|
|
66
66
|
- Build the project with `lake build`
|
|
67
67
|
|
|
68
68
|
!!! tip
|
|
69
|
-
Use the `directory` parameter to control where projects are cached
|
|
69
|
+
Use the [`directory`](../api/project.md#lean_interact.project.GitProject.directory) parameter to control where projects are cached
|
|
70
70
|
|
|
71
71
|
## Working with Temporary Projects
|
|
72
72
|
|
|
73
|
-
LeanInteract allows
|
|
73
|
+
LeanInteract allows creating temporary projects with dependencies for quick experimentation and automated reproducible setups.
|
|
74
74
|
|
|
75
75
|
### Simple Temporary Projects with Dependencies
|
|
76
76
|
|
|
@@ -102,7 +102,7 @@ config = LeanREPLConfig(project=project)
|
|
|
102
102
|
|
|
103
103
|
### Fine-Grained Temporary Projects
|
|
104
104
|
|
|
105
|
-
For more control over the temporary project,
|
|
105
|
+
For more control over the temporary project, specify the complete lakefile content:
|
|
106
106
|
|
|
107
107
|
```python
|
|
108
108
|
from lean_interact import LeanREPLConfig, TemporaryProject
|
|
@@ -128,12 +128,12 @@ require mathlib from git
|
|
|
128
128
|
config = LeanREPLConfig(project=project)
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
This approach gives
|
|
132
|
-
Alternatively,
|
|
131
|
+
This approach gives full control over the Lake configuration.
|
|
132
|
+
Alternatively, define the lakefile content using the TOML format by setting `lakefile_type="toml"`.
|
|
133
133
|
|
|
134
134
|
## Using Custom REPL Revisions
|
|
135
135
|
|
|
136
|
-
LeanInteract uses the Lean REPL from a git repository to interact with Lean. By default, it uses a specific version of the REPL from the default forked repository (`https://github.com/augustepoiroux/repl`) which manages compatibility with Lean versions. However,
|
|
136
|
+
LeanInteract uses the Lean REPL from a git repository to interact with Lean. By default, it uses a specific version of the REPL from the default forked repository (`https://github.com/augustepoiroux/repl`) which manages compatibility with Lean versions. However, this can be customized by specifying a different REPL revision or repository:
|
|
137
137
|
|
|
138
138
|
```python
|
|
139
139
|
from lean_interact import LeanREPLConfig, LeanServer
|
|
@@ -146,37 +146,37 @@ config = LeanREPLConfig(
|
|
|
146
146
|
server = LeanServer(config)
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
When
|
|
149
|
+
When specifying a [`repl_rev`](../api/config.md#lean_interact.config.LeanREPLConfig.repl_rev), LeanInteract will try to:
|
|
150
150
|
|
|
151
151
|
1. Find a tagged revision with the format `{repl_rev}_lean-toolchain-{lean_version}`
|
|
152
|
-
2. If such tag doesn't exist, fall back to using the specified `repl_rev` directly
|
|
153
|
-
3. If `lean_version` is not specified, it will use the latest available Lean version compatible with the REPL
|
|
152
|
+
2. If such tag doesn't exist, fall back to using the specified [`repl_rev`](../api/config.md#lean_interact.config.LeanREPLConfig.repl_rev) directly
|
|
153
|
+
3. If [`lean_version`](../api/config.md#lean_interact.config.LeanREPLConfig.lean_version) is not specified, it will use the latest available Lean version compatible with the REPL
|
|
154
154
|
|
|
155
155
|
This approach allows for better matching between REPL versions and Lean versions, ensuring compatibility.
|
|
156
156
|
|
|
157
157
|
!!! warning
|
|
158
|
-
Custom/older REPL implementations may have interfaces that are incompatible with LeanInteract's current commands.
|
|
158
|
+
Custom/older REPL implementations may have interfaces that are incompatible with LeanInteract's current commands. For compatibility issues, consider using the [`run_dict`](../api/server.md#lean_interact.server.LeanServer.run_dict) method from [`LeanServer`](../api/server.md#lean_interact.server.LeanServer) to communicate directly with the REPL:
|
|
159
159
|
|
|
160
160
|
```python
|
|
161
161
|
result = server.run_dict({"cmd": "your_command_here"})
|
|
162
162
|
```
|
|
163
163
|
|
|
164
164
|
!!! note
|
|
165
|
-
The `repl_rev` and `repl_git` parameters are ignored if
|
|
165
|
+
The [`repl_rev`](../api/config.md#lean_interact.config.LeanREPLConfig.repl_rev) and [`repl_git`](../api/config.md#lean_interact.config.LeanREPLConfig.repl_git) parameters are ignored if [`local_repl_path`](../api/config.md#lean_interact.config.LeanREPLConfig.local_repl_path) is specified.
|
|
166
166
|
|
|
167
167
|
### Using a Local REPL Installation
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
When developing the Lean REPL or using a custom version, a local copy can be used instead of downloading from a git repository:
|
|
170
170
|
|
|
171
171
|
```python
|
|
172
172
|
from lean_interact import LeanREPLConfig, LeanServer
|
|
173
173
|
|
|
174
|
-
config = LeanREPLConfig(local_repl_path="path/to/
|
|
174
|
+
config = LeanREPLConfig(local_repl_path="path/to/local/repl", build_repl=True)
|
|
175
175
|
server = LeanServer(config)
|
|
176
176
|
```
|
|
177
177
|
|
|
178
178
|
!!! note
|
|
179
|
-
When using `local_repl_path
|
|
179
|
+
When using [`local_repl_path`](../api/config.md#lean_interact.config.LeanREPLConfig.local_repl_path), any specified [`repl_rev`](../api/config.md#lean_interact.config.LeanREPLConfig.repl_rev), and [`repl_git`](../api/config.md#lean_interact.config.LeanREPLConfig.repl_git) parameters are ignored as the local REPL is used directly.
|
|
180
180
|
|
|
181
181
|
!!! note
|
|
182
|
-
|
|
182
|
+
Ensure a compatible Lean version is used between the local REPL and the project.
|
|
@@ -4,8 +4,7 @@ LeanInteract makes it easy to extract rich data from elaboration, including decl
|
|
|
4
4
|
|
|
5
5
|
## Declarations
|
|
6
6
|
|
|
7
|
-
Set `declarations
|
|
8
|
-
Full details about the fields in `DeclarationInfo` can be found in the [API reference](../api/interface.md#lean_interact.interface.DeclarationInfo).
|
|
7
|
+
Set [`declarations`](../api/interface.md#lean_interact.interface.Command.declarations) to `True` to retrieve a list of [`DeclarationInfo`](../api/interface.md#lean_interact.interface.DeclarationInfo) for each declaration introduced in the Lean code.
|
|
9
8
|
|
|
10
9
|
```python exec="on" source="above" session="extraction" result="python"
|
|
11
10
|
from lean_interact import LeanServer, LeanREPLConfig, Command
|
|
@@ -38,7 +37,7 @@ Tip: See [`examples/extract_mathlib_decls.py`](https://github.com/augustepoiroux
|
|
|
38
37
|
|
|
39
38
|
## Tactics
|
|
40
39
|
|
|
41
|
-
Use `all_tactics
|
|
40
|
+
Use [`all_tactics`](../api/interface.md#lean_interact.interface.Command.all_tactics) to collect tactic applications with their goals and used constants.
|
|
42
41
|
|
|
43
42
|
```python exec="on" source="above" session="extraction" result="python"
|
|
44
43
|
resp = server.run(Command(cmd=code, all_tactics=True))
|
|
@@ -48,7 +47,7 @@ for t in resp.tactics:
|
|
|
48
47
|
|
|
49
48
|
## InfoTrees
|
|
50
49
|
|
|
51
|
-
Request `infotree` to obtain structured elaboration information. Accepted values include `"full"`, `"tactics"`, `"original"`, and `"substantive"`. See [InfoTreeOptions](../api/interface.md#lean_interact.interface.InfoTreeOptions) for details.
|
|
50
|
+
Request [`infotree`](../api/interface.md#lean_interact.interface.Command.infotree) to obtain structured elaboration information. Accepted values include `"full"`, `"tactics"`, `"original"`, and `"substantive"`. See [`InfoTreeOptions`](../api/interface.md#lean_interact.interface.InfoTreeOptions) for details.
|
|
52
51
|
|
|
53
52
|
```python exec="on" source="above" session="extraction" result="python"
|
|
54
53
|
from lean_interact.interface import InfoTree, InfoTreeOptions
|
|
@@ -64,7 +63,7 @@ for tree in trees:
|
|
|
64
63
|
|
|
65
64
|
## Root goals and messages
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
Set `root_goals=True` to retrieve initial goals for declarations (even if already proved).
|
|
68
67
|
|
|
69
68
|
```python exec="on" source="above" session="extraction" result="python"
|
|
70
69
|
print(server.run(Command(cmd=code, root_goals=True)))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Examples
|
|
2
2
|
|
|
3
|
-
This page provides practical examples of using LeanInteract in different scenarios.
|
|
3
|
+
This page provides practical examples of using LeanInteract in different scenarios. Full example scripts are available in the [`examples`](https://github.com/augustepoiroux/LeanInteract/tree/main/examples) directory of the repository.
|
|
4
4
|
|
|
5
5
|
## Basic Theorem Proving
|
|
6
6
|
|
|
@@ -63,8 +63,8 @@ server = LeanServer(config)
|
|
|
63
63
|
response = server.run(Command(cmd="#eval Lean.versionString"))
|
|
64
64
|
print(response.messages[0].data) # Output: "4.21.0-rc3"
|
|
65
65
|
|
|
66
|
-
#
|
|
67
|
-
#
|
|
66
|
+
# For interface compatibility issues with custom REPLs,
|
|
67
|
+
# use run_dict to communicate directly with the REPL:
|
|
68
68
|
result = server.run_dict({"cmd": "#eval Lean.versionString"})
|
|
69
69
|
print(result) # Example raw output from the REPL
|
|
70
70
|
```
|
|
@@ -84,3 +84,6 @@ For more comprehensive examples, check out the following scripts in the examples
|
|
|
84
84
|
|
|
85
85
|
4. [**type_check.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/type_check.py)
|
|
86
86
|
Shows how to optimize type checking using environment states.
|
|
87
|
+
|
|
88
|
+
5. [**extract_mathlib_decls.py**](https://github.com/augustepoiroux/LeanInteract/blob/main/examples/extract_mathlib_decls.py)
|
|
89
|
+
Demonstrates how to extract declarations from Mathlib in parallel using [`LeanServerPool`](../api/pool.md#lean_interact.pool.LeanServerPool).
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
LeanInteract provides a Python interface to the Lean 4 theorem prover via the Lean REPL (Read-Evaluate-Print Loop). It enables
|
|
5
|
+
LeanInteract provides a Python interface to the Lean 4 theorem prover via the Lean REPL (Read-Evaluate-Print Loop). It enables:
|
|
6
6
|
|
|
7
7
|
- Execute Lean code from Python
|
|
8
8
|
- Process Lean files
|
|
@@ -37,7 +37,7 @@ This will:
|
|
|
37
37
|
|
|
38
38
|
### LeanREPLConfig
|
|
39
39
|
|
|
40
|
-
`LeanREPLConfig` sets up the Lean environment:
|
|
40
|
+
[`LeanREPLConfig`](../api/config.md#lean_interact.config.LeanREPLConfig) sets up the Lean environment:
|
|
41
41
|
|
|
42
42
|
```python
|
|
43
43
|
config = LeanREPLConfig(
|
|
@@ -48,13 +48,13 @@ config = LeanREPLConfig(
|
|
|
48
48
|
|
|
49
49
|
### LeanServer
|
|
50
50
|
|
|
51
|
-
`LeanServer` manages communication with the Lean REPL:
|
|
51
|
+
[`LeanServer`](../api/server.md#lean_interact.server.LeanServer) manages communication with the Lean REPL:
|
|
52
52
|
|
|
53
53
|
```python
|
|
54
54
|
server = LeanServer(config)
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
A more robust alternative is `AutoLeanServer
|
|
57
|
+
A more robust alternative is [`AutoLeanServer`](../api/server.md#lean_interact.server.AutoLeanServer), which automatically recovers from (some) crashes:
|
|
58
58
|
|
|
59
59
|
```python
|
|
60
60
|
from lean_interact import AutoLeanServer
|
|
@@ -65,9 +65,9 @@ auto_server = AutoLeanServer(config)
|
|
|
65
65
|
|
|
66
66
|
LeanInteract provides several types of commands:
|
|
67
67
|
|
|
68
|
-
- `Command
|
|
69
|
-
- `FileCommand
|
|
70
|
-
- `ProofStep
|
|
68
|
+
- [`Command`](../api/interface.md#lean_interact.interface.Command): Execute Lean code directly
|
|
69
|
+
- [`FileCommand`](../api/interface.md#lean_interact.interface.FileCommand): Process Lean files
|
|
70
|
+
- [`ProofStep`](../api/interface.md#lean_interact.interface.ProofStep): Work with proofs step by step using tactics
|
|
71
71
|
|
|
72
72
|
Basic command execution:
|
|
73
73
|
|
|
@@ -78,7 +78,7 @@ server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := id"))
|
|
|
78
78
|
## Next Steps
|
|
79
79
|
|
|
80
80
|
- Learn about [basic usage patterns](basic-usage.md)
|
|
81
|
-
- Explore [
|
|
81
|
+
- Explore [performance optimizations](performance.md)
|
|
82
82
|
- Configure [custom Lean environments](custom-lean-configuration.md)
|
|
83
83
|
|
|
84
84
|
Or check out the [API Reference](../api/config.md) for detailed information on all available classes and methods.
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Prerequisites
|
|
4
4
|
|
|
5
|
-
Before installing LeanInteract, ensure
|
|
5
|
+
Before installing LeanInteract, ensure the following prerequisites are met:
|
|
6
6
|
|
|
7
7
|
- Python 3.10 or newer
|
|
8
8
|
- Git (for Lean installation)
|
|
9
|
-
- [Lean 4](https://leanprover-community.github.io/get_started.html) (optional - LeanInteract can install it
|
|
9
|
+
- [Lean 4](https://leanprover-community.github.io/get_started.html) (optional - LeanInteract can install it)
|
|
10
10
|
|
|
11
11
|
We recommend using Linux or macOS for the best experience, but LeanInteract also supports Windows.
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ We recommend using Linux or macOS for the best experience, but LeanInteract also
|
|
|
14
14
|
|
|
15
15
|
### 1. Install the Package
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Install LeanInteract directly from PyPI:
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
pip install lean-interact
|
|
@@ -31,11 +31,11 @@ install-lean
|
|
|
31
31
|
This command will install Elan, which manages Lean versions.
|
|
32
32
|
|
|
33
33
|
!!! warning "Elan Version"
|
|
34
|
-
|
|
34
|
+
The Elan version should be at least 4.0.0.
|
|
35
35
|
|
|
36
36
|
## Verifying Installation
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Verify that LeanInteract is properly installed by running a simple Python script:
|
|
39
39
|
|
|
40
40
|
```python exec="on" source="above" session="install" result="python"
|
|
41
41
|
from lean_interact import LeanREPLConfig, LeanServer, Command
|
|
@@ -54,13 +54,13 @@ print(response)
|
|
|
54
54
|
If everything is set up correctly, the script should output a successful response.
|
|
55
55
|
|
|
56
56
|
!!! note
|
|
57
|
-
The first time
|
|
57
|
+
The first time LeanInteract is run, it might take some time as it downloads the requested Lean version and builds Lean REPL. Subsequent runs will be significantly faster due to caching.
|
|
58
58
|
|
|
59
59
|
## System-Specific Notes
|
|
60
60
|
|
|
61
61
|
### Windows
|
|
62
62
|
|
|
63
|
-
On Windows,
|
|
63
|
+
On Windows, path length limitations may be encountered. For errors related to path length, enable long paths in Windows 10 and later versions by running the following command in an administrator PowerShell:
|
|
64
64
|
|
|
65
65
|
```powershell
|
|
66
66
|
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name LongPathsEnabled -Value 1 -PropertyType DWord -Force
|
|
@@ -71,11 +71,11 @@ For more information, refer to the [Microsoft documentation](https://learn.micro
|
|
|
71
71
|
|
|
72
72
|
### Docker
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
When using LeanInteract in a Docker container, ensure Git is included in the container with sufficient memory allocated, especially when working with Mathlib.
|
|
75
75
|
|
|
76
76
|
## Uninstallation
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
To clear the LeanInteract cache (for troubleshooting or disk space reasons), use:
|
|
79
79
|
|
|
80
80
|
```bash
|
|
81
81
|
clear-lean-cache
|