def __init__(self, T): self.comps = Rec({'base_type': T}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [ lambda l: isinstance(l, list) and forall(l, lambda x: T.query(x)) ]
def __init__(self, T, a): self.comps = Rec({'base_type': T, 'obj': a}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [lambda x: x == a and T.query(x),\ lambda x: isinstance(a,LazyObj)\ and show(x) == show(a.eval()) and T.query(x)]
def __init__(self, name='', cs={}): self.name = name if self.name == '': self.name = gensym('T') self.comps = Rec(cs) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = []
def __init__(self, pred, args): self.comps = Rec({'pred': pred, 'args': args}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [] self.witness_types = [] self.poss = ''
def __init__(self, T1, T2): self.comps = Rec({'domain': T1, 'range': T2}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [lambda f: isinstance(f,Fun) \ and f.domain_type == self.comps.domain \ and self.comps.range.query(f.app(self.comps.domain.create_hypobj()))]
def __init__(self, T1, T2): self.comps = Rec({'left': T1, 'right': T2}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [lambda a: self.comps.left.in_poss(self.poss).query(a), \ lambda a: self.comps.right.in_poss(self.poss).query(a)] self.witness_types = [] self.poss = ''
def __init__(self, name=gensym('BT')): self.name = name self.comps = Rec({}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [] self.witness_types = [] self.poss = ''
def create_hypobj(self): res = Rec() depfields = RecType() for l in self.comps.__dict__: T = self.comps.__getattribute__(l) if isinstance(T,Type): res.addfield(l,T.create_hypobj()) else: depfields.addfield(l,T) return ProcessDepFields(depfields,res,self,'hyp')
def create(self): res = Rec() depfields = RecType() for l in self.comps.__dict__: T = self.comps.__getattribute__(l) if isinstance(T, TypeClass): res.addfield(l, T.in_poss(self.poss).create()) else: depfields.addfield(l, T) return ProcessDepFields(depfields, res, self)
def __init__(self, list): self.comps = Rec({'types': list}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = \ [lambda s: isinstance(s,TTRString) \ and len(s.items) == len(self.comps.types) \ and forall([x for x in range(len(self.comps.types))], \ lambda i: self.comps.types[i].in_poss(self.poss).query(s.items[i]))] self.poss = ''
def __init__(self, T): self.comps = Rec({'base_type': T}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = \ [lambda s: isinstance(s,TTRString) \ and len(s.items)>0 \ and forall(s.items, lambda a: self.comps.base_type.in_poss(self.poss).query(a))] self.poss = ''
def __init__(self, strT): self.comps = Rec({'base_type': strT}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = \ [lambda s: isinstance(s,TTRString) and s.startswith_recursive(self.comps.base_type)] # and len(s.items)>0 \ # and forall(s.items, # lambda a: self.comps.base_type.in_poss(self.poss).query(a))] self.witness_types = [] self.poss = _M
def __init__(self, d={}): self.comps = Rec() for item in d.items(): if isinstance(item[1], dict): self.addfield(item[0], RecType(item[1])) else: self.addfield(item[0], item[1]) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [ \ lambda r: isinstance(r, Rec) and RecOfRecType(r,self,self.poss)] self.poss = ''
def sample(self, n=config.sample_size): chart = {} count = -1 nondepfields = RecType() for l in self.comps.__dict__: T = self.comps.__getattribute__(l) if isinstance(T, RecType): count = count + 1 chart[count] = [] vals = T.in_poss(self.poss).sample(n) #print(show(T.in_poss(self.poss))) #print(vals) if count == 0: for r in vals: chart[count].append(Rec({l: r})) #print(chart) else: for r in vals: for rec in chart[count - 1]: combrec = rec.addrec(Rec({l: r})) if combrec: chart[count].append(combrec) else: pass elif isinstance(T, TypeClass): nondepfields.addfield(l, T) else: count = count + 1 chart[count] = [] matches = T[0].matches(self.poss, n) #print('matches: ', show(matches)) for m in matches: for s in m[0].in_poss(self.poss).sample(n): r = Rec({l: s}) #print('r: ',show(r)) #print('T[1]',show(T[1])) for p in T[1]: newrec = Rec({}) newrec.addpath(p, m[1][T[1].index(p)]) #print('newrec:',show(newrec)) r = r.addrec(newrec) #print('r after addrec: ',show(r)) if count == 0: chart[count].append(r) else: for rec in chart[count - 1]: combrec = rec.addrec(r) if combrec: chart[count].append(combrec) count = count + 1 chart[count] = [] #print(show(nondepfields)) if count == 0: newrecs = [] for l in nondepfields.comps.__dict__: matches = nondepfields.comps.__getattribute__(l).in_poss( self.poss).sample(n) if newrecs == []: for i in range(2 * n): m = np.random.choice(matches) newrecs.append(Rec({l: m})) else: for i in range(len(newrecs)): m = np.random.choice(matches) newrecs[i] = newrecs[i].addrec(Rec({l: m})) for r in newrecs: chart[count].append(r) else: for rec in chart[count - 1]: #print([l for l in rec.__dict__],[l for l in nondepfields.comps.__dict__]) if set([l for l in nondepfields.comps.__dict__ ]).issubset(set([l for l in rec.__dict__])): chart[count].append(rec) else: newrecs = [] for l in [ l for l in nondepfields.comps.__dict__ if not l in rec.__dict__ ]: matches = nondepfields.comps.__getattribute__( l).in_poss(self.poss).sample(n) if newrecs == []: for i in range(2 * n): m = np.random.choice(matches) newrecs.append(Rec({l: m})) # for m in matches: # newrecs.append(Rec({l:m})) else: for i in range(len(newrecs)): m = np.random.choice(matches) newrecs[i] = newrecs[i].addrec(Rec({l: m})) # for r in newrecs: # m = np.random.choice(matches) # r.addrec(Rec({l:m})) for r in newrecs: chart[count].append(rec.addrec(r)) #print(show(chart)) res = [] for r in chart[count]: if not any(map(lambda x: equal(x, r), res)): res.append(r) if len(res) <= n: return res else: return list(np.random.choice(res, n, False))
def __init__(self, T): self.comps = Rec({'base_type': T}) self.witness_conditions = [ lambda a, c, oracle: PNeg(self.comps.base_type.query(a, c, oracle)) ]
def __init__(self, T1, T2): self.comps = Rec({'left': T1, 'right': T2}) self.witness_cache = [] self.supertype_cache = [] self.witness_conditions = [lambda a: self.comps.left.query(a) \ and self.comps.right.query(a)]
print(show(Fun('x', Ind, PType(man, ['x'])).app('j'))) print(show(manj)) print(manj.query_nonspec()) M = Possibility('M') manj.in_poss(M) print(Fun('x', Ind, PType(man, ['x'])).app('j').in_poss(M).query_nonspec()) print(show(M)) print(Ty.query(RecType({'x': Ind}))) print(RecType({'x': Ind}).query(Rec({'x': 'j'}))) print(RecType({'x': Ind}).query(Rec({'x': 'j', 'y': 'k', 'z': 'e1'}))) print(RecType({'x': Ind, 'y': Ind}).query(Rec({'x': 'j'}))) #False print( RecTy.query( RecType({ 'x': Ind, 'c': (Fun('v', Ind, PType(man, ['v'])), ['x']) }))) T_man = RecType({'x': Ind, 'c': (Fun('v', Ind, PType(man, ['v'])), ['x'])}) print(T_man.query(Rec({'x': 'j', 'c': '_e1'})))
""" Created on Tue Mar 3 15:05:58 2015 @author: cooper """ from records import Rec from utils import show r = Rec({ 'f': { 'f': { 'ff': 'a', 'gg': 'b' }, 'g': 'c' }, 'g': { 'h': { 'g': 'a', 'h': 'd' } } }) print(show(r)) print(show(r.f)) print(show(r.g.h)) print(show(r.f.f.ff)) print(show(r.subst('a', 'z')))