def encode_equality(self,sort,*eterms): n = len(sort.defines()) if il.is_enumerated_sort(sort) else 2**len(eterms[0]) bits = ceillog2(n) eqs = self.sub.andl(*[self.sub.iff(x,y) for x,y in zip(*eterms)]) alt = self.sub.andl(*[self.gebin(e,n-1) for e in eterms]) res = [self.sub.orl(eqs,alt)] return res
def is_finite_sort(sort): if il.is_function_sort(sort): return False interp = thy.get_sort_theory(sort) return (il.is_enumerated_sort(interp) or isinstance(interp,thy.BitVectorTheory) or il.is_boolean_sort(interp))
def concepts_from_sig(symbols,concepts): for c in sorted(symbols,key=str): dom,rng = c.sort.dom,c.sort.rng if il.is_enumerated_sort(rng): # TODO: we have no way to display enumerated constants if len(dom) in [1,2]: vs = [Variable(n,s) for n,s in zip(['X','Y'],dom)] ec = concept_from_formula(c(*vs)) concepts['enum'].append(ec.name) concepts[ec.name] = enum_concepts(ec.name,vs,c(*vs)) for cons in rng.constructors: c1 = add_domain_concept_fmla(concepts,Equals(c(*vs),cons),kind='enum_case') concepts[ec.name].append(c1.name) elif il.is_boolean_sort(rng): # TODO: we have no way to display boolean constants if len(dom) in [1,2,3]: vs = [Variable(n,s) for n,s in zip(['X','Y','Z'],dom)] add_domain_concept_fmla(concepts,c(*vs)) elif il.is_first_order_sort(rng): if len(dom) == 0: add_domain_concept_fmla(concepts,Equals(Variable('X', rng),c)) elif len(dom) in [1,2]: vs = [Variable(n,s) for n,s in zip(['X','Y','Z'],dom+(rng,))] fmla = Equals(c(*vs[0:-1]),vs[-1]) add_domain_concept_fmla(concepts,fmla)
def concepts_from_sig(symbols, concepts): for c in sorted(symbols, key=str): dom, rng = c.sort.dom, c.sort.rng if il.is_enumerated_sort(rng): if len(dom) in [0, 1, 2]: if len(dom) == 0: if c in il.sig.constructors: continue # Hack: we treat enumerated constants as labels on the bogus sort "unit" vs, xvs = [], [Variable('X', create_unit_sort(concepts))] else: vs, xvs = [ Variable(n, s) for n, s in zip(['X', 'Y'], dom) ], None ec = concept_from_formula(c(*vs), vs=xvs) concepts['enum'].append(ec.name) concepts[ec.name] = enum_concepts(ec.name, vs, c(*vs)) for cons in rng.constructors: c1 = add_domain_concept_fmla(concepts, Equals(c(*vs), cons), kind='enum_case', vs=xvs) concepts[ec.name].append(c1.name) elif il.is_boolean_sort(rng): # TODO: we have no way to display boolean constants if len(dom) in [0, 1, 2, 3]: if len(dom) == 0: if c in il.sig.constructors: continue # Hack: we treat boolean constants as labels on the bogus sort "unit" vs, xvs = [], [Variable('X', create_unit_sort(concepts))] else: vs, xvs = [ Variable(n, s) for n, s in zip(['X', 'Y', 'Z'], dom) ], None add_domain_concept_fmla(concepts, c(*vs), vs=xvs) elif il.is_first_order_sort(rng): if len(dom) == 0: add_domain_concept_fmla(concepts, Equals(Variable('X', rng), c)) elif len(dom) in [1, 2]: vs = [ Variable(n, s) for n, s in zip(['X', 'Y', 'Z'], dom + (rng, )) ] fmla = Equals(c(*vs[0:-1]), vs[-1]) add_domain_concept_fmla(concepts, fmla)
def decode_val(self,bits,v): interp = thy.get_sort_theory(v.sort) if il.is_enumerated_sort(interp): num = self.bindec(bits) vals = v.sort.defines() val = vals[num] if num < len(vals) else vals[-1] val = il.Symbol(val,v.sort) elif isinstance(interp,thy.BitVectorTheory): num = self.bindec(bits) val = il.Symbol(str(num),v.sort) elif il.is_boolean_sort(interp): val = bits[0] else: assert False,'variable has unexpected sort: {} {}'.format(v,s.sort) return val
def get_encoding_bits(sort): # iu.dbg('sort') interp = thy.get_sort_theory(sort) if il.is_enumerated_sort(interp): n = ceillog2(len(interp.defines())) elif isinstance(interp,thy.BitVectorTheory): n = interp.bits elif il.is_boolean_sort(interp): n = 1 else: msg = 'model checking cannot handle sort {}'.format(sort) if interp is not sort: msg += '(interpreted as {})'.format(interp) raise iu.IvyError(None,msg) return n
def initial_concept_domain(sorts): concepts = OrderedDict() concepts['nodes'] = [] concepts['node_labels'] = [] concepts['edges'] = [] # add the requested nodes for sort in sorts: X = Variable('X', sort) add_domain_concept(concepts,Equals(X,X),name=sort.name,kind='nodes') # add equality concept if False: X = Variable('X', TopSort()) Y = Variable('Y', TopSort()) concepts['='] = co.Concept([X, Y], Equals(X, Y)) # add concepts from the signature for c in sorted(all_symbols(),key=str): dom,rng = c.sort.dom,c.sort.rng if il.is_enumerated_sort(rng): # TODO: we have no way to display enumerated constants if len(dom) in [1,2]: for cons in rng.constructors: vs = [Variable(n,s) for n,s in zip(['X','Y'],dom)] add_domain_concept(concepts,Equals(c(*vs),cons)) elif il.is_boolean_sort(rng): # TODO: we have no way to display boolean constants if len(dom) in [1,2]: vs = [Variable(n,s) for n,s in zip(['X','Y'],dom)] add_domain_concept(concepts,c(*vs)) elif il.is_first_order_sort(rng): if len(dom) == 0: add_domain_concept(concepts,Equals(Variable('X', rng),c)) elif len(dom == 1): fmla = Equals(c(Variable('X', dom[0])),Variable('Y', rng)) add_domain_concept(concepts,fmla) return co.ConceptDomain(concepts, co.get_standard_combiners(), co.get_standard_combinations())
def concepts_from_sig(symbols,concepts): for c in sorted(symbols,key=str): dom,rng = c.sort.dom,c.sort.rng if il.is_enumerated_sort(rng): if len(dom) in [0,1,2]: if len(dom) == 0: if c in il.sig.constructors: continue # Hack: we treat enumerated constants as labels on the bogus sort "unit" vs,xvs = [],[Variable('X',create_unit_sort(concepts))] else: vs,xvs = [Variable(n,s) for n,s in zip(['X','Y'],dom)],None ec = concept_from_formula(c(*vs),vs=xvs) concepts['enum'].append(ec.name) concepts[ec.name] = enum_concepts(ec.name,vs,c(*vs)) for cons in rng.constructors: c1 = add_domain_concept_fmla(concepts,Equals(c(*vs),cons),kind='enum_case',vs=xvs) concepts[ec.name].append(c1.name) elif il.is_boolean_sort(rng): # TODO: we have no way to display boolean constants if len(dom) in [0,1,2,3]: if len(dom) == 0: if c in il.sig.constructors: continue # Hack: we treat boolean constants as labels on the bogus sort "unit" vs,xvs = [],[Variable('X',create_unit_sort(concepts))] else: vs,xvs = [Variable(n,s) for n,s in zip(['X','Y','Z'],dom)],None add_domain_concept_fmla(concepts,c(*vs),vs=xvs) elif il.is_first_order_sort(rng): if len(dom) == 0: add_domain_concept_fmla(concepts,Equals(Variable('X', rng),c)) elif len(dom) in [1,2]: vs = [Variable(n,s) for n,s in zip(['X','Y','Z'],dom+(rng,))] fmla = Equals(c(*vs[0:-1]),vs[-1]) add_domain_concept_fmla(concepts,fmla)
def concepts_from_sig(symbols, concepts): for c in sorted(symbols, key=str): dom, rng = c.sort.dom, c.sort.rng if il.is_enumerated_sort(rng): # TODO: we have no way to display enumerated constants if len(dom) in [1, 2]: vs = [Variable(n, s) for n, s in zip(['X', 'Y'], dom)] ec = concept_from_formula(c(*vs)) concepts['enum'].append(ec.name) concepts[ec.name] = enum_concepts(ec.name, vs, c(*vs)) for cons in rng.constructors: c1 = add_domain_concept_fmla(concepts, Equals(c(*vs), cons), kind='enum_case') concepts[ec.name].append(c1.name) elif il.is_boolean_sort(rng): # TODO: we have no way to display boolean constants if len(dom) in [1, 2, 3]: vs = [Variable(n, s) for n, s in zip(['X', 'Y', 'Z'], dom)] add_domain_concept_fmla(concepts, c(*vs)) elif il.is_first_order_sort(rng): if len(dom) == 0: add_domain_concept_fmla(concepts, Equals(Variable('X', rng), c)) elif len(dom) in [1, 2]: vs = [ Variable(n, s) for n, s in zip(['X', 'Y', 'Z'], dom + (rng, )) ] fmla = Equals(c(*vs[0:-1]), vs[-1]) add_domain_concept_fmla(concepts, fmla)