Consider the expression $$ a\sin(x)-a\sin\left(\frac{x}{a}\left(a+\frac{ay}{x}\right)\right) \label{a}\tag{1} $$ which can be rewritten as $$ \sin(x)-\sin\left(x+y\right) \label{b} \tag{2} $$ and finally as $$ -2 \sin(y/2) \cos(x+y/2) \label{c} \tag{3} $$ I have a more complicated expression, where an expression such as (\ref{a}) is embedded. I want Mathematica to apply the transformation "(\ref{b}) -> (\ref{c})" to this expression, without any further simplifications. Note that the variable names may differ and I want to inform Mathematica about "(\ref{b}) -> (\ref{c})" in the general most way. That is for example, without the prefactor $a$ in (\ref{a}) or without giving the explicit structure of the parentheses in the $\sin$ on the right hand side of (\ref{a}).
1 Answer
a Sin[x] - a Sin[x/a (a + a y/x)] // FullSimplify // TrigFactor
It works also as
g[a Sin[x] - a Sin[x/a (a + a y/x)]] /. g[a_] :> g[TrigFactor[FullSimplify[a]]]
-
$\begingroup$ Unfortunately, that does not work if the difference of the sines is wrapped inside
Exp
. $\endgroup$ Mar 16, 2020 at 17:40 -
$\begingroup$ Or basically, the expression to simplify is wrapped in any other expression. $\endgroup$ Mar 16, 2020 at 18:44
-
1
-
$\begingroup$ If
g
isExp
I have to explicitly useExp
on the right hand side of/.
, otherwise this still does not work. Furthermore, if there are other things wrapped around theSin
es this still does not work, e.g.:Exp[t + a Sin[x] - a Sin[x/a (a + a y/x)]] /. Exp[x_] :> Exp[TrigFactor[ExpandAll[x]]]
. I guess that's because the sines are wrapped in something because of the+
. $\endgroup$ Mar 16, 2020 at 19:29