1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ There is no Modulus[] function in Mathematica... $\endgroup$ – J. M. will be back soon Nov 4 '12 at 21:55
  • $\begingroup$ Sorry for my mistake. I intended to mean Mod[... , 2]. $\endgroup$ – Pavithran Iyer Nov 5 '12 at 4:03
9
$\begingroup$
addmod = Mod[Plus[##],2]&

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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