2

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

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

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.

vishes_shell
  • 22,409
  • 6
  • 71
  • 81
lukas kiss
  • 381
  • 2
  • 15
  • Looks like systems of linear equations on boolean space are solved exactly as systems of linear equations on real numbers. Could you please clarify in your question, are you looking for an algorithm, or how to implement an algorithm you already have, or both? – u354356007 Oct 11 '16 at 09:59
  • Sounds kind of like a SAT problem. – Nils Werner Oct 11 '16 at 10:01
  • I am looking for both.Algorithm and also for transformation from list to matrix. – lukas kiss Oct 11 '16 at 10:02
  • It was so slow, but I find quick solution. I transform it to matrix and use gaussian elimination. It was so QUICK. But this can only work for xor and not operations. – lukas kiss Feb 28 '17 at 22:17

1 Answers1

2

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

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.

asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • Thanks for solution, but if i have 60 equations with 120 variables it takes long time. Is there possibility to make it faster ? – lukas kiss Oct 17 '16 at 16:54
  • It depends on what part is being slow. It's generally either slow in the conversion to cnf or the SAT solving. You can check by running `to_cnf(And(*list_a))` for your system separately. – asmeurer Oct 18 '16 at 17:57