Some symbolic functions return python ints

3 views
Skip to first unread message

Alastair Irving

unread,
Mar 21, 2011, 12:06:28 PM3/21/11
to sage-s...@googlegroups.com
HI All

I'm running Sage 4.6.2. I've just noticed that if I evaluate various
symbolic expressions which return 0 then the 0 returned is a python int,
rather than a Sage integer. examples of such expressions are sin(0),
tan(0), ln(0).

Is there a reason for this or is it a bug?

Best wishes

Alastair

kcrisman

unread,
Mar 21, 2011, 12:24:43 PM3/21/11
to sage-support


On Mar 21, 12:06 pm, Alastair Irving <alastair.irv...@sjc.ox.ac.uk>
wrote:
I would consider this a bug, but because it should return a symbolic
expression.

sage: a = sin(pi)
sage: a
0
sage: type(a)
<type 'sage.symbolic.expression.Expression'>

It's possible to get this behavior:
sage: type(sin(0,hold=True).simplify())
<type 'sage.symbolic.expression.Expression'>

Anyway, this is an oversight, I would say. Anyone else care to
comment? Otherwise it would be great if you'd file a bug report.
This is important to fix, because some Sage code depends on the input
in integer form being Sage integer or something else with Sage
methods, not a Python int, and one could imagine someone relying on
this and getting a nasty exception.

By the way, I hope you aren't getting 0 for ln(0)!

sage: ln(0)
-Infinity

- kcrisman

Alastair Irving

unread,
Mar 21, 2011, 2:14:09 PM3/21/11
to sage-s...@googlegroups.com
On 21/03/2011 16:24, kcrisman wrote:
>
>
> This is important to fix, because some Sage code depends on the input
> in integer form being Sage integer or something else with Sage
> methods, not a Python int, and one could imagine someone relying on
> this and getting a nasty exception.
exactly what happened to me, I was relying on having a .n() method to
evaluate numerically.

>
> By the way, I hope you aren't getting 0 for ln(0)!
No, I'm not, I intended to write ln(1)


Alastair

kcrisman

unread,
Mar 21, 2011, 2:51:45 PM3/21/11
to sage-support


On Mar 21, 2:14 pm, Alastair Irving <alastair.irv...@sjc.ox.ac.uk>
wrote:
> On 21/03/2011 16:24, kcrisman wrote:
>
> > This is important to fix, because some Sage code depends on the input
> > in integer form being Sage integer or something else with Sage
> > methods, not a Python int, and one could imagine someone relying on
> > this and getting a nasty exception.
>
> exactly what happened to me, I was relying on having a .n() method to
> evaluate numerically.
>

Great. This is now http://trac.sagemath.org/sage_trac/ticket/10972.

- kcrisman
Reply all
Reply to author
Forward
0 new messages