|
[Date Index]
[Thread Index]
[Author Index]
Re: Changing the Natural Sort Order
- To: mathgroup at smc.vnet.net
- Subject: [mg50709] Re: [mg49144] Changing the Natural Sort Order
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Fri, 17 Sep 2004 01:17:35 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message-----
>From: David Park [mailto:djmp at earthlink.net]
To: mathgroup at smc.vnet.net
>Sent: Monday, July 05, 2004 10:54 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg50709] [mg49144] Changing the Natural Sort Order
>
>
>Dear MathGroup,
>
>Is it possible to change the natural sort order of symbols
>that is used in Sort?
>
>I would like something like the following statement (that does
>not work).
>
>Assuming[d < b < c, Sort[{a, b, c, d, f}]]
>
>giving the desired output
>
>{a,d,b,c,f}
>
>I won't be sorting simple lists of symbols, but lists of
>similar, but unspecified, expressions that contain the
>symbols. For example...
>
>{h[x,g[a]], h[x,g[b]], h[x,g[c]], h[x,g[d]], h[x,g[f]]}
>
>which should give
>
>{h[x,g[a]], h[x,g[d]], h[x,g[b]], h[x,g[c]], h[x,g[f]]}
>
>Is there any way to do this?
>
>David Park
>djmp at earthlink.net
>http://home.earthlink.net/~djmp/
>
>
>
>
David,
perhaps you can exploit this idea:
In[9]:=
Block[{c0, c1, c2, c3, c4},
Block[{a, b, c, d, f}, {a, b, c, d, f} = Hold /@ {c0, c2, c3, c1, c4};
Sort[{a, b, c, d, f}]] /.
Thread[Hold /@ {c0, c2, c3, c1, c4} -> {a, b, c, d, f}]]
Out[9]=
{a, d, b, c, f}
In[10]:=
Block[{c0, c1, c2, c3, c4},
Block[{a, b, c, d, f}, {a, b, c, d, f} = Hold /@ {c0, c2, c3, c1, c4};
Sort[{h[x, g[a]], h[x, g[b]], h[x, g[c]], h[x, g[d]], h[x, g[f]]}]] /.
Thread[Hold /@ {c0, c2, c3, c1, c4} -> {a, b, c, d, f}]]
Out[10]=
{h[x, g[a]], h[x, g[d]], h[x, g[b]], h[x, g[c]], h[x, g[f]]}
I didn't do the work: generate & execute this code from the assumptions; and *all* Symbols occuring should be wrapped according to the new Ordering (including g,h,x, but that wasn't important in this very example).
--
Hartmut
Prev by Date:
Re: Re: Log[4]==2*Log[2]
Next by Date:
Re: Re: Technical Publishing Made Easy with New Wolfram Publicon Software
Previous by thread:
Bizarre bug
Next by thread:
GUIKit
|