Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

AW: Sorting with Infinity

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23518] AW: [mg23513] Sorting with Infinity
  • From: Wolf Hartmut <hwolf at debis.com>
  • Date: Tue, 16 May 2000 22:29:51 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com


	-----Ursprüngliche Nachricht-----
	Von:	Jack Goldberg [SMTP:jackgold at math.lsa.umich.edu]
	Gesendet am:	Dienstag, 16. Mai 2000 08:45
	An:	mathgroup at smc.vnet.net
	Betreff:	[mg23513] Sorting with Infinity

	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? 

Hello Jack,

Sort uses canonical order, and such obviously just recognizes Infinity as a
Symbol, see:

	Sort[{7, -2, Infamity, -Infinity, Infinity, 1, -Infamity}]

	{-2, 1, 7, -Infamity, Infamity, -Infinity, Infinity}
	
This is the same as explicitly using the ordering function OrderedQ:

	Sort[{7, -2, -Infinity, Infinity, 1}, OrderedQ[{#1, #2}] &]

	{-2, 1, 7, -Infinity, Infinity}

But choosing numerical ordering helps:

	Sort[{7, -2, -Infinity, Infinity, 1}, Less]

	{-Infinity, -2, 1, 7, Infinity}

	
Hartmut



  • Prev by Date: Re: Parametric Solving Question From 14 Year Old
  • Next by Date: Re: Sorting with Infinity
  • Previous by thread: Mathematica crashing, short cut keys
  • Next by thread: Complex Plane