BeginPackage["CSM`TrigLinear`"]

TrigLinear::usage = "TrigLinear[e] expands products and powers of
	trigonometric functions."

Begin["`Private`"]

trigLinearRules = {
	Sin[x_] Cos[y_] :> Sin[x+y]/2 + Sin[x-y]/2,
	Sin[x_] Sin[y_] :> Cos[x-y]/2 - Cos[x+y]/2,
	Cos[x_] Cos[y_] :> Cos[x+y]/2 + Cos[x-y]/2,
	Sin[x_]^n_Integer?Positive :> (1/2 - Cos[2x]/2) Sin[x]^(n-2),
	Cos[x_]^n_Integer?Positive :> (1/2 + Cos[2x]/2) Cos[x]^(n-2)
}

SetAttributes[TrigLinear, Listable]

TrigLinear[expr_] :=
	FixedPoint[ Function[e, Expand[e //. trigLinearRules]], expr ]

End[]

Protect[TrigLinear]

EndPackage[]
