Skip to content

gives incorrect results (Int64 overflow) or errors (for BigInt) #4

@lampretl

Description

@lampretl

The following code

using IntegerSmithNormalForm
X = BigInt[  3   2  -4   0  -2   6  -5  -3   6   9;
            -7   5  -7   7  -9   8   9   4   1   5;
             5  -3  -6  -1   0   1   4   3  -4   9;
            -6   9   8   2   8   8  -8   4  -3   5;
            -8   8   9   4   6  -4   5   1  -1   5;
             1  -2   4  -6   6  -8   1   2   5   2;
            -5  -6  -5   2  -9   7  -7  -6   3   2;
             2   0  -9   0   8   1   7  -1  -9  -3;
            -2  -1   9  -3  -8  -4  -8   4  -5   0;
            -5  -5  -1   9  -4  -8  -1  -9   1   0 ];   
P,D,Q = snf(Int64.(X));   println(D==P*Int64.(X)*Q, " ", big.(D)==big.(P)*X*big.(Q))

shows that the results are correct in Int64 arithmetic with overflows, but incorrect in the exact BigInt arithmetic. Running the command with exact integers gives an error:

P,D,Q = snf(X);   println(D==P*X*Q)
ERROR: MethodError: no method matching addRow(::LinearAlgebra.Adjoint{BigInt, Matrix{BigInt}}, ::Int64, ::Int64, ::Int64)
The function `addRow` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  addRow(::AbstractMatrix{E}, ::Any, ::Any, ::E) where E
   @ IntegerSmithNormalForm ~/.julia/packages/IntegerSmithNormalForm/6WZhT/src/IntegerSmithNormalForm.jl:67

Stacktrace:
 [1] snf!(A::Matrix{BigInt})
   @ IntegerSmithNormalForm ~/.julia/packages/IntegerSmithNormalForm/6WZhT/src/IntegerSmithNormalForm.jl:197
 [2] snf(A::Matrix{BigInt})
   @ IntegerSmithNormalForm ~/.julia/packages/IntegerSmithNormalForm/6WZhT/src/IntegerSmithNormalForm.jl:238
 [3] top-level scope
   @ REPL[5]:1

In SNF, the matrix entries typically become enormous during the computation. Without support for BigInt, the results are useless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions