Ramón Casero Cañas on Sat, 11 Jan 2003 02:39:08 +0100 (MET)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

the problem of inversing a big boolean matrix


Karim BELABAS wrote:

>
>Use ginv().
>
>Cheers,
>
>    Karim.
>
>P.S: In recent development versions (2.2.4 onward, or so), you can also use
>
>  GEN u_FpM_inv(GEN x, ulong p)
>

Thank you, Karim. Ok, I began to code using your advice. But then it occured
to me that maybe it would fail anyway. This is what I mean:

Let A be an invertible matrix  A = ((ai)), where ai is in {0, 1}. I would
like to invert this matrix. Let say I'm using octave (or matlab). I would do
this:

* input the binary data to the matrix A
* B = inv(A)   -> this gives typically floats < 1.0
* C = B * det(A) -> the det(A) is typically a very big number
* D = round(C)
* E = rem(abs(D), 2)  ->  the modulo 2 wanted solution

This works well with small matrices, but as soon as you go to a relatively
big matrix (only 64 x 64!), you lose precission in the internal data
representation. This means that units are truncated, so then, when you get E, elements
have random values. You can test this with   A * E, it doesn't give the
identity matrix.

This is how I came to PARI. As I saw that PARI has a type that implement
moduloN numbers, I thought that maybe the inversion function worked not like in
the above example. So what I just tried was this: At the very bottom of this
message there's a 32 x 32 matrix, with a format that makes it easy to cut and
paste into GP's command line.

* Now we have an A matrix
* We create a 64x64 matrix with A64 = [mattranspose(A), A; A,A] 
  (if you make A64 = [A, A; A, A] you get a non-invertible matrix)
* We go for the modulo 2 type       A2 = Mod(A64, 2)
* We invert the matrix                  E = A2 ^ (-1)

But again, if we test A2 * E, we don't get the identity matrix.

I would appreciate any comment on what I'm doing wrong, or maybe this is
just a problem without solution, or a problem with such an easy solution that
everybody knows it.

Cheers,

Ramón.

-------------------

{
A =
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1,
0, 0, 0, 1, 0, 0, 1;
1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0,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