MathGroup Archive 2007

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

Search the Archive

RE: Sort with -Infinity fails

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73867] RE: [mg73822] Sort with -Infinity fails
  • From: "Tony Harker" <a.harker at ucl.ac.uk>
  • Date: Fri, 2 Mar 2007 06:34:44 -0500 (EST)

The problem is that Sort is not a numeric function -- but if you define your
own comparison function it can be:

In[153]:=
l={2,-Infinity,-E,-1,0,1,E,Infinity,-2};
Sort[l]

Out[154]=
{-2,-1,0,1,2,-\[ExponentialE],\[ExponentialE],-∞,∞}

In[155]:=
Sort[l,#1<#2&]

Out[155]=
{-∞,-\[ExponentialE],-2,-1,0,1,2,\[ExponentialE],∞}

In[159]:=
Sort[l,Less]

Out[159]=
{-∞,-\[ExponentialE],-2,-1,0,1,2,\[ExponentialE],∞}

  Tony


Dr A.H. Harker
Department of Physics and Astronomy
University College London
Gower Street
London
WC1E 6BT

 

]->-----Original Message-----
]->From: Tom Aldenberg [mailto:Tom.Aldenberg at rivm.nl] 
]->Sent: 01 March 2007 11:17
]->To: mathgroup at smc.vnet.net
]->Subject: [mg73822] Sort with -Infinity fails
]->
]->Dear MathGroup,
]->
]->Minus Infinity (-Infinity) is smaller than -8, but Sort does 
]->not sort it as expected.
]->Is there a Real minus Infinity?
]->
]->
]->In[75]:=
]->      -Infinity < -8
]->Out[75]=
]->      True
]->
]->In[76]:=
]->      Sort[{-Infinity, -8, 5}]
]->Out[76]=
]->      {-8, 5, -∞}
]->
]->
]->Regards,
]->
]->Tom Aldenberg
]->
]->_____________________________________________________________
]->_______________
]->
]->DISCLAIMER:  http://www.rivm.nl/disclaimer.htm
]->
]->
]->



  • Prev by Date: Re: change filename automatically in Export Command
  • Next by Date: Re: Beginner--Problem with FilledPlot
  • Previous by thread: Re: NDSolve. Getting the final values
  • Next by thread: Re: Sort with -Infinity fails