Beispiel #1
0
    def get_value(self, item):
        self._assert_no_function_type(item)

        titem = self.converter.convert(item)
        tval = mathsat.msat_get_model_value(self.msat_env, titem)

        if mathsat.msat_term_is_number(self.msat_env, tval):
            rep = mathsat.msat_term_repr(tval)
            if self.environment.stc.get_type(item).is_real_type():
                match = re.match(r"(-?\d+)/(\d+)", rep)
                if match is not None:
                    return self.mgr.Real(
                        (int(match.group(1)), int(match.group(2))))
                else:
                    return self.mgr.Real(int(rep))
            elif self.environment.stc.get_type(item).is_int_type():
                return self.mgr.Int(int(rep))
            else:
                assert self.environment.stc.get_type(item).is_bv_type()
                # MathSAT representation is <value>_<width>
                value, width = rep.split("_")
                return self.mgr.BV(int(value), int(width))

        else:
            assert mathsat.msat_term_is_true(self.msat_env, tval) or \
                mathsat.msat_term_is_false(self.msat_env, tval)
            bval = (mathsat.msat_term_is_true(self.msat_env, tval) == 1)
            return self.mgr.Bool(bval)
Beispiel #2
0
    def get_value(self, item):
        self._assert_no_function_type(item)

        titem = self.converter.convert(item)
        tval = mathsat.msat_get_model_value(self.msat_env, titem)

        if mathsat.msat_term_is_number(self.msat_env, tval):
            rep = mathsat.msat_term_repr(tval)
            if self.environment.stc.get_type(item).is_real_type():
                match = re.match(r"(-?\d+)/(\d+)", rep)
                if match is not None:
                    return self.mgr.Real((int(match.group(1)),
                                          int(match.group(2))))
                else:
                    return self.mgr.Real(int(rep))
            elif self.environment.stc.get_type(item).is_int_type():
                return self.mgr.Int(int(rep))
            else:
                assert self.environment.stc.get_type(item).is_bv_type()
                # MathSAT representation is <value>_<width>
                value, width = rep.split("_")
                return self.mgr.BV(int(value), int(width))

        else:
            assert mathsat.msat_term_is_true(self.msat_env, tval) or \
                mathsat.msat_term_is_false(self.msat_env, tval)
            bval = (mathsat.msat_term_is_true(self.msat_env, tval) == 1)
            return self.mgr.Bool(bval)
Beispiel #3
0
    def get_value(self, item):
        self._assert_no_function_type(item)

        titem = self.converter.convert(item)
        tval = mathsat.msat_get_model_value(self.msat_env(), titem)
        val = self.converter.back(tval)
        if self.environment.stc.get_type(item).is_real_type() and \
               val.is_int_constant():
            val = self.mgr.Real(val.constant_value())
        return val