-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
66 lines (51 loc) · 1.73 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from typing import Tuple
from agents import Prover, Checker
from interactive import Coqtop
prover = Prover(
goal="Prove the commutativity of addition for natural numbers.",
model="gpt-3.5-turbo",
)
checker = Checker(model="gpt-4-0613")
coqtop = Coqtop()
def check_coq(coq: str) -> Tuple[str, bool]:
"""Check if the coq proof is correct."""
coqtop.reset()
output = ""
success = True
# Execute the coq script line by line
for line in coq.split("\n"):
if line == "":
continue
# If the line starts with a coq comment, skip it
if line[0] == "(":
continue
# Execute the line
output = coqtop.send(line)
output = "\n".join(output)
# Print the result of executing the coq script in yellow
print("\033[93m" + "> " + line + "\033[0m")
print("\033[93m" + output + "\033[0m")
# Check for Error
if "Error" in output:
print(">>> FOUND ERROR <<<")
success = False
break
return output, success
feedback = None
accepted = False
while not accepted:
# Take the first step in the proof
natural, coq = prover.step(input=feedback)
# Print the natural language output in blue
print("\033[94m" + natural + "\033[0m")
# Print the coq output in red
print("\033[91m" + coq + "\033[0m")
coq_output, coq_success = check_coq(coq)
if not coq_success:
feedback = f"Coq error: {coq_output}\n Check your proof for corectness, check the Coq code for syntax errors, and try again."
else:
# Print the feedback in green
feedback, accepted = checker.check(natural)
print("\033[92m" + feedback + "\033[0m")
if accepted:
break