Mathematica-Converting a polynomial function into a list and extracting the terms from it

Mathematica-Converting a polynomial function into a list and extracting the terms from it

For example

v[a_, b_, c_] := a^2 + b^2 + c^2
vl[a_, b_, c_] := Module[{x, y, z}, 
                         MonomialList[v[x, y, z]] /. {x -> a, y -> b, z -> c}]
vl[1, 1, 1]
(*
 -> {1,1,1}
*)

I dont see a reason not to pre-compute the list, like this:

v[a_, b_, c_] := a^2 + b^2 + c^2

Block[{a, b, c},
 vf[a_, b_, c_] = MonomialList[v[a, b, c]];
]

Testing:

vf[q, r, s]
vf[1, 1, 1]
{q^2, r^2, s^2}

{1, 1, 1}

the definition of vf:

Definition[vf]
vf[a_, b_, c_] = {a^2, b^2, c^2}

Mathematica-Converting a polynomial function into a list and extracting the terms from it

Leave a Reply

Your email address will not be published. Required fields are marked *