Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7294

Re: Does Union[] reliably sort?

From markholtuk <markholtuk@googlemail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Does Union[] reliably sort?
Date 2011-12-17 07:40 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jchh16$i9r$1@smc.vnet.net> (permalink)
References <jca06e$a35$1@smc.vnet.net>

Show all headers | View raw


You can get an unsorted Union using a combination of Join and
DeleteDuplicates as follows:

In[1]:= mins = {{{2001, 1, 31}, 0.993268}, {{2002, 3, 31},
    1.01395}, {{2003, 6, 30}, 1.08647}, {{2005, 11, 30},
    1.14752}, {{2006, 9, 30}, 1.18938}, {{2007, 2, 28},
    1.19658}, {{2008, 1, 31}, 1.20432}, {{2011, 1, 31}, 1.37501}};

maxs = {{{2000, 10, 31}, 1.01816}, {{2001, 12, 31},
    1.02714}, {{2004, 2, 29}, 1.12702}, {{2005, 3, 31},
    1.16986}, {{2010, 10, 31}, 1.39026}};

uni = Union[maxs, mins]

Out[3]= {{{2000, 10, 31}, 1.01816}, {{2001, 1, 31},
  0.993268}, {{2001, 12, 31}, 1.02714}, {{2002, 3, 31},
  1.01395}, {{2003, 6, 30}, 1.08647}, {{2004, 2, 29},
  1.12702}, {{2005, 3, 31}, 1.16986}, {{2005, 11, 30},
  1.14752}, {{2006, 9, 30}, 1.18938}, {{2007, 2, 28},
  1.19658}, {{2008, 1, 31}, 1.20432}, {{2010, 10, 31},
  1.39026}, {{2011, 1, 31}, 1.37501}}

In[4]:= del = DeleteDuplicates[Join[maxs, mins]]

Out[4]= {{{2000, 10, 31}, 1.01816}, {{2001, 12, 31},
  1.02714}, {{2004, 2, 29}, 1.12702}, {{2005, 3, 31},
  1.16986}, {{2010, 10, 31}, 1.39026}, {{2001, 1, 31},
  0.993268}, {{2002, 3, 31}, 1.01395}, {{2003, 6, 30},
  1.08647}, {{2005, 11, 30}, 1.14752}, {{2006, 9, 30},
  1.18938}, {{2007, 2, 28}, 1.19658}, {{2008, 1, 31},
  1.20432}, {{2011, 1, 31}, 1.37501}}

In[5]:=uni === del

Out[5]= False

In[6]:= sortdel = Sort[del]

Out[6]= {{{2000, 10, 31}, 1.01816}, {{2001, 1, 31},
  0.993268}, {{2001, 12, 31}, 1.02714}, {{2002, 3, 31},
  1.01395}, {{2003, 6, 30}, 1.08647}, {{2004, 2, 29},
  1.12702}, {{2005, 3, 31}, 1.16986}, {{2005, 11, 30},
  1.14752}, {{2006, 9, 30}, 1.18938}, {{2007, 2, 28},
  1.19658}, {{2008, 1, 31}, 1.20432}, {{2010, 10, 31},
  1.39026}, {{2011, 1, 31}, 1.37501}}

In[7]:=uni === sortdel

Out[7]= True

Cheers,

Mark

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Does Union[] reliably sort? Michael Stern <nycstern@gmail.com> - 2011-12-14 11:10 +0000
  Re: Does Union[] reliably sort? David Bailey <dave@removedbailey.co.uk> - 2011-12-15 10:03 +0000
  Re: Does Union[] reliably sort? "Nasser M. Abbasi" <nma@12000.org> - 2011-12-15 10:07 +0000
  Re: reliably sort? DrMajorBob <btreat1@austin.rr.com> - 2011-12-16 11:00 +0000
  Re: reliably sort? "Nasser M. Abbasi" <nma@12000.org> - 2011-12-16 11:01 +0000
    Re: reliably sort? David Bailey <dave@removedbailey.co.uk> - 2011-12-18 09:39 +0000
  Re: reliably sort? Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2011-12-16 11:09 +0000
  Re: reliably sort? DrMajorBob <btreat1@austin.rr.com> - 2011-12-17 07:45 +0000
  Re: Does Union[] reliably sort? markholtuk <markholtuk@googlemail.com> - 2011-12-17 07:40 +0000
  Re: reliably sort? DrMajorBob <btreat1@austin.rr.com> - 2011-12-17 07:45 +0000
  Re: reliably sort? Ulrich Arndt <ulrich.arndt@data2knowledge.de> - 2011-12-17 07:47 +0000
  Re: reliably sort? DrMajorBob <btreat1@austin.rr.com> - 2011-12-17 07:52 +0000
  R: Re: reliably sort? "Sir Bob Knight" <sir.bob.knight@gmail.com> - 2011-12-18 09:36 +0000
  Re: Does Union[] reliably sort? Szabolcs <szhorvat@gmail.com> - 2011-12-20 08:08 +0000

csiph-web