Question:How to factor a polynomial with compound variables?

Question:How to factor a polynomial with compound variables?

Maple

I have an equation as follows:

By inspection one can see that the last three terms can be simplified (factored) to

How can I coerce Maple to do this? None of the available tools seem to be getting close to this. A partial solution is like this: Writ a procedure as follows:

Fac:=proc(xpr,a,b);
tmp:=xpr+(a^2+2*a*b+b^2);
return tmp-(a+b)^2;
end proc;

and then call it:

Fac(lhs(eq),k0,2*Pi*n/L)=rhs(eq);

to get

which is what I want. But procedure Fac() is not general at all; e.g. it fails if the overall sign of the polynomial terms are different. There does not seem to be any way in Maple to determine the sign of a term in the sum of lhs(eq), I can only find ways to determine signs of a simple indeterminate. I'd like to make this procedure more general (which is trivial enough for a human) but I just cannot find any tools in Maple to support this.

Any ideas out there?

Mac Dude.

﻿