substitute_function when function is a diff ?
I simplified my question as I was asked:
var('m, omega, E', domain='real')
phi_x(t) = function('phi_x', latex_name=r'\phi_x')(t)
dphi_x = diff(phi_x, t, 1)
p_x = function('p_x')(t)
# p_x = m*diff(phi_x, t, 1)
eqTest = E == 1/2*m*omega^2*phi_x(t)^2 + 1/2*m*dphi_x^2
eqTest_wished = E(t) == 1/2*m*omega^2*phi_x(t)^2 + 1/2*p_x^2/m
print('We wish to obtain `eqTest_wished` with SageMath:')
show('eqTest_wished : \t', eqTest_wished)
show("by using substitutions starting from `eqTest`:")
show('eqTest : \t \t \t', eqTest)
# Failed attempt
eqTest_Modified = eqTest.substitute_function(dphi_x, p_x/m)
show('Failed attempt: \t \t ', eqTest_Modified)
How to transform equation eqTest into equation eqTest_wished using SageMath ?
Your notations are inconsistent :
phi_x=is a function (of the single argumentt), therefore, so isdphi_x, and so is1/2*m*omega^2*phi_x(t)^2 + 1/2*m*dphi_x^2.(Similarly,p_xis a function (of the single variablet).)eqTestis therefore a function (of the single variable t`) whose value is an equation.On the other hand,
1/2*m*omega^2*phi_x(t)^2 + 1/2*p_x^2/mus a symbolic expression ; therefore eqTest_wished" is an equation. One notes, BTW, thatEis a variable, whereasE(t)has no proper meaning (it turns out that E(t) has a meaning in "raw" Sage, left as an exercise for the reader...).It is therefore extremely difficult for the reader to guess, suppose, postulate or otherwise divine what you are trying to accomplish...
Please clarify your thoughts...
Thanks @ortollj for simplifying the question with respect to the initial version.
I simplified it a little bit more by removing unused variables from the initial variable declaration.
I also changed
phi_xusinglatex_nameso that its plain text name has no\but it still displays nicely as $\phi_x$ when typeset.