On Thu, Sep 27, 2012 at 7:14 PM, Aaron Meurer <[email protected]> wrote:
> Yes, use expand=False:
>
> Poly((x + y)*z, t, domain='EX', expand=False)
>
> Note that the generators must already be expanded out for this to work.
>
> This is also recommended anyway if you already know ahead of time that
> the generators are expanded out, because it will be much faster.  But
> also keep in mind that Poly won't notice if you have x*z + y*z in
> another place that it is the same as (x + y)*z.

I guess I need a more complicated example then.  What I actually want
to do is something like

    x,y,z = symbols('x y z')
    a,b,c = symbols('a b c')
    xs = x+a
    ys = y+b
    zs = z+c
    p = (xs + ys) * zs

then expand p as a polynomial in a,b,c without losing the structure of
each coefficient.  For example, the constant term should be (x + y)*z.
 As you say, a simple case of this fails:

>>> Poly((x + y + t)*z, t, domain='EX', expand=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/sympy/polys/polytools.py",
line 98, in __new__
    return cls._from_expr(rep, opt)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/sympy/polys/polytools.py",
line 208, in _from_expr
    rep, opt = _dict_from_expr(rep, opt)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/sympy/polys/polyutils.py",
line 292, in _dict_from_expr
    rep, gens = _dict_from_expr_if_gens(expr, opt)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/sympy/polys/polyutils.py",
line 250, in _dict_from_expr_if_gens
    (poly,), gens = _parallel_dict_from_expr_if_gens((expr,), opt)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/sympy/polys/polyutils.py",
line 160, in _parallel_dict_from_expr_if_gens
    raise PolynomialError("%s contains an element of the generators
set" % factor)
sympy.polys.polyerrors.PolynomialError: t + x + y contains an element
of the generators set

Thanks,
Geoffrey

-- 
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.

Reply via email to