I am interested in using LinearSolve[m,b]
which will find a solution to the equation $m.x=b$, where I am in mod 2 arithmetic. Is there any way to perform this computation in Mathematica ?
1 Answer
$\begingroup$
$\endgroup$
There is an option Modulus
in certain algebraic functions (Solve
, LinearSolve
, Det
,Factor
etc.) to specify that integers are to be treated modulo an integer n. Consider e.g.
m0 = {{4, 6, 6}, {6, 3, 2}, {1, 4, 4}};
b0 = {4, 2, 1};
then
LinearSolve[ m0, b0, Modulus -> 2]
{1, 0, 0}
You can work with LinearSolve
specifying only the first variable, then it generates a linear operator, e.g. let :
m1 = {{1, 0, 1, 5}, {0, 4, 6, 7}, {0, 2, 3, 1}, {1, 7, 0, 8}};
c1 = LinearSolve[m1, Modulus -> 2]
LinearSolveFunction[{4,4},<>]
c1
yields automatically solutions modulo 2
. It can be convenient to work with Manipulate
:
Manipulate[ c1[{a1, a2, a3, a4}],
{a1, -5, 5, 1}, {a2, -5, 5, 1}, {a3, -5, 5, 1}, {a4, -5, 5, 1}]
LinearSolve[]
takes aModulus
option, no? $\endgroup$LinearSolve[]
? $\endgroup$