@@ -39,13 +39,155 @@ export PATH="/home/$USER/.opam/default/bin:$PATH"
3939
40405 . Run the commands for installing the Lean 4 interface as mentioned in [ Quick Setup for Lean 4] ( #quick-setup-for-lean-4 ) .
4141
42- 6 . Change to the project root directory, and run the setup script i.e. ` ./src/scripts/setup.sh ` from the root directory.
43-
44- 7 . Add the following to your ` .bashrc ` file for Lean:
42+ 6 . Add the following to your ` .bashrc ` file for Lean:
4543```
4644export PATH="/home/$USER/.elan/bin:$PATH"
4745```
4846
47+ ## Running Simple Interactions:
48+ 1 . Simple example for Lean 4 interaction:
49+ ``` python
50+ import os
51+ from itp_interface.rl.proof_state import ProofState
52+ from itp_interface.rl.proof_action import ProofAction
53+ from itp_interface.rl.simple_proof_env import ProofEnv
54+ from itp_interface.tools.proof_exec_callback import ProofExecutorCallback
55+ from itp_interface.rl.simple_proof_env import ProofEnvReRankStrategy
56+
57+ project_folder = " src/data/test/lean4_proj"
58+ file_path = " src/data/test/lean4_proj/Lean4Proj/Basic.lean"
59+ # Code for building the Lean project
60+ # cd src/data/test/lean4_proj && lake build
61+ with os.popen(f " cd { project_folder} && lake build " ) as proc:
62+ print (" Building Lean4 project..." )
63+ print (' -' * 15 + ' Build Logs' + ' -' * 15 )
64+ print (proc.read())
65+ print (' -' * 15 + ' End Build Logs' + ' -' * 15 )
66+ # Skip the above code if the project is already built
67+ language = ProofAction.Language.LEAN4
68+ theorem_name = " test3"
69+ # theorem test3 (p q : Prop) (hp : p) (hq : q)
70+ # : p ∧ q ∧ p :=
71+ proof_exec_callback = ProofExecutorCallback(
72+ project_folder = project_folder,
73+ file_path = file_path,
74+ language = language,
75+ always_use_retrieval = False ,
76+ keep_local_context = True
77+ )
78+ always_retrieve_thms = False
79+ retrieval_strategy = ProofEnvReRankStrategy.NO_RE_RANK
80+ env = ProofEnv(" test_lean4" , proof_exec_callback, theorem_name, retrieval_strategy = retrieval_strategy, max_proof_depth = 10 , always_retrieve_thms = always_retrieve_thms)
81+ proof_steps = [
82+ ' apply And.intro' ,
83+ ' exact hp' ,
84+ ' apply And.intro' ,
85+ ' exact hq' ,
86+ ' exact hp'
87+ ]
88+ with env:
89+ for proof_step in proof_steps:
90+ action = ProofAction(
91+ ProofAction.ActionType.RUN_TACTIC ,
92+ language,
93+ tactics = [proof_step])
94+ state, _, next_state, _, done, info = env.step(action)
95+ if info.error_message is not None :
96+ print (f " Error: { info.error_message} " )
97+ # This prints StateChanged, StateUnchanged, Failed, or Done
98+ print (info.progress)
99+ print (' -' * 30 )
100+ if done:
101+ print (" Proof Finished!!" )
102+ else :
103+ s1 : ProofState = state
104+ s2 : ProofState = next_state
105+ print (f " Current Goal: " )
106+ print (' -' * 30 )
107+ for goal in s1.training_data_format.start_goals:
108+ hyps = ' \n ' .join([hyp for hyp in goal.hypotheses])
109+ print (hyps)
110+ print (' |- ' , end = ' ' )
111+ print (goal.goal)
112+ print (f " = " * 30 )
113+ print (f " Action: { proof_step} " )
114+ print (f " = " * 30 )
115+ print (f " Next Goal: " )
116+ print (' -' * 30 )
117+ for goal in s2.training_data_format.start_goals:
118+ hyps = ' \n ' .join([hyp for hyp in goal.hypotheses])
119+ print (hyps)
120+ print (' |- ' , end = ' ' )
121+ print (goal.goal)
122+ print (f " = " * 30 )
123+ ```
124+
125+ 2 . One can also backtrack the last proof action using the following code:
126+ ``` python
127+ action = ProofAction(ProofAction.ActionType.BACKTRACK , language)
128+ state, _, next_state, _, done, info = env.step(action)
129+ ```
130+
131+ 3 . The code for Coq interaction is similar to the Lean 4 interaction. The only difference is the language used in the ` ProofAction ` object. The language for Coq is ` ProofAction.Language.COQ ` . We also need to make sure that the Coq project is ** built** before running the code. Please note that it is important to install the ** correct version of Coq and Coq LSP** for the Coq project. The following code snippet shows how to interact with Coq:
132+ ``` python
133+ project_folder = " src/data/test/coq/custom_group_theory/theories"
134+ file_path = " src/data/test/coq/custom_group_theory/theories/grpthm.v"
135+
136+ # IMPORTANT NOTE : The Coq project must be built before running the code.
137+ # Create a switch for building the Coq project
138+ if os.system(" opam switch simple_grp_theory" ) != 0 :
139+ cmds = [
140+ ' opam switch create simple_grp_theory 4.14.1' ,
141+ ' opam switch simple_grp_theory' ,
142+ ' eval $(opam env)' ,
143+ ' opam repo add coq-released https://coq.inria.fr/opam/released' ,
144+ ' opam pin add -y coq 8.18.0' ,
145+ ' opam pin add -y coq-lsp 0.1.8+8.18'
146+ ]
147+ final_cmd = ' && ' .join(cmds)
148+ os.system(final_cmd)
149+ # IMPORTANT NOTE : Make sure to switch to the correct switch before running the code.
150+ os.system(" opam switch simple_grp_theory && eval $(opam env)" )
151+ # Clean the project
152+ os.system(f " cd { project_folder} && make clean " )
153+ # Build the project
154+ with os.popen(f " cd { project_folder} && make " ) as proc:
155+ print (" Building Coq project..." )
156+ print (' -' * 15 + ' Build Logs' + ' -' * 15 )
157+ print (proc.read())
158+ print (' -' * 15 + ' End Build Logs' + ' -' * 15 )
159+ # Skip the above code if the project is already built
160+ language = ProofAction.Language.COQ # IMPORTANT NOTE : The language will change here to COQ
161+ theorem_name = " algb_identity_sum"
162+ # ....
163+
164+ # IMPORTANT NOTE : As a result of language change, the `ProofExecutorCallback` object will also change.
165+ proof_exec_callback = ProofExecutorCallback(
166+ project_folder = project_folder,
167+ file_path = file_path,
168+ language = language, # The language will change here to COQ
169+ always_use_retrieval = False ,
170+ keep_local_context = True
171+ )
172+
173+ # IMPORTANT NOTE : The proof steps will also change for Coq.
174+ proof_steps = [
175+ ' intros.' ,
176+ ' destruct a.' ,
177+ ' - reflexivity.' ,
178+ ' - reflexivity.'
179+ ]
180+
181+ # IMPORTANT NOTE : As a result of language change, the `action` object will also change.
182+ action = ProofAction(
183+ ProofAction.ActionType.RUN_TACTIC ,
184+ language, # The language will change here to COQ
185+ tactics = [proof_step]
186+ )
187+ ```
188+
189+ 4 . See the file [ src/test/simple_env_test.py] ( src/test/simple_env_test.py ) for more examples for Lean 4 interaction and Coq interaction.
190+
49191## Generating Proof Step Data:
50192
511931.a. You need to run the following command to generate sample proof step data for Lean 4:
0 commit comments