def test_bv_ops(create_solver): solver = create_solver(False) bvsort32 = solver.make_sort(ss.sortkinds.BV, 32) one = solver.make_term(1, bvsort32) t0 = solver.make_term(ss.Op(ss.primops.Rotate_Left, 3), one) t = solver.make_term(ss.Op(ss.primops.Rotate_Right, 3), t0) constraint = solver.make_term(ss.primops.Distinct, one, t) solver.assert_formula(constraint) r = solver.check_sat() assert r.is_unsat(), "{} and {} should be identical".format(one, t)
def walk_bv_extract(self, formula, args, **kwargs): res = self.make_term( ss.Op( ss.primops.Extract, formula.bv_extract_end(), formula.bv_extract_start(), ), *args) return res
def test_unit_iter(create_solver): solver = create_solver() null_op = ss.Op() ext = ss.Op(ss.primops.Extract, 2, 0) bvsort = solver.make_sort(ss.sortkinds.BV, 4) x = solver.make_symbol('x', bvsort) f = solver.make_symbol( 'f', solver.make_sort(ss.sortkinds.FUNCTION, [bvsort, bvsort])) fx = solver.make_term(ss.primops.Apply, f, x) cnt = 0 for t in fx: assert cnt != 0 or t == f, 'First child should be f' assert cnt != 1 or t == x, 'Second child should be x' cnt += 1 assert cnt == 2, "Expecting two children"
def test_unit_op(create_solver): solver = create_solver() null_op = ss.Op() ext = ss.Op(ss.primops.Extract, 2, 0) x = solver.make_symbol('x', solver.make_sort(ss.sortkinds.BV, 4)) assert not null_op, 'null op should return false for bool' assert ext, 'non-null op should return true for bool' try: null_op_x = solver.make_term(null_op, x) assert False, 'Should get a ValueError' except ValueError as e: pass except: assert False, 'Should have gotten a ValueError' ext_x = solver.make_term(ext, x) assert ext == ext_x.get_op(), 'Extraction ops should match' assert ext != null_op, 'Extract op should not be equivalent to a null op'
def walk_bv_zext(self, formula, args, **kwargs): res = self.make_term( ss.Op(ss.primops.Zero_Extend, formula.bv_extend_step()), *args) return res
def walk_bv_ror(self, formula, args, **kwargs): res = self.make_term( ss.Op(ss.primops.Rotate_Right, formula.bv_rotation_step()), *args) return res
from smt_switch.primops import Apply, Distinct, Equal, Extract, BVAnd, BVUge if __name__ == "__main__": s = ss.create_btor_solver(True) s.set_logic('QF_UFBV') s.set_opt('incremental', 'true') s.set_opt('produce-models', 'true') s.set_opt('produce-unsat-assumptions', 'true') bvs = s.make_sort(ss.sortkinds.BV, 32) funs = s.make_sort(ss.sortkinds.FUNCTION, [bvs, bvs]) x = s.make_symbol('x', bvs) y = s.make_symbol('y', bvs) f = s.make_symbol('f', funs) ext = ss.Op(Extract, 15, 0) x0 = s.make_term(ext, x) y0 = s.make_term(ext, y) fx = s.make_term(Apply, f, x) fy = s.make_term(Apply, f, y) s.assert_formula(s.make_term(Distinct, fx, fy)) s.push(1) s.assert_formula(s.make_term(Equal, x0, y0)) print(s.check_sat()) print(s.get_value(x)) s.pop(1) xy = s.make_term(BVAnd, x, y) a1 = s.make_term(BVUge, xy, x)