1
$\begingroup$

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.

$\endgroup$
1
  • 1
    $\begingroup$ NestList[RotateLeft, Range@#, #] &[5] ? $\endgroup$
    – wuyudi
    Mar 22 at 5:59
1
$\begingroup$
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}}
$\endgroup$
1
  • $\begingroup$ thanks Now I can read coefficients easily! $\endgroup$
    – phy_math
    Mar 22 at 6:13

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.