1 | initial version |

Hugh Thomas pointed me to the following. When writting:

```
sage: foo = function('foo',x)
```

`foo`

is actually `foo(x)`

. However, in `h`

, and in particular
in pieces like `D[0](foo)'', it's not only`

foo(x)'' that we want to
replace, but ``foo''. So a trick is to store the result of
function('foo',x) in another variable. And now, substituting with
substitute function will work::

```
sage: var('a b x')
sage: f = function('foo',x)
sage: g = a*foo(x) + b*foo(x)^2
sage: h = diff(g, x)
sage: bar(x) = a*x + b
sage: h.substitute_function(foo, bar)
2*(a*x + b)*a*b + a^2
```

Now, some questions:

Is there a way to recover

`foo`

from`foo(x)`

? Something like foo(x).unapply()? Worst come to worst, one can use:`sage.symbolic.function_factory.function('foo')`

Should substitute_function support:

sage: h.substitute_function(foo(x), bar)

Moral: side effects, like those with function, are ugly ...

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.