# Simplify expression by a known expression substitution

A bit complex than a similar question, below is a minimal example,

eqs1 = a b x'[t]^2 - ac x''[t]
eqs2 = x''[t] - b x'[t] - c == 0


I want take x''[t] substitute in eqs1, where $$eq1= a b \dot{x}^2- ac \ddot{x},~ eq2 = \ddot{x}-b\dot{x}-c$$, the output should like $$eq1 = ab\dot{x}^2 -ac(b\dot{x}+c)$$.

I have try Simplify[eqs1, eqs2] but fails. Maybe I should use SubtractSides to let x''[t] in the left-hand?

If eq2 is very complicated, eg. eqs2 = x'[t] x''[t] - b x'[t] - c == 0, I think it's difficult substitute x''[t] of eq2 into eq1.

Any comments very much appreciate!

the output should like $$eq1 = ab\dot{x}^2 -ac(b\dot{x}+c)$$

I am sure there many ways to do this in Mathematica.

One way could be

Clear["Global*"]
eqs1 = a*b*x'[t]^2 - a*c*x''[t]
eqs2 = x''[t] - b*x'[t] - c == 0
eqs1 /. First@Solve[eqs2, x''[t]]


If you do not use First@ above, you'll get same answer but in a list

 eqs1 /. Solve[eqs2, x''[t]]


Then you can do First on it. It is your choice. The above works, since Solve returns results using -> build into the answer. So all you have to do is just add the /. in the front.

In a real program, you should make this more robust of course, by adding additional checks (such as checking if Solve actually solved it, and to check on number of solutions generated and so on.

btw, watch the spaces in Mathematica. You had ac it should be a c or a*c

• Thank you so much, you reminded me that Solve will be good choice.
– Ben
Dec 5 '21 at 2:50
Clear["Global*"]

eqs1 = a b x'[t]^2 - a c x''[t];
eqs2 = x''[t] - b x'[t] - c == 0;


eqs2 can be solved for x[t] using DSolve

sol = DSolve[eqs2, x, t][[1]]

(* {x -> Function[{t}, -((c t)/b) + (E^(b t) C[1])/b + C[2]]} *)


Verifying,

eqs2 /. sol // Simplify

(* True *)


Substituting into eqs1

expr = eqs1 /. sol // Simplify

(* a b (-c E^(b t) C[1] + (c/b - E^(b t) C[1])^2) *)


If the arbitrary constant is set to zero

expr /. C[1] -> 0

(* (a c^2)/b *)


One idea is to give a derivative definition:

x /: Derivative[n_?(GreaterThan[1])][x] := b x'[#] - c &


Then:

a b x'[t]^2-a c x''[t]


a b x'[t]^2 - a c (-c + b x'[t])

and:

x'[t] x''[t] - b x'[t] - c == 0


-c - b x'[t] + x'[t] (-c + b x'[t]) == 0