Ticket #6480 (new defect)
.subs_expr() method doesn't work for argument of D derivative operator
| Reported by: | gmhossain | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | symbolics | Keywords: | |
| Cc: | kcrisman, mjo, eviatarbach | Work issues: | |
| Report Upstream: | N/A | Reviewers: | |
| Authors: | Merged in: | ||
| Dependencies: | Stopgaps: |
Description (last modified by kcrisman) (diff)
In computing functional derivative, one needs to vary a functional. For example, in sage-3.4 one can do as follows
sage: f(x) = function('f',x)
sage: df(x) = function('df',x)
sage: g = f(x).diff(x)
sage: g
diff(f(x), x, 1)
sage: g.subs_expr(f(x)==f(x)+df(x))
diff(f(x) + df(x), x, 1)
In new symbolics, if I do the same I get
sage: g D[0](f)(x) sage: g.subs_expr(f(x)==f(x)+df(x)) D[0](f)(x)
From #11842, the list of what does/doesn't work:
from sage.all import *
# 1. Fails.
x = var('x')
f = function('f', x)
g = function('g', x)
p = f
print p.substitute_function(f, g) # Outputs "f(x)"
# 2. Fails.
x = var('x')
f = function('f')
g = function('g')
p = f(x)
print p.substitute_function(f(x), g(x)) # Outputs "f(x)"
# 3. Works.
x = var('x')
f = function('f')
g = function('g')
p = f(x)
print p.substitute_function(f, g) # Outputs "g(x)"
# 4. Fails.
x = var('x')
f = function('f')
g = function('g')
p = f(1)
print p.substitute_function(f(1), g(1)) # Outputs "f(1)"
# 5. Works.
x = var('x')
f = function('f')
g = function('g')
p = f(1)
print p.substitute_function(f, g) # Outputs "g(1)"
# 6. Fails.
x = var('x')
f = function('f', x)
g = function('g', x)
p = f.diff()
print p.substitute_function(f, g) # Outputs "D[0](f)(x)"
# 7. Fails.
x = var('x')
f = function('f', x)
g = function('g', x)
p = f.diff()
print p.substitute_function(f(x), g(x)) # Outputs "D[0](f)(x)"
# 8. Works.
x = var('x')
f = function('f')
g = function('g')
p = f(x).diff()
print p.substitute_function(f, g) # Outputs "D[0](g)(x)"
# 9. Fails.
x = var('x')
f = function('f')
g = function('g')
p = f(x).diff()(1)
print p.substitute_function(f(x).diff(), g(x).diff()) # Outputs "D[0](f)(1)"
# 10. Works..
x = var('x')
f = function('f')
g = function('g')
p = f(x).diff()(1)
print p.substitute_function(f, g) # Prints D[0](g)(1).
Change History
comment:2 Changed 17 months ago by mjo
- Cc mjo added
I duped this in #11842. We might be able to make use of the test cases there when this gets fixed.
comment:4 Changed 9 days ago by eviatarbach
.substitute_function seems to work: http://ask.sagemath.org/question/2380/how-to-substitute-a-function-within-derivatives
Note: See
TracTickets for help on using
tickets.
