#12801: substitute_function misses some substitutions
-----------------------------+----------------------------------------------
Reporter: nbruin | Owner: burcin
Type: defect | Status: needs_review
Priority: minor | Milestone: sage-5.0
Component: symbolics | Resolution:
Keywords: | Work issues:
Report Upstream: N/A | Reviewers:
Authors: | Merged in:
Dependencies: #12796 | Stopgaps:
-----------------------------+----------------------------------------------
Comment (by nbruin):
Replying to [comment:5 mjo]:
> Is there some way to get a real function out of the expression `g`?
Yes there is:
{{{
sage: f = function('f')
sage: gexpr = 2*x*sin(x)
sage: g = gexpr.function(x)
sage: g
x |--> 2*x*sin(x)
}}}
evil shorthand (do `preparse('g(x)=2*x*sin(x)')` or google sage-devel to
see what's evil about it):
{{{
sage: g(x)=2*x*sin(x)
sage: g
x |--> 2*x*sin(x)
}}}
but then it works:
{{{
sage: f_prime = f(x).diff(x)
sage: f_prime
2*x*cos(x) + 2*sin(x)
}}}
or, if you really want to stick with functions, things get a little
hairier:
{{{
sage: f_prime=sage.symbolic.operators.FDerivativeOperator(f,[0])
sage: f_prime.substitute_function(f,g)
AttributeError
sage: f_prime.change_function(g)
D[0](x |--> 2*x*sin(x))
sage: f_prime.change_function(g)(x)
2*x*cos(x) + 2*sin(x)
sage: f_prime.change_function(g)(x).function(x)
x |--> 2*x*cos(x) + 2*sin(x)
}}}
This basically shows you that arithmetic on functions themselves isn't
really supported yet. Given that functions can have an unspecified arity
that might be a good thing. If we want to make "symbolic functions" into a
(differential) ring, some serious design choices would have to be
considered.
In fact, that trick was used in #12796 in `FDerivativeOperator.__call__`.
I don't know which of
{{{
expr.subs({x: x0, y: y0})
expr.function(x,y)(x0,y0)
}}}
is preferable.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12801#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.