4
$\begingroup$

I have two matrices $A$ and $B$ which I multiply to give

$$\begin{bmatrix} 2 \\ 2 \\ 2 \end{bmatrix}$$

How do I multiply these matrices Modulo 2? I would like to end up with an all zero column vector.

$\endgroup$
2
  • 2
    $\begingroup$ Mod[{2, 2, 2}, 2] ? $\endgroup$ Aug 9, 2023 at 11:08
  • 1
    $\begingroup$ Why not Mod[A.B, 2]? $\endgroup$
    – Michael E2
    Aug 10, 2023 at 0:40

1 Answer 1

6
$\begingroup$

I assume that by multiplication you mean the dot product. The following should work:

Inner[Mod[Times[##], 2] &, A, B, Mod[Plus[##], 2] &]

Or, as a function:

DotModulo[a_, b_, mod_] := Inner[Mod[Times[##], mod] &, a, b, Mod[Plus[##], mod] &]

DotModulo[A, B, 2]
$\endgroup$
2
  • 2
    $\begingroup$ I do not think your algorithm achieves the theoretical $\mathcal{O}(n^2)$ scaling. $\endgroup$
    – yarchik
    Aug 9, 2023 at 22:52
  • 2
    $\begingroup$ No, you'd need a dedicated, low-level implementation for that. But I doubt that really matters for most users. $\endgroup$ Aug 10, 2023 at 8:04

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.