# Substitute formal function by an expression in a differential equation

This is a follow up to substitute expression instead of formal function symbol. I tried to no avail to apply the workaround proposed there for the following application where I build a differential equation involving a formal function P:

  sage: x,y = var('x,y')
sage: P = function('P',x,y)
sage: z = var('z')
sage: C = function('C',z)
sage: equation = P(x=z,y=C) == 0
sage: dequation = diff(equation, z)


and then I would want to substitute P by a specific expression:

  sage: Q(x,y) = y^2 - y + x
sage: dequation.substitute_function(P,Q)


But whatever I tried, I got:

   D[0](C)(z)*D[1](P)(z, C(z)) + D[0](P)(z, C(z)) == 0


Is there a natural syntax to achieve this? If not, should this be a ticket?

Thanks!

edit retag close merge delete

Sort by » oldest newest most voted

This is a bug and it's already on trac: 6480

Unfortunately GiNaC doesn't support pattern matching with functions, or substituting functions (like substitute_function()). This is partly due to the fact that defining symbolic functions at runtime is a Python luxury, which you don't get in a convenient form using C++.

Asking on the GiNaC lists about how to do this would be a good start. At the moment I don't have too much time to start looking at this myself.

more