coeffs cannot handle a general function

16 views
Skip to first unread message

Yi Wang

unread,
Jan 3, 2012, 10:48:31 AM1/3/12
to sage-s...@googlegroups.com
Hi,

I found coeffs does not work with a general function. It would be of
great help for me to have it fixed. Thank you!

I tested 4.7.0, 4.7.2 and 4.8.0alpha5. None of them work, though 4.7.0
gives slightly different result:

# the following is result of 4.7.2 and 4.8alpha5.
sage: g = function('g', var('t'))
sage: f = 3*g + g**2 + t
sage: f.coeff(g)
3
sage: f.coeffs(g)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

/home/wangyi/<ipython console> in <module>()

/opt/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so
in sage.symbolic.expression.Expression.coefficients
(sage/symbolic/expression.cpp:19003)()

/opt/sage/local/lib/python2.6/site-packages/sage/symbolic/ring.so in
sage.symbolic.ring.SymbolicRing.var (sage/symbolic/ring.cpp:6342)()

/opt/sage/local/lib/python2.6/site-packages/sage/symbolic/ring.so in
sage.symbolic.ring.SymbolicRing.var (sage/symbolic/ring.cpp:6069)()

ValueError: The name "g(t)" is not a valid Python identifier.


# the following is the result of 4.7.0
sage: f.coeffs(g)
[[g(t)^2 + t + 3*g(t), 0]]

Michael Orlitzky

unread,
Jan 3, 2012, 11:23:18 AM1/3/12
to sage-s...@googlegroups.com
On 01/03/2012 10:48 AM, Yi Wang wrote:
> Hi,
>
> I found coeffs does not work with a general function. It would be of
> great help for me to have it fixed. Thank you!

I created a ticket for this,

http://trac.sagemath.org/sage_trac/ticket/12255

You should be able to CC yourself and be notified of any progress.

Yi Wang

unread,
Jan 3, 2012, 12:16:37 PM1/3/12
to sage-support, Yi Wang
Thanks a lot for creating the ticket!

But in 4.7.0 coeffs doesn't work either. Because

sage: f.coeffs(g)
[[g(t)^2 + t + 3*g(t), 0]]

is a wrong result for f = 3*g + g**2 + t. I expect a result [[t, 0],
[3, 1], [1, 2]].

It would be very kind of you to update the ticket about it. I am new
here and I am not sure whether I can edit the ticket myself. Thank you
again!

Michael Orlitzky

unread,
Jan 3, 2012, 12:26:55 PM1/3/12
to sage-s...@googlegroups.com
On 01/03/2012 12:16 PM, Yi Wang wrote:
> Thanks a lot for creating the ticket!
>
> But in 4.7.0 coeffs doesn't work either. Because
>
> sage: f.coeffs(g)
> [[g(t)^2 + t + 3*g(t), 0]]
>
> is a wrong result for f = 3*g + g**2 + t. I expect a result [[t, 0],
> [3, 1], [1, 2]].
>
> It would be very kind of you to update the ticket about it. I am new
> here and I am not sure whether I can edit the ticket myself. Thank you
> again!

Oh, sorry, I didn't look very hard at the output, just that it didn't
throw an error.

I've updated the ticket.

If you're interested, anyone can request an account (instructions are on
the trac homepage[1]) and that would allow you to create/modify tickets.


[1] http://trac.sagemath.org/sage_trac/

Reply all
Reply to author
Forward
0 new messages