def main(): slv = cvc5.Solver() slv.setOption("produce-models", "true") # Setting an invalid option try: slv.setOption("non-existing", "true") return 1 except: pass # Creating a term with an invalid type try: integer = slv.getIntegerSort() x = slv.mkConst("x", integer) invalidTerm = em.mkTerm(AND, x, x) slv.checkSat(invalidTerm) return 1 except: pass # Asking for a model after unsat result try: slv.checkSat(slv.mkBoolean(False)) slv.getModel() return 1 except: pass return 0
def test_sort_scoped_tostring(solver): name = "uninterp-sort" bvsort8 = solver.mkBitVectorSort(8) uninterp_sort = solver.mkUninterpretedSort(name) assert str(bvsort8) == "(_ BitVec 8)" assert str(uninterp_sort) == name solver2 = cvc5.Solver() assert str(bvsort8) == "(_ BitVec 8)" assert str(uninterp_sort) == name
def testGetString(): solver = cvc5.Solver() s1 = '"test\n"😃\\u{a}' t1 = solver.mkString(s1) assert s1 == t1.toPythonObj() s2 = '❤️cvc5❤️' t2 = solver.mkString(s2) assert s2 == t2.toPythonObj()
def testGetReal(): solver = cvc5.Solver() half = solver.mkReal("1/2") assert half.toPythonObj() == Fraction(1, 2) neg34 = solver.mkReal("-3/4") assert neg34.toPythonObj() == Fraction(-3, 4) neg1 = solver.mkInteger("-1") assert neg1.toPythonObj() == -1
def testGetValueInt(): solver = cvc5.Solver() solver.setOption("produce-models", "true") intsort = solver.getIntegerSort() x = solver.mkConst(intsort, "x") solver.assertFormula(solver.mkTerm(Kind.Equal, x, solver.mkInteger(6))) r = solver.checkSat() assert r.isSat() xval = solver.getValue(x) assert xval.toPythonObj() == 6
def testGetValueReal(): solver = cvc5.Solver() solver.setOption("produce-models", "true") realsort = solver.getRealSort() x = solver.mkConst(realsort, "x") y = solver.mkConst(realsort, "y") solver.assertFormula(solver.mkTerm(Kind.Equal, x, solver.mkReal("6"))) solver.assertFormula(solver.mkTerm(Kind.Equal, y, solver.mkReal("8.33"))) r = solver.checkSat() assert r.isSat() xval = solver.getValue(x) yval = solver.getValue(y) assert xval.toPythonObj() == Fraction("6") assert yval.toPythonObj() == Fraction("8.33")
def testGetArray(): solver = cvc5.Solver() arrsort = solver.mkArraySort(solver.getIntegerSort(), solver.getIntegerSort()) zero_array = solver.mkConstArray(arrsort, solver.mkInteger(0)) stores = solver.mkTerm( Kind.STORE, zero_array, solver.mkInteger(1), solver.mkInteger(2)) stores = solver.mkTerm( Kind.STORE, stores, solver.mkInteger(2), solver.mkInteger(3)) stores = solver.mkTerm( Kind.STORE, stores, solver.mkInteger(4), solver.mkInteger(5)) array_dict = stores.toPythonObj() assert array_dict[1] == 2 assert array_dict[2] == 3 assert array_dict[4] == 5 # an index that wasn't stored at should give zero assert array_dict[8] == 0
def testGetSymbol(): solver = cvc5.Solver() solver.mkConst(solver.getBooleanSort(), "x")
def testGetBV(): solver = cvc5.Solver() three = solver.mkBitVector(8, 3) assert three.toPythonObj() == 3
def testGetInt(): solver = cvc5.Solver() two = solver.mkInteger(2) assert two.toPythonObj() == 2
def test_term_scoped_to_string(solver): intsort = solver.getIntegerSort() x = solver.mkConst(intsort, "x") assert str(x) == "x" solver2 = cvc5.Solver() assert str(x) == "x"
############################################################################## # Top contributors (to current version): # Yoni Zohar # # This file is part of the cvc5 project. # # Copyright (c) 2009-2021 by the authors listed in the file AUTHORS # in the top-level source directory and their institutional affiliations. # All rights reserved. See the file COPYING in the top-level source # directory for licensing information. # ############################################################################ # # A simple test of multiple SmtEngines. ## import cvc5 s1 = cvc5.Solver() s2 = cvc5.Solver() r1 = s1.checkSatAssuming(s1.mkBoolean(False)) r2 = s2.checkSatAssuming(s2.mkBoolean(False)) assert r1.isUnsat() and r2.isUnsat()
def validate_getters(): slv = cvc5.Solver() # Setup some options for cvc5 slv.setLogic("QF_ALL") slv.setOption("produce-models", "true") slv.setOption("incremental", "false") # Our integer type integer = slv.getIntegerSort() #* Declare the separation logic heap types slv.declareSepHeap(integer, integer) # A "random" constant random_constant = slv.mkInteger(0xDEAD) # Another random constant expr_nil_val = slv.mkInteger(0xFBAD) # Our nil term nil = slv.mkSepNil(integer) # Our SMT constants x = slv.mkConst(integer, "x") y = slv.mkConst(integer, "y") p1 = slv.mkConst(integer, "p1") p2 = slv.mkConst(integer, "p2") # Constraints on x and y x_equal_const = slv.mkTerm(Kind.EQUAL, x, random_constant) y_gt_x = slv.mkTerm(Kind.GT, y, x) # Points-to expressions p1_to_x = slv.mkTerm(Kind.SEP_PTO, p1, x) p2_to_y = slv.mkTerm(Kind.SEP_PTO, p2, y) # Heap -- the points-to have to be "starred"! heap = slv.mkTerm(Kind.SEP_STAR, p1_to_x, p2_to_y) # Constain "nil" to be something random fix_nil = slv.mkTerm(Kind.EQUAL, nil, expr_nil_val) # Add it all to the solver! slv.assertFormula(x_equal_const) slv.assertFormula(y_gt_x) slv.assertFormula(heap) slv.assertFormula(fix_nil) # Incremental is disabled due to using separation logic, so don't query # twice! r = (slv.checkSat()) # If this is UNSAT, we have an issue so bail-out if not r.isSat(): return False # Obtain our separation logic terms from the solver heap_expr = slv.getValueSepHeap() nil_expr = slv.getValueSepNil() # If the heap is not a separating conjunction, bail-out if (heap_expr.getKind() != Kind.SEP_STAR): return False # If nil is not a direct equality, bail-out if (nil_expr.getKind() != Kind.EQUAL): return False # Obtain the values for our "pointers" val_for_p1 = slv.getValue(p1) val_for_p2 = slv.getValue(p2) # We need to make sure we find both pointers in the heap checked_p1 = False checked_p2 = False # Walk all the children for child in heap_expr: # If we don't have a PTO operator, bail-out if (child.getKind() != Kind.SEP_PTO): return False # Find both sides of the PTO operator addr = slv.getValue(child[0]) value = slv.getValue(child[1]) # If the current address is the value for p1 if (addr == val_for_p1): checked_p1 = True # If it doesn't match the random constant, we have a problem if value != random_constant: return False continue if (addr == val_for_p2): checked_p2 = True # Our earlier constraint was that what p2 points to must be *greater* # than the random constant -- if we get a value that is LTE, then # something has gone wrong! if int(str(value)) <= int(str(random_constant)): return False continue # We should only have two addresses in heap, so if we haven't hit the # "continue" for p1 or p2, then bail-out return True # If we complete the loop and we haven't validated both p1 and p2, then we # have a problem if (not checked_p1 or not checked_p2): return False # We now get our value for what nil is value_for_nil = slv.getValue(nil_expr[1]) # The value for nil from the solver should be the value we originally tied # nil to if (value_for_nil != expr_nil_val): return False # All tests pass! return True
def validate_exception(): slv = cvc5.Solver() # Setup some options for cvc5 -- we explictly want to use a simplistic # theory (e.g., QF_IDL) slv.setLogic("QF_IDL") slv.setOption("produce-models", "true") slv.setOption("incremental", "false") # Our integer type integer = slv.getIntegerSort() # we intentionally do not set the separation logic heap # Our SMT constants x = slv.mkConst(integer, "x") y = slv.mkConst(integer, "y") # y > x y_gt_x = slv.mkTerm(Kind.GT, y, x) # assert it slv.assertFormula(y_gt_x) # check r = slv.checkSat() # If this is UNSAT, we have an issue so bail-out if not r.isSat(): return False # We now try to obtain our separation logic expressions from the solver -- # we want to validate that we get our expected exceptions. caught_on_heap = False caught_on_nil = False # The exception message we expect to obtain expected = \ "Cannot obtain separation logic expressions if not using the separation " \ "logic theory." # test the heap expression try: heap_expr = slv.getValueSepHeap() except RuntimeError as e: caught_on_heap = True # Check we get the correct exception string if str(e) != expected: return False # test the nil expression try: nil_expr = slv.getValueSepNil() except RuntimeError as e: caught_on_nil = True # Check we get the correct exception string if str(e) != expected: return False if not caught_on_heap or not caught_on_nil: return False # All tests pass! return True
# # Copyright (c) 2009-2022 by the authors listed in the file AUTHORS # in the top-level source directory and their institutional affiliations. # All rights reserved. See the file COPYING in the top-level source # directory for licensing information. # ############################################################################# # # A simple demonstration of the solving capabilities of the cvc5 relations solver # through the Python API. This is a direct translation of relations.cpp. ## import cvc5 from cvc5 import Kind if __name__ == "__main__": solver = cvc5.Solver() # Set the logic solver.setLogic("ALL") # options solver.setOption("produce-models", "true") # we need finite model finding to answer sat problems with universal # quantified formulas solver.setOption("finite-model-find", "true") # we need sets extension to support set.universe operator solver.setOption("sets-ext", "true") integer = solver.getIntegerSort() set_ = solver.mkSetSort(integer)
# # Copyright (c) 2009-2022 by the authors listed in the file AUTHORS # in the top-level source directory and their institutional affiliations. # All rights reserved. See the file COPYING in the top-level source # directory for licensing information. # ############################################################################# # # A simple demonstration of the solving capabilities of the cvc5 sets solver # through the Python API. This is a direct translation of sets.cpp. ## import cvc5 from cvc5 import Kind if __name__ == "__main__": slv = cvc5.Solver() # Optionally, set the logic. We need at least UF for equality predicate, # integers (LIA) and sets (FS). slv.setLogic("QF_UFLIAFS") # Produce models slv.setOption("produce-models", "true") slv.setOption("output-language", "smt2") integer = slv.getIntegerSort() set_ = slv.mkSetSort(integer) # Verify union distributions over intersection # (A union B) intersection C = (A intersection C) union (B intersection C)
def solver(): return cvc5.Solver()
def testGetBool(): solver = cvc5.Solver() t = solver.mkTrue() f = solver.mkFalse() assert t.toPythonObj() is True assert f.toPythonObj() is False