•An Algebraic Transformation

A user in the MathGroup wanted Mathematica to change

      ((-1 + a) x - a y)2     into    ((a - 1) x + a y)2

Allan Hayes gave the solution in the next cell . This solution has to be entered on a case by case basis .

     Clear[a, x, y] ;
     ((-1 + a) x - a y)^2 /. (p_^n_ ? EvenQ) :> Collect[-p, x]^n
    ((1 - a) x + a y)2

FactorRule in the next cell works and the rule doesn't need to know what variables are involved.  The only disadvantage of FactorRule is that it's much more complicated than the first solution.

     FactorRule = expr : (__Plus)^(n_ ? EvenQ) :>  
      
         (Map[-# &, Part[expr, 1], 1]^n /. 
      
           Times[-1, a_, b___] :> -a * b) ;
     ((-1 + a) x - a y)^2 /. FactorRule
     ((1 - a) x + a y)2