1 | initial version |
A symbolic form of sums and products can be obtained by keeping L in their expressions ; for example :
sum(c[L[i]], i, 0, len(L)-1)
Is mathematically equivalent to $\displaystyle\sum_{i\in L} c_i$, although the notation is $\displaystyle\sum_{i=1}^{\mathrm{len}(L)} c_{L_i}$ which is different...
(And differs also by the fact that Python list indexing is zero-based, wheras mathematical notation indexing is one-based, but this is another story...).
A similar trick may be applied for other cases ; the general principle is to add an indirection through the list of elements of nteres (or possibly through a dictionary or a set).