Skip to content

TrigFactor ​

The factoring counterpart of TrigExpand/TrigReduce — rewrites sums and differences of Sin/Cos into products.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageTrigFactor!
TrigFactor(expr)an identity for expr, factored via the sum-to-product/half-angle identities or, for a genuine polynomial in Sin(x0)/Cos(x0), via Factor after substitution.
Typed signatures
TypePackageApplies
(expression) -> expressionanalyticalways

Domain: Transformations

Details
  • Two independent strategies, tried in order: (1) the four sum-to-product identities (sin⁡a±sin⁡b\sin a\pm\sin b, cos⁡a±cos⁡b\cos a\pm\cos b) and the two half-angle identities (1±cos⁡x1\pm\cos x), matched structurally (each confirmed against wolframscript's own TrigFactor, up to reordering); (2) failing that, if expr is a genuine polynomial in Sin(x0)/Cos(x0) for one common argument x0 (Add/Subtract/Negate/Multiply/an integer Power over those two atoms and x0-free numeric coefficients), substitute u = Sin(x0), v = Cos(x0), factor the polynomial in u, v with compute-engine's own Factor, and substitute back.
  • The polynomial strategy is provably correct (whatever Factor returns for the polynomial IS one, so re-substituting reconstructs the identity) but does not chase the extra trig identities Wolfram's own TrigFactor sometimes prefers — e.g. it rewrites sin⁡2x−cos⁡2x\sin^2x-\cos^2x as −2sin⁡(π/4−x)sin⁡(π/4+x)-2\sin(\pi/4-x)\sin(\pi/4+x) rather than the plain difference-of-squares (sin⁡x−cos⁡x)(sin⁡x+cos⁡x)(\sin x-\cos x)(\sin x+\cos x) this file gives; both are correct identities, just not the same factorization.
  • Declined: two DIFFERENT trig arguments mixed together outside the four named pairs (e.g. sin⁡acos⁡b\sin a\cos b), any transcendental other than Sin/Cos, and an argument-dependent (non-integer) exponent.

Examples

Basic #

sin⁡a+sin⁡b=2sin⁡(a+b2)cos⁡(a−b2)\sin a+\sin b = 2\sin(\frac{a+b}2)\cos(\frac{a-b}2)

live ↗
InTrigFactor(sin⁡(a)+sin⁡(b))\mathrm{TrigFactor}(\sin(a)+\sin(b))Out2sin⁡(a+b2)cos⁡(a−b2)2\sin(\frac{a+b}{2})\cos(\frac{a-b}{2})

cos⁡a−cos⁡b=−2sin⁡(a+b2)sin⁡(a−b2)\cos a-\cos b = -2\sin(\frac{a+b}2)\sin(\frac{a-b}2)

live ↗
InTrigFactor(cos⁡(a)−cos⁡(b))\mathrm{TrigFactor}(\cos(a)-\cos(b))Out−2sin⁡(a+b2)sin⁡(a−b2)-2\sin(\frac{a+b}{2})\sin(\frac{a-b}{2})

1−cos⁡x=2sin⁡2(x/2)1-\cos x = 2\sin^2(x/2)

live ↗
InTrigFactor(1−cos⁡(x))\mathrm{TrigFactor}(1-\cos(x))Out2sin⁡(x2)22\sin(\frac{x}{2})^2
Scope #

the polynomial strategy — sin⁡2x+2sin⁡xcos⁡x+cos⁡2x=(sin⁡x+cos⁡x)2\sin^2x+2\sin x\cos x+\cos^2x = (\sin x+\cos x)^2

live ↗
InTrigFactor(sin⁡(x)2+2sin⁡(x)cos⁡(x)+cos⁡(x)2)\mathrm{TrigFactor}(\sin(x)^2+2\sin(x)\cos(x)+\cos(x)^2)Out(sin⁡(x)+cos⁡(x))2(\sin(x)+\cos(x))^2

A difference of squares factors as (sin⁡x−cos⁡x)(sin⁡x+cos⁡x)(\sin x-\cos x)(\sin x+\cos x)

live ↗
InTrigFactor(sin⁡(x)2−cos⁡(x)2)\mathrm{TrigFactor}(\sin(x)^2-\cos(x)^2)Out(sin⁡(x)−cos⁡(x))(sin⁡(x)+cos⁡(x))(\sin(x)-\cos(x))(\sin(x)+\cos(x))

The factoring is applied inside, but the whole stays symbolic

live ↗
InTrigFactor(1sinh⁡(x)+cosh⁡(x+y)sin⁡(x)2−cos⁡(x)2)\mathrm{TrigFactor}(\frac{1}{\sinh(x)}+\frac{\cosh(x+y)}{\sin(x)^2-\cos(x)^2})OutTrigFactor(1sinh⁡(x)+cosh⁡(x+y)sin⁡(x)2−cos⁡(x)2)\mathrm{TrigFactor}(\frac{1}{\sinh(x)}+\frac{\cosh(x+y)}{\sin(x)^2-\cos(x)^2})
About
Examples6
Checked againstWolfram Language 5 agree1 differ
CrosswalkWolfram Language

Implementation

primitive · kernela kernel — an algorithm over mutable state that would not be readable as a tree

nativeenginetypescriptpackages/symbols/analysis/analytic/src/trig-factor.ts

See also: ExpToTrig, FunctionExpand