Remove duplicate variable from logic gate

Viewed 84

I want to remove duplicate variable from logic gate. For example, suppose i have the following code:

from z3 import *
a = Bool('a')
b = Bool('b')
# c is the same variable as a
c = Bool('a')
or_gate = Or(a, b, c)

I want to check whether or_gate contain multiple of the same variable, if yes i want to leave only one and remove the rest.
In above example, i want the or gate to be Or(a, b) instead of Or(a, b, a). What is the best way to do it?

1 Answers

You can use .hash() method to do that.

if a.hash() == b.hash():
    # they reference the same variable
Related