本文整理汇总了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)