Python3.5 Sympy似乎认为Xor和Xnor是等效的?
python3.5中的以下代码:
from sympy import *
A1,A2 = symbols('A1,A2')
f1 = Xor(A1,A2)
f2 = ~(Xor(A1,A2))
print(bool_map(f2,f1))
print(bool_map(f1,f2))
输出结果:
((A1 & A2) | (~A1 & ~A2), {A1: A1, A2: A2})
((A1 & ~A2) | (A2 & ~A1), {A1: A1, A2: A2})
所以f1和f2的简化逻辑明显不同,但是bool_map仍然返回它,认为这是2个布尔方程的有效符号映射吗?
我在做什么错了?
编辑:这确实是一个错误
这是_finger 5项指纹的缺陷:
'''
Assign a 5-item fingerprint to each symbol in the equation:
[
# of times it appeared as a Symbol,
# of times it appeared as a Not(symbol),
# of times it appeared as a Symbol in an And or Or,
# of times it appeared as a Not(Symbol) in an And or Or,
sum of the number of arguments with which it appeared,
counting Symbol as 1 and Not(Symbol) as 2
]
'''
from sympy import *
from sympy.logic.boolalg import _finger
from collections import defaultdict
from pprint import pprint
A1,A2 = symbols('A1,A2')
a = _finger((A1 & A2) | (~A1 & ~A2))
b = _finger((A1 & ~A2) | (~A1 & A2))
pprint(a)
pprint(b)
对A1和A2使用相同的指纹:
defaultdict(<class 'list'>, {(0, 0, 1, 1, 6): [A1, A2]})
defaultdict(<class 'list'>, {(0, 0, 1, 1, 6): [A1, A2]})
这就是为什么A1和A2看起来可互换的原因