-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,55 @@ | ||
# from z3 import * | ||
import cvc5 | ||
from cvc5.pythonic import * | ||
|
||
Z3PPObject = object | ||
FuncDecl = FuncDeclRef | ||
|
||
|
||
class Solver(cvc5.pythonic.Solver): | ||
def __init__(self): | ||
super().__init__() | ||
self.set("produce-unsat-cores", "true") | ||
|
||
def set(self, option, value): | ||
if option == "timeout": | ||
self.set("tlimit-per", value) | ||
import os | ||
|
||
Z3SOLVER = "z3" | ||
CVC5SOLVER = "cvc5" | ||
solver = os.getenv("KNUCKLE_SOLVER") | ||
if solver is None or solver == Z3SOLVER: | ||
solver = "z3" | ||
from z3 import * | ||
Check failure on line 8 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F403)
Check failure on line 8 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F403)
|
||
elif solver == CVC5SOLVER: | ||
import cvc5 | ||
from cvc5.pythonic import * | ||
Check failure on line 11 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F403)
Check failure on line 11 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F403)
|
||
|
||
Z3PPObject = object | ||
FuncDecl = FuncDeclRef | ||
Check failure on line 14 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F405)
Check failure on line 14 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F405)
|
||
|
||
class Solver(cvc5.pythonic.Solver): | ||
def __init__(self): | ||
super().__init__() | ||
self.set("produce-unsat-cores", "true") | ||
|
||
def set(self, option, value): | ||
if option == "timeout": | ||
self.set("tlimit-per", value) | ||
else: | ||
super().set(option, value) | ||
|
||
def assert_and_track(self, thm, name): | ||
x = Bool(name) | ||
Check failure on line 28 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F405)
Check failure on line 28 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F405)
|
||
self.add(x) | ||
return self.add(Implies(x, thm)) | ||
Check failure on line 30 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F405)
Check failure on line 30 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F405)
|
||
|
||
def unsat_core(self): | ||
return [cvc5.pythonic.BoolRef(x) for x in self.solver.getUnsatCore()] | ||
|
||
def Const(name, sort): | ||
# _to_expr doesn't have a DatatypeRef case | ||
x = cvc5.pythonic.Const(name, sort) | ||
if isinstance(sort, DatatypeSortRef): | ||
Check failure on line 38 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F405)
Check failure on line 38 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F405)
|
||
x = DatatypeRef(x.ast, x.ctx, x.reverse_children) | ||
Check failure on line 39 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F405)
Check failure on line 39 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F405)
|
||
return x | ||
|
||
def Consts(names, sort): | ||
return [Const(name, sort) for name in names.split()] | ||
|
||
def _qsort(self): | ||
if self.is_lambda(): | ||
return ArraySort(self.var_sort(0), self.body().sort()) | ||
Check failure on line 47 in knuckledragger/smt.py GitHub Actions / build (3.9)Ruff (F405)
Check failure on line 47 in knuckledragger/smt.py GitHub Actions / build (3.10)Ruff (F405)
|
||
else: | ||
super().set(option, value) | ||
|
||
def assert_and_track(self, thm, name): | ||
x = Bool(name) | ||
self.add(x) | ||
return self.add(Implies(x, thm)) | ||
|
||
def unsat_core(self): | ||
return [cvc5.pythonic.BoolRef(x) for x in self.solver.getUnsatCore()] | ||
|
||
|
||
def Const(name, sort): | ||
# _to_expr doesn't have a DatatypeRef case | ||
x = cvc5.pythonic.Const(name, sort) | ||
if isinstance(sort, DatatypeSortRef): | ||
x = DatatypeRef(x.ast, x.ctx, x.reverse_children) | ||
return x | ||
|
||
|
||
def Consts(names, sort): | ||
return [Const(name, sort) for name in names.split()] | ||
|
||
|
||
def _qsort(self): | ||
if self.is_lambda(): | ||
return ArraySort(self.var_sort(0), self.body().sort()) | ||
else: | ||
return BoolSort(self.ctx) | ||
|
||
return BoolSort(self.ctx) | ||
|
||
QuantifierRef.sort = _qsort | ||
QuantifierRef.sort = _qsort | ||
else: | ||
raise ValueError( | ||
"Unknown solver in environment variable KNUCKLE_SOLVER: {}".format(solver) | ||
) |