Skip to content

Commit da9b2b4

Browse files
committed
xor optimizer
1 parent 991aee2 commit da9b2b4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

qlasskit/compiler/compiler.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@ def optimizer(expr: Boolean) -> Boolean:
4848
and len(expr.args) == 2
4949
and isinstance(expr.args[0], And)
5050
and isinstance(expr.args[1], And)
51-
and expr.args[1].args[0] == Not(expr.args[0].args[0])
52-
and expr.args[1].args[1] == Not(expr.args[0].args[1])
51+
and (
52+
(
53+
expr.args[1].args[0] == Not(expr.args[0].args[0])
54+
and expr.args[1].args[1] == Not(expr.args[0].args[1])
55+
)
56+
or (
57+
Not(expr.args[1].args[0]) == expr.args[0].args[0]
58+
and Not(expr.args[1].args[1]) == expr.args[0].args[1]
59+
)
60+
)
5361
):
5462
a = optimizer(expr.args[0].args[0])
5563
b = optimizer(expr.args[0].args[1])
@@ -66,15 +74,15 @@ def optimizer(expr: Boolean) -> Boolean:
6674
raise CompilerException("Constant in expression is not allowed")
6775

6876
else:
69-
return expr
77+
raise Exception(expr)
7078

7179

7280
class Compiler:
7381
def __init__(self):
7482
self.qmap = {}
7583

7684
def _symplify_exp(self, exp):
77-
exp = simplify_logic(exp)
85+
exp = simplify_logic(exp) # TODO: remove this
7886
exp = optimizer(exp)
7987
print("exp3", exp)
8088
return exp

0 commit comments

Comments
 (0)