On Mon, Oct 4, 2010 at 5:40 PM, Scott <spectre...@gmail.com> wrote:
> Hello.  I some very large polynomials.  Some coefficients are very
> small (E-16) and I'd like to get rid of these terms.  I found a
> previous method with a solution posted here:
> <http://groups.google.com/group/sympy/browse_thread/thread/
> e244e9d9431f3acd/add6f883e7419b27?lnk=gst&q=close+to
> +zero#add6f883e7419b27>
> def chop(expr, tol=1e-6):
>    return Add(term for term in expr.as_Add() if term.as_coeff_terms()
> [0] >= tol)
>
> However, when I try this method, it doesn't seem to work.  I have the
> latest sympy (0.6.7).  The error demonstrated below is the same as the
> one I get using that chop function.  I'm running this on Windows, but
> could try it on Linux of it would make a difference (though ultimately
> I need a method that works on both).
>
>>>> type(x+y)
> <class 'sympy.core.add.Add'>
>>>> (x+y).as_Add()
> Traceback (most recent call last):
>  File "(stdin)", line 1, in <module>
> AttributeError: 'Add' object has no attribute 'as_Add'

Since you have a large polynomial, you can do something like this:

def chop(expr, tol=1e-6):
    if isinstance(expr, Add)
        return Add(term for term in expr.args if
term.as_coeff_terms()[0] >= tol)
    else:
        raise NotImplementedError()


Ondrej

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to