MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Converting a mapping into a well-defined function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56544] Re: Converting a mapping into a well-defined function
  • From: "Carl K. Woll" <carl at woll2woll.com>
  • Date: Thu, 28 Apr 2005 02:40:46 -0400 (EDT)
  • References: <79344CBB6297454F86DD3106ADCC76CC82F394@mail3.nwfwmd.state.fl.us>
  • Sender: owner-wri-mathgroup at wolfram.com

Gilmar wrote:

> Dear Carl:
> Your map sorts the set A.
> For example, if A={{47, 53}, {31, 61}, {43, 53}, {43, 47}, {37, 61}};
> then using your f[x_] module, we get f[A]= {{31, 61}, {37, 61}, {43,
> 53}, {47, 53}}, when it should be:
> {{47, 53}, {31, 61}, {43, 53}, {37, 61}}; i.e. an unsorted set.
> Nevertheless I don't mind having your version since it can still come
> handy.

It's a simple matter to modify the code to return an unsorted version:

f[x_]:=Module[{tmp},
 tmp = Transpose[{x[[All,1]],Range[Length[x]],x[[All,2]]}];
 tmp = Split[Sort[tmp], #1[[1]]===#2[[1]]&][[All,1]];
 tmp[[Ordering[tmp[[All,2]]]]][[All,{1,3}]]
 ]

Testing:

A={{47, 53}, {31, 61}, {43, 53}, {43, 47}, {37, 61}};

f[A]
{{47, 53}, {31, 61}, {43, 53}, {37, 61}}

[snip]

Carl Woll



  • Prev by Date: MLGetByteString
  • Next by Date: Re: Floor[] Not An Integer?
  • Previous by thread: Re: Converting a mapping into a well-defined function
  • Next by thread: Re: Converting a mapping into a well-defined function