1
$\begingroup$

I have an expression like this:

3*Subscript[v, 0]^3*Subscript[v, 1]^8*Subscript[v, 2]^7*Subscript[v, 3]^2

I would like to extract the exponents and put them into a list sorted by the subscript and separate the constant factor. So I would like to have an output like this:

{3, {3,8,7,2}}

And in case the constant is missing in the expression, it should be output as 1, naturally. How can I achieve this? I tried sequence patter matching, but I did not succeed.

$\endgroup$
2
$\begingroup$

you can use

CoefficientRules

and get

{{3, 8, 7, 2} -> 3}

If we call your expression a then this should do the work

##&@@@CoefficientRules@a    

{{3, 8, 7, 2}, 3}

$\endgroup$
0
$\begingroup$

Try this (expr is your expression):

expr /. Times -> List /. {a_Integer, b__} :> {a, {b}}
MapAt[Total@Outer[Exponent, #, Array[Subscript[v, #] &, 4, 0]] &, %, 2]
$\endgroup$

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.