Developer documentation

polynomial_mv_sparse_test.cpp
# include <sstream>
# include <iomanip>
# include <realroot/GMP.hpp>
int main(int argc, char** argv)
{
using namespace mmx;
typedef Poly_t::Monomial Monomial_t;
//Poly( C, d, i) means C * x_i^d
Poly_t f = Poly_t( 1,0,0) + Poly_t( -1,1,1) + Poly_t(1,1,2);
// + Poly_t(1,1,3);
std::cout << "f : " << f << std::endl;
//std::cout << "f^2 : " << (f*f) << std::endl;
//return 0;
Poly_t g; //=f^2;
Poly_t h; mul(h.rep(),f.rep(),f.rep());
std::cout << "f^2 : ";
print(std::cout, h.rep());
std::cout << std::endl;
int dg = degree( h);
int nbvars = h.nbvar();
std::cout << "dg: " << dg << std::endl;
std::cout << "#vars: " << nbvars << std::endl;
Poly_t k = Poly_t( "x^2+0.00000001*x+100.000000001" );
std::ostringstream os; os <<std::fixed<< std::setprecision(16)<< k;
std::cout << "k : " << os.str() << std::endl;
std::cout << "\nk : " << Poly_t(os.str().data()) << std::endl;
for ( Poly_t::iterator it = g.begin(); it != g.end(); ++it) {
it->set_coeff( 1);
seq << *it;
// std::cout << "it: " << *it << std::endl;
}
Polynomial P("x^2*y+y^2-1"), Q("x-1");
std::cout<<P<<" "<<Q<<std::endl;
std::cout<<"P/Q: "<<P/Q<<std::endl;
std::cout<<"P%Q: "<<P%Q<<std::endl;
std::cout<<"(P*P)/P: "<<(P*P)/P<<std::endl;
// std::cout << "seq: " << seq << std::endl;
// std::cout << "g[2]: " << g[1] << std::endl;
std::cout << "g: " << g << std::endl;
std::cout << "h: " << h << std::endl;
h=0; std::cout << "h: " << h << std::endl;
dg = degree( h);
nbvars = h.nbvar() ;
std::cout << "dg: " << dg << std::endl;
std::cout << "#vars: " << nbvars << std::endl;
//int dg_fact;
double dg_fact = factorial<double>(dg);
for (unsigned i = 0; i < seq.size(); ++i) {
for (unsigned j = 0; j < seq.size(); ++j) {
Monomial_t tmon = seq[i] * seq[j];
for ( Poly_t::iterator it = h.begin(); it != h.end(); ++it) {
if( IsComparable( *it, tmon) ) {
double c = dg_fact;
if( tmon.size() > 0) {
for (int k = 1; k <= nbvars; ++k) {
int t = ((unsigned) k < tmon.size()? tmon[k] : 0);
c = c / factorial<double>(t);
}
c = c / factorial<double>( dg - degree( tmon));
std::cout << "t: " << tmon << " "
<< c << " "
<< it->coeff() << " "
<< ( it->coeff() / c) << " "
<< std::endl;
}
}
}
}
}
return 0;
// q=p*p; std::cout<<q<<std::endl;
}
Home