ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 14 Mar 2013 16:58:52 -0500The difference between f(x=3) and f(3) of callable symbolic expression 'f'http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/f=x.derivative()
f(3) ----> error
f(x=3) ----> ok!
Dose f(x=3) call the method __call__?Thu, 14 Mar 2013 05:06:52 -0500http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/Answer by ppurka for <p>f=x.derivative()</p>
<p>f(3) ----> error</p>
<p>f(x=3) ----> ok!</p>
<p>Dose f(x=3) call the method __call__?</p>
http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/?answer=14649#post-id-14649Not 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)
1Thu, 14 Mar 2013 05:31:38 -0500http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/?answer=14649#post-id-14649Comment by ppurka for <p>Not surprised that <code>f(3)</code> 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 <code>f.subs(x=3)</code> or <code>f(x=3)</code>, i.e., specify the variable name explicitly.</p>
<p>Note that there are some idiosyncrasies while working with symbolic expressions. For instance the following will not complain even though <code>f</code> is not defined as a function of <code>x</code>:</p>
<pre><code>sage: f = SR(1)
sage: f.subs(x=2)
1
</code></pre>
http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/?comment=18067#post-id-18067Yes. 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!Thu, 14 Mar 2013 16:58:52 -0500http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/?comment=18067#post-id-18067Comment by liblenovo for <p>Not surprised that <code>f(3)</code> 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 <code>f.subs(x=3)</code> or <code>f(x=3)</code>, i.e., specify the variable name explicitly.</p>
<p>Note that there are some idiosyncrasies while working with symbolic expressions. For instance the following will not complain even though <code>f</code> is not defined as a function of <code>x</code>:</p>
<pre><code>sage: f = SR(1)
sage: f.subs(x=2)
1
</code></pre>
http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/?comment=18068#post-id-18068Inspired 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.pyxThu, 14 Mar 2013 08:16:28 -0500http://ask.sagemath.org/question/9842/the-difference-between-fx3-and-f3-of-callable-symbolic-expression-f/?comment=18068#post-id-18068