plot/fast_callable error with pi in denominator

4 views
Skip to first unread message

Harald Schilly

unread,
Jan 24, 2010, 1:53:57 PM1/24/10
to sage-...@googlegroups.com
Hi, I got this bug from the "report a problem" link

This code throws an error:

f(x)=1/(pi*x)
plot(f(x),(x,-1,1))

but this works, so does replacing pi with e!
f(x)=1/(pi^2*x)
plot(f(x),(x,-1,1))


Traceback (most recent call last): plot(f(x),(x,-1,1))
File "", line 1, in <module>

File "/tmp/tmpsJA8BR/___code___.py", line 4, in <module>
plot(f(x),(x,-_sage_const_1 ,_sage_const_1 ))
File "", line 1, in <module>

File "/opt/sage/current/local/lib/python2.6/site-packages/sage/plot/misc.py",
line 243, in wrapper
return func(*args, **kwds)
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/plot/misc.py",
line 138, in wrapper
return func(*args, **options)
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/plot/plot.py",
line 2465, in plot
G = funcs.plot(*args, **original_opts)
File "expression.pyx", line 6382, in
sage.symbolic.expression.Expression.plot
(sage/symbolic/expression.cpp:25697)
File "expression.pyx", line 6421, in
sage.symbolic.expression.Expression._plot_fast_callable
(sage/symbolic/expression.cpp:26100)
File "fast_callable.pyx", line 420, in
sage.ext.fast_callable.fast_callable (sage/ext/fast_callable.c:3134)
File "expression.pyx", line 6279, in
sage.symbolic.expression.Expression._fast_callable_
(sage/symbolic/expression.cpp:25105)
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 1355, in fast_callable
return FastCallableConverter(ex, etb)()
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 213, in __call__
return self.arithmetic(div, div.operator())
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 1295, in arithmetic
return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 1295, in <lambda>
return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
File "fast_callable.pyx", line 685, in
sage.ext.fast_callable.ExpressionTreeBuilder.call
(sage/ext/fast_callable.c:4986)
File "fast_callable.pyx", line 565, in
sage.ext.fast_callable.ExpressionTreeBuilder.__call__
(sage/ext/fast_callable.c:4313)
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 121, in _fast_callable_
return fast_callable(self, etb)
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 1355, in fast_callable
return FastCallableConverter(ex, etb)()
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 213, in __call__
return self.arithmetic(div, div.operator())
File "/opt/sage/current/local/lib/python2.6/site-packages/sage/symbolic/expression_conversions.py",
line 1295, in arithmetic
return reduce(lambda x,y: self.etb.call(operator, x,y), operands)
TypeError: reduce() of empty sequence with no initial value

Harald Schilly

unread,
Jan 25, 2010, 10:41:41 AM1/25/10
to sage-devel
here a follow up bug report for the same problem:

x=var('x')
f(x)=1/log(x)/x
plot(f,2,3)

nobody responded to this. Is this already known? Some ideas where
exactly the problem is so that it can be fixed? I think it's rather
serious that these functions cannot be plotted.

H

kcrisman

unread,
Jan 25, 2010, 11:11:58 AM1/25/10
to sage-devel
I just want to point out that these were already in 4.3, so it wasn't
introduced in the last month.

I think it might have something to do with this (f, g, h are hopefully
obvious from earlier in the thread):

sage: h.operands()
[pi^(-2), 1/x]
sage: g.operands()
[1/pi, 1/x]
sage: f.oper
f.operands f.operator
sage: f.operands()
[1/x, 1/log(x)]

Note that multiplying two 1/blah generates it. For instance:

sage: j(x)=1/(e*x)
sage: plot(j)
<all is well>
sage: j.operands()
[1/x, e^(-1)]

I wouldn't be surprised if the following in the function referenced in
the traceback was related, though I have no idea how:

if exponent == -1:
return self.etb.call(_operator.div, 1, operands[0])

Note that

sage: 1/e
e^(-1)
sage: 1/pi
1/pi

So there is some inconsistency already with this. Probably Burcin
will know where the problem lies. Thank you for being persistent on
this, Harald!

- kcrisman

Harald Schilly

unread,
Jan 25, 2010, 12:25:34 PM1/25/10
to sage-devel
On Jan 25, 5:11 pm, kcrisman <kcris...@gmail.com> wrote:
> So there is some inconsistency already with this.  Probably Burcin
> will know where the problem lies.  Thank you for being persistent on
> this, Harald!

Burcin has just created ticket #8056 - hopefully pinpointing the exact
problem !
I'm reading the "report a problem" issues, and this one was reported
twice in the last few days. therefore I have to be persistent ;)

H

Burcin Erocal

unread,
Jan 25, 2010, 2:16:42 PM1/25/10
to sage-...@googlegroups.com

There is also a patch attached to the ticket now:

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


Cheers,
Burcin

Reply all
Reply to author
Forward
0 new messages