This is kind of a continuation of this question.

I want to automate these 2 steps on Mathematica once I give an integer $N$.

  • generate a list of variables $\{a_i\}_{i=1}^{i=N}$
  • then for some function like $f(x) = e^{x}$ or $f(x) = \sin^2(x)$ compute an expression like $\prod\limits_{i \neq j} f(a_i - a_j)$ or $\sum\limits_{i < j} f(a_i - a_j)$ or $\prod\limits_ {i,j} f(a_i - a_j)$

( - and then hopefully integrate such expressions over all $a_i$...)

I am having to type these expressions by hand for every $N$ and that is very hard once $N$ gets large (one would typically have $\binom{N}{2}$ terms to type by hand!) I would like to know how this can be automated - since I would typically need to to use large $N$.

(...also, help with that previous question would be great!)


Implementing for example $\prod_{j>i}^Nf(a_i-a_j)$:

nup = 4;
Times @@ Flatten@Table[f[a[i] - a[j]], {i, 1, nup - 1}, {j, i + 1, nup}]

where nup is $N$.

| improve this answer | |
  • $\begingroup$ ...or With[{nup = 6}, Times @@ f /@ Subtract @@@ Subsets[Array[a, nup], {2}]] $\endgroup$ – J. M.'s discontentment Oct 16 '12 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.