1

How do you solve a system of multivariate nonlinear equations that has three equations and 5000-20000 variables that can either be 0 or 1?

The system probably has a lot of solutions, but I only need to find one of them.

Thanks

Jessica
  • 2,335
  • 2
  • 23
  • 36
  • 1
    What kind of nonlinear equations are these? It sounds kind of like boolean satisfiability. – user2357112 Nov 05 '13 at 21:33
  • @user2357112 They're polynomials of at most degree 3. I'd like to extend it someday to polynomials of degree 6. – Jessica Nov 05 '13 at 21:34
  • I think R is pretty fast, you should be able to use matrix operations for that task. – Verena Haunschmid Nov 05 '13 at 21:35
  • Could you show a simple version of the equations - maybe two equations with five unknowns - to better show the type of expression? – Floris Nov 05 '13 at 21:48
  • x1 + x2 + x3 + x4 + x5 = s, x1x2 + x1x3 + x2x4 + x4x5 = t – Jessica Nov 05 '13 at 21:49
  • This is very similar to [Ramsey Theory](http://en.wikipedia.org/wiki/Ramsey_theory), and also [Boolean Satisfiability](http://en.wikipedia.org/wiki/Boolean_satisfiability_problem). My guess is that this is intractable. – mbeckish Nov 05 '13 at 21:53
  • 1
    The product terms can be linearised. If you define a new binary `y`, with `y <= x1, y <= x2` and `y >= x1 + x2 - 1` then `y = x1x2`. If it has only 3 equations, it should be very easy for mathematical programming solvers, I would try LPSolve, which is free:http://lpsolve.sourceforge.net/5.5/ and can be hooked up to `r`. Or any constraint programming solver would do. – Ioannis Nov 05 '13 at 23:00
  • This question appears to be off-topic because it belongs on the _Maths_ site. – halfer Nov 05 '13 at 23:05
  • 1
    No, it's an algorithms question. If all algorithms were maths, we wouldn't need an algorithms tag... – comingstorm Nov 06 '13 at 00:25

2 Answers2

4

In case your equations are purely Boolean you could use a "satisfiability solver" also known as SAT. Yours is exactly the problem SAT solvers are designed for. Many of them are open source, most known is miniSAT. You simply instantiate a solver, feed your equations (aka "clauses") into it and ask for a solution. Solver will stop the moment it finds the first suitable combinations of variables.

If I understand correctly, yours are not purely Boolean but arithmetic with Boolean variables. There are some tricks to adapt them for SAT. For example, common way to add the equation x1x2+x3x4+x5x6x7=2 to a SAT solver is the following: introduce new variables v1=x1x2, v2=x3x4, v3=x5x6x7 and then add a clause "exactly two of (v1,v2,v3) are true" (miniSAT has a generator for this and similar types of clauses).

In case some of coefficients are not 0 and 1 you will probably need special extension of SAT solvers known as SMT (Satisfiability Modulo Theories). Some of such programs are also available as open-source.

Michael Simbirsky
  • 3,045
  • 1
  • 12
  • 24
  • A SAT solver will never be able to solve for this many variables. The OP doesn't sate how many clauses there might be, but given thousands of "x" variables, that could turn into millions of your "v" variables. – mbeckish Nov 06 '13 at 18:28
  • Will solver handle them or not depends on on the equation and to some extent on the solver. As far as I recall, solver uses about 1K per variable. It then applies some fast elimination algorithms. If OP's equations are not very complicated (have many solutions), 1 mln. variables is tractable. I agree, pathological cases are quite possible too. – Michael Simbirsky Nov 06 '13 at 19:23
2

The nice thing about binary numbers (a = 0 or 1) is that a^b = a for all values of b > 0. So your "nonlinear" equation will become linear by the simple exploit of getting rid of all polynomial terms.

When you have a number of linear equations, the problem becomes: what combination of the coefficients (I am assuming the coefficients are linear) gives me the constant term for this equation? In principle you should be able to eliminate two variables (since you have three equations) and end up with just a single equation. Any combination of 1's and 0's that satisfies this will now be a solution to your problem. You would have to look at the coefficients - is there a single one that is equal to the constant? Then you have your answer (that bit = 1, all the others are 0). Or is there a pair of coefficients that add up to the constant? As you start to combine more terms, the number of permutations to test for gets rapidly larger. I can't think of a "clever" way to get beyond this - you would have to take a look at the coefficients (for example, if two variables have the same coefficient you can reduce your problem accordingly).

UPDATE Given the example

x1 + x2 + x3 + x4 + x5 = s
x1x2 + x2x3 + x3x4 + x4x5 = t

We can notice the following:

  1. the number of bits set to 1 must be == 5 (from the first equation)
  2. t must be < s (since no new terms appear, and we have products of terms)

In a toy example like this we can actually do an exhaustive search. When the number of terms gets much larger, the size of s and t will drive the complexity. A few things to note

Number of possible combinations of n bits summing to s = n!/(n-s)!s!. And it would be worth factoring the "compound" equation, using factors that appear most frequently as common terms. In the above, you would look at

x2(x1+x3) + x4(x3+x5) = t

Now we can see that if t > 2, we must have both x2=1 and x4=1; similar simplifications may be possible elsewhere.

Since you actually have only three equations, I would look for ways to set the largest possible number of elements to zero (using an approach like the above), then do an exhaustive search with the ones that are left...

Floris
  • 45,857
  • 6
  • 70
  • 122
  • Hi Floris, thanks for your answer. But they are multivariate polynomials, that is, the polynomials might look like xy + xz = 4. So you can't easily convert the polynomial equation into a linear equation. – Jessica Nov 05 '13 at 21:41
  • Ah - multivariate. That was a word I had not noticed in the question. You might want to update your wording... Are x, y and z all binary? Do they have integer coefficients? – Floris Nov 05 '13 at 21:46
  • Yeah, they're all binary, and the coefficients are all 1. – Jessica Nov 05 '13 at 21:49