Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

substitute expression instead of formal function symbol

Hi, everyone.

The question seems to be basic, but I cannot find out any simple answer for it...

So, the case is as follows. Let's assume, we have some formal function symbol (which is intended later to be replaced by actual expression)

x = var('x'); f = function('f', x)

and some function, which uses 'f(x)' in its definition:

a, b = var('a b')
g(x) = a*f(x) + b*f(x)^2

now we would like to compute derivative of 'g(x)' (and possibly make some other manipulations)

 h(x) = diff(g, x)

as a result we have h(x), which includes symbols like 'D[0]f(x)'. This can be answer for some problem in general form. But now we would like to evaluate this expression for particular 'f(x)' (and possibly multiple times with different expressinos), e. g. for 'f(x) = a*x + b'.

It is desirable to have this with something like

answer = h.subs({f:a*x + b})  # do not work :(

but this substitution do not work inside derivatives...

So, the question is: is there some simple solution (like simple subs() function) for the case I've described above? Or may be there is some standard tricks/patterns to solve this issue?

Thanks in advance for any suggestions.