# Summation and product term expressed in Mathematica [duplicate]

I have the following term which I would like to express correctly in Mathematica:

$$\sum_{i=1}^{m}\frac{1}{\prod_{j=1,j\neq i}^m(\rho_i-\rho_j)}$$

This means that for $$m=3$$ for example you should get the following

$$\frac{1}{(\rho_1-\rho_2)(\rho_1-\rho_3)}+\frac{1}{(\rho_2-\rho_1)(\rho_2-\rho_3)}+\frac{1}{(\rho_3-\rho_2)(\rho_3-\rho_1)}$$

• There is no duplication since the other question does not have a sum and thus the $i$ is not well defined. I chose to put a new question instead of creating some confusion.
– Y.L
Jun 5, 2019 at 14:44

f[m_Integer] := Sum[1/Product[(Subscript[\[Rho], i] - Subscript[\[Rho], j]),
{j, Complement[Range[1, m], {i}]}], {i, m}]

f[3]


• Thanks @Chris Degnen this is easy to implement into my calculations.
– Y.L
Jun 5, 2019 at 15:28
With[{m = 3},
Sum[1/Product[ρ[i] - ρ[j], {j, DeleteCases[Range[m], i]}], {i, m}]]


$$\frac{1}{(\rho (2)-\rho (1)) (\rho (2)-\rho (3))}+\frac{1}{(\rho (3)-\rho (1)) (\rho (3)-\rho (2))}+\frac{1}{(\rho (1)-\rho (2)) (\rho (1)-\rho (3))}$$

Here I used ρ[i] instead of Subscript[ρ,i] because subscripts are a pitfall for new users.

Update: It's easier to use Drop instead of DeleteCases, as in @kglr's solution:

With[{m = 3},
Sum[1/Product[ρ[i] - ρ[j], {j, Drop[Range[m], {i}]}], {i, m}]]

ClearAll[f1, f2]
f1[m_] := Module[{a = Array[ρ, m]}, m /
HarmonicMean @ MapIndexed[Apply[Times] @* Drop, Outer[Subtract, a, a]]

f2[m_] := Module[{a = Array[ρ, m]},
m Moment[ MapIndexed[Apply[Times] @* Drop, Outer[Subtract, a, a], -1]]

f1[3]


f1[4]


And @@ (f1[#] == f2[#] & /@ Range[100])


True