Opened 5 years ago

Last modified 5 years ago

#22401 new defect

Let substitute_function handle anon functions smoothly — at Initial Version

Reported by: rws Owned by:
Priority: major Milestone: sage-7.6
Component: symbolics Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

substitute_function expects two function objects as argument not expressions (f(x)). This leads to the 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 do this automatically and ignore any arguments. Note that the mess results from function returning f(x) and users assigning this to f or f(x) instead of just doing

sage: function('f')(x)
f(x)
sage: f(1).substitute_function(f,g)
g(1)

Change History (0)

Note: See TracTickets for help on using tickets.