I'm going to describe a toy example here which I'm hoping with some help, I can then soup up into the more complex application I have in mind.
Suppose the input is a list of lists, and for now take the example:
list = {{1,1,3,7}, {2}, {1,2,2,2,3,8}}
Quite simply, I want to sum over list
and produce a certain polynomial in formal symbols $P_1, P_2, ...,P_N$ for some $N$ I choose. My main conceptual obstacle is how to implement these symbols in Mathematica!
There is a simple rule for the polynomial--for the example list above, the polynomial should be:
$$P_{1}^{2} \cdot P_{2} \,+ \,P_{1} \,+\, P_{1}^{3} \cdot P_{3}$$
because in the first entry of list
there are two elements repeated once and one element repeated twice. Similarly, in the third entry, there are three elements repeated once, and one element repeated three times, which explains the last term. So the subscripts of the $P$'s should encode number of times an element repeats.
I have a schematic idea of how this should go, but can't really get started because I don't know how to deal with these formal symbols! I want to first sum over list
. For a given entry, say list[[i]]
, I want to take a product over m
with range {m,1, Max[list[[i]]]}
. And for each iteration of this product, I want to produce one of the $P$'s where the subscript is Count[list[[i]],m]
.
I hope this makes sense, and I'd appreciate any help!
Total[Times @@@ (Subsuperscript[p, ##] & @@@ Normal@GroupBy[Tally@#, Last, Length] & /@ list)]
works? (you can work withIf
to remove power 1) $\endgroup$Subsuperscript
but hopefully with that I can soup this up to what I really need. If you cared to make this an answer, I'd accept it. $\endgroup$Subsuperscript
on symbolic calculations. See this Q&A for a longer explanation of alternatives and the reasoning behind them. Probably @BenIzd may want to reassess their advise? $\endgroup$