Function Repository Resource:

TrigContract

Source Notebook

Attempt to express weighted sums of sines and cosines having the same period in terms of cosines alone

Contributed by: Wolfram Staff

ResourceFunction["TrigContract"][expr]

evaluates TrigReduce[expr] and attempts to contract weighted sums of sines and cosines with the same period.

ResourceFunction["TrigContract"][expr,var]

treats all variables other than var as constants.

Details and Options

ResourceFunction["TrigContract"] attempts to combine terms of the form aSin[x]+bCos[x] into .
ResourceFunction["TrigContract"] automatically threads over lists in expr.
Given the option "ExpandTrigsOfSum" True, ResourceFunction["TrigContract"] expands the terms in the form of Sin[α+β] and Cos[α+β] into sines and cosines of α and β.
The default "ExpandTrigsOfSum"Automatic employs heuristics to decide whether to expand the sums.

Examples

Basic Examples (1) 

Combine sums of sines and cosines:

In[1]:=
ResourceFunction["TrigContract"][ Sin[x] + 3 Cos[x]]
Out[1]=
In[2]:=
ResourceFunction["TrigContract"][
 a Sin[x] + b Sin[2 x] + c Cos[x] + d Cos[2 x]]
Out[2]=

Scope (4) 

TrigContract can handle symbolic parameters:

In[3]:=
ResourceFunction["TrigContract"][a Sin[x] + b Cos[x] ]
Out[3]=

Treat x as the main variable and y as a constant:

In[4]:=
ResourceFunction["TrigContract"][Cos[y] Sin[x] + Sin[y] Cos[x] , x]
Out[4]=

Treat y as the main variable and x as a constant:

In[5]:=
ResourceFunction["TrigContract"][Cos[y] Sin[x] + Sin[y] Cos[x] , y]
Out[5]=

Here TrigContract picks y as the main variable and treats x as a constant:

In[6]:=
ResourceFunction["TrigContract"][Cos[y] Sin[x] + Sin[y] Cos[x] ]
Out[6]=

TrigContract threads over lists:

In[7]:=
ResourceFunction[
 "TrigContract"][{Sin[x] + Cos[x], Cos[y] Sin[x] + Sin[y] Cos[x] }, x]
Out[7]=

Use symbolic manipulations to handle trigonometric functions other than sines and cosines:

In[8]:=
ResourceFunction["TrigContract"][#, x] & /@ Together[a Tan[x] + b, Trig -> True]
Out[8]=

Options (2) 

ExpandTrigsOfSum (2) 

With "ExpandTrigsOfSum"True, TrigContract finds possible contractions for sines and cosines of sums, but may produce relatively more complicated results:

In[9]:=
trigs = {Cos[1 + x] + Sin[1 + x], Cos[x] + Sin[x - y] + Sin[x + y]}
Out[9]=
In[10]:=
ResourceFunction["TrigContract"][trigs, "ExpandTrigsOfSum" -> True]
Out[10]=

Prevent expanding terms in the form (Sin|Cos)[x±y]:

In[11]:=
ResourceFunction["TrigContract"][trigs, "ExpandTrigsOfSum" -> False]
Out[11]=

Properties and Relations (2) 

TrigContract and TrigExpand are, generically, inverses of each other:

In[12]:=
ResourceFunction["TrigContract"][a Sin[x] + b Cos[x]]
Out[12]=
In[13]:=
TrigExpand[%]
Out[13]=

TrigContract produces a result equivalent to the result of TrigReduce:

In[14]:=
e = Cos[2 x] + Sin[x] Cos[x];
In[15]:=
{TrigReduce[e], ResourceFunction["TrigContract"][e]}
Out[15]=
In[16]:=
TrigExpand[%]
Out[16]=

Possible Issues (3) 

Without specifying the variable, TrigContract may not always fully contract expr that contains symbolic parameters:

In[17]:=
ResourceFunction["TrigContract"][Sin[x] Cos[a]^2 + Cos[x]]
Out[17]=

Specify the variable:

In[18]:=
ResourceFunction["TrigContract"][Sin[x] Cos[a]^2 + Cos[x], x]
Out[18]=

Simplify the terms of the product:

In[19]:=
Simplify /@ %
Out[19]=

Version History

  • 1.0.0 – 02 December 2020

License Information