コード例 #1
0
def test_mcsat():
    x = declare_real_var('x');
    p = yices_parse_term('(= (* x x) 2)')
    s = term_to_string(p)
    print 'Assertion: {0}\n'.format(s)
    ctx = make_context()
    yices_assert_formula(ctx, p)
    status = yices_check_context(ctx, None)
    if status != STATUS_SAT:
        print 'Test failed: status = {0} != STATUS_SAT\n'.format(status)

    print 'Satisfiable!\n'

    model = yices_get_model(ctx, 1)

    print "Model:\n"
    yices_pp_model_fd(1, model, 80, 20, 0)


    #print "algebraic value of x = "
    #show_algebraic_value(model, x)
    #print "\n"

    print "Test succeeded\n"

    # cleanup
    yices_free_model(model)
    yices_free_context(ctx)
コード例 #2
0
ファイル: yices.py プロジェクト: aman-goel/pysmt
    def _add_assertion(self, formula, named=None):
        self._assert_is_boolean(formula)
        term = self.get_term(formula)

        if (named is not None) and (self.options.unsat_cores_mode is not None):
            # TODO: IF unsat_cores_mode is all, then we add this fresh variable.
            # Otherwise, we should track this only if it is named.
            key = self.mgr.FreshSymbol(template="_assertion_%d")
            tkey = self.get_term(key)
            key2term = yicespy.yices_implies(tkey, term)
            self.yices_assumptions.append(tkey)
            code = yicespy.yices_assert_formula(self.yices, key2term)
            if code != 0:
                msg = yicespy.yices_error_string()
                if code == -1 and "non-linear arithmetic" in msg:
                    raise NonLinearError(formula)
                raise InternalSolverError("Yices returned non-zero code upon assert"\
                                          ": %s (code: %s)" % \
                                          (msg, code))
            return (key, named, formula)
        else:
            code = yicespy.yices_assert_formula(self.yices, term)
            if code != 0:
                msg = yicespy.yices_error_string()
                if code == -1 and "non-linear arithmetic" in msg:
                    raise NonLinearError(formula)
                raise InternalSolverError("Yices returned non-zero code upon assert"\
                                          ": %s (code: %s)" % \
                                          (msg, code))
            return formula
コード例 #3
0
 def test_context(self):
     cfg = yapi.yices_new_config()
     ctx = yapi.yices_new_context(cfg)
     stat = yapi.yices_context_status(ctx)
     yapi.yices_push(ctx)
     yapi.yices_pop(ctx)
     yapi.yices_reset_context(ctx)
     yapi.yices_context_enable_option(ctx, "arith-elim")
     yapi.yices_context_disable_option(ctx, "arith-elim")
     stat = yapi.yices_context_status(ctx)
     self.assertEqual(stat, 0)
     yapi.yices_reset_context(ctx)
     bool_t = yapi.yices_bool_type()
     bvar1 = yapi.yices_new_variable(bool_t)
     #iam: 9/19/2018 with self.assertRaisesRegexp(YicesAPIException, 'assertion contains a free variable'):
     #iam: 9/19/2018     yapi.yices_assert_formula(ctx, bvar1)
     errcode = yapi.yices_assert_formula(ctx, bvar1)
     error_string = yapi.yices_error_string()
     self.assertEqual(errcode, -1)
     self.assertEqual(error_string, 'assertion contains a free variable')
     bv_t = yapi.yices_bv_type(3)
     bvvar1 = yapi.yices_new_uninterpreted_term(bv_t)
     yapi.yices_set_term_name(bvvar1, 'x')
     bvvar2 = yapi.yices_new_uninterpreted_term(bv_t)
     yapi.yices_set_term_name(bvvar2, 'y')
     bvvar3 = yapi.yices_new_uninterpreted_term(bv_t)
     yapi.yices_set_term_name(bvvar3, 'z')
     fmla1 = yapi.yices_parse_term('(= x (bv-add y z))')
     fmla2 = yapi.yices_parse_term('(bv-gt y 0b000)')
     fmla3 = yapi.yices_parse_term('(bv-gt z 0b000)')
     yapi.yices_assert_formula(ctx, fmla1)
     yapi.yices_assert_formulas(ctx, 3,
                                yapi.make_term_array([fmla1, fmla2, fmla3]))
     smt_stat = yapi.yices_check_context(ctx, None)
     self.assertEqual(smt_stat, yapi.STATUS_SAT)
     yapi.yices_assert_blocking_clause(ctx)
     yapi.yices_stop_search(ctx)
     param = yapi.yices_new_param_record()
     yapi.yices_default_params_for_context(ctx, param)
     yapi.yices_set_param(param, "dyn-ack", "true")
     #iam: 9/19/2018 with self.assertRaisesRegexp(YicesAPIException, 'invalid parameter'):
     #iam: 9/19/2018     yapi.yices_set_param(param, "foo", "bar")
     errcode = yapi.yices_set_param(param, "foo", "bar")
     error_string = yapi.yices_error_string()
     self.assertEqual(errcode, -1)
     self.assertEqual(error_string, 'invalid parameter')
     #iam: 9/19/2018 with self.assertRaisesRegexp(YicesAPIException, 'value not valid for parameter'):
     #iam: 9/19/2018    yapi.yices_set_param(param, "dyn-ack", "bar")
     errcode = yapi.yices_set_param(param, "dyn-ack", "bar")
     error_string = yapi.yices_error_string()
     self.assertEqual(errcode, -1)
     self.assertEqual(error_string, 'value not valid for parameter')
     yapi.yices_free_param_record(param)
     yapi.yices_free_context(ctx)
コード例 #4
0
 def test_bv_models(self):
     bv_t = yapi.yices_bv_type(3)
     bv1 = define_const('bv1', bv_t)
     bv2 = define_const('bv2', bv_t)
     bv3 = define_const('bv3', bv_t)
     fmla1 = yapi.yices_parse_term('(= bv1 (bv-add bv2 bv3))')
     fmla2 = yapi.yices_parse_term('(bv-gt bv2 0b000)')
     fmla3 = yapi.yices_parse_term('(bv-gt bv3 0b000)')
     yapi.yices_assert_formula(self.ctx, fmla1)
     yapi.yices_assert_formulas(self.ctx, 3,
                                yapi.make_term_array([fmla1, fmla2, fmla3]))
     self.assertEqual(yapi.yices_check_context(self.ctx, self.param), 3)
     mdl1 = yapi.yices_get_model(self.ctx, 1)
     val1 = yapi.make_empty_int32_array(3)
     val2 = yapi.make_empty_int32_array(3)
     val3 = yapi.make_empty_int32_array(3)
     yapi.yices_get_bv_value(mdl1, bv1, val1)
     self.assertEqual(val1[0], 0)
     self.assertEqual(val1[1], 0)
     self.assertEqual(val1[2], 0)
     yapi.yices_get_bv_value(mdl1, bv2, val2)
     self.assertEqual(val2[0], 0)
     self.assertEqual(val2[1], 0)
     self.assertEqual(val2[2], 1)
     yapi.yices_get_bv_value(mdl1, bv3, val3)
     self.assertEqual(val3[0], 0)
     self.assertEqual(val3[1], 0)
     self.assertEqual(val3[2], 1)
     yv1 = yapi.yval_t()
     yapi.yices_get_value(mdl1, bv2, yv1)
     self.assertEqual(yapi.yices_val_bitsize(mdl1, yv1), 3)
     self.assertEqual(yv1.node_tag, yapi.YVAL_BV)
     yapi.yices_val_get_bv(mdl1, yv1, val1)
     self.assertEqual(yapi.yices_val_bitsize(mdl1, yv1), 3)
     self.assertEqual(val1[0], 0)
     self.assertEqual(val1[1], 0)
     self.assertEqual(val1[2], 1)
     yapi.yices_free_model(mdl1)
コード例 #5
0
 def test_bool_models(self):
     b1 = define_const('b1', self.bool_t)
     b2 = define_const('b2', self.bool_t)
     b3 = define_const('b3', self.bool_t)
     b_fml1 = yapi.yices_parse_term('(or b1 b2 b3)')
     yapi.yices_assert_formula(self.ctx, b_fml1)
     self.assertEqual(yapi.yices_check_context(self.ctx, self.param),
                      yapi.STATUS_SAT)
     b_mdl1 = yapi.yices_get_model(self.ctx, 1)
     self.assertNotEqual(b_mdl1, None)
     # init to -1 to make sure they get updated
     bval1 = c_int32()
     bval2 = c_int32()
     bval3 = c_int32()
     yapi.yices_get_bool_value(b_mdl1, b1, bval1)
     yapi.yices_get_bool_value(b_mdl1, b2, bval2)
     yapi.yices_get_bool_value(b_mdl1, b3, bval3)
     self.assertEqual(bval1.value, 0)
     self.assertEqual(bval2.value, 0)
     self.assertEqual(bval3.value, 1)
     b_fmla2 = yapi.yices_parse_term('(not b3)')
     yapi.yices_assert_formula(self.ctx, b_fmla2)
     self.assertEqual(yapi.yices_check_context(self.ctx, self.param),
                      yapi.STATUS_SAT)
     b_mdl1 = yapi.yices_get_model(self.ctx, 1)
     self.assertNotEqual(b_mdl1, None)
     yapi.yices_get_bool_value(b_mdl1, b1, bval1)
     yapi.yices_get_bool_value(b_mdl1, b2, bval2)
     yapi.yices_get_bool_value(b_mdl1, b3, bval3)
     self.assertEqual(bval1.value, 0)
     self.assertEqual(bval2.value, 1)
     self.assertEqual(bval3.value, 0)
     yv1 = yapi.yval_t()
     yapi.yices_get_value(b_mdl1, b1, yv1)
     self.assertEqual(yv1.node_tag, yapi.YVAL_BOOL)
     yapi.yices_val_get_bool(b_mdl1, yv1, bval1)
     self.assertEqual(bval1.value, 0)
コード例 #6
0
def assert_formula(formula, ctx):
    if isstr(formula):
        formula = yapi.yices_parse_term(formula)
    yapi.yices_assert_formula(ctx, formula)
コード例 #7
0
 def assert_formula(ctx, t):
     """Assert the formula t in the context ctx."""
     return yapi.yices_assert_formula(ctx, t)