Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is a partial answer, but maybe it will help people do the second thing you want. I don't know if the obvious tuple thing will let you make all of these functions of t at once.

sage: var('t')
t
sage: h=function('h',t)
sage: a=function('a',t)
sage: b=function('b',t)
sage: p=function('p',t)
sage: r=function('r',t)
sage: diff(a^2+b^2,t)
2*a(t)*D[0](a)(t) + 2*b(t)*D[0](b)(t)
sage: z = diff(a^2+b^2,t)
sage: z.operands()[0].operands()[1]
D[0](a)(t)
sage: z.operands()[0].operands()[1].operator()
D[0](a)
sage: y = z.operands()[0].operands()[1]
sage: y
D[0](a)(t)
sage: z.substitute_expression({y:3*p})
6*a(t)*p(t) + 2*b(t)*D[0](b)(t)

but I can't think of a way to substitute with 3*p for y directly:

sage: z.substitute_expression({D[0](a)(t):3*p})
---------------------------------------------------------------------------
NameError: name 'D' is not defined

Maybe this should be implemented somehow? I hate these sorts of pattern-matching things.