def test_image_rename_map_checks(): ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} bdd = BDD(ordering) # non-adjacent rename = {0: 2, 3: 4} qvars = set() r = _bdd.image(1, 1, rename, qvars, bdd) assert r == 1, r r = _bdd.preimage(1, 1, rename, qvars, bdd) assert r == 1, r # overlapping keys and values rename = {0: 1, 1: 2} with nt.assert_raises(AssertionError): _bdd.image(1, 1, rename, qvars, bdd) with nt.assert_raises(AssertionError): _bdd.preimage(1, 1, rename, qvars, bdd) # may be in support after quantification ? trans = bdd.add_expr('x => xp') source = bdd.add_expr('x /\ y') qvars = {0} rename = {1: 0, 3: 2} with nt.assert_raises(AssertionError): _bdd.image(trans, source, rename, qvars, bdd) # in support of `target` ? qvars = set() trans = bdd.add_expr('y') target = bdd.add_expr('x /\ y') rename = {0: 2} r = _bdd.preimage(trans, target, rename, qvars, bdd) assert r == bdd.var('y'), r
def test_image_rename_map_checks(): ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} bdd = BDD(ordering) # non-adjacent rename = {0: 2, 3: 4} qvars = set() r = _bdd.image(1, 1, rename, qvars, bdd) assert r == 1, r r = _bdd.preimage(1, 1, rename, qvars, bdd) assert r == 1, r # overlapping keys and values rename = {0: 1, 1: 2} with nt.assert_raises(AssertionError): _bdd.image(1, 1, rename, qvars, bdd) with nt.assert_raises(AssertionError): _bdd.preimage(1, 1, rename, qvars, bdd) # may be in support after quantification ? trans = bdd.add_expr('x => xp') source = bdd.add_expr('x /\ y') qvars = {0} rename = {1: 0, 3: 2} with nt.assert_raises(AssertionError): _bdd.image(trans, source, rename, qvars, bdd) # in support of `target` ? qvars = set() trans = bdd.add_expr('y') target = bdd.add_expr('x /\ y') rename = {0: 2} r = _bdd.preimage(trans, target, rename, qvars, bdd) assert r == bdd.var('y'), r
def test_preimage(): # exists: x, y # forall: z ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} rename = {0: 1, 2: 3, 4: 5} g = BDD(ordering) f = g.add_expr('~ x') t = g.add_expr('x <=> ~ xp') qvars = {1, 3} p = preimage(t, f, rename, qvars, g) x = g.add_expr('x') assert x == p, (x, p) # a cycle # (x /\ y) --> (~ x /\ y) --> # (~ x /\ ~ y) --> (x /\ ~ y) --> wrap around t = g.add_expr( '((x /\ y) => (~ xp /\ yp)) /\ ' '((~ x /\ y) => (~ xp /\ ~ yp)) /\ ' '((~ x /\ ~ y) => (xp /\ ~ yp)) /\ ' '((x /\ ~ y) => (xp /\ yp))') f = g.add_expr('x /\ y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('x /\ ~ y') f = g.add_expr('x /\ ~ y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('~ x /\ ~ y') # backward reachable set f = g.add_expr('x /\ y') oldf = None while oldf != f: p = preimage(t, f, rename, qvars, g) oldf = f f = g.apply('or', p, oldf) assert f == 1 # go around once f = g.add_expr('x /\ y') start = f for i in range(4): f = preimage(t, f, rename, qvars, g) end = f assert start == end # forall z exists x, y t = g.add_expr( '(' ' ((x /\ y) => (zp /\ xp /\ ~ yp)) \/ ' ' ((x /\ y) => (~ zp /\ ~ xp /\ yp))' ') /\ ' '(~ (x /\ y) => False)') f = g.add_expr('x /\ ~ y') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == -1 f = g.add_expr('(x /\ ~ y) \/ (~ x /\ y)') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == g.add_expr('x /\ y')
def test_preimage(): # exists: x, y # forall: z ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} rename = {0: 1, 2: 3, 4: 5} g = BDD(ordering) f = g.add_expr('!x') t = g.add_expr('x <-> !xp') qvars = {1, 3} p = preimage(t, f, rename, qvars, g) x = g.add_expr('x') assert x == p, (x, p) # a cycle # (x & y) -> (!x & y) -> # (!x & !y) -> (x & !y) -> wrap around t = g.add_expr( '((x & y) -> (!xp & yp)) && ' '((!x & y) -> (!xp & !yp)) && ' '((!x & !y) -> (xp & !yp)) && ' '((x & !y) -> (xp & yp))') f = g.add_expr('x && y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('x & !y') f = g.add_expr('x && !y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('!x & !y') # backward reachable set f = g.add_expr('x & y') oldf = None while oldf != f: p = preimage(t, f, rename, qvars, g) oldf = f f = g.apply('or', p, oldf) assert f == 1 # go around once f = g.add_expr('x & y') start = f for i in range(4): f = preimage(t, f, rename, qvars, g) end = f assert start == end # forall z exists x, y t = g.add_expr( '(' ' ((x & y) -> (zp & xp & !yp)) | ' ' ((x & y) -> (!zp & !xp & yp))' ') & ' '(!(x & y) -> False)') f = g.add_expr('x && !y') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == -1 f = g.add_expr('(x & !y) | (!x & y)') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == g.add_expr('x & y')
def test_preimage(): # exists: x, y # forall: z ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} rename = {0: 1, 2: 3, 4: 5} g = BDD(ordering) f = g.add_expr('~ x') t = g.add_expr('x <=> ~ xp') qvars = {1, 3} p = preimage(t, f, rename, qvars, g) x = g.add_expr('x') assert x == p, (x, p) # a cycle # (x /\ y) --> (~ x /\ y) --> # (~ x /\ ~ y) --> (x /\ ~ y) --> wrap around t = g.add_expr( '((x /\ y) => (~ xp /\ yp)) /\ ' '((~ x /\ y) => (~ xp /\ ~ yp)) /\ ' '((~ x /\ ~ y) => (xp /\ ~ yp)) /\ ' '((x /\ ~ y) => (xp /\ yp))') f = g.add_expr('x /\ y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('x /\ ~ y') f = g.add_expr('x /\ ~ y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('~ x /\ ~ y') # backward reachable set f = g.add_expr('x /\ y') oldf = None while oldf != f: p = preimage(t, f, rename, qvars, g) oldf = f f = g.apply('or', p, oldf) assert f == 1 # go around once f = g.add_expr('x /\ y') start = f for i in range(4): f = preimage(t, f, rename, qvars, g) end = f assert start == end # forall z exists x, y t = g.add_expr( '(' ' ((x /\ y) => (zp /\ xp /\ ~ yp)) \/ ' ' ((x /\ y) => (~ zp /\ ~ xp /\ yp))' ') /\ ' '(~ (x /\ y) => False)') f = g.add_expr('x /\ ~ y') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == -1 f = g.add_expr('(x /\ ~ y) \/ (~ x /\ y)') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == g.add_expr('x /\ y')
def test_preimage(): # exists: x, y # forall: z ordering = {'x': 0, 'xp': 1, 'y': 2, 'yp': 3, 'z': 4, 'zp': 5} rename = {0: 1, 2: 3, 4: 5} g = BDD(ordering) f = g.add_expr('!x') t = g.add_expr('x <-> !xp') qvars = {1, 3} p = preimage(t, f, rename, qvars, g) x = g.add_expr('x') assert x == p, (x, p) # a cycle # (x & y) -> (!x & y) -> # (!x & !y) -> (x & !y) -> wrap around t = g.add_expr('((x & y) -> (!xp & yp)) && ' '((!x & y) -> (!xp & !yp)) && ' '((!x & !y) -> (xp & !yp)) && ' '((x & !y) -> (xp & yp))') f = g.add_expr('x && y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('x & !y') f = g.add_expr('x && !y') p = preimage(t, f, rename, qvars, g) assert p == g.add_expr('!x & !y') # backward reachable set f = g.add_expr('x & y') oldf = None while oldf != f: p = preimage(t, f, rename, qvars, g) oldf = f f = g.apply('or', p, oldf) assert f == 1 # go around once f = g.add_expr('x & y') start = f for i in xrange(4): f = preimage(t, f, rename, qvars, g) end = f assert start == end # forall z exists x, y t = g.add_expr('(' ' ((x & y) -> (zp & xp & !yp)) | ' ' ((x & y) -> (!zp & !xp & yp))' ') & ' '(!(x & y) -> False)') f = g.add_expr('x && !y') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == -1 f = g.add_expr('(x & !y) | (!x & y)') ep = preimage(t, f, rename, qvars, g) p = g.quantify(ep, {'zp'}, forall=True) assert p == g.add_expr('x & y')
def preimage(trans, target, rename, qvars, forall=False): assert trans.bdd is target.bdd u = _bdd.preimage(trans.node, target.node, rename, qvars, trans.manager, forall) return trans.bdd._wrap(u)
def preimage(trans, target, qvars, automaton, forall): """Preimage with non-mixed quantification.""" return _bdd.preimage( trans, target, automaton.prime, qvars, automaton.bdd, forall)
def preimage(trans, target, rename, qvars, forall=False): assert trans.bdd is target.bdd u = _bdd.preimage(trans.node, target.node, rename, qvars, trans.manager, forall) return trans.bdd._wrap(u)
def preimage(trans, target, qvars, automaton, forall): """Preimage with non-mixed quantification.""" return _bdd.preimage(trans, target, automaton.prime, qvars, automaton.bdd, forall)
def preimage(trans, target, rename, qvars, bdd, forall=False): assert trans.bdd == target.bdd assert trans.bdd == bdd._bdd u = _bdd.preimage(trans.node, target.node, rename, qvars, trans.bdd, forall) return bdd._wrap(u)
def preimage(trans, target, rename, qvars, bdd, forall=False): assert trans.bdd == target.bdd assert trans.bdd == bdd._bdd u = _bdd.preimage(trans.node, target.node, rename, qvars, trans.bdd, forall) return bdd._wrap(u)