home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math.symbolic
- Path: sparky!uunet!cs.utexas.edu!swrinde!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!gaylord.slip.uiuc.edu!gaylord
- From: Richard J. Gaylord <gaylord@ux1.cso.uiuc.edu>
- Subject: all intersections of a list of sets
- Message-ID: <C03MqH.DGA@news.cso.uiuc.edu>
- X-Xxdate: Wed, 30 Dec 92 18:59:49 GMT
- Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
- X-Useragent: Nuntius v1.1.1d13
- Organization: University of Illinois
- Date: Thu, 31 Dec 1992 00:59:04 GMT
- X-Xxmessage-Id: <A767A2250F02164B@gaylord.slip.uiuc.edu>
- Lines: 24
-
- ulf wostner asked me how to return all of the intersections of a list of
- sets.
-
- eg.,
-
- AllIntersections[{{a,b,c},{b,c,d},{c,d,e}}]
- {{c}, {b, c}, {c, d}, {a, b, c}, {b, c, d}, {c, d, e}}
-
- he and i are surprised that Outer[Intersection, sets, sets] doesn't work
- at all {in fact, i can't figure out what its doing or why}.
-
- anyway, i made up a nested anonymous function kind of thing to do it.
-
- AllIntersections[set_] :=
- Union[Flatten[Map[(Map[Function[y, Intersection[#,y]], set])&,set], 1]]
-
- AllIntersections[{{a,b,c},{b,c,d},{c,d,e}}]
- {{c}, {b, c}, {c, d}, {a, b, c}, {b, c, d}, {c, d, e}}
-
- its functional but pretty near unreadable, even to me 5 minutes after i
- wrote it [anyone who says functional code is more readable than
- procedural code clearly hasn't read alot of anonymous function code].
-
- there ought to be a better yet still functional way. any suggestions?
-