aggregation of related elements in a list
- To: mathgroup at smc.vnet.net
- Subject: [mg61542] aggregation of related elements in a list
- From: leigh pascoe <leigh at cephb.fr>
- Date: Sat, 22 Oct 2005 00:35:27 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I would like to construct a function to transform a list of integers
into a list of lists of related members. Suppose we have the finite list
and a test function ( relatedQ[x_,y_,n_] ) that decides whether two
elements are related. The actual test may vary, but returns True or
False for any two elements as a function of n (n is an independent
variable not the number of elements in the list}.
I would like to process this list to aggregate those members that are
related either directly to each other or to a common element. For
example if x1 is unrelated to any other element in the list, x2 is
related to x5 but not x7 and x5 is related to x7 etc. would produce the
list of lists
To take a specific example, assume we have the list
and that application of the relatedQ, test to all possible pairs yields
the list of related pairs
Using the list and the list of related pairs we can deduce the desired
list of lists as
If 6 were not in the original list we would get instead
I have tried to develop a Mathematica function or procedure to produce
this list, but am having trouble achieving it. Can anyone help?
The algorithm I have been trying to implement is:
- form a list of all related pairs and singletons in the original list
by comparing all pairs to prlist
- then compare the first element in the resulting list with each of the
others in that list and form the Union of all those where (Intersection
- delete all pairs retained for the Union.
- repeat the process for the next element in the list and so on.
The following ugly code seems to work on some lists, but with others
gives me an error message, presumably an objection to a dynamic
redefinition of the list inside a Do statement.
I have been doing much Intersecting, Unions, Deletions, nested loops and
Sowing, but have so far been unable to Reap the result that I want!
There should be a simple recursive function that will do what I want,
but I can't find it.
Thanks for any help
Prev by Date:
Re: Re: Double integral of a piecewise-constant function
Next by Date:
Apply and up/down value questions
Previous by thread:
tracking precision through ndsolve, findfit, regress, etc
Next by thread:
Re: aggregation of related elements in a list