# Can I use Solve to solve for an expression (instead of a variable)?

I have an equation:$$ds^2=-(C_1+A\space t)^2 dt^2+C_2^2 dr^2$$How would I re-arrange this formula to get an expression of $$\frac{dr}{dt}$$? $$C_1$$, $$C_2$$ and $$A$$ are constants. I know the answer is:$$\frac{dr}{dt}=\frac{ds+(C_1+A\space t)dt}{C_2 dt}$$This would allow me to make a substitution of $$D[r,t]=\frac{dr}{dt}$$ and solve the problem as an ODE, but I'm stuck trying to get the LHS of the equation in this form. Ideally, I'd like to do this:

Solve[ds^2=-(C_1+A*t)^2 dt^2+C_2^2 dr^2,dr/dt]


Are there any tricks?

• It's just a jargon from relativistic theory. See here for what Hadamard said about such differentials: Enfin, que signifie ou que représente l'égalité $d^2z = r\,dx^2 + 2s\,dx\,dy + t\,dy^2\,?$, A mon avis, rien du tout. Without a precise formulation, who would do something about it? – yarchik Mar 13 at 21:44
• @yarchik Are you sure you answered the right question? The question is really about some sort of upgraded Solve function, not relativity or differentials. – Tanner Legvold Mar 13 at 21:58
• You could try Reduce[{q == dr/dt, ds^2 == -(C + A*t)^2 dt^2 + C^2 dr^2}, {q}, {dr, dt}]. However it does not directly reproduce your result. Are you sure of it? Could ds be zero? – MarcoB Mar 13 at 22:07
• @TannerLegvold If one naively solves for $dr$ and divides the result by $dt$ one gets quite different answer. Only by assuming that $dr$, $dt$ and $ds$ are infinitesimally small, one can derive the final equation. – yarchik Mar 13 at 22:10
• @MarcoB - It looked promising, but Reduce appears to be finicky. It works with the constants, but if I replace the constants with constant expressions, it fails to find a solution. If I substitution my actual values for $C_1$ and $C_2$ out of the expression, use Reduce and then sub them back in, I've got something uglier than what I currently have. Thanks for the effort though, that was the general idea of what I wanted. – Quarkly Mar 13 at 22:57

First of all, let us mention two syntax errors in your code.

First, the underscore has a special meaning in Mma. Therefore, notations like C_1 are illegal. Use C1 instead.

Second, the use of Solve requires that the Equal, rather than Set stays in the expression you want to be interpreted as an equation. Therefore, use == instead of =.

After fixing this, the answer to your question is not very difficult. I will do it starting with your original idea.

Here is your equation and its solution:

sol = Solve[ds^2 == -(C1 + A*t)^2 dt^2 + C2^2 dr^2, dr][[2, 1]]

(*  dr -> Sqrt[ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2]/C2 *)


By default, Mma returns the solution in the form of a rule. Let us transform it into an equation:

eq1 = Equal @@ sol

(*  dr == Sqrt[ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2]/C2  *)


Let us now divide the both parts of this equation by dt:

eq2 = Assuming[{dt != 0}, DivideSides[eq1, dt]]

(*  dr/dt == Sqrt[ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2]/(C2 dt)  *)


Now, let us bring dt under the square root:

eq3 = expr1 /. Sqrt[a_]/dt :> Sqrt[a/dt^2]

(*  dr/dt == Sqrt[(
ds^2 + C1^2 dt^2 + 2 A C1 dt^2 t + A^2 dt^2 t^2)/dt^2]/C2  *)


and let us, further, expand the expression under the radical:

MapAt[Expand, expr2, {2, 2, 1}]

(*  dr/dt == Sqrt[C1^2 + ds^2/dt^2 + 2 A C1 t + A^2 t^2]/C2   *) Done. Have fun!