Open
Description
substitute_function
expects two function objects as argument not expressions (f(x)
). This leads to the (to some users) unexpected:
sage: f = function('f')(x)
....: g = function('g')(x)
....: df = f(x).diff(x)
sage: f.substitute_function(f,g)
f(x)
sage: f(1).substitute_function(f,g)
f(1)
sage: df.substitute_function(f,g)
diff(f(x), x)
sage: df(1).substitute_function(f,g)
D[0](f)(1)
(same with f(x)=function...
)
The problem is that f
and g
are not function objects like sin
. Taking this into account:
sage: f.substitute_function(f.operator(), g.operator())
g(x)
sage: f(1).substitute_function(f.operator(), g.operator())
g(1)
sage: df.substitute_function(f.operator(), g.operator())
diff(g(x), x)
sage: df(1).substitute_function(f.operator(), g.operator())
D[0](g)(1)
The ticket should make substitute_function
raise an exception with a hint. Note that the mess results from function('f')
returning a function object but function('f')(x)
returning f(x)
and users assigning this to f
or f(x)
instead of just doing
sage: f=function('f')
sage: f(1).substitute_function(f,g)
g(1)
Documentation of substitute_function
could be made more explicit as well.
Component: symbolics
Issue created by migration from https://trac.sagemath.org/ticket/22401