def test_config(self): cfg = Config() # Valid call cfg.set_config("mode", "push-pop") # Invalid name with assertRaisesRegex(self, YicesException, 'invalid parameter'): cfg.set_config("baz", "bar") # Invalid value with assertRaisesRegex(self, YicesException, 'value not valid for parameter'): cfg.set_config("mode", "bar") cfg.default_config_for_logic("QF_UFNIRA") cfg.dispose()
def delgado(self, delegate): if not Delegates.has_delegate(delegate): notify(f'delgado skipping missing delegate {delegate}\n') return formulas = make_formulas() bound = len(formulas) + 1 for i in range(1, bound): config = Config() config.default_config_for_logic("QF_BV") context = Context(config) terms = truncate(formulas, i) context.assert_formulas(terms) status = context.check_context() notify(f'delgado status = {Status.name(status)} for i = {i}\n') self.assertEqual(status, Status.SAT if i < 3 else Status.UNSAT) config.dispose() context.dispose() for i in range(1, bound): model = [] terms = truncate(formulas, i) status = Delegates.check_formulas(terms, "QF_BV", delegate, model) notify(f'delagdo({delegate}) status = {Status.name(status)} for i = {i}\n') self.assertEqual(status, Status.SAT if i < 3 else Status.UNSAT) if status is Status.SAT: notify(f'delagdo({delegate}) model = {model[0].to_string(80, 100, 0)} for i = {i}\n') else: self.assertEqual(len(model), 0) for i in range(1, bound): model = [] term = conjoin(formulas, i) status = Delegates.check_formula(term, "QF_BV", delegate, model) notify(f'delagdo({delegate}) status = {Status.name(status)} for i = {i}\n') self.assertEqual(status, Status.SAT if i < 3 else Status.UNSAT) if status is Status.SAT: notify(f'delagdo({delegate}) model = {model[0].to_string(80, 100, 0)} for i = {i}\n') else: self.assertEqual(len(model), 0)
def test_timeout(self): cfg = Config() cfg.default_config_for_logic('QF_NIA') ctx = Context(cfg) int_t = Types.int_type() [x, y, z] = [ Terms.new_uninterpreted_term(int_t, id) for id in ['x', 'y', 'z'] ] # x, y, z > 0 for var in [x, y, z]: ctx.assert_formula(Terms.arith_gt0_atom(var)) # x^3 + y^3 = z3 [x3, y3, z3] = [Terms.product([var, var, var]) for var in [x, y, z]] lhs = Terms.sum([x3, y3]) eq = Terms.arith_eq_atom(lhs, z3) ctx.assert_formula(eq) status = ctx.check_context(timeout=1) self.assertEqual(status, Status.INTERRUPTED) ctx.dispose() cfg.dispose()
def test_dimacs(self): formulas = make_formulas() bound = len(formulas) + 1 simplified = [None] * bound # first round, don't simplify the CNF for i in range(1, bound): simplify = False filename = f'/tmp/basic{1}.cnf' terms = truncate(formulas, i) file_ok, status = Dimacs.export_formulas(terms, filename, simplify) notify( f'Round 1: {file_ok}, {Status.name(status)} = export@{i}({terms}, {filename}, {simplify})\n' ) if file_ok: self.assertEqual(os.path.exists(filename), True) else: self.assertEqual(status in [Status.SAT, Status.UNSAT], True) term = Terms.yand(terms) file_ok_c, status_c = Dimacs.export_formula( term, filename, simplify) notify( f'Round 1: {file_ok_c}, {Status.name(status_c)} = export@{i}({term}, {filename}, {simplify})\n' ) # second round, simplify the CNF for i in range(1, bound): simplify = True filename = f'/tmp/simplify{i}.cnf' terms = truncate(formulas, i) file_ok, status = Dimacs.export_formulas(terms, filename, simplify) # save the status for later simplified[i] = status notify( f'Round 2: {file_ok}, {Status.name(status)} = export@{i}({terms}, {filename}, {simplify})\n' ) if file_ok: self.assertEqual(os.path.exists(filename), True) else: self.assertEqual(status in [Status.SAT, Status.UNSAT], True) term = Terms.yand(terms) file_ok_c, status_c = Dimacs.export_formula( term, filename, simplify) notify( f'Round 2: {file_ok_c}, {Status.name(status_c)} = export@{i}({term}, {filename}, {simplify})\n' ) self.assertEqual(status_c, simplified[i]) # third round check the results for i in range(1, bound): config = Config() config.default_config_for_logic("QF_BV") context = Context(config) terms = truncate(formulas, i) context.assert_formulas(terms) status = context.check_context() notify(f'Round 3: status = {Status.name(status)} for i = {i}\n') self.assertEqual(status, simplified[i]) config.dispose() context.dispose()
#not real happy about the indexing going from 0 to 8, but #isolating access via V could make it easier to go from 1 to 9 def V(vi, vj): return X[vi][vj] #make the constants that we will need C = {} for i in range(1, 10): C[i] = Terms.integer(i) one = C[1] nine = C[9] config = Config() config.default_config_for_logic("QF_LIA") context = Context(config) # x is between 1 and 9 def between_1_and_9(x): return Terms.yand( [Terms.arith_leq_atom(one, x), Terms.arith_leq_atom(x, nine)]) for i in range(9): for j in range(9): context.assert_formula(between_1_and_9(V(i, j)))