When I do:
expand(sin(5*u)) (1)
The output is:
16*sin(u)*cos(u)^4 - 12*sin(u)*cos(u)^2 + sin(u) (2)
If I want it to give me an expression with merely sin(u) in it, I would do:
simplify(expand(sin(5*u)), [cos(u)^2 = 1 - sin(u)^2]) (3)
The output of (3) is:
16*sin(u)^5 - 20*sin(u)^3 + 5*sin(u) (4)
Now, I want to expand tan(4*u). I write:
expand(tan(4*u)) (5)
The output of (5) is:
(4*tan(u) - 4*tan(u)^3)/(1 - 6*tan(u)^2 + tan(u)^4) (6)
I want it to be in terms of just sin(u) and cos(u). The natural thing to do (I suppose) is to write:
simplify(expand(tan(4*u)), [tan(u) = sin(u)/cos(u)]) (7)
But the output of (7) is just:
(4*tan(u) - 4*tan(u)^3)/(1 - 6*tan(u)^2 + tan(u)^4) (8)
Which is the same expression as (6). So, (7) turned out to be useless.
My questions are:
$1)$ When is this method (putting an identity inside []) useful and what are its limitations?
$2)$ Are there any shortcuts or better methods to work with than this one?
If you only wish to substitute
tan(u)=sin(u)/cos(u)then use either the 2-argument form of theevalcommand (or thesubsoralgsubscommands).This particular substitution for
tanin terms ofsinandcoscan also be made as a conversion. (Here too you could wrap withnormalorsimplifyjust to get a more terse result.)Here are some other ways to get your first example's result,
If we use the 2-argument
eval(orsubs) command and try to substitute forcos(u)^2then thecos(u)^4will be left untouched. So that's one advantage to using "simplify with subrelations", which what your original code did.For this example it's possible to substitute for
cos(u)and usesqrt.But you can also attain your desired result without using either
sqrtor simplification with side-relations, by using thealgsubscommand.There may not be a canonical "simplest" form for expressions like yours. So, as you've seen, invoking
simplifyleaves some decisions up to the system. If your goal is to perform some particular substitutions and obtain a particular form of result then you may be better off choosing particular manipulations.When I want to retain more control of the substitutions then my own preference is to use 2-argument
evalwhere possible, and if that is not satisfactory then to usealgsubs, and if neither is adequate then to use simplification with side-relations.