[GiNaC-list] how to drop terms in expression with small coefficients?
alexei.sheplyakov at gmail.com
Tue Sep 6 08:33:07 CEST 2011
On Sat, Sep 03, 2011 at 10:22:18PM +1000, Tomasz Rudny wrote:
> I have the following problem - I have a polynomial P(x) and before I
> proceed with some calculations on it, I want to make sure it does
> not contain terms like for example:
> 10e-12 * x
> (in my case x is from (0, 1) so this is safe).
> I want to somehow get rid of such small terms.
> In another words for polynomial P(x) = 2.3 * x ^ 2 + 10e-12 * x + 3.76
> I want to obtain polynomial Q(x) = 2.3 * x ^ 2 + 3.76
using namespace GiNaC;
class drop_small_coeff : public map_function
const numeric small_val;
ex operator()(const ex& e)
numeric c = e.integer_content();
if (c < small_val)
drop_small_coeff(const numeric& small_val_) : small_val(small_val_)
int main(int argc, char** argv)
ex e = p(std::string("x^3 + 10*x^2 + 1/1000*x + 1/10"));
std::cout << e << " => " << d(e) << std::endl;
By the way, the documentation  contains a similar example (look for
More information about the GiNaC-list