Question: How to simplify a expression by substituting its sub-expressions with pre-defined variables


I use the VectorCalculus package to calcutate derivative formula for geometric functions, and met difficulity simplifying the result expression.

For example, I define some vectors P, S, V like below:

P:=<Px, Py, Pz>, S:=<Sx, Sy, Sz>, V:=<Vx, Vy, Vz>

then define an intermediate variable Q:=P - S,

then define a function d:= sqrt(DotProduct(Q, Q)-(DotProuct(Q,V))^2)

by calculating the function's derivative w.r.t Px I got a very complex result expression:

dpx:=1/2 * (2Px - 2Sx - 2 ( (Px - Sx) Vx + (Py - Sy) Vy + (Pz - Sz)Vz )Vx ) / (sqrt( (Px-Sx)^2 + (Py-Sy)^2 + (Pz-Sz)^2 - .....)


Apparently this expression can be simplified by substituting its sub-expression with pre-defined variables like Q and d.

I know I can use subs, eval, and subsalg to do it manually:

subs(1/(sqrt( (Px-Sx)^2 + (Py-Sy)^2 + (Pz-Sz)^2 - .....) = 1/dv, dfdpx)

subs((Px - Sx) Vx + (Py - Sy) Vy + (Pz - Sz)Vz = dotproduct_q_v, dfdpx)

and I can get a simplified expression like this:



But it's like my brain does the simplification first, and Maple only does the text substitution for me.

Is there any way to do it automatically?





Please Wait...