2

I am using sympy to produce symbolic polynomial equations. I have roughly 30 variables and roughly 20 constant variables. The highest power that my equations reach is a squared term.

I need to take 2^13 of these equations and figure out how many of them are unique (i.e., not linear combinations of each other, not degenerate). Otherwise said, I need to find the rank of the matrix produced by the system of equations. Most of these equations are degenerate, they are linear combinations of each other. Ultimately, however, I need to extract the unique equations from the data.

I tried a system as follows:

  1. Create an empty matrix.
  2. Iterate over each equation. For each equation, turn it into a row for a matrix, and check the if the rank of the matrix increases by adding the new row.
  3. If the rank increases, append the row to the empty matrix
  4. Print the resulting matrix.

If done correctly, this should give all of the unique equations. However, numpy.linalg.matrix_rank() does not work on sympy symbols. Unfortunately, I have roughly 20 constants that are represented by sympy symbols.

How do I find my unique equations? Any of these will solve my problem:

  1. An explicit solution to get non-degenerate equations
  2. A method for evaluating the rank of a matrix that has sympy symbols in it.
  3. Or, does sympy have built-in functionality for determining if a sympy equation is a linear combination of other sympy equations?
Paul Terwilliger
  • 1,596
  • 1
  • 20
  • 45

1 Answers1

2

Sympy has a Matrix class with a rank method:

In [1]: x, y = symbols('x y')

In [2]: M = Matrix([[x, y], [2*x, 2*y]])

In [3]: M
Out[3]: 
⎡ x    y ⎤
⎢        ⎥
⎣2⋅x  2⋅y⎦

In [4]: M.rank()
Out[4]: 1

I do not know the implementation, and it might be slow. So you might want to improve your algorithm, e. g. by keeping the matrix reduced to row echelon form.

A more systematic approch which does not rely on the input order of the polynomials might compute and use a Gröbner basis.

ccorn
  • 496
  • 8
  • 10