On Tue, Nov 27, 2012 at 8:48 PM, ThanhVu Nguyen
<
nguyent...@gmail.com> wrote:
> Hi, I came from the Sage (sagemath) background and am trying to use Sympy
> for my new project instead.
>
> I am wondering how to obtain the coefs and terms of a given expression in
> sympy. For example, given the expression a**2+b+5*c+2, I want to get the
> coefs [1,1,5,2] and the terms [a^2,b,c,1].
If you are just working with polynomials, the easiest way is to use
the Poly class, and use the all_coeffs method. I forget what the best
way otherwise is. You can use .coeff, but it doesn't generalize to
getting the constant term from more than one variable. as_independent
does it, but that only works correctly if the expression is an Add.
>
> Also, does Sympy has an equivalence to the class "Expression" of Sage ?
> By expression I mean symbols x,y,z, .. and operations over symbols x > y , x
> + 5 . Sympy seems to treat these separately, e.g. x,y,z are Symbols, x
> + 5 is Add, x > y is StrictGreaterThan. Perhaps all of these seperate
> classes inherit a common class ?
Yes, Expr is the superclass of all of these. And Basic is the
superclass of Expr. There are some classes that are Basic but not
Expr, which are classes that aren't symbolic expressions. Actually,
StrictInequality should be one of these, but it isn't.
Aaron Meurer
>
> Thanks,
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/sympy/-/5f-YQchcnjwJ.
> To post to this group, send email to
sy...@googlegroups.com.
> To unsubscribe from this group, send email to
>
sympy+un...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/sympy?hl=en.