# A complicated derivative problem

I have some equation，like this \begin{aligned} &\hat{t}_{g o}=\frac{R}{V_{m}}\left(1+\frac{(n+2) \sigma^{2}+(n+1)^{2}(n+2) \sigma_{f}^{2}}{2(2 n+3)(2 n+5)}-\frac{(n+1) \sigma \sigma_{f}}{2(2 n+3)(2 n+5)}\right)\\ &\dot{R}=\frac{dR}{dt}=-V_{m} \cos \sigma\\ &\sigma=\theta-\lambda\\ &\dot{\lambda}=\frac{d\lambda}{dt}=-\frac{V_{m} \sin \sigma}{R}\\ &{\sigma_f}=\theta_{f}-\lambda\\ &\dot{\theta}_{f}=\frac{d\theta_f}{dt}=0 \end{aligned}

To solve this problem，this is my code

Clear["Global*"]
sigma[t] = theta[t] - lambda[t];
sigmaF[t] = thetaF[t] - lambda[t];
tgo = r[t]/
vm*(1 + ((n + 2)*
sigma[t]^2 + (n + 1)^2*(n + 2) sigmaF[t]^2)/(2*(2 n +
3)*(2 n + 5)) - (n + 1)*sigma[t]*
sigmaF[t]/(2*(2*n + 3)*(2*n + 5)));
(D[tgo, t] /. {Derivative[1][r][t] -> (-vm*Cos@(sigma[t])),
Derivative[1][lambda][t] -> -(vm*Sin@(sigma[t]))/(r[t]),
Derivative[1][thetaF][t] -> 0}) //
FullSimplify /. {(lambda[t] - theta[t]) ->
sigmat, (lambda[t] - thetaF[t]) -> sigmaft}


get this

The resulting formula is a little bit bug，like this

To solve this problem, I continue with the substitution，like this

I have compared the result with the original answer, and it feels right, but the operation is very complicated and not intuitive. Is there any good way to keep wolfram's output in the same form as the original answer？

You have a precedence problem.

Look at "tutorial/OperatorInputForms" in the help. You will find that "/." has a higher precedence than "//". Therefore, what you evaluate is

... // (FullSimplify /. ... )


You can fix this using parenthesis:

((D[tgo, t] /. {Derivative[1][r][t] -> (-vm*Cos@(sigma[t])),
Derivative[1][lambda][t] -> -(vm*Sin@(sigma[t]))/(r[t]),
Derivative[1][thetaF][t] -> 0}) //
FullSimplify) /. {(lambda[t] - theta[t]) ->
sigmat, (lambda[t] - thetaF[t]) -> sigmaft}
`