f(x).subs() substitution in sympy (python)
<p>I defined symbols a and f. I'm expecting to use "a(3).subs(a,f)" to get f(3), but instead I got a(3). What's wrong with it?</p>

<pre><code>a, f = symbols('a f')

a(3).subs(a,f)
</code></pre>

<p>You can use <code>replace</code> to change the function. Here are some examples. </p>

<pre><code>import sympy as sp

f = sp.Function('f')
g = sp.Function('g')
x,y = sp.symbols('x, y')

f(x).replace(f, g)
</code></pre>

<blockquote>
  <p><code>g(x)</code></p>
</blockquote>

<pre><code>f(x).replace(f, sp.sin)
</code></pre>

<blockquote>
  <p><code>sin(x)</code></p>
</blockquote>

<pre><code>f(x,y).replace(f, lambda *args: sp.exp(-5 * args[0] + args[1] ))
</code></pre>

<blockquote>
  <p><code>exp(-5*x + y)</code></p>
</blockquote>

<p>The <a href="http://docs.sympy.org/latest/modules/core.html#sympy.core.basic.Basic.replace" rel="nofollow">documentation</a> provides an extensive list of additional examples.</p>

python sympy