def from_map(mapping):
     dom = mapping.keys()
     rng = [ mapping[d] for d in dom]
     #model = yapi.yices_model_from_map(len(dom), yapi.make_term_array(dom), yapi.make_term_array(rng))
     model = Yices.model_from_map(len(dom), yapi.make_term_array(dom), yapi.make_term_array(rng))
     if model == 0:
         raise YicesException('yices_model_from_map')
     return Model(model)
 def subst(variables, terms, term):
     assert len(variables) == len(terms)
     retval = yapi.yices_subst_term(len(variables),
                                    yapi.make_term_array(variables),
                                    yapi.make_term_array(terms), term)
     if retval == Terms.NULL_TERM:
         raise YicesException('yices_subst_term')
     return retval
Example #3
0
    def _rename_bound_variables(self, formula, variables):
        """Bounds the variables in formula.

        Returns a tuple (new_formula, new_var_list) in which the old
        variables have been replaced by the new variables in the list.
        """
        new_vars = [self._bound_symbol(x) for x in variables]
        old_vars = [self.walk_symbol(x) for x in variables]
        new_formula = yicespy.yices_subst_term(len(variables), yicespy.make_term_array(new_vars),
                                                yicespy.make_term_array(old_vars), formula)
        return (new_formula, new_vars)
 def substs(variables, terms, list_o_terms):
     assert len(variables) == len(terms)
     array_o_terms = yapi.make_term_array(list_o_terms)
     errorcode = yapi.yices_subst_term_array(
         len(variables), yapi.make_term_array(variables),
         yapi.make_term_array(terms), len(array_o_terms), array_o_terms)
     if errorcode == -1:
         raise YicesException('yices_subst_term_array')
     retval = [None] * len(list_o_terms)
     for i in range(len(list_o_terms)):
         retval[i] = array_o_terms[i]
     return retval
 def generalize_model_array(self, term_array, elim_array, mode):
     tarray = yapi.make_term_array(term_array)
     var_array = yapi.make_term_array(elim_array)
     termv = yapi.term_vector_t()
     yapi.yices_init_term_vector(termv)
     errcode = yapi.yices_generalize_model_array(self.model, len(term_array), tarray, len(elim_array), var_array, mode, termv)
     if errcode == -1:
         yapi.yices_delete_term_vector(termv)
         raise YicesException('yices_generalize_model_array')
     retval = []
     for i in range(0, termv.size):
         retval.append(termv.data[i])
     yapi.yices_delete_term_vector(termv)
     return retval
Example #6
0
 def test_model_from_map(self):
     bv_t = yapi.yices_bv_type(8)
     i1 = define_const('i1', self.int_t)
     r1 = define_const('r1', self.real_t)
     bv1 = define_const('bv1', bv_t)
     iconst1 = yapi.yices_int32(42)
     rconst1 = yapi.yices_rational32(13, 131)
     bvconst1 = yapi.yices_bvconst_int32(8, 134)
     mdl = yapi.yices_model_from_map(
         3, yapi.make_term_array([i1, r1, bv1]),
         yapi.make_term_array([iconst1, rconst1, bvconst1]))
     mdlstr = yapi.yices_model_to_string(mdl, 80, 100, 0)
     self.assertEqual(mdlstr,
                      '(= i1 42)\n(= r1 13/131)\n(= bv1 0b10000110)')
     yapi.yices_free_model(mdl)
Example #7
0
 def check_context_with_assumptions(self, params, python_array_or_tuple):
     alen = len(python_array_or_tuple)
     a = yapi.make_term_array(python_array_or_tuple)
     status = Yices.check_context_with_assumptions(self.context, params, alen, a)
     if status == Status.ERROR:
         raise YicesException('check_context_with_assumptions')
     return status
 def update(fun, args, value):
     assert args
     retval = yapi.yices_update(fun, len(args), yapi.make_term_array(args),
                                value)
     if retval == Terms.NULL_TERM:
         raise YicesException('yices_update')
     return retval
 def application(fun, terms):
     tlen = len(terms)
     assert tlen
     retval = yapi.yices_application(fun, tlen, yapi.make_term_array(terms))
     if retval == Terms.NULL_TERM:
         raise YicesException('yices_application')
     return retval
Example #10
0
 def print_term_values(self, fd, term_array, width=None, height=None, offset=None):
     """Print the values of the terms in the model to the file descriptor, pretty print if width, height, and offset are supplied."""
     tarray = yapi.make_term_array(term_array)
     if (width is None) or (height is None) or (offset is None):
         yapi.yices_print_term_values_fd(fd, self.model, len(term_array), tarray)
     else:
         yapi.yices_pp_term_values_fd(fd, self.model, len(term_array), tarray, int(width), int(height), int(offset))
Example #11
0
 def test_implicant(self):
     i1 = define_const('i1', self.int_t)
     assert_formula('(and (> i1 2) (< i1 8) (/= i1 4))', self.ctx)
     self.assertEqual(yapi.yices_check_context(self.ctx, self.param),
                      yapi.STATUS_SAT)
     mdl = yapi.yices_get_model(self.ctx, 1)
     mdlstr = yapi.yices_model_to_string(mdl, 80, 100, 0)
     self.assertEqual(mdlstr, '(= i1 7)')
     fml = yapi.yices_parse_term('(>= i1 3)')
     tvec = yapi.term_vector_t()
     yapi.yices_init_term_vector(tvec)
     yapi.yices_implicant_for_formula(mdl, fml, tvec)
     self.assertEqual(tvec.size, 1)
     implstr = yapi.yices_term_to_string(tvec.data[0], 200, 10, 0)
     self.assertEqual(implstr, '(>= (+ -3 i1) 0)')
     fml2 = yapi.yices_parse_term('(<= i1 9)')
     fmls = yapi.make_term_array([fml, fml2])
     tvec2 = yapi.term_vector_t()
     yapi.yices_init_term_vector(tvec2)
     yapi.yices_implicant_for_formulas(mdl, 2, fmls, tvec2)
     self.assertEqual(tvec2.size, 2)
     implstr2 = yapi.yices_term_to_string(tvec2.data[0], 200, 10, 0)
     self.assertEqual(implstr2, '(>= (+ -3 i1) 0)')
     implstr3 = yapi.yices_term_to_string(tvec2.data[1], 200, 10, 0)
     self.assertEqual(implstr3, '(>= (+ 9 (* -1 i1)) 0)')
     tvec3 = yapi.term_vector_t()
     yapi.yices_init_term_vector(tvec3)
     a_arr = yapi.term_t(i1)
     yapi.yices_generalize_model_array(mdl, 2, fmls, 1, a_arr, 0, tvec3)
 def yor(terms):
     tlen = len(terms)
     if not len:
         return Terms.FALSE
     retval = yapi.yices_or(tlen, yapi.make_term_array(terms))
     if retval == Terms.NULL_TERM:
         raise YicesException('yices_or')
     return retval
 def yand(terms):
     tlen = len(terms)
     if not len:
         return Terms.TRUE
     retval = yapi.yices_and(tlen, yapi.make_term_array(terms))
     if retval == Terms.NULL_TERM:
         raise YicesException('yices_and')
     return retval
Example #14
0
 def walk_function(self, formula, args, **kwargs):
     name = formula.function_name()
     if name not in self.symbol_to_decl:
         self.declare_variable(name)
     decl = self.symbol_to_decl[name]
     res = yicespy.yices_application(decl, len(args), yicespy.make_term_array(args))
     self._check_term_result(res)
     return res
 def assert_formulas(self, python_array_or_tuple):
     assert self.context is not None
     alen = len(python_array_or_tuple)
     a = yapi.make_term_array(python_array_or_tuple)
     errcode = Yices.assert_formulas(self.context, alen, a)
     if errcode == -1:
         raise YicesException('yices_assert_formulas')
     return True
Example #16
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)
    def export_formulas(f_array, filename, simplify):
        """Bit-blast then export the CNFs to a file, returns a pair consisting of a boolean
        and a status. The boolean is True if the file was written, or False indicating
        that the status of the formulas was determined, and is the second component.

        If the simplify flag is true, then is also possible for CNF
        simplification to detect that the CNF is sat or unsat.
        """
        farray = yapi.make_term_array(f_array)
        status = pointer(yapi.smt_status_t(yapi.STATUS_IDLE))
        code = yapi.yices_export_formulas_to_dimacs(farray, len(f_array), filename, simplify, status)
        return (code == 1, status.contents.value)
    def check_formulas(term_array, logic, delegate, model_array=None):
        """Checks whether the formulas in the array are satisfiable in the logic using the delegate.

        If the formulas are satisfiable, and the model_array is not None, then it
        inserts a model into the beginning of the array.
        """
        tarray = yapi.make_term_array(term_array)
        model = None
        if model_array is not None:
            model = pointer(yapi.model_t(model))
        status = yapi.yices_check_formulas(tarray, len(term_array), logic,
                                           model, delegate)
        if status == Status.SAT and model_array is not None:
            model_array.append(Model(model.contents))
        return status
Example #19
0
 def implicant_for_formulas(self, term_array):
     tarray = yapi.make_term_array(term_array)
     termv = yapi.term_vector_t()
     yapi.yices_init_term_vector(termv)
     try:
         code = yapi.yices_implicant_for_formulas(self.model, len(term_array), tarray, termv)
         retval = []
         if code != -1:
             for i in range(0, termv.size):
                 retval.append(termv.data[i])
         yapi.yices_delete_term_vector(termv)
         return retval
     except yapi.YicesAPIException as catastrophy:
         yapi.yices_delete_term_vector(termv)
         raise YicesException('implicant_for_formulas') from catastrophy
Example #20
0
 def support_for_terms(self, term_array):
     """Returns the list of uninterpreted terms that fix the value in the model of every term in the given array."""
     tarray = yapi.make_term_array(term_array)
     termv = yapi.term_vector_t()
     try:
         yapi.yices_init_term_vector(termv)
         code = yapi.yices_model_term_array_support(self.model, len(term_array), tarray, termv)
         retval = []
         if code != -1:
             for i in range(0, termv.size):
                 retval.append(termv.data[i])
         yapi.yices_delete_term_vector(termv)
         return retval
     except yapi.YicesAPIException as catastrophy:
         yapi.yices_delete_term_vector(termv)
         raise YicesException('support_for_terms') from catastrophy
Example #21
0
    def _solve(self, assumptions=None):
        count = 0
        if assumptions is not None:
            bool_ass = []
            other_ass = []
            assert(len(self.yices_assumptions) == 0)
            for x in assumptions:
                if x.is_literal():
                    self.yices_assumptions.append(self.get_term(x))
                    count += 1
                else:
                    other_ass.append(x)

            if len(other_ass) > 0:
                self.push()
                self.add_assertion(self.mgr.And(other_ass))
                self.pending_pop = True
        
        if len(self.yices_assumptions) == 0:
            out = yicespy.yices_check_context(self.yices, self.yices_params)
        else:
            out = yicespy.yices_check_context_with_assumptions(self.yices, self.yices_params, 
                                                               len(self.yices_assumptions), 
                                                               yicespy.make_term_array(self.yices_assumptions))
            
        if self.model is not None:
            yicespy.yices_free_model(self.model)
            self.model = None
        
        if count != 0:
            for i in range(count):
               self.yices_assumptions.pop()
            
        sres = 'unknown'
        assert out in [STATUS_SAT, STATUS_UNSAT, STATUS_UNKNOWN]
        if out == STATUS_UNKNOWN:
            raise SolverReturnedUnknownResultError()
        elif out == STATUS_SAT:
            sres = 'sat'
            self.model = yicespy.yices_get_model(self.yices, 1)
        else:
            sres = 'unsat'
        return (sres == 'sat')
Example #22
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)
Example #23
0
 def test_terms(self):
     true_ = yapi.yices_true()
     false_ = yapi.yices_false()
     bool_t = yapi.yices_bool_type()
     int_t = yapi.yices_int_type()
     unint_t = yapi.yices_new_uninterpreted_type()
     self.assertNotEqual(true_, false_)
     const1 = yapi.yices_constant(unint_t, 0)
     const2 = yapi.yices_new_uninterpreted_term(unint_t)
     bconst1 = yapi.yices_new_uninterpreted_term(bool_t)
     iconst1 = yapi.yices_new_uninterpreted_term(int_t)
     var1 = yapi.yices_new_variable(unint_t)
     bvar1 = yapi.yices_new_variable(bool_t)
     ivar1 = yapi.yices_new_variable(int_t)
     ivar2 = yapi.yices_new_variable(int_t)
     ivar3 = yapi.yices_new_variable(int_t)
     ivar4 = yapi.yices_new_variable(int_t)
     zero = yapi.yices_zero()
     int1 = yapi.yices_int32(13)
     int2 = yapi.yices_int32(17)
     self.assertEqual(zero, yapi.yices_int32(0))
     fun1_t = yapi.yices_function_type1(int_t, bool_t)
     fun1 = yapi.yices_new_variable(fun1_t)
     app1 = yapi.yices_application1(fun1, int1)
     fun2_t = yapi.yices_function_type2(int_t, int_t, bool_t)
     fun2 = yapi.yices_new_variable(fun2_t)
     app2 = yapi.yices_application2(fun2, int1, int1)
     fun3_t = yapi.yices_function_type3(int_t, int_t, int_t, bool_t)
     fun3 = yapi.yices_new_variable(fun3_t)
     app3 = yapi.yices_application3(fun3, int1, int1, int1)
     tup3_t = yapi.yices_tuple_type3(bool_t, int_t, unint_t)
     tupconst1 = yapi.yices_new_variable(tup3_t)
     ta4 = yapi.make_type_array([int_t, int_t, int_t, int_t])
     int4 = yapi.make_type_array([int1, int2, iconst1, ivar1])
     int4_2 = yapi.make_term_array([ivar1, ivar2, ivar3, ivar4])
     fun4_t = yapi.yices_function_type(4, ta4, bool_t)
     fun4 = yapi.yices_new_variable(fun4_t)
     app4 = yapi.yices_application(fun4, 4, int4)
     ite1 = yapi.yices_ite(bconst1, int1, int2)
     eq1 = yapi.yices_eq(int1, int1)
     neq1 = yapi.yices_neq(int1, int1)
     not1 = yapi.yices_not(false_)
     bool5 = yapi.make_term_array([false_, eq1, neq1, app4, false_])
     or1 = yapi.yices_or(5, bool5)
     and1 = yapi.yices_and(5, bool5)
     xor1 = yapi.yices_xor(5, bool5)
     or2 = yapi.yices_or2(or1, and1)
     and2 = yapi.yices_and2(or1, and1)
     xor2 = yapi.yices_xor2(or1, and1)
     or3 = yapi.yices_or3(or1, and1, or2)
     and3 = yapi.yices_and3(or1, and1, and2)
     xor3 = yapi.yices_xor3(or1, and1, xor2)
     iff1 = yapi.yices_iff(and1, or1)
     implies1 = yapi.yices_implies(and1, or1)
     tup1 = yapi.yices_tuple(4, int4)
     pair1 = yapi.yices_pair(eq1, xor2)
     triple1 = yapi.yices_triple(ite1, fun4, or3)
     select1 = yapi.yices_select(2, tup1)
     select2 = yapi.yices_select(2, tupconst1)
     tupup1 = yapi.yices_tuple_update(tup1, 2, int2)
     update1 = yapi.yices_update1(fun1, int1, false_)
     update2 = yapi.yices_update2(fun2, int1, int1, false_)
     update3 = yapi.yices_update3(fun3, int1, int1, int1, false_)
     update4 = yapi.yices_update(fun4, 4, int4, false_)
     distinct1 = yapi.yices_distinct(4, int4)
     var2 = yapi.yices_new_variable(unint_t)
     vareq = yapi.yices_eq(var1, var2)
     vars2 = yapi.make_term_array([var1, var2])
     forall1 = yapi.yices_forall(2, vars2, vareq)
     exists1 = yapi.yices_exists(2, vars2, vareq)
     lambda1 = yapi.yices_lambda(2, vars2, vareq)
     zero = yapi.yices_zero()
     int64_1 = yapi.yices_int64(42)
     rat32_1 = yapi.yices_rational32(13, 7)
     rat64_1 = yapi.yices_rational64(-47, 111)
     gmpz = yapi.yices_new_mpz(42)
     mpz1 = yapi.yices_mpz(gmpz)
     gmpq = yapi.yices_new_mpq(42, 77)
     mpq1 = yapi.yices_mpq(gmpq)
     rat1 = yapi.yices_parse_rational('-3/117')
     float1 = yapi.yices_parse_float('-3.117e-2')
     add1 = yapi.yices_add(int1, int1)
     sub1 = yapi.yices_sub(int1, zero)
     neg1 = yapi.yices_neg(int1)
     self.assertEqual(yapi.yices_neg(zero), zero)
     self.assertNotEqual(neg1, int1)
     mul1 = yapi.yices_mul(int1, int1)
     square1 = yapi.yices_square(int1)
     self.assertEqual(mul1, square1)
     power1 = yapi.yices_power(int1, 4)
     sum1 = yapi.yices_sum(4, int4)
     product1 = yapi.yices_product(4, int4)
     product2 = yapi.yices_product(4, int4_2)
     div1 = yapi.yices_division(int1, int1)
     idiv1 = yapi.yices_idiv(int1, int1)
     imod1 = yapi.yices_imod(int1, int1)
     divatom1 = yapi.yices_divides_atom(int1, int1)
     intatom1 = yapi.yices_is_int_atom(int1)
     abs1 = yapi.yices_abs(neg1)
     self.assertEqual(abs1, int1)
     floor1 = yapi.yices_floor(rat1)
     ceil1 = yapi.yices_ceil(rat1)
     poly32 = yapi.yices_poly_int32(4, yapi.make_int32_array([2, 3, 4, 5]),
                                    int4)
     poly64 = yapi.yices_poly_int64(4, yapi.make_int64_array([3, 4, 5, 6]),
                                    int4)
     polyrat32 = yapi.yices_poly_rational32(
         4, yapi.make_int32_array([2, 3, 4, 5]),
         yapi.make_int32_array([12, 13, 14, 15]), int4)
     polyrat64 = yapi.yices_poly_rational64(
         4, yapi.make_int64_array([2, 3, 4, 5]),
         yapi.make_int64_array([12, 13, 14, 15]), int4)
     areqatom1 = yapi.yices_arith_eq_atom(int1, zero)
     arneqatom1 = yapi.yices_arith_neq_atom(int1, zero)
     argeqatom1 = yapi.yices_arith_geq_atom(int1, zero)
     arleqatom1 = yapi.yices_arith_leq_atom(int1, zero)
     argtatom1 = yapi.yices_arith_gt_atom(int1, zero)
     arltatom1 = yapi.yices_arith_lt_atom(int1, zero)
     areq0atom1 = yapi.yices_arith_eq0_atom(int1)
     arneq0atom1 = yapi.yices_arith_neq0_atom(int1)
     argeq0atom1 = yapi.yices_arith_geq0_atom(int1)
     arleq0atom1 = yapi.yices_arith_leq0_atom(int1)
     argt0atom1 = yapi.yices_arith_gt0_atom(int1)
     arlt0atom1 = yapi.yices_arith_lt0_atom(int1)
     bv_t = yapi.yices_bv_type(8)
     bvconstu32_1 = yapi.yices_bvconst_uint32(8, 42)
     bvconstu64_1 = yapi.yices_bvconst_uint64(8, 42)
     bvconst32_1 = yapi.yices_bvconst_int32(8, 42)
     bvconst64_1 = yapi.yices_bvconst_int64(8, 42)
     bvconstzero_1 = yapi.yices_bvconst_zero(16)
     bvconstone_1 = yapi.yices_bvconst_one(16)
     bvconstminusone_1 = yapi.yices_bvconst_minus_one(32)
     bvconstarray1 = yapi.yices_bvconst_from_array(
         4, yapi.make_int32_array([1, 0, 1, 0]))
     bvvar1 = yapi.yices_new_variable(bv_t)
     bvvar2 = yapi.yices_new_variable(bv_t)
     bvvar3 = yapi.yices_new_variable(bv_t)
     bvvar4 = yapi.yices_new_variable(bv_t)
     bvbin1 = yapi.yices_parse_bvbin('100101')
     bvhex1 = yapi.yices_parse_bvhex('f0a1b3')
     bvadd1 = yapi.yices_bvadd(bvbin1, bvbin1)
     bvsub1 = yapi.yices_bvsub(bvbin1, bvbin1)
     bvneg1 = yapi.yices_bvneg(bvbin1)
     bvmul1 = yapi.yices_bvmul(bvbin1, bvbin1)
     bvsquare1 = yapi.yices_bvsquare(bvbin1)
     bvpower1 = yapi.yices_bvpower(bvbin1, 3)
     bvdiv1 = yapi.yices_bvdiv(bvbin1, bvbin1)
     bvrem1 = yapi.yices_bvrem(bvbin1, bvbin1)
     bvsdiv1 = yapi.yices_bvsdiv(bvbin1, bvbin1)
     bvsrem1 = yapi.yices_bvsrem(bvbin1, bvbin1)
     bvsmod1 = yapi.yices_bvsmod(bvbin1, bvbin1)
     bvnot1 = yapi.yices_bvnot(bvbin1)
     bvnand1 = yapi.yices_bvnand(bvbin1, bvbin1)
     bvnor1 = yapi.yices_bvnor(bvbin1, bvbin1)
     bvxnor1 = yapi.yices_bvxnor(bvbin1, bvbin1)
     bvshl1 = yapi.yices_bvshl(bvbin1, bvbin1)
     bvlshr1 = yapi.yices_bvlshr(bvbin1, bvbin1)
     bvashr1 = yapi.yices_bvashr(bvbin1, bvbin1)
     bvand1 = yapi.yices_bvand(
         4, yapi.make_term_array([bvbin1, bvbin1, bvbin1, bvbin1]))
     bvor1 = yapi.yices_bvor(
         4, yapi.make_term_array([bvbin1, bvbin1, bvbin1, bvbin1]))
     bvand2_1 = yapi.yices_bvand2(bvbin1, bvbin1)
     bvor2_1 = yapi.yices_bvor2(bvbin1, bvbin1)
     bvxor2_1 = yapi.yices_bvxor2(bvbin1, bvbin1)
     bvand3_1 = yapi.yices_bvand3(bvbin1, bvbin1, bvbin1)
     bvor3_1 = yapi.yices_bvor3(bvbin1, bvbin1, bvbin1)
     bvxor3_1 = yapi.yices_bvxor3(bvbin1, bvbin1, bvbin1)
     bvsum1 = yapi.yices_bvsum(
         4, yapi.make_term_array([bvbin1, bvbin1, bvbin1, bvbin1]))
     bvsum2 = yapi.yices_bvsum(
         4, yapi.make_term_array([bvvar1, bvvar2, bvvar3, bvvar4]))
     bvproduct1 = yapi.yices_bvproduct(
         4, yapi.make_term_array([bvbin1, bvbin1, bvbin1, bvbin1]))
     shleft0_1 = yapi.yices_shift_left0(bvbin1, 5)
     shleft1_1 = yapi.yices_shift_left1(bvbin1, 4)
     shright0_1 = yapi.yices_shift_right0(bvbin1, 3)
     shright1_1 = yapi.yices_shift_right1(bvbin1, 2)
     ashright_1 = yapi.yices_ashift_right(bvbin1, 1)
     rotleft_1 = yapi.yices_rotate_left(bvbin1, 6)
     rotright_1 = yapi.yices_rotate_right(bvbin1, 5)
     bvextract1 = yapi.yices_bvextract(bvbin1, 2, 4)
     bvconcat2_1 = yapi.yices_bvconcat2(bvbin1, bvbin1)
     bvconcat_1 = yapi.yices_bvconcat(
         4, yapi.make_term_array([bvbin1, bvbin1, bvbin1, bvbin1]))
     bvrepeat1 = yapi.yices_bvrepeat(bvbin1, 8)
     signext1 = yapi.yices_sign_extend(bvbin1, 3)
     zeroext1 = yapi.yices_zero_extend(bvbin1, 4)
     redand1 = yapi.yices_redand(bvbin1)
     redor1 = yapi.yices_redor(bvbin1)
     redcomp1 = yapi.yices_redcomp(bvbin1, bvbin1)
     bvarray1 = yapi.yices_bvarray(
         4, yapi.make_term_array([true_, false_, true_, false_]))
     bitextract1 = yapi.yices_bitextract(bvbin1, 3)
     bveqatom1 = yapi.yices_bveq_atom(bvbin1, bvbin1)
     bvneqatom1 = yapi.yices_bvneq_atom(bvbin1, bvbin1)
     bvgeatom1 = yapi.yices_bvge_atom(bvbin1, bvbin1)
     bvgtatom1 = yapi.yices_bvgt_atom(bvbin1, bvbin1)
     bvleatom1 = yapi.yices_bvle_atom(bvbin1, bvbin1)
     bvltatom1 = yapi.yices_bvlt_atom(bvbin1, bvbin1)
     bvsgeatom1 = yapi.yices_bvsge_atom(bvbin1, bvbin1)
     bvsgtatom1 = yapi.yices_bvsgt_atom(bvbin1, bvbin1)
     bvsleatom1 = yapi.yices_bvsle_atom(bvbin1, bvbin1)
     bvsltatom1 = yapi.yices_bvslt_atom(bvbin1, bvbin1)
     ptype1 = yapi.yices_parse_type('int')
     self.assertEqual(ptype1, yapi.yices_int_type())
     pterm1 = yapi.yices_parse_term('42')
     self.assertEqual(pterm1, yapi.yices_int32(42))
     subst1 = yapi.yices_subst_term(
         2,
         yapi.make_term_array([
             yapi.yices_new_variable(ptype1),
             yapi.yices_new_variable(ptype1)
         ]),
         yapi.make_term_array([yapi.yices_int32(2),
                               yapi.yices_int32(3)]), yapi.yices_int32(42))
     substarr1 = yapi.yices_subst_term_array(
         2,
         yapi.make_term_array([
             yapi.yices_new_variable(ptype1),
             yapi.yices_new_variable(ptype1)
         ]),
         yapi.make_term_array([yapi.yices_int32(2),
                               yapi.yices_int32(3)]), 3,
         yapi.make_term_array([
             yapi.yices_int32(2),
             yapi.yices_int32(3),
             yapi.yices_int32(7)
         ]))
     settypename1 = yapi.yices_set_type_name(ptype1, 'I')
     self.assertEqual(settypename1, 0)
     settermname1 = yapi.yices_set_term_name(pterm1, 'answer')
     self.assertEqual(settermname1, 0)
     gettype1 = yapi.yices_get_type_by_name('I')
     self.assertEqual(gettype1, ptype1)
     getterm1 = yapi.yices_get_term_by_name('answer')
     self.assertEqual(getterm1, pterm1)
     gettypename1 = yapi.yices_get_type_name(ptype1)
     self.assertEqual(gettypename1, 'I')
     gettermname1 = yapi.yices_get_term_name(pterm1)
     self.assertEqual(gettermname1, 'answer')
     yapi.yices_remove_type_name('I')
     yapi.yices_remove_term_name('answer')
     yapi.yices_clear_type_name(ptype1)
     yapi.yices_clear_term_name(pterm1)
     typeofterm1 = yapi.yices_type_of_term(pterm1)
     self.assertEqual(typeofterm1, yapi.yices_int_type())
     self.assertEqual(yapi.yices_term_is_bool(false_), 1)
     self.assertEqual(yapi.yices_term_is_bool(pterm1), 0)
     self.assertEqual(yapi.yices_term_is_int(false_), 0)
     self.assertEqual(yapi.yices_term_is_int(pterm1), 1)
     self.assertEqual(yapi.yices_term_is_real(false_), 0)
     self.assertEqual(yapi.yices_term_is_real(pterm1), 0)
     self.assertEqual(yapi.yices_term_is_arithmetic(false_), 0)
     self.assertEqual(yapi.yices_term_is_arithmetic(pterm1), 1)
     self.assertEqual(yapi.yices_term_is_bitvector(false_), 0)
     self.assertEqual(yapi.yices_term_is_bitvector(bvbin1), 1)
     self.assertEqual(yapi.yices_term_is_tuple(false_), 0)
     self.assertEqual(yapi.yices_term_is_tuple(tup1), 1)
     self.assertEqual(yapi.yices_term_is_function(false_), 0)
     self.assertEqual(yapi.yices_term_is_function(fun1), 1)
     self.assertEqual(yapi.yices_term_is_scalar(false_), 0)
     self.assertEqual(yapi.yices_term_is_scalar(fun1), 0)
     self.assertEqual(yapi.yices_term_bitsize(bvbin1), 6)
     self.assertEqual(yapi.yices_term_is_ground(false_), 1)
     self.assertEqual(yapi.yices_term_is_ground(var1), 0)
     self.assertEqual(yapi.yices_term_is_atomic(false_), 1)
     # or1 is atomic because it simplifies to true
     self.assertEqual(yapi.yices_term_is_atomic(or1), 1)
     self.assertEqual(yapi.yices_term_is_composite(false_), 0)
     self.assertEqual(yapi.yices_term_is_composite(ite1), 1)
     self.assertEqual(yapi.yices_term_is_composite(tup1), 1)
     self.assertEqual(yapi.yices_term_is_projection(false_), 0)
     # Select1 simplifies
     self.assertEqual(yapi.yices_term_is_projection(select1), 0)
     self.assertEqual(yapi.yices_term_is_projection(select2), 1)
     self.assertEqual(yapi.yices_term_is_sum(ite1), 0)
     self.assertEqual(yapi.yices_term_is_sum(sum1), 1)
     self.assertEqual(yapi.yices_term_is_bvsum(select1), 0)
     # bvsum1 simplifies since the terms are all numbers
     self.assertEqual(yapi.yices_term_is_bvsum(bvsum1), 0)
     self.assertEqual(yapi.yices_term_is_bvsum(bvsum2), 1)
     self.assertEqual(yapi.yices_term_is_product(ite1), 0)
     self.assertEqual(yapi.yices_term_is_product(product1), 0)
     self.assertEqual(yapi.yices_term_is_product(product2), 1)
     self.assertEqual(yapi.yices_term_constructor(true_), 0)
     self.assertEqual(yapi.yices_term_constructor(int1), 1)
     self.assertEqual(yapi.yices_term_constructor(bvconst32_1), 2)
     self.assertEqual(yapi.yices_term_num_children(bvconst32_1), 0)
     self.assertEqual(yapi.yices_term_num_children(select2), 1)
     self.assertEqual(yapi.yices_term_num_children(tup1), 4)
     self.assertEqual(yapi.yices_term_child(tup1, 2), iconst1)
     projarg1 = yapi.yices_proj_arg(select2)
     self.assertEqual(yapi.yices_proj_index(select2), 2)
     self.assertEqual(yapi.yices_proj_arg(select2), tupconst1)
     val_p = yapi.make_empty_int32_array(1)
     self.assertEqual(yapi.yices_bool_const_value(true_, val_p), 0)
     self.assertEqual(val_p[0], 1)
     bval = yapi.make_empty_int32_array(8)
     self.assertEqual(yapi.yices_bv_const_value(bvconst32_1, bval), 0)
     self.assertEqual(bval[0:7], [0, 1, 0, 1, 0, 1, 0])
     scalar_t = yapi.yices_new_scalar_type(20)
     scalar_c = yapi.yices_constant(scalar_t, 13)
     self.assertEqual(yapi.yices_scalar_const_value(scalar_c, val_p), 0)
     self.assertEqual(val_p[0], 13)
     self.assertEqual(yapi.yices_rational_const_value(rat32_1, gmpq), 0)
     pterm = yapi.term_t()
     self.assertEqual(yapi.yices_sum_component(sum1, 2, gmpq, pterm), 0)
     val = yapi.make_empty_int32_array(8)
     self.assertEqual(yapi.yices_type_of_term(bvsum2),
                      13)  #BD: not very robust
     # val must be an array of eight integers since bvsum has type (bitvector 8)
     dodgy = yapi.yices_bvsum_component(bvsum2, 1, val, pterm)
     self.assertEqual(dodgy, 0)
     self.assertEqual(yapi.yices_term_is_bitvector(pterm), 1)
     self.assertEqual(yapi.yices_term_is_bitvector(bvvar2), 1)
     self.assertEqual(val[0], 1)
     self.assertEqual(val[1], 0)
     self.assertEqual(val[2], 0)
     self.assertEqual(val[3], 0)
     self.assertEqual(val[4], 0)
     self.assertEqual(val[5], 0)
     self.assertEqual(val[6], 0)
     self.assertEqual(val[7], 0)
     # Why is pterm.value needed here?
     self.assertEqual(pterm.value, bvvar2)
     exp1 = c_int32()
     self.assertEqual(
         yapi.yices_product_component(product2, 1, pterm, exp1), 0)
     self.assertEqual(exp1.value, 1)
     # Why is pterm.value needed here?
     self.assertEqual(pterm.value, ivar2)
     # Note that the next two can change easily
     self.assertEqual(yapi.yices_num_terms(), 103)
     self.assertEqual(yapi.yices_num_types(), 26)
     self.assertEqual(yapi.yices_incref_term(pterm), 0)
     self.assertEqual(yapi.yices_num_posref_terms(), 1)
     self.assertEqual(yapi.yices_decref_term(pterm), 0)
     self.assertEqual(yapi.yices_num_posref_terms(), 0)
     self.assertEqual(yapi.yices_incref_type(unint_t), 0)
     self.assertEqual(yapi.yices_num_posref_types(), 1)
     self.assertEqual(yapi.yices_decref_type(unint_t), 0)
     self.assertEqual(yapi.yices_num_posref_types(), 0)
     self.assertEqual(yapi.yices_incref_term(int1), 0)
     self.assertEqual(yapi.yices_incref_type(int_t), 0)
     yapi.yices_garbage_collect(int4, 1, ta4, 1, 0)
     self.assertEqual(yapi.yices_num_terms(), 5)
     self.assertEqual(yapi.yices_num_types(), 3)
 def formulas_true_in_model(self, term_array):
     tarray = yapi.make_term_array(term_array)
     return yapi.yices_formulas_true_in_model(self.model, len(term_array),
                                              tarray) == 1
 def ylambda(variables, body):
     retval = yapi.yices_lambda(len(variables),
                                yapi.make_term_array(variables), body)
     if retval == Terms.NULL_TERM:
         raise YicesException('yices_lambda')
     return retval
 def bvarray(terms):
     retval = yapi.yices_bvarray(len(terms), yapi.make_term_array(terms))
     if retval == Terms.NULL_TERM:
         raise YicesException('yices_bvarray')
     return retval
 def xor(terms):
     assert terms
     return yapi.yices_xor(len(terms), yapi.make_term_array(terms))
Example #28
0
 def test_function_models(self):
     funtype = yapi.yices_function_type3(self.int_t, self.bool_t,
                                         self.real_t, self.real_t)
     ftystr = yapi.yices_type_to_string(funtype, 100, 80, 0)
     yapi.yices_pp_type_fd(1, funtype, 100, 80, 0)
     self.assertEqual(ftystr, '(-> int bool real real)')
     fun1 = define_const('fun1', funtype)
     define_const('b1', self.bool_t)
     i1 = define_const('i1', self.int_t)
     r1 = define_const('r1', self.real_t)
     assert_formula(
         '(> (fun1 i1 b1 r1) (fun1 (+ i1 1) (not b1) (- r1 i1)))', self.ctx)
     self.assertEqual(yapi.yices_check_context(self.ctx, self.param),
                      yapi.STATUS_SAT)
     mdl = yapi.yices_get_model(self.ctx, 1)
     mdlstr = yapi.yices_model_to_string(mdl, 80, 100, 0)
     self.assertEqual(
         mdlstr,
         '(= b1 false)\n(= i1 1463)\n(= r1 -579)\n(function fun1\n (type (-> int bool real real))\n (= (fun1 1463 false -579) 1)\n (= (fun1 1464 true -2042) 0)\n (default 2))'
     )
     yv1 = yapi.yval_t()
     yapi.yices_get_value(mdl, fun1, yv1)
     self.assertEqual(yv1.node_tag, yapi.YVAL_FUNCTION)
     self.assertEqual(yapi.yices_val_function_arity(mdl, yv1), 3)
     def1 = yapi.yval_t()
     vec1 = yapi.yval_vector_t()
     yapi.yices_init_yval_vector(vec1)
     yapi.yices_val_expand_function(mdl, yv1, def1, vec1)
     self.assertEqual(def1.node_tag, yapi.YVAL_RATIONAL)
     i32val1 = c_int32()
     yapi.yices_val_get_int32(mdl, def1, i32val1)
     self.assertEqual(i32val1.value, 2)
     self.assertEqual(vec1.size, 2)
     map1 = vec1.data[0]
     map2 = vec1.data[1]
     self.assertEqual(map1.node_tag, yapi.YVAL_MAPPING)
     self.assertEqual(map2.node_tag, yapi.YVAL_MAPPING)
     self.assertEqual(yapi.yices_val_mapping_arity(mdl, map1), 3)
     self.assertEqual(yapi.yices_val_mapping_arity(mdl, map2), 3)
     # First mapping
     args1 = yapi.make_empty_yval_array(3)
     yval1 = yapi.yval_t()
     yapi.yices_val_expand_mapping(mdl, map1, args1, yval1)
     self.assertEqual(yval1.node_tag, yapi.YVAL_RATIONAL)
     self.assertEqual(yapi.yices_val_is_int32(mdl, yval1), 1)
     val1 = c_int32()
     yapi.yices_val_get_int32(mdl, yval1, val1)
     self.assertEqual(val1.value, 1)
     self.assertEqual(args1[0].node_tag, yapi.YVAL_RATIONAL)
     self.assertEqual(yapi.yices_val_is_int32(mdl, args1[0]), 1)
     m1arg1 = c_int32()
     yapi.yices_val_get_int32(mdl, args1[0], m1arg1)
     self.assertEqual(m1arg1.value, 1463)
     self.assertEqual(args1[1].node_tag, yapi.YVAL_BOOL)
     m1arg2 = c_int()
     yapi.yices_val_get_bool(mdl, args1[1], m1arg2)
     self.assertEqual(m1arg2.value, 0)
     m1arg3 = c_int32()
     yapi.yices_val_get_int32(mdl, args1[2], m1arg3)
     self.assertEqual(m1arg3.value, -579)
     # Second mapping
     args2 = yapi.make_empty_yval_array(3)
     yval2 = yapi.yval_t()
     yapi.yices_val_expand_mapping(mdl, map2, args2, yval2)
     self.assertEqual(yval2.node_tag, yapi.YVAL_RATIONAL)
     self.assertEqual(yapi.yices_val_is_int32(mdl, yval2), 1)
     val2 = c_int32()
     yapi.yices_val_get_int32(mdl, yval2, val2)
     self.assertEqual(val2.value, 0)
     self.assertEqual(args2[0].node_tag, yapi.YVAL_RATIONAL)
     self.assertEqual(yapi.yices_val_is_int32(mdl, args2[0]), 1)
     m2arg2 = c_int32()
     yapi.yices_val_get_int32(mdl, args2[0], m2arg2)
     self.assertEqual(m2arg2.value, 1464)
     self.assertEqual(args2[1].node_tag, yapi.YVAL_BOOL)
     m2arg2 = c_int()
     yapi.yices_val_get_bool(mdl, args2[1], m2arg2)
     self.assertEqual(m2arg2.value, 1)
     m2arg3 = c_int32()
     yapi.yices_val_get_int32(mdl, args2[2], m2arg3)
     self.assertEqual(m2arg3.value, -2042)
     fmla = yapi.yices_parse_term('(> i1 r1)')
     self.assertEqual(yapi.yices_formula_true_in_model(mdl, fmla), 1)
     a_arr = yapi.make_term_array([i1, fmla, r1])
     b_arr = yapi.make_empty_term_array(3)
     yapi.yices_term_array_value(mdl, 3, a_arr, b_arr)
     self.assertEqual(b_arr[0], yapi.yices_int32(1463))
     self.assertEqual(b_arr[1], yapi.yices_true())
     self.assertEqual(b_arr[2], yapi.yices_int32(-579))
     yapi.yices_pp_term_array_fd(1, 3, b_arr, 100, 10, 0, 0)
     tvec3 = yapi.term_vector_t()
     yapi.yices_init_term_vector(tvec3)
     yapi.yices_generalize_model(mdl, fmla, 1, a_arr, 0, tvec3)
     yapi.yices_delete_term_vector(tvec3)
Example #29
0
 def walk_forall(self, formula, args, **kwargs):
     (bound_formula, var_list) = \
              self._rename_bound_variables(args[0], formula.quantifier_vars())
     res = yicespy.yices_forall(len(var_list), yicespy.make_term_array(var_list), bound_formula)
     self._check_term_result(res)
     return res
Example #30
0
 def walk_plus(self, formula, args, **kwargs):
     res = yicespy.yices_sum(len(args), yicespy.make_term_array(args))
     self._check_term_result(res)
     return res