While trying to implement an algorithm, I have come across a strange trick of numbers. I am not really into mathematics so I apologize if this will be a dumb question for some of you.
I am doing addition over arrays of numbers. Here is a picture:
Basically, you have three arrays $r_1$, $r_2$, $r_3$, each containing further arrays (like rows of a matrix). Say you want to do $r_1 + r_2$, you simply:
take the first sub-array in $r_1$
do an element-wise addition of this sub-array with all the sub-arrays in $r_2$
take the second sub-array of $r_1$
do an element-wise addition of this sub-array with all the sub-arrays in $r_2$
- take third sub-array of $r_1$
- and so on... until there are no more sub-arrays of $r_1$ left to add
Now, you can see from the picture that, by changing the order of addition, the result is not the same, while it should be the same! I have double checked the calculations but I don't see any error. Also, by using letters instead of numbers I get in fact that the result should not change, as in this picture:
Can somebody point me out what exactly am I doing wrong? Thanks.

