Inconsistent results of 'coeff'?

24 views
Skip to first unread message

Francesc Ferrer

unread,
Aug 6, 2014, 4:24:57 PM8/6/14
to sy...@googlegroups.com
Hello,

Repeated calls to 'coeff' give inconsistent results:

import sympy

x, y, a, b = sympy.symbols( 'x y a b')

f = a*x**2*y**2 + b*x*y**2

Then, the commands 'f.coeff(x,2).coeff(y,2)' and 'f.coeff(y,2).coeff(x,2)' both give 'a', which is correct.

The command f.coeff(y,0).coeff(x,2) gives 0 as expected.

However, f.coeff(x,2).coeff(y,0) gives 'a', which is wrong!

Is this a bug, or am I missing something obvious?

-Francesc




Ondřej Čertík

unread,
Aug 7, 2014, 3:28:49 PM8/7/14
to sympy
Hi Francesc,
Which sympy version are you using? I just tried a recent git version
(49bf47d24e3bcbe3e7d16e6bf08216ab1976f410) and I can't reproduce the
behavior
you described:

In [1]: var("x y a b")
Out[1]: (x, y, a, b)

In [2]: f = a*x**2*y**2 + b*x*y**2

In [3]: f
Out[3]:
2 2 2
a⋅x ⋅y + b⋅x⋅y

In [4]: f.coeff(x, 2)
Out[4]:
2
a⋅y

In [5]: f.coeff(x, 2).coeff(y, 2)
Out[5]: a

In [6]: f.coeff(x, 2).coeff(y, 0)
Out[6]: 0

Ondrej

>
> -Francesc
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/1462c15f-0e97-43ee-9685-091342b0b0bf%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Francesc Ferrer

unread,
Aug 7, 2014, 5:10:48 PM8/7/14
to sy...@googlegroups.com
Hi Ondrej,

I am using the Debian package version 0.7.5-2.

Francesc
Reply all
Reply to author
Forward
0 new messages