forked from stanford-centaur/PyPantograph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
581 additions
and
513 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
"""Test for special tactics, such as have, let, etc.""" | ||
"""Test for special tactics, such as have, let, etc.""" | ||
import pytest | ||
from pantograph import Server | ||
from pantograph.expr import * | ||
from pantograph.server import TacticFailure | ||
from .utils import apply_tactics | ||
|
||
|
||
def test_simple_have(): | ||
server = Server() | ||
state0 = server.goal_start("1 + (1: Nat) = 2") | ||
state1 = server.goal_tactic(state0, goal_id=0, tactic=TacticHave(branch="(2:Nat) = 1 + 1", binder_name="h")) | ||
state2 = server.goal_tactic(state1, goal_id=0, tactic="simp") | ||
state3 = server.goal_tactic(state2, goal_id=0, tactic="simp") | ||
assert state1.goals == [ | ||
Goal( | ||
variables=[], | ||
target="2 = 1 + 1", | ||
), | ||
Goal( | ||
variables=[Variable(name="h", t="2 = 1 + 1")], | ||
target="1 + 1 = 2", | ||
), | ||
] | ||
assert state2.goals == [ | ||
Goal( | ||
variables=[Variable(name="h", t="2 = 1 + 1")], | ||
target="1 + 1 = 2", | ||
), | ||
] | ||
assert state3.is_solved | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pantograph import Server | ||
from pantograph.expr import GoalState | ||
from loguru import logger | ||
|
||
def apply_tactics(server:Server, state:GoalState, tactics:list): | ||
states = [state] | ||
logger.opt(raw=True).debug(f"{state}\n") | ||
for tactic in tactics: | ||
logger.opt(raw=True).debug(f"{tactic}\n") | ||
state = server.goal_tactic(state, 0, tactic) | ||
if not state.is_solved: | ||
logger.opt(raw=True).debug(f"{state}\n") | ||
else: | ||
logger.debug("close proof") | ||
states.append(state) | ||
return states | ||
|
||
default_header = """ | ||
open BigOperators Real Nat Topology Rat | ||
""" | ||
|
||
def verify_theorem_loading(server: Server, theorem: str) -> tuple[bool, str]: | ||
"""Helper function to verify theorem loading.""" | ||
try: | ||
# the first argument is for the `open` command | ||
unit = server.load_sorry(f"{default_header}\n{theorem} := by sorry")[1] | ||
goal_state, message = unit.goal_state, '\n'.join(unit.messages) | ||
is_valid = ( | ||
goal_state is not None and | ||
len(goal_state.goals) == 1 and | ||
'error' not in message.lower() | ||
) | ||
return is_valid, message | ||
except Exception as e: | ||
logger.error(f"Exception while loading theorem: {e}") | ||
return False, str(e) |