For now you can use the following code:
In [1]: var('a0 a1 a2 a3 a12 a23 a31 a123')
Out[1]: (a₀, a₁, a₂, a₃, a₁₂, a₂₃, a₃₁, a₁₂₃)
In [2]: f = a0+a1*x+a2*y+a3*z+a12*x*y+a23*y*z+a31*z*x+a123*x*y*z
In [3]: p = Poly(f, x, y, z)
In [4]: from __builtin__ import sum
In [5]: q = Poly([ (C, M) for C, M in p.iter_terms() if sum(M) <= 1 ],
*p.symbols)
In [6]: q
Out[6]: Poly((a1, a2, a3, a0), ((1, 0, 0), (0, 1, 0), (0, 0, 1), (0,
0, 0)), (x, y, z), 'grlex')
In [7]: q.as_basic()
Out[7]: a₀ + a₁*x + a₂*y + a₃*z
Note that line [4] is important because sympy's sum() overrides
improperly the built-in sum().
I think Poly class should have this functionality so I will provide a
patch fixing this issue.
Mateusz
2008/6/17 Alan Bromborsky <[EMAIL PROTECTED]>:
>
> If I have a polynomial, for example in three variables such as x, y, and
> z. How do I generate a polynomial that is a select subset of the powers
> of x, y, and z in the original polynomial? For example if x, y, and z
> are small compared to one I would like a polynomial that only consists
> of the zero and first order terms of x, y, and z of the original polynomial.
>
> f(x,y,z) = a0+a1*x+a2*y+a3*z+a12*x*y+a23*y*z+a31*z*x+a123*x*y*z
>
> return
>
> g(x,y,z) = a0+a1*x+a2*y+a3*z
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---