Minimal polynomial of a sparse matrix.
#include <iostream>
template <class Field, class Polynomial>
void printPolynomial (
const Field &F,
const Polynomial &v)
{
for (int i = (int)v.size () ; i-- ; ) {
F.write (std::cout, v[i]);
if (i > 0)
std::cout << " x^" << i << " + ";
}
std::cout << std::endl;
}
#include "linbox/blackbox/sparse.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;
#ifdef __LINBOX_HAVE_MPI
Communicator C(&argc, &argv);
process = C.rank();
M.communicatorp(&C);
#endif
if(process == 0)
cout <<
"A is " << A.
rowdim() <<
" by " << A.
coldim() << endl;
vector<PID_integer::Element> m_A;
minpoly (m_A, A, M);
if(process == 0){
cout << "Minimal Polynomial is ";
printPolynomial (ZZ, m_A);
}
}
else{
double q = atof(argv[2]);
Field F(q);
cout <<
"B is " << B.
rowdim() <<
" by " << B.
coldim() << endl;
vector<Field::Element> m_B;
minpoly (m_B, B);
cout << "Minimal Polynomial is ";
printPolynomial (F, m_B);
}
return 0;
}