def defenum(name, elts): """ Takes a name and list of strings, and builds an enumerated type For example: Beatles, (John, Paul, George, Ringo) = defenum('Beatles', ['John', 'Paul', 'George', 'Ringo']) """ enumtype = deftype(name) enumtype.value = Value(elts, 'enumtype_val') consts = () for e in elts: c = defconst(e, enumtype) c.value = Value(e, 'enumelt_val') consts += (c, ) return enumtype, consts
def model(self, m): """Takes a Z3 model and returns the corresponding Boole model. Arguments: - `m`: an instance of z3.ModelRef """ eqs = {} vals = {} for d in m: if isinstance(m[d], z3.FuncInterp): interp = m[d].as_list()[:-1] interp = [[self.translate(p) for p in r] for r in interp] d_eqs = interp_to_eqns(self.translate(d), interp) for i, e in enumerate(d_eqs): eqs[str(d) + 'def' + str(i)] = e vals[str(d)] = Value(z3_to_val(m[d])) else: eqs[str(d) + 'def'] = \ self.translate(d()) == self.translate(m[d]) vals[str(d)] = Value(z3_to_val(m[d])) return value.Model(eqs, vals)
def rr(n): val = Value(n, desc='float_val', is_num=True) return const(str(n), Real, value=val, \ unicode=color.orange + str(n) + color.reset)
def ii(n): val = Value(n, desc='int_val', is_num=True) return const(str(n), Int, value=val, \ unicode=color.orange + str(n) + color.reset)