def test_quantify(): ordering = {'x': 0, 'y': 1, 'z': 2} g = BDD(ordering) # x & y e = g.add_expr('x && ! y') x = g.add_expr('x') not_y = g.add_expr('! y') assert g.quantify(e, {'x'}) == not_y assert g.quantify(e, {'x'}, forall=True) == -1 assert g.quantify(e, {'y'}) == x assert g.quantify(e, {'x'}, forall=True) == -1 # x | y | z e = g.add_expr('x || y || z') xy = g.add_expr('x || y') yz = g.add_expr('y || z') zx = g.add_expr('z || x') assert g.quantify(e, {'x'}) assert g.quantify(e, {'y'}) assert g.quantify(e, {'z'}) assert g.quantify(e, {'z'}, forall=True) == xy assert g.quantify(e, {'x'}, forall=True) == yz assert g.quantify(e, {'y'}, forall=True) == zx # complement edges u = -x v = g.quantify(u, {'y'}, forall=True) assert v == -x, g.to_expr(v) # multiple values: test recursion e = g.add_expr('x & y & z') x = g.add_expr('x') r = g.quantify(e, {'y', 'z'}) assert r == x, 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 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')