Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect output #33

Open
SiggyLaewsky opened this issue Feb 17, 2023 · 1 comment
Open

Incorrect output #33

SiggyLaewsky opened this issue Feb 17, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@SiggyLaewsky
Copy link

All functions sometimes return a wrong answer even for small-size matrices with small values. For instance:

For matrix

[[ 1 -10 0 4 2 -3 6]
[ -6 -8 -3 -2 7 0 -8]
[ -8 0 0 -4 8 10 -5]
[ 8 -3 3 9 9 10 6]
[ -5 -3 -9 10 -4 7 9]
[ -4 -9 -9 -5 2 0 1]
[ 4 2 -5 1 7 -10 -1]]

function column_style_hermite_normal_form provides output

[[-346925671050097202 -252755 -466370
-630998 -478778 -600398
-659835]
[ 835296760844636953 608561 1122884
1519261 1152759 1445585
1588692]
[-479143188193987710 -349083 -644109
-871479 -661246 -829217
-911306]
[ 191046112789960095 139188 256822
347480 263655 330629
363360]
[1118641869143326448 814994 1503783
2034617 1543792 1935949
2127600]
[-828222439379453903 -603407 -1113374
-1506394 -1142996 -1433342
-1575237]
[ 535626295318601958 390234 720039
974212 739196 926968
1018734]],

[[ 1 0 0 0 0 0 0]
[ 0 1 0 0 0 0 0]
[ 0 0 1 0 0 0 0]
[ 0 0 0 1 0 0 0]
[ 0 0 0 0 1 0 0]
[ 0 0 0 0 0 1 0]
[18454335 13439499 24797837 33551452 25457599 31924387 35084770]]

however, direct multiplication with calculator shows, that element (6, 6) of the HNF in this case would be 18446744073728005951 instead of 18454335 (i.e. the answer has even a self-contradiction). Numpy multiplication doesn't work normally in this case due to int overflow; seems, an implementation has the same problem.

To compare, the correct answer is

1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
20000231 13439499 24797837 33551452 25457599 31924387 35084770.

--
All the best,
Siggy Laewsky

@lan496
Copy link
Owner

lan496 commented Feb 19, 2023

@SiggyLaewsky Thank you for reporting the example to cause an overflow in calculating HNF.
In fact, the current algorithm for HNF and SNF will fail due to overflow in matrix multiplications. A possible solution is to use modular arithmetic, but I am not fully understand the modular-arithmetic algorithm to compute HNF and SNF so far...

@lan496 lan496 added the bug Something isn't working label Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants