Sum-of-Product of subsets

后端 未结 2 1778
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 16:12

Is there a name for this operation? And: is there a closed-form expression?

  • For a given set of n elements, and value k between 1 and n,
  • Take all subs
2条回答
  •  失恋的感觉
    2020-12-31 16:13

    I have just run into the same problem elsewhere and I might have an easier solution. Basically the closed form you are looking for is this one:

    (1+e_1)*(1+e_2)*(1+e_3)*...*(1+e_n) - 1

    where considering the set S={e_1, e_2, ..., e_n}

    Here is why:

    Let 'm' be the product of the elements of S (n=e_1*e_2*...*e_n).
    If you look at the original products of elements of subsets, you can see, that all of those products are divisors of 'm'.
    Now apply the Divisor function to 'm' (from now on called sigma(m) ) with one modification: consider all e_i elements as 'primes' (because we don't want them to be divided), so this gives sigma(e_i)=e_i+1 .

    Then if you apply sigma to m:

    sigma(m)=sigma(e_1*e_2*...*e_n)=1+[e_1+e_2+...+e_n]+[e_1*e_2+e_1*e_3+...+e_(n-1)*e_n]+[e_1*e_2*e_3+e_1*e_2*e_3+...+e_(n-2)]+...+[e_1*e_2*...*e_n]

    This is what the original problem was. (Except for the 1 in the beginning). Our divisor function is multiplicative, so the previous equation can be rewritten as following:

    sigma(m)=(1+e_1)*(1+e_2)*(1+e_3)*...*(1+e_n)
    There is one correction you need here. It is because of the empty subset (which is taken into account here, but in the original problem it is not present), which includes '1' in the sum (in the beginning of the firs equation). So the closed form, what you need is:
    (1+e_1)*(1+e_2)*(1+e_3)*...*(1+e_n) - 1

    Sorry, I can't really code that, but I think the computation shouldn't take more than 2n-1 loops.

    (You can read more about the divisor function here: http://en.wikipedia.org/wiki/Divisor_function)

提交回复
热议问题