1
$\begingroup$

Suppose I have some complicated expressions, I want to extract some terms with $\{a_1, \cdots, a_n\}$ out of the complicated expressions without considering coefficients.

For example, here is my trial.

 exp1 = a1*a2*24 + a1*a2*a3*kk*25 + a1*a2^2 + a1*a2*a3*34;
 MonomialList[exp1, {a1, a2, a3}]

Then what I have is

 {a1 a2^2, a1 a2 a3 (34 + 25 kk), 24 a1 a2}

I want to extract the $a_i$'s not the coefficients in my list, i.e., I want to eliminate (34+25kk) and the number 24 out of my results without imposing //.{34+25*kk}->1, 24->1

What I want to do is for given expressions, I want to find which combinations of $a_i$'s are present in the list form.

$\endgroup$

2 Answers 2

2
$\begingroup$
Clear["Global`*"];
exp1 = a1*a2*24 + a1*a2*a3*kk*25 + a1*a2^2 + a1*a2*a3*34;
DeleteCases[List @@ exp1, _?NumericQ | kk, {2}]

{a1 a2, a1 a2^2, a1 a2 a3, a1 a2 a3}

$\endgroup$
2
$\begingroup$

Using CoefficientRules and FromCoefficientRules:

p = a1*a2*24 + a1*a2*a3*kk*25 + a1*a2^2 + a1*a2*a3*34;

vars = {a1, a2, a3};

rep = Rule[x_, y_] /; y =!= 1 :> Rule[x, 1];

cr = CoefficientRules[#, vars] & /@ List @@ p /. rep

FromCoefficientRules[#, vars] & /@ cr

(*{a1 a2, a1 a2^2, a1 a2 a3, a1 a2 a3}*)
$\endgroup$

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.