0

When I gave insufficient size of matrices to matsolve(M, B) method, I took a segmentation fault instead of warning.

  *** matsolve: bug in PARI/GP (Segmentation Fault), please report.

With correct size of matrices, I got wrong result. Here is my test code:

{
w = ffgen(w^7 + w^2 + Mod(2,3)*w + Mod(1,3));

info = [
  2*w^6 + 2*w^5 + 2*w^4 + 2*w^3 + 2*w^2 + w, w^6 + w^5 + w^4 + 2*w^2 + 2;
  w^4 + w^3 + 2*w^2 + w + 1, w^6 + 2*w^5 + 2*w^4 + w^3 + 2*w^2;
  2*w^6 + w^5 + w^4 + w^3 + 2, 2*w^5 + 2*w^4 + 2*w^3 + 2*w + 2;
  w^5 + w^3 + 2*w^2 + w, w^6 + 2*w^5 + 2*w^4 + 2*w^3 + w^2 + 1;
  w^3 + w^2 + 2*w + 1, 2*w^6 + w^5 + 2*w^3 + w;
  2*w^6 + 2*w^5 + w^4 + 2*w^3 + 2*w + 2, w^6 + 2*w^4 + 2*w^2 + 1;
  w^6 + 2*w^5 + 2*w^4 + 2*w^3 + 2*w^2 + 2*w + 1, w^6 + 2*w^4 + 2*w^3 + w^2 + w + 1
];

result = [
  w^6 + 2*w^5 + w^3 + 2*w;
  2*w^6 + w^2 + w;
  w^4 + 2*w^2 + 2*w + 2;
  2*w^6 + 2*w^5 + w^4 + w^3 + 2*w^2;
  2*w^5 + w^4 + w;
  w^5 + 2*w^2 + w + 2;
  2*w^6 + w^5 + 2*w^4 + 2*w^3 + 2*w^2 + w
];

\\ lamda * info = result
lamda = matsolve(info, result);

calculated_result = mattranspose(mattranspose(lamda) *
                                 mattranspose(info));
}

And the output is:

? result
[                w^6 + 2*w^5 + w^3 + 2*w]
[                        2*w^6 + w^2 + w]
[                  w^4 + 2*w^2 + 2*w + 2]
[      2*w^6 + 2*w^5 + w^4 + w^3 + 2*w^2]
[                        2*w^5 + w^4 + w]
[                    w^5 + 2*w^2 + w + 2]
[2*w^6 + w^5 + 2*w^4 + 2*w^3 + 2*w^2 + w]

? calculated_result
[              w^6 + 2*w^5 + w^3 + 2*w]
[                      2*w^6 + w^2 + w]
[    2*w^5 + w^4 + w^3 + w^2 + 2*w + 2]
[w^6 + w^5 + 2*w^4 + 2*w^3 + 2*w^2 + w]
[      w^6 + w^4 + w^3 + w^2 + 2*w + 1]
[        2*w^4 + 2*w^3 + w^2 + 2*w + 1]
[                  2*w^4 + w^3 + w + 1]

Only the first two rows of results are same, rest of them are different. I guess, for given info(n x k) and result(k x 1) matrices, GP ignores the last (n - k) rows of the info matrix.

karakale
  • 126
  • 11

1 Answers1

1

Note, your system of the linear equations is inconsistent. There are no solutions. Just check the rank of the augmented matrix:

augmented = matconcat([info, result]);
matrank(info) == matrank(augmented)
> 0

Help message for matsolve says:

Let M be a left-invertible matrix and B a column vector such that there exists a solution X to the system of linear equations MX = B; return the (unique) solution X. <...> When there is no solution, the function returns an X such that MX - B is nonzero although it has at least #M zero entries <...>

So there is no bug for your example.

Piotr Semenov
  • 1,761
  • 16
  • 24