trigonometric simplification



The function trigrat is powerful, but it sometimes makes a huge mess; for example, when x is declared complex, try trigrat(asin(1+sin(x))).
Interactively, a user can often guess when trigrat is going to make a mess, but inside a program it's just a guess.

Unfortunately trigrat is the only function I know of that will simplify the following to zero:

   %i*(sin((74*%pi)/41)-sin((3108*%pi)/41))-cos((3108*%pi)/41)+cos((74*%pi)/41);

The functions trigsimp, trigreduce, and trigexpand do not simplify this expression to zero.  Is there another trig simplification
function or some option variable that will crunch expressions similar to

  %i*(sin((74*%pi)/41)-sin((3108*%pi)/41))-cos((3108*%pi)/41)+cos((74*%pi)/41)

to zero?

I'm thinking of something that would work something like the (untested) function buddy:

Reduce x to the interval (-%pi,pi]

  (%i111) sawtooth(x) := x - 2*%pi*ceiling((x-%pi)/(2*%pi))$

Use periodicity to simplify cosine and sine expressions

(%i112) buddy(e) := (
  e : trigexpand(e),
  e : subst(['sin = lambda([s], if ratnump(s/%pi) then sin(sawtooth(s)) else sin(s)),
                'cos = lambda([s], (s : s + %pi/2, if ratnump(s/%pi) then sin(sawtooth(s)) else sin(s)))],e),
  trigreduce(e))$

Example:

  (%i154) e : sin(x+(1907*%pi)/89)+cos(x-(13*%pi)/178)$

  (%i155) buddy(e);
  (%o155) 0

Oops--trigrat doesn't crunch e to zero:

 (%i156) trigrat(e);
 (%o156) -(%i*(sin((178*x+165*%pi)/178)+sin((178*x-13*%pi)/178)-cos((89*x+38*%pi)/89)-cos((89*x-51*%pi)/89))+cos((178*x+165*%pi)/178)-cos((178*x-13*%pi)
 /178)+sin((89*x+38*%pi)/89)-sin((89*x-51*%pi)/89))/2

Am I mistaken that e crunches to zero? Maybe, but I don't think so:

 (%i159) float(subst(x=14/9,e));
 (%o159) 7.3552275381416621*10^-15

--Barton