Given input expressions, I want to extract the function and again extract its element.

For example, given my input

 f= b1 g[1, {a1,a2,a3}] + b2 g[1,{a11,a22,a33}] + b3 g[1,{a111,a222,a333}] 

First I want to extract as follows : $\{ \{a1,a2,a3\},\{a11,a22,a33\}, \{a111,a222,a333\} \}$

Since b1,b2,b3 are arbitrary I don't want to use


Any ideas or comments?

  • 4
    $\begingroup$ Just use Cases[f, {__}, {3}] $\endgroup$
    – flinty
    May 5, 2023 at 11:48
  • 2
    $\begingroup$ Or, Cases[f, _List, All] $\endgroup$
    – Bob Hanlon
    May 5, 2023 at 15:00

1 Answer 1

Cases[f, Times[b_. ,  g[k__]] :> {b, Last@k}, 1] // Transpose

{{b1, b2, b3}, {{a1, a2, a3}, {a11, a22, a33}, {a111, a222, a333}}}


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.