On Tue, Jan 30, 2007 at 04:43:33PM -0300, Charlls Quarra wrote:
The other problem i had with this program is that there wasnt a builtin way to get coefficients from multivariate polynomials [snipped]
I use this function to convert a polynomial into an exmap (std::map<ex, ex, ex_is_less>): exmap vargs_collect(const ex& e, const lst& l) { ex x = e.expand(); exmap cmap; cmap[_ex1] = _ex0; for (const_iterator xi=x.begin(); xi!=x.end(); ++xi) { ex key = _ex1; ex pre_coeff = *xi; for (lst::const_iterator li=l.begin(); li!=l.end(); ++li) { int cexp = pre_coeff.degree(*li); pre_coeff = pre_coeff.coeff(*li, cexp); key *= pow(*li, cexp); } exmap::iterator ci = cmap.find(key); if (ci != cmap.end()) ci->second += pre_coeff; else cmap.insert(exmap::value_type(key, pre_coeff)); } return cmap; } After such a conversion getting coefficients is trivial: ex test = pow(x+y+z, 10); exmap tm = vargs_collect(test, lst(x, y)); cout << tm[pow(x,7)*y] << endl; // 360*z^2 Best regards, Alexei -- All science is either physics or stamp collecting.