0

I want to give the values for a matrix parameter mat_ZZ_p A for the mat_ZZ_p type in NTL. The dimension of my vector is big. So, I am looking at a big square matrix as parameter. So, I cannot assign the values manually. One advantage here to me is that the columns of my matrix are only rotations of the first column. It is of the form

    p_0      p_(n-1)  p_(n-2) .... p_1
    p_1      p_0      p_(n-1) .... p_2
     .
     .
    p_(n-1)  p_(n-2)  p_(n-3) .... p_0

and I have a variable p which is a vector with the values p_0, p_1, ...,p_(n-1). I have assigned the 1st column of the matrix using a loop through the vector p. but I am not sure how to do the rotation for the other columns. I tried to use that the values when viewed diagonally are the same but in that case, I am not sure how to bound the loop. I tried to use the fact that there is a diagonal downward shift of elements as we move from one column to another. But again in this case, I am not able to assign the value for the 1st row, 2nd column just by referring to the previous column. Is there a standard way to do such rotation of columns?

Since I am trying to solve the system of equations in Z_p, I think the comments in this post does not help me. Best way to solve a linear equation in code

Community
  • 1
  • 1
cryptomath
  • 11
  • 3

2 Answers2

1

If you refer to m[i][j] for the generic element of the matrix n x n then what you need is

m[i][j] = m[(i + n - 1) % n][j-1] for every j > 0

marom
  • 5,064
  • 10
  • 14
-1

For a square matrix with dimensions n * n, to refer to any element not in the first column or first row, use m[i - 1][j - 1], with i and j being the row and cols.

  • for `i = 0`, it will give segmentation fault. – uSeemSurprised Mar 14 '16 at 08:01
  • "to refer to any element not in the first column or first row". By first column and first row, I refer to the zeroth rows, not the actual index but the logical order. – hamzamuhammad Mar 14 '16 at 08:03
  • but we need to find the first elements of every column that is the last element of the previous column, a correct answer has been posted above that takes care of all cases. – uSeemSurprised Mar 14 '16 at 08:04
  • That's an easy corner case to fix, just another if statement. The other solution is correct, but inefficient. You're doing more calculation than you need to. Simply subtracting 1, and checking if the row is 0 to do a different (simple) subtraction is much better. You also won't run into any nasty overflow errors. – hamzamuhammad Mar 14 '16 at 08:14