This is an instance of the transitive closure problem. In the matrix form it can be solved as +./ .*./~^:_ M , the power limit of repeated squaring by the or-and inner product.
On Thu, Sep 12, 2013 at 3:44 PM, Richard Gaylord <rjgayl...@gmail.com>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/ > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm