# SplitBy with exponents

I have

SplitBy[Flatten@ Join[{1, 2^n}, Drop[List @@@
Expand[Evaluate[(((FindSequenceFunction[ With[{nn = #}, (Rest@(List @@
Series[Nest[# + Log[#] &, x, #], {x, 1, 10}] & /@ Range[0, 10]))
[[All, 3, nn + 1]]]] & /@ Range[0, 4] /. # -> n)[[All, 1]]))]],
2]], #*2^(_Integer + # n) &]

(*
{{1}, {2^n}, {2^(-2 + n)}, {-2^(-2 + 2 n)}, {2^(-2 + n)/9},
{-2^(-3 + 2 n)}, {7/9 2^(-3 + 3 n)}, {2^(-5 + n)/21},
{-(17/9) 2^(-6 + 2 n)}, {7/3 2^(-5 + 3 n)}, {-(181/63) 2^(-6 + 4 n)}}
*)


but I wopuld like the reult to be

(*
{{1}, {2^n, 2^(-2 + n), 2^(-2 + n)/9}, {-2^(-2 + 2 n), -2^(-3 + 2 n),
-(17/9) 2^(-6 + 2 n)}, {7/9 2^(-3 + 3 n), 7/3 2^(-5 + 3 n)},
{-(181/63) 2^(-6 + 4 n)}, {2^(-5 + n)/21}}
*)


where the results are sorted by #*2^(Integer+# n), but clearly there is a problem with my SplitBy.

• So what do you really have problems with, SplitBy[], or SortBy[]? May 17, 2015 at 15:58
• @Guesswhoitis. ah yes, SplitBy May 17, 2015 at 15:59
• Well, in any event, SplitBy[] requires a two-argument test function that tests when two things are the "same", for some definition of "same" for grouping. How do you say that two of your objects are the same? May 17, 2015 at 16:09
• @Guesswhoitis. I would like to group, for example, {2^(n), 2^(n-4), 2^(n-5)} separately to {2^(2n), 2^(2n-4), 2^(2n-5)} (basically by multiple of n exponent + some random integer). May 17, 2015 at 16:13
• Try Coefficient[PowerExpand[Log2[#]], n] & as the second argument of SplitBy[]. May 17, 2015 at 17:00

I offer the following function with the caveat that I have not tested it on a computer with Mathematica. That being said, SplitBy[] expects a function that is applied to the elements of a list that, within a group, should give the same result.
On a hunch, I went with Coefficient[PowerExpand[Log2[#]], n] &; Log2[] is supposed to isolate only the exponent, but it can only do that after an application of PowerExpand[]. Having isolated the exponent, we then use Coefficient[] to look at the number multiplying n.
• I used SplitBy[SortBy[...,condition &],condition &], but I don't know whether this was necessary. May 17, 2015 at 17:18
• Not if I dont use Plus@@ ...list. May 17, 2015 at 17:22