Determinant of sparse matrix over Z or Zp.
#include <iostream>
int main (int argc, char **argv)
{
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
if (argc <= 1 || argc > 3) {
cerr << "Usage: det <matrix-file-in-supported-format> [<p>]" << endl;
return -1;
}
if (argc == 2 ) {
typedef Givaro::ZRing<Integer> Integers;
Integers ZZ;
ifstream input (argv[1]);
if (!input)
{ cerr << "Error opening matrix file " << argv[1] << endl;
return -1;
}
cout <<
"Matrix is " << A.
rowdim() <<
" by " << A.
coldim() << endl;
Integers::Element det_A;
cout << "Determinant is ";
ZZ.write(cout, det_A) << endl;
}
if (argc == 3) {
typedef Givaro::Modular<double> Field;
double q = atof(argv[2]);
Field F(q);
ifstream input (argv[1]);
if (!input)
{ cerr << "Error opening matrix file " << argv[1] << endl;
return -1;
}
SparseMatrix<Field> B (F); B.read(input);
cout << "Matrix is " << B.rowdim() << " by " << B.coldim() << endl;
Field::Element det_B;
cout << "Determinant is ";
F.write(cout, det_B) << " mod " << q << endl;
}
return 0;
}