A named tactic that dispatches to Pantograph.
| 75 | |
| 76 | |
| 77 | class Tactic: |
| 78 | """A named tactic that dispatches to Pantograph.""" |
| 79 | |
| 80 | __slots__ = ("_name",) |
| 81 | |
| 82 | def __init__(self, name: str) -> None: |
| 83 | self._name = name |
| 84 | |
| 85 | def apply(self, goal: Goal) -> ApplyResult: |
| 86 | """Apply this tactic to a goal via Pantograph.""" |
| 87 | expr = goal.as_expr() |
| 88 | k = _get_kernel() |
| 89 | lib = k._lib |
| 90 | |
| 91 | ast = _wrap_free_vars(expr) |
| 92 | z3_expr = _marshal_expr(lib, ast) |
| 93 | lean_expr = lib.z3_compile(z3_expr) |
| 94 | gs = k.goal_create_expr(lean_expr) |
| 95 | |
| 96 | result = gs.try_tactic(self._name) |
| 97 | if result.ok and result.state is not None and result.state.is_solved(): |
| 98 | return ApplyResult([]) # proved |
| 99 | # Tactic produced subgoals or failed |
| 100 | return ApplyResult([goal]) # unchanged |
| 101 | |
| 102 | def solver(self): |
| 103 | """Create a Solver that uses this tactic.""" |
| 104 | return Solver() |
| 105 | |
| 106 | def __repr__(self) -> str: |
| 107 | return f"Tactic({self._name})" |
| 108 | |
| 109 | |
| 110 | # --------------------------------------------------------------------------- |
no outgoing calls