本文整理匯總了Python中dd.bdd.BDD.to_expr方法的典型用法代碼示例。如果您正苦於以下問題:Python BDD.to_expr方法的具體用法?Python BDD.to_expr怎麽用?Python BDD.to_expr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dd.bdd.BDD
的用法示例。
在下文中一共展示了BDD.to_expr方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_quantify
# 需要導入模塊: from dd.bdd import BDD [as 別名]
# 或者: from dd.bdd.BDD import to_expr [as 別名]
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
示例2: test_compose
# 需要導入模塊: from dd.bdd import BDD [as 別名]
# 或者: from dd.bdd.BDD import to_expr [as 別名]
def test_compose():
ordering = {'x': 0, 'y': 1, 'z': 2}
g = BDD(ordering)
# x & (x | z)
a = g.add_expr('x && y')
b = g.add_expr('x || z')
c = g.compose(a, 'y', b)
d = g.add_expr('x && (x || z)')
assert c == d, (c, d)
# (y | z) & x
ordering = {'x': 0, 'y': 1, 'z': 2, 'w': 3}
g = BDD(ordering)
a = g.add_expr('(x && y) || z')
b = g.add_expr('(y || z) && x')
c = g.compose(a, 'z', b)
assert c == b, (c, b)
# long expr
ordering = {'x': 0, 'y': 1, 'z': 2, 'w': 3}
g = BDD(ordering)
a = g.add_expr('(x && y) || (!z || (w && y && x))')
b = g.add_expr('(y || z) && x')
c = g.compose(a, 'y', b)
d = g.add_expr(
'(x && ((y || z) && x)) ||'
' (!z || (w && ((y || z) && x) && x))')
assert c == d, (c, d)
# complemented edges
ordering = {'x': 0, 'y': 1}
g = BDD(ordering)
f = g.add_expr('x <-> y')
var = 'y'
new_level = 0
var_node = g.find_or_add(new_level, -1, 1)
u = g.compose(f, var, var_node)
assert u == 1, g.to_expr(u)