# Replacing of products of trigonometric and hyperbolic functions with a symbol

Suppose I have a function like

$\qquad f=\sinh(\eta)^2\times \sin(\theta)^2\times \cos(\phi)^2-\cosh(\eta)^2\times \sin(\theta)^2\times \sin(\phi)^2+\cdots$

I want to replace $\sinh(\eta)\times \sin(\theta)\times \cos(\phi)$ by $u_1$

I have tried with

Replace[f, Sinh[η] Sin[θ] Cos[ϕ] -> u1]


but unfortunately it's not working. I have come to know from the Mathematica Documentation Center that Replace does not map down to subparts.

Would anyone be able to help me regarding this issue?

• Look at ReplaceAll.
– gwr
Aug 19, 2016 at 7:06

Familiarize yourself with the structure of expressions in general. The part of the expression you would like to replace doesn't exists in one chunk, because each term is wrapped in Power.

expr = Sinh[e]^2 Sin[t]^2 Cos[f]^2 - Cosh[e]^2 Sin[t]^2 Sin[f]^2 -
Sinh[e]^3 Sin[t]^3 Cos[f]^3
subs = Sinh[e] Sin[t] Cos[f] -> x


You can do this with your specific example:

expr /. Times[a___ , p : Power[_, n_] .., b___] :>
a b Power[Times @@ First /@ {p} /. subs, n]


x^2 - x^3 - Cosh[e]^2 Sin[f]^2 Sin[t]^2

And this works all right with products with same powers. But what if you would like to do the same substitution on this:

Sinh[e]^4 Sin[t]^12 Cos[f]^4


The target expression can be "dug out", with a more complicated code. Yet which could subsume the first case.