Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7776933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:00:23+00:00 2026-06-01T18:00:23+00:00

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

  • 0

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 subsets (combinations) of k items
  • Find the product of each subset
  • Find the sum of all those products

I can express this in Python, and do the calculation pretty easily:

from operator import mul
from itertools import combinations
from functools import reduce
def sum_of_product_of_subsets(list1, k):
    val = 0
    for subset in combinations(list1, k):
        val += reduce(mul, subset)
    return val

I’m just looking for the closed form expression, so as to avoid the loop in case the set size gets big.

Note this is NOT the same as this question: Sum of the product over all combinations with one element from each group — that question is about the sum-of-products of a Cartesian product. I’m looking for the sum-of-products of the set of combinations of size k; I don’t think they are the same.

To be clear, for set(a, b, c, d), then:

k = 4 --> a*b*c*d
k = 3 --> b*c*d + a*c*d + a*b*d + a*b*c
k = 2 --> a*b + a*c + a*d + b*c + b*d + c*d
k = 1 --> a + b + c + d

Just looking for the expression; no need to supply the Python code specifically. (Any language would be illustrative, if you’d like to supply an example implementation.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:00:24+00:00Added an answer on June 1, 2026 at 6:00 pm

    These are elementary symmetric polynomials. You can write them using summation signs as in Wikipedia. You can also use Vieta’s formulas to get all of them at once as coefficients of a polynomial (up to signs)

    (x-a_1)(x-a_2)...(x-a_k) =
       x^k -
       (a_1 + ... + a_k) x^(k-1) +
       (a_1 a_2 + a_1 a_3 + ... + a_(k-1) a_k)) x^(k-2) +
       ... +
       (-1)^k a_1 ... a_k
    

    By expanding (x-a_1)(x-a_2)…(x-a_k) you get a polynomial time algorithm to compute all those numbers (your original implementation runs in exponential time).

    Edit: Python implementation:

    from itertools import izip, chain
    
    l = [2,3,4]
    
    x = [1]    
    for i in l:
        x = [a + b*i for a,b in izip(chain([0],x), chain(x,[0]))]
    print x
    

    That gives you [24, 26, 9, 1], as 2*3*4=24, 2*3+2*4+3*4=26, 2+3+4=9. That last 1 is the empty product, which corresponds to k=0 in your implementation.

    This should be O(N2). Using polynomial FFT you could do O(N log2 N), but I am too lazy to code that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get the exact name of the object that this
I call this a flash meeting, but maybe there is another more appropriate name.
Title pretty much sums it up. Is there a technical name given to a
If I set a session variable in Django, like: request.session[name] = name Is there
There is a design problem like this. Suppose you have a set of class
I have three tables like this: Person table: person_id | name | dob --------------------------------
Is there any name for the following DB table design: Basically we have generic
I'm just curious, but is there a name for the process using print statements
In my list there are some name of the input box, it follow the
I usually have to check things like: if ['Bob','Mary','John'].include? @user.name Is there a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.