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$ Commented Mar 22, 2021 at 5:59

1 Answer 1

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
    Commented Mar 22, 2021 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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