# Why do I get a different answer from the use of TrigExpand?

This is an old post but I get two different answers from Mathematica 9.0.1.0

f[x_] =  Sin[x]^3 + Cos[x]^2 /.
AlgebraicRules[{Sin[x]^2 + Cos[x]^2 == 1, Sin[3*x] == 1/2}]

(* 1 - Sin[x]^2 + Sin[x]^3 *)

g[x_] = Sin[x]^3 + Cos[x]^2 /.
AlgebraicRules[{Sin[x]^2 + Cos[x]^2 == 1, TrigExpand[Sin[3*x]] == 1/2}]

(*  7/8 + (3 Sin[x])/4 - Sin[x]^2 *)

Plot[{f[x], g[x]}, {x, 0, 2 π }] The plot shows that f[x] and g[x] are clearly different. It appears that the use of TrigExpand[Sin[3*x]] in g[x] messes up the answer.

• AlgebraicRules became obsolete in MMA 3 according to reference.wolfram.com/legacy/v5_2/functions/AlgebraicRules. In fact I can't even find a documentation page describing its use and purpose and ?AlgebraicRules gives me some odd things too. – Jonie Jul 23 '13 at 23:57
• Just replace = with := – Hubble07 Jul 24 '13 at 8:05

First note that you don't use the delayed assignment :=, so both of your right-hand side expressions are evaluated where you define them. (Otherwise, you would get the same result for concrete numeric values as TrigExpand[a] == a.)

I don't know what you're attempting to solve but I think I can answer your question anyway. Note that since TrigExpand[Sin[3 x]] gives an polynomial of Sin[x] and Cos[x], the AlgebraicRules in the g expression case is solved only in them as variables, whilst in the f expression case also in terms of Sin[3 x]. Consequently, in the f case, the second equation is not accounted for and what you get is only reduction with respect to the first equation. More specifically, what you get are results of the following terms rewriting rules:

(* f *) Sin[x]^3 + Cos[x]^2 /. { Cos[x]^2 -> 1 - Sin[x]^2,  Sin[3 x] -> 1/2 }
(* g *) Sin[x]^3 + Cos[x]^2 /. { Cos[x]^2 -> 1 - Sin[x]^2,  Sin[x]^3 -> (-1 + 6 Sin[x])/8 }


Cf.:

AlgebraicRules[{Sin[x]^2 + Cos[x]^2 == 1, TrigExpand[Sin[3 x]] == 1/2}][]
AlgebraicRules[{Sin[x]^2 + Cos[x]^2 == 1, Sin[3 x] == 1/2}][]