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 8403151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:16:02+00:00 2026-06-09T22:16:02+00:00

While trying to generate power set for a given list, I came across this

  • 0

While trying to generate power set for a given list, I came across this function over the internet. There was no explanation, but testing suggests that it seems to work correctly. I am not able to understand how this function is working. I will be thankful for any such explanations.

generateSubset [] = [[]]
generateSubset (x:xs) = let p = generateSubset xs in p ++ map (x:) p
  • 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-09T22:16:03+00:00Added an answer on June 9, 2026 at 10:16 pm

    Here’s a property of powersets that’s easy to prove: P(A ∪ B) = {a ∪ b | a ∈ P(A), b ∈ P(B)}. In particular, if we decompose a particular set S into an element s and all the elements S’ that are not s, then

    P(S) = P({s} ∪ S')
         = {a ∪ b | a ∈ P({s}), b ∈ P(S')}.
    

    Now, P({s}) is small enough that we can compute it by hand: P({s}) = {{}, {s}}. Using this fact, we learn

    P(S) = {a ∪ b | a ∈ {{}, {s}}, b ∈ P(S')}
         = {b | b ∈ P(S')} ∪ {{s} ∪ b | b ∈ P(S')}
         = P(S') ∪ {{s} ∪ b | b ∈ P(S')}
         = let p = P(S') in p ∪ {{s} ∪ b | b ∈ p}
    

    That is, one way to compute the powerset of a non-empty set is to choose an element, compute the powerset for the remainder, then either add or don’t add the element to each of the subsets. The function you showed simply turns this into code, using lists as a representation of sets:

    -- P         ({s} ∪ S') = let p = P(S')             in p  ∪ {{s} ∪ b | b ∈ p}
    generateSubset (x:xs)   = let p = generateSubset xs in p ++     map (x:) p
    

    The only thing left is to give a base case for the recursion, and that just comes straight from the definition of a powerset:

    -- P          ({}) = {{}}
    generateSubset []  = [[]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while trying to generate a proxy from this WebService (http://scdemo14.infor.com:9014/axis/services/wb:wsclocks-inbound?wsdl) I'm receiving this error
I am getting this exception while trying to generate a .PDF file from my
While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
I am getting an error while trying to run this Application ... the error
While trying to generate a pdf using ExpertPdf.HtmlToPdf, it's using a lot of memory.
I'm having an issue while trying to generate some Java classes. C:\Users\kon\Desktop>wsimport -keep -verbose
I need to generate a report in .xls format, while trying to write the
While trying to generate the wsdl for my services I get the message: Handler
I've spent quite a while trying to figure this out. I am working on
I have this php code, with which I am trying to generate a popup

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.