# Matrix Multiplication Modulo 2

I would like to perform matrix multiplication modulo 2. Hence, instead of the usual: A.B

I did:

Inner[#1*#2 &, A, B, Modulus[#1+#2,2]&]

However, it does not work, since #1+#2 (in the modulus) only adds the first two inputs, whereas, I want it to add all its inputs (like Plus does). I want to define a function that just adds up all its inputs, modulo 2 and it can take in variable number of inputs.

In otherwords, I want to define a addmod which takes in variable number of inputs and adds them (modulo 2):

addmod[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] = 1, addmod[0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0] = 1

and so on. Note, the input is not a list here. Hence I cannot say something like:

addmod[list]=Fold[Modulus[Plus[#1+#2,2],2]&,0,list]

I would be happy to get some help on this. Sorry, if i am missing out something basic.

Thanks very much.

• There is no Modulus[] function in Mathematica... Nov 4, 2012 at 21:55
• Sorry for my mistake. I intended to mean Mod[... , 2]. Nov 5, 2012 at 4:03

addmod = Mod[Plus[##],2]&

## is a Sequence of all the arguments given to addmod.