object PyUnicode_FromWideChar(const wchar_t*, Py_ssize_t)
void PyMem_Free(void*)
-################################## DECORATORS #################################
-def expand_list_arg(num_req_args=0):
- """
- Creates a decorator that looks at index num_req_args of the args,
- if it's a list, it expands it before calling the function.
- """
- def decorator(func):
- @wraps(func)
- def wrapper(owner, *args):
- if len(args) == num_req_args + 1 and \
- isinstance(args[num_req_args], list):
- args = list(args[:num_req_args]) + args[num_req_args]
- return func(owner, *args)
- return wrapper
- return decorator
-###############################################################################
-
# Style Guidelines
### Using PEP-8 spacing recommendations
### Limit linewidth to 79 characters
sort.csort = self.csolver.mkParamSort(symbolname.encode())
return sort
- @expand_list_arg(num_req_args=0)
def mkPredicateSort(self, *sorts):
"""
Create a predicate sort.
- :param sorts: The list of sorts of the predicate, as a list or as
- distinct arguments.
+ :param sorts: The list of sorts of the predicate.
:return: The predicate sort.
"""
cdef Sort sort = Sort(self)
sort.csort = self.csolver.mkPredicateSort(<const vector[c_Sort]&> v)
return sort
- @expand_list_arg(num_req_args=0)
def mkRecordSort(self, *fields):
"""
Create a record sort
.. warning:: This method is experimental and may change in future
versions.
- :param fields: The list of fields of the record, as a list or as
- distinct arguments.
+ :param fields: The list of fields of the record.
:return: The record sort.
"""
cdef Sort sort = Sort(self)
arity, symbol.encode())
return sort
- @expand_list_arg(num_req_args=0)
def mkTupleSort(self, *sorts):
"""
Create a tuple sort.
- :param sorts: Of the elements of the tuple, as a list or as
- distinct arguments.
+ :param sorts: Of the elements of the tuple.
:return: The tuple sort.
"""
cdef Sort sort = Sort(self)
sort.csort = self.csolver.mkTupleSort(v)
return sort
- @expand_list_arg(num_req_args=1)
def mkTerm(self, kind_or_op, *args):
"""
Create a term.
result.cterm = self.csolver.mkTuple(csorts, cterms)
return result
- @expand_list_arg(num_req_args=0)
def mkOp(self, k, *args):
"""
Create operator.
term.cterm = self.csolver.mkUniverseSet(sort.csort)
return term
- @expand_list_arg(num_req_args=0)
def mkBitVector(self, *args):
"""
Create bit-vector value.
grammar.cgrammar)
return term
- @expand_list_arg(num_req_args=0)
def checkSatAssuming(self, *assumptions):
"""
Check satisfiability assuming the given formula.
( check-sat-assuming ( <prop_literal> ) )
- :param assumptions: The formulas to assume, as a list or as
- distinct arguments.
+ :param assumptions: The formulas to assume.
:return: The result of the satisfiability check.
"""
cdef Result r = Result()
r.cr = self.csolver.checkSatAssuming(<const vector[c_Term]&> v)
return r
- @expand_list_arg(num_req_args=1)
def declareDatatype(self, str symbol, *ctors):
"""
Create datatype sort.
( declare-datatype <symbol> <datatype_decl> )
:param symbol: The name of the datatype sort.
- :param ctors: The constructor declarations of the datatype sort, as
- a list or as distinct arguments.
+ :param ctors: The constructor declarations of the datatype sort.
:return: The datatype sort.
"""
cdef Sort sort = Sort(self)
def test_mk_predicate_sort(solver):
- solver.mkPredicateSort([solver.getIntegerSort()])
+ solver.mkPredicateSort(solver.getIntegerSort())
with pytest.raises(RuntimeError):
- solver.mkPredicateSort([])
+ solver.mkPredicateSort()
funSort = solver.mkFunctionSort(solver.mkUninterpretedSort("u"),\
solver.getIntegerSort())
# functions as arguments are allowed
- solver.mkPredicateSort([solver.getIntegerSort(), funSort])
+ solver.mkPredicateSort(solver.getIntegerSort(), funSort)
slv = cvc5.Solver()
with pytest.raises(RuntimeError):
- slv.mkPredicateSort([solver.getIntegerSort()])
+ slv.mkPredicateSort(solver.getIntegerSort())
def test_mk_record_sort(solver):
fields = [("b", solver.getBooleanSort()),\
("bv", solver.mkBitVectorSort(8)),\
("i", solver.getIntegerSort())]
- empty = []
- solver.mkRecordSort(fields)
- solver.mkRecordSort(empty)
- recSort = solver.mkRecordSort(fields)
+ solver.mkRecordSort(*fields)
+ solver.mkRecordSort()
+ recSort = solver.mkRecordSort(*fields)
recSort.getDatatype()
def test_mk_tuple_sort(solver):
- solver.mkTupleSort([solver.getIntegerSort()])
+ solver.mkTupleSort(solver.getIntegerSort())
funSort = solver.mkFunctionSort(solver.mkUninterpretedSort("u"),\
solver.getIntegerSort())
with pytest.raises(RuntimeError):
- solver.mkTupleSort([solver.getIntegerSort(), funSort])
+ solver.mkTupleSort(solver.getIntegerSort(), funSort)
slv = cvc5.Solver()
with pytest.raises(RuntimeError):
- slv.mkTupleSort([solver.getIntegerSort()])
+ slv.mkTupleSort(solver.getIntegerSort())
def test_mk_bit_vector(solver):
bv32 = solver.mkBitVectorSort(32)
a = solver.mkConst(bv32, "a")
b = solver.mkConst(bv32, "b")
- v1 = [a, b]
- v2 = [a, cvc5.Term(solver)]
- v3 = [a, solver.mkTrue()]
- v4 = [solver.mkInteger(1), solver.mkInteger(2)]
- v5 = [solver.mkInteger(1), cvc5.Term(solver)]
- v6 = []
slv = cvc5.Solver()
# mkTerm(Kind kind) const
solver.mkPi()
solver.mkTerm(Kind.Pi)
- solver.mkTerm(Kind.Pi, v6)
solver.mkTerm(solver.mkOp(Kind.Pi))
- solver.mkTerm(solver.mkOp(Kind.Pi), v6)
solver.mkTerm(Kind.RegexpNone)
- solver.mkTerm(Kind.RegexpNone, v6)
solver.mkTerm(solver.mkOp(Kind.RegexpNone))
- solver.mkTerm(solver.mkOp(Kind.RegexpNone), v6)
solver.mkTerm(Kind.RegexpAllchar)
- solver.mkTerm(Kind.RegexpAllchar, v6)
solver.mkTerm(solver.mkOp(Kind.RegexpAllchar))
- solver.mkTerm(solver.mkOp(Kind.RegexpAllchar), v6)
solver.mkTerm(Kind.SepEmp)
- solver.mkTerm(Kind.SepEmp, v6)
solver.mkTerm(solver.mkOp(Kind.SepEmp))
- solver.mkTerm(solver.mkOp(Kind.SepEmp), v6)
with pytest.raises(RuntimeError):
solver.mkTerm(Kind.ConstBV)
slv.mkTerm(Kind.Ite, solver.mkTrue(), solver.mkTrue(),
solver.mkTrue())
- solver.mkTerm(Kind.Equal, v1)
+ solver.mkTerm(Kind.Equal, a, b)
with pytest.raises(RuntimeError):
- solver.mkTerm(Kind.Equal, v2)
+ solver.mkTerm(Kind.Equal, a, cvc5.Term(solver))
with pytest.raises(RuntimeError):
- solver.mkTerm(Kind.Equal, v3)
+ solver.mkTerm(Kind.Equal, a, solver.mkTrue())
with pytest.raises(RuntimeError):
- solver.mkTerm(Kind.Distinct, v6)
+ solver.mkTerm(Kind.Distinct)
# Test cases that are nary via the API but have arity = 2 internally
s_bool = solver.getBooleanSort()
t_bool = solver.mkConst(s_bool, "t_bool")
- solver.mkTerm(Kind.Implies, [t_bool, t_bool, t_bool])
- solver.mkTerm(Kind.Xor, [t_bool, t_bool, t_bool])
- solver.mkTerm(solver.mkOp(Kind.Xor), [t_bool, t_bool, t_bool])
+ solver.mkTerm(Kind.Implies, t_bool, t_bool, t_bool)
+ solver.mkTerm(Kind.Xor, t_bool, t_bool, t_bool)
+ solver.mkTerm(solver.mkOp(Kind.Xor), t_bool, t_bool, t_bool)
t_int = solver.mkConst(solver.getIntegerSort(), "t_int")
- solver.mkTerm(Kind.Division, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.Division), [t_int, t_int, t_int])
- solver.mkTerm(Kind.IntsDivision, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.IntsDivision), [t_int, t_int, t_int])
- solver.mkTerm(Kind.Sub, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.Sub), [t_int, t_int, t_int])
- solver.mkTerm(Kind.Equal, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.Equal), [t_int, t_int, t_int])
- solver.mkTerm(Kind.Lt, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.Lt), [t_int, t_int, t_int])
- solver.mkTerm(Kind.Gt, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.Gt), [t_int, t_int, t_int])
- solver.mkTerm(Kind.Leq, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.Leq), [t_int, t_int, t_int])
- solver.mkTerm(Kind.Geq, [t_int, t_int, t_int])
- solver.mkTerm(solver.mkOp(Kind.Geq), [t_int, t_int, t_int])
+ solver.mkTerm(Kind.Division, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.Division), t_int, t_int, t_int)
+ solver.mkTerm(Kind.IntsDivision, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.IntsDivision), t_int, t_int, t_int)
+ solver.mkTerm(Kind.Sub, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.Sub), t_int, t_int, t_int)
+ solver.mkTerm(Kind.Equal, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.Equal), t_int, t_int, t_int)
+ solver.mkTerm(Kind.Lt, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.Lt), t_int, t_int, t_int)
+ solver.mkTerm(Kind.Gt, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.Gt), t_int, t_int, t_int)
+ solver.mkTerm(Kind.Leq, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.Leq), t_int, t_int, t_int)
+ solver.mkTerm(Kind.Geq, t_int, t_int, t_int)
+ solver.mkTerm(solver.mkOp(Kind.Geq), t_int, t_int, t_int)
t_reg = solver.mkConst(solver.getRegExpSort(), "t_reg")
- solver.mkTerm(Kind.RegexpDiff, [t_reg, t_reg, t_reg])
- solver.mkTerm(solver.mkOp(Kind.RegexpDiff), [t_reg, t_reg, t_reg])
+ solver.mkTerm(Kind.RegexpDiff, t_reg, t_reg, t_reg)
+ solver.mkTerm(solver.mkOp(Kind.RegexpDiff), t_reg, t_reg, t_reg)
t_fun = solver.mkConst(solver.mkFunctionSort(
[s_bool, s_bool, s_bool], s_bool))
- solver.mkTerm(Kind.HoApply, [t_fun, t_bool, t_bool, t_bool])
- solver.mkTerm(solver.mkOp(Kind.HoApply), [t_fun, t_bool, t_bool, t_bool])
+ solver.mkTerm(Kind.HoApply, t_fun, t_bool, t_bool, t_bool)
+ solver.mkTerm(solver.mkOp(Kind.HoApply), t_fun, t_bool, t_bool, t_bool)
def test_mk_term_from_op(solver):
bv32 = solver.mkBitVectorSort(32)
a = solver.mkConst(bv32, "a")
b = solver.mkConst(bv32, "b")
- v1 = [solver.mkInteger(1), solver.mkInteger(2)]
- v2 = [solver.mkInteger(1), cvc5.Term(solver)]
- v3 = []
- v4 = [solver.mkInteger(5)]
slv = cvc5.Solver()
# simple operator terms
solver.mkTerm(opterm2, solver.mkInteger(1), solver.mkInteger(1),
cvc5.Term(solver))
- solver.mkTerm(opterm2, v4)
+ solver.mkTerm(opterm2, solver.mkInteger(5))
with pytest.raises(RuntimeError):
- solver.mkTerm(opterm2, v1)
+ solver.mkTerm(opterm2, solver.mkInteger(1), solver.mkInteger(2))
with pytest.raises(RuntimeError):
- solver.mkTerm(opterm2, v2)
+ solver.mkTerm(opterm2, solver.mkInteger(1), cvc5.Term(solver))
with pytest.raises(RuntimeError):
- solver.mkTerm(opterm2, v3)
+ solver.mkTerm(opterm2)
with pytest.raises(RuntimeError):
- slv.mkTerm(opterm2, v4)
+ slv.mkTerm(opterm2, solver.mkInteger(5))
def test_mk_true(solver):
# Assertions
assertions =\
solver.mkTerm(Kind.And,\
- [solver.mkTerm(Kind.Leq, zero, f_x), # 0 <= f(x)
+ solver.mkTerm(Kind.Leq, zero, f_x), # 0 <= f(x)
solver.mkTerm(Kind.Leq, zero, f_y), # 0 <= f(y)
solver.mkTerm(Kind.Leq, summ, one), # f(x) + f(y) <= 1
p_0.notTerm(), # not p(0)
p_f_y # p(f(y))
- ])
+ )
solver.checkSatAssuming(solver.mkTrue())
solver.assertFormula(assertions)
solver.checkSatAssuming(solver.mkTerm(Kind.Distinct, x, y))
solver.checkSatAssuming(
- [solver.mkFalse(),
- solver.mkTerm(Kind.Distinct, x, y)])
+ solver.mkFalse(),
+ solver.mkTerm(Kind.Distinct, x, y))
with pytest.raises(RuntimeError):
solver.checkSatAssuming(n)
with pytest.raises(RuntimeError):
- solver.checkSatAssuming([n, solver.mkTerm(Kind.Distinct, x, y)])
+ solver.checkSatAssuming(n, solver.mkTerm(Kind.Distinct, x, y))
slv = cvc5.Solver()
with pytest.raises(RuntimeError):
slv.checkSatAssuming(solver.mkTrue())
solver.push(4)
slt = solver.mkTerm(Kind.BVSlt, srem, one)
solver.resetAssertions()
- solver.checkSatAssuming([slt, ule])
+ solver.checkSatAssuming(slt, ule)
def test_mk_sygus_grammar(solver):
def test_get_data_type_arity(solver):
- ctor1 = solver.mkDatatypeConstructorDecl("_x21");
- ctor2 = solver.mkDatatypeConstructorDecl("_x31");
- s3 = solver.declareDatatype("_x17", [ctor1, ctor2]);
+ ctor1 = solver.mkDatatypeConstructorDecl("_x21")
+ ctor2 = solver.mkDatatypeConstructorDecl("_x31")
+ s3 = solver.declareDatatype("_x17", ctor1, ctor2)
assert s3.getDatatypeArity() == 0