Ask Your Question

Problem with sign / sgn and .n()

asked 2011-12-06 08:28:55 -0500

Louis Cypher gravatar image

updated 2014-07-02 20:20:59 -0500

tmonteil gravatar image

I have an urgent problem with the sign function. I have done a symbolic calculation and want to evaluate the result numerically. The symbolic terms have a sgn() function within, which gives me an error when I try to evaluate the expression numerically. Please find the error below. I do not have the slightest ideas why sage can not evaluate that (simple) expression:

sign(1050*cos(61075634/181449129) + 900).n()

How can i solve that problem?

Thanks a lot in advance,

Best Markus


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 10, in <module>
    exec compile(u'open("","w").write("# -*- coding: utf-8 -*-\\n" + .....

  File "", line 1, in <module>

  File "/tmp/tmp4W3s9l/", line 4, in <module>
    exec compile(u'qwer.n()
  File "", line 1, in <module>

  File "expression.pyx", line 4053, in sage.symbolic.expression.Expression._numerical_approx (sage/symbolic/expression.cpp:17894)
TypeError: cannot evaluate symbolic expression numerically

edit by kcrisman: Here's a minimal example:

sage: M = sgn(cos(3/2))
sage: M.n()

It doesn't suffice to do sgn(cos(1)), because that turns out to be 1.

edit retag flag offensive close merge delete



That looks like a bug to me. I'll see if I can track it down and file a bug report.

benjaminfjones gravatar imagebenjaminfjones ( 2011-12-06 11:57:17 -0500 )edit

Yup. Problem seems to be that in `M.n??` we see that it's looking for `is_a_numeric(x._gobj)` but apparently that fails, as does the constant, so it thinks we are looking at evaluating `sgn(cos(x))` instead of `sgn(cos(3/2))`. Hopefully Burcin will see this and magically know the answer :) But otherwise it's SD 35.5 fodder!

kcrisman gravatar imagekcrisman ( 2011-12-06 13:37:42 -0500 )edit

Thanks for the answers. Would you mind explaining me what a SD 35.5. fodder ist?

Louis Cypher gravatar imageLouis Cypher ( 2011-12-22 08:28:55 -0500 )edit

@Louis Cypher: "SD" stands for Sage Days, workshops at which Sage development is done. Fodder is food for animals, or in this context "something to do at the workshop". See

DSM gravatar imageDSM ( 2011-12-22 08:57:54 -0500 )edit

OK, thanks. This : might be a related problem. There are also some sage constants that are not evaluated at all.

Louis Cypher gravatar imageLouis Cypher ( 2011-12-22 10:37:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-06-29 11:17:39 -0500

I have reported this as

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-12-06 08:28:55 -0500

Seen: 248 times

Last updated: Jun 29 '14