Ask Your Question

The difference between f(x=3) and f(3) of callable symbolic expression 'f'

asked 2013-03-14 11:06:52 +0100

liblenovo gravatar image

updated 2013-03-14 11:11:50 +0100


f(3) ----> error

f(x=3) ----> ok!

Dose f(x=3) call the method __call__?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-03-14 11:31:38 +0100

ppurka gravatar image

updated 2013-03-14 11:32:42 +0100

Not surprised that f(3) is giving you an error. This form of substituting values in symbolic expressions has been deprecated for quite a while (well, over four years!). You must have got the warning at some point in your calculations. You should be using either f.subs(x=3) or f(x=3), i.e., specify the variable name explicitly.

Note that there are some idiosyncrasies while working with symbolic expressions. For instance the following will not complain even though f is not defined as a function of x:

sage: f = SR(1)
sage: f.subs(x=2)
edit flag offensive delete link more


Inspired by your answer. I finally found that if no keywords was specified, f(3) will call variables() method to make a dict to pass to sage.symbolic.expression.Expression.subs method. It is the subs method do the actual work. So when varibles() return None, the dict cannot be made, an error was raised. The code is in Line 683 of /devel/sage/sage/symbolic/ring.pyx

liblenovo gravatar imageliblenovo ( 2013-03-14 14:16:28 +0100 )edit

Yes. I put in a patch at ticket 14270 to remove this deprecation. It will avoid confusion in the future. If you can review the patch, feel free to comment in the ticket!

ppurka gravatar imageppurka ( 2013-03-14 22:58:52 +0100 )edit

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: 2013-03-14 11:06:52 +0100

Seen: 1,344 times

Last updated: Mar 14 '13