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.

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

1 Answer 1

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

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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