Re: Sorting with Infinity
- To: mathgroup at smc.vnet.net
- Subject: [mg23524] Re: [mg23513] Sorting with Infinity
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Tue, 16 May 2000 22:29:56 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Actually the command is not too arcane. Simply use: In[5]:= Sort[{7, -2, -Infinity, Infinity, 1}, Less] Out[5]= {-Infinity, -2, 1, 7, Infinity} The point is that Mathematica does "know" things like: In[7]:= -Infinity < -2 Out[7]= True or In[8]:= 23 < Infinity Out[8]= True but unless you specifically tell it to use Less in sorting it sorts Infinity as a Symbol rather than using Less. This has really nothing to do with Infinity, for example compare this with: In[11]:= Sort[{1, 4, Pi, E}] Out[11]= {1, 4, E, Pi} In[12]:= Sort[{1, 4, Pi, E}, Less] Out[12]= {1, E, Pi, 4} Andrzej -- Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/ http://platon.c.u-tokyo.ac.jp/andrzej/ on 5/16/00 3:44 PM, Jack Goldberg at jackgold at math.lsa.umich.edu wrote: > Hi group; > > I construct lists which may look like this > > {7,-2,-Infinity,Infinity,1} > > When this list is sorted by using Sort, I get > > {-2,1,7,-Infinity,Infinity} > > I would prefer, naturally, > > {-Infinity,-2,1,7,Infinity} > > This is easy to do if one doesn't care about elegance. Without > spelling out the obvious details, here are a few kludges: > > (1) Replace Infinity by 10^15, Sort then switch back to Infinity. > (2) Use Append and Prepend after Sort and deleting infinities. > (3) RotateRight after Sort and switch signs on infinities > > Anyone got a "cute" solution say by using a sorting function or > perhaps some arcane command unknown to mere mortals? > > Jack > > > >