0
$\begingroup$

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.

$\endgroup$
6
  • $\begingroup$ So what do you really have problems with, SplitBy[], or SortBy[]? $\endgroup$ May 17, 2015 at 15:58
  • $\begingroup$ @Guesswhoitis. ah yes, SplitBy $\endgroup$
    – martin
    May 17, 2015 at 15:59
  • $\begingroup$ 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? $\endgroup$ May 17, 2015 at 16:09
  • $\begingroup$ @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). $\endgroup$
    – martin
    May 17, 2015 at 16:13
  • 1
    $\begingroup$ Try Coefficient[PowerExpand[Log2[#]], n] & as the second argument of SplitBy[]. $\endgroup$ May 17, 2015 at 17:00

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ I used SplitBy[SortBy[...,condition &],condition &], but I don't know whether this was necessary. $\endgroup$
    – martin
    May 17, 2015 at 17:18
  • $\begingroup$ That would work; sort them by their exponents before grouping. Doesn't the original list have the things ordered by their exponents already? $\endgroup$ May 17, 2015 at 17:21
  • $\begingroup$ Not if I dont use Plus@@ ...list. $\endgroup$
    – martin
    May 17, 2015 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.