MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica commands needed to solve problem in Set Theory!

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43632] Re: Mathematica commands needed to solve problem in Set Theory!
  • From: poujadej at yahoo.fr (Jean-Claude Poujade)
  • Date: Sat, 27 Sep 2003 04:57:53 -0400 (EDT)
  • References: <bkp284$d0k$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

This is the way I use Mathematica to solve this kind of problem.
(I hope my notations explain themselves)
The tool generating all combinations is of course "Outer".

In[1]:= adele = Outer[a,{"r","nr"},{"g","ng"},{"s","ns"},{"t","nt"}]//
   Flatten[#,3]&;
adele[[1]]
Out[2]= a[r,g,s,t]
Length[adele]
Out[3]= 16

In[4]:= betty = Outer[b,{"r","nr"},{"g","ng"},{"s","ns"},{"t","nt"}]//
   Flatten[#,3]&;

In[5]:= carol = Outer[c,{"r","nr"},{"g","ng"},{"s","ns"},{"t","nt"}]//
   Flatten[#,3]&;

In[6]:= doris = Outer[d,{"r","nr"},{"g","ng"},{"s","ns"},{"t","nt"}]//
   Flatten[#,3]&;

In[7]:= abcd = Outer[List,adele,betty,carol,doris]//Flatten[#,3]&;
abcd[[1]]
Out[8]= {a[r,g,s,t],b[r,g,s,t],c[r,g,s,t],d[r,g,s,t]}

In[9]:= Length[abcd]
Out[9]= 65536

In[10]:= greenSlenderCount[list4_] := Count[list4,_[_,"g","s",_]];
     redTallCount[list4_] := Count[list4,_["r",_,_,"t"]];
     slenderTallCount[list4_] := Count[list4,_[_,_,"s","t"]];
     greenRedCount[list4_] := Count[list4,_["r","g",_,_]];

In[14]:= abcd1 = Select[abcd,greenSlenderCount[#]==3&];
Length[abcd1]
Out[15]= 3072

In[16]:= abcd2 = Select[abcd1,redTallCount[#]==2&];
Length[abcd2]
Out[17]= 648

In[18]:= abcd3 = Select[abcd2,slenderTallCount[#]==2&];
Length[abcd3]
Out[19]= 336

In[20]:= abcd4 = Select[abcd3,greenRedCount[#]==1&];
Length[abcd4]
Out[21]= 36

In[22]:= abcd5 = Cases[abcd4,{a[_,color_,_,_],b[_,color_,_,_],c[_,_,_,_],d[_,_,_,_]}];
Length[abcd5]
Out[23]= 18

In[24]:= abcd6 = Cases[abcd5,{a[_,_,_,_],b[color_,_,_,_],c[color_,_,_,_],d[_,_,_,_]}]
Out[24]= {{a[r,g,s,t],b[nr,g,s,t],c[nr,g,s,nt],d[r,ng,ns,t]},{a[r,g,s,t],b[nr,g,s,nt],
    c[nr,g,s,t],d[r,ng,ns,t]},{a[r,g,s,t],b[nr,g,s,nt],c[nr,g,s,nt],
    d[r,ng,s,t]},{a[nr,g,s,t],b[r,g,s,t],c[r,ng,ns,t],
    d[nr,g,s,nt]},{a[nr,g,s,nt],b[r,g,s,t],c[r,ng,s,t],
    d[nr,g,s,nt]},{a[nr,g,s,nt],b[r,g,s,t],c[r,ng,ns,t],d[nr,g,s,t]}}

In[25]:= abcd7 = Select[
    abcd6,#[[3,1]]!=#[[4,1]] && #[[3,2]]!=#[[4,2]] && #[[3,
                3]]!=#[[4,3]] && #[[3,4]]!=#[[4,4]]&] 
 
Out[25]= {{a[r,g,s,t],b[nr,g,s,t],c[nr,g,s,nt],d[r,ng,ns,t]},{a[nr,g,s,t],b[r,g,s,t],
    c[r,ng,ns,t],d[nr,g,s,nt]}}

In[26]:=abcd8 = Select[abcd7,#[[1,4]]==#[[4,4]]&] 
Out[26]= {{a[r,g,s,t],b[nr,g,s,t],c[nr,g,s,nt],d[r,ng,ns,t]}}
 
Meeting requirement 0 : 
    Adele is different from the three others, therefore she is the one
    Johnny prefers.
---
jcp


  • Prev by Date: Re: guidance in mathematica programming in pde
  • Next by Date: Re: Mathematica commands needed to solve problem in Set Theory!
  • Previous by thread: RE: Mathematica commands needed to solve problem in Set Theory!
  • Next by thread: Re: Mathematica commands needed to solve problem in Set Theory!