Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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

Thanks very much.

share|improve this question
There is no Modulus[] function in Mathematica... – J. M. Nov 4 '12 at 21:55
Sorry for my mistake. I intended to mean Mod[... , 2]. – Pavithran Iyer Nov 5 '12 at 4:03
up vote 9 down vote accepted
addmod = Mod[Plus[##],2]&

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

share|improve this answer
thanks a lot, it works ! – Pavithran Iyer Nov 4 '12 at 21:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.