Determining if n is of the form m^k?



>>>>> "Raymond" == Raymond Toy <raymond.toy at ericsson.com> writes:

    Raymond> Is there a fast and easy way (beside repeated division) to determine
    Raymond> if the integer n is of the form m^k?

    Raymond> One of the outstanding bugs is that maxima leaves 2*2^k as is, instead
    Raymond> of simplifying it to 2^(k+1).  However a*a^k is simplified to a^(k+1).

    Raymond> I have a fix for 2*2^k (and other integers), but it currently only
    Raymond> works for that case.  It won't handle 4*2^k or 1/4*2^k.  Hence, I'm
    Raymond> looking a fast and simple way to determine if n is of the form m^k.

For now, I'm just going to compute m^p until m^p >= n.  Then if m^p =
n, I'm done and have what I need.

So now maxima can do things like:

2*2^k -> 2^(k+1)
27*3^k -> 3^(k+3)
2^k/16 -> 2^(k-4)

But it still gets weird things:

3*2*2^k -> 6*2^k
2*2^k*3 -> 3*2^(k+1)
3/4*2^k -> 3/4*2^k
3*2^k/4 -> 3*(k-2)

6*2^k -> 6*2^k

I think it would be nice if 6*2^k became 3*2^(k+1), but that would
require factoring 6 (easy).  In general, factoring would be hard, and
perhaps not worth the effort.

Maybe a separate function could be made available to try much harder
to simplify these numerical products.

Ray