lean-interact 0.2.0__tar.gz → 0.3.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lean-interact
3
- Version: 0.2.0
3
+ Version: 0.3.1
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
@@ -30,6 +30,7 @@ Requires-Python: >=3.10
30
30
  Requires-Dist: gitpython>=3.1.44
31
31
  Requires-Dist: pexpect>=4.9.0
32
32
  Requires-Dist: psutil>=6.1.0
33
+ Requires-Dist: pydantic>=2.11.1
33
34
  Requires-Dist: requests>=2.32.3
34
35
  Requires-Dist: rich>=13.9.4
35
36
  Description-Content-Type: text/markdown
@@ -40,13 +41,11 @@ Description-Content-Type: text/markdown
40
41
 
41
42
  ## Key Features
42
43
 
43
- - **🔗 Interactivity**: Execute Lean code and files directly from Python, and iterate on environment states.
44
- - **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction, enabling quick experimentation.
45
- - Automatically downloads and builds Lean REPL versions for you. Versions are cached for fast reuse.
46
- - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.18.0-rc1`.
47
- - Ensures compatibility with various Lean projects and machine learning benchmarks.
48
- - **📦 Temporary Projects**: Easily instantiate temporary Lean environments with dependencies.
49
- - Useful for experimenting and interacting 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) without manually setting up a Lean project.
44
+ - **🔗 Interactivity**: Execute Lean code and files directly from Python.
45
+ - **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
46
+ - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.18.0`.
47
+ - **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
48
+ - 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).
50
49
 
51
50
  ## Installation and Setup
52
51
 
@@ -60,8 +59,7 @@ Requirements:
60
59
 
61
60
  - Python >= 3.10
62
61
  - git
63
- - [Lean 4](https://leanprover-community.github.io/get_started.html)
64
- - Tip: the `install-lean` command can install Lean 4 for you after installing LeanInteract.
62
+ - [Lean 4](https://leanprover-community.github.io/get_started.html) (or use the `install-lean` command from LeanInteract)
65
63
 
66
64
  > [!NOTE]
67
65
  > This tool is still experimental and has been primarily tested on Linux. Compatibility with macOS is not guaranteed. For Windows, use WSL.
@@ -69,41 +67,30 @@ Requirements:
69
67
 
70
68
  ## Script examples
71
69
 
72
- In the `examples` directory, you will find a few scripts demonstrating how to use LeanInteract. We recommend [uv](https://github.com/astral-sh/uv) to run these scripts (`uv run <script>.py`).
70
+ In the `examples` directory, you will find a few scripts demonstrating how to use LeanInteract.
73
71
 
72
+ - `proof_generation_and_autoformalization.py`: use [DeepSeek-Prover-V1.5](https://arxiv.org/abs/2408.08152), [Goedel-Prover](https://goedel-lm.github.io/), and other models on [MiniF2F](https://github.com/yangky11/miniF2F-lean4) and [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) benchmarks.
74
73
  - `beq_plus.py`: run the autoformalization [BEq+](https://arxiv.org/abs/2406.07222) metric on the [ProofNetVerif](https://huggingface.co/datasets/PAug/ProofNetVerif) benchmark.
75
- - `type_check.py`: optimize type checking of formal statements using environment states.
76
-
77
- Soon to be added:
78
-
79
- - `proof_generation_and_autoformalization.py`: use [DeepSeek-Prover-V1.5](https://arxiv.org/abs/2408.08152), [Goedel-Prover](https://goedel-lm.github.io/), and other models to prove theorems from the [MiniF2F](https://github.com/yangky11/miniF2F-lean4) and [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) benchmarks.
80
- - `statement_autoformalization_sampling.py`: an implementation of the sampling-based statement autoformalization method used in [Improving Autoformalization using Type Checking](https://arxiv.org/abs/2406.07222).
74
+ - `type_check.py`: optimize type checking using environment states.
75
+ - `statement_autoformalization_sampling.py`: sampling-based method used in [Improving Autoformalization using Type Checking](https://arxiv.org/abs/2406.07222).
81
76
 
82
77
  ## Usage
83
78
 
84
79
  ### Default Lean version (latest available)
85
80
 
86
81
  ```python
87
- from lean_interact import LeanREPLConfig, LeanServer
82
+ from lean_interact import LeanREPLConfig, LeanServer, Command
88
83
 
89
84
  config = LeanREPLConfig(verbose=True) # download and build Lean REPL
90
85
  server = LeanServer(config) # start Lean REPL
91
- server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
86
+ server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := id"))
92
87
  ```
93
88
 
94
89
  <details>
95
90
  <summary>Output</summary>
96
91
 
97
- ```json
98
- {"sorries": [{"proofState": 0,
99
- "pos": {"line": 1, "column": 40},
100
- "goal": "n : Nat\n⊢ n = 5 → n = 5",
101
- "endPos": {"line": 1, "column": 45}}],
102
- "messages": [{"severity": "warning",
103
- "pos": {"line": 1, "column": 8},
104
- "endPos": {"line": 1, "column": 10},
105
- "data": "declaration uses 'sorry'"}],
106
- "env": 0}
92
+ ```python
93
+ CommandResponse(env=0)
107
94
  ```
108
95
 
109
96
  </details>
@@ -111,14 +98,14 @@ server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
111
98
  Iterate on the environment state:
112
99
 
113
100
  ```python
114
- server.run_code("theorem ex2 (x : Nat) : x = 5 → x = 5 := by\n exact ex x", env=0)
101
+ server.run(Command(cmd="example (x : Nat) : x = 5 → x = 5 := by exact ex x", env=0))
115
102
  ```
116
103
 
117
104
  <details>
118
105
  <summary>Output</summary>
119
106
 
120
- ```json
121
- {"env": 1}
107
+ ```python
108
+ CommandResponse(env=1)
122
109
  ```
123
110
 
124
111
  </details>
@@ -144,11 +131,13 @@ or
144
131
  config = LeanREPLConfig(project=GitProject("https://github.com/yangky11/lean4-example"))
145
132
  ```
146
133
 
147
- You can then use `run_code` and `run_file` as usual:
134
+ You can then use `run` as usual:
148
135
 
149
136
  ```python
137
+ from lean_interact import FileCommand
138
+
150
139
  server = LeanServer(config)
151
- server.run_file("file.lean")
140
+ server.run(FileCommand(path="file.lean"))
152
141
  ```
153
142
 
154
143
  > [!IMPORTANT]
@@ -157,6 +146,8 @@ server.run_file("file.lean")
157
146
  ### Temporary project with dependencies
158
147
 
159
148
  ```python
149
+ from lean_interact import TempRequireProject
150
+
160
151
  config = LeanREPLConfig(lean_version="v4.7.0", project=TempRequireProject([LeanRequire(
161
152
  name="mathlib",
162
153
  git="https://github.com/leanprover-community/mathlib4.git",
@@ -174,23 +165,32 @@ You can then use Mathlib as follows:
174
165
 
175
166
  ```python
176
167
  server = LeanServer(config)
177
- server.run_code("""import Mathlib
178
- theorem ex_mathlib (x : ℝ) (y : ℚ) :\n ( Irrational x ) -> Irrational ( x + y ) := sorry""")
168
+ server.run(Command(cmd="""import Mathlib
169
+ theorem ex_mathlib (x : ℝ) (y : ℚ) :
170
+ ( Irrational x ) -> Irrational ( x + y ) := sorry"""))
179
171
  ```
180
172
 
181
173
  <details>
182
174
  <summary>Output</summary>
183
175
 
184
- ```json
185
- {"sorries": [{"proofState": 0,
186
- "pos": {"line": 4, "column": 26},
187
- "goal": "x : ℝ\ny : ℚ\n⊢ Irrational (x + ↑y)",
188
- "endPos": {"line": 4, "column": 31}}],
189
- "messages": [{"severity": "warning",
190
- "pos": {"line": 3, "column": 8},
191
- "endPos": {"line": 3, "column": 18},
192
- "data": "declaration uses 'sorry'"}],
193
- "env": 0}
176
+ ```python
177
+ CommandResponse(
178
+ messages=[
179
+ Message(
180
+ start_pos=Pos(line=2, column=8),
181
+ end_pos=Pos(line=2, column=18),
182
+ data="declaration uses 'sorry'",
183
+ severity='warning'
184
+ )],
185
+ sorries=[
186
+ Sorry(
187
+ start_pos=Pos(line=3, column=46),
188
+ end_pos=Pos(line=3, column=51),
189
+ goal='x : ℝ\ny : ℚ\n⊢ Irrational x → Irrational (x + ↑y)',
190
+ proof_state=0
191
+ )],
192
+ env=0
193
+ )
194
194
  ```
195
195
 
196
196
  </details>
@@ -205,7 +205,9 @@ theorem ex_mathlib (x : ℝ) (y : ℚ) :\n ( Irrational x ) -> Irrational ( x +
205
205
  For more control over the temporary project, you can use `TemporaryProject` to specify the content of the lakefile.
206
206
 
207
207
  ```python
208
- config = LeanREPLConfig(lean_version="v4.18.0-rc1", project=TemporaryProject("""
208
+ from lean_interact import TemporaryProject
209
+
210
+ config = LeanREPLConfig(lean_version="v4.18.0", project=TemporaryProject("""
209
211
  import Lake
210
212
  open Lake DSL
211
213
 
@@ -217,29 +219,37 @@ lean_exe "dummy" where
217
219
  root := `Main
218
220
 
219
221
  require mathlib from git
220
- "https://github.com/leanprover-community/mathlib4.git" @ "v4.18.0-rc1"
222
+ "https://github.com/leanprover-community/mathlib4.git" @ "v4.18.0"
221
223
  """))
222
224
  ```
223
225
 
224
- ### Tactic and proof modes (experimental)
226
+ ### Tactic mode (experimental)
225
227
 
226
228
  ```python
227
- server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
229
+ server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := sorry"))
228
230
  ```
229
231
 
230
232
  <details>
231
233
  <summary>Output</summary>
232
234
 
233
- ```json
234
- {"sorries": [{"proofState": 0,
235
- "pos": {"line": 1, "column": 40},
236
- "goal": "n : Nat\n⊢ n = 5 → n = 5",
237
- "endPos": {"line": 1, "column": 45}}],
238
- "messages": [{"severity": "warning",
239
- "pos": {"line": 1, "column": 8},
240
- "endPos": {"line": 1, "column": 10},
241
- "data": "declaration uses 'sorry'"}],
242
- "env": 0}
235
+ ```python
236
+ CommandResponse(
237
+ messages=[
238
+ Message(
239
+ start_pos=Pos(line=1, column=8),
240
+ end_pos=Pos(line=1, column=10),
241
+ data="declaration uses 'sorry'",
242
+ severity='warning'
243
+ )],
244
+ sorries=[
245
+ Sorry(
246
+ start_pos=Pos(line=1, column=40),
247
+ end_pos=Pos(line=1, column=45),
248
+ goal='n : Nat\n⊢ n = 5 → n = 5',
249
+ proof_state=0
250
+ )],
251
+ env=0
252
+ )
243
253
  ```
244
254
 
245
255
  </details>
@@ -247,50 +257,52 @@ server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
247
257
  You can then iterate on the proof state by executing tactics:
248
258
 
249
259
  ```python
250
- server.run_tactic("intro h", proof_state=0)
260
+ server.run(ProofStep(tactic="intro h", proof_state=0))
251
261
  ```
252
262
 
253
263
  <details>
254
264
  <summary>Output</summary>
255
265
 
256
- ```json
257
- {"proofState": 1, "goals": ["n : Nat\nh : n = 5\n⊢ n = 5"]}
266
+ ```python
267
+ ProofStepResponse(goals=['n : Nat\nh : n = 5\n⊢ n = 5'], proof_state=1)
258
268
  ```
259
269
 
260
270
  </details>
261
271
 
262
272
  ```python
263
- server.run_tactic("exact h", proof_state=1)
273
+ server.run(ProofStep(tactic="exact h", proof_state=1))
264
274
  ```
265
275
 
266
276
  <details>
267
277
  <summary>Output</summary>
268
278
 
269
- ```json
270
- {"proofState": 2, "goals": []}
279
+ ```python
280
+ ProofStepResponse(goals=[], proof_state=2)
271
281
  ```
272
282
 
273
283
  </details>
274
284
 
275
- or by running the entire/partial proofs:
285
+ or by directly running the entire proof:
276
286
 
277
287
  ```python
278
- server.run_proof("intro h\nexact h", proof_state=0)
288
+ server.run(ProofStep(tactic="(\nintro h\nexact h)", proof_state=0))
279
289
  ```
280
290
 
281
291
  <details>
282
292
  <summary>Output</summary>
283
293
 
284
- ```json
285
- {"proofState": 3, "goals": []}
294
+ ```python
295
+ ProofStepResponse(goals=[], proof_state=3)
286
296
  ```
287
297
 
288
298
  </details>
289
299
 
290
300
  ## Helper Commands
291
301
 
292
- - `install_lean`: Installs Lean 4 version manager `elan`.
293
- - `clear_lean_cache`: Removes all Lean REPL versions and temporary projects in the package cache. This can help resolve some issues. If it does, please open an issue.
302
+ The following commands are installed with LeanInteract:
303
+
304
+ - `install-lean`: Installs Lean 4 version manager `elan`.
305
+ - `clear-lean-cache`: Removes all Lean REPL versions and temporary projects in the package cache. This can help resolve some issues. If it does, please open an issue.
294
306
 
295
307
  ## Advanced options
296
308
 
@@ -298,8 +310,8 @@ server.run_proof("intro h\nexact h", proof_state=0)
298
310
 
299
311
  Two versions of Lean servers are available:
300
312
 
301
- - **`LeanServer`**: A wrapper around Lean REPL. Interact with it using `run_code`, `run_file`, and `run_tactic` methods.
302
- - **`AutoLeanServer`**: An experimental subclass of `LeanServer` automatically recovering from crashes and timeouts. It also monitors memory usage to limit *out of memory* crashes in multiprocessing contexts. Use the `add_to_session_cache` attribute available in various methods to prevent selected environment/proof states to be cleared.
313
+ - **`LeanServer`**: A wrapper around Lean REPL. Interact with it using the `run` method.
314
+ - **`AutoLeanServer`**: An experimental subclass of `LeanServer` automatically recovering from some crashes and timeouts. It also monitors memory usage to limit *out of memory* issues in multiprocessing contexts. Use the `add_to_session_cache` attribute available in the `run` method to prevent selected environment/proof states to be cleared.
303
315
 
304
316
  > [!TIP]
305
317
  >
@@ -4,13 +4,11 @@
4
4
 
5
5
  ## Key Features
6
6
 
7
- - **🔗 Interactivity**: Execute Lean code and files directly from Python, and iterate on environment states.
8
- - **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction, enabling quick experimentation.
9
- - Automatically downloads and builds Lean REPL versions for you. Versions are cached for fast reuse.
10
- - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.18.0-rc1`.
11
- - Ensures compatibility with various Lean projects and machine learning benchmarks.
12
- - **📦 Temporary Projects**: Easily instantiate temporary Lean environments with dependencies.
13
- - Useful for experimenting and interacting 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) without manually setting up a Lean project.
7
+ - **🔗 Interactivity**: Execute Lean code and files directly from Python.
8
+ - **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
9
+ - **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.18.0`.
10
+ - **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
11
+ - 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).
14
12
 
15
13
  ## Installation and Setup
16
14
 
@@ -24,8 +22,7 @@ Requirements:
24
22
 
25
23
  - Python >= 3.10
26
24
  - git
27
- - [Lean 4](https://leanprover-community.github.io/get_started.html)
28
- - Tip: the `install-lean` command can install Lean 4 for you after installing LeanInteract.
25
+ - [Lean 4](https://leanprover-community.github.io/get_started.html) (or use the `install-lean` command from LeanInteract)
29
26
 
30
27
  > [!NOTE]
31
28
  > This tool is still experimental and has been primarily tested on Linux. Compatibility with macOS is not guaranteed. For Windows, use WSL.
@@ -33,41 +30,30 @@ Requirements:
33
30
 
34
31
  ## Script examples
35
32
 
36
- In the `examples` directory, you will find a few scripts demonstrating how to use LeanInteract. We recommend [uv](https://github.com/astral-sh/uv) to run these scripts (`uv run <script>.py`).
33
+ In the `examples` directory, you will find a few scripts demonstrating how to use LeanInteract.
37
34
 
35
+ - `proof_generation_and_autoformalization.py`: use [DeepSeek-Prover-V1.5](https://arxiv.org/abs/2408.08152), [Goedel-Prover](https://goedel-lm.github.io/), and other models on [MiniF2F](https://github.com/yangky11/miniF2F-lean4) and [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) benchmarks.
38
36
  - `beq_plus.py`: run the autoformalization [BEq+](https://arxiv.org/abs/2406.07222) metric on the [ProofNetVerif](https://huggingface.co/datasets/PAug/ProofNetVerif) benchmark.
39
- - `type_check.py`: optimize type checking of formal statements using environment states.
40
-
41
- Soon to be added:
42
-
43
- - `proof_generation_and_autoformalization.py`: use [DeepSeek-Prover-V1.5](https://arxiv.org/abs/2408.08152), [Goedel-Prover](https://goedel-lm.github.io/), and other models to prove theorems from the [MiniF2F](https://github.com/yangky11/miniF2F-lean4) and [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) benchmarks.
44
- - `statement_autoformalization_sampling.py`: an implementation of the sampling-based statement autoformalization method used in [Improving Autoformalization using Type Checking](https://arxiv.org/abs/2406.07222).
37
+ - `type_check.py`: optimize type checking using environment states.
38
+ - `statement_autoformalization_sampling.py`: sampling-based method used in [Improving Autoformalization using Type Checking](https://arxiv.org/abs/2406.07222).
45
39
 
46
40
  ## Usage
47
41
 
48
42
  ### Default Lean version (latest available)
49
43
 
50
44
  ```python
51
- from lean_interact import LeanREPLConfig, LeanServer
45
+ from lean_interact import LeanREPLConfig, LeanServer, Command
52
46
 
53
47
  config = LeanREPLConfig(verbose=True) # download and build Lean REPL
54
48
  server = LeanServer(config) # start Lean REPL
55
- server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
49
+ server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := id"))
56
50
  ```
57
51
 
58
52
  <details>
59
53
  <summary>Output</summary>
60
54
 
61
- ```json
62
- {"sorries": [{"proofState": 0,
63
- "pos": {"line": 1, "column": 40},
64
- "goal": "n : Nat\n⊢ n = 5 → n = 5",
65
- "endPos": {"line": 1, "column": 45}}],
66
- "messages": [{"severity": "warning",
67
- "pos": {"line": 1, "column": 8},
68
- "endPos": {"line": 1, "column": 10},
69
- "data": "declaration uses 'sorry'"}],
70
- "env": 0}
55
+ ```python
56
+ CommandResponse(env=0)
71
57
  ```
72
58
 
73
59
  </details>
@@ -75,14 +61,14 @@ server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
75
61
  Iterate on the environment state:
76
62
 
77
63
  ```python
78
- server.run_code("theorem ex2 (x : Nat) : x = 5 → x = 5 := by\n exact ex x", env=0)
64
+ server.run(Command(cmd="example (x : Nat) : x = 5 → x = 5 := by exact ex x", env=0))
79
65
  ```
80
66
 
81
67
  <details>
82
68
  <summary>Output</summary>
83
69
 
84
- ```json
85
- {"env": 1}
70
+ ```python
71
+ CommandResponse(env=1)
86
72
  ```
87
73
 
88
74
  </details>
@@ -108,11 +94,13 @@ or
108
94
  config = LeanREPLConfig(project=GitProject("https://github.com/yangky11/lean4-example"))
109
95
  ```
110
96
 
111
- You can then use `run_code` and `run_file` as usual:
97
+ You can then use `run` as usual:
112
98
 
113
99
  ```python
100
+ from lean_interact import FileCommand
101
+
114
102
  server = LeanServer(config)
115
- server.run_file("file.lean")
103
+ server.run(FileCommand(path="file.lean"))
116
104
  ```
117
105
 
118
106
  > [!IMPORTANT]
@@ -121,6 +109,8 @@ server.run_file("file.lean")
121
109
  ### Temporary project with dependencies
122
110
 
123
111
  ```python
112
+ from lean_interact import TempRequireProject
113
+
124
114
  config = LeanREPLConfig(lean_version="v4.7.0", project=TempRequireProject([LeanRequire(
125
115
  name="mathlib",
126
116
  git="https://github.com/leanprover-community/mathlib4.git",
@@ -138,23 +128,32 @@ You can then use Mathlib as follows:
138
128
 
139
129
  ```python
140
130
  server = LeanServer(config)
141
- server.run_code("""import Mathlib
142
- theorem ex_mathlib (x : ℝ) (y : ℚ) :\n ( Irrational x ) -> Irrational ( x + y ) := sorry""")
131
+ server.run(Command(cmd="""import Mathlib
132
+ theorem ex_mathlib (x : ℝ) (y : ℚ) :
133
+ ( Irrational x ) -> Irrational ( x + y ) := sorry"""))
143
134
  ```
144
135
 
145
136
  <details>
146
137
  <summary>Output</summary>
147
138
 
148
- ```json
149
- {"sorries": [{"proofState": 0,
150
- "pos": {"line": 4, "column": 26},
151
- "goal": "x : ℝ\ny : ℚ\n⊢ Irrational (x + ↑y)",
152
- "endPos": {"line": 4, "column": 31}}],
153
- "messages": [{"severity": "warning",
154
- "pos": {"line": 3, "column": 8},
155
- "endPos": {"line": 3, "column": 18},
156
- "data": "declaration uses 'sorry'"}],
157
- "env": 0}
139
+ ```python
140
+ CommandResponse(
141
+ messages=[
142
+ Message(
143
+ start_pos=Pos(line=2, column=8),
144
+ end_pos=Pos(line=2, column=18),
145
+ data="declaration uses 'sorry'",
146
+ severity='warning'
147
+ )],
148
+ sorries=[
149
+ Sorry(
150
+ start_pos=Pos(line=3, column=46),
151
+ end_pos=Pos(line=3, column=51),
152
+ goal='x : ℝ\ny : ℚ\n⊢ Irrational x → Irrational (x + ↑y)',
153
+ proof_state=0
154
+ )],
155
+ env=0
156
+ )
158
157
  ```
159
158
 
160
159
  </details>
@@ -169,7 +168,9 @@ theorem ex_mathlib (x : ℝ) (y : ℚ) :\n ( Irrational x ) -> Irrational ( x +
169
168
  For more control over the temporary project, you can use `TemporaryProject` to specify the content of the lakefile.
170
169
 
171
170
  ```python
172
- config = LeanREPLConfig(lean_version="v4.18.0-rc1", project=TemporaryProject("""
171
+ from lean_interact import TemporaryProject
172
+
173
+ config = LeanREPLConfig(lean_version="v4.18.0", project=TemporaryProject("""
173
174
  import Lake
174
175
  open Lake DSL
175
176
 
@@ -181,29 +182,37 @@ lean_exe "dummy" where
181
182
  root := `Main
182
183
 
183
184
  require mathlib from git
184
- "https://github.com/leanprover-community/mathlib4.git" @ "v4.18.0-rc1"
185
+ "https://github.com/leanprover-community/mathlib4.git" @ "v4.18.0"
185
186
  """))
186
187
  ```
187
188
 
188
- ### Tactic and proof modes (experimental)
189
+ ### Tactic mode (experimental)
189
190
 
190
191
  ```python
191
- server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
192
+ server.run(Command(cmd="theorem ex (n : Nat) : n = 5 → n = 5 := sorry"))
192
193
  ```
193
194
 
194
195
  <details>
195
196
  <summary>Output</summary>
196
197
 
197
- ```json
198
- {"sorries": [{"proofState": 0,
199
- "pos": {"line": 1, "column": 40},
200
- "goal": "n : Nat\n⊢ n = 5 → n = 5",
201
- "endPos": {"line": 1, "column": 45}}],
202
- "messages": [{"severity": "warning",
203
- "pos": {"line": 1, "column": 8},
204
- "endPos": {"line": 1, "column": 10},
205
- "data": "declaration uses 'sorry'"}],
206
- "env": 0}
198
+ ```python
199
+ CommandResponse(
200
+ messages=[
201
+ Message(
202
+ start_pos=Pos(line=1, column=8),
203
+ end_pos=Pos(line=1, column=10),
204
+ data="declaration uses 'sorry'",
205
+ severity='warning'
206
+ )],
207
+ sorries=[
208
+ Sorry(
209
+ start_pos=Pos(line=1, column=40),
210
+ end_pos=Pos(line=1, column=45),
211
+ goal='n : Nat\n⊢ n = 5 → n = 5',
212
+ proof_state=0
213
+ )],
214
+ env=0
215
+ )
207
216
  ```
208
217
 
209
218
  </details>
@@ -211,50 +220,52 @@ server.run_code("theorem ex (n : Nat) : n = 5 → n = 5 := sorry")
211
220
  You can then iterate on the proof state by executing tactics:
212
221
 
213
222
  ```python
214
- server.run_tactic("intro h", proof_state=0)
223
+ server.run(ProofStep(tactic="intro h", proof_state=0))
215
224
  ```
216
225
 
217
226
  <details>
218
227
  <summary>Output</summary>
219
228
 
220
- ```json
221
- {"proofState": 1, "goals": ["n : Nat\nh : n = 5\n⊢ n = 5"]}
229
+ ```python
230
+ ProofStepResponse(goals=['n : Nat\nh : n = 5\n⊢ n = 5'], proof_state=1)
222
231
  ```
223
232
 
224
233
  </details>
225
234
 
226
235
  ```python
227
- server.run_tactic("exact h", proof_state=1)
236
+ server.run(ProofStep(tactic="exact h", proof_state=1))
228
237
  ```
229
238
 
230
239
  <details>
231
240
  <summary>Output</summary>
232
241
 
233
- ```json
234
- {"proofState": 2, "goals": []}
242
+ ```python
243
+ ProofStepResponse(goals=[], proof_state=2)
235
244
  ```
236
245
 
237
246
  </details>
238
247
 
239
- or by running the entire/partial proofs:
248
+ or by directly running the entire proof:
240
249
 
241
250
  ```python
242
- server.run_proof("intro h\nexact h", proof_state=0)
251
+ server.run(ProofStep(tactic="(\nintro h\nexact h)", proof_state=0))
243
252
  ```
244
253
 
245
254
  <details>
246
255
  <summary>Output</summary>
247
256
 
248
- ```json
249
- {"proofState": 3, "goals": []}
257
+ ```python
258
+ ProofStepResponse(goals=[], proof_state=3)
250
259
  ```
251
260
 
252
261
  </details>
253
262
 
254
263
  ## Helper Commands
255
264
 
256
- - `install_lean`: Installs Lean 4 version manager `elan`.
257
- - `clear_lean_cache`: Removes all Lean REPL versions and temporary projects in the package cache. This can help resolve some issues. If it does, please open an issue.
265
+ The following commands are installed with LeanInteract:
266
+
267
+ - `install-lean`: Installs Lean 4 version manager `elan`.
268
+ - `clear-lean-cache`: Removes all Lean REPL versions and temporary projects in the package cache. This can help resolve some issues. If it does, please open an issue.
258
269
 
259
270
  ## Advanced options
260
271
 
@@ -262,8 +273,8 @@ server.run_proof("intro h\nexact h", proof_state=0)
262
273
 
263
274
  Two versions of Lean servers are available:
264
275
 
265
- - **`LeanServer`**: A wrapper around Lean REPL. Interact with it using `run_code`, `run_file`, and `run_tactic` methods.
266
- - **`AutoLeanServer`**: An experimental subclass of `LeanServer` automatically recovering from crashes and timeouts. It also monitors memory usage to limit *out of memory* crashes in multiprocessing contexts. Use the `add_to_session_cache` attribute available in various methods to prevent selected environment/proof states to be cleared.
276
+ - **`LeanServer`**: A wrapper around Lean REPL. Interact with it using the `run` method.
277
+ - **`AutoLeanServer`**: An experimental subclass of `LeanServer` automatically recovering from some crashes and timeouts. It also monitors memory usage to limit *out of memory* issues in multiprocessing contexts. Use the `add_to_session_cache` attribute available in the `run` method to prevent selected environment/proof states to be cleared.
267
278
 
268
279
  > [!TIP]
269
280
  >