def test_rename(): ordering = {'x': 0, 'xp': 1} g = BDD(ordering) x = g.add_expr('x') xp = g.add_expr('xp') dvars = {'x': 'xp'} xrenamed = _bdd.rename(x, g, dvars) assert xrenamed == xp, xrenamed ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} g = BDD(ordering) u = g.add_expr('x && y && ! z') dvars = {'x': 'xp', 'y': 'yp', 'z': 'zp'} urenamed = _bdd.rename(u, g, dvars) up = g.add_expr('xp && yp && ! zp') assert urenamed == up, urenamed # assertion violations # non-neighbors dvars = {'x': 'yp'} with nt.assert_raises(AssertionError): _bdd.rename(u, g, dvars) # u not in bdd dvars = {'x': 'xp'} with nt.assert_raises(AssertionError): _bdd.rename(15, g, dvars) # y essential for u dvars = {'xp': 'y'} with nt.assert_raises(AssertionError): _bdd.rename(u, g, dvars) # old and new vars intersect dvars = {'x': 'x'} with nt.assert_raises(AssertionError): _bdd.rename(u, g, dvars)
def test_rename(): ordering = {'x': 0, 'xp': 1} g = BDD(ordering) x = g.add_expr('x') xp = g.add_expr('xp') dvars = {'x': 'xp'} xrenamed = _bdd.rename(x, g, dvars) assert xrenamed == xp, xrenamed ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} g = BDD(ordering) u = g.add_expr('x && y && ! z') dvars = {'x': 'xp', 'y': 'yp', 'z': 'zp'} urenamed = _bdd.rename(u, g, dvars) up = g.add_expr('xp && yp && ! zp') assert urenamed == up, urenamed # assertion violations # non-neighbors dvars = {'x': 'yp'} r = _bdd.rename(u, g, dvars) r_ = g.add_expr('yp && y && ! z') assert r == r_, (r, r_) # u not in bdd dvars = {'x': 'xp'} with nt.assert_raises(AssertionError): _bdd.rename(1000, g, dvars) # y essential for u dvars = {'xp': 'y'} with nt.assert_raises(AssertionError): _bdd.rename(u, g, dvars) # old and new vars intersect dvars = {'x': 'x'} with nt.assert_raises(AssertionError): _bdd.rename(u, g, dvars)
def require_closure(z, aut): bdd = aut.bdd for p in aut.players: (action,) = aut.action[p] zp = _bdd.rename(z, bdd, aut.prime[p]) stay = bdd.apply('and', z, zp) u = bdd.apply('and', action, stay) aut.action[p] = [u]
def image(source, aut): bdd = aut.bdd n = len(aut.players) ivar = '_i' pre = bdd.false for i, p in aut.turns.iteritems(): assert i < n, (i, n) assert p in aut.players, (p, aut.players) ip = (i + 1) % n (action,) = aut.action[p] qvars = aut.prime[p] u = symbolic.cofactor(source, ivar, i, bdd, aut.vars) u = bdd.apply('and', action, u) u = bdd.quantify(u, qvars, forall=False) u = _bdd.rename(u, bdd, aut.unprime[p]) s = '{ivar} = {ip}'.format(ivar=ivar, ip=ip) turn = aut.add_expr(s) u = bdd.apply('and', turn, u) pre = bdd.apply('or', pre, u) return pre
def image(source, aut): bdd = aut.bdd n = len(aut.players) ivar = '_i' pre = bdd.false for i, p in aut.turns.items(): assert i < n, (i, n) assert p in aut.players, (p, aut.players) ip = (i + 1) % n (action, ) = aut.action[p] qvars = aut.prime[p] u = symbolic.cofactor(source, ivar, i, bdd, aut.vars) u = bdd.apply('and', action, u) u = bdd.quantify(u, qvars, forall=False) u = _bdd.rename(u, bdd, aut.unprime[p]) s = '{ivar} = {ip}'.format(ivar=ivar, ip=ip) turn = aut.add_expr(s) u = bdd.apply('and', turn, u) pre = bdd.apply('or', pre, u) return pre
def ue_preimage(target, team, aut): bdd = aut.bdd n = len(aut.players) ivar = '_i' pre = bdd.false for i, p in aut.turns.iteritems(): assert i < n, (i, n) assert p in aut.players, (p, aut.players) ip = (i + 1) % n u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars) u = _bdd.rename(u, bdd, aut.prime[p]) (action,) = aut.action[p] if p not in team: u = bdd.apply('not', u) u = bdd.apply('and', action, u) u = bdd.quantify(u, aut.unprime[p], forall=False) if p not in team: u = bdd.apply('not', u) s = '{ivar} = {i}'.format(ivar=ivar, i=i) turn = aut.add_expr(s) u = bdd.apply('and', turn, u) pre = bdd.apply('or', pre, u) return pre
def preimage(target, aut): """Predecessors with interleaving repr.""" bdd = aut.bdd n = len(aut.players) ivar = '_i' # needed to force extra steps outside pre = bdd.false for i, p in aut.turns.iteritems(): assert i < n, (i, n) assert p in aut.players, (p, aut.players) ip = (i + 1) % n u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars) (action,) = aut.action[p] u = _bdd.rename(u, bdd, aut.prime[p]) u = bdd.apply('and', action, u) qvars = aut.unprime[p] u = bdd.quantify(u, qvars, forall=False) s = '{ivar} = {i}'.format(ivar=ivar, i=i) turn = aut.add_expr(s) u = bdd.apply('and', turn, u) # TODO: revisit the index behavior pre = bdd.apply('or', pre, u) return pre
def ue_preimage(target, team, aut): bdd = aut.bdd n = len(aut.players) ivar = '_i' pre = bdd.false for i, p in aut.turns.items(): assert i < n, (i, n) assert p in aut.players, (p, aut.players) ip = (i + 1) % n u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars) u = _bdd.rename(u, bdd, aut.prime[p]) (action, ) = aut.action[p] if p not in team: u = bdd.apply('not', u) u = bdd.apply('and', action, u) u = bdd.quantify(u, aut.unprime[p], forall=False) if p not in team: u = bdd.apply('not', u) s = '{ivar} = {i}'.format(ivar=ivar, i=i) turn = aut.add_expr(s) u = bdd.apply('and', turn, u) pre = bdd.apply('or', pre, u) return pre
def preimage(target, aut): """Predecessors with interleaving repr.""" bdd = aut.bdd n = len(aut.players) ivar = '_i' # needed to force extra steps outside pre = bdd.false for i, p in aut.turns.items(): assert i < n, (i, n) assert p in aut.players, (p, aut.players) ip = (i + 1) % n u = symbolic.cofactor(target, ivar, ip, bdd, aut.vars) (action, ) = aut.action[p] u = _bdd.rename(u, bdd, aut.prime[p]) u = bdd.apply('and', action, u) qvars = aut.unprime[p] u = bdd.quantify(u, qvars, forall=False) s = '{ivar} = {i}'.format(ivar=ivar, i=i) turn = aut.add_expr(s) u = bdd.apply('and', turn, u) # TODO: revisit the index behavior pre = bdd.apply('or', pre, u) return pre
def rename(u, bdd, dvars): r = _bdd.rename(u.node, u.bdd, dvars) return bdd._wrap(r)