Question: using expand in RHS of applyrule?

applyrule is useful but seems limited. I can't do operation such as expand in the RHS of the rule.

For example, I wanted to applyrule that says to take sin(x::anything) and change it to cos(expand(x)), but it does not expand x. 

It seems because in the RHS of the rule, at the instance applyrule sees expand, x remains a symbol and not evaluated. So there is nothing to expand. It gets evaluated at later time, but by then too late for expand to do anything, it is gone. Just a guess.

But is there a trick to allow one to do more things in RHS of applyrule, such as expand or simplify? This would make applyrule much more useful. Otherwise, as it is, applyrule is of limited use. 

I know I can use evalindets ofcourse for this. 

#expand does not work in RHS of applyrule
e1:=sin(2*sqrt(a*b)*(t+mu));
applyrule( sin(x::anything) = cos(expand(x)), e1);

sin(2*(a*b)^(1/2)*(t+mu))

cos(2*(a*b)^(1/2)*(t+mu))

#but other operations worksheetdir
e1:=sin(2*sqrt(a*b)*(t+mu));
applyrule( sin(x::anything) = cos(x^2), e1);

sin(2*(a*b)^(1/2)*(t+mu))

cos(4*a*b*(t+mu)^2)

expand(2*sqrt(a*b)*(t+mu))

2*(a*b)^(1/2)*t+2*(a*b)^(1/2)*mu

#I could do this ofcourse
evalindets(e1,'specfunc'(sin),X->sin(expand(op(1,X))));

sin(2*(a*b)^(1/2)*t+2*(a*b)^(1/2)*mu)

 

 

Download apply_rule.mw


Using other software, there is no such problem using other operations on RHS of a rule

You see, expand worked on RHS of rule. 

I'd like to do same thing using applyrule in Maple. Is there a trick to allow this?

Maple 2024.1

Please Wait...