In each case, the monomials in x and y from the powers of u are unique. For
example, for u = a*x*y + y (btw should it really be a*x*y + b*y?), u has
the monomials x*y and y, u**2 has the monomials x**2*y**2, x*y**2, and
y**2, and so on. So all you need to do is pull together the various
monomials (I'll leave the combinatorial algorithm of going from something
like 2 to [(2, 2), (1, 2), (0, 2)] as an exercise to you), and see if it
factors, and then compare those factors to see if you can get a unique u
(and do this for each possible u that you want to test for). You could test
this with factor, but that won't tell you if you could have done it by
taking roots. A perhaps better way would be to find the relations that must
hold on a general generator and see if they are held (I think you can do
this with solve).

For example, for a*x*y + b*y, u**2 is a**2*x**2*y**2 + 2*a*b*x*y**2 +
b**2*y**2. So if you have A*x**2*y**2 + B*x*y**2 + C*y**2, for it to factor
as a u**2, A, B, and C must satisfy 2*B = sqrt(A)*sqrt(C). solve should be
able to handle this for you

In [52]: solve([1 - a**2, 4 - 2*a*b, 4 - b**2], [a, b])
Out[52]: [(-1, -2), (1, 2)]

In [53]: solve([1 - a**2, 4 - 2*a*b, 3 - b**2], [a, b])
Out[53]: []

Here x**2*y**2 + 4*x*y**2 + 4*y**2 factors, because 4 = 2*sqrt(1)*sqrt(4).
 And we even see from the solutions that u = x*y + 2*y or -x*y - 2*y.

You also could play around with using the extension flag to factor to
handle your square roots for you, but it is limited (e.g., it currently
won't handle symbolic square roots).

You know the limits of solve() better than I do, so maybe it won't always
be strong enough for you. For example, I wasn't able to use it to compute
the general relationship

In [51]: solve([A - a**2, B - 2*a*b, C - b**2], [a, b])
Out[51]: []

It's quite possible too that you could derive a general formula for the
relationships that must hold for a polynomial to factor as (X + Y)**n (and
if there is, you might even be able to find it in the literature).

That's a *very* rough sketch. Let me know if there is something unclear.

Aaron Meurer

p.s., for the other question, of how to make Poly work with Add generators,
I have no idea. Your best bet is to just do a substitution with a Dummy and
substitute back when you are done.


On Sun, May 12, 2013 at 9:34 PM, Chris Smith <smi...@gmail.com> wrote:

> How to recognize such things.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to