Determining if n is of the form m^k?



>>>>> "Stavros" == Stavros Macrakis <macrakis at gmail.com> writes:

    >> 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.

    Stavros> Note that you don't need to factor 6, only gcd(6,2).  To handle the case

    Stavros>      54*3^n, you do

    Stavros> gcd(54,3)=3 so => (54/3) * 3^(n+1) = 18*3^(n+1)
    Stavros> gcd(18,3)=3 so => (18/3) * 3^(n+2) ... etc.

Yes, this is probably something that the times simplifier should do.

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

    Stavros> Yes, I think general simplification should not handle

    Stavros>     3^n*6^n = 2^n*3^(2*n)
    Stavros>     6^n*15^m = 2^n*3^(n+m)*5^m
    Stavros>     3^n*9^m = 3^(n+2*m)

I agree.  Although it would be nice if we could do this.  I think some
of the limit bugs happen because maxima thinks 4^n grows much faster
than 2^(2*n).  (Or vice versa.  I can't remember.)

Ray