roger: thanks very much for your response. the code in my lecture notes does include the case where each person is a member of his network.
when i look at your code , i realize that i would be best to keep using the Wolfram language (WL) rather than learn to master J as you have (of course that's understandable since you created J ). i am too set in my programming ways to learn a new language at this point unless it offers me something very substantially better than WL. also, i happen to truly love WL and have been a WL evangelist for 25 years, using it in my four books and teaching WL with great pleasure to over a thousand students at university in a variety of fields (physics, chemistry, biology, sociology and economics/business) and in industry and government, how WL works in 6.5 hrs. of lecture (sometimes given in four 90 minute classroom increments and sometimes in one day-long lecture). you know, i first learned WL - which has been unfortunately been called Mathematica which is the software that is built upon WL because stephen wolfram took 25 years before announcing this spring the imminent release of WL as a stand-alone app to run on computers and mobile devices (as J already does) - by reading "Life; Nasty, Brutish and Short" and thereby learning array processing. and implementing it in WL while also incorporating anonymous functions (J was not yet created) and nested function calls and eventually rules and pattern matching. To this day, i consider consider myself an APL'er by nature who delights in the creation of unreadable one-liner code LOL. but i do it in WL which is far easier for me to read and work with (and i actually first became aware of APL through stephen's Mathematica book). i also recall returning to the US from an APL meeting in Toronto (where i gave a tutorial on WL) sitting next to Arthur Whitney on the plane, running side-by-side comparisons of the speed of my writing and running pieces of code in WL with Arthur's doing the same with his just created K language on our respective MacBooks. As a scientist (i'm a theoretical condensed soft matter physicist), i have available a community of well over a million users of Mathematica to teach WL to and to learn from and that's too great resource for me to not use (if i could get them each to buy at least one of my books, i'd be financially set LOL). so i guess i'll continue to use WL and to wear my custom-made black WL icon logo T-shirt. richard On Thu, Sep 12, 2013 at 7:53 PM, Roger Hui <[email protected]>wrote: > If we modify the input slightly, by requiring that each person is a member > of his own network (i.e. the reflexive closure), then the computation can > be more concise: > > c=: 0;1 5 7;2 ;3;4 1 2;5 2 7;6 2;7 8;8 5 > c > ┌─┬─────┬─┬─┬─────┬─────┬───┬───┬───┐ > │0│1 5 7│2│3│4 1 2│5 2 7│6 2│7 8│8 5│ > └─┴─────┴─┴─┴─────┴─────┴───┴───┴───┘ > <@~././ |: (,|."1) (I.#&>c),.;c > ┌─┬───────┬───────┬─┬─────┬─────────┬───┬───────┬─────┐ > │0│1 5 7 4│2 4 5 6│3│4 1 2│5 2 7 1 8│6 2│7 8 1 5│8 5 7│ > └─┴───────┴───────┴─┴─────┴─────────┴───┴───────┴─────┘ > > > > > > On Thu, Sep 12, 2013 at 4:27 PM, Roger Hui <[email protected] > >wrote: > > > s=: '';5 7;'';'';1 2;2 7;2;8;5 > > s > > ┌┬───┬┬┬───┬───┬─┬─┬─┐ > > ││5 7│││1 2│2 7│2│8│5│ > > └┴───┴┴┴───┴───┴─┴─┴─┘ > > j -.&.>~ </./ |: (,.~j),(,|."1) (;s),.(#&>s)#j=. i.#s > > ┌┬─────┬─────┬┬───┬───────┬─┬─────┬───┐ > > ││4 5 7│4 5 6││1 2│1 8 2 7│2│1 5 8│7 5│ > > └┴─────┴─────┴┴───┴───────┴─┴─────┴───┘ > > > > (;s),.(#&>s)#j are the relationships in ordered pair form; (,|."1) of > that > > catenates the reversed ordered pairs; and the rest of the code puts the > > information back into the form in which s is specified. > > > > Repeated application of this processes is the transitive closure (friend > > of my friend is also my friend, *ad infinitum*). > > > > > > > > On Thu, Sep 12, 2013 at 3:44 PM, Richard Gaylord <[email protected] > >wrote: > > > >> here's some code in the Wolfram Programming Language (the language > >> underlying Mathematica) illustring the use of pattern matching. > >> > >> > >> > >> Society is a list of the attribute lists of people. As an illustration, > we > >> will create a society consisting of eight people, each with two > >> attributes. > >> In each person's attribute list, > >> the first element (which is a number) represents the person's name , > >> > >> the second element which is a list of numbers) is a list of the names of > >> the members of the person's social network. > >> > >> > >> society = {{1, {5, 7}}, > >> {2, {}}, > >> {3, {}}, > >> {4, {1, 2}}, > >> {5, {2, 7}}, > >> {6, {2}}}, > >> {7, {8}}, > >> {8, {5}}} > >> > >> We can modify society so that anyone who is in another person's social > >> network includes that person in their own social network (i.e., > reciprocal > >> social connections). > >> > >> symSoc = society /. > >> {a_Integer, b_} :> {a, Union[b, Cases[society, {x_, {___, a, ___}} :> > >> x]]} > >> > >> symSoc = {{1, {4, 5, 7}}, > >> {2, {4, 5, 6}}, > >> {3, {}}, > >> {4, {1, 2}}, > >> {5, {1, 2, 7, 8}}, > >> {6, {2}}, > >> {7, {1, 5, 8}}, > >> {8, {5, 7}}} > >> > >> how would this be done in J? > >> > >> note: a pdf of the note set on the Wolfram Language in which the > >> expressions for society and symSoc appear on p. 42 can be downloaded at > >> > >> http://library.wolfram.com/infocenter/MathSource/5216 > -- *"Those who would sacrifice freedom for security deserve neither." - Benjamin Franklin* *"I think that the very notion that equations are a good approach to describing the natural world is a little bizarre." - Stephen Wolfram* * * ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
