# select the symbolic terms of an array

is it possible to extract the symbolic variables from an array ?. For example:

s = {(1+0.1I)a*b*c,4*a*b*c,(0.5-2i)*j*k^3,0.88*b*d^2}


I would like to have another array that contains only the different symbolic terms, like this:

ss = {a*b*c,b*d^2,j*k^3}


After that, I would like to identify the position of each term

Thanks

Clear["Global*"]

s = {(1 + 0.1 I) a*b*c, 4*a*b*c, (0.5 - 2 i)*j*k^3, 0.88*b*d^2};

ss = s /. {Complex[_, _] :> 1, Plus[_, __] :> 1,
a_?NumericQ * z_ :> z} // Union

(* {a b c, b d^2, j k^3} *)

Position[s, #*_] & /@ ss

(* {{{1}, {2}}, {{4}}, {{3}}} *)

• Thanks, it works perfectly. Could you explain a bit the code, I don't understand what to do after the "plus".
– Nico
Mar 27, 2020 at 19:06
• a_?NumericQ * z_ :> z specifies that the product of a numeric factor (a) with an expression (z) is replaced by the just the expression, i.e., drop the numeric factor. It could also be written as _?NumericQ*z_ :> z, that is, the numeric factor does not need to be given a name since it does not appear on the RHS of the rule. Look in the documentation for ReplaceAll Mar 27, 2020 at 19:18
• Thanks so much, :D, And the last question if I wanted the second code to search exactly for the term, for example if I have {a, aa, ab} and I want to find the position of the term "a", which is {1}, do you know how this could be done?, I think this code does not discriminate the length of the expression
– Nico
Mar 27, 2020 at 19:20
• Position[{a, aa, ab}, a] Read the documentation for Position` Mar 27, 2020 at 19:23
• but If I put Position[{a, aa, ab}, a], print the three value. I use
– Nico
Mar 27, 2020 at 19:32