how to handle roots of unity symbolically ?



hello all,

I'm trying to simplify expressions with W being a root of unity.
so that : W^n = 1

I wrote a function, but I'm not happy with it

8<---------------------------------------------
simplifie(a,n) := block(
  local(b, decomposition, taille, premier, expression),
  b:ratsubst(1, w^n, b),
  decomposition:ifactors(n),
  taille:length(decomposition),
  for indice:1 thru taille do (
    premier:decomposition[indice][1],
    division:n/premier,
    expression : sum(w^(i*division),i,0,premier-1),
    b:ratsubst(0, expression, b)
  ), b
);
--------------------------------------------->8

this simplifies some expressions, but fails with others, for example:
when w^6=1 , w^2-w+1 is not simplified, when 0 was expected...

does someone knows the right way to do this ?