> 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.
Note that you don't need to factor 6, only gcd(6,2). To handle the case
54*3^n, you do
gcd(54,3)=3 so => (54/3) * 3^(n+1) = 18*3^(n+1)
gcd(18,3)=3 so => (18/3) * 3^(n+2) ... etc.
And there are various refinements to this, where you do the gcd with a
power of 3 in the first place....
> Maybe a separate function could be made available to try much harder
> to simplify these numerical products.
Yes, I think general simplification should not handle
3^n*6^n = 2^n*3^(2*n)
6^n*15^m = 2^n*3^(n+m)*5^m
3^n*9^m = 3^(n+2*m)
but leave them to an improved version of 'factor'. The reverse
transformation could also be useful...
-s