Consider a function f that is symmetric with regard to its two arguments i.e. f[x,y] == f[y,x]. Using Outer one can for instance build a correspondence matrix that computes some distance measure f between each two points in a list using
Outer[f, list, list]
This however computes every entry f[i, j] literally twice (since f[i, j] == f[j, i]) which is unnecessary. Is there a way to beat Outer (which is quite fast already) using this knowledge?
I tried
Table[Plus[list[[i]], list[[j]]], {i, 1, Length[list]}, {j, i, Length[list]}]
which only computes each entry once but is orders of magnitude slower even for simple examples like f = Plus; list = Range[1000].
{I, list}, since list is aListand not an integer. Perhaps you meanLength[list]. If you want to useTable, then try:Table[f[I,j], {I, Length[list},{I,j}]to compute the unique values, and then fill in the rest with a simple Table call. – David G. Stork Jan 08 '18 at 06:53Table[expr, {i, {i1, i2, i3, ...}}]and thusTable[expr_, {i, someList}]is a valid syntax variant forTable. Its the 5th entry in the syntax overview in the documentation. – Sascha Jan 08 '18 at 06:56Tablevariant with input likelist=Range[10]and for this the Part specification works out. – Sascha Jan 08 '18 at 07:00Tableexpression in the question – Sascha Jan 08 '18 at 07:07Plusis special in a number of way; andOuter[Plus,...]is a special case. It might not be a good test example? – Michael E2 Jan 08 '18 at 21:11