Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
find subsets
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
r_poetic  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 11:46
Newsgroups: comp.soft-sys.math.mathematica
From: r_poetic <radford.scha...@mms.gov>
Date: Sat, 7 Nov 2009 11:46:49 +0000 (UTC)
Local: Sat 7 Nov 2009 11:46
Subject: find subsets
Hello,
here is a quick question from a novice.

First, generate a list of subsets using Subsets or KSubsets
functions.

Ns = KSubsets[{a,b,c,d,e},3] = {{a,b,c},{a,b,d},{a,b,e},{a,c,d}, etc.}

How can one infer from that list a list of its members that contain
given elements, e.g. a list of members that contain b, or those that
contain both b and c? For illustration:

Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}

I keep thinking there must be a direct way to do this using Select or
some other function?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tomas Garza  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 11:52
Newsgroups: comp.soft-sys.math.mathematica
From: Tomas Garza <tgarz...@msn.com>
Date: Sun, 8 Nov 2009 11:52:42 +0000 (UTC)
Local: Sun 8 Nov 2009 11:52
Subject: Re: find subsets
Try

In[2]:= Select[Ns,MemberQ[#,b]&&MemberQ[#,c]&]

Out[2]= {{a,b,c},{b,c,d},{b,c,e}}

Tomas


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Hanlon  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 12:05
Newsgroups: comp.soft-sys.math.mathematica
From: Bob Hanlon <hanl...@cox.net>
Date: Sun, 8 Nov 2009 12:05:18 +0000 (UTC)
Local: Sun 8 Nov 2009 12:05
Subject: Re: find subsets

Ns = Subsets[{a, b, c, d, e}, {3}];

Needs["Combinatorica`"]

Ns == KSubsets[{a, b, c, d, e}, 3]

True

Cases[Ns, {___, b, ___}]

{{a, b, c}, {a, b, d}, {a, b, e}, {b, c, d}, {b, c, e}, {b, d, e}}

% == Cases[Ns, _?(! FreeQ[#, b] &)]

True

%% == Select[Ns, ! FreeQ[#, b] &]

True

Cases[Ns, {___, b, c, ___}]

{{a, b, c}, {b, c, d}, {b, c, e}}

% == Cases[Ns, {___, b, ___, c, ___}]

True

%% == Cases[Ns, _?(! FreeQ[#, b] && ! FreeQ[#, c] &)]

True

Bob Hanlon

---- r_poetic <radford.scha...@mms.gov> wrote:

=============
Hello,
here is a quick question from a novice.

First, generate a list of subsets using Subsets or KSubsets
functions.

Ns = KSubsets[{a,b,c,d,e},3] = {{a,b,c},{a,b,d},{a,b,e},{a,c,d}, etc.}

How can one infer from that list a list of its members that contain
given elements, e.g. a list of members that contain b, or those that
contain both b and c? For illustration:

Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}

I keep thinking there must be a direct way to do this using Select or
some other function?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Helen Read  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 12:07
Newsgroups: comp.soft-sys.math.mathematica
From: Helen Read <h...@together.net>
Date: Sun, 8 Nov 2009 12:07:48 +0000 (UTC)
Local: Sun 8 Nov 2009 12:07
Subject: Re: find subsets

r_poetic wrote:
> Hello,
> here is a quick question from a novice.

> First, generate a list of subsets using Subsets or KSubsets
> functions.

> Ns = KSubsets[{a,b,c,d,e},3] = {{a,b,c},{a,b,d},{a,b,e},{a,c,d}, etc.}

It's a good practice to use names that begin with a lower case letter,
to avoid conflict with the names of built-in symbols and functions.

> How can one infer from that list a list of its members that contain
> given elements, e.g. a list of members that contain b, or those that
> contain both b and c? For illustration:

> Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}

> I keep thinking there must be a direct way to do this using Select or
> some other function?

Select together with MemberQ will do the job. First, generate the subsets:

sets = Subsets[{a, b, c, d, e}, {3}]

This will select the ones that contain b:

Select[sets, MemberQ[#, b] &]

This will select the ones that contain both b and c:

Select[sets, (MemberQ[#, b]) && (MemberQ[#, c]) &]

And this will select the ones that contain b or c:

Select[sets, (MemberQ[#, b]) || (MemberQ[#, c]) &]

--
Helen Read
University of Vermont


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leonid Shifrin  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 12:08
Newsgroups: comp.soft-sys.math.mathematica
From: Leonid Shifrin <lsh...@gmail.com>
Date: Sun, 8 Nov 2009 12:08:00 +0000 (UTC)
Subject: Re: find subsets
Hi,

for initial set not too large, the following function should do:

Clear[getSubsets]
getSubsets[sets_List, all_List] :=
  Select[sets, Complement[all, #] === {} &];
getSubsets[sets_List, all_List, {}] := getSubsets[sets, all];
getSubsets[sets_List, all_List, oneOf_List] :=
  Select[getSubsets[sets, all], MemberQ[#, Alternatives @@ oneOf] &];

It will find all sublists which contain *all* of the elements in <all>
argument and *at least one* of the elements of <oneOf> argument (which can
be omitted altogether). For example:

In[1] :=
ClearAll[a, b, c, d, e, f, g, h];
sets = Subsets[{a, b, c, d, e, f, g, h}, {6}];

In[2]:=
getSubsets[sets,{a,b,g},{}]

Out[2]:=
{{a,b,c,d,e,g},{a,b,c,d,f,g},{a,b,c,d,g,h},{a,b,c,e,f,g},{a,b,c,e,g,h},{a,b ,c,f,g,h},{a,b,d,e,f,g},{a,b,d,e,g,h},{a,b,d,f,g,h},{a,b,e,f,g,h}}

In[3]:=
getSubsets[sets,{a,b},{c,d}]

Out[3]=
{{a,b,c,d,e,f},{a,b,c,d,e,g},{a,b,c,d,e,h},{a,b,c,d,f,g},{a,b,c,d,f,h},{a,b ,c,d,g,h},{a,b,c,e,f,g},{a,b,c,e,f,h},{a,b,c,e,g,h},{a,b,c,f,g,h},{a,b,d,e, f,g},{a,b,d,e,f,h},{a,b,d,e,g,h},{a,b,d,f,g,h}}

If the initial set is large, the above approach may turn inefficient due to
a vary large number of elements in the initial list of subsets. You may want
then to take the requirement of presence of certain elements into account
already at the point when you generate the subsets.

Regards,
Leonid


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bill Rowe  
View profile   Translate to Translated (View Original)
 More options 8 Nov, 12:08
Newsgroups: comp.soft-sys.math.mathematica
From: Bill Rowe <readn...@sbcglobal.net>
Date: Sun, 8 Nov 2009 12:08:23 +0000 (UTC)
Local: Sun 8 Nov 2009 12:08
Subject: Re: find subsets
On 11/7/09 at 6:47 AM, radford.scha...@mms.gov (r_poetic) wrote:

>First, generate a list of subsets using Subsets or KSubsets
>functions.
>Ns = KSubsets[{a,b,c,d,e},3] = {{a,b,c},{a,b,d},{a,b,e},{a,c,d},
>etc.}
>How can one infer from that list a list of its members that contain
>given elements, e.g. a list of members that contain b, or those that
>contain both b and c? For illustration:
>Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}
>I keep thinking there must be a direct way to do this using Select
>or some other function?

In[4]:= Cases[
 Subsets[{a, b, c, d, e},
  3], _?(Length[Intersection[#, {c, b}]] == 2 &)]

Out[4]= {{b,c},{a,b,c},{b,c,d},{b,c,e}}


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
rs_poetic  
View profile   Translate to Translated (View Original)
 More options 9 Nov, 10:47
Newsgroups: comp.soft-sys.math.mathematica
From: rs_poetic <schantz-pla...@cox.net>
Date: Mon, 9 Nov 2009 10:47:26 +0000 (UTC)
Local: Mon 9 Nov 2009 10:47
Subject: Re: find subsets
Thanks to all! Helpful and good lessons in Mathematica!
RS

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google