The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Is there any efficient easy way to compare two lists with the same length with Mathematica?
Replies: 5   Last Post: Jan 21, 2012 5:11 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Andrzej Kozlowski

Posts: 2,112
Registered: 1/29/05
Re: Is there any efficient easy way to compare two lists with the same length with Mathematica?
Posted: Jan 20, 2012 1:53 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Well, actually both. The vector spaces R^n for n>1 have lots of
different orders arising from the natural total order on R (the real
numbers) and none of them is in any sense "canonical". In fact, of
course, mathematica does have a default ordering, which is
lexicographical, as you can see here:

OrderedQ[{1, 4}, {3, 3}]


and not the product ordering which is only a partial order. In any case,
I don't think any of these ordering should by assumed when one applies
the symbol <= etc.


On 19 Jan 2012, at 18:25, Ralph Dratman wrote:

> "Comparisons such as {3, 4} >= {2, 5} do not have a canonical meaning..."
> Andrej,
> Are you referring to a canonical meaning within Mathematica, or to
> the canonical meaning in some wider realm of mathematics?
> I ask because I have seen the expression "canonical" used at Wolfram
> in the past, and I am not sure what is intended.
> How do we determine what the canonical meaning (if any) of an expression is?
> Ralph
> On Thu, Jan 19, 2012 at 5:10 AM, Andrzej Kozlowski <> wrote:

>> I do not think I would like Mathematica to automatically thread Greater
>> etc over lists or automatically return False or True. Comparisons such
>> as {3, 4} >= {2, 5} do not have a canonical meaning and they may arise
>> in programs where the fact that they are kept unevaluated can be
>> convenient e.g this
>> Min /@ ({3, 4} >= {2, 5}) is a convenient way to compare minima
>> (Min@{3,5}>=Min@{2,5} is quite a lot longer...).
>> In general, there has to be a balance between the sort of things
>> Mathematica does automatically and the sort of things that Mathematica
>> leaves unevaluated until you make your intention more clear (by using
>> Thread, for instance). In this particular case I think the second choice
>> is the right one.
>> Andrzej Kozlowski
>> On 18 Jan 2012, at 11:57, Murray Eisenberg wrote:

>>> Over time more and more things like this have been extended to work
>>> automatically on lists. But so far, as you discovered, not GreaterEqual
>>> (nor Greater, etc.). Here's one way without explicitly using Table:
>>> a = RandomInteger[{0, 20}, 5];
>>> b = RandomInteger[{0, 20}, 5];
>>> And @@ MapThread[Greater, {a, b}]
>>> The key there is MapThread, which does what you (and I) would evidently
>>> like Mathematica to do automatically -- in effect, to make GreaterEqual
>>> have Listable as an Attribute.
>>> On 1/17/12 3:34 AM, Rex wrote:

>>>> Given two lists `A={a1,a2,a3,}` and `B={b1,b2,b3,}`, I would
>>>> say `A>=B` if and only if all `ai>=bi`.
>>>> There is a built-in logical comparison of two lists, `A==B`, but no
>>>> `A>B`.
>>>> Do we need to compare each element like this
>>>> And@@Table[A[[i]]>=B[[i]],{i,n}]
>>>> Any better tricks to do this?

>>> --
>>> Murray Eisenberg
>>> Mathematics & Statistics Dept.
>>> Lederle Graduate Research Tower phone 413 549-1020 (H)
>>> University of Massachusetts 413 545-2859 (W)
>>> 710 North Pleasant Street fax 413 545-1801
>>> Amherst, MA 01003-9305


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.