else:
assert string_repr == "false"
res = False
+
elif sort.isInteger():
updated_string_repr = string_repr.strip('()').replace(' ', '')
try:
except:
raise ValueError("Failed to convert"
" {} to an int".format(string_repr))
+
elif sort.isReal():
updated_string_repr = string_repr
try:
- # expecting format (/ a b)
+ # rational format (/ a b) most likely
# note: a or b could be negated: (- a)
splits = [s.strip('()/')
for s in updated_string_repr.strip('()/') \
den = int(splits[1])
res = Fraction(num, den)
except:
- raise ValueError("Failed to convert "
- "{} to a Fraction".format(string_repr))
+ try:
+ # could be exact: e.g., 1.0
+ res = Fraction(updated_string_repr)
+ except:
+ raise ValueError("Failed to convert "
+ "{} to a Fraction".format(string_repr))
elif sort.isBitVector():
# expecting format #b<bits>
except:
raise ValueError("Failed to convert bitvector "
"{} to an int".format(string_repr))
+
elif sort.isArray():
keys = []
values = []
res = defaultdict(lambda : base_value)
for k, v in zip(keys, values):
res[k] = v
+
elif sort.isString():
# Strip leading and trailing double quotes and replace double
# double quotes by single quotes
s2 = '❤️cvc5❤️'
t2 = solver.mkString(s2)
assert s2 == t2.toPythonObj()
+
+
+def testGetValueInt():
+ solver = pycvc5.Solver()
+ solver.setOption("produce-models", "true")
+
+ intsort = solver.getIntegerSort()
+ x = solver.mkConst(intsort, "x")
+ solver.assertFormula(solver.mkTerm(kinds.Equal, x, solver.mkInteger(6)))
+
+ r = solver.checkSat()
+ assert r.isSat()
+
+ xval = solver.getValue(x)
+ assert xval.toPythonObj() == 6
+
+
+def testGetValueReal():
+ solver = pycvc5.Solver()
+ solver.setOption("produce-models", "true")
+
+ realsort = solver.getRealSort()
+ x = solver.mkConst(realsort, "x")
+ y = solver.mkConst(realsort, "y")
+ solver.assertFormula(solver.mkTerm(kinds.Equal, x, solver.mkReal("6")))
+ solver.assertFormula(solver.mkTerm(kinds.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")