# Sum of XOR Matrix [closed]

I was wondering if there is a formula to find the sum of all the items in a matrix. The value at each index is (column $XOR$ row). For example, a matrix with 5 rows and 8 columns would be

0 1 2 3 4 5 6 7
1 0 3 2 5 4 7 6
2 3 0 1 6 7 4 5
3 2 1 0 7 6 5 4
4 5 6 7 0 1 2 3


I also need to take away a fixed amount from each of the items in the matrix (keeping each item 0 or above). Making the grid I need to find the sum of:

0 0 1 2 3 4 5 6
0 0 2 1 4 3 6 5
1 2 0 0 5 6 3 4
2 1 0 0 6 5 4 3
3 4 5 6 0 0 1 2

• Every row is a permutation of the numbers $0$ through $7$, which sum to $28$, so with $5$ rows that's $140$ total. (Btw. a row is left to right, a column top to bottom .. so what you showed has 5 rows and 8 columns) ... Now, can you elaborate on what you need to do with that matrix? Commented Dec 18, 2017 at 20:11
• Sum all the values in the matrix (after subtracting 1 (or any number) from each item in the matrix.) With this example, the sum should be 105, however I have a matrix with $28827050410$ columns and $35165045587$ rows and going through each item would take a long time! Commented Dec 18, 2017 at 20:19
• You mean $100$ in your example, right? Since there are $40$ entries ... Oh, I see, you don;t subtract the $1$ from $0$, is that it? OK, but with that huge matrix: do you know anything about that matrix? That is, are the rows nice permutations of certain numbers as in your example? Or are the entries just totally random numbers? Commented Dec 18, 2017 at 20:20
• Yeah, if you take 1 and it is less than 0 you set the value to 0. Commented Dec 18, 2017 at 20:23
• Where's your own workings on the problem? You've not even provided sufficient information in your post to be answerable. Commented Dec 18, 2017 at 20:24

So ... you have rows numbered $0$ through $35165045587-1=35165045586$, and columns numbered $0$ through $28827050410-1=28827050409$, and the entry at $(x,y)$ is defined as $x \ XOR \ y$ with the $XOR$ defined as an operator on the two numbers written as binary strings.
OK, well, then since you have fewer rows than columns, each column will contain some permutation of the numbers $0$ through $35165045586$ (I'll leave that to you to rigorously prove, but think about how the XOR operation works) meaning that the numbers in each column add up to $$\frac{35165045586\cdot 35165045587}{2}$$ and thus the sum of all entries in the matrix equals:
$$\frac{28827050410\cdot 35165045586\cdot 35165045587}{2}$$
Now, can you figure out how this sum changes when you subtract $k$ from each entry, making it $0$ when it threatens to go below $0$? You saw how it works for $k=1$ ... so now consider what happens when $k=2$ ... and at that point you should see the pattern and should be able to put that in a formula.