# Reading off coefficients as array

Suppose I have a series expansion with non-associative characters, i.e., $$1**2**3**4**5 + 2**3**4**5**1 + \cdots$$

Then I want to make some array which produces $$A[1]= \{1,2,3,4, 5\}, A[2]=\{2,3,4,5,1\}, \cdots$$ Is there any nice command for this? I am considering the arbitrary length. i.e., $$1**2*3**4**5**6**7**8**9 \cdots +$$ as an input and reading ordered coefficients like above.

• NestList[RotateLeft, Range@#, #] &[5] ? Commented Mar 22, 2021 at 5:59

SeedRandom[1]
expr = Plus @@ (NonCommutativeMultiply @@ RandomInteger[{1, 10}, #] & /@
RandomInteger[{2, 9}, 3])

   6 ** 10 ** 5 ** 4 +
10 ** 1 ** 4 ** 3 ** 3 ** 7 +
9 ** 1 ** 1 ** 2 ** 1 ** 2 ** 9 ** 4

 List @@@ List @@ expr

 {{6, 10, 5, 4}, {10, 1, 4, 3, 3, 7}, {9, 1, 1, 2, 1, 2, 9, 4}}


You can also replace Plus and NonCommutativeMultiply with List:

expr /. Plus | NonCommutativeMultiply -> List

{{6, 10, 5, 4}, {10, 1, 4, 3, 3, 7}, {9, 1, 1, 2, 1, 2, 9, 4}}

• thanks Now I can read coefficients easily! Commented Mar 22, 2021 at 6:13