Here is the code:
long long mul(long long x)
{
uint64_t M[64] = INIT;
uint64_t result = 0;
for ( int i = 0; i < 64; i++ )
{
uint64_t a = x & M[i];
uint64_t b = 0;
while ( a ){
b ^= a & 1;;
a >>= 1;
}
result |= b << (63 - i);
}
return result;
}
This code implements multiplication of the matrix and vector on GF(2). The code that returns result as the product of 64x64 matrix M and 1x64 vector x.
I want to know what linear algebraic operation( on GF(2) ) this code is:
long long unknown(long long x)
{
uint64_t A[] = INIT;
uint64_t a = 0, b = 0;
for( i = 1; i <= 64; i++ ){
for( j = i; j <= 64; j++ ){
if( ((x >> (64-i)) & 1) && ((x >> (64-j)) & 1) )
a ^= A[b];
b++;
}
}
return a;
}
Of course you mean GF(2)64, the field of 64-dimensional vectors over GF(2).
Consider first the loop structure:
That's looking at every distinct pair of indices (the indices themselves not necessarily distinct from each other). That should provide a first clue. We then see
, which is testing whether vector
xhas both bitiand bitjset. If it does, then we add a row of matrixAinto accumulation variablea, by vector sum (== element-wise exclusive or). By incrementingbon every inner-loop iteration, we ensure that each iteration services a different row ofA. And that also tells us thatAmust have 64 * 65 / 2 = 160 rows (that matter).In general, this is not a linear operation at all. The criterion for an operation
oon a vector field over GF(2) to be linear boils down to this expression holding for all pairs of vectorsxandy:Now, for notational convenience, let's consider the field GF(2)2 instead of GF(2)64; the result can be extended from the former to the latter simply by adding zeroes. Let
xbe the bit vector (1, 0) (represented, for example, by the integer 2). Letybe the bit vector (0, 1) (represented by the integer 1). And letAbe this matrix:Your operation has the following among its results:
Clearly, it is not the case that
o(x) + o(y) = o(x + y)for thisx,y, and characteristicA, so the operation is not linear for thisA.There are matrices
Afor which the corresponding operation is linear, but what linear operation they represent will depend onA. For example, it is possible to represent a wide variety of matrix-vector multiplications this way. It's not clear to me whether linear operations other than matrix-vector multiplications can be represented in this form, but I'm inclined to think not.