1

I have 10163 equations and 9000 unknowns, all over finite fields, like this style: enter image description here

Of course my equation will be much larger than this, I have 10163 rows and 9000 different x.

Presented in the form of a matrix is AX=B. A is a 10163x9000 coefficient matrix and it may be sparse, X is a 9000x1 unknown vector, B is the result of their multiplication and mod 2.

Because of the large number of unknowns that need to be solved for, it can be time consuming. I'm looking for a faster way to solve this system of equations using C language.

I tried to use Gaussian elimination method to solve this equation, In order to make the elimination between rows more efficient, I store the matrix A in a 64-bit two-dimensional array, and let the last column of the array store the value of B, so that the XOR operation may reduce the calculating time.

The code I am using is as follows:

    uint8_t guss_x_main[R_BITS] = {0};
    uint64_t tmp_guss[guss_j_num];

    for(uint16_t guss_j = 0; guss_j < x_weight; guss_j++)
    {
      uint64_t mask_1    = 1;
      uint64_t mask_guss = (mask_1 << (guss_j % GUSS_BLOCK));
      uint16_t eq_j      = guss_j / GUSS_BLOCK;
      for(uint16_t guss_i = guss_j; guss_i < R_BITS; guss_i++)
      {
        if((mask_guss & equations_guss_byte[guss_i][eq_j]) != 0)
        {
          if(guss_x_main[guss_j] == 0)
          {
            guss_x_main[guss_j] = 1;
            for(uint16_t change_i = 0; change_i < guss_j_num; change_i++)
            {
              tmp_guss[change_i] = equations_guss_byte[guss_j][change_i];
              equations_guss_byte[guss_j][change_i] =
                  equations_guss_byte[guss_i][change_i];
              equations_guss_byte[guss_i][change_i] = tmp_guss[change_i];
            }
          }
          else
          {
            GUARD(xor_64(equations_guss_byte[guss_i], equations_guss_byte[guss_i],
                         equations_guss_byte[guss_j], guss_j_num));
          }
        }
      }
      for(uint16_t guss_i = 0; guss_i < guss_j; guss_i++)
      {
        if((mask_guss & equations_guss_byte[guss_i][eq_j]) != 0)
        {
          GUARD(xor_64(equations_guss_byte[guss_i], equations_guss_byte[guss_i],
                       equations_guss_byte[guss_j], guss_j_num));
        }
      }
    }

R_BIT = 10163, x_weight = 9000, GUSS_BLOCK = 64, guss_j_num = x_weight / GUSS_BLOCK + 1; equations_guss_byte is a two-dimensional array of uint64, where x_weight / GUSS_BLOCK column stores the matrix A and the latter column stores the vector B, xor_64() is used to XOR two arrays, GUARD() is used to check the correctness of function operation.

Using this method takes about 8 seconds to run on my machine. Is there a better way to speed up the calculation?

Abraham
  • 29
  • 6
  • Could you elaborate on "may be sparse"? How sparse? (Also, `uint16_t` is probably not helping the cause on contemporary hardware. I'd use `uint32_t` instead.) – David Eisenstat Dec 07 '22 at 13:39
  • It can be determined that each column of matrix `A` has 71 variables, and the matrix contains a total of `9000 * 71` variables. – Abraham Dec 07 '22 at 13:58
  • Does A have any other special structure? – David Eisenstat Dec 07 '22 at 22:00
  • There seems to be no other sparse structure, the equation is almost random. I'm wondering if I can make the solution faster without using Gaussian elimination. – Abraham Dec 08 '22 at 01:15
  • In theory you could do sparse GE, but it depends on how bad the fill would get (which depends on the matrix structure; if it's an expander, then no, but if there's more locality, then maybe). Vector extensions would be a safe bet, but not standard C. – David Eisenstat Dec 08 '22 at 02:10
  • Do you have any relevant article references for the sparse Gaussian elimination you mentioned? Thanks a lot if you can provide it to me. My matrix `A` seems to be uniformly distributed and it is difficult to find some local features. Vector extensions can indeed do it, but I need to optimize it on standard `C`, which may require a more suitable algorithm. – Abraham Dec 08 '22 at 02:47
  • http://i.stanford.edu/pub/cstr/reports/na/m/80/06/NA-M-80-06.pdf, but it looks like it's going to fill too much to be profitable. – David Eisenstat Dec 08 '22 at 13:42

0 Answers0