1
$\begingroup$

I was wondering how to write a function $ F (r, q, n, f) $ in Mathematica, defined in this way:

$$F(r,q,n,f):=\sum_{i_0=1}^q f(i_0) \Biggl(\sum_{i_1=i_0+1}^{q+1} f(i_1)\biggl(\sum_{i_2=i_1+1}^{q+2} f(i_2)\Bigl(\ldots(\sum_{i_n=i_{n-1}+1}^{q+n} f(i_n))\ldots \Bigl) \biggl) \Biggl)$$ es. $$ \sum_{i_0=1}^2 f(i_0) \Biggl(\sum_{i_1=i_0+1}^{3} f(i_1)\biggl(\sum_{i_2=i_1+1}^{4} f(i_2) \biggl) \Biggl)=f(1)f(2)f(3)+f(1)f(2)f(4)+f(1)f(3)f(4)+ +f(2)f(3)f(4)$$

does an operator already exist that can be used in this way?

trying to write this function on mathematica I realized that the "recursion" is variable and I don't know how to program in this case.

thank you

$ \ $

$ \ $

further example

$$ \sum_{i_0=1}^1 f(i_0) \Biggl(\sum_{i_1=i_0+1}^{2} f(i_1)\biggl(\sum_{i_2=i_1+1}^{3} f(i_2)(\sum_{i_3=i_2+1}^{4} f(i_2)) \biggl) \Biggl)=f(1)f(2)f(3)f(4)$$

$\endgroup$
1
$\begingroup$

What you want is already built-in as SymmetricPolynomial[]:

SymmetricPolynomial[3, Array[f, 4]]
   f[1] f[2] f[3] + f[1] f[2] f[4] + f[1] f[3] f[4] + f[2] f[3] f[4]

SymmetricPolynomial[4, Array[f, 4]]
   f[1] f[2] f[3] f[4]

but otherwise, Bill's suggestion can be vastly simplified using Sum[] and Product[]'s ability to take a list of indices:

Sum[Product[f[k], {k, idx}], {idx, Subsets[Range[4], {3}]}]
   f[1] f[2] f[3] + f[1] f[2] f[4] + f[1] f[3] f[4] + f[2] f[3] f[4]
$\endgroup$
2
$\begingroup$

Consider this

Total[Map[Times@@#&,Map[f,Subsets[{1,2,3,4},{3}],{-1}]]]

which gives you this

f[1]*f[2]*f[3] + f[1]*f[2]*f[4] + f[1]*f[3]*f[4] + f[2]*f[3]*f[4]

and this

Total[Map[Apply[Times,#]&,Map[f,Subsets[{1,2,3,4},{4}],{-1}]]]

which gives you this

f[1]*f[2]*f[3]*f[4]

That seems close to what you want to accomplish. All you have to do is see how to connect the parameters of your function F to the constants in those expressions.

If you look up Total and Map and Apply and Times and Subsets in the help system and study how those work I think you might be able to see how to do this and raise your programming skill to the next level in the process. I suggest you start with the innermost expressions first and after you understand those then add the next layer of expression and repeat until you understand the whole thing.

$\endgroup$
  • 1
    $\begingroup$ (+1) You can shorten it to Total@Subsets[Times @@ f /@ Range[4], {3}] $\endgroup$ – kglr Sep 14 at 1:57
  • 1
    $\begingroup$ @PatrickDanzi, very good point. I guess Times should be outside Subsets for the general case, e.g., Total[Times @@@ Subsets[Map[f, Range[4], {-1}], {1}]] $\endgroup$ – kglr Sep 14 at 10:02
  • $\begingroup$ @kglr I have this problem if i write "Total@Subsets[Times @@ f / @ Range [4], {2}]" I get "f [1] f [2] + f [1] f [3] + f [ 2] f [3] + f [1] f [4] + f [2] f [4] + f [3] f [4] " but if I define f as a fraction "f[x _]: = a [x]/b[x]" instead of getting "(a [1] a [2]) / (b [1] b [2]) + (a [1] a [3]) / (b [1] b [3]) + (a [2] a [3]) / (b [2] b [3]) ..." (which is good for me) I get " a [1] a [2] + a [ 1] a [3] + ... + a [1] / b [1] + a [2] / b [1] + ... + 1 / (b [1] b [2]) + .. . + 1 / (b [1] b [3]) + ... " $\endgroup$ – Patrick Danzi Sep 14 at 10:11
  • $\begingroup$ @kglr great! thank you so much $\endgroup$ – Patrick Danzi Sep 14 at 10:13

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.