Hello,

thanks for your answers. I know, that this representation is for
internal use only. But the thing is, that I made many calculations (in
fact I add one monomial after the other) and at some point I got
exactly the polynomials written down and then the error occured. But
so, the problem is earlier and I will look, why it is sorted in that
way.

I am looking forward to using version 0.7.0.

Martin

On 14 Jan., 19:40, Mateusz Paprocki <[email protected]> wrote:
> Hi Martin,
>
>
>
> On Thu, Jan 14, 2010 at 02:44:06AM -0800, Martin Trinks wrote:
> > Hello,
>
> > I have to do some calculations with polynomials (in fact only
> > addition) and found the following problem:
>
> > import sympy as sy
> > >>> sy.__version__
> > '0.6.6'
> > >>> x, y, z = sy.symbols('xyz')
> > >>> Q = sy.Poly(((sy.S(1), sy.S(1), sy.S(1), sy.S(5), sy.S(6), sy.S(3), 
> > >>> sy.S(1)), ((2, 3, 1), (1, 4, 1), (2, 2, 2), (3, 1, 1), (2, 2, 1), (1, 
> > >>> 3, 1), (4, 0, 0))), x, y, z)
> > >>> Q
> > Poly(x**2*y**3*z + x*y**4*z + x**2*y**2*z**2 + 5*x**3*y*z +
> > 6*x**2*y**2*z + 3*x*y**3*z + x**4, x, y, z)
> > >>> S = sy.Poly(((sy.S(1),), ((2, 2, 2),)), x, y, z)
> > >>> S
> > Poly(x**2*y**2*z**2, x, y, z)
> > >>> P = Q + S
> > >>> P
> > Poly(x**2*y**2*z**2 + x**2*y**3*z + x*y**4*z + x**2*y**2*z**2 +
> > 5*x**3*y*z + 6*x**2*y**2*z + 3*x*y**3*z + x**4, x, y, z)
> > >>> P.as_basic()
> > x**2*y**2*z**2 + 6*z*x**2*y**2 + z*x**2*y**3 + 3*x*z*y**3 + 5*y*z*x**3
> > + x**4 + x*z*y**4
> > >>> P.subs({x:1, y:1, z:1})
> > 18
>
> > As you can see the problem is with the monomial x**2*y**2*z**2, which
> > appears two times in P.monoms. In the following further calculation
> > and also the output for P are not correct.
>
> the problem starts here:
>
> > ((2, 3, 1), (1, 4, 1), (2, 2, 2), (3, 1, 1), (2, 2, 1), (1, 3, 1), (4, 0, 
> > 0))
> >             ^^^^^^^^^^^^^^^^^^^^
>
> You construct a Poly instance using a representation that is reserved
> for internal use. When you do so you must provide the list with elements
> sorted appropriately, which is:
>
>  ((2, 3, 1), (2, 2, 2), (1, 4, 1), (3, 1, 1), (2, 2, 1), (1, 3, 1), (4, 0, 0))
>
> in this case. If you don't want to think about such details, use other
> representations (see help(Poly) or Poly? for details).
>
> In [1]: import sympy as sy
>
> In [2]: Q = sy.Poly(((sy.S(1), sy.S(1), sy.S(1), sy.S(5), sy.S(6),
> sy.S(3), sy.S(1)), ((2, 3, 1), (2, 2, 2), (1, 4, 1), (3, 1, 1), (2, 2,
> 1), (1, 3, 1), (4, 0, 0))), x, y, z)
>
> In [3]: S = sy.Poly(((sy.S(1),), ((2, 2, 2),)), x, y, z)
>
> In [4]: P = Q + S
>
> In [5]: P
> Out[5]: Poly(x**2*y**3*z + 2*x**2*y**2*z**2 + x*y**4*z + 5*x**3*y*z +
> 6*x**2*y**2*z + 3*x*y**3*z + x**4, x, y, z)
>
> In [6]: P.subs({x: 1, y: 1, z: 1})
> Out[6]: 19
>
> btw. In version 0.7.0 you will be only allowed to pass a dict or Basic
> expression to Poly class constructor.
>
> --
> Mateusz
>
>  signature.asc
> < 1 KBAnzeigenHerunterladen
-- 
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