sympy解决线性方程XOR,NOT

时间:2022-09-25 20:22:13

I have 60 equations with 70 variables. all of them are in one list:

我有60个方程,有70个变量。所有这些都在一个列表中:

(x0,x1,...,x239) are sympy symbols

(x0,x1,...,x239)是同情符号

list_a = [Xor(Not(x40), Not(x86)), Xor(x41, Not(x87)), ...]

and my question is, if it is possible somehow transform this equations to matrix or solved them. I think, that it can have more than one solution.

而我的问题是,如果有可能以某种方式将这些方程转换为矩阵或解决它们。我认为,它可以有多个解决方案。

1 个解决方案

#1


1  

A solution to a system of logic expressions is the same as checking SAT for the conjunction (And) of the expressions.

逻辑表达式系统的解决方案与检查SAT表达式的连接(And)相同。

In [3]: list_a = [Xor(Not(x40), Not(x86)), Xor(x41, Not(x87))]

In [4]: list_a
Out[4]: [¬x₄₀ ⊻ ¬x₈₆, x₄₁ ⊻ ¬x₈₇]

In [5]: satisfiable(And(*list_a))
Out[5]: {x87: False, x40: True, x86: False, x41: False}

If you want all solutions you can pass all_models=True, although note that in the general case there are exponentially many solutions.

如果您想要所有解决方案,您可以传递all_models = True,但请注意,在一般情况下,存在指数级的解决方案。

#1


1  

A solution to a system of logic expressions is the same as checking SAT for the conjunction (And) of the expressions.

逻辑表达式系统的解决方案与检查SAT表达式的连接(And)相同。

In [3]: list_a = [Xor(Not(x40), Not(x86)), Xor(x41, Not(x87))]

In [4]: list_a
Out[4]: [¬x₄₀ ⊻ ¬x₈₆, x₄₁ ⊻ ¬x₈₇]

In [5]: satisfiable(And(*list_a))
Out[5]: {x87: False, x40: True, x86: False, x41: False}

If you want all solutions you can pass all_models=True, although note that in the general case there are exponentially many solutions.

如果您想要所有解决方案,您可以传递all_models = True,但请注意,在一般情况下,存在指数级的解决方案。