TrigReduce¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
TrigReduce[expr]
rewrites products and powers of trigonometric functions in expr in
terms of trigonometric functions with combined arguments.
TrigReduce operates on both circular and hyperbolic functions; given a
trigonometric polynomial it typically yields a linear expression
involving trigonometric functions with more complicated arguments
(broadly the inverse of TrigExpand).
TrigReduce automatically threads over lists, equations, inequalities,
and logic functions.
Examples¶
All examples below are verified against the current Mathilda build.
In[1]:= TrigReduce[2 Cos[x]^2]
Out[1]= 1 + Cos[2 x]
In[2]:= TrigReduce[2 Sin[x] Cos[y]]
Out[2]= Sin[x + y] + Sin[x - y]
In[3]:= TrigReduce[2 Cosh[x] Cosh[y]]
Out[3]= Cosh[x + y] + Cosh[x - y]
In[4]:= TrigReduce[Sin[a] (Cos[b] - Sin[b]) + Cos[a] (Sin[b] + Cos[b])]
Out[4]= Cos[a + b] + Sin[a + b]
In[5]:= TrigReduce[Tan[x] + Tan[y]]
Out[5]= Sec[x] Sec[y] Sin[x + y]
In[6]:= TrigReduce[Coth[x] + Coth[y]]
Out[6]= Csch[x] Csch[y] Sinh[x + y]
In[7]:= TrigReduce[Sin[x]^4]
Out[7]= 1/8 (3 + Cos[4 x] - 4 Cos[2 x])
In[8]:= TrigReduce[2 Sin[x + y] Cos[x - y]]
Out[8]= Sin[2 x] + Sin[2 y]
Implementation notes¶
Algorithm. builtin_trigreduce_impl is the product/power-direction inverse of
TrigExpand: it rewrites products and integer powers of single-argument circular
and hyperbolic trig calls into single trig calls of compound (sum / multiple)
arguments, using the classical product-to-sum and power-reduction identities
Sin[a] Cos[b] = (Sin[a+b] + Sin[a-b]) / 2 Cos[a] Cos[b] = (Cos[a+b] + Cos[a-b]) / 2
Sin[a] Sin[b] = (Cos[a-b] - Cos[a+b]) / 2 Sin[x]^2 = (1 - Cos[2x]) / 2
Cos[x]^2 = (1 + Cos[2x]) / 2 (and the Sinh/Cosh hyperbolic analogues)
The pipeline (trig canonicalizer suppressed throughout so the Sin/Cos
intermediate forms are not re-collapsed before the rules fire):
- To Sin/Cos.
ReplaceRepeatedwithtrig_factor_to_sincosrewrites reciprocal heads (Tan/Cot/Sec/Cscand hyperbolic) asSin/Cosratios so the product-to-sum rules can see them. - Iterate to a fixed point (bounded at 16 iterations): alternate
ReplaceRepeatedwithtrig_reduce_rules(the power-reduction and product-to-sum identities, with each constructed compound argument wrapped inExpand[...]so e.g.Sin[(x+y)-(x-y)]canonicalizes toSin[2y]before the surrounding trig head sees it) and anExpandstep. The iteration is required becauseExpandre-exposesCos[2x]^2terms hidden inside(1 - Cos[2x])^2/4after a power-reduction pass onSin[x]^4, which the rule then reduces again. The 16-iteration cap covers exponents throughSin[x]^65536. - Together to combine over a common denominator so numerators appear as a
single
Plusfor the collapse rules. - Angle-addition collapse.
ReplaceRepeatedwithtrig_reduce_collapse: coefficient-aware reverse angle-addition (c. Sin[a]Cos[b] + c. Cos[a]Sin[b] :> c Sin[a+b], etc.) plus negative-argument cancellation rules guarded bySameQ[Expand[a+b], 0]that foldSin[a-b] + Sin[b-a](which the auto-evaluator leaves un-reduced) to zero. - From Sin/Cos.
ReplaceRepeatedwithtrig_factor_from_sincosrestoresTan/Sec/Csc(and hyperbolic) where the ratio/reciprocal shape survives. - Final canonicalisation:
ExpandthenTogether, distributing outer scalars (1/2 (2 Cos[a+b] + 2 Sin[a+b])flattens) while keeping irreducible fractions like(3 - 4 Cos[2x] + Cos[4x])/2as a single rational.
Data structures. Four static rule lists (trig_factor_to_sincos,
trig_reduce_rules, trig_reduce_collapse, trig_factor_from_sincos) parsed in
trigsimp_init. Times is ATTR_ORDERLESS, so the matcher commutes factors and
only one direction of each product-to-sum pair needs to be written. Threads over
List (via ATTR_LISTABLE) and over equation/inequality/logic heads; memoized
through the active FactorMemo via the builtin_trigreduce wrapper.
- Applies the classical product-to-sum identities (Sin·Cos, Sin·Sin,
Attributes: Listable, Protected.
Implementation status¶
Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
References¶
- Source:
src/simp/trigsimp.c - Specification:
docs/spec/builtins/elementary-functions.md
Notes & additional examples¶
Worked examples¶
A square is linearised through the power-reduction formula:
Higher powers spread across several harmonics:
A product of squares reduces to a single fourth harmonic — exactly the
integrand identity behind Integrate[Sin[x]^2 Cos[x]^2, x]:
The product-to-sum identity for two sines appears directly: