home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / sci / math / symbolic / 3345 < prev    next >
Encoding:
Text File  |  1992-12-30  |  1.4 KB  |  38 lines

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