XOR使用数学运算符 [英] XOR using mathematical operators
问题描述
如何使用+, - ,*,/
How can I implement XOR using basic mathematical operators like +,-,*,/
更新:实际上,我需要跟踪改变具有布尔值的两个矩阵。这可以通过使用其他矩阵中的相应值对每个值进行异或来完成。但是,Lp_Solve库不支持XOR操作。此外,它只接受线性方程。
Update: Actually, I need to track change in two matrix having Boolean values. This can be done using XORing each value with corresponding value in other matrix. But, Lp_Solve library doesn't support XOR operation. Also, it accepts only linear equations.
推荐答案
(a - b)²
(a − b)²
这样做是因为:
(a − b)² = a * (a − b) + b * (b − a)
因为ℤ2中的乘法是联合(&
),并且 1 -
是否定(!
),上面的公式相当于的XOR a,b∈ {0,1}
:
Since multiplication in ℤ₂ is conjuction (&
), and 1 - a
is negation (!
), the above formula is equivalent to XOR for a, b ∈ {0, 1}
:
(a & !b) | (b & !a)
请参阅Pascal Cuoq下面的评论解释为什么这不能是线性的等式。
See the comment below by Pascal Cuoq explaining why this cannot be a linear equation.
这篇关于XOR使用数学运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!