Minimal polynomial of a sparse matrix.
#include <iostream>
template <class Field, class Polynomial>
{
for (int i = (int)v.size () ; i-- ; ) {
F.write (std::cout, v[(size_t)i]);
if (i > 0)
std::cout << " x^" << i << " + ";
}
std::cout << std::endl;
}
#include <linbox/blackbox/compose.h>
#include <linbox/solutions/minpoly.h>
int main (int argc, char **argv)
{
commentator().
setMaxDetailLevel (-1);
commentator().
setMaxDepth (-1);
commentator().
setReportStream (std::cerr);
int a = argc;
while(a--){
cerr << "argv[" << a << "] = " << argv[a] << endl;
}
if (argc < 2) {
cerr << "Usage: minpoly <matrix-file-in-SMS-format> [<p>]" << endl;
return -1;
}
ifstream input (argv[1]);
if (!input) { cerr << "Error opening matrix file " << argv[1] << endl; return -1; }
if (argc != 3) {
int process = 0;
Method::Blackbox M;
#ifdef __LINBOX_HAVE_MPI
Communicator C(&argc, &argv);
process = C.rank();
M.communicatorp(&C);
#endif
Givaro::ZRing<Integer> ZZ;
typedef SparseMatrix<Givaro::ZRing<Integer>> SpMat;
SpMat B (ZZ);
B.read (input);
BB2 BT(B);
if(process == 0)
cout <<
"A is " << A.
rowdim() <<
" by " << A.
coldim() << endl;
minpoly (m_A, A, M);
if(process == 0){
cout << "Minimal Polynomial is ";
}
}
else{
typedef Givaro::Modular<double> Field;
double q = atof(argv[2]);
Field F(q);
SparseMatrix<Field> B (F);
B.read (input);
cout << "B is " << B.rowdim() << " by " << B.coldim() << endl;
minpoly (m_B, B);
cout << "Minimal Polynomial is ";
}
return 0;
}